From d70523dce6d43c758e22c40342f4d2dd471e3127 Mon Sep 17 00:00:00 2001 From: "mstarzinger@chromium.org" Date: Fri, 8 Mar 2013 11:47:20 +0000 Subject: [PATCH] Restore Function()'s expected string representation. R=rossberg@chromium.org BUG=v8:2470 TEST=mjsunit/regress/regress-2470 Review URL: https://codereview.chromium.org/12687002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13880 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/v8natives.js | 2 +- test/mjsunit/regress/regress-2470.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/v8natives.js b/src/v8natives.js index 2770e43..cc2e1c5 100644 --- a/src/v8natives.js +++ b/src/v8natives.js @@ -1710,7 +1710,7 @@ function NewFunction(arg1) { // length == 1 p += '\n/' + '**/'; } var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; - var source = '(function(\n' + p + '\n) {\n' + body + '\n})'; + var source = '(function(' + p + ') {\n' + body + '\n})'; // The call to SetNewFunctionAttributes will ensure the prototype // property of the resulting function is enumerable (ECMA262, 15.3.5.2). diff --git a/test/mjsunit/regress/regress-2470.js b/test/mjsunit/regress/regress-2470.js index eed3816..29a0b25 100644 --- a/test/mjsunit/regress/regress-2470.js +++ b/test/mjsunit/regress/regress-2470.js @@ -40,3 +40,8 @@ assertThrows('Function("a", "/*", "*/", "/**/");', SyntaxError); assertDoesNotThrow('Function("//", "//")'); assertDoesNotThrow('Function("//", "//", "//")'); assertThrows('Function("a", "//", "//")', SyntaxError); + +// Some embedders rely on the string representation of the resulting +// function in cases where no formal parameters are specified. +var asString = Function("return 23").toString(); +assertSame("function anonymous() {\nreturn 23\n}", asString); -- 2.7.4