Changeset 11879 in webkit for trunk/JavaScriptCore/kjs
- Timestamp:
- Jan 4, 2006, 1:44:25 PM (19 years ago)
- Location:
- trunk/JavaScriptCore/kjs
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/function_object.cpp
r11527 r11879 222 222 FunctionBodyNode *bodyNode = progNode.get(); 223 223 224 FunctionImp *fimp = new DeclaredFunctionImp(exec, Identifier::null(), bodyNode, 225 scopeChain); 226 224 FunctionImp *fimp = new DeclaredFunctionImp(exec, Identifier::null(), bodyNode, scopeChain); 225 227 226 // parse parameter list. throw syntax error on illegal identifiers 228 227 int len = p.size(); … … 232 231 while (i < len) { 233 232 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 255 253 } 256 254 return throwError(exec, SyntaxError, "Syntax error in parameter list"); 257 255 } 258 256 259 257 List consArgs; 260 258 -
trunk/JavaScriptCore/kjs/lexer.cpp
r10933 r11879 42 42 #include <unicode/uchar.h> 43 43 44 static bool isDecimalDigit(unsigned short c); 45 44 46 // we can't specify the namespace in yacc's C output, so do it here 45 47 using namespace KJS; … … 134 136 do { 135 137 if (pos >= length) { 136 137 138 next3 = 0; 139 break; 138 140 } 139 141 next3 = code[pos++].uc; … … 215 217 state = InString; 216 218 stringType = current; 217 } else if (isIdent Letter(current)) {219 } else if (isIdentStart(current)) { 218 220 record16(current); 219 state = InIdentifier; 221 state = InIdentifierOrKeyword; 222 } else if (current == '\\') { 223 state = InIdentifierUnicodeEscapeStart; 220 224 } else if (current == '0') { 221 225 record8(current); … … 306 310 break; 307 311 case InUnicodeEscape: 308 if (isHexDigit(current) && isHexDigit(next1) && 309 isHexDigit(next2) && isHexDigit(next3)) { 312 if (isHexDigit(current) && isHexDigit(next1) && isHexDigit(next2) && isHexDigit(next3)) { 310 313 record16(convertUnicode(current, next1, next2, next3)); 311 314 shift(3); … … 342 345 } 343 346 break; 347 case InIdentifierOrKeyword: 344 348 case InIdentifier: 345 if (isIdent Letter(current) || isDecimalDigit(current)) {349 if (isIdentPart(current)) 346 350 record16(current); 347 break; 348 } 349 setDone(Identifier); 351 else if (current == '\\') 352 state = InIdentifierUnicodeEscapeStart; 353 else 354 setDone(state == InIdentifierOrKeyword ? IdentifierOrKeyword : Identifier); 350 355 break; 351 356 case InNum0: … … 421 426 } else 422 427 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 } 423 443 break; 424 444 default: … … 436 456 437 457 // 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)) 440 459 state = Bad; 441 460 … … 507 526 } 508 527 break; 528 case IdentifierOrKeyword: 529 if ((token = Lookup::find(&mainTable, buffer16, pos16)) < 0) { 509 530 case Identifier: 510 if ((token = Lookup::find(&mainTable, buffer16, pos16)) < 0) {511 531 // Lookup for keyword failed, means this is an identifier 512 532 // Apply anonymous-function hack below (eat the identifier) … … 553 573 bool Lexer::isWhiteSpace() const 554 574 { 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); 557 576 } 558 577 … … 565 584 else if (lf) 566 585 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 589 bool 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 594 bool 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 599 static bool isDecimalDigit(unsigned short c) 579 600 { 580 601 return (c >= '0' && c <= '9'); … … 823 844 } 824 845 825 while (isIdent Letter(current)) {846 while (isIdentPart(current)) { 826 847 record16(current); 827 848 shift(1); -
trunk/JavaScriptCore/kjs/lexer.h
r9768 r11879 48 48 49 49 enum State { Start, 50 IdentifierOrKeyword, 50 51 Identifier, 52 InIdentifierOrKeyword, 51 53 InIdentifier, 54 InIdentifierUnicodeEscapeStart, 55 InIdentifierUnicodeEscape, 52 56 InSingleLineComment, 53 57 InMultiLineComment, … … 113 117 static UChar convertUnicode(unsigned short c1, unsigned short c2, 114 118 unsigned short c3, unsigned short c4); 115 static bool isIdent Letter(unsigned short c);116 static bool is DecimalDigit(unsigned short c);119 static bool isIdentStart(unsigned short c); 120 static bool isIdentPart(unsigned short c); 117 121 static bool isHexDigit(unsigned short c); 118 122
Note:
See TracChangeset
for help on using the changeset viewer.