Bug 1271653 - Implement a C++ interface for global/allocationSite/errorMessageName;r=jimb
☠☠ backed out by a9f61337bdb5 ☠ ☠
authorEddy Bruel <ejpbruel@mozilla.com>
Tue, 07 Jun 2016 13:36:03 +0200
changeset 300886 080e7c18afed68cf75149dd80accdab319cf1622
parent 300885 448365b11e377ebf1c572d54e45bbd36c45af03a
child 300887 a9f61337bdb57783d199fa4923d13acb0818d0db
push id19599
push usercbook@mozilla.com
push dateWed, 08 Jun 2016 10:16:21 +0000
treeherderfx-team@81f4cc3f6f4c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimb
bugs1271653
milestone50.0a1
Bug 1271653 - Implement a C++ interface for global/allocationSite/errorMessageName;r=jimb
js/src/vm/Debugger.cpp
js/src/vm/Debugger.h
--- a/js/src/vm/Debugger.cpp
+++ b/js/src/vm/Debugger.cpp
@@ -8276,85 +8276,55 @@ DebuggerObject_getPromiseDependentPromis
     args.rval().setObject(*promises);
     return true;
 }
 #endif // SPIDERMONKEY_PROMISE
 
 static bool
 DebuggerObject_getGlobal(JSContext* cx, unsigned argc, Value* vp)
 {
-    THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, "get global", args, dbg, obj);
-
-    RootedValue v(cx, ObjectValue(obj->global()));
-    if (!dbg->wrapDebuggeeValue(cx, &v))
-        return false;
-    args.rval().set(v);
-    return true;
-}
-
-/* static */ SavedFrame*
-Debugger::getObjectAllocationSite(JSObject& obj)
-{
-    JSObject* metadata = GetAllocationMetadata(&obj);
-    if (!metadata)
-        return nullptr;
-
-    MOZ_ASSERT(!metadata->is<WrapperObject>());
-    return SavedFrame::isSavedFrameAndNotProto(*metadata)
-        ? &metadata->as<SavedFrame>()
-        : nullptr;
+    THIS_DEBUGOBJECT(cx, argc, vp, "get global", args, object)
+
+    RootedObject result(cx);
+    if (!DebuggerObject::global(cx, object, &result))
+        return false;
+
+    args.rval().setObject(*result);
+    return true;
 }
 
 static bool
 DebuggerObject_getAllocationSite(JSContext* cx, unsigned argc, Value* vp)
 {
-    THIS_DEBUGOBJECT_REFERENT(cx, argc, vp, "get allocationSite", args, obj);
-
-    RootedObject allocSite(cx, Debugger::getObjectAllocationSite(*obj));
-    if (!allocSite)
-        return null(args);
-    if (!cx->compartment()->wrap(cx, &allocSite))
-        return false;
-    args.rval().setObject(*allocSite);
+    THIS_DEBUGOBJECT(cx, argc, vp, "get allocationSite", args, object)
+
+    RootedObject result(cx);
+    if (!DebuggerObject::allocationSite(cx, object, &result))
+        return false;
+
+    args.rval().setObjectOrNull(result);
     return true;
 }
 
 // Returns the "name" field (see js.msg), which may be used as a unique
 // identifier, for any error object with a JSErrorReport or undefined
 // if the object has no JSErrorReport.
 static bool
 DebuggerObject_getErrorMessageName(JSContext *cx, unsigned argc, Value* vp)
 {
-    THIS_DEBUGOBJECT_REFERENT(cx, argc, vp, "get errorMessageName", args, referent);
-
-    JSObject* obj = referent;
-    if (IsCrossCompartmentWrapper(obj))
-        obj = CheckedUnwrap(obj);
-
-    if (!obj) {
-        JS_ReportError(cx, "Permission denied to access object");
-        return false;
-    }
-
-    JSErrorReport* report = nullptr;
-    if (obj->is<ErrorObject>())
-        report = obj->as<ErrorObject>().getErrorReport();
-
-    if (report) {
-        const JSErrorFormatString* efs = GetErrorMessage(nullptr, report->errorNumber);
-        if (efs) {
-            RootedString str(cx, JS_NewStringCopyZ(cx, efs->name));
-            if (!cx->compartment()->wrap(cx, &str))
-                return false;
-            args.rval().setString(str);
-            return true;
-        }
-    }
-
-    args.rval().setUndefined();
+    THIS_DEBUGOBJECT(cx, argc, vp, "get errorMessageName", args, object)
+
+    RootedString result(cx);
+    if (!DebuggerObject::errorMessageName(cx, object, &result))
+        return false;
+
+    if (result)
+        args.rval().setString(result);
+    else
+        args.rval().setUndefined();
     return true;
 }
 
 static bool
 DebuggerObject_isExtensible(JSContext* cx, unsigned argc, Value* vp)
 {
     THIS_DEBUGOBJECT(cx, argc, vp, "isExtensible", args, object)
 
@@ -8919,16 +8889,26 @@ DebuggerObject::className(JSContext* cx,
     if (!str)
         return false;
 
     result.set(str);
     return true;
 }
 
 /* static */ bool
+DebuggerObject::global(JSContext* cx, Handle<DebuggerObject*> object, MutableHandleObject result)
+{
+    RootedObject referent(cx, object->referent());
+    Debugger* dbg = object->owner();
+
+    result.set(&referent->global());
+    return dbg->wrapDebuggeeObject(cx, result);
+}
+
+/* static */ bool
 DebuggerObject::name(JSContext* cx, Handle<DebuggerObject*> object, MutableHandleString result)
 {
     MOZ_ASSERT(isFunction(cx, object));
 
     RootedFunction referent(cx, &object->referent()->as<JSFunction>());
 
     result.set(referent->name());
     return true;
@@ -9023,16 +9003,77 @@ DebuggerObject::boundArguments(JSContext
     for (size_t i = 0; i < length; i++) {
         result[i].set(referent->getBoundFunctionArgument(cx, i));
         if (!dbg->wrapDebuggeeValue(cx, result[i]))
             return false;
     }
     return true;
 }
 
+/* static */ SavedFrame*
+Debugger::getObjectAllocationSite(JSObject& obj)
+{
+    JSObject* metadata = GetAllocationMetadata(&obj);
+    if (!metadata)
+        return nullptr;
+
+    MOZ_ASSERT(!metadata->is<WrapperObject>());
+    return SavedFrame::isSavedFrameAndNotProto(*metadata)
+        ? &metadata->as<SavedFrame>()
+        : nullptr;
+}
+
+/* static */ bool
+DebuggerObject::allocationSite(JSContext* cx, Handle<DebuggerObject*> object,
+                               MutableHandleObject result)
+{
+    RootedObject referent(cx, object->referent());
+
+    RootedObject allocSite(cx, Debugger::getObjectAllocationSite(*referent));
+    if (!cx->compartment()->wrap(cx, &allocSite))
+        return false;
+
+    result.set(allocSite);
+    return true;
+}
+
+/* static */ bool
+DebuggerObject::errorMessageName(JSContext* cx, Handle<DebuggerObject*> object,
+                                 MutableHandleString result)
+{
+    RootedObject referent(cx, object->referent());
+
+    JSObject* obj = referent;
+    if (IsCrossCompartmentWrapper(obj))
+        obj = CheckedUnwrap(obj);
+
+    if (!obj) {
+        JS_ReportError(cx, "Permission denied to access object");
+        return false;
+    }
+
+    if (obj->is<ErrorObject>()) {
+        JSErrorReport* report = obj->as<ErrorObject>().getErrorReport();
+        if (report) {
+            const JSErrorFormatString* efs = GetErrorMessage(nullptr, report->errorNumber);
+            if (efs) {
+                RootedString str(cx, JS_NewStringCopyZ(cx, efs->name));
+                if (!cx->compartment()->wrap(cx, &str))
+                    return false;
+
+                result.set(str);
+                return true;
+            }
+        }
+    }
+
+    result.set(nullptr);
+    return true;
+}
+
 /* static */ bool
 DebuggerObject::isExtensible(JSContext* cx, Handle<DebuggerObject*> object, bool& result)
 {
     RootedObject referent(cx, object->referent());
 
     Maybe<AutoCompartment> ac;
     ac.emplace(cx, referent);
     ErrorCopier ec(ac);
--- a/js/src/vm/Debugger.h
+++ b/js/src/vm/Debugger.h
@@ -1054,28 +1054,33 @@ class DebuggerObject : public NativeObje
     static bool isCallable(JSContext* cx, Handle<DebuggerObject*> object);
     static bool isFunction(JSContext* cx, Handle<DebuggerObject*> object);
     static bool isDebuggeeFunction(JSContext* cx, Handle<DebuggerObject*> object);
     static bool isBoundFunction(JSContext* cx, Handle<DebuggerObject*> object);
     static bool isArrowFunction(JSContext* cx, Handle<DebuggerObject*> object);
     static bool isGlobal(JSContext* cx, Handle<DebuggerObject*> object);
     static bool className(JSContext* cx, Handle<DebuggerObject*> object,
                           MutableHandleString result);
+    static bool global(JSContext* cx, Handle<DebuggerObject*> object, MutableHandleObject result);
     static bool name(JSContext* cx, Handle<DebuggerObject*> object, MutableHandleString result);
     static bool displayName(JSContext* cx, Handle<DebuggerObject*> object,
                             MutableHandleString result);
 
     static bool parameterNames(JSContext* cx, Handle<DebuggerObject*> object,
                                MutableHandle<StringVector> result);
     static bool boundTargetFunction(JSContext* cx, Handle<DebuggerObject*> object,
                                     MutableHandleObject result);
     static bool boundThis(JSContext* cx, Handle<DebuggerObject*> object,
                           MutableHandleValue result);
     static bool boundArguments(JSContext* cx, Handle<DebuggerObject*> object,
                                MutableHandle<ValueVector> result);
+    static bool allocationSite(JSContext* cx, Handle<DebuggerObject*> object,
+                               MutableHandleObject result);
+    static bool errorMessageName(JSContext* cx, Handle<DebuggerObject*> object,
+                                 MutableHandleString result);
 
     static bool isExtensible(JSContext* cx, Handle<DebuggerObject*> object, bool& result);
     static bool isSealed(JSContext* cx, Handle<DebuggerObject*> object, bool& result);
     static bool isFrozen(JSContext* cx, Handle<DebuggerObject*> object, bool& result);
     static bool getPrototypeOf(JSContext* cx, Handle<DebuggerObject*> object,
                                MutableHandleObject result);
     static bool getOwnPropertyNames(JSContext* cx, Handle<DebuggerObject*> object,
                                     MutableHandle<IdVector> result);