Bug 1445854 - Part 3: Use GenericCreatePrototype in more places. r=arai
authorJason Orendorff <jorendorff@mozilla.com>
Tue, 09 Oct 2018 15:34:35 +0000
changeset 498723 b8c1b55829137acd018c4ff0ca763d5e1e1a89e9
parent 498722 df47d3ad9cc61d1462618ba18dbd2c3359bcc1e7
child 498724 01f7327625291933b8886befa8fb561ced401b3d
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarai
bugs1445854
milestone64.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 1445854 - Part 3: Use GenericCreatePrototype in more places. r=arai Depends on D7667 Differential Revision: https://phabricator.services.mozilla.com/D7783
js/src/builtin/BigInt.cpp
js/src/builtin/BigInt.h
js/src/builtin/DataViewObject.cpp
js/src/builtin/DataViewObject.h
js/src/builtin/MapObject.cpp
js/src/builtin/Promise.cpp
js/src/jsdate.cpp
js/src/vm/ArrayBufferObject.cpp
js/src/vm/RegExpObject.cpp
js/src/vm/SharedArrayObject.cpp
--- a/js/src/builtin/BigInt.cpp
+++ b/js/src/builtin/BigInt.cpp
@@ -21,22 +21,16 @@
 using namespace js;
 
 static MOZ_ALWAYS_INLINE bool
 IsBigInt(HandleValue v)
 {
     return v.isBigInt() || (v.isObject() && v.toObject().is<BigIntObject>());
 }
 
-static JSObject*
-CreateBigIntPrototype(JSContext* cx, JSProtoKey key)
-{
-    return GlobalObject::createBlankPrototype<PlainObject>(cx, cx->global());
-}
-
 // BigInt proposal section 5.1.3
 static bool
 BigIntConstructor(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
     // Step 1.
     if (args.isConstructing()) {
@@ -184,32 +178,39 @@ bool
 BigIntObject::toLocaleString(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
     return CallNonGenericMethod<IsBigInt, toLocaleString_impl>(cx, args);
 }
 
 const ClassSpec BigIntObject::classSpec_ = {
     GenericCreateConstructor<BigIntConstructor, 1, gc::AllocKind::FUNCTION>,
-    CreateBigIntPrototype,
+    GenericCreatePrototype<BigIntObject>,
     nullptr,
     nullptr,
     BigIntObject::methods,
     BigIntObject::properties
 };
 
 // The class is named "Object" as a workaround for bug 1277801.
 const Class BigIntObject::class_ = {
     "Object",
     JSCLASS_HAS_CACHED_PROTO(JSProto_BigInt) |
     JSCLASS_HAS_RESERVED_SLOTS(RESERVED_SLOTS),
     JS_NULL_CLASS_OPS,
     &BigIntObject::classSpec_
 };
 
+const Class BigIntObject::protoClass_ = {
+    js_Object_str,
+    JSCLASS_HAS_CACHED_PROTO(JSProto_BigInt),
+    JS_NULL_CLASS_OPS,
+    &BigIntObject::classSpec_
+};
+
 const JSPropertySpec BigIntObject::properties[] = {
     // BigInt proposal section 5.3.5
     JS_STRING_SYM_PS(toStringTag, "BigInt", JSPROP_READONLY),
     JS_PS_END
 };
 
 const JSFunctionSpec BigIntObject::methods[] = {
     JS_FN("valueOf", valueOf, 0, 0),
--- a/js/src/builtin/BigInt.h
+++ b/js/src/builtin/BigInt.h
@@ -19,16 +19,17 @@ class GlobalObject;
 class BigIntObject : public NativeObject
 {
     static const unsigned PRIMITIVE_VALUE_SLOT = 0;
     static const unsigned RESERVED_SLOTS = 1;
 
   public:
     static const ClassSpec classSpec_;
     static const Class class_;
+    static const Class protoClass_;
 
     static JSObject* create(JSContext* cx, JS::Handle<JS::BigInt*> bi);
 
     // Methods defined on BigInt.prototype.
     static bool valueOf_impl(JSContext* cx, const CallArgs& args);
     static bool valueOf(JSContext* cx, unsigned argc, JS::Value* vp);
     static bool toString_impl(JSContext* cx, const CallArgs& args);
     static bool toString(JSContext* cx, unsigned argc, JS::Value* vp);
--- a/js/src/builtin/DataViewObject.cpp
+++ b/js/src/builtin/DataViewObject.cpp
@@ -930,23 +930,16 @@ DataViewObject::byteOffsetGetterImpl(JSC
 
 bool
 DataViewObject::byteOffsetGetter(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
     return CallNonGenericMethod<is, byteOffsetGetterImpl>(cx, args);
 }
 
-const Class DataViewObject::protoClass_ = {
-    js_Object_str,
-    JSCLASS_HAS_CACHED_PROTO(JSProto_DataView),
-    JS_NULL_CLASS_OPS,
-    &DataViewObject::classSpec_
-};
-
 JSObject*
 DataViewObject::CreatePrototype(JSContext* cx, JSProtoKey key)
 {
     return GlobalObject::createBlankPrototype(cx, cx->global(), &DataViewObject::protoClass_);
 }
 
 static const ClassOps DataViewObjectClassOps = {
     nullptr, /* addProperty */
@@ -959,32 +952,39 @@ static const ClassOps DataViewObjectClas
     nullptr, /* call */
     nullptr, /* hasInstance */
     nullptr, /* construct */
     ArrayBufferViewObject::trace
 };
 
 const ClassSpec DataViewObject::classSpec_ = {
     GenericCreateConstructor<DataViewObject::construct, 3, gc::AllocKind::FUNCTION>,
-    DataViewObject::CreatePrototype,
+    GenericCreatePrototype<DataViewObject>,
     nullptr,
     nullptr,
     DataViewObject::methods,
     DataViewObject::properties,
 };
 
 const Class DataViewObject::class_ = {
     "DataView",
     JSCLASS_HAS_PRIVATE |
     JSCLASS_HAS_RESERVED_SLOTS(TypedArrayObject::RESERVED_SLOTS) |
     JSCLASS_HAS_CACHED_PROTO(JSProto_DataView),
     &DataViewObjectClassOps,
     &DataViewObject::classSpec_
 };
 
+const Class DataViewObject::protoClass_ = {
+    js_Object_str,
+    JSCLASS_HAS_CACHED_PROTO(JSProto_DataView),
+    JS_NULL_CLASS_OPS,
+    &DataViewObject::classSpec_
+};
+
 const JSFunctionSpec DataViewObject::methods[] = {
     JS_FN("getInt8",    DataViewObject::fun_getInt8,      1,0),
     JS_FN("getUint8",   DataViewObject::fun_getUint8,     1,0),
     JS_FN("getInt16",   DataViewObject::fun_getInt16,     1,0),
     JS_FN("getUint16",  DataViewObject::fun_getUint16,    1,0),
     JS_FN("getInt32",   DataViewObject::fun_getInt32,     1,0),
     JS_FN("getUint32",  DataViewObject::fun_getUint32,    1,0),
     JS_FN("getFloat32", DataViewObject::fun_getFloat32,   1,0),
--- a/js/src/builtin/DataViewObject.h
+++ b/js/src/builtin/DataViewObject.h
@@ -21,17 +21,16 @@ namespace js {
 // In the DataViewObject, the private slot contains a raw pointer into
 // the buffer.  The buffer may be shared memory and the raw pointer
 // should not be exposed without sharedness information accompanying
 // it.
 
 class DataViewObject : public NativeObject
 {
   private:
-    static const Class protoClass_;
     static const ClassSpec classSpec_;
 
     static JSObject* CreatePrototype(JSContext* cx, JSProtoKey key);
 
     static bool is(HandleValue v) {
         return v.isObject() && v.toObject().hasClass(&class_);
     }
 
@@ -55,16 +54,17 @@ class DataViewObject : public NativeObje
     static bool constructWrapped(JSContext* cx, HandleObject bufobj, const CallArgs& args);
 
     static DataViewObject*
     create(JSContext* cx, uint32_t byteOffset, uint32_t byteLength,
            Handle<ArrayBufferObjectMaybeShared*> arrayBuffer, HandleObject proto);
 
   public:
     static const Class class_;
+    static const Class protoClass_;
 
     static Value byteOffsetValue(const DataViewObject* view) {
         Value v = view->getFixedSlot(TypedArrayObject::BYTEOFFSET_SLOT);
         MOZ_ASSERT(v.toInt32() >= 0);
         return v;
     }
 
     static Value byteLengthValue(const DataViewObject* view) {
--- a/js/src/builtin/MapObject.cpp
+++ b/js/src/builtin/MapObject.cpp
@@ -407,39 +407,33 @@ MapIteratorObject::createResultPair(JSCo
     AddTypePropertyId(cx, resultPairObj, JSID_VOID, TypeSet::UnknownType());
 
     return resultPairObj;
 }
 
 
 /*** Map *****************************************************************************************/
 
-static JSObject*
-CreateMapPrototype(JSContext* cx, JSProtoKey key)
-{
-    return GlobalObject::createBlankPrototype(cx, cx->global(), &MapObject::protoClass_);
-}
-
 const ClassOps MapObject::classOps_ = {
     nullptr, // addProperty
     nullptr, // delProperty
     nullptr, // enumerate
     nullptr, // newEnumerate
     nullptr, // resolve
     nullptr, // mayResolve
     finalize,
     nullptr, // call
     nullptr, // hasInstance
     nullptr, // construct
     trace
 };
 
 const ClassSpec MapObject::classSpec_ = {
     GenericCreateConstructor<MapObject::construct, 0, gc::AllocKind::FUNCTION>,
-    CreateMapPrototype,
+    GenericCreatePrototype<MapObject>,
     nullptr,
     MapObject::staticProperties,
     MapObject::methods,
     MapObject::properties,
 };
 
 const Class MapObject::class_ = {
     "Map",
@@ -1269,39 +1263,33 @@ SetIteratorObject::createResult(JSContex
     AddTypePropertyId(cx, resultObj, JSID_VOID, TypeSet::UnknownType());
 
     return resultObj;
 }
 
 
 /*** Set *****************************************************************************************/
 
-static JSObject*
-CreateSetPrototype(JSContext* cx, JSProtoKey key)
-{
-    return GlobalObject::createBlankPrototype(cx, cx->global(), &SetObject::protoClass_);
-}
-
 const ClassOps SetObject::classOps_ = {
     nullptr, // addProperty
     nullptr, // delProperty
     nullptr, // enumerate
     nullptr, // newEnumerate
     nullptr, // resolve
     nullptr, // mayResolve
     finalize,
     nullptr, // call
     nullptr, // hasInstance
     nullptr, // construct
     trace
 };
 
 const ClassSpec SetObject::classSpec_ = {
     GenericCreateConstructor<SetObject::construct, 0, gc::AllocKind::FUNCTION>,
-    CreateSetPrototype,
+    GenericCreatePrototype<SetObject>,
     nullptr,
     SetObject::staticProperties,
     SetObject::methods,
     SetObject::properties,
 };
 
 const Class SetObject::class_ = {
     "Set",
--- a/js/src/builtin/Promise.cpp
+++ b/js/src/builtin/Promise.cpp
@@ -5040,22 +5040,16 @@ OffThreadPromiseRuntimeState::shutdown(J
     numCanceled_ = 0;
 
     // After shutdown, there should be no OffThreadPromiseTask activity in this
     // JSRuntime. Revert to the !initialized() state to catch bugs.
     dispatchToEventLoopCallback_ = nullptr;
     MOZ_ASSERT(!initialized());
 }
 
-static JSObject*
-CreatePromisePrototype(JSContext* cx, JSProtoKey key)
-{
-    return GlobalObject::createBlankPrototype(cx, cx->global(), &PromiseObject::protoClass_);
-}
-
 const JSJitInfo promise_then_info = {
   { (JSJitGetterOp)Promise_then_noRetVal },
   { 0 }, /* unused */
   { 0 }, /* unused */
   JSJitInfo::IgnoresReturnValueNative,
   JSJitInfo::AliasEverything,
   JSVAL_TYPE_UNDEFINED,
 };
@@ -5091,17 +5085,17 @@ static const JSFunctionSpec promise_stat
 
 static const JSPropertySpec promise_static_properties[] = {
     JS_SYM_GET(species, Promise_static_species, 0),
     JS_PS_END
 };
 
 static const ClassSpec PromiseObjectClassSpec = {
     GenericCreateConstructor<PromiseConstructor, 1, gc::AllocKind::FUNCTION>,
-    CreatePromisePrototype,
+    GenericCreatePrototype<PromiseObject>,
     promise_static_methods,
     promise_static_properties,
     promise_methods,
     promise_properties
 };
 
 const Class PromiseObject::class_ = {
     "Promise",
--- a/js/src/jsdate.cpp
+++ b/js/src/jsdate.cpp
@@ -3599,23 +3599,16 @@ DateConstructor(JSContext* cx, unsigned 
 
     if (args.length() == 1) {
         return DateOneArgument(cx, args);
     }
 
     return DateMultipleArguments(cx, args);
 }
 
-// ES6 final draft 20.3.4.
-static JSObject*
-CreateDatePrototype(JSContext* cx, JSProtoKey key)
-{
-    return GlobalObject::createBlankPrototype(cx, cx->global(), &DateObject::protoClass_);
-}
-
 static bool
 FinishDateClassInit(JSContext* cx, HandleObject ctor, HandleObject proto)
 {
     /*
      * Date.prototype.toGMTString has the same initial value as
      * Date.prototype.toUTCString.
      */
     RootedValue toUTCStringFun(cx);
@@ -3623,17 +3616,17 @@ FinishDateClassInit(JSContext* cx, Handl
     RootedId toGMTStringId(cx, NameToId(cx->names().toGMTString));
     return NativeGetProperty(cx, proto.as<NativeObject>(), toUTCStringId, &toUTCStringFun) &&
            NativeDefineDataProperty(cx, proto.as<NativeObject>(), toGMTStringId, toUTCStringFun,
                                     0);
 }
 
 static const ClassSpec DateObjectClassSpec = {
     GenericCreateConstructor<DateConstructor, 7, gc::AllocKind::FUNCTION>,
-    CreateDatePrototype,
+    GenericCreatePrototype<DateObject>,
     date_static_methods,
     nullptr,
     date_methods,
     nullptr,
     FinishDateClassInit
 };
 
 const Class DateObject::class_ = {
--- a/js/src/vm/ArrayBufferObject.cpp
+++ b/js/src/vm/ArrayBufferObject.cpp
@@ -256,22 +256,16 @@ js::UnmapBufferMemory(void* base, size_t
  * access.  It can be created explicitly and passed to a TypedArrayObject, or
  * can be created implicitly by constructing a TypedArrayObject with a size.
  */
 
 /*
  * ArrayBufferObject (base)
  */
 
-static JSObject*
-CreateArrayBufferPrototype(JSContext* cx, JSProtoKey key)
-{
-    return GlobalObject::createBlankPrototype(cx, cx->global(), &ArrayBufferObject::protoClass_);
-}
-
 static const ClassOps ArrayBufferObjectClassOps = {
     nullptr,        /* addProperty */
     nullptr,        /* delProperty */
     nullptr,        /* enumerate */
     nullptr,        /* newEnumerate */
     nullptr,        /* resolve */
     nullptr,        /* mayResolve */
     ArrayBufferObject::finalize,
@@ -300,17 +294,17 @@ static const JSFunctionSpec arraybuffer_
 static const JSPropertySpec arraybuffer_proto_properties[] = {
     JS_PSG("byteLength", ArrayBufferObject::byteLengthGetter, 0),
     JS_STRING_SYM_PS(toStringTag, "ArrayBuffer", JSPROP_READONLY),
     JS_PS_END
 };
 
 static const ClassSpec ArrayBufferObjectClassSpec = {
     GenericCreateConstructor<ArrayBufferObject::class_constructor, 1, gc::AllocKind::FUNCTION>,
-    CreateArrayBufferPrototype,
+    GenericCreatePrototype<ArrayBufferObject>,
     arraybuffer_functions,
     arraybuffer_properties,
     arraybuffer_proto_functions,
     arraybuffer_proto_properties
 };
 
 static const ClassExtension ArrayBufferObjectClassExtension = {
     nullptr,    /* weakmapKeyDelegateOp */
--- a/js/src/vm/RegExpObject.cpp
+++ b/js/src/vm/RegExpObject.cpp
@@ -162,39 +162,33 @@ IsMarkingTrace(JSTracer* trc)
 }
 
 void
 RegExpObject::trace(JSTracer* trc)
 {
     TraceNullableEdge(trc, &sharedRef(), "RegExpObject shared");
 }
 
-static JSObject*
-CreateRegExpPrototype(JSContext* cx, JSProtoKey key)
-{
-    return GlobalObject::createBlankPrototype(cx, cx->global(), &RegExpObject::protoClass_);
-}
-
 static const ClassOps RegExpObjectClassOps = {
     nullptr, /* addProperty */
     nullptr, /* delProperty */
     nullptr, /* enumerate */
     nullptr, /* newEnumerate */
     nullptr, /* resolve */
     nullptr, /* mayResolve */
     nullptr, /* finalize */
     nullptr, /* call */
     nullptr, /* hasInstance */
     nullptr, /* construct */
     RegExpObject::trace,
 };
 
 static const ClassSpec RegExpObjectClassSpec = {
     GenericCreateConstructor<js::regexp_construct, 2, gc::AllocKind::FUNCTION>,
-    CreateRegExpPrototype,
+    GenericCreatePrototype<RegExpObject>,
     nullptr,
     js::regexp_static_props,
     js::regexp_methods,
     js::regexp_properties
 };
 
 const Class RegExpObject::class_ = {
     js_RegExp_str,
--- a/js/src/vm/SharedArrayObject.cpp
+++ b/js/src/vm/SharedArrayObject.cpp
@@ -362,23 +362,16 @@ SharedArrayBufferObject::createFromNewRa
         return nullptr;
     }
 
     obj->acceptRawBuffer(buffer, initialSize);
 
     return obj;
 }
 
-static JSObject*
-CreateSharedArrayBufferPrototype(JSContext* cx, JSProtoKey key)
-{
-    return GlobalObject::createBlankPrototype(cx, cx->global(),
-                                              &SharedArrayBufferObject::protoClass_);
-}
-
 static const ClassOps SharedArrayBufferObjectClassOps = {
     nullptr, /* addProperty */
     nullptr, /* delProperty */
     nullptr, /* enumerate */
     nullptr, /* newEnumerate */
     nullptr, /* resolve */
     nullptr, /* mayResolve */
     SharedArrayBufferObject::Finalize,
@@ -405,17 +398,17 @@ static const JSFunctionSpec sharedarray_
 static const JSPropertySpec sharedarray_proto_properties[] = {
     JS_PSG("byteLength", SharedArrayBufferObject::byteLengthGetter, 0),
     JS_STRING_SYM_PS(toStringTag, "SharedArrayBuffer", JSPROP_READONLY),
     JS_PS_END
 };
 
 static const ClassSpec SharedArrayBufferObjectClassSpec = {
     GenericCreateConstructor<SharedArrayBufferObject::class_constructor, 1, gc::AllocKind::FUNCTION>,
-    CreateSharedArrayBufferPrototype,
+    GenericCreatePrototype<SharedArrayBufferObject>,
     sharedarrray_functions,
     sharedarrray_properties,
     sharedarray_proto_functions,
     sharedarray_proto_properties
 };
 
 const Class SharedArrayBufferObject::class_ = {
     "SharedArrayBuffer",