haikuwebkit/LayoutTests/js/class-syntax-string-and-num...

49 lines
3.0 KiB
Plaintext
Raw Permalink Normal View History

Class syntax should allow string and numeric identifiers for method names https://bugs.webkit.org/show_bug.cgi?id=144254 Reviewed by Darin Adler. Source/JavaScriptCore: Added the support for string and numeric identifiers in class syntax. * parser/Parser.cpp: (JSC::Parser<LexerType>::parseFunctionInfo): Instead of using ConstructorKind to indicate whether we're inside a class or not, use the newly added SuperBinding argument instead. ConstructorKind is now None outside a class constructor as it should be. (JSC::Parser<LexerType>::parseFunctionDeclaration): (JSC::Parser<LexerType>::parseClass): No longer expects an identifier at the beginning of every class element to allow numeric and string method names. For both of those method names, parse it here instead of parseFunctionInfo since it doesn't support either type. Also pass in SuperBinding::Needed. (JSC::Parser<LexerType>::parsePropertyMethod): Call parseFunctionInfo with SuperBinding::NotNeeded since this function is never used to parse a class method. (JSC::Parser<LexerType>::parseGetterSetter): Pass in superBinding argument to parseFunctionInfo. (JSC::Parser<LexerType>::parsePrimaryExpression): Call parseFunctionInfo with SuperBinding::NotNeeded. * parser/Parser.h: * parser/SyntaxChecker.h: (JSC::SyntaxChecker::createProperty): LayoutTests: Added a test and rebaselined other tests per syntax error message change. * js/class-syntax-declaration-expected.txt: * js/class-syntax-expression-expected.txt: * js/class-syntax-string-and-numeric-names-expected.txt: Added. * js/class-syntax-string-and-numeric-names.html: Added. * js/class-syntax-super-expected.txt: * js/script-tests/class-syntax-declaration.js: * js/script-tests/class-syntax-expression.js: * js/script-tests/class-syntax-string-and-numeric-names.js: Added. * js/script-tests/class-syntax-super.js: Canonical link: https://commits.webkit.org/162546@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183709 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-05-02 02:23:01 +00:00
Tests for string and numeric method names for ES6 class syntax
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS constructorCallCount = 0; new (class { "constructor"() { constructorCallCount++; } }); constructorCallCount is 1
PASS class A { 'constructor'() { constructorCallCount++; } }; new A; constructorCallCount is 2
PASS new (class { constructor() {} "constructor"() {} }); threw exception SyntaxError: Cannot declare multiple constructors in a single class..
PASS new (class { constructor() {} static "prototype"() {} }); threw exception SyntaxError: Cannot declare a static method named 'prototype'..
PASS class A { 'foo'() { return 3; } }; (new A).foo() is 3
PASS class A { get 'foo'() { return 4; } }; (new A).foo is 4
PASS class A { get 'foo'() { return 4; } }; A.foo is undefined
PASS class A { static get 'foo'() { return 5; } }; A.foo is 5
PASS class A { static get 'foo'() { return 5; } }; (new A).foo is undefined
PASS fooValue = 0; X = class { set 'foo'(value) { fooValue = value; } }; (new X).foo = 6; fooValue is 6
PASS X.foo = 7; fooValue is 6
PASS fooValue = 0; X = class { static set 'foo'(value) { fooValue = value; } }; X.foo = 8; fooValue is 8
PASS (new X).foo = 7; fooValue is 8
PASS X = class { get 'foo'() { return 9 } set 'foo'(x) { } }; x = new X; x.foo is 9
PASS X.foo is undefined
PASS fooValue = 0; X = class { get 'foo'() { } set 'foo'(x) { fooValue = x } }; (new X).foo = 9; fooValue is 9
PASS X.foo = 10; fooValue is 9
PASS X = class { static set 'foo'(x) { } static get 'foo'() { return 10 } }; X.foo is 10
PASS (new X).foo is undefined
PASS fooValue = 0; X = class { static set 'foo'(x) { fooValue = x } static get 'foo'() { } }; X.foo = 11; fooValue is 11
PASS (new X).foo = 12; fooValue is 11
PASS class A { get 0() { return 20; } }; (new A)[0] is 20
PASS class A { get 0() { return 20; } }; A[0] is undefined
PASS class A { static get 1() { return 21; } }; A[1] is 21
PASS class A { static get 1() { return 21; } }; (new A)[1] is undefined
Numeric setter on prototype doesn't get called. https://bugs.webkit.org/show_bug.cgi?id=144252 Reviewed by Darin Adler. Source/JavaScriptCore: When switching the blank indexing type to the other one in putByIndex, if the `structure(vm)->needsSlowPutIndexing()` is true, we need to switch it to the slow put indexing type and reloop the putByIndex since there may be some indexing accessor in the prototype chain. Previously, we just set the value into the allocated vector. In the putDirectIndex case, we just store the value to the vector. This is because putDirectIndex is the operation to store the own property and it does not check the accessors in the prototype chain. * runtime/JSObject.cpp: (JSC::JSObject::putByIndexBeyondVectorLength): * tests/stress/injected-numeric-setter-on-prototype.js: Added. (shouldBe): (Trace): (Trace.prototype.trace): (Trace.prototype.get count): (.): * tests/stress/numeric-setter-on-prototype-non-blank-array.js: Added. (shouldBe): (Trace): (Trace.prototype.trace): (Trace.prototype.get count): (.): * tests/stress/numeric-setter-on-prototype.js: Added. (shouldBe): (Trace): (Trace.prototype.trace): (Trace.prototype.get count): (.z.__proto__.set 3): * tests/stress/numeric-setter-on-self.js: Added. (shouldBe): (Trace): (Trace.prototype.trace): (Trace.prototype.get count): (.y.set 2): LayoutTests: Update the test expectation file. * js/class-syntax-string-and-numeric-names-expected.txt: Canonical link: https://commits.webkit.org/165992@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@188269 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-08-11 19:11:55 +00:00
PASS setterValue = 0; X = class { set 2(x) { setterValue = x; } }; (new X)[2] = 22; setterValue is 22
PASS X[2] = 23; setterValue is 22
Class syntax should allow string and numeric identifiers for method names https://bugs.webkit.org/show_bug.cgi?id=144254 Reviewed by Darin Adler. Source/JavaScriptCore: Added the support for string and numeric identifiers in class syntax. * parser/Parser.cpp: (JSC::Parser<LexerType>::parseFunctionInfo): Instead of using ConstructorKind to indicate whether we're inside a class or not, use the newly added SuperBinding argument instead. ConstructorKind is now None outside a class constructor as it should be. (JSC::Parser<LexerType>::parseFunctionDeclaration): (JSC::Parser<LexerType>::parseClass): No longer expects an identifier at the beginning of every class element to allow numeric and string method names. For both of those method names, parse it here instead of parseFunctionInfo since it doesn't support either type. Also pass in SuperBinding::Needed. (JSC::Parser<LexerType>::parsePropertyMethod): Call parseFunctionInfo with SuperBinding::NotNeeded since this function is never used to parse a class method. (JSC::Parser<LexerType>::parseGetterSetter): Pass in superBinding argument to parseFunctionInfo. (JSC::Parser<LexerType>::parsePrimaryExpression): Call parseFunctionInfo with SuperBinding::NotNeeded. * parser/Parser.h: * parser/SyntaxChecker.h: (JSC::SyntaxChecker::createProperty): LayoutTests: Added a test and rebaselined other tests per syntax error message change. * js/class-syntax-declaration-expected.txt: * js/class-syntax-expression-expected.txt: * js/class-syntax-string-and-numeric-names-expected.txt: Added. * js/class-syntax-string-and-numeric-names.html: Added. * js/class-syntax-super-expected.txt: * js/script-tests/class-syntax-declaration.js: * js/script-tests/class-syntax-expression.js: * js/script-tests/class-syntax-string-and-numeric-names.js: Added. * js/script-tests/class-syntax-super.js: Canonical link: https://commits.webkit.org/162546@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183709 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-05-02 02:23:01 +00:00
PASS setterValue = 0; X = class { static set 3(x) { setterValue = x; } }; X[3] = 23; setterValue is 23
PASS (new X)[3] = 23; setterValue is 23
PASS X = class { get 4() { return 24 } set 4(x) { } }; x = new X; x[4] is 24
PASS X[4] is undefined
Numeric setter on prototype doesn't get called. https://bugs.webkit.org/show_bug.cgi?id=144252 Reviewed by Darin Adler. Source/JavaScriptCore: When switching the blank indexing type to the other one in putByIndex, if the `structure(vm)->needsSlowPutIndexing()` is true, we need to switch it to the slow put indexing type and reloop the putByIndex since there may be some indexing accessor in the prototype chain. Previously, we just set the value into the allocated vector. In the putDirectIndex case, we just store the value to the vector. This is because putDirectIndex is the operation to store the own property and it does not check the accessors in the prototype chain. * runtime/JSObject.cpp: (JSC::JSObject::putByIndexBeyondVectorLength): * tests/stress/injected-numeric-setter-on-prototype.js: Added. (shouldBe): (Trace): (Trace.prototype.trace): (Trace.prototype.get count): (.): * tests/stress/numeric-setter-on-prototype-non-blank-array.js: Added. (shouldBe): (Trace): (Trace.prototype.trace): (Trace.prototype.get count): (.): * tests/stress/numeric-setter-on-prototype.js: Added. (shouldBe): (Trace): (Trace.prototype.trace): (Trace.prototype.get count): (.z.__proto__.set 3): * tests/stress/numeric-setter-on-self.js: Added. (shouldBe): (Trace): (Trace.prototype.trace): (Trace.prototype.get count): (.y.set 2): LayoutTests: Update the test expectation file. * js/class-syntax-string-and-numeric-names-expected.txt: Canonical link: https://commits.webkit.org/165992@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@188269 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-08-11 19:11:55 +00:00
PASS setterValue = 0; X = class { get 5() { } set 5(x) { setterValue = x; } }; (new X)[5] = 25; setterValue is 25
PASS X[5] = 26; setterValue is 25
Class syntax should allow string and numeric identifiers for method names https://bugs.webkit.org/show_bug.cgi?id=144254 Reviewed by Darin Adler. Source/JavaScriptCore: Added the support for string and numeric identifiers in class syntax. * parser/Parser.cpp: (JSC::Parser<LexerType>::parseFunctionInfo): Instead of using ConstructorKind to indicate whether we're inside a class or not, use the newly added SuperBinding argument instead. ConstructorKind is now None outside a class constructor as it should be. (JSC::Parser<LexerType>::parseFunctionDeclaration): (JSC::Parser<LexerType>::parseClass): No longer expects an identifier at the beginning of every class element to allow numeric and string method names. For both of those method names, parse it here instead of parseFunctionInfo since it doesn't support either type. Also pass in SuperBinding::Needed. (JSC::Parser<LexerType>::parsePropertyMethod): Call parseFunctionInfo with SuperBinding::NotNeeded since this function is never used to parse a class method. (JSC::Parser<LexerType>::parseGetterSetter): Pass in superBinding argument to parseFunctionInfo. (JSC::Parser<LexerType>::parsePrimaryExpression): Call parseFunctionInfo with SuperBinding::NotNeeded. * parser/Parser.h: * parser/SyntaxChecker.h: (JSC::SyntaxChecker::createProperty): LayoutTests: Added a test and rebaselined other tests per syntax error message change. * js/class-syntax-declaration-expected.txt: * js/class-syntax-expression-expected.txt: * js/class-syntax-string-and-numeric-names-expected.txt: Added. * js/class-syntax-string-and-numeric-names.html: Added. * js/class-syntax-super-expected.txt: * js/script-tests/class-syntax-declaration.js: * js/script-tests/class-syntax-expression.js: * js/script-tests/class-syntax-string-and-numeric-names.js: Added. * js/script-tests/class-syntax-super.js: Canonical link: https://commits.webkit.org/162546@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183709 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-05-02 02:23:01 +00:00
PASS X = class { static set 6(x) { } static get 6() { return 26 } }; X[6] is 26
PASS (new X)[6] is undefined
PASS setterValue = 0; X = class { static set 7(x) { setterValue = x } static get 7() { } }; X[7] = 27; setterValue is 27
PASS (new X)[7] = 28; setterValue is 27
PASS function x() { return class { 'foo bar'() { return 29; } } }; (new (x()))['foo bar']() is 29
PASS function x() { return class { 30() { return 30; } } }; (new (x()))[30]() is 30
Class syntax should allow string and numeric identifiers for method names https://bugs.webkit.org/show_bug.cgi?id=144254 Reviewed by Darin Adler. Source/JavaScriptCore: Added the support for string and numeric identifiers in class syntax. * parser/Parser.cpp: (JSC::Parser<LexerType>::parseFunctionInfo): Instead of using ConstructorKind to indicate whether we're inside a class or not, use the newly added SuperBinding argument instead. ConstructorKind is now None outside a class constructor as it should be. (JSC::Parser<LexerType>::parseFunctionDeclaration): (JSC::Parser<LexerType>::parseClass): No longer expects an identifier at the beginning of every class element to allow numeric and string method names. For both of those method names, parse it here instead of parseFunctionInfo since it doesn't support either type. Also pass in SuperBinding::Needed. (JSC::Parser<LexerType>::parsePropertyMethod): Call parseFunctionInfo with SuperBinding::NotNeeded since this function is never used to parse a class method. (JSC::Parser<LexerType>::parseGetterSetter): Pass in superBinding argument to parseFunctionInfo. (JSC::Parser<LexerType>::parsePrimaryExpression): Call parseFunctionInfo with SuperBinding::NotNeeded. * parser/Parser.h: * parser/SyntaxChecker.h: (JSC::SyntaxChecker::createProperty): LayoutTests: Added a test and rebaselined other tests per syntax error message change. * js/class-syntax-declaration-expected.txt: * js/class-syntax-expression-expected.txt: * js/class-syntax-string-and-numeric-names-expected.txt: Added. * js/class-syntax-string-and-numeric-names.html: Added. * js/class-syntax-super-expected.txt: * js/script-tests/class-syntax-declaration.js: * js/script-tests/class-syntax-expression.js: * js/script-tests/class-syntax-string-and-numeric-names.js: Added. * js/script-tests/class-syntax-super.js: Canonical link: https://commits.webkit.org/162546@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183709 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-05-02 02:23:01 +00:00
PASS successfullyParsed is true
TEST COMPLETE