Skip to content

Commit

Permalink
In STRICT mode, only define assert when ASSERTIONS is set
Browse files Browse the repository at this point in the history
This matches the behaviour of MINIMAL_RUNTIME, and supports the practice
of not including asserts in release builds.

Also remove the closure externs for `assert` so that closure can
correctly error out end `assert` is not defined.

Helps with emscripten-core#20504
  • Loading branch information
sbc100 committed Nov 2, 2023
1 parent b7c778e commit 31e6d0a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 142 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ See docs/process.md for more on how version tagging works.

3.1.48 (in development)
-----------------------
- The JS `assert` function is no longer available in release builds when
`-sSTRICT` is used. This should only affect users with custom JS library code
which doesn't use `#if ASSERTIONS` guards around their `assert` calls. This
behaviour matches that of `MINIMAL_RUNTIME`. (#20592)
- The minimum version of node required run the compiler was updated from
10.19 to 16.20. This does not effect the node requirements of the generated
JavaScript code. (#20551)
Expand Down
5 changes: 0 additions & 5 deletions src/closure-externs/node-externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ wss._socket.remoteAddress;
*/
wss._socket.remotePort;

/**
* @suppress {duplicate}
*/
var assert;

/**
* @suppress {duplicate}
*/
Expand Down
2 changes: 2 additions & 0 deletions src/library_pthread.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,9 @@ var LibraryPThread = {
PThread.outstandingPromises[pthread_ptr].resolve();
}
#endif
#if ASSERTIONS
assert(worker);
#endif
PThread.returnWorkerToPool(worker);
},

Expand Down
6 changes: 6 additions & 0 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ var ABORT = false;
// but only when noExitRuntime is false.
var EXITSTATUS;
#if ASSERTIONS || !STRICT
// In STRICT mode, we only define assert() when ASSERTIONS is set. i.e. we
// don't define it at all in release modes. This matches the behaviour of
// MINIMAL_RUNTIME.
// TODO(sbc): Make this the default even without STRICT enabled.
/** @type {function(*, string=)} */
function assert(condition, text) {
if (!condition) {
Expand All @@ -88,6 +93,7 @@ function assert(condition, text) {
#endif
}
}
#endif
#if ASSERTIONS
// We used to include malloc/free by default in the past. Show a helpful error in
Expand Down
137 changes: 0 additions & 137 deletions third_party/closure-compiler/node-externs/assert.js

This file was deleted.

0 comments on commit 31e6d0a

Please sign in to comment.