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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 v8::TryCatch tryCatch(isolate); | 55 v8::TryCatch tryCatch(isolate); |
56 tryCatch.SetVerbose(true); | 56 tryCatch.SetVerbose(true); |
57 v8::Local<v8::Value> result; | 57 v8::Local<v8::Value> result; |
58 if (!v8Call(V8ScriptRunner::evaluateModule(m_module->newLocal(isolate), | 58 if (!v8Call(V8ScriptRunner::evaluateModule(m_module->newLocal(isolate), |
59 scriptState->context(), isolate), | 59 scriptState->context(), isolate), |
60 result, tryCatch)) { | 60 result, tryCatch)) { |
61 // TODO(adamk): report error | 61 // TODO(adamk): report error |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
| 65 Vector<String> ScriptModule::moduleRequests(ScriptState* scriptState) { |
| 66 if (isNull()) |
| 67 return Vector<String>(); |
| 68 |
| 69 v8::Local<v8::Module> module = m_module->newLocal(scriptState->isolate()); |
| 70 |
| 71 Vector<String> ret; |
| 72 |
| 73 int length = module->GetModuleRequestsLength(); |
| 74 ret.reserveInitialCapacity(length); |
| 75 for (int i = 0; i < length; ++i) { |
| 76 v8::Local<v8::String> v8Name = module->GetModuleRequest(i); |
| 77 ret.push_back(toCoreString(v8Name)); |
| 78 } |
| 79 return ret; |
| 80 } |
| 81 |
65 v8::MaybeLocal<v8::Module> ScriptModule::resolveModuleCallback( | 82 v8::MaybeLocal<v8::Module> ScriptModule::resolveModuleCallback( |
66 v8::Local<v8::Context> context, | 83 v8::Local<v8::Context> context, |
67 v8::Local<v8::String> specifier, | 84 v8::Local<v8::String> specifier, |
68 v8::Local<v8::Module> referrer) { | 85 v8::Local<v8::Module> referrer) { |
69 v8::Isolate* isolate = context->GetIsolate(); | 86 v8::Isolate* isolate = context->GetIsolate(); |
70 Modulator* modulator = V8PerContextData::from(context)->modulator(); | 87 Modulator* modulator = V8PerContextData::from(context)->modulator(); |
71 DCHECK(modulator); | 88 DCHECK(modulator); |
72 | 89 |
73 ScriptModule referrerRecord(isolate, referrer); | 90 ScriptModule referrerRecord(isolate, referrer); |
74 ExceptionState exceptionState(isolate, ExceptionState::ExecutionContext, | 91 ExceptionState exceptionState(isolate, ExceptionState::ExecutionContext, |
75 "ScriptModule", "resolveModuleCallback"); | 92 "ScriptModule", "resolveModuleCallback"); |
76 ScriptModule resolved = modulator->scriptModuleResolver()->resolve( | 93 ScriptModule resolved = modulator->scriptModuleResolver()->resolve( |
77 toCoreStringWithNullCheck(specifier), referrerRecord, exceptionState); | 94 toCoreStringWithNullCheck(specifier), referrerRecord, exceptionState); |
78 if (resolved.isNull()) { | 95 if (resolved.isNull()) { |
79 DCHECK(exceptionState.hadException()); | 96 DCHECK(exceptionState.hadException()); |
80 return v8::MaybeLocal<v8::Module>(); | 97 return v8::MaybeLocal<v8::Module>(); |
81 } | 98 } |
82 | 99 |
83 DCHECK(!exceptionState.hadException()); | 100 DCHECK(!exceptionState.hadException()); |
84 return v8::MaybeLocal<v8::Module>(resolved.m_module->newLocal(isolate)); | 101 return v8::MaybeLocal<v8::Module>(resolved.m_module->newLocal(isolate)); |
85 } | 102 } |
86 | 103 |
87 } // namespace blink | 104 } // namespace blink |
OLD | NEW |