haikuwebkit/LayoutTests/js/class-syntax-declaration-ex...

53 lines
3.4 KiB
Plaintext
Raw Permalink Normal View History

Enable ES6 classes by default https://bugs.webkit.org/show_bug.cgi?id=142774 Reviewed by Gavin Barraclough. .: * Source/cmake/WebKitFeatures.cmake: Source/JavaScriptCore: Enabled the feature and unskipped tests. * Configurations/FeatureDefines.xcconfig: * tests/stress/class-syntax-no-loop-tdz.js: * tests/stress/class-syntax-no-tdz-in-catch.js: * tests/stress/class-syntax-no-tdz-in-conditional.js: * tests/stress/class-syntax-no-tdz-in-loop-no-inline-super.js: * tests/stress/class-syntax-no-tdz-in-loop.js: * tests/stress/class-syntax-no-tdz.js: * tests/stress/class-syntax-tdz-in-catch.js: * tests/stress/class-syntax-tdz-in-conditional.js: * tests/stress/class-syntax-tdz-in-loop.js: * tests/stress/class-syntax-tdz.js: Source/WebCore: * Configurations/FeatureDefines.xcconfig: Source/WebKit/mac: * Configurations/FeatureDefines.xcconfig: Source/WebKit2: * Configurations/FeatureDefines.xcconfig: Source/WTF: * wtf/FeatureDefines.h: Tools: * Scripts/webkitperl/FeatureList.pm: LayoutTests: Unskipped tests and also fixed tests so that they can run under run-javascript-tests. * TestExpectations: Unskipped tests. * js/class-syntax-call-expected.txt: * js/class-syntax-declaration-expected.txt: * js/class-syntax-default-constructor-expected.txt: * js/class-syntax-expression-expected.txt: * js/class-syntax-extends-expected.txt: * js/class-syntax-super-expected.txt: * js/dom/reserved-words-as-property-expected.txt: Rebaselined now that "class" is a non-reserved keyword. * js/script-tests/class-syntax-call.js: Don't refer to "window" object as it doesn't exit when ran inside jsc. * js/script-tests/class-syntax-declaration.js: Rebaselined after r181611, which added default constructor support. * js/script-tests/class-syntax-default-constructor.js: Don't refer to "window" object. Also replaced shouldNotBe by an explicit !== check as the former is not supported when ran inside jsc. * js/script-tests/class-syntax-expression.js: Rebaselined after r181611. * js/script-tests/class-syntax-extends.js: Ditto. Also replaced evalAndLog by shouldNotThrow as the former is not supported inside jsc. * js/script-tests/class-syntax-super.js: Don't refer to "window" object as it doesn't exist inside jsc. * sputnik/Conformance/07_Lexical_Conventions/7.5_Tokens/7.5.3_Future_Reserved_Words/S7.5.3_A1.11-expected.txt: * sputnik/Conformance/07_Lexical_Conventions/7.5_Tokens/7.5.3_Future_Reserved_Words/S7.5.3_A1.27-expected.txt: * sputnik/Conformance/07_Lexical_Conventions/7.5_Tokens/7.5.3_Future_Reserved_Words/S7.5.3_A1.5-expected.txt: Canonical link: https://commits.webkit.org/160789@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181618 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-03-17 05:55:46 +00:00
Tests for ES6 class syntax declarations
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
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): Canonical link: https://commits.webkit.org/165577@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@187680 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-07-31 21:05:19 +00:00
PASS constructorCallCount:::0
PASS A.someStaticMethod():::staticMethodValue
PASS A.someStaticGetter:::getterValue
PASS setterValue = undefined; A.someStaticSetter = 123; setterValue:::123
PASS (new A).someInstanceMethod():::instanceMethodValue
PASS constructorCallCount:::1
PASS (new A).someGetter:::getterValue
PASS constructorCallCount:::2
PASS (new A).someGetter:::getterValue
PASS setterValue = undefined; (new A).someSetter = 789; setterValue:::789
PASS (new A).__proto__:::A.prototype
PASS A.prototype.constructor:::A
PASS class:::SyntaxError: Unexpected end of script
PASS class [:::SyntaxError: Unexpected token '['
PASS class {:::SyntaxError: Class statements must have a name.
PASS class X {:::SyntaxError: Unexpected end of script
PASS class X { ( }:::SyntaxError: Unexpected token '('
PASS class X {}
PASS class X { constructor() {} constructor() {} }:::SyntaxError: Cannot declare multiple constructors in a single class.
PASS class X { get constructor() {} }:::SyntaxError: Cannot declare a getter or setter named 'constructor'.
PASS class X { set constructor() {} }:::SyntaxError: Cannot declare a getter or setter named 'constructor'.
PASS class X { ['constructor']() {} }
PASS class X { ['constructor']() { throw 'unreached' } }; new X
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): Canonical link: https://commits.webkit.org/165577@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@187680 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-07-31 21:05:19 +00:00
PASS class X { constructor() {} static constructor() { return staticMethodValue; } }
PASS class X { constructor() {} static constructor() { return staticMethodValue; } }; X.constructor():::staticMethodValue
PASS class X { constructor() {} static get constructor() { return staticMethodValue; } }
PASS class X { constructor() {} static get constructor() { return staticMethodValue; } }; X.constructor:::staticMethodValue
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): Canonical link: https://commits.webkit.org/165577@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@187680 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-07-31 21:05:19 +00:00
PASS class X { constructor() {} static prototype() {} }:::SyntaxError: Cannot declare a static method named 'prototype'.
PASS class X { constructor() {} static get prototype() {} }:::SyntaxError: Cannot declare a static method named 'prototype'.
PASS class X { constructor() {} static set prototype() {} }:::SyntaxError: Cannot declare a static method named 'prototype'.
PASS class X { constructor() {} static get ['prototype']() {} }:::TypeError: Attempting to change configurable attribute of unconfigurable property.
PASS class X { constructor() {} static set ['prototype'](x) {} }:::TypeError: Attempting to change configurable attribute of unconfigurable property.
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): Canonical link: https://commits.webkit.org/165577@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@187680 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-07-31 21:05:19 +00:00
PASS class X { constructor() {} prototype() { return instanceMethodValue; } }
PASS class X { constructor() {} get prototype() { return instanceMethodValue; } }
PASS class X { constructor() {} set prototype(x) { } }
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): Canonical link: https://commits.webkit.org/165577@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@187680 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-07-31 21:05:19 +00:00
PASS class X { constructor() {} prototype() { return instanceMethodValue; } }; (new X).prototype():::instanceMethodValue
PASS class X { constructor() {} set foo(a) {} }
PASS class X { constructor() {} set foo({x, y}) {} }
PASS class X { constructor() {} set foo() {} }:::SyntaxError: Unexpected token ')'. setter functions must have one parameter.
PASS class X { constructor() {} set foo(a, b) {} }:::SyntaxError: Unexpected token ','. setter functions must have one parameter.
PASS class X { constructor() {} get foo() {} }
PASS class X { constructor() {} get foo(x) {} }:::SyntaxError: Unexpected identifier 'x'. getter functions must have no parameters.
PASS class X { constructor() {} get foo({x, y}) {} }:::SyntaxError: Unexpected token '{'. getter functions must have no parameters.
PASS successfullyParsed:::true
Implement ES6 class syntax without inheritance support https://bugs.webkit.org/show_bug.cgi?id=140918 Reviewed by Geoffrey Garen. Source/JavaScriptCore: Added the most basic support for ES6 class syntax. After this patch, we support basic class definition like: class A { constructor() { } someMethod() { } } We'll add the support for "extends" keyword and automatically generating a constructor in follow up patches. We also don't support block scoping of a class declaration. We support both class declaration and class expression. A class expression is implemented by the newly added ClassExprNode AST node. A class declaration is implemented by ClassDeclNode, which is a thin wrapper around AssignResolveNode. Tests: js/class-syntax-declaration.html js/class-syntax-expression.html * bytecompiler/NodesCodegen.cpp: (JSC::ObjectLiteralNode::emitBytecode): Create a new object instead of delegating the work to PropertyListNode. Also fixed the 5-space indentation. (JSC::PropertyListNode::emitBytecode): Don't create a new object now that ObjectLiteralNode does this. (JSC::ClassDeclNode::emitBytecode): Added. Just let the AssignResolveNode node emit the byte code. (JSC::ClassExprNode::emitBytecode): Create the class constructor and add static methods to the constructor by emitting the byte code for PropertyListNode. Add instance methods to the class's prototype object the same way. * parser/ASTBuilder.h: (JSC::ASTBuilder::createClassExpr): Added. Creates a ClassExprNode. (JSC::ASTBuilder::createClassDeclStatement): Added. Creates a AssignResolveNode and wraps it by a ClassDeclNode. * parser/NodeConstructors.h: (JSC::ClassDeclNode::ClassDeclNode): Added. (JSC::ClassExprNode::ClassExprNode): Added. * parser/Nodes.h: (JSC::ClassExprNode): Added. (JSC::ClassDeclNode): Added. * parser/Parser.cpp: (JSC::Parser<LexerType>::parseStatement): Added the support for class declaration. (JSC::stringForFunctionMode): Return "method" for MethodMode. (JSC::Parser<LexerType>::parseClassDeclaration): Added. Uses parseClass to create a class expression and wraps it with ClassDeclNode as described above. (JSC::Parser<LexerType>::parseClass): Parses a class expression. (JSC::Parser<LexerType>::parseProperty): (JSC::Parser<LexerType>::parseGetterSetter): Extracted from parseProperty to share the code between parseProperty and parseClass. (JSC::Parser<LexerType>::parsePrimaryExpression): Added the support for class expression. * parser/Parser.h: (FunctionParseMode): Added MethodMode. * parser/SyntaxChecker.h: (JSC::SyntaxChecker::createClassExpr): Added. (JSC::SyntaxChecker::createClassDeclStatement): Added. LayoutTests: Added two tests for class declarations and class expressions. * TestExpectations: * js/class-syntax-declaration-expected.txt: Added. * js/class-syntax-declaration.html: Added. * js/class-syntax-expression-expected.txt: Added. * js/class-syntax-expression.html: Added. * js/script-tests/class-syntax-declaration.js: Added. * js/script-tests/class-syntax-expression.js: Added. Canonical link: https://commits.webkit.org/159052@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@179371 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-01-29 22:59:19 +00:00
TEST COMPLETE