Backed out 7 changesets (bug 1193394) for browser-chrome failures on browser_ext_popup_background.js. CLOSED TREE

Backed out changeset 9683f24ff8ec (bug 1193394)
Backed out changeset 0e7140a7c841 (bug 1193394)
Backed out changeset a0e26f6b2784 (bug 1193394)
Backed out changeset 29e1fceaf48d (bug 1193394)
Backed out changeset b8632bbbd273 (bug 1193394)
Backed out changeset a54ef2d8f896 (bug 1193394)
Backed out changeset 55c94c05c57f (bug 1193394)
This commit is contained in:
Csoregi Natalia 2018-03-01 16:29:02 +02:00
Родитель e497c77767
Коммит 1fd0486e23
41 изменённых файлов: 443 добавлений и 287 удалений

Просмотреть файл

@ -5,7 +5,6 @@ support-files=
[browser_canvas_fingerprinting_resistance.js]
[browser_permissions.js]
skip-if = true # temporarily disabled for bug 1193394
[browser_reservedkey.js]
[browser_temporary_permissions.js]
support-files =

Просмотреть файл

@ -102,5 +102,3 @@ tags = mcb
support-files =
test_no_mcb_for_onions.html
[browser_check_identity_state.js]
skip-if = true # temporarily disabled for bug 1193394

Просмотреть файл

@ -6,20 +6,16 @@ support-files =
head.js
[browser_devices_get_user_media.js]
#skip-if = (os == "linux" && debug) # linux: bug 976544
skip-if = true # temporarily disabled for bug 1193394
skip-if = (os == "linux" && debug) # linux: bug 976544
[browser_devices_get_user_media_anim.js]
[browser_devices_get_user_media_in_frame.js]
#skip-if = debug # bug 1369731
skip-if = true # temporarily disabled for bug 1193394
skip-if = debug # bug 1369731
[browser_devices_get_user_media_multi_process.js]
skip-if = debug && (os == "win" || os == "mac") # bug 1393761
[browser_devices_get_user_media_paused.js]
[browser_devices_get_user_media_screen.js]
#skip-if = (os == "win" && ccov) # bug 1421724
skip-if = true # temporarily disabled for bug 1193394
skip-if = (os == "win" && ccov) # bug 1421724
[browser_devices_get_user_media_tear_off_tab.js]
skip-if = true # temporarily disabled for bug 1193394
[browser_devices_get_user_media_unprompted_access.js]
[browser_devices_get_user_media_unprompted_access_in_frame.js]
[browser_devices_get_user_media_unprompted_access_tear_off_tab.js]

Просмотреть файл

@ -155,7 +155,6 @@ tags = fullscreen
[browser_remove_customized_specials.js]
[browser_switch_to_customize_mode.js]
[browser_synced_tabs_menu.js]
skip-if = true # temporarily disabled for bug 1193394
[browser_backfwd_enabled_post_customize.js]
[browser_check_tooltips_in_navbar.js]
[browser_editcontrols_update.js]

Просмотреть файл

@ -48,12 +48,10 @@ skip-if = os == 'linux'
[browser_ext_browserAction_pageAction_icon.js]
[browser_ext_browserAction_pageAction_icon_permissions.js]
[browser_ext_browserAction_popup.js]
#skip-if = (debug && os == 'linux' && bits == 32) || (os == 'win' && !debug) # Bug 1313372, win: Bug 1285500
skip-if = true # temporarily disabled for bug 1193394
skip-if = (debug && os == 'linux' && bits == 32) || (os == 'win' && !debug) # Bug 1313372, win: Bug 1285500
[browser_ext_browserAction_popup_preload.js]
skip-if = (os == 'win' && !debug) # bug 1352668
[browser_ext_browserAction_popup_resize.js]
skip-if = true # temporarily disabled for bug 1193394
[browser_ext_browserAction_simple.js]
[browser_ext_browserAction_telemetry.js]
[browser_ext_browserAction_theme_icons.js]
@ -65,7 +63,6 @@ skip-if = true # temporarily disabled for bug 1193394
[browser_ext_browsingData_serviceWorkers.js]
[browser_ext_chrome_settings_overrides_home.js]
[browser_ext_commands_execute_browser_action.js]
skip-if = true # temporarily disabled for bug 1193394
[browser_ext_commands_execute_page_action.js]
[browser_ext_commands_execute_sidebar_action.js]
[browser_ext_commands_getAll.js]

Просмотреть файл

@ -12,8 +12,7 @@ skip-if = !e10s # Bug 1373549
[browser_BrowserUITelemetry_sidebar.js]
skip-if = !e10s # Bug 1373549
[browser_BrowserUITelemetry_syncedtabs.js]
#skip-if = !e10s # Bug 1373549
skip-if = true # temporarily disabled for bug 1193394
skip-if = !e10s # Bug 1373549
[browser_ContentSearch.js]
support-files =
contentSearch.js

Просмотреть файл

@ -1565,30 +1565,6 @@ Animation::GetRenderedDocument() const
return mEffect->AsKeyframeEffect()->GetRenderedDocument();
}
class AsyncFinishNotification : public MicroTaskRunnable
{
public:
explicit AsyncFinishNotification(Animation* aAnimation)
: MicroTaskRunnable()
, mAnimation(aAnimation)
{}
virtual void Run(AutoSlowOperation& aAso) override
{
mAnimation->DoFinishNotificationImmediately(this);
mAnimation = nullptr;
}
virtual bool Suppressed() override
{
nsIGlobalObject* global = mAnimation->GetOwnerGlobal();
return global && global->IsInSyncOperation();
}
private:
RefPtr<Animation> mAnimation;
};
void
Animation::DoFinishNotification(SyncNotifyFlag aSyncNotifyFlag)
{
@ -1596,8 +1572,11 @@ Animation::DoFinishNotification(SyncNotifyFlag aSyncNotifyFlag)
if (aSyncNotifyFlag == SyncNotifyFlag::Sync) {
DoFinishNotificationImmediately();
} else if (!mFinishNotificationTask) {
RefPtr<MicroTaskRunnable> runnable = new AsyncFinishNotification(this);
} else if (!mFinishNotificationTask.IsPending()) {
RefPtr<nsRunnableMethod<Animation>> runnable =
NewRunnableMethod("dom::Animation::DoFinishNotificationImmediately",
this,
&Animation::DoFinishNotificationImmediately);
context->DispatchToMicroTask(do_AddRef(runnable));
mFinishNotificationTask = runnable.forget();
}
@ -1620,13 +1599,9 @@ Animation::MaybeResolveFinishedPromise()
}
void
Animation::DoFinishNotificationImmediately(MicroTaskRunnable* aAsync)
Animation::DoFinishNotificationImmediately()
{
if (aAsync && aAsync != mFinishNotificationTask) {
return;
}
mFinishNotificationTask = nullptr;
mFinishNotificationTask.Revoke();
if (PlayState() != AnimationPlayState::Finished) {
return;

Просмотреть файл

@ -11,7 +11,6 @@
#include "nsCycleCollectionParticipant.h"
#include "mozilla/AnimationPerformanceWarning.h"
#include "mozilla/Attributes.h"
#include "mozilla/CycleCollectedJSContext.h"
#include "mozilla/DOMEventTargetHelper.h"
#include "mozilla/EffectCompositor.h" // For EffectCompositor::CascadeLevel
#include "mozilla/LinkedList.h"
@ -45,7 +44,6 @@ struct AnimationRule;
namespace dom {
class AsyncFinishNotification;
class CSSAnimation;
class CSSTransition;
@ -451,8 +449,7 @@ protected:
void ResetFinishedPromise();
void MaybeResolveFinishedPromise();
void DoFinishNotification(SyncNotifyFlag aSyncNotifyFlag);
friend class AsyncFinishNotification;
void DoFinishNotificationImmediately(MicroTaskRunnable* aAsync = nullptr);
void DoFinishNotificationImmediately();
void DispatchPlaybackEvent(const nsAString& aName);
/**
@ -545,7 +542,7 @@ protected:
// getAnimations() list.
bool mIsRelevant;
RefPtr<MicroTaskRunnable> mFinishNotificationTask;
nsRevocableEventPtr<nsRunnableMethod<Animation>> mFinishNotificationTask;
// True if mFinished is resolved or would be resolved if mFinished has
// yet to be created. This is not set when mFinished is rejected since
// in that case mFinished is immediately reset to represent a new current

Просмотреть файл

@ -7,6 +7,7 @@
#include "DocumentTimeline.h"
#include "mozilla/ScopeExit.h"
#include "mozilla/dom/DocumentTimelineBinding.h"
#include "mozilla/dom/Promise.h"
#include "AnimationUtils.h"
#include "nsContentUtils.h"
#include "nsDOMMutationObserver.h"
@ -159,11 +160,14 @@ DocumentTimeline::WillRefresh(mozilla::TimeStamp aTime)
// https://drafts.csswg.org/web-animations-1/#update-animations-and-send-events,
// step2.
// FIXME: This needs to be replaced with nsAutoMicroTask.
// Note that this should be done before nsAutoAnimationMutationBatch. If
// PerformMicroTaskCheckpoint was called before nsAutoAnimationMutationBatch
// is destroyed, some mutation records might not be delivered in this
// checkpoint.
nsAutoMicroTask mt;
auto autoPerformMicrotaskCheckpoint = MakeScopeExit([] {
Promise::PerformMicroTaskCheckpoint();
});
nsAutoAnimationMutationBatch mb(mDocument);
for (Animation* animation = mAnimationOrder.getFirst(); animation;

Просмотреть файл

@ -1067,7 +1067,7 @@ CustomElementReactionsStack::Enqueue(Element* aElement,
CycleCollectedJSContext* context = CycleCollectedJSContext::Get();
RefPtr<BackupQueueMicroTask> bqmt = new BackupQueueMicroTask(this);
context->DispatchToMicroTask(bqmt.forget());
context->DispatchMicroTaskRunnable(bqmt.forget());
}
void

Просмотреть файл

@ -5871,10 +5871,10 @@ nsContentUtils::RunInStableState(already_AddRefed<nsIRunnable> aRunnable)
/* static */
void
nsContentUtils::AddPendingIDBTransaction(already_AddRefed<nsIRunnable> aTransaction)
nsContentUtils::RunInMetastableState(already_AddRefed<nsIRunnable> aRunnable)
{
MOZ_ASSERT(CycleCollectedJSContext::Get(), "Must be on a script thread!");
CycleCollectedJSContext::Get()->AddPendingIDBTransaction(Move(aTransaction));
CycleCollectedJSContext::Get()->RunInMetastableState(Move(aRunnable));
}
/* static */
@ -6933,16 +6933,9 @@ nsContentUtils::IsSubDocumentTabbable(nsIContent* aContent)
contentViewer->GetPreviousViewer(getter_AddRefs(zombieViewer));
// If there are 2 viewers for the current docshell, that
// means the current document may be a zombie document.
// While load and pageshow events are dispatched, zombie viewer is the old,
// to be hidden document.
if (zombieViewer) {
bool inOnLoad = false;
docShell->GetIsExecutingOnLoadHandler(&inOnLoad);
return inOnLoad;
}
return true;
// means the current document is a zombie document.
// Only navigate into the subdocument if it's not a zombie.
return !zombieViewer;
}
bool

Просмотреть файл

@ -2031,12 +2031,17 @@ public:
*/
static void RunInStableState(already_AddRefed<nsIRunnable> aRunnable);
/* Add a pending IDBTransaction to be cleaned up at the end of performing a
* microtask checkpoint.
* See the step of "Cleanup Indexed Database Transactions" in
* https://html.spec.whatwg.org/multipage/webappapis.html#perform-a-microtask-checkpoint
/* Add a "synchronous section", in the form of an nsIRunnable run once the
* event loop has reached a "metastable state". |aRunnable| must not cause any
* queued events to be processed (i.e. must not spin the event loop).
* We've reached a metastable state when the currently executing task or
* microtask has finished. This is not specced at this time.
* In practice this runs aRunnable once the currently executing task or
* microtask finishes. If called multiple times per microtask, all the
* runnables will be executed, in the order in which RunInMetastableState()
* was called
*/
static void AddPendingIDBTransaction(already_AddRefed<nsIRunnable> aTransaction);
static void RunInMetastableState(already_AddRefed<nsIRunnable> aRunnable);
/**
* Returns true if we are doing StableState/MetastableState.

Просмотреть файл

@ -620,7 +620,7 @@ nsDOMMutationObserver::QueueMutationObserverMicroTask()
RefPtr<MutationObserverMicroTask> momt =
new MutationObserverMicroTask();
ccjs->DispatchToMicroTask(momt.forget());
ccjs->DispatchMicroTaskRunnable(momt.forget());
}
void
@ -643,7 +643,7 @@ nsDOMMutationObserver::RescheduleForRun()
RefPtr<MutationObserverMicroTask> momt =
new MutationObserverMicroTask();
ccjs->DispatchToMicroTask(momt.forget());
ccjs->DispatchMicroTaskRunnable(momt.forget());
sScheduledMutationObservers = new AutoTArray<RefPtr<nsDOMMutationObserver>, 4>;
}

Просмотреть файл

@ -6715,6 +6715,12 @@ nsGlobalWindowInner::RunTimeoutHandler(Timeout* aTimeout,
// point anyway, and the script context should have already reported
// the script error in the usual way - so we just drop it.
// Since we might be processing more timeouts, go ahead and flush the promise
// queue now before we do that. We need to do that while we're still in our
// "running JS is safe" state (e.g. mRunningTimeout is set, timeout->mRunning
// is false).
Promise::PerformMicroTaskCheckpoint();
if (trackNestingLevel) {
TimeoutManager::SetNestingLevel(nestingLevel);
}

Просмотреть файл

@ -140,9 +140,11 @@ CallbackObject::CallSetup::CallSetup(CallbackObject* aCallback,
, mExceptionHandling(aExceptionHandling)
, mIsMainThread(NS_IsMainThread())
{
CycleCollectedJSContext* ccjs = CycleCollectedJSContext::Get();
if (ccjs) {
ccjs->EnterMicroTask();
if (mIsMainThread) {
CycleCollectedJSContext* ccjs = CycleCollectedJSContext::Get();
if (ccjs) {
ccjs->EnterMicroTask();
}
}
// Compute the caller's subject principal (if necessary) early, before we
@ -349,9 +351,11 @@ CallbackObject::CallSetup::~CallSetup()
// It is important that this is the last thing we do, after leaving the
// compartment and undoing all our entry/incumbent script changes
CycleCollectedJSContext* ccjs = CycleCollectedJSContext::Get();
if (ccjs) {
ccjs->LeaveMicroTask();
if (mIsMainThread) {
CycleCollectedJSContext* ccjs = CycleCollectedJSContext::Get();
if (ccjs) {
ccjs->LeaveMicroTask();
}
}
}

Просмотреть файл

@ -1095,8 +1095,12 @@ EventListenerManager::HandleEventSubType(Listener* aListener,
}
if (NS_SUCCEEDED(result)) {
nsAutoMicroTask mt;
if (mIsMainThreadELM) {
CycleCollectedJSContext* ccjs = CycleCollectedJSContext::Get();
if (ccjs) {
ccjs->EnterMicroTask();
}
}
// nsIDOMEvent::currentTarget is set in EventDispatcher.
if (listenerHolder.HasWebIDLCallback()) {
ErrorResult rv;
@ -1106,6 +1110,12 @@ EventListenerManager::HandleEventSubType(Listener* aListener,
} else {
result = listenerHolder.GetXPCOMCallback()->HandleEvent(aDOMEvent);
}
if (mIsMainThreadELM) {
CycleCollectedJSContext* ccjs = CycleCollectedJSContext::Get();
if (ccjs) {
ccjs->LeaveMicroTask();
}
}
}
return result;

Просмотреть файл

@ -849,26 +849,22 @@ DispatchSuccessEvent(ResultHelper* aResultHelper,
IDB_LOG_STRINGIFY(aEvent, kSuccessEventType));
}
MOZ_ASSERT_IF(transaction,
transaction->IsOpen() && !transaction->IsAborted());
bool dummy;
nsresult rv = request->DispatchEvent(aEvent, &dummy);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
MOZ_ASSERT_IF(transaction,
transaction->IsOpen() || transaction->IsAborted());
WidgetEvent* internalEvent = aEvent->WidgetEventPtr();
MOZ_ASSERT(internalEvent);
if (transaction &&
transaction->IsOpen()) {
if (internalEvent->mFlags.mExceptionWasRaised) {
transaction->Abort(NS_ERROR_DOM_INDEXEDDB_ABORT_ERR);
} else {
// To handle upgrade transaction.
transaction->Run();
}
transaction->IsOpen() &&
internalEvent->mFlags.mExceptionWasRaised) {
transaction->Abort(NS_ERROR_DOM_INDEXEDDB_ABORT_ERR);
}
}

Просмотреть файл

@ -99,7 +99,7 @@ IDBFileHandle::Create(IDBMutableFile* aMutableFile,
MOZ_ASSERT(NS_IsMainThread(), "This won't work on non-main threads!");
nsCOMPtr<nsIRunnable> runnable = do_QueryObject(fileHandle);
nsContentUtils::AddPendingIDBTransaction(runnable.forget());
nsContentUtils::RunInMetastableState(runnable.forget());
fileHandle->mCreating = true;

Просмотреть файл

@ -192,11 +192,15 @@ IDBTransaction::CreateVersionChange(
transaction->SetScriptOwner(aDatabase->GetScriptOwner());
nsCOMPtr<nsIRunnable> runnable = do_QueryObject(transaction);
nsContentUtils::RunInMetastableState(runnable.forget());
transaction->NoteActiveTransaction();
transaction->mBackgroundActor.mVersionChangeBackgroundActor = aActor;
transaction->mNextObjectStoreId = aNextObjectStoreId;
transaction->mNextIndexId = aNextIndexId;
transaction->mCreating = true;
aDatabase->RegisterTransaction(transaction);
transaction->mRegistered = true;
@ -246,7 +250,7 @@ IDBTransaction::Create(JSContext* aCx, IDBDatabase* aDatabase,
}
nsCOMPtr<nsIRunnable> runnable = do_QueryObject(transaction);
nsContentUtils::AddPendingIDBTransaction(runnable.forget());
nsContentUtils::RunInMetastableState(runnable.forget());
transaction->mCreating = true;

Просмотреть файл

@ -510,6 +510,126 @@ Promise::ReportRejectedPromise(JSContext* aCx, JS::HandleObject aPromise)
}
}
bool
Promise::PerformMicroTaskCheckpoint()
{
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
CycleCollectedJSContext* context = CycleCollectedJSContext::Get();
// On the main thread, we always use the main promise micro task queue.
std::queue<nsCOMPtr<nsIRunnable>>& microtaskQueue =
context->GetPromiseMicroTaskQueue();
if (microtaskQueue.empty()) {
return false;
}
AutoSlowOperation aso;
do {
nsCOMPtr<nsIRunnable> runnable = microtaskQueue.front().forget();
MOZ_ASSERT(runnable);
// This function can re-enter, so we remove the element before calling.
microtaskQueue.pop();
nsresult rv = runnable->Run();
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
}
aso.CheckForInterrupt();
context->AfterProcessMicrotask();
} while (!microtaskQueue.empty());
return true;
}
bool
Promise::IsWorkerDebuggerMicroTaskEmpty()
{
MOZ_ASSERT(!NS_IsMainThread(), "Wrong thread!");
CycleCollectedJSContext* context = CycleCollectedJSContext::Get();
if (!context) {
return true;
}
std::queue<nsCOMPtr<nsIRunnable>>* microtaskQueue =
&context->GetDebuggerPromiseMicroTaskQueue();
return microtaskQueue->empty();
}
void
Promise::PerformWorkerMicroTaskCheckpoint()
{
MOZ_ASSERT(!NS_IsMainThread(), "Wrong thread!");
CycleCollectedJSContext* context = CycleCollectedJSContext::Get();
if (!context) {
return;
}
for (;;) {
// For a normal microtask checkpoint, we try to use the debugger microtask
// queue first. If the debugger queue is empty, we use the normal microtask
// queue instead.
std::queue<nsCOMPtr<nsIRunnable>>* microtaskQueue =
&context->GetDebuggerPromiseMicroTaskQueue();
if (microtaskQueue->empty()) {
microtaskQueue = &context->GetPromiseMicroTaskQueue();
if (microtaskQueue->empty()) {
break;
}
}
nsCOMPtr<nsIRunnable> runnable = microtaskQueue->front().forget();
MOZ_ASSERT(runnable);
// This function can re-enter, so we remove the element before calling.
microtaskQueue->pop();
nsresult rv = runnable->Run();
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
context->AfterProcessMicrotask();
}
}
void
Promise::PerformWorkerDebuggerMicroTaskCheckpoint()
{
MOZ_ASSERT(!NS_IsMainThread(), "Wrong thread!");
CycleCollectedJSContext* context = CycleCollectedJSContext::Get();
if (!context) {
return;
}
for (;;) {
// For a debugger microtask checkpoint, we always use the debugger microtask
// queue.
std::queue<nsCOMPtr<nsIRunnable>>* microtaskQueue =
&context->GetDebuggerPromiseMicroTaskQueue();
if (microtaskQueue->empty()) {
break;
}
nsCOMPtr<nsIRunnable> runnable = microtaskQueue->front().forget();
MOZ_ASSERT(runnable);
// This function can re-enter, so we remove the element before calling.
microtaskQueue->pop();
nsresult rv = runnable->Run();
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
context->AfterProcessMicrotask();
}
}
JSObject*
Promise::GlobalJSObject() const
{

Просмотреть файл

@ -104,6 +104,15 @@ public:
// specializations in the .cpp for
// the T values we support.
// Called by DOM to let us execute our callbacks. May be called recursively.
// Returns true if at least one microtask was processed.
static bool PerformMicroTaskCheckpoint();
static void PerformWorkerMicroTaskCheckpoint();
static void PerformWorkerDebuggerMicroTaskCheckpoint();
static bool IsWorkerDebuggerMicroTaskEmpty();
// WebIDL
nsIGlobalObject* GetParentObject() const

Просмотреть файл

@ -186,7 +186,7 @@ function promiseAsync_SyncXHR()
xhr.open("GET", "testXHR.txt", false);
xhr.send(null);
ok(!handlerExecuted, "Sync XHR should not trigger microtask execution.");
todo(!handlerExecuted, "Sync XHR should not trigger microtask execution.");
}
function promiseDoubleThen() {

Просмотреть файл

@ -830,6 +830,8 @@ AutoSafeJSContext::AutoSafeJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMP
AutoSlowOperation::AutoSlowOperation(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMPL)
: AutoJSAPI()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
Init();
@ -838,12 +840,9 @@ AutoSlowOperation::AutoSlowOperation(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMP
void
AutoSlowOperation::CheckForInterrupt()
{
// For now we support only main thread!
if (mIsMainThread) {
// JS_CheckForInterrupt expects us to be in a compartment.
JSAutoCompartment ac(cx(), xpc::UnprivilegedJunkScope());
JS_CheckForInterrupt(cx());
}
// JS_CheckForInterrupt expects us to be in a compartment.
JSAutoCompartment ac(cx(), xpc::UnprivilegedJunkScope());
JS_CheckForInterrupt(cx());
}
} // namespace mozilla

Просмотреть файл

@ -293,6 +293,7 @@ protected:
// AutoJSAPI, so Init must NOT be called on subclasses that use this.
AutoJSAPI(nsIGlobalObject* aGlobalObject, bool aIsMainThread, Type aType);
private:
mozilla::Maybe<JSAutoRequest> mAutoRequest;
mozilla::Maybe<JSAutoNullableCompartment> mAutoNullableCompartment;
JSContext *mCx;
@ -301,7 +302,6 @@ protected:
bool mIsMainThread;
Maybe<JS::WarningReporter> mOldWarningReporter;
private:
void InitInternal(nsIGlobalObject* aGlobalObject, JSObject* aGlobal,
JSContext* aCx, bool aIsMainThread);

Просмотреть файл

@ -333,7 +333,7 @@ public:
MOZ_ASSERT(mWorkerPrivate);
mWorkerPrivate->AssertIsOnWorkerThread();
if (mPendingPromisesCount || !mKeepAliveToken) {
if (mPendingPromisesCount) {
return;
}
if (mCallback) {
@ -365,18 +365,6 @@ private:
mSelfRef = nullptr;
}
class MaybeDoneRunner : public MicroTaskRunnable
{
public:
explicit MaybeDoneRunner(KeepAliveHandler* aHandler) : mHandler(aHandler) {}
virtual void Run(AutoSlowOperation& aAso) override
{
mHandler->MaybeDone();
}
RefPtr<KeepAliveHandler> mHandler;
};
void
RemovePromise(ExtendableEventResult aResult)
{
@ -400,7 +388,10 @@ private:
CycleCollectedJSContext* cx = CycleCollectedJSContext::Get();
MOZ_ASSERT(cx);
RefPtr<MaybeDoneRunner> r = new MaybeDoneRunner(this);
RefPtr<nsIRunnable> r =
NewRunnableMethod("dom::KeepAliveHandler::MaybeDone",
this,
&KeepAliveHandler::MaybeDone);
cx->DispatchToMicroTask(r.forget());
}
};

Просмотреть файл

@ -1052,10 +1052,6 @@ public:
{
MOZ_COUNT_CTOR_INHERITED(WorkerJSContext, CycleCollectedJSContext);
MOZ_ASSERT(aWorkerPrivate);
// Magical number 2. Workers have the base recursion depth 1, and normal
// runnables run at level 2, and we don't want to process microtasks
// at any other level.
SetTargetedMicroTaskRecursionDepth(2);
}
~WorkerJSContext()
@ -1109,14 +1105,26 @@ public:
return NS_OK;
}
virtual void DispatchToMicroTask(already_AddRefed<MicroTaskRunnable> aRunnable) override
virtual void AfterProcessTask(uint32_t aRecursionDepth) override
{
RefPtr<MicroTaskRunnable> runnable(aRunnable);
// Only perform the Promise microtask checkpoint on the outermost event
// loop. Don't run it, for example, during sync XHR or importScripts.
if (aRecursionDepth == 2) {
CycleCollectedJSContext::AfterProcessTask(aRecursionDepth);
} else if (aRecursionDepth > 2) {
AutoDisableMicroTaskCheckpoint disableMicroTaskCheckpoint;
CycleCollectedJSContext::AfterProcessTask(aRecursionDepth);
}
}
virtual void DispatchToMicroTask(already_AddRefed<nsIRunnable> aRunnable) override
{
RefPtr<nsIRunnable> runnable(aRunnable);
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(runnable);
std::queue<RefPtr<MicroTaskRunnable>>* microTaskQueue = nullptr;
std::queue<nsCOMPtr<nsIRunnable>>* microTaskQueue = nullptr;
JSContext* cx = GetCurrentWorkerThreadJSContext();
NS_ASSERTION(cx, "This should never be null!");
@ -1125,16 +1133,16 @@ public:
NS_ASSERTION(global, "This should never be null!");
// On worker threads, if the current global is the worker global, we use the
// main micro task queue. Otherwise, the current global must be
// main promise micro task queue. Otherwise, the current global must be
// either the debugger global or a debugger sandbox, and we use the debugger
// micro task queue instead.
// promise micro task queue instead.
if (IsWorkerGlobal(global)) {
microTaskQueue = &GetMicroTaskQueue();
microTaskQueue = &mPromiseMicroTaskQueue;
} else {
MOZ_ASSERT(IsWorkerDebuggerGlobal(global) ||
IsWorkerDebuggerSandbox(global));
microTaskQueue = &GetDebuggerMicroTaskQueue();
microTaskQueue = &mDebuggerPromiseMicroTaskQueue;
}
microTaskQueue->push(runnable.forget());

Просмотреть файл

@ -3259,10 +3259,8 @@ WorkerPrivate::DoRunLoop(JSContext* aCx)
static_cast<nsIRunnable*>(runnable)->Run();
runnable->Release();
CycleCollectedJSContext* ccjs = CycleCollectedJSContext::Get();
if (ccjs) {
ccjs->PerformDebuggerMicroTaskCheckpoint();
}
// Flush the promise queue.
Promise::PerformWorkerDebuggerMicroTaskCheckpoint();
if (debuggerRunnablesPending) {
WorkerDebuggerGlobalScope* globalScope = DebuggerGlobalScope();
@ -4346,12 +4344,9 @@ WorkerPrivate::EnterDebuggerEventLoop()
{
MutexAutoLock lock(mMutex);
CycleCollectedJSContext* context = CycleCollectedJSContext::Get();
std::queue<RefPtr<MicroTaskRunnable>>& debuggerMtQueue =
context->GetDebuggerMicroTaskQueue();
while (mControlQueue.IsEmpty() &&
!(debuggerRunnablesPending = !mDebuggerQueue.IsEmpty()) &&
debuggerMtQueue.empty()) {
Promise::IsWorkerDebuggerMicroTaskEmpty()) {
WaitForWorkerEvents();
}
@ -4359,9 +4354,8 @@ WorkerPrivate::EnterDebuggerEventLoop()
// XXXkhuey should we abort JS on the stack here if we got Abort above?
}
CycleCollectedJSContext* context = CycleCollectedJSContext::Get();
if (context) {
context->PerformDebuggerMicroTaskCheckpoint();
if (!Promise::IsWorkerDebuggerMicroTaskEmpty()) {
Promise::PerformWorkerDebuggerMicroTaskCheckpoint();
}
if (debuggerRunnablesPending) {
// Start the periodic GC timer if it is not already running.
@ -4379,10 +4373,8 @@ WorkerPrivate::EnterDebuggerEventLoop()
static_cast<nsIRunnable*>(runnable)->Run();
runnable->Release();
CycleCollectedJSContext* ccjs = CycleCollectedJSContext::Get();
if (ccjs) {
ccjs->PerformDebuggerMicroTaskCheckpoint();
}
// Flush the promise queue.
Promise::PerformWorkerDebuggerMicroTaskCheckpoint();
// Now *might* be a good time to GC. Let the JS engine make the decision.
if (JS::CurrentGlobalOrNull(cx)) {
@ -4747,8 +4739,8 @@ WorkerPrivate::RunExpiredTimeouts(JSContext* aCx)
RefPtr<Function> callback = info->mHandler->GetCallback();
if (!callback) {
nsAutoMicroTask mt;
// scope for the AutoEntryScript, so it comes off the stack before we do
// Promise::PerformMicroTaskCheckpoint.
AutoEntryScript aes(global, reason, false);
// Evaluate the timeout expression.
@ -4783,6 +4775,10 @@ WorkerPrivate::RunExpiredTimeouts(JSContext* aCx)
rv.SuppressException();
}
// Since we might be processing more timeouts, go ahead and flush
// the promise queue now before we do that.
Promise::PerformWorkerMicroTaskCheckpoint();
NS_ASSERTION(mRunningExpiredTimeouts, "Someone changed this!");
}

Просмотреть файл

@ -1219,6 +1219,21 @@ XPCJSContext::BeforeProcessTask(bool aMightBlock)
{
MOZ_ASSERT(NS_IsMainThread());
// If ProcessNextEvent was called during a Promise "then" callback, we
// must process any pending microtasks before blocking in the event loop,
// otherwise we may deadlock until an event enters the queue later.
if (aMightBlock) {
if (Promise::PerformMicroTaskCheckpoint()) {
// If any microtask was processed, we post a dummy event in order to
// force the ProcessNextEvent call not to block. This is required
// to support nested event loops implemented using a pattern like
// "while (condition) thread.processNextEvent(true)", in case the
// condition is triggered here by a Promise "then" callback.
NS_DispatchToMainThread(new Runnable("Empty_microtask_runnable"));
}
}
// Start the slow script timer.
mSlowScriptCheckpoint = mozilla::TimeStamp::NowLoRes();
mSlowScriptSecondHalf = false;

Просмотреть файл

@ -0,0 +1,13 @@
[event-dispatch-active-flag.html]
[Transactions are active during success handlers]
expected: FAIL
[Transactions are active during success listeners]
expected: FAIL
[Transactions are active during error handlers]
expected: FAIL
[Transactions are active during error listeners]
expected: FAIL

Просмотреть файл

@ -0,0 +1,10 @@
[transaction-deactivation-timing.html]
[New transactions are not deactivated until after the microtask checkpoint]
expected: FAIL
[New transactions from microtask are still active through the microtask checkpoint]
expected: FAIL
[Deactivation of new transactions happens at end of invocation]
expected: FAIL

Просмотреть файл

@ -0,0 +1,4 @@
[upgrade-transaction-deactivation-timing.html]
[Upgrade transactions are active in upgradeneeded callback and microtasks]
expected: FAIL

Просмотреть файл

@ -0,0 +1,4 @@
[upgrade-transaction-lifecycle-user-aborted.html]
[in a promise microtask after abort() is called, before the transaction abort event is fired]
expected: FAIL

Просмотреть файл

@ -0,0 +1,13 @@
[microtasks-and-constructors.html]
[Microtasks evaluate immediately when the stack is empty inside the parser]
expected: FAIL
[Microtasks evaluate afterward when the stack is not empty using createElement()]
expected: FAIL
[Microtasks evaluate afterward when the stack is not empty using the constructor]
expected: FAIL
[Microtasks evaluate afterward when the stack is not empty due to upgrades]
expected: FAIL

Просмотреть файл

@ -0,0 +1,4 @@
[task_microtask_ordering.html]
[Level 1 bossfight (synthetic click)]
expected: FAIL

Просмотреть файл

@ -1,4 +0,0 @@
[extendable-event-async-waituntil.https.html]
type: testharness
[Test calling waitUntil in a different microtask without an existing extension throws]
expected: FAIL

Просмотреть файл

@ -0,0 +1,3 @@
[basic.html]
expected:
if e10s and (os == "mac") and (version == "OS X 10.10.5") and (processor == "x86_64") and (bits == 64): FAIL

Просмотреть файл

@ -0,0 +1,3 @@
[bidi_ruby.html]
expected:
if e10s and (os == "mac") and (version == "OS X 10.10.5") and (processor == "x86_64") and (bits == 64): FAIL

Просмотреть файл

@ -0,0 +1,3 @@
[u0041_first.html]
expected:
if e10s and (os == "mac") and (version == "OS X 10.10.5") and (processor == "x86_64") and (bits == 64): FAIL

Просмотреть файл

@ -0,0 +1,3 @@
[u06E9_no_strong_dir.html]
expected:
if os == "mac": FAIL

Просмотреть файл

@ -52,7 +52,7 @@ CycleCollectedJSContext::CycleCollectedJSContext()
, mRuntime(nullptr)
, mJSContext(nullptr)
, mDoingStableStates(false)
, mTargetedMicroTaskRecursionDepth(0)
, mDisableMicroTaskCheckpoint(false)
, mMicroTaskLevel(0)
, mMicroTaskRecursionDepth(0)
{
@ -77,8 +77,8 @@ CycleCollectedJSContext::~CycleCollectedJSContext()
}
// Last chance to process any events.
CleanupIDBTransactions(mBaseRecursionDepth);
MOZ_ASSERT(mPendingIDBTransactions.IsEmpty());
ProcessMetastableStateQueue(mBaseRecursionDepth);
MOZ_ASSERT(mMetastableStateEvents.IsEmpty());
ProcessStableStateQueue();
MOZ_ASSERT(mStableStateEvents.IsEmpty());
@ -86,8 +86,8 @@ CycleCollectedJSContext::~CycleCollectedJSContext()
// Clear mPendingException first, since it might be cycle collected.
mPendingException = nullptr;
MOZ_ASSERT(mDebuggerMicroTaskQueue.empty());
MOZ_ASSERT(mPendingMicroTaskRunnables.empty());
MOZ_ASSERT(mDebuggerPromiseMicroTaskQueue.empty());
MOZ_ASSERT(mPromiseMicroTaskQueue.empty());
mUncaughtRejections.reset();
mConsumedRejections.reset();
@ -181,14 +181,15 @@ CycleCollectedJSContext::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
return 0;
}
class PromiseJobRunnable final : public MicroTaskRunnable
class PromiseJobRunnable final : public Runnable
{
public:
PromiseJobRunnable(JS::HandleObject aCallback,
JS::HandleObject aAllocationSite,
nsIGlobalObject* aIncumbentGlobal)
:mCallback(
new PromiseJobCallback(aCallback, aAllocationSite, aIncumbentGlobal))
: Runnable("PromiseJobRunnable")
, mCallback(
new PromiseJobCallback(aCallback, aAllocationSite, aIncumbentGlobal))
{
}
@ -197,21 +198,15 @@ public:
}
protected:
virtual void Run(AutoSlowOperation& aAso) override
NS_IMETHOD
Run() override
{
JSObject* callback = mCallback->CallbackPreserveColor();
nsIGlobalObject* global = callback ? xpc::NativeGlobal(callback) : nullptr;
if (global && !global->IsDying()) {
mCallback->Call("promise callback");
aAso.CheckForInterrupt();
}
}
virtual bool Suppressed() override
{
nsIGlobalObject* global =
xpc::NativeGlobal(mCallback->CallbackPreserveColor());
return global && global->IsInSyncOperation();
return NS_OK;
}
private:
@ -245,7 +240,7 @@ CycleCollectedJSContext::EnqueuePromiseJobCallback(JSContext* aCx,
if (aIncumbentGlobal) {
global = xpc::NativeGlobal(aIncumbentGlobal);
}
RefPtr<MicroTaskRunnable> runnable = new PromiseJobRunnable(aJob, aAllocationSite, global);
nsCOMPtr<nsIRunnable> runnable = new PromiseJobRunnable(aJob, aAllocationSite, global);
self->DispatchToMicroTask(runnable.forget());
return true;
}
@ -286,18 +281,18 @@ CycleCollectedJSContext::SetPendingException(Exception* aException)
mPendingException = aException;
}
std::queue<RefPtr<MicroTaskRunnable>>&
CycleCollectedJSContext::GetMicroTaskQueue()
std::queue<nsCOMPtr<nsIRunnable>>&
CycleCollectedJSContext::GetPromiseMicroTaskQueue()
{
MOZ_ASSERT(mJSContext);
return mPendingMicroTaskRunnables;
return mPromiseMicroTaskQueue;
}
std::queue<RefPtr<MicroTaskRunnable>>&
CycleCollectedJSContext::GetDebuggerMicroTaskQueue()
std::queue<nsCOMPtr<nsIRunnable>>&
CycleCollectedJSContext::GetDebuggerPromiseMicroTaskQueue()
{
MOZ_ASSERT(mJSContext);
return mDebuggerMicroTaskQueue;
return mDebuggerPromiseMicroTaskQueue;
}
void
@ -317,24 +312,24 @@ CycleCollectedJSContext::ProcessStableStateQueue()
}
void
CycleCollectedJSContext::CleanupIDBTransactions(uint32_t aRecursionDepth)
CycleCollectedJSContext::ProcessMetastableStateQueue(uint32_t aRecursionDepth)
{
MOZ_ASSERT(mJSContext);
MOZ_RELEASE_ASSERT(!mDoingStableStates);
mDoingStableStates = true;
nsTArray<PendingIDBTransactionData> localQueue = Move(mPendingIDBTransactions);
nsTArray<RunInMetastableStateData> localQueue = Move(mMetastableStateEvents);
for (uint32_t i = 0; i < localQueue.Length(); ++i)
{
PendingIDBTransactionData& data = localQueue[i];
RunInMetastableStateData& data = localQueue[i];
if (data.mRecursionDepth != aRecursionDepth) {
continue;
}
{
nsCOMPtr<nsIRunnable> transaction = data.mTransaction.forget();
transaction->Run();
nsCOMPtr<nsIRunnable> runnable = data.mRunnable.forget();
runnable->Run();
}
localQueue.RemoveElementAt(i--);
@ -342,27 +337,11 @@ CycleCollectedJSContext::CleanupIDBTransactions(uint32_t aRecursionDepth)
// If the queue has events in it now, they were added from something we called,
// so they belong at the end of the queue.
localQueue.AppendElements(mPendingIDBTransactions);
localQueue.SwapElements(mPendingIDBTransactions);
localQueue.AppendElements(mMetastableStateEvents);
localQueue.SwapElements(mMetastableStateEvents);
mDoingStableStates = false;
}
void
CycleCollectedJSContext::BeforeProcessTask(bool aMightBlock)
{
// If ProcessNextEvent was called during a microtask callback, we
// must process any pending microtasks before blocking in the event loop,
// otherwise we may deadlock until an event enters the queue later.
if (aMightBlock && PerformMicroTaskCheckPoint()) {
// If any microtask was processed, we post a dummy event in order to
// force the ProcessNextEvent call not to block. This is required
// to support nested event loops implemented using a pattern like
// "while (condition) thread.processNextEvent(true)", in case the
// condition is triggered here by a Promise "then" callback.
NS_DispatchToMainThread(new Runnable("BeforeProcessTask"));
}
}
void
CycleCollectedJSContext::AfterProcessTask(uint32_t aRecursionDepth)
{
@ -370,8 +349,19 @@ CycleCollectedJSContext::AfterProcessTask(uint32_t aRecursionDepth)
// See HTML 6.1.4.2 Processing model
// Execute any events that were waiting for a microtask to complete.
// This is not (yet) in the spec.
ProcessMetastableStateQueue(aRecursionDepth);
// Step 4.1: Execute microtasks.
PerformMicroTaskCheckPoint();
if (!mDisableMicroTaskCheckpoint) {
PerformMicroTaskCheckPoint();
if (NS_IsMainThread()) {
Promise::PerformMicroTaskCheckpoint();
} else {
Promise::PerformWorkerMicroTaskCheckpoint();
}
}
// Step 4.2 Execute any events that were waiting for a stable state.
ProcessStableStateQueue();
@ -381,12 +371,10 @@ CycleCollectedJSContext::AfterProcessTask(uint32_t aRecursionDepth)
}
void
CycleCollectedJSContext::AfterProcessMicrotasks()
CycleCollectedJSContext::AfterProcessMicrotask()
{
MOZ_ASSERT(mJSContext);
// Cleanup Indexed Database transactions:
// https://html.spec.whatwg.org/multipage/webappapis.html#perform-a-microtask-checkpoint
CleanupIDBTransactions(RecursionDepth());
AfterProcessMicrotask(RecursionDepth());
}
void CycleCollectedJSContext::IsIdleGCTaskNeeded()
@ -419,6 +407,16 @@ void CycleCollectedJSContext::IsIdleGCTaskNeeded()
}
}
void
CycleCollectedJSContext::AfterProcessMicrotask(uint32_t aRecursionDepth)
{
MOZ_ASSERT(mJSContext);
// Between microtasks, execute any events that were waiting for a microtask
// to complete.
ProcessMetastableStateQueue(aRecursionDepth);
}
uint32_t
CycleCollectedJSContext::RecursionDepth()
{
@ -433,12 +431,12 @@ CycleCollectedJSContext::RunInStableState(already_AddRefed<nsIRunnable>&& aRunna
}
void
CycleCollectedJSContext::AddPendingIDBTransaction(already_AddRefed<nsIRunnable>&& aTransaction)
CycleCollectedJSContext::RunInMetastableState(already_AddRefed<nsIRunnable>&& aRunnable)
{
MOZ_ASSERT(mJSContext);
PendingIDBTransactionData data;
data.mTransaction = aTransaction;
RunInMetastableStateData data;
data.mRunnable = aRunnable;
MOZ_ASSERT(mOwningThread);
data.mRecursionDepth = RecursionDepth();
@ -455,19 +453,18 @@ CycleCollectedJSContext::AddPendingIDBTransaction(already_AddRefed<nsIRunnable>&
}
#endif
mPendingIDBTransactions.AppendElement(Move(data));
mMetastableStateEvents.AppendElement(Move(data));
}
void
CycleCollectedJSContext::DispatchToMicroTask(
already_AddRefed<MicroTaskRunnable> aRunnable)
CycleCollectedJSContext::DispatchToMicroTask(already_AddRefed<nsIRunnable> aRunnable)
{
RefPtr<MicroTaskRunnable> runnable(aRunnable);
RefPtr<nsIRunnable> runnable(aRunnable);
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(runnable);
mPendingMicroTaskRunnables.push(runnable.forget());
mPromiseMicroTaskQueue.push(runnable.forget());
}
class AsyncMutationHandler final : public mozilla::Runnable
@ -485,61 +482,41 @@ public:
}
};
bool
void
CycleCollectedJSContext::PerformMicroTaskCheckPoint()
{
if (mPendingMicroTaskRunnables.empty() && mDebuggerMicroTaskQueue.empty()) {
AfterProcessMicrotasks();
if (mPendingMicroTaskRunnables.empty()) {
// Nothing to do, return early.
return false;
return;
}
uint32_t currentDepth = RecursionDepth();
if (mMicroTaskRecursionDepth >= currentDepth) {
// We are already executing microtasks for the current recursion depth.
return false;
}
if (mTargetedMicroTaskRecursionDepth != 0 &&
mTargetedMicroTaskRecursionDepth != currentDepth) {
return false;
return;
}
if (NS_IsMainThread() && !nsContentUtils::IsSafeToRunScript()) {
// Special case for main thread where DOM mutations may happen when
// it is not safe to run scripts.
nsContentUtils::AddScriptRunner(new AsyncMutationHandler());
return false;
return;
}
mozilla::AutoRestore<uint32_t> restore(mMicroTaskRecursionDepth);
MOZ_ASSERT(currentDepth > 0);
mMicroTaskRecursionDepth = currentDepth;
bool didProcess = false;
AutoSlowOperation aso;
std::queue<RefPtr<MicroTaskRunnable>> suppressed;
for (;;) {
RefPtr<MicroTaskRunnable> runnable;
if (!mDebuggerMicroTaskQueue.empty()) {
runnable = mDebuggerMicroTaskQueue.front().forget();
mDebuggerMicroTaskQueue.pop();
} else if (!mPendingMicroTaskRunnables.empty()) {
runnable = mPendingMicroTaskRunnables.front().forget();
mPendingMicroTaskRunnables.pop();
} else {
break;
}
while (!mPendingMicroTaskRunnables.empty()) {
RefPtr<MicroTaskRunnable> runnable =
mPendingMicroTaskRunnables.front().forget();
mPendingMicroTaskRunnables.pop();
if (runnable->Suppressed()) {
// Microtasks in worker shall never be suppressed.
// Otherwise, mPendingMicroTaskRunnables will be replaced later with
// all suppressed tasks in mDebuggerMicroTaskQueue unexpectedly.
MOZ_ASSERT(NS_IsMainThread());
suppressed.push(runnable);
} else {
didProcess = true;
runnable->Run(aso);
}
}
@ -549,37 +526,13 @@ CycleCollectedJSContext::PerformMicroTaskCheckPoint()
// for some time, but no longer than spinning the event loop nestedly
// (sync XHR, alert, etc.)
mPendingMicroTaskRunnables.swap(suppressed);
AfterProcessMicrotasks();
return didProcess;
}
void
CycleCollectedJSContext::PerformDebuggerMicroTaskCheckpoint()
{
// Don't do normal microtask handling checks here, since whoever is calling
// this method is supposed to know what they are doing.
AutoSlowOperation aso;
for (;;) {
// For a debugger microtask checkpoint, we always use the debugger microtask
// queue.
std::queue<RefPtr<MicroTaskRunnable>>* microtaskQueue =
&GetDebuggerMicroTaskQueue();
if (microtaskQueue->empty()) {
break;
}
RefPtr<MicroTaskRunnable> runnable = microtaskQueue->front().forget();
MOZ_ASSERT(runnable);
// This function can re-enter, so we remove the element before calling.
microtaskQueue->pop();
runnable->Run(aso);
}
AfterProcessMicrotasks();
CycleCollectedJSContext::DispatchMicroTaskRunnable(
already_AddRefed<MicroTaskRunnable> aRunnable)
{
mPendingMicroTaskRunnables.push(aRunnable);
}
} // namespace mozilla

Просмотреть файл

@ -103,6 +103,9 @@ protected:
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
std::queue<nsCOMPtr<nsIRunnable>> mPromiseMicroTaskQueue;
std::queue<nsCOMPtr<nsIRunnable>> mDebuggerPromiseMicroTaskQueue;
private:
MOZ_IS_CLASS_INIT
void InitializeCommon();
@ -118,11 +121,11 @@ private:
JS::PromiseRejectionHandlingState state,
void* aData);
void AfterProcessMicrotasks();
void AfterProcessMicrotask(uint32_t aRecursionDepth);
public:
void ProcessStableStateQueue();
private:
void CleanupIDBTransactions(uint32_t aRecursionDepth);
void ProcessMetastableStateQueue(uint32_t aRecursionDepth);
public:
enum DeferredFinalizeType {
@ -139,8 +142,8 @@ public:
already_AddRefed<dom::Exception> GetPendingException() const;
void SetPendingException(dom::Exception* aException);
std::queue<RefPtr<MicroTaskRunnable>>& GetMicroTaskQueue();
std::queue<RefPtr<MicroTaskRunnable>>& GetDebuggerMicroTaskQueue();
std::queue<nsCOMPtr<nsIRunnable>>& GetPromiseMicroTaskQueue();
std::queue<nsCOMPtr<nsIRunnable>>& GetDebuggerPromiseMicroTaskQueue();
JSContext* Context() const
{
@ -154,19 +157,46 @@ public:
return JS::RootingContext::get(mJSContext);
}
void SetTargetedMicroTaskRecursionDepth(uint32_t aDepth)
bool MicroTaskCheckpointDisabled() const
{
mTargetedMicroTaskRecursionDepth = aDepth;
return mDisableMicroTaskCheckpoint;
}
void DisableMicroTaskCheckpoint(bool aDisable)
{
mDisableMicroTaskCheckpoint = aDisable;
}
class MOZ_RAII AutoDisableMicroTaskCheckpoint
{
public:
AutoDisableMicroTaskCheckpoint()
: mCCJSCX(CycleCollectedJSContext::Get())
{
mOldValue = mCCJSCX->MicroTaskCheckpointDisabled();
mCCJSCX->DisableMicroTaskCheckpoint(true);
}
~AutoDisableMicroTaskCheckpoint()
{
mCCJSCX->DisableMicroTaskCheckpoint(mOldValue);
}
CycleCollectedJSContext* mCCJSCX;
bool mOldValue;
};
protected:
JSContext* MaybeContext() const { return mJSContext; }
public:
// nsThread entrypoints
virtual void BeforeProcessTask(bool aMightBlock);
virtual void BeforeProcessTask(bool aMightBlock) { };
virtual void AfterProcessTask(uint32_t aRecursionDepth);
// microtask processor entry point
void AfterProcessMicrotask();
// Check whether we need an idle GC task.
void IsIdleGCTaskNeeded();
@ -174,15 +204,16 @@ public:
// Run in stable state (call through nsContentUtils)
void RunInStableState(already_AddRefed<nsIRunnable>&& aRunnable);
void AddPendingIDBTransaction(already_AddRefed<nsIRunnable>&& aTransaction);
// This isn't in the spec at all yet, but this gets the behavior we want for IDB.
// Runs after the current microtask completes.
void RunInMetastableState(already_AddRefed<nsIRunnable>&& aRunnable);
// Get the current thread's CycleCollectedJSContext. Returns null if there
// isn't one.
static CycleCollectedJSContext* Get();
// Queue an async microtask to the current main or worker thread.
virtual void DispatchToMicroTask(already_AddRefed<MicroTaskRunnable> aRunnable);
virtual void DispatchToMicroTask(already_AddRefed<nsIRunnable> aRunnable);
// Call EnterMicroTask when you're entering JS execution.
// Usually the best way to do this is to use nsAutoMicroTask.
@ -213,9 +244,9 @@ public:
mMicroTaskLevel = aLevel;
}
bool PerformMicroTaskCheckPoint();
void PerformMicroTaskCheckPoint();
void PerformDebuggerMicroTaskCheckpoint();
void DispatchMicroTaskRunnable(already_AddRefed<MicroTaskRunnable> aRunnable);
bool IsInStableOrMetaStableState()
{
@ -250,25 +281,21 @@ private:
nsCOMPtr<dom::Exception> mPendingException;
nsThread* mOwningThread; // Manual refcounting to avoid include hell.
struct PendingIDBTransactionData
struct RunInMetastableStateData
{
nsCOMPtr<nsIRunnable> mTransaction;
nsCOMPtr<nsIRunnable> mRunnable;
uint32_t mRecursionDepth;
};
nsTArray<nsCOMPtr<nsIRunnable>> mStableStateEvents;
nsTArray<PendingIDBTransactionData> mPendingIDBTransactions;
nsTArray<RunInMetastableStateData> mMetastableStateEvents;
uint32_t mBaseRecursionDepth;
bool mDoingStableStates;
// If set to none 0, microtasks will be processed only when recursion depth
// is the set value.
uint32_t mTargetedMicroTaskRecursionDepth;
bool mDisableMicroTaskCheckpoint;
uint32_t mMicroTaskLevel;
std::queue<RefPtr<MicroTaskRunnable>> mPendingMicroTaskRunnables;
std::queue<RefPtr<MicroTaskRunnable>> mDebuggerMicroTaskQueue;
uint32_t mMicroTaskRecursionDepth;
};