1
+ // Copyright 2010 The Emscripten Authors. All rights reserved.
2
+ // Emscripten is available under two separate licenses, the MIT license and the
3
+ // University of Illinois/NCSA Open Source License. Both these licenses can be
4
+ // found in the LICENSE file.
5
+
1
6
// The Module object: Our interface to the outside world. We import
2
7
// and export values on it. There are various ways Module can be used:
3
8
// 1. Not defined. We create it here
@@ -161,8 +166,8 @@ Module['quit'] = function(status, toThrow) {
161
166
Module [ 'preRun' ] = [ ] ;
162
167
Module [ 'postRun' ] = [ ] ;
163
168
164
- // The environment setup code below is customized to use Module.
165
- // *** Environment setup code ***
169
+ // Determine the runtime environment we are in. You can customize this by
170
+ // setting the ENVIRONMENT setting at compile time (see settings.js).
166
171
167
172
var ENVIRONMENT_IS_WEB = false ;
168
173
var ENVIRONMENT_IS_WORKER = false ;
@@ -234,9 +239,7 @@ if (ENVIRONMENT_IS_NODE) {
234
239
} ) ;
235
240
// Currently node will swallow unhandled rejections, but this behavior is
236
241
// deprecated, and in the future it will exit with error status.
237
- process [ 'on' ] ( 'unhandledRejection' , function ( reason , p ) {
238
- process [ 'exit' ] ( 1 ) ;
239
- } ) ;
242
+ process [ 'on' ] ( 'unhandledRejection' , abort ) ;
240
243
241
244
Module [ 'quit' ] = function ( status ) {
242
245
process [ 'exit' ] ( status ) ;
@@ -276,17 +279,17 @@ if (ENVIRONMENT_IS_SHELL) {
276
279
}
277
280
} else
278
281
if ( ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER ) {
279
- if ( ENVIRONMENT_IS_WEB ) {
280
- if ( document . currentScript ) {
281
- scriptDirectory = document . currentScript . src ;
282
- }
283
- } else { // worker
282
+ if ( ENVIRONMENT_IS_WORKER ) { // Check worker, not web, since window could be polyfilled
284
283
scriptDirectory = self . location . href ;
284
+ } else if ( document . currentScript ) { // web
285
+ scriptDirectory = document . currentScript . src ;
285
286
}
286
287
// blob urls look like blob:http://site.com/etc/etc and we cannot infer anything from them.
287
288
// otherwise, slice off the final part of the url to find the script directory.
289
+ // if scriptDirectory does not contain a slash, lastIndexOf will return -1,
290
+ // and scriptDirectory will correctly be replaced with an empty string.
288
291
if ( scriptDirectory . indexOf ( 'blob:' ) !== 0 ) {
289
- scriptDirectory = scriptDirectory . split ( '/' ) . slice ( 0 , - 1 ) . join ( '/' ) + '/' ;
292
+ scriptDirectory = scriptDirectory . substr ( 0 , scriptDirectory . lastIndexOf ( '/' ) + 1 ) ;
290
293
} else {
291
294
scriptDirectory = '' ;
292
295
}
@@ -338,8 +341,6 @@ if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
338
341
var out = Module [ 'print' ] || ( typeof console !== 'undefined' ? console . log . bind ( console ) : ( typeof print !== 'undefined' ? print : null ) ) ;
339
342
var err = Module [ 'printErr' ] || ( typeof printErr !== 'undefined' ? printErr : ( ( typeof console !== 'undefined' && console . warn . bind ( console ) ) || out ) ) ;
340
343
341
- // *** Environment setup code ***
342
-
343
344
// Merge back in the overrides
344
345
for ( key in moduleOverrides ) {
345
346
if ( moduleOverrides . hasOwnProperty ( key ) ) {
@@ -352,6 +353,11 @@ moduleOverrides = undefined;
352
353
353
354
354
355
356
+ // Copyright 2017 The Emscripten Authors. All rights reserved.
357
+ // Emscripten is available under two separate licenses, the MIT license and the
358
+ // University of Illinois/NCSA Open Source License. Both these licenses can be
359
+ // found in the LICENSE file.
360
+
355
361
// {{PREAMBLE_ADDITIONS}}
356
362
357
363
var STACK_ALIGN = 16 ;
@@ -517,7 +523,13 @@ var GLOBAL_BASE = 1024;
517
523
// Runtime essentials
518
524
//========================================
519
525
520
- var ABORT = 0 ; // whether we are quitting the application. no code should run after this. set in exit() and abort()
526
+ // whether we are quitting the application. no code should run after this.
527
+ // set in exit() and abort()
528
+ var ABORT = false ;
529
+
530
+ // set by exit() and abort(). Passed to 'onExit' handler.
531
+ // NOTE: This is also used as the process return code code in shell environments
532
+ // but only when noExitRuntime is false.
521
533
var EXITSTATUS = 0 ;
522
534
523
535
/** @type {function(*, string=) } */
@@ -808,7 +820,10 @@ function UTF8ArrayToString(u8Array, idx) {
808
820
809
821
var str = '' ;
810
822
while ( 1 ) {
811
- // For UTF8 byte structure, see http://en.wikipedia.org/wiki/UTF-8#Description and https://www.ietf.org/rfc/rfc2279.txt and https://tools.ietf.org/html/rfc3629
823
+ // For UTF8 byte structure, see:
824
+ // http://en.wikipedia.org/wiki/UTF-8#Description
825
+ // https://www.ietf.org/rfc/rfc2279.txt
826
+ // https://tools.ietf.org/html/rfc3629
812
827
u0 = u8Array [ idx ++ ] ;
813
828
if ( ! u0 ) return str ;
814
829
if ( ! ( u0 & 0x80 ) ) { str += String . fromCharCode ( u0 ) ; continue ; }
@@ -1114,7 +1129,7 @@ function demangleAll(text) {
1114
1129
return text . replace ( regex ,
1115
1130
function ( x ) {
1116
1131
var y = demangle ( x ) ;
1117
- return x === y ? x : ( x + ' [' + y + ']' ) ;
1132
+ return x === y ? x : ( y + ' [' + x + ']' ) ;
1118
1133
} ) ;
1119
1134
}
1120
1135
@@ -1407,7 +1422,7 @@ var Math_trunc = Math.trunc;
1407
1422
// A counter of dependencies for calling run(). If we need to
1408
1423
// do asynchronous work before running, increment this and
1409
1424
// decrement it. Incrementing must happen in a place like
1410
- // PRE_RUN_ADDITIONS (used by emcc to add file preloading).
1425
+ // Module.preRun (used by emcc to add file preloading).
1411
1426
// Note that you can add dependencies in preRun, even though
1412
1427
// it happens right before run - run will be postponed until
1413
1428
// the dependencies are met.
@@ -1456,6 +1471,11 @@ var memoryInitializer = null;
1456
1471
1457
1472
1458
1473
1474
+ // Copyright 2017 The Emscripten Authors. All rights reserved.
1475
+ // Emscripten is available under two separate licenses, the MIT license and the
1476
+ // University of Illinois/NCSA Open Source License. Both these licenses can be
1477
+ // found in the LICENSE file.
1478
+
1459
1479
// Prefix of data URIs emitted by SINGLE_FILE and related options.
1460
1480
var dataURIPrefix = 'data:application/octet-stream;base64,' ;
1461
1481
@@ -1622,7 +1642,7 @@ function integrateWasmJS() {
1622
1642
function instantiateArrayBuffer ( receiver ) {
1623
1643
getBinaryPromise ( ) . then ( function ( binary ) {
1624
1644
return WebAssembly . instantiate ( binary , info ) ;
1625
- } ) . then ( receiver ) . catch ( function ( reason ) {
1645
+ } ) . then ( receiver , function ( reason ) {
1626
1646
err ( 'failed to asynchronously prepare wasm: ' + reason ) ;
1627
1647
abort ( reason ) ;
1628
1648
} ) ;
@@ -1633,8 +1653,7 @@ function integrateWasmJS() {
1633
1653
! isDataURI ( wasmBinaryFile ) &&
1634
1654
typeof fetch === 'function' ) {
1635
1655
WebAssembly . instantiateStreaming ( fetch ( wasmBinaryFile , { credentials : 'same-origin' } ) , info )
1636
- . then ( receiveInstantiatedSource )
1637
- . catch ( function ( reason ) {
1656
+ . then ( receiveInstantiatedSource , function ( reason ) {
1638
1657
// We expect the most common failure cause to be a bad MIME type for the binary,
1639
1658
// in which case falling back to ArrayBuffer instantiation should work.
1640
1659
err ( 'wasm streaming compile failed: ' + reason ) ;
@@ -1860,6 +1879,11 @@ staticSealed = true; // seal the static portion of memory
1860
1879
1861
1880
var ASSERTIONS = false ;
1862
1881
1882
+ // Copyright 2017 The Emscripten Authors. All rights reserved.
1883
+ // Emscripten is available under two separate licenses, the MIT license and the
1884
+ // University of Illinois/NCSA Open Source License. Both these licenses can be
1885
+ // found in the LICENSE file.
1886
+
1863
1887
/** @type {function(string, boolean=, number=) } */
1864
1888
function intArrayFromString ( stringy , dontAddNull , length ) {
1865
1889
var len = length > 0 ? length : lengthBytesUTF8 ( stringy ) + 1 ;
@@ -1903,7 +1927,7 @@ function invoke_iiiiiii(index,a1,a2,a3,a4,a5,a6) {
1903
1927
1904
1928
Module . asmGlobalArg = { } ;
1905
1929
1906
- Module . asmLibraryArg = { "abort" : abort , "assert" : assert , "enlargeMemory" : enlargeMemory , "getTotalMemory" : getTotalMemory , "abortOnCannotGrowMemory" : abortOnCannotGrowMemory , "invoke_iiiiiii" : invoke_iiiiiii , "___setErrNo" : ___setErrNo , "_abort" : _abort , "_emscripten_memcpy_big" : _emscripten_memcpy_big , "_llvm_cos_f64" : _llvm_cos_f64 , "_llvm_exp_f64" : _llvm_exp_f64 , "_llvm_fabs_f32" : _llvm_fabs_f32 , "_llvm_floor_f32" : _llvm_floor_f32 , "_llvm_sin_f64" : _llvm_sin_f64 , "_llvm_sqrt_f32" : _llvm_sqrt_f32 , "_llvm_sqrt_f64" : _llvm_sqrt_f64 , "_llvm_stackrestore" : _llvm_stackrestore , "_llvm_stacksave" : _llvm_stacksave , "DYNAMICTOP_PTR" : DYNAMICTOP_PTR , "tempDoublePtr" : tempDoublePtr , "ABORT" : ABORT , " STACKTOP" : STACKTOP , "STACK_MAX" : STACK_MAX } ;
1930
+ Module . asmLibraryArg = { "abort" : abort , "assert" : assert , "enlargeMemory" : enlargeMemory , "getTotalMemory" : getTotalMemory , "abortOnCannotGrowMemory" : abortOnCannotGrowMemory , "invoke_iiiiiii" : invoke_iiiiiii , "___setErrNo" : ___setErrNo , "_abort" : _abort , "_emscripten_memcpy_big" : _emscripten_memcpy_big , "_llvm_cos_f64" : _llvm_cos_f64 , "_llvm_exp_f64" : _llvm_exp_f64 , "_llvm_fabs_f32" : _llvm_fabs_f32 , "_llvm_floor_f32" : _llvm_floor_f32 , "_llvm_sin_f64" : _llvm_sin_f64 , "_llvm_sqrt_f32" : _llvm_sqrt_f32 , "_llvm_sqrt_f64" : _llvm_sqrt_f64 , "_llvm_stackrestore" : _llvm_stackrestore , "_llvm_stacksave" : _llvm_stacksave , "DYNAMICTOP_PTR" : DYNAMICTOP_PTR , "tempDoublePtr" : tempDoublePtr , "STACKTOP" : STACKTOP , "STACK_MAX" : STACK_MAX } ;
1907
1931
// EMSCRIPTEN_START_ASM
1908
1932
var asm = Module [ "asm" ] // EMSCRIPTEN_END_ASM
1909
1933
( Module . asmGlobalArg , Module . asmLibraryArg , buffer ) ;
@@ -2131,8 +2155,6 @@ function abort(what) {
2131
2155
}
2132
2156
Module [ 'abort' ] = abort ;
2133
2157
2134
- // {{PRE_RUN_ADDITIONS}}
2135
-
2136
2158
if ( Module [ 'preInit' ] ) {
2137
2159
if ( typeof Module [ 'preInit' ] == 'function' ) Module [ 'preInit' ] = [ Module [ 'preInit' ] ] ;
2138
2160
while ( Module [ 'preInit' ] . length > 0 ) {
@@ -2145,8 +2167,6 @@ Module["noExitRuntime"] = true;
2145
2167
2146
2168
run ( ) ;
2147
2169
2148
- // {{POST_RUN_ADDITIONS}}
2149
-
2150
2170
2151
2171
2152
2172
0 commit comments