|
Lines 218-239
JSC::JSInternalPromise* ScriptModuleLoader::importModule(JSC::JSGlobalObject* js
a/Source/WebCore/bindings/js/ScriptModuleLoader.cpp_sec1
|
| 218 |
JSC::VM& vm = exec->vm(); |
218 |
JSC::VM& vm = exec->vm(); |
| 219 |
auto& globalObject = *JSC::jsCast<JSDOMGlobalObject*>(jsGlobalObject); |
219 |
auto& globalObject = *JSC::jsCast<JSDOMGlobalObject*>(jsGlobalObject); |
| 220 |
|
220 |
|
| 221 |
// FIXME: setTimeout and setInterval with "string()" should propagate SourceOrigin. |
221 |
// If SourceOrigin and/or CachedScriptFetcher is null, we import the module with the default fetcher. |
| 222 |
// https://webkit.org/b/167097 |
222 |
// SourceOrigin can be null if the source code is not coupled with the script file. |
| 223 |
ASSERT_WITH_MESSAGE(!sourceOrigin.isNull(), "If SourceOrigin is null, this function is not invoked."); |
223 |
// The examples, |
| 224 |
if (!sourceOrigin.fetcher()) |
224 |
// 1. The code evaluated by the inspector. |
| 225 |
return rejectPromise(state, globalObject, TypeError, ASCIILiteral("Could not use import operator in this context.")); |
225 |
// 2. The other unusual code execution like the evaluation through the NPAPI. |
| 226 |
|
226 |
URL baseURL; |
| 227 |
URL baseURL(URL(), sourceOrigin.string()); |
227 |
RefPtr<JSC::ScriptFetcher> scriptFetcher; |
| 228 |
if (!baseURL.isValid()) |
228 |
if (sourceOrigin.isNull()) { |
| 229 |
return rejectPromise(state, globalObject, TypeError, ASCIILiteral("Importer module key is not Symbol or String.")); |
229 |
baseURL = m_document.baseURL(); |
|
|
230 |
scriptFetcher = CachedScriptFetcher::create(m_document.charset()); |
| 231 |
} else { |
| 232 |
baseURL = URL(URL(), sourceOrigin.string()); |
| 233 |
if (!baseURL.isValid()) |
| 234 |
return rejectPromise(state, globalObject, TypeError, ASCIILiteral("Importer module key is not a Symbol or a String.")); |
| 235 |
|
| 236 |
if (sourceOrigin.fetcher()) |
| 237 |
scriptFetcher = sourceOrigin.fetcher(); |
| 238 |
else |
| 239 |
scriptFetcher = CachedScriptFetcher::create(m_document.charset()); |
| 240 |
} |
| 241 |
ASSERT(baseURL.isValid()); |
| 242 |
ASSERT(scriptFetcher); |
| 230 |
|
243 |
|
| 231 |
auto specifier = moduleName->value(exec); |
244 |
auto specifier = moduleName->value(exec); |
| 232 |
auto result = resolveModuleSpecifier(m_document, specifier, baseURL); |
245 |
auto result = resolveModuleSpecifier(m_document, specifier, baseURL); |
| 233 |
if (!result) |
246 |
if (!result) |
| 234 |
return rejectPromise(state, globalObject, TypeError, result.error()); |
247 |
return rejectPromise(state, globalObject, TypeError, result.error()); |
| 235 |
|
248 |
|
| 236 |
return JSC::importModule(exec, JSC::Identifier::fromString(&vm, result->string()), JSC::JSScriptFetcher::create(vm, sourceOrigin.fetcher() )); |
249 |
return JSC::importModule(exec, JSC::Identifier::fromString(&vm, result->string()), JSC::JSScriptFetcher::create(vm, WTFMove(scriptFetcher) )); |
| 237 |
} |
250 |
} |
| 238 |
|
251 |
|
| 239 |
void ScriptModuleLoader::notifyFinished(CachedModuleScriptLoader& loader, RefPtr<DeferredPromise> promise) |
252 |
void ScriptModuleLoader::notifyFinished(CachedModuleScriptLoader& loader, RefPtr<DeferredPromise> promise) |