OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 (function() { | 5 (function() { |
6 var ShadowDOMPolyfill = window.ShadowDOMPolyfill; | 6 var ShadowDOMPolyfill = window.ShadowDOMPolyfill; |
7 if (!ShadowDOMPolyfill) return; | 7 if (!ShadowDOMPolyfill) return; |
8 | 8 |
| 9 if (navigator.userAgent.indexOf('(Dart)') !== -1) { |
| 10 console.error("ShadowDOMPolyfill polyfill was loaded in Dartium. This " + |
| 11 "will not work. This indicates that Dartium's Chrome version is " + |
| 12 "not compatible with this version of web_components."); |
| 13 } |
| 14 |
9 var needsConstructorFix = window.constructor === window.Window; | 15 var needsConstructorFix = window.constructor === window.Window; |
10 | 16 |
11 // TODO(jmesserly): we need to wrap document somehow (a dart:html hook?) | 17 // TODO(jmesserly): we need to wrap document somehow (a dart:html hook?) |
12 window.dartExperimentalFixupGetTag = function(originalGetTag) { | 18 window.dartExperimentalFixupGetTag = function(originalGetTag) { |
13 var NodeList = ShadowDOMPolyfill.wrappers.NodeList; | 19 var NodeList = ShadowDOMPolyfill.wrappers.NodeList; |
14 var ShadowRoot = ShadowDOMPolyfill.wrappers.ShadowRoot; | 20 var ShadowRoot = ShadowDOMPolyfill.wrappers.ShadowRoot; |
15 var unwrapIfNeeded = ShadowDOMPolyfill.unwrapIfNeeded; | 21 var unwrapIfNeeded = ShadowDOMPolyfill.unwrapIfNeeded; |
16 function getTag(obj) { | 22 function getTag(obj) { |
17 // TODO(jmesserly): do we still need these? | 23 // TODO(jmesserly): do we still need these? |
18 if (obj instanceof NodeList) return 'NodeList'; | 24 if (obj instanceof NodeList) return 'NodeList'; |
19 if (obj instanceof ShadowRoot) return 'ShadowRoot'; | 25 if (obj instanceof ShadowRoot) return 'ShadowRoot'; |
20 if (MutationRecord && (obj instanceof MutationRecord)) | 26 if (MutationRecord && (obj instanceof MutationRecord)) |
21 return 'MutationRecord'; | 27 return 'MutationRecord'; |
22 if (MutationObserver && (obj instanceof MutationObserver)) | 28 if (MutationObserver && (obj instanceof MutationObserver)) |
23 return 'MutationObserver'; | 29 return 'MutationObserver'; |
24 | 30 |
25 // TODO(jmesserly): this prevents incorrect interaction between ShadowDOM | 31 // TODO(jmesserly): this prevents incorrect interaction between ShadowDOM |
26 // and dart:html's <template> polyfill. Essentially, ShadowDOM is | 32 // and dart:html's <template> polyfill. Essentially, ShadowDOM is |
27 // polyfilling native template, but our Dart polyfill fails to detect this | 33 // polyfilling native template, but our Dart polyfill fails to detect this |
28 // because the unwrapped node is an HTMLUnknownElement, leading it to | 34 // because the unwrapped node is an HTMLUnknownElement, leading it to |
29 // think the node has no content. | 35 // think the node has no content. |
30 if (obj instanceof HTMLTemplateElement) return 'HTMLTemplateElement'; | 36 if (obj instanceof HTMLTemplateElement) return 'HTMLTemplateElement'; |
31 | 37 |
32 var unwrapped = unwrapIfNeeded(obj); | 38 var unwrapped = unwrapIfNeeded(obj); |
33 if (needsConstructorFix || obj !== unwrapped) { | 39 if (unwrapped && (needsConstructorFix || obj !== unwrapped)) { |
34 // Fix up class names for Firefox, or if using the minified polyfill. | 40 // Fix up class names for Firefox, or if using the minified polyfill. |
35 // dart2js prefers .constructor.name, but there are all kinds of cases | 41 // dart2js prefers .constructor.name, but there are all kinds of cases |
36 // where this will give the wrong answer. | 42 // where this will give the wrong answer. |
37 var ctor = obj.constructor | 43 var ctor = obj.constructor |
38 if (ctor === unwrapped.constructor) { | 44 if (ctor === unwrapped.constructor) { |
39 var name = ctor._ShadowDOMPolyfill$cacheTag_; | 45 var name = ctor._ShadowDOMPolyfill$cacheTag_; |
40 if (!name) { | 46 if (!name) { |
41 name = Object.prototype.toString.call(unwrapped); | 47 name = Object.prototype.toString.call(unwrapped); |
42 name = name.substring(8, name.length - 1); | 48 name = name.substring(8, name.length - 1); |
43 ctor._ShadowDOMPolyfill$cacheTag_ = name; | 49 ctor._ShadowDOMPolyfill$cacheTag_ = name; |
44 } | 50 } |
45 return name; | 51 return name; |
46 } | 52 } |
47 | 53 |
48 obj = unwrapped; | 54 obj = unwrapped; |
49 } | 55 } |
50 return originalGetTag(obj); | 56 return originalGetTag(obj); |
51 } | 57 } |
52 | 58 |
53 return getTag; | 59 return getTag; |
54 }; | 60 }; |
55 })(); | 61 })(); |
OLD | NEW |