| OLD | NEW |
| 1 // Copyright 2012 Google Inc. | 1 /* |
| 2 // | 2 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 * This code may only be used under the BSD style license found at http://polyme
r.github.io/LICENSE.txt |
| 4 // you may not use this file except in compliance with the License. | 4 * The complete set of authors may be found at http://polymer.github.io/AUTHORS.
txt |
| 5 // You may obtain a copy of the License at | 5 * The complete set of contributors may be found at http://polymer.github.io/CON
TRIBUTORS.txt |
| 6 // | 6 * Code distributed by Google as part of the polymer project is also |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 * subject to an additional IP rights grant found at http://polymer.github.io/PA
TENTS.txt |
| 8 // | 8 */ |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 | 9 |
| 15 (function(global) { | 10 (function(global) { |
| 16 'use strict'; | 11 'use strict'; |
| 17 | 12 |
| 18 var testingExposeCycleCount = global.testingExposeCycleCount; | 13 var testingExposeCycleCount = global.testingExposeCycleCount; |
| 19 | 14 |
| 20 // Detect and do basic sanity checking on Object/Array.observe. | 15 // Detect and do basic sanity checking on Object/Array.observe. |
| 21 function detectObjectObserve() { | 16 function detectObjectObserve() { |
| 22 if (typeof Object.observe !== 'function' || | 17 if (typeof Object.observe !== 'function' || |
| 23 typeof Array.observe !== 'function') { | 18 typeof Array.observe !== 'function') { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 function detectEval() { | 58 function detectEval() { |
| 64 // Don't test for eval if we're running in a Chrome App environment. | 59 // Don't test for eval if we're running in a Chrome App environment. |
| 65 // We check for APIs set that only exist in a Chrome App context. | 60 // We check for APIs set that only exist in a Chrome App context. |
| 66 if (typeof chrome !== 'undefined' && chrome.app && chrome.app.runtime) { | 61 if (typeof chrome !== 'undefined' && chrome.app && chrome.app.runtime) { |
| 67 return false; | 62 return false; |
| 68 } | 63 } |
| 69 | 64 |
| 70 // Firefox OS Apps do not allow eval. This feature detection is very hacky | 65 // Firefox OS Apps do not allow eval. This feature detection is very hacky |
| 71 // but even if some other platform adds support for this function this code | 66 // but even if some other platform adds support for this function this code |
| 72 // will continue to work. | 67 // will continue to work. |
| 73 if (navigator.getDeviceStorage) { | 68 if (typeof navigator != 'undefined' && navigator.getDeviceStorage) { |
| 74 return false; | 69 return false; |
| 75 } | 70 } |
| 76 | 71 |
| 77 try { | 72 try { |
| 78 var f = new Function('', 'return true;'); | 73 var f = new Function('', 'return true;'); |
| 79 return f(); | 74 return f(); |
| 80 } catch (ex) { | 75 } catch (ex) { |
| 81 return false; | 76 return false; |
| 82 } | 77 } |
| 83 } | 78 } |
| 84 | 79 |
| 85 var hasEval = detectEval(); | 80 var hasEval = detectEval(); |
| 86 | 81 |
| 87 function isIndex(s) { | 82 function isIndex(s) { |
| 88 return +s === s >>> 0; | 83 return +s === s >>> 0 && s !== ''; |
| 89 } | 84 } |
| 90 | 85 |
| 91 function toNumber(s) { | 86 function toNumber(s) { |
| 92 return +s; | 87 return +s; |
| 93 } | 88 } |
| 94 | 89 |
| 95 function isObject(obj) { | 90 function isObject(obj) { |
| 96 return obj === Object(obj); | 91 return obj === Object(obj); |
| 97 } | 92 } |
| 98 | 93 |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 | 787 |
| 793 allObservers.push(observer); | 788 allObservers.push(observer); |
| 794 } | 789 } |
| 795 | 790 |
| 796 function removeFromAll(observer) { | 791 function removeFromAll(observer) { |
| 797 Observer._allObserversCount--; | 792 Observer._allObserversCount--; |
| 798 } | 793 } |
| 799 | 794 |
| 800 var runningMicrotaskCheckpoint = false; | 795 var runningMicrotaskCheckpoint = false; |
| 801 | 796 |
| 802 var hasDebugForceFullDelivery = hasObserve && hasEval && (function() { | |
| 803 try { | |
| 804 eval('%RunMicrotasks()'); | |
| 805 return true; | |
| 806 } catch (ex) { | |
| 807 return false; | |
| 808 } | |
| 809 })(); | |
| 810 | |
| 811 global.Platform = global.Platform || {}; | 797 global.Platform = global.Platform || {}; |
| 812 | 798 |
| 813 global.Platform.performMicrotaskCheckpoint = function() { | 799 global.Platform.performMicrotaskCheckpoint = function() { |
| 814 if (runningMicrotaskCheckpoint) | 800 if (runningMicrotaskCheckpoint) |
| 815 return; | 801 return; |
| 816 | 802 |
| 817 if (hasDebugForceFullDelivery) { | |
| 818 eval('%RunMicrotasks()'); | |
| 819 return; | |
| 820 } | |
| 821 | |
| 822 if (!collectObservers) | 803 if (!collectObservers) |
| 823 return; | 804 return; |
| 824 | 805 |
| 825 runningMicrotaskCheckpoint = true; | 806 runningMicrotaskCheckpoint = true; |
| 826 | 807 |
| 827 var cycles = 0; | 808 var cycles = 0; |
| 828 var anyChanged, toCheck; | 809 var anyChanged, toCheck; |
| 829 | 810 |
| 830 do { | 811 do { |
| 831 cycles++; | 812 cycles++; |
| (...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1718 return arraySplice.calculateSplices(current, previous); | 1699 return arraySplice.calculateSplices(current, previous); |
| 1719 }; | 1700 }; |
| 1720 | 1701 |
| 1721 global.ArraySplice = ArraySplice; | 1702 global.ArraySplice = ArraySplice; |
| 1722 global.ObjectObserver = ObjectObserver; | 1703 global.ObjectObserver = ObjectObserver; |
| 1723 global.PathObserver = PathObserver; | 1704 global.PathObserver = PathObserver; |
| 1724 global.CompoundObserver = CompoundObserver; | 1705 global.CompoundObserver = CompoundObserver; |
| 1725 global.Path = Path; | 1706 global.Path = Path; |
| 1726 global.ObserverTransform = ObserverTransform; | 1707 global.ObserverTransform = ObserverTransform; |
| 1727 })(typeof global !== 'undefined' && global && typeof module !== 'undefined' && m
odule ? global : this || window); | 1708 })(typeof global !== 'undefined' && global && typeof module !== 'undefined' && m
odule ? global : this || window); |
| OLD | NEW |