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 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 int kProgramByteSize = i::StrLength(surroundings[j].prefix) + | 818 int kProgramByteSize = i::StrLength(surroundings[j].prefix) + |
819 i::StrLength(surroundings[j].suffix) + | 819 i::StrLength(surroundings[j].suffix) + |
820 i::StrLength(source_data[i].body); | 820 i::StrLength(source_data[i].body); |
821 i::ScopedVector<char> program(kProgramByteSize + 1); | 821 i::ScopedVector<char> program(kProgramByteSize + 1); |
822 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix, | 822 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix, |
823 source_data[i].body, surroundings[j].suffix); | 823 source_data[i].body, surroundings[j].suffix); |
824 i::Handle<i::String> source = | 824 i::Handle<i::String> source = |
825 factory->NewStringFromUtf8(i::CStrVector(program.start())) | 825 factory->NewStringFromUtf8(i::CStrVector(program.start())) |
826 .ToHandleChecked(); | 826 .ToHandleChecked(); |
827 i::Handle<i::Script> script = factory->NewScript(source); | 827 i::Handle<i::Script> script = factory->NewScript(source); |
828 i::ParseInfo info(script); | 828 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 829 i::ParseInfo info(&zone, script); |
829 // The information we're checking is only produced when eager parsing. | 830 // The information we're checking is only produced when eager parsing. |
830 info.set_allow_lazy_parsing(false); | 831 info.set_allow_lazy_parsing(false); |
831 CHECK(i::parsing::ParseProgram(&info)); | 832 CHECK(i::parsing::ParseProgram(&info)); |
832 CHECK(i::Rewriter::Rewrite(&info)); | 833 CHECK(i::Rewriter::Rewrite(&info)); |
833 i::DeclarationScope::Analyze(&info, i::AnalyzeMode::kRegular); | 834 i::DeclarationScope::Analyze(&info, i::AnalyzeMode::kRegular); |
834 CHECK(info.literal() != NULL); | 835 CHECK(info.literal() != NULL); |
835 | 836 |
836 i::DeclarationScope* script_scope = info.literal()->scope(); | 837 i::DeclarationScope* script_scope = info.literal()->scope(); |
837 CHECK(script_scope->is_script_scope()); | 838 CHECK(script_scope->is_script_scope()); |
838 | 839 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 std::string full_source = "function f() { return "; | 875 std::string full_source = "function f() { return "; |
875 full_source += source; | 876 full_source += source; |
876 full_source += "; }"; | 877 full_source += "; }"; |
877 | 878 |
878 i::Handle<i::String> source_code = | 879 i::Handle<i::String> source_code = |
879 factory->NewStringFromUtf8(i::CStrVector(full_source.c_str())) | 880 factory->NewStringFromUtf8(i::CStrVector(full_source.c_str())) |
880 .ToHandleChecked(); | 881 .ToHandleChecked(); |
881 | 882 |
882 i::Handle<i::Script> script = factory->NewScript(source_code); | 883 i::Handle<i::Script> script = factory->NewScript(source_code); |
883 | 884 |
884 i::ParseInfo info(script); | 885 i::ParseInfo info(handles.main_zone(), script); |
885 i::Parser parser(&info); | 886 i::Parser parser(&info); |
886 info.set_allow_lazy_parsing(false); | 887 info.set_allow_lazy_parsing(false); |
887 info.set_toplevel(true); | 888 info.set_toplevel(true); |
888 | 889 |
889 CHECK(i::Compiler::ParseAndAnalyze(&info)); | 890 CHECK(i::Compiler::ParseAndAnalyze(&info)); |
890 | 891 |
891 CHECK_EQ(1, info.scope()->declarations()->LengthForTest()); | 892 CHECK_EQ(1, info.scope()->declarations()->LengthForTest()); |
892 i::Declaration* decl = info.scope()->declarations()->AtForTest(0); | 893 i::Declaration* decl = info.scope()->declarations()->AtForTest(0); |
893 i::FunctionLiteral* fun = decl->AsFunctionDeclaration()->fun(); | 894 i::FunctionLiteral* fun = decl->AsFunctionDeclaration()->fun(); |
894 CHECK(fun->body()->length() == 1); | 895 CHECK(fun->body()->length() == 1); |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 i::SNPrintF(program, "%s%s%s", | 1173 i::SNPrintF(program, "%s%s%s", |
1173 source_data[i].outer_prefix, | 1174 source_data[i].outer_prefix, |
1174 source_data[i].inner_source, | 1175 source_data[i].inner_source, |
1175 source_data[i].outer_suffix); | 1176 source_data[i].outer_suffix); |
1176 | 1177 |
1177 // Parse program source. | 1178 // Parse program source. |
1178 i::Handle<i::String> source = factory->NewStringFromUtf8( | 1179 i::Handle<i::String> source = factory->NewStringFromUtf8( |
1179 i::CStrVector(program.start())).ToHandleChecked(); | 1180 i::CStrVector(program.start())).ToHandleChecked(); |
1180 CHECK_EQ(source->length(), kProgramSize); | 1181 CHECK_EQ(source->length(), kProgramSize); |
1181 i::Handle<i::Script> script = factory->NewScript(source); | 1182 i::Handle<i::Script> script = factory->NewScript(source); |
1182 i::ParseInfo info(script); | 1183 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 1184 i::ParseInfo info(&zone, script); |
1183 info.set_language_mode(source_data[i].language_mode); | 1185 info.set_language_mode(source_data[i].language_mode); |
1184 i::parsing::ParseProgram(&info); | 1186 i::parsing::ParseProgram(&info); |
1185 CHECK_NOT_NULL(info.literal()); | 1187 CHECK_NOT_NULL(info.literal()); |
1186 | 1188 |
1187 // Check scope types and positions. | 1189 // Check scope types and positions. |
1188 i::Scope* scope = info.literal()->scope(); | 1190 i::Scope* scope = info.literal()->scope(); |
1189 CHECK(scope->is_script_scope()); | 1191 CHECK(scope->is_script_scope()); |
1190 CHECK_EQ(scope->start_position(), 0); | 1192 CHECK_EQ(scope->start_position(), 0); |
1191 CHECK_EQ(scope->end_position(), kProgramSize); | 1193 CHECK_EQ(scope->end_position(), kProgramSize); |
1192 | 1194 |
(...skipping 25 matching lines...) Expand all Loading... |
1218 i::Isolate* isolate = CcTest::i_isolate(); | 1220 i::Isolate* isolate = CcTest::i_isolate(); |
1219 i::Factory* factory = isolate->factory(); | 1221 i::Factory* factory = isolate->factory(); |
1220 v8::HandleScope handles(CcTest::isolate()); | 1222 v8::HandleScope handles(CcTest::isolate()); |
1221 i::FunctionLiteral* function; | 1223 i::FunctionLiteral* function; |
1222 | 1224 |
1223 for (int i = 0; discard_sources[i]; i++) { | 1225 for (int i = 0; discard_sources[i]; i++) { |
1224 const char* source = discard_sources[i]; | 1226 const char* source = discard_sources[i]; |
1225 i::Handle<i::String> source_code = | 1227 i::Handle<i::String> source_code = |
1226 factory->NewStringFromUtf8(i::CStrVector(source)).ToHandleChecked(); | 1228 factory->NewStringFromUtf8(i::CStrVector(source)).ToHandleChecked(); |
1227 i::Handle<i::Script> script = factory->NewScript(source_code); | 1229 i::Handle<i::Script> script = factory->NewScript(source_code); |
1228 i::ParseInfo info(script); | 1230 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 1231 i::ParseInfo info(&zone, script); |
1229 i::parsing::ParseProgram(&info); | 1232 i::parsing::ParseProgram(&info); |
1230 function = info.literal(); | 1233 function = info.literal(); |
1231 CHECK_NOT_NULL(function); | 1234 CHECK_NOT_NULL(function); |
1232 CHECK_NOT_NULL(function->body()); | 1235 CHECK_NOT_NULL(function->body()); |
1233 CHECK_EQ(1, function->body()->length()); | 1236 CHECK_EQ(1, function->body()->length()); |
1234 i::FunctionLiteral* inner = | 1237 i::FunctionLiteral* inner = |
1235 function->body()->first()->AsExpressionStatement()->expression()-> | 1238 function->body()->first()->AsExpressionStatement()->expression()-> |
1236 AsCall()->expression()->AsFunctionLiteral(); | 1239 AsCall()->expression()->AsFunctionLiteral(); |
1237 i::Scope* inner_scope = inner->scope(); | 1240 i::Scope* inner_scope = inner->scope(); |
1238 i::FunctionLiteral* fun = nullptr; | 1241 i::FunctionLiteral* fun = nullptr; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1344 scanner.Initialize(stream.get()); | 1347 scanner.Initialize(stream.get()); |
1345 i::PreParser::PreParseResult result = | 1348 i::PreParser::PreParseResult result = |
1346 preparser.PreParseProgram(&preparser_materialized_literals, is_module); | 1349 preparser.PreParseProgram(&preparser_materialized_literals, is_module); |
1347 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 1350 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
1348 } | 1351 } |
1349 | 1352 |
1350 // Parse the data | 1353 // Parse the data |
1351 i::FunctionLiteral* function; | 1354 i::FunctionLiteral* function; |
1352 { | 1355 { |
1353 i::Handle<i::Script> script = factory->NewScript(source); | 1356 i::Handle<i::Script> script = factory->NewScript(source); |
1354 i::ParseInfo info(script); | 1357 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 1358 i::ParseInfo info(&zone, script); |
1355 info.set_allow_lazy_parsing(flags.Contains(kAllowLazy)); | 1359 info.set_allow_lazy_parsing(flags.Contains(kAllowLazy)); |
1356 SetGlobalFlags(flags); | 1360 SetGlobalFlags(flags); |
1357 if (is_module) info.set_module(); | 1361 if (is_module) info.set_module(); |
1358 i::parsing::ParseProgram(&info); | 1362 i::parsing::ParseProgram(&info); |
1359 function = info.literal(); | 1363 function = info.literal(); |
1360 if (function) { | 1364 if (function) { |
1361 parser_materialized_literals = function->materialized_literal_count(); | 1365 parser_materialized_literals = function->materialized_literal_count(); |
1362 } | 1366 } |
1363 } | 1367 } |
1364 | 1368 |
(...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2475 {"function lazy() { var x = {get foo(){} } }", 1}, | 2479 {"function lazy() { var x = {get foo(){} } }", 1}, |
2476 {NULL, 0} | 2480 {NULL, 0} |
2477 }; | 2481 }; |
2478 | 2482 |
2479 for (int i = 0; test_cases[i].program; i++) { | 2483 for (int i = 0; test_cases[i].program; i++) { |
2480 const char* program = test_cases[i].program; | 2484 const char* program = test_cases[i].program; |
2481 i::Factory* factory = CcTest::i_isolate()->factory(); | 2485 i::Factory* factory = CcTest::i_isolate()->factory(); |
2482 i::Handle<i::String> source = | 2486 i::Handle<i::String> source = |
2483 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked(); | 2487 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked(); |
2484 i::Handle<i::Script> script = factory->NewScript(source); | 2488 i::Handle<i::Script> script = factory->NewScript(source); |
2485 i::ParseInfo info(script); | 2489 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 2490 i::ParseInfo info(&zone, script); |
2486 i::ScriptData* sd = NULL; | 2491 i::ScriptData* sd = NULL; |
2487 info.set_cached_data(&sd); | 2492 info.set_cached_data(&sd); |
2488 info.set_compile_options(v8::ScriptCompiler::kProduceParserCache); | 2493 info.set_compile_options(v8::ScriptCompiler::kProduceParserCache); |
2489 i::parsing::ParseProgram(&info); | 2494 i::parsing::ParseProgram(&info); |
2490 i::ParseData* pd = i::ParseData::FromCachedData(sd); | 2495 i::ParseData* pd = i::ParseData::FromCachedData(sd); |
2491 | 2496 |
2492 if (pd->FunctionCount() != test_cases[i].functions) { | 2497 if (pd->FunctionCount() != test_cases[i].functions) { |
2493 v8::base::OS::Print( | 2498 v8::base::OS::Print( |
2494 "Expected preparse data for program:\n" | 2499 "Expected preparse data for program:\n" |
2495 "\t%s\n" | 2500 "\t%s\n" |
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3362 if (outers[i].strict && inners[j].with) continue; | 3367 if (outers[i].strict && inners[j].with) continue; |
3363 const char* inner = inners[j].source; | 3368 const char* inner = inners[j].source; |
3364 int inner_len = Utf8LengthHelper(inner); | 3369 int inner_len = Utf8LengthHelper(inner); |
3365 | 3370 |
3366 int len = prefix_len + outer_len + midfix_len + inner_len + suffix_len; | 3371 int len = prefix_len + outer_len + midfix_len + inner_len + suffix_len; |
3367 i::ScopedVector<char> program(len + 1); | 3372 i::ScopedVector<char> program(len + 1); |
3368 | 3373 |
3369 i::SNPrintF(program, "%s%s%s%s%s", prefix, outer, midfix, inner, | 3374 i::SNPrintF(program, "%s%s%s%s%s", prefix, outer, midfix, inner, |
3370 suffix); | 3375 suffix); |
3371 | 3376 |
| 3377 i::Zone zone(isolate->allocator(), ZONE_NAME); |
3372 std::unique_ptr<i::ParseInfo> info; | 3378 std::unique_ptr<i::ParseInfo> info; |
3373 if (lazy) { | 3379 if (lazy) { |
3374 printf("%s\n", program.start()); | 3380 printf("%s\n", program.start()); |
3375 v8::Local<v8::Value> v = CompileRun(program.start()); | 3381 v8::Local<v8::Value> v = CompileRun(program.start()); |
3376 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v); | 3382 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v); |
3377 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); | 3383 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); |
3378 i::Handle<i::SharedFunctionInfo> shared = i::handle(f->shared()); | 3384 i::Handle<i::SharedFunctionInfo> shared = i::handle(f->shared()); |
3379 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(shared)); | 3385 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, shared)); |
3380 CHECK(i::parsing::ParseFunction(info.get())); | 3386 CHECK(i::parsing::ParseFunction(info.get())); |
3381 } else { | 3387 } else { |
3382 i::Handle<i::String> source = | 3388 i::Handle<i::String> source = |
3383 factory->InternalizeUtf8String(program.start()); | 3389 factory->InternalizeUtf8String(program.start()); |
3384 source->PrintOn(stdout); | 3390 source->PrintOn(stdout); |
3385 printf("\n"); | 3391 printf("\n"); |
3386 i::Handle<i::Script> script = factory->NewScript(source); | 3392 i::Handle<i::Script> script = factory->NewScript(source); |
3387 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(script)); | 3393 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, script)); |
3388 info->set_allow_lazy_parsing(false); | 3394 info->set_allow_lazy_parsing(false); |
3389 CHECK(i::parsing::ParseProgram(info.get())); | 3395 CHECK(i::parsing::ParseProgram(info.get())); |
3390 } | 3396 } |
3391 CHECK(i::Compiler::Analyze(info.get())); | 3397 CHECK(i::Compiler::Analyze(info.get())); |
3392 CHECK(info->literal() != NULL); | 3398 CHECK(info->literal() != NULL); |
3393 | 3399 |
3394 i::Scope* scope = info->literal()->scope(); | 3400 i::Scope* scope = info->literal()->scope(); |
3395 if (!lazy) { | 3401 if (!lazy) { |
3396 scope = scope->inner_scope(); | 3402 scope = scope->inner_scope(); |
3397 } | 3403 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3476 | 3482 |
3477 const char* suffix = "; f"; | 3483 const char* suffix = "; f"; |
3478 | 3484 |
3479 for (unsigned i = 0; i < arraysize(tests); ++i) { | 3485 for (unsigned i = 0; i < arraysize(tests); ++i) { |
3480 bool assigned = tests[i].arg_assigned; | 3486 bool assigned = tests[i].arg_assigned; |
3481 const char* source = tests[i].source; | 3487 const char* source = tests[i].source; |
3482 for (unsigned allow_lazy = 0; allow_lazy < 2; ++allow_lazy) { | 3488 for (unsigned allow_lazy = 0; allow_lazy < 2; ++allow_lazy) { |
3483 i::ScopedVector<char> program(Utf8LengthHelper(source) + | 3489 i::ScopedVector<char> program(Utf8LengthHelper(source) + |
3484 Utf8LengthHelper(suffix) + 1); | 3490 Utf8LengthHelper(suffix) + 1); |
3485 i::SNPrintF(program, "%s%s", source, suffix); | 3491 i::SNPrintF(program, "%s%s", source, suffix); |
| 3492 i::Zone zone(isolate->allocator(), ZONE_NAME); |
3486 std::unique_ptr<i::ParseInfo> info; | 3493 std::unique_ptr<i::ParseInfo> info; |
3487 printf("%s\n", program.start()); | 3494 printf("%s\n", program.start()); |
3488 v8::Local<v8::Value> v = CompileRun(program.start()); | 3495 v8::Local<v8::Value> v = CompileRun(program.start()); |
3489 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v); | 3496 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v); |
3490 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); | 3497 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); |
3491 i::Handle<i::SharedFunctionInfo> shared = i::handle(f->shared()); | 3498 i::Handle<i::SharedFunctionInfo> shared = i::handle(f->shared()); |
3492 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(shared)); | 3499 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, shared)); |
3493 info->set_allow_lazy_parsing(allow_lazy); | 3500 info->set_allow_lazy_parsing(allow_lazy); |
3494 CHECK(i::parsing::ParseFunction(info.get())); | 3501 CHECK(i::parsing::ParseFunction(info.get())); |
3495 CHECK(i::Compiler::Analyze(info.get())); | 3502 CHECK(i::Compiler::Analyze(info.get())); |
3496 CHECK_NOT_NULL(info->literal()); | 3503 CHECK_NOT_NULL(info->literal()); |
3497 | 3504 |
3498 i::Scope* scope = info->literal()->scope(); | 3505 i::Scope* scope = info->literal()->scope(); |
3499 CHECK(!scope->AsDeclarationScope()->was_lazily_parsed()); | 3506 CHECK(!scope->AsDeclarationScope()->was_lazily_parsed()); |
3500 CHECK_NULL(scope->sibling()); | 3507 CHECK_NULL(scope->sibling()); |
3501 CHECK(scope->is_function_scope()); | 3508 CHECK(scope->is_function_scope()); |
3502 const i::AstRawString* var_name = | 3509 const i::AstRawString* var_name = |
(...skipping 24 matching lines...) Expand all Loading... |
3527 "function* bar() {eval(ext)}; ext(bar); ext(foo)", | 3534 "function* bar() {eval(ext)}; ext(bar); ext(foo)", |
3528 }; | 3535 }; |
3529 | 3536 |
3530 for (unsigned i = 0; i < arraysize(prefixes); ++i) { | 3537 for (unsigned i = 0; i < arraysize(prefixes); ++i) { |
3531 const char* prefix = prefixes[i]; | 3538 const char* prefix = prefixes[i]; |
3532 for (unsigned j = 0; j < arraysize(sources); ++j) { | 3539 for (unsigned j = 0; j < arraysize(sources); ++j) { |
3533 const char* source = sources[j]; | 3540 const char* source = sources[j]; |
3534 i::ScopedVector<char> program(Utf8LengthHelper(prefix) + | 3541 i::ScopedVector<char> program(Utf8LengthHelper(prefix) + |
3535 Utf8LengthHelper(source) + 1); | 3542 Utf8LengthHelper(source) + 1); |
3536 i::SNPrintF(program, "%s%s", prefix, source); | 3543 i::SNPrintF(program, "%s%s", prefix, source); |
| 3544 i::Zone zone(isolate->allocator(), ZONE_NAME); |
3537 | 3545 |
3538 i::Handle<i::String> string = | 3546 i::Handle<i::String> string = |
3539 factory->InternalizeUtf8String(program.start()); | 3547 factory->InternalizeUtf8String(program.start()); |
3540 string->PrintOn(stdout); | 3548 string->PrintOn(stdout); |
3541 printf("\n"); | 3549 printf("\n"); |
3542 i::Handle<i::Script> script = factory->NewScript(string); | 3550 i::Handle<i::Script> script = factory->NewScript(string); |
3543 | 3551 |
3544 for (unsigned allow_lazy = 0; allow_lazy < 2; ++allow_lazy) { | 3552 for (unsigned allow_lazy = 0; allow_lazy < 2; ++allow_lazy) { |
3545 for (unsigned module = 0; module < 2; ++module) { | 3553 for (unsigned module = 0; module < 2; ++module) { |
3546 std::unique_ptr<i::ParseInfo> info; | 3554 std::unique_ptr<i::ParseInfo> info; |
3547 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(script)); | 3555 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, script)); |
3548 info->set_module(module); | 3556 info->set_module(module); |
3549 info->set_allow_lazy_parsing(allow_lazy); | 3557 info->set_allow_lazy_parsing(allow_lazy); |
3550 | 3558 |
3551 CHECK(i::parsing::ParseProgram(info.get())); | 3559 CHECK(i::parsing::ParseProgram(info.get())); |
3552 CHECK(i::Compiler::Analyze(info.get())); | 3560 CHECK(i::Compiler::Analyze(info.get())); |
3553 | 3561 |
3554 CHECK_NOT_NULL(info->literal()); | 3562 CHECK_NOT_NULL(info->literal()); |
3555 i::Scope* scope = info->literal()->scope(); | 3563 i::Scope* scope = info->literal()->scope(); |
3556 CHECK(!scope->AsDeclarationScope()->was_lazily_parsed()); | 3564 CHECK(!scope->AsDeclarationScope()->was_lazily_parsed()); |
3557 CHECK_NULL(scope->sibling()); | 3565 CHECK_NULL(scope->sibling()); |
(...skipping 2298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5856 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 5864 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
5857 128 * 1024); | 5865 128 * 1024); |
5858 | 5866 |
5859 for (unsigned i = 0; i < arraysize(kSources); ++i) { | 5867 for (unsigned i = 0; i < arraysize(kSources); ++i) { |
5860 i::Handle<i::String> source = | 5868 i::Handle<i::String> source = |
5861 factory->NewStringFromAsciiChecked(kSources[i]); | 5869 factory->NewStringFromAsciiChecked(kSources[i]); |
5862 | 5870 |
5863 // Show that parsing as a module works | 5871 // Show that parsing as a module works |
5864 { | 5872 { |
5865 i::Handle<i::Script> script = factory->NewScript(source); | 5873 i::Handle<i::Script> script = factory->NewScript(source); |
5866 i::ParseInfo info(script); | 5874 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 5875 i::ParseInfo info(&zone, script); |
5867 info.set_module(); | 5876 info.set_module(); |
5868 if (!i::parsing::ParseProgram(&info)) { | 5877 if (!i::parsing::ParseProgram(&info)) { |
5869 i::Handle<i::JSObject> exception_handle( | 5878 i::Handle<i::JSObject> exception_handle( |
5870 i::JSObject::cast(isolate->pending_exception())); | 5879 i::JSObject::cast(isolate->pending_exception())); |
5871 i::Handle<i::String> message_string = i::Handle<i::String>::cast( | 5880 i::Handle<i::String> message_string = i::Handle<i::String>::cast( |
5872 i::JSReceiver::GetProperty(isolate, exception_handle, "message") | 5881 i::JSReceiver::GetProperty(isolate, exception_handle, "message") |
5873 .ToHandleChecked()); | 5882 .ToHandleChecked()); |
5874 isolate->clear_pending_exception(); | 5883 isolate->clear_pending_exception(); |
5875 | 5884 |
5876 v8::base::OS::Print( | 5885 v8::base::OS::Print( |
5877 "Parser failed on:\n" | 5886 "Parser failed on:\n" |
5878 "\t%s\n" | 5887 "\t%s\n" |
5879 "with error:\n" | 5888 "with error:\n" |
5880 "\t%s\n" | 5889 "\t%s\n" |
5881 "However, we expected no error.", | 5890 "However, we expected no error.", |
5882 source->ToCString().get(), message_string->ToCString().get()); | 5891 source->ToCString().get(), message_string->ToCString().get()); |
5883 CHECK(false); | 5892 CHECK(false); |
5884 } | 5893 } |
5885 } | 5894 } |
5886 | 5895 |
5887 // And that parsing a script does not. | 5896 // And that parsing a script does not. |
5888 { | 5897 { |
5889 i::Handle<i::Script> script = factory->NewScript(source); | 5898 i::Handle<i::Script> script = factory->NewScript(source); |
5890 i::ParseInfo info(script); | 5899 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 5900 i::ParseInfo info(&zone, script); |
5891 CHECK(!i::parsing::ParseProgram(&info)); | 5901 CHECK(!i::parsing::ParseProgram(&info)); |
5892 isolate->clear_pending_exception(); | 5902 isolate->clear_pending_exception(); |
5893 } | 5903 } |
5894 } | 5904 } |
5895 } | 5905 } |
5896 | 5906 |
5897 | 5907 |
5898 TEST(ImportExportParsingErrors) { | 5908 TEST(ImportExportParsingErrors) { |
5899 // clang-format off | 5909 // clang-format off |
5900 const char* kErrorSources[] = { | 5910 const char* kErrorSources[] = { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5970 v8::Context::Scope context_scope(context); | 5980 v8::Context::Scope context_scope(context); |
5971 | 5981 |
5972 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 5982 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
5973 128 * 1024); | 5983 128 * 1024); |
5974 | 5984 |
5975 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { | 5985 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { |
5976 i::Handle<i::String> source = | 5986 i::Handle<i::String> source = |
5977 factory->NewStringFromAsciiChecked(kErrorSources[i]); | 5987 factory->NewStringFromAsciiChecked(kErrorSources[i]); |
5978 | 5988 |
5979 i::Handle<i::Script> script = factory->NewScript(source); | 5989 i::Handle<i::Script> script = factory->NewScript(source); |
5980 i::ParseInfo info(script); | 5990 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 5991 i::ParseInfo info(&zone, script); |
5981 info.set_module(); | 5992 info.set_module(); |
5982 CHECK(!i::parsing::ParseProgram(&info)); | 5993 CHECK(!i::parsing::ParseProgram(&info)); |
5983 isolate->clear_pending_exception(); | 5994 isolate->clear_pending_exception(); |
5984 } | 5995 } |
5985 } | 5996 } |
5986 | 5997 |
5987 TEST(ModuleTopLevelFunctionDecl) { | 5998 TEST(ModuleTopLevelFunctionDecl) { |
5988 // clang-format off | 5999 // clang-format off |
5989 const char* kErrorSources[] = { | 6000 const char* kErrorSources[] = { |
5990 "function f() {} function f() {}", | 6001 "function f() {} function f() {}", |
(...skipping 15 matching lines...) Expand all Loading... |
6006 v8::Context::Scope context_scope(context); | 6017 v8::Context::Scope context_scope(context); |
6007 | 6018 |
6008 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 6019 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
6009 128 * 1024); | 6020 128 * 1024); |
6010 | 6021 |
6011 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { | 6022 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { |
6012 i::Handle<i::String> source = | 6023 i::Handle<i::String> source = |
6013 factory->NewStringFromAsciiChecked(kErrorSources[i]); | 6024 factory->NewStringFromAsciiChecked(kErrorSources[i]); |
6014 | 6025 |
6015 i::Handle<i::Script> script = factory->NewScript(source); | 6026 i::Handle<i::Script> script = factory->NewScript(source); |
6016 i::ParseInfo info(script); | 6027 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 6028 i::ParseInfo info(&zone, script); |
6017 info.set_module(); | 6029 info.set_module(); |
6018 CHECK(!i::parsing::ParseProgram(&info)); | 6030 CHECK(!i::parsing::ParseProgram(&info)); |
6019 isolate->clear_pending_exception(); | 6031 isolate->clear_pending_exception(); |
6020 } | 6032 } |
6021 } | 6033 } |
6022 | 6034 |
6023 TEST(ModuleAwaitReserved) { | 6035 TEST(ModuleAwaitReserved) { |
6024 // clang-format off | 6036 // clang-format off |
6025 const char* kErrorSources[] = { | 6037 const char* kErrorSources[] = { |
6026 "await;", | 6038 "await;", |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6203 "import 'q.js';" | 6215 "import 'q.js';" |
6204 "let nonexport = 42;" | 6216 "let nonexport = 42;" |
6205 "import {m as mm} from 'm.js';" | 6217 "import {m as mm} from 'm.js';" |
6206 "import {aa} from 'm.js';" | 6218 "import {aa} from 'm.js';" |
6207 "export {aa as bb, x};" | 6219 "export {aa as bb, x};" |
6208 "import * as loo from 'bar.js';" | 6220 "import * as loo from 'bar.js';" |
6209 "import * as foob from 'bar.js';" | 6221 "import * as foob from 'bar.js';" |
6210 "export {foob};"; | 6222 "export {foob};"; |
6211 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource); | 6223 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource); |
6212 i::Handle<i::Script> script = factory->NewScript(source); | 6224 i::Handle<i::Script> script = factory->NewScript(source); |
6213 i::ParseInfo info(script); | 6225 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 6226 i::ParseInfo info(&zone, script); |
6214 info.set_module(); | 6227 info.set_module(); |
6215 CHECK(i::parsing::ParseProgram(&info)); | 6228 CHECK(i::parsing::ParseProgram(&info)); |
6216 CHECK(i::Compiler::Analyze(&info)); | 6229 CHECK(i::Compiler::Analyze(&info)); |
6217 i::FunctionLiteral* func = info.literal(); | 6230 i::FunctionLiteral* func = info.literal(); |
6218 i::ModuleScope* module_scope = func->scope()->AsModuleScope(); | 6231 i::ModuleScope* module_scope = func->scope()->AsModuleScope(); |
6219 i::Scope* outer_scope = module_scope->outer_scope(); | 6232 i::Scope* outer_scope = module_scope->outer_scope(); |
6220 CHECK(outer_scope->is_script_scope()); | 6233 CHECK(outer_scope->is_script_scope()); |
6221 CHECK_NULL(outer_scope->outer_scope()); | 6234 CHECK_NULL(outer_scope->outer_scope()); |
6222 CHECK(module_scope->is_module_scope()); | 6235 CHECK(module_scope->is_module_scope()); |
6223 const i::ModuleDescriptor::Entry* entry; | 6236 const i::ModuleDescriptor::Entry* entry; |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6462 i::Isolate* isolate = CcTest::i_isolate(); | 6475 i::Isolate* isolate = CcTest::i_isolate(); |
6463 i::Factory* factory = isolate->factory(); | 6476 i::Factory* factory = isolate->factory(); |
6464 v8::HandleScope handles(CcTest::isolate()); | 6477 v8::HandleScope handles(CcTest::isolate()); |
6465 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); | 6478 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
6466 v8::Context::Scope context_scope(context); | 6479 v8::Context::Scope context_scope(context); |
6467 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 6480 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
6468 128 * 1024); | 6481 128 * 1024); |
6469 | 6482 |
6470 i::Handle<i::Script> script = | 6483 i::Handle<i::Script> script = |
6471 factory->NewScript(factory->NewStringFromAsciiChecked(source)); | 6484 factory->NewScript(factory->NewStringFromAsciiChecked(source)); |
6472 i::ParseInfo info(script); | 6485 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 6486 i::ParseInfo info(&zone, script); |
6473 i::parsing::ParseProgram(&info); | 6487 i::parsing::ParseProgram(&info); |
6474 CHECK(info.literal() != NULL); | 6488 CHECK(info.literal() != NULL); |
6475 CHECK_EQ(expected_language_mode, info.literal()->language_mode()); | 6489 CHECK_EQ(expected_language_mode, info.literal()->language_mode()); |
6476 } | 6490 } |
6477 | 6491 |
6478 | 6492 |
6479 TEST(LanguageModeDirectives) { | 6493 TEST(LanguageModeDirectives) { |
6480 TestLanguageMode("\"use nothing\"", i::SLOPPY); | 6494 TestLanguageMode("\"use nothing\"", i::SLOPPY); |
6481 TestLanguageMode("\"use strict\"", i::STRICT); | 6495 TestLanguageMode("\"use strict\"", i::STRICT); |
6482 | 6496 |
(...skipping 2425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8908 i::SNPrintF( | 8922 i::SNPrintF( |
8909 program + prefix_len + inner_function_len + params_len + source_len, | 8923 program + prefix_len + inner_function_len + params_len + source_len, |
8910 "%s", suffix); | 8924 "%s", suffix); |
8911 | 8925 |
8912 i::Handle<i::String> source = | 8926 i::Handle<i::String> source = |
8913 factory->InternalizeUtf8String(program.start()); | 8927 factory->InternalizeUtf8String(program.start()); |
8914 source->PrintOn(stdout); | 8928 source->PrintOn(stdout); |
8915 printf("\n"); | 8929 printf("\n"); |
8916 | 8930 |
8917 i::Handle<i::Script> script = factory->NewScript(source); | 8931 i::Handle<i::Script> script = factory->NewScript(source); |
8918 i::ParseInfo info(script); | 8932 i::Zone zone(isolate->allocator(), ZONE_NAME); |
| 8933 i::ParseInfo info(&zone, script); |
8919 | 8934 |
8920 CHECK(i::parsing::ParseProgram(&info)); | 8935 CHECK(i::parsing::ParseProgram(&info)); |
8921 CHECK(i::Compiler::Analyze(&info)); | 8936 CHECK(i::Compiler::Analyze(&info)); |
8922 CHECK(info.literal() != NULL); | 8937 CHECK(info.literal() != NULL); |
8923 | 8938 |
8924 i::Scope* scope = info.literal()->scope()->inner_scope(); | 8939 i::Scope* scope = info.literal()->scope()->inner_scope(); |
8925 DCHECK_NOT_NULL(scope); | 8940 DCHECK_NOT_NULL(scope); |
8926 DCHECK_NULL(scope->sibling()); | 8941 DCHECK_NULL(scope->sibling()); |
8927 DCHECK(scope->is_function_scope()); | 8942 DCHECK(scope->is_function_scope()); |
8928 const i::AstRawString* var_name = | 8943 const i::AstRawString* var_name = |
8929 info.ast_value_factory()->GetOneByteString("my_var"); | 8944 info.ast_value_factory()->GetOneByteString("my_var"); |
8930 i::Variable* var = scope->Lookup(var_name); | 8945 i::Variable* var = scope->Lookup(var_name); |
8931 CHECK_EQ(inners[i].ctxt_allocate, | 8946 CHECK_EQ(inners[i].ctxt_allocate, |
8932 i::ScopeTestHelper::MustAllocateInContext(var)); | 8947 i::ScopeTestHelper::MustAllocateInContext(var)); |
8933 } | 8948 } |
8934 } | 8949 } |
8935 } | 8950 } |
OLD | NEW |