Changeset 11879 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Jan 4, 2006, 1:44:25 PM (19 years ago)
Author:
ggaren
Message:

Patch by [email protected], reviewed by darin, tweaked by me.

  • kjs/function_object.cpp: (FunctionObjectImp::construct):
  • kjs/lexer.cpp: (Lexer::shift): (Lexer::lex): (Lexer::isWhiteSpace): (Lexer::isLineTerminator): (Lexer::isIdentStart): (Lexer::isIdentPart): (isDecimalDigit): (Lexer::scanRegExp):
  • kjs/lexer.h: (KJS::Lexer::):
  • tests/mozilla/expected.html: Updated test results.
Location:
trunk/JavaScriptCore/kjs
Files:
3 edited

Legend:

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

    r11527 r11879  
    222222  FunctionBodyNode *bodyNode = progNode.get();
    223223
    224   FunctionImp *fimp = new DeclaredFunctionImp(exec, Identifier::null(), bodyNode,
    225                                               scopeChain);
    226 
     224  FunctionImp *fimp = new DeclaredFunctionImp(exec, Identifier::null(), bodyNode, scopeChain);
     225 
    227226  // parse parameter list. throw syntax error on illegal identifiers
    228227  int len = p.size();
     
    232231  while (i < len) {
    233232      while (*c == ' ' && i < len)
    234           c++, i++;
    235       if (Lexer::isIdentLetter(c->uc)) {  // else error
    236           param = UString(c, 1);
    237           c++, i++;
    238           while (i < len && (Lexer::isIdentLetter(c->uc) ||
    239                              Lexer::isDecimalDigit(c->uc))) {
    240               param += UString(c, 1);
    241               c++, i++;
    242           }
    243           while (i < len && *c == ' ')
    244               c++, i++;
    245           if (i == len) {
    246               fimp->addParameter(Identifier(param));
    247               params++;
    248               break;
    249           } else if (*c == ',') {
    250               fimp->addParameter(Identifier(param));
    251               params++;
    252               c++, i++;
    253               continue;
    254           } // else error
     233          c++, i++;
     234      if (Lexer::isIdentStart(c->uc)) {  // else error
     235          param = UString(c, 1);
     236          c++, i++;
     237          while (i < len && (Lexer::isIdentPart(c->uc))) {
     238              param += UString(c, 1);
     239              c++, i++;
     240          }
     241          while (i < len && *c == ' ')
     242              c++, i++;
     243          if (i == len) {
     244              fimp->addParameter(Identifier(param));
     245              params++;
     246              break;
     247          } else if (*c == ',') {
     248              fimp->addParameter(Identifier(param));
     249              params++;
     250              c++, i++;
     251              continue;
     252          } // else error
    255253      }
    256254      return throwError(exec, SyntaxError, "Syntax error in parameter list");
    257255  }
    258 
     256 
    259257  List consArgs;
    260258
  • trunk/JavaScriptCore/kjs/lexer.cpp

    r10933 r11879  
    4242#include <unicode/uchar.h>
    4343
     44static bool isDecimalDigit(unsigned short c);
     45
    4446// we can't specify the namespace in yacc's C output, so do it here
    4547using namespace KJS;
     
    134136    do {
    135137      if (pos >= length) {
    136         next3 = 0;
    137         break;
     138        next3 = 0;
     139        break;
    138140      }
    139141      next3 = code[pos++].uc;
     
    215217        state = InString;
    216218        stringType = current;
    217       } else if (isIdentLetter(current)) {
     219      } else if (isIdentStart(current)) {
    218220        record16(current);
    219         state = InIdentifier;
     221        state = InIdentifierOrKeyword;
     222      } else if (current == '\\') {
     223        state = InIdentifierUnicodeEscapeStart;
    220224      } else if (current == '0') {
    221225        record8(current);
     
    306310      break;
    307311    case InUnicodeEscape:
    308       if (isHexDigit(current) && isHexDigit(next1) &&
    309           isHexDigit(next2) && isHexDigit(next3)) {
     312      if (isHexDigit(current) && isHexDigit(next1) && isHexDigit(next2) && isHexDigit(next3)) {
    310313        record16(convertUnicode(current, next1, next2, next3));
    311314        shift(3);
     
    342345      }
    343346      break;
     347    case InIdentifierOrKeyword:
    344348    case InIdentifier:
    345       if (isIdentLetter(current) || isDecimalDigit(current)) {
     349      if (isIdentPart(current))
    346350        record16(current);
    347         break;
    348       }
    349       setDone(Identifier);
     351      else if (current == '\\')
     352        state = InIdentifierUnicodeEscapeStart;
     353      else
     354        setDone(state == InIdentifierOrKeyword ? IdentifierOrKeyword : Identifier);
    350355      break;
    351356    case InNum0:
     
    421426      } else
    422427        setDone(Number);
     428      break;
     429    case InIdentifierUnicodeEscapeStart:
     430      if (current == 'u')
     431        state = InIdentifierUnicodeEscape;
     432      else
     433        setDone(Bad);
     434      break;
     435    case InIdentifierUnicodeEscape:
     436      if (isHexDigit(current) && isHexDigit(next1) && isHexDigit(next2) && isHexDigit(next3)) {
     437        record16(convertUnicode(current, next1, next2, next3));
     438        shift(3);
     439        state = InIdentifier;
     440      } else {
     441        setDone(Bad);
     442      }
    423443      break;
    424444    default:
     
    436456
    437457  // no identifiers allowed directly after numeric literal, e.g. "3in" is bad
    438   if ((state == Number || state == Octal || state == Hex)
    439       && isIdentLetter(current))
     458  if ((state == Number || state == Octal || state == Hex) && isIdentStart(current))
    440459    state = Bad;
    441460
     
    507526    }
    508527    break;
     528  case IdentifierOrKeyword:
     529    if ((token = Lookup::find(&mainTable, buffer16, pos16)) < 0) {
    509530  case Identifier:
    510     if ((token = Lookup::find(&mainTable, buffer16, pos16)) < 0) {
    511531      // Lookup for keyword failed, means this is an identifier
    512532      // Apply anonymous-function hack below (eat the identifier)
     
    553573bool Lexer::isWhiteSpace() const
    554574{
    555   return (current == ' ' || current == '\t' ||
    556           current == 0x0b || current == 0x0c || current == 0xa0);
     575  return (current == '\t' || current == 0x0b || current == 0x0c || u_charType(current) == U_SPACE_SEPARATOR);
    557576}
    558577
     
    565584  else if (lf)
    566585      skipCR = true;
    567   return cr || lf;
    568 }
    569 
    570 bool Lexer::isIdentLetter(unsigned short c)
    571 {
    572   /* TODO: allow other legitimate unicode chars */
    573   return (c >= 'a' && c <= 'z' ||
    574           c >= 'A' && c <= 'Z' ||
    575           c == '$' || c == '_');
    576 }
    577 
    578 bool Lexer::isDecimalDigit(unsigned short c)
     586  return cr || lf || current == 0x2028 || current == 0x2029;
     587}
     588
     589bool Lexer::isIdentStart(unsigned short c)
     590{
     591  return (U_GET_GC_MASK(c) & (U_GC_L_MASK | U_GC_NL_MASK)) || c == '$' || c == '_';
     592}
     593
     594bool Lexer::isIdentPart(unsigned short c)
     595{
     596  return (U_GET_GC_MASK(c) & (U_GC_L_MASK | U_GC_NL_MASK | U_GC_MN_MASK | U_GC_MC_MASK | U_GC_ND_MASK | U_GC_PC_MASK)) || c == '$' || c == '_';
     597}
     598
     599static bool isDecimalDigit(unsigned short c)
    579600{
    580601  return (c >= '0' && c <= '9');
     
    823844  }
    824845
    825   while (isIdentLetter(current)) {
     846  while (isIdentPart(current)) {
    826847    record16(current);
    827848    shift(1);
  • trunk/JavaScriptCore/kjs/lexer.h

    r9768 r11879  
    4848
    4949    enum State { Start,
     50                 IdentifierOrKeyword,
    5051                 Identifier,
     52                 InIdentifierOrKeyword,
    5153                 InIdentifier,
     54                 InIdentifierUnicodeEscapeStart,
     55                 InIdentifierUnicodeEscape,
    5256                 InSingleLineComment,
    5357                 InMultiLineComment,
     
    113117    static UChar convertUnicode(unsigned short c1, unsigned short c2,
    114118                                unsigned short c3, unsigned short c4);
    115     static bool isIdentLetter(unsigned short c);
    116     static bool isDecimalDigit(unsigned short c);
     119    static bool isIdentStart(unsigned short c);
     120    static bool isIdentPart(unsigned short c);
    117121    static bool isHexDigit(unsigned short c);
    118122
Note: See TracChangeset for help on using the changeset viewer.