|
811 | 811 | }
|
812 | 812 |
|
813 | 813 | function hashJSObj(obj) {
|
814 |
| - var hash = weakMap && weakMap.get(obj); |
815 |
| - if (hash) return hash; |
| 814 | + var hash; |
| 815 | + if (usingWeakMap) { |
| 816 | + hash = weakMap.get(obj); |
| 817 | + if (hash !== undefined) { |
| 818 | + return hash; |
| 819 | + } |
| 820 | + } |
816 | 821 |
|
817 | 822 | hash = obj[UID_HASH_KEY];
|
818 |
| - if (hash) return hash; |
| 823 | + if (hash !== undefined) { |
| 824 | + return hash; |
| 825 | + } |
819 | 826 |
|
820 | 827 | if (!canDefineProperty) {
|
821 | 828 | hash = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
|
822 |
| - if (hash) return hash; |
| 829 | + if (hash !== undefined) { |
| 830 | + return hash; |
| 831 | + } |
823 | 832 |
|
824 | 833 | hash = getIENodeHash(obj);
|
825 |
| - if (hash) return hash; |
| 834 | + if (hash !== undefined) { |
| 835 | + return hash; |
| 836 | + } |
826 | 837 | }
|
827 | 838 |
|
828 |
| - if (Object.isExtensible && !Object.isExtensible(obj)) { |
| 839 | + if (!usingWeakMap && |
| 840 | + typeof Object.isExtensible === 'function' && |
| 841 | + Object.isExtensible(obj) === false) { |
829 | 842 | throw new Error('Non-extensible objects are not allowed as keys.');
|
830 | 843 | }
|
831 | 844 |
|
|
834 | 847 | objHashUID = 0;
|
835 | 848 | }
|
836 | 849 |
|
837 |
| - if (weakMap) { |
| 850 | + if (usingWeakMap) { |
838 | 851 | weakMap.set(obj, hash);
|
839 | 852 | } else if (canDefineProperty) {
|
840 | 853 | Object.defineProperty(obj, UID_HASH_KEY, {
|
|
843 | 856 | 'writable': false,
|
844 | 857 | 'value': hash
|
845 | 858 | });
|
846 |
| - } else if (obj.propertyIsEnumerable && |
| 859 | + } else if (obj.propertyIsEnumerable !== undefined && |
847 | 860 | obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
|
848 | 861 | // Since we can't define a non-enumerable property on the object
|
849 | 862 | // we'll hijack one of the less-used non-enumerable properties to
|
|
853 | 866 | return this.constructor.prototype.propertyIsEnumerable.apply(this, arguments);
|
854 | 867 | };
|
855 | 868 | obj.propertyIsEnumerable[UID_HASH_KEY] = hash;
|
856 |
| - } else if (obj.nodeType) { |
| 869 | + } else if (obj.nodeType !== undefined) { |
857 | 870 | // At this point we couldn't get the IE `uniqueID` to use as a hash
|
858 | 871 | // and we couldn't use a non-enumerable property to exploit the
|
859 | 872 | // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
|
|
890 | 903 | }
|
891 | 904 |
|
892 | 905 | // If possible, use a WeakMap.
|
893 |
| - var weakMap = typeof WeakMap === 'function' && new WeakMap(); |
| 906 | + var usingWeakMap = typeof WeakMap === 'function'; |
| 907 | + var weakMap; |
| 908 | + if (usingWeakMap) { |
| 909 | + weakMap = new WeakMap(); |
| 910 | + } |
894 | 911 |
|
895 | 912 | var objHashUID = 0;
|
896 | 913 |
|
|
0 commit comments