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:
Christoph Nakazawa
2019-04-04 10:49:06 -07:00
committed by Facebook Github Bot
parent d9a82221a4
commit c36151ecef
4 changed files with 0 additions and 46 deletions

View File

@@ -14,8 +14,6 @@ const {freeze, seal, preventExtensions} = Object;
function setup() {
jest.setMock('../../vendor/core/_shouldPolyfillES6Collection', () => true);
jest.unmock('_wrapObjectFreezeAndFriends');
require('_wrapObjectFreezeAndFriends');
}
function cleanup() {

View File

@@ -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'));
}

View File

@@ -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;
/**

View File

@@ -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);
}
};
}
});