Title: [235514] trunk
Revision
235514
Author
[email protected]
Date
2018-08-30 12:05:34 -0700 (Thu, 30 Aug 2018)

Log Message

output of toString() of Generator is wrong
https://bugs.webkit.org/show_bug.cgi?id=188952

Reviewed by Saam Barati.

JSTests:

* stress/function-to-string.js: Added.
(shouldBe):
(shouldBe.test):
(test):
(shouldBe.async.test):
(async.test):
(shouldBe.async):
(async):
* test262/expectations.yaml:

Source/_javascript_Core:

Function#toString does not respect generator and async generator.
This patch fixes them and supports all the function types.

* runtime/FunctionPrototype.cpp:
(JSC::functionProtoFuncToString):

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (235513 => 235514)


--- trunk/JSTests/ChangeLog	2018-08-30 19:03:55 UTC (rev 235513)
+++ trunk/JSTests/ChangeLog	2018-08-30 19:05:34 UTC (rev 235514)
@@ -1,3 +1,20 @@
+2018-08-30  Yusuke Suzuki  <[email protected]>
+
+        output of toString() of Generator is wrong
+        https://bugs.webkit.org/show_bug.cgi?id=188952
+
+        Reviewed by Saam Barati.
+
+        * stress/function-to-string.js: Added.
+        (shouldBe):
+        (shouldBe.test):
+        (test):
+        (shouldBe.async.test):
+        (async.test):
+        (shouldBe.async):
+        (async):
+        * test262/expectations.yaml:
+
 2018-08-29  Mark Lam  <[email protected]>
 
         Add some missing exception checks in JSRopeString::resolveRopeToAtomicString().

Added: trunk/JSTests/stress/function-to-string.js (0 => 235514)


--- trunk/JSTests/stress/function-to-string.js	                        (rev 0)
+++ trunk/JSTests/stress/function-to-string.js	2018-08-30 19:05:34 UTC (rev 235514)
@@ -0,0 +1,11 @@
+function shouldBe(actual, expected) {
+    if (actual !== expected)
+        throw new Error('bad value: ' + actual);
+}
+
+shouldBe((function test() { }).toString(), `function test() { }`);
+shouldBe((() => { }).toString(), `() => { }`);
+shouldBe((function* test() { }).toString(), `function* test() { }`);
+shouldBe((async function* test() { }).toString(), `async function* test() { }`);
+shouldBe((async function test() { }).toString(), `async function test() { }`);
+shouldBe((async () => { }).toString(), `async () => { }`);

Modified: trunk/JSTests/test262/expectations.yaml (235513 => 235514)


--- trunk/JSTests/test262/expectations.yaml	2018-08-30 19:03:55 UTC (rev 235513)
+++ trunk/JSTests/test262/expectations.yaml	2018-08-30 19:05:34 UTC (rev 235514)
@@ -909,8 +909,8 @@
   default: "SyntaxError: Unexpected token '}'. Expected a ')' or a ',' after a parameter declaration."
   strict mode: "SyntaxError: Unexpected token '}'. Expected a ')' or a ',' after a parameter declaration."
 test/built-ins/Function/prototype/toString/async-arrow-function.js:
-  default: "Test262Error: Conforms to NativeFunction Syntax: 'async function ( /* b */ a /* c */ , /* d */ b /* e */ ) /* f */ => /* g */ { /* h */ ; /* i */ }'.(async /* a */ ( /* b */ a /* c */ , /* d */ b /* e */ ) /* f */ => /* g */ { /* h */ ; /* i */ })"
-  strict mode: "Test262Error: Conforms to NativeFunction Syntax: 'async function ( /* b */ a /* c */ , /* d */ b /* e */ ) /* f */ => /* g */ { /* h */ ; /* i */ }'.(async /* a */ ( /* b */ a /* c */ , /* d */ b /* e */ ) /* f */ => /* g */ { /* h */ ; /* i */ })"
+  default: "Test262Error: Conforms to NativeFunction Syntax: 'async ( /* b */ a /* c */ , /* d */ b /* e */ ) /* f */ => /* g */ { /* h */ ; /* i */ }'.(async /* a */ ( /* b */ a /* c */ , /* d */ b /* e */ ) /* f */ => /* g */ { /* h */ ; /* i */ })"
+  strict mode: "Test262Error: Conforms to NativeFunction Syntax: 'async ( /* b */ a /* c */ , /* d */ b /* e */ ) /* f */ => /* g */ { /* h */ ; /* i */ }'.(async /* a */ ( /* b */ a /* c */ , /* d */ b /* e */ ) /* f */ => /* g */ { /* h */ ; /* i */ })"
 test/built-ins/Function/prototype/toString/async-function-declaration.js:
   default: "Test262Error: Conforms to NativeFunction Syntax: 'async function f( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ }'.(async function /* a */ f /* b */ ( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ })"
   strict mode: "Test262Error: Conforms to NativeFunction Syntax: 'async function f( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ }'.(async function /* a */ f /* b */ ( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ })"
@@ -942,14 +942,14 @@
   default: "Test262Error: Conforms to NativeFunction Syntax: 'function F( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ }'.(function /* a */ F /* b */ ( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ })"
   strict mode: "Test262Error: Conforms to NativeFunction Syntax: 'function F( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ }'.(function /* a */ F /* b */ ( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ })"
 test/built-ins/Function/prototype/toString/generator-function-declaration.js:
-  default: "Test262Error: Conforms to NativeFunction Syntax: 'function g( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }'.(function /* a */ * /* b */ g /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ })"
-  strict mode: "Test262Error: Conforms to NativeFunction Syntax: 'function g( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }'.(function /* a */ * /* b */ g /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ })"
+  default: "Test262Error: Conforms to NativeFunction Syntax: 'function* g( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }'.(function /* a */ * /* b */ g /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ })"
+  strict mode: "Test262Error: Conforms to NativeFunction Syntax: 'function* g( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }'.(function /* a */ * /* b */ g /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ })"
 test/built-ins/Function/prototype/toString/generator-function-_expression_.js:
-  default: "Test262Error: Conforms to NativeFunction Syntax: 'function F( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }'.(function /* a */ * /* b */ F /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ })"
-  strict mode: "Test262Error: Conforms to NativeFunction Syntax: 'function F( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }'.(function /* a */ * /* b */ F /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ })"
+  default: "Test262Error: Conforms to NativeFunction Syntax: 'function* F( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }'.(function /* a */ * /* b */ F /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ })"
+  strict mode: "Test262Error: Conforms to NativeFunction Syntax: 'function* F( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }'.(function /* a */ * /* b */ F /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ })"
 test/built-ins/Function/prototype/toString/generator-method.js:
-  default: "Test262Error: Conforms to NativeFunction Syntax: 'function f( /* c */ ) /* d */ { /* e */ }'.(* /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ })"
-  strict mode: "Test262Error: Conforms to NativeFunction Syntax: 'function f( /* c */ ) /* d */ { /* e */ }'.(* /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ })"
+  default: "Test262Error: Conforms to NativeFunction Syntax: 'function* f( /* c */ ) /* d */ { /* e */ }'.(* /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ })"
+  strict mode: "Test262Error: Conforms to NativeFunction Syntax: 'function* f( /* c */ ) /* d */ { /* e */ }'.(* /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ })"
 test/built-ins/Function/prototype/toString/getter-class-_expression_-static.js:
   default: "Test262Error: Conforms to NativeFunction Syntax: 'function ( /* c */ ) /* d */ { /* e */ }'.(get /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ })"
   strict mode: "Test262Error: Conforms to NativeFunction Syntax: 'function ( /* c */ ) /* d */ { /* e */ }'.(get /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ })"

Modified: trunk/Source/_javascript_Core/ChangeLog (235513 => 235514)


--- trunk/Source/_javascript_Core/ChangeLog	2018-08-30 19:03:55 UTC (rev 235513)
+++ trunk/Source/_javascript_Core/ChangeLog	2018-08-30 19:05:34 UTC (rev 235514)
@@ -1,3 +1,16 @@
+2018-08-30  Yusuke Suzuki  <[email protected]>
+
+        output of toString() of Generator is wrong
+        https://bugs.webkit.org/show_bug.cgi?id=188952
+
+        Reviewed by Saam Barati.
+
+        Function#toString does not respect generator and async generator.
+        This patch fixes them and supports all the function types.
+
+        * runtime/FunctionPrototype.cpp:
+        (JSC::functionProtoFuncToString):
+
 2018-08-29  Mark Lam  <[email protected]>
 
         Add some missing exception checks in JSRopeString::resolveRopeToAtomicString().

Modified: trunk/Source/_javascript_Core/runtime/FunctionPrototype.cpp (235513 => 235514)


--- trunk/Source/_javascript_Core/runtime/FunctionPrototype.cpp	2018-08-30 19:03:55 UTC (rev 235513)
+++ trunk/Source/_javascript_Core/runtime/FunctionPrototype.cpp	2018-08-30 19:05:34 UTC (rev 235514)
@@ -98,18 +98,46 @@
             return JSValue::encode(jsString(exec, classSource.toStringWithoutCopying()));
         }
 
-        if (thisValue.inherits<JSAsyncFunction>(vm)) {
-            String functionHeader = executable->isArrowFunction() ? "async " : "async function ";
+        String functionHeader;
+        switch (executable->parseMode()) {
+        case SourceParseMode::GeneratorWrapperFunctionMode:
+        case SourceParseMode::GeneratorWrapperMethodMode:
+            functionHeader = "function* ";
+            break;
 
-            StringView source = executable->source().provider()->getRange(
-                executable->parametersStartOffset(),
-                executable->parametersStartOffset() + executable->source().length());
-            scope.release();
-            return JSValue::encode(jsMakeNontrivialString(exec, functionHeader, function->name(vm), source));
+        case SourceParseMode::NormalFunctionMode:
+        case SourceParseMode::GetterMode:
+        case SourceParseMode::SetterMode:
+        case SourceParseMode::MethodMode:
+        case SourceParseMode::ProgramMode:
+        case SourceParseMode::ModuleAnalyzeMode:
+        case SourceParseMode::ModuleEvaluateMode:
+        case SourceParseMode::GeneratorBodyMode:
+        case SourceParseMode::AsyncGeneratorBodyMode:
+        case SourceParseMode::AsyncFunctionBodyMode:
+        case SourceParseMode::AsyncArrowFunctionBodyMode:
+            functionHeader = "function ";
+            break;
+
+        case SourceParseMode::ArrowFunctionMode:
+            functionHeader = "";
+            break;
+
+        case SourceParseMode::AsyncFunctionMode:
+        case SourceParseMode::AsyncMethodMode:
+            functionHeader = "async function ";
+            break;
+
+        case SourceParseMode::AsyncArrowFunctionMode:
+            functionHeader = "async ";
+            break;
+
+        case SourceParseMode::AsyncGeneratorWrapperFunctionMode:
+        case SourceParseMode::AsyncGeneratorWrapperMethodMode:
+            functionHeader = "async function* ";
+            break;
         }
 
-        String functionHeader = executable->isArrowFunction() ? "" : "function ";
-        
         StringView source = executable->source().provider()->getRange(
             executable->parametersStartOffset(),
             executable->parametersStartOffset() + executable->source().length());
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to