Bug 1595745 - Part 8: Change Reflect to use ClassSpec. r=mgaudet
☠☠ backed out by ec8cad689121 ☠ ☠
authorAndré Bargull <andre.bargull@gmail.com>
Fri, 15 Nov 2019 15:04:02 +0000
changeset 502202 3b0e242d762a12cdcb16a0e9f2ac60ce3af21833
parent 502201 fef5c8d5cb909dd147da181f45851603cddeb045
child 502203 29ec5ccb4adf6d914edf9fb7dfaf9f362a902455
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmgaudet
bugs1595745
milestone72.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 1595745 - Part 8: Change Reflect to use ClassSpec. r=mgaudet Differential Revision: https://phabricator.services.mozilla.com/D52664
js/public/ProtoKey.h
js/src/builtin/Reflect.cpp
js/src/builtin/Reflect.h
js/src/vm/GlobalObject.cpp
--- a/js/public/ProtoKey.h
+++ b/js/public/ProtoKey.h
@@ -99,17 +99,17 @@
   REAL_IF_INTL(Locale, InitViaClassSpec, OCLASP(Locale))                     \
   REAL_IF_INTL(ListFormat, InitViaClassSpec, OCLASP(ListFormat))             \
   REAL_IF_INTL(NumberFormat, InitViaClassSpec, OCLASP(NumberFormat))         \
   REAL_IF_INTL(PluralRules, InitViaClassSpec, OCLASP(PluralRules))           \
   REAL_IF_INTL(RelativeTimeFormat, InitViaClassSpec,                         \
                OCLASP(RelativeTimeFormat))                                   \
   REAL_IF_BDATA(TypedObject, InitTypedObjectModuleObject,                    \
                 OCLASP(TypedObjectModule))                                   \
-  REAL(Reflect, InitReflect, nullptr)                                        \
+  REAL(Reflect, InitViaClassSpec, CLASP(Reflect))                            \
   REAL(WeakSet, InitViaClassSpec, OCLASP(WeakSet))                           \
   REAL(TypedArray, InitViaClassSpec,                                         \
        &js::TypedArrayObject::sharedTypedArrayPrototypeClass)                \
   REAL(Atomics, InitViaClassSpec, OCLASP(Atomics))                           \
   REAL(SavedFrame, InitViaClassSpec, &js::SavedFrame::class_)                \
   REAL(Promise, InitViaClassSpec, OCLASP(Promise))                           \
   REAL(AsyncFunction, InitAsyncFunction, nullptr)                            \
   REAL(GeneratorFunction, InitGeneratorFunction, nullptr)                    \
--- a/js/src/builtin/Reflect.cpp
+++ b/js/src/builtin/Reflect.cpp
@@ -189,17 +189,17 @@ static bool Reflect_setPrototypeOf(JSCon
   ObjectOpResult result;
   if (!SetPrototype(cx, obj, proto, result)) {
     return false;
   }
   args.rval().setBoolean(result.reallyOk());
   return true;
 }
 
-static const JSFunctionSpec methods[] = {
+static const JSFunctionSpec reflect_methods[] = {
     JS_SELF_HOSTED_FN("apply", "Reflect_apply", 3, 0),
     JS_SELF_HOSTED_FN("construct", "Reflect_construct", 2, 0),
     JS_SELF_HOSTED_FN("defineProperty", "Reflect_defineProperty", 3, 0),
     JS_FN("deleteProperty", Reflect_deleteProperty, 2, 0),
     JS_SELF_HOSTED_FN("get", "Reflect_get", 2, 0),
     JS_SELF_HOSTED_FN("getOwnPropertyDescriptor",
                       "Reflect_getOwnPropertyDescriptor", 2, 0),
     JS_INLINABLE_FN("getPrototypeOf", Reflect_getPrototypeOf, 1, 0,
@@ -209,33 +209,22 @@ static const JSFunctionSpec methods[] = 
     JS_FN("ownKeys", Reflect_ownKeys, 1, 0),
     JS_FN("preventExtensions", Reflect_preventExtensions, 1, 0),
     JS_FN("set", Reflect_set, 3, 0),
     JS_FN("setPrototypeOf", Reflect_setPrototypeOf, 2, 0),
     JS_FS_END};
 
 /*** Setup ******************************************************************/
 
-JSObject* js::InitReflect(JSContext* cx, Handle<GlobalObject*> global) {
+static JSObject* CreateReflectObject(JSContext* cx, JSProtoKey key) {
+  Handle<GlobalObject*> global = cx->global();
   RootedObject proto(cx, GlobalObject::getOrCreateObjectPrototype(cx, global));
   if (!proto) {
     return nullptr;
   }
-
-  RootedObject reflect(
-      cx, NewObjectWithGivenProto<PlainObject>(cx, proto, SingletonObject));
-  if (!reflect) {
-    return nullptr;
-  }
-  if (!JS_DefineFunctions(cx, reflect, methods)) {
-    return nullptr;
-  }
+  return NewObjectWithGivenProto<PlainObject>(cx, proto, SingletonObject);
+}
 
-  RootedValue value(cx, ObjectValue(*reflect));
-  if (!DefineDataProperty(cx, global, cx->names().Reflect, value,
-                          JSPROP_RESOLVING)) {
-    return nullptr;
-  }
+static const ClassSpec ReflectClassSpec = {CreateReflectObject, nullptr,
+                                           reflect_methods, nullptr};
 
-  global->setConstructor(JSProto_Reflect, value);
-
-  return reflect;
-}
+const JSClass js::ReflectClass = {"Reflect", 0, JS_NULL_CLASS_OPS,
+                                  &ReflectClassSpec};
--- a/js/src/builtin/Reflect.h
+++ b/js/src/builtin/Reflect.h
@@ -6,19 +6,17 @@
 
 #ifndef builtin_Reflect_h
 #define builtin_Reflect_h
 
 #include "vm/JSObject.h"
 
 namespace js {
 
-class GlobalObject;
-
-extern JSObject* InitReflect(JSContext* cx, js::Handle<GlobalObject*> global);
+extern const JSClass ReflectClass;
 
 }  // namespace js
 
 namespace js {
 
 extern MOZ_MUST_USE bool Reflect_getPrototypeOf(JSContext* cx, unsigned argc,
                                                 Value* vp);
 
--- a/js/src/vm/GlobalObject.cpp
+++ b/js/src/vm/GlobalObject.cpp
@@ -1,8 +1,9 @@
+
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * vim: set ts=8 sts=2 et sw=2 tw=80:
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "vm/GlobalObject.h"
 
@@ -69,16 +70,17 @@ struct ProtoTableEntry {
   ClassInitializerOp init;
 };
 
 namespace js {
 
 extern const JSClass IntlClass;
 extern const JSClass JSONClass;
 extern const JSClass MathClass;
+extern const JSClass ReflectClass;
 extern const JSClass WebAssemblyClass;
 
 #define DECLARE_PROTOTYPE_CLASS_INIT(name, init, clasp) \
   extern JSObject* init(JSContext* cx, Handle<GlobalObject*> global);
 JS_FOR_EACH_PROTOTYPE(DECLARE_PROTOTYPE_CLASS_INIT)
 #undef DECLARE_PROTOTYPE_CLASS_INIT
 
 }  // namespace js