OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 ? cacheHandler->cachedMetadata(cacheTag(CacheTagCode, cacheHandler)) | 486 ? cacheHandler->cachedMetadata(cacheTag(CacheTagCode, cacheHandler)) |
487 : nullptr); | 487 : nullptr); |
488 std::unique_ptr<CompileFn> compileFn = | 488 std::unique_ptr<CompileFn> compileFn = |
489 streamer ? selectCompileFunction(cacheOptions, resource, streamer) | 489 streamer ? selectCompileFunction(cacheOptions, resource, streamer) |
490 : selectCompileFunction(cacheOptions, cacheHandler, codeCache, | 490 : selectCompileFunction(cacheOptions, cacheHandler, codeCache, |
491 code, cacheabilityIfNoHandler); | 491 code, cacheabilityIfNoHandler); |
492 | 492 |
493 return (*compileFn)(isolate, code, origin); | 493 return (*compileFn)(isolate, code, origin); |
494 } | 494 } |
495 | 495 |
| 496 v8::MaybeLocal<v8::Module> V8ScriptRunner::compileModule( |
| 497 v8::Isolate* isolate, |
| 498 const String& source, |
| 499 const String& fileName) { |
| 500 TRACE_EVENT1("v8", "v8.compileModule", "fileName", fileName.utf8()); |
| 501 // TODO(adamk): Add Inspector integration? |
| 502 // TODO(adamk): Pass more info into ScriptOrigin. |
| 503 v8::ScriptOrigin origin(v8String(isolate, fileName)); |
| 504 v8::ScriptCompiler::Source scriptSource(v8String(isolate, source), origin); |
| 505 return v8::ScriptCompiler::CompileModule(isolate, &scriptSource); |
| 506 } |
| 507 |
496 v8::MaybeLocal<v8::Value> V8ScriptRunner::runCompiledScript( | 508 v8::MaybeLocal<v8::Value> V8ScriptRunner::runCompiledScript( |
497 v8::Isolate* isolate, | 509 v8::Isolate* isolate, |
498 v8::Local<v8::Script> script, | 510 v8::Local<v8::Script> script, |
499 ExecutionContext* context) { | 511 ExecutionContext* context) { |
500 ASSERT(!script.IsEmpty()); | 512 ASSERT(!script.IsEmpty()); |
501 ScopedFrameBlamer frameBlamer( | 513 ScopedFrameBlamer frameBlamer( |
502 context->isDocument() ? toDocument(context)->frame() : nullptr); | 514 context->isDocument() ? toDocument(context)->frame() : nullptr); |
503 TRACE_EVENT1("v8", "v8.run", "fileName", | 515 TRACE_EVENT1("v8", "v8.run", "fileName", |
504 TRACE_STR_COPY(*v8::String::Utf8Value( | 516 TRACE_STR_COPY(*v8::String::Utf8Value( |
505 script->GetUnboundScript()->GetScriptName()))); | 517 script->GetUnboundScript()->GetScriptName()))); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 TRACE_EVENT0("v8", "v8.callFunction"); | 665 TRACE_EVENT0("v8", "v8.callFunction"); |
654 CHECK(!ThreadState::current()->isWrapperTracingForbidden()); | 666 CHECK(!ThreadState::current()->isWrapperTracingForbidden()); |
655 v8::MicrotasksScope microtasksScope(isolate, | 667 v8::MicrotasksScope microtasksScope(isolate, |
656 v8::MicrotasksScope::kDoNotRunMicrotasks); | 668 v8::MicrotasksScope::kDoNotRunMicrotasks); |
657 v8::MaybeLocal<v8::Value> result = | 669 v8::MaybeLocal<v8::Value> result = |
658 function->Call(isolate->GetCurrentContext(), receiver, argc, args); | 670 function->Call(isolate->GetCurrentContext(), receiver, argc, args); |
659 crashIfIsolateIsDead(isolate); | 671 crashIfIsolateIsDead(isolate); |
660 return result; | 672 return result; |
661 } | 673 } |
662 | 674 |
| 675 v8::MaybeLocal<v8::Value> V8ScriptRunner::evaluateModule( |
| 676 v8::Local<v8::Module> module, |
| 677 v8::Local<v8::Context> context, |
| 678 v8::Isolate* isolate) { |
| 679 TRACE_EVENT0("v8", "v8.evaluateModule"); |
| 680 v8::MicrotasksScope microtasksScope(isolate, |
| 681 v8::MicrotasksScope::kRunMicrotasks); |
| 682 return module->Evaluate(context); |
| 683 } |
| 684 |
663 v8::MaybeLocal<v8::Object> V8ScriptRunner::instantiateObject( | 685 v8::MaybeLocal<v8::Object> V8ScriptRunner::instantiateObject( |
664 v8::Isolate* isolate, | 686 v8::Isolate* isolate, |
665 v8::Local<v8::ObjectTemplate> objectTemplate) { | 687 v8::Local<v8::ObjectTemplate> objectTemplate) { |
666 TRACE_EVENT0("v8", "v8.newInstance"); | 688 TRACE_EVENT0("v8", "v8.newInstance"); |
667 | 689 |
668 v8::MicrotasksScope microtasksScope(isolate, | 690 v8::MicrotasksScope microtasksScope(isolate, |
669 v8::MicrotasksScope::kDoNotRunMicrotasks); | 691 v8::MicrotasksScope::kDoNotRunMicrotasks); |
670 v8::MaybeLocal<v8::Object> result = | 692 v8::MaybeLocal<v8::Object> result = |
671 objectTemplate->NewInstance(isolate->GetCurrentContext()); | 693 objectTemplate->NewInstance(isolate->GetCurrentContext()); |
672 crashIfIsolateIsDead(isolate); | 694 crashIfIsolateIsDead(isolate); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 v8AtomicString(isolate, "((e) => { throw e; })"), origin) | 767 v8AtomicString(isolate, "((e) => { throw e; })"), origin) |
746 .ToLocalChecked(); | 768 .ToLocalChecked(); |
747 v8::Local<v8::Function> thrower = runCompiledInternalScript(isolate, script) | 769 v8::Local<v8::Function> thrower = runCompiledInternalScript(isolate, script) |
748 .ToLocalChecked() | 770 .ToLocalChecked() |
749 .As<v8::Function>(); | 771 .As<v8::Function>(); |
750 v8::Local<v8::Value> args[] = {exception}; | 772 v8::Local<v8::Value> args[] = {exception}; |
751 callInternalFunction(thrower, thrower, WTF_ARRAY_LENGTH(args), args, isolate); | 773 callInternalFunction(thrower, thrower, WTF_ARRAY_LENGTH(args), args, isolate); |
752 } | 774 } |
753 | 775 |
754 } // namespace blink | 776 } // namespace blink |
OLD | NEW |