summaryrefslogtreecommitdiffstats
path: root/js/src/builtin/ModuleObject.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/builtin/ModuleObject.cpp')
-rw-r--r--js/src/builtin/ModuleObject.cpp69
1 files changed, 38 insertions, 31 deletions
diff --git a/js/src/builtin/ModuleObject.cpp b/js/src/builtin/ModuleObject.cpp
index b275cb968..0a836c75b 100644
--- a/js/src/builtin/ModuleObject.cpp
+++ b/js/src/builtin/ModuleObject.cpp
@@ -18,10 +18,11 @@
using namespace js;
using namespace js::frontend;
-static_assert(MODULE_STATE_FAILED < MODULE_STATE_PARSED &&
- MODULE_STATE_PARSED < MODULE_STATE_INSTANTIATED &&
- MODULE_STATE_INSTANTIATED < MODULE_STATE_EVALUATED,
- "Module states are ordered incorrectly");
+static_assert(MODULE_STATUS_ERRORED < MODULE_STATUS_UNINSTANTIATED &&
+ MODULE_STATUS_UNINSTANTIATED < MODULE_STATUS_INSTANTIATING &&
+ MODULE_STATUS_INSTANTIATING < MODULE_STATUS_INSTANTIATED &&
+ MODULE_STATUS_INSTANTIATED < MODULE_STATUS_EVALUATED,
+ "Module statuses are ordered incorrectly");
template<typename T, Value ValueGetter(const T* obj)>
static bool
@@ -42,7 +43,7 @@ ModuleValueGetter(JSContext* cx, unsigned argc, Value* vp)
#define DEFINE_GETTER_FUNCTIONS(cls, name, slot) \
static Value \
cls##_##name##Value(const cls* obj) { \
- return obj->getFixedSlot(cls::slot); \
+ return obj->getReservedSlot(cls::slot); \
} \
\
static bool \
@@ -564,7 +565,7 @@ ModuleObject::class_ = {
ArrayObject& \
cls::name() const \
{ \
- return getFixedSlot(cls::slot).toObject().as<ArrayObject>(); \
+ return getReservedSlot(cls::slot).toObject().as<ArrayObject>(); \
}
DEFINE_ARRAY_SLOT_ACCESSOR(ModuleObject, requestedModules, RequestedModulesSlot)
@@ -688,7 +689,7 @@ void
ModuleObject::init(HandleScript script)
{
initReservedSlot(ScriptSlot, PrivateValue(script));
- initReservedSlot(StateSlot, Int32Value(MODULE_STATE_FAILED));
+ initReservedSlot(StatusSlot, Int32Value(MODULE_STATUS_ERRORED));
}
void
@@ -709,7 +710,7 @@ ModuleObject::initImportExportData(HandleArrayObject requestedModules,
initReservedSlot(LocalExportEntriesSlot, ObjectValue(*localExportEntries));
initReservedSlot(IndirectExportEntriesSlot, ObjectValue(*indirectExportEntries));
initReservedSlot(StarExportEntriesSlot, ObjectValue(*starExportEntries));
- setReservedSlot(StateSlot, Int32Value(MODULE_STATE_PARSED));
+ setReservedSlot(StatusSlot, Int32Value(MODULE_STATUS_UNINSTANTIATED));
}
static bool
@@ -790,17 +791,24 @@ ModuleObject::script() const
}
static inline void
-AssertValidModuleState(ModuleState state)
+AssertValidModuleStatus(ModuleStatus status)
{
- MOZ_ASSERT(state >= MODULE_STATE_FAILED && state <= MODULE_STATE_EVALUATED);
+ MOZ_ASSERT(status >= MODULE_STATUS_ERRORED && status <= MODULE_STATUS_EVALUATED);
}
-ModuleState
-ModuleObject::state() const
+ModuleStatus
+ModuleObject::status() const
{
- ModuleState state = getReservedSlot(StateSlot).toInt32();
- AssertValidModuleState(state);
- return state;
+ ModuleStatus status = getReservedSlot(StatusSlot).toInt32();
+ AssertValidModuleStatus(status);
+ return status;
+}
+
+Value
+ModuleObject::error() const
+{
+ MOZ_ASSERT(status() == MODULE_STATUS_ERRORED);
+ return getReservedSlot(ErrorSlot);
}
Value
@@ -899,17 +907,8 @@ ModuleObject::instantiateFunctionDeclarations(JSContext* cx, HandleModuleObject
return true;
}
-void
-ModuleObject::setState(int32_t newState)
-{
- AssertValidModuleState(newState);
- MOZ_ASSERT(state() != MODULE_STATE_FAILED);
- MOZ_ASSERT(newState == MODULE_STATE_FAILED || newState > state());
- setReservedSlot(StateSlot, Int32Value(newState));
-}
-
/* static */ bool
-ModuleObject::evaluate(JSContext* cx, HandleModuleObject self, MutableHandleValue rval)
+ModuleObject::execute(JSContext* cx, HandleModuleObject self, MutableHandleValue rval)
{
MOZ_ASSERT(IsFrozen(cx, self));
@@ -959,36 +958,42 @@ InvokeSelfHostedMethod(JSContext* cx, HandleModuleObject self, HandlePropertyNam
}
/* static */ bool
-ModuleObject::DeclarationInstantiation(JSContext* cx, HandleModuleObject self)
+ModuleObject::Instantiate(JSContext* cx, HandleModuleObject self)
{
- return InvokeSelfHostedMethod(cx, self, cx->names().ModuleDeclarationInstantiation);
+ return InvokeSelfHostedMethod(cx, self, cx->names().ModuleInstantiate);
}
/* static */ bool
-ModuleObject::Evaluation(JSContext* cx, HandleModuleObject self)
+ModuleObject::Evaluate(JSContext* cx, HandleModuleObject self)
{
- return InvokeSelfHostedMethod(cx, self, cx->names().ModuleEvaluation);
+ return InvokeSelfHostedMethod(cx, self, cx->names().ModuleEvaluate);
}
DEFINE_GETTER_FUNCTIONS(ModuleObject, namespace_, NamespaceSlot)
-DEFINE_GETTER_FUNCTIONS(ModuleObject, state, StateSlot)
+DEFINE_GETTER_FUNCTIONS(ModuleObject, status, StatusSlot)
+DEFINE_GETTER_FUNCTIONS(ModuleObject, error, ErrorSlot)
DEFINE_GETTER_FUNCTIONS(ModuleObject, requestedModules, RequestedModulesSlot)
DEFINE_GETTER_FUNCTIONS(ModuleObject, importEntries, ImportEntriesSlot)
DEFINE_GETTER_FUNCTIONS(ModuleObject, localExportEntries, LocalExportEntriesSlot)
DEFINE_GETTER_FUNCTIONS(ModuleObject, indirectExportEntries, IndirectExportEntriesSlot)
DEFINE_GETTER_FUNCTIONS(ModuleObject, starExportEntries, StarExportEntriesSlot)
+DEFINE_GETTER_FUNCTIONS(ModuleObject, dfsIndex, DFSIndexSlot)
+DEFINE_GETTER_FUNCTIONS(ModuleObject, dfsAncestorIndex, DFSAncestorIndexSlot)
/* static */ bool
GlobalObject::initModuleProto(JSContext* cx, Handle<GlobalObject*> global)
{
static const JSPropertySpec protoAccessors[] = {
JS_PSG("namespace", ModuleObject_namespace_Getter, 0),
- JS_PSG("state", ModuleObject_stateGetter, 0),
+ JS_PSG("status", ModuleObject_statusGetter, 0),
+ JS_PSG("error", ModuleObject_errorGetter, 0),
JS_PSG("requestedModules", ModuleObject_requestedModulesGetter, 0),
JS_PSG("importEntries", ModuleObject_importEntriesGetter, 0),
JS_PSG("localExportEntries", ModuleObject_localExportEntriesGetter, 0),
JS_PSG("indirectExportEntries", ModuleObject_indirectExportEntriesGetter, 0),
JS_PSG("starExportEntries", ModuleObject_starExportEntriesGetter, 0),
+ JS_PSG("dfsIndex", ModuleObject_dfsIndexGetter, 0),
+ JS_PSG("dfsAncestorIndex", ModuleObject_dfsAncestorIndexGetter, 0),
JS_PS_END
};
@@ -997,6 +1002,8 @@ GlobalObject::initModuleProto(JSContext* cx, Handle<GlobalObject*> global)
JS_SELF_HOSTED_FN("resolveExport", "ModuleResolveExport", 2, 0),
JS_SELF_HOSTED_FN("declarationInstantiation", "ModuleDeclarationInstantiation", 0, 0),
JS_SELF_HOSTED_FN("evaluation", "ModuleEvaluation", 0, 0),
+ JS_SELF_HOSTED_FN("declarationInstantiation", "ModuleInstantiate", 0, 0),
+ JS_SELF_HOSTED_FN("evaluation", "ModuleEvaluate", 0, 0),
JS_FS_END
};