Changeset 29075 in webkit for trunk/JavaScriptCore/kjs/lexer.cpp


Ignore:
Timestamp:
Jan 1, 2008, 10:44:22 PM (17 years ago)
Author:
Darin Adler
Message:

JavaScriptCore:

Reviewed by Eric.

Test: fast/js/kde/parse.html

  • kjs/lexer.cpp: (KJS::Lexer::lex): Added additional states to distinguish Unicode escapes at the start of identifiers from ones inside identifiers. Rejected characters that don't pass the isIdentStart and isIdentPart tests. (KJS::Lexer::convertUnicode): Removed incorrect FIXME comment.
  • kjs/lexer.h: Added new states to distinguish \u escapes at the start of identifiers from \u escapes inside identifiers.

LayoutTests:

Reviewed by Eric.

  • fast/js/kde/parse-expected.txt: Updated.
  • fast/js/kde/resources/parse.js: Added tests that cover both the non-ASCII characters themselves and the same characters parsed as \u sequences.
File:
1 edited

Legend:

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

    r28859 r29075  
    213213        state = InIdentifierOrKeyword;
    214214      } else if (current == '\\') {
    215         state = InIdentifierUnicodeEscapeStart;
     215        state = InIdentifierStartUnicodeEscapeStart;
    216216      } else if (current == '0') {
    217217        record8(current);
     
    342342        record16(current);
    343343      else if (current == '\\')
    344         state = InIdentifierUnicodeEscapeStart;
     344        state = InIdentifierPartUnicodeEscapeStart;
    345345      else
    346346        setDone(state == InIdentifierOrKeyword ? IdentifierOrKeyword : Identifier);
     
    419419        setDone(Number);
    420420      break;
    421     case InIdentifierUnicodeEscapeStart:
     421    case InIdentifierStartUnicodeEscapeStart:
    422422      if (current == 'u')
    423         state = InIdentifierUnicodeEscape;
     423        state = InIdentifierStartUnicodeEscape;
    424424      else
    425425        setDone(Bad);
    426426      break;
    427     case InIdentifierUnicodeEscape:
    428       if (isHexDigit(current) && isHexDigit(next1) && isHexDigit(next2) && isHexDigit(next3)) {
    429         record16(convertUnicode(current, next1, next2, next3));
    430         shift(3);
    431         state = InIdentifier;
    432       } else {
     427    case InIdentifierPartUnicodeEscapeStart:
     428      if (current == 'u')
     429        state = InIdentifierPartUnicodeEscape;
     430      else
    433431        setDone(Bad);
    434       }
     432      break;
     433    case InIdentifierStartUnicodeEscape:
     434      if (!isHexDigit(current) || !isHexDigit(next1) || !isHexDigit(next2) || !isHexDigit(next3)) {
     435        setDone(Bad);
     436        break;
     437      }
     438      token = convertUnicode(current, next1, next2, next3).uc;
     439      shift(3);
     440      if (!isIdentStart(token)) {
     441        setDone(Bad);
     442        break;
     443      }
     444      record16(token);
     445      state = InIdentifier;
     446      break;
     447    case InIdentifierPartUnicodeEscape:
     448      if (!isHexDigit(current) || !isHexDigit(next1) || !isHexDigit(next2) || !isHexDigit(next3)) {
     449        setDone(Bad);
     450        break;
     451      }
     452      token = convertUnicode(current, next1, next2, next3).uc;
     453      shift(3);
     454      if (!isIdentPart(token)) {
     455        setDone(Bad);
     456        break;
     457      }
     458      record16(token);
     459      state = InIdentifier;
    435460      break;
    436461    default:
     
    780805KJS::UChar Lexer::convertUnicode(int c1, int c2, int c3, int c4)
    781806{
    782   // FIXME: This conversion is lossy. See http://bugs.webkit.org/show_bug.cgi?id=4920.
    783807  return KJS::UChar((convertHex(c1) << 4) + convertHex(c2),
    784808               (convertHex(c3) << 4) + convertHex(c4));
Note: See TracChangeset for help on using the changeset viewer.