Bug 1304551 - Properly handle bound functions in getBacktrace. r?efaust draft
authorTill Schneidereit <till@tillschneidereit.net>
Thu, 29 Sep 2016 15:31:20 +0200
changeset 419016 d8b9c8c4bd9fe932b35a1d135af7af7283cd34fa
parent 419015 b6f62be719ae36609cde88c878c35c5160ff502f
child 532467 9b62757c7f749de80593008cd7483c206da18e52
push id30818
push userbmo:till@tillschneidereit.net
push dateThu, 29 Sep 2016 13:34:45 +0000
reviewersefaust
bugs1304551
milestone52.0a1
Bug 1304551 - Properly handle bound functions in getBacktrace. r?efaust getBacktrace, when invoked with `{locals:true}`, prints the `this` value for each frame, where applicable. When constructing bound functions, the `this` value is magic, which FormatFrame doesn't handle. Since printing that `this` value isn't useful, we just skip it. MozReview-Commit-ID: 8axhOqyrA2B
js/src/jit-test/tests/self-hosting/get-backtrace-in-constructing-bound-function.js
js/src/jsfriendapi.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/self-hosting/get-backtrace-in-constructing-bound-function.js
@@ -0,0 +1,6 @@
+function t() {
+    getBacktrace({ locals: true });
+}
+var f = t.bind();
+new f();
+f();
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -792,17 +792,18 @@ FormatFrame(JSContext* cx, const FrameIt
     RootedFunction fun(cx, iter.maybeCallee(cx));
     RootedString funname(cx);
     if (fun)
         funname = fun->displayAtom();
 
     RootedValue thisVal(cx);
     if (iter.hasUsableAbstractFramePtr() &&
         iter.isFunctionFrame() &&
-        fun && !fun->isArrow() && !fun->isDerivedClassConstructor())
+        fun && !fun->isArrow() && !fun->isDerivedClassConstructor() &&
+        !(fun->isBoundFunction() && iter.isConstructing()))
     {
         if (!GetFunctionThis(cx, iter.abstractFramePtr(), &thisVal))
             return nullptr;
     }
 
     // print the frame number and function name
     if (funname) {
         JSAutoByteString funbytes;