mirror of
https://github.com/status-im/react-native.git
synced 2025-02-23 14:48:25 +00:00
Remove isNode call from Map polyfill
Summary: There are no DOM Nodes in React Native so our Map polyfill does not need to consider that use case. I deleted the references to `isNode` and `IE. In case this is important for react-native-web, I suggest to shim the Map polyfill with an IE compatible one outside of react-native. Reviewed By: yungsters Differential Revision: D13138030 fbshipit-source-id: 661511ea03b4477bd55d0fdf5e485178fe59d96b
This commit is contained in:
parent
dc8246d56e
commit
f377926677
42
Libraries/vendor/core/Map.js
vendored
42
Libraries/vendor/core/Map.js
vendored
@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
const _shouldPolyfillES6Collection = require('_shouldPolyfillES6Collection');
|
const _shouldPolyfillES6Collection = require('_shouldPolyfillES6Collection');
|
||||||
const guid = require('guid');
|
const guid = require('guid');
|
||||||
const isNode = require('fbjs/lib/isNode');
|
|
||||||
const toIterator = require('toIterator');
|
const toIterator = require('toIterator');
|
||||||
|
|
||||||
module.exports = (function(global, undefined) {
|
module.exports = (function(global, undefined) {
|
||||||
@ -97,9 +96,6 @@ module.exports = (function(global, undefined) {
|
|||||||
SECRET_SIZE_PROP = '$size' + guid();
|
SECRET_SIZE_PROP = '$size' + guid();
|
||||||
}
|
}
|
||||||
|
|
||||||
// In oldIE we use the DOM Node `uniqueID` property to get create the hash.
|
|
||||||
const OLD_IE_HASH_PREFIX = 'IE_HASH_';
|
|
||||||
|
|
||||||
class Map {
|
class Map {
|
||||||
/**
|
/**
|
||||||
* 23.1.1.1
|
* 23.1.1.1
|
||||||
@ -523,34 +519,6 @@ module.exports = (function(global, undefined) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* IE has a `uniqueID` set on every DOM node. So we construct the hash from
|
|
||||||
* this uniqueID to avoid memory leaks and the IE cloneNode bug where it
|
|
||||||
* clones properties in addition to the attributes.
|
|
||||||
*
|
|
||||||
* @param {object} node
|
|
||||||
* @return {?string}
|
|
||||||
*/
|
|
||||||
function getIENodeHash(node) {
|
|
||||||
let uniqueID;
|
|
||||||
switch (node.nodeType) {
|
|
||||||
case 1: // Element
|
|
||||||
uniqueID = node.uniqueID;
|
|
||||||
break;
|
|
||||||
case 9: // Document
|
|
||||||
uniqueID = node.documentElement.uniqueID;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (uniqueID) {
|
|
||||||
return OLD_IE_HASH_PREFIX + uniqueID;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const getHash = (function() {
|
const getHash = (function() {
|
||||||
const propIsEnumerable = Object.prototype.propertyIsEnumerable;
|
const propIsEnumerable = Object.prototype.propertyIsEnumerable;
|
||||||
const hashProperty = '__MAP_POLYFILL_INTERNAL_HASH__';
|
const hashProperty = '__MAP_POLYFILL_INTERNAL_HASH__';
|
||||||
@ -572,8 +540,6 @@ module.exports = (function(global, undefined) {
|
|||||||
o.propertyIsEnumerable[hashProperty]
|
o.propertyIsEnumerable[hashProperty]
|
||||||
) {
|
) {
|
||||||
return o.propertyIsEnumerable[hashProperty];
|
return o.propertyIsEnumerable[hashProperty];
|
||||||
} else if (!isES5 && isNode(o) && getIENodeHash(o)) {
|
|
||||||
return getIENodeHash(o);
|
|
||||||
} else if (!isES5 && o[hashProperty]) {
|
} else if (!isES5 && o[hashProperty]) {
|
||||||
return o[hashProperty];
|
return o[hashProperty];
|
||||||
}
|
}
|
||||||
@ -590,18 +556,12 @@ module.exports = (function(global, undefined) {
|
|||||||
} else if (o.propertyIsEnumerable) {
|
} else if (o.propertyIsEnumerable) {
|
||||||
// Since we can't define a non-enumerable property on the object
|
// Since we can't define a non-enumerable property on the object
|
||||||
// we'll hijack one of the less-used non-enumerable properties to
|
// we'll hijack one of the less-used non-enumerable properties to
|
||||||
// save our hash on it. Addiotionally, since this is a function it
|
// save our hash on it. Additionally, since this is a function it
|
||||||
// will not show up in `JSON.stringify` which is what we want.
|
// will not show up in `JSON.stringify` which is what we want.
|
||||||
o.propertyIsEnumerable = function() {
|
o.propertyIsEnumerable = function() {
|
||||||
return propIsEnumerable.apply(this, arguments);
|
return propIsEnumerable.apply(this, arguments);
|
||||||
};
|
};
|
||||||
o.propertyIsEnumerable[hashProperty] = hashCounter;
|
o.propertyIsEnumerable[hashProperty] = hashCounter;
|
||||||
} else if (isNode(o)) {
|
|
||||||
// At this point we couldn't get the IE `uniqueID` to use as a hash
|
|
||||||
// and we couldn't use a non-enumerable property to exploit the
|
|
||||||
// dontEnum bug so we simply add the `hashProperty` on the node
|
|
||||||
// itself.
|
|
||||||
o[hashProperty] = hashCounter;
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Unable to set a non-enumerable property on object.');
|
throw new Error('Unable to set a non-enumerable property on object.');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user