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/ModuleScript.h" | |
9 #include "core/dom/ScriptModuleResolver.h" | 10 #include "core/dom/ScriptModuleResolver.h" |
10 | 11 |
11 namespace blink { | 12 namespace blink { |
12 | 13 |
13 ScriptModule::ScriptModule(v8::Isolate* isolate, v8::Local<v8::Module> module) | 14 ScriptModule::ScriptModule(v8::Isolate* isolate, v8::Local<v8::Module> module) |
14 : module_(SharedPersistent<v8::Module>::Create(module, isolate)), | 15 : module_(SharedPersistent<v8::Module>::Create(module, isolate)), |
15 identity_hash_(static_cast<unsigned>(module->GetIdentityHash())) { | 16 identity_hash_(static_cast<unsigned>(module->GetIdentityHash())) { |
16 DCHECK(!module_->IsEmpty()); | 17 DCHECK(!module_->IsEmpty()); |
17 } | 18 } |
18 | 19 |
(...skipping 29 matching lines...) Expand all Loading... | |
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 // https://html.spec.whatwg.org/#run-a-module-script |
60 void ScriptModule::Evaluate(ScriptState* script_state, | |
61 const ModuleScript* moduleScript) { | |
59 v8::Isolate* isolate = script_state->GetIsolate(); | 62 v8::Isolate* isolate = script_state->GetIsolate(); |
60 v8::TryCatch try_catch(isolate); | 63 v8::TryCatch try_catch(isolate); |
61 try_catch.SetVerbose(true); | 64 try_catch.SetVerbose(true); |
62 v8::Local<v8::Value> result; | 65 v8::Local<v8::Value> result; |
66 | |
67 // 3. "If s's instantiation state is "errored", then report the exception | |
hiroshige
2017/04/12 19:57:05
Where should this logic be placed?
(Note that this
kouhei (in TOK)
2017/04/13 02:28:36
I'd put this logic in ModulatorImpl
hiroshige
2017/04/13 23:53:15
Splitted the ModulatorImpl change into
https://cod
| |
68 // given by s's instantiation error for s and abort these steps." | |
69 if (moduleScript->InstantiationState() == | |
70 ModuleInstantiationState::kErrored) { | |
71 V8ThrowException::ThrowException( | |
72 isolate, moduleScript->CreateInstantiationError(isolate)); | |
73 return; | |
74 } | |
75 | |
76 // 4. "Assert: s's instantiation state is "instantiated" (and thus its | |
77 // module record is not null)." | |
78 DCHECK_EQ(moduleScript->InstantiationState(), | |
79 ModuleInstantiationState::kInstantiated); | |
80 | |
81 // 5. "Let record be s's module record." | |
82 const ScriptModule& record = moduleScript->Record(); | |
83 DCHECK(!record.IsNull()); | |
84 | |
85 // 6.--9.? | |
63 if (!V8Call( | 86 if (!V8Call( |
64 V8ScriptRunner::EvaluateModule(module_->NewLocal(isolate), | 87 V8ScriptRunner::EvaluateModule(record.module_->NewLocal(isolate), |
65 script_state->GetContext(), isolate), | 88 script_state->GetContext(), isolate), |
66 result, try_catch)) { | 89 result, try_catch)) { |
67 // TODO(adamk): report error | 90 // TODO(adamk): report error |
68 } | 91 } |
69 } | 92 } |
70 | 93 |
71 Vector<String> ScriptModule::ModuleRequests(ScriptState* script_state) { | 94 Vector<String> ScriptModule::ModuleRequests(ScriptState* script_state) { |
72 if (IsNull()) | 95 if (IsNull()) |
73 return Vector<String>(); | 96 return Vector<String>(); |
74 | 97 |
(...skipping 26 matching lines...) Expand all Loading... | |
101 if (resolved.IsNull()) { | 124 if (resolved.IsNull()) { |
102 DCHECK(exception_state.HadException()); | 125 DCHECK(exception_state.HadException()); |
103 return v8::MaybeLocal<v8::Module>(); | 126 return v8::MaybeLocal<v8::Module>(); |
104 } | 127 } |
105 | 128 |
106 DCHECK(!exception_state.HadException()); | 129 DCHECK(!exception_state.HadException()); |
107 return v8::MaybeLocal<v8::Module>(resolved.module_->NewLocal(isolate)); | 130 return v8::MaybeLocal<v8::Module>(resolved.module_->NewLocal(isolate)); |
108 } | 131 } |
109 | 132 |
110 } // namespace blink | 133 } // namespace blink |
OLD | NEW |