Skip to content

Commit 54b933f

Browse files
committed
[embind] Add #if ASSERTIONS guard around assert calls
Supersedes #20504
1 parent ad52571 commit 54b933f

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ See docs/process.md for more on how version tagging works.
2020

2121
3.1.48 (in development)
2222
-----------------------
23+
- The JS `assert` function is no longer available in release builds when
24+
`-sSTRICT` is used. This should only effect users with custom JS library code
25+
which doesn't use `#if ASSERTIONS` guards around their `assert` calls. This
26+
bahaviour matches the behaviour of `MINIMAL_RUNTIME`. (#20592)
2327
- The minimum version of node required run the compiler was updated from
2428
10.19 to 16.20. This does not effect the node requirements of the generated
2529
JavaScript code. (#20551)

src/embind/embind_shared.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ var LibraryEmbindShared = {
129129
signature = signature.trim();
130130
const argsIndex = signature.indexOf("(");
131131
if (argsIndex !== -1) {
132+
#if ASSERTIONS
132133
assert(signature[signature.length - 1] == ")", "Parentheses for argument names should match.");
134+
#endif
133135
return signature.substr(0, argsIndex);
134136
} else {
135137
return signature;
@@ -140,7 +142,9 @@ var LibraryEmbindShared = {
140142
signature = signature.trim();
141143
const argsIndex = signature.indexOf("(") + 1;
142144
if (argsIndex !== 0) {
145+
#if ASSERTIONS
143146
assert(signature[signature.length - 1] == ")", "Parentheses for argument names should match.");
147+
#endif
144148
return signature.substr(argsIndex, signature.length - argsIndex - 1).replaceAll(" ", "").split(",").filter(n => n.length);
145149
} else {
146150
return [];

src/library_pthread.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,9 @@ var LibraryPThread = {
592592
PThread.outstandingPromises[pthread_ptr].resolve();
593593
}
594594
#endif
595+
#if ASSERTIONS
595596
assert(worker);
597+
#endif
596598
PThread.returnWorkerToPool(worker);
597599
},
598600

test/test_other.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2892,9 +2892,11 @@ def test_embind_closure_no_dynamic_execution(self):
28922892
emscripten::function("bar", &bar);
28932893
}
28942894
''')
2895-
self.emcc_args.remove('-Wclosure')
2895+
self.set_setting('INCOMING_MODULE_JS_API', 'onRuntimeInitialized')
2896+
self.set_setting('STRICT')
2897+
self.set_setting('NO_DYNAMIC_EXECUTION')
28962898
self.do_runf('main.cpp', '10\nok\n',
2897-
emcc_args=['-lembind', '-O2', '--closure', '1', '-sNO_DYNAMIC_EXECUTION', '--post-js', 'post.js'])
2899+
emcc_args=['--no-entry', '-lembind', '-O2', '--closure=-1', '--minify=0', '--post-js=post.js'])
28982900

28992901
@is_slow_test
29002902
@parameterized({

0 commit comments

Comments
 (0)