Index: pkg/web_components/lib/platform.concat.js |
diff --git a/pkg/web_components/lib/platform.concat.js b/pkg/web_components/lib/platform.concat.js |
index 9b7ff43b306605248f61313126fcba359fd2e5f2..c4009c652dc2debb9d654c91f54def366a7429db 100644 |
--- a/pkg/web_components/lib/platform.concat.js |
+++ b/pkg/web_components/lib/platform.concat.js |
@@ -2327,7 +2327,7 @@ window.ShadowDOMPolyfill = {}; |
var globalMutationObservers = []; |
var isScheduled = false; |
- function scheduleCallback(observer) { |
+ function scheduleCallback() { |
if (isScheduled) |
return; |
setEndOfMicrotask(notifyObservers); |
@@ -2338,21 +2338,25 @@ window.ShadowDOMPolyfill = {}; |
function notifyObservers() { |
isScheduled = false; |
- do { |
- var notifyList = globalMutationObservers.slice(); |
- var anyNonEmpty = false; |
+ while (globalMutationObservers.length) { |
+ var notifyList = globalMutationObservers; |
+ globalMutationObservers = []; |
+ |
+ // Deliver changes in birth order of the MutationObservers. |
+ notifyList.sort(function(x, y) { return x.uid_ - y.uid_; }); |
+ |
for (var i = 0; i < notifyList.length; i++) { |
var mo = notifyList[i]; |
var queue = mo.takeRecords(); |
removeTransientObserversFor(mo); |
if (queue.length) { |
mo.callback_(queue, mo); |
- anyNonEmpty = true; |
} |
} |
- } while (anyNonEmpty); |
+ } |
} |
+ |
/** |
* @param {string} type |
* @param {Node} target |
@@ -2458,7 +2462,7 @@ window.ShadowDOMPolyfill = {}; |
} |
} |
- var anyRecordsEnqueued = false; |
+ var anyObserversEnqueued = false; |
// 4. |
for (var uid in interestedObservers) { |
@@ -2492,12 +2496,14 @@ window.ShadowDOMPolyfill = {}; |
record.oldValue = associatedStrings[uid]; |
// 8. |
+ if (!observer.records_.length) { |
+ globalMutationObservers.push(observer); |
+ anyObserversEnqueued = true; |
+ } |
observer.records_.push(record); |
- |
- anyRecordsEnqueued = true; |
} |
- if (anyRecordsEnqueued) |
+ if (anyObserversEnqueued) |
scheduleCallback(); |
} |
@@ -2561,9 +2567,6 @@ window.ShadowDOMPolyfill = {}; |
this.nodes_ = []; |
this.records_ = []; |
this.uid_ = ++uidCounter; |
- |
- // This will leak. There is no way to implement this without WeakRefs :'( |
- globalMutationObservers.push(this); |
} |
MutationObserver.prototype = { |