| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 // Teaches dart2js about the wrapping that is done by the Shadow DOM polyfill. | |
| 6 (function() { | |
| 7 var ShadowDOMPolyfill = window.ShadowDOMPolyfill; | |
| 8 if (!ShadowDOMPolyfill) return; | |
| 9 | |
| 10 // TODO(sigmund): remove the userAgent check once 1.6 rolls as stable. | |
| 11 // See: dartbug.com/18463 | |
| 12 if (navigator.dartEnabled || (navigator.userAgent.indexOf('(Dart)') !== -1)) { | |
| 13 console.error("ShadowDOMPolyfill polyfill was loaded in Dartium. This " + | |
| 14 "will not work. This indicates that Dartium's Chrome version is " + | |
| 15 "not compatible with this version of web_components."); | |
| 16 } | |
| 17 | |
| 18 var needsConstructorFix = window.constructor === window.Window; | |
| 19 | |
| 20 // TODO(jmesserly): we need to wrap document somehow (a dart:html hook?) | |
| 21 | |
| 22 // dartNativeDispatchHooksTransformer is described on initHooks() in | |
| 23 // sdk/lib/_internal/lib/native_helper.dart. | |
| 24 if (typeof window.dartNativeDispatchHooksTransformer == 'undefined') | |
| 25 window.dartNativeDispatchHooksTransformer = []; | |
| 26 | |
| 27 window.dartNativeDispatchHooksTransformer.push(function(hooks) { | |
| 28 var NodeList = ShadowDOMPolyfill.wrappers.NodeList; | |
| 29 var ShadowRoot = ShadowDOMPolyfill.wrappers.ShadowRoot; | |
| 30 var unwrapIfNeeded = ShadowDOMPolyfill.unwrapIfNeeded; | |
| 31 var originalGetTag = hooks.getTag; | |
| 32 hooks.getTag = function getTag(obj) { | |
| 33 // TODO(jmesserly): do we still need these? | |
| 34 if (obj instanceof NodeList) return 'NodeList'; | |
| 35 if (obj instanceof ShadowRoot) return 'ShadowRoot'; | |
| 36 if (MutationRecord && (obj instanceof MutationRecord)) | |
| 37 return 'MutationRecord'; | |
| 38 if (MutationObserver && (obj instanceof MutationObserver)) | |
| 39 return 'MutationObserver'; | |
| 40 | |
| 41 // TODO(jmesserly): this prevents incorrect interaction between ShadowDOM | |
| 42 // and dart:html's <template> polyfill. Essentially, ShadowDOM is | |
| 43 // polyfilling native template, but our Dart polyfill fails to detect this | |
| 44 // because the unwrapped node is an HTMLUnknownElement, leading it to | |
| 45 // think the node has no content. | |
| 46 if (obj instanceof HTMLTemplateElement) return 'HTMLTemplateElement'; | |
| 47 | |
| 48 var unwrapped = unwrapIfNeeded(obj); | |
| 49 if (unwrapped && (needsConstructorFix || obj !== unwrapped)) { | |
| 50 // Fix up class names for Firefox, or if using the minified polyfill. | |
| 51 // dart2js prefers .constructor.name, but there are all kinds of cases | |
| 52 // where this will give the wrong answer. | |
| 53 var ctor = obj.constructor | |
| 54 if (ctor === unwrapped.constructor) { | |
| 55 var name = ctor._ShadowDOMPolyfill$cacheTag_; | |
| 56 if (!name) { | |
| 57 name = originalGetTag(unwrapped); | |
| 58 ctor._ShadowDOMPolyfill$cacheTag_ = name; | |
| 59 } | |
| 60 return name; | |
| 61 } | |
| 62 | |
| 63 obj = unwrapped; | |
| 64 } | |
| 65 return originalGetTag(obj); | |
| 66 } | |
| 67 }); | |
| 68 })(); | |
| OLD | NEW |