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 330281 a97ebab940c6ba0f19348c38d17a2193ee75c9ab
parent 330280 a80fdfc128b0c29dc34dd3fc28868252111a5d52
child 330282 d2cbe0d4b29aa2981e8a443651e6b966840a84f2
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1242662
milestone50.0a1
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");
 
 
 /******************************************************************************/