Bug 1242662 - Don't emit opening paren for decompiled bound function. r=jandem
authorTill Schneidereit <till@tillschneidereit.net>
Sat, 16 Jul 2016 15:40:13 +0200
changeset 305217 a97ebab940c6ba0f19348c38d17a2193ee75c9ab
parent 305216 a80fdfc128b0c29dc34dd3fc28868252111a5d52
child 305218 d2cbe0d4b29aa2981e8a443651e6b966840a84f2
push id30455
push usercbook@mozilla.com
push dateSun, 17 Jul 2016 08:08:29 +0000
treeherdermozilla-central@711963e8daa3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1242662
milestone50.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 1242662 - Don't emit opening paren for decompiled bound function. r=jandem
js/src/jsfun.cpp
js/src/tests/ecma_5/Function/function-bind.js
--- a/js/src/jsfun.cpp
+++ b/js/src/jsfun.cpp
@@ -1026,17 +1026,19 @@ js::FunctionToString(JSContext* cx, Hand
             return out.finishString();
         }
     }
 
     bool funIsMethodOrNonArrowLambda = (fun->isLambda() && !fun->isArrow()) || fun->isMethod() ||
                                         fun->isGetter() || fun->isSetter();
 
     // If we're not in pretty mode, put parentheses around lambda functions and methods.
-    if (fun->isInterpreted() && !lambdaParen && funIsMethodOrNonArrowLambda) {
+    if (fun->isInterpreted() && !lambdaParen && funIsMethodOrNonArrowLambda &&
+        !fun->isSelfHostedBuiltin())
+    {
         if (!out.append("("))
             return nullptr;
     }
     if (!fun->isArrow()) {
         if (!(fun->isStarGenerator() ? out.append("function* ") : out.append("function ")))
             return nullptr;
     }
     if (fun->name()) {
--- a/js/src/tests/ecma_5/Function/function-bind.js
+++ b/js/src/tests/ecma_5/Function/function-bind.js
@@ -257,16 +257,28 @@ function testBound(fun)
 
   expectThrowTypeError(function() { return boundf.arguments; });
   expectThrowTypeError(function() { return boundf.caller; });
 }
 
 testBound(strict);
 testBound(nonstrict);
 
+assertEq((function unbound(){"body"}).bind().toString(), `function bound unbound() {
+    [native code]
+}`);
+
+assertEq((function unbound(){"body"}).bind().toSource(), `function bound unbound() {
+    [native code]
+}`);
+
+assertEq(uneval((function unbound(){"body"}).bind()), `function bound unbound() {
+    [native code]
+}`);
+
 
 /* 22. Return F. */
 var passim = function p(){}.bind(1);
 assertEq(typeof passim, "function");
 
 
 /******************************************************************************/