Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/deterministic.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Date.now = deterministicNow;
// Note: this approach does not work on certain versions of Node.js
// Specifically it seems like its not possible to override performance.now on
// node v16 through v18.
// See getPerformanceNow in parseTools.mjs for how we deal with this.
if (globalThis.performance) performance.now = deterministicNow;

// for consistency between different builds than between runs of the same build
Expand Down
12 changes: 6 additions & 6 deletions src/lib/libcore.js
Original file line number Diff line number Diff line change
Expand Up @@ -1355,25 +1355,25 @@ addToLibrary({

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

emscripten_performance_now: () => {{{ getPerformanceNow() }}}(),
emscripten_performance_now: () => performance.now(),

#if PTHREADS && !AUDIO_WORKLET
// Pthreads need their clocks synchronized to the execution of the main
// thread, so, when using them, make sure to adjust all timings to the
// respective time origins.
emscripten_get_now: () => performance.timeOrigin + {{{ getPerformanceNow() }}}(),
emscripten_get_now: () => performance.timeOrigin + performance.now(),
#else
#if AUDIO_WORKLET // https://github.com/WebAudio/web-audio-api/issues/2413
emscripten_get_now: `;
// AudioWorkletGlobalScope does not have performance.now()
// (https://github.com/WebAudio/web-audio-api/issues/2527), so if building
// with
// Audio Worklets enabled, do a dynamic check for its presence.
if (globalThis.performance && {{{ getPerformanceNow() }}}) {
if (globalThis.performance && performance.now) {
#if PTHREADS
_emscripten_get_now = () => performance.timeOrigin + {{{ getPerformanceNow() }}}();
_emscripten_get_now = () => performance.timeOrigin + performance.now();
#else
_emscripten_get_now = () => {{{ getPerformanceNow() }}}();
_emscripten_get_now = () => performance.now();
#endif
} else {
_emscripten_get_now = Date.now;
Expand All @@ -1383,7 +1383,7 @@ addToLibrary({
// Modern environment where performance.now() is supported:
// N.B. a shorter form "_emscripten_get_now = performance.now;" is
// unfortunately not allowed even in current browsers (e.g. FF Nightly 75).
emscripten_get_now: () => {{{ getPerformanceNow() }}}(),
emscripten_get_now: () => performance.now(),
#endif
#endif

Expand Down
12 changes: 0 additions & 12 deletions src/parseTools.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,17 +1105,6 @@ function formattedMinNodeVersion() {
return `v${major}.${minor}.${rev}`;
}

function getPerformanceNow() {
// This is needed to support Node.js v16 - v18 where `performance.now`
// cannot be overridden in the normal way.
// TODO(sbc): remove this once we drop support for these versions.
if (DETERMINISTIC && ENVIRONMENT_MAY_BE_NODE) {
return 'deterministicNow';
} else {
return 'performance.now';
}
}

function ENVIRONMENT_IS_MAIN_THREAD() {
return `(!${ENVIRONMENT_IS_WORKER_THREAD()})`;
}
Expand Down Expand Up @@ -1231,7 +1220,6 @@ addToCompileTimeContext({
getHeapForType,
getHeapOffset,
getNativeTypeSize,
getPerformanceNow,
getUnsharedTextDecoderView,
hasExportedSymbol,
isSymbolNeeded,
Expand Down
2 changes: 2 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -12059,6 +12059,8 @@ def test_deterministic(self):
printf("JS random: %d\n", EM_ASM_INT({ return Math.random() }));
}
''')
if not self.try_require_node_version(19):
self.skipTest('-sDETERMINISTIC requires node v19 or above')
self.run_process([EMCC, 'src.c', '-sDETERMINISTIC'] + self.get_cflags())
one = self.run_js('a.out.js')
# ensure even if the time resolution is 1 second, that if we see the real
Expand Down
3 changes: 3 additions & 0 deletions tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,9 @@ def limit_incoming_module_api():

check_browser_versions()

if settings.DETERMINISTIC and settings.MIN_NODE_VERSION < 190000:
exit_with_error('DETERMINISTIC does not work with node < v19')

if settings.POLYFILL:
# Emscripten requires certain ES6+ constructs by default in library code
# - (various ES6 operators available in all browsers listed below)
Expand Down
Loading