WebKit Bugzilla
Attachment 348511 Details for
Bug 188952
: output of toString() of Generator is wrong
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-188952-20180831030955.patch (text/plain), 11.48 KB, created by
Yusuke Suzuki
on 2018-08-30 11:09:56 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Yusuke Suzuki
Created:
2018-08-30 11:09:56 PDT
Size:
11.48 KB
patch
obsolete
>Subversion Revision: 235509 >diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog >index 724ed19e61ed15f174da30d7a0628a591b9a7bd3..41d405b6678e176bc550fb36e5219a92ccfb384c 100644 >--- a/Source/JavaScriptCore/ChangeLog >+++ b/Source/JavaScriptCore/ChangeLog >@@ -1,3 +1,16 @@ >+2018-08-30 Yusuke Suzuki <yusukesuzuki@slowstart.org> >+ >+ output of toString() of Generator is wrong >+ https://bugs.webkit.org/show_bug.cgi?id=188952 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ 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 <mark.lam@apple.com> > > Add some missing exception checks in JSRopeString::resolveRopeToAtomicString(). >diff --git a/Source/JavaScriptCore/runtime/FunctionPrototype.cpp b/Source/JavaScriptCore/runtime/FunctionPrototype.cpp >index 3e0407a8284ffa92ce0c60a69f34495bd1811b2b..8fc301371f5a25b383a53e50e2c35baa731a3d31 100644 >--- a/Source/JavaScriptCore/runtime/FunctionPrototype.cpp >+++ b/Source/JavaScriptCore/runtime/FunctionPrototype.cpp >@@ -98,18 +98,46 @@ EncodedJSValue JSC_HOST_CALL functionProtoFuncToString(ExecState* exec) > return JSValue::encode(jsString(exec, classSource.toStringWithoutCopying())); > } > >- if (thisValue.inherits<JSAsyncFunction>(vm)) { >- String functionHeader = executable->isArrowFunction() ? "async " : "async function "; >- >- 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)); >+ String functionHeader; >+ switch (executable->parseMode()) { >+ case SourceParseMode::GeneratorWrapperFunctionMode: >+ case SourceParseMode::GeneratorWrapperMethodMode: >+ functionHeader = "function* "; >+ break; >+ >+ 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()); >diff --git a/JSTests/ChangeLog b/JSTests/ChangeLog >index e040c19950f67a66222cb82ece533082a6cadc66..b3e8e22dbd44b54fa2e8961a4c62cd943a593332 100644 >--- a/JSTests/ChangeLog >+++ b/JSTests/ChangeLog >@@ -1,3 +1,20 @@ >+2018-08-30 Yusuke Suzuki <yusukesuzuki@slowstart.org> >+ >+ output of toString() of Generator is wrong >+ https://bugs.webkit.org/show_bug.cgi?id=188952 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * 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 <mark.lam@apple.com> > > Add some missing exception checks in JSRopeString::resolveRopeToAtomicString(). >diff --git a/JSTests/stress/function-to-string.js b/JSTests/stress/function-to-string.js >new file mode 100644 >index 0000000000000000000000000000000000000000..2f96a1195798f59811d276cab059f9d759a1f5da >--- /dev/null >+++ b/JSTests/stress/function-to-string.js >@@ -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 () => { }`); >diff --git a/JSTests/test262/expectations.yaml b/JSTests/test262/expectations.yaml >index 2d4a0a3d3f040ac655e40c39793daafef36d3b4f..875f52d7db0924619c49c3fb47bef1334d87060f 100644 >--- a/JSTests/test262/expectations.yaml >+++ b/JSTests/test262/expectations.yaml >@@ -909,8 +909,8 @@ test/built-ins/Function/prototype/toString/GeneratorFunction.js: > 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 @@ test/built-ins/Function/prototype/toString/function-expression.js: > 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 */ })"
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
saam
:
review+
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 188952
: 348511