Ignore:
Timestamp:
Dec 30, 2008, 4:07:20 PM (16 years ago)
Author:
[email protected]
Message:

2008-12-30 Cameron Zwarich <[email protected]>

Reviewed by Sam Weinig.

Bug 23037: Parsing and reparsing disagree on automatic semicolon insertion
<https://bugs.webkit.org/show_bug.cgi?id=23037>
<rdar://problem/6467124>

Parsing and reparsing disagree about automatic semicolon insertion, so that a
function like

function() { a = 1, }

is parsed as being syntactically valid but gets a syntax error upon reparsing.
This leads to an assertion failure in Parser::reparse(). It is not that big of
an issue in practice, because in a Release build such a function will return
'undefined' when called.

In this case, we are not following the spec and it should be a syntax error.
However, unless there is a newline separating the ',' and the '}', WebKit would
not treat it as a syntax error in the past either. It would be a bit of work to
make the automatic semicolon insertion match the spec exactly, so this patch
changes it to match our past behaviour.

The problem is that even during reparsing, the Lexer adds a semicolon at the
end of the input, which confuses allowAutomaticSemicolon(), because it is
expecting either a '}', the end of input, or a terminator like a newline.

JavaScriptCore:

  • parser/Lexer.cpp: (JSC::Lexer::Lexer): Initialize m_isReparsing to false. (JSC::Lexer::lex): Do not perform automatic semicolon insertion in the Lexer if we are in the middle of reparsing. (JSC::Lexer::clear): Set m_isReparsing to false.
  • parser/Lexer.h: (JSC::Lexer::setIsReparsing): Added.
  • parser/Parser.cpp: (JSC::Parser::reparse): Call Lexer::setIsReparsing() to notify the Lexer of reparsing.

LayoutTests:

  • fast/js/reparsing-semicolon-insertion-expected.txt: Added.
  • fast/js/reparsing-semicolon-insertion.html: Added.
  • fast/js/resources/reparsing-semicolon-insertion.js: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/parser/Lexer.cpp

    r38856 r39521  
    6868    , m_code(0)
    6969    , m_length(0)
     70    , m_isReparsing(false)
    7071    , m_atLineStart(true)
    7172    , m_current(0)
     
    193194                    m_state = InMultiLineComment;
    194195                } else if (m_current == -1) {
    195                     if (!m_terminator && !m_delimited) {
     196                    if (!m_terminator && !m_delimited && !m_isReparsing) {
    196197                        // automatic semicolon insertion if program incomplete
    197198                        token = ';';
     
    891892    m_buffer16.swap(newBuffer16);
    892893
     894    m_isReparsing = false;
     895
    893896    m_pattern = 0;
    894897    m_flags = 0;
Note: See TracChangeset for help on using the changeset viewer.