Changeset 91765 in webkit
- Timestamp:
- Jul 26, 2011, 10:53:40 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r91763 r91765 1 2011-07-26 Juan C. Montemayor <[email protected]> 2 3 JSON errors should be informative 4 https://bugs.webkit.org/show_bug.cgi?id=63339 5 6 Updated expected test results. 7 8 Reviewed by Oliver Hunt. 9 10 * fast/js/JSON-parse-expected.txt: 11 * platform/chromium/fast/js/JSON-parse-expected.txt: Added. 12 1 13 2011-07-26 Emil A Eklund <[email protected]> 2 14 -
trunk/LayoutTests/fast/js/JSON-parse-expected.txt
r91715 r91765 6 6 return jsonObject.parse(''); 7 7 } 8 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.8 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Unexpected EOF. 9 9 function (jsonObject) { 10 10 return jsonObject.parse('1'); … … 18 18 return jsonObject.parse('Infinity'); 19 19 } 20 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.20 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Unexpected identifier "Infinity?". 21 21 function (jsonObject) { 22 22 return jsonObject.parse('NaN'); 23 23 } 24 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.24 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Unexpected identifier "NaN". 25 25 function (jsonObject) { 26 26 return jsonObject.parse('null'); … … 30 30 return jsonObject.parse('undefined'); 31 31 } 32 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.32 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Unexpected identifier "undefined". 33 33 function (jsonObject) { 34 34 return jsonObject.parse('{}'); … … 38 38 return jsonObject.parse('({})'); 39 39 } 40 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.40 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Unexpected token '('. 41 41 function (jsonObject) { 42 42 return jsonObject.parse('{a}'); 43 43 } 44 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.44 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Expected '}'. 45 45 function (jsonObject) { 46 46 return jsonObject.parse('{a:}'); 47 47 } 48 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.48 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Expected '}'. 49 49 function (jsonObject) { 50 50 return jsonObject.parse('{a:5}'); 51 51 } 52 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.52 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Expected '}'. 53 53 function (jsonObject) { 54 54 return jsonObject.parse('{a:5,}'); 55 55 } 56 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.56 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Expected '}'. 57 57 function (jsonObject) { 58 58 return jsonObject.parse('{"a"}'); 59 59 } 60 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.60 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Expected ':' before value in object property definition. 61 61 function (jsonObject) { 62 62 return jsonObject.parse('{"a":}'); 63 63 } 64 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.64 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Unexpected token '}'. 65 65 function (jsonObject) { 66 66 return jsonObject.parse('{"a":5}'); … … 74 74 return jsonObject.parse('{"a":5,}'); 75 75 } 76 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.76 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Property name must be a string literal. 77 77 json2.js did not throw for a test we expect to throw. 78 78 function (jsonObject) { 79 79 return jsonObject.parse('{"a":5,,}'); 80 80 } 81 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.81 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Property name must be a string literal. 82 82 function (jsonObject) { 83 83 return jsonObject.parse('{"a":5,"a",}'); 84 84 } 85 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.85 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Expected ':'. 86 86 function (jsonObject) { 87 87 return jsonObject.parse('{"a":(5,"a"),}'); 88 88 } 89 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.89 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Unexpected token '('. 90 90 function (jsonObject) { 91 91 return jsonObject.parse('[]'); … … 99 99 return jsonObject.parse('[1,]'); 100 100 } 101 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.101 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Unexpected comma at the end of array expression. 102 102 json2.js did not throw for a test we expect to throw. 103 103 function (jsonObject) { … … 108 108 return jsonObject.parse('[1,2,,]'); 109 109 } 110 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.110 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Unexpected token ','. 111 111 json2.js did not throw for a test we expect to throw. 112 112 function (jsonObject) { 113 113 return jsonObject.parse('[1,2,,4]'); 114 114 } 115 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.115 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Unexpected token ','. 116 116 json2.js did not throw for a test we expect to throw. 117 117 function (jsonObject) { … … 130 130 return jsonObject.parse('"a\\"'); 131 131 } 132 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSONstring.132 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Unterminated string. 133 133 function (jsonObject) { 134 134 return jsonObject.parse('"a\\z"'); 135 135 } 136 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.136 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Invalid escape character z. 137 137 function (jsonObject) { 138 138 return jsonObject.parse('"a\\\z"'); 139 139 } 140 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.140 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Invalid escape character z. 141 141 function (jsonObject) { 142 142 return jsonObject.parse('"a\\\\z"'); … … 154 154 return jsonObject.parse('"a\nz"'); 155 155 } 156 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSONstring.156 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Unterminated string. 157 157 function (jsonObject) { 158 158 return jsonObject.parse('"a\\nz"'); … … 162 162 return jsonObject.parse('"a\rz"'); 163 163 } 164 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSONstring.164 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Unterminated string. 165 165 function (jsonObject) { 166 166 return jsonObject.parse('"a\\rz"'); … … 178 178 return jsonObject.parse('"a\bz"'); 179 179 } 180 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSONstring.180 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Unterminated string. 181 181 json2.js did not throw for a test we expect to throw. 182 182 function (jsonObject) { … … 187 187 return jsonObject.parse('"a\rz"'); 188 188 } 189 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSONstring.189 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Unterminated string. 190 190 function (jsonObject) { 191 191 return jsonObject.parse('"a\\rz"'); … … 195 195 return jsonObject.parse('"a\\uz" '); 196 196 } 197 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.197 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: "\uz" " is not a valid unicode escape. 198 198 function (jsonObject) { 199 199 return jsonObject.parse('"a\\u0z" '); 200 200 } 201 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.201 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: "\u0z" " is not a valid unicode escape. 202 202 function (jsonObject) { 203 203 return jsonObject.parse('"a\\u00z" '); 204 204 } 205 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.205 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: "\u00z"" is not a valid unicode escape. 206 206 function (jsonObject) { 207 207 return jsonObject.parse('"a\\u000z" '); 208 208 } 209 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.209 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: "\u000z" is not a valid unicode escape. 210 210 function (jsonObject) { 211 211 return jsonObject.parse('"a\\u0000z" '); … … 223 223 return jsonObject.parse('"a\\u000Gz" '); 224 224 } 225 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.225 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: "\u000G" is not a valid unicode escape. 226 226 function (jsonObject) { 227 227 return jsonObject.parse('"a\\u000gz" '); 228 228 } 229 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.229 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: "\u000g" is not a valid unicode escape. 230 230 function (jsonObject) { 231 231 return jsonObject.parse('"a\\u00A0z" '); … … 239 239 return jsonObject.parse('"a\\u00G0z" '); 240 240 } 241 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.241 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: "\u00G0" is not a valid unicode escape. 242 242 function (jsonObject) { 243 243 return jsonObject.parse('"a\\u00g0z" '); 244 244 } 245 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.245 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: "\u00g0" is not a valid unicode escape. 246 246 function (jsonObject) { 247 247 return jsonObject.parse('"a\\u0A00z" '); … … 255 255 return jsonObject.parse('"a\\u0G00z" '); 256 256 } 257 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.257 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: "\u0G00" is not a valid unicode escape. 258 258 function (jsonObject) { 259 259 return jsonObject.parse('"a\\u0g00z" '); 260 260 } 261 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.261 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: "\u0g00" is not a valid unicode escape. 262 262 function (jsonObject) { 263 263 return jsonObject.parse('"a\\uA000z" '); … … 271 271 return jsonObject.parse('"a\\uG000z" '); 272 272 } 273 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.273 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: "\uG000" is not a valid unicode escape. 274 274 function (jsonObject) { 275 275 return jsonObject.parse('"a\\ug000z" '); 276 276 } 277 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.277 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: "\ug000" is not a valid unicode escape. 278 278 function (jsonObject) { 279 279 return jsonObject.parse('00'); 280 280 } 281 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.281 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Unable to parse JSON string. 282 282 json2.js did not throw for a test we expect to throw. 283 283 function (jsonObject) { 284 284 return jsonObject.parse('01'); 285 285 } 286 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.286 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Unable to parse JSON string. 287 287 json2.js did not throw for a test we expect to throw. 288 288 function (jsonObject) { 289 289 return jsonObject.parse('0.a'); 290 290 } 291 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.291 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Invalid digits after decimal point. 292 292 function (jsonObject) { 293 293 return jsonObject.parse('0x0'); 294 294 } 295 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.295 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Unable to parse JSON string. 296 296 function (jsonObject) { 297 297 return jsonObject.parse('2e1.3'); 298 298 } 299 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.299 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Unable to parse JSON string. 300 300 function (jsonObject) { 301 301 return jsonObject.parse('2e-+10'); 302 302 } 303 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.303 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Exponent symbols should be followed by an optional '+' or '-' and then by at least one number. 304 304 function (jsonObject) { 305 305 return jsonObject.parse('2e+-10'); 306 306 } 307 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.307 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Exponent symbols should be followed by an optional '+' or '-' and then by at least one number. 308 308 function (jsonObject) { 309 309 return jsonObject.parse('2e3e4'); 310 310 } 311 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.311 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Unable to parse JSON string. 312 312 function (jsonObject) { 313 313 return jsonObject.parse('-01.0'); 314 314 } 315 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.315 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Unable to parse JSON string. 316 316 function (jsonObject) { 317 317 return jsonObject.parse('-01'); 318 318 } 319 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.319 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Unable to parse JSON string. 320 320 json2.js did not throw for a test we expect to throw. 321 321 function (jsonObject) { 322 322 return jsonObject.parse('-01.a'); 323 323 } 324 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.324 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Invalid digits after decimal point. 325 325 function (jsonObject) { 326 326 return jsonObject.parse('1.e1'); 327 327 } 328 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.328 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Invalid digits after decimal point. 329 329 json2.js did not throw for a test we expect to throw. 330 330 function (jsonObject) { 331 331 return jsonObject.parse('{/* block comments are not allowed */}'); 332 332 } 333 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.333 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Unrecognized token '/'. 334 334 function (jsonObject) { 335 335 return jsonObject.parse('{// line comments are not allowed \n}'); 336 336 } 337 PASS tests[i](nativeJSON) threw exception SyntaxError: Unable to parse JSON string.337 PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Unrecognized token '/'. 338 338 function (jsonObject) { 339 339 return jsonObject.parse('true'); -
trunk/Source/JavaScriptCore/ChangeLog
r91756 r91765 1 2011-07-26 Juan C. Montemayor <[email protected]> 2 3 JSON errors should be informative 4 https://bugs.webkit.org/show_bug.cgi?id=63339 5 6 Added error messages to the JSON Parser. 7 8 Reviewed by Oliver Hunt. 9 10 * runtime/JSONObject.cpp: 11 (JSC::JSONProtoFuncParse): 12 * runtime/LiteralParser.cpp: 13 (JSC::LiteralParser::Lexer::lex): 14 (JSC::LiteralParser::Lexer::lexString): 15 (JSC::LiteralParser::Lexer::lexNumber): 16 (JSC::LiteralParser::parse): 17 * runtime/LiteralParser.h: 18 (JSC::LiteralParser::getErrorMessage): 19 (JSC::LiteralParser::Lexer::sawError): 20 (JSC::LiteralParser::Lexer::getErrorMessage): 21 1 22 2011-07-26 Sheriff Bot <[email protected]> 2 23 -
trunk/Source/JavaScriptCore/runtime/JSONObject.cpp
r91715 r91765 820 820 JSValue unfiltered = jsonParser.tryLiteralParse(); 821 821 if (!unfiltered) 822 return throwVMError(exec, createSyntaxError(exec, "Unable to parse JSON string"));822 return throwVMError(exec, createSyntaxError(exec, jsonParser.getErrorMessage())); 823 823 824 824 if (exec->argumentCount() < 2) -
trunk/Source/JavaScriptCore/runtime/LiteralParser.cpp
r91715 r91765 237 237 } 238 238 if (*m_ptr == '\'') { 239 if (mode == StrictJSON) 239 if (mode == StrictJSON) { 240 m_lexErrorMessage = "Single quotes (\') are not allowed in JSON"; 240 241 return TokError; 242 } 241 243 return lexString<mode, '\''>(token); 242 244 } 243 245 } 246 m_lexErrorMessage = String::format("Unrecognized token '%c'", *m_ptr).impl(); 244 247 return TokError; 245 248 } … … 275 278 builder.append(runStart, m_ptr - runStart); 276 279 ++m_ptr; 277 if (m_ptr >= m_end) 280 if (m_ptr >= m_end) { 281 m_lexErrorMessage = "Unterminated string"; 278 282 return TokError; 283 } 279 284 switch (*m_ptr) { 280 285 case '"': … … 312 317 313 318 case 'u': 314 if ((m_end - m_ptr) < 5) // uNNNN == 5 characters 319 if ((m_end - m_ptr) < 5) { 320 m_lexErrorMessage = "\\u must be followed by 4 hex digits"; 315 321 return TokError; 322 } // uNNNN == 5 characters 316 323 for (int i = 1; i < 5; i++) { 317 if (!isASCIIHexDigit(m_ptr[i])) 324 if (!isASCIIHexDigit(m_ptr[i])) { 325 m_lexErrorMessage = String::format("\"\\%s\" is not a valid unicode escape", UString(m_ptr, 5).ascii().data()).impl(); 318 326 return TokError; 327 } 319 328 } 320 329 builder.append(JSC::Lexer::convertUnicode(m_ptr[1], m_ptr[2], m_ptr[3], m_ptr[4])); … … 328 337 break; 329 338 } 339 m_lexErrorMessage = String::format("Invalid escape character %c", *m_ptr).impl(); 330 340 return TokError; 331 341 } … … 333 343 } while ((mode != NonStrictJSON) && m_ptr != runStart && (m_ptr < m_end) && *m_ptr != terminator); 334 344 335 if (m_ptr >= m_end || *m_ptr != terminator) 345 if (m_ptr >= m_end || *m_ptr != terminator) { 346 m_lexErrorMessage = "Unterminated string"; 336 347 return TokError; 348 } 337 349 338 350 if (builder.isEmpty()) { … … 377 389 while (m_ptr < m_end && isASCIIDigit(*m_ptr)) 378 390 ++m_ptr; 379 } else 391 } else { 392 m_lexErrorMessage = "Invalid number"; 380 393 return TokError; 394 } 381 395 382 396 // ('.' [0-9]+)? … … 384 398 ++m_ptr; 385 399 // [0-9]+ 386 if (m_ptr >= m_end || !isASCIIDigit(*m_ptr)) 400 if (m_ptr >= m_end || !isASCIIDigit(*m_ptr)) { 401 m_lexErrorMessage = "Invalid digits after decimal point"; 387 402 return TokError; 403 } 388 404 389 405 ++m_ptr; … … 417 433 418 434 // [0-9]+ 419 if (m_ptr >= m_end || !isASCIIDigit(*m_ptr)) 435 if (m_ptr >= m_end || !isASCIIDigit(*m_ptr)) { 436 m_lexErrorMessage = "Exponent symbols should be followed by an optional '+' or '-' and then by at least one number"; 420 437 return TokError; 438 } 421 439 422 440 ++m_ptr; … … 459 477 TokenType lastToken = m_lexer.currentToken().type; 460 478 if (m_lexer.next() == TokRBracket) { 461 if (lastToken == TokComma) 462 return JSValue(); 479 if (lastToken == TokComma) { 480 m_parseErrorMessage = "Unexpected comma at the end of array expression"; 481 return JSValue(); 482 } 463 483 m_lexer.next(); 464 484 lastValue = objectStack.last(); … … 476 496 goto doParseArrayStartExpression; 477 497 478 if (m_lexer.currentToken().type != TokRBracket) 498 if (m_lexer.currentToken().type != TokRBracket) { 499 m_parseErrorMessage = "Expected ']'"; 479 500 return JSValue(); 501 } 480 502 481 503 m_lexer.next(); … … 494 516 495 517 // Check for colon 496 if (m_lexer.next() != TokColon) 497 return JSValue(); 518 if (m_lexer.next() != TokColon) { 519 m_parseErrorMessage = "Expected ':' before value in object property definition"; 520 return JSValue(); 521 } 498 522 499 523 m_lexer.next(); … … 502 526 goto startParseExpression; 503 527 } 504 if (type != TokRBrace) 528 if (type != TokRBrace) { 529 m_parseErrorMessage = "Expected '}'"; 505 530 return JSValue(); 531 } 506 532 m_lexer.next(); 507 533 lastValue = objectStack.last(); … … 512 538 case DoParseObjectStartExpression: { 513 539 TokenType type = m_lexer.next(); 514 if (type != TokString && (m_mode == StrictJSON || type != TokIdentifier)) 540 if (type != TokString && (m_mode == StrictJSON || type != TokIdentifier)) { 541 m_parseErrorMessage = "Property name must be a string literal"; 515 542 return JSValue(); 543 } 516 544 Lexer::LiteralParserToken identifierToken = m_lexer.currentToken(); 517 545 518 546 // Check for colon 519 if (m_lexer.next() != TokColon) 547 if (m_lexer.next() != TokColon) { 548 m_parseErrorMessage = "Expected ':'"; 520 549 return JSValue(); 550 } 521 551 522 552 m_lexer.next(); … … 531 561 if (m_lexer.currentToken().type == TokComma) 532 562 goto doParseObjectStartExpression; 533 if (m_lexer.currentToken().type != TokRBrace) 563 if (m_lexer.currentToken().type != TokRBrace) { 564 m_parseErrorMessage = "Expected '}'"; 534 565 return JSValue(); 566 } 535 567 m_lexer.next(); 536 568 lastValue = objectStack.last(); … … 571 603 lastValue = jsBoolean(false); 572 604 break; 573 605 case TokRBracket: 606 m_parseErrorMessage = "Unexpected token ']'"; 607 return JSValue(); 608 case TokRBrace: 609 m_parseErrorMessage = "Unexpected token '}'"; 610 return JSValue(); 611 case TokIdentifier: 612 m_parseErrorMessage = String::format("Unexpected identifier \"%s\"", UString(m_lexer.currentToken().stringToken).ascii().data()).impl(); 613 return JSValue(); 614 case TokColon: 615 m_parseErrorMessage = "Unexpected token ':'"; 616 return JSValue(); 617 case TokLParen: 618 m_parseErrorMessage = "Unexpected token '('"; 619 return JSValue(); 620 case TokRParen: 621 m_parseErrorMessage = "Unexpected token ')'"; 622 return JSValue(); 623 case TokComma: 624 m_parseErrorMessage = "Unexpected token ','"; 625 return JSValue(); 626 case TokDot: 627 m_parseErrorMessage = "Unexpected token '.'"; 628 return JSValue(); 629 case TokAssign: 630 m_parseErrorMessage = "Unexpected token '='"; 631 return JSValue(); 632 case TokSemi: 633 m_parseErrorMessage = "Unexpected token ';'"; 634 return JSValue(); 635 case TokEnd: 636 m_parseErrorMessage = "Unexpected EOF"; 637 return JSValue(); 638 case TokError: 574 639 default: 575 640 // Error 641 m_parseErrorMessage = "Could not parse value expression"; 576 642 return JSValue(); 577 643 } … … 590 656 goto startParseExpression; 591 657 } 658 case TokRBracket: 659 m_parseErrorMessage = "Unexpected token ']'"; 660 return JSValue(); 661 case TokLBrace: 662 m_parseErrorMessage = "Unexpected token '{'"; 663 return JSValue(); 664 case TokRBrace: 665 m_parseErrorMessage = "Unexpected token '}'"; 666 return JSValue(); 667 case TokIdentifier: 668 m_parseErrorMessage = "Unexpected identifier"; 669 return JSValue(); 670 case TokColon: 671 m_parseErrorMessage = "Unexpected token ':'"; 672 return JSValue(); 673 case TokRParen: 674 m_parseErrorMessage = "Unexpected token ')'"; 675 return JSValue(); 676 case TokComma: 677 m_parseErrorMessage = "Unexpected token ','"; 678 return JSValue(); 679 case TokTrue: 680 m_parseErrorMessage = "Unexpected token 'true'"; 681 return JSValue(); 682 case TokFalse: 683 m_parseErrorMessage = "Unexpected token 'false'"; 684 return JSValue(); 685 case TokNull: 686 m_parseErrorMessage = "Unexpected token 'null'"; 687 return JSValue(); 688 case TokEnd: 689 m_parseErrorMessage = "Unexpected EOF"; 690 return JSValue(); 691 case TokDot: 692 m_parseErrorMessage = "Unexpected token '.'"; 693 return JSValue(); 694 case TokAssign: 695 m_parseErrorMessage = "Unexpected token '='"; 696 return JSValue(); 697 case TokSemi: 698 m_parseErrorMessage = "Unexpected token ';'"; 699 return JSValue(); 700 case TokError: 592 701 default: 702 m_parseErrorMessage = "Could not parse statement"; 593 703 return JSValue(); 594 704 } … … 600 710 if (m_lexer.next() == TokEnd) 601 711 return lastValue; 712 m_parseErrorMessage = "Unexpected content at end of JSON literal"; 602 713 return JSValue(); 603 714 } -
trunk/Source/JavaScriptCore/runtime/LiteralParser.h
r91715 r91765 42 42 , m_mode(mode) 43 43 { 44 } 45 46 UString getErrorMessage() 47 { 48 if (!m_lexer.getErrorMessage().isEmpty()) 49 return String::format("JSON Parse error: %s", m_lexer.getErrorMessage().ascii().data()).impl(); 50 if (!m_parseErrorMessage.isEmpty()) 51 return String::format("JSON Parse error: %s", m_parseErrorMessage.ascii().data()).impl(); 52 return "JSON Parse error: Unable to parse JSON string"; 44 53 } 45 54 … … 113 122 } 114 123 124 UString getErrorMessage() { return m_lexErrorMessage; } 125 115 126 private: 127 UString m_lexErrorMessage; 116 128 template <ParserMode mode> TokenType lex(LiteralParserToken&); 117 129 template <ParserMode mode, UChar terminator> ALWAYS_INLINE TokenType lexString(LiteralParserToken&); … … 130 142 LiteralParser::Lexer m_lexer; 131 143 ParserMode m_mode; 144 UString m_parseErrorMessage; 132 145 static unsigned const MaximumCachableCharacter = 128; 133 146 FixedArray<Identifier, MaximumCachableCharacter> m_shortIdentifiers;
Note:
See TracChangeset
for help on using the changeset viewer.