2019-10-25 19:23:16 +02:00
|
|
|
import {
|
|
|
|
assert,
|
|
|
|
assertEquals,
|
|
|
|
assertMatch,
|
2020-03-04 17:31:14 +01:00
|
|
|
unitTest,
|
2020-03-29 04:03:49 +11:00
|
|
|
unreachable,
|
2019-10-25 19:23:16 +02:00
|
|
|
} from "./test_util.ts";
|
|
|
|
|
|
|
|
const readErrorStackPattern = new RegExp(
|
|
|
|
`^.*
|
2020-07-19 19:49:44 +02:00
|
|
|
at unwrapResponse \\(.*dispatch_minimal\\.js:.*\\)
|
|
|
|
at sendAsync \\(.*dispatch_minimal\\.js:.*\\)
|
|
|
|
at async Object\\.read \\(.*io\\.js:.*\\).*$`,
|
2020-07-14 15:24:17 -04:00
|
|
|
"ms",
|
2019-10-25 19:23:16 +02:00
|
|
|
);
|
|
|
|
|
2020-03-04 17:31:14 +01:00
|
|
|
unitTest(async function sendAsyncStackTrace(): Promise<void> {
|
2019-10-25 19:23:16 +02:00
|
|
|
const buf = new Uint8Array(10);
|
2020-02-25 09:14:27 -05:00
|
|
|
const rid = 10;
|
2020-02-05 08:23:23 +00:00
|
|
|
try {
|
2020-02-25 09:14:27 -05:00
|
|
|
await Deno.read(rid, buf);
|
2020-02-05 08:23:23 +00:00
|
|
|
unreachable();
|
|
|
|
} catch (error) {
|
|
|
|
assertMatch(error.stack, readErrorStackPattern);
|
|
|
|
}
|
2019-10-25 19:23:16 +02:00
|
|
|
});
|
2020-02-05 08:23:23 +00:00
|
|
|
|
2020-06-02 14:24:44 +10:00
|
|
|
declare global {
|
2020-11-03 16:19:29 +01:00
|
|
|
// deno-lint-ignore no-namespace
|
2020-06-02 14:24:44 +10:00
|
|
|
namespace Deno {
|
2020-11-03 16:19:29 +01:00
|
|
|
// deno-lint-ignore no-explicit-any
|
2020-06-19 02:05:37 -07:00
|
|
|
var core: any; // eslint-disable-line no-var
|
2020-06-02 14:24:44 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-20 14:38:34 +01:00
|
|
|
unitTest(function malformedMinimalControlBuffer(): void {
|
2020-02-25 09:14:27 -05:00
|
|
|
const readOpId = Deno.core.ops()["op_read"];
|
2020-02-05 08:23:23 +00:00
|
|
|
const res = Deno.core.send(readOpId, new Uint8Array([1, 2, 3, 4, 5]));
|
2019-10-25 19:23:16 +02:00
|
|
|
const header = res.slice(0, 12);
|
|
|
|
const buf32 = new Int32Array(
|
|
|
|
header.buffer,
|
|
|
|
header.byteOffset,
|
2020-07-14 15:24:17 -04:00
|
|
|
header.byteLength / 4,
|
2019-10-25 19:23:16 +02:00
|
|
|
);
|
|
|
|
const arg = buf32[1];
|
2020-08-07 22:47:18 +02:00
|
|
|
const codeAndMessage = new TextDecoder().decode(res.slice(12)).trim();
|
2019-10-25 19:23:16 +02:00
|
|
|
assert(arg < 0);
|
2020-08-07 22:47:18 +02:00
|
|
|
assertEquals(codeAndMessage, "TypeErrorUnparsable control buffer");
|
2019-10-25 19:23:16 +02:00
|
|
|
});
|