Bug 1264377. Get rid of some unnecessary custom JSClass hook functions in xpconnect sandboxes and DOM simple globals. r=bholley
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 14 Apr 2016 14:54:01 -0400
changeset 351777 7dd74bf4952716714a380d4f37215fea3c4c2d5c
parent 351776 77d53bf103a26592944ae70cd45a80f0204cd4b9
child 351778 b6ab9982be5af1c6e5c3d68288880cd105cc6209
push id15527
push userbmo:rail@mozilla.com
push dateFri, 15 Apr 2016 01:44:41 +0000
reviewersbholley
bugs1264377
milestone48.0a1
Bug 1264377. Get rid of some unnecessary custom JSClass hook functions in xpconnect sandboxes and DOM simple globals. r=bholley
dom/bindings/SimpleGlobalObject.cpp
js/xpconnect/src/Sandbox.cpp
--- a/dom/bindings/SimpleGlobalObject.cpp
+++ b/dom/bindings/SimpleGlobalObject.cpp
@@ -36,29 +36,16 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCA
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(SimpleGlobalObject)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(SimpleGlobalObject)
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SimpleGlobalObject)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsIGlobalObject)
 NS_INTERFACE_MAP_END
 
-static bool
-SimpleGlobal_enumerate(JSContext *cx, JS::Handle<JSObject *> obj)
-{
-  return JS_EnumerateStandardClasses(cx, obj);
-}
-
-static bool
-SimpleGlobal_resolve(JSContext *cx, JS::Handle<JSObject *> obj,
-                    JS::Handle<jsid> id, bool *resolvedp)
-{
-  return JS_ResolveStandardClass(cx, obj, id, resolvedp);
-}
-
 static void
 SimpleGlobal_finalize(js::FreeOp *fop, JSObject *obj)
 {
   SimpleGlobalObject* globalObject =
     static_cast<SimpleGlobalObject*>(JS_GetPrivate(obj));
   NS_RELEASE(globalObject);
 }
 
@@ -70,19 +57,19 @@ SimpleGlobal_moved(JSObject *obj, const 
   globalObject->UpdateWrapper(obj, old);
 }
 
 static const js::ClassOps SimpleGlobalClassOps = {
     nullptr,
     nullptr,
     nullptr,
     nullptr,
-    SimpleGlobal_enumerate,
-    SimpleGlobal_resolve,
-    nullptr,
+    JS_EnumerateStandardClasses,
+    JS_ResolveStandardClass,
+    JS_MayResolveStandardClass,
     SimpleGlobal_finalize,
     nullptr,
     nullptr,
     nullptr,
     JS_GlobalObjectTraceHook,
 };
 
 static const js::ClassExtension SimpleGlobalClassExtension = {
--- a/js/xpconnect/src/Sandbox.cpp
+++ b/js/xpconnect/src/Sandbox.cpp
@@ -394,28 +394,16 @@ SandboxCloneInto(JSContext* cx, unsigned
         JS_ReportError(cx, "Function requires at least 2 arguments");
         return false;
     }
 
     RootedValue options(cx, args.length() > 2 ? args[2] : UndefinedValue());
     return xpc::CloneInto(cx, args[0], args[1], options, args.rval());
 }
 
-static bool
-sandbox_enumerate(JSContext* cx, HandleObject obj)
-{
-    return JS_EnumerateStandardClasses(cx, obj);
-}
-
-static bool
-sandbox_resolve(JSContext* cx, HandleObject obj, HandleId id, bool* resolvedp)
-{
-    return JS_ResolveStandardClass(cx, obj, id, resolvedp);
-}
-
 static void
 sandbox_finalize(js::FreeOp* fop, JSObject* obj)
 {
     nsIScriptObjectPrincipal* sop =
         static_cast<nsIScriptObjectPrincipal*>(xpc_GetJSPrivate(obj));
     if (!sop) {
         // sop can be null if CreateSandboxObject fails in the middle.
         return;
@@ -485,19 +473,19 @@ struct AutoSkipPropertyMirroring
 // add-ons in a separate compartment while still giving them access to the
 // chrome window.
 static bool
 sandbox_addProperty(JSContext* cx, HandleObject obj, HandleId id, HandleValue v)
 {
     CompartmentPrivate* priv = CompartmentPrivate::Get(obj);
     MOZ_ASSERT(priv->writeToGlobalPrototype);
 
-    // Whenever JS_EnumerateStandardClasses is called (by sandbox_enumerate for
-    // example), it defines the "undefined" property, even if it's already
-    // defined. We don't want to do anything in that case.
+    // Whenever JS_EnumerateStandardClasses is called, it defines the
+    // "undefined" property, even if it's already defined. We don't want to do
+    // anything in that case.
     if (id == XPCJSRuntime::Get()->GetStringID(XPCJSRuntime::IDX_UNDEFINED))
         return true;
 
     // Avoid recursively triggering sandbox_addProperty in the
     // JS_DefinePropertyById call below.
     if (priv->skipWriteToGlobalPrototype)
         return true;
 
@@ -547,18 +535,18 @@ sandbox_addProperty(JSContext* cx, Handl
 
     return true;
 }
 
 #define XPCONNECT_SANDBOX_CLASS_METADATA_SLOT (XPCONNECT_GLOBAL_EXTRA_SLOT_OFFSET)
 
 static const js::ClassOps SandboxClassOps = {
     nullptr, nullptr, nullptr, nullptr,
-    sandbox_enumerate, sandbox_resolve,
-    nullptr,        /* mayResolve */
+    JS_EnumerateStandardClasses, JS_ResolveStandardClass,
+    JS_MayResolveStandardClass,
     sandbox_finalize,
     nullptr, nullptr, nullptr, JS_GlobalObjectTraceHook,
 };
 
 static const js::ClassExtension SandboxClassExtension = {
     nullptr,      /* weakmapKeyDelegateOp */
     sandbox_moved /* objectMovedOp */
 };
@@ -571,18 +559,18 @@ static const js::Class SandboxClass = {
     &SandboxClassExtension,
     JS_NULL_OBJECT_OPS
 };
 
 // Note to whomever comes here to remove addProperty hooks: billm has promised
 // to do the work for this class.
 static const js::ClassOps SandboxWriteToProtoClassOps = {
     sandbox_addProperty, nullptr, nullptr, nullptr,
-    sandbox_enumerate, sandbox_resolve,
-    nullptr,        /* mayResolve */
+    JS_EnumerateStandardClasses, JS_ResolveStandardClass,
+    JS_MayResolveStandardClass,
     sandbox_finalize,
     nullptr, nullptr, nullptr, JS_GlobalObjectTraceHook,
 };
 
 static const js::Class SandboxWriteToProtoClass = {
     "Sandbox",
     XPCONNECT_GLOBAL_FLAGS_WITH_EXTRA_SLOTS(1),
     &SandboxWriteToProtoClassOps,