/* static */ ModuleObject* ModuleObject::create(ExclusiveContext* cx, HandleObject enclosingStaticScope) { RootedObject proto(cx, cx->global()->getModulePrototype()); RootedObject obj(cx, NewObjectWithGivenProto(cx, &class_, proto)); if (!obj) return nullptr; RootedModuleObject self(cx, &obj->as<ModuleObject>()); self->initReservedSlot(StaticScopeSlot, ObjectOrNullValue(enclosingStaticScope)); Zone* zone = cx->zone(); IndirectBindingMap* bindings = zone->new_<IndirectBindingMap>(zone); if (!bindings || !bindings->init()) { ReportOutOfMemory(cx); js_delete<IndirectBindingMap>(bindings); return nullptr; } self->initReservedSlot(ImportBindingsSlot, PrivateValue(bindings)); FunctionDeclarationVector* funDecls = zone->new_<FunctionDeclarationVector>(zone); if (!funDecls) { ReportOutOfMemory(cx); return nullptr; } self->initReservedSlot(FunctionDeclarationsSlot, PrivateValue(funDecls)); return self; }
/* static */ ModuleNamespaceObject* ModuleObject::createNamespace(JSContext* cx, HandleModuleObject self, HandleArrayObject exports) { MOZ_ASSERT(!self->namespace_()); RootedModuleNamespaceObject ns(cx, ModuleNamespaceObject::create(cx, self)); if (!ns) return nullptr; IndirectBindingMap* bindings = cx->new_<IndirectBindingMap>(); if (!bindings || !bindings->init()) { ReportOutOfMemory(cx); return nullptr; } self->initReservedSlot(NamespaceSlot, ObjectValue(*ns)); self->initReservedSlot(NamespaceExportsSlot, ObjectValue(*exports)); self->initReservedSlot(NamespaceBindingsSlot, PrivateValue(bindings)); return ns; }
/* static */ ModuleObject* ModuleObject::create(ExclusiveContext* cx, HandleObject enclosingStaticScope) { Rooted<ModuleObject*> self(cx, NewBuiltinClassInstance<ModuleObject>(cx, TenuredObject)); if (!self) return nullptr; self->initReservedSlot(StaticScopeSlot, ObjectOrNullValue(enclosingStaticScope)); IndirectBindingMap* bindings = cx->new_<IndirectBindingMap>(); if (!bindings || !bindings->init()) { ReportOutOfMemory(cx); return nullptr; } self->initReservedSlot(ImportBindingsSlot, PrivateValue(bindings)); FunctionDeclarationVector* funDecls = cx->new_<FunctionDeclarationVector>(cx); if (!funDecls) return nullptr; self->initReservedSlot(FunctionDeclarationsSlot, PrivateValue(funDecls)); return self; }