Bug 1742437 - re-scope all generic module/script loader files under js/loader; r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D138133
This commit is contained in:
@@ -31,6 +31,7 @@
|
|||||||
#include "js/CompileOptions.h"
|
#include "js/CompileOptions.h"
|
||||||
#include "js/friend/PerformanceHint.h"
|
#include "js/friend/PerformanceHint.h"
|
||||||
#include "js/Id.h"
|
#include "js/Id.h"
|
||||||
|
#include "js/loader/LoadedScript.h"
|
||||||
#include "js/PropertyAndElement.h" // JS_DefineProperty, JS_GetProperty
|
#include "js/PropertyAndElement.h" // JS_DefineProperty, JS_GetProperty
|
||||||
#include "js/PropertyDescriptor.h"
|
#include "js/PropertyDescriptor.h"
|
||||||
#include "js/RealmOptions.h"
|
#include "js/RealmOptions.h"
|
||||||
@@ -135,7 +136,6 @@
|
|||||||
#include "mozilla/dom/IntlUtils.h"
|
#include "mozilla/dom/IntlUtils.h"
|
||||||
#include "mozilla/dom/JSExecutionContext.h"
|
#include "mozilla/dom/JSExecutionContext.h"
|
||||||
#include "mozilla/dom/LSObject.h"
|
#include "mozilla/dom/LSObject.h"
|
||||||
#include "mozilla/dom/LoadedScript.h"
|
|
||||||
#include "mozilla/dom/LocalStorage.h"
|
#include "mozilla/dom/LocalStorage.h"
|
||||||
#include "mozilla/dom/LocalStorageCommon.h"
|
#include "mozilla/dom/LocalStorageCommon.h"
|
||||||
#include "mozilla/dom/Location.h"
|
#include "mozilla/dom/Location.h"
|
||||||
@@ -6126,7 +6126,7 @@ class WindowScriptTimeoutHandler final : public ScriptTimeoutHandler {
|
|||||||
virtual ~WindowScriptTimeoutHandler() = default;
|
virtual ~WindowScriptTimeoutHandler() = default;
|
||||||
|
|
||||||
// Initiating script for use when evaluating mExpr on the main thread.
|
// Initiating script for use when evaluating mExpr on the main thread.
|
||||||
RefPtr<LoadedScript> mInitiatingScript;
|
RefPtr<JS::loader::LoadedScript> mInitiatingScript;
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_IMPL_CYCLE_COLLECTION_INHERITED(WindowScriptTimeoutHandler,
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(WindowScriptTimeoutHandler,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
// Microsoft's API Name hackery sucks
|
// Microsoft's API Name hackery sucks
|
||||||
#undef CreateEvent
|
#undef CreateEvent
|
||||||
|
|
||||||
|
#include "js/loader/LoadedScript.h"
|
||||||
#include "mozilla/BasicEvents.h"
|
#include "mozilla/BasicEvents.h"
|
||||||
#include "mozilla/CycleCollectedJSRuntime.h"
|
#include "mozilla/CycleCollectedJSRuntime.h"
|
||||||
#include "mozilla/DOMEventTargetHelper.h"
|
#include "mozilla/DOMEventTargetHelper.h"
|
||||||
@@ -25,7 +26,6 @@
|
|||||||
#include "mozilla/dom/Element.h"
|
#include "mozilla/dom/Element.h"
|
||||||
#include "mozilla/dom/Event.h"
|
#include "mozilla/dom/Event.h"
|
||||||
#include "mozilla/dom/EventTargetBinding.h"
|
#include "mozilla/dom/EventTargetBinding.h"
|
||||||
#include "mozilla/dom/LoadedScript.h"
|
|
||||||
#include "mozilla/dom/PopupBlocker.h"
|
#include "mozilla/dom/PopupBlocker.h"
|
||||||
#include "mozilla/dom/ScriptLoader.h"
|
#include "mozilla/dom/ScriptLoader.h"
|
||||||
#include "mozilla/dom/ScriptSettings.h"
|
#include "mozilla/dom/ScriptSettings.h"
|
||||||
@@ -1234,12 +1234,13 @@ nsresult EventListenerManager::CompileEventHandlerInternal(
|
|||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<ScriptFetchOptions> fetchOptions = new ScriptFetchOptions(
|
RefPtr<JS::loader::ScriptFetchOptions> fetchOptions =
|
||||||
CORS_NONE, aElement->OwnerDoc()->GetReferrerPolicy(),
|
new JS::loader::ScriptFetchOptions(
|
||||||
aElement->OwnerDoc()->NodePrincipal());
|
CORS_NONE, aElement->OwnerDoc()->GetReferrerPolicy(),
|
||||||
|
aElement->OwnerDoc()->NodePrincipal());
|
||||||
|
|
||||||
RefPtr<EventScript> eventScript =
|
RefPtr<JS::loader::EventScript> eventScript =
|
||||||
new EventScript(fetchOptions, uri, aElement);
|
new JS::loader::EventScript(fetchOptions, uri, aElement);
|
||||||
|
|
||||||
JS::CompileOptions options(cx);
|
JS::CompileOptions options(cx);
|
||||||
// Use line 0 to make the function body starts from line 1.
|
// Use line 0 to make the function body starts from line 1.
|
||||||
|
|||||||
@@ -5,12 +5,7 @@
|
|||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#include "ScriptLoader.h"
|
#include "ScriptLoader.h"
|
||||||
#include "ScriptLoadRequest.h"
|
|
||||||
#include "ScriptTrace.h"
|
|
||||||
#include "LoadedScript.h"
|
|
||||||
#include "ModuleLoader.h"
|
#include "ModuleLoader.h"
|
||||||
#include "ModuleLoaderBase.h"
|
|
||||||
#include "ModuleLoadRequest.h"
|
|
||||||
|
|
||||||
#include "jsapi.h"
|
#include "jsapi.h"
|
||||||
#include "js/ContextOptions.h" // JS::ContextOptionsRef
|
#include "js/ContextOptions.h" // JS::ContextOptionsRef
|
||||||
@@ -20,11 +15,16 @@
|
|||||||
#include "js/PropertyAndElement.h" // JS_DefineProperty
|
#include "js/PropertyAndElement.h" // JS_DefineProperty
|
||||||
#include "js/Realm.h"
|
#include "js/Realm.h"
|
||||||
#include "js/SourceText.h"
|
#include "js/SourceText.h"
|
||||||
|
#include "js/loader/LoadedScript.h"
|
||||||
|
#include "js/loader/ScriptLoadRequest.h"
|
||||||
|
#include "js/loader/ModuleLoaderBase.h"
|
||||||
|
#include "js/loader/ModuleLoadRequest.h"
|
||||||
#include "xpcpublic.h"
|
#include "xpcpublic.h"
|
||||||
#include "GeckoProfiler.h"
|
#include "GeckoProfiler.h"
|
||||||
#include "nsIContent.h"
|
#include "nsIContent.h"
|
||||||
#include "nsJSUtils.h"
|
#include "nsJSUtils.h"
|
||||||
#include "mozilla/dom/AutoEntryScript.h"
|
#include "mozilla/dom/AutoEntryScript.h"
|
||||||
|
#include "mozilla/dom/Document.h"
|
||||||
#include "mozilla/dom/Element.h"
|
#include "mozilla/dom/Element.h"
|
||||||
#include "mozilla/Preferences.h"
|
#include "mozilla/Preferences.h"
|
||||||
#include "nsGlobalWindowInner.h"
|
#include "nsGlobalWindowInner.h"
|
||||||
@@ -32,6 +32,7 @@
|
|||||||
#include "mozilla/LoadInfo.h"
|
#include "mozilla/LoadInfo.h"
|
||||||
|
|
||||||
using JS::SourceText;
|
using JS::SourceText;
|
||||||
|
using namespace JS::loader;
|
||||||
|
|
||||||
namespace mozilla::dom {
|
namespace mozilla::dom {
|
||||||
|
|
||||||
|
|||||||
@@ -7,9 +7,9 @@
|
|||||||
#ifndef mozilla_dom_ModuleLoader_h
|
#ifndef mozilla_dom_ModuleLoader_h
|
||||||
#define mozilla_dom_ModuleLoader_h
|
#define mozilla_dom_ModuleLoader_h
|
||||||
|
|
||||||
#include "ModuleLoaderBase.h"
|
|
||||||
#include "mozilla/dom/ScriptLoadContext.h"
|
#include "mozilla/dom/ScriptLoadContext.h"
|
||||||
#include "mozilla/dom/ScriptLoadRequest.h"
|
#include "js/loader/ModuleLoaderBase.h"
|
||||||
|
#include "js/loader/ScriptLoadRequest.h"
|
||||||
#include "ScriptLoader.h"
|
#include "ScriptLoader.h"
|
||||||
|
|
||||||
class nsIURI;
|
class nsIURI;
|
||||||
@@ -18,19 +18,24 @@ namespace JS {
|
|||||||
|
|
||||||
class CompileOptions;
|
class CompileOptions;
|
||||||
|
|
||||||
|
namespace loader {
|
||||||
|
|
||||||
|
class ModuleLoadRequest;
|
||||||
|
|
||||||
|
} // namespace loader
|
||||||
} // namespace JS
|
} // namespace JS
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace dom {
|
namespace dom {
|
||||||
|
|
||||||
class ModuleLoadRequest;
|
class ScriptLoader;
|
||||||
class SRIMetadata;
|
class SRIMetadata;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
// DOM Module loader implementation
|
// DOM Module loader implementation
|
||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
class ModuleLoader final : public ModuleLoaderBase {
|
class ModuleLoader final : public JS::loader::ModuleLoaderBase {
|
||||||
private:
|
private:
|
||||||
virtual ~ModuleLoader();
|
virtual ~ModuleLoader();
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#include "ScriptLoadRequest.h"
|
|
||||||
#include "GeckoProfiler.h"
|
#include "GeckoProfiler.h"
|
||||||
|
|
||||||
#include "mozilla/dom/Document.h"
|
#include "mozilla/dom/Document.h"
|
||||||
@@ -15,15 +14,13 @@
|
|||||||
|
|
||||||
#include "js/OffThreadScriptCompilation.h"
|
#include "js/OffThreadScriptCompilation.h"
|
||||||
#include "js/SourceText.h"
|
#include "js/SourceText.h"
|
||||||
|
#include "js/loader/ScriptLoadRequest.h"
|
||||||
|
|
||||||
#include "ModuleLoadRequest.h"
|
#include "ModuleLoadRequest.h"
|
||||||
#include "nsContentUtils.h"
|
#include "nsContentUtils.h"
|
||||||
#include "nsICacheInfoChannel.h"
|
#include "nsICacheInfoChannel.h"
|
||||||
#include "nsIClassOfService.h"
|
#include "nsIClassOfService.h"
|
||||||
#include "nsISupportsPriority.h"
|
#include "nsISupportsPriority.h"
|
||||||
#include "ScriptSettings.h"
|
|
||||||
|
|
||||||
using JS::SourceText;
|
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace dom {
|
namespace dom {
|
||||||
@@ -134,7 +131,7 @@ void ScriptLoadContext::MaybeCancelOffThreadScript() {
|
|||||||
mOffThreadToken = nullptr;
|
mOffThreadToken = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptLoadContext::SetRequest(ScriptLoadRequest* aRequest) {
|
void ScriptLoadContext::SetRequest(JS::loader::ScriptLoadRequest* aRequest) {
|
||||||
MOZ_ASSERT(!mRequest);
|
MOZ_ASSERT(!mRequest);
|
||||||
mRequest = aRequest;
|
mRequest = aRequest;
|
||||||
}
|
}
|
||||||
@@ -172,7 +169,8 @@ void ScriptLoadContext::PrioritizeAsPreload() {
|
|||||||
|
|
||||||
bool ScriptLoadContext::IsPreload() const {
|
bool ScriptLoadContext::IsPreload() const {
|
||||||
if (mRequest->IsModuleRequest() && !mRequest->IsTopLevel()) {
|
if (mRequest->IsModuleRequest() && !mRequest->IsTopLevel()) {
|
||||||
ModuleLoadRequest* root = mRequest->AsModuleRequest()->GetRootModule();
|
JS::loader::ModuleLoadRequest* root =
|
||||||
|
mRequest->AsModuleRequest()->GetRootModule();
|
||||||
return root->GetLoadContext()->IsPreload();
|
return root->GetLoadContext()->IsPreload();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,7 +180,8 @@ bool ScriptLoadContext::IsPreload() const {
|
|||||||
|
|
||||||
nsIGlobalObject* ScriptLoadContext::GetWebExtGlobal() const {
|
nsIGlobalObject* ScriptLoadContext::GetWebExtGlobal() const {
|
||||||
if (mRequest->IsModuleRequest() && !mRequest->IsTopLevel()) {
|
if (mRequest->IsModuleRequest() && !mRequest->IsTopLevel()) {
|
||||||
ModuleLoadRequest* root = mRequest->AsModuleRequest()->GetRootModule();
|
JS::loader::ModuleLoadRequest* root =
|
||||||
|
mRequest->AsModuleRequest()->GetRootModule();
|
||||||
return root->GetLoadContext()->GetWebExtGlobal();
|
return root->GetLoadContext()->GetWebExtGlobal();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,7 +195,8 @@ bool ScriptLoadContext::CompileStarted() const {
|
|||||||
|
|
||||||
nsIScriptElement* ScriptLoadContext::GetScriptElement() const {
|
nsIScriptElement* ScriptLoadContext::GetScriptElement() const {
|
||||||
if (mRequest->IsModuleRequest() && !mRequest->IsTopLevel()) {
|
if (mRequest->IsModuleRequest() && !mRequest->IsTopLevel()) {
|
||||||
ModuleLoadRequest* root = mRequest->AsModuleRequest()->GetRootModule();
|
JS::loader::ModuleLoadRequest* root =
|
||||||
|
mRequest->AsModuleRequest()->GetRootModule();
|
||||||
return root->GetLoadContext()->GetScriptElement();
|
return root->GetLoadContext()->GetScriptElement();
|
||||||
}
|
}
|
||||||
nsCOMPtr<nsIScriptElement> scriptElement = do_QueryInterface(mElement);
|
nsCOMPtr<nsIScriptElement> scriptElement = do_QueryInterface(mElement);
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
#include "js/RootingAPI.h"
|
#include "js/RootingAPI.h"
|
||||||
#include "js/SourceText.h"
|
#include "js/SourceText.h"
|
||||||
#include "js/TypeDecls.h"
|
#include "js/TypeDecls.h"
|
||||||
|
#include "js/loader/ScriptKind.h"
|
||||||
|
#include "js/loader/ScriptLoadRequest.h"
|
||||||
#include "mozilla/Atomics.h"
|
#include "mozilla/Atomics.h"
|
||||||
#include "mozilla/Assertions.h"
|
#include "mozilla/Assertions.h"
|
||||||
#include "mozilla/CORSMode.h"
|
#include "mozilla/CORSMode.h"
|
||||||
@@ -27,19 +29,21 @@
|
|||||||
#include "nsCycleCollectionParticipant.h"
|
#include "nsCycleCollectionParticipant.h"
|
||||||
#include "nsIGlobalObject.h"
|
#include "nsIGlobalObject.h"
|
||||||
#include "nsIScriptElement.h"
|
#include "nsIScriptElement.h"
|
||||||
#include "ScriptKind.h"
|
#include "js/loader/ScriptKind.h"
|
||||||
|
|
||||||
class nsICacheInfoChannel;
|
class nsICacheInfoChannel;
|
||||||
|
|
||||||
namespace JS {
|
namespace JS {
|
||||||
class OffThreadToken;
|
class OffThreadToken;
|
||||||
|
namespace loader {
|
||||||
|
class ScriptLoadRequest;
|
||||||
}
|
}
|
||||||
|
} // namespace JS
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace dom {
|
namespace dom {
|
||||||
|
|
||||||
class Element;
|
class Element;
|
||||||
class ScriptLoadRequest;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DOM specific ScriptLoadContext.
|
* DOM specific ScriptLoadContext.
|
||||||
@@ -87,7 +91,7 @@ class ScriptLoadContext : public PreloaderBase {
|
|||||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ScriptLoadContext)
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ScriptLoadContext)
|
||||||
|
|
||||||
void SetRequest(ScriptLoadRequest* aRequest);
|
void SetRequest(JS::loader::ScriptLoadRequest* aRequest);
|
||||||
|
|
||||||
// PreloaderBase
|
// PreloaderBase
|
||||||
static void PrioritizeAsPreload(nsIChannel* aChannel);
|
static void PrioritizeAsPreload(nsIChannel* aChannel);
|
||||||
@@ -198,7 +202,7 @@ class ScriptLoadContext : public PreloaderBase {
|
|||||||
*/
|
*/
|
||||||
nsCOMPtr<nsIGlobalObject> mWebExtGlobal;
|
nsCOMPtr<nsIGlobalObject> mWebExtGlobal;
|
||||||
|
|
||||||
RefPtr<ScriptLoadRequest> mRequest;
|
RefPtr<JS::loader::ScriptLoadRequest> mRequest;
|
||||||
|
|
||||||
// Non-null if there is a document that this request is blocking from loading.
|
// Non-null if there is a document that this request is blocking from loading.
|
||||||
RefPtr<Document> mLoadBlockedDocument;
|
RefPtr<Document> mLoadBlockedDocument;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "ScriptLoader.h"
|
#include "ScriptLoader.h"
|
||||||
#include "ScriptTrace.h"
|
#include "ScriptTrace.h"
|
||||||
#include "js/Transcoding.h"
|
#include "js/Transcoding.h"
|
||||||
|
#include "js/loader/ScriptLoadRequest.h"
|
||||||
#include "mozilla/Assertions.h"
|
#include "mozilla/Assertions.h"
|
||||||
#include "mozilla/CheckedInt.h"
|
#include "mozilla/CheckedInt.h"
|
||||||
#include "mozilla/DebugOnly.h"
|
#include "mozilla/DebugOnly.h"
|
||||||
@@ -24,7 +25,6 @@
|
|||||||
#include "mozilla/dom/Document.h"
|
#include "mozilla/dom/Document.h"
|
||||||
#include "mozilla/dom/SRICheck.h"
|
#include "mozilla/dom/SRICheck.h"
|
||||||
#include "mozilla/dom/ScriptDecoding.h"
|
#include "mozilla/dom/ScriptDecoding.h"
|
||||||
#include "mozilla/dom/ScriptLoadRequest.h"
|
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "nsContentUtils.h"
|
#include "nsContentUtils.h"
|
||||||
#include "nsDebug.h"
|
#include "nsDebug.h"
|
||||||
@@ -50,7 +50,7 @@ namespace dom {
|
|||||||
MOZ_LOG_TEST(ScriptLoader::gScriptLoaderLog, mozilla::LogLevel::Debug)
|
MOZ_LOG_TEST(ScriptLoader::gScriptLoaderLog, mozilla::LogLevel::Debug)
|
||||||
|
|
||||||
ScriptLoadHandler::ScriptLoadHandler(
|
ScriptLoadHandler::ScriptLoadHandler(
|
||||||
ScriptLoader* aScriptLoader, ScriptLoadRequest* aRequest,
|
ScriptLoader* aScriptLoader, JS::loader::ScriptLoadRequest* aRequest,
|
||||||
UniquePtr<SRICheckDataVerifier>&& aSRIDataVerifier)
|
UniquePtr<SRICheckDataVerifier>&& aSRIDataVerifier)
|
||||||
: mScriptLoader(aScriptLoader),
|
: mScriptLoader(aScriptLoader),
|
||||||
mRequest(aRequest),
|
mRequest(aRequest),
|
||||||
@@ -76,7 +76,7 @@ nsresult ScriptLoadHandler::DecodeRawDataHelper(const uint8_t* aData,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reference to the script source buffer which we will update.
|
// Reference to the script source buffer which we will update.
|
||||||
ScriptLoadRequest::ScriptTextBuffer<Unit>& scriptText =
|
JS::loader::ScriptLoadRequest::ScriptTextBuffer<Unit>& scriptText =
|
||||||
mRequest->ScriptText<Unit>();
|
mRequest->ScriptText<Unit>();
|
||||||
|
|
||||||
uint32_t haveRead = scriptText.length();
|
uint32_t haveRead = scriptText.length();
|
||||||
|
|||||||
@@ -17,20 +17,23 @@
|
|||||||
#include "mozilla/RefPtr.h"
|
#include "mozilla/RefPtr.h"
|
||||||
#include "mozilla/UniquePtr.h"
|
#include "mozilla/UniquePtr.h"
|
||||||
|
|
||||||
|
namespace JS::loader {
|
||||||
|
class ScriptLoadRequest;
|
||||||
|
}
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
|
||||||
class Decoder;
|
class Decoder;
|
||||||
|
|
||||||
namespace dom {
|
namespace dom {
|
||||||
|
|
||||||
class ScriptLoadRequest;
|
|
||||||
class ScriptLoader;
|
class ScriptLoader;
|
||||||
class SRICheckDataVerifier;
|
class SRICheckDataVerifier;
|
||||||
|
|
||||||
class ScriptLoadHandler final : public nsIIncrementalStreamLoaderObserver {
|
class ScriptLoadHandler final : public nsIIncrementalStreamLoaderObserver {
|
||||||
public:
|
public:
|
||||||
explicit ScriptLoadHandler(
|
explicit ScriptLoadHandler(
|
||||||
ScriptLoader* aScriptLoader, ScriptLoadRequest* aRequest,
|
ScriptLoader* aScriptLoader, JS::loader::ScriptLoadRequest* aRequest,
|
||||||
UniquePtr<SRICheckDataVerifier>&& aSRIDataVerifier);
|
UniquePtr<SRICheckDataVerifier>&& aSRIDataVerifier);
|
||||||
|
|
||||||
NS_DECL_ISUPPORTS
|
NS_DECL_ISUPPORTS
|
||||||
@@ -96,7 +99,7 @@ class ScriptLoadHandler final : public nsIIncrementalStreamLoaderObserver {
|
|||||||
RefPtr<ScriptLoader> mScriptLoader;
|
RefPtr<ScriptLoader> mScriptLoader;
|
||||||
|
|
||||||
// The ScriptLoadRequest for this load. Decoded data are accumulated on it.
|
// The ScriptLoadRequest for this load. Decoded data are accumulated on it.
|
||||||
RefPtr<ScriptLoadRequest> mRequest;
|
RefPtr<JS::loader::ScriptLoadRequest> mRequest;
|
||||||
|
|
||||||
// SRI data verifier.
|
// SRI data verifier.
|
||||||
UniquePtr<SRICheckDataVerifier> mSRIDataVerifier;
|
UniquePtr<SRICheckDataVerifier> mSRIDataVerifier;
|
||||||
|
|||||||
@@ -6,11 +6,8 @@
|
|||||||
|
|
||||||
#include "ScriptLoader.h"
|
#include "ScriptLoader.h"
|
||||||
#include "ScriptLoadHandler.h"
|
#include "ScriptLoadHandler.h"
|
||||||
#include "ScriptLoadRequest.h"
|
|
||||||
#include "ScriptTrace.h"
|
#include "ScriptTrace.h"
|
||||||
#include "LoadedScript.h"
|
|
||||||
#include "ModuleLoader.h"
|
#include "ModuleLoader.h"
|
||||||
#include "ModuleLoadRequest.h"
|
|
||||||
|
|
||||||
#include "prsystem.h"
|
#include "prsystem.h"
|
||||||
#include "jsapi.h"
|
#include "jsapi.h"
|
||||||
@@ -19,6 +16,9 @@
|
|||||||
#include "js/CompilationAndEvaluation.h"
|
#include "js/CompilationAndEvaluation.h"
|
||||||
#include "js/ContextOptions.h" // JS::ContextOptionsRef
|
#include "js/ContextOptions.h" // JS::ContextOptionsRef
|
||||||
#include "js/friend/ErrorMessages.h" // js::GetErrorMessage, JSMSG_*
|
#include "js/friend/ErrorMessages.h" // js::GetErrorMessage, JSMSG_*
|
||||||
|
#include "js/loader/ScriptLoadRequest.h"
|
||||||
|
#include "js/loader/LoadedScript.h"
|
||||||
|
#include "js/loader/ModuleLoadRequest.h"
|
||||||
#include "js/MemoryFunctions.h"
|
#include "js/MemoryFunctions.h"
|
||||||
#include "js/OffThreadScriptCompilation.h"
|
#include "js/OffThreadScriptCompilation.h"
|
||||||
#include "js/PropertyAndElement.h" // JS_DefineProperty
|
#include "js/PropertyAndElement.h" // JS_DefineProperty
|
||||||
@@ -92,6 +92,7 @@
|
|||||||
#include "nsIAsyncOutputStream.h"
|
#include "nsIAsyncOutputStream.h"
|
||||||
|
|
||||||
using JS::SourceText;
|
using JS::SourceText;
|
||||||
|
using namespace JS::loader;
|
||||||
|
|
||||||
using mozilla::Telemetry::LABELS_DOM_SCRIPT_PRELOAD_RESULT;
|
using mozilla::Telemetry::LABELS_DOM_SCRIPT_PRELOAD_RESULT;
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,9 @@
|
|||||||
#define mozilla_dom_ScriptLoader_h
|
#define mozilla_dom_ScriptLoader_h
|
||||||
|
|
||||||
#include "js/TypeDecls.h"
|
#include "js/TypeDecls.h"
|
||||||
|
#include "js/loader/LoadedScript.h"
|
||||||
|
#include "js/loader/ScriptKind.h"
|
||||||
|
#include "js/loader/ScriptLoadRequest.h"
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "nsRefPtrHashtable.h"
|
#include "nsRefPtrHashtable.h"
|
||||||
#include "nsIScriptElement.h"
|
#include "nsIScriptElement.h"
|
||||||
@@ -20,13 +23,10 @@
|
|||||||
#include "nsIScriptLoaderObserver.h"
|
#include "nsIScriptLoaderObserver.h"
|
||||||
#include "nsURIHashKey.h"
|
#include "nsURIHashKey.h"
|
||||||
#include "mozilla/CORSMode.h"
|
#include "mozilla/CORSMode.h"
|
||||||
#include "mozilla/dom/LoadedScript.h"
|
|
||||||
#include "mozilla/dom/JSExecutionContext.h" // JSExecutionContext
|
#include "mozilla/dom/JSExecutionContext.h" // JSExecutionContext
|
||||||
#include "mozilla/dom/ScriptLoadRequest.h"
|
|
||||||
#include "ModuleLoader.h"
|
#include "ModuleLoader.h"
|
||||||
#include "mozilla/MaybeOneOf.h"
|
#include "mozilla/MaybeOneOf.h"
|
||||||
#include "mozilla/MozPromise.h"
|
#include "mozilla/MozPromise.h"
|
||||||
#include "ScriptKind.h"
|
|
||||||
|
|
||||||
class nsCycleCollectionTraversalCallback;
|
class nsCycleCollectionTraversalCallback;
|
||||||
class nsIChannel;
|
class nsIChannel;
|
||||||
@@ -44,6 +44,16 @@ class CompileOptions;
|
|||||||
template <typename UnitT>
|
template <typename UnitT>
|
||||||
class SourceText;
|
class SourceText;
|
||||||
|
|
||||||
|
namespace loader {
|
||||||
|
|
||||||
|
class LoadedScript;
|
||||||
|
class ScriptLoaderInterface;
|
||||||
|
class ModuleLoadRequest;
|
||||||
|
class ModuleScript;
|
||||||
|
class ScriptLoadRequest;
|
||||||
|
class ScriptLoadRequestList;
|
||||||
|
|
||||||
|
} // namespace loader
|
||||||
} // namespace JS
|
} // namespace JS
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
@@ -56,18 +66,11 @@ namespace dom {
|
|||||||
class AutoJSAPI;
|
class AutoJSAPI;
|
||||||
class DocGroup;
|
class DocGroup;
|
||||||
class Document;
|
class Document;
|
||||||
class LoadedScript;
|
|
||||||
class ScriptLoaderInterface;
|
|
||||||
class ModuleLoader;
|
class ModuleLoader;
|
||||||
class ModuleLoadRequest;
|
|
||||||
class ModuleScript;
|
|
||||||
class SRICheckDataVerifier;
|
class SRICheckDataVerifier;
|
||||||
class SRIMetadata;
|
class SRIMetadata;
|
||||||
class ScriptLoadHandler;
|
class ScriptLoadHandler;
|
||||||
class ScriptLoadRequest;
|
|
||||||
class ScriptLoadRequestList;
|
|
||||||
class ScriptLoadContext;
|
class ScriptLoadContext;
|
||||||
|
|
||||||
class ScriptLoader;
|
class ScriptLoader;
|
||||||
class ScriptRequestProcessor;
|
class ScriptRequestProcessor;
|
||||||
|
|
||||||
@@ -96,7 +99,7 @@ class AsyncCompileShutdownObserver final : public nsIObserver {
|
|||||||
// Script loader implementation
|
// Script loader implementation
|
||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
class ScriptLoader final : public ScriptLoaderInterface {
|
class ScriptLoader final : public JS::loader::ScriptLoaderInterface {
|
||||||
class MOZ_STACK_CLASS AutoCurrentScriptUpdater {
|
class MOZ_STACK_CLASS AutoCurrentScriptUpdater {
|
||||||
public:
|
public:
|
||||||
AutoCurrentScriptUpdater(ScriptLoader* aScriptLoader,
|
AutoCurrentScriptUpdater(ScriptLoader* aScriptLoader,
|
||||||
@@ -117,7 +120,7 @@ class ScriptLoader final : public ScriptLoaderInterface {
|
|||||||
ScriptLoader* mScriptLoader;
|
ScriptLoader* mScriptLoader;
|
||||||
};
|
};
|
||||||
|
|
||||||
friend class ModuleLoadRequest;
|
friend class JS::loader::ModuleLoadRequest;
|
||||||
friend class ScriptRequestProcessor;
|
friend class ScriptRequestProcessor;
|
||||||
friend class ModuleLoader;
|
friend class ModuleLoader;
|
||||||
friend class ScriptLoadHandler;
|
friend class ScriptLoadHandler;
|
||||||
@@ -409,7 +412,7 @@ class ScriptLoader final : public ScriptLoaderInterface {
|
|||||||
* Get the currently active script. This is used as the initiating script when
|
* Get the currently active script. This is used as the initiating script when
|
||||||
* executing timeout handler scripts.
|
* executing timeout handler scripts.
|
||||||
*/
|
*/
|
||||||
static LoadedScript* GetActiveScript(JSContext* aCx);
|
static JS::loader::LoadedScript* GetActiveScript(JSContext* aCx);
|
||||||
|
|
||||||
Document* GetDocument() const { return mDocument; }
|
Document* GetDocument() const { return mDocument; }
|
||||||
|
|
||||||
@@ -439,9 +442,9 @@ class ScriptLoader final : public ScriptLoaderInterface {
|
|||||||
|
|
||||||
bool ProcessInlineScript(nsIScriptElement* aElement, ScriptKind aScriptKind);
|
bool ProcessInlineScript(nsIScriptElement* aElement, ScriptKind aScriptKind);
|
||||||
|
|
||||||
ScriptLoadRequest* LookupPreloadRequest(nsIScriptElement* aElement,
|
JS::loader::ScriptLoadRequest* LookupPreloadRequest(
|
||||||
ScriptKind aScriptKind,
|
nsIScriptElement* aElement, ScriptKind aScriptKind,
|
||||||
const SRIMetadata& aSRIMetadata);
|
const SRIMetadata& aSRIMetadata);
|
||||||
|
|
||||||
void GetSRIMetadata(const nsAString& aIntegrityAttr,
|
void GetSRIMetadata(const nsAString& aIntegrityAttr,
|
||||||
SRIMetadata* aMetadataOut);
|
SRIMetadata* aMetadataOut);
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
#include "mozilla/dom/ScriptSettings.h"
|
#include "mozilla/dom/ScriptSettings.h"
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "LoadedScript.h"
|
|
||||||
#include "MainThreadUtils.h"
|
#include "MainThreadUtils.h"
|
||||||
#include "js/CharacterEncoding.h"
|
#include "js/CharacterEncoding.h"
|
||||||
#include "js/CompilationAndEvaluation.h"
|
#include "js/CompilationAndEvaluation.h"
|
||||||
@@ -21,6 +20,8 @@
|
|||||||
#include "js/Warnings.h"
|
#include "js/Warnings.h"
|
||||||
#include "js/Wrapper.h"
|
#include "js/Wrapper.h"
|
||||||
#include "js/friend/ErrorMessages.h"
|
#include "js/friend/ErrorMessages.h"
|
||||||
|
#include "js/loader/LoadedScript.h"
|
||||||
|
#include "js/loader/ScriptLoadRequest.h"
|
||||||
#include "jsapi.h"
|
#include "jsapi.h"
|
||||||
#include "mozilla/Assertions.h"
|
#include "mozilla/Assertions.h"
|
||||||
#include "mozilla/BasePrincipal.h"
|
#include "mozilla/BasePrincipal.h"
|
||||||
@@ -33,7 +34,6 @@
|
|||||||
#include "mozilla/dom/BindingUtils.h"
|
#include "mozilla/dom/BindingUtils.h"
|
||||||
#include "mozilla/dom/Document.h"
|
#include "mozilla/dom/Document.h"
|
||||||
#include "mozilla/dom/Element.h"
|
#include "mozilla/dom/Element.h"
|
||||||
#include "mozilla/dom/ScriptLoadRequest.h"
|
|
||||||
#include "mozilla/dom/WorkerCommon.h"
|
#include "mozilla/dom/WorkerCommon.h"
|
||||||
#include "nsContentUtils.h"
|
#include "nsContentUtils.h"
|
||||||
#include "nsDebug.h"
|
#include "nsDebug.h"
|
||||||
@@ -55,7 +55,8 @@ JSObject* SourceElementCallback(JSContext* aCx, JS::HandleValue aPrivateValue) {
|
|||||||
// NOTE: The result of this is only used by DevTools for matching sources, so
|
// NOTE: The result of this is only used by DevTools for matching sources, so
|
||||||
// it is safe to silently ignore any errors and return nullptr for them.
|
// it is safe to silently ignore any errors and return nullptr for them.
|
||||||
|
|
||||||
LoadedScript* script = static_cast<LoadedScript*>(aPrivateValue.toPrivate());
|
JS::loader::LoadedScript* script =
|
||||||
|
static_cast<JS::loader::LoadedScript*>(aPrivateValue.toPrivate());
|
||||||
|
|
||||||
JS::Rooted<JS::Value> elementValue(aCx);
|
JS::Rooted<JS::Value> elementValue(aCx);
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,34 +10,33 @@
|
|||||||
#include "mozilla/AsyncEventDispatcher.h"
|
#include "mozilla/AsyncEventDispatcher.h"
|
||||||
#include "mozilla/StaticPrefs_dom.h"
|
#include "mozilla/StaticPrefs_dom.h"
|
||||||
|
|
||||||
namespace mozilla {
|
|
||||||
namespace dom {
|
|
||||||
namespace script {
|
|
||||||
|
|
||||||
// This macro is used to wrap a tracing mechanism which is scheduling events
|
// This macro is used to wrap a tracing mechanism which is scheduling events
|
||||||
// which are then used by the JavaScript code of test cases to track the code
|
// which are then used by the JavaScript code of test cases to track the code
|
||||||
// path to verify the optimizations are working as expected.
|
// path to verify the optimizations are working as expected.
|
||||||
#define TRACE_FOR_TEST(elem, str) \
|
#define TRACE_FOR_TEST(elem, str) \
|
||||||
PR_BEGIN_MACRO \
|
PR_BEGIN_MACRO \
|
||||||
nsresult rv = NS_OK; \
|
nsresult rv = NS_OK; \
|
||||||
rv = \
|
rv = mozilla::dom::script::TestingDispatchEvent( \
|
||||||
script::TestingDispatchEvent(elem, NS_LITERAL_STRING_FROM_CSTRING(str)); \
|
elem, NS_LITERAL_STRING_FROM_CSTRING(str)); \
|
||||||
NS_ENSURE_SUCCESS(rv, rv); \
|
NS_ENSURE_SUCCESS(rv, rv); \
|
||||||
PR_END_MACRO
|
PR_END_MACRO
|
||||||
|
|
||||||
#define TRACE_FOR_TEST_BOOL(elem, str) \
|
#define TRACE_FOR_TEST_BOOL(elem, str) \
|
||||||
PR_BEGIN_MACRO \
|
PR_BEGIN_MACRO \
|
||||||
nsresult rv = NS_OK; \
|
nsresult rv = NS_OK; \
|
||||||
rv = \
|
rv = mozilla::dom::script::TestingDispatchEvent( \
|
||||||
script::TestingDispatchEvent(elem, NS_LITERAL_STRING_FROM_CSTRING(str)); \
|
elem, NS_LITERAL_STRING_FROM_CSTRING(str)); \
|
||||||
NS_ENSURE_SUCCESS(rv, false); \
|
NS_ENSURE_SUCCESS(rv, false); \
|
||||||
PR_END_MACRO
|
PR_END_MACRO
|
||||||
|
|
||||||
#define TRACE_FOR_TEST_NONE(elem, str) \
|
#define TRACE_FOR_TEST_NONE(elem, str) \
|
||||||
PR_BEGIN_MACRO \
|
PR_BEGIN_MACRO \
|
||||||
script::TestingDispatchEvent(elem, NS_LITERAL_STRING_FROM_CSTRING(str)); \
|
mozilla::dom::script::TestingDispatchEvent( \
|
||||||
|
elem, NS_LITERAL_STRING_FROM_CSTRING(str)); \
|
||||||
PR_END_MACRO
|
PR_END_MACRO
|
||||||
|
|
||||||
|
namespace mozilla::dom::script {
|
||||||
|
|
||||||
static nsresult TestingDispatchEvent(nsIScriptElement* aScriptElement,
|
static nsresult TestingDispatchEvent(nsIScriptElement* aScriptElement,
|
||||||
const nsAString& aEventType) {
|
const nsAString& aEventType) {
|
||||||
if (!StaticPrefs::dom_expose_test_interfaces()) {
|
if (!StaticPrefs::dom_expose_test_interfaces()) {
|
||||||
@@ -53,8 +52,6 @@ static nsresult TestingDispatchEvent(nsIScriptElement* aScriptElement,
|
|||||||
target, aEventType, CanBubble::eYes, ChromeOnlyDispatch::eNo);
|
target, aEventType, CanBubble::eYes, ChromeOnlyDispatch::eNo);
|
||||||
return dispatcher->PostDOMEvent();
|
return dispatcher->PostDOMEvent();
|
||||||
}
|
}
|
||||||
} // namespace script
|
} // namespace mozilla::dom::script
|
||||||
} // namespace dom
|
|
||||||
} // namespace mozilla
|
|
||||||
|
|
||||||
#endif // mozilla_dom_ScriptTrace_h
|
#endif // mozilla_dom_ScriptTrace_h
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "js/PropertyAndElement.h"
|
#include "js/PropertyAndElement.h"
|
||||||
#include "js/TypeDecls.h"
|
#include "js/TypeDecls.h"
|
||||||
#include "js/Value.h"
|
#include "js/Value.h"
|
||||||
|
#include "js/loader/ModuleMapKey.h"
|
||||||
#include "mozilla/AlreadyAddRefed.h"
|
#include "mozilla/AlreadyAddRefed.h"
|
||||||
#include "mozilla/Assertions.h"
|
#include "mozilla/Assertions.h"
|
||||||
#include "mozilla/Attributes.h"
|
#include "mozilla/Attributes.h"
|
||||||
@@ -20,7 +21,6 @@
|
|||||||
#include "mozilla/dom/BindingCallContext.h"
|
#include "mozilla/dom/BindingCallContext.h"
|
||||||
#include "mozilla/dom/ByteStreamHelpers.h"
|
#include "mozilla/dom/ByteStreamHelpers.h"
|
||||||
#include "mozilla/dom/BodyStream.h"
|
#include "mozilla/dom/BodyStream.h"
|
||||||
#include "mozilla/dom/ModuleMapKey.h"
|
|
||||||
#include "mozilla/dom/QueueWithSizes.h"
|
#include "mozilla/dom/QueueWithSizes.h"
|
||||||
#include "mozilla/dom/QueuingStrategyBinding.h"
|
#include "mozilla/dom/QueuingStrategyBinding.h"
|
||||||
#include "mozilla/dom/ReadIntoRequest.h"
|
#include "mozilla/dom/ReadIntoRequest.h"
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
#ifndef mozilla_dom_UnderlyingSinkCallbackHelpers_h
|
#ifndef mozilla_dom_UnderlyingSinkCallbackHelpers_h
|
||||||
#define mozilla_dom_UnderlyingSinkCallbackHelpers_h
|
#define mozilla_dom_UnderlyingSinkCallbackHelpers_h
|
||||||
|
|
||||||
|
#include "js/loader/ModuleMapKey.h"
|
||||||
#include "mozilla/HoldDropJSObjects.h"
|
#include "mozilla/HoldDropJSObjects.h"
|
||||||
#include "mozilla/dom/ModuleMapKey.h"
|
|
||||||
#include "mozilla/dom/Promise.h"
|
#include "mozilla/dom/Promise.h"
|
||||||
#include "mozilla/dom/UnderlyingSinkBinding.h"
|
#include "mozilla/dom/UnderlyingSinkBinding.h"
|
||||||
#include "nsISupports.h"
|
#include "nsISupports.h"
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
#ifndef mozilla_dom_UnderlyingSourceCallbackHelpers_h
|
#ifndef mozilla_dom_UnderlyingSourceCallbackHelpers_h
|
||||||
#define mozilla_dom_UnderlyingSourceCallbackHelpers_h
|
#define mozilla_dom_UnderlyingSourceCallbackHelpers_h
|
||||||
|
|
||||||
|
#include "js/loader/ModuleMapKey.h"
|
||||||
#include "mozilla/HoldDropJSObjects.h"
|
#include "mozilla/HoldDropJSObjects.h"
|
||||||
#include "mozilla/dom/ModuleMapKey.h"
|
|
||||||
#include "mozilla/dom/Promise.h"
|
#include "mozilla/dom/Promise.h"
|
||||||
#include "mozilla/dom/UnderlyingSourceBinding.h"
|
#include "mozilla/dom/UnderlyingSourceBinding.h"
|
||||||
#include "nsISupports.h"
|
#include "nsISupports.h"
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "js/PropertyAndElement.h"
|
#include "js/PropertyAndElement.h"
|
||||||
#include "js/TypeDecls.h"
|
#include "js/TypeDecls.h"
|
||||||
#include "js/Value.h"
|
#include "js/Value.h"
|
||||||
|
#include "js/loader/ModuleMapKey.h"
|
||||||
#include "mozilla/AlreadyAddRefed.h"
|
#include "mozilla/AlreadyAddRefed.h"
|
||||||
#include "mozilla/Assertions.h"
|
#include "mozilla/Assertions.h"
|
||||||
#include "mozilla/Attributes.h"
|
#include "mozilla/Attributes.h"
|
||||||
@@ -17,7 +18,6 @@
|
|||||||
#include "mozilla/HoldDropJSObjects.h"
|
#include "mozilla/HoldDropJSObjects.h"
|
||||||
#include "mozilla/dom/AbortSignal.h"
|
#include "mozilla/dom/AbortSignal.h"
|
||||||
#include "mozilla/dom/BindingCallContext.h"
|
#include "mozilla/dom/BindingCallContext.h"
|
||||||
#include "mozilla/dom/ModuleMapKey.h"
|
|
||||||
#include "mozilla/dom/QueueWithSizes.h"
|
#include "mozilla/dom/QueueWithSizes.h"
|
||||||
#include "mozilla/dom/QueuingStrategyBinding.h"
|
#include "mozilla/dom/QueuingStrategyBinding.h"
|
||||||
#include "mozilla/dom/ReadRequest.h"
|
#include "mozilla/dom/ReadRequest.h"
|
||||||
|
|||||||
@@ -12,8 +12,7 @@
|
|||||||
#include "jsfriendapi.h"
|
#include "jsfriendapi.h"
|
||||||
#include "js/Modules.h" // JS::{Get,Set}ModulePrivate
|
#include "js/Modules.h" // JS::{Get,Set}ModulePrivate
|
||||||
|
|
||||||
namespace mozilla {
|
namespace JS::loader {
|
||||||
namespace dom {
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
// LoadedScript
|
// LoadedScript
|
||||||
@@ -41,7 +40,7 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(LoadedScript)
|
|||||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(LoadedScript)
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(LoadedScript)
|
||||||
|
|
||||||
LoadedScript::LoadedScript(ScriptKind aKind, ScriptFetchOptions* aFetchOptions,
|
LoadedScript::LoadedScript(ScriptKind aKind, ScriptFetchOptions* aFetchOptions,
|
||||||
nsIURI* aBaseURL, Element* aElement)
|
nsIURI* aBaseURL, mozilla::dom::Element* aElement)
|
||||||
: mKind(aKind),
|
: mKind(aKind),
|
||||||
mFetchOptions(aFetchOptions),
|
mFetchOptions(aFetchOptions),
|
||||||
mBaseURL(aBaseURL),
|
mBaseURL(aBaseURL),
|
||||||
@@ -50,7 +49,7 @@ LoadedScript::LoadedScript(ScriptKind aKind, ScriptFetchOptions* aFetchOptions,
|
|||||||
MOZ_ASSERT(mBaseURL);
|
MOZ_ASSERT(mBaseURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadedScript::~LoadedScript() { DropJSObjects(this); }
|
LoadedScript::~LoadedScript() { mozilla::DropJSObjects(this); }
|
||||||
|
|
||||||
void LoadedScript::AssociateWithScript(JSScript* aScript) {
|
void LoadedScript::AssociateWithScript(JSScript* aScript) {
|
||||||
// Set a JSScript's private value to point to this object. The JS engine will
|
// Set a JSScript's private value to point to this object. The JS engine will
|
||||||
@@ -96,7 +95,7 @@ void HostReleaseTopLevelScript(const JS::Value& aPrivate) {
|
|||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
EventScript::EventScript(ScriptFetchOptions* aFetchOptions, nsIURI* aBaseURL,
|
EventScript::EventScript(ScriptFetchOptions* aFetchOptions, nsIURI* aBaseURL,
|
||||||
Element* aElement)
|
mozilla::dom::Element* aElement)
|
||||||
: LoadedScript(ScriptKind::eEvent, aFetchOptions, aBaseURL, aElement) {}
|
: LoadedScript(ScriptKind::eEvent, aFetchOptions, aBaseURL, aElement) {}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
@@ -104,7 +103,7 @@ EventScript::EventScript(ScriptFetchOptions* aFetchOptions, nsIURI* aBaseURL,
|
|||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ClassicScript::ClassicScript(ScriptFetchOptions* aFetchOptions,
|
ClassicScript::ClassicScript(ScriptFetchOptions* aFetchOptions,
|
||||||
nsIURI* aBaseURL, Element* aElement)
|
nsIURI* aBaseURL, mozilla::dom::Element* aElement)
|
||||||
: LoadedScript(ScriptKind::eClassic, aFetchOptions, aBaseURL, aElement) {}
|
: LoadedScript(ScriptKind::eClassic, aFetchOptions, aBaseURL, aElement) {}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
@@ -135,7 +134,7 @@ NS_IMPL_ADDREF_INHERITED(ModuleScript, LoadedScript)
|
|||||||
NS_IMPL_RELEASE_INHERITED(ModuleScript, LoadedScript)
|
NS_IMPL_RELEASE_INHERITED(ModuleScript, LoadedScript)
|
||||||
|
|
||||||
ModuleScript::ModuleScript(ScriptFetchOptions* aFetchOptions, nsIURI* aBaseURL,
|
ModuleScript::ModuleScript(ScriptFetchOptions* aFetchOptions, nsIURI* aBaseURL,
|
||||||
Element* aElement)
|
mozilla::dom::Element* aElement)
|
||||||
: LoadedScript(ScriptKind::eModule, aFetchOptions, aBaseURL, aElement),
|
: LoadedScript(ScriptKind::eModule, aFetchOptions, aBaseURL, aElement),
|
||||||
mDebuggerDataInitialized(false) {
|
mDebuggerDataInitialized(false) {
|
||||||
MOZ_ASSERT(!ModuleRecord());
|
MOZ_ASSERT(!ModuleRecord());
|
||||||
@@ -173,7 +172,7 @@ void ModuleScript::SetModuleRecord(JS::Handle<JSObject*> aModuleRecord) {
|
|||||||
MOZ_ASSERT(JS::GetModulePrivate(mModuleRecord).isUndefined());
|
MOZ_ASSERT(JS::GetModulePrivate(mModuleRecord).isUndefined());
|
||||||
JS::SetModulePrivate(mModuleRecord, JS::PrivateValue(this));
|
JS::SetModulePrivate(mModuleRecord, JS::PrivateValue(this));
|
||||||
|
|
||||||
HoldJSObjects(this);
|
mozilla::HoldJSObjects(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModuleScript::SetParseError(const JS::Value& aError) {
|
void ModuleScript::SetParseError(const JS::Value& aError) {
|
||||||
@@ -183,7 +182,7 @@ void ModuleScript::SetParseError(const JS::Value& aError) {
|
|||||||
|
|
||||||
UnlinkModuleRecord();
|
UnlinkModuleRecord();
|
||||||
mParseError = aError;
|
mParseError = aError;
|
||||||
HoldJSObjects(this);
|
mozilla::HoldJSObjects(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModuleScript::SetErrorToRethrow(const JS::Value& aError) {
|
void ModuleScript::SetErrorToRethrow(const JS::Value& aError) {
|
||||||
@@ -203,5 +202,4 @@ void ModuleScript::SetDebuggerDataInitialized() {
|
|||||||
mDebuggerDataInitialized = true;
|
mDebuggerDataInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace JS::loader
|
||||||
} // namespace mozilla
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#ifndef mozilla_dom_LoadedScript_h
|
#ifndef js_loader_LoadedScript_h
|
||||||
#define mozilla_dom_LoadedScript_h
|
#define js_loader_LoadedScript_h
|
||||||
|
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "nsCycleCollectionParticipant.h"
|
#include "nsCycleCollectionParticipant.h"
|
||||||
@@ -14,11 +14,7 @@
|
|||||||
|
|
||||||
class nsIURI;
|
class nsIURI;
|
||||||
|
|
||||||
namespace mozilla {
|
namespace JS::loader {
|
||||||
namespace dom {
|
|
||||||
|
|
||||||
class Element;
|
|
||||||
class ScriptLoader;
|
|
||||||
|
|
||||||
void HostAddRefTopLevelScript(const JS::Value& aPrivate);
|
void HostAddRefTopLevelScript(const JS::Value& aPrivate);
|
||||||
void HostReleaseTopLevelScript(const JS::Value& aPrivate);
|
void HostReleaseTopLevelScript(const JS::Value& aPrivate);
|
||||||
@@ -31,11 +27,11 @@ class LoadedScript : public nsISupports {
|
|||||||
ScriptKind mKind;
|
ScriptKind mKind;
|
||||||
RefPtr<ScriptFetchOptions> mFetchOptions;
|
RefPtr<ScriptFetchOptions> mFetchOptions;
|
||||||
nsCOMPtr<nsIURI> mBaseURL;
|
nsCOMPtr<nsIURI> mBaseURL;
|
||||||
nsCOMPtr<Element> mElement;
|
RefPtr<mozilla::dom::Element> mElement;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
LoadedScript(ScriptKind aKind, ScriptFetchOptions* aFetchOptions,
|
LoadedScript(ScriptKind aKind, ScriptFetchOptions* aFetchOptions,
|
||||||
nsIURI* aBaseURL, Element* aElement);
|
nsIURI* aBaseURL, mozilla::dom::Element* aElement);
|
||||||
|
|
||||||
virtual ~LoadedScript();
|
virtual ~LoadedScript();
|
||||||
|
|
||||||
@@ -54,7 +50,7 @@ class LoadedScript : public nsISupports {
|
|||||||
ScriptFetchOptions* GetFetchOptions() const { return mFetchOptions; }
|
ScriptFetchOptions* GetFetchOptions() const { return mFetchOptions; }
|
||||||
|
|
||||||
// Used by the Debugger to get the associated Script Element
|
// Used by the Debugger to get the associated Script Element
|
||||||
Element* GetScriptElement() const { return mElement; }
|
mozilla::dom::Element* GetScriptElement() const { return mElement; }
|
||||||
|
|
||||||
nsIURI* BaseURL() const { return mBaseURL; }
|
nsIURI* BaseURL() const { return mBaseURL; }
|
||||||
|
|
||||||
@@ -66,7 +62,7 @@ class ClassicScript final : public LoadedScript {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
ClassicScript(ScriptFetchOptions* aFetchOptions, nsIURI* aBaseURL,
|
ClassicScript(ScriptFetchOptions* aFetchOptions, nsIURI* aBaseURL,
|
||||||
Element* aElement);
|
mozilla::dom::Element* aElement);
|
||||||
};
|
};
|
||||||
|
|
||||||
class EventScript final : public LoadedScript {
|
class EventScript final : public LoadedScript {
|
||||||
@@ -74,7 +70,7 @@ class EventScript final : public LoadedScript {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
EventScript(ScriptFetchOptions* aFetchOptions, nsIURI* aBaseURL,
|
EventScript(ScriptFetchOptions* aFetchOptions, nsIURI* aBaseURL,
|
||||||
Element* aElement);
|
mozilla::dom::Element* aElement);
|
||||||
};
|
};
|
||||||
|
|
||||||
// A single module script. May be used to satisfy multiple load requests.
|
// A single module script. May be used to satisfy multiple load requests.
|
||||||
@@ -93,7 +89,7 @@ class ModuleScript final : public LoadedScript {
|
|||||||
LoadedScript)
|
LoadedScript)
|
||||||
|
|
||||||
ModuleScript(ScriptFetchOptions* aFetchOptions, nsIURI* aBaseURL,
|
ModuleScript(ScriptFetchOptions* aFetchOptions, nsIURI* aBaseURL,
|
||||||
Element* aElement);
|
mozilla::dom::Element* aElement);
|
||||||
|
|
||||||
void SetModuleRecord(JS::Handle<JSObject*> aModuleRecord);
|
void SetModuleRecord(JS::Handle<JSObject*> aModuleRecord);
|
||||||
void SetParseError(const JS::Value& aError);
|
void SetParseError(const JS::Value& aError);
|
||||||
@@ -123,7 +119,6 @@ ModuleScript* LoadedScript::AsModuleScript() {
|
|||||||
return static_cast<ModuleScript*>(this);
|
return static_cast<ModuleScript*>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace JS::loader
|
||||||
} // namespace mozilla
|
|
||||||
|
|
||||||
#endif // mozilla_dom_LoadedScript_h
|
#endif // js_loader_LoadedScript_h
|
||||||
|
|||||||
@@ -11,8 +11,7 @@
|
|||||||
#include "LoadedScript.h"
|
#include "LoadedScript.h"
|
||||||
#include "ModuleLoaderBase.h"
|
#include "ModuleLoaderBase.h"
|
||||||
|
|
||||||
namespace mozilla {
|
namespace JS::loader {
|
||||||
namespace dom {
|
|
||||||
|
|
||||||
#undef LOG
|
#undef LOG
|
||||||
#define LOG(args) \
|
#define LOG(args) \
|
||||||
@@ -55,10 +54,10 @@ VisitedURLSet* ModuleLoadRequest::NewVisitedSetForTopLevelImport(nsIURI* aURI) {
|
|||||||
|
|
||||||
ModuleLoadRequest::ModuleLoadRequest(
|
ModuleLoadRequest::ModuleLoadRequest(
|
||||||
nsIURI* aURI, ScriptFetchOptions* aFetchOptions,
|
nsIURI* aURI, ScriptFetchOptions* aFetchOptions,
|
||||||
const SRIMetadata& aIntegrity, nsIURI* aReferrer,
|
const mozilla::dom::SRIMetadata& aIntegrity, nsIURI* aReferrer,
|
||||||
ScriptLoadContext* aContext, bool aIsTopLevel, bool aIsDynamicImport,
|
mozilla::dom::ScriptLoadContext* aContext, bool aIsTopLevel,
|
||||||
ModuleLoaderBase* aLoader, VisitedURLSet* aVisitedSet,
|
bool aIsDynamicImport, ModuleLoaderBase* aLoader,
|
||||||
ModuleLoadRequest* aRootModule)
|
VisitedURLSet* aVisitedSet, ModuleLoadRequest* aRootModule)
|
||||||
: ScriptLoadRequest(ScriptKind::eModule, aURI, aFetchOptions, aIntegrity,
|
: ScriptLoadRequest(ScriptKind::eModule, aURI, aFetchOptions, aIntegrity,
|
||||||
aReferrer, aContext),
|
aReferrer, aContext),
|
||||||
mIsTopLevel(aIsTopLevel),
|
mIsTopLevel(aIsTopLevel),
|
||||||
@@ -192,5 +191,4 @@ void ModuleLoadRequest::ClearDynamicImport() {
|
|||||||
mDynamicPromise = nullptr;
|
mDynamicPromise = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace JS::loader
|
||||||
} // namespace mozilla
|
|
||||||
|
|||||||
@@ -4,18 +4,18 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#ifndef mozilla_dom_ModuleLoadRequest_h
|
#ifndef js_loader_ModuleLoadRequest_h
|
||||||
#define mozilla_dom_ModuleLoadRequest_h
|
#define js_loader_ModuleLoadRequest_h
|
||||||
|
|
||||||
#include "ScriptLoadRequest.h"
|
#include "ScriptLoadRequest.h"
|
||||||
|
#include "ModuleLoaderBase.h"
|
||||||
#include "mozilla/MozPromise.h"
|
#include "mozilla/MozPromise.h"
|
||||||
#include "js/RootingAPI.h"
|
#include "js/RootingAPI.h"
|
||||||
#include "js/Value.h"
|
#include "js/Value.h"
|
||||||
#include "nsURIHashKey.h"
|
#include "nsURIHashKey.h"
|
||||||
#include "nsTHashtable.h"
|
#include "nsTHashtable.h"
|
||||||
|
|
||||||
namespace mozilla {
|
namespace JS::loader {
|
||||||
namespace dom {
|
|
||||||
|
|
||||||
class ModuleScript;
|
class ModuleScript;
|
||||||
class ModuleLoaderBase;
|
class ModuleLoaderBase;
|
||||||
@@ -43,10 +43,15 @@ class ModuleLoadRequest final : public ScriptLoadRequest {
|
|||||||
NS_DECL_ISUPPORTS_INHERITED
|
NS_DECL_ISUPPORTS_INHERITED
|
||||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(ModuleLoadRequest,
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(ModuleLoadRequest,
|
||||||
ScriptLoadRequest)
|
ScriptLoadRequest)
|
||||||
|
using SRIMetadata = mozilla::dom::SRIMetadata;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using MozPromiseHolder = mozilla::MozPromiseHolder<T>;
|
||||||
|
using GenericPromise = mozilla::GenericPromise;
|
||||||
|
|
||||||
ModuleLoadRequest(nsIURI* aURI, ScriptFetchOptions* aFetchOptions,
|
ModuleLoadRequest(nsIURI* aURI, ScriptFetchOptions* aFetchOptions,
|
||||||
const SRIMetadata& aIntegrity, nsIURI* aReferrer,
|
const SRIMetadata& aIntegrity, nsIURI* aReferrer,
|
||||||
ScriptLoadContext* aContext, bool aIsTopLevel,
|
mozilla::dom::ScriptLoadContext* aContext, bool aIsTopLevel,
|
||||||
bool aIsDynamicImport, ModuleLoaderBase* aLoader,
|
bool aIsDynamicImport, ModuleLoaderBase* aLoader,
|
||||||
VisitedURLSet* aVisitedSet, ModuleLoadRequest* aRootModule);
|
VisitedURLSet* aVisitedSet, ModuleLoadRequest* aRootModule);
|
||||||
|
|
||||||
@@ -114,7 +119,6 @@ class ModuleLoadRequest final : public ScriptLoadRequest {
|
|||||||
JS::Heap<JSObject*> mDynamicPromise;
|
JS::Heap<JSObject*> mDynamicPromise;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace JS::loader
|
||||||
} // namespace mozilla
|
|
||||||
|
|
||||||
#endif // mozilla_dom_ModuleLoadRequest_h
|
#endif // js_loader_ModuleLoadRequest_h
|
||||||
|
|||||||
@@ -6,9 +6,9 @@
|
|||||||
|
|
||||||
#include "GeckoProfiler.h"
|
#include "GeckoProfiler.h"
|
||||||
#include "LoadedScript.h"
|
#include "LoadedScript.h"
|
||||||
|
#include "ModuleLoadRequest.h"
|
||||||
#include "ScriptLoadRequest.h"
|
#include "ScriptLoadRequest.h"
|
||||||
#include "mozilla/dom/ScriptTrace.h"
|
#include "mozilla/dom/ScriptTrace.h"
|
||||||
#include "ModuleLoadRequest.h"
|
|
||||||
|
|
||||||
#include "js/Array.h" // JS::GetArrayLength
|
#include "js/Array.h" // JS::GetArrayLength
|
||||||
#include "js/CompilationAndEvaluation.h"
|
#include "js/CompilationAndEvaluation.h"
|
||||||
@@ -26,10 +26,11 @@
|
|||||||
|
|
||||||
using JS::SourceText;
|
using JS::SourceText;
|
||||||
|
|
||||||
namespace mozilla::dom {
|
namespace JS::loader {
|
||||||
|
|
||||||
LazyLogModule ModuleLoaderBase::gCspPRLog("CSP");
|
mozilla::LazyLogModule ModuleLoaderBase::gCspPRLog("CSP");
|
||||||
LazyLogModule ModuleLoaderBase::gModuleLoaderBaseLog("ModuleLoaderBase");
|
mozilla::LazyLogModule ModuleLoaderBase::gModuleLoaderBaseLog(
|
||||||
|
"ModuleLoaderBase");
|
||||||
|
|
||||||
#undef LOG
|
#undef LOG
|
||||||
#define LOG(args) \
|
#define LOG(args) \
|
||||||
@@ -49,7 +50,8 @@ inline void ImplCycleCollectionUnlink(
|
|||||||
for (auto iter = aField.Iter(); !iter.Done(); iter.Next()) {
|
for (auto iter = aField.Iter(); !iter.Done(); iter.Next()) {
|
||||||
ImplCycleCollectionUnlink(iter.Key());
|
ImplCycleCollectionUnlink(iter.Key());
|
||||||
|
|
||||||
RefPtr<GenericNonExclusivePromise::Private> promise = iter.UserData();
|
RefPtr<mozilla::GenericNonExclusivePromise::Private> promise =
|
||||||
|
iter.UserData();
|
||||||
if (promise) {
|
if (promise) {
|
||||||
promise->Reject(NS_ERROR_ABORT, __func__);
|
promise->Reject(NS_ERROR_ABORT, __func__);
|
||||||
}
|
}
|
||||||
@@ -119,7 +121,7 @@ void ModuleLoaderBase::SetModuleFetchStarted(ModuleLoadRequest* aRequest) {
|
|||||||
aRequest->mLoadContext->GetWebExtGlobal()));
|
aRequest->mLoadContext->GetWebExtGlobal()));
|
||||||
ModuleMapKey key(aRequest->mURI, aRequest->mLoadContext->GetWebExtGlobal());
|
ModuleMapKey key(aRequest->mURI, aRequest->mLoadContext->GetWebExtGlobal());
|
||||||
mFetchingModules.InsertOrUpdate(
|
mFetchingModules.InsertOrUpdate(
|
||||||
key, RefPtr<GenericNonExclusivePromise::Private>{});
|
key, RefPtr<mozilla::GenericNonExclusivePromise::Private>{});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModuleLoaderBase::SetModuleFetchFinishedAndResumeWaitingRequests(
|
void ModuleLoaderBase::SetModuleFetchFinishedAndResumeWaitingRequests(
|
||||||
@@ -136,7 +138,7 @@ void ModuleLoaderBase::SetModuleFetchFinishedAndResumeWaitingRequests(
|
|||||||
aRequest, aRequest->mModuleScript.get(), unsigned(aResult)));
|
aRequest, aRequest->mModuleScript.get(), unsigned(aResult)));
|
||||||
|
|
||||||
ModuleMapKey key(aRequest->mURI, aRequest->mLoadContext->GetWebExtGlobal());
|
ModuleMapKey key(aRequest->mURI, aRequest->mLoadContext->GetWebExtGlobal());
|
||||||
RefPtr<GenericNonExclusivePromise::Private> promise;
|
RefPtr<mozilla::GenericNonExclusivePromise::Private> promise;
|
||||||
if (!mFetchingModules.Remove(key, getter_AddRefs(promise))) {
|
if (!mFetchingModules.Remove(key, getter_AddRefs(promise))) {
|
||||||
LOG(
|
LOG(
|
||||||
("ScriptLoadRequest (%p): Key not found in mFetchingModules, "
|
("ScriptLoadRequest (%p): Key not found in mFetchingModules, "
|
||||||
@@ -161,14 +163,14 @@ void ModuleLoaderBase::SetModuleFetchFinishedAndResumeWaitingRequests(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<GenericNonExclusivePromise> ModuleLoaderBase::WaitForModuleFetch(
|
RefPtr<mozilla::GenericNonExclusivePromise>
|
||||||
nsIURI* aURL, nsIGlobalObject* aGlobal) {
|
ModuleLoaderBase::WaitForModuleFetch(nsIURI* aURL, nsIGlobalObject* aGlobal) {
|
||||||
MOZ_ASSERT(ModuleMapContainsURL(aURL, aGlobal));
|
MOZ_ASSERT(ModuleMapContainsURL(aURL, aGlobal));
|
||||||
|
|
||||||
ModuleMapKey key(aURL, aGlobal);
|
ModuleMapKey key(aURL, aGlobal);
|
||||||
if (auto entry = mFetchingModules.Lookup(key)) {
|
if (auto entry = mFetchingModules.Lookup(key)) {
|
||||||
if (!entry.Data()) {
|
if (!entry.Data()) {
|
||||||
entry.Data() = new GenericNonExclusivePromise::Private(__func__);
|
entry.Data() = new mozilla::GenericNonExclusivePromise::Private(__func__);
|
||||||
}
|
}
|
||||||
return entry.Data();
|
return entry.Data();
|
||||||
}
|
}
|
||||||
@@ -176,11 +178,11 @@ RefPtr<GenericNonExclusivePromise> ModuleLoaderBase::WaitForModuleFetch(
|
|||||||
RefPtr<ModuleScript> ms;
|
RefPtr<ModuleScript> ms;
|
||||||
MOZ_ALWAYS_TRUE(mFetchedModules.Get(key, getter_AddRefs(ms)));
|
MOZ_ALWAYS_TRUE(mFetchedModules.Get(key, getter_AddRefs(ms)));
|
||||||
if (!ms) {
|
if (!ms) {
|
||||||
return GenericNonExclusivePromise::CreateAndReject(NS_ERROR_FAILURE,
|
return mozilla::GenericNonExclusivePromise::CreateAndReject(
|
||||||
__func__);
|
NS_ERROR_FAILURE, __func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
return GenericNonExclusivePromise::CreateAndResolve(true, __func__);
|
return mozilla::GenericNonExclusivePromise::CreateAndResolve(true, __func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
ModuleScript* ModuleLoaderBase::GetFetchedModule(
|
ModuleScript* ModuleLoaderBase::GetFetchedModule(
|
||||||
@@ -233,11 +235,11 @@ nsresult ModuleLoaderBase::CreateModuleScript(ModuleLoadRequest* aRequest) {
|
|||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoMicroTask mt;
|
mozilla::nsAutoMicroTask mt;
|
||||||
|
|
||||||
AutoAllowLegacyScriptExecution exemption;
|
mozilla::AutoAllowLegacyScriptExecution exemption;
|
||||||
|
|
||||||
AutoEntryScript aes(globalObject, "CompileModule", true);
|
mozilla::dom::AutoEntryScript aes(globalObject, "CompileModule", true);
|
||||||
|
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
{
|
{
|
||||||
@@ -391,7 +393,7 @@ nsresult ModuleLoaderBase::ResolveRequestedModules(
|
|||||||
ModuleLoadRequest* aRequest, nsCOMArray<nsIURI>* aUrlsOut) {
|
ModuleLoadRequest* aRequest, nsCOMArray<nsIURI>* aUrlsOut) {
|
||||||
ModuleScript* ms = aRequest->mModuleScript;
|
ModuleScript* ms = aRequest->mModuleScript;
|
||||||
|
|
||||||
AutoJSAPI jsapi;
|
mozilla::dom::AutoJSAPI jsapi;
|
||||||
if (!jsapi.Init(ms->ModuleRecord())) {
|
if (!jsapi.Init(ms->ModuleRecord())) {
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
@@ -494,23 +496,25 @@ void ModuleLoaderBase::StartFetchingModuleDependencies(
|
|||||||
|
|
||||||
// For each url in urls, fetch a module script tree given url, module script's
|
// For each url in urls, fetch a module script tree given url, module script's
|
||||||
// CORS setting, and module script's settings object.
|
// CORS setting, and module script's settings object.
|
||||||
nsTArray<RefPtr<GenericPromise>> importsReady;
|
nsTArray<RefPtr<mozilla::GenericPromise>> importsReady;
|
||||||
for (auto* url : urls) {
|
for (auto* url : urls) {
|
||||||
RefPtr<GenericPromise> childReady =
|
RefPtr<mozilla::GenericPromise> childReady =
|
||||||
StartFetchingModuleAndDependencies(aRequest, url);
|
StartFetchingModuleAndDependencies(aRequest, url);
|
||||||
importsReady.AppendElement(childReady);
|
importsReady.AppendElement(childReady);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for all imports to become ready.
|
// Wait for all imports to become ready.
|
||||||
RefPtr<GenericPromise::AllPromiseType> allReady =
|
RefPtr<mozilla::GenericPromise::AllPromiseType> allReady =
|
||||||
GenericPromise::All(GetMainThreadSerialEventTarget(), importsReady);
|
mozilla::GenericPromise::All(mozilla::GetMainThreadSerialEventTarget(),
|
||||||
allReady->Then(GetMainThreadSerialEventTarget(), __func__, aRequest,
|
importsReady);
|
||||||
|
allReady->Then(mozilla::GetMainThreadSerialEventTarget(), __func__, aRequest,
|
||||||
&ModuleLoadRequest::DependenciesLoaded,
|
&ModuleLoadRequest::DependenciesLoaded,
|
||||||
&ModuleLoadRequest::ModuleErrored);
|
&ModuleLoadRequest::ModuleErrored);
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<GenericPromise> ModuleLoaderBase::StartFetchingModuleAndDependencies(
|
RefPtr<mozilla::GenericPromise>
|
||||||
ModuleLoadRequest* aParent, nsIURI* aURI) {
|
ModuleLoaderBase::StartFetchingModuleAndDependencies(ModuleLoadRequest* aParent,
|
||||||
|
nsIURI* aURI) {
|
||||||
MOZ_ASSERT(aURI);
|
MOZ_ASSERT(aURI);
|
||||||
|
|
||||||
RefPtr<ModuleLoadRequest> childRequest = CreateStaticImport(aURI, aParent);
|
RefPtr<ModuleLoadRequest> childRequest = CreateStaticImport(aURI, aParent);
|
||||||
@@ -530,7 +534,7 @@ RefPtr<GenericPromise> ModuleLoaderBase::StartFetchingModuleAndDependencies(
|
|||||||
url2.get()));
|
url2.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<GenericPromise> ready = childRequest->mReady.Ensure(__func__);
|
RefPtr<mozilla::GenericPromise> ready = childRequest->mReady.Ensure(__func__);
|
||||||
|
|
||||||
nsresult rv = StartModuleLoad(childRequest);
|
nsresult rv = StartModuleLoad(childRequest);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
@@ -560,7 +564,7 @@ void ModuleLoaderBase::StartDynamicImport(ModuleLoadRequest* aRequest) {
|
|||||||
|
|
||||||
void ModuleLoaderBase::FinishDynamicImportAndReject(ModuleLoadRequest* aRequest,
|
void ModuleLoaderBase::FinishDynamicImportAndReject(ModuleLoadRequest* aRequest,
|
||||||
nsresult aResult) {
|
nsresult aResult) {
|
||||||
AutoJSAPI jsapi;
|
mozilla::dom::AutoJSAPI jsapi;
|
||||||
MOZ_ASSERT(NS_FAILED(aResult));
|
MOZ_ASSERT(NS_FAILED(aResult));
|
||||||
MOZ_ALWAYS_TRUE(jsapi.Init(aRequest->mDynamicPromise));
|
MOZ_ALWAYS_TRUE(jsapi.Init(aRequest->mDynamicPromise));
|
||||||
FinishDynamicImport(jsapi.cx(), aRequest, aResult, nullptr);
|
FinishDynamicImport(jsapi.cx(), aRequest, aResult, nullptr);
|
||||||
@@ -652,8 +656,8 @@ bool ModuleLoaderBase::InstantiateModuleTree(ModuleLoadRequest* aRequest) {
|
|||||||
|
|
||||||
MOZ_ASSERT(moduleScript->ModuleRecord());
|
MOZ_ASSERT(moduleScript->ModuleRecord());
|
||||||
|
|
||||||
nsAutoMicroTask mt;
|
mozilla::nsAutoMicroTask mt;
|
||||||
AutoJSAPI jsapi;
|
mozilla::dom::AutoJSAPI jsapi;
|
||||||
if (NS_WARN_IF(!jsapi.Init(moduleScript->ModuleRecord()))) {
|
if (NS_WARN_IF(!jsapi.Init(moduleScript->ModuleRecord()))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -724,8 +728,8 @@ void ModuleLoaderBase::ProcessDynamicImport(ModuleLoadRequest* aRequest) {
|
|||||||
|
|
||||||
nsresult ModuleLoaderBase::EvaluateModule(nsIGlobalObject* aGlobalObject,
|
nsresult ModuleLoaderBase::EvaluateModule(nsIGlobalObject* aGlobalObject,
|
||||||
ScriptLoadRequest* aRequest) {
|
ScriptLoadRequest* aRequest) {
|
||||||
nsAutoMicroTask mt;
|
mozilla::nsAutoMicroTask mt;
|
||||||
AutoEntryScript aes(aGlobalObject, "EvaluateModule", true);
|
mozilla::dom::AutoEntryScript aes(aGlobalObject, "EvaluateModule", true);
|
||||||
JSContext* cx = aes.cx();
|
JSContext* cx = aes.cx();
|
||||||
|
|
||||||
nsAutoCString profilerLabelString;
|
nsAutoCString profilerLabelString;
|
||||||
@@ -843,4 +847,4 @@ void ModuleLoaderBase::CancelAndClearDynamicImports() {
|
|||||||
#undef LOG
|
#undef LOG
|
||||||
#undef LOG_ENABLED
|
#undef LOG_ENABLED
|
||||||
|
|
||||||
} // namespace mozilla::dom
|
} // namespace JS::loader
|
||||||
|
|||||||
@@ -4,8 +4,11 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#ifndef mozilla_dom_ModuleLoaderBase_h
|
#ifndef js_loader_ModuleLoaderBase_h
|
||||||
#define mozilla_dom_ModuleLoaderBase_h
|
#define js_loader_ModuleLoaderBase_h
|
||||||
|
|
||||||
|
#include "LoadedScript.h"
|
||||||
|
#include "ScriptLoadRequest.h"
|
||||||
|
|
||||||
#include "js/TypeDecls.h" // JS::MutableHandle, JS::Handle, JS::Root
|
#include "js/TypeDecls.h" // JS::MutableHandle, JS::Handle, JS::Root
|
||||||
#include "nsRefPtrHashtable.h"
|
#include "nsRefPtrHashtable.h"
|
||||||
@@ -15,15 +18,20 @@
|
|||||||
#include "nsINode.h" // nsIURI
|
#include "nsINode.h" // nsIURI
|
||||||
#include "nsURIHashKey.h"
|
#include "nsURIHashKey.h"
|
||||||
#include "mozilla/CORSMode.h"
|
#include "mozilla/CORSMode.h"
|
||||||
#include "mozilla/dom/LoadedScript.h"
|
|
||||||
#include "mozilla/dom/JSExecutionContext.h"
|
#include "mozilla/dom/JSExecutionContext.h"
|
||||||
#include "mozilla/dom/ScriptLoadRequest.h"
|
|
||||||
#include "mozilla/MaybeOneOf.h"
|
#include "mozilla/MaybeOneOf.h"
|
||||||
#include "mozilla/MozPromise.h"
|
#include "mozilla/MozPromise.h"
|
||||||
#include "ModuleMapKey.h"
|
#include "ModuleMapKey.h"
|
||||||
|
|
||||||
class nsIURI;
|
class nsIURI;
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
|
||||||
|
class LazyLogModule;
|
||||||
|
union Utf8Unit;
|
||||||
|
|
||||||
|
} // namespace mozilla
|
||||||
|
|
||||||
namespace JS {
|
namespace JS {
|
||||||
|
|
||||||
class CompileOptions;
|
class CompileOptions;
|
||||||
@@ -31,14 +39,7 @@ class CompileOptions;
|
|||||||
template <typename UnitT>
|
template <typename UnitT>
|
||||||
class SourceText;
|
class SourceText;
|
||||||
|
|
||||||
} // namespace JS
|
namespace loader {
|
||||||
|
|
||||||
namespace mozilla {
|
|
||||||
|
|
||||||
class LazyLogModule;
|
|
||||||
union Utf8Unit;
|
|
||||||
|
|
||||||
namespace dom {
|
|
||||||
|
|
||||||
class ModuleLoaderBase;
|
class ModuleLoaderBase;
|
||||||
class ModuleLoadRequest;
|
class ModuleLoadRequest;
|
||||||
@@ -46,6 +47,13 @@ class ModuleScript;
|
|||||||
|
|
||||||
class ScriptLoaderInterface : public nsISupports {
|
class ScriptLoaderInterface : public nsISupports {
|
||||||
public:
|
public:
|
||||||
|
// alias common classes
|
||||||
|
using ScriptFetchOptions = JS::loader::ScriptFetchOptions;
|
||||||
|
using ScriptKind = JS::loader::ScriptKind;
|
||||||
|
using ScriptLoadRequest = JS::loader::ScriptLoadRequest;
|
||||||
|
using ScriptLoadRequestList = JS::loader::ScriptLoadRequestList;
|
||||||
|
using ModuleLoadRequest = JS::loader::ModuleLoadRequest;
|
||||||
|
|
||||||
// In some environments, we will need to default to a base URI
|
// In some environments, we will need to default to a base URI
|
||||||
virtual nsIURI* GetBaseURI() const = 0;
|
virtual nsIURI* GetBaseURI() const = 0;
|
||||||
|
|
||||||
@@ -66,8 +74,10 @@ class ScriptLoaderInterface : public nsISupports {
|
|||||||
|
|
||||||
class ModuleLoaderBase : public nsISupports {
|
class ModuleLoaderBase : public nsISupports {
|
||||||
private:
|
private:
|
||||||
|
using GenericNonExclusivePromise = mozilla::GenericNonExclusivePromise;
|
||||||
|
using GenericPromise = mozilla::GenericPromise;
|
||||||
// Module map
|
// Module map
|
||||||
nsRefPtrHashtable<ModuleMapKey, mozilla::GenericNonExclusivePromise::Private>
|
nsRefPtrHashtable<ModuleMapKey, GenericNonExclusivePromise::Private>
|
||||||
mFetchingModules;
|
mFetchingModules;
|
||||||
nsRefPtrHashtable<ModuleMapKey, ModuleScript> mFetchedModules;
|
nsRefPtrHashtable<ModuleMapKey, ModuleScript> mFetchedModules;
|
||||||
|
|
||||||
@@ -80,6 +90,9 @@ class ModuleLoaderBase : public nsISupports {
|
|||||||
NS_DECL_CYCLE_COLLECTION_CLASS(ModuleLoaderBase)
|
NS_DECL_CYCLE_COLLECTION_CLASS(ModuleLoaderBase)
|
||||||
explicit ModuleLoaderBase(ScriptLoaderInterface* aLoader);
|
explicit ModuleLoaderBase(ScriptLoaderInterface* aLoader);
|
||||||
|
|
||||||
|
using ScriptFetchOptions = JS::loader::ScriptFetchOptions;
|
||||||
|
using ScriptLoadRequest = JS::loader::ScriptLoadRequest;
|
||||||
|
using ModuleLoadRequest = JS::loader::ModuleLoadRequest;
|
||||||
ScriptLoadRequestList mDynamicImportRequests;
|
ScriptLoadRequestList mDynamicImportRequests;
|
||||||
|
|
||||||
using MaybeSourceText =
|
using MaybeSourceText =
|
||||||
@@ -112,7 +125,7 @@ class ModuleLoaderBase : public nsISupports {
|
|||||||
ModuleLoadRequest* aRequest, nsresult aResult);
|
ModuleLoadRequest* aRequest, nsresult aResult);
|
||||||
|
|
||||||
bool ModuleMapContainsURL(nsIURI* aURL, nsIGlobalObject* aGlobal) const;
|
bool ModuleMapContainsURL(nsIURI* aURL, nsIGlobalObject* aGlobal) const;
|
||||||
RefPtr<mozilla::GenericNonExclusivePromise> WaitForModuleFetch(
|
RefPtr<GenericNonExclusivePromise> WaitForModuleFetch(
|
||||||
nsIURI* aURL, nsIGlobalObject* aGlobal);
|
nsIURI* aURL, nsIGlobalObject* aGlobal);
|
||||||
ModuleScript* GetFetchedModule(nsIURI* aURL, nsIGlobalObject* aGlobal) const;
|
ModuleScript* GetFetchedModule(nsIURI* aURL, nsIGlobalObject* aGlobal) const;
|
||||||
|
|
||||||
@@ -134,7 +147,7 @@ class ModuleLoaderBase : public nsISupports {
|
|||||||
|
|
||||||
void StartFetchingModuleDependencies(ModuleLoadRequest* aRequest);
|
void StartFetchingModuleDependencies(ModuleLoadRequest* aRequest);
|
||||||
|
|
||||||
RefPtr<mozilla::GenericPromise> StartFetchingModuleAndDependencies(
|
RefPtr<GenericPromise> StartFetchingModuleAndDependencies(
|
||||||
ModuleLoadRequest* aParent, nsIURI* aURI);
|
ModuleLoadRequest* aParent, nsIURI* aURI);
|
||||||
|
|
||||||
void StartDynamicImport(ModuleLoadRequest* aRequest);
|
void StartDynamicImport(ModuleLoadRequest* aRequest);
|
||||||
@@ -182,11 +195,11 @@ class ModuleLoaderBase : public nsISupports {
|
|||||||
void CancelAndClearDynamicImports();
|
void CancelAndClearDynamicImports();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static LazyLogModule gCspPRLog;
|
static mozilla::LazyLogModule gCspPRLog;
|
||||||
static LazyLogModule gModuleLoaderBaseLog;
|
static mozilla::LazyLogModule gModuleLoaderBaseLog;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace loader
|
||||||
} // namespace mozilla
|
} // namespace JS
|
||||||
|
|
||||||
#endif // mozilla_dom_ModuleLoaderBase_h
|
#endif // js_loader_ModuleLoaderBase_h
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include "ModuleMapKey.h"
|
#include "ModuleMapKey.h"
|
||||||
|
|
||||||
using namespace mozilla::dom;
|
using namespace JS::loader;
|
||||||
|
|
||||||
ModuleMapKey::ModuleMapKey(const nsIURI* aURI, nsIGlobalObject* aWebExtGlobal)
|
ModuleMapKey::ModuleMapKey(const nsIURI* aURI, nsIGlobalObject* aWebExtGlobal)
|
||||||
: nsURIHashKey(aURI), mWebExtGlobal(aWebExtGlobal) {}
|
: nsURIHashKey(aURI), mWebExtGlobal(aWebExtGlobal) {}
|
||||||
@@ -32,7 +32,7 @@ bool ModuleMapKey::KeyEquals(KeyTypePointer aOther) const {
|
|||||||
PLDHashNumber ModuleMapKey::HashKey(KeyTypePointer aKey) {
|
PLDHashNumber ModuleMapKey::HashKey(KeyTypePointer aKey) {
|
||||||
PLDHashNumber hash = nsURIHashKey::HashKey(aKey->mKey);
|
PLDHashNumber hash = nsURIHashKey::HashKey(aKey->mKey);
|
||||||
// XXX This seems wrong.
|
// XXX This seems wrong.
|
||||||
hash =
|
hash = mozilla::AddToHash(
|
||||||
AddToHash(hash, reinterpret_cast<uintptr_t>(aKey->mWebExtGlobal.get()));
|
hash, reinterpret_cast<uintptr_t>(aKey->mWebExtGlobal.get()));
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#include "nsURIHashKey.h"
|
#include "nsURIHashKey.h"
|
||||||
#include "nsIGlobalObject.h"
|
#include "nsIGlobalObject.h"
|
||||||
|
|
||||||
namespace mozilla::dom {
|
namespace JS::loader {
|
||||||
|
|
||||||
class ModuleMapKey : public nsURIHashKey {
|
class ModuleMapKey : public nsURIHashKey {
|
||||||
public:
|
public:
|
||||||
@@ -42,6 +42,6 @@ inline void ImplCycleCollectionTraverse(
|
|||||||
ImplCycleCollectionTraverse(aCallback, aField.mWebExtGlobal, aName, aFlags);
|
ImplCycleCollectionTraverse(aCallback, aField.mWebExtGlobal, aName, aFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace mozilla::dom
|
} // namespace JS::loader
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -4,15 +4,13 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#ifndef mozilla_dom_ScriptKind_h
|
#ifndef js_loader_ScriptKind_h
|
||||||
#define mozilla_dom_ScriptKind_h
|
#define js_loader_ScriptKind_h
|
||||||
|
|
||||||
namespace mozilla {
|
namespace JS::loader {
|
||||||
namespace dom {
|
|
||||||
|
|
||||||
enum class ScriptKind { eClassic, eModule, eEvent };
|
enum class ScriptKind { eClassic, eModule, eEvent };
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace JS::loader
|
||||||
} // namespace mozilla
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -5,10 +5,11 @@
|
|||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#include "ScriptLoadRequest.h"
|
#include "ScriptLoadRequest.h"
|
||||||
#include "mozilla/dom/ScriptLoadContext.h"
|
|
||||||
#include "GeckoProfiler.h"
|
#include "GeckoProfiler.h"
|
||||||
|
|
||||||
#include "mozilla/dom/Document.h"
|
#include "mozilla/dom/Document.h"
|
||||||
|
#include "mozilla/dom/ScriptLoadContext.h"
|
||||||
|
#include "mozilla/dom/ScriptSettings.h"
|
||||||
#include "mozilla/HoldDropJSObjects.h"
|
#include "mozilla/HoldDropJSObjects.h"
|
||||||
#include "mozilla/StaticPrefs_dom.h"
|
#include "mozilla/StaticPrefs_dom.h"
|
||||||
#include "mozilla/Unused.h"
|
#include "mozilla/Unused.h"
|
||||||
@@ -22,13 +23,10 @@
|
|||||||
#include "nsICacheInfoChannel.h"
|
#include "nsICacheInfoChannel.h"
|
||||||
#include "nsIClassOfService.h"
|
#include "nsIClassOfService.h"
|
||||||
#include "nsISupportsPriority.h"
|
#include "nsISupportsPriority.h"
|
||||||
#include "ScriptLoadRequest.h"
|
|
||||||
#include "mozilla/dom/ScriptSettings.h"
|
|
||||||
|
|
||||||
using JS::SourceText;
|
using JS::SourceText;
|
||||||
|
|
||||||
namespace mozilla {
|
namespace JS::loader {
|
||||||
namespace dom {
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
// ScriptFetchOptions
|
// ScriptFetchOptions
|
||||||
@@ -39,9 +37,9 @@ NS_IMPL_CYCLE_COLLECTION(ScriptFetchOptions, mTriggeringPrincipal)
|
|||||||
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(ScriptFetchOptions, AddRef)
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(ScriptFetchOptions, AddRef)
|
||||||
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(ScriptFetchOptions, Release)
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(ScriptFetchOptions, Release)
|
||||||
|
|
||||||
ScriptFetchOptions::ScriptFetchOptions(mozilla::CORSMode aCORSMode,
|
ScriptFetchOptions::ScriptFetchOptions(
|
||||||
ReferrerPolicy aReferrerPolicy,
|
mozilla::CORSMode aCORSMode, mozilla::dom::ReferrerPolicy aReferrerPolicy,
|
||||||
nsIPrincipal* aTriggeringPrincipal)
|
nsIPrincipal* aTriggeringPrincipal)
|
||||||
: mCORSMode(aCORSMode),
|
: mCORSMode(aCORSMode),
|
||||||
mReferrerPolicy(aReferrerPolicy),
|
mReferrerPolicy(aReferrerPolicy),
|
||||||
mTriggeringPrincipal(aTriggeringPrincipal) {
|
mTriggeringPrincipal(aTriggeringPrincipal) {
|
||||||
@@ -80,7 +78,7 @@ ScriptLoadRequest::ScriptLoadRequest(ScriptKind aKind, nsIURI* aURI,
|
|||||||
ScriptFetchOptions* aFetchOptions,
|
ScriptFetchOptions* aFetchOptions,
|
||||||
const SRIMetadata& aIntegrity,
|
const SRIMetadata& aIntegrity,
|
||||||
nsIURI* aReferrer,
|
nsIURI* aReferrer,
|
||||||
ScriptLoadContext* aContext)
|
mozilla::dom::ScriptLoadContext* aContext)
|
||||||
: mKind(aKind),
|
: mKind(aKind),
|
||||||
mIsCanceled(false),
|
mIsCanceled(false),
|
||||||
mProgress(Progress::eLoading),
|
mProgress(Progress::eLoading),
|
||||||
@@ -232,5 +230,4 @@ bool ScriptLoadRequestList::Contains(ScriptLoadRequest* aElem) const {
|
|||||||
}
|
}
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace JS::loader
|
||||||
} // namespace mozilla
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#ifndef mozilla_dom_ScriptLoadRequest_h
|
#ifndef js_loader_ScriptLoadRequest_h
|
||||||
#define mozilla_dom_ScriptLoadRequest_h
|
#define js_loader_ScriptLoadRequest_h
|
||||||
|
|
||||||
#include "js/AllocPolicy.h"
|
#include "js/AllocPolicy.h"
|
||||||
#include "js/RootingAPI.h"
|
#include "js/RootingAPI.h"
|
||||||
@@ -27,22 +27,25 @@
|
|||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "nsCycleCollectionParticipant.h"
|
#include "nsCycleCollectionParticipant.h"
|
||||||
#include "nsIGlobalObject.h"
|
#include "nsIGlobalObject.h"
|
||||||
#include "nsIScriptElement.h"
|
|
||||||
#include "ScriptKind.h"
|
#include "ScriptKind.h"
|
||||||
|
|
||||||
class nsICacheInfoChannel;
|
class nsICacheInfoChannel;
|
||||||
|
|
||||||
|
namespace mozilla::dom {
|
||||||
|
|
||||||
|
class ScriptLoadContext;
|
||||||
|
|
||||||
|
} // namespace mozilla::dom
|
||||||
|
|
||||||
namespace JS {
|
namespace JS {
|
||||||
class OffThreadToken;
|
class OffThreadToken;
|
||||||
}
|
|
||||||
|
|
||||||
namespace mozilla {
|
namespace loader {
|
||||||
namespace dom {
|
|
||||||
|
using Utf8Unit = mozilla::Utf8Unit;
|
||||||
|
|
||||||
class Element;
|
|
||||||
class ModuleLoadRequest;
|
class ModuleLoadRequest;
|
||||||
class ScriptLoadRequestList;
|
class ScriptLoadRequestList;
|
||||||
class ScriptLoadContext;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ScriptFetchOptions loosely corresponds to HTML's "script fetch options",
|
* ScriptFetchOptions loosely corresponds to HTML's "script fetch options",
|
||||||
@@ -73,7 +76,7 @@ class ScriptFetchOptions {
|
|||||||
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(ScriptFetchOptions)
|
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(ScriptFetchOptions)
|
||||||
|
|
||||||
ScriptFetchOptions(mozilla::CORSMode aCORSMode,
|
ScriptFetchOptions(mozilla::CORSMode aCORSMode,
|
||||||
enum ReferrerPolicy aReferrerPolicy,
|
enum mozilla::dom::ReferrerPolicy aReferrerPolicy,
|
||||||
nsIPrincipal* aTriggeringPrincipal);
|
nsIPrincipal* aTriggeringPrincipal);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -87,7 +90,7 @@ class ScriptFetchOptions {
|
|||||||
* The referrer policy used for the initial fetch and for fetching any
|
* The referrer policy used for the initial fetch and for fetching any
|
||||||
* imported modules
|
* imported modules
|
||||||
*/
|
*/
|
||||||
const enum ReferrerPolicy mReferrerPolicy;
|
const enum mozilla::dom::ReferrerPolicy mReferrerPolicy;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* related to cryptographic nonce, used to determine CSP
|
* related to cryptographic nonce, used to determine CSP
|
||||||
@@ -137,16 +140,27 @@ class ScriptLoadRequest
|
|||||||
virtual ~ScriptLoadRequest();
|
virtual ~ScriptLoadRequest();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
using SRIMetadata = mozilla::dom::SRIMetadata;
|
||||||
ScriptLoadRequest(ScriptKind aKind, nsIURI* aURI,
|
ScriptLoadRequest(ScriptKind aKind, nsIURI* aURI,
|
||||||
ScriptFetchOptions* aFetchOptions,
|
ScriptFetchOptions* aFetchOptions,
|
||||||
const SRIMetadata& aIntegrity, nsIURI* aReferrer,
|
const SRIMetadata& aIntegrity, nsIURI* aReferrer,
|
||||||
ScriptLoadContext* aContext);
|
mozilla::dom::ScriptLoadContext* aContext);
|
||||||
|
|
||||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ScriptLoadRequest)
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ScriptLoadRequest)
|
||||||
|
|
||||||
using super::getNext;
|
using super::getNext;
|
||||||
using super::isInList;
|
using super::isInList;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using VariantType = mozilla::VariantType<T>;
|
||||||
|
|
||||||
|
template <typename... Ts>
|
||||||
|
using Variant = mozilla::Variant<Ts...>;
|
||||||
|
|
||||||
|
template <typename T, typename D = JS::DeletePolicy<T>>
|
||||||
|
using UniquePtr = mozilla::UniquePtr<T, D>;
|
||||||
|
|
||||||
using MaybeSourceText =
|
using MaybeSourceText =
|
||||||
mozilla::MaybeOneOf<JS::SourceText<char16_t>, JS::SourceText<Utf8Unit>>;
|
mozilla::MaybeOneOf<JS::SourceText<char16_t>, JS::SourceText<Utf8Unit>>;
|
||||||
|
|
||||||
@@ -196,7 +210,7 @@ class ScriptLoadRequest
|
|||||||
void SetTextSource() {
|
void SetTextSource() {
|
||||||
MOZ_ASSERT(IsUnknownDataType());
|
MOZ_ASSERT(IsUnknownDataType());
|
||||||
mDataType = DataType::eTextSource;
|
mDataType = DataType::eTextSource;
|
||||||
if (StaticPrefs::
|
if (mozilla::StaticPrefs::
|
||||||
dom_script_loader_external_scripts_utf8_parsing_enabled()) {
|
dom_script_loader_external_scripts_utf8_parsing_enabled()) {
|
||||||
mScriptData.emplace(VariantType<ScriptTextBuffer<Utf8Unit>>());
|
mScriptData.emplace(VariantType<ScriptTextBuffer<Utf8Unit>>());
|
||||||
} else {
|
} else {
|
||||||
@@ -208,7 +222,7 @@ class ScriptLoadRequest
|
|||||||
// can be transferred in constant time to the JS engine, not copied in linear
|
// can be transferred in constant time to the JS engine, not copied in linear
|
||||||
// time.
|
// time.
|
||||||
template <typename Unit>
|
template <typename Unit>
|
||||||
using ScriptTextBuffer = Vector<Unit, 0, js::MallocAllocPolicy>;
|
using ScriptTextBuffer = mozilla::Vector<Unit, 0, js::MallocAllocPolicy>;
|
||||||
|
|
||||||
bool IsUTF16Text() const {
|
bool IsUTF16Text() const {
|
||||||
return mScriptData->is<ScriptTextBuffer<char16_t>>();
|
return mScriptData->is<ScriptTextBuffer<char16_t>>();
|
||||||
@@ -244,7 +258,7 @@ class ScriptLoadRequest
|
|||||||
: ScriptText<Utf8Unit>().clearAndFree();
|
: ScriptText<Utf8Unit>().clearAndFree();
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ReferrerPolicy ReferrerPolicy() const {
|
enum mozilla::dom::ReferrerPolicy ReferrerPolicy() const {
|
||||||
return mFetchOptions->mReferrerPolicy;
|
return mFetchOptions->mReferrerPolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,7 +280,7 @@ class ScriptLoadRequest
|
|||||||
|
|
||||||
bool HasLoadContext() { return mLoadContext; }
|
bool HasLoadContext() { return mLoadContext; }
|
||||||
|
|
||||||
ScriptLoadContext* GetLoadContext() {
|
mozilla::dom::ScriptLoadContext* GetLoadContext() {
|
||||||
MOZ_ASSERT(mLoadContext);
|
MOZ_ASSERT(mLoadContext);
|
||||||
return mLoadContext;
|
return mLoadContext;
|
||||||
}
|
}
|
||||||
@@ -280,10 +294,12 @@ class ScriptLoadRequest
|
|||||||
RefPtr<ScriptFetchOptions> mFetchOptions;
|
RefPtr<ScriptFetchOptions> mFetchOptions;
|
||||||
const SRIMetadata mIntegrity;
|
const SRIMetadata mIntegrity;
|
||||||
const nsCOMPtr<nsIURI> mReferrer;
|
const nsCOMPtr<nsIURI> mReferrer;
|
||||||
Maybe<nsString> mSourceMapURL; // Holds source map url for loaded scripts
|
mozilla::Maybe<nsString>
|
||||||
|
mSourceMapURL; // Holds source map url for loaded scripts
|
||||||
|
|
||||||
// Holds script source data for non-inline scripts.
|
// Holds script source data for non-inline scripts.
|
||||||
Maybe<Variant<ScriptTextBuffer<char16_t>, ScriptTextBuffer<Utf8Unit>>>
|
mozilla::Maybe<
|
||||||
|
Variant<ScriptTextBuffer<char16_t>, ScriptTextBuffer<Utf8Unit>>>
|
||||||
mScriptData;
|
mScriptData;
|
||||||
|
|
||||||
// The length of script source text, set when reading completes. This is used
|
// The length of script source text, set when reading completes. This is used
|
||||||
@@ -313,7 +329,7 @@ class ScriptLoadRequest
|
|||||||
|
|
||||||
// ScriptLoadContext for augmenting the load depending on the loading
|
// ScriptLoadContext for augmenting the load depending on the loading
|
||||||
// context (DOM, Worker, etc.)
|
// context (DOM, Worker, etc.)
|
||||||
RefPtr<ScriptLoadContext> mLoadContext;
|
RefPtr<mozilla::dom::ScriptLoadContext> mLoadContext;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ScriptLoadRequestList : private mozilla::LinkedList<ScriptLoadRequest> {
|
class ScriptLoadRequestList : private mozilla::LinkedList<ScriptLoadRequest> {
|
||||||
@@ -368,7 +384,7 @@ inline void ImplCycleCollectionTraverse(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace loader
|
||||||
} // namespace mozilla
|
} // namespace JS
|
||||||
|
|
||||||
#endif // mozilla_dom_ScriptLoadRequest_h
|
#endif // js_loader_ScriptLoadRequest_h
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
EXPORTS.mozilla.dom += [
|
EXPORTS.js.loader += [
|
||||||
"LoadedScript.h",
|
"LoadedScript.h",
|
||||||
"ModuleLoaderBase.h",
|
"ModuleLoaderBase.h",
|
||||||
"ModuleLoadRequest.h",
|
"ModuleLoadRequest.h",
|
||||||
|
|||||||
@@ -75,8 +75,8 @@ PreloadHashKey& PreloadHashKey::operator=(const PreloadHashKey& aOther) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
PreloadHashKey PreloadHashKey::CreateAsScript(nsIURI* aURI, CORSMode aCORSMode,
|
PreloadHashKey PreloadHashKey::CreateAsScript(
|
||||||
dom::ScriptKind aScriptKind) {
|
nsIURI* aURI, CORSMode aCORSMode, JS::loader::ScriptKind aScriptKind) {
|
||||||
PreloadHashKey key(aURI, ResourceType::SCRIPT);
|
PreloadHashKey key(aURI, ResourceType::SCRIPT);
|
||||||
key.mCORSMode = aCORSMode;
|
key.mCORSMode = aCORSMode;
|
||||||
|
|
||||||
@@ -89,9 +89,9 @@ PreloadHashKey PreloadHashKey::CreateAsScript(nsIURI* aURI, CORSMode aCORSMode,
|
|||||||
PreloadHashKey PreloadHashKey::CreateAsScript(nsIURI* aURI,
|
PreloadHashKey PreloadHashKey::CreateAsScript(nsIURI* aURI,
|
||||||
const nsAString& aCrossOrigin,
|
const nsAString& aCrossOrigin,
|
||||||
const nsAString& aType) {
|
const nsAString& aType) {
|
||||||
dom::ScriptKind scriptKind = dom::ScriptKind::eClassic;
|
JS::loader::ScriptKind scriptKind = JS::loader::ScriptKind::eClassic;
|
||||||
if (aType.LowerCaseEqualsASCII("module")) {
|
if (aType.LowerCaseEqualsASCII("module")) {
|
||||||
scriptKind = dom::ScriptKind::eModule;
|
scriptKind = JS::loader::ScriptKind::eModule;
|
||||||
}
|
}
|
||||||
CORSMode crossOrigin = dom::Element::StringToCORSMode(aCrossOrigin);
|
CORSMode crossOrigin = dom::Element::StringToCORSMode(aCrossOrigin);
|
||||||
return CreateAsScript(aURI, crossOrigin, scriptKind);
|
return CreateAsScript(aURI, crossOrigin, scriptKind);
|
||||||
|
|||||||
@@ -7,11 +7,15 @@
|
|||||||
|
|
||||||
#include "mozilla/CORSMode.h"
|
#include "mozilla/CORSMode.h"
|
||||||
#include "mozilla/css/SheetParsingMode.h"
|
#include "mozilla/css/SheetParsingMode.h"
|
||||||
#include "mozilla/dom/ScriptKind.h"
|
#include "js/loader/ScriptKind.h"
|
||||||
#include "nsURIHashKey.h"
|
#include "nsURIHashKey.h"
|
||||||
|
|
||||||
class nsIPrincipal;
|
class nsIPrincipal;
|
||||||
|
|
||||||
|
namespace JS::loader {
|
||||||
|
enum class ScriptKind;
|
||||||
|
}
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
|
||||||
namespace css {
|
namespace css {
|
||||||
@@ -44,7 +48,7 @@ class PreloadHashKey : public nsURIHashKey {
|
|||||||
|
|
||||||
// Construct key for "script"
|
// Construct key for "script"
|
||||||
static PreloadHashKey CreateAsScript(nsIURI* aURI, CORSMode aCORSMode,
|
static PreloadHashKey CreateAsScript(nsIURI* aURI, CORSMode aCORSMode,
|
||||||
dom::ScriptKind aScriptKind);
|
JS::loader::ScriptKind aScriptKind);
|
||||||
static PreloadHashKey CreateAsScript(nsIURI* aURI,
|
static PreloadHashKey CreateAsScript(nsIURI* aURI,
|
||||||
const nsAString& aCrossOrigin,
|
const nsAString& aCrossOrigin,
|
||||||
const nsAString& aType);
|
const nsAString& aType);
|
||||||
@@ -92,7 +96,7 @@ class PreloadHashKey : public nsURIHashKey {
|
|||||||
nsCOMPtr<nsIPrincipal> mPrincipal;
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
dom::ScriptKind mScriptKind = dom::ScriptKind::eClassic;
|
JS::loader::ScriptKind mScriptKind = JS::loader::ScriptKind::eClassic;
|
||||||
} mScript;
|
} mScript;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user