27
27
*/
28
28
'use strict' ;
29
29
30
+ const { polyfillObjectProperty, polyfillGlobal} = require ( 'PolyfillFunctions' ) ;
31
+
30
32
if ( global . GLOBAL === undefined ) {
31
33
global . GLOBAL = global ;
32
34
}
@@ -35,8 +37,6 @@ if (global.window === undefined) {
35
37
global . window = global ;
36
38
}
37
39
38
- const defineLazyObjectProperty = require ( 'defineLazyObjectProperty' ) ;
39
-
40
40
// Set up collections
41
41
const _shouldPolyfillCollection = require ( '_shouldPolyfillES6Collection' ) ;
42
42
if ( _shouldPolyfillCollection ( 'Map' ) ) {
@@ -46,50 +46,6 @@ if (_shouldPolyfillCollection('Set')) {
46
46
polyfillGlobal ( 'Set' , ( ) => require ( 'Set' ) ) ;
47
47
}
48
48
49
- /**
50
- * Sets an object's property. If a property with the same name exists, this will
51
- * replace it but maintain its descriptor configuration. The property will be
52
- * replaced with a lazy getter.
53
- *
54
- * In DEV mode the original property value will be preserved as `original[PropertyName]`
55
- * so that, if necessary, it can be restored. For example, if you want to route
56
- * network requests through DevTools (to trace them):
57
- *
58
- * global.XMLHttpRequest = global.originalXMLHttpRequest;
59
- *
60
- * @see https://github.com/facebook/react-native/issues/934
61
- */
62
- function defineLazyProperty < T > (
63
- object: Object,
64
- name: string,
65
- getValue: () => T ,
66
- ) : void {
67
- const descriptor = Object . getOwnPropertyDescriptor ( object , name ) ;
68
- if ( __DEV__ && descriptor ) {
69
- const backupName = `original${ name [ 0 ] . toUpperCase ( ) } ${ name . substr ( 1 ) } ` ;
70
- Object . defineProperty ( object , backupName , {
71
- ...descriptor ,
72
- value : object [ name ] ,
73
- } ) ;
74
- }
75
-
76
- const { enumerable, writable, configurable} = descriptor || { } ;
77
- if ( descriptor && ! configurable ) {
78
- console . error ( 'Failed to set polyfill. ' + name + ' is not configurable.' ) ;
79
- return ;
80
- }
81
-
82
- defineLazyObjectProperty ( object , name , {
83
- get : getValue ,
84
- enumerable : enumerable !== false ,
85
- writable : writable !== false ,
86
- } ) ;
87
- }
88
-
89
- function polyfillGlobal < T > (name: string, getValue: () => T) : void {
90
- defineLazyProperty ( global , name , getValue ) ;
91
- }
92
-
93
49
// Set up process
94
50
global . process = global . process || { } ;
95
51
global . process . env = global . process . env || { } ;
@@ -191,8 +147,8 @@ if (navigator === undefined) {
191
147
}
192
148
193
149
// see https://github.com/facebook/react-native/issues/10881
194
- defineLazyProperty ( navigator , 'product' , ( ) => 'ReactNative' ) ;
195
- defineLazyProperty ( navigator , 'geolocation' , ( ) => require ( 'Geolocation' ) ) ;
150
+ polyfillObjectProperty ( navigator , 'product' , ( ) => 'ReactNative' ) ;
151
+ polyfillObjectProperty ( navigator , 'geolocation' , ( ) => require ( 'Geolocation' ) ) ;
196
152
197
153
// Just to make sure the JS gets packaged up. Wait until the JS environment has
198
154
// been initialized before requiring them.
0 commit comments