haikuwebkit/LayoutTests/js/arrowfunction-supercall-exp...

33 lines
2.1 KiB
Plaintext
Raw Permalink Normal View History

[ES6] "super" and "this" should be lexically bound inside an arrow function and should live in a JSLexicalEnvironment https://bugs.webkit.org/show_bug.cgi?id=149338 Source/JavaScriptCore: Patch by Aleksandr Skachkov <gskachkov@gmail.com> on 2015-12-05 Reviewed by Saam Barati. Implemented new version of the lexically bound 'this' in arrow function. In current version 'this' is stored inside of the lexical environment of the function. To store and load we use op_get_from_scope and op_put_to_scope operations. Also new implementation prevent raising TDZ error for arrow functions that are declared before super() but invoke after. * builtins/BuiltinExecutables.cpp: (JSC::createExecutableInternal): * bytecode/BytecodeList.json: * bytecode/BytecodeUseDef.h: * bytecode/CodeBlock.cpp: (JSC::CodeBlock::dumpBytecode): * bytecode/EvalCodeCache.h: (JSC::EvalCodeCache::getSlow): * bytecode/ExecutableInfo.h: (JSC::ExecutableInfo::ExecutableInfo): (JSC::ExecutableInfo::isDerivedConstructorContext): (JSC::ExecutableInfo::isArrowFunctionContext): * bytecode/UnlinkedCodeBlock.cpp: (JSC::UnlinkedCodeBlock::UnlinkedCodeBlock): * bytecode/UnlinkedCodeBlock.h: (JSC::UnlinkedCodeBlock::isArrowFunction): (JSC::UnlinkedCodeBlock::isDerivedConstructorContext): (JSC::UnlinkedCodeBlock::isArrowFunctionContext): * bytecode/UnlinkedFunctionExecutable.cpp: (JSC::generateUnlinkedFunctionCodeBlock): (JSC::UnlinkedFunctionExecutable::UnlinkedFunctionExecutable): * bytecode/UnlinkedFunctionExecutable.h: * bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::BytecodeGenerator): (JSC::BytecodeGenerator::initializeArrowFunctionContextScopeIfNeeded): (JSC::BytecodeGenerator::variable): (JSC::BytecodeGenerator::emitNewArrowFunctionExpression): (JSC::BytecodeGenerator::emitLoadArrowFunctionLexicalEnvironment): (JSC::BytecodeGenerator::emitLoadThisFromArrowFunctionLexicalEnvironment): (JSC::BytecodeGenerator::emitLoadNewTargetFromArrowFunctionLexicalEnvironment): (JSC::BytecodeGenerator::emitLoadDerivedConstructorFromArrowFunctionLexicalEnvironment): (JSC::BytecodeGenerator::emitPutNewTargetToArrowFunctionContextScope): (JSC::BytecodeGenerator::emitPutDerivedConstructorToArrowFunctionContextScope): (JSC::BytecodeGenerator::emitPutThisToArrowFunctionContextScope): * bytecompiler/BytecodeGenerator.h: (JSC::BytecodeGenerator::isDerivedConstructorContext): (JSC::BytecodeGenerator::usesArrowFunction): (JSC::BytecodeGenerator::needsToUpdateArrowFunctionContext): (JSC::BytecodeGenerator::usesEval): (JSC::BytecodeGenerator::usesThis): (JSC::BytecodeGenerator::newTarget): (JSC::BytecodeGenerator::makeFunction): * bytecompiler/NodesCodegen.cpp: (JSC::ThisNode::emitBytecode): (JSC::SuperNode::emitBytecode): (JSC::EvalFunctionCallNode::emitBytecode): (JSC::FunctionCallValueNode::emitBytecode): (JSC::FunctionNode::emitBytecode): * debugger/DebuggerCallFrame.cpp: (JSC::DebuggerCallFrame::evaluate): * dfg/DFGAbstractInterpreterInlines.h: * dfg/DFGByteCodeParser.cpp: (JSC::DFG::ByteCodeParser::parseBlock): * dfg/DFGCapabilities.cpp: * dfg/DFGClobberize.h: * dfg/DFGDoesGC.cpp: * dfg/DFGFixupPhase.cpp: * dfg/DFGNodeType.h: * dfg/DFGObjectAllocationSinkingPhase.cpp: * dfg/DFGPredictionPropagationPhase.cpp: * dfg/DFGPromotedHeapLocation.cpp: * dfg/DFGPromotedHeapLocation.h: * dfg/DFGSafeToExecute.h: * dfg/DFGSpeculativeJIT.cpp: * dfg/DFGSpeculativeJIT.h: * dfg/DFGSpeculativeJIT32_64.cpp: * dfg/DFGSpeculativeJIT64.cpp: * ftl/FTLCapabilities.cpp: * ftl/FTLLowerDFGToLLVM.cpp: * ftl/FTLOperations.cpp: (JSC::FTL::operationMaterializeObjectInOSR): * interpreter/Interpreter.cpp: (JSC::eval): * jit/JIT.cpp: * jit/JIT.h: * jit/JITOpcodes.cpp: (JSC::JIT::emitNewFuncExprCommon): * jit/JITOpcodes32_64.cpp: * llint/LLIntSlowPaths.cpp: (JSC::LLInt::LLINT_SLOW_PATH_DECL): * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * parser/ASTBuilder.h: (JSC::ASTBuilder::createArrowFunctionExpr): (JSC::ASTBuilder::usesArrowFunction): * parser/Nodes.h: (JSC::ScopeNode::usesArrowFunction): * parser/Parser.cpp: (JSC::Parser<LexerType>::parseFunctionInfo): * parser/ParserModes.h: * runtime/CodeCache.cpp: (JSC::CodeCache::getGlobalCodeBlock): (JSC::CodeCache::getProgramCodeBlock): (JSC::CodeCache::getEvalCodeBlock): (JSC::CodeCache::getModuleProgramCodeBlock): (JSC::CodeCache::getFunctionExecutableFromGlobalCode): * runtime/CodeCache.h: * runtime/CommonIdentifiers.h: * runtime/CommonSlowPaths.cpp: (JSC::SLOW_PATH_DECL): * runtime/Executable.cpp: (JSC::ScriptExecutable::ScriptExecutable): (JSC::EvalExecutable::create): (JSC::EvalExecutable::EvalExecutable): (JSC::ProgramExecutable::ProgramExecutable): (JSC::ModuleProgramExecutable::ModuleProgramExecutable): (JSC::FunctionExecutable::FunctionExecutable): * runtime/Executable.h: (JSC::ScriptExecutable::isArrowFunctionContext): (JSC::ScriptExecutable::isDerivedConstructorContext): * runtime/JSGlobalObject.cpp: (JSC::JSGlobalObject::createEvalCodeBlock): * runtime/JSGlobalObject.h: * runtime/JSGlobalObjectFunctions.cpp: (JSC::globalFuncEval): * tests/es6.yaml: * tests/stress/arrowfunction-activation-sink-osrexit.js: * tests/stress/arrowfunction-activation-sink.js: * tests/stress/arrowfunction-lexical-bind-newtarget.js: Added. * tests/stress/arrowfunction-lexical-bind-supercall-1.js: Added. * tests/stress/arrowfunction-lexical-bind-supercall-2.js: Added. * tests/stress/arrowfunction-lexical-bind-supercall-3.js: Added. * tests/stress/arrowfunction-lexical-bind-supercall-4.js: Added. * tests/stress/arrowfunction-lexical-bind-this-1.js: * tests/stress/arrowfunction-lexical-bind-this-7.js: Added. * tests/stress/arrowfunction-tdz-1.js: Added. * tests/stress/arrowfunction-tdz-2.js: Added. * tests/stress/arrowfunction-tdz-3.js: Added. * tests/stress/arrowfunction-tdz-4.js: Added. * tests/stress/arrowfunction-tdz.js: Removed. LayoutTests: Patch by Skachkov Oleksandr <gskachkov@gmail.com> on 2015-12-08 Reviewed by Saam Barati. * js/arrowfunction-supercall-expected.txt: Added. * js/arrowfunction-supercall.html: Added. * js/arrowfunction-tdz-expected.txt: Added new expectation. * js/script-tests/arrowfunction-supercall.js: Added. * js/script-tests/arrowfunction-tdz.js: Added new cases. Canonical link: https://commits.webkit.org/170152@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@193766 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-12-08 20:24:04 +00:00
Tests for ES6 arrow function, calling of the super in arrow function
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS isReferenceError is true
PASS b.id is value
PASS isReferenceError is true
PASS d1.id is "b"
PASS d2.id is value
PASS (new D()).id is value
PASS (new E(false)).id is value
PASS typeof (new E(true)).id is 'undefined'
PASS (new F(false)).id is value
PASS typeof (new F(true)).id is 'undefined'
PASS indexOfParentClassInStackError < indexOfnestedArrowInStackError is true
PASS indexOfnestedArrowInStackError < indexOfarrowInChildConstructorInStackError is true
PASS indexOfarrowInChildConstructorInStackError < indexOfChildClassInStackError is true
PASS indexOfChildClassInStackError > 0 is true
PASS indexOfParentClassInStackError > -1 && errorStack.indexOf('ParentClass', indexOfParentClassInStackError + 1) === -1 is true
PASS indexOfnestedArrowInStackError > -1 && errorStack.indexOf('nestedArrow', indexOfnestedArrowInStackError + 1) === -1 is true
PASS indexOfarrowInChildConstructorInStackError > -1 && errorStack.indexOf('arrowInChildConstructor', indexOfarrowInChildConstructorInStackError + 1) === -1 is true
PASS indexOfChildClassInStackError > -1 && errorStack.indexOf('ChildClass', indexOfChildClassInStackError + 1) === -1 is true
PASS (new class extends A { constructor() { ((a = super())=>{})() } }).id is value
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 A { constructor() { ((a = this)=>{ return a; })() } }) threw exception ReferenceError: 'super()' must be called in derived constructor before accessing |this| or returning non-object..
PASS (new class extends A { constructor() { ((a = this, b=super())=>{ return a; })() } }) threw exception ReferenceError: 'super()' must be called in derived constructor before accessing |this| or returning non-object..
PASS (new class extends A { constructor() { ((a = new.target)=>{ return a; })(); super(); } }) did not throw exception.
PASS (new class extends A { constructor() { ((a = new.target, b=super())=>{ return a; })() } }) did not throw exception.
[ES6] "super" and "this" should be lexically bound inside an arrow function and should live in a JSLexicalEnvironment https://bugs.webkit.org/show_bug.cgi?id=149338 Source/JavaScriptCore: Patch by Aleksandr Skachkov <gskachkov@gmail.com> on 2015-12-05 Reviewed by Saam Barati. Implemented new version of the lexically bound 'this' in arrow function. In current version 'this' is stored inside of the lexical environment of the function. To store and load we use op_get_from_scope and op_put_to_scope operations. Also new implementation prevent raising TDZ error for arrow functions that are declared before super() but invoke after. * builtins/BuiltinExecutables.cpp: (JSC::createExecutableInternal): * bytecode/BytecodeList.json: * bytecode/BytecodeUseDef.h: * bytecode/CodeBlock.cpp: (JSC::CodeBlock::dumpBytecode): * bytecode/EvalCodeCache.h: (JSC::EvalCodeCache::getSlow): * bytecode/ExecutableInfo.h: (JSC::ExecutableInfo::ExecutableInfo): (JSC::ExecutableInfo::isDerivedConstructorContext): (JSC::ExecutableInfo::isArrowFunctionContext): * bytecode/UnlinkedCodeBlock.cpp: (JSC::UnlinkedCodeBlock::UnlinkedCodeBlock): * bytecode/UnlinkedCodeBlock.h: (JSC::UnlinkedCodeBlock::isArrowFunction): (JSC::UnlinkedCodeBlock::isDerivedConstructorContext): (JSC::UnlinkedCodeBlock::isArrowFunctionContext): * bytecode/UnlinkedFunctionExecutable.cpp: (JSC::generateUnlinkedFunctionCodeBlock): (JSC::UnlinkedFunctionExecutable::UnlinkedFunctionExecutable): * bytecode/UnlinkedFunctionExecutable.h: * bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::BytecodeGenerator): (JSC::BytecodeGenerator::initializeArrowFunctionContextScopeIfNeeded): (JSC::BytecodeGenerator::variable): (JSC::BytecodeGenerator::emitNewArrowFunctionExpression): (JSC::BytecodeGenerator::emitLoadArrowFunctionLexicalEnvironment): (JSC::BytecodeGenerator::emitLoadThisFromArrowFunctionLexicalEnvironment): (JSC::BytecodeGenerator::emitLoadNewTargetFromArrowFunctionLexicalEnvironment): (JSC::BytecodeGenerator::emitLoadDerivedConstructorFromArrowFunctionLexicalEnvironment): (JSC::BytecodeGenerator::emitPutNewTargetToArrowFunctionContextScope): (JSC::BytecodeGenerator::emitPutDerivedConstructorToArrowFunctionContextScope): (JSC::BytecodeGenerator::emitPutThisToArrowFunctionContextScope): * bytecompiler/BytecodeGenerator.h: (JSC::BytecodeGenerator::isDerivedConstructorContext): (JSC::BytecodeGenerator::usesArrowFunction): (JSC::BytecodeGenerator::needsToUpdateArrowFunctionContext): (JSC::BytecodeGenerator::usesEval): (JSC::BytecodeGenerator::usesThis): (JSC::BytecodeGenerator::newTarget): (JSC::BytecodeGenerator::makeFunction): * bytecompiler/NodesCodegen.cpp: (JSC::ThisNode::emitBytecode): (JSC::SuperNode::emitBytecode): (JSC::EvalFunctionCallNode::emitBytecode): (JSC::FunctionCallValueNode::emitBytecode): (JSC::FunctionNode::emitBytecode): * debugger/DebuggerCallFrame.cpp: (JSC::DebuggerCallFrame::evaluate): * dfg/DFGAbstractInterpreterInlines.h: * dfg/DFGByteCodeParser.cpp: (JSC::DFG::ByteCodeParser::parseBlock): * dfg/DFGCapabilities.cpp: * dfg/DFGClobberize.h: * dfg/DFGDoesGC.cpp: * dfg/DFGFixupPhase.cpp: * dfg/DFGNodeType.h: * dfg/DFGObjectAllocationSinkingPhase.cpp: * dfg/DFGPredictionPropagationPhase.cpp: * dfg/DFGPromotedHeapLocation.cpp: * dfg/DFGPromotedHeapLocation.h: * dfg/DFGSafeToExecute.h: * dfg/DFGSpeculativeJIT.cpp: * dfg/DFGSpeculativeJIT.h: * dfg/DFGSpeculativeJIT32_64.cpp: * dfg/DFGSpeculativeJIT64.cpp: * ftl/FTLCapabilities.cpp: * ftl/FTLLowerDFGToLLVM.cpp: * ftl/FTLOperations.cpp: (JSC::FTL::operationMaterializeObjectInOSR): * interpreter/Interpreter.cpp: (JSC::eval): * jit/JIT.cpp: * jit/JIT.h: * jit/JITOpcodes.cpp: (JSC::JIT::emitNewFuncExprCommon): * jit/JITOpcodes32_64.cpp: * llint/LLIntSlowPaths.cpp: (JSC::LLInt::LLINT_SLOW_PATH_DECL): * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * parser/ASTBuilder.h: (JSC::ASTBuilder::createArrowFunctionExpr): (JSC::ASTBuilder::usesArrowFunction): * parser/Nodes.h: (JSC::ScopeNode::usesArrowFunction): * parser/Parser.cpp: (JSC::Parser<LexerType>::parseFunctionInfo): * parser/ParserModes.h: * runtime/CodeCache.cpp: (JSC::CodeCache::getGlobalCodeBlock): (JSC::CodeCache::getProgramCodeBlock): (JSC::CodeCache::getEvalCodeBlock): (JSC::CodeCache::getModuleProgramCodeBlock): (JSC::CodeCache::getFunctionExecutableFromGlobalCode): * runtime/CodeCache.h: * runtime/CommonIdentifiers.h: * runtime/CommonSlowPaths.cpp: (JSC::SLOW_PATH_DECL): * runtime/Executable.cpp: (JSC::ScriptExecutable::ScriptExecutable): (JSC::EvalExecutable::create): (JSC::EvalExecutable::EvalExecutable): (JSC::ProgramExecutable::ProgramExecutable): (JSC::ModuleProgramExecutable::ModuleProgramExecutable): (JSC::FunctionExecutable::FunctionExecutable): * runtime/Executable.h: (JSC::ScriptExecutable::isArrowFunctionContext): (JSC::ScriptExecutable::isDerivedConstructorContext): * runtime/JSGlobalObject.cpp: (JSC::JSGlobalObject::createEvalCodeBlock): * runtime/JSGlobalObject.h: * runtime/JSGlobalObjectFunctions.cpp: (JSC::globalFuncEval): * tests/es6.yaml: * tests/stress/arrowfunction-activation-sink-osrexit.js: * tests/stress/arrowfunction-activation-sink.js: * tests/stress/arrowfunction-lexical-bind-newtarget.js: Added. * tests/stress/arrowfunction-lexical-bind-supercall-1.js: Added. * tests/stress/arrowfunction-lexical-bind-supercall-2.js: Added. * tests/stress/arrowfunction-lexical-bind-supercall-3.js: Added. * tests/stress/arrowfunction-lexical-bind-supercall-4.js: Added. * tests/stress/arrowfunction-lexical-bind-this-1.js: * tests/stress/arrowfunction-lexical-bind-this-7.js: Added. * tests/stress/arrowfunction-tdz-1.js: Added. * tests/stress/arrowfunction-tdz-2.js: Added. * tests/stress/arrowfunction-tdz-3.js: Added. * tests/stress/arrowfunction-tdz-4.js: Added. * tests/stress/arrowfunction-tdz.js: Removed. LayoutTests: Patch by Skachkov Oleksandr <gskachkov@gmail.com> on 2015-12-08 Reviewed by Saam Barati. * js/arrowfunction-supercall-expected.txt: Added. * js/arrowfunction-supercall.html: Added. * js/arrowfunction-tdz-expected.txt: Added new expectation. * js/script-tests/arrowfunction-supercall.js: Added. * js/script-tests/arrowfunction-tdz.js: Added new cases. Canonical link: https://commits.webkit.org/170152@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@193766 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-12-08 20:24:04 +00:00
PASS successfullyParsed is true
TEST COMPLETE