haikuwebkit/LayoutTests/js/class-syntax-super-expected...

69 lines
6.2 KiB
Plaintext
Raw Permalink Normal View History

Support extends and super keywords https://bugs.webkit.org/show_bug.cgi?id=142200 Reviewed by Filip Pizlo. Source/JavaScriptCore: Added the support for ES6 class syntax inheritance. Added ConstructorKind as well as boolean flags indicating the constructor kind to various classes in UnlinkedCodeBlock as well as AST nodes. Each method stores the associated class as its homeObjectPrivateName. This value is used to make super calls. * bytecode/UnlinkedCodeBlock.cpp: (JSC::generateFunctionCodeBlock): (JSC::UnlinkedFunctionExecutable::UnlinkedFunctionExecutable): (JSC::UnlinkedCodeBlock::UnlinkedCodeBlock): * bytecode/UnlinkedCodeBlock.h: (JSC::ExecutableInfo::ExecutableInfo): (JSC::UnlinkedFunctionExecutable::constructorKindIsDerived): Added. (JSC::UnlinkedCodeBlock::constructorKindIsDerived): Added. * bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::BytecodeGenerator): Don't emit op_create_this in a derived class as the object is allocated by the highest base class's constructor. Also set "this" to null and store the original value in m_newTargetRegister. "this" is supposed to be in TDZ but that will be implemented in a separate patch. (JSC::BytecodeGenerator::emitReturn): Allow "undefined" to be returned from a derived class. In a derived class's constructor, not returning "undefined" or an object results in a type error instead of "this" being returned. (JSC::BytecodeGenerator::emitThrowTypeError): Added. * bytecompiler/BytecodeGenerator.h: (JSC::BytecodeGenerator::constructorKindIsDerived): Added. (JSC::BytecodeGenerator::newTarget): Added. * bytecompiler/NodesCodegen.cpp: (JSC::SuperNode::emitBytecode): Added. Emits the code to obtain the callee's parent class. (JSC::emitSuperBaseForCallee): Added. Emits the code to obtain the parent class's prototype. (JSC::emitPutHomeObject): Added. (JSC::PropertyListNode::emitBytecode): Stores the home object when adding methods. (JSC::PropertyListNode::emitPutConstantProperty): Ditto. (JSC::BracketAccessorNode::emitBytecode): Added the support for super['foo']. (JSC::DotAccessorNode::emitBytecode): Added the support for super.foo. (JSC::FunctionCallValueNode::emitBytecode): Added the support for super(). (JSC::FunctionCallBracketNode::emitBytecode): Added the support for super['foo'](). (JSC::FunctionCallDotNode::emitBytecode): Added the support for super.foo(). (JSC::DeleteBracketNode::emitBytecode): Forbid "delete super.foo". (JSC::DeleteDotNode::emitBytecode): Forbid "delete super['foo']". (JSC::ClassExprNode::emitBytecode): Added the support for "classHeritage". This is the main logic for inheritance. When a class B inherits from a class A, set B.__proto__ to A and set B.prototype.__proto__ to A.prototype. Throw exceptions when either A or A.__proto__ is not an object. * parser/ASTBuilder.h: (JSC::ASTBuilder::superExpr): Added. * parser/NodeConstructors.h: (JSC::SuperNode::SuperNode): Added. * parser/Nodes.cpp: (JSC::FunctionBodyNode::FunctionBodyNode): * parser/Nodes.h: (JSC::ExpressionNode::isSuperNode): (JSC::PropertyNode::type): (JSC::PropertyNode::needsSuperBinding): * parser/Parser.cpp: (JSC::Parser<LexerType>::parseFunctionBody): (JSC::Parser<LexerType>::parseFunctionInfo): Throw a parser error if super() is used outside of class constructors. (JSC::Parser<LexerType>::parseFunctionDeclaration): (JSC::Parser<LexerType>::parseClass): ConstructorKind is "derived" if and only if the parent class is specified in the declaration / expression. (JSC::Parser<LexerType>::parseGetterSetter): (JSC::Parser<LexerType>::parsePrimaryExpression): (JSC::Parser<LexerType>::parseMemberExpression): Added the support for "super()", "super.foo", and "super['foo']". Throw a semantic error if "super" appears by itself. * parser/Parser.h: (JSC::Scope::Scope): Added m_hasDirectSuper. This variable keeps track of the use of "super()" so that parseFunctionInfo can spit an error if it's used outside of class constructors. (JSC::Scope::hasDirectSuper): Added. (JSC::Scope::setHasDirectSuper): Added. * parser/ParserModes.h: (JSC::ConstructorKind): Added. * parser/SyntaxChecker.h: (JSC::SyntaxChecker::superExpr): Added. * runtime/CommonIdentifiers.h: Added homeObjectPrivateName. * runtime/Executable.h: (JSC::EvalExecutable::executableInfo): (JSC::ProgramExecutable::executableInfo): LayoutTests: Added tests for "extends" and "super" keywords. * TestExpectations: * js/class-syntax-extends-expected.txt: Added. * js/class-syntax-extends.html: Added. * js/class-syntax-super-expected.txt: Added. * js/class-syntax-super.html: Added. * js/script-tests/class-syntax-extends.js: Added. * js/script-tests/class-syntax-super.js: Added. Canonical link: https://commits.webkit.org/160546@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181293 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-03-09 23:47:06 +00:00
Tests for ES6 class syntax "super"
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 (new Base) instanceof Base
PASS (new Derived) instanceof Derived
Invoking super()/super inside of the eval should not lead to SyntaxError https://bugs.webkit.org/show_bug.cgi?id=153864 Reviewed by Saam Barati. Source/JavaScriptCore: Added support of the invoking super/super() inside of the eval within class. Also support cases when eval is invoked in constructor, class method directly or via arrow function. Access to the new.target in eval is not part of this patch and will be implemented in https://bugs.webkit.org/show_bug.cgi?id=155545 * bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::BytecodeGenerator): (JSC::BytecodeGenerator::emitLoadArrowFunctionLexicalEnvironment): (JSC::BytecodeGenerator::isThisUsedInInnerArrowFunction): (JSC::BytecodeGenerator::isNewTargetUsedInInnerArrowFunction): (JSC::BytecodeGenerator::isSuperUsedInInnerArrowFunction): (JSC::BytecodeGenerator::isSuperCallUsedInInnerArrowFunction): (JSC::BytecodeGenerator::emitPutThisToArrowFunctionContextScope): * interpreter/Interpreter.cpp: (JSC::eval): * parser/Parser.cpp: (JSC::Parser<LexerType>::Parser): (JSC::Parser<LexerType>::parseFunctionInfo): (JSC::Parser<LexerType>::parseMemberExpression): * parser/Parser.h: (JSC::Scope::Scope): (JSC::Scope::isEvalContext): (JSC::Scope::setIsEvalContext): (JSC::parse): * runtime/CodeCache.cpp: (JSC::CodeCache::getGlobalCodeBlock): * tests/stress/arrowfunction-lexical-bind-supercall-4.js: * tests/stress/arrowfunction-lexical-bind-superproperty.js: * tests/stress/class-syntax-super-in-eval.js: Added. * tests/stress/generator-with-super.js: LayoutTests: * js/class-syntax-super-expected.txt: * js/script-tests/class-syntax-super.js: Canonical link: https://commits.webkit.org/173693@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@198324 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-03-17 09:46:07 +00:00
PASS (new DerivedWithEval) instanceof DerivedWithEval
Improve error message for uninitialized |this| in derived constructor https://bugs.webkit.org/show_bug.cgi?id=220221 Reviewed by Yusuke Suzuki. JSTests: * stress/async-arrow-functions-lexical-binding-in-class.js: * stress/async-arrow-functions-lexical-super-binding.js: * stress/class-derived-from-null.js: * stress/generator-eval-this.js: * stress/super-property-access-tdz.js: LayoutTests/imported/w3c: * web-platform-tests/custom-elements/parser/parser-fallsback-to-unknown-element-expected.txt: Source/JavaScriptCore: Since class constructors perform `return this;` by default, and derived constructors require `super()` to be called before |this| access, regular TDZ error message is quite confusing, given the following code: `new (class extends Object { constructor() { } });` Considering that currently op_check_tdz is called on thisRegister() only in derived constructors, this patch modifies its slow path to throw a helpful error message that covers |this| access and non-object returns. V8 and SpiderMonkey have similar error messages, mentioning `super()`. slow_path_throw_tdz_error is merged into slow_path_check_tdz, which is invoked from baseline JIT, so we can reliably acquire the bytecode and avoid code duplication. * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/CommonSlowPaths.cpp: (JSC::JSC_DEFINE_COMMON_SLOW_PATH): * runtime/CommonSlowPaths.h: LayoutTests: * js/arrowfunction-supercall-expected.txt: * js/arrowfunction-superproperty-expected.txt: * js/class-syntax-extends-expected.txt: * js/class-syntax-super-expected.txt: * js/script-tests/arrowfunction-supercall.js: * js/script-tests/arrowfunction-superproperty.js: * js/script-tests/class-syntax-super.js: Canonical link: https://commits.webkit.org/232717@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@271120 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-01-02 19:27:42 +00:00
PASS (new DerivedWithEval(true)):::ReferenceError: 'super()' must be called in derived constructor before accessing |this| or returning non-object.
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 (new Derived).callBaseMethod():::baseMethodValue
PASS x = (new Derived).callBaseMethod; x():::baseMethodValue
PASS (new Derived).callBaseMethodInGetter:::baseMethodValue
PASS (new Derived).callBaseMethodInSetter = 1; valueInSetter:::baseMethodValue
PASS (new Derived).baseMethodInGetterSetter:::(new Base).baseMethod
PASS (new Derived).baseMethodInGetterSetter = 1; valueInSetter:::(new Base).baseMethod
PASS Derived.staticMethod():::"base3"
PASS (new SecondDerived).chainMethod().toString():::["base", "derived", "secondDerived"].toString()
PASS x = class extends Base { constructor() { super(); } super() {} }
super should be available in object literals https://bugs.webkit.org/show_bug.cgi?id=156933 Reviewed by Saam Barati. Source/JavaScriptCore: When we originally implemented classes, super seemed to be a class-only feature. But the final spec says it's available in object literals too. * bytecompiler/NodesCodegen.cpp: (JSC::PropertyListNode::emitBytecode): Having 'super' and being a class property are no longer synonymous, so we track two separate variables. (JSC::PropertyListNode::emitPutConstantProperty): Being inside the super branch no longer guarantees that you're a class property, so we decide our attributes and our function name dynamically. * parser/ASTBuilder.h: (JSC::ASTBuilder::createArrowFunctionExpr): (JSC::ASTBuilder::createGetterOrSetterProperty): (JSC::ASTBuilder::createArguments): (JSC::ASTBuilder::createArgumentsList): (JSC::ASTBuilder::createProperty): (JSC::ASTBuilder::createPropertyList): Pass through state to indicate whether we're a class property, since we can't infer it from 'super' anymore. * parser/NodeConstructors.h: (JSC::PropertyNode::PropertyNode): See ASTBuilder.h. * parser/Nodes.h: (JSC::PropertyNode::expressionName): (JSC::PropertyNode::name): (JSC::PropertyNode::type): (JSC::PropertyNode::needsSuperBinding): (JSC::PropertyNode::isClassProperty): (JSC::PropertyNode::putType): See ASTBuilder.h. * parser/Parser.cpp: (JSC::Parser<LexerType>::parseFunctionInfo): (JSC::Parser<LexerType>::parseClass): (JSC::Parser<LexerType>::parseProperty): (JSC::Parser<LexerType>::parsePropertyMethod): (JSC::Parser<LexerType>::parseGetterSetter): (JSC::Parser<LexerType>::parseMemberExpression): I made these error messages generic because it is no longer practical to say concise things about the list of places you can use super. * parser/Parser.h: * parser/SyntaxChecker.h: (JSC::SyntaxChecker::createArgumentsList): (JSC::SyntaxChecker::createProperty): (JSC::SyntaxChecker::appendExportSpecifier): (JSC::SyntaxChecker::appendConstDecl): (JSC::SyntaxChecker::createGetterOrSetterProperty): Updated for interface change. * tests/stress/generator-with-super.js: (test): * tests/stress/modules-syntax-error.js: * tests/stress/super-in-lexical-scope.js: (testSyntaxError): (testSyntaxError.test): * tests/stress/tagged-templates-syntax.js: Updated for error message changes. See Parser.cpp. LayoutTests: Updated expected results and added a few new tests. * js/arrowfunction-syntax-errors-expected.txt: * js/class-syntax-super-expected.txt: * js/object-literal-methods-expected.txt: * js/script-tests/arrowfunction-syntax-errors.js: * js/script-tests/class-syntax-super.js: * js/script-tests/object-literal-methods.js: Canonical link: https://commits.webkit.org/175044@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@199927 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-04-22 23:04:55 +00:00
PASS x = class extends Base { constructor() { super(); } method() { super() } }:::SyntaxError: super is not valid in this context.
PASS x = class extends Base { constructor() { super(); } method() { super } }:::SyntaxError: super is not valid in this context.
PASS x = class extends Base { constructor() { super(); } method() { return new super } }:::SyntaxError: Cannot use new with super call.
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 x = class extends Base { constructor() { super(); } method1() { delete (super.foo) } method2() { delete super["foo"] } }
PASS (new x).method1():::ReferenceError: Cannot delete a super property
PASS (new x).method2():::ReferenceError: Cannot delete a super property
PASS (new (class { constructor() { super.property = "ABC"; } })).property === "ABC"
PASS (new (class extends Base { constructor() { super(); super.property = "ABC"; } })).property === "ABC"
PASS (new (class { constructor() { var arr = () => super.property = "ABC"; arr(); } })).property === "ABC"
PASS (new (class { constructor() { var async_arr = async () => super.property = "ABC"; async_arr(); } })).property === "ABC"
PASS (new (class { constructor() { eval('super.property = "ABC"'); } })).property === "ABC"
PASS (new (class { constructor() { var arr = () => eval('super.property = "ABC"'); arr(); } })).property === "ABC"
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 new (class { constructor() { return undefined; } }) instanceof Object
PASS new (class { constructor() { return 1; } }) instanceof Object
Improve error message for uninitialized |this| in derived constructor https://bugs.webkit.org/show_bug.cgi?id=220221 Reviewed by Yusuke Suzuki. JSTests: * stress/async-arrow-functions-lexical-binding-in-class.js: * stress/async-arrow-functions-lexical-super-binding.js: * stress/class-derived-from-null.js: * stress/generator-eval-this.js: * stress/super-property-access-tdz.js: LayoutTests/imported/w3c: * web-platform-tests/custom-elements/parser/parser-fallsback-to-unknown-element-expected.txt: Source/JavaScriptCore: Since class constructors perform `return this;` by default, and derived constructors require `super()` to be called before |this| access, regular TDZ error message is quite confusing, given the following code: `new (class extends Object { constructor() { } });` Considering that currently op_check_tdz is called on thisRegister() only in derived constructors, this patch modifies its slow path to throw a helpful error message that covers |this| access and non-object returns. V8 and SpiderMonkey have similar error messages, mentioning `super()`. slow_path_throw_tdz_error is merged into slow_path_check_tdz, which is invoked from baseline JIT, so we can reliably acquire the bytecode and avoid code duplication. * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/CommonSlowPaths.cpp: (JSC::JSC_DEFINE_COMMON_SLOW_PATH): * runtime/CommonSlowPaths.h: LayoutTests: * js/arrowfunction-supercall-expected.txt: * js/arrowfunction-superproperty-expected.txt: * js/class-syntax-extends-expected.txt: * js/class-syntax-super-expected.txt: * js/script-tests/arrowfunction-supercall.js: * js/script-tests/arrowfunction-superproperty.js: * js/script-tests/class-syntax-super.js: Canonical link: https://commits.webkit.org/232717@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@271120 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-01-02 19:27:42 +00:00
PASS new (class extends Base { constructor() { return undefined } }):::ReferenceError: 'super()' must be called in derived constructor before accessing |this| or returning non-object.
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 new (class extends Base { constructor() { super(); return undefined } }) instanceof Object
PASS x = { }; new (class extends Base { constructor() { return x } });:::x
PASS x instanceof Base
Improve error message for uninitialized |this| in derived constructor https://bugs.webkit.org/show_bug.cgi?id=220221 Reviewed by Yusuke Suzuki. JSTests: * stress/async-arrow-functions-lexical-binding-in-class.js: * stress/async-arrow-functions-lexical-super-binding.js: * stress/class-derived-from-null.js: * stress/generator-eval-this.js: * stress/super-property-access-tdz.js: LayoutTests/imported/w3c: * web-platform-tests/custom-elements/parser/parser-fallsback-to-unknown-element-expected.txt: Source/JavaScriptCore: Since class constructors perform `return this;` by default, and derived constructors require `super()` to be called before |this| access, regular TDZ error message is quite confusing, given the following code: `new (class extends Object { constructor() { } });` Considering that currently op_check_tdz is called on thisRegister() only in derived constructors, this patch modifies its slow path to throw a helpful error message that covers |this| access and non-object returns. V8 and SpiderMonkey have similar error messages, mentioning `super()`. slow_path_throw_tdz_error is merged into slow_path_check_tdz, which is invoked from baseline JIT, so we can reliably acquire the bytecode and avoid code duplication. * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/CommonSlowPaths.cpp: (JSC::JSC_DEFINE_COMMON_SLOW_PATH): * runtime/CommonSlowPaths.h: LayoutTests: * js/arrowfunction-supercall-expected.txt: * js/arrowfunction-superproperty-expected.txt: * js/class-syntax-extends-expected.txt: * js/class-syntax-super-expected.txt: * js/script-tests/arrowfunction-supercall.js: * js/script-tests/arrowfunction-superproperty.js: * js/script-tests/class-syntax-super.js: Canonical link: https://commits.webkit.org/232717@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@271120 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-01-02 19:27:42 +00:00
PASS new (class extends Base { constructor() { } }):::ReferenceError: 'super()' must be called in derived constructor before accessing |this| or returning non-object.
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 new (class extends Base { constructor() { return 1; } }):::TypeError: Cannot return a non-object type in the constructor of a derived class.
Improve error message for uninitialized |this| in derived constructor https://bugs.webkit.org/show_bug.cgi?id=220221 Reviewed by Yusuke Suzuki. JSTests: * stress/async-arrow-functions-lexical-binding-in-class.js: * stress/async-arrow-functions-lexical-super-binding.js: * stress/class-derived-from-null.js: * stress/generator-eval-this.js: * stress/super-property-access-tdz.js: LayoutTests/imported/w3c: * web-platform-tests/custom-elements/parser/parser-fallsback-to-unknown-element-expected.txt: Source/JavaScriptCore: Since class constructors perform `return this;` by default, and derived constructors require `super()` to be called before |this| access, regular TDZ error message is quite confusing, given the following code: `new (class extends Object { constructor() { } });` Considering that currently op_check_tdz is called on thisRegister() only in derived constructors, this patch modifies its slow path to throw a helpful error message that covers |this| access and non-object returns. V8 and SpiderMonkey have similar error messages, mentioning `super()`. slow_path_throw_tdz_error is merged into slow_path_check_tdz, which is invoked from baseline JIT, so we can reliably acquire the bytecode and avoid code duplication. * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/CommonSlowPaths.cpp: (JSC::JSC_DEFINE_COMMON_SLOW_PATH): * runtime/CommonSlowPaths.h: LayoutTests: * js/arrowfunction-supercall-expected.txt: * js/arrowfunction-superproperty-expected.txt: * js/class-syntax-extends-expected.txt: * js/class-syntax-super-expected.txt: * js/script-tests/arrowfunction-supercall.js: * js/script-tests/arrowfunction-superproperty.js: * js/script-tests/class-syntax-super.js: Canonical link: https://commits.webkit.org/232717@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@271120 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-01-02 19:27:42 +00:00
PASS new (class extends null { constructor() { return undefined } }):::ReferenceError: 'super()' must be called in derived constructor before accessing |this| or returning non-object.
PASS new (class extends null { constructor() { super(); return undefined } }):::TypeError: function is not a constructor (evaluating 'super()')
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 x = { }; new (class extends null { constructor() { return x } });:::x
PASS x instanceof Object
Improve error message for uninitialized |this| in derived constructor https://bugs.webkit.org/show_bug.cgi?id=220221 Reviewed by Yusuke Suzuki. JSTests: * stress/async-arrow-functions-lexical-binding-in-class.js: * stress/async-arrow-functions-lexical-super-binding.js: * stress/class-derived-from-null.js: * stress/generator-eval-this.js: * stress/super-property-access-tdz.js: LayoutTests/imported/w3c: * web-platform-tests/custom-elements/parser/parser-fallsback-to-unknown-element-expected.txt: Source/JavaScriptCore: Since class constructors perform `return this;` by default, and derived constructors require `super()` to be called before |this| access, regular TDZ error message is quite confusing, given the following code: `new (class extends Object { constructor() { } });` Considering that currently op_check_tdz is called on thisRegister() only in derived constructors, this patch modifies its slow path to throw a helpful error message that covers |this| access and non-object returns. V8 and SpiderMonkey have similar error messages, mentioning `super()`. slow_path_throw_tdz_error is merged into slow_path_check_tdz, which is invoked from baseline JIT, so we can reliably acquire the bytecode and avoid code duplication. * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/CommonSlowPaths.cpp: (JSC::JSC_DEFINE_COMMON_SLOW_PATH): * runtime/CommonSlowPaths.h: LayoutTests: * js/arrowfunction-supercall-expected.txt: * js/arrowfunction-superproperty-expected.txt: * js/class-syntax-extends-expected.txt: * js/class-syntax-super-expected.txt: * js/script-tests/arrowfunction-supercall.js: * js/script-tests/arrowfunction-superproperty.js: * js/script-tests/class-syntax-super.js: Canonical link: https://commits.webkit.org/232717@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@271120 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-01-02 19:27:42 +00:00
PASS new (class extends null { constructor() { } }):::ReferenceError: 'super()' must be called in derived constructor before accessing |this| or returning non-object.
PASS new (class extends null { constructor() { return 1; } }):::TypeError: Cannot return a non-object type in the constructor of a derived class.
PASS new (class extends null { constructor() { super() } }):::TypeError: function is not a constructor (evaluating 'super()')
super should be available in object literals https://bugs.webkit.org/show_bug.cgi?id=156933 Reviewed by Saam Barati. Source/JavaScriptCore: When we originally implemented classes, super seemed to be a class-only feature. But the final spec says it's available in object literals too. * bytecompiler/NodesCodegen.cpp: (JSC::PropertyListNode::emitBytecode): Having 'super' and being a class property are no longer synonymous, so we track two separate variables. (JSC::PropertyListNode::emitPutConstantProperty): Being inside the super branch no longer guarantees that you're a class property, so we decide our attributes and our function name dynamically. * parser/ASTBuilder.h: (JSC::ASTBuilder::createArrowFunctionExpr): (JSC::ASTBuilder::createGetterOrSetterProperty): (JSC::ASTBuilder::createArguments): (JSC::ASTBuilder::createArgumentsList): (JSC::ASTBuilder::createProperty): (JSC::ASTBuilder::createPropertyList): Pass through state to indicate whether we're a class property, since we can't infer it from 'super' anymore. * parser/NodeConstructors.h: (JSC::PropertyNode::PropertyNode): See ASTBuilder.h. * parser/Nodes.h: (JSC::PropertyNode::expressionName): (JSC::PropertyNode::name): (JSC::PropertyNode::type): (JSC::PropertyNode::needsSuperBinding): (JSC::PropertyNode::isClassProperty): (JSC::PropertyNode::putType): See ASTBuilder.h. * parser/Parser.cpp: (JSC::Parser<LexerType>::parseFunctionInfo): (JSC::Parser<LexerType>::parseClass): (JSC::Parser<LexerType>::parseProperty): (JSC::Parser<LexerType>::parsePropertyMethod): (JSC::Parser<LexerType>::parseGetterSetter): (JSC::Parser<LexerType>::parseMemberExpression): I made these error messages generic because it is no longer practical to say concise things about the list of places you can use super. * parser/Parser.h: * parser/SyntaxChecker.h: (JSC::SyntaxChecker::createArgumentsList): (JSC::SyntaxChecker::createProperty): (JSC::SyntaxChecker::appendExportSpecifier): (JSC::SyntaxChecker::appendConstDecl): (JSC::SyntaxChecker::createGetterOrSetterProperty): Updated for interface change. * tests/stress/generator-with-super.js: (test): * tests/stress/modules-syntax-error.js: * tests/stress/super-in-lexical-scope.js: (testSyntaxError): (testSyntaxError.test): * tests/stress/tagged-templates-syntax.js: Updated for error message changes. See Parser.cpp. LayoutTests: Updated expected results and added a few new tests. * js/arrowfunction-syntax-errors-expected.txt: * js/class-syntax-super-expected.txt: * js/object-literal-methods-expected.txt: * js/script-tests/arrowfunction-syntax-errors.js: * js/script-tests/class-syntax-super.js: * js/script-tests/object-literal-methods.js: Canonical link: https://commits.webkit.org/175044@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@199927 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-04-22 23:04:55 +00:00
PASS new (class { constructor() { super() } }):::SyntaxError: super is not valid in this context.
PASS function x() { super(); }:::SyntaxError: super is not valid in this context.
PASS new (class extends Object { constructor() { function x() { super() } } }):::SyntaxError: super is not valid in this context.
PASS new (class extends Object { constructor() { function x() { super.method } } }):::SyntaxError: super is not valid in this context.
PASS function x() { super.method(); }:::SyntaxError: super is not valid in this context.
PASS function x() { super(); }:::SyntaxError: super is not valid in this context.
PASS eval("super.method()"):::SyntaxError: super is not valid in this context.
PASS eval("super()"):::SyntaxError: super is not valid in this context.
PASS (function () { eval("super.method()");})():::SyntaxError: super is not valid in this context.
PASS (function () { eval("super()");})():::SyntaxError: super is not valid in this context.
PASS new (class { constructor() { (function () { eval("super()");})(); } }):::SyntaxError: super is not valid in this context.
PASS (new (class { method() { (function () { eval("super.method()");})(); }})).method():::SyntaxError: super is not valid in this context.
calling super() a second time in a constructor should throw https://bugs.webkit.org/show_bug.cgi?id=151113 Reviewed by Saam Barati and Keith Miller. Source/JavaScriptCore: Currently, our implementation checks if 'super()' was called in a constructor more than once and raises a RuntimeError before the second call. According to the spec we need to raise an error just after the second super() is finished and before the new 'this' is assigned https://esdiscuss.org/topic/duplicate-super-call-behaviour. To implement this behavior this patch adds a new op code, op_is_empty, that is used to check if 'this' is empty. * bytecode/BytecodeList.json: * bytecode/BytecodeUseDef.h: (JSC::computeUsesForBytecodeOffset): (JSC::computeDefsForBytecodeOffset): * bytecode/CodeBlock.cpp: (JSC::CodeBlock::dumpBytecode): * bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::emitIsEmpty): * bytecompiler/BytecodeGenerator.h: * bytecompiler/NodesCodegen.cpp: (JSC::FunctionCallValueNode::emitBytecode): * dfg/DFGAbstractInterpreterInlines.h: (JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects): * dfg/DFGByteCodeParser.cpp: (JSC::DFG::ByteCodeParser::parseBlock): * dfg/DFGCapabilities.cpp: (JSC::DFG::capabilityLevel): * dfg/DFGClobberize.h: (JSC::DFG::clobberize): * dfg/DFGDoesGC.cpp: (JSC::DFG::doesGC): * dfg/DFGFixupPhase.cpp: (JSC::DFG::FixupPhase::fixupNode): * dfg/DFGNodeType.h: * dfg/DFGPredictionPropagationPhase.cpp: * dfg/DFGSafeToExecute.h: (JSC::DFG::safeToExecute): * dfg/DFGSpeculativeJIT32_64.cpp: (JSC::DFG::SpeculativeJIT::compile): * dfg/DFGSpeculativeJIT64.cpp: (JSC::DFG::SpeculativeJIT::compile): * ftl/FTLCapabilities.cpp: (JSC::FTL::canCompile): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::compileNode): (JSC::FTL::DFG::LowerDFGToB3::compileIsEmpty): * jit/JIT.cpp: (JSC::JIT::privateCompileMainPass): * jit/JIT.h: * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_is_empty): * jit/JITOpcodes32_64.cpp: (JSC::JIT::emit_op_is_empty): * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * tests/stress/class-syntax-double-constructor.js: Added. LayoutTests: * js/class-syntax-super-expected.txt: * js/script-tests/class-syntax-super.js: Canonical link: https://commits.webkit.org/175157@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200102 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-04-26 18:40:41 +00:00
PASS new (class extends Base { constructor() { super(); super();}}):::ReferenceError: 'super()' can't be called more than once in a constructor.
Improve error message for uninitialized |this| in derived constructor https://bugs.webkit.org/show_bug.cgi?id=220221 Reviewed by Yusuke Suzuki. JSTests: * stress/async-arrow-functions-lexical-binding-in-class.js: * stress/async-arrow-functions-lexical-super-binding.js: * stress/class-derived-from-null.js: * stress/generator-eval-this.js: * stress/super-property-access-tdz.js: LayoutTests/imported/w3c: * web-platform-tests/custom-elements/parser/parser-fallsback-to-unknown-element-expected.txt: Source/JavaScriptCore: Since class constructors perform `return this;` by default, and derived constructors require `super()` to be called before |this| access, regular TDZ error message is quite confusing, given the following code: `new (class extends Object { constructor() { } });` Considering that currently op_check_tdz is called on thisRegister() only in derived constructors, this patch modifies its slow path to throw a helpful error message that covers |this| access and non-object returns. V8 and SpiderMonkey have similar error messages, mentioning `super()`. slow_path_throw_tdz_error is merged into slow_path_check_tdz, which is invoked from baseline JIT, so we can reliably acquire the bytecode and avoid code duplication. * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/CommonSlowPaths.cpp: (JSC::JSC_DEFINE_COMMON_SLOW_PATH): * runtime/CommonSlowPaths.h: LayoutTests: * js/arrowfunction-supercall-expected.txt: * js/arrowfunction-superproperty-expected.txt: * js/class-syntax-extends-expected.txt: * js/class-syntax-super-expected.txt: * js/script-tests/arrowfunction-supercall.js: * js/script-tests/arrowfunction-superproperty.js: * js/script-tests/class-syntax-super.js: Canonical link: https://commits.webkit.org/232717@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@271120 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-01-02 19:27:42 +00:00
PASS (new class D extends class { m() {}} { constructor() { eval('super["m"]()') } }):::ReferenceError: 'super()' must be called in derived constructor before accessing |this| or returning non-object.
PASS new class extends class { m() {}} { constructor() { super["m"](super()) } }:::ReferenceError: 'super()' must be called in derived constructor before accessing |this| or returning non-object.
PASS (new class D extends class { m() {}} { constructor(f) { super[f()]() } }(()=>"m")):::ReferenceError: 'super()' must be called in derived constructor before accessing |this| or returning non-object.
PASS (new class D extends class { m() {}} { constructor() { super(); eval('super["m"]()') } })
PASS new class extends class { m() {}} { constructor() { super(); super["m"](super()) } }:::ReferenceError: 'super()' can't be called more than once in a constructor.
PASS (new class D extends class { m() {}} { constructor(f) { super(); super[f()]() } }(()=>"m"))
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 successfullyParsed
Support extends and super keywords https://bugs.webkit.org/show_bug.cgi?id=142200 Reviewed by Filip Pizlo. Source/JavaScriptCore: Added the support for ES6 class syntax inheritance. Added ConstructorKind as well as boolean flags indicating the constructor kind to various classes in UnlinkedCodeBlock as well as AST nodes. Each method stores the associated class as its homeObjectPrivateName. This value is used to make super calls. * bytecode/UnlinkedCodeBlock.cpp: (JSC::generateFunctionCodeBlock): (JSC::UnlinkedFunctionExecutable::UnlinkedFunctionExecutable): (JSC::UnlinkedCodeBlock::UnlinkedCodeBlock): * bytecode/UnlinkedCodeBlock.h: (JSC::ExecutableInfo::ExecutableInfo): (JSC::UnlinkedFunctionExecutable::constructorKindIsDerived): Added. (JSC::UnlinkedCodeBlock::constructorKindIsDerived): Added. * bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::BytecodeGenerator): Don't emit op_create_this in a derived class as the object is allocated by the highest base class's constructor. Also set "this" to null and store the original value in m_newTargetRegister. "this" is supposed to be in TDZ but that will be implemented in a separate patch. (JSC::BytecodeGenerator::emitReturn): Allow "undefined" to be returned from a derived class. In a derived class's constructor, not returning "undefined" or an object results in a type error instead of "this" being returned. (JSC::BytecodeGenerator::emitThrowTypeError): Added. * bytecompiler/BytecodeGenerator.h: (JSC::BytecodeGenerator::constructorKindIsDerived): Added. (JSC::BytecodeGenerator::newTarget): Added. * bytecompiler/NodesCodegen.cpp: (JSC::SuperNode::emitBytecode): Added. Emits the code to obtain the callee's parent class. (JSC::emitSuperBaseForCallee): Added. Emits the code to obtain the parent class's prototype. (JSC::emitPutHomeObject): Added. (JSC::PropertyListNode::emitBytecode): Stores the home object when adding methods. (JSC::PropertyListNode::emitPutConstantProperty): Ditto. (JSC::BracketAccessorNode::emitBytecode): Added the support for super['foo']. (JSC::DotAccessorNode::emitBytecode): Added the support for super.foo. (JSC::FunctionCallValueNode::emitBytecode): Added the support for super(). (JSC::FunctionCallBracketNode::emitBytecode): Added the support for super['foo'](). (JSC::FunctionCallDotNode::emitBytecode): Added the support for super.foo(). (JSC::DeleteBracketNode::emitBytecode): Forbid "delete super.foo". (JSC::DeleteDotNode::emitBytecode): Forbid "delete super['foo']". (JSC::ClassExprNode::emitBytecode): Added the support for "classHeritage". This is the main logic for inheritance. When a class B inherits from a class A, set B.__proto__ to A and set B.prototype.__proto__ to A.prototype. Throw exceptions when either A or A.__proto__ is not an object. * parser/ASTBuilder.h: (JSC::ASTBuilder::superExpr): Added. * parser/NodeConstructors.h: (JSC::SuperNode::SuperNode): Added. * parser/Nodes.cpp: (JSC::FunctionBodyNode::FunctionBodyNode): * parser/Nodes.h: (JSC::ExpressionNode::isSuperNode): (JSC::PropertyNode::type): (JSC::PropertyNode::needsSuperBinding): * parser/Parser.cpp: (JSC::Parser<LexerType>::parseFunctionBody): (JSC::Parser<LexerType>::parseFunctionInfo): Throw a parser error if super() is used outside of class constructors. (JSC::Parser<LexerType>::parseFunctionDeclaration): (JSC::Parser<LexerType>::parseClass): ConstructorKind is "derived" if and only if the parent class is specified in the declaration / expression. (JSC::Parser<LexerType>::parseGetterSetter): (JSC::Parser<LexerType>::parsePrimaryExpression): (JSC::Parser<LexerType>::parseMemberExpression): Added the support for "super()", "super.foo", and "super['foo']". Throw a semantic error if "super" appears by itself. * parser/Parser.h: (JSC::Scope::Scope): Added m_hasDirectSuper. This variable keeps track of the use of "super()" so that parseFunctionInfo can spit an error if it's used outside of class constructors. (JSC::Scope::hasDirectSuper): Added. (JSC::Scope::setHasDirectSuper): Added. * parser/ParserModes.h: (JSC::ConstructorKind): Added. * parser/SyntaxChecker.h: (JSC::SyntaxChecker::superExpr): Added. * runtime/CommonIdentifiers.h: Added homeObjectPrivateName. * runtime/Executable.h: (JSC::EvalExecutable::executableInfo): (JSC::ProgramExecutable::executableInfo): LayoutTests: Added tests for "extends" and "super" keywords. * TestExpectations: * js/class-syntax-extends-expected.txt: Added. * js/class-syntax-extends.html: Added. * js/class-syntax-super-expected.txt: Added. * js/class-syntax-super.html: Added. * js/script-tests/class-syntax-extends.js: Added. * js/script-tests/class-syntax-super.js: Added. Canonical link: https://commits.webkit.org/160546@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181293 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-03-09 23:47:06 +00:00
TEST COMPLETE