Skip to content

Commit

Permalink
fix(node): remove deprecation warnings (#22120)
Browse files Browse the repository at this point in the history
Closes #22116
  • Loading branch information
bartlomieju committed Jan 26, 2024
1 parent cd3af19 commit 616646c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
1 change: 0 additions & 1 deletion cli/tests/node_compat/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ async function runTest(t: Deno.TestContext, path: string): Promise<void> {
"run",
"-A",
"--quiet",
"--unstable",
//"--unsafely-ignore-certificate-errors",
"--unstable-bare-node-builtins",
"--v8-flags=" + v8Flags.join(),
Expand Down
2 changes: 2 additions & 0 deletions ext/fs/30_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,12 +655,14 @@ function create(path) {
}

class FsFile {
[SymbolFor("Deno.internal.rid")] = 0;
#rid = 0;

#readable;
#writable;

constructor(rid, symbol) {
this[SymbolFor("Deno.internal.rid")] = rid;
this.#rid = rid;
if (!symbol || symbol !== SymbolFor("Deno.internal.FsFile")) {
internals.warnOnDeprecatedApi(
Expand Down
8 changes: 5 additions & 3 deletions ext/node/polyfills/_fs/_fs_open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export function open(
path as string,
convertFlagAndModeToOptions(flags as openFlags, mode),
).then(
(file) => callback!(null, file.rid),
(file) => callback!(null, file[Symbol.for("Deno.internal.rid")]),
(err) => (callback as (err: Error) => void)(err),
);
}
Expand Down Expand Up @@ -186,8 +186,10 @@ export function openSync(
throw new Error(`EEXIST: file already exists, open '${path}'`);
}

return Deno.openSync(path as string, convertFlagAndModeToOptions(flags, mode))
.rid;
return Deno.openSync(
path as string,
convertFlagAndModeToOptions(flags, mode),
)[Symbol.for("Deno.internal.rid")];
}

function existenceCheckRequired(flags: openFlags | number) {
Expand Down
16 changes: 11 additions & 5 deletions ext/node/polyfills/internal_binding/stream_wrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ import {
} from "ext:deno_node/internal_binding/async_wrap.ts";
import { codeMap } from "ext:deno_node/internal_binding/uv.ts";

const DENO_RID_SYMBOL = Symbol.for("Deno.internal.rid");

interface Reader {
read(p: Uint8Array): Promise<number | null>;
}
Expand Down Expand Up @@ -203,7 +205,7 @@ export class LibuvStreamWrap extends HandleWrap {
allBuffers: boolean,
): number {
const supportsWritev = this.provider === providerType.TCPSERVERWRAP;
const rid = this[kStreamBaseField]!.rid;
const rid = this[kStreamBaseField]![DENO_RID_SYMBOL];
// Fast case optimization: two chunks, and all buffers.
if (
chunks.length === 2 && allBuffers && supportsWritev &&
Expand Down Expand Up @@ -317,13 +319,15 @@ export class LibuvStreamWrap extends HandleWrap {
async #read() {
let buf = this.#buf;
let nread: number | null;
const ridBefore = this[kStreamBaseField]!.rid;
const ridBefore = this[kStreamBaseField]![DENO_RID_SYMBOL];
try {
nread = await this[kStreamBaseField]!.read(buf);
} catch (e) {
// Try to read again if the underlying stream resource
// changed. This can happen during TLS upgrades (eg. STARTTLS)
if (ridBefore != this[kStreamBaseField]!.rid) {
if (
ridBefore != this[kStreamBaseField]![DENO_RID_SYMBOL]
) {
return this.#read();
}

Expand Down Expand Up @@ -373,7 +377,7 @@ export class LibuvStreamWrap extends HandleWrap {
async #write(req: WriteWrap<LibuvStreamWrap>, data: Uint8Array) {
const { byteLength } = data;

const ridBefore = this[kStreamBaseField]!.rid;
const ridBefore = this[kStreamBaseField]![DENO_RID_SYMBOL];

let nwritten = 0;
try {
Expand All @@ -386,7 +390,9 @@ export class LibuvStreamWrap extends HandleWrap {
} catch (e) {
// Try to read again if the underlying stream resource
// changed. This can happen during TLS upgrades (eg. STARTTLS)
if (ridBefore != this[kStreamBaseField]!.rid) {
if (
ridBefore != this[kStreamBaseField]![DENO_RID_SYMBOL]
) {
return this.#write(req, data.subarray(nwritten));
}

Expand Down

0 comments on commit 616646c

Please sign in to comment.