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_ModuleLoader_h
8 #define mozilla_dom_ModuleLoader_h
10 #include "mozilla/dom/ScriptLoadContext.h"
11 #include "js/loader/ModuleLoaderBase.h"
12 #include "js/loader/ScriptLoadRequest.h"
13 #include "ScriptLoader.h"
23 class ModuleLoadRequest
;
28 namespace mozilla::dom
{
33 //////////////////////////////////////////////////////////////
34 // DOM Module loader implementation
35 //////////////////////////////////////////////////////////////
37 class ModuleLoader final
: public JS::loader::ModuleLoaderBase
{
39 virtual ~ModuleLoader();
42 enum Kind
{ Normal
, WebExtension
};
44 ModuleLoader(ScriptLoader
* aLoader
, nsIGlobalObject
* aGlobalObject
,
47 Kind
GetKind() const { return mKind
; }
49 ScriptLoader
* GetScriptLoader();
51 bool CanStartLoad(ModuleLoadRequest
* aRequest
, nsresult
* aRvOut
) override
;
53 nsresult
StartFetch(ModuleLoadRequest
* aRequest
) override
;
55 void OnModuleLoadComplete(ModuleLoadRequest
* aRequest
) override
;
57 nsresult
CompileFetchedModule(
58 JSContext
* aCx
, JS::Handle
<JSObject
*> aGlobal
,
59 JS::CompileOptions
& aOptions
, ModuleLoadRequest
* aRequest
,
60 JS::MutableHandle
<JSObject
*> aModuleScript
) override
;
62 // Create a top-level module load request.
63 static already_AddRefed
<ModuleLoadRequest
> CreateTopLevel(
64 nsIURI
* aURI
, ReferrerPolicy aReferrerPolicy
,
65 ScriptFetchOptions
* aFetchOptions
, const SRIMetadata
& aIntegrity
,
66 nsIURI
* aReferrer
, ScriptLoader
* aLoader
, ScriptLoadContext
* aContext
);
68 // Create a module load request for a static module import.
69 already_AddRefed
<ModuleLoadRequest
> CreateStaticImport(
70 nsIURI
* aURI
, ModuleLoadRequest
* aParent
) override
;
72 // Create a module load request for a dynamic module import.
73 already_AddRefed
<ModuleLoadRequest
> CreateDynamicImport(
74 JSContext
* aCx
, nsIURI
* aURI
, LoadedScript
* aMaybeActiveScript
,
75 JS::Handle
<JSString
*> aSpecifier
,
76 JS::Handle
<JSObject
*> aPromise
) override
;
78 static ModuleLoader
* From(ModuleLoaderBase
* aLoader
) {
79 return static_cast<ModuleLoader
*>(aLoader
);
82 void AsyncExecuteInlineModule(ModuleLoadRequest
* aRequest
);
83 void ExecuteInlineModule(ModuleLoadRequest
* aRequest
);
89 } // namespace mozilla::dom
91 #endif // mozilla_dom_ModuleLoader_h