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 <ashersaupingomez@gmail.com>
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
This commit is contained in:
Bartek Iwańczuk 2024-01-24 14:57:54 +01:00 committed by GitHub
parent 745333f073
commit 064a6c048a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 70 additions and 23 deletions

View file

@ -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));