| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium 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 #include "bindings/core/v8/ScriptModule.h" | 5 #include "bindings/core/v8/ScriptModule.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/V8BindingForCore.h" | 7 #include "bindings/core/v8/V8BindingForCore.h" |
| 8 #include "core/dom/Modulator.h" | 8 #include "core/dom/Modulator.h" |
| 9 #include "core/dom/ScriptModuleResolver.h" | 9 #include "core/dom/ScriptModuleResolver.h" |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 ScriptModule::ScriptModule(v8::Isolate* isolate, v8::Local<v8::Module> module) | 13 ScriptModule::ScriptModule(v8::Isolate* isolate, v8::Local<v8::Module> module) |
| 14 : module_(SharedPersistent<v8::Module>::Create(module, isolate)), | 14 : module_(SharedPersistent<v8::Module>::Create(module, isolate)), |
| 15 identity_hash_(static_cast<unsigned>(module->GetIdentityHash())) { | 15 identity_hash_(static_cast<unsigned>(module->GetIdentityHash())) { |
| 16 DCHECK(!module_->IsEmpty()); | 16 DCHECK(!module_->IsEmpty()); |
| 17 } | 17 } |
| 18 | 18 |
| 19 ScriptModule::~ScriptModule() {} | 19 ScriptModule::~ScriptModule() {} |
| 20 | 20 |
| 21 ScriptModule ScriptModule::Compile(v8::Isolate* isolate, | 21 ScriptModule ScriptModule::Compile(v8::Isolate* isolate, |
| 22 const String& source, | 22 const String& source, |
| 23 const String& file_name, | 23 const String& file_name, |
| 24 AccessControlStatus access_control_status) { | 24 AccessControlStatus access_control_status) { |
| 25 v8::TryCatch try_catch(isolate); | 25 v8::TryCatch try_catch(isolate); |
| 26 try_catch.SetVerbose(true); | 26 try_catch.SetVerbose(true); |
| 27 v8::Local<v8::Module> module; | 27 v8::Local<v8::Module> module; |
| 28 if (!V8Call(V8ScriptRunner::CompileModule(isolate, source, file_name, | 28 if (!V8ScriptRunner::CompileModule(isolate, source, file_name, |
| 29 access_control_status), | 29 access_control_status) |
| 30 module, try_catch)) { | 30 .ToLocal(&module)) { |
| 31 // Compilation error is not used in Blink implementaion logic. | 31 // Compilation error is not used in Blink implementaion logic. |
| 32 // Note: Error message is delivered to user (e.g. console) by message | 32 // Note: Error message is delivered to user (e.g. console) by message |
| 33 // listeners set on v8::Isolate. See V8Initializer::initalizeMainThread(). | 33 // listeners set on v8::Isolate. See V8Initializer::initalizeMainThread(). |
| 34 // TODO(nhiroki): Revisit this when supporting modules on worker threads. | 34 // TODO(nhiroki): Revisit this when supporting modules on worker threads. |
| 35 DCHECK(try_catch.HasCaught()); | 35 DCHECK(try_catch.HasCaught()); |
| 36 return ScriptModule(); | 36 return ScriptModule(); |
| 37 } | 37 } |
| 38 DCHECK(!try_catch.HasCaught()); | 38 DCHECK(!try_catch.HasCaught()); |
| 39 return ScriptModule(isolate, module); | 39 return ScriptModule(isolate, module); |
| 40 } | 40 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 61 | 61 |
| 62 // Isolate exceptions that occur when executing the code. These exceptions | 62 // Isolate exceptions that occur when executing the code. These exceptions |
| 63 // should not interfere with javascript code we might evaluate from C++ when | 63 // should not interfere with javascript code we might evaluate from C++ when |
| 64 // returning from here. | 64 // returning from here. |
| 65 v8::TryCatch try_catch(isolate); | 65 v8::TryCatch try_catch(isolate); |
| 66 try_catch.SetVerbose(true); | 66 try_catch.SetVerbose(true); |
| 67 | 67 |
| 68 // TODO(kouhei): We currently don't have a code-path which use return value of | 68 // TODO(kouhei): We currently don't have a code-path which use return value of |
| 69 // EvaluateModule. Stop ignoring result once we have such path. | 69 // EvaluateModule. Stop ignoring result once we have such path. |
| 70 v8::Local<v8::Value> result; | 70 v8::Local<v8::Value> result; |
| 71 if (!V8Call( | 71 if (!V8ScriptRunner::EvaluateModule(module_->NewLocal(isolate), |
| 72 V8ScriptRunner::EvaluateModule(module_->NewLocal(isolate), | 72 script_state->GetContext(), isolate) |
| 73 script_state->GetContext(), isolate), | 73 .ToLocal(&result)) { |
| 74 result, try_catch)) { | |
| 75 return; | 74 return; |
| 76 } | 75 } |
| 77 } | 76 } |
| 78 | 77 |
| 79 Vector<String> ScriptModule::ModuleRequests(ScriptState* script_state) { | 78 Vector<String> ScriptModule::ModuleRequests(ScriptState* script_state) { |
| 80 if (IsNull()) | 79 if (IsNull()) |
| 81 return Vector<String>(); | 80 return Vector<String>(); |
| 82 | 81 |
| 83 v8::Local<v8::Module> module = module_->NewLocal(script_state->GetIsolate()); | 82 v8::Local<v8::Module> module = module_->NewLocal(script_state->GetIsolate()); |
| 84 | 83 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 109 if (resolved.IsNull()) { | 108 if (resolved.IsNull()) { |
| 110 DCHECK(exception_state.HadException()); | 109 DCHECK(exception_state.HadException()); |
| 111 return v8::MaybeLocal<v8::Module>(); | 110 return v8::MaybeLocal<v8::Module>(); |
| 112 } | 111 } |
| 113 | 112 |
| 114 DCHECK(!exception_state.HadException()); | 113 DCHECK(!exception_state.HadException()); |
| 115 return v8::MaybeLocal<v8::Module>(resolved.module_->NewLocal(isolate)); | 114 return v8::MaybeLocal<v8::Module>(resolved.module_->NewLocal(isolate)); |
| 116 } | 115 } |
| 117 | 116 |
| 118 } // namespace blink | 117 } // namespace blink |
| OLD | NEW |