mirror of
https://github.com/roytam1/UXP.git
synced 2026-05-29 16:58:28 +00:00
Issue #1691 - Part 6b: Initial browser support for dynamic import from module scripts. https://bugzilla.mozilla.org/show_bug.cgi?id=1342012 Factor out script fetch options from script load request classes. https://bugzilla.mozilla.org/show_bug.cgi?id=1480720 Remove support for version parameter from script loader. https://bugzilla.mozilla.org/show_bug.cgi?id=1428745
(cherry picked from commit 3ec2529aa6303f6950622e3cb91a23580649c73b)
This commit is contained in:
@@ -4,6 +4,9 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "ModuleLoadRequest.h"
|
||||
|
||||
#include "mozilla/HoldDropJSObjects.h"
|
||||
|
||||
#include "ModuleScript.h"
|
||||
#include "ScriptLoader.h"
|
||||
|
||||
@@ -13,58 +16,93 @@ 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,
|
||||
mModuleScript,
|
||||
mImports)
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(ModuleLoadRequest)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(ModuleLoadRequest,
|
||||
ScriptLoadRequest)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mBaseURL, mLoader, mModuleScript, mImports)
|
||||
tmp->ClearDynamicImport();
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(ModuleLoadRequest,
|
||||
ScriptLoadRequest)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBaseURL, mLoader, mModuleScript, mImports)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(ModuleLoadRequest,
|
||||
ScriptLoadRequest)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mDynamicReferencingPrivate)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mDynamicSpecifier)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mDynamicPromise)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(ModuleLoadRequest, ScriptLoadRequest)
|
||||
NS_IMPL_RELEASE_INHERITED(ModuleLoadRequest, ScriptLoadRequest)
|
||||
|
||||
ModuleLoadRequest::ModuleLoadRequest(nsIURI* aURI,
|
||||
nsIScriptElement* aElement,
|
||||
uint32_t aVersion,
|
||||
CORSMode aCORSMode,
|
||||
const SRIMetadata &aIntegrity,
|
||||
nsIURI* aReferrer,
|
||||
mozilla::net::ReferrerPolicy aReferrerPolicy,
|
||||
ScriptLoader* aLoader)
|
||||
: ScriptLoadRequest(ScriptKind::Module,
|
||||
aURI,
|
||||
aElement,
|
||||
aVersion,
|
||||
aCORSMode,
|
||||
aIntegrity,
|
||||
aReferrer,
|
||||
aReferrerPolicy),
|
||||
mIsTopLevel(true),
|
||||
mLoader(aLoader),
|
||||
mVisitedSet(new VisitedURLSet())
|
||||
{
|
||||
mVisitedSet->PutEntry(aURI);
|
||||
static VisitedURLSet* NewVisitedSetForTopLevelImport(nsIURI* aURI) {
|
||||
auto set = new VisitedURLSet();
|
||||
set->PutEntry(aURI);
|
||||
return set;
|
||||
}
|
||||
|
||||
ModuleLoadRequest::ModuleLoadRequest(nsIURI* aURI,
|
||||
ModuleLoadRequest* aParent)
|
||||
: ScriptLoadRequest(ScriptKind::Module,
|
||||
aURI,
|
||||
aParent->mElement,
|
||||
aParent->mJSVersion,
|
||||
aParent->mCORSMode,
|
||||
SRIMetadata(),
|
||||
aParent->mURI,
|
||||
aParent->mReferrerPolicy),
|
||||
mIsTopLevel(false),
|
||||
mLoader(aParent->mLoader),
|
||||
mVisitedSet(aParent->mVisitedSet)
|
||||
{
|
||||
MOZ_ASSERT(mVisitedSet->Contains(aURI));
|
||||
|
||||
mIsInline = false;
|
||||
mScriptMode = aParent->mScriptMode;
|
||||
/* static */ ModuleLoadRequest* ModuleLoadRequest::CreateTopLevel(
|
||||
nsIURI* aURI, ScriptFetchOptions* aFetchOptions,
|
||||
const SRIMetadata& aIntegrity, nsIURI* aReferrer, ScriptLoader* aLoader) {
|
||||
return new ModuleLoadRequest(aURI, aFetchOptions, aIntegrity, aReferrer,
|
||||
true, /* is top level */
|
||||
false, /* is dynamic import */
|
||||
aLoader, NewVisitedSetForTopLevelImport(aURI));
|
||||
}
|
||||
|
||||
/* static */ ModuleLoadRequest* ModuleLoadRequest::CreateStaticImport(
|
||||
nsIURI* aURI, ModuleLoadRequest* aParent) {
|
||||
auto request =
|
||||
new ModuleLoadRequest(aURI, aParent->mFetchOptions, SRIMetadata(),
|
||||
aParent->mURI, false, /* is top level */
|
||||
false, /* is dynamic import */
|
||||
aParent->mLoader, aParent->mVisitedSet);
|
||||
|
||||
request->mIsInline = false;
|
||||
request->mScriptMode = aParent->mScriptMode;
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
/* static */ ModuleLoadRequest* ModuleLoadRequest::CreateDynamicImport(
|
||||
nsIURI* aURI, ModuleScript* aScript,
|
||||
JS::Handle<JS::Value> aReferencingPrivate, JS::Handle<JSString*> aSpecifier,
|
||||
JS::Handle<JSObject*> aPromise) {
|
||||
MOZ_ASSERT(aSpecifier);
|
||||
MOZ_ASSERT(aPromise);
|
||||
|
||||
auto request = new ModuleLoadRequest(
|
||||
aURI, aScript->FetchOptions(), SRIMetadata(), aScript->BaseURL(),
|
||||
true, /* is top level */
|
||||
true, /* is dynamic import */
|
||||
aScript->Loader(), NewVisitedSetForTopLevelImport(aURI));
|
||||
|
||||
request->mIsInline = false;
|
||||
request->mScriptMode = ScriptMode::eAsync;
|
||||
request->mDynamicReferencingPrivate = aReferencingPrivate;
|
||||
request->mDynamicSpecifier = aSpecifier;
|
||||
request->mDynamicPromise = aPromise;
|
||||
|
||||
HoldJSObjects(request);
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
ModuleLoadRequest::ModuleLoadRequest(
|
||||
nsIURI* aURI, ScriptFetchOptions* aFetchOptions,
|
||||
const SRIMetadata& aIntegrity, nsIURI* aReferrer, bool aIsTopLevel,
|
||||
bool aIsDynamicImport, ScriptLoader* aLoader, VisitedURLSet* aVisitedSet)
|
||||
: ScriptLoadRequest(ScriptKind::Module, aURI, aFetchOptions, aIntegrity,
|
||||
aReferrer),
|
||||
mIsTopLevel(aIsTopLevel),
|
||||
mIsDynamicImport(aIsDynamicImport),
|
||||
mLoader(aLoader),
|
||||
mVisitedSet(aVisitedSet) {}
|
||||
|
||||
void ModuleLoadRequest::Cancel()
|
||||
{
|
||||
ScriptLoadRequest::Cancel();
|
||||
@@ -166,5 +204,11 @@ ModuleLoadRequest::LoadFinished()
|
||||
mLoader = nullptr;
|
||||
}
|
||||
|
||||
void ModuleLoadRequest::ClearDynamicImport() {
|
||||
mDynamicReferencingPrivate = JS::UndefinedValue();
|
||||
mDynamicSpecifier = nullptr;
|
||||
mDynamicPromise = nullptr;
|
||||
}
|
||||
|
||||
} // dom namespace
|
||||
} // mozilla namespace
|
||||
|
||||
@@ -37,30 +37,42 @@ class ModuleLoadRequest final : public ScriptLoadRequest
|
||||
ModuleLoadRequest(const ModuleLoadRequest& aOther) = delete;
|
||||
ModuleLoadRequest(ModuleLoadRequest&& aOther) = delete;
|
||||
|
||||
ModuleLoadRequest(nsIURI* aURI, ScriptFetchOptions* aFetchOptions,
|
||||
const SRIMetadata& aIntegrity, nsIURI* aReferrer,
|
||||
bool aIsTopLevel, bool aIsDynamicImport,
|
||||
ScriptLoader* aLoader, VisitedURLSet* aVisitedSet);
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ModuleLoadRequest, ScriptLoadRequest)
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(ModuleLoadRequest,
|
||||
ScriptLoadRequest)
|
||||
|
||||
// Create a top-level module load request.
|
||||
ModuleLoadRequest(nsIURI* aURI,
|
||||
nsIScriptElement* aElement,
|
||||
uint32_t aVersion,
|
||||
CORSMode aCORSMode,
|
||||
const SRIMetadata& aIntegrity,
|
||||
nsIURI* aReferrer,
|
||||
mozilla::net::ReferrerPolicy,
|
||||
ScriptLoader* aLoader);
|
||||
static ModuleLoadRequest* CreateTopLevel(nsIURI* aURI,
|
||||
ScriptFetchOptions* aFetchOptions,
|
||||
const SRIMetadata& aIntegrity,
|
||||
nsIURI* aReferrer,
|
||||
ScriptLoader* aLoader);
|
||||
|
||||
// Create a module load request for an imported module.
|
||||
ModuleLoadRequest(nsIURI* aURI,
|
||||
ModuleLoadRequest* aParent);
|
||||
// Create a module load request for a static module import.
|
||||
static ModuleLoadRequest* CreateStaticImport(nsIURI* aURI,
|
||||
ModuleLoadRequest* aParent);
|
||||
|
||||
// Create a module load request for dynamic module import.
|
||||
static ModuleLoadRequest* CreateDynamicImport(
|
||||
nsIURI* aURI, ModuleScript* aScript,
|
||||
JS::Handle<JS::Value> aReferencingPrivate,
|
||||
JS::Handle<JSString*> aSpecifier, JS::Handle<JSObject*> aPromise);
|
||||
|
||||
bool IsTopLevel() const override {
|
||||
return mIsTopLevel;
|
||||
}
|
||||
|
||||
bool IsDynamicImport() const { return mIsDynamicImport; }
|
||||
|
||||
void SetReady() override;
|
||||
void Cancel() override;
|
||||
void ClearDynamicImport();
|
||||
|
||||
void ModuleLoaded();
|
||||
void ModuleErrored();
|
||||
@@ -74,6 +86,9 @@ private:
|
||||
public:
|
||||
// Is this a request for a top level module script or an import?
|
||||
const bool mIsTopLevel;
|
||||
|
||||
// Is this the top level request for a dynamic module import?
|
||||
const bool mIsDynamicImport;
|
||||
|
||||
// The base URL used for resolving relative module imports.
|
||||
nsCOMPtr<nsIURI> mBaseURL;
|
||||
@@ -97,6 +112,11 @@ public:
|
||||
// Set of module URLs visited while fetching the module graph this request is
|
||||
// part of.
|
||||
RefPtr<VisitedURLSet> mVisitedSet;
|
||||
|
||||
// For dynamic imports, the details to pass to FinishDynamicImport.
|
||||
JS::Heap<JS::Value> mDynamicReferencingPrivate;
|
||||
JS::Heap<JSString*> mDynamicSpecifier;
|
||||
JS::Heap<JSObject*> mDynamicPromise;
|
||||
};
|
||||
|
||||
} // dom namespace
|
||||
|
||||
@@ -7,9 +7,11 @@
|
||||
* A class that handles loading and evaluation of <script> elements.
|
||||
*/
|
||||
|
||||
#include "ScriptLoader.h"
|
||||
#include "ModuleScript.h"
|
||||
#include "mozilla/HoldDropJSObjects.h"
|
||||
#include "ScriptLoader.h"
|
||||
|
||||
#include "jsfriendapi.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
@@ -23,6 +25,7 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(ModuleScript)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ModuleScript)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mLoader)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mFetchOptions)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mBaseURL)
|
||||
tmp->UnlinkModuleRecord();
|
||||
tmp->mParseError.setUndefined();
|
||||
@@ -31,6 +34,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(ModuleScript)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLoader)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFetchOptions)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(ModuleScript)
|
||||
@@ -42,11 +46,13 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(ModuleScript)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(ModuleScript)
|
||||
|
||||
ModuleScript::ModuleScript(ScriptLoader *aLoader, nsIURI* aBaseURL)
|
||||
: mLoader(aLoader),
|
||||
mBaseURL(aBaseURL)
|
||||
{
|
||||
ModuleScript::ModuleScript(ScriptLoader* aLoader,
|
||||
ScriptFetchOptions* aFetchOptions, nsIURI* aBaseURL)
|
||||
: mLoader(aLoader),
|
||||
mFetchOptions(aFetchOptions),
|
||||
mBaseURL(aBaseURL) {
|
||||
MOZ_ASSERT(mLoader);
|
||||
MOZ_ASSERT(mFetchOptions);
|
||||
MOZ_ASSERT(mBaseURL);
|
||||
MOZ_ASSERT(!mModuleRecord);
|
||||
MOZ_ASSERT(!HasParseError());
|
||||
@@ -56,7 +62,9 @@ ModuleScript::ModuleScript(ScriptLoader *aLoader, nsIURI* aBaseURL)
|
||||
void
|
||||
ModuleScript::UnlinkModuleRecord()
|
||||
{
|
||||
// Remove module's back reference to this object request if present.
|
||||
// Remove the module record's pointer to this object if present and
|
||||
// decrement our reference count. The reference is added by
|
||||
// SetModuleRecord() below.
|
||||
if (mModuleRecord) {
|
||||
MOZ_ASSERT(JS::GetModulePrivate(mModuleRecord).toPrivate() ==
|
||||
this);
|
||||
@@ -81,8 +89,9 @@ ModuleScript::SetModuleRecord(JS::Handle<JSObject*> aModuleRecord)
|
||||
|
||||
mModuleRecord = aModuleRecord;
|
||||
|
||||
// Make module's host defined field point to this module script object.
|
||||
// This is cleared in the UnlinkModuleRecord().
|
||||
// Make module's host defined field point to this object and
|
||||
// increment our reference count. This is decremented by
|
||||
// UnlinkModuleRecord() above.
|
||||
JS::SetModulePrivate(mModuleRecord, JS::PrivateValue(this));
|
||||
HoldJSObjects(this);
|
||||
}
|
||||
@@ -97,13 +106,26 @@ ModuleScript::SetParseError(const JS::Value& aError)
|
||||
UnlinkModuleRecord();
|
||||
mParseError = aError;
|
||||
HoldJSObjects(this);
|
||||
AddRef();
|
||||
}
|
||||
|
||||
void HostFinalizeTopLevelScript(JSFreeOp* aFop, const JS::Value& aPrivate) {
|
||||
auto script = static_cast<ModuleScript*>(aPrivate.toPrivate());
|
||||
if (script) {
|
||||
MOZ_ASSERT(JS::GetModulePrivate(script->mModuleRecord.unbarrieredGet()) ==
|
||||
aPrivate);
|
||||
script->UnlinkModuleRecord();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ModuleScript::SetErrorToRethrow(const JS::Value& aError)
|
||||
{
|
||||
MOZ_ASSERT(!aError.isUndefined());
|
||||
MOZ_ASSERT(!HasErrorToRethrow());
|
||||
|
||||
// This is only called after SetModuleRecord() or SetParseError() so we don't
|
||||
// need to call HoldJSObjects() here.
|
||||
MOZ_ASSERT(mModuleRecord || HasParseError());
|
||||
|
||||
mErrorToRethrow = aError;
|
||||
}
|
||||
|
||||
@@ -17,9 +17,12 @@ namespace dom {
|
||||
|
||||
class ScriptLoader;
|
||||
|
||||
void HostFinalizeTopLevelScript(JSFreeOp* aFop, const JS::Value& aPrivate);
|
||||
|
||||
class ModuleScript final : public nsISupports
|
||||
{
|
||||
RefPtr<ScriptLoader> mLoader;
|
||||
RefPtr<ScriptFetchOptions> mFetchOptions;
|
||||
nsCOMPtr<nsIURI> mBaseURL;
|
||||
JS::Heap<JSObject*> mModuleRecord;
|
||||
JS::Heap<JS::Value> mParseError;
|
||||
@@ -31,7 +34,7 @@ public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ModuleScript)
|
||||
|
||||
ModuleScript(ScriptLoader* aLoader,
|
||||
ModuleScript(ScriptLoader* aLoader, ScriptFetchOptions* aFetchOptions,
|
||||
nsIURI* aBaseURL);
|
||||
|
||||
void SetModuleRecord(JS::Handle<JSObject*> aModuleRecord);
|
||||
@@ -39,6 +42,7 @@ public:
|
||||
void SetErrorToRethrow(const JS::Value& aError);
|
||||
|
||||
ScriptLoader* Loader() const { return mLoader; }
|
||||
ScriptFetchOptions* FetchOptions() const { return mFetchOptions; }
|
||||
JSObject* ModuleRecord() const { return mModuleRecord; }
|
||||
nsIURI* BaseURL() const { return mBaseURL; }
|
||||
|
||||
@@ -48,6 +52,8 @@ public:
|
||||
bool HasErrorToRethrow() const { return !mErrorToRethrow.isUndefined(); }
|
||||
|
||||
void UnlinkModuleRecord();
|
||||
|
||||
friend void HostFinalizeTopLevelScript(JSFreeOp*, const JS::Value&);
|
||||
};
|
||||
|
||||
} // dom namespace
|
||||
|
||||
@@ -154,7 +154,7 @@ ScriptLoadHandler::EnsureDecoder(nsIIncrementalStreamLoader *aLoader,
|
||||
// request.
|
||||
nsAutoString hintCharset;
|
||||
if (!mRequest->IsPreload()) {
|
||||
mRequest->mElement->GetScriptCharset(hintCharset);
|
||||
mRequest->Element()->GetScriptCharset(hintCharset);
|
||||
} else {
|
||||
nsTArray<ScriptLoader::PreloadInfo>::index_type i =
|
||||
mScriptLoader->mPreloads.IndexOf(mRequest, 0,
|
||||
|
||||
+316
-111
@@ -72,6 +72,31 @@ ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
|
||||
const char* aName,
|
||||
uint32_t aFlags = 0);
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// ScriptFetchOptions
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION(ScriptFetchOptions,
|
||||
mElement,
|
||||
mTriggeringPrincipal)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(ScriptFetchOptions, AddRef)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(ScriptFetchOptions, Release)
|
||||
|
||||
ScriptFetchOptions::ScriptFetchOptions(mozilla::CORSMode aCORSMode,
|
||||
mozilla::net::ReferrerPolicy aReferrerPolicy,
|
||||
nsIScriptElement* aElement,
|
||||
nsIPrincipal* aTriggeringPrincipal)
|
||||
: mCORSMode(aCORSMode)
|
||||
, mReferrerPolicy(aReferrerPolicy)
|
||||
, mElement(aElement)
|
||||
, mTriggeringPrincipal(aTriggeringPrincipal)
|
||||
{
|
||||
}
|
||||
|
||||
ScriptFetchOptions::~ScriptFetchOptions()
|
||||
{}
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// nsScriptLoadRequest
|
||||
//////////////////////////////////////////////////////////////
|
||||
@@ -85,11 +110,12 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(ScriptLoadRequest)
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(ScriptLoadRequest)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ScriptLoadRequest)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mElement)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mFetchOptions)
|
||||
tmp->mScript = nullptr;
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(ScriptLoadRequest)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mElement)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFetchOptions)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
ScriptLoadRequest::~ScriptLoadRequest()
|
||||
@@ -102,6 +128,8 @@ ScriptLoadRequest::~ScriptLoadRequest()
|
||||
// But play it safe in release builds and try to clean them up here
|
||||
// as a fail safe.
|
||||
MaybeCancelOffThreadScript();
|
||||
|
||||
DropJSObjects(this);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -151,6 +179,12 @@ ScriptLoadRequest::SetScriptMode(bool aDeferAttr, bool aAsyncAttr)
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptLoadRequest::SetScript(JSScript* aScript) {
|
||||
MOZ_ASSERT(!mScript);
|
||||
mScript = aScript;
|
||||
HoldJSObjects(this);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// ScriptLoadRequestList
|
||||
@@ -237,11 +271,12 @@ NS_IMPL_CYCLE_COLLECTION(ScriptLoader,
|
||||
mNonAsyncExternalScriptInsertedRequests,
|
||||
mLoadingAsyncRequests,
|
||||
mLoadedAsyncRequests,
|
||||
mDeferRequests,
|
||||
mXSLTRequests,
|
||||
mParserBlockingRequest,
|
||||
mPreloads,
|
||||
mPendingChildLoaders,
|
||||
mDeferRequests,
|
||||
mXSLTRequests,
|
||||
mDynamicImportRequests,
|
||||
mParserBlockingRequest,
|
||||
mPreloads,
|
||||
mPendingChildLoaders,
|
||||
mFetchedModules)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(ScriptLoader)
|
||||
@@ -258,6 +293,7 @@ ScriptLoader::ScriptLoader(nsIDocument *aDocument)
|
||||
mBlockingDOMContentLoaded(false),
|
||||
mReporter(new ConsoleReportCollector())
|
||||
{
|
||||
EnsureModuleHooksInitialized();
|
||||
}
|
||||
|
||||
ScriptLoader::~ScriptLoader()
|
||||
@@ -288,6 +324,11 @@ ScriptLoader::~ScriptLoader()
|
||||
req->FireScriptAvailable(NS_ERROR_ABORT);
|
||||
}
|
||||
|
||||
for (ScriptLoadRequest* req = mDynamicImportRequests.getFirst(); req;
|
||||
req = req->getNext()) {
|
||||
FinishDynamicImport(req->AsModuleRequest(), NS_ERROR_ABORT);
|
||||
}
|
||||
|
||||
for(ScriptLoadRequest* req = mNonAsyncExternalScriptInsertedRequests.getFirst();
|
||||
req;
|
||||
req = req->getNext()) {
|
||||
@@ -541,7 +582,7 @@ ScriptLoader::CreateModuleScript(ModuleLoadRequest* aRequest)
|
||||
nsCOMPtr<nsIDocument> master = mDocument->MasterDocument();
|
||||
if (master != mDocument) {
|
||||
masterScriptUpdater.emplace(master->ScriptLoader(),
|
||||
aRequest->mElement);
|
||||
aRequest->Element());
|
||||
}
|
||||
|
||||
JSContext* cx = aes.cx();
|
||||
@@ -566,7 +607,8 @@ ScriptLoader::CreateModuleScript(ModuleLoadRequest* aRequest)
|
||||
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv) == (module != nullptr));
|
||||
|
||||
RefPtr<ModuleScript> moduleScript = new ModuleScript(this, aRequest->mBaseURL);
|
||||
RefPtr<ModuleScript> moduleScript =
|
||||
new ModuleScript(this, aRequest->mFetchOptions, aRequest->mBaseURL);
|
||||
aRequest->mModuleScript = moduleScript;
|
||||
|
||||
if (!module) {
|
||||
@@ -780,7 +822,8 @@ ScriptLoader::StartFetchingModuleAndDependencies(ModuleLoadRequest* aParent,
|
||||
{
|
||||
MOZ_ASSERT(aURI);
|
||||
|
||||
RefPtr<ModuleLoadRequest> childRequest = new ModuleLoadRequest(aURI, aParent);
|
||||
RefPtr<ModuleLoadRequest> childRequest =
|
||||
ModuleLoadRequest::CreateStaticImport(aURI, aParent);
|
||||
|
||||
aParent->mImports.AppendElement(childRequest);
|
||||
|
||||
@@ -803,6 +846,12 @@ HostResolveImportedModule(JSContext* aCx,
|
||||
JS::Handle<JSString*> aSpecifier)
|
||||
{
|
||||
// Let referencing module script be referencingModule.[[HostDefined]].
|
||||
if (aReferencingPrivate.isUndefined()) {
|
||||
JS_ReportErrorNumberUC(aCx, js::GetErrorMessage, nullptr,
|
||||
JSMSG_IMPORT_SCRIPT_NOT_FOUND);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto script = static_cast<ModuleScript*>(aReferencingPrivate.toPrivate());
|
||||
MOZ_ASSERT(JS::GetModulePrivate(script->ModuleRecord()) == aReferencingPrivate);
|
||||
|
||||
@@ -867,16 +916,108 @@ HostPopulateImportMeta(JSContext* aCx, JS::Handle<JSObject*> aModule,
|
||||
return JS_DefineProperty(aCx, aMetaObject, "url", urlString, JSPROP_ENUMERATE);
|
||||
}
|
||||
|
||||
static void
|
||||
EnsureModuleResolveHook(JSContext* aCx)
|
||||
{
|
||||
JSRuntime* rt = JS_GetRuntime(aCx);
|
||||
bool HostImportModuleDynamically(JSContext* aCx,
|
||||
JS::Handle<JS::Value> aReferencingPrivate,
|
||||
JS::Handle<JSString*> aSpecifier,
|
||||
JS::Handle<JSObject*> aPromise) {
|
||||
if (aReferencingPrivate.isUndefined()) {
|
||||
JS_ReportErrorNumberUC(aCx, js::GetErrorMessage, nullptr,
|
||||
JSMSG_IMPORT_SCRIPT_NOT_FOUND);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto script = static_cast<ModuleScript*>(aReferencingPrivate.toPrivate());
|
||||
MOZ_ASSERT(JS::GetModulePrivate(script->ModuleRecord()) ==
|
||||
aReferencingPrivate);
|
||||
|
||||
// Attempt to resolve the module specifier.
|
||||
nsAutoJSString string;
|
||||
if (!string.init(aCx, aSpecifier)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIURI> uri = ResolveModuleSpecifier(script, string);
|
||||
if (!uri) {
|
||||
JS_ReportErrorNumberUC(aCx, js::GetErrorMessage, nullptr,
|
||||
JSMSG_BAD_MODULE_SPECIFIER, string.get());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create a new top-level load request.
|
||||
RefPtr<ModuleLoadRequest> request = ModuleLoadRequest::CreateDynamicImport(
|
||||
uri, script, aReferencingPrivate, aSpecifier, aPromise);
|
||||
|
||||
script->Loader()->StartDynamicImport(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScriptLoader::StartDynamicImport(ModuleLoadRequest* aRequest) {
|
||||
mDynamicImportRequests.AppendElement(aRequest);
|
||||
|
||||
nsresult rv = StartLoad(aRequest, NS_LITERAL_STRING("script"), false);
|
||||
if (NS_FAILED(rv)) {
|
||||
FinishDynamicImport(aRequest, rv);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptLoader::FinishDynamicImport(ModuleLoadRequest* aRequest,
|
||||
nsresult aResult) {
|
||||
AutoJSAPI jsapi;
|
||||
MOZ_ALWAYS_TRUE(jsapi.Init(aRequest->mDynamicPromise));
|
||||
FinishDynamicImport(jsapi.cx(), aRequest, aResult);
|
||||
}
|
||||
|
||||
void ScriptLoader::FinishDynamicImport(JSContext* aCx,
|
||||
ModuleLoadRequest* aRequest,
|
||||
nsresult aResult) {
|
||||
// Complete the dynamic import, report failures indicated by aResult or as a
|
||||
// pending exception on the context.
|
||||
|
||||
if (NS_FAILED(aResult)) {
|
||||
MOZ_ASSERT(!JS_IsExceptionPending(aCx));
|
||||
JS_ReportErrorNumberUC(aCx, js::GetErrorMessage, nullptr,
|
||||
JSMSG_IMPORT_SCRIPT_NOT_FOUND);
|
||||
}
|
||||
|
||||
JS::Rooted<JS::Value> referencingScript(aCx,
|
||||
aRequest->mDynamicReferencingPrivate);
|
||||
JS::Rooted<JSString*> specifier(aCx, aRequest->mDynamicSpecifier);
|
||||
JS::Rooted<JSObject*> promise(aCx, aRequest->mDynamicPromise);
|
||||
|
||||
JS::FinishDynamicModuleImport(aCx, referencingScript, specifier, promise);
|
||||
|
||||
// FinishDynamicModuleImport clears any pending exception.
|
||||
MOZ_ASSERT(!JS_IsExceptionPending(aCx));
|
||||
|
||||
aRequest->ClearDynamicImport();
|
||||
}
|
||||
|
||||
static void DynamicImportPrefChangedCallback(const char* aPrefName,
|
||||
void* aClosure) {
|
||||
bool enabled = Preferences::GetBool(aPrefName);
|
||||
JS::ModuleDynamicImportHook hook =
|
||||
enabled ? HostImportModuleDynamically : nullptr;
|
||||
|
||||
AutoJSAPI jsapi;
|
||||
jsapi.Init();
|
||||
JS::SetModuleDynamicImportHook(jsapi.cx(), hook);
|
||||
}
|
||||
|
||||
void ScriptLoader::EnsureModuleHooksInitialized() {
|
||||
AutoJSAPI jsapi;
|
||||
jsapi.Init();
|
||||
JSRuntime* rt = JS_GetRuntime(jsapi.cx());
|
||||
if (JS::GetModuleResolveHook(rt)) {
|
||||
return;
|
||||
}
|
||||
|
||||
JS::SetModuleResolveHook(rt, HostResolveImportedModule);
|
||||
JS::SetModuleMetadataHook(aCx, HostPopulateImportMeta);
|
||||
JS::SetModuleMetadataHook(jsapi.cx(), HostPopulateImportMeta);
|
||||
JS::SetScriptPrivateFinalizeHook(jsapi.cx(), HostFinalizeTopLevelScript);
|
||||
|
||||
Preferences::RegisterCallbackAndCall(DynamicImportPrefChangedCallback,
|
||||
"javascript.options.dynamicImport",
|
||||
(void*)nullptr);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -908,12 +1049,22 @@ public:
|
||||
: mLoader(aLoader)
|
||||
, mRequest(aRequest)
|
||||
{}
|
||||
NS_IMETHOD Run() override
|
||||
{
|
||||
NS_IMETHOD Run() override {
|
||||
if (mRequest->IsModuleRequest() &&
|
||||
mRequest->AsModuleRequest()->IsDynamicImport()) {
|
||||
mLoader->ProcessDynamicImport(mRequest->AsModuleRequest());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return mLoader->ProcessRequest(mRequest);
|
||||
}
|
||||
};
|
||||
|
||||
void ScriptLoader::RunScriptWhenSafe(ScriptLoadRequest* aRequest) {
|
||||
auto runnable = new ScriptRequestProcessor(this, aRequest);
|
||||
nsContentUtils::AddScriptRunner(runnable);
|
||||
}
|
||||
|
||||
void
|
||||
ScriptLoader::ProcessLoadedModuleTree(ModuleLoadRequest* aRequest)
|
||||
{
|
||||
@@ -925,12 +1076,13 @@ ScriptLoader::ProcessLoadedModuleTree(ModuleLoadRequest* aRequest)
|
||||
}
|
||||
}
|
||||
|
||||
if (aRequest->mIsInline &&
|
||||
aRequest->mElement->GetParserCreated() == NOT_FROM_PARSER)
|
||||
{
|
||||
MOZ_ASSERT(!aRequest->isInList());
|
||||
nsContentUtils::AddScriptRunner(
|
||||
new ScriptRequestProcessor(this, aRequest));
|
||||
if (aRequest->IsDynamicImport()) {
|
||||
MOZ_ASSERT(aRequest->isInList());
|
||||
RefPtr<ScriptLoadRequest> req = mDynamicImportRequests.Steal(aRequest);
|
||||
RunScriptWhenSafe(req);
|
||||
} else if (aRequest->mIsInline &&
|
||||
aRequest->Element()->GetParserCreated() == NOT_FROM_PARSER) {
|
||||
RunScriptWhenSafe(aRequest);
|
||||
} else {
|
||||
MaybeMoveToLoadedList(aRequest);
|
||||
ProcessPendingRequests();
|
||||
@@ -990,8 +1142,6 @@ ScriptLoader::InstantiateModuleTree(ModuleLoadRequest* aRequest)
|
||||
return false;
|
||||
}
|
||||
|
||||
EnsureModuleResolveHook(jsapi.cx());
|
||||
|
||||
JS::Rooted<JSObject*> module(jsapi.cx(), moduleScript->ModuleRecord());
|
||||
bool ok = NS_SUCCEEDED(nsJSUtils::ModuleInstantiate(jsapi.cx(), module));
|
||||
|
||||
@@ -1037,8 +1187,8 @@ ScriptLoader::StartLoad(ScriptLoadRequest *aRequest, const nsAString &aType,
|
||||
? nsIContentPolicy::TYPE_INTERNAL_SCRIPT_PRELOAD
|
||||
: nsIContentPolicy::TYPE_INTERNAL_SCRIPT;
|
||||
nsCOMPtr<nsINode> context;
|
||||
if (aRequest->mElement) {
|
||||
context = do_QueryInterface(aRequest->mElement);
|
||||
if (aRequest->Element()) {
|
||||
context = do_QueryInterface(aRequest->Element());
|
||||
}
|
||||
else {
|
||||
context = mDocument;
|
||||
@@ -1055,21 +1205,21 @@ ScriptLoader::StartLoad(ScriptLoadRequest *aRequest, const nsAString &aType,
|
||||
// According to the spec, module scripts have different behaviour to classic
|
||||
// scripts and always use CORS.
|
||||
securityFlags = nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS;
|
||||
if (aRequest->mCORSMode == CORS_NONE) {
|
||||
if (aRequest->CORSMode() == CORS_NONE) {
|
||||
securityFlags |= nsILoadInfo::SEC_COOKIES_OMIT;
|
||||
} else if (aRequest->mCORSMode == CORS_ANONYMOUS) {
|
||||
} else if (aRequest->CORSMode() == CORS_ANONYMOUS) {
|
||||
securityFlags |= nsILoadInfo::SEC_COOKIES_SAME_ORIGIN;
|
||||
} else {
|
||||
MOZ_ASSERT(aRequest->mCORSMode == CORS_USE_CREDENTIALS);
|
||||
MOZ_ASSERT(aRequest->CORSMode() == CORS_USE_CREDENTIALS);
|
||||
securityFlags |= nsILoadInfo::SEC_COOKIES_INCLUDE;
|
||||
}
|
||||
} else {
|
||||
securityFlags = aRequest->mCORSMode == CORS_NONE
|
||||
securityFlags = aRequest->CORSMode() == CORS_NONE
|
||||
? nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL
|
||||
: nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS;
|
||||
if (aRequest->mCORSMode == CORS_ANONYMOUS) {
|
||||
if (aRequest->CORSMode() == CORS_ANONYMOUS) {
|
||||
securityFlags |= nsILoadInfo::SEC_COOKIES_SAME_ORIGIN;
|
||||
} else if (aRequest->mCORSMode == CORS_USE_CREDENTIALS) {
|
||||
} else if (aRequest->CORSMode() == CORS_USE_CREDENTIALS) {
|
||||
securityFlags |= nsILoadInfo::SEC_COOKIES_INCLUDE;
|
||||
}
|
||||
}
|
||||
@@ -1108,7 +1258,7 @@ ScriptLoader::StartLoad(ScriptLoadRequest *aRequest, const nsAString &aType,
|
||||
NS_LITERAL_CSTRING("*/*"),
|
||||
false);
|
||||
httpChannel->SetReferrerWithPolicy(aRequest->mReferrer,
|
||||
aRequest->mReferrerPolicy);
|
||||
aRequest->ReferrerPolicy());
|
||||
|
||||
nsCOMPtr<nsIHttpChannelInternal> internalChannel(do_QueryInterface(httpChannel));
|
||||
if (internalChannel) {
|
||||
@@ -1230,22 +1380,21 @@ ScriptLoadRequest*
|
||||
ScriptLoader::CreateLoadRequest(ScriptKind aKind,
|
||||
nsIURI* aURI,
|
||||
nsIScriptElement* aElement,
|
||||
uint32_t aVersion, CORSMode aCORSMode,
|
||||
nsIPrincipal* aTriggeringPrincipal,
|
||||
CORSMode aCORSMode,
|
||||
const SRIMetadata& aIntegrity,
|
||||
mozilla::net::ReferrerPolicy aReferrerPolicy)
|
||||
{
|
||||
nsIURI* referrer = mDocument->GetDocumentURI();
|
||||
ScriptFetchOptions* fetchOptions =
|
||||
new ScriptFetchOptions(aCORSMode, aReferrerPolicy, aElement, aTriggeringPrincipal);
|
||||
|
||||
if (aKind == ScriptKind::Classic) {
|
||||
return new ScriptLoadRequest(aKind, aURI, aElement,
|
||||
aVersion, aCORSMode,
|
||||
aIntegrity,
|
||||
referrer, aReferrerPolicy);
|
||||
return new ScriptLoadRequest(aKind, aURI, fetchOptions, aIntegrity, referrer);
|
||||
}
|
||||
|
||||
MOZ_ASSERT(aKind == ScriptKind::Module);
|
||||
return new ModuleLoadRequest(aURI, aElement, aVersion, aCORSMode,
|
||||
aIntegrity, referrer, aReferrerPolicy, this);
|
||||
return ModuleLoadRequest::CreateTopLevel(aURI, fetchOptions, aIntegrity, referrer, this);
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -1332,7 +1481,7 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
|
||||
// preloaded
|
||||
// note that a script-inserted script can steal a preload!
|
||||
request = mPreloads[i].mRequest;
|
||||
request->mElement = aElement;
|
||||
request->SetElement(aElement);
|
||||
nsString preloadCharset(mPreloads[i].mCharset);
|
||||
mPreloads.RemoveElementAt(i);
|
||||
|
||||
@@ -1341,8 +1490,8 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
|
||||
nsAutoString elementCharset;
|
||||
aElement->GetScriptCharset(elementCharset);
|
||||
if (elementCharset.Equals(preloadCharset) &&
|
||||
ourCORSMode == request->mCORSMode &&
|
||||
ourRefPolicy == request->mReferrerPolicy &&
|
||||
ourCORSMode == request->CORSMode() &&
|
||||
ourRefPolicy == request->ReferrerPolicy() &&
|
||||
scriptKind == request->mKind) {
|
||||
rv = CheckContentPolicy(mDocument, aElement, request->mURI, type, false);
|
||||
if (NS_FAILED(rv)) {
|
||||
@@ -1385,9 +1534,10 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
|
||||
}
|
||||
}
|
||||
|
||||
request = CreateLoadRequest(scriptKind, scriptURI, aElement,
|
||||
version, ourCORSMode, sriMetadata,
|
||||
ourRefPolicy);
|
||||
nsCOMPtr<nsIPrincipal> principal = scriptContent->NodePrincipal();
|
||||
|
||||
request = CreateLoadRequest(scriptKind, scriptURI, aElement, principal,
|
||||
ourCORSMode, sriMetadata, ourRefPolicy);
|
||||
request->mIsInline = false;
|
||||
request->SetScriptMode(aElement->GetScriptDeferred(),
|
||||
aElement->GetScriptAsync());
|
||||
@@ -1408,8 +1558,6 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
|
||||
NS_ASSERTION(!request->InCompilingStage() || request->IsModuleRequest(),
|
||||
"Request should not yet be in compiling stage.");
|
||||
|
||||
request->mJSVersion = version;
|
||||
|
||||
if (request->IsAsyncScript()) {
|
||||
AddAsyncRequest(request);
|
||||
if (request->IsReadyToRun()) {
|
||||
@@ -1507,10 +1655,10 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
|
||||
|
||||
// Inline scripts ignore their CORS mode and are always CORS_NONE.
|
||||
request = CreateLoadRequest(scriptKind, mDocument->GetDocumentURI(), aElement,
|
||||
version, CORS_NONE,
|
||||
mDocument->NodePrincipal(),
|
||||
CORS_NONE,
|
||||
SRIMetadata(), // SRI doesn't apply
|
||||
ourRefPolicy);
|
||||
request->mJSVersion = version;
|
||||
request->mIsInline = true;
|
||||
request->mLineNo = aElement->GetScriptLineNumber();
|
||||
|
||||
@@ -1760,7 +1908,7 @@ ScriptLoader::GetScriptSource(ScriptLoadRequest* aRequest, nsAutoString& inlineD
|
||||
if (aRequest->mIsInline) {
|
||||
// XXX This is inefficient - GetText makes multiple
|
||||
// copies.
|
||||
aRequest->mElement->GetScriptText(inlineData);
|
||||
aRequest->Element()->GetScriptText(inlineData);
|
||||
return SourceBufferHolder(inlineData.get(),
|
||||
inlineData.Length(),
|
||||
SourceBufferHolder::NoOwnership);
|
||||
@@ -1781,15 +1929,22 @@ ScriptLoader::ProcessRequest(ScriptLoadRequest* aRequest)
|
||||
|
||||
NS_ENSURE_ARG(aRequest);
|
||||
|
||||
if (aRequest->IsModuleRequest() &&
|
||||
!aRequest->AsModuleRequest()->mModuleScript)
|
||||
{
|
||||
// There was an error fetching a module script. Nothing to do here.
|
||||
FireScriptAvailable(NS_ERROR_FAILURE, aRequest);
|
||||
return NS_OK;
|
||||
if (aRequest->IsModuleRequest()) {
|
||||
ModuleLoadRequest* request = aRequest->AsModuleRequest();
|
||||
if (request->mModuleScript) {
|
||||
if (!InstantiateModuleTree(request)) {
|
||||
request->mModuleScript = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (!request->mModuleScript) {
|
||||
// There was an error fetching a module script. Nothing to do here.
|
||||
FireScriptAvailable(NS_ERROR_FAILURE, aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsINode> scriptElem = do_QueryInterface(aRequest->mElement);
|
||||
nsCOMPtr<nsINode> scriptElem = do_QueryInterface(aRequest->Element());
|
||||
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
if (!aRequest->mIsInline) {
|
||||
@@ -1797,13 +1952,13 @@ ScriptLoader::ProcessRequest(ScriptLoadRequest* aRequest)
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIScriptElement> oldParserInsertedScript;
|
||||
uint32_t parserCreated = aRequest->mElement->GetParserCreated();
|
||||
uint32_t parserCreated = aRequest->Element()->GetParserCreated();
|
||||
if (parserCreated) {
|
||||
oldParserInsertedScript = mCurrentParserInsertedScript;
|
||||
mCurrentParserInsertedScript = aRequest->mElement;
|
||||
mCurrentParserInsertedScript = aRequest->Element();
|
||||
}
|
||||
|
||||
aRequest->mElement->BeginEvaluating();
|
||||
aRequest->Element()->BeginEvaluating();
|
||||
|
||||
FireScriptAvailable(NS_OK, aRequest);
|
||||
|
||||
@@ -1848,7 +2003,7 @@ ScriptLoader::ProcessRequest(ScriptLoadRequest* aRequest)
|
||||
|
||||
FireScriptEvaluated(rv, aRequest);
|
||||
|
||||
aRequest->mElement->EndEvaluating();
|
||||
aRequest->Element()->EndEvaluating();
|
||||
|
||||
if (parserCreated) {
|
||||
mCurrentParserInsertedScript = oldParserInsertedScript;
|
||||
@@ -1871,13 +2026,32 @@ ScriptLoader::ProcessRequest(ScriptLoadRequest* aRequest)
|
||||
return rv;
|
||||
}
|
||||
|
||||
void ScriptLoader::ProcessDynamicImport(ModuleLoadRequest* aRequest) {
|
||||
if (aRequest->mModuleScript) {
|
||||
if (!InstantiateModuleTree(aRequest)) {
|
||||
aRequest->mModuleScript = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
if (aRequest->mModuleScript) {
|
||||
rv = EvaluateScript(aRequest);
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
FinishDynamicImport(aRequest, rv);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
ScriptLoader::FireScriptAvailable(nsresult aResult,
|
||||
ScriptLoadRequest* aRequest)
|
||||
{
|
||||
for (int32_t i = 0; i < mObservers.Count(); i++) {
|
||||
nsCOMPtr<nsIScriptLoaderObserver> obs = mObservers[i];
|
||||
obs->ScriptAvailable(aResult, aRequest->mElement,
|
||||
obs->ScriptAvailable(aResult, aRequest->Element(),
|
||||
aRequest->mIsInline, aRequest->mURI,
|
||||
aRequest->mLineNo);
|
||||
}
|
||||
@@ -1891,7 +2065,7 @@ ScriptLoader::FireScriptEvaluated(nsresult aResult,
|
||||
{
|
||||
for (int32_t i = 0; i < mObservers.Count(); i++) {
|
||||
nsCOMPtr<nsIScriptLoaderObserver> obs = mObservers[i];
|
||||
obs->ScriptEvaluated(aResult, aRequest->mElement,
|
||||
obs->ScriptEvaluated(aResult, aRequest->Element(),
|
||||
aRequest->mIsInline);
|
||||
}
|
||||
|
||||
@@ -1920,10 +2094,9 @@ ScriptLoader::GetScriptGlobalObject()
|
||||
}
|
||||
|
||||
nsresult
|
||||
ScriptLoader::FillCompileOptionsForRequest(const AutoJSAPI&jsapi,
|
||||
ScriptLoadRequest* aRequest,
|
||||
JS::Handle<JSObject*> aScopeChain,
|
||||
JS::CompileOptions* aOptions)
|
||||
ScriptLoader::FillCompileOptionsForRequest(
|
||||
const mozilla::dom::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.
|
||||
@@ -1939,7 +2112,6 @@ ScriptLoader::FillCompileOptionsForRequest(const AutoJSAPI&jsapi,
|
||||
aOptions->setIntroductionType(isScriptElement ? "scriptElement"
|
||||
: "importedModule");
|
||||
aOptions->setFileAndLine(aRequest->mURL.get(), aRequest->mLineNo);
|
||||
aOptions->setVersion(JSVersion(aRequest->mJSVersion));
|
||||
aOptions->setIsRunOnce(true);
|
||||
// We only need the setNoScriptRval bit when compiling off-thread here, since
|
||||
// otherwise nsJSUtils::EvaluateString will set it up for us.
|
||||
@@ -1957,8 +2129,8 @@ ScriptLoader::FillCompileOptionsForRequest(const AutoJSAPI&jsapi,
|
||||
// Only do this for classic scripts.
|
||||
JSContext* cx = jsapi.cx();
|
||||
JS::Rooted<JS::Value> elementVal(cx);
|
||||
MOZ_ASSERT(aRequest->mElement);
|
||||
if (NS_SUCCEEDED(nsContentUtils::WrapNative(cx, aRequest->mElement,
|
||||
MOZ_ASSERT(aRequest->Element());
|
||||
if (NS_SUCCEEDED(nsContentUtils::WrapNative(cx, aRequest->Element(),
|
||||
&elementVal,
|
||||
/* aAllowWrapping = */ true))) {
|
||||
MOZ_ASSERT(elementVal.isObject());
|
||||
@@ -1969,6 +2141,19 @@ ScriptLoader::FillCompileOptionsForRequest(const AutoJSAPI&jsapi,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
class MOZ_RAII AutoSetProcessingScriptTag {
|
||||
nsCOMPtr<nsIScriptContext> mContext;
|
||||
bool mOldTag;
|
||||
|
||||
public:
|
||||
explicit AutoSetProcessingScriptTag(nsIScriptContext* aContext)
|
||||
: mContext(aContext), mOldTag(mContext->GetProcessingScriptTag()) {
|
||||
mContext->SetProcessingScriptTag(true);
|
||||
}
|
||||
|
||||
~AutoSetProcessingScriptTag() { mContext->SetProcessingScriptTag(mOldTag); }
|
||||
};
|
||||
|
||||
nsresult
|
||||
ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest)
|
||||
{
|
||||
@@ -1977,7 +2162,7 @@ ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest)
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIContent> scriptContent(do_QueryInterface(aRequest->mElement));
|
||||
nsCOMPtr<nsIContent> scriptContent(do_QueryInterface(aRequest->Element()));
|
||||
nsIDocument* ownerDoc = scriptContent->OwnerDoc();
|
||||
if (ownerDoc != mDocument) {
|
||||
// Willful violation of HTML5 as of 2010-12-01
|
||||
@@ -2000,11 +2185,6 @@ ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest)
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSVersion version = JSVersion(aRequest->mJSVersion);
|
||||
if (version == JSVERSION_UNKNOWN) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// New script entry point required, due to the "Create a script" sub-step of
|
||||
// http://www.whatwg.org/specs/web-apps/current-work/#execute-the-script-block
|
||||
nsAutoMicroTask mt;
|
||||
@@ -2012,8 +2192,7 @@ ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest)
|
||||
JSContext* cx = aes.cx();
|
||||
JS::Rooted<JSObject*> global(cx, globalObject->GetGlobalJSObject());
|
||||
|
||||
bool oldProcessingScriptTag = context->GetProcessingScriptTag();
|
||||
context->SetProcessingScriptTag(true);
|
||||
AutoSetProcessingScriptTag setProcessingScriptTag(context);
|
||||
nsresult rv;
|
||||
{
|
||||
Maybe<AutoCurrentScriptUpdater> masterScriptUpdater;
|
||||
@@ -2025,15 +2204,13 @@ ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest)
|
||||
// script. So let's update the mCurrentScript of the ScriptLoader
|
||||
// of the master document too.
|
||||
masterScriptUpdater.emplace(master->ScriptLoader(),
|
||||
aRequest->mElement);
|
||||
aRequest->Element());
|
||||
}
|
||||
|
||||
if (aRequest->IsModuleRequest()) {
|
||||
// For modules, currentScript is set to null.
|
||||
AutoCurrentScriptUpdater scriptUpdater(this, nullptr);
|
||||
|
||||
EnsureModuleResolveHook(cx);
|
||||
|
||||
ModuleLoadRequest* request = aRequest->AsModuleRequest();
|
||||
MOZ_ASSERT(request->mModuleScript);
|
||||
MOZ_ASSERT(!request->mOffThreadToken);
|
||||
@@ -2043,7 +2220,13 @@ ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest)
|
||||
// Module has an error status to be rethrown
|
||||
JS::Rooted<JS::Value> error(cx, moduleScript->ErrorToRethrow());
|
||||
JS_SetPendingException(cx, error);
|
||||
return NS_OK; // An error is reported by AutoEntryScript.
|
||||
|
||||
// For a dynamic import, the promise is rejected. Otherwise an error is
|
||||
// either reported by AutoEntryScript.
|
||||
if (request->IsDynamicImport()) {
|
||||
FinishDynamicImport(cx, request, NS_OK);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
JS::Rooted<JSObject*> module(cx, moduleScript->ModuleRecord());
|
||||
@@ -2052,12 +2235,17 @@ ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest)
|
||||
rv = nsJSUtils::ModuleEvaluate(cx, module);
|
||||
MOZ_ASSERT(NS_FAILED(rv) == aes.HasException());
|
||||
if (NS_FAILED(rv)) {
|
||||
// Evaluation failed
|
||||
rv = NS_OK; // An error is reported by AutoEntryScript.
|
||||
// For a dynamic import, the promise is rejected. Otherwise an error is
|
||||
// either reported by AutoEntryScript.
|
||||
rv = NS_OK;
|
||||
}
|
||||
|
||||
if (request->IsDynamicImport()) {
|
||||
FinishDynamicImport(cx, request, rv);
|
||||
}
|
||||
} else {
|
||||
// Update our current script.
|
||||
AutoCurrentScriptUpdater scriptUpdater(this, aRequest->mElement);
|
||||
AutoCurrentScriptUpdater scriptUpdater(this, aRequest->Element());
|
||||
|
||||
JS::CompileOptions options(cx);
|
||||
rv = FillCompileOptionsForRequest(aes, aRequest, global, &options);
|
||||
@@ -2071,7 +2259,6 @@ ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest)
|
||||
}
|
||||
}
|
||||
|
||||
context->SetProcessingScriptTag(oldProcessingScriptTag);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -2083,6 +2270,7 @@ ScriptLoader::ProcessPendingRequestsAsync()
|
||||
!mLoadedAsyncRequests.isEmpty() ||
|
||||
!mNonAsyncExternalScriptInsertedRequests.isEmpty() ||
|
||||
!mDeferRequests.isEmpty() ||
|
||||
!mDynamicImportRequests.isEmpty() ||
|
||||
!mPendingChildLoaders.IsEmpty()) {
|
||||
NS_DispatchToCurrentThread(NewRunnableMethod(this,
|
||||
&ScriptLoader::ProcessPendingRequests));
|
||||
@@ -2371,7 +2559,7 @@ ScriptLoader::VerifySRI(ScriptLoadRequest* aRequest,
|
||||
loadInfo->LoadingPrincipal()->GetCsp(getter_AddRefs(csp));
|
||||
nsAutoCString violationURISpec;
|
||||
mDocument->GetDocumentURI()->GetAsciiSpec(violationURISpec);
|
||||
uint32_t lineNo = aRequest->mElement ? aRequest->mElement->GetScriptLineNumber() : 0;
|
||||
uint32_t lineNo = aRequest->Element() ? aRequest->Element()->GetScriptLineNumber() : 0;
|
||||
csp->LogViolationDetails(
|
||||
nsIContentSecurityPolicy::VIOLATION_TYPE_REQUIRE_SRI_FOR_SCRIPT,
|
||||
NS_ConvertUTF8toUTF16(violationURISpec),
|
||||
@@ -2425,13 +2613,30 @@ ScriptLoader::HandleLoadError(ScriptLoadRequest *aRequest, nsresult aResult) {
|
||||
RefPtr<ScriptLoadRequest> req = mXSLTRequests.Steal(aRequest);
|
||||
FireScriptAvailable(aResult, req);
|
||||
}
|
||||
} else if (aRequest->IsModuleRequest() && !aRequest->IsPreload()) {
|
||||
} else if (aRequest->IsPreload()) {
|
||||
if (aRequest->IsModuleRequest()) {
|
||||
aRequest->Cancel();
|
||||
}
|
||||
if (aRequest->IsTopLevel()) {
|
||||
MOZ_ALWAYS_TRUE(
|
||||
mPreloads.RemoveElement(aRequest, PreloadRequestComparator()));
|
||||
}
|
||||
MOZ_ASSERT(!aRequest->isInList());
|
||||
} else if (aRequest->IsModuleRequest()) {
|
||||
ModuleLoadRequest* modReq = aRequest->AsModuleRequest();
|
||||
MOZ_ASSERT(!modReq->IsTopLevel());
|
||||
MOZ_ASSERT(!modReq->isInList());
|
||||
modReq->Cancel();
|
||||
// A single error is fired for the top level module, so don't use
|
||||
// FireScriptAvailable here.
|
||||
if (modReq->IsDynamicImport()) {
|
||||
MOZ_ASSERT(modReq->IsTopLevel());
|
||||
if (aRequest->isInList()) {
|
||||
RefPtr<ScriptLoadRequest> req = mDynamicImportRequests.Steal(aRequest);
|
||||
modReq->Cancel();
|
||||
FinishDynamicImport(modReq, aResult);
|
||||
}
|
||||
} else {
|
||||
MOZ_ASSERT(!modReq->IsTopLevel());
|
||||
MOZ_ASSERT(!modReq->isInList());
|
||||
modReq->Cancel();
|
||||
// The error is handled for the top level module.
|
||||
}
|
||||
} else if (mParserBlockingRequest == aRequest) {
|
||||
MOZ_ASSERT(!aRequest->isInList());
|
||||
mParserBlockingRequest = nullptr;
|
||||
@@ -2439,22 +2644,13 @@ ScriptLoader::HandleLoadError(ScriptLoadRequest *aRequest, nsresult aResult) {
|
||||
|
||||
// Ensure that we treat request->mElement as our current parser-inserted
|
||||
// script while firing onerror on it.
|
||||
MOZ_ASSERT(aRequest->mElement->GetParserCreated());
|
||||
MOZ_ASSERT(aRequest->Element()->GetParserCreated());
|
||||
nsCOMPtr<nsIScriptElement> oldParserInsertedScript =
|
||||
mCurrentParserInsertedScript;
|
||||
mCurrentParserInsertedScript = aRequest->mElement;
|
||||
mCurrentParserInsertedScript = aRequest->Element();
|
||||
FireScriptAvailable(aResult, aRequest);
|
||||
ContinueParserAsync(aRequest);
|
||||
mCurrentParserInsertedScript = oldParserInsertedScript;
|
||||
} else if (aRequest->IsPreload()) {
|
||||
if (aRequest->IsModuleRequest()) {
|
||||
// If there is an error preloading modules, cancel the load request.
|
||||
aRequest->Cancel();
|
||||
}
|
||||
if (aRequest->IsTopLevel()) {
|
||||
MOZ_ALWAYS_TRUE(mPreloads.RemoveElement(aRequest, PreloadRequestComparator()));
|
||||
}
|
||||
MOZ_ASSERT(!aRequest->isInList());
|
||||
} else {
|
||||
// This happens for blocking requests cancelled by ParsingComplete().
|
||||
MOZ_ASSERT(aRequest->IsCanceled());
|
||||
@@ -2466,13 +2662,13 @@ ScriptLoader::HandleLoadError(ScriptLoadRequest *aRequest, nsresult aResult) {
|
||||
void
|
||||
ScriptLoader::UnblockParser(ScriptLoadRequest* aParserBlockingRequest)
|
||||
{
|
||||
aParserBlockingRequest->mElement->UnblockParser();
|
||||
aParserBlockingRequest->Element()->UnblockParser();
|
||||
}
|
||||
|
||||
void
|
||||
ScriptLoader::ContinueParserAsync(ScriptLoadRequest* aParserBlockingRequest)
|
||||
{
|
||||
aParserBlockingRequest->mElement->ContinueParserAsync();
|
||||
aParserBlockingRequest->Element()->ContinueParserAsync();
|
||||
}
|
||||
|
||||
uint32_t
|
||||
@@ -2548,7 +2744,7 @@ ScriptLoader::PrepareLoadedRequest(ScriptLoadRequest* aRequest,
|
||||
// If this load was subject to a CORS check, don't flag it with a separate
|
||||
// origin principal, so that it will treat our document's principal as the
|
||||
// origin principal. Module loads always use CORS.
|
||||
if (!aRequest->IsModuleRequest() && aRequest->mCORSMode == CORS_NONE) {
|
||||
if (!aRequest->IsModuleRequest() && aRequest->CORSMode() == CORS_NONE) {
|
||||
rv = nsContentUtils::GetSecurityManager()->
|
||||
GetChannelResultPrincipal(channel, getter_AddRefs(aRequest->mOriginPrincipal));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@@ -2567,11 +2763,12 @@ ScriptLoader::PrepareLoadedRequest(ScriptLoadRequest* aRequest,
|
||||
mLoadingAsyncRequests.Contains(aRequest) ||
|
||||
mNonAsyncExternalScriptInsertedRequests.Contains(aRequest) ||
|
||||
mXSLTRequests.Contains(aRequest) ||
|
||||
mDynamicImportRequests.Contains(aRequest) ||
|
||||
(aRequest->IsModuleRequest() &&
|
||||
!aRequest->AsModuleRequest()->IsTopLevel() &&
|
||||
!aRequest->isInList()) ||
|
||||
mPreloads.Contains(aRequest, PreloadRequestComparator()) ||
|
||||
mParserBlockingRequest,
|
||||
mParserBlockingRequest == aRequest,
|
||||
"aRequest should be pending!");
|
||||
|
||||
if (aRequest->IsModuleRequest()) {
|
||||
@@ -2649,6 +2846,13 @@ ScriptLoader::ParsingComplete(bool aTerminated)
|
||||
mLoadedAsyncRequests.Clear();
|
||||
mNonAsyncExternalScriptInsertedRequests.Clear();
|
||||
mXSLTRequests.Clear();
|
||||
|
||||
for (ScriptLoadRequest* req = mDynamicImportRequests.getFirst(); req;
|
||||
req = req->getNext()) {
|
||||
req->Cancel();
|
||||
FinishDynamicImport(req->AsModuleRequest(), NS_ERROR_ABORT);
|
||||
}
|
||||
|
||||
if (mParserBlockingRequest) {
|
||||
mParserBlockingRequest->Cancel();
|
||||
mParserBlockingRequest = nullptr;
|
||||
@@ -2716,7 +2920,8 @@ ScriptLoader::PreloadURI(nsIURI *aURI,
|
||||
}
|
||||
|
||||
RefPtr<ScriptLoadRequest> request =
|
||||
CreateLoadRequest(scriptKind, aURI, nullptr, 0,
|
||||
CreateLoadRequest(scriptKind, aURI, nullptr,
|
||||
mDocument->NodePrincipal(),
|
||||
Element::StringToCORSMode(aCrossOrigin), sriMetadata,
|
||||
aReferrerPolicy);
|
||||
request->mIsInline = false;
|
||||
|
||||
+82
-21
@@ -47,6 +47,33 @@ enum class ScriptKind {
|
||||
Module
|
||||
};
|
||||
|
||||
/*
|
||||
* Some options used when fetching script resources. This only loosely
|
||||
* corresponds to HTML's "script fetch options".
|
||||
*
|
||||
* These are common to all modules in a module graph, and hence a single
|
||||
* instance is shared by all ModuleLoadRequest objects in a graph.
|
||||
*/
|
||||
|
||||
class ScriptFetchOptions
|
||||
{
|
||||
~ScriptFetchOptions();
|
||||
|
||||
public:
|
||||
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(ScriptFetchOptions)
|
||||
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(ScriptFetchOptions)
|
||||
|
||||
ScriptFetchOptions(mozilla::CORSMode aCORSMode,
|
||||
mozilla::net::ReferrerPolicy aReferrerPolicy,
|
||||
nsIScriptElement* aElement,
|
||||
nsIPrincipal* aTriggeringPrincipal);
|
||||
|
||||
const mozilla::CORSMode mCORSMode;
|
||||
const mozilla::net::ReferrerPolicy mReferrerPolicy;
|
||||
nsCOMPtr<nsIScriptElement> mElement;
|
||||
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
|
||||
};
|
||||
|
||||
class ScriptLoadRequest : public nsISupports,
|
||||
private mozilla::LinkedListElement<ScriptLoadRequest>
|
||||
{
|
||||
@@ -62,16 +89,12 @@ protected:
|
||||
public:
|
||||
ScriptLoadRequest(ScriptKind aKind,
|
||||
nsIURI* aURI,
|
||||
nsIScriptElement* aElement,
|
||||
uint32_t aVersion,
|
||||
mozilla::CORSMode aCORSMode,
|
||||
ScriptFetchOptions* aFetchOptions,
|
||||
const SRIMetadata& aIntegrity,
|
||||
nsIURI* aReferrer,
|
||||
mozilla::net::ReferrerPolicy aReferrerPolicy)
|
||||
nsIURI* aReferrer)
|
||||
: mKind(aKind),
|
||||
mElement(aElement),
|
||||
mProgress(Progress::Loading),
|
||||
mScriptMode(ScriptMode::eBlocking),
|
||||
mProgress(Progress::Loading),
|
||||
mIsInline(true),
|
||||
mHasSourceMapURL(false),
|
||||
mInDeferList(false),
|
||||
@@ -83,13 +106,10 @@ public:
|
||||
mOffThreadToken(nullptr),
|
||||
mScriptTextBuf(nullptr),
|
||||
mScriptTextLength(0),
|
||||
mJSVersion(aVersion),
|
||||
mURI(aURI),
|
||||
mLineNo(1),
|
||||
mCORSMode(aCORSMode),
|
||||
mIntegrity(aIntegrity),
|
||||
mReferrer(aReferrer),
|
||||
mReferrerPolicy(aReferrerPolicy)
|
||||
mReferrer(aReferrer)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -106,16 +126,16 @@ public:
|
||||
void FireScriptAvailable(nsresult aResult)
|
||||
{
|
||||
bool isInlineClassicScript = mIsInline && !IsModuleRequest();
|
||||
mElement->ScriptAvailable(aResult, mElement, isInlineClassicScript, mURI, mLineNo);
|
||||
Element()->ScriptAvailable(aResult, Element(), isInlineClassicScript, mURI, mLineNo);
|
||||
}
|
||||
void FireScriptEvaluated(nsresult aResult)
|
||||
{
|
||||
mElement->ScriptEvaluated(aResult, mElement, mIsInline);
|
||||
Element()->ScriptEvaluated(aResult, Element(), mIsInline);
|
||||
}
|
||||
|
||||
bool IsPreload()
|
||||
{
|
||||
return mElement == nullptr;
|
||||
return Element() == nullptr;
|
||||
}
|
||||
|
||||
virtual void Cancel();
|
||||
@@ -178,15 +198,42 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
mozilla::CORSMode CORSMode() const
|
||||
{
|
||||
return mFetchOptions->mCORSMode;
|
||||
}
|
||||
mozilla::net::ReferrerPolicy ReferrerPolicy() const
|
||||
{
|
||||
return mFetchOptions->mReferrerPolicy;
|
||||
}
|
||||
nsIScriptElement* Element() const
|
||||
{
|
||||
return mFetchOptions->mElement;
|
||||
}
|
||||
nsIPrincipal* TriggeringPrincipal() const
|
||||
{
|
||||
return mFetchOptions->mTriggeringPrincipal;
|
||||
}
|
||||
|
||||
void SetElement(nsIScriptElement* aElement)
|
||||
{
|
||||
// Called when a preload request is later used for an actual request.
|
||||
MOZ_ASSERT(aElement);
|
||||
MOZ_ASSERT(!Element());
|
||||
mFetchOptions->mElement = aElement;
|
||||
}
|
||||
|
||||
void SetScript(JSScript* aScript);
|
||||
|
||||
void MaybeCancelOffThreadScript();
|
||||
|
||||
using super::getNext;
|
||||
using super::isInList;
|
||||
|
||||
const ScriptKind mKind;
|
||||
nsCOMPtr<nsIScriptElement> mElement;
|
||||
const ScriptKind mKind; // Whether this is a classic script or a module script.
|
||||
ScriptMode mScriptMode; // Whether this is a blocking, defer or async script.
|
||||
Progress mProgress; // Are we still waiting for a load to complete?
|
||||
ScriptMode mScriptMode; // Whether this script is blocking, deferred or async.
|
||||
bool mScriptFromHead; // Synchronous head script block loading of other non js/css content.
|
||||
bool mIsInline; // Is the script inline or loaded?
|
||||
bool mHasSourceMapURL; // Does the HTTP header have a source map url?
|
||||
bool mInDeferList; // True if we live in mDeferRequests.
|
||||
@@ -199,15 +246,18 @@ public:
|
||||
nsString mSourceMapURL; // Holds source map url for loaded scripts
|
||||
char16_t* mScriptTextBuf; // Holds script text for non-inline scripts. Don't
|
||||
size_t mScriptTextLength; // use nsString so we can give ownership to jsapi.
|
||||
uint32_t mJSVersion;
|
||||
const nsCOMPtr<nsIURI> mURI;
|
||||
nsCOMPtr<nsIPrincipal> mOriginPrincipal;
|
||||
nsAutoCString mURL; // Keep the URI's filename alive during off thread parsing.
|
||||
int32_t mLineNo;
|
||||
const mozilla::CORSMode mCORSMode;
|
||||
const SRIMetadata mIntegrity;
|
||||
const nsCOMPtr<nsIURI> mReferrer;
|
||||
const mozilla::net::ReferrerPolicy mReferrerPolicy;
|
||||
|
||||
RefPtr<ScriptFetchOptions> mFetchOptions;
|
||||
|
||||
// Holds the top-level JSScript that corresponds to the current source, once
|
||||
// it is parsed, and planned to be saved in the bytecode cache.
|
||||
JS::Heap<JSScript*> mScript;
|
||||
};
|
||||
|
||||
class ScriptLoadRequestList : private mozilla::LinkedList<ScriptLoadRequest>
|
||||
@@ -511,13 +561,20 @@ public:
|
||||
*/
|
||||
void ClearModuleMap();
|
||||
|
||||
void StartDynamicImport(ModuleLoadRequest* aRequest);
|
||||
void FinishDynamicImport(ModuleLoadRequest* aRequest, nsresult aResult);
|
||||
void FinishDynamicImport(JSContext* aCx, ModuleLoadRequest* aRequest,
|
||||
nsresult aResult);
|
||||
|
||||
private:
|
||||
virtual ~ScriptLoader();
|
||||
|
||||
void EnsureModuleHooksInitialized();
|
||||
|
||||
ScriptLoadRequest* CreateLoadRequest(ScriptKind aKind,
|
||||
nsIURI* aURI,
|
||||
nsIScriptElement* aElement,
|
||||
uint32_t aVersion,
|
||||
nsIPrincipal* aTriggeringPrincipal,
|
||||
mozilla::CORSMode aCORSMode,
|
||||
const SRIMetadata& aIntegrity,
|
||||
mozilla::net::ReferrerPolicy aReferrerPolicy);
|
||||
@@ -591,6 +648,7 @@ private:
|
||||
|
||||
nsresult AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest);
|
||||
nsresult ProcessRequest(ScriptLoadRequest* aRequest);
|
||||
void ProcessDynamicImport(ModuleLoadRequest* aRequest);
|
||||
nsresult CompileOffThreadOrProcessRequest(ScriptLoadRequest* aRequest);
|
||||
void FireScriptAvailable(nsresult aResult,
|
||||
ScriptLoadRequest* aRequest);
|
||||
@@ -645,6 +703,8 @@ private:
|
||||
RefPtr<mozilla::GenericPromise>
|
||||
StartFetchingModuleAndDependencies(ModuleLoadRequest* aParent, nsIURI* aURI);
|
||||
|
||||
void RunScriptWhenSafe(ScriptLoadRequest* aRequest);
|
||||
|
||||
nsIDocument* mDocument; // [WEAK]
|
||||
nsCOMArray<nsIScriptLoaderObserver> mObservers;
|
||||
ScriptLoadRequestList mNonAsyncExternalScriptInsertedRequests;
|
||||
@@ -654,6 +714,7 @@ private:
|
||||
ScriptLoadRequestList mLoadedAsyncRequests;
|
||||
ScriptLoadRequestList mDeferRequests;
|
||||
ScriptLoadRequestList mXSLTRequests;
|
||||
ScriptLoadRequestList mDynamicImportRequests;
|
||||
RefPtr<ScriptLoadRequest> mParserBlockingRequest;
|
||||
|
||||
// In mRequests, the additional information here is stored by the element.
|
||||
|
||||
Reference in New Issue
Block a user