Function parameters should be parsed in the same parser arena as the function body
authorsaambarati1@gmail.com <saambarati1@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Jul 2015 18:48:30 +0000 (18:48 +0000)
committersaambarati1@gmail.com <saambarati1@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Jul 2015 18:48:30 +0000 (18:48 +0000)
commit29dc33e17609cdba61536259902692421fbcbb32
treec88c9b80bb72b9bb4d47a28687df3bb86bac8090
parent8695c97846b051126d31c99784555e8a05a24da6
Function parameters should be parsed in the same parser arena as the function body
https://bugs.webkit.org/show_bug.cgi?id=145995

Reviewed by Yusuke Suzuki.

Source/JavaScriptCore:

This patch changes how functions are parsed in JSC. A function's
parameters are now parsed in the same arena as the function itself.
This allows us to arena allocate all destructuring AST nodes and
the FunctionParameters node. This will help make implementing ES6
default parameter values sane.

A source code that represents a function now includes the text of the function's
parameters. The starting offset is at the opening parenthesis of the parameter
list or at the starting character of the identifier for arrow functions that
have single arguments and don't start with parenthesis.

For example:

"function (param1, param2) { ... }"
                           ^
                           | This offset used to be the starting offset of a function's SourceCode
          ^
          | This is the new starting offset for a function's SourceCode.

This requires us to change how some offsets are calculated
and also requires us to report some different line numbers for internal
metrics that use a SourceCode's starting line and column numbers.

This patch also does a bit of cleanup with regards to how
functions are parsed in general (especially arrow functions).
It removes some unnecessary #ifdefs and the likes for arrow
to make things clearer and more deliberate.

* API/JSScriptRef.cpp:
(parseScript):
* builtins/BuiltinExecutables.cpp:
(JSC::BuiltinExecutables::createExecutableInternal):
* bytecode/UnlinkedCodeBlock.cpp:
(JSC::generateFunctionCodeBlock):
(JSC::UnlinkedFunctionExecutable::UnlinkedFunctionExecutable):
(JSC::UnlinkedFunctionExecutable::visitChildren):
(JSC::UnlinkedFunctionExecutable::parameterCount): Deleted.
* bytecode/UnlinkedCodeBlock.h:
* bytecompiler/NodesCodegen.cpp:
(JSC::DestructuringAssignmentNode::emitBytecode):
(JSC::assignDefaultValueIfUndefined):
(JSC::ArrayPatternNode::collectBoundIdentifiers):
(JSC::DestructuringPatternNode::~DestructuringPatternNode): Deleted.
* parser/ASTBuilder.h:
(JSC::ASTBuilder::createClassExpr):
(JSC::ASTBuilder::createFunctionExpr):
(JSC::ASTBuilder::createFunctionBody):
(JSC::ASTBuilder::createArrowFunctionExpr):
(JSC::ASTBuilder::createGetterOrSetterProperty):
(JSC::ASTBuilder::createElementList):
(JSC::ASTBuilder::createFormalParameterList):
(JSC::ASTBuilder::appendParameter):
(JSC::ASTBuilder::createClause):
(JSC::ASTBuilder::createClauseList):
(JSC::ASTBuilder::createFuncDeclStatement):
(JSC::ASTBuilder::createForInLoop):
(JSC::ASTBuilder::createForOfLoop):
(JSC::ASTBuilder::isResolve):
(JSC::ASTBuilder::createDestructuringAssignment):
(JSC::ASTBuilder::createArrayPattern):
(JSC::ASTBuilder::appendArrayPatternSkipEntry):
(JSC::ASTBuilder::appendArrayPatternEntry):
(JSC::ASTBuilder::appendArrayPatternRestEntry):
(JSC::ASTBuilder::finishArrayPattern):
(JSC::ASTBuilder::createObjectPattern):
(JSC::ASTBuilder::appendObjectPatternEntry):
(JSC::ASTBuilder::createBindingLocation):
(JSC::ASTBuilder::setEndOffset):
* parser/Lexer.cpp:
(JSC::Lexer<T>::Lexer):
(JSC::Lexer<T>::nextTokenIsColon):
(JSC::Lexer<T>::setTokenPosition):
(JSC::Lexer<T>::lex):
(JSC::Lexer<T>::clear):
* parser/Lexer.h:
(JSC::Lexer::setIsReparsingFunction):
(JSC::Lexer::isReparsingFunction):
(JSC::Lexer::lineNumber):
(JSC::Lexer::setIsReparsing): Deleted.
(JSC::Lexer::isReparsing): Deleted.
* parser/NodeConstructors.h:
(JSC::TryNode::TryNode):
(JSC::FunctionParameters::FunctionParameters):
(JSC::FuncExprNode::FuncExprNode):
(JSC::FuncDeclNode::FuncDeclNode):
(JSC::ArrayPatternNode::ArrayPatternNode):
(JSC::ObjectPatternNode::ObjectPatternNode):
(JSC::BindingNode::BindingNode):
(JSC::DestructuringAssignmentNode::DestructuringAssignmentNode):
(JSC::ParameterNode::ParameterNode): Deleted.
(JSC::ArrayPatternNode::create): Deleted.
(JSC::ObjectPatternNode::create): Deleted.
(JSC::BindingNode::create): Deleted.
* parser/Nodes.cpp:
(JSC::ProgramNode::ProgramNode):
(JSC::EvalNode::EvalNode):
(JSC::FunctionBodyNode::FunctionBodyNode):
(JSC::FunctionBodyNode::finishParsing):
(JSC::FunctionNode::FunctionNode):
(JSC::FunctionNode::finishParsing):
(JSC::FunctionParameters::create): Deleted.
(JSC::FunctionParameters::FunctionParameters): Deleted.
(JSC::FunctionParameters::~FunctionParameters): Deleted.
* parser/Nodes.h:
(JSC::ProgramNode::startColumn):
(JSC::ProgramNode::endColumn):
(JSC::EvalNode::startColumn):
(JSC::EvalNode::endColumn):
(JSC::FunctionParameters::size):
(JSC::FunctionParameters::at):
(JSC::FunctionParameters::append):
(JSC::FuncExprNode::body):
(JSC::DestructuringPatternNode::~DestructuringPatternNode):
(JSC::DestructuringPatternNode::isBindingNode):
(JSC::DestructuringPatternNode::emitDirectBinding):
(JSC::ArrayPatternNode::appendIndex):
(JSC::ObjectPatternNode::appendEntry):
(JSC::BindingNode::boundProperty):
(JSC::BindingNode::divotStart):
(JSC::BindingNode::divotEnd):
(JSC::DestructuringAssignmentNode::bindings):
(JSC::FuncDeclNode::body):
(JSC::ParameterNode::pattern): Deleted.
(JSC::ParameterNode::nextParam): Deleted.
(JSC::FunctionParameters::patterns): Deleted.
* parser/Parser.cpp:
(JSC::Parser<LexerType>::Parser):
(JSC::Parser<LexerType>::~Parser):
(JSC::Parser<LexerType>::parseInner):
(JSC::Parser<LexerType>::allowAutomaticSemicolon):
(JSC::Parser<LexerType>::parseSourceElements):
(JSC::Parser<LexerType>::createBindingPattern):
(JSC::Parser<LexerType>::parseArrowFunctionSingleExpressionBodySourceElements):
(JSC::Parser<LexerType>::tryParseDestructuringPatternExpression):
(JSC::Parser<LexerType>::parseSwitchClauses):
(JSC::Parser<LexerType>::parseSwitchDefaultClause):
(JSC::Parser<LexerType>::parseBlockStatement):
(JSC::Parser<LexerType>::parseStatement):
(JSC::Parser<LexerType>::parseFormalParameters):
(JSC::Parser<LexerType>::parseFunctionBody):
(JSC::stringForFunctionMode):
(JSC::Parser<LexerType>::parseFunctionParameters):
(JSC::Parser<LexerType>::parseFunctionInfo):
(JSC::Parser<LexerType>::parseFunctionDeclaration):
(JSC::Parser<LexerType>::parseClass):
(JSC::Parser<LexerType>::parsePrimaryExpression):
(JSC::Parser<LexerType>::parseMemberExpression):
(JSC::Parser<LexerType>::parseArrowFunctionExpression):
(JSC::operatorString):
(JSC::Parser<LexerType>::parseArrowFunctionSingleExpressionBody): Deleted.
* parser/Parser.h:
(JSC::Parser::positionBeforeLastNewline):
(JSC::Parser::locationBeforeLastToken):
(JSC::Parser::findCachedFunctionInfo):
(JSC::Parser::isofToken):
(JSC::Parser::isEndOfArrowFunction):
(JSC::Parser::isArrowFunctionParamters):
(JSC::Parser::tokenStart):
(JSC::Parser::isLETMaskedAsIDENT):
(JSC::Parser::autoSemiColon):
(JSC::Parser::setEndOfStatement):
(JSC::Parser::canRecurse):
(JSC::Parser<LexerType>::parse):
(JSC::parse):
* parser/ParserFunctionInfo.h:
* parser/ParserModes.h:
(JSC::functionNameIsInScope):
* parser/SourceCode.h:
(JSC::makeSource):
(JSC::SourceCode::subExpression):
(JSC::SourceCode::subArrowExpression): Deleted.
* parser/SourceProviderCache.h:
(JSC::SourceProviderCache::get):
* parser/SourceProviderCacheItem.h:
(JSC::SourceProviderCacheItem::endFunctionToken):
(JSC::SourceProviderCacheItem::usedVariables):
(JSC::SourceProviderCacheItem::writtenVariables):
(JSC::SourceProviderCacheItem::SourceProviderCacheItem):
* parser/SyntaxChecker.h:
(JSC::SyntaxChecker::SyntaxChecker):
(JSC::SyntaxChecker::createClassExpr):
(JSC::SyntaxChecker::createFunctionExpr):
(JSC::SyntaxChecker::createFunctionBody):
(JSC::SyntaxChecker::createArrowFunctionExpr):
(JSC::SyntaxChecker::setFunctionNameStart):
(JSC::SyntaxChecker::createArguments):
(JSC::SyntaxChecker::createPropertyList):
(JSC::SyntaxChecker::createElementList):
(JSC::SyntaxChecker::createFormalParameterList):
(JSC::SyntaxChecker::appendParameter):
(JSC::SyntaxChecker::createClause):
(JSC::SyntaxChecker::createClauseList):
* runtime/CodeCache.cpp:
(JSC::CodeCache::getGlobalCodeBlock):
(JSC::CodeCache::getFunctionExecutableFromGlobalCode):
* runtime/Completion.cpp:
(JSC::checkSyntax):
* runtime/Executable.cpp:
(JSC::ProgramExecutable::checkSyntax):
* tests/controlFlowProfiler/conditional-expression.js:
(testConditionalFunctionCall):

LayoutTests:

* fast/profiler/anonymous-event-handler-expected.txt:
* fast/profiler/anonymous-function-called-from-different-contexts-expected.txt:
* fast/profiler/anonymous-function-calls-built-in-functions-expected.txt:
* fast/profiler/anonymous-function-calls-eval-expected.txt:
* fast/profiler/anonymous-functions-with-display-names-expected.txt:
* fast/profiler/apply-expected.txt:
* fast/profiler/built-in-function-calls-anonymous-expected.txt:
* fast/profiler/built-in-function-calls-user-defined-function-expected.txt:
* fast/profiler/call-expected.txt:
* fast/profiler/calling-the-function-that-started-the-profiler-from-another-scope-expected.txt:
* fast/profiler/compare-multiple-profiles-expected.txt:
* fast/profiler/constructor-expected.txt:
* fast/profiler/dead-time-expected.txt:
* fast/profiler/document-dot-write-expected.txt:
* fast/profiler/event-handler-expected.txt:
* fast/profiler/execution-context-and-eval-on-same-line-expected.txt:
* fast/profiler/inline-event-handler-expected.txt:
* fast/profiler/many-calls-in-the-same-scope-expected.txt:
* fast/profiler/multiple-and-different-scoped-anonymous-function-calls-expected.txt:
* fast/profiler/multiple-and-different-scoped-function-calls-expected.txt:
* fast/profiler/multiple-anonymous-functions-called-from-the-same-function-expected.txt:
* fast/profiler/multiple-frames-expected.txt:
* fast/profiler/named-functions-with-display-names-expected.txt:
* fast/profiler/nested-anonymous-functon-expected.txt:
* fast/profiler/nested-start-and-stop-profiler-expected.txt:
* fast/profiler/one-execution-context-expected.txt:
* fast/profiler/profile-calls-in-included-file-expected.txt:
* fast/profiler/profile-with-no-title-expected.txt:
* fast/profiler/profiling-from-a-nested-location-but-stop-profiling-outside-the-nesting-expected.txt:
* fast/profiler/profiling-from-a-nested-location-expected.txt:
* fast/profiler/simple-event-call-expected.txt:
* fast/profiler/simple-no-level-change-expected.txt:
* fast/profiler/start-and-stop-profiler-multiple-times-expected.txt:
* fast/profiler/start-and-stop-profiling-in-the-same-function-expected.txt:
* fast/profiler/stop-profiling-after-setTimeout-expected.txt:
* fast/profiler/stop-then-function-call-expected.txt:
* fast/profiler/two-execution-contexts-expected.txt:
* fast/profiler/user-defined-function-calls-built-in-functions-expected.txt:
* fast/profiler/window-dot-eval-expected.txt:
* js/dom/script-start-end-locations-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@186959 268f45cc-cd09-0410-ab3c-d52691b4dbfc
65 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/profiler/anonymous-event-handler-expected.txt
LayoutTests/fast/profiler/anonymous-function-called-from-different-contexts-expected.txt
LayoutTests/fast/profiler/anonymous-function-calls-built-in-functions-expected.txt
LayoutTests/fast/profiler/anonymous-function-calls-eval-expected.txt
LayoutTests/fast/profiler/anonymous-functions-with-display-names-expected.txt
LayoutTests/fast/profiler/apply-expected.txt
LayoutTests/fast/profiler/built-in-function-calls-anonymous-expected.txt
LayoutTests/fast/profiler/built-in-function-calls-user-defined-function-expected.txt
LayoutTests/fast/profiler/call-expected.txt
LayoutTests/fast/profiler/calling-the-function-that-started-the-profiler-from-another-scope-expected.txt
LayoutTests/fast/profiler/compare-multiple-profiles-expected.txt
LayoutTests/fast/profiler/constructor-expected.txt
LayoutTests/fast/profiler/dead-time-expected.txt
LayoutTests/fast/profiler/document-dot-write-expected.txt
LayoutTests/fast/profiler/event-handler-expected.txt
LayoutTests/fast/profiler/execution-context-and-eval-on-same-line-expected.txt
LayoutTests/fast/profiler/inline-event-handler-expected.txt
LayoutTests/fast/profiler/many-calls-in-the-same-scope-expected.txt
LayoutTests/fast/profiler/multiple-and-different-scoped-anonymous-function-calls-expected.txt
LayoutTests/fast/profiler/multiple-and-different-scoped-function-calls-expected.txt
LayoutTests/fast/profiler/multiple-anonymous-functions-called-from-the-same-function-expected.txt
LayoutTests/fast/profiler/multiple-frames-expected.txt
LayoutTests/fast/profiler/named-functions-with-display-names-expected.txt
LayoutTests/fast/profiler/nested-anonymous-functon-expected.txt
LayoutTests/fast/profiler/nested-start-and-stop-profiler-expected.txt
LayoutTests/fast/profiler/one-execution-context-expected.txt
LayoutTests/fast/profiler/profile-calls-in-included-file-expected.txt
LayoutTests/fast/profiler/profile-with-no-title-expected.txt
LayoutTests/fast/profiler/profiling-from-a-nested-location-but-stop-profiling-outside-the-nesting-expected.txt
LayoutTests/fast/profiler/profiling-from-a-nested-location-expected.txt
LayoutTests/fast/profiler/simple-event-call-expected.txt
LayoutTests/fast/profiler/simple-no-level-change-expected.txt
LayoutTests/fast/profiler/start-and-stop-profiler-multiple-times-expected.txt
LayoutTests/fast/profiler/start-and-stop-profiling-in-the-same-function-expected.txt
LayoutTests/fast/profiler/stop-profiling-after-setTimeout-expected.txt
LayoutTests/fast/profiler/stop-then-function-call-expected.txt
LayoutTests/fast/profiler/two-execution-contexts-expected.txt
LayoutTests/fast/profiler/user-defined-function-calls-built-in-functions-expected.txt
LayoutTests/fast/profiler/window-dot-eval-expected.txt
LayoutTests/js/dom/script-start-end-locations-expected.txt
Source/JavaScriptCore/API/JSScriptRef.cpp
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/builtins/BuiltinExecutables.cpp
Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.cpp
Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.h
Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
Source/JavaScriptCore/parser/ASTBuilder.h
Source/JavaScriptCore/parser/Lexer.cpp
Source/JavaScriptCore/parser/Lexer.h
Source/JavaScriptCore/parser/NodeConstructors.h
Source/JavaScriptCore/parser/Nodes.cpp
Source/JavaScriptCore/parser/Nodes.h
Source/JavaScriptCore/parser/Parser.cpp
Source/JavaScriptCore/parser/Parser.h
Source/JavaScriptCore/parser/ParserFunctionInfo.h
Source/JavaScriptCore/parser/ParserModes.h
Source/JavaScriptCore/parser/SourceCode.h
Source/JavaScriptCore/parser/SourceProviderCache.h
Source/JavaScriptCore/parser/SourceProviderCacheItem.h
Source/JavaScriptCore/parser/SyntaxChecker.h
Source/JavaScriptCore/runtime/CodeCache.cpp
Source/JavaScriptCore/runtime/Completion.cpp
Source/JavaScriptCore/runtime/Executable.cpp
Source/JavaScriptCore/tests/controlFlowProfiler/conditional-expression.js