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/. */
12 #include "vm/JSObject.h"
13 #include "vm/PropertyResult.h"
15 #include "gc/GCContext-inl.h"
16 #include "gc/Marking-inl.h"
17 #include "vm/PropMap-inl.h"
21 template <class ObjectSubclass
>
22 /* static */ inline bool SharedShape::ensureInitialCustomShape(
23 JSContext
* cx
, Handle
<ObjectSubclass
*> obj
) {
24 static_assert(std::is_base_of_v
<JSObject
, ObjectSubclass
>,
25 "ObjectSubclass must be a subclass of JSObject");
27 // If the provided object has a non-empty shape, it was given the cached
28 // initial shape when created: nothing to do.
33 // Ensure the initial shape isn't collected under assignInitialShape, to
34 // simplify insertInitialShape.
35 Rooted
<Shape
*> emptyShape(cx
, obj
->shape());
37 // If no initial shape was assigned, do so.
38 Rooted
<SharedShape
*> shape(cx
, ObjectSubclass::assignInitialShape(cx
, obj
));
42 MOZ_ASSERT(!obj
->empty());
44 // Cache the initial shape, so that future instances will begin life with that
46 SharedShape::insertInitialShape(cx
, shape
);
50 MOZ_ALWAYS_INLINE PropMap
* NativeShape::lookup(JSContext
* cx
, PropertyKey key
,
52 uint32_t len
= propMapLength();
53 return len
> 0 ? propMap_
->lookup(cx
, len
, key
, index
) : nullptr;
56 MOZ_ALWAYS_INLINE PropMap
* NativeShape::lookupPure(PropertyKey key
,
58 uint32_t len
= propMapLength();
59 return len
> 0 ? propMap_
->lookupPure(len
, key
, index
) : nullptr;
62 inline void Shape::purgeCache(JS::GCContext
* gcx
) {
63 if (cache_
.isShapeSetForAdd()) {
64 gcx
->delete_(this, cache_
.toShapeSetForAdd(), MemoryUse::ShapeSetForAdd
);
69 inline void Shape::finalize(JS::GCContext
* gcx
) {
70 if (!cache_
.isNone()) {
74 asWasmGC().finalize(gcx
);
78 inline void WasmGCShape::init() { recGroup_
->AddRef(); }
80 inline void WasmGCShape::finalize(JS::GCContext
* gcx
) { recGroup_
->Release(); }
82 inline SharedPropMap
* SharedShape::propMapMaybeForwarded() const {
83 MOZ_ASSERT(isShared());
84 PropMap
* propMap
= propMap_
;
85 return propMap
? MaybeForwarded(propMap
)->asShared() : nullptr;
88 static inline JS::PropertyAttributes
GetPropertyAttributes(
89 JSObject
* obj
, PropertyResult prop
) {
90 MOZ_ASSERT(obj
->is
<NativeObject
>());
92 if (prop
.isDenseElement()) {
93 return obj
->as
<NativeObject
>().getElementsHeader()->elementAttributes();
95 if (prop
.isTypedArrayElement()) {
96 return {JS::PropertyAttribute::Configurable
,
97 JS::PropertyAttribute::Enumerable
, JS::PropertyAttribute::Writable
};
100 return prop
.propertyInfo().propAttributes();
105 #endif /* vm_Shape_inl_h */