diff options
Diffstat (limited to 'dom')
50 files changed, 1091 insertions, 934 deletions
diff --git a/dom/base/ImportManager.cpp b/dom/base/ImportManager.cpp index d0e514b59..1f4d376b3 100644 --- a/dom/base/ImportManager.cpp +++ b/dom/base/ImportManager.cpp @@ -6,6 +6,7 @@ #include "ImportManager.h" +#include "mozilla/dom/ScriptLoader.h" #include "mozilla/EventListenerManager.h" #include "HTMLLinkElement.h" #include "nsContentPolicyUtils.h" @@ -18,7 +19,6 @@ #include "nsIDOMEvent.h" #include "nsIPrincipal.h" #include "nsIScriptObjectPrincipal.h" -#include "nsScriptLoader.h" #include "nsNetUtil.h" //----------------------------------------------------------------------------- @@ -156,7 +156,7 @@ ImportLoader::Updater::UpdateMainReferrer(uint32_t aNewIdx) // Our nearest predecessor has changed. So let's add the ScriptLoader to the // new one if there is any. And remove it from the old one. RefPtr<ImportManager> manager = mLoader->Manager(); - nsScriptLoader* loader = mLoader->mDocument->ScriptLoader(); + ScriptLoader* loader = mLoader->mDocument->ScriptLoader(); ImportLoader*& pred = mLoader->mBlockingPredecessor; ImportLoader* newPred = manager->GetNearestPredecessor(newMainReferrer); if (pred) { @@ -339,7 +339,7 @@ ImportLoader::DispatchEventIfFinished(nsINode* aNode) } void -ImportLoader::AddBlockedScriptLoader(nsScriptLoader* aScriptLoader) +ImportLoader::AddBlockedScriptLoader(ScriptLoader* aScriptLoader) { if (mBlockedScriptLoaders.Contains(aScriptLoader)) { return; @@ -352,7 +352,7 @@ ImportLoader::AddBlockedScriptLoader(nsScriptLoader* aScriptLoader) } bool -ImportLoader::RemoveBlockedScriptLoader(nsScriptLoader* aScriptLoader) +ImportLoader::RemoveBlockedScriptLoader(ScriptLoader* aScriptLoader) { aScriptLoader->RemoveParserBlockingScriptExecutionBlocker(); return mBlockedScriptLoaders.RemoveElement(aScriptLoader); diff --git a/dom/base/ImportManager.h b/dom/base/ImportManager.h index 258d4691c..ccc00125a 100644 --- a/dom/base/ImportManager.h +++ b/dom/base/ImportManager.h @@ -45,8 +45,8 @@ #include "nsIStreamListener.h" #include "nsIWeakReferenceUtils.h" #include "nsRefPtrHashtable.h" -#include "nsScriptLoader.h" #include "nsURIHashKey.h" +#include "mozilla/dom/ScriptLoader.h" class nsIDocument; class nsIPrincipal; @@ -184,8 +184,8 @@ public: // and wait for that to run its scripts. We keep track of all the // ScriptRunners that are waiting for this import. NOTE: updating // the main referrer might change this list. - void AddBlockedScriptLoader(nsScriptLoader* aScriptLoader); - bool RemoveBlockedScriptLoader(nsScriptLoader* aScriptLoader); + void AddBlockedScriptLoader(ScriptLoader* aScriptLoader); + bool RemoveBlockedScriptLoader(ScriptLoader* aScriptLoader); void SetBlockingPredecessor(ImportLoader* aLoader); private: @@ -230,7 +230,7 @@ private: // List of pending ScriptLoaders that are waiting for this import // to finish. - nsTArray<RefPtr<nsScriptLoader>> mBlockedScriptLoaders; + nsTArray<RefPtr<ScriptLoader>> mBlockedScriptLoaders; // There is always exactly one referrer link that is flagged as // the main referrer the primary link. This is the one that is diff --git a/dom/base/Location.cpp b/dom/base/Location.cpp index 1483c32f9..308e9a4ff 100644 --- a/dom/base/Location.cpp +++ b/dom/base/Location.cpp @@ -32,9 +32,9 @@ #include "mozilla/Likely.h" #include "nsCycleCollectionParticipant.h" #include "nsNullPrincipal.h" -#include "ScriptSettings.h" #include "mozilla/Unused.h" #include "mozilla/dom/LocationBinding.h" +#include "mozilla/dom/ScriptSettings.h" namespace mozilla { namespace dom { diff --git a/dom/base/moz.build b/dom/base/moz.build index cedaa0e49..ded203c50 100755 --- a/dom/base/moz.build +++ b/dom/base/moz.build @@ -26,7 +26,6 @@ XPIDL_SOURCES += [ 'nsIObjectLoadingContent.idl', 'nsIRemoteWindowContext.idl', 'nsIScriptChannel.idl', - 'nsIScriptLoaderObserver.idl', 'nsISelection.idl', 'nsISelectionController.idl', 'nsISelectionDisplay.idl', @@ -97,7 +96,6 @@ EXPORTS += [ 'nsINode.h', 'nsINodeList.h', 'nsIScriptContext.h', - 'nsIScriptElement.h', 'nsIScriptGlobalObject.h', 'nsIScriptNameSpaceManager.h', 'nsIScriptObjectPrincipal.h', @@ -118,7 +116,6 @@ EXPORTS += [ 'nsRange.h', 'nsReferencedElement.h', 'nsSandboxFlags.h', - 'nsScriptLoader.h', 'nsStructuredCloneContainer.h', 'nsStubAnimationObserver.h', 'nsStubDocumentObserver.h', @@ -210,7 +207,6 @@ EXPORTS.mozilla.dom += [ 'ResponsiveImageSelector.h', 'SameProcessMessageQueue.h', 'ScreenOrientation.h', - 'ScriptSettings.h', 'ShadowRoot.h', 'SimpleTreeIterator.h', 'StructuredCloneHolder.h', @@ -331,8 +327,6 @@ SOURCES += [ 'nsRange.cpp', 'nsReferencedElement.cpp', 'nsScreen.cpp', - 'nsScriptElement.cpp', - 'nsScriptLoader.cpp', 'nsScriptNameSpaceManager.cpp', 'nsStructuredCloneContainer.cpp', 'nsStubAnimationObserver.cpp', @@ -359,7 +353,6 @@ SOURCES += [ 'ResponsiveImageSelector.cpp', 'SameProcessMessageQueue.cpp', 'ScreenOrientation.cpp', - 'ScriptSettings.cpp', 'ShadowRoot.cpp', 'StructuredCloneHolder.cpp', 'StyleSheetList.cpp', diff --git a/dom/base/nsContentPermissionHelper.cpp b/dom/base/nsContentPermissionHelper.cpp index c57fc6233..eaaec2a41 100644 --- a/dom/base/nsContentPermissionHelper.cpp +++ b/dom/base/nsContentPermissionHelper.cpp @@ -29,9 +29,8 @@ #include "nsIDocument.h" #include "nsIDOMEvent.h" #include "nsWeakPtr.h" -#include "ScriptSettings.h" -using mozilla::Unused; // <snicker> +using mozilla::Unused; using namespace mozilla::dom; using namespace mozilla; diff --git a/dom/base/nsContentSink.cpp b/dom/base/nsContentSink.cpp index 490f0ec17..1e6465a1b 100644 --- a/dom/base/nsContentSink.cpp +++ b/dom/base/nsContentSink.cpp @@ -10,7 +10,6 @@ */ #include "nsContentSink.h" -#include "nsScriptLoader.h" #include "nsIDocument.h" #include "nsIDOMDocument.h" #include "mozilla/css/Loader.h" @@ -49,6 +48,7 @@ #include "nsHTMLDNSPrefetch.h" #include "nsIObserverService.h" #include "mozilla/Preferences.h" +#include "mozilla/dom/ScriptLoader.h" #include "nsParserConstants.h" #include "nsSandboxFlags.h" diff --git a/dom/base/nsContentSink.h b/dom/base/nsContentSink.h index b1a758874..2d914a8d7 100644 --- a/dom/base/nsContentSink.h +++ b/dom/base/nsContentSink.h @@ -36,13 +36,16 @@ class nsIAtom; class nsIChannel; class nsIContent; class nsNodeInfoManager; -class nsScriptLoader; class nsIApplicationCache; namespace mozilla { namespace css { class Loader; } // namespace css + +namespace dom { +class ScriptLoader; +} // namespace dom } // namespace mozilla #ifdef DEBUG @@ -273,7 +276,7 @@ protected: nsCOMPtr<nsIDocShell> mDocShell; RefPtr<mozilla::css::Loader> mCSSLoader; RefPtr<nsNodeInfoManager> mNodeInfoManager; - RefPtr<nsScriptLoader> mScriptLoader; + RefPtr<mozilla::dom::ScriptLoader> mScriptLoader; // back off timer notification after count int32_t mBackoffCount; diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 40bfa97e2..dc4b23f2c 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -1834,7 +1834,7 @@ nsDocument::Init() mScopeObject = do_GetWeakReference(global); MOZ_ASSERT(mScopeObject); - mScriptLoader = new nsScriptLoader(this); + mScriptLoader = new dom::ScriptLoader(this); mozilla::HoldJSObjects(this); @@ -4623,7 +4623,7 @@ nsDocument::GetWindowInternal() const return win; } -nsScriptLoader* +ScriptLoader* nsDocument::ScriptLoader() { return mScriptLoader; diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index 9d7b0aafd..502ba0f13 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -32,7 +32,6 @@ #include "nsJSThingHashtable.h" #include "nsIScriptObjectPrincipal.h" #include "nsIURI.h" -#include "nsScriptLoader.h" #include "nsIRadioGroupContainer.h" #include "nsILayoutHistoryState.h" #include "nsIRequest.h" @@ -61,6 +60,7 @@ #include "mozilla/MemoryReporting.h" #include "mozilla/PendingAnimationTracker.h" #include "mozilla/dom/DOMImplementation.h" +#include "mozilla/dom/ScriptLoader.h" #include "mozilla/dom/StyleSheetList.h" #include "nsDataHashtable.h" #include "mozilla/TimeStamp.h" @@ -491,7 +491,7 @@ public: /** * Get the script loader for this document */ - virtual nsScriptLoader* ScriptLoader() override; + virtual mozilla::dom::ScriptLoader* ScriptLoader() override; /** * Add/Remove an element to the document's id and name hashes @@ -1205,7 +1205,7 @@ protected: public: RefPtr<mozilla::EventListenerManager> mListenerManager; RefPtr<nsDOMStyleSheetSetList> mStyleSheetSetList; - RefPtr<nsScriptLoader> mScriptLoader; + RefPtr<mozilla::dom::ScriptLoader> mScriptLoader; nsDocHeaderData* mHeaderData; nsClassHashtable<nsStringHashKey, nsRadioGroupStruct> mRadioGroups; diff --git a/dom/base/nsFrameMessageManager.cpp b/dom/base/nsFrameMessageManager.cpp index bba4232aa..331931f19 100644 --- a/dom/base/nsFrameMessageManager.cpp +++ b/dom/base/nsFrameMessageManager.cpp @@ -19,7 +19,6 @@ #include "nsJSUtils.h" #include "nsJSPrincipals.h" #include "nsNetUtil.h" -#include "nsScriptLoader.h" #include "nsFrameLoader.h" #include "nsIXULRuntime.h" #include "nsIScriptError.h" @@ -38,6 +37,7 @@ #include "mozilla/dom/PermissionMessageUtils.h" #include "mozilla/dom/ProcessGlobal.h" #include "mozilla/dom/SameProcessMessageQueue.h" +#include "mozilla/dom/ScriptLoader.h" #include "mozilla/dom/ScriptSettings.h" #include "mozilla/dom/ipc/BlobChild.h" #include "mozilla/dom/ipc/BlobParent.h" @@ -1786,9 +1786,9 @@ nsMessageManagerScriptExecutor::TryCacheLoadAndCompileScript( if (NS_FAILED(NS_ReadInputStreamToString(input, buffer, avail))) { return; } - nsScriptLoader::ConvertToUTF16(channel, (uint8_t*)buffer.get(), avail, - EmptyString(), nullptr, - dataStringBuf, dataStringLength); + ScriptLoader::ConvertToUTF16(channel, (uint8_t*)buffer.get(), avail, + EmptyString(), nullptr, + dataStringBuf, dataStringLength); } JS::SourceBufferHolder srcBuf(dataStringBuf, dataStringLength, diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 69643762c..acd596a44 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -62,7 +62,7 @@ #include "nsReadableUtils.h" #include "nsDOMClassInfo.h" #include "nsJSEnvironment.h" -#include "ScriptSettings.h" +#include "mozilla/dom/ScriptSettings.h" #include "mozilla/Preferences.h" #include "mozilla/Likely.h" #include "mozilla/Sprintf.h" diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index d88db8423..33aac3a3d 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -93,7 +93,6 @@ class nsIVariant; class nsViewManager; class nsPresContext; class nsRange; -class nsScriptLoader; class nsSMILAnimationController; class nsTextNode; class nsWindowSizes; @@ -153,6 +152,7 @@ enum class OrientationType : uint32_t; class ProcessingInstruction; class Promise; class Selection; +class ScriptLoader; class StyleSheetList; class SVGDocument; class SVGSVGElement; @@ -1278,7 +1278,7 @@ public: /** * Get the script loader for this document */ - virtual nsScriptLoader* ScriptLoader() = 0; + virtual mozilla::dom::ScriptLoader* ScriptLoader() = 0; /** * Add/Remove an element to the document's id and name hashes diff --git a/dom/base/nsInProcessTabChildGlobal.cpp b/dom/base/nsInProcessTabChildGlobal.cpp index 9885b41a8..4cc3c9ce9 100644 --- a/dom/base/nsInProcessTabChildGlobal.cpp +++ b/dom/base/nsInProcessTabChildGlobal.cpp @@ -11,13 +11,13 @@ #include "nsIComponentManager.h" #include "nsIServiceManager.h" #include "nsComponentManagerUtils.h" -#include "nsScriptLoader.h" #include "nsFrameLoader.h" #include "xpcpublic.h" #include "nsIMozBrowserFrame.h" #include "nsDOMClassInfoID.h" #include "mozilla/EventDispatcher.h" #include "mozilla/dom/SameProcessMessageQueue.h" +#include "mozilla/dom/ScriptLoader.h" using namespace mozilla; using namespace mozilla::dom; diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index efea3ee40..605b1917f 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -37,7 +37,6 @@ #include "nsXPCOMCIDInternal.h" #include "nsIXULRuntime.h" #include "nsTextFormatter.h" -#include "ScriptSettings.h" #include "xpcpublic.h" @@ -55,6 +54,7 @@ #include "mozilla/dom/DOMException.h" #include "mozilla/dom/DOMExceptionBinding.h" #include "mozilla/dom/ErrorEvent.h" +#include "mozilla/dom/ScriptSettings.h" #include "nsAXPCNativeCallContext.h" #include "mozilla/CycleCollectedJSContext.h" #include "mozilla/Telemetry.h" diff --git a/dom/base/nsPlainTextSerializer.h b/dom/base/nsPlainTextSerializer.h index 650a8e3e7..58aeb4207 100644 --- a/dom/base/nsPlainTextSerializer.h +++ b/dom/base/nsPlainTextSerializer.h @@ -16,6 +16,7 @@ #include "mozilla/Attributes.h" #include "nsCOMPtr.h" #include "nsIAtom.h" +#include "nsCycleCollectionParticipant.h" #include "nsIContentSerializer.h" #include "nsIDocumentEncoder.h" #include "nsILineBreaker.h" diff --git a/dom/console/Console.cpp b/dom/console/Console.cpp index b174172e0..119a259fe 100755 --- a/dom/console/Console.cpp +++ b/dom/console/Console.cpp @@ -12,6 +12,7 @@ #include "mozilla/dom/File.h" #include "mozilla/dom/FunctionBinding.h" #include "mozilla/dom/Performance.h" +#include "mozilla/dom/ScriptSettings.h" #include "mozilla/dom/StructuredCloneHolder.h" #include "mozilla/dom/ToJSValue.h" #include "mozilla/dom/WorkletGlobalScope.h" @@ -22,7 +23,6 @@ #include "nsGlobalWindow.h" #include "nsJSUtils.h" #include "nsNetUtil.h" -#include "ScriptSettings.h" #include "WorkerPrivate.h" #include "WorkerRunnable.h" #include "WorkerScope.h" diff --git a/dom/events/DOMEventTargetHelper.cpp b/dom/events/DOMEventTargetHelper.cpp index f534f119c..3d162b01e 100644 --- a/dom/events/DOMEventTargetHelper.cpp +++ b/dom/events/DOMEventTargetHelper.cpp @@ -8,7 +8,7 @@ #include "nsIDocument.h" #include "mozilla/Sprintf.h" #include "nsGlobalWindow.h" -#include "ScriptSettings.h" +#include "mozilla/dom/ScriptSettings.h" #include "mozilla/DOMEventTargetHelper.h" #include "mozilla/EventDispatcher.h" #include "mozilla/EventListenerManager.h" diff --git a/dom/html/HTMLScriptElement.cpp b/dom/html/HTMLScriptElement.cpp index a1bea94d9..5b727280f 100644 --- a/dom/html/HTMLScriptElement.cpp +++ b/dom/html/HTMLScriptElement.cpp @@ -37,7 +37,7 @@ HTMLScriptElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) HTMLScriptElement::HTMLScriptElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo, FromParser aFromParser) : nsGenericHTMLElement(aNodeInfo) - , nsScriptElement(aFromParser) + , ScriptElement(aFromParser) { AddMutationObserver(this); } diff --git a/dom/html/HTMLScriptElement.h b/dom/html/HTMLScriptElement.h index bd446fa97..6edeb9832 100644 --- a/dom/html/HTMLScriptElement.h +++ b/dom/html/HTMLScriptElement.h @@ -8,16 +8,16 @@ #define mozilla_dom_HTMLScriptElement_h #include "nsIDOMHTMLScriptElement.h" -#include "nsScriptElement.h" #include "nsGenericHTMLElement.h" #include "mozilla/Attributes.h" +#include "mozilla/dom/ScriptElement.h" namespace mozilla { namespace dom { class HTMLScriptElement final : public nsGenericHTMLElement, public nsIDOMHTMLScriptElement, - public nsScriptElement + public ScriptElement { public: using Element::GetText; @@ -98,7 +98,8 @@ protected: virtual ~HTMLScriptElement(); virtual JSObject* WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override; - // nsScriptElement + + // ScriptElement virtual bool HasScriptContent() override; }; diff --git a/dom/html/nsGenericHTMLElement.cpp b/dom/html/nsGenericHTMLElement.cpp index 17dba6da9..b52e61ce6 100644 --- a/dom/html/nsGenericHTMLElement.cpp +++ b/dom/html/nsGenericHTMLElement.cpp @@ -48,7 +48,6 @@ #include "nsIDocShell.h" #include "nsNameSpaceManager.h" #include "nsError.h" -#include "nsScriptLoader.h" #include "nsRuleData.h" #include "nsIPrincipal.h" #include "nsContainerFrame.h" @@ -92,6 +91,7 @@ #include "mozilla/dom/FromParser.h" #include "mozilla/dom/Link.h" #include "mozilla/BloomFilter.h" +#include "mozilla/dom/ScriptLoader.h" #include "nsVariant.h" #include "nsDOMTokenList.h" diff --git a/dom/html/nsHTMLContentSink.cpp b/dom/html/nsHTMLContentSink.cpp index eb22b772f..f7e380f40 100644 --- a/dom/html/nsHTMLContentSink.cpp +++ b/dom/html/nsHTMLContentSink.cpp @@ -20,10 +20,10 @@ #include "nsIHTMLContentSink.h" #include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestorUtils.h" -#include "nsScriptLoader.h" #include "nsIURI.h" #include "nsIContentViewer.h" #include "mozilla/dom/NodeInfo.h" +#include "mozilla/dom/ScriptLoader.h" #include "nsToken.h" #include "nsIAppShell.h" #include "nsCRT.h" diff --git a/dom/messagechannel/MessagePort.cpp b/dom/messagechannel/MessagePort.cpp index 56204da99..fcbe36a72 100644 --- a/dom/messagechannel/MessagePort.cpp +++ b/dom/messagechannel/MessagePort.cpp @@ -16,6 +16,7 @@ #include "mozilla/dom/MessagePortBinding.h" #include "mozilla/dom/MessagePortChild.h" #include "mozilla/dom/PMessagePort.h" +#include "mozilla/dom/ScriptSettings.h" #include "mozilla/dom/StructuredCloneTags.h" #include "mozilla/dom/WorkerPrivate.h" #include "mozilla/dom/WorkerScope.h" @@ -28,7 +29,6 @@ #include "nsContentUtils.h" #include "nsGlobalWindow.h" #include "nsPresContext.h" -#include "ScriptSettings.h" #include "SharedMessagePortMessage.h" #include "nsIBFCacheEntry.h" diff --git a/dom/moz.build b/dom/moz.build index 8a958982f..7888ccd69 100644 --- a/dom/moz.build +++ b/dom/moz.build @@ -100,6 +100,7 @@ DIRS += [ 'performance', 'xhr', 'worklet', + 'script', ] if CONFIG['OS_ARCH'] == 'WINNT': diff --git a/dom/script/ModuleLoadRequest.cpp b/dom/script/ModuleLoadRequest.cpp new file mode 100644 index 000000000..e72edca2e --- /dev/null +++ b/dom/script/ModuleLoadRequest.cpp @@ -0,0 +1,102 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + +#include "ModuleLoadRequest.h" +#include "ModuleScript.h" +#include "ScriptLoader.h" + +namespace mozilla { +namespace dom { + +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ModuleLoadRequest) +NS_INTERFACE_MAP_END_INHERITING(ScriptLoadRequest) + +NS_IMPL_CYCLE_COLLECTION_INHERITED(ModuleLoadRequest, ScriptLoadRequest, + mBaseURL, + mLoader, + mParent, + mModuleScript, + mImports) + +NS_IMPL_ADDREF_INHERITED(ModuleLoadRequest, ScriptLoadRequest) +NS_IMPL_RELEASE_INHERITED(ModuleLoadRequest, ScriptLoadRequest) + +ModuleLoadRequest::ModuleLoadRequest(nsIScriptElement* aElement, + uint32_t aVersion, + CORSMode aCORSMode, + const SRIMetadata &aIntegrity, + ScriptLoader* aLoader) + : ScriptLoadRequest(ScriptKind::Module, + aElement, + aVersion, + aCORSMode, + aIntegrity), + mIsTopLevel(true), + mLoader(aLoader) +{} + +void ModuleLoadRequest::Cancel() +{ + ScriptLoadRequest::Cancel(); + mModuleScript = nullptr; + mProgress = ScriptLoadRequest::Progress::Ready; + for (size_t i = 0; i < mImports.Length(); i++) { + mImports[i]->Cancel(); + } + mReady.RejectIfExists(NS_ERROR_FAILURE, __func__); +} + +void +ModuleLoadRequest::SetReady() +{ +#ifdef DEBUG + for (size_t i = 0; i < mImports.Length(); i++) { + MOZ_ASSERT(mImports[i]->IsReadyToRun()); + } +#endif + + ScriptLoadRequest::SetReady(); + mReady.ResolveIfExists(true, __func__); +} + +void +ModuleLoadRequest::ModuleLoaded() +{ + // A module that was found to be marked as fetching in the module map has now + // been loaded. + + mModuleScript = mLoader->GetFetchedModule(mURI); + mLoader->StartFetchingModuleDependencies(this); +} + +void +ModuleLoadRequest::DependenciesLoaded() +{ + // The module and all of its dependencies have been successfully fetched and + // compiled. + + if (!mLoader->InstantiateModuleTree(this)) { + LoadFailed(); + return; + } + + SetReady(); + mLoader->ProcessLoadedModuleTree(this); + mLoader = nullptr; + mParent = nullptr; +} + +void +ModuleLoadRequest::LoadFailed() +{ + Cancel(); + mLoader->ProcessLoadedModuleTree(this); + mLoader = nullptr; + mParent = nullptr; +} + +} // dom namespace +} // mozilla namespace
\ No newline at end of file diff --git a/dom/script/ModuleLoadRequest.h b/dom/script/ModuleLoadRequest.h new file mode 100644 index 000000000..0119fad38 --- /dev/null +++ b/dom/script/ModuleLoadRequest.h @@ -0,0 +1,81 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + +#ifndef mozilla_dom_ModuleLoadRequest_h +#define mozilla_dom_ModuleLoadRequest_h + +#include "mozilla/dom/ScriptLoader.h" +#include "mozilla/MozPromise.h" + +namespace mozilla { +namespace dom { + +class ModuleScript; +class ScriptLoader; + +// A load request for a module, created for every top level module script and +// every module import. Load request can share a ModuleScript if there are +// multiple imports of the same module. + +class ModuleLoadRequest final : public ScriptLoadRequest +{ + ~ModuleLoadRequest() {} + + ModuleLoadRequest(const ModuleLoadRequest& aOther) = delete; + ModuleLoadRequest(ModuleLoadRequest&& aOther) = delete; + +public: + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ModuleLoadRequest, ScriptLoadRequest) + + ModuleLoadRequest(nsIScriptElement* aElement, + uint32_t aVersion, + CORSMode aCORSMode, + const SRIMetadata& aIntegrity, + ScriptLoader* aLoader); + + bool IsTopLevel() const { + return mIsTopLevel; + } + + void SetReady() override; + void Cancel() override; + + void ModuleLoaded(); + void DependenciesLoaded(); + void LoadFailed(); + + // Is this a request for a top level module script or an import? + bool mIsTopLevel; + + // The base URL used for resolving relative module imports. + nsCOMPtr<nsIURI> mBaseURL; + + // Pointer to the script loader, used to trigger actions when the module load + // finishes. + RefPtr<ScriptLoader> mLoader; + + // The importing module, or nullptr for top level module scripts. Used to + // implement the ancestor list checked when fetching module dependencies. + RefPtr<ModuleLoadRequest> mParent; + + // Set to a module script object after a successful load or nullptr on + // failure. + RefPtr<ModuleScript> mModuleScript; + + // A promise that is completed on successful load of this module and all of + // its dependencies, indicating that the module is ready for instantiation and + // evaluation. + MozPromiseHolder<GenericPromise> mReady; + + // Array of imported modules. + nsTArray<RefPtr<ModuleLoadRequest>> mImports; +}; + +} // dom namespace +} // mozilla namespace + +#endif // mozilla_dom_ModuleLoadRequest_h
\ No newline at end of file diff --git a/dom/script/ModuleScript.cpp b/dom/script/ModuleScript.cpp new file mode 100644 index 000000000..34ef4dec4 --- /dev/null +++ b/dom/script/ModuleScript.cpp @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + +/* + * A class that handles loading and evaluation of <script> elements. + */ + +#include "ModuleScript.h" +#include "mozilla/HoldDropJSObjects.h" +#include "ScriptLoader.h" + +namespace mozilla { +namespace dom { + +// A single module script. May be used to satisfy multiple load requests. + +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ModuleScript) +NS_INTERFACE_MAP_END + +NS_IMPL_CYCLE_COLLECTION_CLASS(ModuleScript) + +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ModuleScript) + NS_IMPL_CYCLE_COLLECTION_UNLINK(mLoader) + NS_IMPL_CYCLE_COLLECTION_UNLINK(mBaseURL) + tmp->UnlinkModuleRecord(); +NS_IMPL_CYCLE_COLLECTION_UNLINK_END + +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(ModuleScript) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLoader) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + +NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(ModuleScript) + NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mModuleRecord) + NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mException) +NS_IMPL_CYCLE_COLLECTION_TRACE_END + +NS_IMPL_CYCLE_COLLECTING_ADDREF(ModuleScript) +NS_IMPL_CYCLE_COLLECTING_RELEASE(ModuleScript) + +ModuleScript::ModuleScript(ScriptLoader *aLoader, nsIURI* aBaseURL, + JS::Handle<JSObject*> aModuleRecord) + : mLoader(aLoader), + mBaseURL(aBaseURL), + mModuleRecord(aModuleRecord), + mInstantiationState(Uninstantiated) +{ + MOZ_ASSERT(mLoader); + MOZ_ASSERT(mBaseURL); + MOZ_ASSERT(mModuleRecord); + MOZ_ASSERT(mException.isUndefined()); + + // Make module's host defined field point to this module script object. + // This is cleared in the UnlinkModuleRecord(). + JS::SetModuleHostDefinedField(mModuleRecord, JS::PrivateValue(this)); + HoldJSObjects(this); +} + +void +ModuleScript::UnlinkModuleRecord() +{ + // Remove module's back reference to this object request if present. + if (mModuleRecord) { + MOZ_ASSERT(JS::GetModuleHostDefinedField(mModuleRecord).toPrivate() == + this); + JS::SetModuleHostDefinedField(mModuleRecord, JS::UndefinedValue()); + } + mModuleRecord = nullptr; + mException.setUndefined(); +} + +ModuleScript::~ModuleScript() +{ + if (mModuleRecord) { + // The object may be destroyed without being unlinked first. + UnlinkModuleRecord(); + } + DropJSObjects(this); +} + +void +ModuleScript::SetInstantiationResult(JS::Handle<JS::Value> aMaybeException) +{ + MOZ_ASSERT(mInstantiationState == Uninstantiated); + MOZ_ASSERT(mModuleRecord); + MOZ_ASSERT(mException.isUndefined()); + + if (aMaybeException.isUndefined()) { + mInstantiationState = Instantiated; + } else { + mModuleRecord = nullptr; + mException = aMaybeException; + mInstantiationState = Errored; + } +} + +} // dom namespace +} // mozilla namespace diff --git a/dom/script/ModuleScript.h b/dom/script/ModuleScript.h new file mode 100644 index 000000000..dd0d07e84 --- /dev/null +++ b/dom/script/ModuleScript.h @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + +#ifndef mozilla_dom_ModuleScript_h +#define mozilla_dom_ModuleScript_h + +#include "nsCOMPtr.h" +#include "nsCycleCollectionParticipant.h" +#include "jsapi.h" + +class nsIURI; + +namespace mozilla { +namespace dom { + +class ScriptLoader; + +class ModuleScript final : public nsISupports +{ + enum InstantiationState { + Uninstantiated, + Instantiated, + Errored + }; + + RefPtr<ScriptLoader> mLoader; + nsCOMPtr<nsIURI> mBaseURL; + JS::Heap<JSObject*> mModuleRecord; + JS::Heap<JS::Value> mException; + InstantiationState mInstantiationState; + + ~ModuleScript(); + +public: + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ModuleScript) + + ModuleScript(ScriptLoader* aLoader, + nsIURI* aBaseURL, + JS::Handle<JSObject*> aModuleRecord); + + ScriptLoader* Loader() const { return mLoader; } + JSObject* ModuleRecord() const { return mModuleRecord; } + JS::Value Exception() const { return mException; } + nsIURI* BaseURL() const { return mBaseURL; } + + void SetInstantiationResult(JS::Handle<JS::Value> aMaybeException); + bool IsUninstantiated() const { + return mInstantiationState == Uninstantiated; + } + bool IsInstantiated() const { + return mInstantiationState == Instantiated; + } + bool InstantiationFailed() const { + return mInstantiationState == Errored; + } + + void UnlinkModuleRecord(); +}; + +} // dom namespace +} // mozilla namespace + +#endif // mozilla_dom_ModuleScript_h
\ No newline at end of file diff --git a/dom/base/nsScriptElement.cpp b/dom/script/ScriptElement.cpp index ebeb18f81..0cb17dcb0 100644 --- a/dom/base/nsScriptElement.cpp +++ b/dom/script/ScriptElement.cpp @@ -4,13 +4,13 @@ * 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/. */ -#include "nsScriptElement.h" +#include "ScriptElement.h" +#include "ScriptLoader.h" #include "mozilla/BasicEvents.h" #include "mozilla/EventDispatcher.h" #include "mozilla/dom/Element.h" #include "nsContentUtils.h" #include "nsPresContext.h" -#include "nsScriptLoader.h" #include "nsIParser.h" #include "nsGkAtoms.h" #include "nsContentSink.h" @@ -19,11 +19,11 @@ using namespace mozilla; using namespace mozilla::dom; NS_IMETHODIMP -nsScriptElement::ScriptAvailable(nsresult aResult, - nsIScriptElement *aElement, - bool aIsInline, - nsIURI *aURI, - int32_t aLineNo) +ScriptElement::ScriptAvailable(nsresult aResult, + nsIScriptElement *aElement, + bool aIsInline, + nsIURI *aURI, + int32_t aLineNo) { if (!aIsInline && NS_FAILED(aResult)) { nsCOMPtr<nsIParser> parser = do_QueryReferent(mCreatorParser); @@ -40,7 +40,7 @@ nsScriptElement::ScriptAvailable(nsresult aResult, } /* virtual */ nsresult -nsScriptElement::FireErrorEvent() +ScriptElement::FireErrorEvent() { nsCOMPtr<nsIContent> cont = do_QueryInterface((nsIScriptElement*) this); @@ -53,9 +53,9 @@ nsScriptElement::FireErrorEvent() } NS_IMETHODIMP -nsScriptElement::ScriptEvaluated(nsresult aResult, - nsIScriptElement *aElement, - bool aIsInline) +ScriptElement::ScriptEvaluated(nsresult aResult, + nsIScriptElement *aElement, + bool aIsInline) { nsresult rv = NS_OK; if (!aIsInline) { @@ -78,44 +78,44 @@ nsScriptElement::ScriptEvaluated(nsresult aResult, } void -nsScriptElement::CharacterDataChanged(nsIDocument *aDocument, - nsIContent* aContent, - CharacterDataChangeInfo* aInfo) +ScriptElement::CharacterDataChanged(nsIDocument *aDocument, + nsIContent* aContent, + CharacterDataChangeInfo* aInfo) { MaybeProcessScript(); } void -nsScriptElement::AttributeChanged(nsIDocument* aDocument, - Element* aElement, - int32_t aNameSpaceID, - nsIAtom* aAttribute, - int32_t aModType, - const nsAttrValue* aOldValue) +ScriptElement::AttributeChanged(nsIDocument* aDocument, + Element* aElement, + int32_t aNameSpaceID, + nsIAtom* aAttribute, + int32_t aModType, + const nsAttrValue* aOldValue) { MaybeProcessScript(); } void -nsScriptElement::ContentAppended(nsIDocument* aDocument, - nsIContent* aContainer, - nsIContent* aFirstNewContent, - int32_t aNewIndexInContainer) +ScriptElement::ContentAppended(nsIDocument* aDocument, + nsIContent* aContainer, + nsIContent* aFirstNewContent, + int32_t aNewIndexInContainer) { MaybeProcessScript(); } void -nsScriptElement::ContentInserted(nsIDocument *aDocument, - nsIContent* aContainer, - nsIContent* aChild, - int32_t aIndexInContainer) +ScriptElement::ContentInserted(nsIDocument *aDocument, + nsIContent* aContainer, + nsIContent* aChild, + int32_t aIndexInContainer) { MaybeProcessScript(); } bool -nsScriptElement::MaybeProcessScript() +ScriptElement::MaybeProcessScript() { nsCOMPtr<nsIContent> cont = do_QueryInterface((nsIScriptElement*) this); @@ -145,6 +145,6 @@ nsScriptElement::MaybeProcessScript() } } - RefPtr<nsScriptLoader> loader = ownerDoc->ScriptLoader(); + RefPtr<ScriptLoader> loader = ownerDoc->ScriptLoader(); return loader->ProcessScriptElement(this); } diff --git a/dom/base/nsScriptElement.h b/dom/script/ScriptElement.h index 4a2a584ac..0babda674 100644 --- a/dom/base/nsScriptElement.h +++ b/dom/script/ScriptElement.h @@ -4,22 +4,25 @@ * 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/. */ -#ifndef nsScriptElement_h -#define nsScriptElement_h +#ifndef mozilla_dom_ScriptElement_h +#define mozilla_dom_ScriptElement_h #include "mozilla/Attributes.h" #include "nsIScriptLoaderObserver.h" #include "nsIScriptElement.h" #include "nsStubMutationObserver.h" +namespace mozilla { +namespace dom { + /** * Baseclass useful for script elements (such as <xhtml:script> and * <svg:script>). Currently the class assumes that only the 'src' * attribute and the children of the class affect what script to execute. */ -class nsScriptElement : public nsIScriptElement, - public nsStubMutationObserver +class ScriptElement : public nsIScriptElement, + public nsStubMutationObserver { public: // nsIScriptLoaderObserver @@ -31,7 +34,7 @@ public: NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED - explicit nsScriptElement(mozilla::dom::FromParser aFromParser) + explicit ScriptElement(FromParser aFromParser) : nsIScriptElement(aFromParser) { } @@ -49,4 +52,7 @@ protected: virtual bool MaybeProcessScript() override; }; -#endif // nsScriptElement_h +} // dom namespace +} // mozilla namespace + +#endif // mozilla_dom_ScriptElement_h diff --git a/dom/script/ScriptLoadHandler.cpp b/dom/script/ScriptLoadHandler.cpp new file mode 100644 index 000000000..80fb70f6a --- /dev/null +++ b/dom/script/ScriptLoadHandler.cpp @@ -0,0 +1,216 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + +/* + * A class that handles loading and evaluation of <script> elements. + */ + +#include "ScriptLoadHandler.h" +#include "ScriptLoader.h" +#include "nsContentUtils.h" + +#include "mozilla/dom/EncodingUtils.h" + +namespace mozilla { +namespace dom { + +ScriptLoadHandler::ScriptLoadHandler(ScriptLoader *aScriptLoader, + ScriptLoadRequest *aRequest, + mozilla::dom::SRICheckDataVerifier *aSRIDataVerifier) + : mScriptLoader(aScriptLoader), + mRequest(aRequest), + mSRIDataVerifier(aSRIDataVerifier), + mSRIStatus(NS_OK), + mDecoder(), + mBuffer() +{} + +ScriptLoadHandler::~ScriptLoadHandler() +{} + +NS_IMPL_ISUPPORTS(ScriptLoadHandler, nsIIncrementalStreamLoaderObserver) + +NS_IMETHODIMP +ScriptLoadHandler::OnIncrementalData(nsIIncrementalStreamLoader* aLoader, + nsISupports* aContext, + uint32_t aDataLength, + const uint8_t* aData, + uint32_t *aConsumedLength) +{ + if (mRequest->IsCanceled()) { + // If request cancelled, ignore any incoming data. + *aConsumedLength = aDataLength; + return NS_OK; + } + + if (!EnsureDecoder(aLoader, aData, aDataLength, + /* aEndOfStream = */ false)) { + return NS_OK; + } + + // Below we will/shall consume entire data chunk. + *aConsumedLength = aDataLength; + + // Decoder has already been initialized. -- trying to decode all loaded bytes. + nsresult rv = TryDecodeRawData(aData, aDataLength, + /* aEndOfStream = */ false); + NS_ENSURE_SUCCESS(rv, rv); + + // If SRI is required for this load, appending new bytes to the hash. + if (mSRIDataVerifier && NS_SUCCEEDED(mSRIStatus)) { + mSRIStatus = mSRIDataVerifier->Update(aDataLength, aData); + } + + return rv; +} + +nsresult +ScriptLoadHandler::TryDecodeRawData(const uint8_t* aData, + uint32_t aDataLength, + bool aEndOfStream) +{ + int32_t srcLen = aDataLength; + const char* src = reinterpret_cast<const char *>(aData); + int32_t dstLen; + nsresult rv = + mDecoder->GetMaxLength(src, srcLen, &dstLen); + + NS_ENSURE_SUCCESS(rv, rv); + + uint32_t haveRead = mBuffer.length(); + + CheckedInt<uint32_t> capacity = haveRead; + capacity += dstLen; + + if (!capacity.isValid() || !mBuffer.reserve(capacity.value())) { + return NS_ERROR_OUT_OF_MEMORY; + } + + rv = mDecoder->Convert(src, + &srcLen, + mBuffer.begin() + haveRead, + &dstLen); + + NS_ENSURE_SUCCESS(rv, rv); + + haveRead += dstLen; + MOZ_ASSERT(haveRead <= capacity.value(), "mDecoder produced more data than expected"); + MOZ_ALWAYS_TRUE(mBuffer.resizeUninitialized(haveRead)); + + return NS_OK; +} + +bool +ScriptLoadHandler::EnsureDecoder(nsIIncrementalStreamLoader *aLoader, + const uint8_t* aData, + uint32_t aDataLength, + bool aEndOfStream) +{ + // Check if decoder has already been created. + if (mDecoder) { + return true; + } + + nsAutoCString charset; + + // JavaScript modules are always UTF-8. + if (mRequest->IsModuleRequest()) { + charset = "UTF-8"; + mDecoder = EncodingUtils::DecoderForEncoding(charset); + return true; + } + + // Determine if BOM check should be done. This occurs either + // if end-of-stream has been reached, or at least 3 bytes have + // been read from input. + if (!aEndOfStream && (aDataLength < 3)) { + return false; + } + + // Do BOM detection. + if (nsContentUtils::CheckForBOM(aData, aDataLength, charset)) { + mDecoder = EncodingUtils::DecoderForEncoding(charset); + return true; + } + + // BOM detection failed, check content stream for charset. + nsCOMPtr<nsIRequest> req; + nsresult rv = aLoader->GetRequest(getter_AddRefs(req)); + NS_ASSERTION(req, "StreamLoader's request went away prematurely"); + NS_ENSURE_SUCCESS(rv, false); + + nsCOMPtr<nsIChannel> channel = do_QueryInterface(req); + + if (channel && + NS_SUCCEEDED(channel->GetContentCharset(charset)) && + EncodingUtils::FindEncodingForLabel(charset, charset)) { + mDecoder = EncodingUtils::DecoderForEncoding(charset); + return true; + } + + // Check the hint charset from the script element or preload + // request. + nsAutoString hintCharset; + if (!mRequest->IsPreload()) { + mRequest->mElement->GetScriptCharset(hintCharset); + } else { + nsTArray<ScriptLoader::PreloadInfo>::index_type i = + mScriptLoader->mPreloads.IndexOf(mRequest, 0, + ScriptLoader::PreloadRequestComparator()); + + NS_ASSERTION(i != mScriptLoader->mPreloads.NoIndex, + "Incorrect preload bookkeeping"); + hintCharset = mScriptLoader->mPreloads[i].mCharset; + } + + if (EncodingUtils::FindEncodingForLabel(hintCharset, charset)) { + mDecoder = EncodingUtils::DecoderForEncoding(charset); + return true; + } + + // Get the charset from the charset of the document. + if (mScriptLoader->mDocument) { + charset = mScriptLoader->mDocument->GetDocumentCharacterSet(); + mDecoder = EncodingUtils::DecoderForEncoding(charset); + return true; + } + + // Curiously, there are various callers that don't pass aDocument. The + // fallback in the old code was ISO-8859-1, which behaved like + // windows-1252. Saying windows-1252 for clarity and for compliance + // with the Encoding Standard. + charset = "windows-1252"; + mDecoder = EncodingUtils::DecoderForEncoding(charset); + return true; +} + +NS_IMETHODIMP +ScriptLoadHandler::OnStreamComplete(nsIIncrementalStreamLoader* aLoader, + nsISupports* aContext, + nsresult aStatus, + uint32_t aDataLength, + const uint8_t* aData) +{ + if (!mRequest->IsCanceled()) { + DebugOnly<bool> encoderSet = + EnsureDecoder(aLoader, aData, aDataLength, /* aEndOfStream = */ true); + MOZ_ASSERT(encoderSet); + DebugOnly<nsresult> rv = TryDecodeRawData(aData, aDataLength, + /* aEndOfStream = */ true); + + // If SRI is required for this load, appending new bytes to the hash. + if (mSRIDataVerifier && NS_SUCCEEDED(mSRIStatus)) { + mSRIStatus = mSRIDataVerifier->Update(aDataLength, aData); + } + } + + // we have to mediate and use mRequest. + return mScriptLoader->OnStreamComplete(aLoader, mRequest, aStatus, mSRIStatus, + mBuffer, mSRIDataVerifier); +} + +} // dom namespace +} // mozilla namespace
\ No newline at end of file diff --git a/dom/script/ScriptLoadHandler.h b/dom/script/ScriptLoadHandler.h new file mode 100644 index 000000000..b70f87397 --- /dev/null +++ b/dom/script/ScriptLoadHandler.h @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + +/* + * A class that handles loading and evaluation of <script> elements. + */ + +#ifndef mozilla_dom_ScriptLoadHandler_h +#define mozilla_dom_ScriptLoadHandler_h + +#include "nsIIncrementalStreamLoader.h" +#include "nsIUnicodeDecoder.h" +#include "nsAutoPtr.h" +#include "mozilla/Vector.h" + +namespace mozilla { +namespace dom { + +class ScriptLoadRequest; +class ScriptLoader; +class SRICheckDataVerifier; + +class ScriptLoadHandler final : public nsIIncrementalStreamLoaderObserver +{ +public: + explicit ScriptLoadHandler(ScriptLoader* aScriptLoader, + ScriptLoadRequest* aRequest, + SRICheckDataVerifier* aSRIDataVerifier); + + NS_DECL_ISUPPORTS + NS_DECL_NSIINCREMENTALSTREAMLOADEROBSERVER + +private: + virtual ~ScriptLoadHandler(); + + /* + * Try to decode some raw data. + */ + nsresult TryDecodeRawData(const uint8_t* aData, uint32_t aDataLength, + bool aEndOfStream); + + /* + * Discover the charset by looking at the stream data, the script + * tag, and other indicators. Returns true if charset has been + * discovered. + */ + bool EnsureDecoder(nsIIncrementalStreamLoader *aLoader, + const uint8_t* aData, uint32_t aDataLength, + bool aEndOfStream); + + // ScriptLoader which will handle the parsed script. + RefPtr<ScriptLoader> mScriptLoader; + + // The ScriptLoadRequest for this load. + RefPtr<ScriptLoadRequest> mRequest; + + // SRI data verifier. + nsAutoPtr<SRICheckDataVerifier> mSRIDataVerifier; + + // Status of SRI data operations. + nsresult mSRIStatus; + + // Unicode decoder for charset. + nsCOMPtr<nsIUnicodeDecoder> mDecoder; + + // Accumulated decoded char buffer. + mozilla::Vector<char16_t> mBuffer; +}; + +} // namespace dom +} // namespace mozilla + +#endif //mozilla_dom_ScriptLoader_h diff --git a/dom/base/nsScriptLoader.cpp b/dom/script/ScriptLoader.cpp index 25482fe7b..adc046b7c 100644 --- a/dom/base/nsScriptLoader.cpp +++ b/dom/script/ScriptLoader.cpp @@ -4,11 +4,10 @@ * 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/. */ -/* - * A class that handles loading and evaluation of <script> elements. - */ - -#include "nsScriptLoader.h" +#include "ScriptLoader.h" +#include "ScriptLoadHandler.h" +#include "ModuleLoadRequest.h" +#include "ModuleScript.h" #include "prsystem.h" #include "jsapi.h" @@ -58,19 +57,19 @@ #include "mozilla/Unused.h" #include "nsIScriptError.h" -using namespace mozilla; -using namespace mozilla::dom; - using JS::SourceBufferHolder; +namespace mozilla { +namespace dom { + static LazyLogModule gCspPRLog("CSP"); void -ImplCycleCollectionUnlink(nsScriptLoadRequestList& aField); +ImplCycleCollectionUnlink(ScriptLoadRequestList& aField); void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, - nsScriptLoadRequestList& aField, + ScriptLoadRequestList& aField, const char* aName, uint32_t aFlags = 0); @@ -78,23 +77,23 @@ ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, // nsScriptLoadRequest ////////////////////////////////////////////////////////////// -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsScriptLoadRequest) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ScriptLoadRequest) NS_INTERFACE_MAP_END -NS_IMPL_CYCLE_COLLECTING_ADDREF(nsScriptLoadRequest) -NS_IMPL_CYCLE_COLLECTING_RELEASE(nsScriptLoadRequest) +NS_IMPL_CYCLE_COLLECTING_ADDREF(ScriptLoadRequest) +NS_IMPL_CYCLE_COLLECTING_RELEASE(ScriptLoadRequest) -NS_IMPL_CYCLE_COLLECTION_CLASS(nsScriptLoadRequest) +NS_IMPL_CYCLE_COLLECTION_CLASS(ScriptLoadRequest) -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsScriptLoadRequest) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ScriptLoadRequest) NS_IMPL_CYCLE_COLLECTION_UNLINK(mElement) NS_IMPL_CYCLE_COLLECTION_UNLINK_END -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsScriptLoadRequest) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(ScriptLoadRequest) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mElement) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END -nsScriptLoadRequest::~nsScriptLoadRequest() +ScriptLoadRequest::~ScriptLoadRequest() { js_free(mScriptTextBuf); @@ -107,21 +106,21 @@ nsScriptLoadRequest::~nsScriptLoadRequest() } void -nsScriptLoadRequest::SetReady() +ScriptLoadRequest::SetReady() { MOZ_ASSERT(mProgress != Progress::Ready); mProgress = Progress::Ready; } void -nsScriptLoadRequest::Cancel() +ScriptLoadRequest::Cancel() { MaybeCancelOffThreadScript(); mIsCanceled = true; } void -nsScriptLoadRequest::MaybeCancelOffThreadScript() +ScriptLoadRequest::MaybeCancelOffThreadScript() { MOZ_ASSERT(NS_IsMainThread()); @@ -134,306 +133,28 @@ nsScriptLoadRequest::MaybeCancelOffThreadScript() mOffThreadToken = nullptr; } -////////////////////////////////////////////////////////////// -// nsModuleLoadRequest -////////////////////////////////////////////////////////////// - -// A load request for a module, created for every top level module script and -// every module import. Load request can share an nsModuleScript if there are -// multiple imports of the same module. - -class nsModuleLoadRequest final : public nsScriptLoadRequest -{ - ~nsModuleLoadRequest() {} - - nsModuleLoadRequest(const nsModuleLoadRequest& aOther) = delete; - nsModuleLoadRequest(nsModuleLoadRequest&& aOther) = delete; - -public: - NS_DECL_ISUPPORTS_INHERITED - NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsModuleLoadRequest, nsScriptLoadRequest) - - nsModuleLoadRequest(nsIScriptElement* aElement, - uint32_t aVersion, - CORSMode aCORSMode, - const SRIMetadata& aIntegrity, - nsScriptLoader* aLoader); - - bool IsTopLevel() const { - return mIsTopLevel; - } - - void SetReady() override; - void Cancel() override; - - void ModuleLoaded(); - void DependenciesLoaded(); - void LoadFailed(); - - // Is this a request for a top level module script or an import? - bool mIsTopLevel; - - // The base URL used for resolving relative module imports. - nsCOMPtr<nsIURI> mBaseURL; - - // Pointer to the script loader, used to trigger actions when the module load - // finishes. - RefPtr<nsScriptLoader> mLoader; - - // The importing module, or nullptr for top level module scripts. Used to - // implement the ancestor list checked when fetching module dependencies. - RefPtr<nsModuleLoadRequest> mParent; - - // Set to a module script object after a successful load or nullptr on - // failure. - RefPtr<nsModuleScript> mModuleScript; - - // A promise that is completed on successful load of this module and all of - // its dependencies, indicating that the module is ready for instantiation and - // evaluation. - MozPromiseHolder<GenericPromise> mReady; - - // Array of imported modules. - nsTArray<RefPtr<nsModuleLoadRequest>> mImports; -}; - -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsModuleLoadRequest) -NS_INTERFACE_MAP_END_INHERITING(nsScriptLoadRequest) - -NS_IMPL_CYCLE_COLLECTION_INHERITED(nsModuleLoadRequest, nsScriptLoadRequest, - mBaseURL, - mLoader, - mParent, - mModuleScript, - mImports) - -NS_IMPL_ADDREF_INHERITED(nsModuleLoadRequest, nsScriptLoadRequest) -NS_IMPL_RELEASE_INHERITED(nsModuleLoadRequest, nsScriptLoadRequest) - -nsModuleLoadRequest::nsModuleLoadRequest(nsIScriptElement* aElement, - uint32_t aVersion, - CORSMode aCORSMode, - const SRIMetadata &aIntegrity, - nsScriptLoader* aLoader) - : nsScriptLoadRequest(nsScriptKind::Module, - aElement, - aVersion, - aCORSMode, - aIntegrity), - mIsTopLevel(true), - mLoader(aLoader) -{} - -inline nsModuleLoadRequest* -nsScriptLoadRequest::AsModuleRequest() +inline ModuleLoadRequest* +ScriptLoadRequest::AsModuleRequest() { MOZ_ASSERT(IsModuleRequest()); - return static_cast<nsModuleLoadRequest*>(this); -} - -void nsModuleLoadRequest::Cancel() -{ - nsScriptLoadRequest::Cancel(); - mModuleScript = nullptr; - mProgress = nsScriptLoadRequest::Progress::Ready; - for (size_t i = 0; i < mImports.Length(); i++) { - mImports[i]->Cancel(); - } - mReady.RejectIfExists(NS_ERROR_FAILURE, __func__); + return static_cast<ModuleLoadRequest*>(this); } -void -nsModuleLoadRequest::SetReady() -{ -#ifdef DEBUG - for (size_t i = 0; i < mImports.Length(); i++) { - MOZ_ASSERT(mImports[i]->IsReadyToRun()); - } -#endif - - nsScriptLoadRequest::SetReady(); - mReady.ResolveIfExists(true, __func__); -} - -void -nsModuleLoadRequest::ModuleLoaded() -{ - // A module that was found to be marked as fetching in the module map has now - // been loaded. - - mModuleScript = mLoader->GetFetchedModule(mURI); - mLoader->StartFetchingModuleDependencies(this); -} - -void -nsModuleLoadRequest::DependenciesLoaded() -{ - // The module and all of its dependencies have been successfully fetched and - // compiled. - - if (!mLoader->InstantiateModuleTree(this)) { - LoadFailed(); - return; - } - - SetReady(); - mLoader->ProcessLoadedModuleTree(this); - mLoader = nullptr; - mParent = nullptr; -} - -void -nsModuleLoadRequest::LoadFailed() -{ - Cancel(); - mLoader->ProcessLoadedModuleTree(this); - mLoader = nullptr; - mParent = nullptr; -} - -////////////////////////////////////////////////////////////// -// nsModuleScript ////////////////////////////////////////////////////////////// -// A single module script. May be used to satisfy multiple load requests. - -class nsModuleScript final : public nsISupports -{ - enum InstantiationState { - Uninstantiated, - Instantiated, - Errored - }; - - RefPtr<nsScriptLoader> mLoader; - nsCOMPtr<nsIURI> mBaseURL; - JS::Heap<JSObject*> mModuleRecord; - JS::Heap<JS::Value> mException; - InstantiationState mInstantiationState; - - ~nsModuleScript(); - -public: - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsModuleScript) - - nsModuleScript(nsScriptLoader* aLoader, - nsIURI* aBaseURL, - JS::Handle<JSObject*> aModuleRecord); - - nsScriptLoader* Loader() const { return mLoader; } - JSObject* ModuleRecord() const { return mModuleRecord; } - JS::Value Exception() const { return mException; } - nsIURI* BaseURL() const { return mBaseURL; } - - void SetInstantiationResult(JS::Handle<JS::Value> aMaybeException); - bool IsUninstantiated() const { - return mInstantiationState == Uninstantiated; - } - bool IsInstantiated() const { - return mInstantiationState == Instantiated; - } - bool InstantiationFailed() const { - return mInstantiationState == Errored; - } - - void UnlinkModuleRecord(); -}; - -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsModuleScript) -NS_INTERFACE_MAP_END - -NS_IMPL_CYCLE_COLLECTION_CLASS(nsModuleScript) - -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsModuleScript) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mLoader) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mBaseURL) - tmp->UnlinkModuleRecord(); -NS_IMPL_CYCLE_COLLECTION_UNLINK_END - -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsModuleScript) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLoader) -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END - -NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsModuleScript) - NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mModuleRecord) - NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mException) -NS_IMPL_CYCLE_COLLECTION_TRACE_END - -NS_IMPL_CYCLE_COLLECTING_ADDREF(nsModuleScript) -NS_IMPL_CYCLE_COLLECTING_RELEASE(nsModuleScript) - -nsModuleScript::nsModuleScript(nsScriptLoader *aLoader, nsIURI* aBaseURL, - JS::Handle<JSObject*> aModuleRecord) - : mLoader(aLoader), - mBaseURL(aBaseURL), - mModuleRecord(aModuleRecord), - mInstantiationState(Uninstantiated) -{ - MOZ_ASSERT(mLoader); - MOZ_ASSERT(mBaseURL); - MOZ_ASSERT(mModuleRecord); - MOZ_ASSERT(mException.isUndefined()); - - // Make module's host defined field point to this module script object. - // This is cleared in the UnlinkModuleRecord(). - JS::SetModuleHostDefinedField(mModuleRecord, JS::PrivateValue(this)); - HoldJSObjects(this); -} - -void -nsModuleScript::UnlinkModuleRecord() -{ - // Remove module's back reference to this object request if present. - if (mModuleRecord) { - MOZ_ASSERT(JS::GetModuleHostDefinedField(mModuleRecord).toPrivate() == - this); - JS::SetModuleHostDefinedField(mModuleRecord, JS::UndefinedValue()); - } - mModuleRecord = nullptr; - mException.setUndefined(); -} - -nsModuleScript::~nsModuleScript() -{ - if (mModuleRecord) { - // The object may be destroyed without being unlinked first. - UnlinkModuleRecord(); - } - DropJSObjects(this); -} - -void -nsModuleScript::SetInstantiationResult(JS::Handle<JS::Value> aMaybeException) -{ - MOZ_ASSERT(mInstantiationState == Uninstantiated); - MOZ_ASSERT(mModuleRecord); - MOZ_ASSERT(mException.isUndefined()); - - if (aMaybeException.isUndefined()) { - mInstantiationState = Instantiated; - } else { - mModuleRecord = nullptr; - mException = aMaybeException; - mInstantiationState = Errored; - } -} - +// ScriptLoadRequestList ////////////////////////////////////////////////////////////// -// nsScriptLoadRequestList -////////////////////////////////////////////////////////////// - -nsScriptLoadRequestList::~nsScriptLoadRequestList() +ScriptLoadRequestList::~ScriptLoadRequestList() { Clear(); } void -nsScriptLoadRequestList::Clear() +ScriptLoadRequestList::Clear() { while (!isEmpty()) { - RefPtr<nsScriptLoadRequest> first = StealFirst(); + RefPtr<ScriptLoadRequest> first = StealFirst(); first->Cancel(); // And just let it go out of scope and die. } @@ -441,9 +162,9 @@ nsScriptLoadRequestList::Clear() #ifdef DEBUG bool -nsScriptLoadRequestList::Contains(nsScriptLoadRequest* aElem) const +ScriptLoadRequestList::Contains(ScriptLoadRequest* aElem) const { - for (const nsScriptLoadRequest* req = getFirst(); + for (const ScriptLoadRequest* req = getFirst(); req; req = req->getNext()) { if (req == aElem) { return true; @@ -455,20 +176,20 @@ nsScriptLoadRequestList::Contains(nsScriptLoadRequest* aElem) const #endif // DEBUG inline void -ImplCycleCollectionUnlink(nsScriptLoadRequestList& aField) +ImplCycleCollectionUnlink(ScriptLoadRequestList& aField) { while (!aField.isEmpty()) { - RefPtr<nsScriptLoadRequest> first = aField.StealFirst(); + RefPtr<ScriptLoadRequest> first = aField.StealFirst(); } } inline void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, - nsScriptLoadRequestList& aField, + ScriptLoadRequestList& aField, const char* aName, uint32_t aFlags) { - for (nsScriptLoadRequest* request = aField.getFirst(); + for (ScriptLoadRequest* request = aField.getFirst(); request; request = request->getNext()) { CycleCollectionNoteChild(aCallback, request, aName, aFlags); @@ -476,18 +197,18 @@ ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, } ////////////////////////////////////////////////////////////// -// nsScriptLoader::PreloadInfo +// ScriptLoader::PreloadInfo ////////////////////////////////////////////////////////////// inline void -ImplCycleCollectionUnlink(nsScriptLoader::PreloadInfo& aField) +ImplCycleCollectionUnlink(ScriptLoader::PreloadInfo& aField) { ImplCycleCollectionUnlink(aField.mRequest); } inline void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, - nsScriptLoader::PreloadInfo& aField, + ScriptLoader::PreloadInfo& aField, const char* aName, uint32_t aFlags = 0) { @@ -495,13 +216,13 @@ ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, } ////////////////////////////////////////////////////////////// -// nsScriptLoader +// ScriptLoader ////////////////////////////////////////////////////////////// -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsScriptLoader) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ScriptLoader) NS_INTERFACE_MAP_END -NS_IMPL_CYCLE_COLLECTION(nsScriptLoader, +NS_IMPL_CYCLE_COLLECTION(ScriptLoader, mNonAsyncExternalScriptInsertedRequests, mLoadingAsyncRequests, mLoadedAsyncRequests, @@ -512,10 +233,10 @@ NS_IMPL_CYCLE_COLLECTION(nsScriptLoader, mPendingChildLoaders, mFetchedModules) -NS_IMPL_CYCLE_COLLECTING_ADDREF(nsScriptLoader) -NS_IMPL_CYCLE_COLLECTING_RELEASE(nsScriptLoader) +NS_IMPL_CYCLE_COLLECTING_ADDREF(ScriptLoader) +NS_IMPL_CYCLE_COLLECTING_RELEASE(ScriptLoader) -nsScriptLoader::nsScriptLoader(nsIDocument *aDocument) +ScriptLoader::ScriptLoader(nsIDocument *aDocument) : mDocument(aDocument), mParserBlockingBlockerCount(0), mBlockerCount(0), @@ -528,7 +249,7 @@ nsScriptLoader::nsScriptLoader(nsIDocument *aDocument) { } -nsScriptLoader::~nsScriptLoader() +ScriptLoader::~ScriptLoader() { mObservers.Clear(); @@ -536,27 +257,27 @@ nsScriptLoader::~nsScriptLoader() mParserBlockingRequest->FireScriptAvailable(NS_ERROR_ABORT); } - for (nsScriptLoadRequest* req = mXSLTRequests.getFirst(); req; + for (ScriptLoadRequest* req = mXSLTRequests.getFirst(); req; req = req->getNext()) { req->FireScriptAvailable(NS_ERROR_ABORT); } - for (nsScriptLoadRequest* req = mDeferRequests.getFirst(); req; + for (ScriptLoadRequest* req = mDeferRequests.getFirst(); req; req = req->getNext()) { req->FireScriptAvailable(NS_ERROR_ABORT); } - for (nsScriptLoadRequest* req = mLoadingAsyncRequests.getFirst(); req; + for (ScriptLoadRequest* req = mLoadingAsyncRequests.getFirst(); req; req = req->getNext()) { req->FireScriptAvailable(NS_ERROR_ABORT); } - for (nsScriptLoadRequest* req = mLoadedAsyncRequests.getFirst(); req; + for (ScriptLoadRequest* req = mLoadedAsyncRequests.getFirst(); req; req = req->getNext()) { req->FireScriptAvailable(NS_ERROR_ABORT); } - for(nsScriptLoadRequest* req = mNonAsyncExternalScriptInsertedRequests.getFirst(); + for(ScriptLoadRequest* req = mNonAsyncExternalScriptInsertedRequests.getFirst(); req; req = req->getNext()) { req->FireScriptAvailable(NS_ERROR_ABORT); @@ -623,11 +344,11 @@ IsScriptEventHandler(nsIContent* aScriptElement) } nsresult -nsScriptLoader::CheckContentPolicy(nsIDocument* aDocument, - nsISupports *aContext, - nsIURI *aURI, - const nsAString &aType, - bool aIsPreLoad) +ScriptLoader::CheckContentPolicy(nsIDocument* aDocument, + nsISupports *aContext, + nsIURI *aURI, + const nsAString &aType, + bool aIsPreLoad) { nsContentPolicyType contentPolicyType = aIsPreLoad ? nsIContentPolicy::TYPE_INTERNAL_SCRIPT_PRELOAD @@ -654,7 +375,7 @@ nsScriptLoader::CheckContentPolicy(nsIDocument* aDocument, } bool -nsScriptLoader::ModuleScriptsEnabled() +ScriptLoader::ModuleScriptsEnabled() { static bool sEnabledForContent = false; static bool sCachedPref = false; @@ -667,7 +388,7 @@ nsScriptLoader::ModuleScriptsEnabled() } bool -nsScriptLoader::ModuleMapContainsModule(nsModuleLoadRequest *aRequest) const +ScriptLoader::ModuleMapContainsModule(ModuleLoadRequest *aRequest) const { // Returns whether we have fetched, or are currently fetching, a module script // for the request's URL. @@ -676,7 +397,7 @@ nsScriptLoader::ModuleMapContainsModule(nsModuleLoadRequest *aRequest) const } bool -nsScriptLoader::IsFetchingModule(nsModuleLoadRequest *aRequest) const +ScriptLoader::IsFetchingModule(ModuleLoadRequest *aRequest) const { bool fetching = mFetchingModules.Contains(aRequest->mURI); MOZ_ASSERT_IF(fetching, !mFetchedModules.Contains(aRequest->mURI)); @@ -684,7 +405,7 @@ nsScriptLoader::IsFetchingModule(nsModuleLoadRequest *aRequest) const } void -nsScriptLoader::SetModuleFetchStarted(nsModuleLoadRequest *aRequest) +ScriptLoader::SetModuleFetchStarted(ModuleLoadRequest *aRequest) { // Update the module map to indicate that a module is currently being fetched. @@ -694,8 +415,8 @@ nsScriptLoader::SetModuleFetchStarted(nsModuleLoadRequest *aRequest) } void -nsScriptLoader::SetModuleFetchFinishedAndResumeWaitingRequests(nsModuleLoadRequest *aRequest, - nsresult aResult) +ScriptLoader::SetModuleFetchFinishedAndResumeWaitingRequests(ModuleLoadRequest *aRequest, + nsresult aResult) { // Update module map with the result of fetching a single module script. The // module script pointer is nullptr on error. @@ -706,7 +427,7 @@ nsScriptLoader::SetModuleFetchFinishedAndResumeWaitingRequests(nsModuleLoadReque MOZ_ALWAYS_TRUE(mFetchingModules.Get(aRequest->mURI, getter_AddRefs(promise))); mFetchingModules.Remove(aRequest->mURI); - RefPtr<nsModuleScript> ms(aRequest->mModuleScript); + RefPtr<ModuleScript> ms(aRequest->mModuleScript); MOZ_ASSERT(NS_SUCCEEDED(aResult) == (ms != nullptr)); mFetchedModules.Put(aRequest->mURI, ms); @@ -720,7 +441,7 @@ nsScriptLoader::SetModuleFetchFinishedAndResumeWaitingRequests(nsModuleLoadReque } RefPtr<GenericPromise> -nsScriptLoader::WaitForModuleFetch(nsModuleLoadRequest *aRequest) +ScriptLoader::WaitForModuleFetch(ModuleLoadRequest *aRequest) { MOZ_ASSERT(ModuleMapContainsModule(aRequest)); @@ -733,7 +454,7 @@ nsScriptLoader::WaitForModuleFetch(nsModuleLoadRequest *aRequest) return promise; } - RefPtr<nsModuleScript> ms; + RefPtr<ModuleScript> ms; MOZ_ALWAYS_TRUE(mFetchedModules.Get(aRequest->mURI, getter_AddRefs(ms))); if (!ms) { return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__); @@ -742,17 +463,17 @@ nsScriptLoader::WaitForModuleFetch(nsModuleLoadRequest *aRequest) return GenericPromise::CreateAndResolve(true, __func__); } -nsModuleScript* -nsScriptLoader::GetFetchedModule(nsIURI* aURL) const +ModuleScript* +ScriptLoader::GetFetchedModule(nsIURI* aURL) const { bool found; - nsModuleScript* ms = mFetchedModules.GetWeak(aURL, &found); + ModuleScript* ms = mFetchedModules.GetWeak(aURL, &found); MOZ_ASSERT(found); return ms; } nsresult -nsScriptLoader::ProcessFetchedModuleSource(nsModuleLoadRequest* aRequest) +ScriptLoader::ProcessFetchedModuleSource(ModuleLoadRequest* aRequest) { MOZ_ASSERT(!aRequest->mModuleScript); @@ -771,7 +492,7 @@ nsScriptLoader::ProcessFetchedModuleSource(nsModuleLoadRequest* aRequest) } nsresult -nsScriptLoader::CreateModuleScript(nsModuleLoadRequest* aRequest) +ScriptLoader::CreateModuleScript(ModuleLoadRequest* aRequest) { MOZ_ASSERT(!aRequest->mModuleScript); MOZ_ASSERT(aRequest->mBaseURL); @@ -825,7 +546,7 @@ nsScriptLoader::CreateModuleScript(nsModuleLoadRequest* aRequest) MOZ_ASSERT(NS_SUCCEEDED(rv) == (module != nullptr)); if (module) { aRequest->mModuleScript = - new nsModuleScript(this, aRequest->mBaseURL, module); + new ModuleScript(this, aRequest->mBaseURL, module); } } @@ -835,7 +556,7 @@ nsScriptLoader::CreateModuleScript(nsModuleLoadRequest* aRequest) } static bool -ThrowTypeError(JSContext* aCx, nsModuleScript* aScript, +ThrowTypeError(JSContext* aCx, ModuleScript* aScript, const nsString& aMessage) { JS::Rooted<JSObject*> module(aCx, aScript->ModuleRecord()); @@ -862,7 +583,7 @@ ThrowTypeError(JSContext* aCx, nsModuleScript* aScript, } static bool -HandleResolveFailure(JSContext* aCx, nsModuleScript* aScript, +HandleResolveFailure(JSContext* aCx, ModuleScript* aScript, const nsAString& aSpecifier) { // TODO: How can we get the line number of the failed import? @@ -874,7 +595,7 @@ HandleResolveFailure(JSContext* aCx, nsModuleScript* aScript, } static bool -HandleModuleNotFound(JSContext* aCx, nsModuleScript* aScript, +HandleModuleNotFound(JSContext* aCx, ModuleScript* aScript, const nsAString& aSpecifier) { // TODO: How can we get the line number of the failed import? @@ -886,7 +607,7 @@ HandleModuleNotFound(JSContext* aCx, nsModuleScript* aScript, } static already_AddRefed<nsIURI> -ResolveModuleSpecifier(nsModuleScript* aScript, +ResolveModuleSpecifier(ModuleScript* aScript, const nsAString& aSpecifier) { // The following module specifiers are allowed by the spec: @@ -921,7 +642,7 @@ ResolveModuleSpecifier(nsModuleScript* aScript, } static nsresult -RequestedModuleIsInAncestorList(nsModuleLoadRequest* aRequest, nsIURI* aURL, bool* aResult) +RequestedModuleIsInAncestorList(ModuleLoadRequest* aRequest, nsIURI* aURL, bool* aResult) { const size_t ImportDepthLimit = 100; @@ -947,9 +668,9 @@ RequestedModuleIsInAncestorList(nsModuleLoadRequest* aRequest, nsIURI* aURL, boo } static nsresult -ResolveRequestedModules(nsModuleLoadRequest* aRequest, nsCOMArray<nsIURI> &aUrls) +ResolveRequestedModules(ModuleLoadRequest* aRequest, nsCOMArray<nsIURI> &aUrls) { - nsModuleScript* ms = aRequest->mModuleScript; + ModuleScript* ms = aRequest->mModuleScript; AutoJSAPI jsapi; if (!jsapi.Init(ms->ModuleRecord())) { @@ -977,7 +698,7 @@ ResolveRequestedModules(nsModuleLoadRequest* aRequest, nsCOMArray<nsIURI> &aUrls } // Let url be the result of resolving a module specifier given module script and requested. - nsModuleScript* ms = aRequest->mModuleScript; + ModuleScript* ms = aRequest->mModuleScript; nsCOMPtr<nsIURI> uri = ResolveModuleSpecifier(ms, specifier); if (!uri) { HandleResolveFailure(cx, ms, specifier); @@ -996,11 +717,11 @@ ResolveRequestedModules(nsModuleLoadRequest* aRequest, nsCOMArray<nsIURI> &aUrls } void -nsScriptLoader::StartFetchingModuleDependencies(nsModuleLoadRequest* aRequest) +ScriptLoader::StartFetchingModuleDependencies(ModuleLoadRequest* aRequest) { MOZ_ASSERT(aRequest->mModuleScript); MOZ_ASSERT(!aRequest->IsReadyToRun()); - aRequest->mProgress = nsModuleLoadRequest::Progress::FetchingImports; + aRequest->mProgress = ModuleLoadRequest::Progress::FetchingImports; nsCOMArray<nsIURI> urls; nsresult rv = ResolveRequestedModules(aRequest, urls); @@ -1028,19 +749,19 @@ nsScriptLoader::StartFetchingModuleDependencies(nsModuleLoadRequest* aRequest) RefPtr<GenericPromise::AllPromiseType> allReady = GenericPromise::All(AbstractThread::GetCurrent(), importsReady); allReady->Then(AbstractThread::GetCurrent(), __func__, aRequest, - &nsModuleLoadRequest::DependenciesLoaded, - &nsModuleLoadRequest::LoadFailed); + &ModuleLoadRequest::DependenciesLoaded, + &ModuleLoadRequest::LoadFailed); } RefPtr<GenericPromise> -nsScriptLoader::StartFetchingModuleAndDependencies(nsModuleLoadRequest* aRequest, - nsIURI* aURI) +ScriptLoader::StartFetchingModuleAndDependencies(ModuleLoadRequest* aRequest, + nsIURI* aURI) { MOZ_ASSERT(aURI); - RefPtr<nsModuleLoadRequest> childRequest = - new nsModuleLoadRequest(aRequest->mElement, aRequest->mJSVersion, - aRequest->mCORSMode, aRequest->mIntegrity, this); + RefPtr<ModuleLoadRequest> childRequest = + new ModuleLoadRequest(aRequest->mElement, aRequest->mJSVersion, + aRequest->mCORSMode, aRequest->mIntegrity, this); childRequest->mIsTopLevel = false; childRequest->mURI = aURI; @@ -1070,7 +791,7 @@ HostResolveImportedModule(JSContext* aCx, unsigned argc, JS::Value* vp) // Let referencing module script be referencingModule.[[HostDefined]]. JS::Value value = JS::GetModuleHostDefinedField(module); - auto script = static_cast<nsModuleScript*>(value.toPrivate()); + auto script = static_cast<ModuleScript*>(value.toPrivate()); MOZ_ASSERT(script->ModuleRecord() == module); // Let url be the result of resolving a module specifier given referencing @@ -1089,7 +810,7 @@ HostResolveImportedModule(JSContext* aCx, unsigned argc, JS::Value* vp) // Let resolved module script be the value of the entry in module map whose // key is url. If no such entry exists, throw a TypeError exception and abort // these steps. - nsModuleScript* ms = script->Loader()->GetFetchedModule(uri); + ModuleScript* ms = script->Loader()->GetFetchedModule(uri); if (!ms) { return HandleModuleNotFound(aCx, script, string); } @@ -1123,7 +844,7 @@ EnsureModuleResolveHook(JSContext* aCx) } void -nsScriptLoader::ProcessLoadedModuleTree(nsModuleLoadRequest* aRequest) +ScriptLoader::ProcessLoadedModuleTree(ModuleLoadRequest* aRequest) { if (aRequest->IsTopLevel()) { MaybeMoveToLoadedList(aRequest); @@ -1136,13 +857,13 @@ nsScriptLoader::ProcessLoadedModuleTree(nsModuleLoadRequest* aRequest) } bool -nsScriptLoader::InstantiateModuleTree(nsModuleLoadRequest* aRequest) +ScriptLoader::InstantiateModuleTree(ModuleLoadRequest* aRequest) { // Perform eager instantiation of the loaded module tree. MOZ_ASSERT(aRequest); - nsModuleScript* ms = aRequest->mModuleScript; + ModuleScript* ms = aRequest->mModuleScript; MOZ_ASSERT(ms); if (!ms || !ms->ModuleRecord()) { return false; @@ -1171,14 +892,14 @@ nsScriptLoader::InstantiateModuleTree(nsModuleLoadRequest* aRequest) // Mark this module and any uninstantiated dependencies found via depth-first // search as instantiated and record any error. - mozilla::Vector<nsModuleLoadRequest*, 1> requests; + mozilla::Vector<ModuleLoadRequest*, 1> requests; if (!requests.append(aRequest)) { return false; } while (!requests.empty()) { - nsModuleLoadRequest* request = requests.popCopy(); - nsModuleScript* ms = request->mModuleScript; + ModuleLoadRequest* request = requests.popCopy(); + ModuleScript* ms = request->mModuleScript; if (!ms->IsUninstantiated()) { continue; } @@ -1198,8 +919,8 @@ nsScriptLoader::InstantiateModuleTree(nsModuleLoadRequest* aRequest) } nsresult -nsScriptLoader::StartLoad(nsScriptLoadRequest *aRequest, const nsAString &aType, - bool aScriptFromHead) +ScriptLoader::StartLoad(ScriptLoadRequest *aRequest, const nsAString &aType, + bool aScriptFromHead) { MOZ_ASSERT(aRequest->IsLoading()); NS_ENSURE_TRUE(mDocument, NS_ERROR_NULL_POINTER); @@ -1212,12 +933,12 @@ nsScriptLoader::StartLoad(nsScriptLoadRequest *aRequest, const nsAString &aType, if (aRequest->IsModuleRequest()) { // Check whether the module has been fetched or is currently being fetched, // and if so wait for it. - nsModuleLoadRequest* request = aRequest->AsModuleRequest(); + ModuleLoadRequest* request = aRequest->AsModuleRequest(); if (ModuleMapContainsModule(request)) { WaitForModuleFetch(request) ->Then(AbstractThread::GetCurrent(), __func__, request, - &nsModuleLoadRequest::ModuleLoaded, - &nsModuleLoadRequest::LoadFailed); + &ModuleLoadRequest::ModuleLoaded, + &ModuleLoadRequest::LoadFailed); return NS_OK; } @@ -1330,8 +1051,8 @@ nsScriptLoader::StartLoad(nsScriptLoadRequest *aRequest, const nsAString &aType, mReporter); } - RefPtr<nsScriptLoadHandler> handler = - new nsScriptLoadHandler(this, aRequest, sriDataVerifier.forget()); + RefPtr<ScriptLoadHandler> handler = + new ScriptLoadHandler(this, aRequest, sriDataVerifier.forget()); nsCOMPtr<nsIIncrementalStreamLoader> loader; rv = NS_NewIncrementalStreamLoader(getter_AddRefs(loader), handler); @@ -1341,22 +1062,22 @@ nsScriptLoader::StartLoad(nsScriptLoadRequest *aRequest, const nsAString &aType, } bool -nsScriptLoader::PreloadURIComparator::Equals(const PreloadInfo &aPi, - nsIURI * const &aURI) const +ScriptLoader::PreloadURIComparator::Equals(const PreloadInfo &aPi, + nsIURI * const &aURI) const { bool same; return NS_SUCCEEDED(aPi.mRequest->mURI->Equals(aURI, &same)) && same; } -class nsScriptRequestProcessor : public Runnable +class ScriptRequestProcessor : public Runnable { private: - RefPtr<nsScriptLoader> mLoader; - RefPtr<nsScriptLoadRequest> mRequest; + RefPtr<ScriptLoader> mLoader; + RefPtr<ScriptLoadRequest> mRequest; public: - nsScriptRequestProcessor(nsScriptLoader* aLoader, - nsScriptLoadRequest* aRequest) + ScriptRequestProcessor(ScriptLoader* aLoader, + ScriptLoadRequest* aRequest) : mLoader(aLoader) , mRequest(aRequest) {} @@ -1428,24 +1149,23 @@ CSPAllowsInlineScript(nsIScriptElement *aElement, nsIDocument *aDocument) return allowInlineScript; } -nsScriptLoadRequest* -nsScriptLoader::CreateLoadRequest(nsScriptKind aKind, - nsIScriptElement* aElement, - uint32_t aVersion, CORSMode aCORSMode, - const SRIMetadata &aIntegrity) +ScriptLoadRequest* +ScriptLoader::CreateLoadRequest(ScriptKind aKind, + nsIScriptElement* aElement, + uint32_t aVersion, CORSMode aCORSMode, + const SRIMetadata &aIntegrity) { - if (aKind == nsScriptKind::Classic) { - return new nsScriptLoadRequest(aKind, aElement, aVersion, aCORSMode, - aIntegrity); + if (aKind == ScriptKind::Classic) { + return new ScriptLoadRequest(aKind, aElement, aVersion, aCORSMode, + aIntegrity); } - MOZ_ASSERT(aKind == nsScriptKind::Module); - return new nsModuleLoadRequest(aElement, aVersion, aCORSMode, aIntegrity, - this); + MOZ_ASSERT(aKind == ScriptKind::Module); + return new ModuleLoadRequest(aElement, aVersion, aCORSMode, aIntegrity, this); } bool -nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement) +ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement) { // We need a document to evaluate scripts. NS_ENSURE_TRUE(mDocument, false); @@ -1471,10 +1191,10 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement) nsAutoString type; bool hasType = aElement->GetScriptType(type); - nsScriptKind scriptKind = nsScriptKind::Classic; + ScriptKind scriptKind = ScriptKind::Classic; if (!type.IsEmpty()) { if (ModuleScriptsEnabled() && type.LowerCaseEqualsASCII("module")) { - scriptKind = nsScriptKind::Module; + scriptKind = ScriptKind::Module; } else { NS_ENSURE_TRUE(ParseTypeAttribute(type, &version), false); } @@ -1498,7 +1218,7 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement) // "The nomodule attribute must not be specified on module scripts (and will // be ignored if it is)." if (ModuleScriptsEnabled() && - scriptKind == nsScriptKind::Classic && + scriptKind == ScriptKind::Classic && scriptContent->IsHTMLElement() && scriptContent->HasAttr(kNameSpaceID_None, nsGkAtoms::nomodule)) { return false; @@ -1506,7 +1226,7 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement) // Step 15. and later in the HTML5 spec nsresult rv = NS_OK; - RefPtr<nsScriptLoadRequest> request; + RefPtr<ScriptLoadRequest> request; if (aElement->GetScriptExternal()) { // external script nsCOMPtr<nsIURI> scriptURI = aElement->GetScriptURI(); @@ -1562,7 +1282,7 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement) integrity); if (!integrity.IsEmpty()) { MOZ_LOG(SRILogHelper::GetSriLog(), mozilla::LogLevel::Debug, - ("nsScriptLoader::ProcessScriptElement, integrity=%s", + ("ScriptLoader::ProcessScriptElement, integrity=%s", NS_ConvertUTF16toUTF8(integrity).get())); nsAutoCString sourceUri; if (mDocument->GetDocumentURI()) { @@ -1704,7 +1424,7 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement) request->mLineNo = aElement->GetScriptLineNumber(); if (request->IsModuleRequest()) { - nsModuleLoadRequest* modReq = request->AsModuleRequest(); + ModuleLoadRequest* modReq = request->AsModuleRequest(); modReq->mBaseURL = mDocument->GetDocBaseURI(); rv = CreateModuleScript(modReq); NS_ENSURE_SUCCESS(rv, false); @@ -1716,7 +1436,7 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement) } return false; } - request->mProgress = nsScriptLoadRequest::Progress::Ready; + request->mProgress = ScriptLoadRequest::Progress::Ready; if (aElement->GetParserCreated() == FROM_PARSER_XSLT && (!ReadyToExecuteParserBlockingScripts() || !mXSLTRequests.isEmpty())) { // Need to maintain order for XSLT-inserted scripts @@ -1728,7 +1448,7 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement) if (aElement->GetParserCreated() == NOT_FROM_PARSER) { NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(), "A script-inserted script is inserted without an update batch?"); - nsContentUtils::AddScriptRunner(new nsScriptRequestProcessor(this, + nsContentUtils::AddScriptRunner(new ScriptRequestProcessor(this, request)); return false; } @@ -1758,13 +1478,13 @@ namespace { class NotifyOffThreadScriptLoadCompletedRunnable : public Runnable { - RefPtr<nsScriptLoadRequest> mRequest; - RefPtr<nsScriptLoader> mLoader; + RefPtr<ScriptLoadRequest> mRequest; + RefPtr<ScriptLoader> mLoader; void *mToken; public: - NotifyOffThreadScriptLoadCompletedRunnable(nsScriptLoadRequest* aRequest, - nsScriptLoader* aLoader) + NotifyOffThreadScriptLoadCompletedRunnable(ScriptLoadRequest* aRequest, + ScriptLoader* aLoader) : mRequest(aRequest), mLoader(aLoader), mToken(nullptr) {} @@ -1781,16 +1501,16 @@ public: } /* anonymous namespace */ nsresult -nsScriptLoader::ProcessOffThreadRequest(nsScriptLoadRequest* aRequest) +ScriptLoader::ProcessOffThreadRequest(ScriptLoadRequest* aRequest) { - MOZ_ASSERT(aRequest->mProgress == nsScriptLoadRequest::Progress::Compiling); + MOZ_ASSERT(aRequest->mProgress == ScriptLoadRequest::Progress::Compiling); MOZ_ASSERT(!aRequest->mWasCompiledOMT); aRequest->mWasCompiledOMT = true; if (aRequest->IsModuleRequest()) { MOZ_ASSERT(aRequest->mOffThreadToken); - nsModuleLoadRequest* request = aRequest->AsModuleRequest(); + ModuleLoadRequest* request = aRequest->AsModuleRequest(); nsresult rv = ProcessFetchedModuleSource(request); if (NS_FAILED(rv)) { request->LoadFailed(); @@ -1837,8 +1557,8 @@ NotifyOffThreadScriptLoadCompletedRunnable::Run() // We want these to be dropped on the main thread, once we return from this // function. - RefPtr<nsScriptLoadRequest> request = mRequest.forget(); - RefPtr<nsScriptLoader> loader = mLoader.forget(); + RefPtr<ScriptLoadRequest> request = mRequest.forget(); + RefPtr<ScriptLoader> loader = mLoader.forget(); request->mOffThreadToken = mToken; nsresult rv = loader->ProcessOffThreadRequest(request); @@ -1856,7 +1576,7 @@ OffThreadScriptLoaderCallback(void *aToken, void *aCallbackData) } nsresult -nsScriptLoader::AttemptAsyncScriptCompile(nsScriptLoadRequest* aRequest) +ScriptLoader::AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest) { MOZ_ASSERT_IF(!aRequest->IsModuleRequest(), aRequest->IsReadyToRun()); MOZ_ASSERT(!aRequest->mWasCompiledOMT); @@ -1909,14 +1629,14 @@ nsScriptLoader::AttemptAsyncScriptCompile(nsScriptLoadRequest* aRequest) } mDocument->BlockOnload(); - aRequest->mProgress = nsScriptLoadRequest::Progress::Compiling; + aRequest->mProgress = ScriptLoadRequest::Progress::Compiling; Unused << runnable.forget(); return NS_OK; } nsresult -nsScriptLoader::CompileOffThreadOrProcessRequest(nsScriptLoadRequest* aRequest) +ScriptLoader::CompileOffThreadOrProcessRequest(ScriptLoadRequest* aRequest) { NS_ASSERTION(nsContentUtils::IsSafeToRunScript(), "Processing requests when running scripts is unsafe."); @@ -1934,7 +1654,7 @@ nsScriptLoader::CompileOffThreadOrProcessRequest(nsScriptLoadRequest* aRequest) } SourceBufferHolder -nsScriptLoader::GetScriptSource(nsScriptLoadRequest* aRequest, nsAutoString& inlineData) +ScriptLoader::GetScriptSource(ScriptLoadRequest* aRequest, nsAutoString& inlineData) { // Return a SourceBufferHolder object holding the script's source text. // |inlineData| is used to hold the text for inline objects. @@ -1955,7 +1675,7 @@ nsScriptLoader::GetScriptSource(nsScriptLoadRequest* aRequest, nsAutoString& inl } nsresult -nsScriptLoader::ProcessRequest(nsScriptLoadRequest* aRequest) +ScriptLoader::ProcessRequest(ScriptLoadRequest* aRequest) { NS_ASSERTION(nsContentUtils::IsSafeToRunScript(), "Processing requests when running scripts is unsafe."); @@ -2055,8 +1775,8 @@ nsScriptLoader::ProcessRequest(nsScriptLoadRequest* aRequest) } void -nsScriptLoader::FireScriptAvailable(nsresult aResult, - nsScriptLoadRequest* aRequest) +ScriptLoader::FireScriptAvailable(nsresult aResult, + ScriptLoadRequest* aRequest) { for (int32_t i = 0; i < mObservers.Count(); i++) { nsCOMPtr<nsIScriptLoaderObserver> obs = mObservers[i]; @@ -2069,8 +1789,8 @@ nsScriptLoader::FireScriptAvailable(nsresult aResult, } void -nsScriptLoader::FireScriptEvaluated(nsresult aResult, - nsScriptLoadRequest* aRequest) +ScriptLoader::FireScriptEvaluated(nsresult aResult, + ScriptLoadRequest* aRequest) { for (int32_t i = 0; i < mObservers.Count(); i++) { nsCOMPtr<nsIScriptLoaderObserver> obs = mObservers[i]; @@ -2082,7 +1802,7 @@ nsScriptLoader::FireScriptEvaluated(nsresult aResult, } already_AddRefed<nsIScriptGlobalObject> -nsScriptLoader::GetScriptGlobalObject() +ScriptLoader::GetScriptGlobalObject() { nsCOMPtr<nsIDocument> master = mDocument->MasterDocument(); nsPIDOMWindowInner *pwin = master->GetInnerWindow(); @@ -2103,10 +1823,10 @@ nsScriptLoader::GetScriptGlobalObject() } nsresult -nsScriptLoader::FillCompileOptionsForRequest(const AutoJSAPI&jsapi, - nsScriptLoadRequest* aRequest, - JS::Handle<JSObject*> aScopeChain, - JS::CompileOptions* aOptions) +ScriptLoader::FillCompileOptionsForRequest(const AutoJSAPI&jsapi, + ScriptLoadRequest* aRequest, + JS::Handle<JSObject*> aScopeChain, + JS::CompileOptions* aOptions) { // It's very important to use aRequest->mURI, not the final URI of the channel // aRequest ended up getting script data from, as the script filename. @@ -2150,7 +1870,7 @@ nsScriptLoader::FillCompileOptionsForRequest(const AutoJSAPI&jsapi, } nsresult -nsScriptLoader::EvaluateScript(nsScriptLoadRequest* aRequest) +ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest) { // We need a document to evaluate scripts. if (!mDocument) { @@ -2211,10 +1931,10 @@ nsScriptLoader::EvaluateScript(nsScriptLoadRequest* aRequest) } if (aRequest->IsModuleRequest()) { - nsModuleLoadRequest* request = aRequest->AsModuleRequest(); + ModuleLoadRequest* request = aRequest->AsModuleRequest(); MOZ_ASSERT(request->mModuleScript); MOZ_ASSERT(!request->mOffThreadToken); - nsModuleScript* ms = request->mModuleScript; + ModuleScript* ms = request->mModuleScript; MOZ_ASSERT(!ms->IsUninstantiated()); if (ms->InstantiationFailed()) { JS::Rooted<JS::Value> exception(aes.cx(), ms->Exception()); @@ -2243,7 +1963,7 @@ nsScriptLoader::EvaluateScript(nsScriptLoadRequest* aRequest) } void -nsScriptLoader::ProcessPendingRequestsAsync() +ScriptLoader::ProcessPendingRequestsAsync() { if (mParserBlockingRequest || !mXSLTRequests.isEmpty() || @@ -2252,14 +1972,14 @@ nsScriptLoader::ProcessPendingRequestsAsync() !mDeferRequests.isEmpty() || !mPendingChildLoaders.IsEmpty()) { NS_DispatchToCurrentThread(NewRunnableMethod(this, - &nsScriptLoader::ProcessPendingRequests)); + &ScriptLoader::ProcessPendingRequests)); } } void -nsScriptLoader::ProcessPendingRequests() +ScriptLoader::ProcessPendingRequests() { - RefPtr<nsScriptLoadRequest> request; + RefPtr<ScriptLoadRequest> request; if (mParserBlockingRequest && mParserBlockingRequest->IsReadyToRun() && @@ -2311,7 +2031,7 @@ nsScriptLoader::ProcessPendingRequests() while (!mPendingChildLoaders.IsEmpty() && ReadyToExecuteParserBlockingScripts()) { - RefPtr<nsScriptLoader> child = mPendingChildLoaders[0]; + RefPtr<ScriptLoader> child = mPendingChildLoaders[0]; mPendingChildLoaders.RemoveElementAt(0); child->RemoveParserBlockingScriptExecutionBlocker(); } @@ -2337,7 +2057,7 @@ nsScriptLoader::ProcessPendingRequests() } bool -nsScriptLoader::ReadyToExecuteParserBlockingScripts() +ScriptLoader::ReadyToExecuteParserBlockingScripts() { // Make sure the SelfReadyToExecuteParserBlockingScripts check is first, so // that we don't block twice on an ancestor. @@ -2346,7 +2066,7 @@ nsScriptLoader::ReadyToExecuteParserBlockingScripts() } for (nsIDocument* doc = mDocument; doc; doc = doc->GetParentDocument()) { - nsScriptLoader* ancestor = doc->ScriptLoader(); + ScriptLoader* ancestor = doc->ScriptLoader(); if (!ancestor->SelfReadyToExecuteParserBlockingScripts() && ancestor->AddPendingChildLoader(this)) { AddParserBlockingScriptExecutionBlocker(); @@ -2394,10 +2114,10 @@ nsScriptLoader::ReadyToExecuteParserBlockingScripts() } /* static */ nsresult -nsScriptLoader::ConvertToUTF16(nsIChannel* aChannel, const uint8_t* aData, - uint32_t aLength, const nsAString& aHintCharset, - nsIDocument* aDocument, - char16_t*& aBufOut, size_t& aLengthOut) +ScriptLoader::ConvertToUTF16(nsIChannel* aChannel, const uint8_t* aData, + uint32_t aLength, const nsAString& aHintCharset, + nsIDocument* aDocument, + char16_t*& aBufOut, size_t& aLengthOut) { if (!aLength) { aBufOut = nullptr; @@ -2474,14 +2194,14 @@ nsScriptLoader::ConvertToUTF16(nsIChannel* aChannel, const uint8_t* aData, } nsresult -nsScriptLoader::OnStreamComplete(nsIIncrementalStreamLoader* aLoader, - nsISupports* aContext, - nsresult aChannelStatus, - nsresult aSRIStatus, - mozilla::Vector<char16_t> &aString, - mozilla::dom::SRICheckDataVerifier* aSRIDataVerifier) -{ - nsScriptLoadRequest* request = static_cast<nsScriptLoadRequest*>(aContext); +ScriptLoader::OnStreamComplete(nsIIncrementalStreamLoader* aLoader, + nsISupports* aContext, + nsresult aChannelStatus, + nsresult aSRIStatus, + mozilla::Vector<char16_t> &aString, + mozilla::dom::SRICheckDataVerifier* aSRIDataVerifier) +{ + ScriptLoadRequest* request = static_cast<ScriptLoadRequest*>(aContext); NS_ASSERTION(request, "null request in stream complete handler"); NS_ENSURE_TRUE(request, NS_ERROR_FAILURE); @@ -2511,7 +2231,7 @@ nsScriptLoader::OnStreamComplete(nsIIncrementalStreamLoader* aLoader, if (loadInfo->GetEnforceSRI()) { MOZ_LOG(SRILogHelper::GetSriLog(), mozilla::LogLevel::Debug, - ("nsScriptLoader::OnStreamComplete, required SRI not found")); + ("ScriptLoader::OnStreamComplete, required SRI not found")); nsCOMPtr<nsIContentSecurityPolicy> csp; loadInfo->LoadingPrincipal()->GetCsp(getter_AddRefs(csp)); nsAutoCString violationURISpec; @@ -2544,29 +2264,29 @@ nsScriptLoader::OnStreamComplete(nsIIncrementalStreamLoader* aLoader, MOZ_ASSERT_IF(request->IsModuleRequest(), request->AsModuleRequest()->IsTopLevel()); if (request->isInList()) { - RefPtr<nsScriptLoadRequest> req = mDeferRequests.Steal(request); + RefPtr<ScriptLoadRequest> req = mDeferRequests.Steal(request); FireScriptAvailable(rv, req); } } else if (request->mIsAsync) { MOZ_ASSERT_IF(request->IsModuleRequest(), request->AsModuleRequest()->IsTopLevel()); if (request->isInList()) { - RefPtr<nsScriptLoadRequest> req = mLoadingAsyncRequests.Steal(request); + RefPtr<ScriptLoadRequest> req = mLoadingAsyncRequests.Steal(request); FireScriptAvailable(rv, req); } } else if (request->mIsNonAsyncScriptInserted) { if (request->isInList()) { - RefPtr<nsScriptLoadRequest> req = + RefPtr<ScriptLoadRequest> req = mNonAsyncExternalScriptInsertedRequests.Steal(request); FireScriptAvailable(rv, req); } } else if (request->mIsXSLT) { if (request->isInList()) { - RefPtr<nsScriptLoadRequest> req = mXSLTRequests.Steal(request); + RefPtr<ScriptLoadRequest> req = mXSLTRequests.Steal(request); FireScriptAvailable(rv, req); } } else if (request->IsModuleRequest()) { - nsModuleLoadRequest* modReq = request->AsModuleRequest(); + ModuleLoadRequest* modReq = request->AsModuleRequest(); MOZ_ASSERT(!modReq->IsTopLevel()); MOZ_ASSERT(!modReq->isInList()); modReq->Cancel(); @@ -2597,19 +2317,19 @@ nsScriptLoader::OnStreamComplete(nsIIncrementalStreamLoader* aLoader, } void -nsScriptLoader::UnblockParser(nsScriptLoadRequest* aParserBlockingRequest) +ScriptLoader::UnblockParser(ScriptLoadRequest* aParserBlockingRequest) { aParserBlockingRequest->mElement->UnblockParser(); } void -nsScriptLoader::ContinueParserAsync(nsScriptLoadRequest* aParserBlockingRequest) +ScriptLoader::ContinueParserAsync(ScriptLoadRequest* aParserBlockingRequest) { aParserBlockingRequest->mElement->ContinueParserAsync(); } uint32_t -nsScriptLoader::NumberOfProcessors() +ScriptLoader::NumberOfProcessors() { if (mNumberOfProcessors > 0) return mNumberOfProcessors; @@ -2621,7 +2341,7 @@ nsScriptLoader::NumberOfProcessors() } void -nsScriptLoader::MaybeMoveToLoadedList(nsScriptLoadRequest* aRequest) +ScriptLoader::MaybeMoveToLoadedList(ScriptLoadRequest* aRequest) { MOZ_ASSERT(aRequest->IsReadyToRun()); @@ -2631,17 +2351,17 @@ nsScriptLoader::MaybeMoveToLoadedList(nsScriptLoadRequest* aRequest) if (aRequest->mIsAsync) { MOZ_ASSERT(aRequest->isInList()); if (aRequest->isInList()) { - RefPtr<nsScriptLoadRequest> req = mLoadingAsyncRequests.Steal(aRequest); + RefPtr<ScriptLoadRequest> req = mLoadingAsyncRequests.Steal(aRequest); mLoadedAsyncRequests.AppendElement(req); } } } nsresult -nsScriptLoader::PrepareLoadedRequest(nsScriptLoadRequest* aRequest, - nsIIncrementalStreamLoader* aLoader, - nsresult aStatus, - mozilla::Vector<char16_t> &aString) +ScriptLoader::PrepareLoadedRequest(ScriptLoadRequest* aRequest, + nsIIncrementalStreamLoader* aLoader, + nsresult aStatus, + mozilla::Vector<char16_t> &aString) { if (NS_FAILED(aStatus)) { return aStatus; @@ -2713,7 +2433,7 @@ nsScriptLoader::PrepareLoadedRequest(nsScriptLoadRequest* aRequest, "aRequest should be pending!"); if (aRequest->IsModuleRequest()) { - nsModuleLoadRequest* request = aRequest->AsModuleRequest(); + ModuleLoadRequest* request = aRequest->AsModuleRequest(); // When loading a module, only responses with a JavaScript MIME type are // acceptable. @@ -2744,7 +2464,7 @@ nsScriptLoader::PrepareLoadedRequest(nsScriptLoadRequest* aRequest, MOZ_ASSERT(!aRequest->IsModuleRequest()); nsresult rv = AttemptAsyncScriptCompile(aRequest); if (rv == NS_OK) { - MOZ_ASSERT(aRequest->mProgress == nsScriptLoadRequest::Progress::Compiling, + MOZ_ASSERT(aRequest->mProgress == ScriptLoadRequest::Progress::Compiling, "Request should be off-thread compiling now."); return NS_OK; } @@ -2763,7 +2483,7 @@ nsScriptLoader::PrepareLoadedRequest(nsScriptLoadRequest* aRequest, } void -nsScriptLoader::ParsingComplete(bool aTerminated) +ScriptLoader::ParsingComplete(bool aTerminated) { if (mDeferEnabled) { // Have to check because we apparently get ParsingComplete @@ -2789,12 +2509,12 @@ nsScriptLoader::ParsingComplete(bool aTerminated) } void -nsScriptLoader::PreloadURI(nsIURI *aURI, const nsAString &aCharset, - const nsAString &aType, - const nsAString &aCrossOrigin, - const nsAString& aIntegrity, - bool aScriptFromHead, - const mozilla::net::ReferrerPolicy aReferrerPolicy) +ScriptLoader::PreloadURI(nsIURI *aURI, const nsAString &aCharset, + const nsAString &aType, + const nsAString &aCrossOrigin, + const nsAString& aIntegrity, + bool aScriptFromHead, + const mozilla::net::ReferrerPolicy aReferrerPolicy) { NS_ENSURE_TRUE_VOID(mDocument); // Check to see if scripts has been turned off. @@ -2810,7 +2530,7 @@ nsScriptLoader::PreloadURI(nsIURI *aURI, const nsAString &aCharset, SRIMetadata sriMetadata; if (!aIntegrity.IsEmpty()) { MOZ_LOG(SRILogHelper::GetSriLog(), mozilla::LogLevel::Debug, - ("nsScriptLoader::PreloadURI, integrity=%s", + ("ScriptLoader::PreloadURI, integrity=%s", NS_ConvertUTF16toUTF8(aIntegrity).get())); nsAutoCString sourceUri; if (mDocument->GetDocumentURI()) { @@ -2819,8 +2539,8 @@ nsScriptLoader::PreloadURI(nsIURI *aURI, const nsAString &aCharset, SRICheck::IntegrityMetadata(aIntegrity, sourceUri, mReporter, &sriMetadata); } - RefPtr<nsScriptLoadRequest> request = - CreateLoadRequest(nsScriptKind::Classic, nullptr, 0, + RefPtr<ScriptLoadRequest> request = + CreateLoadRequest(ScriptKind::Classic, nullptr, 0, Element::StringToCORSMode(aCrossOrigin), sriMetadata); request->mURI = aURI; request->mIsInline = false; @@ -2837,7 +2557,7 @@ nsScriptLoader::PreloadURI(nsIURI *aURI, const nsAString &aCharset, } void -nsScriptLoader::AddDeferRequest(nsScriptLoadRequest* aRequest) +ScriptLoader::AddDeferRequest(ScriptLoadRequest* aRequest) { aRequest->mIsDefer = true; mDeferRequests.AppendElement(aRequest); @@ -2850,7 +2570,7 @@ nsScriptLoader::AddDeferRequest(nsScriptLoadRequest* aRequest) } bool -nsScriptLoader::MaybeRemovedDeferRequests() +ScriptLoader::MaybeRemovedDeferRequests() { if (mDeferRequests.isEmpty() && mDocument && mBlockingDOMContentLoaded) { @@ -2861,201 +2581,5 @@ nsScriptLoader::MaybeRemovedDeferRequests() return false; } -////////////////////////////////////////////////////////////// -// nsScriptLoadHandler -////////////////////////////////////////////////////////////// - -nsScriptLoadHandler::nsScriptLoadHandler(nsScriptLoader *aScriptLoader, - nsScriptLoadRequest *aRequest, - mozilla::dom::SRICheckDataVerifier *aSRIDataVerifier) - : mScriptLoader(aScriptLoader), - mRequest(aRequest), - mSRIDataVerifier(aSRIDataVerifier), - mSRIStatus(NS_OK), - mDecoder(), - mBuffer() -{} - -nsScriptLoadHandler::~nsScriptLoadHandler() -{} - -NS_IMPL_ISUPPORTS(nsScriptLoadHandler, nsIIncrementalStreamLoaderObserver) - -NS_IMETHODIMP -nsScriptLoadHandler::OnIncrementalData(nsIIncrementalStreamLoader* aLoader, - nsISupports* aContext, - uint32_t aDataLength, - const uint8_t* aData, - uint32_t *aConsumedLength) -{ - if (mRequest->IsCanceled()) { - // If request cancelled, ignore any incoming data. - *aConsumedLength = aDataLength; - return NS_OK; - } - - if (!EnsureDecoder(aLoader, aData, aDataLength, - /* aEndOfStream = */ false)) { - return NS_OK; - } - - // Below we will/shall consume entire data chunk. - *aConsumedLength = aDataLength; - - // Decoder has already been initialized. -- trying to decode all loaded bytes. - nsresult rv = TryDecodeRawData(aData, aDataLength, - /* aEndOfStream = */ false); - NS_ENSURE_SUCCESS(rv, rv); - - // If SRI is required for this load, appending new bytes to the hash. - if (mSRIDataVerifier && NS_SUCCEEDED(mSRIStatus)) { - mSRIStatus = mSRIDataVerifier->Update(aDataLength, aData); - } - - return rv; -} - -nsresult -nsScriptLoadHandler::TryDecodeRawData(const uint8_t* aData, - uint32_t aDataLength, - bool aEndOfStream) -{ - int32_t srcLen = aDataLength; - const char* src = reinterpret_cast<const char *>(aData); - int32_t dstLen; - nsresult rv = - mDecoder->GetMaxLength(src, srcLen, &dstLen); - - NS_ENSURE_SUCCESS(rv, rv); - - uint32_t haveRead = mBuffer.length(); - - CheckedInt<uint32_t> capacity = haveRead; - capacity += dstLen; - - if (!capacity.isValid() || !mBuffer.reserve(capacity.value())) { - return NS_ERROR_OUT_OF_MEMORY; - } - - rv = mDecoder->Convert(src, - &srcLen, - mBuffer.begin() + haveRead, - &dstLen); - - NS_ENSURE_SUCCESS(rv, rv); - - haveRead += dstLen; - MOZ_ASSERT(haveRead <= capacity.value(), "mDecoder produced more data than expected"); - MOZ_ALWAYS_TRUE(mBuffer.resizeUninitialized(haveRead)); - - return NS_OK; -} - -bool -nsScriptLoadHandler::EnsureDecoder(nsIIncrementalStreamLoader *aLoader, - const uint8_t* aData, - uint32_t aDataLength, - bool aEndOfStream) -{ - // Check if decoder has already been created. - if (mDecoder) { - return true; - } - - nsAutoCString charset; - - // JavaScript modules are always UTF-8. - if (mRequest->IsModuleRequest()) { - charset = "UTF-8"; - mDecoder = EncodingUtils::DecoderForEncoding(charset); - return true; - } - - // Determine if BOM check should be done. This occurs either - // if end-of-stream has been reached, or at least 3 bytes have - // been read from input. - if (!aEndOfStream && (aDataLength < 3)) { - return false; - } - - // Do BOM detection. - if (nsContentUtils::CheckForBOM(aData, aDataLength, charset)) { - mDecoder = EncodingUtils::DecoderForEncoding(charset); - return true; - } - - // BOM detection failed, check content stream for charset. - nsCOMPtr<nsIRequest> req; - nsresult rv = aLoader->GetRequest(getter_AddRefs(req)); - NS_ASSERTION(req, "StreamLoader's request went away prematurely"); - NS_ENSURE_SUCCESS(rv, false); - - nsCOMPtr<nsIChannel> channel = do_QueryInterface(req); - - if (channel && - NS_SUCCEEDED(channel->GetContentCharset(charset)) && - EncodingUtils::FindEncodingForLabel(charset, charset)) { - mDecoder = EncodingUtils::DecoderForEncoding(charset); - return true; - } - - // Check the hint charset from the script element or preload - // request. - nsAutoString hintCharset; - if (!mRequest->IsPreload()) { - mRequest->mElement->GetScriptCharset(hintCharset); - } else { - nsTArray<nsScriptLoader::PreloadInfo>::index_type i = - mScriptLoader->mPreloads.IndexOf(mRequest, 0, - nsScriptLoader::PreloadRequestComparator()); - - NS_ASSERTION(i != mScriptLoader->mPreloads.NoIndex, - "Incorrect preload bookkeeping"); - hintCharset = mScriptLoader->mPreloads[i].mCharset; - } - - if (EncodingUtils::FindEncodingForLabel(hintCharset, charset)) { - mDecoder = EncodingUtils::DecoderForEncoding(charset); - return true; - } - - // Get the charset from the charset of the document. - if (mScriptLoader->mDocument) { - charset = mScriptLoader->mDocument->GetDocumentCharacterSet(); - mDecoder = EncodingUtils::DecoderForEncoding(charset); - return true; - } - - // Curiously, there are various callers that don't pass aDocument. The - // fallback in the old code was ISO-8859-1, which behaved like - // windows-1252. Saying windows-1252 for clarity and for compliance - // with the Encoding Standard. - charset = "windows-1252"; - mDecoder = EncodingUtils::DecoderForEncoding(charset); - return true; -} - -NS_IMETHODIMP -nsScriptLoadHandler::OnStreamComplete(nsIIncrementalStreamLoader* aLoader, - nsISupports* aContext, - nsresult aStatus, - uint32_t aDataLength, - const uint8_t* aData) -{ - if (!mRequest->IsCanceled()) { - DebugOnly<bool> encoderSet = - EnsureDecoder(aLoader, aData, aDataLength, /* aEndOfStream = */ true); - MOZ_ASSERT(encoderSet); - DebugOnly<nsresult> rv = TryDecodeRawData(aData, aDataLength, - /* aEndOfStream = */ true); - - // If SRI is required for this load, appending new bytes to the hash. - if (mSRIDataVerifier && NS_SUCCEEDED(mSRIStatus)) { - mSRIStatus = mSRIDataVerifier->Update(aDataLength, aData); - } - } - - // we have to mediate and use mRequest. - return mScriptLoader->OnStreamComplete(aLoader, mRequest, aStatus, mSRIStatus, - mBuffer, mSRIDataVerifier); -} +} // dom namespace +} // mozilla namespace diff --git a/dom/base/nsScriptLoader.h b/dom/script/ScriptLoader.h index a00239be5..3c428deea 100644 --- a/dom/base/nsScriptLoader.h +++ b/dom/script/ScriptLoader.h @@ -4,12 +4,8 @@ * 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/. */ -/* - * A class that handles loading and evaluation of <script> elements. - */ - -#ifndef __nsScriptLoader_h__ -#define __nsScriptLoader_h__ +#ifndef mozilla_dom_ScriptLoader_h +#define mozilla_dom_ScriptLoader_h #include "nsCOMPtr.h" #include "nsRefPtrHashtable.h" @@ -25,14 +21,10 @@ #include "mozilla/CORSMode.h" #include "mozilla/dom/SRIMetadata.h" #include "mozilla/dom/SRICheck.h" -#include "mozilla/LinkedList.h" #include "mozilla/MozPromise.h" #include "mozilla/net/ReferrerPolicy.h" #include "mozilla/Vector.h" -class nsModuleLoadRequest; -class nsModuleScript; -class nsScriptLoadRequestList; class nsIURI; namespace JS { @@ -41,37 +33,39 @@ namespace JS { namespace mozilla { namespace dom { + class AutoJSAPI; -} // namespace dom -} // namespace mozilla +class ModuleLoadRequest; +class ModuleScript; +class ScriptLoadRequestList; ////////////////////////////////////////////////////////////// // Per-request data structure ////////////////////////////////////////////////////////////// -enum class nsScriptKind { +enum class ScriptKind { Classic, Module }; -class nsScriptLoadRequest : public nsISupports, - private mozilla::LinkedListElement<nsScriptLoadRequest> +class ScriptLoadRequest : public nsISupports, + private mozilla::LinkedListElement<ScriptLoadRequest> { - typedef LinkedListElement<nsScriptLoadRequest> super; + typedef LinkedListElement<ScriptLoadRequest> super; - // Allow LinkedListElement<nsScriptLoadRequest> to cast us to itself as needed. - friend class mozilla::LinkedListElement<nsScriptLoadRequest>; - friend class nsScriptLoadRequestList; + // Allow LinkedListElement<ScriptLoadRequest> to cast us to itself as needed. + friend class mozilla::LinkedListElement<ScriptLoadRequest>; + friend class ScriptLoadRequestList; protected: - virtual ~nsScriptLoadRequest(); + virtual ~ScriptLoadRequest(); public: - nsScriptLoadRequest(nsScriptKind aKind, - nsIScriptElement* aElement, - uint32_t aVersion, - mozilla::CORSMode aCORSMode, - const mozilla::dom::SRIMetadata &aIntegrity) + ScriptLoadRequest(ScriptKind aKind, + nsIScriptElement* aElement, + uint32_t aVersion, + mozilla::CORSMode aCORSMode, + const mozilla::dom::SRIMetadata &aIntegrity) : mKind(aKind), mElement(aElement), mProgress(Progress::Loading), @@ -95,14 +89,14 @@ public: } NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_CLASS(nsScriptLoadRequest) + NS_DECL_CYCLE_COLLECTION_CLASS(ScriptLoadRequest) bool IsModuleRequest() const { - return mKind == nsScriptKind::Module; + return mKind == ScriptKind::Module; } - nsModuleLoadRequest* AsModuleRequest(); + ModuleLoadRequest* AsModuleRequest(); void FireScriptAvailable(nsresult aResult) { @@ -154,7 +148,7 @@ public: using super::getNext; using super::isInList; - const nsScriptKind mKind; + const ScriptKind mKind; nsCOMPtr<nsIScriptElement> mElement; Progress mProgress; // Are we still waiting for a load to complete? bool mIsInline; // Is the script inline or loaded? @@ -179,23 +173,23 @@ public: mozilla::net::ReferrerPolicy mReferrerPolicy; }; -class nsScriptLoadRequestList : private mozilla::LinkedList<nsScriptLoadRequest> +class ScriptLoadRequestList : private mozilla::LinkedList<ScriptLoadRequest> { - typedef mozilla::LinkedList<nsScriptLoadRequest> super; + typedef mozilla::LinkedList<ScriptLoadRequest> super; public: - ~nsScriptLoadRequestList(); + ~ScriptLoadRequestList(); void Clear(); #ifdef DEBUG - bool Contains(nsScriptLoadRequest* aElem) const; + bool Contains(ScriptLoadRequest* aElem) const; #endif // DEBUG using super::getFirst; using super::isEmpty; - void AppendElement(nsScriptLoadRequest* aElem) + void AppendElement(ScriptLoadRequest* aElem) { MOZ_ASSERT(!aElem->isInList()); NS_ADDREF(aElem); @@ -203,36 +197,37 @@ public: } MOZ_MUST_USE - already_AddRefed<nsScriptLoadRequest> Steal(nsScriptLoadRequest* aElem) + already_AddRefed<ScriptLoadRequest> Steal(ScriptLoadRequest* aElem) { aElem->removeFrom(*this); return dont_AddRef(aElem); } MOZ_MUST_USE - already_AddRefed<nsScriptLoadRequest> StealFirst() + already_AddRefed<ScriptLoadRequest> StealFirst() { MOZ_ASSERT(!isEmpty()); return Steal(getFirst()); } - void Remove(nsScriptLoadRequest* aElem) + void Remove(ScriptLoadRequest* aElem) { aElem->removeFrom(*this); NS_RELEASE(aElem); } }; +class ScriptLoadHandler; ////////////////////////////////////////////////////////////// // Script loader implementation ////////////////////////////////////////////////////////////// -class nsScriptLoader final : public nsISupports +class ScriptLoader final : public nsISupports { class MOZ_STACK_CLASS AutoCurrentScriptUpdater { public: - AutoCurrentScriptUpdater(nsScriptLoader* aScriptLoader, + AutoCurrentScriptUpdater(ScriptLoader* aScriptLoader, nsIScriptElement* aCurrentScript) : mOldScript(aScriptLoader->mCurrentScript) , mScriptLoader(aScriptLoader) @@ -245,19 +240,19 @@ class nsScriptLoader final : public nsISupports } private: nsCOMPtr<nsIScriptElement> mOldScript; - nsScriptLoader* mScriptLoader; + ScriptLoader* mScriptLoader; }; - friend class nsModuleLoadRequest; - friend class nsScriptRequestProcessor; - friend class nsScriptLoadHandler; + friend class ModuleLoadRequest; + friend class ScriptRequestProcessor; + friend class ScriptLoadHandler; friend class AutoCurrentScriptUpdater; public: - explicit nsScriptLoader(nsIDocument* aDocument); + explicit ScriptLoader(nsIDocument* aDocument); NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_CLASS(nsScriptLoader) + NS_DECL_CYCLE_COLLECTION_CLASS(ScriptLoader) /** * The loader maintains a weak reference to the document with @@ -395,7 +390,7 @@ public: /** * Handle the completion of a stream. This is called by the - * nsScriptLoadHandler object which observes the IncrementalStreamLoader + * ScriptLoadHandler object which observes the IncrementalStreamLoader * loading the script. */ nsresult OnStreamComplete(nsIIncrementalStreamLoader* aLoader, @@ -463,17 +458,17 @@ public: * Process a request that was deferred so that the script could be compiled * off thread. */ - nsresult ProcessOffThreadRequest(nsScriptLoadRequest *aRequest); + nsresult ProcessOffThreadRequest(ScriptLoadRequest *aRequest); - bool AddPendingChildLoader(nsScriptLoader* aChild) { + bool AddPendingChildLoader(ScriptLoader* aChild) { return mPendingChildLoaders.AppendElement(aChild) != nullptr; } private: - virtual ~nsScriptLoader(); + virtual ~ScriptLoader(); - nsScriptLoadRequest* CreateLoadRequest( - nsScriptKind aKind, + ScriptLoadRequest* CreateLoadRequest( + ScriptKind aKind, nsIScriptElement* aElement, uint32_t aVersion, mozilla::CORSMode aCORSMode, @@ -482,12 +477,12 @@ private: /** * Unblocks the creator parser of the parser-blocking scripts. */ - void UnblockParser(nsScriptLoadRequest* aParserBlockingRequest); + void UnblockParser(ScriptLoadRequest* aParserBlockingRequest); /** * Asynchronously resumes the creator parser of the parser-blocking scripts. */ - void ContinueParserAsync(nsScriptLoadRequest* aParserBlockingRequest); + void ContinueParserAsync(ScriptLoadRequest* aParserBlockingRequest); /** @@ -502,7 +497,7 @@ private: /** * Start a load for aRequest's URI. */ - nsresult StartLoad(nsScriptLoadRequest *aRequest, const nsAString &aType, + nsresult StartLoad(ScriptLoadRequest *aRequest, const nsAString &aType, bool aScriptFromHead); /** @@ -539,83 +534,83 @@ private: return mEnabled && !mBlockerCount; } - nsresult AttemptAsyncScriptCompile(nsScriptLoadRequest* aRequest); - nsresult ProcessRequest(nsScriptLoadRequest* aRequest); - nsresult CompileOffThreadOrProcessRequest(nsScriptLoadRequest* aRequest); + nsresult AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest); + nsresult ProcessRequest(ScriptLoadRequest* aRequest); + nsresult CompileOffThreadOrProcessRequest(ScriptLoadRequest* aRequest); void FireScriptAvailable(nsresult aResult, - nsScriptLoadRequest* aRequest); + ScriptLoadRequest* aRequest); void FireScriptEvaluated(nsresult aResult, - nsScriptLoadRequest* aRequest); - nsresult EvaluateScript(nsScriptLoadRequest* aRequest); + ScriptLoadRequest* aRequest); + nsresult EvaluateScript(ScriptLoadRequest* aRequest); already_AddRefed<nsIScriptGlobalObject> GetScriptGlobalObject(); nsresult FillCompileOptionsForRequest(const mozilla::dom::AutoJSAPI& jsapi, - nsScriptLoadRequest* aRequest, + ScriptLoadRequest* aRequest, JS::Handle<JSObject*> aScopeChain, JS::CompileOptions* aOptions); uint32_t NumberOfProcessors(); - nsresult PrepareLoadedRequest(nsScriptLoadRequest* aRequest, + nsresult PrepareLoadedRequest(ScriptLoadRequest* aRequest, nsIIncrementalStreamLoader* aLoader, nsresult aStatus, mozilla::Vector<char16_t> &aString); - void AddDeferRequest(nsScriptLoadRequest* aRequest); + void AddDeferRequest(ScriptLoadRequest* aRequest); bool MaybeRemovedDeferRequests(); - void MaybeMoveToLoadedList(nsScriptLoadRequest* aRequest); + void MaybeMoveToLoadedList(ScriptLoadRequest* aRequest); - JS::SourceBufferHolder GetScriptSource(nsScriptLoadRequest* aRequest, + JS::SourceBufferHolder GetScriptSource(ScriptLoadRequest* aRequest, nsAutoString& inlineData); bool ModuleScriptsEnabled(); - void SetModuleFetchStarted(nsModuleLoadRequest *aRequest); - void SetModuleFetchFinishedAndResumeWaitingRequests(nsModuleLoadRequest *aRequest, + void SetModuleFetchStarted(ModuleLoadRequest *aRequest); + void SetModuleFetchFinishedAndResumeWaitingRequests(ModuleLoadRequest *aRequest, nsresult aResult); - bool IsFetchingModule(nsModuleLoadRequest *aRequest) const; + bool IsFetchingModule(ModuleLoadRequest *aRequest) const; - bool ModuleMapContainsModule(nsModuleLoadRequest *aRequest) const; - RefPtr<mozilla::GenericPromise> WaitForModuleFetch(nsModuleLoadRequest *aRequest); - nsModuleScript* GetFetchedModule(nsIURI* aURL) const; + bool ModuleMapContainsModule(ModuleLoadRequest *aRequest) const; + RefPtr<mozilla::GenericPromise> WaitForModuleFetch(ModuleLoadRequest *aRequest); + ModuleScript* GetFetchedModule(nsIURI* aURL) const; friend bool HostResolveImportedModule(JSContext* aCx, unsigned argc, JS::Value* vp); - nsresult CreateModuleScript(nsModuleLoadRequest* aRequest); - nsresult ProcessFetchedModuleSource(nsModuleLoadRequest* aRequest); - void ProcessLoadedModuleTree(nsModuleLoadRequest* aRequest); - bool InstantiateModuleTree(nsModuleLoadRequest* aRequest); - void StartFetchingModuleDependencies(nsModuleLoadRequest* aRequest); + nsresult CreateModuleScript(ModuleLoadRequest* aRequest); + nsresult ProcessFetchedModuleSource(ModuleLoadRequest* aRequest); + void ProcessLoadedModuleTree(ModuleLoadRequest* aRequest); + bool InstantiateModuleTree(ModuleLoadRequest* aRequest); + void StartFetchingModuleDependencies(ModuleLoadRequest* aRequest); RefPtr<mozilla::GenericPromise> - StartFetchingModuleAndDependencies(nsModuleLoadRequest* aRequest, nsIURI* aURI); + StartFetchingModuleAndDependencies(ModuleLoadRequest* aRequest, nsIURI* aURI); nsIDocument* mDocument; // [WEAK] nsCOMArray<nsIScriptLoaderObserver> mObservers; - nsScriptLoadRequestList mNonAsyncExternalScriptInsertedRequests; + ScriptLoadRequestList mNonAsyncExternalScriptInsertedRequests; // mLoadingAsyncRequests holds async requests while they're loading; when they // have been loaded they are moved to mLoadedAsyncRequests. - nsScriptLoadRequestList mLoadingAsyncRequests; - nsScriptLoadRequestList mLoadedAsyncRequests; - nsScriptLoadRequestList mDeferRequests; - nsScriptLoadRequestList mXSLTRequests; - RefPtr<nsScriptLoadRequest> mParserBlockingRequest; + ScriptLoadRequestList mLoadingAsyncRequests; + ScriptLoadRequestList mLoadedAsyncRequests; + ScriptLoadRequestList mDeferRequests; + ScriptLoadRequestList mXSLTRequests; + RefPtr<ScriptLoadRequest> mParserBlockingRequest; // In mRequests, the additional information here is stored by the element. struct PreloadInfo { - RefPtr<nsScriptLoadRequest> mRequest; + RefPtr<ScriptLoadRequest> mRequest; nsString mCharset; }; - friend void ImplCycleCollectionUnlink(nsScriptLoader::PreloadInfo& aField); + friend void ImplCycleCollectionUnlink(ScriptLoader::PreloadInfo& aField); friend void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, - nsScriptLoader::PreloadInfo& aField, + ScriptLoader::PreloadInfo& aField, const char* aName, uint32_t aFlags); struct PreloadRequestComparator { - bool Equals(const PreloadInfo &aPi, nsScriptLoadRequest * const &aRequest) + bool Equals(const PreloadInfo &aPi, ScriptLoadRequest * const &aRequest) const { return aRequest == aPi.mRequest; @@ -628,7 +623,7 @@ private: nsCOMPtr<nsIScriptElement> mCurrentScript; nsCOMPtr<nsIScriptElement> mCurrentParserInsertedScript; - nsTArray< RefPtr<nsScriptLoader> > mPendingChildLoaders; + nsTArray< RefPtr<ScriptLoader> > mPendingChildLoaders; uint32_t mParserBlockingBlockerCount; uint32_t mBlockerCount; uint32_t mNumberOfProcessors; @@ -639,58 +634,11 @@ private: // Module map nsRefPtrHashtable<nsURIHashKey, mozilla::GenericPromise::Private> mFetchingModules; - nsRefPtrHashtable<nsURIHashKey, nsModuleScript> mFetchedModules; + nsRefPtrHashtable<nsURIHashKey, ModuleScript> mFetchedModules; nsCOMPtr<nsIConsoleReportCollector> mReporter; }; -class nsScriptLoadHandler final : public nsIIncrementalStreamLoaderObserver -{ -public: - explicit nsScriptLoadHandler(nsScriptLoader* aScriptLoader, - nsScriptLoadRequest *aRequest, - mozilla::dom::SRICheckDataVerifier *aSRIDataVerifier); - - NS_DECL_ISUPPORTS - NS_DECL_NSIINCREMENTALSTREAMLOADEROBSERVER - -private: - virtual ~nsScriptLoadHandler(); - - /* - * Try to decode some raw data. - */ - nsresult TryDecodeRawData(const uint8_t* aData, uint32_t aDataLength, - bool aEndOfStream); - - /* - * Discover the charset by looking at the stream data, the script - * tag, and other indicators. Returns true if charset has been - * discovered. - */ - bool EnsureDecoder(nsIIncrementalStreamLoader *aLoader, - const uint8_t* aData, uint32_t aDataLength, - bool aEndOfStream); - - // ScriptLoader which will handle the parsed script. - RefPtr<nsScriptLoader> mScriptLoader; - - // The nsScriptLoadRequest for this load. - RefPtr<nsScriptLoadRequest> mRequest; - - // SRI data verifier. - nsAutoPtr<mozilla::dom::SRICheckDataVerifier> mSRIDataVerifier; - - // Status of SRI data operations. - nsresult mSRIStatus; - - // Unicode decoder for charset. - nsCOMPtr<nsIUnicodeDecoder> mDecoder; - - // Accumulated decoded char buffer. - mozilla::Vector<char16_t> mBuffer; -}; - class nsAutoScriptLoaderDisabler { public: @@ -711,7 +659,10 @@ public: } bool mWasEnabled; - RefPtr<nsScriptLoader> mLoader; + RefPtr<ScriptLoader> mLoader; }; -#endif //__nsScriptLoader_h__ +} // namespace dom +} // namespace mozilla + +#endif //mozilla_dom_ScriptLoader_h diff --git a/dom/base/ScriptSettings.cpp b/dom/script/ScriptSettings.cpp index 92ab221c9..92ab221c9 100644 --- a/dom/base/ScriptSettings.cpp +++ b/dom/script/ScriptSettings.cpp diff --git a/dom/base/ScriptSettings.h b/dom/script/ScriptSettings.h index 05e62f55e..05e62f55e 100644 --- a/dom/base/ScriptSettings.h +++ b/dom/script/ScriptSettings.h diff --git a/dom/script/moz.build b/dom/script/moz.build new file mode 100644 index 000000000..280850ed4 --- /dev/null +++ b/dom/script/moz.build @@ -0,0 +1,36 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# This Source Code Form is subject to the terms of the Mozilla Public +# 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/. + +XPIDL_SOURCES += [ + 'nsIScriptLoaderObserver.idl', +] + +XPIDL_MODULE = 'dom' + +EXPORTS += ['nsIScriptElement.h'] + +EXPORTS.mozilla.dom += [ + 'ScriptElement.h', + 'ScriptLoader.h', + 'ScriptSettings.h', +] + +SOURCES += [ + 'ModuleLoadRequest.cpp', + 'ModuleScript.cpp', + 'ScriptElement.cpp', + 'ScriptLoader.cpp', + 'ScriptLoadHandler.cpp', + 'ScriptSettings.cpp', +] + +LOCAL_INCLUDES += [ + '/dom/base', + '/dom/workers', +] + +include('/ipc/chromium/chromium-config.mozbuild') + +FINAL_LIBRARY = 'xul' diff --git a/dom/base/nsIScriptElement.h b/dom/script/nsIScriptElement.h index 470d51c94..470d51c94 100644 --- a/dom/base/nsIScriptElement.h +++ b/dom/script/nsIScriptElement.h diff --git a/dom/base/nsIScriptLoaderObserver.idl b/dom/script/nsIScriptLoaderObserver.idl index ed7196525..ed7196525 100644 --- a/dom/base/nsIScriptLoaderObserver.idl +++ b/dom/script/nsIScriptLoaderObserver.idl diff --git a/dom/svg/SVGScriptElement.cpp b/dom/svg/SVGScriptElement.cpp index 0cc827b9f..7adce2f46 100644 --- a/dom/svg/SVGScriptElement.cpp +++ b/dom/svg/SVGScriptElement.cpp @@ -42,7 +42,7 @@ NS_IMPL_ISUPPORTS_INHERITED(SVGScriptElement, SVGScriptElementBase, SVGScriptElement::SVGScriptElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo, FromParser aFromParser) : SVGScriptElementBase(aNodeInfo) - , nsScriptElement(aFromParser) + , ScriptElement(aFromParser) { AddMutationObserver(this); } @@ -168,7 +168,7 @@ SVGScriptElement::FreezeUriAsyncDefer() } //---------------------------------------------------------------------- -// nsScriptElement methods +// ScriptElement methods bool SVGScriptElement::HasScriptContent() diff --git a/dom/svg/SVGScriptElement.h b/dom/svg/SVGScriptElement.h index d3a233b72..79a3de70d 100644 --- a/dom/svg/SVGScriptElement.h +++ b/dom/svg/SVGScriptElement.h @@ -10,7 +10,7 @@ #include "nsSVGElement.h" #include "nsCOMPtr.h" #include "nsSVGString.h" -#include "nsScriptElement.h" +#include "mozilla/dom/ScriptElement.h" class nsIDocument; @@ -24,7 +24,7 @@ namespace dom { typedef nsSVGElement SVGScriptElementBase; class SVGScriptElement final : public SVGScriptElementBase, - public nsScriptElement + public ScriptElement { protected: friend nsresult (::NS_NewSVGScriptElement(nsIContent **aResult, @@ -47,7 +47,7 @@ public: virtual void FreezeUriAsyncDefer() override; virtual CORSMode GetCORSMode() const override; - // nsScriptElement + // ScriptElement virtual bool HasScriptContent() override; // nsIContent specializations: diff --git a/dom/workers/ScriptLoader.cpp b/dom/workers/ScriptLoader.cpp index 56b18441e..bcec94dcb 100644 --- a/dom/workers/ScriptLoader.cpp +++ b/dom/workers/ScriptLoader.cpp @@ -34,7 +34,6 @@ #include "nsIPipe.h" #include "nsIOutputStream.h" #include "nsPrintfCString.h" -#include "nsScriptLoader.h" #include "nsString.h" #include "nsStreamUtils.h" #include "nsTArray.h" @@ -58,6 +57,7 @@ #include "mozilla/dom/Promise.h" #include "mozilla/dom/PromiseNativeHandler.h" #include "mozilla/dom/Response.h" +#include "mozilla/dom/ScriptLoader.h" #include "mozilla/dom/ScriptSettings.h" #include "mozilla/dom/SRILogHelper.h" #include "mozilla/UniquePtr.h" @@ -1075,14 +1075,14 @@ private: // May be null. nsIDocument* parentDoc = mWorkerPrivate->GetDocument(); - // Use the regular nsScriptLoader for this grunt work! Should be just fine + // Use the regular ScriptLoader for this grunt work! Should be just fine // because we're running on the main thread. // Unlike <script> tags, Worker scripts are always decoded as UTF-8, // per spec. So we explicitly pass in the charset hint. - rv = nsScriptLoader::ConvertToUTF16(aLoadInfo.mChannel, aString, aStringLen, - NS_LITERAL_STRING("UTF-8"), parentDoc, - aLoadInfo.mScriptTextBuf, - aLoadInfo.mScriptTextLength); + rv = ScriptLoader::ConvertToUTF16(aLoadInfo.mChannel, aString, aStringLen, + NS_LITERAL_STRING("UTF-8"), parentDoc, + aLoadInfo.mScriptTextBuf, + aLoadInfo.mScriptTextLength); if (NS_FAILED(rv)) { return rv; } @@ -1289,10 +1289,10 @@ private: MOZ_ASSERT(!loadInfo.mScriptTextBuf); nsresult rv = - nsScriptLoader::ConvertToUTF16(nullptr, aString, aStringLen, - NS_LITERAL_STRING("UTF-8"), parentDoc, - loadInfo.mScriptTextBuf, - loadInfo.mScriptTextLength); + ScriptLoader::ConvertToUTF16(nullptr, aString, aStringLen, + NS_LITERAL_STRING("UTF-8"), parentDoc, + loadInfo.mScriptTextBuf, + loadInfo.mScriptTextLength); if (NS_SUCCEEDED(rv) && IsMainWorkerScript()) { nsCOMPtr<nsIURI> finalURI; rv = NS_NewURI(getter_AddRefs(finalURI), loadInfo.mFullURL, nullptr, nullptr); diff --git a/dom/workers/ServiceWorkerManager.cpp b/dom/workers/ServiceWorkerManager.cpp index a8f191f2e..306ef6b23 100644 --- a/dom/workers/ServiceWorkerManager.cpp +++ b/dom/workers/ServiceWorkerManager.cpp @@ -22,7 +22,6 @@ #include "nsITimer.h" #include "nsIUploadChannel2.h" #include "nsPIDOMWindow.h" -#include "nsScriptLoader.h" #include "nsServiceManagerUtils.h" #include "nsDebug.h" #include "nsISupportsPrimitives.h" @@ -44,6 +43,7 @@ #include "mozilla/dom/PromiseNativeHandler.h" #include "mozilla/dom/Request.h" #include "mozilla/dom/RootedDictionary.h" +#include "mozilla/dom/ScriptLoader.h" #include "mozilla/dom/TypedArray.h" #include "mozilla/ipc/BackgroundChild.h" #include "mozilla/ipc/PBackgroundChild.h" diff --git a/dom/workers/ServiceWorkerScriptCache.cpp b/dom/workers/ServiceWorkerScriptCache.cpp index f44bb673c..707b689e8 100644 --- a/dom/workers/ServiceWorkerScriptCache.cpp +++ b/dom/workers/ServiceWorkerScriptCache.cpp @@ -11,6 +11,7 @@ #include "mozilla/dom/cache/Cache.h" #include "mozilla/dom/Promise.h" #include "mozilla/dom/PromiseWorkerProxy.h" +#include "mozilla/dom/ScriptLoader.h" #include "mozilla/ipc/BackgroundUtils.h" #include "mozilla/ipc/PBackgroundSharedTypes.h" #include "nsICacheInfoChannel.h" @@ -23,7 +24,6 @@ #include "nsIScriptError.h" #include "nsContentUtils.h" #include "nsNetUtil.h" -#include "nsScriptLoader.h" #include "ServiceWorkerManager.h" #include "Workers.h" #include "nsStringStream.h" @@ -801,9 +801,9 @@ CompareNetwork::OnStreamComplete(nsIStreamLoader* aLoader, nsISupports* aContext char16_t* buffer = nullptr; size_t len = 0; - rv = nsScriptLoader::ConvertToUTF16(httpChannel, aString, aLen, - NS_LITERAL_STRING("UTF-8"), nullptr, - buffer, len); + rv = ScriptLoader::ConvertToUTF16(httpChannel, aString, aLen, + NS_LITERAL_STRING("UTF-8"), nullptr, + buffer, len); if (NS_WARN_IF(NS_FAILED(rv))) { mManager->NetworkFinished(rv); return rv; @@ -855,9 +855,9 @@ CompareCache::OnStreamComplete(nsIStreamLoader* aLoader, nsISupports* aContext, char16_t* buffer = nullptr; size_t len = 0; - nsresult rv = nsScriptLoader::ConvertToUTF16(nullptr, aString, aLen, - NS_LITERAL_STRING("UTF-8"), - nullptr, buffer, len); + nsresult rv = ScriptLoader::ConvertToUTF16(nullptr, aString, aLen, + NS_LITERAL_STRING("UTF-8"), + nullptr, buffer, len); if (NS_WARN_IF(NS_FAILED(rv))) { mManager->CacheFinished(rv, false); return rv; diff --git a/dom/worklet/Worklet.cpp b/dom/worklet/Worklet.cpp index 19a877ea8..1b71916ab 100644 --- a/dom/worklet/Worklet.cpp +++ b/dom/worklet/Worklet.cpp @@ -12,11 +12,11 @@ #include "mozilla/dom/PromiseNativeHandler.h" #include "mozilla/dom/RegisterWorkletBindings.h" #include "mozilla/dom/Response.h" +#include "mozilla/dom/ScriptLoader.h" #include "mozilla/dom/ScriptSettings.h" #include "nsIInputStreamPump.h" #include "nsIThreadRetargetableRequest.h" #include "nsNetUtil.h" -#include "nsScriptLoader.h" #include "xpcprivate.h" namespace mozilla { @@ -171,9 +171,9 @@ public: char16_t* scriptTextBuf; size_t scriptTextLength; nsresult rv = - nsScriptLoader::ConvertToUTF16(nullptr, aString, aStringLen, - NS_LITERAL_STRING("UTF-8"), nullptr, - scriptTextBuf, scriptTextLength); + ScriptLoader::ConvertToUTF16(nullptr, aString, aStringLen, + NS_LITERAL_STRING("UTF-8"), nullptr, + scriptTextBuf, scriptTextLength); if (NS_WARN_IF(NS_FAILED(rv))) { RejectPromises(rv); return NS_OK; diff --git a/dom/xml/nsXMLContentSink.cpp b/dom/xml/nsXMLContentSink.cpp index 7c9d308fd..daf1dbf27 100644 --- a/dom/xml/nsXMLContentSink.cpp +++ b/dom/xml/nsXMLContentSink.cpp @@ -35,7 +35,6 @@ #include "nsRect.h" #include "nsIWebNavigation.h" #include "nsIScriptElement.h" -#include "nsScriptLoader.h" #include "nsStyleLinkElement.h" #include "nsReadableUtils.h" #include "nsUnicharUtils.h" @@ -62,6 +61,7 @@ #include "mozilla/dom/Element.h" #include "mozilla/dom/HTMLTemplateElement.h" #include "mozilla/dom/ProcessingInstruction.h" +#include "mozilla/dom/ScriptLoader.h" using namespace mozilla; using namespace mozilla::dom; diff --git a/dom/xml/nsXMLFragmentContentSink.cpp b/dom/xml/nsXMLFragmentContentSink.cpp index 7fa815c84..7d9f86987 100644 --- a/dom/xml/nsXMLFragmentContentSink.cpp +++ b/dom/xml/nsXMLFragmentContentSink.cpp @@ -24,10 +24,10 @@ #include "nsTArray.h" #include "nsCycleCollectionParticipant.h" #include "nsIDocShell.h" -#include "nsScriptLoader.h" #include "mozilla/css/Loader.h" #include "mozilla/dom/DocumentFragment.h" #include "mozilla/dom/ProcessingInstruction.h" +#include "mozilla/dom/ScriptLoader.h" using namespace mozilla::dom; diff --git a/dom/xslt/xslt/txMozillaXMLOutput.cpp b/dom/xslt/xslt/txMozillaXMLOutput.cpp index 069413d97..704d8ac11 100644 --- a/dom/xslt/xslt/txMozillaXMLOutput.cpp +++ b/dom/xslt/xslt/txMozillaXMLOutput.cpp @@ -7,7 +7,6 @@ #include "nsIDocument.h" #include "nsIDocShell.h" -#include "nsScriptLoader.h" #include "nsIDOMDocument.h" #include "nsIDOMDocumentType.h" #include "nsIScriptElement.h" @@ -31,6 +30,7 @@ #include "mozilla/css/Loader.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/EncodingUtils.h" +#include "mozilla/dom/ScriptLoader.h" #include "nsContentUtils.h" #include "txXMLUtils.h" #include "nsContentSink.h" @@ -230,7 +230,7 @@ txMozillaXMLOutput::endDocument(nsresult aResult) MOZ_ASSERT(mDocument->GetReadyStateEnum() == nsIDocument::READYSTATE_LOADING, "Bad readyState"); mDocument->SetReadyStateInternal(nsIDocument::READYSTATE_INTERACTIVE); - nsScriptLoader* loader = mDocument->ScriptLoader(); + ScriptLoader* loader = mDocument->ScriptLoader(); if (loader) { loader->ParsingComplete(false); } @@ -416,7 +416,7 @@ txMozillaXMLOutput::startDocument() } if (mCreatingNewDocument) { - nsScriptLoader* loader = mDocument->ScriptLoader(); + ScriptLoader* loader = mDocument->ScriptLoader(); if (loader) { loader->BeginDeferringScripts(); } @@ -857,7 +857,7 @@ txMozillaXMLOutput::createResultDocument(const nsSubstring& aName, int32_t aNsID } // Set up script loader of the result document. - nsScriptLoader *loader = mDocument->ScriptLoader(); + ScriptLoader *loader = mDocument->ScriptLoader(); if (mNotifier) { loader->AddObserver(mNotifier); } diff --git a/dom/xul/XULDocument.cpp b/dom/xul/XULDocument.cpp index d3b94920a..c5ec9a208 100644 --- a/dom/xul/XULDocument.cpp +++ b/dom/xul/XULDocument.cpp @@ -3325,10 +3325,10 @@ XULDocument::OnStreamComplete(nsIStreamLoader* aLoader, !mOffThreadCompileStringBuf), "XULDocument can't load multiple scripts at once"); - rv = nsScriptLoader::ConvertToUTF16(channel, string, stringLen, - EmptyString(), this, - mOffThreadCompileStringBuf, - mOffThreadCompileStringLength); + rv = ScriptLoader::ConvertToUTF16(channel, string, stringLen, + EmptyString(), this, + mOffThreadCompileStringBuf, + mOffThreadCompileStringLength); if (NS_SUCCEEDED(rv)) { // Attempt to give ownership of the buffer to the JS engine. If // we hit offthread compilation, however, we will have to take it diff --git a/dom/xul/XULDocument.h b/dom/xul/XULDocument.h index a5ed49704..5c4dad42e 100644 --- a/dom/xul/XULDocument.h +++ b/dom/xul/XULDocument.h @@ -21,13 +21,13 @@ #include "nsCOMArray.h" #include "nsIURI.h" #include "nsIXULDocument.h" -#include "nsScriptLoader.h" #include "nsIStreamListener.h" #include "nsIStreamLoader.h" #include "nsICSSLoaderObserver.h" #include "nsIXULStore.h" #include "mozilla/Attributes.h" +#include "mozilla/dom/ScriptLoader.h" #include "js/TracingAPI.h" #include "js/TypeDecls.h" diff --git a/dom/xul/nsXULContentSink.cpp b/dom/xul/nsXULContentSink.cpp index edeee8728..94560e70d 100644 --- a/dom/xul/nsXULContentSink.cpp +++ b/dom/xul/nsXULContentSink.cpp @@ -881,7 +881,7 @@ XULContentSinkImpl::OpenScript(const char16_t** aAttributes, isJavaScript = false; } } else if (key.EqualsLiteral("language")) { - // Language is deprecated, and the impl in nsScriptLoader ignores the + // Language is deprecated, and the impl in ScriptLoader ignores the // various version strings anyway. So we make no attempt to support // languages other than JS for language= nsAutoString lang(aAttributes[1]); |