| Index: pkg/custom_element/lib/custom-elements.debug.js
|
| diff --git a/pkg/custom_element/lib/custom-elements.debug.js b/pkg/custom_element/lib/custom-elements.debug.js
|
| index be0a36032bbe1c5743357070633f9280a8a1d192..befb1a929029e8b6959a1443ccf3992c002922cb 100644
|
| --- a/pkg/custom_element/lib/custom-elements.debug.js
|
| +++ b/pkg/custom_element/lib/custom-elements.debug.js
|
| @@ -131,8 +131,7 @@ if (typeof WeakMap !== 'undefined' && navigator.userAgent.indexOf('Firefox/') <
|
| } else {
|
| (function() {
|
| var defineProperty = Object.defineProperty;
|
| - var hasOwnProperty = Object.hasOwnProperty;
|
| - var counter = new Date().getTime() % 1e9;
|
| + var counter = Date.now() % 1e9;
|
|
|
| SideTable = function() {
|
| this.name = '__st' + (Math.random() * 1e9 >>> 0) + (counter++ + '__');
|
| @@ -140,10 +139,16 @@ if (typeof WeakMap !== 'undefined' && navigator.userAgent.indexOf('Firefox/') <
|
|
|
| SideTable.prototype = {
|
| set: function(key, value) {
|
| - defineProperty(key, this.name, {value: value, writable: true});
|
| + var entry = key[this.name];
|
| + if (entry && entry[0] === key)
|
| + entry[1] = value;
|
| + else
|
| + defineProperty(key, this.name, {value: [key, value], writable: true});
|
| },
|
| get: function(key) {
|
| - return hasOwnProperty.call(key, this.name) ? key[this.name] : undefined;
|
| + var entry;
|
| + return (entry = key[this.name]) && entry[0] === key ?
|
| + entry[1] : undefined;
|
| },
|
| delete: function(key) {
|
| this.set(key, undefined);
|
| @@ -700,15 +705,7 @@ if (!window.MutationObserver) {
|
|
|
| (function(scope){
|
|
|
| -/*
|
| -if (HTMLElement.prototype.webkitShadowRoot) {
|
| - Object.defineProperty(HTMLElement.prototype, 'shadowRoot', {
|
| - get: function() {
|
| - return this.webkitShadowRoot;
|
| - }
|
| - };
|
| -}
|
| -*/
|
| +var logFlags = window.logFlags || {};
|
|
|
| // walk the subtree rooted at node, applying 'find(element, data)' function
|
| // to each element
|
| @@ -812,7 +809,7 @@ function inserted(element) {
|
| // TODO(sjmiles): when logging, do work on all custom elements so we can
|
| // track behavior even when callbacks not defined
|
| //console.log('inserted: ', element.localName);
|
| - if (element.enteredDocumentCallback || (element.__upgraded__ && logFlags.dom)) {
|
| + if (element.enteredViewCallback || (element.__upgraded__ && logFlags.dom)) {
|
| logFlags.dom && console.group('inserted:', element.localName);
|
| if (inDocument(element)) {
|
| element.__inserted = (element.__inserted || 0) + 1;
|
| @@ -824,9 +821,9 @@ function inserted(element) {
|
| if (element.__inserted > 1) {
|
| logFlags.dom && console.warn('inserted:', element.localName,
|
| 'insert/remove count:', element.__inserted)
|
| - } else if (element.enteredDocumentCallback) {
|
| + } else if (element.enteredViewCallback) {
|
| logFlags.dom && console.log('inserted:', element.localName);
|
| - element.enteredDocumentCallback();
|
| + element.enteredViewCallback();
|
| }
|
| }
|
| logFlags.dom && console.groupEnd();
|
| @@ -843,7 +840,7 @@ function removedNode(node) {
|
| function removed(element) {
|
| // TODO(sjmiles): temporary: do work on all custom elements so we can track
|
| // behavior even when callbacks not defined
|
| - if (element.leftDocumentCallback || (element.__upgraded__ && logFlags.dom)) {
|
| + if (element.leftViewCallback || (element.__upgraded__ && logFlags.dom)) {
|
| logFlags.dom && console.log('removed:', element.localName);
|
| if (!inDocument(element)) {
|
| element.__inserted = (element.__inserted || 0) - 1;
|
| @@ -855,8 +852,8 @@ function removed(element) {
|
| if (element.__inserted < 0) {
|
| logFlags.dom && console.warn('removed:', element.localName,
|
| 'insert/remove count:', element.__inserted)
|
| - } else if (element.leftDocumentCallback) {
|
| - element.leftDocumentCallback();
|
| + } else if (element.leftViewCallback) {
|
| + element.leftViewCallback();
|
| }
|
| }
|
| }
|
| @@ -864,8 +861,10 @@ function removed(element) {
|
|
|
| function inDocument(element) {
|
| var p = element;
|
| + var doc = window.ShadowDOMPolyfill &&
|
| + window.ShadowDOMPolyfill.wrapIfNeeded(document) || document;
|
| while (p) {
|
| - if (p == element.ownerDocument) {
|
| + if (p == doc) {
|
| return true;
|
| }
|
| p = p.parentNode || p.host;
|
| @@ -891,13 +890,6 @@ function watchRoot(root) {
|
| }
|
| }
|
|
|
| -function watchAllShadows(node) {
|
| - watchShadow(node);
|
| - forSubtree(node, function(e) {
|
| - watchShadow(node);
|
| - });
|
| -}
|
| -
|
| function filter(inNode) {
|
| switch (inNode.localName) {
|
| case 'style':
|
| @@ -933,11 +925,6 @@ function handler(mutations) {
|
| if (filter(n)) {
|
| return;
|
| }
|
| - // watch shadow-roots on nodes that have had them attached manually
|
| - // TODO(sjmiles): remove if createShadowRoot is overridden
|
| - // TODO(sjmiles): removed as an optimization, manual shadow roots
|
| - // must be watched explicitly
|
| - //watchAllShadows(n);
|
| // nodes added may need lifecycle management
|
| addedNode(n);
|
| });
|
| @@ -981,8 +968,6 @@ function upgradeDocument(document) {
|
| // exports
|
|
|
| scope.watchShadow = watchShadow;
|
| -scope.watchAllShadows = watchAllShadows;
|
| -
|
| scope.upgradeAll = addedNode;
|
| scope.upgradeSubtree = addedSubtree;
|
|
|
| @@ -1014,14 +999,11 @@ var flags = scope.flags;
|
|
|
| // native document.register?
|
|
|
| -var hasNative = Boolean(document.webkitRegister || document.register);
|
| +var hasNative = Boolean(document.register);
|
| var useNative = !flags.register && hasNative;
|
|
|
| if (useNative) {
|
|
|
| - // normalize
|
| - document.register = document.register || document.webkitRegister;
|
| -
|
| // stub
|
| var nop = function() {};
|
|
|
| @@ -1030,7 +1012,6 @@ if (useNative) {
|
| scope.upgradeElement = nop;
|
|
|
| scope.watchShadow = nop;
|
| - scope.watchAllShadows = nop;
|
| scope.upgrade = nop;
|
| scope.upgradeAll = nop;
|
| scope.upgradeSubtree = nop;
|
| @@ -1091,7 +1072,7 @@ if (useNative) {
|
| if (name.indexOf('-') < 0) {
|
| // TODO(sjmiles): replace with more appropriate error (EricB can probably
|
| // offer guidance)
|
| - throw new Error('document.register: first argument `name` must contain a dash (\'-\'). Argument was \'' + String(name) + '\'.');
|
| + throw new Error('document.register: first argument (\'name\') must contain a dash (\'-\'). Argument provided was \'' + String(name) + '\'.');
|
| }
|
| // record name
|
| definition.name = name;
|
| @@ -1162,11 +1143,11 @@ if (useNative) {
|
| // prototype for precise mixing in
|
| if (!Object.__proto__) {
|
| // default prototype
|
| - var native = HTMLElement.prototype;
|
| + var nativePrototype = HTMLElement.prototype;
|
| // work out prototype when using type-extension
|
| if (definition.is) {
|
| var inst = document.createElement(definition.tag);
|
| - native = Object.getPrototypeOf(inst);
|
| + nativePrototype = Object.getPrototypeOf(inst);
|
| }
|
| // ensure __proto__ reference is installed at each point on the prototype
|
| // chain.
|
| @@ -1174,14 +1155,14 @@ if (useNative) {
|
| // of prototype swizzling. In this case, this generated __proto__ provides
|
| // limited support for prototype traversal.
|
| var proto = definition.prototype, ancestor;
|
| - while (proto && (proto !== native)) {
|
| + while (proto && (proto !== nativePrototype)) {
|
| var ancestor = Object.getPrototypeOf(proto);
|
| proto.__proto__ = ancestor;
|
| proto = ancestor;
|
| }
|
| }
|
| // cache this in case of mixin
|
| - definition.native = native;
|
| + definition.native = nativePrototype;
|
| }
|
|
|
| // SECTION 4
|
| @@ -1289,7 +1270,7 @@ if (useNative) {
|
|
|
| function registerDefinition(name, definition) {
|
| if (registry[name]) {
|
| - throw new Error('a type with that name is already registered.');
|
| + throw new Error('Cannot register a tag more than once');
|
| }
|
| registry[name] = definition;
|
| }
|
| @@ -1442,14 +1423,16 @@ CustomElements.parser = parser;
|
| (function(){
|
|
|
| // bootstrap parsing
|
| -
|
| function bootstrap() {
|
| - // go async so call stack can unwind
|
| - setTimeout(function() {
|
| - // parse document
|
| - CustomElements.parser.parse(document);
|
| - // one more pass before register is 'live'
|
| - CustomElements.upgradeDocument(document);
|
| + // parse document
|
| + CustomElements.parser.parse(document);
|
| + // one more pass before register is 'live'
|
| + CustomElements.upgradeDocument(document);
|
| + // choose async
|
| + var async = window.Platform && Platform.endOfMicrotask ?
|
| + Platform.endOfMicrotask :
|
| + setTimeout;
|
| + async(function() {
|
| // set internal 'ready' flag, now document.register will trigger
|
| // synchronous upgrades
|
| CustomElements.ready = true;
|
| @@ -1462,7 +1445,7 @@ function bootstrap() {
|
| document.body.dispatchEvent(
|
| new CustomEvent('WebComponentsReady', {bubbles: true})
|
| );
|
| - }, 0);
|
| + });
|
| }
|
|
|
| // CustomEvent shim for IE
|
|
|