Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup generate_traditional_runtime_html. NFC #21267

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 15 additions & 26 deletions tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -2427,6 +2427,12 @@ def generate_traditional_runtime_html(target, options, js_target, target_basenam
document.body.appendChild(script);
}
'''
# add required helper functions such as tryParseAsDataURI
for filename in ('arrayUtils.js', 'base64Utils.js', 'URIUtils.js'):
content = shared.read_and_preprocess(utils.path_from_root('src', filename))
script.inline = content + script.inline
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

script.inline may be None here, I think? The old code guarded against that. I can't find where that is prevented in the new code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The live right above sets script.inline unconditionally so I think its fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, the indentation confused me. This is indented the same as line 2413, even though there are unindented lines in between (which are JS code, not Python).


script.inline = 'var ASSERTIONS = %s;\n%s' % (settings.ASSERTIONS, script.inline)
else:
# Normal code generation path
script.src = base_js_target
Expand All @@ -2446,29 +2452,20 @@ def generate_traditional_runtime_html(target, options, js_target, target_basenam
''' % get_subresource_location(memfile)) + script.inline

if not settings.WASM_ASYNC_COMPILATION:
# We need to load the wasm file before anything else, it has to be synchronously ready TODO: optimize
# We need to load the wasm file before anything else, since it
# has be synchronously ready.
script.un_src()
script.inline = '''
var wasmURL = '%s';
var wasmXHR = new XMLHttpRequest();
wasmXHR.open('GET', wasmURL, true);
wasmXHR.responseType = 'arraybuffer';
wasmXHR.onload = function() {
if (wasmXHR.status === 200 || wasmXHR.status === 0) {
Module.wasmBinary = wasmXHR.response;
} else {
var wasmURLBytes = tryParseAsDataURI(wasmURL);
if (wasmURLBytes) {
Module.wasmBinary = wasmURLBytes.buffer;
}
}
%s
};
wasmXHR.send(null);
fetch('%s').then((result) => result.arrayBuffer())
.then((buf) => {
Module.wasmBinary = buf;
%s;
});
''' % (get_subresource_location(wasm_target), script.inline)

if settings.WASM == 2:
# If target browser does not support WebAssembly, we need to load the .wasm.js file before the main .js file.
# If target browser does not support WebAssembly, we need to load
# the .wasm.js file before the main .js file.
script.un_src()
script.inline = '''
function loadMainJs() {
Expand All @@ -2487,14 +2484,6 @@ def generate_traditional_runtime_html(target, options, js_target, target_basenam
}
''' % (script.inline, get_subresource_location(wasm_target) + '.js')

# when script.inline isn't empty, add required helper functions such as tryParseAsDataURI
if script.inline:
for filename in ('arrayUtils.js', 'base64Utils.js', 'URIUtils.js'):
content = shared.read_and_preprocess(utils.path_from_root('src', filename))
script.inline = content + script.inline

script.inline = 'var ASSERTIONS = %s;\n%s' % (settings.ASSERTIONS, script.inline)

# inline script for SINGLE_FILE output
if settings.SINGLE_FILE:
js_contents = script.inline or ''
Expand Down
Loading