Bug 1472338: part 2) Change `clipboard.readText()` to read from the clipboard asynchr...
[gecko.git] / dom / script / ScriptLoader.h
blobb535f09114abefe5b79af55e109a120e4569e9cd
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_ScriptLoader_h
8 #define mozilla_dom_ScriptLoader_h
10 #include "js/TypeDecls.h"
11 #include "js/loader/LoadedScript.h"
12 #include "js/loader/ScriptKind.h"
13 #include "js/loader/ScriptLoadRequest.h"
14 #include "nsCOMPtr.h"
15 #include "nsRefPtrHashtable.h"
16 #include "nsIScriptElement.h"
17 #include "nsCOMArray.h"
18 #include "nsCycleCollectionParticipant.h"
19 #include "nsTArray.h"
20 #include "nsILoadInfo.h" // nsSecurityFlags
21 #include "nsINode.h"
22 #include "nsIObserver.h"
23 #include "nsIScriptLoaderObserver.h"
24 #include "nsURIHashKey.h"
25 #include "mozilla/CORSMode.h"
26 #include "mozilla/dom/JSExecutionContext.h" // JSExecutionContext
27 #include "ModuleLoader.h"
28 #include "mozilla/MaybeOneOf.h"
29 #include "mozilla/MozPromise.h"
31 class nsCycleCollectionTraversalCallback;
32 class nsIChannel;
33 class nsIConsoleReportCollector;
34 class nsIContent;
35 class nsIIncrementalStreamLoader;
36 class nsIPrincipal;
37 class nsIScriptGlobalObject;
38 class nsIURI;
40 namespace JS {
42 class CompileOptions;
44 template <typename UnitT>
45 class SourceText;
47 namespace loader {
49 class LoadedScript;
50 class ScriptLoaderInterface;
51 class ModuleLoadRequest;
52 class ModuleScript;
53 class ScriptLoadRequest;
54 class ScriptLoadRequestList;
56 } // namespace loader
57 } // namespace JS
59 namespace mozilla {
61 class LazyLogModule;
62 union Utf8Unit;
64 namespace dom {
66 class AutoJSAPI;
67 class DocGroup;
68 class Document;
69 class ModuleLoader;
70 class SRICheckDataVerifier;
71 class SRIMetadata;
72 class ScriptLoadHandler;
73 class ScriptLoadContext;
74 class ScriptLoader;
75 class ScriptRequestProcessor;
77 enum class ReferrerPolicy : uint8_t;
79 class AsyncCompileShutdownObserver final : public nsIObserver {
80 ~AsyncCompileShutdownObserver() { Unregister(); }
82 public:
83 explicit AsyncCompileShutdownObserver(ScriptLoader* aLoader)
84 : mScriptLoader(aLoader) {}
86 void OnShutdown();
87 void Unregister();
89 NS_DECL_ISUPPORTS
90 NS_DECL_NSIOBSERVER
92 private:
93 // Defined during registration in ScriptLoader constructor, and
94 // cleared during destructor, ScriptLoader::Destroy() or Shutdown.
95 ScriptLoader* mScriptLoader;
98 //////////////////////////////////////////////////////////////
99 // Script loader implementation
100 //////////////////////////////////////////////////////////////
102 class ScriptLoader final : public JS::loader::ScriptLoaderInterface {
103 class MOZ_STACK_CLASS AutoCurrentScriptUpdater {
104 public:
105 AutoCurrentScriptUpdater(ScriptLoader* aScriptLoader,
106 nsIScriptElement* aCurrentScript)
107 : mOldScript(aScriptLoader->mCurrentScript),
108 mScriptLoader(aScriptLoader) {
109 nsCOMPtr<nsINode> node = do_QueryInterface(aCurrentScript);
110 mScriptLoader->mCurrentScript =
111 node && !node->IsInShadowTree() ? aCurrentScript : nullptr;
114 ~AutoCurrentScriptUpdater() {
115 mScriptLoader->mCurrentScript.swap(mOldScript);
118 private:
119 nsCOMPtr<nsIScriptElement> mOldScript;
120 ScriptLoader* mScriptLoader;
123 friend class JS::loader::ModuleLoadRequest;
124 friend class ScriptRequestProcessor;
125 friend class ModuleLoader;
126 friend class ScriptLoadHandler;
127 friend class AutoCurrentScriptUpdater;
129 public:
130 explicit ScriptLoader(Document* aDocument);
132 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
133 NS_DECL_CYCLE_COLLECTION_CLASS(ScriptLoader)
136 * The loader maintains a weak reference to the document with
137 * which it is initialized. This call forces the reference to
138 * be dropped.
140 void DropDocumentReference() { mDocument = nullptr; }
143 * Add an observer for all scripts loaded through this loader.
145 * @param aObserver observer for all script processing.
147 nsresult AddObserver(nsIScriptLoaderObserver* aObserver) {
148 return mObservers.AppendObject(aObserver) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
152 * Remove an observer.
154 * @param aObserver observer to be removed
156 void RemoveObserver(nsIScriptLoaderObserver* aObserver) {
157 mObservers.RemoveObject(aObserver);
161 * Process a script element. This will include both loading the
162 * source of the element if it is not inline and evaluating
163 * the script itself.
165 * If the script is an inline script that can be executed immediately
166 * (i.e. there are no other scripts pending) then ScriptAvailable
167 * and ScriptEvaluated will be called before the function returns.
169 * If true is returned the script could not be executed immediately.
170 * In this case ScriptAvailable is guaranteed to be called at a later
171 * point (as well as possibly ScriptEvaluated).
173 * @param aElement The element representing the script to be loaded and
174 * evaluated.
176 bool ProcessScriptElement(nsIScriptElement* aElement);
179 * Gets the currently executing script. This is useful if you want to
180 * generate a unique key based on the currently executing script.
182 nsIScriptElement* GetCurrentScript() { return mCurrentScript; }
184 nsIScriptElement* GetCurrentParserInsertedScript() {
185 return mCurrentParserInsertedScript;
189 * Whether the loader is enabled or not.
190 * When disabled, processing of new script elements is disabled.
191 * Any call to ProcessScriptElement() will return false. Note that
192 * this DOES NOT disable currently loading or executing scripts.
194 bool GetEnabled() { return mEnabled; }
196 void SetEnabled(bool aEnabled) {
197 if (!mEnabled && aEnabled) {
198 ProcessPendingRequestsAsync();
200 mEnabled = aEnabled;
203 ModuleLoader* GetModuleLoader() { return mModuleLoader; }
206 * Check whether to speculatively OMT parse scripts as soon as
207 * they are fetched, even if not a parser blocking request.
208 * Controlled by
209 * dom.script_loader.external_scripts.speculative_omt_parse_enabled
211 bool SpeculativeOMTParsingEnabled() const {
212 return mSpeculativeOMTParsingEnabled;
216 * Add/remove a blocker for parser-blocking scripts (and XSLT
217 * scripts). Blockers will stop such scripts from executing, but not from
218 * loading.
220 void AddParserBlockingScriptExecutionBlocker() {
221 ++mParserBlockingBlockerCount;
224 void RemoveParserBlockingScriptExecutionBlocker() {
225 if (!--mParserBlockingBlockerCount && ReadyToExecuteScripts()) {
226 ProcessPendingRequestsAsync();
231 * Add/remove a blocker for execution of all scripts. Blockers will stop
232 * scripts from executing, but not from loading.
234 void AddExecuteBlocker() { ++mBlockerCount; }
236 void RemoveExecuteBlocker() {
237 MOZ_ASSERT(mBlockerCount);
238 if (!--mBlockerCount) {
239 ProcessPendingRequestsAsync();
244 * Convert the given buffer to a UTF-16 string. If the buffer begins with a
245 * BOM, it is interpreted as that encoding; otherwise the first of |aChannel|,
246 * |aHintCharset|, or |aDocument| that provides a recognized encoding is used,
247 * or Windows-1252 if none of them do.
249 * Encoding errors in the buffer are converted to replacement characters, so
250 * allocation failure is the only way this function can fail.
252 * @param aChannel Channel corresponding to the data. May be null.
253 * @param aData The data to convert
254 * @param aLength Length of the data
255 * @param aHintCharset Character set hint (e.g., from a charset attribute).
256 * @param aDocument Document which the data is loaded for. May be null.
257 * @param aBufOut [out] fresh char16_t array containing data converted to
258 * Unicode. Caller must js_free() this data when finished
259 * with it.
260 * @param aLengthOut [out] Length of array returned in aBufOut in number
261 * of char16_t code units.
263 static nsresult ConvertToUTF16(nsIChannel* aChannel, const uint8_t* aData,
264 uint32_t aLength,
265 const nsAString& aHintCharset,
266 Document* aDocument, char16_t*& aBufOut,
267 size_t& aLengthOut);
269 static inline nsresult ConvertToUTF16(nsIChannel* aChannel,
270 const uint8_t* aData, uint32_t aLength,
271 const nsAString& aHintCharset,
272 Document* aDocument,
273 JS::UniqueTwoByteChars& aBufOut,
274 size_t& aLengthOut) {
275 char16_t* bufOut;
276 nsresult rv = ConvertToUTF16(aChannel, aData, aLength, aHintCharset,
277 aDocument, bufOut, aLengthOut);
278 if (NS_SUCCEEDED(rv)) {
279 aBufOut.reset(bufOut);
281 return rv;
285 * Convert the given buffer to a UTF-8 string. If the buffer begins with a
286 * BOM, it is interpreted as that encoding; otherwise the first of |aChannel|,
287 * |aHintCharset|, or |aDocument| that provides a recognized encoding is used,
288 * or Windows-1252 if none of them do.
290 * Encoding errors in the buffer are converted to replacement characters, so
291 * allocation failure is the only way this function can fail.
293 * @param aChannel Channel corresponding to the data. May be null.
294 * @param aData The data to convert
295 * @param aLength Length of the data
296 * @param aHintCharset Character set hint (e.g., from a charset attribute).
297 * @param aDocument Document which the data is loaded for. May be null.
298 * @param aBufOut [out] fresh Utf8Unit array containing data converted to
299 * Unicode. Caller must js_free() this data when finished
300 * with it.
301 * @param aLengthOut [out] Length of array returned in aBufOut in UTF-8 code
302 * units (i.e. in bytes).
304 static nsresult ConvertToUTF8(nsIChannel* aChannel, const uint8_t* aData,
305 uint32_t aLength, const nsAString& aHintCharset,
306 Document* aDocument, Utf8Unit*& aBufOut,
307 size_t& aLengthOut);
310 * Handle the completion of a stream. This is called by the
311 * ScriptLoadHandler object which observes the IncrementalStreamLoader
312 * loading the script. The streamed content is expected to be stored on the
313 * aRequest argument.
315 nsresult OnStreamComplete(nsIIncrementalStreamLoader* aLoader,
316 ScriptLoadRequest* aRequest,
317 nsresult aChannelStatus, nsresult aSRIStatus,
318 SRICheckDataVerifier* aSRIDataVerifier);
321 * Returns wether any request is queued, and not executed yet.
323 bool HasPendingRequests();
326 * Processes any pending requests that are ready for processing.
328 void ProcessPendingRequests();
331 * Starts deferring deferred scripts and puts them in the mDeferredRequests
332 * queue instead.
334 void BeginDeferringScripts();
337 * Notifies the script loader that parsing is done. If aTerminated is true,
338 * this will drop any pending scripts that haven't run yet, otherwise it will
339 * do nothing.
341 void ParsingComplete(bool aTerminated);
344 * Notifies the script loader that the checkpoint to begin execution of defer
345 * scripts has been reached. This is either the end of of the document parse
346 * or the end of loading of parser-inserted stylesheets, whatever happens
347 * last.
349 * Otherwise, it will stop deferring scripts and immediately processes the
350 * mDeferredRequests queue.
352 * WARNING: This function will synchronously execute content scripts, so be
353 * prepared that the world might change around you.
355 void DeferCheckpointReached();
358 * Returns the number of pending scripts, deferred or not.
360 uint32_t HasPendingOrCurrentScripts() {
361 return mCurrentScript || mParserBlockingRequest;
365 * Adds aURI to the preload list and starts loading it.
367 * @param aURI The URI of the external script.
368 * @param aCharset The charset parameter for the script.
369 * @param aType The type parameter for the script.
370 * @param aCrossOrigin The crossorigin attribute for the script.
371 * Void if not present.
372 * @param aIntegrity The expect hash url, if avail, of the request
373 * @param aScriptFromHead Whether or not the script was a child of head
375 virtual void PreloadURI(nsIURI* aURI, const nsAString& aCharset,
376 const nsAString& aType, const nsAString& aCrossOrigin,
377 const nsAString& aIntegrity, bool aScriptFromHead,
378 bool aAsync, bool aDefer, bool aNoModule,
379 bool aLinkPreload,
380 const ReferrerPolicy aReferrerPolicy);
383 * Process a request that was deferred so that the script could be compiled
384 * off thread.
386 nsresult ProcessOffThreadRequest(ScriptLoadRequest* aRequest);
388 bool AddPendingChildLoader(ScriptLoader* aChild) {
389 // XXX(Bug 1631371) Check if this should use a fallible operation as it
390 // pretended earlier. Else, change the return type to void.
391 mPendingChildLoaders.AppendElement(aChild);
392 return true;
395 mozilla::dom::DocGroup* GetDocGroup() const;
398 * Register the fact that we saw the load event, and that we need to save the
399 * bytecode at the next loop cycle unless new scripts are waiting in the
400 * pipeline.
402 void LoadEventFired();
405 * Destroy and prevent the ScriptLoader or the ScriptLoadRequests from owning
406 * any references to the JSScript or to the Request which might be used for
407 * caching the encoded bytecode.
409 void Destroy();
412 * Get the currently active script. This is used as the initiating script when
413 * executing timeout handler scripts.
415 static JS::loader::LoadedScript* GetActiveScript(JSContext* aCx);
417 Document* GetDocument() const { return mDocument; }
419 nsIURI* GetBaseURI() const override;
421 private:
422 virtual ~ScriptLoader();
424 already_AddRefed<ScriptLoadRequest> CreateLoadRequest(
425 ScriptKind aKind, nsIURI* aURI, nsIScriptElement* aElement,
426 nsIPrincipal* aTriggeringPrincipal, mozilla::CORSMode aCORSMode,
427 const SRIMetadata& aIntegrity, ReferrerPolicy aReferrerPolicy);
430 * Unblocks the creator parser of the parser-blocking scripts.
432 void UnblockParser(ScriptLoadRequest* aParserBlockingRequest);
435 * Asynchronously resumes the creator parser of the parser-blocking scripts.
437 void ContinueParserAsync(ScriptLoadRequest* aParserBlockingRequest);
439 bool ProcessExternalScript(nsIScriptElement* aElement, ScriptKind aScriptKind,
440 const nsAutoString& aTypeAttr,
441 nsIContent* aScriptContent);
443 bool ProcessInlineScript(nsIScriptElement* aElement, ScriptKind aScriptKind);
445 JS::loader::ScriptLoadRequest* LookupPreloadRequest(
446 nsIScriptElement* aElement, ScriptKind aScriptKind,
447 const SRIMetadata& aSRIMetadata);
449 void GetSRIMetadata(const nsAString& aIntegrityAttr,
450 SRIMetadata* aMetadataOut);
453 * Given a script element, get the referrer policy should be applied to load
454 * requests.
456 ReferrerPolicy GetReferrerPolicy(nsIScriptElement* aElement);
459 * Helper function to check the content policy for a given request.
461 static nsresult CheckContentPolicy(Document* aDocument, nsISupports* aContext,
462 const nsAString& aType,
463 ScriptLoadRequest* aRequest);
466 * Helper function to determine whether an about: page loads a chrome: URI.
467 * Please note that this function only returns true if:
468 * * the about: page uses a ContentPrincipal with scheme about:
469 * * the about: page is not linkable from content
470 * (e.g. the function will return false for about:blank or about:srcdoc)
472 static bool IsAboutPageLoadingChromeURI(ScriptLoadRequest* aRequest,
473 Document* aDocument);
476 * Start a load for aRequest's URI.
478 nsresult StartLoad(ScriptLoadRequest* aRequest);
480 * Start a load for a classic script URI.
481 * Sets up the necessary security flags before calling StartLoadInternal.
483 nsresult StartClassicLoad(ScriptLoadRequest* aRequest);
486 * Start a load for a module script URI.
488 nsresult StartLoadInternal(ScriptLoadRequest* aRequest,
489 nsSecurityFlags securityFlags);
492 * Abort the current stream, and re-start with a new load request from scratch
493 * without requesting any alternate data. Returns NS_BINDING_RETARGETED on
494 * success, as this error code is used to abort the input stream.
496 nsresult RestartLoad(ScriptLoadRequest* aRequest);
498 void HandleLoadError(ScriptLoadRequest* aRequest, nsresult aResult);
501 * Process any pending requests asynchronously (i.e. off an event) if there
502 * are any. Note that this is a no-op if there aren't any currently pending
503 * requests.
505 * This function is virtual to allow cross-library calls to SetEnabled()
507 virtual void ProcessPendingRequestsAsync();
510 * If true, the loader is ready to execute parser-blocking scripts, and so are
511 * all its ancestors. If the loader itself is ready but some ancestor is not,
512 * this function will add an execute blocker and ask the ancestor to remove it
513 * once it becomes ready.
515 bool ReadyToExecuteParserBlockingScripts();
518 * Return whether just this loader is ready to execute parser-blocking
519 * scripts.
521 bool SelfReadyToExecuteParserBlockingScripts() {
522 return ReadyToExecuteScripts() && !mParserBlockingBlockerCount;
526 * Return whether this loader is ready to execute scripts in general.
528 bool ReadyToExecuteScripts() { return mEnabled && !mBlockerCount; }
530 nsresult VerifySRI(ScriptLoadRequest* aRequest,
531 nsIIncrementalStreamLoader* aLoader, nsresult aSRIStatus,
532 SRICheckDataVerifier* aSRIDataVerifier) const;
534 nsresult SaveSRIHash(ScriptLoadRequest* aRequest,
535 SRICheckDataVerifier* aSRIDataVerifier,
536 uint32_t* sriLength) const;
538 void ReportErrorToConsole(ScriptLoadRequest* aRequest,
539 nsresult aResult) const override;
540 void ReportPreloadErrorsToConsole(ScriptLoadRequest* aRequest);
542 nsresult AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest,
543 bool* aCouldCompileOut);
544 nsresult ProcessRequest(ScriptLoadRequest* aRequest);
545 nsresult CompileOffThreadOrProcessRequest(ScriptLoadRequest* aRequest);
546 void FireScriptAvailable(nsresult aResult, ScriptLoadRequest* aRequest);
547 // TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
548 MOZ_CAN_RUN_SCRIPT_BOUNDARY void FireScriptEvaluated(
549 nsresult aResult, ScriptLoadRequest* aRequest);
551 // Implements https://html.spec.whatwg.org/#execute-the-script-block
552 nsresult EvaluateScriptElement(ScriptLoadRequest* aRequest);
554 // Handles both bytecode and text source scripts; populates exec with a
555 // compiled script
556 nsresult CompileOrDecodeClassicScript(JSContext* aCx,
557 JSExecutionContext& aExec,
558 ScriptLoadRequest* aRequest);
560 nsresult MaybePrepareForBytecodeEncoding(JS::Handle<JSScript*> aScript,
561 ScriptLoadRequest* aRequest,
562 nsresult aRv);
564 // Implements https://html.spec.whatwg.org/#run-a-classic-script
565 nsresult EvaluateScript(nsIGlobalObject* aGlobalObject,
566 ScriptLoadRequest* aRequest);
569 * Queue the current script load request to be saved, when the page
570 * initialization ends. The page initialization end is defined as being the
571 * time when the load event got received, and when no more scripts are waiting
572 * to be executed.
574 void RegisterForBytecodeEncoding(ScriptLoadRequest* aRequest);
577 * Check if all conditions are met, i-e that the onLoad event fired and that
578 * no more script have to be processed. If all conditions are met, queue an
579 * event to encode all the bytecode and save them on the cache.
581 void MaybeTriggerBytecodeEncoding();
584 * Iterate over all script load request and save the bytecode of executed
585 * functions on the cache provided by the channel.
587 void EncodeBytecode();
588 void EncodeRequestBytecode(JSContext* aCx, ScriptLoadRequest* aRequest);
590 void GiveUpBytecodeEncoding();
592 already_AddRefed<nsIGlobalObject> GetGlobalForRequest(
593 ScriptLoadRequest* aRequest) override;
595 // This is a marker class to ensure proper handling of requests with a
596 // WebExtGlobal.
597 enum class WebExtGlobal { Ignore, Handled };
599 already_AddRefed<nsIScriptGlobalObject> GetScriptGlobalObject(
600 WebExtGlobal aWebExtGlobal);
602 // Fill in CompileOptions, as well as produce the introducer script for
603 // subsequent calls to UpdateDebuggerMetadata
604 nsresult FillCompileOptionsForRequest(
605 JSContext* aCx, ScriptLoadRequest* aRequest,
606 JS::Handle<JSObject*> aScopeChain, JS::CompileOptions* aOptions,
607 JS::MutableHandle<JSScript*> aIntroductionScript) override;
609 uint32_t NumberOfProcessors();
610 int32_t PhysicalSizeOfMemoryInGB();
612 nsresult PrepareLoadedRequest(ScriptLoadRequest* aRequest,
613 nsIIncrementalStreamLoader* aLoader,
614 nsresult aStatus);
616 void AddDeferRequest(ScriptLoadRequest* aRequest);
617 void AddAsyncRequest(ScriptLoadRequest* aRequest);
618 bool MaybeRemovedDeferRequests();
620 bool ShouldFullParse(ScriptLoadRequest* aRequest);
621 bool ShouldCompileOffThread(ScriptLoadRequest* aRequest);
623 void MaybeMoveToLoadedList(ScriptLoadRequest* aRequest);
625 using MaybeSourceText =
626 mozilla::MaybeOneOf<JS::SourceText<char16_t>, JS::SourceText<Utf8Unit>>;
628 // Returns wether we should save the bytecode of this script after the
629 // execution of the script.
630 static bool ShouldCacheBytecode(ScriptLoadRequest* aRequest);
632 void RunScriptWhenSafe(ScriptLoadRequest* aRequest);
635 * Wait for any unused off thread compilations to finish and then
636 * cancel them.
638 void CancelScriptLoadRequests();
640 Document* mDocument; // [WEAK]
641 nsCOMArray<nsIScriptLoaderObserver> mObservers;
642 ScriptLoadRequestList mNonAsyncExternalScriptInsertedRequests;
643 // mLoadingAsyncRequests holds async requests while they're loading; when they
644 // have been loaded they are moved to mLoadedAsyncRequests.
645 ScriptLoadRequestList mLoadingAsyncRequests;
646 ScriptLoadRequestList mLoadedAsyncRequests;
647 ScriptLoadRequestList mDeferRequests;
648 ScriptLoadRequestList mXSLTRequests;
649 RefPtr<ScriptLoadRequest> mParserBlockingRequest;
650 ScriptLoadRequestList mOffThreadCompilingRequests;
652 // List of script load request that are holding a buffer which has to be saved
653 // on the cache.
654 ScriptLoadRequestList mBytecodeEncodingQueue;
656 // In mRequests, the additional information here is stored by the element.
657 struct PreloadInfo {
658 RefPtr<ScriptLoadRequest> mRequest;
659 nsString mCharset;
662 friend void ImplCycleCollectionUnlink(ScriptLoader::PreloadInfo& aField);
663 friend void ImplCycleCollectionTraverse(
664 nsCycleCollectionTraversalCallback& aCallback,
665 ScriptLoader::PreloadInfo& aField, const char* aName, uint32_t aFlags);
667 struct PreloadRequestComparator {
668 bool Equals(const PreloadInfo& aPi,
669 ScriptLoadRequest* const& aRequest) const {
670 return aRequest == aPi.mRequest;
674 struct PreloadURIComparator {
675 bool Equals(const PreloadInfo& aPi, nsIURI* const& aURI) const;
678 nsTArray<PreloadInfo> mPreloads;
680 nsCOMPtr<nsIScriptElement> mCurrentScript;
681 nsCOMPtr<nsIScriptElement> mCurrentParserInsertedScript;
682 nsTArray<RefPtr<ScriptLoader>> mPendingChildLoaders;
683 uint32_t mParserBlockingBlockerCount;
684 uint32_t mBlockerCount;
685 uint32_t mNumberOfProcessors;
686 uint32_t mTotalFullParseSize;
687 int32_t mPhysicalSizeOfMemory;
688 bool mEnabled;
689 bool mDeferEnabled;
690 bool mSpeculativeOMTParsingEnabled;
691 bool mDeferCheckpointReached;
692 bool mBlockingDOMContentLoaded;
693 bool mLoadEventFired;
694 bool mGiveUpEncoding;
696 TimeDuration mMainThreadParseTime;
698 nsCOMPtr<nsIConsoleReportCollector> mReporter;
700 // ShutdownObserver for off thread compilations
701 RefPtr<AsyncCompileShutdownObserver> mShutdownObserver;
703 RefPtr<ModuleLoader> mModuleLoader;
705 // Logging
706 public:
707 static LazyLogModule gCspPRLog;
708 static LazyLogModule gScriptLoaderLog;
711 class nsAutoScriptLoaderDisabler {
712 public:
713 explicit nsAutoScriptLoaderDisabler(Document* aDoc);
715 ~nsAutoScriptLoaderDisabler();
717 bool mWasEnabled;
718 RefPtr<ScriptLoader> mLoader;
721 } // namespace dom
722 } // namespace mozilla
724 #endif // mozilla_dom_ScriptLoader_h