ES6 class syntax should use block scoping
https://bugs.webkit.org/show_bug.cgi?id=142567
Reviewed by Geoffrey Garen.
Source/JavaScriptCore:
We treat class declarations like we do "let" declarations.
The class name is under TDZ until the class declaration
statement is evaluated. Class declarations also follow
the same rules as "let": No duplicate definitions inside
a lexical environment.
(JSC::ASTBuilder::createClassDeclStatement):
(JSC::Parser<LexerType>::parseClassDeclaration):
- tests/stress/class-syntax-block-scoping.js: Added.
(assert):
(truth):
(.):
- tests/stress/class-syntax-definition-semantics.js: Added.
(shouldBeSyntaxError):
(shouldNotBeSyntaxError):
(truth):
- tests/stress/class-syntax-tdz.js:
(assert):
(shouldThrowTDZ):
(truth):
(.):
LayoutTests:
- js/class-constructor-return-expected.txt:
- js/class-syntax-call-expected.txt:
- js/class-syntax-declaration-expected.txt:
- js/class-syntax-default-constructor-expected.txt:
- js/class-syntax-extends-expected.txt:
- js/class-syntax-name-expected.txt:
- js/class-syntax-super-expected.txt:
- js/script-tests/class-constructor-return.js:
(shouldThrow):
(shouldNotThrow):
(shouldBeTrue):
(shouldBeFalse):
- js/script-tests/class-syntax-call.js:
(A):
(B):
(shouldThrow):
(shouldNotThrow):
- js/script-tests/class-syntax-declaration.js:
(shouldThrow):
(shouldNotThrow):
(shouldBe):
- js/script-tests/class-syntax-default-constructor.js:
(shouldThrow):
(shouldBe):
(shouldBeTrue):
(assert):
(A):
(B):
- js/script-tests/class-syntax-extends.js:
(shouldThrow):
(shouldNotThrow):
(shouldBe):
(shouldBeTrue):
(Base):
(Base.prototype.baseMethod):
- js/script-tests/class-syntax-name.js:
(shouldThrow):
(shouldNotThrow):
(shouldBe):
(shouldBeTrue):
(runTestShouldBe):
- js/script-tests/class-syntax-super.js:
(shouldThrow):
(shouldNotThrow):
(shouldBe):
(shouldBeTrue):
(shouldBeFalse):