Bug 1721333 part 7 - Use a reserved slot instead of private slot for WeakMapObject and WeakSetObject. r=jonco
authorJan de Mooij <jdemooij@mozilla.com>
Tue, 20 Jul 2021 15:05:17 +0000
changeset 586169 7027d71565f9a4aba49dae525025ea69e00adb26
parent 586168 afdf120fa94cc831a754c5d9a0f93cbae7a19982
child 586170 97f0e495e8aa8ca7c35aa40f19dbbc58f246e02e
push id38627
push usersmolnar@mozilla.com
push dateTue, 20 Jul 2021 21:56:01 +0000
treeherdermozilla-central@3d302847f025 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs1721333
milestone92.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1721333 part 7 - Use a reserved slot instead of private slot for WeakMapObject and WeakSetObject. r=jonco Depends on D120312 Differential Revision: https://phabricator.services.mozilla.com/D120313
js/src/builtin/WeakMapObject-inl.h
js/src/builtin/WeakMapObject.cpp
js/src/builtin/WeakMapObject.h
js/src/builtin/WeakSetObject.cpp
--- a/js/src/builtin/WeakMapObject-inl.h
+++ b/js/src/builtin/WeakMapObject-inl.h
@@ -32,17 +32,18 @@ static MOZ_ALWAYS_INLINE bool WeakCollec
     HandleValue value) {
   ObjectValueWeakMap* map = obj->getMap();
   if (!map) {
     auto newMap = cx->make_unique<ObjectValueWeakMap>(cx, obj.get());
     if (!newMap) {
       return false;
     }
     map = newMap.release();
-    InitObjectPrivate(obj, map, MemoryUse::WeakMapObject);
+    InitReservedSlot(obj, WeakCollectionObject::DataSlot, map,
+                     MemoryUse::WeakMapObject);
   }
 
   // Preserve wrapped native keys to prevent wrapper optimization.
   if (!TryPreserveReflector(cx, key)) {
     return false;
   }
 
   RootedObject delegate(cx, UncheckedUnwrapWithoutExpose(key));
--- a/js/src/builtin/WeakMapObject.cpp
+++ b/js/src/builtin/WeakMapObject.cpp
@@ -281,18 +281,18 @@ const ClassSpec WeakMapObject::classSpec
     nullptr,
     nullptr,
     WeakMapObject::methods,
     WeakMapObject::properties,
 };
 
 const JSClass WeakMapObject::class_ = {
     "WeakMap",
-    JSCLASS_HAS_PRIVATE | JSCLASS_HAS_CACHED_PROTO(JSProto_WeakMap) |
-        JSCLASS_BACKGROUND_FINALIZE,
+    JSCLASS_HAS_RESERVED_SLOTS(SlotCount) |
+        JSCLASS_HAS_CACHED_PROTO(JSProto_WeakMap) | JSCLASS_BACKGROUND_FINALIZE,
     &WeakCollectionObject::classOps_, &WeakMapObject::classSpec_};
 
 const JSClass WeakMapObject::protoClass_ = {
     "WeakMap.prototype", JSCLASS_HAS_CACHED_PROTO(JSProto_WeakMap),
     JS_NULL_CLASS_OPS, &WeakMapObject::classSpec_};
 
 const JSPropertySpec WeakMapObject::properties[] = {
     JS_STRING_SYM_PS(toStringTag, "WeakMap", JSPROP_READONLY), JS_PS_END};
--- a/js/src/builtin/WeakMapObject.h
+++ b/js/src/builtin/WeakMapObject.h
@@ -12,18 +12,20 @@
 
 namespace js {
 
 class GlobalObject;
 
 // Abstract base class for WeakMapObject and WeakSetObject.
 class WeakCollectionObject : public NativeObject {
  public:
+  enum { DataSlot, SlotCount };
+
   ObjectValueWeakMap* getMap() {
-    return static_cast<ObjectValueWeakMap*>(getPrivate());
+    return maybePtrFromReservedSlot<ObjectValueWeakMap>(DataSlot);
   }
 
   size_t sizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) {
     ObjectValueWeakMap* map = getMap();
     return map ? map->sizeOfIncludingThis(aMallocSizeOf) : 0;
   }
 
   [[nodiscard]] static bool nondeterministicGetKeys(
--- a/js/src/builtin/WeakSetObject.cpp
+++ b/js/src/builtin/WeakSetObject.cpp
@@ -137,18 +137,18 @@ const ClassSpec WeakSetObject::classSpec
     nullptr,
     nullptr,
     WeakSetObject::methods,
     WeakSetObject::properties,
 };
 
 const JSClass WeakSetObject::class_ = {
     "WeakSet",
-    JSCLASS_HAS_PRIVATE | JSCLASS_HAS_CACHED_PROTO(JSProto_WeakSet) |
-        JSCLASS_BACKGROUND_FINALIZE,
+    JSCLASS_HAS_RESERVED_SLOTS(SlotCount) |
+        JSCLASS_HAS_CACHED_PROTO(JSProto_WeakSet) | JSCLASS_BACKGROUND_FINALIZE,
     &WeakCollectionObject::classOps_, &WeakSetObject::classSpec_};
 
 const JSClass WeakSetObject::protoClass_ = {
     "WeakSet.prototype", JSCLASS_HAS_CACHED_PROTO(JSProto_WeakSet),
     JS_NULL_CLASS_OPS, &WeakSetObject::classSpec_};
 
 const JSPropertySpec WeakSetObject::properties[] = {
     JS_STRING_SYM_PS(toStringTag, "WeakSet", JSPROP_READONLY), JS_PS_END};