perf: remove knowledge of promise IDs from deno (#21132)

We can move all promise ID knowledge to deno_core, allowing us to better
experiment with promise implementation in deno_core.

`{un,}refOpPromise(promise)` is equivalent to
`{un,}refOp(promise[promiseIdSymbol])`
This commit is contained in:
Matt Mastracci 2023-11-09 13:57:26 -07:00 committed by GitHub
parent c4029f6af2
commit 9010b8df53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 70 additions and 124 deletions

55
Cargo.lock generated
View file

@ -1084,19 +1084,17 @@ dependencies = [
[[package]] [[package]]
name = "deno_core" name = "deno_core"
version = "0.228.0" version = "0.229.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78996b42de9975a052cfc9234be39eabf3d6f7721e7cfe79f14a5bd0a252b552" checksum = "6bba7ed998f57ecd03640a82e6ddef281328b6d4c48c55e9e17cd906bab08020"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
"deno_ops", "deno_ops",
"deno_unsync 0.3.0", "deno_unsync 0.3.0",
"futures", "futures",
"indexmap 2.0.2",
"libc", "libc",
"log", "log",
"once_cell",
"parking_lot 0.12.1", "parking_lot 0.12.1",
"pin-project", "pin-project",
"serde", "serde",
@ -1510,18 +1508,13 @@ dependencies = [
[[package]] [[package]]
name = "deno_ops" name = "deno_ops"
version = "0.104.0" version = "0.105.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06291034a0ad5293efcfa01826e4af6adabdfd513b766e2f2cc60dd6c75a94f" checksum = "32976e42a50a1ac64d065a9219f5daf82a3ad6938da9d4aa3071890c08e1cd97"
dependencies = [ dependencies = [
"lazy-regex",
"once_cell",
"pmutil",
"proc-macro-crate",
"proc-macro-rules", "proc-macro-rules",
"proc-macro2", "proc-macro2",
"quote", "quote",
"regex",
"strum", "strum",
"strum_macros", "strum_macros",
"syn 2.0.37", "syn 2.0.37",
@ -3943,15 +3936,6 @@ dependencies = [
"elliptic-curve", "elliptic-curve",
] ]
[[package]]
name = "proc-macro-crate"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8"
dependencies = [
"toml_edit",
]
[[package]] [[package]]
name = "proc-macro-error" name = "proc-macro-error"
version = "1.0.4" version = "1.0.4"
@ -4756,15 +4740,14 @@ dependencies = [
[[package]] [[package]]
name = "serde_v8" name = "serde_v8"
version = "0.137.0" version = "0.138.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c22cbbd634a5b13e9c6a0c6718ae9a8da3696aec5e5eff48fb90e4c9be0809e" checksum = "add36cea4acc8cbfa4a1614a9e985e1057fd6748b672c8b4c4496f889d25e539"
dependencies = [ dependencies = [
"bytes", "bytes",
"derive_more", "derive_more",
"num-bigint", "num-bigint",
"serde", "serde",
"serde_bytes",
"smallvec", "smallvec",
"thiserror", "thiserror",
"v8", "v8",
@ -5844,23 +5827,6 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "toml_datetime"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1"
[[package]]
name = "toml_edit"
version = "0.20.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81"
dependencies = [
"indexmap 2.0.2",
"toml_datetime",
"winnow",
]
[[package]] [[package]]
name = "tower" name = "tower"
version = "0.4.13" version = "0.4.13"
@ -6548,15 +6514,6 @@ version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
[[package]]
name = "winnow"
version = "0.5.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c2e3184b9c4e92ad5167ca73039d0c42476302ab603e2fec4487511f38ccefc"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "winreg" name = "winreg"
version = "0.50.0" version = "0.50.0"

View file

@ -40,7 +40,7 @@ repository = "https://github.com/denoland/deno"
[workspace.dependencies] [workspace.dependencies]
deno_ast = { version = "0.31.2", features = ["transpiling"] } deno_ast = { version = "0.31.2", features = ["transpiling"] }
deno_core = { version = "0.228.0" } deno_core = { version = "0.229.0" }
deno_runtime = { version = "0.130.0", path = "./runtime" } deno_runtime = { version = "0.130.0", path = "./runtime" }
napi_sym = { version = "0.52.0", path = "./cli/napi/sym" } napi_sym = { version = "0.52.0", path = "./cli/napi/sym" }

View file

@ -2,11 +2,11 @@
import { assertNotEquals, execCode } from "./test_util.ts"; import { assertNotEquals, execCode } from "./test_util.ts";
Deno.test("[unrefOp] unref'ing invalid ops does not have effects", async () => { Deno.test("[unrefOpPromise] unref'ing invalid ops does not have effects", async () => {
const [statusCode, _] = await execCode(` const [statusCode, _] = await execCode(`
Deno[Deno.internal].core.unrefOp(-1); Deno[Deno.internal].core.unrefOpPromise(new Promise(r => null));
setTimeout(() => { throw new Error() }, 10) setTimeout(() => { throw new Error() }, 10)
`); `);
// Invalid unrefOp call doesn't affect exit condition of event loop // Invalid unrefOpPromise call doesn't affect exit condition of event loop
assertNotEquals(statusCode, 0); assertNotEquals(statusCode, 0);
}); });

View file

@ -32,7 +32,6 @@ const {
SafeMap, SafeMap,
SafeArrayIterator, SafeArrayIterator,
SafeWeakMap, SafeWeakMap,
SymbolFor,
} = primordials; } = primordials;
import { pathFromURL } from "ext:deno_web/00_infra.js"; import { pathFromURL } from "ext:deno_web/00_infra.js";
@ -52,8 +51,6 @@ function getBufferSourceByteLength(source) {
} }
return ArrayBufferPrototypeGetByteLength(source); return ArrayBufferPrototypeGetByteLength(source);
} }
const promiseIdSymbol = SymbolFor("Deno.core.internalPromiseId");
const U32_BUFFER = new Uint32Array(2); const U32_BUFFER = new Uint32Array(2);
const U64_BUFFER = new BigUint64Array(TypedArrayPrototypeGetBuffer(U32_BUFFER)); const U64_BUFFER = new BigUint64Array(TypedArrayPrototypeGetBuffer(U32_BUFFER));
const I64_BUFFER = new BigInt64Array(TypedArrayPrototypeGetBuffer(U32_BUFFER)); const I64_BUFFER = new BigInt64Array(TypedArrayPrototypeGetBuffer(U32_BUFFER));
@ -422,7 +419,7 @@ class UnsafeCallback {
if (this.#refcount++ === 0) { if (this.#refcount++ === 0) {
if (this.#refpromise) { if (this.#refpromise) {
// Re-refing // Re-refing
core.refOp(this.#refpromise[promiseIdSymbol]); core.refOpPromise(this.#refpromise);
} else { } else {
this.#refpromise = core.opAsync( this.#refpromise = core.opAsync(
"op_ffi_unsafe_callback_ref", "op_ffi_unsafe_callback_ref",
@ -437,7 +434,7 @@ class UnsafeCallback {
// Only decrement refcount if it is positive, and only // Only decrement refcount if it is positive, and only
// unref the callback if refcount reaches zero. // unref the callback if refcount reaches zero.
if (this.#refcount > 0 && --this.#refcount === 0) { if (this.#refcount > 0 && --this.#refcount === 0) {
core.unrefOp(this.#refpromise[promiseIdSymbol]); core.unrefOpPromise(this.#refpromise);
} }
return this.#refcount; return this.#refcount;
} }

View file

@ -44,7 +44,6 @@ const {
ObjectPrototypeIsPrototypeOf, ObjectPrototypeIsPrototypeOf,
PromisePrototypeCatch, PromisePrototypeCatch,
Symbol, Symbol,
SymbolFor,
TypeError, TypeError,
Uint8Array, Uint8Array,
Uint8ArrayPrototype, Uint8ArrayPrototype,
@ -642,7 +641,6 @@ function serveHttpOnConnection(connection, signal, handler, onError, onListen) {
function serveHttpOn(context, callback) { function serveHttpOn(context, callback) {
let ref = true; let ref = true;
let currentPromise = null; let currentPromise = null;
const promiseIdSymbol = SymbolFor("Deno.core.internalPromiseId");
const promiseErrorHandler = (error) => { const promiseErrorHandler = (error) => {
// Abnormal exit // Abnormal exit
@ -666,7 +664,7 @@ function serveHttpOn(context, callback) {
} }
currentPromise = op_http_wait(rid); currentPromise = op_http_wait(rid);
if (!ref) { if (!ref) {
core.unrefOp(currentPromise[promiseIdSymbol]); core.unrefOpPromise(currentPromise);
} }
req = await currentPromise; req = await currentPromise;
currentPromise = null; currentPromise = null;
@ -708,13 +706,13 @@ function serveHttpOn(context, callback) {
ref() { ref() {
ref = true; ref = true;
if (currentPromise) { if (currentPromise) {
core.refOp(currentPromise[promiseIdSymbol]); core.refOpPromise(currentPromise);
} }
}, },
unref() { unref() {
ref = false; ref = false;
if (currentPromise) { if (currentPromise) {
core.unrefOp(currentPromise[promiseIdSymbol]); core.unrefOpPromise(currentPromise);
} }
}, },
[SymbolAsyncDispose]() { [SymbolAsyncDispose]() {

View file

@ -13,23 +13,21 @@ import { SymbolDispose } from "ext:deno_web/00_infra.js";
const primordials = globalThis.__bootstrap.primordials; const primordials = globalThis.__bootstrap.primordials;
const { const {
ArrayPrototypeFilter,
ArrayPrototypeForEach,
ArrayPrototypePush,
Error, Error,
Number, Number,
ObjectPrototypeIsPrototypeOf, ObjectPrototypeIsPrototypeOf,
PromiseResolve, PromiseResolve,
SafeSet,
SetPrototypeAdd,
SetPrototypeDelete,
SetPrototypeForEach,
SymbolAsyncIterator, SymbolAsyncIterator,
Symbol, Symbol,
SymbolFor,
TypeError, TypeError,
TypedArrayPrototypeSubarray, TypedArrayPrototypeSubarray,
Uint8Array, Uint8Array,
} = primordials; } = primordials;
const promiseIdSymbol = SymbolFor("Deno.core.internalPromiseId");
async function write(rid, data) { async function write(rid, data) {
return await core.write(rid, data); return await core.write(rid, data);
} }
@ -70,7 +68,7 @@ class Conn {
#remoteAddr = null; #remoteAddr = null;
#localAddr = null; #localAddr = null;
#unref = false; #unref = false;
#pendingReadPromiseIds = []; #pendingReadPromises = new SafeSet();
#readable; #readable;
#writable; #writable;
@ -102,19 +100,15 @@ class Conn {
return 0; return 0;
} }
const promise = core.read(this.rid, buffer); const promise = core.read(this.rid, buffer);
const promiseId = promise[promiseIdSymbol]; if (this.#unref) core.unrefOpPromise(promise);
if (this.#unref) core.unrefOp(promiseId); SetPrototypeAdd(this.#pendingReadPromises, promise);
ArrayPrototypePush(this.#pendingReadPromiseIds, promiseId);
let nread; let nread;
try { try {
nread = await promise; nread = await promise;
} catch (e) { } catch (e) {
throw e; throw e;
} finally { } finally {
this.#pendingReadPromiseIds = ArrayPrototypeFilter( SetPrototypeDelete(this.#pendingReadPromises, promise);
this.#pendingReadPromiseIds,
(id) => id !== promiseId,
);
} }
return nread === 0 ? null : nread; return nread === 0 ? null : nread;
} }
@ -149,7 +143,11 @@ class Conn {
if (this.#readable) { if (this.#readable) {
readableStreamForRidUnrefableRef(this.#readable); readableStreamForRidUnrefableRef(this.#readable);
} }
ArrayPrototypeForEach(this.#pendingReadPromiseIds, (id) => core.refOp(id));
SetPrototypeForEach(
this.#pendingReadPromises,
(promise) => core.refOpPromise(promise),
);
} }
unref() { unref() {
@ -157,9 +155,9 @@ class Conn {
if (this.#readable) { if (this.#readable) {
readableStreamForRidUnrefableUnref(this.#readable); readableStreamForRidUnrefableUnref(this.#readable);
} }
ArrayPrototypeForEach( SetPrototypeForEach(
this.#pendingReadPromiseIds, this.#pendingReadPromises,
(id) => core.unrefOp(id), (promise) => core.unrefOpPromise(promise),
); );
} }
@ -184,7 +182,7 @@ class Listener {
#rid = 0; #rid = 0;
#addr = null; #addr = null;
#unref = false; #unref = false;
#promiseId = null; #promise = null;
constructor(rid, addr) { constructor(rid, addr) {
this.#rid = rid; this.#rid = rid;
@ -211,10 +209,10 @@ class Listener {
default: default:
throw new Error(`Unsupported transport: ${this.addr.transport}`); throw new Error(`Unsupported transport: ${this.addr.transport}`);
} }
this.#promiseId = promise[promiseIdSymbol]; this.#promise = promise;
if (this.#unref) core.unrefOp(this.#promiseId); if (this.#unref) core.unrefOpPromise(promise);
const { 0: rid, 1: localAddr, 2: remoteAddr } = await promise; const { 0: rid, 1: localAddr, 2: remoteAddr } = await promise;
this.#promiseId = null; this.#promise = null;
if (this.addr.transport == "tcp") { if (this.addr.transport == "tcp") {
localAddr.transport = "tcp"; localAddr.transport = "tcp";
remoteAddr.transport = "tcp"; remoteAddr.transport = "tcp";
@ -265,15 +263,15 @@ class Listener {
ref() { ref() {
this.#unref = false; this.#unref = false;
if (typeof this.#promiseId === "number") { if (this.#promise !== null) {
core.refOp(this.#promiseId); core.refOpPromise(this.#promise);
} }
} }
unref() { unref() {
this.#unref = true; this.#unref = true;
if (typeof this.#promiseId === "number") { if (this.#promise !== null) {
core.unrefOp(this.#promiseId); core.unrefOpPromise(this.#promise);
} }
} }
} }

View file

@ -68,7 +68,7 @@ const kDenoResponse = Symbol("kDenoResponse");
const kDenoRid = Symbol("kDenoRid"); const kDenoRid = Symbol("kDenoRid");
const kDenoClientRid = Symbol("kDenoClientRid"); const kDenoClientRid = Symbol("kDenoClientRid");
const kDenoConnRid = Symbol("kDenoConnRid"); const kDenoConnRid = Symbol("kDenoConnRid");
const kPollConnPromiseId = Symbol("kPollConnPromiseId"); const kPollConnPromise = Symbol("kPollConnPromise");
const STREAM_FLAGS_PENDING = 0x0; const STREAM_FLAGS_PENDING = 0x0;
const STREAM_FLAGS_READY = 0x1; const STREAM_FLAGS_READY = 0x1;
@ -364,7 +364,7 @@ export class ClientHttp2Session extends Http2Session {
this[kPendingRequestCalls] = null; this[kPendingRequestCalls] = null;
this[kDenoClientRid] = undefined; this[kDenoClientRid] = undefined;
this[kDenoConnRid] = undefined; this[kDenoConnRid] = undefined;
this[kPollConnPromiseId] = undefined; this[kPollConnPromise] = undefined;
socket.on("error", socketOnError); socket.on("error", socketOnError);
socket.on("close", socketOnClose); socket.on("close", socketOnClose);
@ -394,8 +394,7 @@ export class ClientHttp2Session extends Http2Session {
"op_http2_poll_client_connection", "op_http2_poll_client_connection",
this[kDenoConnRid], this[kDenoConnRid],
); );
this[kPollConnPromiseId] = this[kPollConnPromise] = promise;
promise[Symbol.for("Deno.core.internalPromiseId")];
if (!this.#refed) { if (!this.#refed) {
this.unref(); this.unref();
} }
@ -410,15 +409,15 @@ export class ClientHttp2Session extends Http2Session {
ref() { ref() {
this.#refed = true; this.#refed = true;
if (this[kPollConnPromiseId]) { if (this[kPollConnPromise]) {
core.refOp(this[kPollConnPromiseId]); core.refOpPromise(this[kPollConnPromise]);
} }
} }
unref() { unref() {
this.#refed = false; this.#refed = false;
if (this[kPollConnPromiseId]) { if (this[kPollConnPromise]) {
core.unrefOp(this[kPollConnPromiseId]); core.unrefOpPromise(this[kPollConnPromise]);
} }
} }

View file

@ -16,7 +16,6 @@ const {
PromisePrototypeThen, PromisePrototypeThen,
SafeArrayIterator, SafeArrayIterator,
SafeMap, SafeMap,
SymbolFor,
TypedArrayPrototypeGetBuffer, TypedArrayPrototypeGetBuffer,
TypeError, TypeError,
indirectEval, indirectEval,
@ -75,7 +74,7 @@ function handleTimerMacrotask() {
* The keys in this map correspond to the key ID's in the spec's map of active * The keys in this map correspond to the key ID's in the spec's map of active
* timers. The values are the timeout's cancel rid. * timers. The values are the timeout's cancel rid.
* *
* @type {Map<number, { cancelRid: number, isRef: boolean, promiseId: number }>} * @type {Map<number, { cancelRid: number, isRef: boolean, promise: Promise<void> }>}
*/ */
const activeTimers = new SafeMap(); const activeTimers = new SafeMap();
@ -114,7 +113,7 @@ function initializeTimer(
// https://github.com/whatwg/html/issues/7358 // https://github.com/whatwg/html/issues/7358
id = nextId++; id = nextId++;
const cancelRid = ops.op_timer_handle(); const cancelRid = ops.op_timer_handle();
timerInfo = { cancelRid, isRef: true, promiseId: -1 }; timerInfo = { cancelRid, isRef: true, promise: null };
// Step 4 in "run steps after a timeout". // Step 4 in "run steps after a timeout".
MapPrototypeSet(activeTimers, id, timerInfo); MapPrototypeSet(activeTimers, id, timerInfo);
@ -216,7 +215,7 @@ const scheduledTimers = { head: null, tail: null };
* @param { {action: () => void, nestingLevel: number}[] } task Will be run * @param { {action: () => void, nestingLevel: number}[] } task Will be run
* after the timeout, if it hasn't been cancelled. * after the timeout, if it hasn't been cancelled.
* @param {number} millis * @param {number} millis
* @param {{ cancelRid: number, isRef: boolean, promiseId: number }} timerInfo * @param {{ cancelRid: number, isRef: boolean, promise: Promise<void> }} timerInfo
*/ */
function runAfterTimeout(task, millis, timerInfo) { function runAfterTimeout(task, millis, timerInfo) {
const cancelRid = timerInfo.cancelRid; const cancelRid = timerInfo.cancelRid;
@ -230,9 +229,9 @@ function runAfterTimeout(task, millis, timerInfo) {
} else { } else {
sleepPromise = op_sleep(millis, cancelRid); sleepPromise = op_sleep(millis, cancelRid);
} }
timerInfo.promiseId = sleepPromise[SymbolFor("Deno.core.internalPromiseId")]; timerInfo.promise = sleepPromise;
if (!timerInfo.isRef) { if (!timerInfo.isRef) {
core.unrefOp(timerInfo.promiseId); core.unrefOpPromise(timerInfo.promise);
} }
/** @type {ScheduledTimer} */ /** @type {ScheduledTimer} */
@ -376,7 +375,7 @@ function refTimer(id) {
return; return;
} }
timerInfo.isRef = true; timerInfo.isRef = true;
core.refOp(timerInfo.promiseId); core.refOpPromise(timerInfo.promise);
} }
function unrefTimer(id) { function unrefTimer(id) {
@ -385,7 +384,7 @@ function unrefTimer(id) {
return; return;
} }
timerInfo.isRef = false; timerInfo.isRef = false;
core.unrefOp(timerInfo.promiseId); core.unrefOpPromise(timerInfo.promise);
} }
export { export {

View file

@ -967,7 +967,7 @@ function readableStreamForRid(rid, autoClose = true) {
return stream; return stream;
} }
const promiseIdSymbol = SymbolFor("Deno.core.internalPromiseId"); const promiseSymbol = SymbolFor("__promise");
const _isUnref = Symbol("isUnref"); const _isUnref = Symbol("isUnref");
/** /**
* Create a new ReadableStream object that is backed by a Resource that * Create a new ReadableStream object that is backed by a Resource that
@ -981,7 +981,7 @@ const _isUnref = Symbol("isUnref");
*/ */
function readableStreamForRidUnrefable(rid) { function readableStreamForRidUnrefable(rid) {
const stream = new ReadableStream(_brand); const stream = new ReadableStream(_brand);
stream[promiseIdSymbol] = undefined; stream[promiseSymbol] = undefined;
stream[_isUnref] = false; stream[_isUnref] = false;
stream[_resourceBackingUnrefable] = { rid, autoClose: true }; stream[_resourceBackingUnrefable] = { rid, autoClose: true };
const underlyingSource = { const underlyingSource = {
@ -990,10 +990,10 @@ function readableStreamForRidUnrefable(rid) {
const v = controller.byobRequest.view; const v = controller.byobRequest.view;
try { try {
const promise = core.read(rid, v); const promise = core.read(rid, v);
const promiseId = stream[promiseIdSymbol] = promise[promiseIdSymbol]; stream[promiseSymbol] = promise;
if (stream[_isUnref]) core.unrefOp(promiseId); if (stream[_isUnref]) core.unrefOpPromise(promise);
const bytesRead = await promise; const bytesRead = await promise;
stream[promiseIdSymbol] = undefined; stream[promiseSymbol] = undefined;
if (bytesRead === 0) { if (bytesRead === 0) {
core.tryClose(rid); core.tryClose(rid);
controller.close(); controller.close();
@ -1030,8 +1030,8 @@ function readableStreamForRidUnrefableRef(stream) {
throw new TypeError("Not an unrefable stream"); throw new TypeError("Not an unrefable stream");
} }
stream[_isUnref] = false; stream[_isUnref] = false;
if (stream[promiseIdSymbol] !== undefined) { if (stream[promiseSymbol] !== undefined) {
core.refOp(stream[promiseIdSymbol]); core.refOpPromise(stream[promiseSymbol]);
} }
} }
@ -1040,8 +1040,8 @@ function readableStreamForRidUnrefableUnref(stream) {
throw new TypeError("Not an unrefable stream"); throw new TypeError("Not an unrefable stream");
} }
stream[_isUnref] = true; stream[_isUnref] = true;
if (stream[promiseIdSymbol] !== undefined) { if (stream[promiseSymbol] !== undefined) {
core.unrefOp(stream[promiseIdSymbol]); core.unrefOpPromise(stream[promiseSymbol]);
} }
} }
@ -1064,10 +1064,11 @@ async function readableStreamCollectIntoUint8Array(stream) {
readableStreamDisturb(stream); readableStreamDisturb(stream);
const promise = core.opAsync("op_read_all", resourceBacking.rid); const promise = core.opAsync("op_read_all", resourceBacking.rid);
if (readableStreamIsUnrefable(stream)) { if (readableStreamIsUnrefable(stream)) {
const promiseId = stream[promiseIdSymbol] = promise[promiseIdSymbol]; stream[promiseSymbol] = promise;
if (stream[_isUnref]) core.unrefOp(promiseId); if (stream[_isUnref]) core.unrefOpPromise(promise);
} }
const buf = await promise; const buf = await promise;
stream[promiseSymbol] = undefined;
readableStreamThrowIfErrored(stream); readableStreamThrowIfErrored(stream);
readableStreamClose(stream); readableStreamClose(stream);
return buf; return buf;

View file

@ -13,7 +13,6 @@ const {
ObjectPrototypeIsPrototypeOf, ObjectPrototypeIsPrototypeOf,
PromisePrototypeThen, PromisePrototypeThen,
SafePromiseAll, SafePromiseAll,
SymbolFor,
Symbol, Symbol,
} = primordials; } = primordials;
import { FsFile } from "ext:deno_fs/30_fs.js"; import { FsFile } from "ext:deno_fs/30_fs.js";
@ -148,7 +147,6 @@ function run({
} }
const illegalConstructorKey = Symbol("illegalConstructorKey"); const illegalConstructorKey = Symbol("illegalConstructorKey");
const promiseIdSymbol = SymbolFor("Deno.core.internalPromiseId");
function spawnChildInner(opFn, command, apiName, { function spawnChildInner(opFn, command, apiName, {
args = [], args = [],
@ -203,7 +201,7 @@ function collectOutput(readableStream) {
class ChildProcess { class ChildProcess {
#rid; #rid;
#waitPromiseId; #waitPromise;
#waitComplete = false; #waitComplete = false;
#pid; #pid;
@ -266,7 +264,7 @@ class ChildProcess {
signal?.[abortSignal.add](onAbort); signal?.[abortSignal.add](onAbort);
const waitPromise = core.opAsync("op_spawn_wait", this.#rid); const waitPromise = core.opAsync("op_spawn_wait", this.#rid);
this.#waitPromiseId = waitPromise[promiseIdSymbol]; this.#waitPromise = waitPromise;
this.#status = PromisePrototypeThen(waitPromise, (res) => { this.#status = PromisePrototypeThen(waitPromise, (res) => {
signal?.[abortSignal.remove](onAbort); signal?.[abortSignal.remove](onAbort);
this.#waitComplete = true; this.#waitComplete = true;
@ -333,13 +331,13 @@ class ChildProcess {
} }
ref() { ref() {
core.refOp(this.#waitPromiseId); core.refOpPromise(this.#waitPromise);
if (this.#stdout) readableStreamForRidUnrefableRef(this.#stdout); if (this.#stdout) readableStreamForRidUnrefableRef(this.#stdout);
if (this.#stderr) readableStreamForRidUnrefableRef(this.#stderr); if (this.#stderr) readableStreamForRidUnrefableRef(this.#stderr);
} }
unref() { unref() {
core.unrefOp(this.#waitPromiseId); core.unrefOpPromise(this.#waitPromise);
if (this.#stdout) readableStreamForRidUnrefableUnref(this.#stdout); if (this.#stdout) readableStreamForRidUnrefableUnref(this.#stdout);
if (this.#stderr) readableStreamForRidUnrefableUnref(this.#stderr); if (this.#stderr) readableStreamForRidUnrefableUnref(this.#stderr);
} }

View file

@ -8,7 +8,6 @@ const {
SafeSetIterator, SafeSetIterator,
SetPrototypeAdd, SetPrototypeAdd,
SetPrototypeDelete, SetPrototypeDelete,
SymbolFor,
TypeError, TypeError,
} = primordials; } = primordials;
@ -18,7 +17,7 @@ function bindSignal(signo) {
function pollSignal(rid) { function pollSignal(rid) {
const promise = core.opAsync("op_signal_poll", rid); const promise = core.opAsync("op_signal_poll", rid);
core.unrefOp(promise[SymbolFor("Deno.core.internalPromiseId")]); core.unrefOpPromise(promise);
return promise; return promise;
} }