Skip to content

Commit 9ef0baa

Browse files
authored
Do not default to TextDecoder-only in -Oz if targeting a shell (#13578)
Shells may not have TextDecoder - only Web and Node are guaranteed to.
1 parent dedddd7 commit 9ef0baa

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

emcc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,10 @@ def default_setting(name, new_default):
12451245
# in -Oz builds, since custom decoder for UTF-8 takes up space.
12461246
# In pthreads enabled builds, TEXTDECODER==2 may not work, see
12471247
# https://github.com/whatwg/encoding/issues/172
1248-
if shared.Settings.SHRINK_LEVEL >= 2 and not shared.Settings.USE_PTHREADS:
1248+
# When supporting shell environments, do not do this as TextDecoder is not
1249+
# widely supported there.
1250+
if shared.Settings.SHRINK_LEVEL >= 2 and not shared.Settings.USE_PTHREADS and \
1251+
not shared.Settings.ENVIRONMENT_MAY_BE_SHELL:
12491252
default_setting('TEXTDECODER', 2)
12501253

12511254
# If set to 1, we will run the autodebugger (the automatic debugging tool, see

tests/test_other.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10048,3 +10048,11 @@ def test_deps_info(self):
1004810048
print(f' checking for: {dep}')
1004910049
if direct not in js and via_module not in js and assignment not in js:
1005010050
self.fail(f'use of declared dependency {dep} not found in JS output for {function}')
10051+
10052+
def test_shell_Oz(self):
10053+
# regression test for -Oz working on non-web, non-node environments that
10054+
# lack TextDecoder
10055+
if config.V8_ENGINE not in config.JS_ENGINES:
10056+
return self.skipTest('no shell to test')
10057+
self.run_process([EMCC, path_from_root('tests', 'hello_world.c'), '-Oz'])
10058+
self.assertContained('hello, world!', self.run_js('a.out.js', engine=config.V8_ENGINE))

0 commit comments

Comments
 (0)