mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-06 17:34:07 +08:00
Do not overwrite Object.freeze
Summary: Now that React Native ships with a newer version of JSC, we do not need this code to wrap `Object.freeze` any longer. Reviewed By: mmmulani Differential Revision: D14779239 fbshipit-source-id: 1a6e1a9c7f4312572bd08ba604fa8c9d6b1927e1
This commit is contained in:
committed by
Facebook Github Bot
parent
d9a82221a4
commit
c36151ecef
@@ -14,8 +14,6 @@ const {freeze, seal, preventExtensions} = Object;
|
||||
|
||||
function setup() {
|
||||
jest.setMock('../../vendor/core/_shouldPolyfillES6Collection', () => true);
|
||||
jest.unmock('_wrapObjectFreezeAndFriends');
|
||||
require('_wrapObjectFreezeAndFriends');
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
|
||||
@@ -18,10 +18,8 @@ const {polyfillGlobal} = require('PolyfillFunctions');
|
||||
*/
|
||||
const _shouldPolyfillCollection = require('_shouldPolyfillES6Collection');
|
||||
if (_shouldPolyfillCollection('Map')) {
|
||||
require('_wrapObjectFreezeAndFriends');
|
||||
polyfillGlobal('Map', () => require('Map'));
|
||||
}
|
||||
if (_shouldPolyfillCollection('Set')) {
|
||||
require('_wrapObjectFreezeAndFriends');
|
||||
polyfillGlobal('Set', () => require('Set'));
|
||||
}
|
||||
|
||||
3
Libraries/vendor/core/Map.js
vendored
3
Libraries/vendor/core/Map.js
vendored
@@ -26,9 +26,6 @@ module.exports = (function(global, undefined) {
|
||||
return global.Map;
|
||||
}
|
||||
|
||||
// In case this module has not already been evaluated, import it now.
|
||||
require('./_wrapObjectFreezeAndFriends');
|
||||
|
||||
const hasOwn = Object.prototype.hasOwnProperty;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @author Ben Newman (@benjamn) <ben@benjamn.com>
|
||||
* @flow
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
let testMap; // Initialized lazily.
|
||||
function getTestMap() {
|
||||
return testMap || (testMap = new (require('./Map'))());
|
||||
}
|
||||
|
||||
// Wrap Object.{freeze,seal,preventExtensions} so each function adds its
|
||||
// argument to a Map first, which gives our ./Map.js polyfill a chance to
|
||||
// tag the object before it becomes non-extensible.
|
||||
['freeze', 'seal', 'preventExtensions'].forEach(name => {
|
||||
const method = Object[name];
|
||||
if (typeof method === 'function') {
|
||||
(Object: any)[name] = function(obj) {
|
||||
try {
|
||||
// If .set succeeds, also call .delete to avoid leaking memory.
|
||||
getTestMap()
|
||||
.set(obj, obj)
|
||||
.delete(obj);
|
||||
} finally {
|
||||
// If .set fails, the exception will be silently swallowed
|
||||
// by this return-from-finally statement, and the method will
|
||||
// behave exactly as it did before it was wrapped.
|
||||
return method.call(Object, obj);
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user