From 92b2e28c6491f339124ec5851173ac0aaef93908 Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Sun, 24 Dec 2023 06:04:32 -0700 Subject: chore: ensure that each op provided to ensureFastOps is only used once (#21689) When we migrate to op-import-per-extension, we will want to ensure that ops have one and only one place where they are imported. This tackles the ops that are imported via `ensureFastOps`, but does not yet tackle direct `ops` imports. Landing ahead of https://github.com/denoland/deno_core/pull/393 --- ext/web/02_timers.js | 8 ++++++++ ext/web/06_streams.js | 1 + ext/web/13_message_port.js | 3 ++- 3 files changed, 11 insertions(+), 1 deletion(-) (limited to 'ext/web') diff --git a/ext/web/02_timers.js b/ext/web/02_timers.js index 27a9fcbde..c7dc90c82 100644 --- a/ext/web/02_timers.js +++ b/ext/web/02_timers.js @@ -386,9 +386,17 @@ function unrefTimer(id) { core.unrefOpPromise(timerInfo.promise); } +// Defer to avoid starving the event loop. Not using queueMicrotask() +// for that reason: it lets promises make forward progress but can +// still starve other parts of the event loop. +function defer(go) { + PromisePrototypeThen(op_void_async_deferred(), () => go()); +} + export { clearInterval, clearTimeout, + defer, handleTimerMacrotask, opNow, refTimer, diff --git a/ext/web/06_streams.js b/ext/web/06_streams.js index 1df375328..988f1d990 100644 --- a/ext/web/06_streams.js +++ b/ext/web/06_streams.js @@ -6895,6 +6895,7 @@ export { errorReadableStream, getReadableStreamResourceBacking, getWritableStreamResourceBacking, + isDetachedBuffer, isReadableStreamDisturbed, ReadableByteStreamController, ReadableStream, diff --git a/ext/web/13_message_port.js b/ext/web/13_message_port.js index c1ba3f4c4..9645f5f11 100644 --- a/ext/web/13_message_port.js +++ b/ext/web/13_message_port.js @@ -17,6 +17,7 @@ import { setEventTargetData, setIsTrusted, } from "ext:deno_web/02_event.js"; +import { isDetachedBuffer } from "ext:deno_web/06_streams.js"; import DOMException from "ext:deno_web/01_dom_exception.js"; const { ArrayBufferPrototype, @@ -282,7 +283,7 @@ function serializeJsMessageData(data, transferables) { if (ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, t)) { if ( ArrayBufferPrototypeGetByteLength(t) === 0 && - ops.op_arraybuffer_was_detached(t) + isDetachedBuffer(t) ) { throw new DOMException( `ArrayBuffer at index ${j} is already detached`, -- cgit v1.2.3