Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: src/d8.cc

Issue 2347933002: [modules] Introduce v8::Module to the API and return it from CompileModule (Closed)
Patch Set: Less maybe Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/d8.h ('k') | src/factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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) {
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 {
485 DCHECK(false); // A new compile option? 479 DCHECK(false); // A new compile option?
486 } 480 }
487 if (data == NULL) compile_options = ScriptCompiler::kNoCompileOptions; 481 if (data == NULL) compile_options = ScriptCompiler::kNoCompileOptions;
488 DCHECK_EQ(SCRIPT, source_type);
489 MaybeLocal<Script> result = 482 MaybeLocal<Script> result =
490 ScriptCompiler::Compile(context, &cached_source, compile_options); 483 ScriptCompiler::Compile(context, &cached_source, compile_options);
491 CHECK(data == NULL || !data->rejected); 484 CHECK(data == NULL || !data->rejected);
492 return result; 485 return result;
493 } 486 }
494 487
495 488
496 // Executes a string within the current v8 context. 489 // Executes a string within the current v8 context.
497 bool Shell::ExecuteString(Isolate* isolate, Local<String> source, 490 bool Shell::ExecuteString(Isolate* isolate, Local<String> source,
498 Local<Value> name, bool print_result, 491 Local<Value> name, bool print_result,
499 bool report_exceptions, SourceType source_type) { 492 bool report_exceptions, SourceType source_type) {
500 HandleScope handle_scope(isolate); 493 HandleScope handle_scope(isolate);
501 TryCatch try_catch(isolate); 494 TryCatch try_catch(isolate);
502 try_catch.SetVerbose(true); 495 try_catch.SetVerbose(true);
503 496
504 MaybeLocal<Value> maybe_result; 497 MaybeLocal<Value> maybe_result;
505 { 498 {
506 PerIsolateData* data = PerIsolateData::Get(isolate); 499 PerIsolateData* data = PerIsolateData::Get(isolate);
507 Local<Context> realm = 500 Local<Context> realm =
508 Local<Context>::New(isolate, data->realms_[data->realm_current_]); 501 Local<Context>::New(isolate, data->realms_[data->realm_current_]);
509 Context::Scope context_scope(realm); 502 Context::Scope context_scope(realm);
510 Local<Script> script; 503 if (source_type == SCRIPT) {
511 if (!Shell::CompileString(isolate, source, name, options.compile_options, 504 Local<Script> script;
512 source_type).ToLocal(&script)) { 505 if (!Shell::CompileString(isolate, source, name, options.compile_options)
513 // Print errors that happened during compilation. 506 .ToLocal(&script)) {
514 if (report_exceptions) ReportException(isolate, &try_catch); 507 // Print errors that happened during compilation.
515 return false; 508 if (report_exceptions) ReportException(isolate, &try_catch);
509 return false;
510 }
511 maybe_result = script->Run(realm);
512 } else {
513 DCHECK_EQ(MODULE, source_type);
514 Local<Module> module;
515 ScriptOrigin origin(name);
516 ScriptCompiler::Source script_source(source, origin);
517 // TODO(adamk): Make use of compile options for Modules.
518 if (!ScriptCompiler::CompileModule(isolate, &script_source)
519 .ToLocal(&module)) {
520 // Print errors that happened during compilation.
521 if (report_exceptions) ReportException(isolate, &try_catch);
522 return false;
523 }
524 // This can't fail until we support linking.
525 CHECK(module->Instantiate(realm));
526 maybe_result = module->Evaluate(realm);
516 } 527 }
517 maybe_result = script->Run(realm);
518 EmptyMessageQueues(isolate); 528 EmptyMessageQueues(isolate);
519 data->realm_current_ = data->realm_switch_; 529 data->realm_current_ = data->realm_switch_;
520 } 530 }
521 Local<Value> result; 531 Local<Value> result;
522 if (!maybe_result.ToLocal(&result)) { 532 if (!maybe_result.ToLocal(&result)) {
523 DCHECK(try_catch.HasCaught()); 533 DCHECK(try_catch.HasCaught());
524 // Print errors that happened during execution. 534 // Print errors that happened during execution.
525 if (report_exceptions) ReportException(isolate, &try_catch); 535 if (report_exceptions) ReportException(isolate, &try_catch);
526 return false; 536 return false;
527 } 537 }
(...skipping 2187 matching lines...) Expand 10 before | Expand all | Expand 10 after
2715 } 2725 }
2716 2726
2717 } // namespace v8 2727 } // namespace v8
2718 2728
2719 2729
2720 #ifndef GOOGLE3 2730 #ifndef GOOGLE3
2721 int main(int argc, char* argv[]) { 2731 int main(int argc, char* argv[]) {
2722 return v8::Shell::Main(argc, argv); 2732 return v8::Shell::Main(argc, argv);
2723 } 2733 }
2724 #endif 2734 #endif
OLDNEW
« no previous file with comments | « src/d8.h ('k') | src/factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698