Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[JSC] Align Function#name behavior with spec
https://bugs.webkit.org/show_bug.cgi?id=247725 Reviewed by Yusuke Suzuki. This patch fixes two bugs in our Function#name implementation, which were reported in the same BZ issue (each is due to misalignment between object literals and class bodies -- one issue in each direction): 1. `class C { async ['f']() {} }` Async class methods with computed names were given the function name "async", because we were storing the async identifier *anytime* we encountered it. 2. `{ 0: () => {} }` Object literal function properties with Number literal names were given an empty function name (as would be correct behavior for Array). Incidentally, BigInt literal names were already behaving properly here. * JSTests/stress/function-name-property.js: Added. * Source/JavaScriptCore/parser/Parser.cpp: (JSC::Parser<LexerType>::parseClass): (JSC::Parser<LexerType>::parseProperty): Canonical link: https://commits.webkit.org/257114@main
- Loading branch information
Showing
2 changed files
with
29 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
function shouldBe(actual, expected) { | ||
if (actual !== expected) | ||
throw new Error(`expected ${expected} but got ${actual}`); | ||
} | ||
|
||
shouldBe(({ f: () => {} }).f.name, 'f'); | ||
shouldBe(({ f: function () {} }).f.name, 'f'); | ||
shouldBe(({ ['f']: () => {} }).f.name, 'f'); | ||
shouldBe(({ ['f']: function () {} }).f.name, 'f'); | ||
shouldBe(({ async f() {} }).f.name, 'f'); | ||
shouldBe(({ async ['f']() {} }).f.name, 'f'); | ||
shouldBe((class { f() {} }).prototype.f.name, 'f'); | ||
shouldBe((class { ['f']() {} }).prototype.f.name, 'f'); | ||
shouldBe((class { async f() {} }).prototype.f.name, 'f'); | ||
shouldBe((class { async ['f']() {} }).prototype.f.name, 'f'); | ||
|
||
shouldBe([() => {}][0].name, ''); | ||
shouldBe([function () {}][0].name, ''); | ||
shouldBe(({ 0: () => {} })[0].name, '0'); | ||
shouldBe(({ 0: function () {} })[0].name, '0'); | ||
shouldBe(({ [0]: () => {} })[0].name, '0'); | ||
shouldBe(({ [0]: function () {} })[0].name, '0'); | ||
shouldBe((class { 0() {} }).prototype[0].name, '0'); | ||
shouldBe((class { [0]() {} }).prototype[0].name, '0'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters