author | Andrea Marchesini <amarchesini@mozilla.com> |
Mon, 08 May 2017 08:25:03 +0200 | |
changeset 357088 | f0b31688e9f32fbc0898740f1ad733823ef393ef |
parent 357087 | 692529b223ec44199999aaf201a6a14fce674398 |
child 357089 | 1054eb4b27827df1a64ac98e7ad1a7994538a8c0 |
push id | 31782 |
push user | kwierso@gmail.com |
push date | Mon, 08 May 2017 23:07:35 +0000 |
treeherder | mozilla-central@b21b974d60d3 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | ehsan |
bugs | 1362119 |
milestone | 55.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/dom/script/ModuleLoadRequest.cpp +++ b/dom/script/ModuleLoadRequest.cpp @@ -22,17 +22,17 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED(Modul 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, + const SRIMetadata& aIntegrity, ScriptLoader* aLoader) : ScriptLoadRequest(ScriptKind::Module, aElement, aVersion, aCORSMode, aIntegrity), mIsTopLevel(true), mLoader(aLoader)
--- a/dom/script/ModuleLoadRequest.h +++ b/dom/script/ModuleLoadRequest.h @@ -32,17 +32,18 @@ public: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ModuleLoadRequest, ScriptLoadRequest) ModuleLoadRequest(nsIScriptElement* aElement, uint32_t aVersion, CORSMode aCORSMode, const SRIMetadata& aIntegrity, ScriptLoader* aLoader); - bool IsTopLevel() const { + bool IsTopLevel() const + { return mIsTopLevel; } void SetReady() override; void Cancel() override; void ModuleLoaded(); void DependenciesLoaded();
--- a/dom/script/ModuleScript.cpp +++ b/dom/script/ModuleScript.cpp @@ -31,17 +31,17 @@ 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, +ModuleScript::ModuleScript(ScriptLoader* aLoader, nsIURI* aBaseURL, JS::Handle<JSObject*> aModuleRecord) : mLoader(aLoader), mBaseURL(aBaseURL), mModuleRecord(aModuleRecord), mInstantiationState(Uninstantiated) { MOZ_ASSERT(mLoader); MOZ_ASSERT(mBaseURL);
--- a/dom/script/ModuleScript.h +++ b/dom/script/ModuleScript.h @@ -43,23 +43,29 @@ public: 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 { + + bool IsUninstantiated() const + { return mInstantiationState == Uninstantiated; } - bool IsInstantiated() const { + + bool IsInstantiated() const + { return mInstantiationState == Instantiated; } - bool InstantiationFailed() const { + + bool InstantiationFailed() const + { return mInstantiationState == Errored; } void UnlinkModuleRecord(); }; } // dom namespace } // mozilla namespace
--- a/dom/script/ScriptElement.cpp +++ b/dom/script/ScriptElement.cpp @@ -15,19 +15,19 @@ #include "nsGkAtoms.h" #include "nsContentSink.h" using namespace mozilla; using namespace mozilla::dom; NS_IMETHODIMP ScriptElement::ScriptAvailable(nsresult aResult, - nsIScriptElement *aElement, + nsIScriptElement* aElement, bool aIsInline, - nsIURI *aURI, + nsIURI* aURI, int32_t aLineNo) { if (!aIsInline && NS_FAILED(aResult)) { nsCOMPtr<nsIParser> parser = do_QueryReferent(mCreatorParser); if (parser) { parser->PushDefinedInsertionPoint(); } nsresult rv = FireErrorEvent(); @@ -49,17 +49,17 @@ ScriptElement::FireErrorEvent() cont, NS_LITERAL_STRING("error"), false /* bubbles */, false /* cancelable */); } NS_IMETHODIMP ScriptElement::ScriptEvaluated(nsresult aResult, - nsIScriptElement *aElement, + nsIScriptElement* aElement, bool aIsInline) { nsresult rv = NS_OK; if (!aIsInline) { nsCOMPtr<nsIContent> cont = do_QueryInterface((nsIScriptElement*) this); RefPtr<nsPresContext> presContext = @@ -73,17 +73,17 @@ ScriptElement::ScriptEvaluated(nsresult EventDispatcher::Dispatch(cont, presContext, &event, nullptr, &status); } return rv; } void -ScriptElement::CharacterDataChanged(nsIDocument *aDocument, +ScriptElement::CharacterDataChanged(nsIDocument* aDocument, nsIContent* aContent, CharacterDataChangeInfo* aInfo) { MaybeProcessScript(); } void ScriptElement::AttributeChanged(nsIDocument* aDocument, @@ -101,17 +101,17 @@ ScriptElement::ContentAppended(nsIDocume nsIContent* aContainer, nsIContent* aFirstNewContent, int32_t aNewIndexInContainer) { MaybeProcessScript(); } void -ScriptElement::ContentInserted(nsIDocument *aDocument, +ScriptElement::ContentInserted(nsIDocument* aDocument, nsIContent* aContainer, nsIContent* aChild, int32_t aIndexInContainer) { MaybeProcessScript(); } bool
--- a/dom/script/ScriptLoadHandler.cpp +++ b/dom/script/ScriptLoadHandler.cpp @@ -16,19 +16,19 @@ namespace dom { #undef LOG #define LOG(args) \ MOZ_LOG(ScriptLoader::gScriptLoaderLog, mozilla::LogLevel::Debug, args) #define LOG_ENABLED() \ MOZ_LOG_TEST(ScriptLoader::gScriptLoaderLog, mozilla::LogLevel::Debug) -ScriptLoadHandler::ScriptLoadHandler(ScriptLoader *aScriptLoader, - ScriptLoadRequest *aRequest, - mozilla::dom::SRICheckDataVerifier *aSRIDataVerifier) +ScriptLoadHandler::ScriptLoadHandler(ScriptLoader* aScriptLoader, + ScriptLoadRequest* aRequest, + SRICheckDataVerifier* aSRIDataVerifier) : mScriptLoader(aScriptLoader), mRequest(aRequest), mSRIDataVerifier(aSRIDataVerifier), mSRIStatus(NS_OK), mDecoder() { MOZ_ASSERT(mRequest->IsUnknownDataType()); MOZ_ASSERT(mRequest->IsLoading()); @@ -39,17 +39,17 @@ 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) + uint32_t* aConsumedLength) { if (mRequest->IsCanceled()) { // If request cancelled, ignore any incoming data. *aConsumedLength = aDataLength; return NS_OK; } nsresult rv = NS_OK; @@ -94,17 +94,17 @@ ScriptLoadHandler::OnIncrementalData(nsI } nsresult ScriptLoadHandler::DecodeRawData(const uint8_t* aData, uint32_t aDataLength, bool aEndOfStream) { int32_t srcLen = aDataLength; - const char* src = reinterpret_cast<const char *>(aData); + 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 = mRequest->mScriptText.length(); @@ -125,17 +125,17 @@ ScriptLoadHandler::DecodeRawData(const u haveRead += dstLen; MOZ_ASSERT(haveRead <= capacity.value(), "mDecoder produced more data than expected"); MOZ_ALWAYS_TRUE(mRequest->mScriptText.resizeUninitialized(haveRead)); return NS_OK; } bool -ScriptLoadHandler::EnsureDecoder(nsIIncrementalStreamLoader *aLoader, +ScriptLoadHandler::EnsureDecoder(nsIIncrementalStreamLoader* aLoader, const uint8_t* aData, uint32_t aDataLength, bool aEndOfStream) { // Check if decoder has already been created. if (mDecoder) { return true; } @@ -148,17 +148,17 @@ ScriptLoadHandler::EnsureDecoder(nsIIncr charset = "?"; } mozilla::Telemetry::Accumulate(mozilla::Telemetry::DOM_SCRIPT_SRC_ENCODING, charset); return true; } bool -ScriptLoadHandler::EnsureDecoder(nsIIncrementalStreamLoader *aLoader, +ScriptLoadHandler::EnsureDecoder(nsIIncrementalStreamLoader* aLoader, const uint8_t* aData, uint32_t aDataLength, bool aEndOfStream, nsCString& oCharset) { // JavaScript modules are always UTF-8. if (mRequest->IsModuleRequest()) { oCharset = "UTF-8"; @@ -253,17 +253,17 @@ ScriptLoadHandler::MaybeDecodeSRI() return mSRIStatus; } mRequest->mBytecodeOffset = mSRIDataVerifier->DataSummaryLength(); return NS_OK; } nsresult -ScriptLoadHandler::EnsureKnownDataType(nsIIncrementalStreamLoader *aLoader) +ScriptLoadHandler::EnsureKnownDataType(nsIIncrementalStreamLoader* aLoader) { MOZ_ASSERT(mRequest->IsUnknownDataType()); MOZ_ASSERT(mRequest->IsLoading()); if (mRequest->IsLoadingSource()) { mRequest->mDataType = ScriptLoadRequest::DataType::Source; TRACE_FOR_TEST(mRequest->mElement, "scriptloader_load_source"); return NS_OK; }
--- a/dom/script/ScriptLoadHandler.h +++ b/dom/script/ScriptLoadHandler.h @@ -40,44 +40,44 @@ private: nsresult DecodeRawData(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, + bool EnsureDecoder(nsIIncrementalStreamLoader* aLoader, const uint8_t* aData, uint32_t aDataLength, bool aEndOfStream); - bool EnsureDecoder(nsIIncrementalStreamLoader *aLoader, + bool EnsureDecoder(nsIIncrementalStreamLoader* aLoader, const uint8_t* aData, uint32_t aDataLength, bool aEndOfStream, nsCString& oCharset); /* * When streaming bytecode, we have the opportunity to fallback early if SRI * does not match the expectation of the document. */ nsresult MaybeDecodeSRI(); // Query the channel to find the data type associated with the input stream. - nsresult EnsureKnownDataType(nsIIncrementalStreamLoader *aLoader); + nsresult EnsureKnownDataType(nsIIncrementalStreamLoader* aLoader); // ScriptLoader which will handle the parsed script. - RefPtr<ScriptLoader> mScriptLoader; + RefPtr<ScriptLoader> mScriptLoader; // The ScriptLoadRequest for this load. Decoded data are accumulated on it. - RefPtr<ScriptLoadRequest> mRequest; + RefPtr<ScriptLoadRequest> mRequest; // SRI data verifier. nsAutoPtr<SRICheckDataVerifier> mSRIDataVerifier; // Status of SRI data operations. - nsresult mSRIStatus; + nsresult mSRIStatus; // Unicode decoder for charset. - nsCOMPtr<nsIUnicodeDecoder> mDecoder; + nsCOMPtr<nsIUnicodeDecoder> mDecoder; }; } // namespace dom } // namespace mozilla #endif // mozilla_dom_ScriptLoadHandler_h
--- a/dom/script/ScriptLoadRequest.cpp +++ b/dom/script/ScriptLoadRequest.cpp @@ -37,17 +37,17 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(ScriptLoadRequest) NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mScript) NS_IMPL_CYCLE_COLLECTION_TRACE_END ScriptLoadRequest::ScriptLoadRequest(ScriptKind aKind, nsIScriptElement* aElement, uint32_t aVersion, mozilla::CORSMode aCORSMode, - const mozilla::dom::SRIMetadata &aIntegrity) + const mozilla::dom::SRIMetadata& aIntegrity) : mKind(aKind) , mElement(aElement) , mScriptFromHead(false) , mProgress(Progress::Loading) , mDataType(DataType::Unknown) , mIsInline(true) , mHasSourceMapURL(false) , mIsDefer(false)
--- a/dom/script/ScriptLoader.cpp +++ b/dom/script/ScriptLoader.cpp @@ -227,19 +227,19 @@ IsScriptEventHandler(nsIContent* aScript return true; } return false; } nsresult ScriptLoader::CheckContentPolicy(nsIDocument* aDocument, - nsISupports *aContext, - nsIURI *aURI, - const nsAString &aType, + nsISupports* aContext, + nsIURI* aURI, + const nsAString& aType, bool aIsPreLoad) { nsContentPolicyType contentPolicyType = aIsPreLoad ? nsIContentPolicy::TYPE_INTERNAL_SCRIPT_PRELOAD : nsIContentPolicy::TYPE_INTERNAL_SCRIPT; int16_t shouldLoad = nsIContentPolicy::ACCEPT; nsresult rv = NS_CheckContentLoadPolicy(contentPolicyType, @@ -270,44 +270,44 @@ ScriptLoader::ModuleScriptsEnabled() sCachedPref = true; Preferences::AddBoolVarCache(&sEnabledForContent, "dom.moduleScripts.enabled", false); } return nsContentUtils::IsChromeDoc(mDocument) || sEnabledForContent; } bool -ScriptLoader::ModuleMapContainsModule(ModuleLoadRequest *aRequest) const +ScriptLoader::ModuleMapContainsModule(ModuleLoadRequest* aRequest) const { // Returns whether we have fetched, or are currently fetching, a module script // for the request's URL. return mFetchingModules.Contains(aRequest->mURI) || mFetchedModules.Contains(aRequest->mURI); } bool -ScriptLoader::IsFetchingModule(ModuleLoadRequest *aRequest) const +ScriptLoader::IsFetchingModule(ModuleLoadRequest* aRequest) const { bool fetching = mFetchingModules.Contains(aRequest->mURI); MOZ_ASSERT_IF(fetching, !mFetchedModules.Contains(aRequest->mURI)); return fetching; } void -ScriptLoader::SetModuleFetchStarted(ModuleLoadRequest *aRequest) +ScriptLoader::SetModuleFetchStarted(ModuleLoadRequest* aRequest) { // Update the module map to indicate that a module is currently being fetched. MOZ_ASSERT(aRequest->IsLoading()); MOZ_ASSERT(!ModuleMapContainsModule(aRequest)); mFetchingModules.Put(aRequest->mURI, nullptr); } void -ScriptLoader::SetModuleFetchFinishedAndResumeWaitingRequests(ModuleLoadRequest *aRequest, +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. MOZ_ASSERT(!aRequest->IsReadyToRun()); RefPtr<GenericPromise::Private> promise; @@ -323,17 +323,17 @@ ScriptLoader::SetModuleFetchFinishedAndR promise->Resolve(true, __func__); } else { promise->Reject(aResult, __func__); } } } RefPtr<GenericPromise> -ScriptLoader::WaitForModuleFetch(ModuleLoadRequest *aRequest) +ScriptLoader::WaitForModuleFetch(ModuleLoadRequest* aRequest) { MOZ_ASSERT(ModuleMapContainsModule(aRequest)); RefPtr<GenericPromise::Private> promise; if (mFetchingModules.Get(aRequest->mURI, getter_AddRefs(promise))) { if (!promise) { promise = new GenericPromise::Private(__func__); mFetchingModules.Put(aRequest->mURI, promise); @@ -548,17 +548,17 @@ RequestedModuleIsInAncestorList(ModuleLo aRequest = aRequest->mParent; } return NS_OK; } static nsresult -ResolveRequestedModules(ModuleLoadRequest* aRequest, nsCOMArray<nsIURI> &aUrls) +ResolveRequestedModules(ModuleLoadRequest* aRequest, nsCOMArray<nsIURI>& aUrls) { ModuleScript* ms = aRequest->mModuleScript; AutoJSAPI jsapi; if (!jsapi.Init(ms->ModuleRecord())) { return NS_ERROR_FAILURE; } @@ -814,17 +814,17 @@ ScriptLoader::IsBytecodeCacheEnabled() Preferences::AddBoolVarCache(&sExposeTestInterfaceEnabled, "dom.script_loader.bytecode_cache.enabled", false); } return sExposeTestInterfaceEnabled; } nsresult -ScriptLoader::RestartLoad(ScriptLoadRequest *aRequest) +ScriptLoader::RestartLoad(ScriptLoadRequest* aRequest) { MOZ_ASSERT(aRequest->IsBytecode()); aRequest->mScriptBytecode.clearAndFree(); TRACE_FOR_TEST(aRequest->mElement, "scriptloader_fallback"); // Start a new channel from which we explicitly request to stream the source // instead of the bytecode. aRequest->mProgress = ScriptLoadRequest::Progress::Loading_Source; @@ -834,17 +834,17 @@ ScriptLoader::RestartLoad(ScriptLoadRequ } // Close the current channel and this ScriptLoadHandler as we created a new // one for the same request. return NS_BINDING_RETARGETED; } nsresult -ScriptLoader::StartLoad(ScriptLoadRequest *aRequest) +ScriptLoader::StartLoad(ScriptLoadRequest* aRequest) { MOZ_ASSERT(aRequest->IsLoading()); NS_ENSURE_TRUE(mDocument, NS_ERROR_NULL_POINTER); aRequest->mDataType = ScriptLoadRequest::DataType::Unknown; // If this document is sandboxed without 'allow-scripts', abort. if (mDocument->HasScriptsBlockedBySandbox()) { return NS_OK; @@ -875,17 +875,17 @@ ScriptLoader::StartLoad(ScriptLoadReques } else { context = mDocument; } nsCOMPtr<nsILoadGroup> loadGroup = mDocument->GetDocumentLoadGroup(); nsCOMPtr<nsPIDOMWindowOuter> window = mDocument->MasterDocument()->GetWindow(); NS_ENSURE_TRUE(window, NS_ERROR_NULL_POINTER); - nsIDocShell *docshell = window->GetDocShell(); + nsIDocShell* docshell = window->GetDocShell(); nsCOMPtr<nsIInterfaceRequestor> prompter(do_QueryInterface(docshell)); nsSecurityFlags securityFlags; if (aRequest->IsModuleRequest()) { // 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) { @@ -938,17 +938,17 @@ ScriptLoader::StartLoad(ScriptLoadReques // The following tell the cache to look for an alternative data type which // does not exist, such that we can later save the bytecode with a // different alternative data type. LOG(("ScriptLoadRequest (%p): Request saving bytecode later", aRequest)); cic->PreferAlternativeDataType(kNullMimeType); } } - nsIScriptElement *script = aRequest->mElement; + nsIScriptElement* script = aRequest->mElement; nsCOMPtr<nsIClassOfService> cos(do_QueryInterface(channel)); if (cos) { if (aRequest->mScriptFromHead && !(script && (script->GetScriptAsync() || script->GetScriptDeferred()))) { // synchronous head scripts block loading of most other non js/css // content such as images cos->AddClassFlags(nsIClassOfService::Leader); @@ -1002,18 +1002,18 @@ ScriptLoader::StartLoad(ScriptLoadReques nsCOMPtr<nsIIncrementalStreamLoader> loader; rv = NS_NewIncrementalStreamLoader(getter_AddRefs(loader), handler); NS_ENSURE_SUCCESS(rv, rv); return channel->AsyncOpen2(loader); } bool -ScriptLoader::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 ScriptRequestProcessor : public Runnable { @@ -1058,17 +1058,17 @@ ParseTypeAttribute(const nsAString& aTyp } else if (rv != NS_ERROR_INVALID_ARG) { return false; } return true; } static bool -CSPAllowsInlineScript(nsIScriptElement *aElement, nsIDocument *aDocument) +CSPAllowsInlineScript(nsIScriptElement* aElement, nsIDocument* aDocument) { nsCOMPtr<nsIContentSecurityPolicy> csp; // Note: For imports NodePrincipal and the principal of the master are // the same. nsresult rv = aDocument->NodePrincipal()->GetCsp(getter_AddRefs(csp)); NS_ENSURE_SUCCESS(rv, false); if (!csp) { @@ -1093,29 +1093,29 @@ CSPAllowsInlineScript(nsIScriptElement * &allowInlineScript); return allowInlineScript; } ScriptLoadRequest* ScriptLoader::CreateLoadRequest(ScriptKind aKind, nsIScriptElement* aElement, uint32_t aVersion, CORSMode aCORSMode, - const SRIMetadata &aIntegrity) + const SRIMetadata& aIntegrity) { if (aKind == ScriptKind::Classic) { return new ScriptLoadRequest(aKind, aElement, aVersion, aCORSMode, aIntegrity); } MOZ_ASSERT(aKind == ScriptKind::Module); return new ModuleLoadRequest(aElement, aVersion, aCORSMode, aIntegrity, this); } bool -ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement) +ScriptLoader::ProcessScriptElement(nsIScriptElement* aElement) { // We need a document to evaluate scripts. NS_ENSURE_TRUE(mDocument, false); // Check to see if scripts has been turned off. if (!mEnabled || !mDocument->IsScriptEnabled()) { return false; } @@ -1442,17 +1442,17 @@ ScriptLoader::ProcessScriptElement(nsISc namespace { class NotifyOffThreadScriptLoadCompletedRunnable : public Runnable { RefPtr<ScriptLoadRequest> mRequest; RefPtr<ScriptLoader> mLoader; RefPtr<DocGroup> mDocGroup; - void *mToken; + void* mToken; public: NotifyOffThreadScriptLoadCompletedRunnable(ScriptLoadRequest* aRequest, ScriptLoader* aLoader) : mRequest(aRequest) , mLoader(aLoader) , mDocGroup(aLoader->GetDocGroup()) , mToken(nullptr) @@ -1541,17 +1541,17 @@ NotifyOffThreadScriptLoadCompletedRunnab request->mOffThreadToken = mToken; nsresult rv = loader->ProcessOffThreadRequest(request); return rv; } static void -OffThreadScriptLoaderCallback(void *aToken, void *aCallbackData) +OffThreadScriptLoaderCallback(void* aToken, void* aCallbackData) { RefPtr<NotifyOffThreadScriptLoadCompletedRunnable> aRunnable = dont_AddRef(static_cast<NotifyOffThreadScriptLoadCompletedRunnable*>(aCallbackData)); aRunnable->SetToken(aToken); NotifyOffThreadScriptLoadCompletedRunnable::Dispatch(aRunnable.forget()); } nsresult @@ -1710,17 +1710,17 @@ ScriptLoader::ProcessRequest(ScriptLoadR // The window may have gone away by this point, in which case there's no point // in trying to run the script. nsCOMPtr<nsIDocument> master = mDocument->MasterDocument(); { // Try to perform a microtask checkpoint nsAutoMicroTask mt; } - nsPIDOMWindowInner *pwin = master->GetInnerWindow(); + nsPIDOMWindowInner* pwin = master->GetInnerWindow(); bool runScript = !!pwin; if (runScript) { nsContentUtils::DispatchTrustedEvent(scriptElem->OwnerDoc(), scriptElem, NS_LITERAL_STRING("beforescriptexecute"), true, true, &runScript); } @@ -1796,17 +1796,17 @@ ScriptLoader::FireScriptEvaluated(nsresu aRequest->FireScriptEvaluated(aResult); } already_AddRefed<nsIScriptGlobalObject> ScriptLoader::GetScriptGlobalObject() { nsCOMPtr<nsIDocument> master = mDocument->MasterDocument(); - nsPIDOMWindowInner *pwin = master->GetInnerWindow(); + nsPIDOMWindowInner* pwin = master->GetInnerWindow(); if (!pwin) { return nullptr; } nsCOMPtr<nsIScriptGlobalObject> globalObject = do_QueryInterface(pwin); NS_ASSERTION(globalObject, "windows must be global objects"); // and make sure we are setup for this type of script. @@ -2839,19 +2839,19 @@ ScriptLoader::ParsingComplete(bool aTerm } // Have to call this even if aTerminated so we'll correctly unblock // onload and all. ProcessPendingRequests(); } void -ScriptLoader::PreloadURI(nsIURI *aURI, const nsAString &aCharset, - const nsAString &aType, - const nsAString &aCrossOrigin, +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. if (!mEnabled || !mDocument->IsScriptEnabled()) { return; @@ -2882,17 +2882,17 @@ ScriptLoader::PreloadURI(nsIURI *aURI, c request->mReferrerPolicy = aReferrerPolicy; request->mScriptFromHead = aScriptFromHead; nsresult rv = StartLoad(request); if (NS_FAILED(rv)) { return; } - PreloadInfo *pi = mPreloads.AppendElement(); + PreloadInfo* pi = mPreloads.AppendElement(); pi->mRequest = request; pi->mCharset = aCharset; } void ScriptLoader::AddDeferRequest(ScriptLoadRequest* aRequest) { aRequest->mIsDefer = true;
--- a/dom/script/ScriptLoader.h +++ b/dom/script/ScriptLoader.h @@ -53,20 +53,22 @@ class ScriptLoader final : public nsISup public: AutoCurrentScriptUpdater(ScriptLoader* aScriptLoader, nsIScriptElement* aCurrentScript) : mOldScript(aScriptLoader->mCurrentScript) , mScriptLoader(aScriptLoader) { mScriptLoader->mCurrentScript = aCurrentScript; } + ~AutoCurrentScriptUpdater() { mScriptLoader->mCurrentScript.swap(mOldScript); } + private: nsCOMPtr<nsIScriptElement> mOldScript; ScriptLoader* mScriptLoader; }; friend class ModuleLoadRequest; friend class ScriptRequestProcessor; friend class ScriptLoadHandler; @@ -146,16 +148,17 @@ public: * When disabled, processing of new script elements is disabled. * Any call to ProcessScriptElement() will return false. Note that * this DOES NOT disable currently loading or executing scripts. */ bool GetEnabled() { return mEnabled; } + void SetEnabled(bool aEnabled) { if (!mEnabled && aEnabled) { ProcessPendingRequestsAsync(); } mEnabled = aEnabled; } @@ -163,31 +166,33 @@ public: * Add/remove a blocker for parser-blocking scripts (and XSLT * scripts). Blockers will stop such scripts from executing, but not from * loading. */ void AddParserBlockingScriptExecutionBlocker() { ++mParserBlockingBlockerCount; } + void RemoveParserBlockingScriptExecutionBlocker() { if (!--mParserBlockingBlockerCount && ReadyToExecuteScripts()) { ProcessPendingRequestsAsync(); } } /** * Add/remove a blocker for execution of all scripts. Blockers will stop * scripts from executing, but not from loading. */ void AddExecuteBlocker() { ++mBlockerCount; } + void RemoveExecuteBlocker() { MOZ_ASSERT(mBlockerCount); if (!--mBlockerCount) { ProcessPendingRequestsAsync(); } } @@ -214,18 +219,18 @@ public: static inline nsresult ConvertToUTF16(nsIChannel* aChannel, const uint8_t* aData, uint32_t aLength, const nsAString& aHintCharset, nsIDocument* aDocument, JS::UniqueTwoByteChars& aBufOut, size_t& aLengthOut) { char16_t* bufOut; - nsresult rv = ConvertToUTF16(aChannel, aData, aLength, aHintCharset, aDocument, - bufOut, aLengthOut); + nsresult rv = ConvertToUTF16(aChannel, aData, aLength, aHintCharset, + aDocument, bufOut, aLengthOut); if (NS_SUCCEEDED(rv)) { aBufOut.reset(bufOut); } return rv; }; /** * Handle the completion of a stream. This is called by the @@ -286,30 +291,31 @@ public: * @param aURI The URI of the external script. * @param aCharset The charset parameter for the script. * @param aType The type parameter for the script. * @param aCrossOrigin The crossorigin attribute for the script. * Void if not present. * @param aIntegrity The expect hash url, if avail, of the request * @param aScriptFromHead Whether or not the script was a child of head */ - virtual void PreloadURI(nsIURI *aURI, const nsAString &aCharset, - const nsAString &aType, - const nsAString &aCrossOrigin, + virtual void PreloadURI(nsIURI* aURI, const nsAString& aCharset, + const nsAString& aType, + const nsAString& aCrossOrigin, const nsAString& aIntegrity, bool aScriptFromHead, const mozilla::net::ReferrerPolicy aReferrerPolicy); /** * Process a request that was deferred so that the script could be compiled * off thread. */ - nsresult ProcessOffThreadRequest(ScriptLoadRequest *aRequest); + nsresult ProcessOffThreadRequest(ScriptLoadRequest* aRequest); - bool AddPendingChildLoader(ScriptLoader* aChild) { + bool AddPendingChildLoader(ScriptLoader* aChild) + { return mPendingChildLoaders.AppendElement(aChild) != nullptr; } mozilla::dom::DocGroup* GetDocGroup() const { return mDocument->GetDocGroup(); } @@ -318,54 +324,53 @@ public: * bytecode at the next loop cycle unless new scripts are waiting in the * pipeline. */ void LoadEventFired(); private: virtual ~ScriptLoader(); - ScriptLoadRequest* CreateLoadRequest( - ScriptKind aKind, - nsIScriptElement* aElement, - uint32_t aVersion, - mozilla::CORSMode aCORSMode, - const mozilla::dom::SRIMetadata &aIntegrity); + ScriptLoadRequest* CreateLoadRequest(ScriptKind aKind, + nsIScriptElement* aElement, + uint32_t aVersion, + mozilla::CORSMode aCORSMode, + const mozilla::dom::SRIMetadata& aIntegrity); /** * Unblocks the creator parser of the parser-blocking scripts. */ void UnblockParser(ScriptLoadRequest* aParserBlockingRequest); /** * Asynchronously resumes the creator parser of the parser-blocking scripts. */ void ContinueParserAsync(ScriptLoadRequest* aParserBlockingRequest); /** * Helper function to check the content policy for a given request. */ static nsresult CheckContentPolicy(nsIDocument* aDocument, - nsISupports *aContext, - nsIURI *aURI, - const nsAString &aType, + nsISupports* aContext, + nsIURI* aURI, + const nsAString& aType, bool aIsPreLoad); /** * Start a load for aRequest's URI. */ - nsresult StartLoad(ScriptLoadRequest *aRequest); + nsresult StartLoad(ScriptLoadRequest* aRequest); /** * Abort the current stream, and re-start with a new load request from scratch * without requesting any alternate data. Returns NS_BINDING_RETARGETED on * success, as this error code is used to abort the input stream. */ - nsresult RestartLoad(ScriptLoadRequest *aRequest); + nsresult RestartLoad(ScriptLoadRequest* aRequest); /** * Process any pending requests asynchronously (i.e. off an event) if there * are any. Note that this is a no-op if there aren't any currently pending * requests. * * This function is virtual to allow cross-library calls to SetEnabled() */ @@ -446,23 +451,23 @@ private: void MaybeMoveToLoadedList(ScriptLoadRequest* aRequest); JS::SourceBufferHolder GetScriptSource(ScriptLoadRequest* aRequest, nsAutoString& inlineData); bool ModuleScriptsEnabled(); void SetModuleFetchStarted(ModuleLoadRequest *aRequest); - void SetModuleFetchFinishedAndResumeWaitingRequests(ModuleLoadRequest *aRequest, + void SetModuleFetchFinishedAndResumeWaitingRequests(ModuleLoadRequest* aRequest, nsresult aResult); - bool IsFetchingModule(ModuleLoadRequest *aRequest) const; + bool IsFetchingModule(ModuleLoadRequest* aRequest) const; - bool ModuleMapContainsModule(ModuleLoadRequest *aRequest) const; - RefPtr<mozilla::GenericPromise> WaitForModuleFetch(ModuleLoadRequest *aRequest); + 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); static bool IsBytecodeCacheEnabled(); @@ -486,36 +491,40 @@ private: ScriptLoadRequestList mXSLTRequests; RefPtr<ScriptLoadRequest> mParserBlockingRequest; // List of script load request that are holding a buffer which has to be saved // on the cache. ScriptLoadRequestList mBytecodeEncodingQueue; // In mRequests, the additional information here is stored by the element. - struct PreloadInfo { + struct PreloadInfo + { RefPtr<ScriptLoadRequest> mRequest; nsString mCharset; }; friend void ImplCycleCollectionUnlink(ScriptLoader::PreloadInfo& aField); friend void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, ScriptLoader::PreloadInfo& aField, const char* aName, uint32_t aFlags); - struct PreloadRequestComparator { - bool Equals(const PreloadInfo &aPi, ScriptLoadRequest * const &aRequest) - const + struct PreloadRequestComparator + { + bool Equals(const PreloadInfo& aPi, ScriptLoadRequest* const& aRequest) const { return aRequest == aPi.mRequest; } }; - struct PreloadURIComparator { - bool Equals(const PreloadInfo &aPi, nsIURI * const &aURI) const; + + struct PreloadURIComparator + { + bool Equals(const PreloadInfo& aPi, nsIURI* const &aURI) const; }; + nsTArray<PreloadInfo> mPreloads; nsCOMPtr<nsIScriptElement> mCurrentScript; nsCOMPtr<nsIScriptElement> mCurrentParserInsertedScript; nsTArray< RefPtr<ScriptLoader> > mPendingChildLoaders; uint32_t mParserBlockingBlockerCount; uint32_t mBlockerCount; uint32_t mNumberOfProcessors;
--- a/dom/script/ScriptSettings.cpp +++ b/dom/script/ScriptSettings.cpp @@ -24,75 +24,82 @@ #include "WorkerPrivate.h" namespace mozilla { namespace dom { static MOZ_THREAD_LOCAL(ScriptSettingsStackEntry*) sScriptSettingsTLS; static bool sScriptSettingsTLSInitialized; -class ScriptSettingsStack { +class ScriptSettingsStack +{ public: static ScriptSettingsStackEntry* Top() { return sScriptSettingsTLS.get(); } - static void Push(ScriptSettingsStackEntry *aEntry) { + static void Push(ScriptSettingsStackEntry* aEntry) + { MOZ_ASSERT(!aEntry->mOlder); // Whenever JSAPI use is disabled, the next stack entry pushed must // not be an AutoIncumbentScript. MOZ_ASSERT_IF(!Top() || Top()->NoJSAPI(), !aEntry->IsIncumbentScript()); // Whenever the top entry is not an incumbent canidate, the next stack entry // pushed must not be an AutoIncumbentScript. MOZ_ASSERT_IF(Top() && !Top()->IsIncumbentCandidate(), !aEntry->IsIncumbentScript()); aEntry->mOlder = Top(); sScriptSettingsTLS.set(aEntry); } - static void Pop(ScriptSettingsStackEntry *aEntry) { + static void Pop(ScriptSettingsStackEntry* aEntry) + { MOZ_ASSERT(aEntry == Top()); sScriptSettingsTLS.set(aEntry->mOlder); } - static nsIGlobalObject* IncumbentGlobal() { - ScriptSettingsStackEntry *entry = Top(); + static nsIGlobalObject* IncumbentGlobal() + { + ScriptSettingsStackEntry* entry = Top(); while (entry) { if (entry->IsIncumbentCandidate()) { return entry->mGlobalObject; } entry = entry->mOlder; } return nullptr; } - static ScriptSettingsStackEntry* EntryPoint() { - ScriptSettingsStackEntry *entry = Top(); + static ScriptSettingsStackEntry* EntryPoint() + { + ScriptSettingsStackEntry* entry = Top(); while (entry) { if (entry->IsEntryCandidate()) { return entry; } entry = entry->mOlder; } return nullptr; } - static nsIGlobalObject* EntryGlobal() { - ScriptSettingsStackEntry *entry = EntryPoint(); + static nsIGlobalObject* EntryGlobal() + { + ScriptSettingsStackEntry* entry = EntryPoint(); if (!entry) { return nullptr; } return entry->mGlobalObject; } #ifdef DEBUG - static ScriptSettingsStackEntry* TopNonIncumbentScript() { - ScriptSettingsStackEntry *entry = Top(); + static ScriptSettingsStackEntry* TopNonIncumbentScript() + { + ScriptSettingsStackEntry* entry = Top(); while (entry) { if (!entry->IsIncumbentScript()) { return entry; } entry = entry->mOlder; } return nullptr; } @@ -136,17 +143,17 @@ DestroyScriptSettings() } bool ScriptSettingsInitialized() { return sScriptSettingsTLSInitialized; } -ScriptSettingsStackEntry::ScriptSettingsStackEntry(nsIGlobalObject *aGlobal, +ScriptSettingsStackEntry::ScriptSettingsStackEntry(nsIGlobalObject* aGlobal, Type aType) : mGlobalObject(aGlobal) , mType(aType) , mOlder(nullptr) { MOZ_ASSERT_IF(IsIncumbentCandidate() && !NoJSAPI(), mGlobalObject); MOZ_ASSERT(!mGlobalObject || mGlobalObject->GetGlobalJSObject(), "Must have an actual JS global for the duration on the stack"); @@ -222,56 +229,56 @@ GetEntryDocument() nsIGlobalObject* GetIncumbentGlobal() { // We need the current JSContext in order to check the JS for // scripted frames that may have appeared since anyone last // manipulated the stack. If it's null, that means that there // must be no entry global on the stack, and therefore no incumbent // global either. - JSContext *cx = nsContentUtils::GetCurrentJSContextForThread(); + JSContext* cx = nsContentUtils::GetCurrentJSContextForThread(); if (!cx) { MOZ_ASSERT(ScriptSettingsStack::EntryGlobal() == nullptr); return nullptr; } // See what the JS engine has to say. If we've got a scripted caller // override in place, the JS engine will lie to us and pretend that // there's nothing on the JS stack, which will cause us to check the // incumbent script stack below. - if (JSObject *global = JS::GetScriptedCallerGlobal(cx)) { + if (JSObject* global = JS::GetScriptedCallerGlobal(cx)) { return ClampToSubject(xpc::NativeGlobal(global)); } // Ok, nothing from the JS engine. Let's use whatever's on the // explicit stack. return ClampToSubject(ScriptSettingsStack::IncumbentGlobal()); } nsIGlobalObject* GetCurrentGlobal() { - JSContext *cx = nsContentUtils::GetCurrentJSContextForThread(); + JSContext* cx = nsContentUtils::GetCurrentJSContextForThread(); if (!cx) { return nullptr; } - JSObject *global = JS::CurrentGlobalOrNull(cx); + JSObject* global = JS::CurrentGlobalOrNull(cx); if (!global) { return nullptr; } return xpc::NativeGlobal(global); } nsIPrincipal* GetWebIDLCallerPrincipal() { MOZ_ASSERT(NS_IsMainThread()); - ScriptSettingsStackEntry *entry = ScriptSettingsStack::EntryPoint(); + ScriptSettingsStackEntry* entry = ScriptSettingsStack::EntryPoint(); // If we have an entry point that is not NoJSAPI, we know it must be an // AutoEntryScript. if (!entry || entry->NoJSAPI()) { return nullptr; } AutoEntryScript* aes = static_cast<AutoEntryScript*>(entry); @@ -653,33 +660,33 @@ AutoJSAPI::StealException(JS::MutableHan bool AutoJSAPI::IsStackTop() const { return ScriptSettingsStack::TopNonIncumbentScript() == this; } #endif // DEBUG AutoEntryScript::AutoEntryScript(nsIGlobalObject* aGlobalObject, - const char *aReason, + const char* aReason, bool aIsMainThread) : AutoJSAPI(aGlobalObject, aIsMainThread, eEntryScript) , mWebIDLCallerPrincipal(nullptr) // This relies on us having a cx() because the AutoJSAPI constructor already // ran. , mCallerOverride(cx()) { MOZ_ASSERT(aGlobalObject); if (aIsMainThread && gRunToCompletionListeners > 0) { mDocShellEntryMonitor.emplace(cx(), aReason); } } AutoEntryScript::AutoEntryScript(JSObject* aObject, - const char *aReason, + const char* aReason, bool aIsMainThread) : AutoEntryScript(xpc::NativeGlobal(aObject), aReason, aIsMainThread) { } AutoEntryScript::~AutoEntryScript() { // GC when we pop a script entry point. This is a useful heuristic that helps
--- a/dom/script/nsIScriptElement.h +++ b/dom/script/nsIScriptElement.h @@ -19,17 +19,18 @@ #define NS_ISCRIPTELEMENT_IID \ { 0xe60fca9b, 0x1b96, 0x4e4e, \ { 0xa9, 0xb4, 0xdc, 0x98, 0x4f, 0x88, 0x3f, 0x9c } } /** * Internal interface implemented by script elements */ -class nsIScriptElement : public nsIScriptLoaderObserver { +class nsIScriptElement : public nsIScriptLoaderObserver +{ public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTELEMENT_IID) explicit nsIScriptElement(mozilla::dom::FromParser aFromParser) : mLineNumber(1), mAlreadyStarted(false), mMalformed(false), mDoneAddingChildren(aFromParser == mozilla::dom::NOT_FROM_PARSER || @@ -113,25 +114,27 @@ public: { return mParserCreated; } void SetScriptLineNumber(uint32_t aLineNumber) { mLineNumber = aLineNumber; } + uint32_t GetScriptLineNumber() { return mLineNumber; } void SetIsMalformed() { mMalformed = true; } + bool IsMalformed() { return mMalformed; } void PreventExecution() { mAlreadyStarted = true;