Skip to content

Commit 1c1ada4

Browse files
committed
Fix webidl_binder so it can't handle missing assert function
This can happen when ASSERTIONS is not set and we are in STRICT mode or MINIMAL_RUNTIME mode. See #20592
1 parent c4d76b8 commit 1c1ada4

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

test/test_core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7637,6 +7637,7 @@ def test_embind_no_rtti_followed_by_rtti(self):
76377637
def test_webidl(self, mode, allow_memory_growth):
76387638
self.uses_es6 = True
76397639
self.set_setting('WASM_ASYNC_COMPILATION', 0)
7640+
self.set_setting('STRICT')
76407641
if self.maybe_closure():
76417642
# avoid closure minified names competing with our test code in the global name space
76427643
self.set_setting('MODULARIZE')
@@ -7670,7 +7671,7 @@ def test_webidl(self, mode, allow_memory_growth):
76707671

76717672
# Export things on "TheModule". This matches the typical use pattern of the bound library
76727673
# being used as Box2D.* or Ammo.*, and we cannot rely on "Module" being always present (closure may remove it).
7673-
self.emcc_args += ['--post-js=glue.js', '--extern-post-js=extern-post.js']
7674+
self.emcc_args += ['--no-entry', '--post-js=glue.js', '--extern-post-js=extern-post.js']
76747675
if mode == 'ALL':
76757676
self.emcc_args += ['-sASSERTIONS']
76767677
if allow_memory_growth:

test/webidl/post.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ try {
239239
} catch (e) {}
240240

241241
try {
242-
s = new TheModule.StringUser('abc', 1);
242+
var s = new TheModule.StringUser('abc', 1);
243243
s.Print(123, null); // Expects a string or a wrapped pointer
244244
} catch (e) {}
245245

tools/webidl_binder.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ def build_constructor(name):
133133
mid_js += build_constructor('WrapperObject')
134134

135135
mid_js += ['''
136+
/*
137+
* For now, the webidl-generated code unconditionally depends on the `assert` function,
138+
* but there are certain build modes where emscripten does not define this.
139+
* TODO(sbc): Make the usage of assert conditional.
140+
*/
141+
if (typeof assert == "undefined") {
142+
assert = (cond) => {}
143+
}
144+
136145
/** @suppress {duplicate} (TODO: avoid emitting this multiple times, it is redundant)
137146
@param {*=} __class__ */
138147
function getCache(__class__) {

0 commit comments

Comments
 (0)