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(); |
| 61 |
| 62 // Isolate exceptions that occur when executing the code. These exceptions |
| 63 // should not interfere with javascript code we might evaluate from C++ when |
| 64 // returning from here. |
60 v8::TryCatch try_catch(isolate); | 65 v8::TryCatch try_catch(isolate); |
61 try_catch.SetVerbose(true); | 66 try_catch.SetVerbose(true); |
| 67 |
| 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. |
62 v8::Local<v8::Value> result; | 70 v8::Local<v8::Value> result; |
63 if (!V8Call( | 71 if (!V8Call( |
64 V8ScriptRunner::EvaluateModule(module_->NewLocal(isolate), | 72 V8ScriptRunner::EvaluateModule(module_->NewLocal(isolate), |
65 script_state->GetContext(), isolate), | 73 script_state->GetContext(), isolate), |
66 result, try_catch)) { | 74 result, try_catch)) { |
67 // TODO(adamk): report error | 75 return; |
68 } | 76 } |
69 } | 77 } |
70 | 78 |
71 Vector<String> ScriptModule::ModuleRequests(ScriptState* script_state) { | 79 Vector<String> ScriptModule::ModuleRequests(ScriptState* script_state) { |
72 if (IsNull()) | 80 if (IsNull()) |
73 return Vector<String>(); | 81 return Vector<String>(); |
74 | 82 |
75 v8::Local<v8::Module> module = module_->NewLocal(script_state->GetIsolate()); | 83 v8::Local<v8::Module> module = module_->NewLocal(script_state->GetIsolate()); |
76 | 84 |
77 Vector<String> ret; | 85 Vector<String> ret; |
(...skipping 23 matching lines...) Expand all Loading... |
101 if (resolved.IsNull()) { | 109 if (resolved.IsNull()) { |
102 DCHECK(exception_state.HadException()); | 110 DCHECK(exception_state.HadException()); |
103 return v8::MaybeLocal<v8::Module>(); | 111 return v8::MaybeLocal<v8::Module>(); |
104 } | 112 } |
105 | 113 |
106 DCHECK(!exception_state.HadException()); | 114 DCHECK(!exception_state.HadException()); |
107 return v8::MaybeLocal<v8::Module>(resolved.module_->NewLocal(isolate)); | 115 return v8::MaybeLocal<v8::Module>(resolved.module_->NewLocal(isolate)); |
108 } | 116 } |
109 | 117 |
110 } // namespace blink | 118 } // namespace blink |
OLD | NEW |