commit 0a0abe40bbe8cc587e6316541d7c59042fb9ae54
parent 5c11e6db0b70304f1b3a9ef5c51b5d39bc5fa85d
Author: Alexandru Marc <amarc@mozilla.com>
Date: Tue, 11 Nov 2025 08:14:40 +0200
Revert "Bug 1993582 - Disambiguiate MicroTask kinds at the C++ type level r=arai,smaug" for causing hazard bustages @ Promise.cpp
This reverts commit ff7da48b891cb7cc533d9df3b0bba2c136bce89a.
Revert "Bug 1993582 - Rename JS::MicroTask to JS::GenericMicroTask r=arai"
This reverts commit 6d8788fd15726d8661d6f1a37cc276cc4acd833c.
Revert "Bug 1993582 - Fix missed use of typedef r=arai"
This reverts commit 7326d5e59a3b5816e5597a1e3e8ee095b6d602d7.
Diffstat:
7 files changed, 104 insertions(+), 141 deletions(-)
diff --git a/js/public/friend/MicroTask.h b/js/public/friend/MicroTask.h
@@ -58,21 +58,15 @@ namespace JS {
//
// An embedding is free to do with non-JS MicroTasks as it
// sees fit.
-using GenericMicroTask = JS::Value;
-using JSMicroTask = JSObject;
+using MicroTask = JS::Value;
-JS_PUBLIC_API bool IsJSMicroTask(const JS::GenericMicroTask& hv);
-JS_PUBLIC_API JSMicroTask* ToUnwrappedJSMicroTask(
- const JS::GenericMicroTask& genericMicroTask);
-JS_PUBLIC_API JSMicroTask* ToMaybeWrappedJSMicroTask(
- const JS::GenericMicroTask& genericMicroTask);
+JS_PUBLIC_API bool IsJSMicroTask(const JS::Value& hv);
// Run a MicroTask that is known to be a JS MicroTask. This will crash
// if provided an invalid task kind.
//
// This will return false if an exception is thrown while processing.
-JS_PUBLIC_API bool RunJSMicroTask(JSContext* cx,
- Handle<JS::JSMicroTask*> entry);
+JS_PUBLIC_API bool RunJSMicroTask(JSContext* cx, Handle<MicroTask> entry);
// Queue Management. This is done per-JSContext.
//
@@ -88,12 +82,9 @@ JS_PUBLIC_API bool RunJSMicroTask(JSContext* cx,
// patterns used by Gecko.
//
// These methods only fail for OOM.
-JS_PUBLIC_API bool EnqueueMicroTask(JSContext* cx,
- const GenericMicroTask& entry);
-JS_PUBLIC_API bool EnqueueDebugMicroTask(JSContext* cx,
- const GenericMicroTask& entry);
-JS_PUBLIC_API bool PrependMicroTask(JSContext* cx,
- const GenericMicroTask& entry);
+JS_PUBLIC_API bool EnqueueMicroTask(JSContext* cx, const MicroTask& entry);
+JS_PUBLIC_API bool EnqueueDebugMicroTask(JSContext* cx, const MicroTask& entry);
+JS_PUBLIC_API bool PrependMicroTask(JSContext* cx, const MicroTask& entry);
// Dequeue the next MicroTask. If there are no MicroTasks of the appropriate
// kind, each of the below API returns JS::NullValue().
@@ -109,9 +100,9 @@ JS_PUBLIC_API bool PrependMicroTask(JSContext* cx,
//
// so checking for emptiness before calling these is not required, and is
// very slightly less efficient.
-JS_PUBLIC_API GenericMicroTask DequeueNextMicroTask(JSContext* cx);
-JS_PUBLIC_API GenericMicroTask DequeueNextDebuggerMicroTask(JSContext* cx);
-JS_PUBLIC_API GenericMicroTask DequeueNextRegularMicroTask(JSContext* cx);
+JS_PUBLIC_API MicroTask DequeueNextMicroTask(JSContext* cx);
+JS_PUBLIC_API MicroTask DequeueNextDebuggerMicroTask(JSContext* cx);
+JS_PUBLIC_API MicroTask DequeueNextRegularMicroTask(JSContext* cx);
// Returns true if there are -any- microtasks pending in the queue.
JS_PUBLIC_API bool HasAnyMicroTasks(JSContext* cx);
@@ -127,7 +118,8 @@ JS_PUBLIC_API bool HasRegularMicroTasks(JSContext* cx);
JS_PUBLIC_API size_t GetRegularMicroTaskCount(JSContext* cx);
// This is the global associated with the realm RunJSMicroTask expects to be in.
-JS_PUBLIC_API JSObject* GetExecutionGlobalFromJSMicroTask(JSMicroTask* entry);
+JS_PUBLIC_API JSObject* GetExecutionGlobalFromJSMicroTask(
+ const MicroTask& entry);
// To handle cases where the queue needs to be set aside for some reason
// (mostly the Debugger API), we provide a Save and Restore API.
@@ -156,21 +148,22 @@ JS_PUBLIC_API void RestoreMicroTaskQueue(
// All of these may return null if there's no data, or if there's a
// security error.
JS_PUBLIC_API JSObject* MaybeGetHostDefinedDataFromJSMicroTask(
- JSMicroTask* entry);
+ const MicroTask& entry);
JS_PUBLIC_API JSObject* MaybeGetAllocationSiteFromJSMicroTask(
- JSMicroTask* entry);
+ const MicroTask& entry);
// In some circumstances an entry may not have host defined data but may
// still have a host defined global;
JS_PUBLIC_API JSObject* MaybeGetHostDefinedGlobalFromJSMicroTask(
- JSMicroTask* entry);
+ const MicroTask& entry);
-JS_PUBLIC_API JSObject* MaybeGetPromiseFromJSMicroTask(JSMicroTask* entry);
+JS_PUBLIC_API JSObject* MaybeGetPromiseFromJSMicroTask(const MicroTask& entry);
// Get the flow ID from a JS microtask for profiler markers.
// This only returns false if entry has become a dead wrapper,
// in which case the microtask doesn't run anyhow.
-JS_PUBLIC_API bool GetFlowIdFromJSMicroTask(JSMicroTask* entry, uint64_t* uid);
+JS_PUBLIC_API bool GetFlowIdFromJSMicroTask(const MicroTask& entry,
+ uint64_t* uid);
} // namespace JS
diff --git a/js/src/builtin/Promise.cpp b/js/src/builtin/Promise.cpp
@@ -1678,7 +1678,7 @@ static bool ResolvePromiseFunction(JSContext* cx, unsigned argc, Value* vp) {
return true;
}
-static bool EnqueueJob(JSContext* cx, JS::JSMicroTask* job) {
+static bool EnqueueJob(JSContext* cx, JS::MicroTask&& job) {
MOZ_ASSERT(cx->realm());
GeckoProfilerRuntime& profiler = cx->runtime()->geckoProfiler();
if (profiler.enabled()) {
@@ -1693,9 +1693,9 @@ static bool EnqueueJob(JSContext* cx, JS::JSMicroTask* job) {
// Only check if we need to use the debug queue when we're not on main thread.
if (MOZ_UNLIKELY(!cx->runtime()->isMainRuntime() &&
cx->jobQueue->useDebugQueue(cx->global()))) {
- return cx->microTaskQueues->enqueueDebugMicroTask(cx, ObjectValue(*job));
+ return cx->microTaskQueues->enqueueDebugMicroTask(cx, std::move(job));
}
- return cx->microTaskQueues->enqueueRegularMicroTask(cx, ObjectValue(*job));
+ return cx->microTaskQueues->enqueueRegularMicroTask(cx, std::move(job));
}
static bool PromiseReactionJob(JSContext* cx, unsigned argc, Value* vp);
@@ -1923,7 +1923,7 @@ static bool PromiseReactionJob(JSContext* cx, unsigned argc, Value* vp);
}
// HostEnqueuePromiseJob(job.[[Job]], job.[[Realm]]).
- return EnqueueJob(cx, &reactionVal.toObject());
+ return EnqueueJob(cx, std::move(reactionVal.get()));
}
RootedField<JSObject*, 7> hostDefinedData(roots);
@@ -2940,7 +2940,7 @@ static bool PromiseResolveBuiltinThenableJob(JSContext* cx, unsigned argc,
thenableJob->setHostDefinedGlobalRepresentative(
hostDefinedGlobalRepresentative);
- return EnqueueJob(cx, thenableJob);
+ return EnqueueJob(cx, ObjectValue(*thenableJob));
}
// Step 1. Let job be a new Job Abstract Closure with no parameters that
@@ -3000,7 +3000,7 @@ static bool PromiseResolveBuiltinThenableJob(JSContext* cx, unsigned argc,
return false;
}
- return EnqueueJob(cx, thenableJob);
+ return EnqueueJob(cx, ObjectValue(*thenableJob));
}
// Step 1. Let job be a new Job Abstract Closure with no parameters that
@@ -7633,17 +7633,17 @@ void PromiseObject::dumpOwnStringContent(js::GenericPrinter& out) const {}
return true;
}
-JS_PUBLIC_API bool JS::RunJSMicroTask(JSContext* cx,
- Handle<JS::JSMicroTask*> entry) {
+JS_PUBLIC_API bool JS::RunJSMicroTask(JSContext* cx, Handle<MicroTask> entry) {
#ifdef DEBUG
+ MOZ_ASSERT(entry.isObject());
JSObject* global = JS::GetExecutionGlobalFromJSMicroTask(entry);
MOZ_ASSERT(global == cx->global());
#endif
- RootedObject task(cx, entry);
+ RootedObject task(cx, &entry.toObject());
MOZ_ASSERT(!JS_IsDeadWrapper(task));
- RootedObject unwrappedTask(cx, UncheckedUnwrap(entry));
+ RootedObject unwrappedTask(cx, UncheckedUnwrap(&entry.toObject()));
MOZ_ASSERT(unwrappedTask);
if (unwrappedTask->is<PromiseReactionRecord>()) {
@@ -7691,9 +7691,12 @@ inline bool JSObject::is<MicroTaskEntry>() const {
}
JS_PUBLIC_API JSObject* JS::MaybeGetHostDefinedDataFromJSMicroTask(
- JS::JSMicroTask* entry) {
- MOZ_ASSERT(!JS_IsDeadWrapper(entry));
- JSObject* task = CheckedUnwrapStatic(entry);
+ const MicroTask& entry) {
+ if (!entry.isObject()) {
+ return nullptr;
+ }
+ MOZ_ASSERT(!JS_IsDeadWrapper(&entry.toObject()));
+ JSObject* task = CheckedUnwrapStatic(&entry.toObject());
if (!task) {
return nullptr;
}
@@ -7711,8 +7714,11 @@ JS_PUBLIC_API JSObject* JS::MaybeGetHostDefinedDataFromJSMicroTask(
}
JS_PUBLIC_API JSObject* JS::MaybeGetAllocationSiteFromJSMicroTask(
- JS::JSMicroTask* entry) {
- JSObject* task = UncheckedUnwrap(entry);
+ const MicroTask& entry) {
+ if (!entry.isObject()) {
+ return nullptr;
+ }
+ JSObject* task = UncheckedUnwrap(&entry.toObject());
MOZ_ASSERT(task);
if (JS_IsDeadWrapper(task)) {
return nullptr;
@@ -7733,8 +7739,11 @@ JS_PUBLIC_API JSObject* JS::MaybeGetAllocationSiteFromJSMicroTask(
}
JS_PUBLIC_API JSObject* JS::MaybeGetHostDefinedGlobalFromJSMicroTask(
- JSMicroTask* entry) {
- JSObject* task = UncheckedUnwrap(entry);
+ const MicroTask& entry) {
+ if (!entry.isObject()) {
+ return nullptr;
+ }
+ JSObject* task = UncheckedUnwrap(&entry.toObject());
MOZ_ASSERT(task->is<MicroTaskEntry>());
JSObject* maybeWrappedHostDefinedRepresentative =
@@ -7749,8 +7758,10 @@ JS_PUBLIC_API JSObject* JS::MaybeGetHostDefinedGlobalFromJSMicroTask(
}
JS_PUBLIC_API JSObject* JS::GetExecutionGlobalFromJSMicroTask(
- JS::JSMicroTask* entry) {
- JSObject* unwrapped = UncheckedUnwrap(entry);
+ const MicroTask& entry) {
+ MOZ_RELEASE_ASSERT(entry.isObject(), "Only use on JSMicroTasks");
+
+ JSObject* unwrapped = UncheckedUnwrap(&entry.toObject());
if (unwrapped->is<PromiseReactionRecord>()) {
// Use the stored equeue representative (which may need to be unwrapped)
JSObject* enqueueGlobalRepresentative =
@@ -7779,8 +7790,10 @@ JS_PUBLIC_API JSObject* JS::GetExecutionGlobalFromJSMicroTask(
}
JS_PUBLIC_API JSObject* JS::MaybeGetPromiseFromJSMicroTask(
- JS::JSMicroTask* entry) {
- JSObject* unwrapped = UncheckedUnwrap(entry);
+ const MicroTask& entry) {
+ MOZ_RELEASE_ASSERT(entry.isObject(), "Only use on JSMicroTasks");
+
+ JSObject* unwrapped = UncheckedUnwrap(&entry.toObject());
// We don't expect to ever lose the record a job points to.
MOZ_RELEASE_ASSERT(!JS_IsDeadWrapper(unwrapped));
@@ -7791,11 +7804,13 @@ JS_PUBLIC_API JSObject* JS::MaybeGetPromiseFromJSMicroTask(
return nullptr;
}
-JS_PUBLIC_API bool JS::GetFlowIdFromJSMicroTask(JS::JSMicroTask* entry,
+JS_PUBLIC_API bool JS::GetFlowIdFromJSMicroTask(const MicroTask& entry,
uint64_t* uid) {
+ MOZ_RELEASE_ASSERT(entry.isObject(), "Only use on JSMicroTasks");
+
// We want to make sure we get the flow id from the target object
// not the wrapper.
- JSObject* unwrapped = UncheckedUnwrap(entry);
+ JSObject* unwrapped = UncheckedUnwrap(&entry.toObject());
if (JS_IsDeadWrapper(unwrapped)) {
return false;
}
@@ -7806,36 +7821,18 @@ JS_PUBLIC_API bool JS::GetFlowIdFromJSMicroTask(JS::JSMicroTask* entry,
return true;
}
-JS_PUBLIC_API JS::JSMicroTask* JS::ToUnwrappedJSMicroTask(
- const JS::GenericMicroTask& genericMicroTask) {
- if (!genericMicroTask.isObject()) {
- return nullptr;
+JS_PUBLIC_API bool JS::IsJSMicroTask(const JS::Value& hv) {
+ if (!hv.isObject()) {
+ return false;
}
- JSObject* unwrapped = UncheckedUnwrap(&genericMicroTask.toObject());
+ JSObject* unwrapped = UncheckedUnwrap(&hv.toObject());
// On the off chance someone hands us a dead wrapper.
if (JS_IsDeadWrapper(unwrapped)) {
- return nullptr;
- }
- if (!unwrapped->is<MicroTaskEntry>()) {
- return nullptr;
- }
-
- return unwrapped;
-}
-
-JS_PUBLIC_API JS::JSMicroTask* JS::ToMaybeWrappedJSMicroTask(
- const JS::GenericMicroTask& genericMicroTask) {
- if (!genericMicroTask.isObject()) {
- return nullptr;
+ return false;
}
-
- return &genericMicroTask.toObject();
-}
-
-JS_PUBLIC_API bool JS::IsJSMicroTask(const JS::GenericMicroTask& hv) {
- return JS::ToUnwrappedJSMicroTask(hv) != nullptr;
+ return unwrapped->is<MicroTaskEntry>();
}
JS::AutoDebuggerJobQueueInterruption::AutoDebuggerJobQueueInterruption()
diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp
@@ -1488,9 +1488,7 @@ static bool GlobalOfFirstJobInQueue(JSContext* cx, unsigned argc, Value* vp) {
return false;
}
- auto& genericJob = cx->microTaskQueues->microTaskQueue.front();
- JS::JSMicroTask* job = JS::ToUnwrappedJSMicroTask(genericJob);
- MOZ_ASSERT(job);
+ auto& job = cx->microTaskQueues->microTaskQueue.front();
RootedObject global(cx, JS::GetExecutionGlobalFromJSMicroTask(job));
MOZ_ASSERT(global);
if (!cx->compartment()->wrap(cx, &global)) {
diff --git a/js/src/vm/JSContext.cpp b/js/src/vm/JSContext.cpp
@@ -783,10 +783,9 @@ JSObject* InternalJobQueue::copyJobs(JSContext* cx) {
auto& queues = cx->microTaskQueues;
auto addToArray = [&](auto& queue) -> bool {
for (const auto& e : queue) {
- JS::JSMicroTask* task = JS::ToUnwrappedJSMicroTask(e);
- if (task) {
+ if (JS::GetExecutionGlobalFromJSMicroTask(e)) {
// All any test cares about is the global of the job so let's do it.
- RootedObject global(cx, JS::GetExecutionGlobalFromJSMicroTask(task));
+ RootedObject global(cx, JS::GetExecutionGlobalFromJSMicroTask(e));
if (!cx->compartment()->wrap(cx, &global)) {
return false;
}
@@ -891,8 +890,7 @@ void InternalJobQueue::runJobs(JSContext* cx) {
if (JS::Prefs::use_js_microtask_queue()) {
// Execute jobs in a loop until we've reached the end of the queue.
- JS::Rooted<JS::JSMicroTask*> job(cx);
- JS::Rooted<JS::GenericMicroTask> dequeueJob(cx);
+ JS::Rooted<JS::MicroTask> job(cx);
while (JS::HasAnyMicroTasks(cx)) {
MOZ_ASSERT(queue.empty());
// A previous job might have set this flag. E.g., the js shell
@@ -903,10 +901,8 @@ void InternalJobQueue::runJobs(JSContext* cx) {
cx->runtime()->offThreadPromiseState.ref().internalDrain(cx);
- dequeueJob = JS::DequeueNextMicroTask(cx);
- MOZ_ASSERT(!dequeueJob.isNull());
- job = JS::ToMaybeWrappedJSMicroTask(dequeueJob);
- MOZ_ASSERT(job);
+ job = JS::DequeueNextMicroTask(cx);
+ MOZ_ASSERT(!job.isNull());
// If the next job is the last job in the job queue, allow
// skipping the standard job queuing behavior.
@@ -1074,7 +1070,7 @@ void js::MicroTaskQueueElement::trace(JSTracer* trc) {
}
}
-JS::GenericMicroTask js::MicroTaskQueueSet::popDebugFront() {
+JS::MicroTask js::MicroTaskQueueSet::popDebugFront() {
JS_LOG(mtq, Info, "JS Drain Queue: popDebugFront");
if (!debugMicroTaskQueue.empty()) {
JS::Value p = debugMicroTaskQueue.front();
@@ -1084,7 +1080,7 @@ JS::GenericMicroTask js::MicroTaskQueueSet::popDebugFront() {
return JS::NullValue();
}
-JS::GenericMicroTask js::MicroTaskQueueSet::popFront() {
+JS::MicroTask js::MicroTaskQueueSet::popFront() {
JS_LOG(mtq, Info, "JS Drain Queue");
if (!debugMicroTaskQueue.empty()) {
JS::Value p = debugMicroTaskQueue.front();
@@ -1101,52 +1097,49 @@ JS::GenericMicroTask js::MicroTaskQueueSet::popFront() {
}
bool js::MicroTaskQueueSet::enqueueRegularMicroTask(
- JSContext* cx, const JS::GenericMicroTask& entry) {
+ JSContext* cx, const JS::MicroTask& entry) {
JS_LOG(mtq, Verbose, "JS: Enqueue Regular MT");
JS::JobQueueMayNotBeEmpty(cx);
return microTaskQueue.pushBack(entry);
}
bool js::MicroTaskQueueSet::prependRegularMicroTask(
- JSContext* cx, const JS::GenericMicroTask& entry) {
+ JSContext* cx, const JS::MicroTask& entry) {
JS_LOG(mtq, Verbose, "JS: Prepend Regular MT");
JS::JobQueueMayNotBeEmpty(cx);
return microTaskQueue.emplaceFront(entry);
}
-bool js::MicroTaskQueueSet::enqueueDebugMicroTask(
- JSContext* cx, const JS::GenericMicroTask& entry) {
+bool js::MicroTaskQueueSet::enqueueDebugMicroTask(JSContext* cx,
+ const JS::MicroTask& entry) {
JS_LOG(mtq, Verbose, "JS: Enqueue Debug MT");
return debugMicroTaskQueue.pushBack(entry);
}
-JS_PUBLIC_API bool JS::EnqueueMicroTask(JSContext* cx,
- const JS::GenericMicroTask& entry) {
+JS_PUBLIC_API bool JS::EnqueueMicroTask(JSContext* cx, const MicroTask& entry) {
JS_LOG(mtq, Info, "Enqueue of non JS MT");
return cx->microTaskQueues->enqueueRegularMicroTask(cx, entry);
}
-JS_PUBLIC_API bool JS::EnqueueDebugMicroTask(
- JSContext* cx, const JS::GenericMicroTask& entry) {
+JS_PUBLIC_API bool JS::EnqueueDebugMicroTask(JSContext* cx,
+ const MicroTask& entry) {
JS_LOG(mtq, Info, "Enqueue of non JS MT");
return cx->microTaskQueues->enqueueDebugMicroTask(cx, entry);
}
-JS_PUBLIC_API bool JS::PrependMicroTask(JSContext* cx,
- const JS::GenericMicroTask& entry) {
+JS_PUBLIC_API bool JS::PrependMicroTask(JSContext* cx, const MicroTask& entry) {
JS_LOG(mtq, Info, "Prepend job to MTQ");
return cx->microTaskQueues->prependRegularMicroTask(cx, entry);
}
-JS_PUBLIC_API JS::GenericMicroTask JS::DequeueNextMicroTask(JSContext* cx) {
+JS_PUBLIC_API JS::MicroTask JS::DequeueNextMicroTask(JSContext* cx) {
return cx->microTaskQueues->popFront();
}
-JS_PUBLIC_API JS::GenericMicroTask JS::DequeueNextDebuggerMicroTask(
- JSContext* cx) {
+JS_PUBLIC_API JS::MicroTask JS::DequeueNextDebuggerMicroTask(JSContext* cx) {
return cx->microTaskQueues->popDebugFront();
}
@@ -1196,11 +1189,10 @@ JS_PUBLIC_API bool JS::HasRegularMicroTasks(JSContext* cx) {
return !cx->microTaskQueues->microTaskQueue.empty();
}
-JS_PUBLIC_API JS::GenericMicroTask JS::DequeueNextRegularMicroTask(
- JSContext* cx) {
+JS_PUBLIC_API JS::MicroTask JS::DequeueNextRegularMicroTask(JSContext* cx) {
auto& queue = cx->microTaskQueues->microTaskQueue;
if (!queue.empty()) {
- JS::GenericMicroTask p = queue.front();
+ JS::MicroTask p = queue.front();
queue.popFront();
return p;
}
diff --git a/js/src/vm/JSContext.h b/js/src/vm/JSContext.h
@@ -189,12 +189,12 @@ struct MicroTaskQueueSet {
MicroTaskQueueSet(const MicroTaskQueueSet&) = delete;
MicroTaskQueueSet& operator=(const MicroTaskQueueSet&) = delete;
- bool enqueueRegularMicroTask(JSContext* cx, const JS::GenericMicroTask&);
- bool enqueueDebugMicroTask(JSContext* cx, const JS::GenericMicroTask&);
- bool prependRegularMicroTask(JSContext* cx, const JS::GenericMicroTask&);
+ bool enqueueRegularMicroTask(JSContext* cx, const JS::MicroTask&);
+ bool enqueueDebugMicroTask(JSContext* cx, const JS::MicroTask&);
+ bool prependRegularMicroTask(JSContext* cx, const JS::MicroTask&);
- JS::GenericMicroTask popFront();
- JS::GenericMicroTask popDebugFront();
+ JS::MicroTask popFront();
+ JS::MicroTask popDebugFront();
bool empty() { return microTaskQueue.empty() && debugMicroTaskQueue.empty(); }
diff --git a/xpcom/base/CycleCollectedJSContext.cpp b/xpcom/base/CycleCollectedJSContext.cpp
@@ -852,9 +852,9 @@ void CycleCollectedJSContext::AddPendingIDBTransaction(
//
// - This means runnables in the queue have their refcounts stay above zero for
// the duration of the time they are in the queue.
-JS::GenericMicroTask RunnableToMicroTask(
+JS::MicroTask RunnableToMicroTask(
already_AddRefed<MicroTaskRunnable>& aRunnable) {
- JS::GenericMicroTask v;
+ JS::MicroTask v;
auto* r = aRunnable.take();
MOZ_ASSERT(r);
v.setPrivate(r);
@@ -864,13 +864,13 @@ JS::GenericMicroTask RunnableToMicroTask(
bool EnqueueMicroTask(JSContext* aCx,
already_AddRefed<MicroTaskRunnable> aRunnable) {
MOZ_ASSERT(StaticPrefs::javascript_options_use_js_microtask_queue());
- JS::GenericMicroTask v = RunnableToMicroTask(aRunnable);
+ JS::MicroTask v = RunnableToMicroTask(aRunnable);
return JS::EnqueueMicroTask(aCx, v);
}
bool EnqueueDebugMicroTask(JSContext* aCx,
already_AddRefed<MicroTaskRunnable> aRunnable) {
MOZ_ASSERT(StaticPrefs::javascript_options_use_js_microtask_queue());
- JS::GenericMicroTask v = RunnableToMicroTask(aRunnable);
+ JS::MicroTask v = RunnableToMicroTask(aRunnable);
return JS::EnqueueDebugMicroTask(aCx, v);
}
diff --git a/xpcom/base/CycleCollectedJSContext.h b/xpcom/base/CycleCollectedJSContext.h
@@ -159,8 +159,8 @@ class MustConsumeMicroTask {
// This is a non-owning conversion: This class still owns the refcount.
MicroTaskRunnable* MaybeUnwrapTaskToRunnable() const;
- // Take ownership of a non-JS task inside a JS::GenericMicroTask - This clears
- // the contents of the value to make it clear that we've transfered ownership.
+ // Take ownership of a non-JS task inside a JS::MicroTask - This clears the
+ // contents of the value to make it clear that we've transfered ownership.
// `this` is marked is only edited if unwrapping succeeds, and so
// you can conditionally try to consume as owned;
//
@@ -196,8 +196,7 @@ class MustConsumeMicroTask {
// consuming the contents.
JSObject* GetExecutionGlobalFromJSMicroTask(JSContext* aCx) const {
MOZ_ASSERT(IsJSMicroTask());
- JS::JSMicroTask* task = JS::ToUnwrappedJSMicroTask(mMicroTask);
- MOZ_ASSERT(task);
+ JS::Rooted<JS::MicroTask> task(aCx, mMicroTask);
return JS::GetExecutionGlobalFromJSMicroTask(task);
}
@@ -207,46 +206,30 @@ class MustConsumeMicroTask {
// These are documented in MicroTask.h.
bool GetFlowIdFromJSMicroTask(uint64_t* aFlowId) {
- JS::JSMicroTask* task = JS::ToUnwrappedJSMicroTask(mMicroTask);
- MOZ_ASSERT(task);
- return JS::GetFlowIdFromJSMicroTask(task, aFlowId);
+ MOZ_ASSERT(IsJSMicroTask());
+ return JS::GetFlowIdFromJSMicroTask(mMicroTask, aFlowId);
}
JSObject* MaybeGetPromiseFromJSMicroTask() {
- JS::JSMicroTask* task = JS::ToUnwrappedJSMicroTask(mMicroTask);
- MOZ_ASSERT(task);
- return JS::MaybeGetPromiseFromJSMicroTask(task);
+ MOZ_ASSERT(IsJSMicroTask());
+ return JS::MaybeGetPromiseFromJSMicroTask(mMicroTask);
}
JSObject* MaybeGetHostDefinedDataFromJSMicroTask() {
- JS::JSMicroTask* task = JS::ToUnwrappedJSMicroTask(mMicroTask);
- if (!task) {
- return nullptr;
- }
- return JS::MaybeGetHostDefinedDataFromJSMicroTask(task);
+ return JS::MaybeGetHostDefinedDataFromJSMicroTask(mMicroTask);
}
JSObject* MaybeGetAllocationSiteFromJSMicroTask() {
- JS::JSMicroTask* task = JS::ToUnwrappedJSMicroTask(mMicroTask);
- if (!task) {
- return nullptr;
- }
- return JS::MaybeGetAllocationSiteFromJSMicroTask(task);
+ return JS::MaybeGetAllocationSiteFromJSMicroTask(mMicroTask);
}
JSObject* MaybeGetHostDefinedGlobalFromJSMicroTask() {
- JS::JSMicroTask* task = JS::ToUnwrappedJSMicroTask(mMicroTask);
- if (!task) {
- return nullptr;
- }
- return JS::MaybeGetHostDefinedGlobalFromJSMicroTask(task);
+ return JS::MaybeGetHostDefinedGlobalFromJSMicroTask(mMicroTask);
}
bool RunAndConsumeJSMicroTask(JSContext* aCx) {
- JS::Rooted<JS::JSMicroTask*> task(
- aCx, JS::ToMaybeWrappedJSMicroTask(mMicroTask));
- MOZ_ASSERT(task);
- bool v = JS::RunJSMicroTask(aCx, task);
+ JS::Rooted<JS::Value> rootedTask(aCx, mMicroTask);
+ bool v = JS::RunJSMicroTask(aCx, rootedTask);
mMicroTask.setUndefined();
return v;
}
@@ -256,10 +239,10 @@ class MustConsumeMicroTask {
}
private:
- explicit MustConsumeMicroTask(JS::GenericMicroTask&& aMicroTask)
+ explicit MustConsumeMicroTask(JS::MicroTask&& aMicroTask)
: mMicroTask(aMicroTask) {}
- JS::Heap<JS::GenericMicroTask> mMicroTask;
+ JS::Heap<JS::MicroTask> mMicroTask;
};
class SuppressedMicroTaskList final : public MicroTaskRunnable {