/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
class ScriptLoadContext; class WorkerLoadContext; class WorkletLoadContext; enumclass RequestPriority : uint8_t;
} // namespace mozilla::dom
namespace mozilla::loader { class SyncLoadContext;
} // namespace mozilla::loader
namespace JS { namespace loader {
class LoadContextBase; class ModuleLoadRequest; class ScriptLoadRequestList;
/* * ScriptLoadRequest * * ScriptLoadRequest is a generic representation of a JavaScript script that * will be loaded by a Script/Module loader. This representation is used by the * DOM ScriptLoader and will be used by workers and MOZJSComponentLoader. * * The ScriptLoadRequest contains information about the kind of script (classic * or module), the URI, and the ScriptFetchOptions associated with the script. * It is responsible for holding the script data once the fetch is complete, or * if the request is cached, the bytecode. * * Relationship to ScriptLoadContext: * * ScriptLoadRequest and ScriptLoadContexts have a circular pointer. A * ScriptLoadContext augments the loading of a ScriptLoadRequest by providing * additional information regarding the loading and evaluation behavior (see * the ScriptLoadContext class for details). In terms of responsibility, * the ScriptLoadRequest represents "What" is being loaded, and the * ScriptLoadContext represents "How". * * TODO: see if we can use it in the jsshell script loader. We need to either * remove ISUPPORTS or find a way to encorporate that in the jsshell. We would * then only have one implementation of the script loader, and it would be * tested whenever jsshell tests are run. This would mean finding another way to * create ScriptLoadRequest lists. *
*/
class ScriptLoadRequest : public nsISupports, private mozilla::LinkedListElement<ScriptLoadRequest>, public LoadedScriptDelegate<ScriptLoadRequest> { using super = LinkedListElement<ScriptLoadRequest>;
// Allow LinkedListElement<ScriptLoadRequest> to cast us to itself as needed. friendclass mozilla::LinkedListElement<ScriptLoadRequest>; friendclass ScriptLoadRequestList;
// Before any attempt at fetching resources from the cache we should first // make sure that the resource does not yet exists in the cache. In which case // we might simply alias its LoadedScript. Otherwise a new one would be // created. bool IsCheckingCache() const { return mState == State::CheckingCache; }
// Setup and load resources, to fill the LoadedScript and make it usable by // the JavaScript engine. bool IsFetching() const { return mState == State::Fetching; } bool IsCompiling() const { return mState == State::Compiling; } bool IsLoadingImports() const { return mState == State::LoadingImports; } bool IsCancelingImports() const { return mState == State::CancelingImports; } bool IsCanceled() const { return mState == State::Canceled; }
// Convert a CheckingCache ScriptLoadRequest into a Ready one, by populating // the script data from cached script. void CacheEntryFound(LoadedScript* aLoadedScript);
// Convert a CheckingCache ScriptLoadRequest into a Fetching one, by creating // a new LoadedScript which is matching the ScriptKind provided when // constructing this ScriptLoadRequest. void NoCacheEntryFound();
/* * Set the request's mBaseURL, based on aChannel. * aOriginalURI is the result of aChannel->GetOriginalURI.
*/ void SetBaseURLFromChannelAndOriginalURI(nsIChannel* aChannel,
nsIURI* aOriginalURI);
const ScriptKind mKind; // Whether this is a classic script or a module // script.
State mState; // Are we still waiting for a load to complete? bool mFetchSourceOnly; // Request source, not cached bytecode.
enumclass BytecodeEncodingPlan : uint8_t { // This is not yet considered for encoding.
Uninitialized,
// This is marked for skipping the encoding.
Skipped,
// This fits the condition for the encoding (e.g. file size, fetch count).
PassedCondition,
// This is marked for encoding, with setting sufficient input, // e.g. mScriptForBytecodeEncoding for script.
MarkedForEncode,
};
BytecodeEncodingPlan mBytecodeEncodingPlan =
BytecodeEncodingPlan::Uninitialized;
// The referrer policy used for the initial fetch and for fetching any // imported modules enum mozilla::dom::ReferrerPolicy mReferrerPolicy;
// Keep the URI's filename alive during off thread parsing. // Also used by workers to report on errors while loading, and used by // worklets as the file name in compile options.
nsAutoCString mURL;
// The base URL used for resolving relative module imports.
nsCOMPtr<nsIURI> mBaseURL;
// The loaded script holds the source / bytecode which is loaded. // // Currently it is used to hold information which are needed by the Debugger. // Soon it would be used as a way to dissociate the LoadRequest from the // loaded value, such that multiple request referring to the same content // would share the same loaded script.
RefPtr<LoadedScript> mLoadedScript;
// Holds the top-level JSScript that corresponds to the current source, once // it is parsed, and marked to be saved in the bytecode cache. // // NOTE: This field is not used for ModuleLoadRequest.
JS::Heap<JSScript*> mScriptForBytecodeEncoding;
// Holds the Cache information, which is used to register the bytecode // on the cache entry, such that we can load it the next time.
nsCOMPtr<nsICacheInfoChannel> mCacheInfo;
// LoadContext for augmenting the load depending on the loading // context (DOM, Worker, etc.)
RefPtr<LoadContextBase> mLoadContext;
// EarlyHintRegistrar id to connect the http channel back to the preload, with // a default of value of 0 indicating that this request is not an early hints // preload.
uint64_t mEarlyHintPreloaderId;
};
class ScriptLoadRequestList : private mozilla::LinkedList<ScriptLoadRequest> { using super = mozilla::LinkedList<ScriptLoadRequest>;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.