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 786 matching lines...) Loading... |
797 int kProgramByteSize = i::StrLength(surroundings[j].prefix) + | 797 int kProgramByteSize = i::StrLength(surroundings[j].prefix) + |
798 i::StrLength(surroundings[j].suffix) + | 798 i::StrLength(surroundings[j].suffix) + |
799 i::StrLength(source_data[i].body); | 799 i::StrLength(source_data[i].body); |
800 i::ScopedVector<char> program(kProgramByteSize + 1); | 800 i::ScopedVector<char> program(kProgramByteSize + 1); |
801 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix, | 801 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix, |
802 source_data[i].body, surroundings[j].suffix); | 802 source_data[i].body, surroundings[j].suffix); |
803 i::Handle<i::String> source = | 803 i::Handle<i::String> source = |
804 factory->NewStringFromUtf8(i::CStrVector(program.start())) | 804 factory->NewStringFromUtf8(i::CStrVector(program.start())) |
805 .ToHandleChecked(); | 805 .ToHandleChecked(); |
806 i::Handle<i::Script> script = factory->NewScript(source); | 806 i::Handle<i::Script> script = factory->NewScript(source); |
807 i::ParseInfo info(script); | 807 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 808 i::ParseInfo info(&zone, script); |
808 // The information we're checking is only produced when eager parsing. | 809 // The information we're checking is only produced when eager parsing. |
809 info.set_allow_lazy_parsing(false); | 810 info.set_allow_lazy_parsing(false); |
810 CHECK(i::parsing::ParseProgram(&info)); | 811 CHECK(i::parsing::ParseProgram(&info)); |
811 CHECK(i::Rewriter::Rewrite(&info)); | 812 CHECK(i::Rewriter::Rewrite(&info)); |
812 i::DeclarationScope::Analyze(&info, i::AnalyzeMode::kRegular); | 813 i::DeclarationScope::Analyze(&info, i::AnalyzeMode::kRegular); |
813 CHECK(info.literal() != NULL); | 814 CHECK(info.literal() != NULL); |
814 | 815 |
815 i::DeclarationScope* script_scope = info.literal()->scope(); | 816 i::DeclarationScope* script_scope = info.literal()->scope(); |
816 CHECK(script_scope->is_script_scope()); | 817 CHECK(script_scope->is_script_scope()); |
817 | 818 |
(...skipping 35 matching lines...) Loading... |
853 std::string full_source = "function f() { return "; | 854 std::string full_source = "function f() { return "; |
854 full_source += source; | 855 full_source += source; |
855 full_source += "; }"; | 856 full_source += "; }"; |
856 | 857 |
857 i::Handle<i::String> source_code = | 858 i::Handle<i::String> source_code = |
858 factory->NewStringFromUtf8(i::CStrVector(full_source.c_str())) | 859 factory->NewStringFromUtf8(i::CStrVector(full_source.c_str())) |
859 .ToHandleChecked(); | 860 .ToHandleChecked(); |
860 | 861 |
861 i::Handle<i::Script> script = factory->NewScript(source_code); | 862 i::Handle<i::Script> script = factory->NewScript(source_code); |
862 | 863 |
863 i::ParseInfo info(script); | 864 i::ParseInfo info(handles.main_zone(), script); |
864 i::Parser parser(&info); | 865 i::Parser parser(&info); |
865 info.set_allow_lazy_parsing(false); | 866 info.set_allow_lazy_parsing(false); |
866 info.set_toplevel(true); | 867 info.set_toplevel(true); |
867 | 868 |
868 CHECK(i::Compiler::ParseAndAnalyze(&info)); | 869 CHECK(i::Compiler::ParseAndAnalyze(&info)); |
869 | 870 |
870 CHECK_EQ(1, info.scope()->declarations()->LengthForTest()); | 871 CHECK_EQ(1, info.scope()->declarations()->LengthForTest()); |
871 i::Declaration* decl = info.scope()->declarations()->AtForTest(0); | 872 i::Declaration* decl = info.scope()->declarations()->AtForTest(0); |
872 i::FunctionLiteral* fun = decl->AsFunctionDeclaration()->fun(); | 873 i::FunctionLiteral* fun = decl->AsFunctionDeclaration()->fun(); |
873 CHECK(fun->body()->length() == 1); | 874 CHECK(fun->body()->length() == 1); |
(...skipping 277 matching lines...) Loading... |
1151 i::SNPrintF(program, "%s%s%s", | 1152 i::SNPrintF(program, "%s%s%s", |
1152 source_data[i].outer_prefix, | 1153 source_data[i].outer_prefix, |
1153 source_data[i].inner_source, | 1154 source_data[i].inner_source, |
1154 source_data[i].outer_suffix); | 1155 source_data[i].outer_suffix); |
1155 | 1156 |
1156 // Parse program source. | 1157 // Parse program source. |
1157 i::Handle<i::String> source = factory->NewStringFromUtf8( | 1158 i::Handle<i::String> source = factory->NewStringFromUtf8( |
1158 i::CStrVector(program.start())).ToHandleChecked(); | 1159 i::CStrVector(program.start())).ToHandleChecked(); |
1159 CHECK_EQ(source->length(), kProgramSize); | 1160 CHECK_EQ(source->length(), kProgramSize); |
1160 i::Handle<i::Script> script = factory->NewScript(source); | 1161 i::Handle<i::Script> script = factory->NewScript(source); |
1161 i::ParseInfo info(script); | 1162 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 1163 i::ParseInfo info(&zone, script); |
1162 info.set_language_mode(source_data[i].language_mode); | 1164 info.set_language_mode(source_data[i].language_mode); |
1163 i::parsing::ParseProgram(&info); | 1165 i::parsing::ParseProgram(&info); |
1164 CHECK_NOT_NULL(info.literal()); | 1166 CHECK_NOT_NULL(info.literal()); |
1165 | 1167 |
1166 // Check scope types and positions. | 1168 // Check scope types and positions. |
1167 i::Scope* scope = info.literal()->scope(); | 1169 i::Scope* scope = info.literal()->scope(); |
1168 CHECK(scope->is_script_scope()); | 1170 CHECK(scope->is_script_scope()); |
1169 CHECK_EQ(scope->start_position(), 0); | 1171 CHECK_EQ(scope->start_position(), 0); |
1170 CHECK_EQ(scope->end_position(), kProgramSize); | 1172 CHECK_EQ(scope->end_position(), kProgramSize); |
1171 | 1173 |
(...skipping 25 matching lines...) Loading... |
1197 i::Isolate* isolate = CcTest::i_isolate(); | 1199 i::Isolate* isolate = CcTest::i_isolate(); |
1198 i::Factory* factory = isolate->factory(); | 1200 i::Factory* factory = isolate->factory(); |
1199 v8::HandleScope handles(CcTest::isolate()); | 1201 v8::HandleScope handles(CcTest::isolate()); |
1200 i::FunctionLiteral* function; | 1202 i::FunctionLiteral* function; |
1201 | 1203 |
1202 for (int i = 0; discard_sources[i]; i++) { | 1204 for (int i = 0; discard_sources[i]; i++) { |
1203 const char* source = discard_sources[i]; | 1205 const char* source = discard_sources[i]; |
1204 i::Handle<i::String> source_code = | 1206 i::Handle<i::String> source_code = |
1205 factory->NewStringFromUtf8(i::CStrVector(source)).ToHandleChecked(); | 1207 factory->NewStringFromUtf8(i::CStrVector(source)).ToHandleChecked(); |
1206 i::Handle<i::Script> script = factory->NewScript(source_code); | 1208 i::Handle<i::Script> script = factory->NewScript(source_code); |
1207 i::ParseInfo info(script); | 1209 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 1210 i::ParseInfo info(&zone, script); |
1208 i::parsing::ParseProgram(&info); | 1211 i::parsing::ParseProgram(&info); |
1209 function = info.literal(); | 1212 function = info.literal(); |
1210 CHECK_NOT_NULL(function); | 1213 CHECK_NOT_NULL(function); |
1211 CHECK_NOT_NULL(function->body()); | 1214 CHECK_NOT_NULL(function->body()); |
1212 CHECK_EQ(1, function->body()->length()); | 1215 CHECK_EQ(1, function->body()->length()); |
1213 i::FunctionLiteral* inner = | 1216 i::FunctionLiteral* inner = |
1214 function->body()->first()->AsExpressionStatement()->expression()-> | 1217 function->body()->first()->AsExpressionStatement()->expression()-> |
1215 AsCall()->expression()->AsFunctionLiteral(); | 1218 AsCall()->expression()->AsFunctionLiteral(); |
1216 i::Scope* inner_scope = inner->scope(); | 1219 i::Scope* inner_scope = inner->scope(); |
1217 i::FunctionLiteral* fun = nullptr; | 1220 i::FunctionLiteral* fun = nullptr; |
(...skipping 109 matching lines...) Loading... |
1327 scanner.Initialize(stream.get()); | 1330 scanner.Initialize(stream.get()); |
1328 i::PreParser::PreParseResult result = | 1331 i::PreParser::PreParseResult result = |
1329 preparser.PreParseProgram(&preparser_materialized_literals, is_module); | 1332 preparser.PreParseProgram(&preparser_materialized_literals, is_module); |
1330 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 1333 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
1331 } | 1334 } |
1332 | 1335 |
1333 // Parse the data | 1336 // Parse the data |
1334 i::FunctionLiteral* function; | 1337 i::FunctionLiteral* function; |
1335 { | 1338 { |
1336 i::Handle<i::Script> script = factory->NewScript(source); | 1339 i::Handle<i::Script> script = factory->NewScript(source); |
1337 i::ParseInfo info(script); | 1340 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 1341 i::ParseInfo info(&zone, script); |
1338 info.set_allow_lazy_parsing(flags.Contains(kAllowLazy)); | 1342 info.set_allow_lazy_parsing(flags.Contains(kAllowLazy)); |
1339 SetGlobalFlags(flags); | 1343 SetGlobalFlags(flags); |
1340 if (is_module) info.set_module(); | 1344 if (is_module) info.set_module(); |
1341 i::parsing::ParseProgram(&info); | 1345 i::parsing::ParseProgram(&info); |
1342 function = info.literal(); | 1346 function = info.literal(); |
1343 if (function) { | 1347 if (function) { |
1344 parser_materialized_literals = function->materialized_literal_count(); | 1348 parser_materialized_literals = function->materialized_literal_count(); |
1345 } | 1349 } |
1346 } | 1350 } |
1347 | 1351 |
(...skipping 1106 matching lines...) Loading... |
2454 {"function lazy() { var x = {get foo(){} } }", 1}, | 2458 {"function lazy() { var x = {get foo(){} } }", 1}, |
2455 {NULL, 0} | 2459 {NULL, 0} |
2456 }; | 2460 }; |
2457 | 2461 |
2458 for (int i = 0; test_cases[i].program; i++) { | 2462 for (int i = 0; test_cases[i].program; i++) { |
2459 const char* program = test_cases[i].program; | 2463 const char* program = test_cases[i].program; |
2460 i::Factory* factory = CcTest::i_isolate()->factory(); | 2464 i::Factory* factory = CcTest::i_isolate()->factory(); |
2461 i::Handle<i::String> source = | 2465 i::Handle<i::String> source = |
2462 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked(); | 2466 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked(); |
2463 i::Handle<i::Script> script = factory->NewScript(source); | 2467 i::Handle<i::Script> script = factory->NewScript(source); |
2464 i::ParseInfo info(script); | 2468 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 2469 i::ParseInfo info(&zone, script); |
2465 i::ScriptData* sd = NULL; | 2470 i::ScriptData* sd = NULL; |
2466 info.set_cached_data(&sd); | 2471 info.set_cached_data(&sd); |
2467 info.set_compile_options(v8::ScriptCompiler::kProduceParserCache); | 2472 info.set_compile_options(v8::ScriptCompiler::kProduceParserCache); |
2468 i::parsing::ParseProgram(&info); | 2473 i::parsing::ParseProgram(&info); |
2469 i::ParseData* pd = i::ParseData::FromCachedData(sd); | 2474 i::ParseData* pd = i::ParseData::FromCachedData(sd); |
2470 | 2475 |
2471 if (pd->FunctionCount() != test_cases[i].functions) { | 2476 if (pd->FunctionCount() != test_cases[i].functions) { |
2472 v8::base::OS::Print( | 2477 v8::base::OS::Print( |
2473 "Expected preparse data for program:\n" | 2478 "Expected preparse data for program:\n" |
2474 "\t%s\n" | 2479 "\t%s\n" |
(...skipping 866 matching lines...) Loading... |
3341 if (outers[i].strict && inners[j].with) continue; | 3346 if (outers[i].strict && inners[j].with) continue; |
3342 const char* inner = inners[j].source; | 3347 const char* inner = inners[j].source; |
3343 int inner_len = Utf8LengthHelper(inner); | 3348 int inner_len = Utf8LengthHelper(inner); |
3344 | 3349 |
3345 int len = prefix_len + outer_len + midfix_len + inner_len + suffix_len; | 3350 int len = prefix_len + outer_len + midfix_len + inner_len + suffix_len; |
3346 i::ScopedVector<char> program(len + 1); | 3351 i::ScopedVector<char> program(len + 1); |
3347 | 3352 |
3348 i::SNPrintF(program, "%s%s%s%s%s", prefix, outer, midfix, inner, | 3353 i::SNPrintF(program, "%s%s%s%s%s", prefix, outer, midfix, inner, |
3349 suffix); | 3354 suffix); |
3350 | 3355 |
| 3356 i::Zone zone(isolate->allocator(), ZONE_NAME); |
3351 std::unique_ptr<i::ParseInfo> info; | 3357 std::unique_ptr<i::ParseInfo> info; |
3352 if (lazy) { | 3358 if (lazy) { |
3353 printf("%s\n", program.start()); | 3359 printf("%s\n", program.start()); |
3354 v8::Local<v8::Value> v = CompileRun(program.start()); | 3360 v8::Local<v8::Value> v = CompileRun(program.start()); |
3355 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v); | 3361 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v); |
3356 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); | 3362 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); |
3357 i::Handle<i::SharedFunctionInfo> shared = i::handle(f->shared()); | 3363 i::Handle<i::SharedFunctionInfo> shared = i::handle(f->shared()); |
3358 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(shared)); | 3364 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, shared)); |
3359 CHECK(i::parsing::ParseFunction(info.get())); | 3365 CHECK(i::parsing::ParseFunction(info.get())); |
3360 } else { | 3366 } else { |
3361 i::Handle<i::String> source = | 3367 i::Handle<i::String> source = |
3362 factory->InternalizeUtf8String(program.start()); | 3368 factory->InternalizeUtf8String(program.start()); |
3363 source->PrintOn(stdout); | 3369 source->PrintOn(stdout); |
3364 printf("\n"); | 3370 printf("\n"); |
3365 i::Handle<i::Script> script = factory->NewScript(source); | 3371 i::Handle<i::Script> script = factory->NewScript(source); |
3366 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(script)); | 3372 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, script)); |
3367 info->set_allow_lazy_parsing(false); | 3373 info->set_allow_lazy_parsing(false); |
3368 CHECK(i::parsing::ParseProgram(info.get())); | 3374 CHECK(i::parsing::ParseProgram(info.get())); |
3369 } | 3375 } |
3370 CHECK(i::Compiler::Analyze(info.get())); | 3376 CHECK(i::Compiler::Analyze(info.get())); |
3371 CHECK(info->literal() != NULL); | 3377 CHECK(info->literal() != NULL); |
3372 | 3378 |
3373 i::Scope* scope = info->literal()->scope(); | 3379 i::Scope* scope = info->literal()->scope(); |
3374 if (!lazy) { | 3380 if (!lazy) { |
3375 scope = scope->inner_scope(); | 3381 scope = scope->inner_scope(); |
3376 } | 3382 } |
(...skipping 78 matching lines...) Loading... |
3455 | 3461 |
3456 const char* suffix = "; f"; | 3462 const char* suffix = "; f"; |
3457 | 3463 |
3458 for (unsigned i = 0; i < arraysize(tests); ++i) { | 3464 for (unsigned i = 0; i < arraysize(tests); ++i) { |
3459 bool assigned = tests[i].arg_assigned; | 3465 bool assigned = tests[i].arg_assigned; |
3460 const char* source = tests[i].source; | 3466 const char* source = tests[i].source; |
3461 for (unsigned allow_lazy = 0; allow_lazy < 2; ++allow_lazy) { | 3467 for (unsigned allow_lazy = 0; allow_lazy < 2; ++allow_lazy) { |
3462 i::ScopedVector<char> program(Utf8LengthHelper(source) + | 3468 i::ScopedVector<char> program(Utf8LengthHelper(source) + |
3463 Utf8LengthHelper(suffix) + 1); | 3469 Utf8LengthHelper(suffix) + 1); |
3464 i::SNPrintF(program, "%s%s", source, suffix); | 3470 i::SNPrintF(program, "%s%s", source, suffix); |
| 3471 i::Zone zone(isolate->allocator(), ZONE_NAME); |
3465 std::unique_ptr<i::ParseInfo> info; | 3472 std::unique_ptr<i::ParseInfo> info; |
3466 printf("%s\n", program.start()); | 3473 printf("%s\n", program.start()); |
3467 v8::Local<v8::Value> v = CompileRun(program.start()); | 3474 v8::Local<v8::Value> v = CompileRun(program.start()); |
3468 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v); | 3475 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v); |
3469 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); | 3476 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); |
3470 i::Handle<i::SharedFunctionInfo> shared = i::handle(f->shared()); | 3477 i::Handle<i::SharedFunctionInfo> shared = i::handle(f->shared()); |
3471 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(shared)); | 3478 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, shared)); |
3472 info->set_allow_lazy_parsing(allow_lazy); | 3479 info->set_allow_lazy_parsing(allow_lazy); |
3473 CHECK(i::parsing::ParseFunction(info.get())); | 3480 CHECK(i::parsing::ParseFunction(info.get())); |
3474 CHECK(i::Compiler::Analyze(info.get())); | 3481 CHECK(i::Compiler::Analyze(info.get())); |
3475 CHECK_NOT_NULL(info->literal()); | 3482 CHECK_NOT_NULL(info->literal()); |
3476 | 3483 |
3477 i::Scope* scope = info->literal()->scope(); | 3484 i::Scope* scope = info->literal()->scope(); |
3478 CHECK(!scope->AsDeclarationScope()->was_lazily_parsed()); | 3485 CHECK(!scope->AsDeclarationScope()->was_lazily_parsed()); |
3479 CHECK_NULL(scope->sibling()); | 3486 CHECK_NULL(scope->sibling()); |
3480 CHECK(scope->is_function_scope()); | 3487 CHECK(scope->is_function_scope()); |
3481 const i::AstRawString* var_name = | 3488 const i::AstRawString* var_name = |
(...skipping 27 matching lines...) Loading... |
3509 "function* bar() {eval(ext)}; ext(bar); ext(foo)", | 3516 "function* bar() {eval(ext)}; ext(bar); ext(foo)", |
3510 }; | 3517 }; |
3511 | 3518 |
3512 for (unsigned i = 0; i < arraysize(prefixes); ++i) { | 3519 for (unsigned i = 0; i < arraysize(prefixes); ++i) { |
3513 const char* prefix = prefixes[i]; | 3520 const char* prefix = prefixes[i]; |
3514 for (unsigned j = 0; j < arraysize(sources); ++j) { | 3521 for (unsigned j = 0; j < arraysize(sources); ++j) { |
3515 const char* source = sources[j]; | 3522 const char* source = sources[j]; |
3516 i::ScopedVector<char> program(Utf8LengthHelper(prefix) + | 3523 i::ScopedVector<char> program(Utf8LengthHelper(prefix) + |
3517 Utf8LengthHelper(source) + 1); | 3524 Utf8LengthHelper(source) + 1); |
3518 i::SNPrintF(program, "%s%s", prefix, source); | 3525 i::SNPrintF(program, "%s%s", prefix, source); |
| 3526 i::Zone zone(isolate->allocator(), ZONE_NAME); |
3519 | 3527 |
3520 i::Handle<i::String> string = | 3528 i::Handle<i::String> string = |
3521 factory->InternalizeUtf8String(program.start()); | 3529 factory->InternalizeUtf8String(program.start()); |
3522 string->PrintOn(stdout); | 3530 string->PrintOn(stdout); |
3523 printf("\n"); | 3531 printf("\n"); |
3524 i::Handle<i::Script> script = factory->NewScript(string); | 3532 i::Handle<i::Script> script = factory->NewScript(string); |
3525 | 3533 |
3526 for (unsigned allow_lazy = 0; allow_lazy < 2; ++allow_lazy) { | 3534 for (unsigned allow_lazy = 0; allow_lazy < 2; ++allow_lazy) { |
3527 for (unsigned module = 0; module < 2; ++module) { | 3535 for (unsigned module = 0; module < 2; ++module) { |
3528 std::unique_ptr<i::ParseInfo> info; | 3536 std::unique_ptr<i::ParseInfo> info; |
3529 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(script)); | 3537 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, script)); |
3530 info->set_module(module); | 3538 info->set_module(module); |
3531 info->set_allow_lazy_parsing(allow_lazy); | 3539 info->set_allow_lazy_parsing(allow_lazy); |
3532 | 3540 |
3533 CHECK(i::parsing::ParseProgram(info.get())); | 3541 CHECK(i::parsing::ParseProgram(info.get())); |
3534 CHECK(i::Compiler::Analyze(info.get())); | 3542 CHECK(i::Compiler::Analyze(info.get())); |
3535 | 3543 |
3536 CHECK_NOT_NULL(info->literal()); | 3544 CHECK_NOT_NULL(info->literal()); |
3537 i::Scope* scope = info->literal()->scope(); | 3545 i::Scope* scope = info->literal()->scope(); |
3538 CHECK(!scope->AsDeclarationScope()->was_lazily_parsed()); | 3546 CHECK(!scope->AsDeclarationScope()->was_lazily_parsed()); |
3539 CHECK_NULL(scope->sibling()); | 3547 CHECK_NULL(scope->sibling()); |
(...skipping 2432 matching lines...) Loading... |
5972 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 5980 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
5973 128 * 1024); | 5981 128 * 1024); |
5974 | 5982 |
5975 for (unsigned i = 0; i < arraysize(kSources); ++i) { | 5983 for (unsigned i = 0; i < arraysize(kSources); ++i) { |
5976 i::Handle<i::String> source = | 5984 i::Handle<i::String> source = |
5977 factory->NewStringFromAsciiChecked(kSources[i]); | 5985 factory->NewStringFromAsciiChecked(kSources[i]); |
5978 | 5986 |
5979 // Show that parsing as a module works | 5987 // Show that parsing as a module works |
5980 { | 5988 { |
5981 i::Handle<i::Script> script = factory->NewScript(source); | 5989 i::Handle<i::Script> script = factory->NewScript(source); |
5982 i::ParseInfo info(script); | 5990 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 5991 i::ParseInfo info(&zone, script); |
5983 info.set_module(); | 5992 info.set_module(); |
5984 if (!i::parsing::ParseProgram(&info)) { | 5993 if (!i::parsing::ParseProgram(&info)) { |
5985 i::Handle<i::JSObject> exception_handle( | 5994 i::Handle<i::JSObject> exception_handle( |
5986 i::JSObject::cast(isolate->pending_exception())); | 5995 i::JSObject::cast(isolate->pending_exception())); |
5987 i::Handle<i::String> message_string = i::Handle<i::String>::cast( | 5996 i::Handle<i::String> message_string = i::Handle<i::String>::cast( |
5988 i::JSReceiver::GetProperty(isolate, exception_handle, "message") | 5997 i::JSReceiver::GetProperty(isolate, exception_handle, "message") |
5989 .ToHandleChecked()); | 5998 .ToHandleChecked()); |
5990 isolate->clear_pending_exception(); | 5999 isolate->clear_pending_exception(); |
5991 | 6000 |
5992 v8::base::OS::Print( | 6001 v8::base::OS::Print( |
5993 "Parser failed on:\n" | 6002 "Parser failed on:\n" |
5994 "\t%s\n" | 6003 "\t%s\n" |
5995 "with error:\n" | 6004 "with error:\n" |
5996 "\t%s\n" | 6005 "\t%s\n" |
5997 "However, we expected no error.", | 6006 "However, we expected no error.", |
5998 source->ToCString().get(), message_string->ToCString().get()); | 6007 source->ToCString().get(), message_string->ToCString().get()); |
5999 CHECK(false); | 6008 CHECK(false); |
6000 } | 6009 } |
6001 } | 6010 } |
6002 | 6011 |
6003 // And that parsing a script does not. | 6012 // And that parsing a script does not. |
6004 { | 6013 { |
6005 i::Handle<i::Script> script = factory->NewScript(source); | 6014 i::Handle<i::Script> script = factory->NewScript(source); |
6006 i::ParseInfo info(script); | 6015 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 6016 i::ParseInfo info(&zone, script); |
6007 CHECK(!i::parsing::ParseProgram(&info)); | 6017 CHECK(!i::parsing::ParseProgram(&info)); |
6008 isolate->clear_pending_exception(); | 6018 isolate->clear_pending_exception(); |
6009 } | 6019 } |
6010 } | 6020 } |
6011 } | 6021 } |
6012 | 6022 |
6013 | 6023 |
6014 TEST(ImportExportParsingErrors) { | 6024 TEST(ImportExportParsingErrors) { |
6015 // clang-format off | 6025 // clang-format off |
6016 const char* kErrorSources[] = { | 6026 const char* kErrorSources[] = { |
(...skipping 69 matching lines...) Loading... |
6086 v8::Context::Scope context_scope(context); | 6096 v8::Context::Scope context_scope(context); |
6087 | 6097 |
6088 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 6098 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
6089 128 * 1024); | 6099 128 * 1024); |
6090 | 6100 |
6091 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { | 6101 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { |
6092 i::Handle<i::String> source = | 6102 i::Handle<i::String> source = |
6093 factory->NewStringFromAsciiChecked(kErrorSources[i]); | 6103 factory->NewStringFromAsciiChecked(kErrorSources[i]); |
6094 | 6104 |
6095 i::Handle<i::Script> script = factory->NewScript(source); | 6105 i::Handle<i::Script> script = factory->NewScript(source); |
6096 i::ParseInfo info(script); | 6106 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 6107 i::ParseInfo info(&zone, script); |
6097 info.set_module(); | 6108 info.set_module(); |
6098 CHECK(!i::parsing::ParseProgram(&info)); | 6109 CHECK(!i::parsing::ParseProgram(&info)); |
6099 isolate->clear_pending_exception(); | 6110 isolate->clear_pending_exception(); |
6100 } | 6111 } |
6101 } | 6112 } |
6102 | 6113 |
6103 TEST(ModuleTopLevelFunctionDecl) { | 6114 TEST(ModuleTopLevelFunctionDecl) { |
6104 // clang-format off | 6115 // clang-format off |
6105 const char* kErrorSources[] = { | 6116 const char* kErrorSources[] = { |
6106 "function f() {} function f() {}", | 6117 "function f() {} function f() {}", |
(...skipping 15 matching lines...) Loading... |
6122 v8::Context::Scope context_scope(context); | 6133 v8::Context::Scope context_scope(context); |
6123 | 6134 |
6124 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 6135 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
6125 128 * 1024); | 6136 128 * 1024); |
6126 | 6137 |
6127 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { | 6138 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { |
6128 i::Handle<i::String> source = | 6139 i::Handle<i::String> source = |
6129 factory->NewStringFromAsciiChecked(kErrorSources[i]); | 6140 factory->NewStringFromAsciiChecked(kErrorSources[i]); |
6130 | 6141 |
6131 i::Handle<i::Script> script = factory->NewScript(source); | 6142 i::Handle<i::Script> script = factory->NewScript(source); |
6132 i::ParseInfo info(script); | 6143 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 6144 i::ParseInfo info(&zone, script); |
6133 info.set_module(); | 6145 info.set_module(); |
6134 CHECK(!i::parsing::ParseProgram(&info)); | 6146 CHECK(!i::parsing::ParseProgram(&info)); |
6135 isolate->clear_pending_exception(); | 6147 isolate->clear_pending_exception(); |
6136 } | 6148 } |
6137 } | 6149 } |
6138 | 6150 |
6139 TEST(ModuleAwaitReserved) { | 6151 TEST(ModuleAwaitReserved) { |
6140 // clang-format off | 6152 // clang-format off |
6141 const char* kErrorSources[] = { | 6153 const char* kErrorSources[] = { |
6142 "await;", | 6154 "await;", |
(...skipping 176 matching lines...) Loading... |
6319 "import 'q.js';" | 6331 "import 'q.js';" |
6320 "let nonexport = 42;" | 6332 "let nonexport = 42;" |
6321 "import {m as mm} from 'm.js';" | 6333 "import {m as mm} from 'm.js';" |
6322 "import {aa} from 'm.js';" | 6334 "import {aa} from 'm.js';" |
6323 "export {aa as bb, x};" | 6335 "export {aa as bb, x};" |
6324 "import * as loo from 'bar.js';" | 6336 "import * as loo from 'bar.js';" |
6325 "import * as foob from 'bar.js';" | 6337 "import * as foob from 'bar.js';" |
6326 "export {foob};"; | 6338 "export {foob};"; |
6327 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource); | 6339 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource); |
6328 i::Handle<i::Script> script = factory->NewScript(source); | 6340 i::Handle<i::Script> script = factory->NewScript(source); |
6329 i::ParseInfo info(script); | 6341 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 6342 i::ParseInfo info(&zone, script); |
6330 info.set_module(); | 6343 info.set_module(); |
6331 CHECK(i::parsing::ParseProgram(&info)); | 6344 CHECK(i::parsing::ParseProgram(&info)); |
6332 CHECK(i::Compiler::Analyze(&info)); | 6345 CHECK(i::Compiler::Analyze(&info)); |
6333 i::FunctionLiteral* func = info.literal(); | 6346 i::FunctionLiteral* func = info.literal(); |
6334 i::ModuleScope* module_scope = func->scope()->AsModuleScope(); | 6347 i::ModuleScope* module_scope = func->scope()->AsModuleScope(); |
6335 i::Scope* outer_scope = module_scope->outer_scope(); | 6348 i::Scope* outer_scope = module_scope->outer_scope(); |
6336 CHECK(outer_scope->is_script_scope()); | 6349 CHECK(outer_scope->is_script_scope()); |
6337 CHECK_NULL(outer_scope->outer_scope()); | 6350 CHECK_NULL(outer_scope->outer_scope()); |
6338 CHECK(module_scope->is_module_scope()); | 6351 CHECK(module_scope->is_module_scope()); |
6339 const i::ModuleDescriptor::Entry* entry; | 6352 const i::ModuleDescriptor::Entry* entry; |
(...skipping 238 matching lines...) Loading... |
6578 i::Isolate* isolate = CcTest::i_isolate(); | 6591 i::Isolate* isolate = CcTest::i_isolate(); |
6579 i::Factory* factory = isolate->factory(); | 6592 i::Factory* factory = isolate->factory(); |
6580 v8::HandleScope handles(CcTest::isolate()); | 6593 v8::HandleScope handles(CcTest::isolate()); |
6581 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); | 6594 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
6582 v8::Context::Scope context_scope(context); | 6595 v8::Context::Scope context_scope(context); |
6583 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 6596 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
6584 128 * 1024); | 6597 128 * 1024); |
6585 | 6598 |
6586 i::Handle<i::Script> script = | 6599 i::Handle<i::Script> script = |
6587 factory->NewScript(factory->NewStringFromAsciiChecked(source)); | 6600 factory->NewScript(factory->NewStringFromAsciiChecked(source)); |
6588 i::ParseInfo info(script); | 6601 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); |
| 6602 i::ParseInfo info(&zone, script); |
6589 i::parsing::ParseProgram(&info); | 6603 i::parsing::ParseProgram(&info); |
6590 CHECK(info.literal() != NULL); | 6604 CHECK(info.literal() != NULL); |
6591 CHECK_EQ(expected_language_mode, info.literal()->language_mode()); | 6605 CHECK_EQ(expected_language_mode, info.literal()->language_mode()); |
6592 } | 6606 } |
6593 | 6607 |
6594 | 6608 |
6595 TEST(LanguageModeDirectives) { | 6609 TEST(LanguageModeDirectives) { |
6596 TestLanguageMode("\"use nothing\"", i::SLOPPY); | 6610 TestLanguageMode("\"use nothing\"", i::SLOPPY); |
6597 TestLanguageMode("\"use strict\"", i::STRICT); | 6611 TestLanguageMode("\"use strict\"", i::STRICT); |
6598 | 6612 |
(...skipping 2453 matching lines...) Loading... |
9052 i::SNPrintF( | 9066 i::SNPrintF( |
9053 program + prefix_len + inner_function_len + params_len + source_len, | 9067 program + prefix_len + inner_function_len + params_len + source_len, |
9054 "%s", suffix); | 9068 "%s", suffix); |
9055 | 9069 |
9056 i::Handle<i::String> source = | 9070 i::Handle<i::String> source = |
9057 factory->InternalizeUtf8String(program.start()); | 9071 factory->InternalizeUtf8String(program.start()); |
9058 source->PrintOn(stdout); | 9072 source->PrintOn(stdout); |
9059 printf("\n"); | 9073 printf("\n"); |
9060 | 9074 |
9061 i::Handle<i::Script> script = factory->NewScript(source); | 9075 i::Handle<i::Script> script = factory->NewScript(source); |
9062 i::ParseInfo info(script); | 9076 i::Zone zone(isolate->allocator(), ZONE_NAME); |
| 9077 i::ParseInfo info(&zone, script); |
9063 | 9078 |
9064 CHECK(i::parsing::ParseProgram(&info)); | 9079 CHECK(i::parsing::ParseProgram(&info)); |
9065 CHECK(i::Compiler::Analyze(&info)); | 9080 CHECK(i::Compiler::Analyze(&info)); |
9066 CHECK(info.literal() != NULL); | 9081 CHECK(info.literal() != NULL); |
9067 | 9082 |
9068 i::Scope* scope = info.literal()->scope()->inner_scope(); | 9083 i::Scope* scope = info.literal()->scope()->inner_scope(); |
9069 DCHECK_NOT_NULL(scope); | 9084 DCHECK_NOT_NULL(scope); |
9070 DCHECK_NULL(scope->sibling()); | 9085 DCHECK_NULL(scope->sibling()); |
9071 DCHECK(scope->is_function_scope()); | 9086 DCHECK(scope->is_function_scope()); |
9072 const i::AstRawString* var_name = | 9087 const i::AstRawString* var_name = |
9073 info.ast_value_factory()->GetOneByteString("my_var"); | 9088 info.ast_value_factory()->GetOneByteString("my_var"); |
9074 i::Variable* var = scope->Lookup(var_name); | 9089 i::Variable* var = scope->Lookup(var_name); |
9075 CHECK_EQ(inners[i].ctxt_allocate, | 9090 CHECK_EQ(inners[i].ctxt_allocate, |
9076 i::ScopeTestHelper::MustAllocateInContext(var)); | 9091 i::ScopeTestHelper::MustAllocateInContext(var)); |
9077 } | 9092 } |
9078 } | 9093 } |
9079 } | 9094 } |
OLD | NEW |