Bug 1842773 - Part 32: Allow constructing growable SharedArrayBuffers. r=sfink
[gecko.git] / js / src / vm / PlainObject-inl.h
blob496b10c3d5fd9d0c4f677b5ac534bdf3cf279eb5
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef vm_PlainObject_inl_h
8 #define vm_PlainObject_inl_h
10 #include "vm/PlainObject.h"
12 #include "mozilla/Assertions.h" // MOZ_ASSERT, MOZ_ASSERT_IF
13 #include "mozilla/Attributes.h" // MOZ_ALWAYS_INLINE
15 #include "gc/AllocKind.h" // js::gc::Heap
16 #include "js/RootingAPI.h" // JS::Handle, JS::Rooted, JS::MutableHandle
17 #include "js/Value.h" // JS::Value, JS_IS_CONSTRUCTING
18 #include "vm/JSFunction.h" // JSFunction
19 #include "vm/JSObject.h" // js::GenericObject, js::NewObjectKind
20 #include "vm/NativeObject.h" // js::NativeObject::create
21 #include "vm/Shape.h" // js::Shape
23 #include "gc/ObjectKind-inl.h" // js::gc::GetGCObjectKind
24 #include "vm/JSObject-inl.h" // js::GetInitialHeap, js::NewBuiltinClassInstance
25 #include "vm/NativeObject-inl.h" // js::NativeObject::{create,setLastProperty}
27 /* static */ inline js::PlainObject* js::PlainObject::createWithShape(
28 JSContext* cx, JS::Handle<SharedShape*> shape, gc::AllocKind kind,
29 NewObjectKind newKind) {
30 MOZ_ASSERT(shape->getObjectClass() == &PlainObject::class_);
31 gc::Heap heap = GetInitialHeap(newKind, &PlainObject::class_);
33 MOZ_ASSERT(gc::CanChangeToBackgroundAllocKind(kind, &PlainObject::class_));
34 kind = gc::ForegroundToBackgroundAllocKind(kind);
36 return NativeObject::create<PlainObject>(cx, kind, heap, shape);
39 /* static */ inline js::PlainObject* js::PlainObject::createWithShape(
40 JSContext* cx, JS::Handle<SharedShape*> shape, NewObjectKind newKind) {
41 gc::AllocKind kind = gc::GetGCObjectKind(shape->numFixedSlots());
42 return createWithShape(cx, shape, kind, newKind);
45 /* static */ inline js::PlainObject* js::PlainObject::createWithTemplate(
46 JSContext* cx, JS::Handle<PlainObject*> templateObject) {
47 JS::Rooted<SharedShape*> shape(cx, templateObject->sharedShape());
48 return createWithShape(cx, shape);
51 inline js::gc::AllocKind js::PlainObject::allocKindForTenure() const {
52 gc::AllocKind kind = gc::GetGCObjectFixedSlotsKind(numFixedSlots());
53 MOZ_ASSERT(!gc::IsBackgroundFinalized(kind));
54 MOZ_ASSERT(gc::CanChangeToBackgroundAllocKind(kind, getClass()));
55 return gc::ForegroundToBackgroundAllocKind(kind);
58 namespace js {
60 static MOZ_ALWAYS_INLINE bool CreateThis(JSContext* cx,
61 JS::Handle<JSFunction*> callee,
62 JS::Handle<JSObject*> newTarget,
63 NewObjectKind newKind,
64 JS::MutableHandle<JS::Value> thisv) {
65 if (callee->constructorNeedsUninitializedThis()) {
66 thisv.setMagic(JS_UNINITIALIZED_LEXICAL);
67 return true;
70 MOZ_ASSERT(thisv.isMagic(JS_IS_CONSTRUCTING));
72 Rooted<SharedShape*> shape(cx, ThisShapeForFunction(cx, callee, newTarget));
73 if (!shape) {
74 return false;
77 PlainObject* obj = PlainObject::createWithShape(cx, shape, newKind);
78 if (!obj) {
79 return false;
82 MOZ_ASSERT(obj->nonCCWRealm() == callee->realm());
83 thisv.setObject(*obj);
84 return true;
87 } // namespace js
89 #endif // vm_PlainObject_inl_h