Line data Source code
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/. */
6 :
7 : #ifndef mozilla_dom_ModuleLoadRequest_h
8 : #define mozilla_dom_ModuleLoadRequest_h
9 :
10 : #include "ScriptLoadRequest.h"
11 : #include "mozilla/MozPromise.h"
12 :
13 : namespace mozilla {
14 : namespace dom {
15 :
16 : class ModuleScript;
17 : class ScriptLoader;
18 :
19 : // A load request for a module, created for every top level module script and
20 : // every module import. Load request can share an ModuleScript if there are
21 : // multiple imports of the same module.
22 :
23 : class ModuleLoadRequest final : public ScriptLoadRequest
24 : {
25 0 : ~ModuleLoadRequest() = default;
26 :
27 : ModuleLoadRequest(const ModuleLoadRequest& aOther) = delete;
28 : ModuleLoadRequest(ModuleLoadRequest&& aOther) = delete;
29 :
30 : public:
31 : NS_DECL_ISUPPORTS_INHERITED
32 0 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ModuleLoadRequest, ScriptLoadRequest)
33 :
34 : ModuleLoadRequest(nsIScriptElement* aElement,
35 : uint32_t aVersion,
36 : CORSMode aCORSMode,
37 : const SRIMetadata& aIntegrity,
38 : ScriptLoader* aLoader);
39 :
40 0 : bool IsTopLevel() const
41 : {
42 0 : return mIsTopLevel;
43 : }
44 :
45 : void SetReady() override;
46 : void Cancel() override;
47 :
48 : void ModuleLoaded();
49 : void DependenciesLoaded();
50 : void LoadFailed();
51 :
52 : // Is this a request for a top level module script or an import?
53 : bool mIsTopLevel;
54 :
55 : // The base URL used for resolving relative module imports.
56 : nsCOMPtr<nsIURI> mBaseURL;
57 :
58 : // Pointer to the script loader, used to trigger actions when the module load
59 : // finishes.
60 : RefPtr<ScriptLoader> mLoader;
61 :
62 : // The importing module, or nullptr for top level module scripts. Used to
63 : // implement the ancestor list checked when fetching module dependencies.
64 : RefPtr<ModuleLoadRequest> mParent;
65 :
66 : // Set to a module script object after a successful load or nullptr on
67 : // failure.
68 : RefPtr<ModuleScript> mModuleScript;
69 :
70 : // A promise that is completed on successful load of this module and all of
71 : // its dependencies, indicating that the module is ready for instantiation and
72 : // evaluation.
73 : MozPromiseHolder<GenericPromise> mReady;
74 :
75 : // Array of imported modules.
76 : nsTArray<RefPtr<ModuleLoadRequest>> mImports;
77 : };
78 :
79 : } // dom namespace
80 : } // mozilla namespace
81 :
82 : #endif // mozilla_dom_ModuleLoadRequest_h
|