mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-01 13:03:08 +08:00
Freeze UTFSequence
Summary: Don't want anyone accidentally mutating it. Also make deepFreezeAndThrowOnMutationInDev easier to use with nice flow typing. Reviewed By: yungsters Differential Revision: D6974089 fbshipit-source-id: 0f90e7939cb726893fa353a4f2a6bbba701205bc
This commit is contained in:
committed by
Facebook Github Bot
parent
74e54cbcc4
commit
d220118dbd
@@ -13,6 +13,8 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const deepFreezeAndThrowOnMutationInDev = require('deepFreezeAndThrowOnMutationInDev');
|
||||
|
||||
/**
|
||||
* A collection of Unicode sequences for various characters and emoji.
|
||||
*
|
||||
@@ -20,7 +22,7 @@
|
||||
* - Source code should be limitted to ASCII.
|
||||
* - Less chance of typos.
|
||||
*/
|
||||
const UTFSequence = {
|
||||
const UTFSequence = deepFreezeAndThrowOnMutationInDev({
|
||||
MIDDOT: '\u00B7', // normal middle dot: ·
|
||||
MIDDOT_SP: '\u00A0\u00B7\u00A0', // ·
|
||||
MIDDOT_KATAKANA: '\u30FB', // katakana middle dot
|
||||
@@ -30,6 +32,6 @@ const UTFSequence = {
|
||||
NDASH_SP: '\u00A0\u2013\u00A0', // –
|
||||
NBSP: '\u00A0', // non-breaking space:
|
||||
PIZZA: '\uD83C\uDF55',
|
||||
};
|
||||
});
|
||||
|
||||
module.exports = UTFSequence;
|
||||
|
||||
@@ -29,13 +29,13 @@
|
||||
* Freezing the object and adding the throw mechanism is expensive and will
|
||||
* only be used in DEV.
|
||||
*/
|
||||
function deepFreezeAndThrowOnMutationInDev(object: Object) {
|
||||
function deepFreezeAndThrowOnMutationInDev<T: Object>(object: T): T {
|
||||
if (__DEV__) {
|
||||
if (typeof object !== 'object' ||
|
||||
object === null ||
|
||||
Object.isFrozen(object) ||
|
||||
Object.isSealed(object)) {
|
||||
return;
|
||||
return object;
|
||||
}
|
||||
|
||||
var keys = Object.keys(object);
|
||||
@@ -58,6 +58,7 @@ function deepFreezeAndThrowOnMutationInDev(object: Object) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
function throwOnImmutableMutation(key, value) {
|
||||
|
||||
Reference in New Issue
Block a user