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