-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
@build-break Back out "[RN] Remove Map/Set from RN Open Source"
Summary: Backing out D14786123 as it's causing failures on fbandroid/stable. Differential Revision: D15693250 Ninja: sheriff fbshipit-source-id: 526054d4f0dab2a811f2328540e7418ece9810b1
- Loading branch information
1 parent
bdc530b
commit 63bc4b4
Showing
8 changed files
with
1,060 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/** | ||
* 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. | ||
* | ||
* @format | ||
* @emails oncall+react_native | ||
*/ | ||
'use strict'; | ||
|
||
// Save these methods so that we can restore them afterward. | ||
const {freeze, seal, preventExtensions} = Object; | ||
|
||
function setup() { | ||
jest.setMock('../../vendor/core/_shouldPolyfillES6Collection', () => true); | ||
} | ||
|
||
function cleanup() { | ||
Object.assign(Object, {freeze, seal, preventExtensions}); | ||
} | ||
|
||
describe('Map polyfill', () => { | ||
setup(); | ||
|
||
const Map = require('../../vendor/core/Map'); | ||
|
||
it('is not native', () => { | ||
const getCode = Function.prototype.toString.call(Map.prototype.get); | ||
expect(getCode).not.toContain('[native code]'); | ||
expect(getCode).toContain('getIndex'); | ||
}); | ||
|
||
it('should tolerate non-extensible object keys', () => { | ||
const map = new Map(); | ||
const key = Object.create(null); | ||
Object.freeze(key); | ||
map.set(key, key); | ||
expect(map.size).toBe(1); | ||
expect(map.has(key)).toBe(true); | ||
map.delete(key); | ||
expect(map.size).toBe(0); | ||
expect(map.has(key)).toBe(false); | ||
}); | ||
|
||
it('should not get confused by prototypal inheritance', () => { | ||
const map = new Map(); | ||
const proto = Object.create(null); | ||
const base = Object.create(proto); | ||
map.set(proto, proto); | ||
expect(map.size).toBe(1); | ||
expect(map.has(proto)).toBe(true); | ||
expect(map.has(base)).toBe(false); | ||
map.set(base, base); | ||
expect(map.size).toBe(2); | ||
expect(map.get(proto)).toBe(proto); | ||
expect(map.get(base)).toBe(base); | ||
}); | ||
|
||
afterAll(cleanup); | ||
}); | ||
|
||
describe('Set polyfill', () => { | ||
setup(); | ||
|
||
const Set = require('../../vendor/core/Set'); | ||
|
||
it('is not native', () => { | ||
const addCode = Function.prototype.toString.call(Set.prototype.add); | ||
expect(addCode).not.toContain('[native code]'); | ||
}); | ||
|
||
it('should tolerate non-extensible object elements', () => { | ||
const set = new Set(); | ||
const elem = Object.create(null); | ||
Object.freeze(elem); | ||
set.add(elem); | ||
expect(set.size).toBe(1); | ||
expect(set.has(elem)).toBe(true); | ||
set.add(elem); | ||
expect(set.size).toBe(1); | ||
set.delete(elem); | ||
expect(set.size).toBe(0); | ||
expect(set.has(elem)).toBe(false); | ||
}); | ||
|
||
it('should not get confused by prototypal inheritance', () => { | ||
const set = new Set(); | ||
const proto = Object.create(null); | ||
const base = Object.create(proto); | ||
set.add(proto); | ||
expect(set.size).toBe(1); | ||
expect(set.has(proto)).toBe(true); | ||
expect(set.has(base)).toBe(false); | ||
set.add(base); | ||
expect(set.size).toBe(2); | ||
expect(set.has(proto)).toBe(true); | ||
expect(set.has(base)).toBe(true); | ||
}); | ||
|
||
afterAll(cleanup); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* 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. | ||
* | ||
* @flow strict-local | ||
* @format | ||
*/ | ||
'use strict'; | ||
|
||
const {polyfillGlobal} = require('../Utilities/PolyfillFunctions'); | ||
|
||
/** | ||
* Polyfill ES6 collections (Map and Set). | ||
* If you don't need these polyfills, don't use InitializeCore; just directly | ||
* require the modules you need from InitializeCore for setup. | ||
*/ | ||
const _shouldPolyfillCollection = require('../vendor/core/_shouldPolyfillES6Collection'); | ||
if (_shouldPolyfillCollection('Map')) { | ||
// $FlowFixMe: even in strict-local mode Flow expects Map to be Flow-typed | ||
polyfillGlobal('Map', () => require('../vendor/core/Map')); | ||
} | ||
if (_shouldPolyfillCollection('Set')) { | ||
// $FlowFixMe: even in strict-local mode Flow expects Set to be Flow-typed | ||
polyfillGlobal('Set', () => require('../vendor/core/Set')); | ||
} |
Oops, something went wrong.