gecko-dev/dom/workers
Kyle Huey 76e3009ab8 Bug 1179909: Refactor stable state handling. r=smaug
This is motivated by three separate but related problems:

1. Our concept of recursion depth is broken for things that run from AfterProcessNextEvent observers (e.g. Promises). We decrement the recursionDepth counter before firing observers, so a Promise callback running at the lowest event loop depth has a recursion depth of 0 (whereas a regular nsIRunnable would be 1). This is a problem because it's impossible to distinguish a Promise running after a sync XHR's onreadystatechange handler from a top-level event (since the former runs with depth 2 - 1 = 1, and the latter runs with just 1).

2. The nsIThreadObserver mechanism that is used by a lot of code to run "after" the current event is a poor fit for anything that runs script. First, the order the observers fire in is the order they were added, not anything fixed by spec. Additionally, running script can cause the event loop to spin, which is a big source of pain here (bholley has some nasty bug caused by this).

3. We run Promises from different points in the code for workers and main thread. The latter runs from XPConnect's nsIThreadObserver callbacks, while the former runs from a hardcoded call to run Promises in the worker event loop. What workers do is particularly problematic because it means we can't get the right recursion depth no matter what we do to nsThread.

The solve this, this patch does the following:

1. Consolidate some handling of microtasks and all handling of stable state from appshell and WorkerPrivate into CycleCollectedJSRuntime.
2. Make the recursionDepth counter only available to CycleCollectedJSRuntime (and its consumers) and remove it from the nsIThreadInternal and nsIThreadObserver APIs.
3. Adjust the recursionDepth counter so that microtasks run with the recursionDepth of the task they are associated with.
4. Introduce the concept of metastable state to replace appshell's RunBeforeNextEvent. Metastable state is reached after every microtask or task is completed. This provides the semantics that bent and I want for IndexedDB, where transactions autocommit at the end of a microtask and do not "spill" from one microtask into a subsequent microtask. This differs from appshell's RunBeforeNextEvent in two ways:
a) It fires between microtasks, which was the motivation for starting this.
b) It no longer ensures that we're at the same event loop depth in the native event queue. bent decided we don't care about this.
5. Reorder stable state to happen after microtasks such as Promises, per HTML. Right now we call the regular thread observers, including appshell, before the main thread observer (XPConnect), so stable state tasks happen before microtasks.
2015-08-11 06:10:46 -07:00
..
test Bug 1179909: Refactor stable state handling. r=smaug 2015-08-11 06:10:46 -07:00
ChromeWorkerScope.cpp Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
ChromeWorkerScope.h Bug 1152551, part 2 - Fix mode lines in dom/. r=jst 2015-05-03 15:32:37 -04:00
DataStore.cpp Bug 1188265 - No manual JS_ClearPendingException when StructuredCloneHelper is used, r=smaug 2015-07-31 01:38:00 +01:00
DataStore.h Bug 1152551, part 2 - Fix mode lines in dom/. r=jst 2015-05-03 15:32:37 -04:00
DataStoreCursor.cpp Bug 1152551, part 2 - Fix mode lines in dom/. r=jst 2015-05-03 15:32:37 -04:00
DataStoreCursor.h Bug 1152551, part 2 - Fix mode lines in dom/. r=jst 2015-05-03 15:32:37 -04:00
FileReaderSync.cpp Bug 1166231 - Make nsIDOMBlob an empty interface, r=ehsan 2015-05-19 15:36:37 +01:00
FileReaderSync.h Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
Location.cpp Bug 1152551, part 2 - Fix mode lines in dom/. r=jst 2015-05-03 15:32:37 -04:00
Location.h Bug 1152551, part 2 - Fix mode lines in dom/. r=jst 2015-05-03 15:32:37 -04:00
MessagePort.cpp Bug 1183894 - Remove warning if MessagePort::CloseInternal is called before start. r=khuey 2015-07-14 18:06:32 -07:00
MessagePort.h Bug 911972 - MessagePort and MessageChannel in workers, r=smaug, r=bent 2015-06-17 11:44:27 +01:00
moz.build Bug 1169819 Add browser chrome test to validate SW force refresh. r=ehsan 2015-06-12 18:59:01 -07:00
Navigator.cpp Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
Navigator.h Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
nsIWorkerDebugger.idl Bug 1168853 - Implement WorkerDebugger.isInitialized;r=khuey 2015-06-08 09:08:20 +02:00
nsIWorkerDebuggerManager.idl
Performance.cpp Bug 1186880 - Performance timing api in workers should output entries if preference is enabled. r=baku 2015-07-28 17:33:37 +01:00
Performance.h Bug 1186880 - Performance timing api in workers should output entries if preference is enabled. r=baku 2015-07-28 17:33:37 +01:00
Principal.cpp Bug 1152551, part 2 - Fix mode lines in dom/. r=jst 2015-05-03 15:32:37 -04:00
Principal.h Bug 1152551, part 2 - Fix mode lines in dom/. r=jst 2015-05-03 15:32:37 -04:00
PServiceWorkerManager.ipdl Bug 1167296 - patch 2 - ServiceWorkerManager::Remove should use PBackground, r=nsm 2015-06-21 12:19:07 +01:00
Queue.h Bug 1152551, part 2 - Fix mode lines in dom/. r=jst 2015-05-03 15:32:37 -04:00
RegisterBindings.cpp Bug 1152551, part 2 - Fix mode lines in dom/. r=jst 2015-05-03 15:32:37 -04:00
RuntimeService.cpp Bug 1179909: Refactor stable state handling. r=smaug 2015-08-11 06:10:46 -07:00
RuntimeService.h Bug 1179489 - Don't count service workers towards an origin's max worker quota; r=nsm 2015-07-02 18:48:48 -04:00
ScriptLoader.cpp Bug 1176341 - De-holder nsIXPConnect::CreateSandbox. r=baku,gabor 2015-07-21 11:31:44 -07:00
ScriptLoader.h Bug 1148935 - Correctly reflect worker and sharedworker RequestContext values; r=smaug 2015-06-30 18:52:42 -04:00
ServiceWorker.cpp Bug 1179982 - Fix all compile errors in dom/workers on non-unified build. r=mrbkap 2015-07-02 14:54:00 +02:00
ServiceWorker.h Bug 1179567 - Make ServiceWorker keep its document and window alive; r=baku 2015-07-02 09:48:27 -04:00
ServiceWorkerClient.cpp Bug 1186307 - part 1 - Unify the StructuredCloneCallbacks in WorkerPrivate.cpp, r=smaug 2015-08-10 16:33:23 +01:00
ServiceWorkerClient.h Bug 1179567 - Make ServiceWorker keep its document and window alive; r=baku 2015-07-02 09:48:27 -04:00
ServiceWorkerClients.cpp Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
ServiceWorkerClients.h Bug 1130684 - Implement Service Worker clients.claim. r=nsm,ehsan 2015-05-14 12:41:42 -07:00
ServiceWorkerCommon.h Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
ServiceWorkerContainer.cpp Bug 1190703 - Relax scope resolution assertion in ServiceWorkerContainer::Register. r=bkelly 2015-08-05 14:33:50 -07:00
ServiceWorkerContainer.h Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
ServiceWorkerEvents.cpp Bug 1190478 - Hide PushEvent.data until we ship message encryption. r=mt,jst 2015-08-03 11:04:41 -07:00
ServiceWorkerEvents.h Bug 1190478 - Hide PushEvent.data until we ship message encryption. r=mt,jst 2015-08-03 11:04:41 -07:00
ServiceWorkerManager.cpp Bug 1144660 - client.focus() adds window interaction checks and directly uses DOMServiceWorkerFocusClient to focus window. r=ehsan,dao 2015-07-23 08:30:27 -07:00
ServiceWorkerManager.h Bug 1180148 - Clear service workers registered for a site when clearing the cookies and stored data is not working in b2g. r=baku 2015-08-03 22:51:07 +02:00
ServiceWorkerManagerChild.cpp Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
ServiceWorkerManagerChild.h Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
ServiceWorkerManagerParent.cpp Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
ServiceWorkerManagerParent.h Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
ServiceWorkerManagerService.cpp Bug 1178233 - [non-e10s] The update process doesn't work within about:serviceworkers in non-e10s mode. r=baku 2015-07-14 15:44:13 +02:00
ServiceWorkerManagerService.h Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
ServiceWorkerPeriodicUpdater.cpp Bug 1171931 - Refactor duplicated code using XRE_IsParent/ContentProcess. r=froydnj 2015-07-03 18:29:00 -07:00
ServiceWorkerPeriodicUpdater.h Bug 1152551, part 3 - Fix more mode lines in dom/. r=jst 2015-05-03 15:32:37 -04:00
ServiceWorkerRegistrar.cpp Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
ServiceWorkerRegistrar.h Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
ServiceWorkerRegistrarTypes.ipdlh
ServiceWorkerRegistration.cpp Bug 1184574 - Allow access to PushManager on ServiceWorker. r=kitcambridge,smaug,catalinb 2015-07-23 08:30:15 -07:00
ServiceWorkerRegistration.h Bug 1184574 - Allow access to PushManager on ServiceWorker. r=kitcambridge,smaug,catalinb 2015-07-23 08:30:15 -07:00
ServiceWorkerScriptCache.cpp Bug 1176341 - De-holder nsIXPConnect::CreateSandbox. r=baku,gabor 2015-07-21 11:31:44 -07:00
ServiceWorkerScriptCache.h Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
ServiceWorkerWindowClient.cpp Bug 1144660 - client.focus() adds window interaction checks and directly uses DOMServiceWorkerFocusClient to focus window. r=ehsan,dao 2015-07-23 08:30:27 -07:00
ServiceWorkerWindowClient.h Bug 1179982 - Fix all compile errors in dom/workers on non-unified build. r=mrbkap 2015-07-02 14:54:00 +02:00
SharedWorker.cpp Bug 1152551, part 2 - Fix mode lines in dom/. r=jst 2015-05-03 15:32:37 -04:00
SharedWorker.h Bug 1152551, part 2 - Fix mode lines in dom/. r=jst 2015-05-03 15:32:37 -04:00
URL.cpp Bug 1183907, properly wrappercache worker URL object, r=baku 2015-07-15 14:50:59 +03:00
URL.h Bug 1183907, properly wrappercache worker URL object, r=baku 2015-07-15 14:50:59 +03:00
WorkerDebuggerManager.cpp Bug 1181318 - Eliminate duplicate mRefCnt members in nsRunnable subclasses. r=ehsan 2015-07-07 14:03:00 +02:00
WorkerDebuggerManager.h Bug 1152551, part 2 - Fix mode lines in dom/. r=jst 2015-05-03 15:32:37 -04:00
WorkerFeature.h Bug 1152551, part 2 - Fix mode lines in dom/. r=jst 2015-05-03 15:32:37 -04:00
WorkerInlines.h Bug 1152551, part 2 - Fix mode lines in dom/. r=jst 2015-05-03 15:32:37 -04:00
WorkerPrivate.cpp Bug 1179909: Refactor stable state handling. r=smaug 2015-08-11 06:10:46 -07:00
WorkerPrivate.h Bug 1179909: Refactor stable state handling. r=smaug 2015-08-11 06:10:46 -07:00
WorkerRunnable.cpp Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
WorkerRunnable.h Bug 1152551, part 2 - Fix mode lines in dom/. r=jst 2015-05-03 15:32:37 -04:00
Workers.h Bug 1188062 - Unship Request.context; r=baku 2015-07-30 08:14:00 -04:00
WorkerScope.cpp Bug 1144660 - client.focus() adds window interaction checks and directly uses DOMServiceWorkerFocusClient to focus window. r=ehsan,dao 2015-07-23 08:30:27 -07:00
WorkerScope.h Bug 1144660 - client.focus() adds window interaction checks and directly uses DOMServiceWorkerFocusClient to focus window. r=ehsan,dao 2015-07-23 08:30:27 -07:00
WorkerStructuredClone.h Bug 1044102 - Part 3 - Support StructuredClone. r=baku 2015-07-30 20:50:00 +02:00
WorkerThread.cpp Bug 1179909: Refactor stable state handling. r=smaug 2015-08-11 06:10:46 -07:00
WorkerThread.h Bug 1188696 - Hoist nsRefPtr.h into MFBT. r=froydnj 2015-07-29 10:44:59 -07:00
XMLHttpRequest.cpp Bug 1186307 - part 1 - Unify the StructuredCloneCallbacks in WorkerPrivate.cpp, r=smaug 2015-08-10 16:33:23 +01:00
XMLHttpRequest.h Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
XMLHttpRequestUpload.cpp Bug 1152551, part 2 - Fix mode lines in dom/. r=jst 2015-05-03 15:32:37 -04:00
XMLHttpRequestUpload.h Bug 1152551, part 2 - Fix mode lines in dom/. r=jst 2015-05-03 15:32:37 -04:00