Bug 1736060 - Part 3: Extend ModuleRequestObject to hold assertions. r=mgaudet,arai
authorJonatan Klemets <jonatan.r.klemets@gmail.com>
Wed, 01 Dec 2021 18:26:09 +0000
changeset 600818 745266de3cd629b4c32712d01d063a2af0cb1b61
parent 600817 e6610d067c5c2518cf57fbdd96f520a48ac8b060
child 600819 5b9622ccd0d2defa689d4c39b2c1a5a57ba3cce5
push id39030
push userccozmuta@mozilla.com
push dateThu, 02 Dec 2021 09:42:49 +0000
treeherdermozilla-central@7af79a49bf5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmgaudet, arai
bugs1736060
milestone96.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1736060 - Part 3: Extend ModuleRequestObject to hold assertions. r=mgaudet,arai Differential Revision: https://phabricator.services.mozilla.com/D126043
js/src/builtin/ModuleObject.cpp
js/src/builtin/ModuleObject.h
js/src/shell/ShellModuleObjectWrapper.cpp
js/src/shell/js.cpp
js/src/vm/Modules.cpp
--- a/js/src/builtin/ModuleObject.cpp
+++ b/js/src/builtin/ModuleObject.cpp
@@ -323,60 +323,63 @@ RequestedModuleObject* RequestedModuleOb
 
 ///////////////////////////////////////////////////////////////////////////
 // ModuleRequestObject
 /* static */ const JSClass ModuleRequestObject::class_ = {
     "ModuleRequest",
     JSCLASS_HAS_RESERVED_SLOTS(ModuleRequestObject::SlotCount)};
 
 DEFINE_GETTER_FUNCTIONS(ModuleRequestObject, specifier, SpecifierSlot)
+DEFINE_GETTER_FUNCTIONS(ModuleRequestObject, assertions, AssertionSlot)
 
 DEFINE_ATOM_OR_NULL_ACCESSOR_METHOD(ModuleRequestObject, specifier)
 
 /* static */
 bool ModuleRequestObject::isInstance(HandleValue value) {
   return value.isObject() && value.toObject().is<ModuleRequestObject>();
 }
 
 /* static */
 bool GlobalObject::initModuleRequestProto(JSContext* cx,
                                           Handle<GlobalObject*> global) {
   static const JSPropertySpec protoAccessors[] = {
-      JS_PSG("specifier", ModuleRequestObject_specifierGetter, 0), JS_PS_END};
+      JS_PSG("specifier", ModuleRequestObject_specifierGetter, 0),
+      JS_PSG("assertions", ModuleRequestObject_assertionsGetter, 0), JS_PS_END};
 
   RootedObject proto(
       cx, GlobalObject::createBlankPrototype<PlainObject>(cx, global));
   if (!proto) {
     return false;
   }
 
   if (!DefinePropertiesAndFunctions(cx, proto, protoAccessors, nullptr)) {
     return false;
   }
 
   global->initBuiltinProto(ProtoKind::ModuleRequestProto, proto);
   return true;
 }
 
 /* static */
-ModuleRequestObject* ModuleRequestObject::create(JSContext* cx,
-                                                 HandleAtom specifier) {
+ModuleRequestObject* ModuleRequestObject::create(
+    JSContext* cx, HandleAtom specifier, HandleArrayObject maybeAssertions) {
   RootedObject proto(
       cx, GlobalObject::getOrCreateModuleRequestPrototype(cx, cx->global()));
   if (!proto) {
     return nullptr;
   }
 
   ModuleRequestObject* self =
       NewObjectWithGivenProto<ModuleRequestObject>(cx, proto);
   if (!self) {
     return nullptr;
   }
 
   self->initReservedSlot(SpecifierSlot, StringOrNullValue(specifier));
+  self->initReservedSlot(AssertionSlot, ObjectOrNullValue(maybeAssertions));
   return self;
 }
 
 ///////////////////////////////////////////////////////////////////////////
 // IndirectBindingMap
 
 IndirectBindingMap::Binding::Binding(ModuleEnvironmentObject* environment,
                                      jsid targetName, PropertyInfo prop)
@@ -1532,17 +1535,17 @@ static ArrayObject* ModuleBuilderInitArr
 
     if (entry.exportName) {
       exportName = atomCache.getExistingAtomAt(cx, entry.exportName);
       MOZ_ASSERT(exportName);
     } else {
       MOZ_ASSERT(!exportName);
     }
 
-    moduleRequest = ModuleRequestObject::create(cx, specifier);
+    moduleRequest = ModuleRequestObject::create(cx, specifier, nullptr);
     if (!moduleRequest) {
       return nullptr;
     }
 
     switch (arrayType) {
       case ModuleArrayType::ImportEntryObject:
         MOZ_ASSERT(localName);
         req = ImportEntryObject::create(cx, moduleRequest, importName,
@@ -2289,18 +2292,18 @@ JSObject* js::StartDynamicModuleImport(J
   RootedAtom specifierAtom(cx, AtomizeString(cx, specifier));
   if (!specifierAtom) {
     if (!RejectPromiseWithPendingError(cx, promise)) {
       return nullptr;
     }
     return promise;
   }
 
-  RootedObject moduleRequest(cx,
-                             ModuleRequestObject::create(cx, specifierAtom));
+  RootedObject moduleRequest(
+      cx, ModuleRequestObject::create(cx, specifierAtom, nullptr));
   if (!moduleRequest) {
     if (!RejectPromiseWithPendingError(cx, promise)) {
       return nullptr;
     }
     return promise;
   }
 
   if (!importHook(cx, referencingPrivate, moduleRequest, promise)) {
@@ -2363,17 +2366,18 @@ static bool OnResolvedDynamicModule(JSCo
     return false;
   }
 
   Rooted<PromiseObject*> promise(cx, TargetFromHandler<PromiseObject>(args));
 
   auto releasePrivate = mozilla::MakeScopeExit(
       [&] { cx->runtime()->releaseScriptPrivate(referencingPrivate); });
 
-  RootedObject moduleRequest(cx, ModuleRequestObject::create(cx, specifier));
+  RootedObject moduleRequest(
+      cx, ModuleRequestObject::create(cx, specifier, nullptr));
   if (!moduleRequest) {
     return RejectPromiseWithPendingError(cx, promise);
   }
 
   RootedObject result(
       cx, CallModuleResolveHook(cx, referencingPrivate, moduleRequest));
 
   if (!result) {
--- a/js/src/builtin/ModuleObject.h
+++ b/js/src/builtin/ModuleObject.h
@@ -50,22 +50,22 @@ class ModuleObject;
 
 using RootedModuleObject = Rooted<ModuleObject*>;
 using HandleModuleObject = Handle<ModuleObject*>;
 using RootedModuleEnvironmentObject = Rooted<ModuleEnvironmentObject*>;
 using HandleModuleEnvironmentObject = Handle<ModuleEnvironmentObject*>;
 
 class ModuleRequestObject : public NativeObject {
  public:
-  enum { SpecifierSlot = 0, SlotCount };
+  enum { SpecifierSlot = 0, AssertionSlot, SlotCount };
 
   static const JSClass class_;
   static bool isInstance(HandleValue value);
-  [[nodiscard]] static ModuleRequestObject* create(JSContext* cx,
-                                                   HandleAtom specifier);
+  [[nodiscard]] static ModuleRequestObject* create(
+      JSContext* cx, HandleAtom specifier, HandleArrayObject maybeAssertions);
 
   JSAtom* specifier() const;
 };
 
 class ImportEntryObject : public NativeObject {
  public:
   enum {
     ModuleRequestSlot = 0,
--- a/js/src/shell/ShellModuleObjectWrapper.cpp
+++ b/js/src/shell/ShellModuleObjectWrapper.cpp
@@ -182,19 +182,21 @@ bool ShellModuleWrapperGetter(JSContext*
                                                    unsigned argc, Value* vp) { \
     JS::CallArgs args = JS::CallArgsFromVp(argc, vp);                          \
     return CallNonGenericMethod<IsShell##CLASS##Wrapper,                       \
                                 Shell##CLASS##Wrapper_##PROP##Getter_impl>(    \
         cx, args);                                                             \
   }
 
 DEFINE_GETTER_FUNCTIONS(ModuleRequestObject, specifier, IdentFilter)
+DEFINE_GETTER_FUNCTIONS(ModuleRequestObject, assertions, IdentFilter)
 
 static const JSPropertySpec ShellModuleRequestObjectWrapper_accessors[] = {
     JS_PSG("specifier", ShellModuleRequestObjectWrapper_specifierGetter, 0),
+    JS_PSG("assertions", ShellModuleRequestObjectWrapper_assertionsGetter, 0),
     JS_PS_END};
 
 DEFINE_GETTER_FUNCTIONS(ImportEntryObject, moduleRequest,
                         SingleFilter<ShellModuleRequestObjectWrapper>)
 DEFINE_GETTER_FUNCTIONS(ImportEntryObject, importName, IdentFilter)
 DEFINE_GETTER_FUNCTIONS(ImportEntryObject, localName, IdentFilter)
 DEFINE_GETTER_FUNCTIONS(ImportEntryObject, lineNumber, IdentFilter)
 DEFINE_GETTER_FUNCTIONS(ImportEntryObject, columnNumber, IdentFilter)
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -5664,17 +5664,18 @@ static bool RegisterModule(JSContext* cx
   RootedModuleObject module(
       cx, args[1].toObject().as<ShellModuleObjectWrapper>().get());
 
   RootedAtom specifier(cx, AtomizeString(cx, args[0].toString()));
   if (!specifier) {
     return false;
   }
 
-  RootedObject moduleRequest(cx, ModuleRequestObject::create(cx, specifier));
+  RootedObject moduleRequest(
+      cx, ModuleRequestObject::create(cx, specifier, nullptr));
   if (!moduleRequest) {
     return false;
   }
 
   if (!sc->moduleLoader->registerTestModule(cx, moduleRequest, module)) {
     return false;
   }
 
--- a/js/src/vm/Modules.cpp
+++ b/js/src/vm/Modules.cpp
@@ -189,17 +189,17 @@ JS_PUBLIC_API JSObject* JS::CreateModule
   AssertHeapIsIdle();
   CHECK_THREAD(cx);
 
   js::RootedAtom specifierAtom(cx, AtomizeString(cx, specifierArg));
   if (!specifierAtom) {
     return nullptr;
   }
 
-  return js::ModuleRequestObject::create(cx, specifierAtom);
+  return js::ModuleRequestObject::create(cx, specifierAtom, nullptr);
 }
 
 JS_PUBLIC_API JSString* JS::GetModuleRequestSpecifier(
     JSContext* cx, Handle<JSObject*> moduleRequestArg) {
   AssertHeapIsIdle();
   CHECK_THREAD(cx);
   cx->check(moduleRequestArg);