| Index: src/scanner-base.cc
|
| ===================================================================
|
| --- src/scanner-base.cc (revision 8618)
|
| +++ src/scanner-base.cc (working copy)
|
| @@ -77,9 +77,22 @@
|
| : Scanner(scanner_contants), octal_pos_(Location::invalid()) { }
|
|
|
|
|
| +void JavaScriptScanner::Initialize(UC16CharacterStream* source) {
|
| + source_ = source;
|
| + // Need to capture identifiers in order to recognize "get" and "set"
|
| + // in object literals.
|
| + Init();
|
| + // Skip initial whitespace allowing HTML comment ends just like
|
| + // after a newline and scan first token.
|
| + has_line_terminator_before_next_ = true;
|
| + SkipWhiteSpace();
|
| + Scan();
|
| +}
|
| +
|
| Token::Value JavaScriptScanner::Next() {
|
| current_ = next_;
|
| has_line_terminator_before_next_ = false;
|
| + has_multiline_comment_before_next_ = false;
|
| Scan();
|
| return current_.token;
|
| }
|
| @@ -144,7 +157,7 @@
|
| // to be part of the single-line comment; it is recognized
|
| // separately by the lexical grammar and becomes part of the
|
| // stream of input elements for the syntactic grammar (see
|
| - // ECMA-262, section 7.4, page 12).
|
| + // ECMA-262, section 7.4).
|
| while (c0_ >= 0 && !unicode_cache_->IsLineTerminator(c0_)) {
|
| Advance();
|
| }
|
| @@ -160,13 +173,14 @@
|
| while (c0_ >= 0) {
|
| char ch = c0_;
|
| Advance();
|
| + if (unicode_cache_->IsLineTerminator(ch)) {
|
| + // Following ECMA-262, section 7.4, a comment containing
|
| + // a newline will make the comment count as a line-terminator.
|
| + has_multiline_comment_before_next_ = true;
|
| + }
|
| // If we have reached the end of the multi-line comment, we
|
| // consume the '/' and insert a whitespace. This way all
|
| - // multi-line comments are treated as whitespace - even the ones
|
| - // containing line terminators. This contradicts ECMA-262, section
|
| - // 7.4, page 12, that says that multi-line comments containing
|
| - // line terminators should be treated as a line terminator, but it
|
| - // matches the behaviour of SpiderMonkey and KJS.
|
| + // multi-line comments are treated as whitespace.
|
| if (ch == '*' && c0_ == '/') {
|
| c0_ = ' ';
|
| return Token::WHITESPACE;
|
| @@ -448,6 +462,7 @@
|
| // of the end of a function (at the "}" token). It doesn't matter
|
| // whether there was a line terminator in the part we skip.
|
| has_line_terminator_before_next_ = false;
|
| + has_multiline_comment_before_next_ = false;
|
| }
|
| Scan();
|
| }
|
| @@ -784,7 +799,7 @@
|
| { NULL, I, Token::ILLEGAL },
|
| { NULL, UNMATCHABLE, Token::ILLEGAL },
|
| { NULL, UNMATCHABLE, Token::ILLEGAL },
|
| - { "let", KEYWORD_PREFIX, Token::FUTURE_RESERVED_WORD },
|
| + { "let", KEYWORD_PREFIX, Token::FUTURE_STRICT_RESERVED_WORD },
|
| { NULL, UNMATCHABLE, Token::ILLEGAL },
|
| { NULL, N, Token::ILLEGAL },
|
| { NULL, UNMATCHABLE, Token::ILLEGAL },
|
| @@ -797,7 +812,7 @@
|
| { NULL, V, Token::ILLEGAL },
|
| { NULL, W, Token::ILLEGAL },
|
| { NULL, UNMATCHABLE, Token::ILLEGAL },
|
| - { "yield", KEYWORD_PREFIX, Token::FUTURE_RESERVED_WORD }
|
| + { "yield", KEYWORD_PREFIX, Token::FUTURE_STRICT_RESERVED_WORD }
|
| };
|
|
|
|
|
| @@ -834,7 +849,7 @@
|
| case C:
|
| if (MatchState(input, 'a', CA)) return;
|
| if (MatchKeywordStart(input, "class", 1,
|
| - Token::FUTURE_RESERVED_WORD)) return;
|
| + Token::FUTURE_RESERVED_WORD)) return;
|
| if (MatchState(input, 'o', CO)) return;
|
| break;
|
| case CA:
|
| @@ -860,14 +875,14 @@
|
| case E:
|
| if (MatchKeywordStart(input, "else", 1, Token::ELSE)) return;
|
| if (MatchKeywordStart(input, "enum", 1,
|
| - Token::FUTURE_RESERVED_WORD)) return;
|
| + Token::FUTURE_RESERVED_WORD)) return;
|
| if (MatchState(input, 'x', EX)) return;
|
| break;
|
| case EX:
|
| if (MatchKeywordStart(input, "export", 2,
|
| - Token::FUTURE_RESERVED_WORD)) return;
|
| + Token::FUTURE_RESERVED_WORD)) return;
|
| if (MatchKeywordStart(input, "extends", 2,
|
| - Token::FUTURE_RESERVED_WORD)) return;
|
| + Token::FUTURE_RESERVED_WORD)) return;
|
| break;
|
| case F:
|
| if (MatchKeywordStart(input, "false", 1, Token::FALSE_LITERAL)) return;
|
| @@ -885,41 +900,40 @@
|
| break;
|
| case IMP:
|
| if (MatchKeywordStart(input, "implements", 3,
|
| - Token::FUTURE_RESERVED_WORD )) return;
|
| + Token::FUTURE_STRICT_RESERVED_WORD )) return;
|
| if (MatchKeywordStart(input, "import", 3,
|
| - Token::FUTURE_RESERVED_WORD)) return;
|
| + Token::FUTURE_RESERVED_WORD)) return;
|
| break;
|
| case IN:
|
| token_ = Token::IDENTIFIER;
|
| if (MatchKeywordStart(input, "interface", 2,
|
| - Token::FUTURE_RESERVED_WORD)) return;
|
| + Token::FUTURE_STRICT_RESERVED_WORD)) return;
|
| if (MatchKeywordStart(input, "instanceof", 2, Token::INSTANCEOF)) return;
|
| break;
|
| case N:
|
| - if (MatchKeywordStart(input, "native", 1, Token::NATIVE)) return;
|
| if (MatchKeywordStart(input, "new", 1, Token::NEW)) return;
|
| if (MatchKeywordStart(input, "null", 1, Token::NULL_LITERAL)) return;
|
| break;
|
| case P:
|
| if (MatchKeywordStart(input, "package", 1,
|
| - Token::FUTURE_RESERVED_WORD)) return;
|
| + Token::FUTURE_STRICT_RESERVED_WORD)) return;
|
| if (MatchState(input, 'r', PR)) return;
|
| if (MatchKeywordStart(input, "public", 1,
|
| - Token::FUTURE_RESERVED_WORD)) return;
|
| + Token::FUTURE_STRICT_RESERVED_WORD)) return;
|
| break;
|
| case PR:
|
| if (MatchKeywordStart(input, "private", 2,
|
| - Token::FUTURE_RESERVED_WORD)) return;
|
| + Token::FUTURE_STRICT_RESERVED_WORD)) return;
|
| if (MatchKeywordStart(input, "protected", 2,
|
| - Token::FUTURE_RESERVED_WORD)) return;
|
| + Token::FUTURE_STRICT_RESERVED_WORD)) return;
|
| break;
|
| case S:
|
| if (MatchKeywordStart(input, "static", 1,
|
| - Token::FUTURE_RESERVED_WORD)) return;
|
| + Token::FUTURE_STRICT_RESERVED_WORD)) return;
|
| if (MatchKeywordStart(input, "super", 1,
|
| - Token::FUTURE_RESERVED_WORD)) return;
|
| + Token::FUTURE_RESERVED_WORD)) return;
|
| if (MatchKeywordStart(input, "switch", 1,
|
| - Token::SWITCH)) return;
|
| + Token::SWITCH)) return;
|
| break;
|
| case T:
|
| if (MatchState(input, 'h', TH)) return;
|
|
|