Changeset 127810 in webkit for trunk/Source/JavaScriptCore/parser


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.
Location:
trunk/Source/JavaScriptCore/parser
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/NodeConstructors.h

    r127654 r127810  
    750750        , m_body(body)
    751751    {
    752         m_body->finishParsing(source, parameter, ident);
     752        m_body->finishParsing(source, parameter, ident, FunctionNameIsInScope);
    753753    }
    754754
     
    757757        , m_body(body)
    758758    {
    759         m_body->finishParsing(source, parameter, ident);
     759        m_body->finishParsing(source, parameter, ident, FunctionNameIsNotInScope);
    760760    }
    761761
  • trunk/Source/JavaScriptCore/parser/Nodes.cpp

    r126893 r127810  
    168168}
    169169
    170 void FunctionBodyNode::finishParsing(const SourceCode& source, ParameterNode* firstParameter, const Identifier& ident)
     170void FunctionBodyNode::finishParsing(const SourceCode& source, ParameterNode* firstParameter, const Identifier& ident, FunctionNameIsInScopeToggle functionNameIsInScopeToggle)
    171171{
    172172    setSource(source);
    173     finishParsing(FunctionParameters::create(firstParameter), ident);
    174 }
    175 
    176 void FunctionBodyNode::finishParsing(PassRefPtr<FunctionParameters> parameters, const Identifier& ident)
     173    finishParsing(FunctionParameters::create(firstParameter), ident, functionNameIsInScopeToggle);
     174}
     175
     176void FunctionBodyNode::finishParsing(PassRefPtr<FunctionParameters> parameters, const Identifier& ident, FunctionNameIsInScopeToggle functionNameIsInScopeToggle)
    177177{
    178178    ASSERT(!source().isNull());
    179179    m_parameters = parameters;
    180180    m_ident = ident;
     181    m_functionNameIsInScopeToggle = functionNameIsInScopeToggle;
    181182}
    182183
  • trunk/Source/JavaScriptCore/parser/Nodes.h

    r127666 r127810  
    14041404    };
    14051405
     1406    enum FunctionNameIsInScopeToggle { FunctionNameIsNotInScope, FunctionNameIsInScope };
    14061407    class FunctionBodyNode : public ScopeNode {
    14071408    public:
     
    14151416        virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
    14161417
    1417         void finishParsing(const SourceCode&, ParameterNode*, const Identifier&);
    1418         void finishParsing(PassRefPtr<FunctionParameters>, const Identifier&);
     1418        void finishParsing(const SourceCode&, ParameterNode*, const Identifier&, FunctionNameIsInScopeToggle);
     1419        void finishParsing(PassRefPtr<FunctionParameters>, const Identifier&, FunctionNameIsInScopeToggle);
    14191420       
    14201421        const Identifier& ident() { return m_ident; }
     
    14221423        const Identifier& inferredName() { return m_inferredName.isEmpty() ? m_ident : m_inferredName; }
    14231424
     1425        bool functionNameIsInScope() { return m_functionNameIsInScopeToggle == FunctionNameIsInScope; }
     1426        FunctionNameIsInScopeToggle functionNameIsInScopeToggle() { return m_functionNameIsInScopeToggle; }
     1427
    14241428        static const bool scopeIsFunction = true;
    14251429
     
    14301434        Identifier m_ident;
    14311435        Identifier m_inferredName;
     1436        FunctionNameIsInScopeToggle m_functionNameIsInScopeToggle;
    14321437        RefPtr<FunctionParameters> m_parameters;
    14331438    };
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r127774 r127810  
    4141
    4242template <typename LexerType>
    43 Parser<LexerType>::Parser(JSGlobalData* globalData, const SourceCode& source, FunctionParameters* parameters, JSParserStrictness strictness, JSParserMode parserMode)
     43Parser<LexerType>::Parser(JSGlobalData* globalData, const SourceCode& source, FunctionParameters* parameters, const Identifier& name, JSParserStrictness strictness, JSParserMode parserMode)
    4444    : m_globalData(globalData)
    4545    , m_source(&source)
     
    7272            scope->declareParameter(&parameters->at(i));
    7373    }
     74    if (!name.isNull())
     75        scope->declareCallee(&name);
    7476    next();
    7577    m_lexer->setLastLineNumber(tokenLine());
  • trunk/Source/JavaScriptCore/parser/Parser.h

    r127774 r127810  
    209209    bool isFunctionBoundary() { return m_isFunctionBoundary; }
    210210
     211    void declareCallee(const Identifier* ident)
     212    {
     213        m_declaredVariables.add(ident->ustring().impl());
     214    }
     215
    211216    bool declareVariable(const Identifier* ident)
    212217    {
     
    383388
    384389public:
    385     Parser(JSGlobalData*, const SourceCode&, FunctionParameters*, JSParserStrictness, JSParserMode);
     390    Parser(JSGlobalData*, const SourceCode&, FunctionParameters*, const Identifier&, JSParserStrictness, JSParserMode);
    386391    ~Parser();
    387392
     
    10211026
    10221027template <class ParsedNode>
    1023 PassRefPtr<ParsedNode> parse(JSGlobalData* globalData, JSGlobalObject* lexicalGlobalObject, const SourceCode& source, FunctionParameters* parameters, JSParserStrictness strictness, JSParserMode parserMode, Debugger* debugger, ExecState* execState, JSObject** exception)
     1028PassRefPtr<ParsedNode> parse(JSGlobalData* globalData, JSGlobalObject* lexicalGlobalObject, const SourceCode& source, FunctionParameters* parameters, const Identifier& name, JSParserStrictness strictness, JSParserMode parserMode, Debugger* debugger, ExecState* execState, JSObject** exception)
    10241029{
    10251030    SamplingRegion samplingRegion("Parsing");
     
    10281033
    10291034    if (source.provider()->data()->is8Bit()) {
    1030         Parser< Lexer<LChar> > parser(globalData, source, parameters, strictness, parserMode);
     1035        Parser< Lexer<LChar> > parser(globalData, source, parameters, name, strictness, parserMode);
    10311036        return parser.parse<ParsedNode>(lexicalGlobalObject, debugger, execState, exception);
    10321037    }
    1033     Parser< Lexer<UChar> > parser(globalData, source, parameters, strictness, parserMode);
     1038    Parser< Lexer<UChar> > parser(globalData, source, parameters, name, strictness, parserMode);
    10341039    return parser.parse<ParsedNode>(lexicalGlobalObject, debugger, execState, exception);
    10351040}
Note: See TracChangeset for help on using the changeset viewer.