From 174bb70eda6bd3eea48c9fcd240041a62749eab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 25 Jan 2024 00:45:19 +0100 Subject: [PATCH] fix: don't use public rid accessors in internal APIs (#22091) Co-authored-by: Asher Gomez --- ext/http/00_serve.js | 5 +++-- ext/net/01_net.js | 9 +++++++++ ext/net/02_tls.js | 7 ++++++- runtime/js/40_http.js | 7 +++++-- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/ext/http/00_serve.js b/ext/http/00_serve.js index 578eb718f7..977497c0bb 100644 --- a/ext/http/00_serve.js +++ b/ext/http/00_serve.js @@ -33,6 +33,7 @@ const { PromisePrototypeCatch, PromisePrototypeThen, Symbol, + SymbolFor, TypeError, TypedArrayPrototypeGetSymbolToStringTag, Uint8Array, @@ -617,7 +618,7 @@ function serve(arg1, arg2) { function serveHttpOnListener(listener, signal, handler, onError, onListen) { const context = new CallbackContext( signal, - op_http_serve(listener.rid), + op_http_serve(listener[SymbolFor("Deno.internal.rid")]), listener, ); const callback = mapToCallback(context, handler, onError); @@ -633,7 +634,7 @@ function serveHttpOnListener(listener, signal, handler, onError, onListen) { function serveHttpOnConnection(connection, signal, handler, onError, onListen) { const context = new CallbackContext( signal, - op_http_serve_on(connection.rid), + op_http_serve_on(connection[SymbolFor("Deno.internal.rid")]), null, ); const callback = mapToCallback(context, handler, onError); diff --git a/ext/net/01_net.js b/ext/net/01_net.js index a2b04de76a..f761aed14a 100644 --- a/ext/net/01_net.js +++ b/ext/net/01_net.js @@ -40,6 +40,7 @@ const { SetPrototypeForEach, SymbolAsyncIterator, Symbol, + SymbolFor, TypeError, TypedArrayPrototypeSubarray, Uint8Array, @@ -90,6 +91,7 @@ async function resolveDns(query, recordType, options) { } class Conn { + [SymbolFor("Deno.internal.rid")] = 0; #rid = 0; #remoteAddr = null; #localAddr = null; @@ -100,6 +102,7 @@ class Conn { #writable; constructor(rid, remoteAddr, localAddr) { + this[SymbolFor("Deno.internal.rid")] = rid; this.#rid = rid; this.#remoteAddr = remoteAddr; this.#localAddr = localAddr; @@ -198,10 +201,12 @@ class Conn { } class TcpConn extends Conn { + [SymbolFor("Deno.internal.rid")] = 0; #rid = 0; constructor(rid, remoteAddr, localAddr) { super(rid, remoteAddr, localAddr); + this[SymbolFor("Deno.internal.rid")] = rid; this.#rid = rid; } @@ -224,10 +229,12 @@ class TcpConn extends Conn { } class UnixConn extends Conn { + [SymbolFor("Deno.internal.rid")] = 0; #rid = 0; constructor(rid, remoteAddr, localAddr) { super(rid, remoteAddr, localAddr); + this[SymbolFor("Deno.internal.rid")] = rid; this.#rid = rid; } @@ -242,12 +249,14 @@ class UnixConn extends Conn { } class Listener { + [SymbolFor("Deno.internal.rid")] = 0; #rid = 0; #addr = null; #unref = false; #promise = null; constructor(rid, addr) { + this[SymbolFor("Deno.internal.rid")] = rid; this.#rid = rid; this.#addr = addr; } diff --git a/ext/net/02_tls.js b/ext/net/02_tls.js index 5405d68a38..021ad93716 100644 --- a/ext/net/02_tls.js +++ b/ext/net/02_tls.js @@ -10,6 +10,7 @@ const { } = core.ensureFastOps(); const { Number, + SymbolFor, TypeError, } = primordials; @@ -24,10 +25,12 @@ function opTlsHandshake(rid) { } class TlsConn extends Conn { + [SymbolFor("Deno.internal.rid")] = 0; #rid = 0; constructor(rid, remoteAddr, localAddr) { super(rid, remoteAddr, localAddr); + this[SymbolFor("Deno.internal.rid")] = rid; this.#rid = rid; } @@ -75,10 +78,12 @@ async function connectTls({ } class TlsListener extends Listener { + [SymbolFor("Deno.internal.rid")] = 0; #rid = 0; constructor(rid, addr) { super(rid, addr); + this[SymbolFor("Deno.internal.rid")] = rid; this.#rid = rid; } @@ -146,7 +151,7 @@ async function startTls( } = {}, ) { const { 0: rid, 1: localAddr, 2: remoteAddr } = await opStartTls({ - rid: conn.rid, + rid: conn[SymbolFor("Deno.internal.rid")], hostname, certFile, caCerts, diff --git a/runtime/js/40_http.js b/runtime/js/40_http.js index fcabf237bc..313adcbee9 100644 --- a/runtime/js/40_http.js +++ b/runtime/js/40_http.js @@ -1,8 +1,11 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { core, internals } from "ext:core/mod.js"; +import { core, internals, primordials } from "ext:core/mod.js"; const { op_http_start, } = core.ensureFastOps(); +const { + SymbolFor, +} = primordials; import { HttpConn } from "ext:deno_http/01_http.js"; @@ -12,7 +15,7 @@ function serveHttp(conn) { new Error().stack, "Use `Deno.serve()` instead.", ); - const rid = op_http_start(conn.rid); + const rid = op_http_start(conn[SymbolFor("Deno.internal.rid")]); return new HttpConn(rid, conn.remoteAddr, conn.localAddr); }