Bug 1505511 - Part 2: Use ClassSpec in WeakSetObject. r=evilpie
authorTooru Fujisawa <arai_a@mac.com>
Tue, 20 Nov 2018 20:21:32 +0900
changeset 503652 32915637657a5e92dbdd8abec557c1f229b70cd1
parent 503651 a5d9fa8dc136d167e53b1ae4a7b494d2e691dd60
child 503653 754cc91c9d3b50207679ef25861d662496811c64
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersevilpie
bugs1505511
milestone65.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 1505511 - Part 2: Use ClassSpec in WeakSetObject. r=evilpie
js/public/ProtoKey.h
js/src/builtin/WeakSetObject.cpp
js/src/builtin/WeakSetObject.h
--- a/js/public/ProtoKey.h
+++ b/js/public/ProtoKey.h
@@ -95,17 +95,17 @@
     REAL(Map,                   InitViaClassSpec,       OCLASP(Map)) \
     REAL(Set,                   InitViaClassSpec,       OCLASP(Set)) \
     REAL(DataView,              InitViaClassSpec,       OCLASP(DataView)) \
     REAL(Symbol,                InitSymbolClass,        OCLASP(Symbol)) \
     REAL(SharedArrayBuffer,     InitViaClassSpec,       OCLASP(SharedArrayBuffer)) \
     REAL_IF_INTL(Intl, InitIntlClass, CLASP(Intl)) \
     REAL_IF_BDATA(TypedObject, InitTypedObjectModuleObject, OCLASP(TypedObjectModule)) \
     REAL(Reflect,               InitReflect,            nullptr) \
-    REAL(WeakSet,               InitWeakSetClass,       OCLASP(WeakSet)) \
+    REAL(WeakSet,               InitViaClassSpec,       OCLASP(WeakSet)) \
     REAL(TypedArray,            InitViaClassSpec,       &js::TypedArrayObject::sharedTypedArrayPrototypeClass) \
     REAL(Atomics,               InitAtomicsClass,       OCLASP(Atomics)) \
     REAL(SavedFrame,            InitViaClassSpec,       &js::SavedFrame::class_) \
     REAL(Promise,               InitViaClassSpec,       OCLASP(Promise)) \
     REAL(ReadableStream,        InitViaClassSpec,       &js::ReadableStream::class_) \
     REAL(ReadableStreamDefaultReader,           InitViaClassSpec, &js::ReadableStreamDefaultReader::class_) \
     REAL(ReadableStreamDefaultController,       InitViaClassSpec, &js::ReadableStreamDefaultController::class_) \
     REAL(ReadableByteStreamController,          InitViaClassSpec, &js::ReadableByteStreamController::class_) \
--- a/js/src/builtin/WeakSetObject.cpp
+++ b/js/src/builtin/WeakSetObject.cpp
@@ -16,28 +16,28 @@
 
 #include "builtin/WeakMapObject-inl.h"
 #include "vm/Interpreter-inl.h"
 #include "vm/JSObject-inl.h"
 #include "vm/NativeObject-inl.h"
 
 using namespace js;
 
-MOZ_ALWAYS_INLINE bool
-IsWeakSet(HandleValue v)
+/* static */ MOZ_ALWAYS_INLINE bool
+WeakSetObject::is(HandleValue v)
 {
     return v.isObject() && v.toObject().is<WeakSetObject>();
 }
 
 // ES2018 draft rev 7a2d3f053ecc2336fc19f377c55d52d78b11b296
 // 23.4.3.1 WeakSet.prototype.add ( value )
-MOZ_ALWAYS_INLINE bool
-WeakSet_add_impl(JSContext* cx, const CallArgs& args)
+/* static */ MOZ_ALWAYS_INLINE bool
+WeakSetObject::add_impl(JSContext* cx, const CallArgs& args)
 {
-    MOZ_ASSERT(IsWeakSet(args.thisv()));
+    MOZ_ASSERT(is(args.thisv()));
 
     // Step 4.
     if (!args.get(0).isObject()) {
         ReportNotObjectWithName(cx, "WeakSet value", args.get(0));
         return false;
     }
 
     // Steps 5-7.
@@ -47,30 +47,30 @@ WeakSet_add_impl(JSContext* cx, const Ca
         return false;
     }
 
     // Steps 6.a.i, 8.
     args.rval().set(args.thisv());
     return true;
 }
 
-static bool
-WeakSet_add(JSContext* cx, unsigned argc, Value* vp)
+/* static */ bool
+WeakSetObject::add(JSContext* cx, unsigned argc, Value* vp)
 {
     // Steps 1-3.
     CallArgs args = CallArgsFromVp(argc, vp);
-    return CallNonGenericMethod<IsWeakSet, WeakSet_add_impl>(cx, args);
+    return CallNonGenericMethod<WeakSetObject::is, WeakSetObject::add_impl>(cx, args);
 }
 
 // ES2018 draft rev 7a2d3f053ecc2336fc19f377c55d52d78b11b296
 // 23.4.3.3 WeakSet.prototype.delete ( value )
-MOZ_ALWAYS_INLINE bool
-WeakSet_delete_impl(JSContext* cx, const CallArgs& args)
+/* static */ MOZ_ALWAYS_INLINE bool
+WeakSetObject::delete_impl(JSContext* cx, const CallArgs& args)
 {
-    MOZ_ASSERT(IsWeakSet(args.thisv()));
+    MOZ_ASSERT(is(args.thisv()));
 
     // Step 4.
     if (!args.get(0).isObject()) {
         args.rval().setBoolean(false);
         return true;
     }
 
     // Steps 5-6.
@@ -83,30 +83,30 @@ WeakSet_delete_impl(JSContext* cx, const
         }
     }
 
     // Step 7.
     args.rval().setBoolean(false);
     return true;
 }
 
-static bool
-WeakSet_delete(JSContext* cx, unsigned argc, Value* vp)
+/* static */ bool
+WeakSetObject::delete_(JSContext* cx, unsigned argc, Value* vp)
 {
     // Steps 1-3.
     CallArgs args = CallArgsFromVp(argc, vp);
-    return CallNonGenericMethod<IsWeakSet, WeakSet_delete_impl>(cx, args);
+    return CallNonGenericMethod<WeakSetObject::is, WeakSetObject::delete_impl>(cx, args);
 }
 
 // ES2018 draft rev 7a2d3f053ecc2336fc19f377c55d52d78b11b296
 // 23.4.3.4 WeakSet.prototype.has ( value )
-MOZ_ALWAYS_INLINE bool
-WeakSet_has_impl(JSContext* cx, const CallArgs& args)
+/* static */ MOZ_ALWAYS_INLINE bool
+WeakSetObject::has_impl(JSContext* cx, const CallArgs& args)
 {
-    MOZ_ASSERT(IsWeakSet(args.thisv()));
+    MOZ_ASSERT(is(args.thisv()));
 
     // Step 5.
     if (!args.get(0).isObject()) {
         args.rval().setBoolean(false);
         return true;
     }
 
     // Steps 4, 6.
@@ -118,74 +118,73 @@ WeakSet_has_impl(JSContext* cx, const Ca
         }
     }
 
     // Step 7.
     args.rval().setBoolean(false);
     return true;
 }
 
-static bool
-WeakSet_has(JSContext* cx, unsigned argc, Value* vp)
+/* static */ bool
+WeakSetObject::has(JSContext* cx, unsigned argc, Value* vp)
 {
     // Steps 1-3.
     CallArgs args = CallArgsFromVp(argc, vp);
-    return CallNonGenericMethod<IsWeakSet, WeakSet_has_impl>(cx, args);
+    return CallNonGenericMethod<WeakSetObject::is, WeakSetObject::has_impl>(cx, args);
 }
 
+const ClassSpec WeakSetObject::classSpec_ = {
+    GenericCreateConstructor<WeakSetObject::construct, 0, gc::AllocKind::FUNCTION>,
+    GenericCreatePrototype<WeakSetObject>,
+    nullptr,
+    nullptr,
+    WeakSetObject::methods,
+    WeakSetObject::properties,
+};
+
 const Class WeakSetObject::class_ = {
     "WeakSet",
     JSCLASS_HAS_PRIVATE |
     JSCLASS_HAS_CACHED_PROTO(JSProto_WeakSet) |
     JSCLASS_BACKGROUND_FINALIZE,
-    &WeakCollectionObject::classOps_
+    &WeakCollectionObject::classOps_,
+    &WeakSetObject::classSpec_
+};
+
+const Class WeakSetObject::protoClass_ = {
+    js_Object_str,
+    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
 };
 
 const JSFunctionSpec WeakSetObject::methods[] = {
-    JS_FN("add",    WeakSet_add,    1, 0),
-    JS_FN("delete", WeakSet_delete, 1, 0),
-    JS_FN("has",    WeakSet_has,    1, 0),
+    // clang-format off
+    JS_FN("add", add, 1, 0),
+    JS_FN("delete", delete_, 1, 0),
+    JS_FN("has", has, 1, 0),
     JS_FS_END
+    // clang-format on
 };
 
-JSObject*
-WeakSetObject::initClass(JSContext* cx, Handle<GlobalObject*> global)
-{
-    RootedPlainObject proto(cx, NewBuiltinClassInstance<PlainObject>(cx));
-    if (!proto) {
-        return nullptr;
-    }
-
-    Rooted<JSFunction*> ctor(cx, GlobalObject::createConstructor(cx, construct,
-                                                                 ClassName(JSProto_WeakSet, cx), 0));
-    if (!ctor ||
-        !LinkConstructorAndPrototype(cx, ctor, proto) ||
-        !DefinePropertiesAndFunctions(cx, proto, properties, methods) ||
-        !DefineToStringTag(cx, proto, cx->names().WeakSet) ||
-        !GlobalObject::initBuiltinConstructor(cx, global, JSProto_WeakSet, ctor, proto))
-    {
-        return nullptr;
-    }
-    return proto;
-}
-
 WeakSetObject*
 WeakSetObject::create(JSContext* cx, HandleObject proto /* = nullptr */)
 {
     return NewObjectWithClassProto<WeakSetObject>(cx, proto);
 }
 
 bool
 WeakSetObject::isBuiltinAdd(HandleValue add)
 {
-    return IsNativeFunction(add, WeakSet_add);
+    return IsNativeFunction(add, WeakSetObject::add);
 }
 
 bool
 WeakSetObject::construct(JSContext* cx, unsigned argc, Value* vp)
 {
     // Based on our "Set" implementation instead of the more general ES6 steps.
     CallArgs args = CallArgsFromVp(argc, vp);
 
@@ -238,23 +237,16 @@ WeakSetObject::construct(JSContext* cx, 
             }
         }
     }
 
     args.rval().setObject(*obj);
     return true;
 }
 
-
-JSObject*
-js::InitWeakSetClass(JSContext* cx, Handle<GlobalObject*> global)
-{
-    return WeakSetObject::initClass(cx, global);
-}
-
 JS_FRIEND_API bool
 JS_NondeterministicGetWeakSetKeys(JSContext* cx, HandleObject objArg, MutableHandleObject ret)
 {
     RootedObject obj(cx, UncheckedUnwrap(objArg));
     if (!obj || !obj->is<WeakSetObject>()) {
         ret.set(nullptr);
         return true;
     }
--- a/js/src/builtin/WeakSetObject.h
+++ b/js/src/builtin/WeakSetObject.h
@@ -11,32 +11,40 @@
 
 namespace js {
 
 class GlobalObject;
 
 class WeakSetObject : public WeakCollectionObject
 {
   public:
-    static JSObject* initClass(JSContext* cx, Handle<GlobalObject*> global);
     static const Class class_;
+    static const Class protoClass_;
 
   private:
+    static const ClassSpec classSpec_;
+
     static const JSPropertySpec properties[];
     static const JSFunctionSpec methods[];
 
     static WeakSetObject* create(JSContext* cx, HandleObject proto = nullptr);
     static MOZ_MUST_USE bool construct(JSContext* cx, unsigned argc, Value* vp);
 
+    static MOZ_MUST_USE MOZ_ALWAYS_INLINE bool is(HandleValue v);
+
+    static MOZ_MUST_USE MOZ_ALWAYS_INLINE bool add_impl(JSContext* cx, const CallArgs& args);
+    static MOZ_MUST_USE bool add(JSContext* cx, unsigned argc, Value* vp);
+    static MOZ_MUST_USE MOZ_ALWAYS_INLINE bool delete_impl(JSContext* cx, const CallArgs& args);
+    static MOZ_MUST_USE bool delete_(JSContext* cx, unsigned argc, Value* vp);
+    static MOZ_MUST_USE MOZ_ALWAYS_INLINE bool has_impl(JSContext* cx, const CallArgs& args);
+    static MOZ_MUST_USE bool has(JSContext* cx, unsigned argc, Value* vp);
+
     static bool isBuiltinAdd(HandleValue add);
 };
 
-extern JSObject*
-InitWeakSetClass(JSContext* cx, Handle<GlobalObject*> global);
-
 } // namespace js
 
 template<>
 inline bool
 JSObject::is<js::WeakCollectionObject>() const
 {
     return is<js::WeakMapObject>() || is<js::WeakSetObject>();
 }