OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 // entry was added to the data. | 526 // entry was added to the data. |
527 int marker; | 527 int marker; |
528 isolate->stack_guard()->SetStackLimit( | 528 isolate->stack_guard()->SetStackLimit( |
529 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 529 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
530 | 530 |
531 const char* program = | 531 const char* program = |
532 "try { } catch (e) { var foo = function () { /* first */ } }" | 532 "try { } catch (e) { var foo = function () { /* first */ } }" |
533 "var bar = function () { /* second */ }"; | 533 "var bar = function () { /* second */ }"; |
534 | 534 |
535 v8::HandleScope handles(CcTest::isolate()); | 535 v8::HandleScope handles(CcTest::isolate()); |
536 i::Handle<i::String> source( | 536 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(program); |
537 factory->NewStringFromAscii(i::CStrVector(program))); | |
538 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); | 537 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); |
539 i::CompleteParserRecorder log; | 538 i::CompleteParserRecorder log; |
540 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 539 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
541 scanner.Initialize(&stream); | 540 scanner.Initialize(&stream); |
542 i::PreParser preparser(&scanner, &log, | 541 i::PreParser preparser(&scanner, &log, |
543 CcTest::i_isolate()->stack_guard()->real_climit()); | 542 CcTest::i_isolate()->stack_guard()->real_climit()); |
544 preparser.set_allow_lazy(true); | 543 preparser.set_allow_lazy(true); |
545 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 544 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
546 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 545 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
547 i::ScriptData data(log.ExtractData()); | 546 i::ScriptData data(log.ExtractData()); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 if (end == 0) end = length; | 622 if (end == 0) end = length; |
624 unsigned sub_length = end - start; | 623 unsigned sub_length = end - start; |
625 i::Isolate* isolate = CcTest::i_isolate(); | 624 i::Isolate* isolate = CcTest::i_isolate(); |
626 i::Factory* factory = isolate->factory(); | 625 i::Factory* factory = isolate->factory(); |
627 i::HandleScope test_scope(isolate); | 626 i::HandleScope test_scope(isolate); |
628 i::SmartArrayPointer<i::uc16> uc16_buffer(new i::uc16[length]); | 627 i::SmartArrayPointer<i::uc16> uc16_buffer(new i::uc16[length]); |
629 for (unsigned i = 0; i < length; i++) { | 628 for (unsigned i = 0; i < length; i++) { |
630 uc16_buffer[i] = static_cast<i::uc16>(ascii_source[i]); | 629 uc16_buffer[i] = static_cast<i::uc16>(ascii_source[i]); |
631 } | 630 } |
632 i::Vector<const char> ascii_vector(ascii_source, static_cast<int>(length)); | 631 i::Vector<const char> ascii_vector(ascii_source, static_cast<int>(length)); |
633 i::Handle<i::String> ascii_string( | 632 i::Handle<i::String> ascii_string = |
634 factory->NewStringFromAscii(ascii_vector)); | 633 factory->NewStringFromAscii(ascii_vector).ToHandleChecked(); |
635 TestExternalResource resource(uc16_buffer.get(), length); | 634 TestExternalResource resource(uc16_buffer.get(), length); |
636 i::Handle<i::String> uc16_string( | 635 i::Handle<i::String> uc16_string( |
637 factory->NewExternalStringFromTwoByte(&resource).ToHandleChecked()); | 636 factory->NewExternalStringFromTwoByte(&resource).ToHandleChecked()); |
638 | 637 |
639 i::ExternalTwoByteStringUtf16CharacterStream uc16_stream( | 638 i::ExternalTwoByteStringUtf16CharacterStream uc16_stream( |
640 i::Handle<i::ExternalTwoByteString>::cast(uc16_string), start, end); | 639 i::Handle<i::ExternalTwoByteString>::cast(uc16_string), start, end); |
641 i::GenericStringUtf16CharacterStream string_stream(ascii_string, start, end); | 640 i::GenericStringUtf16CharacterStream string_stream(ascii_string, start, end); |
642 i::Utf8ToUtf16CharacterStream utf8_stream( | 641 i::Utf8ToUtf16CharacterStream utf8_stream( |
643 reinterpret_cast<const i::byte*>(ascii_source), end); | 642 reinterpret_cast<const i::byte*>(ascii_source), end); |
644 utf8_stream.SeekForward(start); | 643 utf8_stream.SeekForward(start); |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1202 int kSuffixByteLen = i::StrLength(source_data[i].outer_suffix); | 1201 int kSuffixByteLen = i::StrLength(source_data[i].outer_suffix); |
1203 int kProgramSize = kPrefixLen + kInnerLen + kSuffixLen; | 1202 int kProgramSize = kPrefixLen + kInnerLen + kSuffixLen; |
1204 int kProgramByteSize = kPrefixByteLen + kInnerByteLen + kSuffixByteLen; | 1203 int kProgramByteSize = kPrefixByteLen + kInnerByteLen + kSuffixByteLen; |
1205 i::ScopedVector<char> program(kProgramByteSize + 1); | 1204 i::ScopedVector<char> program(kProgramByteSize + 1); |
1206 i::OS::SNPrintF(program, "%s%s%s", | 1205 i::OS::SNPrintF(program, "%s%s%s", |
1207 source_data[i].outer_prefix, | 1206 source_data[i].outer_prefix, |
1208 source_data[i].inner_source, | 1207 source_data[i].inner_source, |
1209 source_data[i].outer_suffix); | 1208 source_data[i].outer_suffix); |
1210 | 1209 |
1211 // Parse program source. | 1210 // Parse program source. |
1212 i::Handle<i::String> source( | 1211 i::Handle<i::String> source = factory->NewStringFromUtf8( |
1213 factory->NewStringFromUtf8(i::CStrVector(program.start()))); | 1212 i::CStrVector(program.start())).ToHandleChecked(); |
1214 CHECK_EQ(source->length(), kProgramSize); | 1213 CHECK_EQ(source->length(), kProgramSize); |
1215 i::Handle<i::Script> script = factory->NewScript(source); | 1214 i::Handle<i::Script> script = factory->NewScript(source); |
1216 i::CompilationInfoWithZone info(script); | 1215 i::CompilationInfoWithZone info(script); |
1217 i::Parser parser(&info); | 1216 i::Parser parser(&info); |
1218 parser.set_allow_lazy(true); | 1217 parser.set_allow_lazy(true); |
1219 parser.set_allow_harmony_scoping(true); | 1218 parser.set_allow_harmony_scoping(true); |
1220 info.MarkAsGlobal(); | 1219 info.MarkAsGlobal(); |
1221 info.SetStrictMode(source_data[i].strict_mode); | 1220 info.SetStrictMode(source_data[i].strict_mode); |
1222 parser.Parse(); | 1221 parser.Parse(); |
1223 CHECK(info.function() != NULL); | 1222 CHECK(info.function() != NULL); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1396 CHECK(false); | 1395 CHECK(false); |
1397 } | 1396 } |
1398 } | 1397 } |
1399 | 1398 |
1400 | 1399 |
1401 void TestParserSync(const char* source, | 1400 void TestParserSync(const char* source, |
1402 const ParserFlag* flag_list, | 1401 const ParserFlag* flag_list, |
1403 size_t flag_list_length, | 1402 size_t flag_list_length, |
1404 ParserSyncTestResult result = kSuccessOrError) { | 1403 ParserSyncTestResult result = kSuccessOrError) { |
1405 i::Handle<i::String> str = | 1404 i::Handle<i::String> str = |
1406 CcTest::i_isolate()->factory()->NewStringFromAscii(i::CStrVector(source)); | 1405 CcTest::i_isolate()->factory()->NewStringFromAsciiChecked(source); |
1407 for (int bits = 0; bits < (1 << flag_list_length); bits++) { | 1406 for (int bits = 0; bits < (1 << flag_list_length); bits++) { |
1408 i::EnumSet<ParserFlag> flags; | 1407 i::EnumSet<ParserFlag> flags; |
1409 for (size_t flag_index = 0; flag_index < flag_list_length; flag_index++) { | 1408 for (size_t flag_index = 0; flag_index < flag_list_length; flag_index++) { |
1410 if ((bits & (1 << flag_index)) != 0) flags.Add(flag_list[flag_index]); | 1409 if ((bits & (1 << flag_index)) != 0) flags.Add(flag_list[flag_index]); |
1411 } | 1410 } |
1412 TestParserSyncWithFlags(str, flags, result); | 1411 TestParserSyncWithFlags(str, flags, result); |
1413 } | 1412 } |
1414 } | 1413 } |
1415 | 1414 |
1416 | 1415 |
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2093 {"function lazy() { var a, b, c; }", 1, 1}, | 2092 {"function lazy() { var a, b, c; }", 1, 1}, |
2094 {"function lazy() { a: 1; b: 2; c: 3; }", 1, 1}, | 2093 {"function lazy() { a: 1; b: 2; c: 3; }", 1, 1}, |
2095 {"function lazy() { function a() {} function b() {} function c() {} }", 1, | 2094 {"function lazy() { function a() {} function b() {} function c() {} }", 1, |
2096 1}, | 2095 1}, |
2097 {NULL, 0, 0} | 2096 {NULL, 0, 0} |
2098 }; | 2097 }; |
2099 | 2098 |
2100 for (int i = 0; test_cases[i].program; i++) { | 2099 for (int i = 0; test_cases[i].program; i++) { |
2101 const char* program = test_cases[i].program; | 2100 const char* program = test_cases[i].program; |
2102 i::Factory* factory = CcTest::i_isolate()->factory(); | 2101 i::Factory* factory = CcTest::i_isolate()->factory(); |
2103 i::Handle<i::String> source( | 2102 i::Handle<i::String> source = |
2104 factory->NewStringFromUtf8(i::CStrVector(program))); | 2103 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked(); |
2105 i::Handle<i::Script> script = factory->NewScript(source); | 2104 i::Handle<i::Script> script = factory->NewScript(source); |
2106 i::CompilationInfoWithZone info(script); | 2105 i::CompilationInfoWithZone info(script); |
2107 i::ScriptData* data = NULL; | 2106 i::ScriptData* data = NULL; |
2108 info.SetCachedData(&data, i::PRODUCE_CACHED_DATA); | 2107 info.SetCachedData(&data, i::PRODUCE_CACHED_DATA); |
2109 i::Parser::Parse(&info, true); | 2108 i::Parser::Parse(&info, true); |
2110 CHECK(data); | 2109 CHECK(data); |
2111 CHECK(!data->HasError()); | 2110 CHECK(!data->HasError()); |
2112 | 2111 |
2113 if (data->symbol_count() != test_cases[i].symbols) { | 2112 if (data->symbol_count() != test_cases[i].symbols) { |
2114 i::OS::Print( | 2113 i::OS::Print( |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2567 RunParserSyncTest(assignment_context_data, bad_statement_data_common, kError); | 2566 RunParserSyncTest(assignment_context_data, bad_statement_data_common, kError); |
2568 RunParserSyncTest(assignment_context_data, bad_statement_data_for_assignment, | 2567 RunParserSyncTest(assignment_context_data, bad_statement_data_for_assignment, |
2569 kError); | 2568 kError); |
2570 | 2569 |
2571 RunParserSyncTest(prefix_context_data, good_statement_data, kSuccess); | 2570 RunParserSyncTest(prefix_context_data, good_statement_data, kSuccess); |
2572 RunParserSyncTest(prefix_context_data, bad_statement_data_common, kError); | 2571 RunParserSyncTest(prefix_context_data, bad_statement_data_common, kError); |
2573 | 2572 |
2574 RunParserSyncTest(postfix_context_data, good_statement_data, kSuccess); | 2573 RunParserSyncTest(postfix_context_data, good_statement_data, kSuccess); |
2575 RunParserSyncTest(postfix_context_data, bad_statement_data_common, kError); | 2574 RunParserSyncTest(postfix_context_data, bad_statement_data_common, kError); |
2576 } | 2575 } |
OLD | NEW |