@@ -122,50 +122,48 @@ var LibraryEmVal = {
122
122
_emval_new_u16string__deps : [ '$Emval' ] ,
123
123
_emval_new_u16string : ( v ) => Emval . toHandle ( UTF16ToString ( v ) ) ,
124
124
125
+ $emGlobalThis__internal : true ,
125
126
#if SUPPORTS_GLOBALTHIS
126
- $emval_get_global : ( ) => globalThis ,
127
- #elif ! DYNAMIC_EXECUTION
128
- $emval_get_global : ( ) => {
129
- if ( typeof globalThis == 'object' ) {
127
+ $emGlobalThis : 'globalThis' ,
128
+ #else
129
+ $getGlobalThis__internal : true ,
130
+ $getGlobalThis : ( ) => {
131
+ if ( typeof globalThis != 'undefined' ) {
130
132
return globalThis ;
131
133
}
134
+ #if DYNAMIC_EXECUTION
135
+ return new Function ( 'return this' ) ( ) ;
136
+ #else
132
137
function testGlobal ( obj ) {
133
- obj [ '$$$embind_global$$$' ] = obj ;
134
- var success = typeof $$$embind_global$$$ == ' object' && obj [ '$$$embind_global$$$' ] == obj ;
135
- if ( ! success ) {
136
- delete obj [ '$$$embind_global$$$' ] ;
137
- }
138
+ // Use __emGlobalThis as a test symbol to see if ` obj` is indeed the
139
+ // global object.
140
+ obj [ '__emGlobalThis' ] = obj ;
141
+ var success = typeof __emGlobalThis == 'object' && obj [ '__emGlobalThis' ] === obj ;
142
+ delete obj [ '__emGlobalThis' ] ;
138
143
return success ;
139
144
}
140
- if ( typeof $$$embind_global$$$ == 'object' ) {
141
- return $$$embind_global$$$ ;
145
+ if ( typeof self != 'undefined' && testGlobal ( self ) ) {
146
+ return self ; // This works for both "window" and "self" (Web Workers) global objects
142
147
}
143
- if ( typeof global == 'object' && testGlobal ( global ) ) {
144
- $$$embind_global$$$ = global ;
145
- } else if ( typeof self == 'object' && testGlobal ( self ) ) {
146
- $$$embind_global$$$ = self ; // This works for both "window" and "self" (Web Workers) global objects
147
- }
148
- if ( typeof $$$embind_global$$$ == 'object' ) {
149
- return $$$embind_global$$$ ;
150
- }
151
- throw Error ( 'unable to get global object.' ) ;
152
- } ,
153
- #else
154
- $emval_get_global : ( ) => {
155
- if ( typeof globalThis == 'object' ) {
156
- return globalThis ;
148
+ #if ENVIRONMENT_MAY_BE_NODE
149
+ if ( typeof global != 'undefined' && testGlobal ( global ) ) {
150
+ return global ;
157
151
}
158
- return new Function ( 'return this' ) ( ) ;
159
- } ,
160
152
#endif
161
- _emval_get_global__deps : [ '$Emval' , '$getStringOrSymbol' , '$emval_get_global' ] ,
153
+ abort ( 'unable to get global object.' ) ;
154
+ #endif // DYNAMIC_EXECUTION
155
+ } ,
156
+ $emGlobalThis__deps : [ '$getGlobalThis' ] ,
157
+ $emGlobalThis : 'getGlobalThis()' ,
158
+ #endif // SUPPORTS_GLOBALTHIS
159
+
160
+ _emval_get_global__deps : [ '$Emval' , '$getStringOrSymbol' , '$emGlobalThis' ] ,
162
161
_emval_get_global : ( name ) => {
163
- if ( name === 0 ) {
164
- return Emval . toHandle ( emval_get_global ( ) ) ;
165
- } else {
166
- name = getStringOrSymbol ( name ) ;
167
- return Emval . toHandle ( emval_get_global ( ) [ name ] ) ;
162
+ if ( ! name ) {
163
+ return Emval . toHandle ( emGlobalThis ) ;
168
164
}
165
+ name = getStringOrSymbol ( name ) ;
166
+ return Emval . toHandle ( emGlobalThis [ name ] ) ;
169
167
} ,
170
168
171
169
_emval_get_module_property__deps : [ '$getStringOrSymbol' , '$Emval' ] ,
0 commit comments