| OLD | NEW |
| 1 // Copyright (c) 2012 The Polymer Authors. All rights reserved. | 1 // Copyright (c) 2012 The Polymer Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Redistribution and use in source and binary forms, with or without | 3 // Redistribution and use in source and binary forms, with or without |
| 4 // modification, are permitted provided that the following conditions are | 4 // modification, are permitted provided that the following conditions are |
| 5 // met: | 5 // met: |
| 6 // | 6 // |
| 7 // * Redistributions of source code must retain the above copyright | 7 // * Redistributions of source code must retain the above copyright |
| 8 // notice, this list of conditions and the following disclaimer. | 8 // notice, this list of conditions and the following disclaimer. |
| 9 // * Redistributions in binary form must reproduce the above | 9 // * Redistributions in binary form must reproduce the above |
| 10 // copyright notice, this list of conditions and the following disclaimer | 10 // copyright notice, this list of conditions and the following disclaimer |
| (...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 scope = window.CustomElements = {flags:{}}; | 955 scope = window.CustomElements = {flags:{}}; |
| 956 } | 956 } |
| 957 var flags = scope.flags; | 957 var flags = scope.flags; |
| 958 | 958 |
| 959 // native document.registerElement? | 959 // native document.registerElement? |
| 960 | 960 |
| 961 var hasNative = Boolean(document.registerElement); | 961 var hasNative = Boolean(document.registerElement); |
| 962 // TODO(sorvell): See https://github.com/Polymer/polymer/issues/399 | 962 // TODO(sorvell): See https://github.com/Polymer/polymer/issues/399 |
| 963 // we'll address this by defaulting to CE polyfill in the presence of the SD | 963 // we'll address this by defaulting to CE polyfill in the presence of the SD |
| 964 // polyfill. This will avoid spamming excess attached/detached callbacks. | 964 // polyfill. This will avoid spamming excess attached/detached callbacks. |
| 965 // If there is a compelling need to run CE native with SD polyfill, | 965 // If there is a compelling need to run CE native with SD polyfill, |
| 966 // we'll need to fix this issue. | 966 // we'll need to fix this issue. |
| 967 var useNative = !flags.register && hasNative && !window.ShadowDOMPolyfill; | 967 var useNative = !flags.register && hasNative && !window.ShadowDOMPolyfill; |
| 968 | 968 |
| 969 if (useNative) { | 969 if (useNative) { |
| 970 | 970 |
| 971 // stub | 971 // stub |
| 972 var nop = function() {}; | 972 var nop = function() {}; |
| 973 | 973 |
| 974 // exports | 974 // exports |
| 975 scope.registry = {}; | 975 scope.registry = {}; |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 | 1168 |
| 1169 function implement(element, definition) { | 1169 function implement(element, definition) { |
| 1170 // prototype swizzling is best | 1170 // prototype swizzling is best |
| 1171 if (Object.__proto__) { | 1171 if (Object.__proto__) { |
| 1172 element.__proto__ = definition.prototype; | 1172 element.__proto__ = definition.prototype; |
| 1173 } else { | 1173 } else { |
| 1174 // where above we can re-acquire inPrototype via | 1174 // where above we can re-acquire inPrototype via |
| 1175 // getPrototypeOf(Element), we cannot do so when | 1175 // getPrototypeOf(Element), we cannot do so when |
| 1176 // we use mixin, so we install a magic reference | 1176 // we use mixin, so we install a magic reference |
| 1177 customMixin(element, definition.prototype, definition.native); | 1177 customMixin(element, definition.prototype, definition.native); |
| 1178 | |
| 1179 // Dart note: make sure we pick up the right constructor. | |
| 1180 // dart2js depends on this for dart:mirrors caching to work. | |
| 1181 // See tests/html/custom/mirrors_test.dart | |
| 1182 element.constructor = definition.prototype.constructor; | |
| 1183 element.__proto__ = definition.prototype; | 1178 element.__proto__ = definition.prototype; |
| 1184 } | 1179 } |
| 1185 } | 1180 } |
| 1186 | 1181 |
| 1187 function customMixin(inTarget, inSrc, inNative) { | 1182 function customMixin(inTarget, inSrc, inNative) { |
| 1188 // TODO(sjmiles): 'used' allows us to only copy the 'youngest' version of | 1183 // TODO(sjmiles): 'used' allows us to only copy the 'youngest' version of |
| 1189 // any property. This set should be precalculated. We also need to | 1184 // any property. This set should be precalculated. We also need to |
| 1190 // consider this for supporting 'super'. | 1185 // consider this for supporting 'super'. |
| 1191 var used = {}; | 1186 var used = {}; |
| 1192 // start with inSrc | 1187 // start with inSrc |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1517 if (window.CustomElements && !CustomElements.useNative) { | 1512 if (window.CustomElements && !CustomElements.useNative) { |
| 1518 var originalImportNode = Document.prototype.importNode; | 1513 var originalImportNode = Document.prototype.importNode; |
| 1519 Document.prototype.importNode = function(node, deep) { | 1514 Document.prototype.importNode = function(node, deep) { |
| 1520 var imported = originalImportNode.call(this, node, deep); | 1515 var imported = originalImportNode.call(this, node, deep); |
| 1521 CustomElements.upgradeAll(imported); | 1516 CustomElements.upgradeAll(imported); |
| 1522 return imported; | 1517 return imported; |
| 1523 } | 1518 } |
| 1524 } | 1519 } |
| 1525 | 1520 |
| 1526 })(); | 1521 })(); |
| OLD | NEW |