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