gecko-dev/dom
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
..
activities Bug 1026290 - Update mochitest-chrome manifests for android; r=jgriffin 2015-07-10 14:41:59 -06:00
alarm Bug 1140275 - System messages shouldn't be sent to app pages not registered in manifests. r=fabrice 2015-08-03 01:05:00 +02:00
animation Bug 1181392 part 10 - Remove KeyframeEffect::IsFinishedTransition; r=dbaron 2015-08-07 12:29:36 +09:00
apps Bug 1191516 - Basic test for checkInstalled. r=fabrice 2015-08-08 15:28:00 -04:00
archivereader
asmjscache Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
audiochannel Merge b2g-inbound to m-c. a=merge 2015-08-06 15:37:49 -04:00
base Bug 1179909: Refactor stable state handling. r=smaug 2015-08-11 06:10:46 -07:00
battery
bindings Bug 1191305 - Alphabetize some includes; r=froydnj 2015-08-06 15:45:21 +03:00
bluetooth Bug 1190730 - Patch 5/5: Wrap get device related variables into get device request, r=joliu 2015-08-07 14:43:44 +08:00
broadcastchannel Bug 1190921 - Broadcastchannel keeps its containing iframe in memory when it has a user defined property, r=khuey 2015-08-06 01:26:00 +03:00
browser-element Bug 1190082 - Rename media-playback and the related stuff to audio-playback; r=smaug 2015-08-04 21:07:41 -04:00
cache Backed out 2 changesets (bug 1191107, bug 1180273) for causing xpcshell and m-oth testfailures on a CLOSED TREEi IGNORE IDL 2015-08-06 08:39:05 +02:00
camera Bug 1190040 - Part 2: Teach the audio channel service how to not notify audio-playback, and do that when a media element has no audio track; r=padenot 2015-08-06 10:26:27 -04:00
canvas Bug 1191608 - initialize element to null in CanvasRenderingContext2D::DrawImage. r=bas 2015-08-06 12:07:09 -04:00
cellbroadcast Bug 1171931 - Refactor duplicated code using XRE_IsParent/ContentProcess. r=froydnj 2015-07-03 18:29:00 -07:00
contacts Bug 1171678 - Follow up, whitespace. DONTBUILD 2015-08-07 13:15:49 -03:00
crypto
datastore Bug 1085575 - Skip test_app_install.html on OSX debug. rs=khuey 2015-08-06 13:41:33 -04:00
devicestorage Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
downloads
encoding Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
engineeringmode
events Bug 1191100 - Remove XPIDL signature comments in .cpp files. r=ehsan 2015-08-04 16:17:36 -07:00
fetch Backed out 2 changesets (bug 1191107, bug 1180273) for causing xpcshell and m-oth testfailures on a CLOSED TREEi IGNORE IDL 2015-08-06 08:39:05 +02:00
filehandle Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
filesystem Bug 1164310, part 4 - Implement the new HTMLInputElement API including the new Promise returning GetFilesAndDirectories. r=baku 2015-07-10 18:55:52 +01:00
fmradio Bug 1190040 - Part 2: Teach the audio channel service how to not notify audio-playback, and do that when a media element has no audio track; r=padenot 2015-08-06 10:26:27 -04:00
gamepad Bug 1191100 - Remove XPIDL signature comments in .cpp files. r=ehsan 2015-08-04 16:17:36 -07:00
geolocation Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
html Bug 1191491 - Do not dispatch an audio-playback notification when swapping browsers; r=smaug 2015-08-07 12:18:24 -04:00
icc Bug 1187832 - Update ril_worker and corresponding test cases. r=btseng 2015-08-04 13:58:42 +08:00
identity
imptests Bug 1008146 - Split up test_runtest.html; rs=Ms2ger 2015-08-11 14:02:33 +03:00
indexedDB Bug 1179909: Refactor stable state handling. r=smaug 2015-08-11 06:10:46 -07:00
inputmethod Bug 1175399 - Move readonly detection into isFocusableElement. r=janjongboom 2015-07-03 01:42:00 +02:00
inputport Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
interfaces Bug 1179909: Refactor stable state handling. r=smaug 2015-08-11 06:10:46 -07:00
ipc Backed out 8 changesets (bug 1183910, bug 1190281) 2015-08-11 10:13:43 +02:00
json
jsurl Bug 1181619. Make sure we've entered a microtask before we call nsJSUtils::EvaluateString, and put those microtasks outside the relevant AutoEntryScripts so we report any possible exceptions before doing the microtask checkpoint. r=bholley 2015-07-09 02:41:43 -04:00
locales Bug 1124649 - Part 1 - Add specific error messages for various types of STS and PKP header failures. r=keeler,hurley 2015-08-05 07:51:00 +02:00
manifest Bug 1171200 - Add means of checking if a document links to a manifest. r=billm 2015-07-30 11:56:12 -04:00
mathml
media Bug 1179909: Refactor stable state handling. r=smaug 2015-08-11 06:10:46 -07:00
messagechannel Bug 1188265 - No manual JS_ClearPendingException when StructuredCloneHelper is used, r=smaug 2015-07-31 01:38:00 +01:00
messages Bug 1140275 - System messages shouldn't be sent to app pages not registered in manifests. r=fabrice 2015-08-03 01:05:00 +02:00
mobileconnection Bug 1156231 - enable data registration recovery. r=hsinyi 2015-08-05 16:29:20 +08:00
mobileid
mobilemessage Merge b2ginbound to central, a=merge CLOSED TREE 2015-08-10 14:58:41 -07:00
network Bug 1190735 - Remove nsITimer.TYPE_REPEATING_PRECISE. r=froydnj. 2015-08-04 17:30:53 -07:00
nfc Bug 1173802: Store global NFC service in ref-counted variable, r=allstars.chh 2015-07-31 10:07:25 +02:00
notification Bug 1191305 - Alphabetize some includes; r=froydnj 2015-08-06 15:45:21 +03:00
offline
payment
permission Bug 1105827 - Part 5: Add test for Permissions.query. r=baku 2015-07-28 06:33:46 -07:00
phonenumberutils Bug 1179379 - PhonenumberJS: Update Metadata. r=bent 2015-07-06 10:12:37 -07:00
plugins Bug 1190040 - Part 2: Teach the audio channel service how to not notify audio-playback, and do that when a media element has no audio track; r=padenot 2015-08-06 10:26:27 -04:00
power Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
presentation Bug 1188935 - Part 3: register MulticastDNSDeviceProvider on Android only if API level >= 21; r=schien 2015-08-06 03:24:00 +02:00
promise Bug 1179909: Refactor stable state handling. r=smaug 2015-08-11 06:10:46 -07:00
push Bug 1192441: Disable Push service debug logging by default. r=dougt 2015-08-08 09:58:24 -07:00
quota Bug 1183689 - Having moz-safe-about+home in storage/permanent and storage/persistent breaks temporary storage initialization; r=khuey 2015-07-25 09:20:19 +02:00
requestsync Bug 1140275 - System messages shouldn't be sent to app pages not registered in manifests. r=fabrice 2015-08-03 01:05:00 +02:00
res
resourcestats
secureelement
security Bug 1188637 - Use channel->ascynOpen2 in dom/base/EventSource.cpp (r=sicking) 2015-08-04 20:06:19 -07:00
settings Bug 1187419 - Make sure SettingsRequestManager is only loaded in parent. r=gwagner 2015-07-24 12:32:00 +02:00
simplepush Bug 1167132 - Part 10: [NetworkManager] Move network information into a separate interface (PushService). r=nsm 2015-07-29 02:11:00 -04:00
smil Bug 1171966 - Update SMIL animation styles only when there are pending changes; r=dholbert 2015-07-31 13:14:46 +09:00
speakermanager Bug 1183925 - Part 1: Clean up the SpeakerManagerService shutdown; r=baku 2015-07-15 17:47:08 -04:00
storage Bug 1179909: Refactor stable state handling. r=smaug 2015-08-11 06:10:46 -07:00
svg Bug 1191100 - Remove XPIDL signature comments in .cpp files. r=ehsan 2015-08-04 16:17:36 -07:00
system Bug 1184822 - Use classId to get provider. r=fabrice 2015-08-06 11:54:14 +08:00
telephony Bug 1191237 - Part 2: Stablize |test_TelephonyUtils.js|. r=aknow 2015-08-06 10:26:00 +02:00
tests Bug 1192986 Fix test_interfaces.html to expect Cache API and font loading to be released. r=ehsan 2015-08-10 20:17:11 -07:00
tethering
time
tv
voicemail Bug 1171931 - Refactor duplicated code using XRE_IsParent/ContentProcess. r=froydnj 2015-07-03 18:29:00 -07:00
vr
wappush
webidl Bug 1188099 - (Part 3) Introduce [ChromeOnly] SpeechSynthesis.forceEnd for tests. r=smaug r=kdavis 2015-08-08 10:30:46 -07:00
wifi Bug 1167132 - Part 5: [NetworkManager] Move network information into a separate interface (Tethering). r=echen 2015-07-29 02:05:00 -04:00
workers Bug 1179909: Refactor stable state handling. r=smaug 2015-08-11 06:10:46 -07:00
xbl Bug 1180017 - Fix up the badly-horked backout and re-land. 2015-07-29 12:31:47 -04:00
xml Backed out 2 changesets (bug 1191107, bug 1180273) for causing xpcshell and m-oth testfailures on a CLOSED TREEi IGNORE IDL 2015-08-06 08:39:05 +02:00
xslt Bug 1184842. Pass aOldValue to all mutation observers. r=peterv 2015-07-25 18:01:19 +12:00
xul Bug 1191100 - Remove XPIDL signature comments in .cpp files. r=ehsan 2015-08-04 16:17:36 -07:00
jar.mn
moz.build Bug 1188937 - Only add Push API interfaces to build if the feature is enabled. r=kitcambridge 2015-07-29 09:12:51 -07:00