Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def standardize_setting_change(key, value):
filename = value[1:]
if not os.path.exists(filename):
exit_with_error('%s: file not found parsing argument: %s=%s' % (filename, key, value))
value = open(filename).read()
value = open(filename).read().strip()
else:
value = value.replace('\\', '\\\\')

Expand Down Expand Up @@ -2231,6 +2231,9 @@ def get_full_import_name(name):
if settings.SINGLE_FILE:
exit_with_error('NODE_CODE_CACHING saves a file on the side and is not compatible with SINGLE_FILE')

if not shared.JS.isidentifier(settings.EXPORT_NAME):
exit_with_error(f'EXPORT_NAME is not a valid JS identifier: `{settings.EXPORT_NAME}`')

if options.tracing and settings.ALLOW_MEMORY_GROWTH:
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['emscripten_trace_report_memory_layout']
settings.EXPORTED_FUNCTIONS += ['_emscripten_stack_get_current',
Expand Down
4 changes: 4 additions & 0 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -10603,3 +10603,7 @@ def test_no_deprecated(self):
err = self.expect_fail([EMCC, '-c', '-Werror', 'test.c'])
self.assertContained("error: 'foo' is deprecated", err)
self.run_process([EMCC, '-c', '-Werror', '-Wno-deprecated', 'test.c'])

def test_bad_export_name(self):
err = self.expect_fail([EMCC, '-sEXPORT_NAME=foo bar', test_file('hello_world.c')])
self.assertContained('error: EXPORT_NAME is not a valid JS identifier: `foo bar`', err)
5 changes: 5 additions & 0 deletions tools/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,11 @@ def is_legal_sig(sig):
return True
return sig == JS.legalize_sig(sig)

@staticmethod
def isidentifier(name):
# https://stackoverflow.com/questions/43244604/check-that-a-string-is-a-valid-javascript-identifier-name-using-python-3
return name.replace('$', '_').isidentifier()

@staticmethod
def make_dynCall(sig, args):
# wasm2c and asyncify are not yet compatible with direct wasm table calls
Expand Down