Skip to content

Commit 43f8f83

Browse files
committed
Remove performance.now hackery which only exists for node v18 + DETERMINISTIC. NFC
I don't think its worth the extra complexity to support `DETERMINISTIC` on node v18 since that combination is likely extremely rare. (I don't know of any active users of `-sDETERMINISTIC` myself).
1 parent 426fb2d commit 43f8f83

5 files changed

Lines changed: 11 additions & 19 deletions

File tree

src/deterministic.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ Date.now = deterministicNow;
2020
// Note: this approach does not work on certain versions of Node.js
2121
// Specifically it seems like its not possible to override performance.now on
2222
// node v16 through v18.
23-
// See getPerformanceNow in parseTools.mjs for how we deal with this.
2423
if (globalThis.performance) performance.now = deterministicNow;
2524

2625
// for consistency between different builds than between runs of the same build

src/lib/libcore.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,25 +1355,25 @@ addToLibrary({
13551355

13561356
emscripten_date_now: () => Date.now(),
13571357

1358-
emscripten_performance_now: () => {{{ getPerformanceNow() }}}(),
1358+
emscripten_performance_now: () => performance.now(),
13591359

13601360
#if PTHREADS && !AUDIO_WORKLET
13611361
// Pthreads need their clocks synchronized to the execution of the main
13621362
// thread, so, when using them, make sure to adjust all timings to the
13631363
// respective time origins.
1364-
emscripten_get_now: () => performance.timeOrigin + {{{ getPerformanceNow() }}}(),
1364+
emscripten_get_now: () => performance.timeOrigin + performance.now(),
13651365
#else
13661366
#if AUDIO_WORKLET // https://github.com/WebAudio/web-audio-api/issues/2413
13671367
emscripten_get_now: `;
13681368
// AudioWorkletGlobalScope does not have performance.now()
13691369
// (https://github.com/WebAudio/web-audio-api/issues/2527), so if building
13701370
// with
13711371
// Audio Worklets enabled, do a dynamic check for its presence.
1372-
if (globalThis.performance && {{{ getPerformanceNow() }}}) {
1372+
if (globalThis.performance && performance.now) {
13731373
#if PTHREADS
1374-
_emscripten_get_now = () => performance.timeOrigin + {{{ getPerformanceNow() }}}();
1374+
_emscripten_get_now = () => performance.timeOrigin + performance.now();
13751375
#else
1376-
_emscripten_get_now = () => {{{ getPerformanceNow() }}}();
1376+
_emscripten_get_now = () => performance.now();
13771377
#endif
13781378
} else {
13791379
_emscripten_get_now = Date.now;
@@ -1383,7 +1383,7 @@ addToLibrary({
13831383
// Modern environment where performance.now() is supported:
13841384
// N.B. a shorter form "_emscripten_get_now = performance.now;" is
13851385
// unfortunately not allowed even in current browsers (e.g. FF Nightly 75).
1386-
emscripten_get_now: () => {{{ getPerformanceNow() }}}(),
1386+
emscripten_get_now: () => performance.now(),
13871387
#endif
13881388
#endif
13891389

src/parseTools.mjs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,17 +1105,6 @@ function formattedMinNodeVersion() {
11051105
return `v${major}.${minor}.${rev}`;
11061106
}
11071107

1108-
function getPerformanceNow() {
1109-
// This is needed to support Node.js v16 - v18 where `performance.now`
1110-
// cannot be overridden in the normal way.
1111-
// TODO(sbc): remove this once we drop support for these versions.
1112-
if (DETERMINISTIC && ENVIRONMENT_MAY_BE_NODE) {
1113-
return 'deterministicNow';
1114-
} else {
1115-
return 'performance.now';
1116-
}
1117-
}
1118-
11191108
function ENVIRONMENT_IS_MAIN_THREAD() {
11201109
return `(!${ENVIRONMENT_IS_WORKER_THREAD()})`;
11211110
}
@@ -1231,7 +1220,6 @@ addToCompileTimeContext({
12311220
getHeapForType,
12321221
getHeapOffset,
12331222
getNativeTypeSize,
1234-
getPerformanceNow,
12351223
getUnsharedTextDecoderView,
12361224
hasExportedSymbol,
12371225
isSymbolNeeded,

test/test_other.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12059,6 +12059,8 @@ def test_deterministic(self):
1205912059
printf("JS random: %d\n", EM_ASM_INT({ return Math.random() }));
1206012060
}
1206112061
''')
12062+
if not self.try_require_node_version(19):
12063+
self.skipTest('-sDETERMINISTIC requires node v19 or above')
1206212064
self.run_process([EMCC, 'src.c', '-sDETERMINISTIC'] + self.get_cflags())
1206312065
one = self.run_js('a.out.js')
1206412066
# ensure even if the time resolution is 1 second, that if we see the real

tools/link.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,9 @@ def limit_incoming_module_api():
13661366

13671367
check_browser_versions()
13681368

1369+
if settings.DETERMINISTIC and settings.MIN_NODE_VERSION < 190000:
1370+
exit_with_error('DETERMINISTIC does not work with node < v19')
1371+
13691372
if settings.POLYFILL:
13701373
# Emscripten requires certain ES6+ constructs by default in library code
13711374
# - (various ES6 operators available in all browsers listed below)

0 commit comments

Comments
 (0)