Add Debug.Object.prototype.callable.
authorJason Orendorff <jorendorff@mozilla.com>
Wed, 11 May 2011 15:15:50 -0500
changeset 74804 ddab2f5eb8df82b549b4c94c925569c9f3b57c0f
parent 74803 453701d5c7e7000b2f3ac3f58ce967ddbfe600d2
child 74805 5842d0285cdafaa4ae329214f0b46953d0c3d5e7
push idunknown
push userunknown
push dateunknown
milestone6.0a1
Add Debug.Object.prototype.callable.
js/src/jit-test/tests/debug/Object-callable.js
js/src/jsdbg.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/debug/Object-callable.js
@@ -0,0 +1,23 @@
+// |jit-test| debug
+// Test Debug.Object.prototype.callable.
+
+var g = newGlobal('new-compartment');
+var dbg = new Debug(g);
+var hits = 0;
+dbg.hooks = {
+    debuggerHandler: function (frame) {
+        assertEq(frame.arguments[0].callable, frame.arguments[1]);
+        hits++;
+    }
+};
+
+g.eval("function f(obj, iscallable) { debugger; }");
+
+g.eval("f({}, false);");
+g.eval("f(Function.prototype, true);");
+g.eval("f(f, true);");
+g.eval("f(Proxy.create({}), false);");
+g.eval("f(Proxy.createFunction(f, f), true);");
+g.f({}, false);
+g.f(Function.prototype, true);
+assertEq(hits, 7);
--- a/js/src/jsdbg.cpp
+++ b/js/src/jsdbg.cpp
@@ -949,16 +949,24 @@ DebugObject_getClass(JSContext *cx, uint
     JSAtom *str = js_Atomize(cx, s, strlen(s), 0);
     if (!str)
         return false;
     vp->setString(str);
     return true;
 }
 
 static JSBool
+DebugObject_getCallable(JSContext *cx, uintN argc, Value *vp)
+{
+    THIS_DEBUGOBJECT_REFERENT(cx, vp, "get callable", refobj);
+    vp->setBoolean(refobj->isCallable());
+    return true;
+}
+
+static JSBool
 DebugObject_getName(JSContext *cx, uintN argc, Value *vp)
 {
     THIS_DEBUGOBJECT_REFERENT(cx, vp, "get name", obj);
     if (obj->isFunction()) {
         if (JSString *name = obj->getFunctionPrivate()->atom) {
             vp->setString(name);
             return Debug::fromChildJSObject(&vp[1].toObject())->wrapDebuggeeValue(cx, vp);
         }
@@ -1022,16 +1030,17 @@ DebugObject_apply(JSContext *cx, uintN a
     Value rval;
     bool ok = ExternalInvoke(cx, thisv, calleev, argv.length(), argv.begin(), &rval);
     return dbg->newCompletionValue(ac, ok, rval, vp);
 }
 
 static JSPropertySpec DebugObject_properties[] = {
     JS_PSG("proto", DebugObject_getProto, 0),
     JS_PSG("class", DebugObject_getClass, 0),
+    JS_PSG("callable", DebugObject_getCallable, 0),
     JS_PSG("name", DebugObject_getName, 0),
     JS_PS_END
 };
 
 static JSFunctionSpec DebugObject_methods[] = {
     JS_FN("apply", DebugObject_apply, 0, 0),
     JS_FS_END
 };