Skip to content

Commit

Permalink
[JSC] Refine SyntaxError message for generator method parsing failure
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=264368
<rdar://problem/118081884>

Reviewed by Justin Michaud.

This change rewords SyntaxError message, thrown in case of generator method parsing failure,
to mention "method" rather than "function", aligning error wording for sync generator functions
with async counterparts.

Also, tweaks the helper to return "generator function" instead of "generator" for GeneratorBodyMode,
which is unobservable yet matches the terminology of the spec [1].

[1]: https://tc39.es/ecma262/#sec-generator-objects

* JSTests/stress/generator-class-methods-syntax.js:
* JSTests/stress/regress-189292.js:
* Source/JavaScriptCore/parser/Parser.cpp:
(JSC::stringForFunctionMode):

Canonical link: https://commits.webkit.org/270379@main
  • Loading branch information
Alexey Shvayka committed Nov 8, 2023
1 parent f1403b1 commit 17d1d74
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion JSTests/stress/generator-class-methods-syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Cocoa {
{
}
}
`, `SyntaxError: Cannot declare a generator function named 'constructor'.`);
`, `SyntaxError: Cannot declare a generator method named 'constructor'.`);

testSyntax(`
class Cocoa {
Expand Down
2 changes: 1 addition & 1 deletion JSTests/stress/regress-189292.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ function test(script) {
}

assert(test("class C1 { async constructor() { } }"), "SyntaxError: Cannot declare an async method named 'constructor'.");
assert(test("class C1 { *constructor() { } }"), "SyntaxError: Cannot declare a generator function named 'constructor'.");
assert(test("class C1 { *constructor() { } }"), "SyntaxError: Cannot declare a generator method named 'constructor'.");
assert(test("class C1 { async *constructor() { } }"), "SyntaxError: Cannot declare an async generator method named 'constructor'.");
6 changes: 3 additions & 3 deletions Source/JavaScriptCore/parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2265,11 +2265,11 @@ static const char* stringForFunctionMode(SourceParseMode mode)
return "function";
case SourceParseMode::MethodMode:
return "method";
case SourceParseMode::GeneratorBodyMode:
return "generator";
case SourceParseMode::GeneratorWrapperFunctionMode:
case SourceParseMode::GeneratorWrapperMethodMode:
case SourceParseMode::GeneratorBodyMode:
return "generator function";
case SourceParseMode::GeneratorWrapperMethodMode:
return "generator method";
case SourceParseMode::ArrowFunctionMode:
return "arrow function";
case SourceParseMode::AsyncFunctionMode:
Expand Down

0 comments on commit 17d1d74

Please sign in to comment.