| 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/V8Binding.h" | 7 #include "bindings/core/v8/V8Binding.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 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 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 } |
| 41 | 41 |
| 42 ScriptValue ScriptModule::Instantiate(ScriptState* script_state) { | 42 ScriptValue ScriptModule::Instantiate(ScriptState* script_state) { |
| 43 v8::Isolate* isolate = script_state->GetIsolate(); | 43 v8::Isolate* isolate = script_state->GetIsolate(); |
| 44 v8::TryCatch try_catch(isolate); | 44 v8::TryCatch try_catch(isolate); |
| 45 try_catch.SetVerbose(true); |
| 45 | 46 |
| 46 DCHECK(!IsNull()); | 47 DCHECK(!IsNull()); |
| 47 v8::Local<v8::Context> context = script_state->GetContext(); | 48 v8::Local<v8::Context> context = script_state->GetContext(); |
| 48 bool success = module_->NewLocal(script_state->GetIsolate()) | 49 bool success = module_->NewLocal(script_state->GetIsolate()) |
| 49 ->Instantiate(context, &ResolveModuleCallback); | 50 ->Instantiate(context, &ResolveModuleCallback); |
| 50 if (!success) { | 51 if (!success) { |
| 51 DCHECK(try_catch.HasCaught()); | 52 DCHECK(try_catch.HasCaught()); |
| 52 return ScriptValue(script_state, try_catch.Exception()); | 53 return ScriptValue(script_state, try_catch.Exception()); |
| 53 } | 54 } |
| 54 DCHECK(!try_catch.HasCaught()); | 55 DCHECK(!try_catch.HasCaught()); |
| 55 return ScriptValue(); | 56 return ScriptValue(); |
| 56 } | 57 } |
| 57 | 58 |
| 58 void ScriptModule::Evaluate(ScriptState* script_state) { | 59 void ScriptModule::Evaluate(ScriptState* script_state) const { |
| 59 v8::Isolate* isolate = script_state->GetIsolate(); | 60 v8::Isolate* isolate = script_state->GetIsolate(); |
| 60 v8::TryCatch try_catch(isolate); | 61 v8::TryCatch try_catch(isolate); |
| 61 try_catch.SetVerbose(true); | 62 try_catch.SetVerbose(true); |
| 62 v8::Local<v8::Value> result; | 63 v8::Local<v8::Value> result; |
| 63 if (!V8Call( | 64 if (!V8Call( |
| 64 V8ScriptRunner::EvaluateModule(module_->NewLocal(isolate), | 65 V8ScriptRunner::EvaluateModule(module_->NewLocal(isolate), |
| 65 script_state->GetContext(), isolate), | 66 script_state->GetContext(), isolate), |
| 66 result, try_catch)) { | 67 result, try_catch)) { |
| 67 // TODO(adamk): report error | 68 // TODO(adamk): report error |
| 68 } | 69 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 if (resolved.IsNull()) { | 102 if (resolved.IsNull()) { |
| 102 DCHECK(exception_state.HadException()); | 103 DCHECK(exception_state.HadException()); |
| 103 return v8::MaybeLocal<v8::Module>(); | 104 return v8::MaybeLocal<v8::Module>(); |
| 104 } | 105 } |
| 105 | 106 |
| 106 DCHECK(!exception_state.HadException()); | 107 DCHECK(!exception_state.HadException()); |
| 107 return v8::MaybeLocal<v8::Module>(resolved.module_->NewLocal(isolate)); | 108 return v8::MaybeLocal<v8::Module>(resolved.module_->NewLocal(isolate)); |
| 108 } | 109 } |
| 109 | 110 |
| 110 } // namespace blink | 111 } // namespace blink |
| OLD | NEW |