diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /dom/workers/loader/WorkerModuleLoader.h | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/workers/loader/WorkerModuleLoader.h')
-rw-r--r-- | dom/workers/loader/WorkerModuleLoader.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/dom/workers/loader/WorkerModuleLoader.h b/dom/workers/loader/WorkerModuleLoader.h new file mode 100644 index 0000000000..6ad45b42a0 --- /dev/null +++ b/dom/workers/loader/WorkerModuleLoader.h @@ -0,0 +1,83 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_loader_WorkerModuleLoader_h +#define mozilla_loader_WorkerModuleLoader_h + +#include "js/loader/ModuleLoaderBase.h" +#include "js/loader/ScriptFetchOptions.h" +#include "mozilla/dom/SerializedStackHolder.h" +#include "mozilla/UniquePtr.h" + +namespace mozilla::dom::workerinternals::loader { +class WorkerScriptLoader; + +// alias common classes +using ScriptFetchOptions = JS::loader::ScriptFetchOptions; +using ScriptKind = JS::loader::ScriptKind; +using ScriptLoadRequest = JS::loader::ScriptLoadRequest; +using ScriptLoadRequestList = JS::loader::ScriptLoadRequestList; +using ModuleLoadRequest = JS::loader::ModuleLoadRequest; + +// WorkerModuleLoader +// +// The WorkerModuleLoader provides the methods that implement specification +// step 5 from "To fetch a worklet/module worker script graph", specifically for +// workers. In addition, this implements worker specific initialization for +// Static imports and Dynamic imports. +// +// The steps are outlined in "To fetch the descendants of and link a module +// script" and are common for all Modules. Thus we delegate to ModuleLoaderBase +// for those steps. +class WorkerModuleLoader : public JS::loader::ModuleLoaderBase { + public: + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(WorkerModuleLoader, + JS::loader::ModuleLoaderBase) + + WorkerModuleLoader(WorkerScriptLoader* aScriptLoader, + nsIGlobalObject* aGlobalObject); + + private: + ~WorkerModuleLoader() = default; + + bool CreateDynamicImportLoader(); + void SetScriptLoader(JS::loader::ScriptLoaderInterface* aLoader) { + mLoader = aLoader; + } + + WorkerScriptLoader* GetCurrentScriptLoader(); + + WorkerScriptLoader* GetScriptLoaderFor(ModuleLoadRequest* aRequest); + + nsIURI* GetBaseURI() const override; + + already_AddRefed<ModuleLoadRequest> CreateStaticImport( + nsIURI* aURI, ModuleLoadRequest* aParent) override; + + already_AddRefed<ModuleLoadRequest> CreateDynamicImport( + JSContext* aCx, nsIURI* aURI, LoadedScript* aMaybeActiveScript, + JS::Handle<JSString*> aSpecifier, + JS::Handle<JSObject*> aPromise) override; + + bool CanStartLoad(ModuleLoadRequest* aRequest, nsresult* aRvOut) override; + + // StartFetch is special for worker modules, as we need to move back to the + // main thread to start a new load. + nsresult StartFetch(ModuleLoadRequest* aRequest) override; + + nsresult CompileFetchedModule( + JSContext* aCx, JS::Handle<JSObject*> aGlobal, + JS::CompileOptions& aOptions, ModuleLoadRequest* aRequest, + JS::MutableHandle<JSObject*> aModuleScript) override; + + void OnModuleLoadComplete(ModuleLoadRequest* aRequest) override; + + bool IsModuleEvaluationAborted(ModuleLoadRequest* aRequest) override; +}; + +} // namespace mozilla::dom::workerinternals::loader +#endif // mozilla_loader_WorkerModuleLoader_h |