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 shell_ModuleLoader_h
8 #define shell_ModuleLoader_h
10 #include "builtin/ModuleObject.h"
11 #include "js/RootingAPI.h"
18 bool init(JSContext
* cx
, HandleString loadPath
);
19 bool loadRootModule(JSContext
* cx
, HandleString path
);
21 // Testing hook to register a module that wasn't loaded by the module loader.
22 bool registerTestModule(JSContext
* cx
, HandleObject moduleRequest
,
23 Handle
<ModuleObject
*> module
);
25 // Testing hook to clear all loaded modules.
26 void clearModules(JSContext
* cx
);
29 static JSObject
* ResolveImportedModule(JSContext
* cx
,
30 HandleValue referencingPrivate
,
31 HandleObject moduleRequest
);
32 static bool GetImportMetaProperties(JSContext
* cx
, HandleValue privateValue
,
33 HandleObject metaObject
);
34 static bool ImportMetaResolve(JSContext
* cx
, unsigned argc
, Value
* vp
);
35 static bool ImportModuleDynamically(JSContext
* cx
,
36 HandleValue referencingPrivate
,
37 HandleObject moduleRequest
,
38 HandleObject promise
);
39 static bool GetSupportedImportAssertions(JSContext
* cx
,
40 JS::ImportAssertionVector
& values
);
42 static bool DynamicImportDelayFulfilled(JSContext
* cx
, unsigned argc
,
44 static bool DynamicImportDelayRejected(JSContext
* cx
, unsigned argc
,
47 bool loadAndExecute(JSContext
* cx
, HandleString path
, MutableHandleValue
);
48 JSObject
* resolveImportedModule(JSContext
* cx
, HandleValue referencingPrivate
,
49 HandleObject moduleRequest
);
50 bool populateImportMeta(JSContext
* cx
, HandleValue privateValue
,
51 HandleObject metaObject
);
52 bool importMetaResolve(JSContext
* cx
,
53 JS::Handle
<JS::Value
> referencingPrivate
,
54 JS::Handle
<JSString
*> specifier
,
55 JS::MutableHandle
<JSString
*> urlOut
);
56 bool dynamicImport(JSContext
* cx
, HandleValue referencingPrivate
,
57 HandleObject moduleRequest
, HandleObject promise
);
58 bool doDynamicImport(JSContext
* cx
, HandleValue referencingPrivate
,
59 HandleObject moduleRequest
, HandleObject promise
);
60 bool tryDynamicImport(JSContext
* cx
, HandleValue referencingPrivate
,
61 HandleObject moduleRequest
, HandleObject promise
,
62 MutableHandleValue rval
);
63 JSObject
* loadAndParse(JSContext
* cx
, HandleString path
);
64 bool lookupModuleInRegistry(JSContext
* cx
, HandleString path
,
65 MutableHandleObject moduleOut
);
66 bool addModuleToRegistry(JSContext
* cx
, HandleString path
,
68 JSLinearString
* resolve(JSContext
* cx
, HandleObject moduleRequestArg
,
69 HandleValue referencingInfo
);
70 JSLinearString
* resolve(JSContext
* cx
, HandleString specifier
,
71 HandleValue referencingInfo
);
72 bool getScriptPath(JSContext
* cx
, HandleValue privateValue
,
73 MutableHandle
<JSLinearString
*> pathOut
);
74 JSLinearString
* normalizePath(JSContext
* cx
, Handle
<JSLinearString
*> path
);
75 JSObject
* getOrCreateModuleRegistry(JSContext
* cx
);
76 JSString
* fetchSource(JSContext
* cx
, Handle
<JSLinearString
*> path
);
78 // The following are used for pinned atoms which do not need rooting.
79 JSAtom
* loadPathStr
= nullptr;
80 JSAtom
* pathSeparatorStr
= nullptr;
82 // The slot stored in ImportMetaResolve function.
83 enum { ModulePrivateSlot
= 0, SlotCount
};
85 // The number of args in ImportMetaResolve.
86 static const uint32_t ImportMetaResolveNumArgs
= 1;
87 // The index of the 'specifier' argument in ImportMetaResolve.
88 static const uint32_t ImportMetaResolveSpecifierArg
= 0;
89 } JS_HAZ_NON_GC_POINTER
;
94 #endif // shell_ModuleLoader_h