Skip to content

Commit a2f3b92

Browse files
authored
In STRICT mode, only define assert when ASSERTIONS is set (#20592)
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 #20504
1 parent a0f6f24 commit a2f3b92

File tree

5 files changed

+12
-142
lines changed

5 files changed

+12
-142
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 affect users with custom JS library code
25+
which doesn't use `#if ASSERTIONS` guards around their `assert` calls. This
26+
behaviour matches that 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/closure-externs/node-externs.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ wss._socket.remoteAddress;
5757
*/
5858
wss._socket.remotePort;
5959

60-
/**
61-
* @suppress {duplicate}
62-
*/
63-
var assert;
64-
6560
/**
6661
* @suppress {duplicate}
6762
*/

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

src/preamble.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ var ABORT = false;
7575
// but only when noExitRuntime is false.
7676
var EXITSTATUS;
7777

78+
#if ASSERTIONS || !STRICT
79+
// In STRICT mode, we only define assert() when ASSERTIONS is set. i.e. we
80+
// don't define it at all in release modes. This matches the behaviour of
81+
// MINIMAL_RUNTIME.
82+
// TODO(sbc): Make this the default even without STRICT enabled.
7883
/** @type {function(*, string=)} */
7984
function assert(condition, text) {
8085
if (!condition) {
@@ -88,6 +93,7 @@ function assert(condition, text) {
8893
#endif
8994
}
9095
}
96+
#endif
9197

9298
#if ASSERTIONS
9399
// We used to include malloc/free by default in the past. Show a helpful error in

third_party/closure-compiler/node-externs/assert.js

Lines changed: 0 additions & 137 deletions
This file was deleted.

0 commit comments

Comments
 (0)