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_ModuleScript_h
8 : #define mozilla_dom_ModuleScript_h
9 :
10 : #include "nsCOMPtr.h"
11 : #include "nsCycleCollectionParticipant.h"
12 : #include "jsapi.h"
13 :
14 : class nsIURI;
15 :
16 : namespace mozilla {
17 : namespace dom {
18 :
19 : class ScriptLoader;
20 :
21 : class ModuleScript final : public nsISupports
22 : {
23 : enum InstantiationState {
24 : Uninstantiated,
25 : Instantiated,
26 : Errored
27 : };
28 :
29 : RefPtr<ScriptLoader> mLoader;
30 : nsCOMPtr<nsIURI> mBaseURL;
31 : JS::Heap<JSObject*> mModuleRecord;
32 : JS::Heap<JS::Value> mException;
33 : InstantiationState mInstantiationState;
34 :
35 : ~ModuleScript();
36 :
37 : public:
38 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
39 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ModuleScript)
40 :
41 : ModuleScript(ScriptLoader* aLoader,
42 : nsIURI* aBaseURL,
43 : JS::Handle<JSObject*> aModuleRecord);
44 :
45 0 : ScriptLoader* Loader() const { return mLoader; }
46 0 : JSObject* ModuleRecord() const { return mModuleRecord; }
47 0 : JS::Value Exception() const { return mException; }
48 0 : nsIURI* BaseURL() const { return mBaseURL; }
49 :
50 : void SetInstantiationResult(JS::Handle<JS::Value> aMaybeException);
51 :
52 0 : bool IsUninstantiated() const
53 : {
54 0 : return mInstantiationState == Uninstantiated;
55 : }
56 :
57 : bool IsInstantiated() const
58 : {
59 : return mInstantiationState == Instantiated;
60 : }
61 :
62 0 : bool InstantiationFailed() const
63 : {
64 0 : return mInstantiationState == Errored;
65 : }
66 :
67 : void UnlinkModuleRecord();
68 : };
69 :
70 : } // dom namespace
71 : } // mozilla namespace
72 :
73 : #endif // mozilla_dom_ModuleScript_h
|