From 71b988d1b43333431c4a087671c35486ac7ad586 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Tue, 8 Sep 2020 08:22:28 +0000 Subject: Issue #618 - Make ES6 modules work for resource: URIs --- dom/script/ScriptLoader.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'dom/script') diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp index 851987ed1..71838580f 100644 --- a/dom/script/ScriptLoader.cpp +++ b/dom/script/ScriptLoader.cpp @@ -2446,6 +2446,18 @@ ScriptLoader::NumberOfProcessors() return mNumberOfProcessors; } +static bool +IsInternalURIScheme(nsIURI* uri) +{ + // Note: Extend this if other schemes need to be included. + bool isResource; + if (NS_SUCCEEDED(uri->SchemeIs("resource", &isResource)) && isResource) { + return true; + } + + return false; +} + nsresult ScriptLoader::PrepareLoadedRequest(ScriptLoadRequest* aRequest, nsIIncrementalStreamLoader* aLoader, @@ -2533,7 +2545,17 @@ ScriptLoader::PrepareLoadedRequest(ScriptLoadRequest* aRequest, return NS_ERROR_FAILURE; } - channel->GetURI(getter_AddRefs(request->mBaseURL)); + nsCOMPtr uri; + rv = channel->GetOriginalURI(getter_AddRefs(uri)); + NS_ENSURE_SUCCESS(rv, rv); + + // Fixup internal scheme URIs like resource:, because the channel URI + // will point to file: which won't be allowed to load. + if (uri && IsInternalURIScheme(uri)) { + request->mBaseURL = uri; + } else { + channel->GetURI(getter_AddRefs(request->mBaseURL)); + } // Attempt to compile off main thread. rv = AttemptAsyncScriptCompile(request); -- cgit v1.2.3