Skip to content

Commit e3b26f9

Browse files
authored
[pthreads] Use blob to create worker in single file mode. (#24784)
This keeps the source readable and avoids console error messages including the full base64 data url in the console output.
1 parent ee58484 commit e3b26f9

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

src/settings_internal.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,5 @@ var WEBGL_USE_GARBAGE_FREE_APIS = false;
274274
var INCLUDE_WEBGL1_FALLBACK = true;
275275

276276
var MINIFICATION_MAP = '';
277+
278+
var OUTPUT_FORMAT = '';

src/shell.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ var _scriptName = import.meta.url;
144144
#if !MODULARIZE
145145
// In MODULARIZE mode _scriptName needs to be captured already at the very top of the page immediately when the page is parsed, so it is generated there
146146
// before the page load. In non-MODULARIZE modes generate it here.
147+
#if SINGLE_FILE && OUTPUT_FORMAT == 'HTML'
148+
var _scriptName = typeof document != 'undefined' ? URL.createObjectURL(new Blob([document.getElementById('mainScript').textContent], { "type" : "text/javascript" })) : undefined;
149+
#else
147150
var _scriptName = typeof document != 'undefined' ? document.currentScript?.src : undefined;
151+
#endif
148152
#endif // !MODULARIZE
149153
#elif ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_WORKER
150154
var _scriptName;

tools/link.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,8 @@ def phase_linker_setup(options, linker_args): # noqa: C901, PLR0912, PLR0915
792792
if options.oformat == OFormat.MJS:
793793
default_setting('EXPORT_ES6', 1)
794794

795+
settings.OUTPUT_FORMAT = options.oformat.name
796+
795797
if settings.JS_BASE64_API:
796798
diagnostics.warning('experimental', '-sJS_BASE64_API is still experimental and not yet supported in browsers')
797799

@@ -2504,17 +2506,11 @@ def generate_traditional_runtime_html(target, options, js_target, target_basenam
25042506
script.src = base_js_target
25052507

25062508
if settings.SINGLE_FILE:
2507-
# In SINGLE_FILE mode we either inline the script, or in the case
2508-
# of SHARED_MEMORY convert the entire thing into a data URL.
2509-
if settings.SHARED_MEMORY:
2510-
assert not script.inline
2511-
script.src = get_subresource_location(js_target)
2512-
else:
2513-
js_contents = script.inline or ''
2514-
if script.src:
2515-
js_contents += read_file(js_target)
2516-
script.src = None
2517-
script.inline = read_file(js_target)
2509+
js_contents = script.inline or ''
2510+
if script.src:
2511+
js_contents += read_file(js_target)
2512+
script.src = None
2513+
script.inline = read_file(js_target)
25182514
delete_file(js_target)
25192515
else:
25202516
if not settings.WASM_ASYNC_COMPILATION:
@@ -2810,12 +2806,8 @@ def replacement(self):
28102806
"""Returns the script tag to replace the {{{ SCRIPT }}} tag in the target"""
28112807
assert (self.src or self.inline) and not (self.src and self.inline)
28122808
if self.src:
2813-
src = self.src
2814-
if src.startswith('data:'):
2815-
filename = src
2816-
else:
2817-
src = quote(self.src)
2818-
filename = f'./{src}'
2809+
src = quote(self.src)
2810+
filename = f'./{src}'
28192811
if settings.EXPORT_ES6:
28202812
return f'''
28212813
<script type="module">
@@ -2826,7 +2818,7 @@ def replacement(self):
28262818
else:
28272819
return f'<script async type="text/javascript" src="{src}"></script>'
28282820
else:
2829-
return '<script>\n%s\n</script>' % self.inline
2821+
return f'<script id="mainScript">\n{self.inline}\n</script>'
28302822

28312823

28322824
def filter_out_fake_dynamic_libs(options, inputs):

0 commit comments

Comments
 (0)