Ignore:
Timestamp:
Jul 31, 2015, 2:05:19 PM (10 years ago)
Author:
[email protected]
Message:

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.

  • parser/ASTBuilder.h:

(JSC::ASTBuilder::createClassDeclStatement):

  • parser/Parser.cpp:

(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):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/ASTBuilder.h

    r187515 r187680  
    443443        const JSTextPosition& classStart, const JSTextPosition& classEnd, unsigned startLine, unsigned endLine)
    444444    {
    445         // FIXME: Use "let" declaration.
    446445        ExpressionNode* assign = createAssignResolve(location, classExpression->name(), classExpression, classStart, classStart + 1, classEnd, AssignmentContext::DeclarationStatement);
    447446        ClassDeclNode* decl = new (m_parserArena) ClassDeclNode(location, assign);
Note: See TracChangeset for help on using the changeset viewer.