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


Ignore:
Timestamp:
Oct 26, 2006, 10:30:25 PM (19 years ago)
Author:
bdash
Message:

2006-10-26 W. Andy Carrel <[email protected]>

Reviewed by Maciej.

  • kjs/lexer.cpp: (Lexer::Lexer): (Lexer::setCode): (Lexer::shift): Looking ahead one additional character for the benefit of scanRegExp (Lexer::scanRegExp): Change code to support unicode escapes in inline regexps.
  • kjs/lexer.h: Extra lookahead added.
  • tests/mozilla/ecma_2/RegExp/properties-001.js: Changed test to look for Unicode character rather than the '\u' escaped equivalent for .source and .toString().
File:
1 edited

Legend:

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

    r16542 r17354  
    6161    bol(true),
    6262#endif
    63     current(0), next1(0), next2(0), next3(0),
     63    current(0), next1(0), next2(0), next3(0), next4(0),
    6464    strings(0), numStrings(0), stringsCapacity(0),
    6565    identifiers(0), numIdentifiers(0), identifiersCapacity(0)
     
    119119  next2 = (length > 2) ? code[2].uc : -1;
    120120  next3 = (length > 3) ? code[3].uc : -1;
     121  next4 = (length > 4) ? code[4].uc : -1;
    121122}
    122123
     
    130131    next1 = next2;
    131132    next2 = next3;
    132     next3 = (pos + 3 < length) ? code[pos+3].uc : -1;
     133    next3 = next4;
     134    next4 = (pos + 4 < length) ? code[pos+4].uc : -1;
    133135  }
    134136}
     
    837839    else if (current != '/' || lastWasEscape == true || inBrackets == true)
    838840    {
    839         // keep track of '[' and ']'
    840         if ( !lastWasEscape ) {
     841        if (lastWasEscape) {
     842          // deal with unicode escapes in inline regexps
     843          if (current == 'u') {
     844            if (isHexDigit(next1) && isHexDigit(next2) &&
     845                isHexDigit(next3) && isHexDigit(next4)) {
     846              record16(convertUnicode(next1, next2, next3, next4));
     847              shift(5);
     848              lastWasEscape = false;
     849              continue;
     850            } else
     851              // this wasn't unicode after all
     852              record16('\\');
     853          }
     854        } else {
     855          // keep track of '[' and ']'
    841856          if ( current == '[' && !inBrackets )
    842857            inBrackets = true;
     
    844859            inBrackets = false;
    845860        }
    846         record16(current);
     861        // don't want to capture the '\' for unicode escapes
     862        if (current != '\\' || next1 != 'u')
     863          record16(current);
    847864        lastWasEscape =
    848865            !lastWasEscape && (current == '\\');
Note: See TracChangeset for help on using the changeset viewer.