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-07-19 13:49:44 -04: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 13:23:16 -04:00
|
|
|
);
|
|
|
|
|
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
|
|
|
declare global {
|
2020-06-19 05:05:37 -04:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
2020-06-02 00:24:44 -04:00
|
|
|
namespace Deno {
|
2020-06-19 05:05:37 -04:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
var core: any; // eslint-disable-line no-var
|
2020-06-02 00:24:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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,
|
2020-07-14 15:24:17 -04:00
|
|
|
header.byteLength / 4,
|
2019-10-25 13:23:16 -04:00
|
|
|
);
|
|
|
|
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");
|
|
|
|
});
|