2023-01-13 02:51:32 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
2023-06-08 14:10:37 -04:00
|
|
|
import { assertEquals } from "../../../test_util/std/testing/asserts.ts";
|
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
|
|
|
try {
|
2023-04-30 04:50:24 -04:00
|
|
|
await core.ops.op_error_async();
|
2021-03-18 09:10:27 -04:00
|
|
|
unreachable();
|
|
|
|
} catch (error) {
|
2021-10-27 17:43:40 -04:00
|
|
|
assert(error instanceof Error);
|
|
|
|
const s = error.stack?.toString();
|
|
|
|
assert(s);
|
2021-04-23 11:50:45 -04:00
|
|
|
assertStringIncludes(s, "opcall_test.ts");
|
2023-04-30 04:50:24 -04:00
|
|
|
assertStringIncludes(s, "sendAsyncStackTrace");
|
2021-10-07 12:39:27 -04:00
|
|
|
assert(
|
2023-03-08 06:44:54 -05:00
|
|
|
!s.includes("ext:core"),
|
|
|
|
"opcall stack traces should NOT include ext:core internals such as unwrapOpResult",
|
2021-10-07 12:39:27 -04:00
|
|
|
);
|
2021-03-18 09:10:27 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-04-30 04:50:24 -04:00
|
|
|
Deno.test(async function sendAsyncStackTraceDeferred() {
|
|
|
|
try {
|
|
|
|
await core.ops.op_error_async_deferred();
|
|
|
|
unreachable();
|
|
|
|
} catch (error) {
|
|
|
|
assert(error instanceof Error);
|
|
|
|
const s = error.stack?.toString();
|
|
|
|
assert(s);
|
|
|
|
assertStringIncludes(s, "opcall_test.ts");
|
|
|
|
assertStringIncludes(s, "sendAsyncStackTraceDeferred");
|
|
|
|
assert(
|
|
|
|
!s.includes("ext:core"),
|
|
|
|
"opcall stack traces should NOT include ext:core internals such as unwrapOpResult",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test(function syncAdd() {
|
|
|
|
assertEquals(30, core.ops.op_add(10, 20));
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test(async function asyncAdd() {
|
|
|
|
assertEquals(30, await core.ops.op_add_async(10, 20));
|
|
|
|
});
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|