2023-01-13 02:51:32 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
import { assert, assertStringIncludes, unreachable } from "./test_util.ts";
|
2021-03-18 09:10:27 -04:00
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(async function sendAsyncStackTrace() {
|
2021-03-18 09:10:27 -04:00
|
|
|
const buf = new Uint8Array(10);
|
|
|
|
const rid = 10;
|
|
|
|
try {
|
|
|
|
await Deno.read(rid, buf);
|
|
|
|
unreachable();
|
|
|
|
} catch (error) {
|
2021-10-27 17:43:40 -04:00
|
|
|
assert(error instanceof Error);
|
|
|
|
const s = error.stack?.toString();
|
|
|
|
assert(s);
|
2021-04-09 11:55:33 -04:00
|
|
|
console.log(s);
|
2021-04-23 11:50:45 -04:00
|
|
|
assertStringIncludes(s, "opcall_test.ts");
|
2021-04-09 11:55:33 -04:00
|
|
|
assertStringIncludes(s, "read");
|
2021-10-07 12:39:27 -04:00
|
|
|
assert(
|
|
|
|
!s.includes("deno:core"),
|
|
|
|
"opcall stack traces should NOT include deno:core internals such as unwrapOpResult",
|
|
|
|
);
|
2021-03-18 09:10:27 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-01-24 12:54:10 -05:00
|
|
|
// @ts-ignore This is not publicly typed namespace, but it's there for sure.
|
|
|
|
const core = Deno[Deno.internal].core;
|
2021-04-08 12:04:02 -04:00
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(async function opsAsyncBadResource() {
|
2021-04-08 12:04:02 -04:00
|
|
|
try {
|
|
|
|
const nonExistingRid = 9999;
|
2023-01-24 12:54:10 -05:00
|
|
|
await core.read(
|
2021-04-08 12:04:02 -04:00
|
|
|
nonExistingRid,
|
|
|
|
new Uint8Array(0),
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
if (!(e instanceof Deno.errors.BadResource)) {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(function opsSyncBadResource() {
|
2021-04-08 12:04:02 -04:00
|
|
|
try {
|
|
|
|
const nonExistingRid = 9999;
|
2023-01-24 12:54:10 -05:00
|
|
|
core.ops.op_read_sync(
|
|
|
|
nonExistingRid,
|
|
|
|
new Uint8Array(0),
|
|
|
|
);
|
2021-04-08 12:04:02 -04:00
|
|
|
} catch (e) {
|
|
|
|
if (!(e instanceof Deno.errors.BadResource)) {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|