@@ -1612,6 +1612,41 @@ addToLibrary({
1612
1612
emscripten_asm_const_async_on_main_thread : ( emAsmAddr , sigPtr , argbuf ) => runMainThreadEmAsm ( emAsmAddr , sigPtr , argbuf , 0 ) ,
1613
1613
#endif
1614
1614
1615
+ $emGlobalThis__internal : true ,
1616
+ #if SUPPORTS_GLOBALTHIS
1617
+ $emGlobalThis : 'globalThis' ,
1618
+ #else
1619
+ $getGlobalThis__internal : true ,
1620
+ $getGlobalThis : ( ) => {
1621
+ if ( typeof globalThis != 'undefined' ) {
1622
+ return globalThis ;
1623
+ }
1624
+ #if DYNAMIC_EXECUTION
1625
+ return new Function ( 'return this' ) ( ) ;
1626
+ #else
1627
+ function testGlobal ( obj ) {
1628
+ // Use __emGlobalThis as a test symbol to see if `obj` is indeed the
1629
+ // global object.
1630
+ obj [ '__emGlobalThis' ] = obj ;
1631
+ var success = typeof __emGlobalThis == 'object' && obj [ '__emGlobalThis' ] === obj ;
1632
+ delete obj [ '__emGlobalThis' ] ;
1633
+ return success ;
1634
+ }
1635
+ if ( typeof self != 'undefined' && testGlobal ( self ) ) {
1636
+ return self ; // This works for both "window" and "self" (Web Workers) global objects
1637
+ }
1638
+ #if ENVIRONMENT_MAY_BE_NODE
1639
+ if ( typeof global != 'undefined' && testGlobal ( global ) ) {
1640
+ return global ;
1641
+ }
1642
+ #endif
1643
+ abort ( 'unable to get global object.' ) ;
1644
+ #endif // DYNAMIC_EXECUTION
1645
+ } ,
1646
+ $emGlobalThis__deps: [ '$getGlobalThis' ] ,
1647
+ $emGlobalThis : 'getGlobalThis()' ,
1648
+ #endif // SUPPORTS_GLOBALTHIS
1649
+
1615
1650
#if ! DECLARE_ASM_MODULE_EXPORTS
1616
1651
// When DECLARE_ASM_MODULE_EXPORTS is not set we export native symbols
1617
1652
// at runtime rather than statically in JS code.
0 commit comments