Add Debug.Object.prototype.getPrototype.
authorJason Orendorff <jorendorff@mozilla.com>
Fri, 06 May 2011 12:40:56 -0500
changeset 74416 52446c5ddd225c2917b21f0898cc79b38241927e
parent 74415 930f17ad5ff1800a545d307b0d5c611950f821a3
child 74417 903f198d10ee01f7de2a0451db1fbbc2dafae84d
push id2
push userbsmedberg@mozilla.com
push dateFri, 19 Aug 2011 14:38:13 +0000
milestone6.0a1
Add Debug.Object.prototype.getPrototype.
js/src/jit-test/tests/debug/Object-getPrototype.js
js/src/jsdbg.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/debug/Object-getPrototype.js
@@ -0,0 +1,23 @@
+// |jit-test| debug
+var g = newGlobal('new-compartment');
+var dbgeval = function () {
+        var dbg = new Debug(g);
+        var hits = 0;
+        g.eval("function f() { debugger; }");
+        var lastval;
+        dbg.hooks = {debuggerHandler: function (frame) { lastval = frame.arguments[0]; }};
+        return function dbgeval(s) {
+            g.eval("f(" + s + ");");
+            return lastval;
+        };
+    }();
+
+var Op = dbgeval("Object.prototype");
+assertEq(Op.getPrototype(), null);
+assertEq(dbgeval("({})").getPrototype(), Op);
+
+var Ap = dbgeval("[]").getPrototype();
+assertEq(Ap, dbgeval("Array.prototype"));
+assertEq(Ap.getPrototype(), Op);
+
+assertEq(dbgeval("Object").getPrototype(), dbgeval("Function.prototype"));
--- a/js/src/jsdbg.cpp
+++ b/js/src/jsdbg.cpp
@@ -898,16 +898,24 @@ DebugObject_checkThis(JSContext *cx, Val
 static JSBool
 DebugObject_construct(JSContext *cx, uintN argc, Value *vp)
 {
     JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_NO_CONSTRUCTOR, "Debug.Object");
     return false;
 }
 
 static JSBool
+DebugObject_getPrototype(JSContext *cx, uintN argc, Value *vp)
+{
+    THIS_DEBUGOBJECT_REFERENT(cx, vp, "getClass", refobj);
+    vp->setObjectOrNull(refobj->getProto());
+    return Debug::fromChildJSObject(&vp[1].toObject())->wrapDebuggeeValue(cx, vp);
+}
+
+static JSBool
 DebugObject_getClass(JSContext *cx, uintN argc, Value *vp)
 {
     THIS_DEBUGOBJECT_REFERENT(cx, vp, "getClass", refobj);
     const char *s = refobj->clasp->name;
     JSAtom *str = js_Atomize(cx, s, strlen(s), 0);
     if (!str)
         return false;
     vp->setString(str);
@@ -986,16 +994,17 @@ DebugObject_apply(JSContext *cx, uintN a
 }
 
 static JSPropertySpec DebugObject_properties[] = {
     JS_PSG("name", DebugObject_getName, 0),
     JS_PS_END
 };
 
 static JSFunctionSpec DebugObject_methods[] = {
+    JS_FN("getPrototype", DebugObject_getPrototype, 0, 0),
     JS_FN("getClass", DebugObject_getClass, 0, 0),
     JS_FN("apply", DebugObject_apply, 0, 0),
     JS_FS_END
 };
 
 // === Glue
 
 extern JS_PUBLIC_API(JSBool)