OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 // Defined when linking against shared lib on Windows. | 6 // Defined when linking against shared lib on Windows. |
7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) | 7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) |
8 #define V8_SHARED | 8 #define V8_SHARED |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
453 temp_isolate->Dispose(); | 453 temp_isolate->Dispose(); |
454 delete[] source_buffer; | 454 delete[] source_buffer; |
455 delete[] name_buffer; | 455 delete[] name_buffer; |
456 return result; | 456 return result; |
457 } | 457 } |
458 | 458 |
459 | 459 |
460 // Compile a string within the current v8 context. | 460 // Compile a string within the current v8 context. |
461 MaybeLocal<Script> Shell::CompileString( | 461 MaybeLocal<Script> Shell::CompileString( |
462 Isolate* isolate, Local<String> source, Local<Value> name, | 462 Isolate* isolate, Local<String> source, Local<Value> name, |
463 ScriptCompiler::CompileOptions compile_options, SourceType source_type) { | 463 ScriptCompiler::CompileOptions compile_options, SourceType source_type) { |
neis
2016/09/16 20:53:33
This shouldn't take a SourceType anymore.
adamk
2016/09/16 20:58:06
Done.
| |
464 Local<Context> context(isolate->GetCurrentContext()); | 464 Local<Context> context(isolate->GetCurrentContext()); |
465 ScriptOrigin origin(name); | 465 ScriptOrigin origin(name); |
466 // TODO(adamk): Make use of compile options for Modules. | 466 if (compile_options == ScriptCompiler::kNoCompileOptions) { |
467 if (compile_options == ScriptCompiler::kNoCompileOptions || | |
468 source_type == MODULE) { | |
469 ScriptCompiler::Source script_source(source, origin); | 467 ScriptCompiler::Source script_source(source, origin); |
470 return source_type == SCRIPT | 468 return ScriptCompiler::Compile(context, &script_source, compile_options); |
471 ? ScriptCompiler::Compile(context, &script_source, | |
472 compile_options) | |
473 : ScriptCompiler::CompileModule(context, &script_source, | |
474 compile_options); | |
475 } | 469 } |
476 | 470 |
477 ScriptCompiler::CachedData* data = | 471 ScriptCompiler::CachedData* data = |
478 CompileForCachedData(source, name, compile_options); | 472 CompileForCachedData(source, name, compile_options); |
479 ScriptCompiler::Source cached_source(source, origin, data); | 473 ScriptCompiler::Source cached_source(source, origin, data); |
480 if (compile_options == ScriptCompiler::kProduceCodeCache) { | 474 if (compile_options == ScriptCompiler::kProduceCodeCache) { |
481 compile_options = ScriptCompiler::kConsumeCodeCache; | 475 compile_options = ScriptCompiler::kConsumeCodeCache; |
482 } else if (compile_options == ScriptCompiler::kProduceParserCache) { | 476 } else if (compile_options == ScriptCompiler::kProduceParserCache) { |
483 compile_options = ScriptCompiler::kConsumeParserCache; | 477 compile_options = ScriptCompiler::kConsumeParserCache; |
484 } else { | 478 } else { |
(...skipping 15 matching lines...) Expand all Loading... | |
500 HandleScope handle_scope(isolate); | 494 HandleScope handle_scope(isolate); |
501 TryCatch try_catch(isolate); | 495 TryCatch try_catch(isolate); |
502 try_catch.SetVerbose(true); | 496 try_catch.SetVerbose(true); |
503 | 497 |
504 MaybeLocal<Value> maybe_result; | 498 MaybeLocal<Value> maybe_result; |
505 { | 499 { |
506 PerIsolateData* data = PerIsolateData::Get(isolate); | 500 PerIsolateData* data = PerIsolateData::Get(isolate); |
507 Local<Context> realm = | 501 Local<Context> realm = |
508 Local<Context>::New(isolate, data->realms_[data->realm_current_]); | 502 Local<Context>::New(isolate, data->realms_[data->realm_current_]); |
509 Context::Scope context_scope(realm); | 503 Context::Scope context_scope(realm); |
510 Local<Script> script; | 504 if (source_type == SCRIPT) { |
511 if (!Shell::CompileString(isolate, source, name, options.compile_options, | 505 Local<Script> script; |
512 source_type).ToLocal(&script)) { | 506 if (!Shell::CompileString(isolate, source, name, options.compile_options, |
513 // Print errors that happened during compilation. | 507 source_type) |
514 if (report_exceptions) ReportException(isolate, &try_catch); | 508 .ToLocal(&script)) { |
515 return false; | 509 // Print errors that happened during compilation. |
510 if (report_exceptions) ReportException(isolate, &try_catch); | |
511 return false; | |
512 } | |
513 maybe_result = script->Run(realm); | |
514 } else { | |
515 DCHECK_EQ(MODULE, source_type); | |
516 Local<Module> module; | |
517 ScriptOrigin origin(name); | |
518 ScriptCompiler::Source script_source(source, origin); | |
519 // TODO(adamk): Make use of compile options for Modules. | |
520 if (!ScriptCompiler::CompileModule(isolate, &script_source) | |
521 .ToLocal(&module)) { | |
522 // Print errors that happened during compilation. | |
523 if (report_exceptions) ReportException(isolate, &try_catch); | |
524 return false; | |
525 } | |
526 // This can't fail until we support linking. | |
527 CHECK(module->Instantiate(realm).FromJust()); | |
528 maybe_result = module->Evaluate(realm); | |
516 } | 529 } |
517 maybe_result = script->Run(realm); | |
518 EmptyMessageQueues(isolate); | 530 EmptyMessageQueues(isolate); |
519 data->realm_current_ = data->realm_switch_; | 531 data->realm_current_ = data->realm_switch_; |
520 } | 532 } |
521 Local<Value> result; | 533 Local<Value> result; |
522 if (!maybe_result.ToLocal(&result)) { | 534 if (!maybe_result.ToLocal(&result)) { |
523 DCHECK(try_catch.HasCaught()); | 535 DCHECK(try_catch.HasCaught()); |
524 // Print errors that happened during execution. | 536 // Print errors that happened during execution. |
525 if (report_exceptions) ReportException(isolate, &try_catch); | 537 if (report_exceptions) ReportException(isolate, &try_catch); |
526 return false; | 538 return false; |
527 } | 539 } |
(...skipping 2187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2715 } | 2727 } |
2716 | 2728 |
2717 } // namespace v8 | 2729 } // namespace v8 |
2718 | 2730 |
2719 | 2731 |
2720 #ifndef GOOGLE3 | 2732 #ifndef GOOGLE3 |
2721 int main(int argc, char* argv[]) { | 2733 int main(int argc, char* argv[]) { |
2722 return v8::Shell::Main(argc, argv); | 2734 return v8::Shell::Main(argc, argv); |
2723 } | 2735 } |
2724 #endif | 2736 #endif |
OLD | NEW |