1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00
denoland-deno/cli/tests/unit/opcall_test.ts
Aaron O'Mullan 375ce63c63
feat(core): streams (#12596)
This allows resources to be "streams" by implementing read/write/shutdown. These streams are implicit since their nature (read/write/duplex) isn't known until called, but we could easily add another method to explicitly tag resources as streams.

`op_read/op_write/op_shutdown` are now builtin ops provided by `deno_core`

Note: this current implementation is simple & straightforward but it results in an additional alloc per read/write call

Closes #12556
2021-11-09 19:26:17 +01:00

58 lines
1.2 KiB
TypeScript

import {
assert,
assertStringIncludes,
unitTest,
unreachable,
} from "./test_util.ts";
unitTest(async function sendAsyncStackTrace() {
const buf = new Uint8Array(10);
const rid = 10;
try {
await Deno.read(rid, buf);
unreachable();
} catch (error) {
assert(error instanceof Error);
const s = error.stack?.toString();
assert(s);
console.log(s);
assertStringIncludes(s, "opcall_test.ts");
assertStringIncludes(s, "read");
assert(
!s.includes("deno:core"),
"opcall stack traces should NOT include deno:core internals such as unwrapOpResult",
);
}
});
declare global {
namespace Deno {
// deno-lint-ignore no-explicit-any, no-var
var core: any;
}
}
unitTest(async function opsAsyncBadResource() {
try {
const nonExistingRid = 9999;
await Deno.core.read(
nonExistingRid,
new Uint8Array(0),
);
} catch (e) {
if (!(e instanceof Deno.errors.BadResource)) {
throw e;
}
}
});
unitTest(function opsSyncBadResource() {
try {
const nonExistingRid = 9999;
Deno.core.opSync("op_read_sync", nonExistingRid, new Uint8Array(0));
} catch (e) {
if (!(e instanceof Deno.errors.BadResource)) {
throw e;
}
}
});