feat(unstable): use Node.js setTimeout and setInterval (#29993)

This commit repurposes `--unstable-node-globals` flag that was
deprecated
in https://github.com/denoland/deno/pull/29887 to switch out timers
implemention that is used.

Ie. using this flag cause `setTimeout`, `setInterval`, `clearTimeout`
and `clearInterval` globals to use functions from `node:timers` 
module instead of the Web version.

This is also enabled using `DENO_COMPAT=1` env var. 

TODO:
<s>make typechecking be conditional depending on this, most likely
requires
changes in our TS fork.</s> This has been deferred until Deno 3

Towards https://github.com/denoland/deno/issues/29703

---------

Signed-off-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: David Sherret <dsherret@users.noreply.github.com>
This commit is contained in:
Bartek Iwańczuk 2025-09-09 00:48:58 +02:00 committed by GitHub
parent 3e58caa8f4
commit a434ac2a1e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 78 additions and 8 deletions

View file

@ -738,7 +738,6 @@ function bootstrapMainRuntime(runtimeOptions, warmup = false) {
location.setLocationHref(location_);
}
exposeUnstableFeaturesForWindowOrWorkerGlobalScope(unstableFeatures);
ObjectDefineProperties(globalThis, mainRuntimeGlobalProperties);
ObjectDefineProperties(globalThis, {
// TODO(bartlomieju): in the future we might want to change the
@ -748,6 +747,7 @@ function bootstrapMainRuntime(runtimeOptions, warmup = false) {
close: core.propWritable(windowClose),
closed: core.propGetterOnly(() => windowIsClosing),
});
exposeUnstableFeaturesForWindowOrWorkerGlobalScope(unstableFeatures);
ObjectSetPrototypeOf(globalThis, Window.prototype);
bootstrapOtel(otelConfig);
@ -859,7 +859,6 @@ function bootstrapWorkerRuntime(
delete globalThis.bootstrap;
hasBootstrapped = true;
exposeUnstableFeaturesForWindowOrWorkerGlobalScope(unstableFeatures);
if (workerType === "node") {
delete workerRuntimeGlobalProperties["WorkerGlobalScope"];
delete workerRuntimeGlobalProperties["self"];
@ -878,6 +877,7 @@ function bootstrapWorkerRuntime(
core.propWritable(importScripts),
);
}
exposeUnstableFeaturesForWindowOrWorkerGlobalScope(unstableFeatures);
ObjectSetPrototypeOf(globalThis, DedicatedWorkerGlobalScope.prototype);
bootstrapOtel(otelConfig);