Ignore:
Timestamp:
Sep 6, 2012, 6:42:53 PM (13 years ago)
Author:
[email protected]
Message:

Source/JavaScriptCore: Rolled back in <http://trac.webkit.org/changeset/127698> with a fix for
fast/dom/HTMLScriptElement/script-reexecution-pretty-diff.html, which
is to make sure that function declarations don't put their names in scope.

Reviewed by Gavin Barraclough.

Named functions should not allocate scope objects for their names
https://bugs.webkit.org/show_bug.cgi?id=95659

Reviewed by Oliver Hunt.

LayoutTests: Rolled back in <http://trac.webkit.org/changeset/127698> with a fix for
fast/dom/HTMLScriptElement/script-reexecution-pretty-diff.html.

Added a more explicit test for the feature I broke in
fast/dom/HTMLScriptElement/script-reexecution-pretty-diff.html.

Reviewed by Gavin Barraclough.

Named functions should not allocate scope objects for their names
https://bugs.webkit.org/show_bug.cgi?id=95659

Reviewed by Oliver Hunt.

  • fast/dom/HTMLScriptElement/script-reexecution.html:
  • fast/js/function-name-is-in-scope-expected.txt: Added.
  • fast/js/function-name-is-in-scope.html: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/Executable.cpp

    r127774 r127810  
    134134const ClassInfo FunctionExecutable::s_info = { "FunctionExecutable", &ScriptExecutable::s_info, 0, 0, CREATE_METHOD_TABLE(FunctionExecutable) };
    135135
    136 FunctionExecutable::FunctionExecutable(JSGlobalData& globalData, const Identifier& name, const Identifier& inferredName, const SourceCode& source, bool forceUsesArguments, FunctionParameters* parameters, bool inStrictContext)
    137     : ScriptExecutable(globalData.functionExecutableStructure.get(), globalData, source, inStrictContext)
     136FunctionExecutable::FunctionExecutable(JSGlobalData& globalData, FunctionBodyNode* node)
     137    : ScriptExecutable(globalData.functionExecutableStructure.get(), globalData, node->source(), node->isStrictMode())
    138138    , m_numCapturedVariables(0)
    139     , m_forceUsesArguments(forceUsesArguments)
    140     , m_parameters(parameters)
    141     , m_name(name)
    142     , m_inferredName(inferredName.isNull() ? globalData.propertyNames->emptyIdentifier : inferredName)
    143 {
    144 }
    145 
    146 FunctionExecutable::FunctionExecutable(ExecState* exec, const Identifier& name, const Identifier& inferredName, const SourceCode& source, bool forceUsesArguments, FunctionParameters* parameters, bool inStrictContext)
    147     : ScriptExecutable(exec->globalData().functionExecutableStructure.get(), exec, source, inStrictContext)
    148     , m_numCapturedVariables(0)
    149     , m_forceUsesArguments(forceUsesArguments)
    150     , m_parameters(parameters)
    151     , m_name(name)
    152     , m_inferredName(inferredName.isNull() ? exec->globalData().propertyNames->emptyIdentifier : inferredName)
    153 {
     139    , m_forceUsesArguments(node->usesArguments())
     140    , m_parameters(node->parameters())
     141    , m_name(node->ident())
     142    , m_inferredName(node->inferredName().isNull() ? globalData.propertyNames->emptyIdentifier : node->inferredName())
     143    , m_functionNameIsInScopeToggle(node->functionNameIsInScopeToggle())
     144{
     145    m_firstLine = node->lineNo();
     146    m_lastLine = node->lastLine();
    154147}
    155148
     
    211204        if (!lexicalGlobalObject->evalEnabled())
    212205            return throwError(exec, createEvalError(exec, ASCIILiteral("Eval is disabled")));
    213         RefPtr<EvalNode> evalNode = parse<EvalNode>(globalData, lexicalGlobalObject, m_source, 0, isStrictMode() ? JSParseStrict : JSParseNormal, EvalNode::isFunctionNode ? JSParseFunctionCode : JSParseProgramCode, lexicalGlobalObject->debugger(), exec, &exception);
     206        RefPtr<EvalNode> evalNode = parse<EvalNode>(globalData, lexicalGlobalObject, m_source, 0, Identifier(), isStrictMode() ? JSParseStrict : JSParseNormal, EvalNode::isFunctionNode ? JSParseFunctionCode : JSParseProgramCode, lexicalGlobalObject->debugger(), exec, &exception);
    214207        if (!evalNode) {
    215208            ASSERT(exception);
     
    294287    JSGlobalData* globalData = &exec->globalData();
    295288    JSGlobalObject* lexicalGlobalObject = exec->lexicalGlobalObject();
    296     RefPtr<ProgramNode> programNode = parse<ProgramNode>(globalData, lexicalGlobalObject, m_source, 0, JSParseNormal, ProgramNode::isFunctionNode ? JSParseFunctionCode : JSParseProgramCode, lexicalGlobalObject->debugger(), exec, &exception);
     289    RefPtr<ProgramNode> programNode = parse<ProgramNode>(globalData, lexicalGlobalObject, m_source, 0, Identifier(), JSParseNormal, ProgramNode::isFunctionNode ? JSParseFunctionCode : JSParseProgramCode, lexicalGlobalObject->debugger(), exec, &exception);
    297290    if (programNode)
    298291        return 0;
     
    336329        m_programCodeBlock = newCodeBlock.release();
    337330    } else {
    338         RefPtr<ProgramNode> programNode = parse<ProgramNode>(globalData, lexicalGlobalObject, m_source, 0, isStrictMode() ? JSParseStrict : JSParseNormal, ProgramNode::isFunctionNode ? JSParseFunctionCode : JSParseProgramCode, lexicalGlobalObject->debugger(), exec, &exception);
     331        RefPtr<ProgramNode> programNode = parse<ProgramNode>(globalData, lexicalGlobalObject, m_source, 0, Identifier(), isStrictMode() ? JSParseStrict : JSParseNormal, ProgramNode::isFunctionNode ? JSParseFunctionCode : JSParseProgramCode, lexicalGlobalObject->debugger(), exec, &exception);
    339332        if (!programNode) {
    340333            ASSERT(exception);
     
    479472    JSGlobalData* globalData = scope->globalData();
    480473    JSGlobalObject* globalObject = scope->globalObject();
    481     RefPtr<FunctionBodyNode> body = parse<FunctionBodyNode>(globalData, globalObject, m_source, m_parameters.get(), isStrictMode() ? JSParseStrict : JSParseNormal, FunctionBodyNode::isFunctionNode ? JSParseFunctionCode : JSParseProgramCode, 0, 0, &exception);
     474    RefPtr<FunctionBodyNode> body = parse<FunctionBodyNode>(
     475        globalData,
     476        globalObject,
     477        m_source,
     478        m_parameters.get(),
     479        name(),
     480        isStrictMode() ? JSParseStrict : JSParseNormal,
     481        FunctionBodyNode::isFunctionNode ? JSParseFunctionCode : JSParseProgramCode,
     482        0,
     483        0,
     484        &exception
     485    );
    482486
    483487    if (!body) {
     
    487491    if (m_forceUsesArguments)
    488492        body->setUsesArguments();
    489     body->finishParsing(m_parameters, m_name);
     493    body->finishParsing(m_parameters, m_name, m_functionNameIsInScopeToggle);
    490494    recordParse(body->features(), body->hasCapturedVariables(), body->lineNo(), body->lastLine());
    491495
     
    648652}
    649653
    650 FunctionExecutable* FunctionExecutable::fromGlobalCode(const Identifier& functionName, ExecState* exec, Debugger* debugger, const SourceCode& source, JSObject** exception)
     654FunctionExecutable* FunctionExecutable::fromGlobalCode(const Identifier& name, ExecState* exec, Debugger* debugger, const SourceCode& source, JSObject** exception)
    651655{
    652656    JSGlobalObject* lexicalGlobalObject = exec->lexicalGlobalObject();
    653     RefPtr<ProgramNode> program = parse<ProgramNode>(&exec->globalData(), lexicalGlobalObject, source, 0, JSParseNormal, ProgramNode::isFunctionNode ? JSParseFunctionCode : JSParseProgramCode, debugger, exec, exception);
     657    RefPtr<ProgramNode> program = parse<ProgramNode>(&exec->globalData(), lexicalGlobalObject, source, 0, Identifier(), JSParseNormal, ProgramNode::isFunctionNode ? JSParseFunctionCode : JSParseProgramCode, debugger, exec, exception);
    654658    if (!program) {
    655659        ASSERT(*exception);
     
    657661    }
    658662
    659     // Uses of this function that would not result in a single function expression are invalid.
     663    // This function assumes an input string that would result in a single anonymous function expression.
    660664    StatementNode* exprStatement = program->singleStatement();
    661665    ASSERT(exprStatement);
     
    666670    FunctionBodyNode* body = static_cast<FuncExprNode*>(funcExpr)->body();
    667671    ASSERT(body);
    668 
    669     return FunctionExecutable::create(exec->globalData(), functionName, functionName, body->source(), body->usesArguments(), body->parameters(), body->isStrictMode(), body->lineNo(), body->lastLine());
     672    ASSERT(body->ident().isNull());
     673
     674    FunctionExecutable* functionExecutable = FunctionExecutable::create(exec->globalData(), body);
     675    functionExecutable->m_nameValue.set(exec->globalData(), functionExecutable, jsString(&exec->globalData(), name.ustring()));
     676    return functionExecutable;
    670677}
    671678
Note: See TracChangeset for help on using the changeset viewer.