@@ -2427,6 +2427,12 @@ def generate_traditional_runtime_html(target, options, js_target, target_basenam
2427
2427
document.body.appendChild(script);
2428
2428
}
2429
2429
'''
2430
+ # add required helper functions such as tryParseAsDataURI
2431
+ for filename in ('arrayUtils.js' , 'base64Utils.js' , 'URIUtils.js' ):
2432
+ content = shared .read_and_preprocess (utils .path_from_root ('src' , filename ))
2433
+ script .inline = content + script .inline
2434
+
2435
+ script .inline = 'var ASSERTIONS = %s;\n %s' % (settings .ASSERTIONS , script .inline )
2430
2436
else :
2431
2437
# Normal code generation path
2432
2438
script .src = base_js_target
@@ -2446,29 +2452,20 @@ def generate_traditional_runtime_html(target, options, js_target, target_basenam
2446
2452
''' % get_subresource_location (memfile )) + script .inline
2447
2453
2448
2454
if not settings .WASM_ASYNC_COMPILATION :
2449
- # We need to load the wasm file before anything else, it has to be synchronously ready TODO: optimize
2455
+ # We need to load the wasm file before anything else, since it
2456
+ # has be synchronously ready.
2450
2457
script .un_src ()
2451
2458
script .inline = '''
2452
- var wasmURL = '%s';
2453
- var wasmXHR = new XMLHttpRequest();
2454
- wasmXHR.open('GET', wasmURL, true);
2455
- wasmXHR.responseType = 'arraybuffer';
2456
- wasmXHR.onload = function() {
2457
- if (wasmXHR.status === 200 || wasmXHR.status === 0) {
2458
- Module.wasmBinary = wasmXHR.response;
2459
- } else {
2460
- var wasmURLBytes = tryParseAsDataURI(wasmURL);
2461
- if (wasmURLBytes) {
2462
- Module.wasmBinary = wasmURLBytes.buffer;
2463
- }
2464
- }
2465
- %s
2466
- };
2467
- wasmXHR.send(null);
2459
+ fetch('%s').then((result) => result.arrayBuffer())
2460
+ .then((buf) => {
2461
+ Module.wasmBinary = buf;
2462
+ %s;
2463
+ });
2468
2464
''' % (get_subresource_location (wasm_target ), script .inline )
2469
2465
2470
2466
if settings .WASM == 2 :
2471
- # If target browser does not support WebAssembly, we need to load the .wasm.js file before the main .js file.
2467
+ # If target browser does not support WebAssembly, we need to load
2468
+ # the .wasm.js file before the main .js file.
2472
2469
script .un_src ()
2473
2470
script .inline = '''
2474
2471
function loadMainJs() {
@@ -2487,14 +2484,6 @@ def generate_traditional_runtime_html(target, options, js_target, target_basenam
2487
2484
}
2488
2485
''' % (script .inline , get_subresource_location (wasm_target ) + '.js' )
2489
2486
2490
- # when script.inline isn't empty, add required helper functions such as tryParseAsDataURI
2491
- if script .inline :
2492
- for filename in ('arrayUtils.js' , 'base64Utils.js' , 'URIUtils.js' ):
2493
- content = shared .read_and_preprocess (utils .path_from_root ('src' , filename ))
2494
- script .inline = content + script .inline
2495
-
2496
- script .inline = 'var ASSERTIONS = %s;\n %s' % (settings .ASSERTIONS , script .inline )
2497
-
2498
2487
# inline script for SINGLE_FILE output
2499
2488
if settings .SINGLE_FILE :
2500
2489
js_contents = script .inline or ''
0 commit comments