Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/script/ModuleLoadRequest.h
Line
Count
Source (jump to first uncovered line)
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 "nsURIHashKey.h"
12
#include "mozilla/MozPromise.h"
13
14
namespace mozilla {
15
namespace dom {
16
17
class ModuleScript;
18
class ScriptLoader;
19
20
// A reference counted set of URLs we have visited in the process of loading a
21
// module graph.
22
class VisitedURLSet : public nsTHashtable<nsURIHashKey>
23
{
24
  NS_INLINE_DECL_REFCOUNTING(VisitedURLSet)
25
26
private:
27
  ~VisitedURLSet() = default;
28
};
29
30
// A load request for a module, created for every top level module script and
31
// every module import.  Load request can share an ModuleScript if there are
32
// multiple imports of the same module.
33
34
class ModuleLoadRequest final : public ScriptLoadRequest
35
{
36
0
  ~ModuleLoadRequest() = default;
37
38
  ModuleLoadRequest(const ModuleLoadRequest& aOther) = delete;
39
  ModuleLoadRequest(ModuleLoadRequest&& aOther) = delete;
40
41
public:
42
  NS_DECL_ISUPPORTS_INHERITED
43
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ModuleLoadRequest, ScriptLoadRequest)
44
45
  // Create a top-level module load request.
46
  ModuleLoadRequest(nsIURI* aURI,
47
                    ScriptFetchOptions* aFetchOptions,
48
                    const SRIMetadata& aIntegrity,
49
                    nsIURI* aReferrer,
50
                    ScriptLoader* aLoader);
51
52
  // Create a module load request for an imported module.
53
  ModuleLoadRequest(nsIURI* aURI,
54
                    ModuleLoadRequest* aParent);
55
56
  bool IsTopLevel() const override
57
0
  {
58
0
    return mIsTopLevel;
59
0
  }
60
61
  void SetReady() override;
62
  void Cancel() override;
63
64
  void ModuleLoaded();
65
  void ModuleErrored();
66
  void DependenciesLoaded();
67
  void LoadFailed();
68
69
 private:
70
  void LoadFinished();
71
  void CancelImports();
72
73
 public:
74
  // Is this a request for a top level module script or an import?
75
  const bool mIsTopLevel;
76
77
  // The base URL used for resolving relative module imports.
78
  nsCOMPtr<nsIURI> mBaseURL;
79
80
  // Pointer to the script loader, used to trigger actions when the module load
81
  // finishes.
82
  RefPtr<ScriptLoader> mLoader;
83
84
  // Set to a module script object after a successful load or nullptr on
85
  // failure.
86
  RefPtr<ModuleScript> mModuleScript;
87
88
  // A promise that is completed on successful load of this module and all of
89
  // its dependencies, indicating that the module is ready for instantiation and
90
  // evaluation.
91
  MozPromiseHolder<GenericPromise> mReady;
92
93
  // Array of imported modules.
94
  nsTArray<RefPtr<ModuleLoadRequest>> mImports;
95
96
  // Set of module URLs visited while fetching the module graph this request is
97
  // part of.
98
  RefPtr<VisitedURLSet> mVisitedSet;
99
};
100
101
} // dom namespace
102
} // mozilla namespace
103
104
#endif // mozilla_dom_ModuleLoadRequest_h