Changeset 28577 in webkit for trunk/JavaScriptCore/kjs/Parser.cpp


Ignore:
Timestamp:
Dec 9, 2007, 8:05:56 PM (17 years ago)
Author:
Darin Adler
Message:

Reviewed by Maciej.

Test: fast/js/exception-linenums-in-html-1.html
Test: fast/js/exception-linenums-in-html-2.html
Test: fast/js/exception-linenums.html

By the time the ProgramNode was constructed, the source URL was empty.

  • kjs/Parser.cpp: (KJS::Parser::parseProgram): Added code to set and clear m_sourceURL, which is now handled here instead of in the lexer; it needs to still be set when we create the program node. Call setLoc to set the first and last line number. (KJS::Parser::parseFunctionBody): Ditto, but for the body. (KJS::Parser::parse): Removed the sourceURL argument.
  • kjs/Parser.h: Added sourceURL(), m_sourceURL, and m_lastLine. Added a lastLine parameter to didFinishParsing, since the bison grammar knows the last line number and we otherwise do not know it. Removed the sourceURL parameter from parse, since that's now handled at a higher level.
  • kjs/grammar.y: Pass the last line number to didFinishParsing.
  • kjs/lexer.cpp: (KJS::Lexer::setCode): Removed the sourceURL argument and the code to set m_sourceURL. (KJS::Lexer::clear): Ditto.
  • kjs/lexer.h: More of the same.
  • kjs/nodes.cpp: (KJS::FunctionBodyNode::FunctionBodyNode): Get the source URL from the parser rather than from the lexer. Removed unneeded call to setLoc, since the line numbers already both default to -1.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/Parser.cpp

    r28540 r28577  
    4444    int* sourceId, int* errLine, UString* errMsg)
    4545{
    46     parse(sourceURL, startingLineNumber, code, length, sourceId, errLine, errMsg);
    47     if (!m_sourceElements)
     46    m_sourceURL = sourceURL;
     47    parse(startingLineNumber, code, length, sourceId, errLine, errMsg);
     48    if (!m_sourceElements) {
     49        m_sourceURL = UString();
    4850        return 0;
    49     return new ProgramNode(m_sourceElements.release());
     51    }
     52    RefPtr<ProgramNode> program = new ProgramNode(m_sourceElements.release());
     53    m_sourceURL = UString();
     54    program->setLoc(startingLineNumber, m_lastLine);
     55    return program.release();
    5056}
    5157
     
    5460    int* sourceId, int* errLine, UString* errMsg)
    5561{
    56     parse(sourceURL, startingLineNumber, code, length, sourceId, errLine, errMsg);
    57     if (!m_sourceElements)
     62    m_sourceURL = sourceURL;
     63    parse(startingLineNumber, code, length, sourceId, errLine, errMsg);
     64    if (!m_sourceElements) {
     65        m_sourceURL = UString();
    5866        return 0;
    59     return new FunctionBodyNode(m_sourceElements.release());
     67    }
     68    RefPtr<FunctionBodyNode> body = new FunctionBodyNode(m_sourceElements.release());
     69    m_sourceURL = UString();
     70    body->setLoc(startingLineNumber, m_lastLine);
     71    return body;
    6072}
    6173
    62 void Parser::parse(const UString& sourceURL, int startingLineNumber,
     74void Parser::parse(int startingLineNumber,
    6375    const UChar* code, unsigned length,
    6476    int* sourceId, int* errLine, UString* errMsg)
     
    7385    Lexer& lexer = KJS::lexer();
    7486
    75     lexer.setCode(sourceURL, startingLineNumber, code, length);
     87    lexer.setCode(startingLineNumber, code, length);
    7688    m_sourceId++;
    7789    if (sourceId)
Note: See TracChangeset for help on using the changeset viewer.