Ignore:
Timestamp:
Apr 29, 2014, 3:23:17 PM (11 years ago)
Author:
[email protected]
Message:

Source/JavaScriptCore: Don't hold on to parameterBindingNodes forever
https://bugs.webkit.org/show_bug.cgi?id=132360

Reviewed by Geoffrey Garen.

Don't keep the parameter nodes anymore. Instead we store the
original parameter string and reparse whenever we actually
need them. Because we only actually need them for compilation
this only results in a single extra parse.

  • bytecode/UnlinkedCodeBlock.cpp:

(JSC::generateFunctionCodeBlock):
(JSC::UnlinkedFunctionExecutable::UnlinkedFunctionExecutable):
(JSC::UnlinkedFunctionExecutable::visitChildren):
(JSC::UnlinkedFunctionExecutable::finishCreation):
(JSC::UnlinkedFunctionExecutable::paramString):
(JSC::UnlinkedFunctionExecutable::parameters):
(JSC::UnlinkedFunctionExecutable::parameterCount): Deleted.

  • bytecode/UnlinkedCodeBlock.h:

(JSC::UnlinkedFunctionExecutable::create):
(JSC::UnlinkedFunctionExecutable::parameterCount):
(JSC::UnlinkedFunctionExecutable::parameters): Deleted.
(JSC::UnlinkedFunctionExecutable::finishCreation): Deleted.

  • parser/ASTBuilder.h:

(JSC::ASTBuilder::ASTBuilder):
(JSC::ASTBuilder::setFunctionBodyParameters):

  • parser/Nodes.h:

(JSC::FunctionBodyNode::parametersStartOffset):
(JSC::FunctionBodyNode::parametersEndOffset):
(JSC::FunctionBodyNode::setParameterLocation):

  • parser/Parser.cpp:

(JSC::Parser<LexerType>::parseFunctionInfo):
(JSC::parseParameters):

  • parser/Parser.h:

(JSC::parse):

  • parser/SourceCode.h:

(JSC::SourceCode::subExpression):

  • parser/SyntaxChecker.h:

(JSC::SyntaxChecker::setFunctionBodyParameters):

LayoutTests: Don't hold on to parameter BindingNodes forever
https://bugs.webkit.org/show_bug.cgi?id=132360

Reviewed by Geoffrey Garen.

We don't regenerate the parameter string anymore, so these tests now
match the original input.

  • js/destructuring-assignment-expected.txt:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.cpp

    r167813 r167964  
    5252static UnlinkedFunctionCodeBlock* generateFunctionCodeBlock(VM& vm, UnlinkedFunctionExecutable* executable, const SourceCode& source, CodeSpecializationKind kind, DebuggerMode debuggerMode, ProfilerMode profilerMode, UnlinkedFunctionKind functionKind, ParserError& error)
    5353{
    54     RefPtr<FunctionBodyNode> body = parse<FunctionBodyNode>(&vm, source, executable->parameters(), executable->name(), executable->toStrictness(), JSParseFunctionCode, error);
     54    RefPtr<FunctionParameters> parameters = executable->parameters(&vm);
     55    if (!parameters) {
     56        error = ParserError(ParserError::StackOverflow);
     57        error.m_line = source.firstLine();
     58        return 0;
     59    }
     60
     61    RefPtr<FunctionBodyNode> body = parse<FunctionBodyNode>(&vm, source, parameters.get(), executable->name(), executable->toStrictness(), JSParseFunctionCode, error);
    5562
    5663    if (!body) {
     
    6168    if (executable->forceUsesArguments())
    6269        body->setUsesArguments();
    63     body->finishParsing(executable->parameters(), executable->name(), executable->functionMode());
     70    body->finishParsing(parameters.get(), executable->name(), executable->functionMode());
    6471    executable->recordParse(body->features(), body->hasCapturedVariables());
    6572   
     
    93100    , m_name(node->ident())
    94101    , m_inferredName(node->inferredName())
    95     , m_parameters(node->parameters())
     102    , m_parameterCount(node->parameterCount())
    96103    , m_firstLineOffset(node->firstLine() - source.firstLine())
    97104    , m_lineCount(node->lastLine() - node->firstLine())
     
    104111    , m_functionMode(node->functionMode())
    105112{
    106 }
    107 
    108 size_t UnlinkedFunctionExecutable::parameterCount() const
    109 {
    110     return m_parameters->size();
    111113}
    112114
     
    123125    visitor.append(&thisObject->m_symbolTableForCall);
    124126    visitor.append(&thisObject->m_symbolTableForConstruct);
     127    visitor.append(&thisObject->m_parameterString);
    125128}
    126129
     
    185188}
    186189
     190void UnlinkedFunctionExecutable::finishCreation(VM& vm, const SourceCode& source, FunctionBodyNode* node)
     191{
     192    Base::finishCreation(vm);
     193    m_nameValue.set(vm, this, jsString(&vm, name().string()));
     194    // We make an isolated copy of the parameter string as we don't want to keep the
     195    // full source string alive.
     196    String parameterString = source.provider()->getRange(node->parametersStartOffset(), node->parametersEndOffset()).isolatedCopy();
     197    m_parameterString.set(vm, this, jsString(&vm, parameterString));
     198}
     199
    187200String UnlinkedFunctionExecutable::paramString() const
    188201{
    189     FunctionParameters& parameters = *m_parameters;
    190     StringBuilder builder;
    191     for (size_t pos = 0; pos < parameters.size(); ++pos) {
    192         if (!builder.isEmpty())
    193             builder.appendLiteral(", ");
    194         parameters.at(pos)->toString(builder);
    195     }
    196     return builder.toString();
     202    return m_parameterString->tryGetValue();
     203}
     204
     205RefPtr<FunctionParameters> UnlinkedFunctionExecutable::parameters(VM* vm)
     206{
     207    if (!m_parameterCount)
     208        return FunctionParameters::create(nullptr);
     209
     210    SourceCode parameterSource = makeSource(m_parameterString->tryGetValue());
     211    RefPtr<FunctionParameters> parameters = parseParameters(vm, parameterSource, toStrictness());
     212    ASSERT(!parameters || parameters->size() == m_parameterCount);
     213    return parameters;
    197214}
    198215
Note: See TracChangeset for help on using the changeset viewer.