Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(468)

Unified Diff: pkg/web_components/lib/platform.concat.js

Issue 556403003: cherry pick to fix memory leak (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: apply patch Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/web_components/lib/platform.js ('k') | pkg/web_components/lib/platform.concat.js.map » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 = {
« no previous file with comments | « pkg/web_components/lib/platform.js ('k') | pkg/web_components/lib/platform.concat.js.map » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698