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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
declare global {
|
|
|
|
namespace Deno {
|
2021-11-01 16:22:27 -04:00
|
|
|
// deno-lint-ignore no-explicit-any, no-var
|
2021-05-18 11:24:01 -04:00
|
|
|
var core: any;
|
2021-03-18 09:10:27 -04:00
|
|
|
}
|
|
|
|
}
|
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;
|
2021-11-09 13:26:17 -05:00
|
|
|
await Deno.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;
|
2022-08-11 09:56:56 -04:00
|
|
|
Deno.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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|