From 064a6c048ab420302cbb822bedd3fc365b4259a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 24 Jan 2024 14:57:54 +0100 Subject: feat: Add warnings for more deprecated APIs (#21992) Follow up to https://github.com/denoland/deno/pull/21939 that adds deprecation warnings to more `Deno` APIs: - `Deno.copy()` - `Deno.iter()` - `Deno.iterSync()` - `new Deno.Buffer()` - `Deno.readAll()` - `Deno.readAllSync()` - `Deno.writeAll()` - `Deno.writeAllSync()` - `Deno.FsWatcher.return` - `Deno.serveHttp()` - `Deno.metrics()` --------- Signed-off-by: Asher Gomez Co-authored-by: Asher Gomez --- runtime/js/13_buffer.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'runtime/js/13_buffer.js') diff --git a/runtime/js/13_buffer.js b/runtime/js/13_buffer.js index 36d979e75..cac1a6694 100644 --- a/runtime/js/13_buffer.js +++ b/runtime/js/13_buffer.js @@ -4,7 +4,7 @@ // Copyright 2009 The Go Authors. All rights reserved. BSD license. // https://github.com/golang/go/blob/master/LICENSE -import { primordials } from "ext:core/mod.js"; +import { internals, primordials } from "ext:core/mod.js"; const { ArrayBufferPrototypeGetByteLength, TypedArrayPrototypeSubarray, @@ -45,6 +45,11 @@ class Buffer { #off = 0; // read at buf[off], write at buf[buf.byteLength] constructor(ab) { + internals.warnOnDeprecatedApi( + "new Deno.Buffer()", + new Error().stack, + "Use `Buffer` from `https://deno.land/std/io/buffer.ts` instead.", + ); if (ab == null) { this.#buf = new Uint8Array(0); return; @@ -230,18 +235,33 @@ class Buffer { } async function readAll(r) { + internals.warnOnDeprecatedApi( + "Deno.readAll()", + new Error().stack, + "Use `readAll()` from `https://deno.land/std/io/read_all.ts` instead.", + ); const buf = new Buffer(); await buf.readFrom(r); return buf.bytes(); } function readAllSync(r) { + internals.warnOnDeprecatedApi( + "Deno.readAllSync()", + new Error().stack, + "Use `readAllSync()` from `https://deno.land/std/io/read_all.ts` instead.", + ); const buf = new Buffer(); buf.readFromSync(r); return buf.bytes(); } async function writeAll(w, arr) { + internals.warnOnDeprecatedApi( + "Deno.writeAll()", + new Error().stack, + "Use `writeAll()` from `https://deno.land/std/io/write_all.ts` instead.", + ); let nwritten = 0; while (nwritten < arr.length) { nwritten += await w.write(TypedArrayPrototypeSubarray(arr, nwritten)); @@ -249,6 +269,11 @@ async function writeAll(w, arr) { } function writeAllSync(w, arr) { + internals.warnOnDeprecatedApi( + "Deno.writeAllSync()", + new Error().stack, + "Use `writeAllSync()` from `https://deno.land/std/io/write_all.ts` instead.", + ); let nwritten = 0; while (nwritten < arr.length) { nwritten += w.writeSync(TypedArrayPrototypeSubarray(arr, nwritten)); -- cgit v1.2.3