Bug 1573844 - Remove js::Jsvalify and js::Valueify r=tcampbell
authorJon Coppeard <jcoppeard@mozilla.com>
Wed, 14 Aug 2019 17:18:54 +0000
changeset 488203 3c8af6860ce4722fc04ff6808799a1c75a49147d
parent 488202 7ecc384e1afe190ae13ef6fce9aaaadb0971ebea
child 488204 d8a479850f5903711dba26c4cbd9631baea8f844
push id113904
push userncsoregi@mozilla.com
push dateThu, 15 Aug 2019 19:41:00 +0000
treeherdermozilla-inbound@b283a7ef186c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstcampbell
bugs1573844
milestone70.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 1573844 - Remove js::Jsvalify and js::Valueify r=tcampbell Depends on D41984 Differential Revision: https://phabricator.services.mozilla.com/D41985
js/public/Class.h
js/rust/src/jsglue.cpp
js/src/builtin/TestingFunctions.cpp
js/src/jsapi-tests/testWeakMap.cpp
js/src/jsapi-tests/testWindowNonConfigurable.cpp
js/src/jsapi.cpp
js/src/jsfriendapi.cpp
js/src/jsfriendapi.h
js/src/shell/js.cpp
js/src/vm/JSObject.h
--- a/js/public/Class.h
+++ b/js/public/Class.h
@@ -941,24 +941,16 @@ struct JSClass {
 
 // Initializer for unused members of statically initialized JSClass structs.
 #define JSCLASS_NO_INTERNAL_MEMBERS \
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
 #define JSCLASS_NO_OPTIONAL_MEMBERS 0, 0, 0, 0, 0, JSCLASS_NO_INTERNAL_MEMBERS
 
 namespace js {
 
-static MOZ_ALWAYS_INLINE const JSClass* Jsvalify(const Class* c) {
-  return (const JSClass*)c;
-}
-
-static MOZ_ALWAYS_INLINE const Class* Valueify(const JSClass* c) {
-  return (const Class*)c;
-}
-
 /**
  * Enumeration describing possible values of the [[Class]] internal property
  * value of objects.
  */
 enum class ESClass {
   Object,
   Array,
   Number,
@@ -985,13 +977,9 @@ enum class ESClass {
 bool Unbox(JSContext* cx, JS::HandleObject obj, JS::MutableHandleValue vp);
 
 #ifdef DEBUG
 JS_FRIEND_API bool HasObjectMovedOp(JSObject* obj);
 #endif
 
 } /* namespace js */
 
-// Alias these into global scope for now.
-using js::Jsvalify;
-using js::Valueify;
-
 #endif /* js_Class_h */
--- a/js/rust/src/jsglue.cpp
+++ b/js/rust/src/jsglue.cpp
@@ -451,17 +451,17 @@ JSObject* NewProxyObject(JSContext* aCx,
                             options);
 }
 
 JSObject* WrapperNew(JSContext* aCx, JS::HandleObject aObj,
                      const void* aHandler, const JSClass* aClass,
                      bool aSingleton) {
   js::WrapperOptions options;
   if (aClass) {
-    options.setClass(js::Valueify(aClass));
+    options.setClass(aClass);
   }
   options.setSingleton(aSingleton);
   return js::Wrapper::New(aCx, aObj, (const js::Wrapper*)aHandler, options);
 }
 
 const js::Class WindowProxyClass = PROXY_CLASS_DEF(
     "Proxy", JSCLASS_HAS_RESERVED_SLOTS(1)); /* additional class flags */
 
@@ -472,17 +472,17 @@ JS::Value GetProxyReservedSlot(JSObject*
 }
 
 void SetProxyReservedSlot(JSObject* obj, uint32_t slot, const JS::Value* val) {
   js::SetProxyReservedSlot(obj, slot, *val);
 }
 
 JSObject* NewWindowProxy(JSContext* aCx, JS::HandleObject aObj,
                          const void* aHandler) {
-  return WrapperNew(aCx, aObj, aHandler, Jsvalify(&WindowProxyClass), true);
+  return WrapperNew(aCx, aObj, aHandler, &WindowProxyClass, true);
 }
 
 JS::Value GetProxyPrivate(JSObject* obj) { return js::GetProxyPrivate(obj); }
 
 void SetProxyPrivate(JSObject* obj, const JS::Value* expando) {
   js::SetProxyPrivate(obj, *expando);
 }
 
--- a/js/src/builtin/TestingFunctions.cpp
+++ b/js/src/builtin/TestingFunctions.cpp
@@ -2935,17 +2935,17 @@ class CloneBufferObject : public NativeO
   static const size_t DATA_SLOT = 0;
   static const size_t SYNTHETIC_SLOT = 1;
   static const size_t NUM_SLOTS = 2;
 
  public:
   static const Class class_;
 
   static CloneBufferObject* Create(JSContext* cx) {
-    RootedObject obj(cx, JS_NewObject(cx, Jsvalify(&class_)));
+    RootedObject obj(cx, JS_NewObject(cx, &class_));
     if (!obj) {
       return nullptr;
     }
     obj->as<CloneBufferObject>().setReservedSlot(DATA_SLOT,
                                                  PrivateValue(nullptr));
     obj->as<CloneBufferObject>().setReservedSlot(SYNTHETIC_SLOT,
                                                  BooleanValue(false));
 
--- a/js/src/jsapi-tests/testWeakMap.cpp
+++ b/js/src/jsapi-tests/testWeakMap.cpp
@@ -150,17 +150,17 @@ static size_t DelegateObjectMoved(JSObje
 }
 
 JSObject* newKey() {
   static const js::Class keyClass = {
       "keyWithDelegate", JSCLASS_HAS_PRIVATE | JSCLASS_HAS_RESERVED_SLOTS(1),
       JS_NULL_CLASS_OPS, JS_NULL_CLASS_SPEC,
       JS_NULL_CLASS_EXT, JS_NULL_OBJECT_OPS};
 
-  JS::RootedObject key(cx, JS_NewObject(cx, Jsvalify(&keyClass)));
+  JS::RootedObject key(cx, JS_NewObject(cx, &keyClass));
   if (!key) {
     return nullptr;
   }
 
   return key;
 }
 
 JSObject* newCCW(JS::HandleObject sourceZone, JS::HandleObject destZone) {
@@ -214,19 +214,19 @@ JSObject* newDelegate() {
       JSCLASS_GLOBAL_FLAGS | JSCLASS_HAS_RESERVED_SLOTS(1),
       &delegateClassOps,
       JS_NULL_CLASS_SPEC,
       &delegateClassExtension,
       JS_NULL_OBJECT_OPS};
 
   /* Create the global object. */
   JS::RealmOptions options;
-  JS::RootedObject global(
-      cx, JS_NewGlobalObject(cx, Jsvalify(&delegateClass), nullptr,
-                             JS::FireOnNewGlobalHook, options));
+  JS::RootedObject global(cx,
+                          JS_NewGlobalObject(cx, &delegateClass, nullptr,
+                                             JS::FireOnNewGlobalHook, options));
   if (!global) {
     return nullptr;
   }
 
   JS_SetReservedSlot(global, 0, JS::Int32Value(42));
   return global;
 }
 
--- a/js/src/jsapi-tests/testWindowNonConfigurable.cpp
+++ b/js/src/jsapi-tests/testWindowNonConfigurable.cpp
@@ -21,17 +21,17 @@ static bool windowProxy_defineProperty(J
 
 static const js::ObjectOps windowProxy_objectOps = {nullptr,
                                                     windowProxy_defineProperty};
 
 static const js::Class windowProxy_class = {
     "WindowProxy", 0, nullptr, nullptr, nullptr, &windowProxy_objectOps};
 
 BEGIN_TEST(testWindowNonConfigurable) {
-  JS::RootedObject obj(cx, JS_NewObject(cx, Jsvalify(&windowProxy_class)));
+  JS::RootedObject obj(cx, JS_NewObject(cx, &windowProxy_class));
   CHECK(obj);
   CHECK(JS_DefineProperty(cx, global, "windowProxy", obj, 0));
   JS::RootedValue v(cx);
   EVAL(
       "Object.defineProperty(windowProxy, 'bar', {value: 1, configurable: "
       "false})",
       &v);
   CHECK(v.isNull());  // This is the important bit!
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -1565,43 +1565,43 @@ JS_PUBLIC_API JSObject* JS_InitClass(JSC
                                      const JSClass* clasp, JSNative constructor,
                                      unsigned nargs, const JSPropertySpec* ps,
                                      const JSFunctionSpec* fs,
                                      const JSPropertySpec* static_ps,
                                      const JSFunctionSpec* static_fs) {
   AssertHeapIsIdle();
   CHECK_THREAD(cx);
   cx->check(obj, parent_proto);
-  return InitClass(cx, obj, parent_proto, Valueify(clasp), constructor, nargs,
-                   ps, fs, static_ps, static_fs);
+  return InitClass(cx, obj, parent_proto, clasp, constructor, nargs, ps, fs,
+                   static_ps, static_fs);
 }
 
 JS_PUBLIC_API bool JS_LinkConstructorAndPrototype(JSContext* cx,
                                                   HandleObject ctor,
                                                   HandleObject proto) {
   return LinkConstructorAndPrototype(cx, ctor, proto);
 }
 
 JS_PUBLIC_API const JSClass* JS_GetClass(JSObject* obj) {
-  return obj->getJSClass();
+  return obj->getClass();
 }
 
 JS_PUBLIC_API bool JS_InstanceOf(JSContext* cx, HandleObject obj,
                                  const JSClass* clasp, CallArgs* args) {
   AssertHeapIsIdle();
   CHECK_THREAD(cx);
 #ifdef DEBUG
   if (args) {
     cx->check(obj);
     cx->check(args->thisv(), args->calleev());
   }
 #endif
-  if (!obj || obj->getJSClass() != clasp) {
+  if (!obj || obj->getClass() != clasp) {
     if (args) {
-      ReportIncompatibleMethod(cx, *args, Valueify(clasp));
+      ReportIncompatibleMethod(cx, *args, clasp);
     }
     return false;
   }
   return true;
 }
 
 JS_PUBLIC_API bool JS_HasInstance(JSContext* cx, HandleObject obj,
                                   HandleValue value, bool* bp) {
@@ -1716,18 +1716,17 @@ JS_PUBLIC_API JSObject* JS_NewGlobalObje
                                            const JS::RealmOptions& options) {
   MOZ_RELEASE_ASSERT(
       cx->runtime()->hasInitializedSelfHosting(),
       "Must call JS::InitSelfHostedCode() before creating a global");
 
   AssertHeapIsIdle();
   CHECK_THREAD(cx);
 
-  return GlobalObject::new_(cx, Valueify(clasp), principals, hookOption,
-                            options);
+  return GlobalObject::new_(cx, clasp, principals, hookOption, options);
 }
 
 JS_PUBLIC_API void JS_GlobalObjectTraceHook(JSTracer* trc, JSObject* global) {
   GlobalObject* globalObj = &global->as<GlobalObject>();
   Realm* globalRealm = globalObj->realm();
 
   // Off thread parsing and compilation tasks create a dummy global which is
   // then merged back into the host realm. Since it used to be a global, it
@@ -1769,41 +1768,39 @@ JS_PUBLIC_API void JS_FireOnNewGlobalObj
   // This infallibility will eat OOM and slow script, but if that happens
   // we'll likely run up into them again soon in a fallible context.
   cx->check(global);
   Rooted<js::GlobalObject*> globalObject(cx, &global->as<GlobalObject>());
   DebugAPI::onNewGlobalObject(cx, globalObject);
   cx->runtime()->ensureRealmIsRecordingAllocations(globalObject);
 }
 
-JS_PUBLIC_API JSObject* JS_NewObject(JSContext* cx, const JSClass* jsclasp) {
+JS_PUBLIC_API JSObject* JS_NewObject(JSContext* cx, const JSClass* clasp) {
   MOZ_ASSERT(!cx->zone()->isAtomsZone());
   AssertHeapIsIdle();
   CHECK_THREAD(cx);
 
-  const Class* clasp = Valueify(jsclasp);
   if (!clasp) {
     clasp = &PlainObject::class_; /* default class is Object */
   }
 
   MOZ_ASSERT(clasp != &JSFunction::class_);
   MOZ_ASSERT(!(clasp->flags & JSCLASS_IS_GLOBAL));
 
   return NewBuiltinClassInstance(cx, clasp);
 }
 
 JS_PUBLIC_API JSObject* JS_NewObjectWithGivenProto(JSContext* cx,
-                                                   const JSClass* jsclasp,
+                                                   const JSClass* clasp,
                                                    HandleObject proto) {
   MOZ_ASSERT(!cx->zone()->isAtomsZone());
   AssertHeapIsIdle();
   CHECK_THREAD(cx);
   cx->check(proto);
 
-  const Class* clasp = Valueify(jsclasp);
   if (!clasp) {
     clasp = &PlainObject::class_; /* default class is Object */
   }
 
   MOZ_ASSERT(clasp != &JSFunction::class_);
   MOZ_ASSERT(!(clasp->flags & JSCLASS_IS_GLOBAL));
 
   return NewObjectWithGivenProto(cx, clasp, proto);
@@ -1824,17 +1821,17 @@ JS_PUBLIC_API JSObject* JS_NewObjectForC
   CHECK_THREAD(cx);
 
   if (!ThrowIfNotConstructing(cx, args, clasp->name)) {
     return nullptr;
   }
 
   RootedObject newTarget(cx, &args.newTarget().toObject());
   cx->check(newTarget);
-  return CreateThis(cx, Valueify(clasp), newTarget);
+  return CreateThis(cx, clasp, newTarget);
 }
 
 JS_PUBLIC_API bool JS_IsNative(JSObject* obj) { return obj->isNative(); }
 
 JS_PUBLIC_API void JS::AssertObjectBelongsToCurrentThread(JSObject* obj) {
   JSRuntime* rt = obj->compartment()->runtimeFromAnyThread();
   MOZ_RELEASE_ASSERT(CurrentThreadCanAccessRuntime(rt));
 }
@@ -2917,24 +2914,22 @@ static bool DefineSelfHostedProperty(JSC
                setterValue.toObject().is<JSFunction>());
     setterFunc = &setterValue.toObject().as<JSFunction>();
   }
 
   return DefineAccessorPropertyById(cx, obj, id, getterFunc, setterFunc, attrs);
 }
 
 JS_PUBLIC_API JSObject* JS_DefineObject(JSContext* cx, HandleObject obj,
-                                        const char* name,
-                                        const JSClass* jsclasp,
+                                        const char* name, const JSClass* clasp,
                                         unsigned attrs) {
   AssertHeapIsIdle();
   CHECK_THREAD(cx);
   cx->check(obj);
 
-  const Class* clasp = Valueify(jsclasp);
   if (!clasp) {
     clasp = &PlainObject::class_; /* default class is Object */
   }
 
   RootedObject nobj(cx, NewBuiltinClassInstance(cx, clasp));
   if (!nobj) {
     return nullptr;
   }
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -116,18 +116,18 @@ JS_FRIEND_API JSObject* JS_NewObjectWith
                                                    const JSClass* clasp,
                                                    HandleObject proto) {
   /*
    * Create our object with a null proto and then splice in the correct proto
    * after we setSingleton, so that we don't pollute the default
    * ObjectGroup attached to our proto with information about our object, since
    * we're not going to be using that ObjectGroup anyway.
    */
-  RootedObject obj(cx, NewObjectWithGivenProto(cx, Valueify(clasp), nullptr,
-                                               SingletonObject));
+  RootedObject obj(
+      cx, NewObjectWithGivenProto(cx, clasp, nullptr, SingletonObject));
   if (!obj) {
     return nullptr;
   }
   if (!JS_SplicePrototype(cx, obj, proto)) {
     return nullptr;
   }
   return obj;
 }
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -599,24 +599,20 @@ struct Function {
 };
 
 } /* namespace shadow */
 
 // This is equal to |&JSObject::class_|.  Use it in places where you don't want
 // to #include vm/JSObject.h.
 extern JS_FRIEND_DATA const js::Class* const ObjectClassPtr;
 
-inline const js::Class* GetObjectClass(const JSObject* obj) {
+inline const JSClass* GetObjectClass(const JSObject* obj) {
   return reinterpret_cast<const shadow::Object*>(obj)->group->clasp;
 }
 
-inline const JSClass* GetObjectJSClass(JSObject* obj) {
-  return js::Jsvalify(GetObjectClass(obj));
-}
-
 JS_FRIEND_API const Class* ProtoKeyToClass(JSProtoKey key);
 
 // Returns the key for the class inherited by a given standard class (that
 // is to say, the prototype of this standard class's prototype).
 //
 // You must be sure that this corresponds to a standard class with a cached
 // JSProtoKey before calling this function. In general |key| will match the
 // cached proto key, except in cases where multiple JSProtoKeys share a
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -2836,18 +2836,17 @@ static JSScript* GetTopScript(JSContext*
 
 static bool GetScriptAndPCArgs(JSContext* cx, CallArgs& args,
                                MutableHandleScript scriptp, int32_t* ip) {
   RootedScript script(cx, GetTopScript(cx));
   *ip = 0;
   if (!args.get(0).isUndefined()) {
     HandleValue v = args[0];
     unsigned intarg = 0;
-    if (v.isObject() &&
-        JS_GetClass(&v.toObject()) == Jsvalify(&JSFunction::class_)) {
+    if (v.isObject() && JS_GetClass(&v.toObject()) == &JSFunction::class_) {
       script = TestingFunctionArgumentToScript(cx, v);
       if (!script) {
         return false;
       }
       intarg++;
     }
     if (!args.get(intarg).isUndefined()) {
       if (!JS::ToInt32(cx, args[intarg], ip)) {
@@ -8321,18 +8320,18 @@ static bool TransplantableObject(JSConte
                    "Live objects should be tenured after one GC, because "
                    "the nursery has only a single generation");
       }
     }
   }
 
   if (!source) {
     if (!createProxy) {
-      source = NewBuiltinClassInstance(
-          cx, Valueify(&TransplantableDOMObjectClass), TenuredObject);
+      source = NewBuiltinClassInstance(cx, &TransplantableDOMObjectClass,
+                                       TenuredObject);
       if (!source) {
         return false;
       }
 
       SetReservedSlot(source, DOM_OBJECT_SLOT, JS::PrivateValue(nullptr));
     } else {
       JSObject* expando = JS_NewPlainObject(cx);
       if (!expando) {
@@ -9781,17 +9780,17 @@ static bool dom_genericMethod(JSContext*
 
 static void InitDOMObject(HandleObject obj) {
   SetReservedSlot(obj, DOM_OBJECT_SLOT,
                   PrivateValue(const_cast<void*>(DOM_PRIVATE_VALUE)));
 }
 
 static JSObject* GetDOMPrototype(JSContext* cx, JSObject* global) {
   MOZ_ASSERT(JS_IsGlobalObject(global));
-  if (GetObjectJSClass(global) != &global_class) {
+  if (GetObjectClass(global) != &global_class) {
     JS_ReportErrorASCII(cx, "Can't get FakeDOMObject prototype in sandbox");
     return nullptr;
   }
   MOZ_ASSERT(GetReservedSlot(global, DOM_PROTOTYPE_SLOT).isObject());
   return &GetReservedSlot(global, DOM_PROTOTYPE_SLOT).toObject();
 }
 
 static bool dom_constructor(JSContext* cx, unsigned argc, JS::Value* vp) {
@@ -9819,17 +9818,17 @@ static bool dom_constructor(JSContext* c
 
   args.rval().setObject(*domObj);
   return true;
 }
 
 static bool InstanceClassHasProtoAtDepth(const Class* clasp, uint32_t protoID,
                                          uint32_t depth) {
   // Only the (fake) DOM object supports any JIT optimizations.
-  return clasp == Valueify(GetDomClass());
+  return clasp == GetDomClass();
 }
 
 static bool ShellBuildId(JS::BuildIdCharVector* buildId) {
   // The browser embeds the date into the buildid and the buildid is embedded
   // in the binary, so every 'make' necessarily builds a new firefox binary.
   // Fortunately, the actual firefox executable is tiny -- all the code is in
   // libxul.so and other shared modules -- so this isn't a big deal. Not so
   // for the statically-linked JS shell. To avoid recompiling js.cpp and
--- a/js/src/vm/JSObject.h
+++ b/js/src/vm/JSObject.h
@@ -98,19 +98,18 @@ class JSObject : public js::gc::Cell {
                                         bool* succeeded);
 
   // Make a new group to use for a singleton object.
   static js::ObjectGroup* makeLazyGroup(JSContext* cx, js::HandleObject obj);
 
  public:
   bool isNative() const { return getClass()->isNative(); }
 
-  const js::Class* getClass() const { return group_->clasp(); }
-  const JSClass* getJSClass() const { return Jsvalify(getClass()); }
-  bool hasClass(const js::Class* c) const { return getClass() == c; }
+  const JSClass* getClass() const { return group_->clasp(); }
+  bool hasClass(const JSClass* c) const { return getClass() == c; }
 
   js::LookupPropertyOp getOpsLookupProperty() const {
     return getClass()->getOpsLookupProperty();
   }
   js::DefinePropertyOp getOpsDefineProperty() const {
     return getClass()->getOpsDefineProperty();
   }
   js::HasPropertyOp getOpsHasProperty() const {