diff options
Diffstat (limited to 'js/src/builtin/ModuleObject.h')
-rw-r--r-- | js/src/builtin/ModuleObject.h | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/js/src/builtin/ModuleObject.h b/js/src/builtin/ModuleObject.h index 015cb42a5f..d39d65b18c 100644 --- a/js/src/builtin/ModuleObject.h +++ b/js/src/builtin/ModuleObject.h @@ -43,6 +43,7 @@ namespace js { class ArrayObject; class CyclicModuleFields; +class SyntheticModuleFields; class ListObject; class ModuleEnvironmentObject; class ModuleObject; @@ -51,16 +52,20 @@ class ScriptSourceObject; class ModuleRequestObject : public NativeObject { public: - enum { SpecifierSlot = 0, AssertionSlot, SlotCount }; + enum { SpecifierSlot = 0, AttributesSlot, SlotCount }; static const JSClass class_; static bool isInstance(HandleValue value); [[nodiscard]] static ModuleRequestObject* create( JSContext* cx, Handle<JSAtom*> specifier, - Handle<ArrayObject*> maybeAssertions); + Handle<ArrayObject*> maybeAttributes); JSAtom* specifier() const; - ArrayObject* assertions() const; + ArrayObject* attributes() const; + bool hasAttributes() const; + static bool getModuleType(JSContext* cx, + const Handle<ModuleRequestObject*> moduleRequest, + JS::ModuleType& moduleType); }; using ModuleRequestVector = @@ -309,6 +314,10 @@ constexpr uint32_t ASYNC_EVALUATING_POST_ORDER_INIT = 1; // Value that the field is set to after being cleared. constexpr uint32_t ASYNC_EVALUATING_POST_ORDER_CLEARED = 0; +// Currently, the ModuleObject class is used to represent both the Source Text +// Module Record and the Synthetic Module Record. Ideally, this is something +// that should be refactored to follow the same hierarchy as in the spec. +// TODO: See Bug 1880519. class ModuleObject : public NativeObject { public: // Module fields including those for AbstractModuleRecords described by: @@ -318,6 +327,8 @@ class ModuleObject : public NativeObject { EnvironmentSlot, NamespaceSlot, CyclicModuleFieldsSlot, + // `SyntheticModuleFields` if a synthetic module. Otherwise `undefined`. + SyntheticModuleFieldsSlot, SlotCount }; @@ -327,6 +338,9 @@ class ModuleObject : public NativeObject { static ModuleObject* create(JSContext* cx); + static ModuleObject* createSynthetic( + JSContext* cx, MutableHandle<ExportNameVector> exportNames); + // Initialize the slots on this object that are dependent on the script. void initScriptSlots(HandleScript script); @@ -364,6 +378,8 @@ class ModuleObject : public NativeObject { mozilla::Span<const ExportEntry> localExportEntries() const; mozilla::Span<const ExportEntry> indirectExportEntries() const; mozilla::Span<const ExportEntry> starExportEntries() const; + const ExportNameVector& syntheticExportNames() const; + IndirectBindingMap& importBindings(); void setStatus(ModuleStatus newStatus); @@ -390,6 +406,8 @@ class ModuleObject : public NativeObject { void clearAsyncEvaluatingPostOrder(); void setCycleRoot(ModuleObject* cycleRoot); ModuleObject* getCycleRoot() const; + bool hasCyclicModuleFields() const; + bool hasSyntheticModuleFields() const; static void onTopLevelEvaluationFinished(ModuleObject* module); @@ -413,6 +431,9 @@ class ModuleObject : public NativeObject { MutableHandle<UniquePtr<ExportNameVector>> exports); static bool createEnvironment(JSContext* cx, Handle<ModuleObject*> self); + static bool createSyntheticEnvironment(JSContext* cx, + Handle<ModuleObject*> self, + Handle<GCVector<Value>> values); void initAsyncSlots(JSContext* cx, bool hasTopLevelAwait, Handle<ListObject*> asyncParentModules); @@ -423,9 +444,11 @@ class ModuleObject : public NativeObject { static void trace(JSTracer* trc, JSObject* obj); static void finalize(JS::GCContext* gcx, JSObject* obj); - bool hasCyclicModuleFields() const; CyclicModuleFields* cyclicModuleFields(); const CyclicModuleFields* cyclicModuleFields() const; + + SyntheticModuleFields* syntheticModuleFields(); + const SyntheticModuleFields* syntheticModuleFields() const; }; JSObject* GetOrCreateModuleMetaObject(JSContext* cx, HandleObject module); |