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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /** 1 /**
2 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. 2 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
3 * This code may only be used under the BSD style license found at http://polyme r.github.io/LICENSE.txt 3 * This code may only be used under the BSD style license found at http://polyme r.github.io/LICENSE.txt
4 * The complete set of authors may be found at http://polymer.github.io/AUTHORS. txt 4 * The complete set of authors may be found at http://polymer.github.io/AUTHORS. txt
5 * The complete set of contributors may be found at http://polymer.github.io/CON TRIBUTORS.txt 5 * The complete set of contributors may be found at http://polymer.github.io/CON TRIBUTORS.txt
6 * Code distributed by Google as part of the polymer project is also 6 * Code distributed by Google as part of the polymer project is also
7 * subject to an additional IP rights grant found at http://polymer.github.io/PA TENTS.txt 7 * subject to an additional IP rights grant found at http://polymer.github.io/PA TENTS.txt
8 */ 8 */
9 9
10 window.Platform = window.Platform || {}; 10 window.Platform = window.Platform || {};
(...skipping 2309 matching lines...) Expand 10 before | Expand all | Expand 10 after
2320 'use strict'; 2320 'use strict';
2321 2321
2322 var setEndOfMicrotask = scope.setEndOfMicrotask 2322 var setEndOfMicrotask = scope.setEndOfMicrotask
2323 var wrapIfNeeded = scope.wrapIfNeeded 2323 var wrapIfNeeded = scope.wrapIfNeeded
2324 var wrappers = scope.wrappers; 2324 var wrappers = scope.wrappers;
2325 2325
2326 var registrationsTable = new WeakMap(); 2326 var registrationsTable = new WeakMap();
2327 var globalMutationObservers = []; 2327 var globalMutationObservers = [];
2328 var isScheduled = false; 2328 var isScheduled = false;
2329 2329
2330 function scheduleCallback(observer) { 2330 function scheduleCallback() {
2331 if (isScheduled) 2331 if (isScheduled)
2332 return; 2332 return;
2333 setEndOfMicrotask(notifyObservers); 2333 setEndOfMicrotask(notifyObservers);
2334 isScheduled = true; 2334 isScheduled = true;
2335 } 2335 }
2336 2336
2337 // http://dom.spec.whatwg.org/#mutation-observers 2337 // http://dom.spec.whatwg.org/#mutation-observers
2338 function notifyObservers() { 2338 function notifyObservers() {
2339 isScheduled = false; 2339 isScheduled = false;
2340 2340
2341 do { 2341 while (globalMutationObservers.length) {
2342 var notifyList = globalMutationObservers.slice(); 2342 var notifyList = globalMutationObservers;
2343 var anyNonEmpty = false; 2343 globalMutationObservers = [];
2344
2345 // Deliver changes in birth order of the MutationObservers.
2346 notifyList.sort(function(x, y) { return x.uid_ - y.uid_; });
2347
2344 for (var i = 0; i < notifyList.length; i++) { 2348 for (var i = 0; i < notifyList.length; i++) {
2345 var mo = notifyList[i]; 2349 var mo = notifyList[i];
2346 var queue = mo.takeRecords(); 2350 var queue = mo.takeRecords();
2347 removeTransientObserversFor(mo); 2351 removeTransientObserversFor(mo);
2348 if (queue.length) { 2352 if (queue.length) {
2349 mo.callback_(queue, mo); 2353 mo.callback_(queue, mo);
2350 anyNonEmpty = true;
2351 } 2354 }
2352 } 2355 }
2353 } while (anyNonEmpty); 2356 }
2354 } 2357 }
2355 2358
2359
2356 /** 2360 /**
2357 * @param {string} type 2361 * @param {string} type
2358 * @param {Node} target 2362 * @param {Node} target
2359 * @constructor 2363 * @constructor
2360 */ 2364 */
2361 function MutationRecord(type, target) { 2365 function MutationRecord(type, target) {
2362 this.type = type; 2366 this.type = type;
2363 this.target = target; 2367 this.target = target;
2364 this.addedNodes = new wrappers.NodeList(); 2368 this.addedNodes = new wrappers.NodeList();
2365 this.removedNodes = new wrappers.NodeList(); 2369 this.removedNodes = new wrappers.NodeList();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
2451 // true, or type is "characterData" and options's characterDataOldValue 2455 // true, or type is "characterData" and options's characterDataOldValue
2452 // is true, set the paired string of registered observer's observer in 2456 // is true, set the paired string of registered observer's observer in
2453 // interested observers to oldValue. 2457 // interested observers to oldValue.
2454 if (type === 'attributes' && options.attributeOldValue || 2458 if (type === 'attributes' && options.attributeOldValue ||
2455 type === 'characterData' && options.characterDataOldValue) { 2459 type === 'characterData' && options.characterDataOldValue) {
2456 associatedStrings[observer.uid_] = data.oldValue; 2460 associatedStrings[observer.uid_] = data.oldValue;
2457 } 2461 }
2458 } 2462 }
2459 } 2463 }
2460 2464
2461 var anyRecordsEnqueued = false; 2465 var anyObserversEnqueued = false;
2462 2466
2463 // 4. 2467 // 4.
2464 for (var uid in interestedObservers) { 2468 for (var uid in interestedObservers) {
2465 var observer = interestedObservers[uid]; 2469 var observer = interestedObservers[uid];
2466 var record = new MutationRecord(type, target); 2470 var record = new MutationRecord(type, target);
2467 2471
2468 // 2. 2472 // 2.
2469 if ('name' in data && 'namespace' in data) { 2473 if ('name' in data && 'namespace' in data) {
2470 record.attributeName = data.name; 2474 record.attributeName = data.name;
2471 record.attributeNamespace = data.namespace; 2475 record.attributeNamespace = data.namespace;
(...skipping 13 matching lines...) Expand all
2485 2489
2486 // 6. 2490 // 6.
2487 if (data.nextSibling) 2491 if (data.nextSibling)
2488 record.nextSibling = data.nextSibling; 2492 record.nextSibling = data.nextSibling;
2489 2493
2490 // 7. 2494 // 7.
2491 if (associatedStrings[uid] !== undefined) 2495 if (associatedStrings[uid] !== undefined)
2492 record.oldValue = associatedStrings[uid]; 2496 record.oldValue = associatedStrings[uid];
2493 2497
2494 // 8. 2498 // 8.
2499 if (!observer.records_.length) {
2500 globalMutationObservers.push(observer);
2501 anyObserversEnqueued = true;
2502 }
2495 observer.records_.push(record); 2503 observer.records_.push(record);
2496
2497 anyRecordsEnqueued = true;
2498 } 2504 }
2499 2505
2500 if (anyRecordsEnqueued) 2506 if (anyObserversEnqueued)
2501 scheduleCallback(); 2507 scheduleCallback();
2502 } 2508 }
2503 2509
2504 var slice = Array.prototype.slice; 2510 var slice = Array.prototype.slice;
2505 2511
2506 /** 2512 /**
2507 * @param {!Object} options 2513 * @param {!Object} options
2508 * @constructor 2514 * @constructor
2509 */ 2515 */
2510 function MutationObserverOptions(options) { 2516 function MutationObserverOptions(options) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2554 /** 2560 /**
2555 * The class that maps to the DOM MutationObserver interface. 2561 * The class that maps to the DOM MutationObserver interface.
2556 * @param {Function} callback. 2562 * @param {Function} callback.
2557 * @constructor 2563 * @constructor
2558 */ 2564 */
2559 function MutationObserver(callback) { 2565 function MutationObserver(callback) {
2560 this.callback_ = callback; 2566 this.callback_ = callback;
2561 this.nodes_ = []; 2567 this.nodes_ = [];
2562 this.records_ = []; 2568 this.records_ = [];
2563 this.uid_ = ++uidCounter; 2569 this.uid_ = ++uidCounter;
2564
2565 // This will leak. There is no way to implement this without WeakRefs :'(
2566 globalMutationObservers.push(this);
2567 } 2570 }
2568 2571
2569 MutationObserver.prototype = { 2572 MutationObserver.prototype = {
2570 constructor: MutationObserver, 2573 constructor: MutationObserver,
2571 2574
2572 // http://dom.spec.whatwg.org/#dom-mutationobserver-observe 2575 // http://dom.spec.whatwg.org/#dom-mutationobserver-observe
2573 observe: function(target, options) { 2576 observe: function(target, options) {
2574 target = wrapIfNeeded(target); 2577 target = wrapIfNeeded(target);
2575 2578
2576 var newOptions = new MutationObserverOptions(options); 2579 var newOptions = new MutationObserverOptions(options);
(...skipping 9677 matching lines...) Expand 10 before | Expand all | Expand 10 after
12254 // exports 12257 // exports
12255 12258
12256 scope.marshal = marshal; 12259 scope.marshal = marshal;
12257 // `module` confuses commonjs detectors 12260 // `module` confuses commonjs detectors
12258 scope.modularize = module; 12261 scope.modularize = module;
12259 scope.using = using; 12262 scope.using = using;
12260 12263
12261 })(window); 12264 })(window);
12262 12265
12263 //# sourceMappingURL=platform.concat.js.map 12266 //# sourceMappingURL=platform.concat.js.map
OLDNEW
« 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