OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 i::UnicodeCache unicode_cache; | 57 i::UnicodeCache unicode_cache; |
58 i::byte buffer[32]; | 58 i::byte buffer[32]; |
59 for (int i = 0; (key_token = keywords[i]).keyword != NULL; i++) { | 59 for (int i = 0; (key_token = keywords[i]).keyword != NULL; i++) { |
60 const i::byte* keyword = | 60 const i::byte* keyword = |
61 reinterpret_cast<const i::byte*>(key_token.keyword); | 61 reinterpret_cast<const i::byte*>(key_token.keyword); |
62 int length = i::StrLength(key_token.keyword); | 62 int length = i::StrLength(key_token.keyword); |
63 CHECK(static_cast<int>(sizeof(buffer)) >= length); | 63 CHECK(static_cast<int>(sizeof(buffer)) >= length); |
64 { | 64 { |
65 i::Utf8ToUC16CharacterStream stream(keyword, length); | 65 i::Utf8ToUC16CharacterStream stream(keyword, length); |
66 i::JavaScriptScanner scanner(&unicode_cache); | 66 i::JavaScriptScanner scanner(&unicode_cache); |
| 67 // The scanner should parse 'let' as Token::LET for this test. |
| 68 scanner.SetHarmonyBlockScoping(true); |
67 scanner.Initialize(&stream); | 69 scanner.Initialize(&stream); |
68 CHECK_EQ(key_token.token, scanner.Next()); | 70 CHECK_EQ(key_token.token, scanner.Next()); |
69 CHECK_EQ(i::Token::EOS, scanner.Next()); | 71 CHECK_EQ(i::Token::EOS, scanner.Next()); |
70 } | 72 } |
71 // Removing characters will make keyword matching fail. | 73 // Removing characters will make keyword matching fail. |
72 { | 74 { |
73 i::Utf8ToUC16CharacterStream stream(keyword, length - 1); | 75 i::Utf8ToUC16CharacterStream stream(keyword, length - 1); |
74 i::JavaScriptScanner scanner(&unicode_cache); | 76 i::JavaScriptScanner scanner(&unicode_cache); |
75 scanner.Initialize(&stream); | 77 scanner.Initialize(&stream); |
76 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); | 78 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 const char* program = "var x = 'something';\n" | 282 const char* program = "var x = 'something';\n" |
281 "escape: function() {}"; | 283 "escape: function() {}"; |
282 // Fails parsing expecting an identifier after "function". | 284 // Fails parsing expecting an identifier after "function". |
283 // Before fix, didn't check *ok after Expect(Token::Identifier, ok), | 285 // Before fix, didn't check *ok after Expect(Token::Identifier, ok), |
284 // and then used the invalid currently scanned literal. This always | 286 // and then used the invalid currently scanned literal. This always |
285 // failed in debug mode, and sometimes crashed in release mode. | 287 // failed in debug mode, and sometimes crashed in release mode. |
286 | 288 |
287 i::Utf8ToUC16CharacterStream stream(reinterpret_cast<const i::byte*>(program), | 289 i::Utf8ToUC16CharacterStream stream(reinterpret_cast<const i::byte*>(program), |
288 static_cast<unsigned>(strlen(program))); | 290 static_cast<unsigned>(strlen(program))); |
289 i::ScriptDataImpl* data = | 291 i::ScriptDataImpl* data = |
290 i::ParserApi::PreParse(&stream, NULL); | 292 i::ParserApi::PreParse(&stream, NULL, false); |
291 CHECK(data->HasError()); | 293 CHECK(data->HasError()); |
292 delete data; | 294 delete data; |
293 } | 295 } |
294 | 296 |
295 | 297 |
296 TEST(Regress928) { | 298 TEST(Regress928) { |
297 v8::V8::Initialize(); | 299 v8::V8::Initialize(); |
298 | 300 |
299 // Preparsing didn't consider the catch clause of a try statement | 301 // Preparsing didn't consider the catch clause of a try statement |
300 // as with-content, which made it assume that a function inside | 302 // as with-content, which made it assume that a function inside |
301 // the block could be lazily compiled, and an extra, unexpected, | 303 // the block could be lazily compiled, and an extra, unexpected, |
302 // entry was added to the data. | 304 // entry was added to the data. |
303 int marker; | 305 int marker; |
304 i::Isolate::Current()->stack_guard()->SetStackLimit( | 306 i::Isolate::Current()->stack_guard()->SetStackLimit( |
305 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 307 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
306 | 308 |
307 const char* program = | 309 const char* program = |
308 "try { } catch (e) { var foo = function () { /* first */ } }" | 310 "try { } catch (e) { var foo = function () { /* first */ } }" |
309 "var bar = function () { /* second */ }"; | 311 "var bar = function () { /* second */ }"; |
310 | 312 |
311 i::Utf8ToUC16CharacterStream stream(reinterpret_cast<const i::byte*>(program), | 313 i::Utf8ToUC16CharacterStream stream(reinterpret_cast<const i::byte*>(program), |
312 static_cast<unsigned>(strlen(program))); | 314 static_cast<unsigned>(strlen(program))); |
313 i::ScriptDataImpl* data = | 315 i::ScriptDataImpl* data = |
314 i::ParserApi::PartialPreParse(&stream, NULL); | 316 i::ParserApi::PartialPreParse(&stream, NULL, false); |
315 CHECK(!data->HasError()); | 317 CHECK(!data->HasError()); |
316 | 318 |
317 data->Initialize(); | 319 data->Initialize(); |
318 | 320 |
319 int first_function = | 321 int first_function = |
320 static_cast<int>(strstr(program, "function") - program); | 322 static_cast<int>(strstr(program, "function") - program); |
321 int first_lbrace = first_function + static_cast<int>(strlen("function () ")); | 323 int first_lbrace = first_function + static_cast<int>(strlen("function () ")); |
322 CHECK_EQ('{', program[first_lbrace]); | 324 CHECK_EQ('{', program[first_lbrace]); |
323 i::FunctionEntry entry1 = data->GetFunctionEntry(first_lbrace); | 325 i::FunctionEntry entry1 = data->GetFunctionEntry(first_lbrace); |
324 CHECK(!entry1.is_valid()); | 326 CHECK(!entry1.is_valid()); |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 TestScanRegExp("/[\\u12]/flipperwald", "[\\u12]"); | 699 TestScanRegExp("/[\\u12]/flipperwald", "[\\u12]"); |
698 TestScanRegExp("/[\\u123]/flipperwald", "[\\u123]"); | 700 TestScanRegExp("/[\\u123]/flipperwald", "[\\u123]"); |
699 // Escaped ']'s wont end the character class. | 701 // Escaped ']'s wont end the character class. |
700 TestScanRegExp("/[\\]/]/flipperwald", "[\\]/]"); | 702 TestScanRegExp("/[\\]/]/flipperwald", "[\\]/]"); |
701 // Escaped slashes are not terminating. | 703 // Escaped slashes are not terminating. |
702 TestScanRegExp("/\\//flipperwald", "\\/"); | 704 TestScanRegExp("/\\//flipperwald", "\\/"); |
703 // Starting with '=' works too. | 705 // Starting with '=' works too. |
704 TestScanRegExp("/=/", "="); | 706 TestScanRegExp("/=/", "="); |
705 TestScanRegExp("/=?/", "=?"); | 707 TestScanRegExp("/=?/", "=?"); |
706 } | 708 } |
OLD | NEW |