Bug 1074994: Implement Debugger.Object.prototype.isArrowFunction. r=sfink
authorJim Blandy <jimb@mozilla.com>
Thu, 02 Oct 2014 10:44:25 +0100
changeset 231590 9f9bbf84c3e8174278336e322643a4fc697e45eb
parent 231589 a59c2ddcf04cae9dc2e3a7702c8703b7430c3ff3
child 231591 a39933b3beccd3c9680e8e929609164909690248
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1074994
milestone35.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 1074994: Implement Debugger.Object.prototype.isArrowFunction. r=sfink
js/src/doc/Debugger/Debugger.Object.md
js/src/jit-test/tests/debug/Object-isArrowFunction.js
js/src/vm/Debugger.cpp
--- a/js/src/doc/Debugger/Debugger.Object.md
+++ b/js/src/doc/Debugger/Debugger.Object.md
@@ -151,16 +151,19 @@ from its prototype:
 :   If the referent is a function that is debuggee code, a
     [`Debugger.Environment`][environment] instance representing the lexical
     environment enclosing the function when it was created. If the referent
     is a function proxy or not debuggee code, this is `undefined`.
 
 `isBoundFunction`
 :   `true` if the referent is a bound function; `false` otherwise.
 
+`isArrowFunction`
+:   `true` if the referent is an arrow function; `false` otherwise.
+
 `boundTargetFunction`
 :   If the referent is a bound function, this is its target function—the
     function that was bound to a particular `this` object. If the referent
     is not a bound function, this is `undefined`.
 
 `boundThis`
 :   If the referent is a bound function, this is the `this` value it was
     bound to. If the referent is not a bound function, this is `undefined`.
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/debug/Object-isArrowFunction.js
@@ -0,0 +1,22 @@
+// Debugger.Object.prototype.isArrowFunction recognizes arrow functions.
+
+var g = newGlobal();
+var dbg = new Debugger;
+var gDO = dbg.addDebuggee(g);
+var hits = 0;
+
+function checkIsArrow(shouldBe, expr) {
+  print(expr);
+  assertEq(gDO.evalInGlobal(expr).return.isArrowFunction, shouldBe);
+}
+
+checkIsArrow(true, '() => { }');
+checkIsArrow(true, '(a) => { bleh; }');
+checkIsArrow(false, 'Object.getPrototypeOf(() => { })');
+checkIsArrow(false, '(function () { })');
+checkIsArrow(false, 'function f() { } f');
+checkIsArrow(false, '({})');
+checkIsArrow(false, 'Math.atan2');
+checkIsArrow(false, 'Function.prototype');
+checkIsArrow(false, 'Function("")');
+checkIsArrow(false, 'new Function("")');
--- a/js/src/vm/Debugger.cpp
+++ b/js/src/vm/Debugger.cpp
@@ -5283,16 +5283,26 @@ DebuggerObject_getEnvironment(JSContext 
         if (!env)
             return false;
     }
 
     return dbg->wrapEnvironment(cx, env, args.rval());
 }
 
 static bool
+DebuggerObject_getIsArrowFunction(JSContext *cx, unsigned argc, Value *vp)
+{
+    THIS_DEBUGOBJECT_REFERENT(cx, argc, vp, "get isArrowFunction", args, refobj);
+
+    args.rval().setBoolean(refobj->is<JSFunction>()
+                           && refobj->as<JSFunction>().isArrow());
+    return true;
+}
+
+static bool
 DebuggerObject_getIsBoundFunction(JSContext *cx, unsigned argc, Value *vp)
 {
     THIS_DEBUGOBJECT_REFERENT(cx, argc, vp, "get isBoundFunction", args, refobj);
 
     args.rval().setBoolean(refobj->isBoundFunction());
     return true;
 }
 
@@ -5862,16 +5872,17 @@ static const JSPropertySpec DebuggerObje
     JS_PSG("proto", DebuggerObject_getProto, 0),
     JS_PSG("class", DebuggerObject_getClass, 0),
     JS_PSG("callable", DebuggerObject_getCallable, 0),
     JS_PSG("name", DebuggerObject_getName, 0),
     JS_PSG("displayName", DebuggerObject_getDisplayName, 0),
     JS_PSG("parameterNames", DebuggerObject_getParameterNames, 0),
     JS_PSG("script", DebuggerObject_getScript, 0),
     JS_PSG("environment", DebuggerObject_getEnvironment, 0),
+    JS_PSG("isArrowFunction", DebuggerObject_getIsArrowFunction, 0),
     JS_PSG("isBoundFunction", DebuggerObject_getIsBoundFunction, 0),
     JS_PSG("boundTargetFunction", DebuggerObject_getBoundTargetFunction, 0),
     JS_PSG("boundThis", DebuggerObject_getBoundThis, 0),
     JS_PSG("boundArguments", DebuggerObject_getBoundArguments, 0),
     JS_PSG("global", DebuggerObject_getGlobal, 0),
     JS_PSG("allocationSite", DebuggerObject_getAllocationSite, 0),
     JS_PS_END
 };