File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -456,6 +456,13 @@ void ModuleScript::SetModuleRecord(Handle<JSObject*> aModuleRecord) {
456456 SetModulePrivate (mModuleRecord , PrivateValue (this ));
457457 }
458458
459+ #ifdef DEBUG
460+ // Sync the [[PreloadSlot]] in ModuleObject.
461+ if (mModuleRecord ) {
462+ SetModulePreload (mModuleRecord , mForPreload );
463+ }
464+ #endif
465+
459466 mozilla::HoldJSObjects (this );
460467}
461468
@@ -479,7 +486,14 @@ void ModuleScript::SetErrorToRethrow(const Value& aError) {
479486 mErrorToRethrow = aError;
480487}
481488
482- void ModuleScript::SetForPreload (bool aValue) { mForPreload = aValue; }
489+ void ModuleScript::SetForPreload (bool aValue) {
490+ mForPreload = aValue;
491+ #ifdef DEBUG
492+ if (ModuleRecord ()) {
493+ SetModulePreload (ModuleRecord (), aValue);
494+ }
495+ #endif
496+ }
483497void ModuleScript::SetHadImportMap (bool aValue) { mHadImportMap = aValue; }
484498
485499ResolvedModuleSet* ModuleScript::GetPreloadedResolvedSet () {
Original file line number Diff line number Diff line change @@ -1055,8 +1055,8 @@ nsresult ModuleLoaderBase::CreateModuleScript(ModuleLoadRequest* aRequest) {
10551055 moduleScript->SetModuleRecord (module );
10561056 }
10571057
1058- LOG ((" ScriptLoadRequest (%p): module script == %p" , aRequest,
1059- aRequest->mModuleScript .get ()));
1058+ LOG ((" ScriptLoadRequest (%p): module script == %p ForPreload %d " , aRequest,
1059+ aRequest->mModuleScript .get (), aRequest-> mModuleScript -> ForPreload () ));
10601060
10611061 return rv;
10621062}
Original file line number Diff line number Diff line change @@ -246,6 +246,14 @@ extern JS_PUBLIC_API Value GetModulePrivate(JSObject* module);
246246 */
247247extern JS_PUBLIC_API bool IsCyclicModule (JSObject* module );
248248
249+ #ifdef DEBUG
250+ /* *
251+ * A helper function to set the isPreload flag on the ModuleObject.
252+ * The flag will be verified later when ResetPreloadedModule is called.
253+ */
254+ extern JS_PUBLIC_API void SetModulePreload (JSObject* module , bool isPreload);
255+ #endif
256+
249257/*
250258 * Perform the ModuleLink operation on the given source text module record.
251259 *
Original file line number Diff line number Diff line change @@ -1342,6 +1342,16 @@ void ModuleObject::setMetaObject(JSObject* obj) {
13421342 cyclicModuleFields ()->metaObject = obj;
13431343}
13441344
1345+ #ifdef DEBUG
1346+ void ModuleObject::setPreload (bool isPreload) {
1347+ setReservedSlot (PreloadSlot, BooleanValue (isPreload));
1348+ }
1349+
1350+ bool ModuleObject::isPreload () const {
1351+ return getReservedSlot (PreloadSlot).toBoolean ();
1352+ }
1353+ #endif
1354+
13451355/* static */
13461356void ModuleObject::trace (JSTracer* trc, JSObject* obj) {
13471357 ModuleObject& module = obj->as <ModuleObject>();
Original file line number Diff line number Diff line change @@ -395,6 +395,9 @@ class ModuleObject : public NativeObject {
395395 CyclicModuleFieldsSlot,
396396 // `SyntheticModuleFields` if a synthetic module. Otherwise `undefined`.
397397 SyntheticModuleFieldsSlot,
398+ #ifdef DEBUG
399+ PreloadSlot,
400+ #endif
398401 SlotCount
399402 };
400403
@@ -501,6 +504,11 @@ class ModuleObject : public NativeObject {
501504 void initAsyncSlots (JSContext* cx, bool hasTopLevelAwait,
502505 Handle<ListObject*> asyncParentModules);
503506
507+ #ifdef DEBUG
508+ void setPreload (bool isPreload);
509+ bool isPreload () const ;
510+ #endif
511+
504512 private:
505513 static const JSClassOps classOps_;
506514
Original file line number Diff line number Diff line change @@ -338,6 +338,13 @@ JS_PUBLIC_API bool JS::IsCyclicModule(JSObject* module) {
338338 return module ->as <ModuleObject>().hasCyclicModuleFields ();
339339}
340340
341+ #ifdef DEBUG
342+ JS_PUBLIC_API void JS::SetModulePreload (JSObject* module , bool isPreload) {
343+ MOZ_ASSERT (module ->is <ModuleObject>());
344+ module ->as <ModuleObject>().setPreload (isPreload);
345+ }
346+ #endif
347+
341348JS_PUBLIC_API bool JS::ModuleLink (JSContext* cx, Handle<JSObject*> moduleArg) {
342349 AssertHeapIsIdle ();
343350 CHECK_THREAD (cx);
You can’t perform that action at this time.
0 commit comments