OLD | NEW |
1 if (!HTMLElement.prototype.createShadowRoot | 1 if (!HTMLElement.prototype.createShadowRoot |
2 || window.__forceShadowDomPolyfill) { | 2 || window.__forceShadowDomPolyfill) { |
3 | 3 |
4 /* | 4 /* |
5 * Copyright 2013 The Polymer Authors. All rights reserved. | 5 * Copyright 2013 The Polymer Authors. All rights reserved. |
6 * Use of this source code is governed by a BSD-style | 6 * Use of this source code is governed by a BSD-style |
7 * license that can be found in the LICENSE file. | 7 * license that can be found in the LICENSE file. |
8 */ | 8 */ |
9 (function() { | 9 (function() { |
10 // TODO(jmesserly): fix dart:html to use unprefixed name | 10 // TODO(jmesserly): fix dart:html to use unprefixed name |
(...skipping 14 matching lines...) Expand all Loading... |
25 // | 25 // |
26 // Unless required by applicable law or agreed to in writing, software | 26 // Unless required by applicable law or agreed to in writing, software |
27 // distributed under the License is distributed on an "AS IS" BASIS, | 27 // distributed under the License is distributed on an "AS IS" BASIS, |
28 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 28 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
29 // See the License for the specific language governing permissions and | 29 // See the License for the specific language governing permissions and |
30 // limitations under the License. | 30 // limitations under the License. |
31 | 31 |
32 (function(global) { | 32 (function(global) { |
33 'use strict'; | 33 'use strict'; |
34 | 34 |
| 35 var PROP_ADD_TYPE = 'add'; |
| 36 var PROP_UPDATE_TYPE = 'update'; |
| 37 var PROP_RECONFIGURE_TYPE = 'reconfigure'; |
| 38 var PROP_DELETE_TYPE = 'delete'; |
| 39 var ARRAY_SPLICE_TYPE = 'splice'; |
| 40 |
| 41 // Detect and do basic sanity checking on Object/Array.observe. |
35 function detectObjectObserve() { | 42 function detectObjectObserve() { |
36 if (typeof Object.observe !== 'function' || | 43 if (typeof Object.observe !== 'function' || |
37 typeof Array.observe !== 'function') { | 44 typeof Array.observe !== 'function') { |
38 return false; | 45 return false; |
39 } | 46 } |
40 | 47 |
41 var gotSplice = false; | 48 var records = []; |
42 function callback(records) { | 49 |
43 if (records[0].type === 'splice' && records[1].type === 'splice') | 50 function callback(recs) { |
44 gotSplice = true; | 51 records = recs; |
45 } | 52 } |
46 | 53 |
47 var test = [0]; | 54 var test = {}; |
| 55 Object.observe(test, callback); |
| 56 test.id = 1; |
| 57 test.id = 2; |
| 58 delete test.id; |
| 59 Object.deliverChangeRecords(callback); |
| 60 if (records.length !== 3) |
| 61 return false; |
| 62 |
| 63 // TODO(rafaelw): Remove this when new change record type names make it to |
| 64 // chrome release. |
| 65 if (records[0].type == 'new' && |
| 66 records[1].type == 'updated' && |
| 67 records[2].type == 'deleted') { |
| 68 PROP_ADD_TYPE = 'new'; |
| 69 PROP_UPDATE_TYPE = 'updated'; |
| 70 PROP_RECONFIGURE_TYPE = 'reconfigured'; |
| 71 PROP_DELETE_TYPE = 'deleted'; |
| 72 } else if (records[0].type != 'add' || |
| 73 records[1].type != 'update' || |
| 74 records[2].type != 'delete') { |
| 75 console.error('Unexpected change record names for Object.observe. ' + |
| 76 'Using dirty-checking instead'); |
| 77 return false; |
| 78 } |
| 79 Object.unobserve(test, callback); |
| 80 |
| 81 test = [0]; |
48 Array.observe(test, callback); | 82 Array.observe(test, callback); |
49 test[1] = 1; | 83 test[1] = 1; |
50 test.length = 0; | 84 test.length = 0; |
51 Object.deliverChangeRecords(callback); | 85 Object.deliverChangeRecords(callback); |
52 return gotSplice; | 86 if (records.length != 2) |
| 87 return false; |
| 88 if (records[0].type != ARRAY_SPLICE_TYPE || |
| 89 records[1].type != ARRAY_SPLICE_TYPE) { |
| 90 return false; |
| 91 } |
| 92 Array.unobserve(test, callback); |
| 93 |
| 94 return true; |
53 } | 95 } |
54 | 96 |
55 var hasObserve = detectObjectObserve(); | 97 var hasObserve = detectObjectObserve(); |
56 | 98 |
57 function detectEval() { | 99 function detectEval() { |
58 // don't test for eval if document has CSP securityPolicy object and we can
see that | 100 // don't test for eval if document has CSP securityPolicy object and we can
see that |
59 // eval is not supported. This avoids an error message in console even when
the exception | 101 // eval is not supported. This avoids an error message in console even when
the exception |
60 // is caught | 102 // is caught |
61 if (global.document && | 103 if (global.document && |
62 'securityPolicy' in global.document && | 104 'securityPolicy' in global.document && |
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 object.close(); | 871 object.close(); |
830 } | 872 } |
831 this.observed = undefined; | 873 this.observed = undefined; |
832 this.values = undefined; | 874 this.values = undefined; |
833 } | 875 } |
834 | 876 |
835 Observer.prototype.close.call(this); | 877 Observer.prototype.close.call(this); |
836 } | 878 } |
837 }); | 879 }); |
838 | 880 |
839 var knownRecordTypes = { | 881 var expectedRecordTypes = {}; |
840 'new': true, | 882 expectedRecordTypes[PROP_ADD_TYPE] = true; |
841 'updated': true, | 883 expectedRecordTypes[PROP_UPDATE_TYPE] = true; |
842 'deleted': true | 884 expectedRecordTypes[PROP_DELETE_TYPE] = true; |
843 }; | |
844 | 885 |
845 function notifyFunction(object, name) { | 886 function notifyFunction(object, name) { |
846 if (typeof Object.observe !== 'function') | 887 if (typeof Object.observe !== 'function') |
847 return; | 888 return; |
848 | 889 |
849 var notifier = Object.getNotifier(object); | 890 var notifier = Object.getNotifier(object); |
850 return function(type, oldValue) { | 891 return function(type, oldValue) { |
851 var changeRecord = { | 892 var changeRecord = { |
852 object: object, | 893 object: object, |
853 type: type, | 894 type: type, |
(...skipping 11 matching lines...) Expand all Loading... |
865 // to any dependent value will be observed. | 906 // to any dependent value will be observed. |
866 PathObserver.defineProperty = function(object, name, descriptor) { | 907 PathObserver.defineProperty = function(object, name, descriptor) { |
867 // TODO(rafaelw): Validate errors | 908 // TODO(rafaelw): Validate errors |
868 var obj = descriptor.object; | 909 var obj = descriptor.object; |
869 var path = getPath(descriptor.path); | 910 var path = getPath(descriptor.path); |
870 var notify = notifyFunction(object, name); | 911 var notify = notifyFunction(object, name); |
871 | 912 |
872 var observer = new PathObserver(obj, descriptor.path, | 913 var observer = new PathObserver(obj, descriptor.path, |
873 function(newValue, oldValue) { | 914 function(newValue, oldValue) { |
874 if (notify) | 915 if (notify) |
875 notify('updated', oldValue); | 916 notify(PROP_UPDATE_TYPE, oldValue); |
876 } | 917 } |
877 ); | 918 ); |
878 | 919 |
879 Object.defineProperty(object, name, { | 920 Object.defineProperty(object, name, { |
880 get: function() { | 921 get: function() { |
881 return path.getValueFrom(obj); | 922 return path.getValueFrom(obj); |
882 }, | 923 }, |
883 set: function(newValue) { | 924 set: function(newValue) { |
884 path.setValueFrom(obj, newValue); | 925 path.setValueFrom(obj, newValue); |
885 }, | 926 }, |
(...skipping 14 matching lines...) Expand all Loading... |
900 } | 941 } |
901 }; | 942 }; |
902 } | 943 } |
903 | 944 |
904 function diffObjectFromChangeRecords(object, changeRecords, oldValues) { | 945 function diffObjectFromChangeRecords(object, changeRecords, oldValues) { |
905 var added = {}; | 946 var added = {}; |
906 var removed = {}; | 947 var removed = {}; |
907 | 948 |
908 for (var i = 0; i < changeRecords.length; i++) { | 949 for (var i = 0; i < changeRecords.length; i++) { |
909 var record = changeRecords[i]; | 950 var record = changeRecords[i]; |
910 if (!knownRecordTypes[record.type]) { | 951 if (!expectedRecordTypes[record.type]) { |
911 console.error('Unknown changeRecord type: ' + record.type); | 952 console.error('Unknown changeRecord type: ' + record.type); |
912 console.error(record); | 953 console.error(record); |
913 continue; | 954 continue; |
914 } | 955 } |
915 | 956 |
916 if (!(record.name in oldValues)) | 957 if (!(record.name in oldValues)) |
917 oldValues[record.name] = record.oldValue; | 958 oldValues[record.name] = record.oldValue; |
918 | 959 |
919 if (record.type == 'updated') | 960 if (record.type == PROP_UPDATE_TYPE) |
920 continue; | 961 continue; |
921 | 962 |
922 if (record.type == 'new') { | 963 if (record.type == PROP_ADD_TYPE) { |
923 if (record.name in removed) | 964 if (record.name in removed) |
924 delete removed[record.name]; | 965 delete removed[record.name]; |
925 else | 966 else |
926 added[record.name] = true; | 967 added[record.name] = true; |
927 | 968 |
928 continue; | 969 continue; |
929 } | 970 } |
930 | 971 |
931 // type = 'deleted' | 972 // type = 'delete' |
932 if (record.name in added) { | 973 if (record.name in added) { |
933 delete added[record.name]; | 974 delete added[record.name]; |
934 delete oldValues[record.name]; | 975 delete oldValues[record.name]; |
935 } else { | 976 } else { |
936 removed[record.name] = true; | 977 removed[record.name] = true; |
937 } | 978 } |
938 } | 979 } |
939 | 980 |
940 for (var prop in added) | 981 for (var prop in added) |
941 added[prop] = object[prop]; | 982 added[prop] = object[prop]; |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1309 if (!inserted) | 1350 if (!inserted) |
1310 splices.push(splice); | 1351 splices.push(splice); |
1311 } | 1352 } |
1312 | 1353 |
1313 function createInitialSplices(array, changeRecords) { | 1354 function createInitialSplices(array, changeRecords) { |
1314 var splices = []; | 1355 var splices = []; |
1315 | 1356 |
1316 for (var i = 0; i < changeRecords.length; i++) { | 1357 for (var i = 0; i < changeRecords.length; i++) { |
1317 var record = changeRecords[i]; | 1358 var record = changeRecords[i]; |
1318 switch(record.type) { | 1359 switch(record.type) { |
1319 case 'splice': | 1360 case ARRAY_SPLICE_TYPE: |
1320 mergeSplice(splices, record.index, record.removed.slice(), record.adde
dCount); | 1361 mergeSplice(splices, record.index, record.removed.slice(), record.adde
dCount); |
1321 break; | 1362 break; |
1322 case 'new': | 1363 case PROP_ADD_TYPE: |
1323 case 'updated': | 1364 case PROP_UPDATE_TYPE: |
1324 case 'deleted': | 1365 case PROP_DELETE_TYPE: |
1325 if (!isIndex(record.name)) | 1366 if (!isIndex(record.name)) |
1326 continue; | 1367 continue; |
1327 var index = toNumber(record.name); | 1368 var index = toNumber(record.name); |
1328 if (index < 0) | 1369 if (index < 0) |
1329 continue; | 1370 continue; |
1330 mergeSplice(splices, index, [record.oldValue], 1); | 1371 mergeSplice(splices, index, [record.oldValue], 1); |
1331 break; | 1372 break; |
1332 default: | 1373 default: |
1333 console.error('Unexpected record type: ' + JSON.stringify(record)); | 1374 console.error('Unexpected record type: ' + JSON.stringify(record)); |
1334 break; | 1375 break; |
(...skipping 26 matching lines...) Expand all Loading... |
1361 global.ArrayObserver = ArrayObserver; | 1402 global.ArrayObserver = ArrayObserver; |
1362 global.ArrayObserver.calculateSplices = function(current, previous) { | 1403 global.ArrayObserver.calculateSplices = function(current, previous) { |
1363 return arraySplice.calculateSplices(current, previous); | 1404 return arraySplice.calculateSplices(current, previous); |
1364 }; | 1405 }; |
1365 | 1406 |
1366 global.ArraySplice = ArraySplice; | 1407 global.ArraySplice = ArraySplice; |
1367 global.ObjectObserver = ObjectObserver; | 1408 global.ObjectObserver = ObjectObserver; |
1368 global.PathObserver = PathObserver; | 1409 global.PathObserver = PathObserver; |
1369 global.CompoundPathObserver = CompoundPathObserver; | 1410 global.CompoundPathObserver = CompoundPathObserver; |
1370 global.Path = Path; | 1411 global.Path = Path; |
| 1412 |
| 1413 // TODO(rafaelw): Only needed for testing until new change record names |
| 1414 // make it to release. |
| 1415 global.Observer.changeRecordTypes = { |
| 1416 add: PROP_ADD_TYPE, |
| 1417 update: PROP_UPDATE_TYPE, |
| 1418 reconfigure: PROP_RECONFIGURE_TYPE, |
| 1419 'delete': PROP_DELETE_TYPE, |
| 1420 splice: ARRAY_SPLICE_TYPE |
| 1421 }; |
1371 })(typeof global !== 'undefined' && global ? global : this); | 1422 })(typeof global !== 'undefined' && global ? global : this); |
1372 | 1423 |
1373 /* | 1424 /* |
1374 * Copyright 2012 The Polymer Authors. All rights reserved. | 1425 * Copyright 2012 The Polymer Authors. All rights reserved. |
1375 * Use of this source code is governed by a BSD-style | 1426 * Use of this source code is governed by a BSD-style |
1376 * license that can be found in the LICENSE file. | 1427 * license that can be found in the LICENSE file. |
1377 */ | 1428 */ |
1378 | 1429 |
1379 if (typeof WeakMap === 'undefined') { | 1430 if (typeof WeakMap === 'undefined') { |
1380 (function() { | 1431 (function() { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1423 // Don't test for eval if document has CSP securityPolicy object and we can | 1474 // Don't test for eval if document has CSP securityPolicy object and we can |
1424 // see that eval is not supported. This avoids an error message in console | 1475 // see that eval is not supported. This avoids an error message in console |
1425 // even when the exception is caught | 1476 // even when the exception is caught |
1426 var hasEval = !('securityPolicy' in document) || | 1477 var hasEval = !('securityPolicy' in document) || |
1427 document.securityPolicy.allowsEval; | 1478 document.securityPolicy.allowsEval; |
1428 if (hasEval) { | 1479 if (hasEval) { |
1429 try { | 1480 try { |
1430 var f = new Function('', 'return true;'); | 1481 var f = new Function('', 'return true;'); |
1431 hasEval = f(); | 1482 hasEval = f(); |
1432 } catch (ex) { | 1483 } catch (ex) { |
| 1484 hasEval = false; |
1433 } | 1485 } |
1434 } | 1486 } |
1435 | 1487 |
1436 function assert(b) { | 1488 function assert(b) { |
1437 if (!b) | 1489 if (!b) |
1438 throw new Error('Assertion failed'); | 1490 throw new Error('Assertion failed'); |
1439 }; | 1491 }; |
1440 | 1492 |
1441 function mixin(to, from) { | 1493 function mixin(to, from) { |
1442 Object.getOwnPropertyNames(from).forEach(function(name) { | 1494 Object.getOwnPropertyNames(from).forEach(function(name) { |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1773 scope.registerObject = registerObject; | 1825 scope.registerObject = registerObject; |
1774 scope.registerWrapper = register; | 1826 scope.registerWrapper = register; |
1775 scope.rewrap = rewrap; | 1827 scope.rewrap = rewrap; |
1776 scope.unwrap = unwrap; | 1828 scope.unwrap = unwrap; |
1777 scope.unwrapIfNeeded = unwrapIfNeeded; | 1829 scope.unwrapIfNeeded = unwrapIfNeeded; |
1778 scope.wrap = wrap; | 1830 scope.wrap = wrap; |
1779 scope.wrapIfNeeded = wrapIfNeeded; | 1831 scope.wrapIfNeeded = wrapIfNeeded; |
1780 scope.wrappers = wrappers; | 1832 scope.wrappers = wrappers; |
1781 | 1833 |
1782 })(this.ShadowDOMPolyfill); | 1834 })(this.ShadowDOMPolyfill); |
| 1835 |
1783 // Copyright 2013 The Polymer Authors. All rights reserved. | 1836 // Copyright 2013 The Polymer Authors. All rights reserved. |
1784 // Use of this source code is goverened by a BSD-style | 1837 // Use of this source code is goverened by a BSD-style |
1785 // license that can be found in the LICENSE file. | 1838 // license that can be found in the LICENSE file. |
1786 | 1839 |
1787 (function(scope) { | 1840 (function(scope) { |
1788 'use strict'; | 1841 'use strict'; |
1789 | 1842 |
1790 var forwardMethodsToWrapper = scope.forwardMethodsToWrapper; | 1843 var forwardMethodsToWrapper = scope.forwardMethodsToWrapper; |
1791 var mixin = scope.mixin; | 1844 var mixin = scope.mixin; |
1792 var registerWrapper = scope.registerWrapper; | 1845 var registerWrapper = scope.registerWrapper; |
(...skipping 3072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4865 ].forEach(function(name) { | 4918 ].forEach(function(name) { |
4866 var f = prototype[name]; | 4919 var f = prototype[name]; |
4867 if (!f) | 4920 if (!f) |
4868 return; | 4921 return; |
4869 newPrototype[name] = function() { | 4922 newPrototype[name] = function() { |
4870 f.apply(wrap(this), arguments); | 4923 f.apply(wrap(this), arguments); |
4871 }; | 4924 }; |
4872 }); | 4925 }); |
4873 | 4926 |
4874 var nativeConstructor = originalRegister.call(unwrap(this), tagName, | 4927 var nativeConstructor = originalRegister.call(unwrap(this), tagName, |
| 4928 object.extends ? {prototype: newPrototype, extends: object.extends} : |
4875 {prototype: newPrototype}); | 4929 {prototype: newPrototype}); |
4876 | 4930 |
4877 function GeneratedWrapper(node) { | 4931 function GeneratedWrapper(node) { |
4878 if (!node) | 4932 if (!node) |
4879 return document.createElement(tagName); | 4933 return document.createElement(tagName); |
4880 this.impl = node; | 4934 this.impl = node; |
4881 } | 4935 } |
4882 GeneratedWrapper.prototype = prototype; | 4936 GeneratedWrapper.prototype = prototype; |
4883 GeneratedWrapper.prototype.constructor = GeneratedWrapper; | 4937 GeneratedWrapper.prototype.constructor = GeneratedWrapper; |
4884 | 4938 |
(...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5983 var head = document.querySelector('head'); | 6037 var head = document.querySelector('head'); |
5984 head.insertBefore(getSheet(), head.childNodes[0]); | 6038 head.insertBefore(getSheet(), head.childNodes[0]); |
5985 } | 6039 } |
5986 | 6040 |
5987 // exports | 6041 // exports |
5988 scope.ShadowCSS = ShadowCSS; | 6042 scope.ShadowCSS = ShadowCSS; |
5989 | 6043 |
5990 })(window.Platform); | 6044 })(window.Platform); |
5991 | 6045 |
5992 } | 6046 } |
OLD | NEW |