haikuwebkit/LayoutTests/js/methods-names-should-not-be...

4 lines
16 B
Plaintext
Raw Permalink Normal View History

Method names should not appear in the lexical scope of the method's body. https://bugs.webkit.org/show_bug.cgi?id=155568 Reviewed by Saam Barati. Source/JavaScriptCore: Consider this scenario: var f = "foo"; var result = ({ f() { return f; // f should be the string "foo", not this method f. } }).f(); result === "foo"; // Should be true. The reason this is not current working is because the parser does not yet distinguish between FunctionExpressions and MethodDefinitions. The ES6 spec explicitly distinguishes between the 2, and we should do the same. This patch changes all methods (and getters and setters which are also methods) to have a FunctionMode of MethodDefinition (instead of FunctionExpression). functionNameIsInScope() is responsible for determining whether a function's name should be in its scope or not. It already returns false for any function whose FunctionMode is not FunctionExpression. Giving methods the MethodDefinition FunctionMode gets us the correct behavior ES6 expects. * bytecode/UnlinkedFunctionExecutable.cpp: (JSC::UnlinkedFunctionExecutable::UnlinkedFunctionExecutable): * bytecode/UnlinkedFunctionExecutable.h: * bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::emitNewArrowFunctionExpression): (JSC::BytecodeGenerator::emitNewMethodDefinition): * bytecompiler/BytecodeGenerator.h: * bytecompiler/NodesCodegen.cpp: (JSC::ArrowFuncExprNode::emitBytecode): (JSC::MethodDefinitionNode::emitBytecode): (JSC::YieldExprNode::emitBytecode): * parser/ASTBuilder.h: (JSC::ASTBuilder::createFunctionExpr): (JSC::ASTBuilder::createMethodDefinition): (JSC::ASTBuilder::createFunctionMetadata): (JSC::ASTBuilder::createGetterOrSetterProperty): (JSC::ASTBuilder::createArguments): * parser/NodeConstructors.h: (JSC::FunctionParameters::FunctionParameters): (JSC::BaseFuncExprNode::BaseFuncExprNode): (JSC::FuncExprNode::FuncExprNode): (JSC::FuncDeclNode::FuncDeclNode): (JSC::ArrowFuncExprNode::ArrowFuncExprNode): (JSC::MethodDefinitionNode::MethodDefinitionNode): (JSC::YieldExprNode::YieldExprNode): * parser/Nodes.h: (JSC::BaseFuncExprNode::metadata): * parser/Parser.cpp: (JSC::Parser<LexerType>::parseClass): (JSC::Parser<LexerType>::parsePropertyMethod): * parser/ParserModes.h: * parser/SyntaxChecker.h: (JSC::SyntaxChecker::createFunctionExpr): (JSC::SyntaxChecker::createFunctionMetadata): (JSC::SyntaxChecker::createArrowFunctionExpr): (JSC::SyntaxChecker::createMethodDefinition): (JSC::SyntaxChecker::setFunctionNameStart): (JSC::SyntaxChecker::createArguments): * tests/es6.yaml: LayoutTests: * inspector/model/scope-chain-node-expected.txt: - rebased expected result. * js/script-tests/function-toString-vs-name.js: - fixed a bug in the shouldBe() function. * js/methods-names-should-not-be-in-lexical-scope-expected.txt: Added. * js/methods-names-should-not-be-in-lexical-scope.html: Added. * js/script-tests/methods-names-should-not-be-in-lexical-scope.js: Added. - test all variations of methods. Canonical link: https://commits.webkit.org/173701@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@198332 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-03-17 14:58:57 +00:00
TEST COMPLETE