From 71ca61e189cca9215982ce4598b7a4da8430c584 Mon Sep 17 00:00:00 2001 From: snek Date: Fri, 2 Aug 2024 11:16:59 -0700 Subject: Revert "feat: async context" (#24856) Reverts denoland/deno#24402 deno_web can't depend on code in runtime --- ext/web/02_timers.js | 52 ++++++++++++++++------------------------------------ 1 file changed, 16 insertions(+), 36 deletions(-) (limited to 'ext/web') diff --git a/ext/web/02_timers.js b/ext/web/02_timers.js index a651df5a5..559147861 100644 --- a/ext/web/02_timers.js +++ b/ext/web/02_timers.js @@ -2,10 +2,6 @@ import { core, primordials } from "ext:core/mod.js"; import { op_defer, op_now } from "ext:core/ops"; -import { - getAsyncContext, - setAsyncContext, -} from "ext:runtime/01_async_context.js"; const { Uint8Array, Uint32Array, @@ -37,16 +33,14 @@ function checkThis(thisArg) { * Call a callback function immediately. */ function setImmediate(callback, ...args) { - const asyncContext = getAsyncContext(); - return core.queueImmediate(() => { - const oldContext = getAsyncContext(); - try { - setAsyncContext(asyncContext); - return ReflectApply(callback, globalThis, args); - } finally { - setAsyncContext(oldContext); - } - }); + if (args.length > 0) { + const unboundCallback = callback; + callback = () => ReflectApply(unboundCallback, globalThis, args); + } + + return core.queueImmediate( + callback, + ); } /** @@ -59,17 +53,10 @@ function setTimeout(callback, timeout = 0, ...args) { const unboundCallback = webidl.converters.DOMString(callback); callback = () => indirectEval(unboundCallback); } - const unboundCallback = callback; - const asyncContext = getAsyncContext(); - callback = () => { - const oldContext = getAsyncContext(); - try { - setAsyncContext(asyncContext); - ReflectApply(unboundCallback, globalThis, args); - } finally { - setAsyncContext(oldContext); - } - }; + if (args.length > 0) { + const unboundCallback = callback; + callback = () => ReflectApply(unboundCallback, globalThis, args); + } timeout = webidl.converters.long(timeout); return core.queueUserTimer( core.getTimerDepth() + 1, @@ -88,17 +75,10 @@ function setInterval(callback, timeout = 0, ...args) { const unboundCallback = webidl.converters.DOMString(callback); callback = () => indirectEval(unboundCallback); } - const unboundCallback = callback; - const asyncContext = getAsyncContext(); - callback = () => { - const oldContext = getAsyncContext(asyncContext); - try { - setAsyncContext(asyncContext); - ReflectApply(unboundCallback, globalThis, args); - } finally { - setAsyncContext(oldContext); - } - }; + if (args.length > 0) { + const unboundCallback = callback; + callback = () => ReflectApply(unboundCallback, globalThis, args); + } timeout = webidl.converters.long(timeout); return core.queueUserTimer( core.getTimerDepth() + 1, -- cgit v1.2.3