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/Parser.cpp

    r187515 r187680  
    18221822    TreeClassExpression classExpr = parseClass(context, FunctionNeedsName, info);
    18231823    failIfFalse(classExpr, "Failed to parse class");
    1824     // FIXME: This should be like `let`, not `var`.
    1825     declareVariable(info.className);
     1824
     1825    DeclarationResultMask declarationResult = declareVariable(info.className, DeclarationType::LetDeclaration);
     1826    if (declarationResult & DeclarationResult::InvalidDuplicateDeclaration)
     1827        internalFailWithMessage(false, "Cannot declare a class twice: '", info.className->impl(), "'");
    18261828
    18271829    JSTextPosition classEnd = lastTokenEndPosition();
Note: See TracChangeset for help on using the changeset viewer.