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

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: 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..bf10fe7149cbe2065ae214e23382f3bfcf99e759 100644
--- a/pkg/web_components/lib/platform.concat.js
+++ b/pkg/web_components/lib/platform.concat.js
@@ -1,71 +1,3 @@
-/**
- * Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
Siggi Cherem (dart-lang) 2014/09/10 22:13:52 seems odd that this part is removed?
jakemac 2014/09/10 22:37:43 fixed
- * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
- * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
- * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
- * Code distributed by Google as part of the polymer project is also
- * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
- */
-
-window.Platform = window.Platform || {};
-// prepopulate window.logFlags if necessary
-window.logFlags = window.logFlags || {};
-// process flags
-(function(scope){
- // import
- var flags = scope.flags || {};
- // populate flags from location
- location.search.slice(1).split('&').forEach(function(o) {
- o = o.split('=');
- o[0] && (flags[o[0]] = o[1] || true);
- });
- var entryPoint = document.currentScript ||
- document.querySelector('script[src*="platform.js"]');
- if (entryPoint) {
- var a = entryPoint.attributes;
- for (var i = 0, n; i < a.length; i++) {
- n = a[i];
- if (n.name !== 'src') {
- flags[n.name] = n.value || true;
- }
- }
- }
- if (flags.log) {
- flags.log.split(',').forEach(function(f) {
- window.logFlags[f] = true;
- });
- }
- // If any of these flags match 'native', then force native ShadowDOM; any
- // other truthy value, or failure to detect native
- // ShadowDOM, results in polyfill
- flags.shadow = flags.shadow || flags.shadowdom || flags.polyfill;
- if (flags.shadow === 'native') {
- flags.shadow = false;
- } else {
- flags.shadow = flags.shadow || !HTMLElement.prototype.createShadowRoot;
- }
-
- if (flags.shadow && document.querySelectorAll('script').length > 1) {
- console.warn('platform.js is not the first script on the page. ' +
- 'See http://www.polymer-project.org/docs/start/platform.html#setup ' +
- 'for details.');
- }
-
- // CustomElements polyfill flag
- if (flags.register) {
- window.CustomElements = window.CustomElements || {flags: {}};
- window.CustomElements.flags.register = flags.register;
- }
-
- if (flags.imports) {
- window.HTMLImports = window.HTMLImports || {flags: {}};
- window.HTMLImports.flags.imports = flags.imports;
- }
-
- // export
- scope.flags = flags;
-})(Platform);
-
/*
* Copyright 2012 The Polymer Authors. All rights reserved.
* Use of this source code is governed by a BSD-style
@@ -112,9 +44,6 @@ if (typeof WeakMap === 'undefined') {
})();
}
-// select ShadowDOM impl
-if (Platform.flags.shadow) {
-
// Copyright 2012 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -2327,7 +2256,7 @@ window.ShadowDOMPolyfill = {};
var globalMutationObservers = [];
var isScheduled = false;
- function scheduleCallback(observer) {
+ function scheduleCallback() {
if (isScheduled)
return;
setEndOfMicrotask(notifyObservers);
@@ -2338,21 +2267,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 +2391,7 @@ window.ShadowDOMPolyfill = {};
}
}
- var anyRecordsEnqueued = false;
+ var anyObserversEnqueued = false;
// 4.
for (var uid in interestedObservers) {
@@ -2492,12 +2425,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 +2496,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 = {
@@ -8883,7 +8815,6 @@ scope.ShadowCSS = ShadowCSS;
})(window.Platform);
-} else {
/*
* Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
@@ -8913,7 +8844,6 @@ scope.ShadowCSS = ShadowCSS;
})(window.Platform);
-}
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
« 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