forked from AssemblyScript/assemblyscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabort.js
More file actions
31 lines (29 loc) · 1.03 KB
/
abort.js
File metadata and controls
31 lines (29 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var memory;
var failed;
exports.preInstantiate = function(imports, exports) {
imports["wasi_snapshot_preview1"] = {
fd_write: function(fd, iov, iov_len, nptr) {
if (fd != 2) failed = "unexpected fd: " + fd;
const messagePtr = new Uint32Array(memory.buffer)[ iov >>> 2 ];
const messageLen = new Uint32Array(memory.buffer)[(iov >>> 2) + 1];
const message = Array.from(new Uint8Array(memory.buffer, messagePtr, messageLen)).map(c => String.fromCharCode(c)).join("");
if (message != "abort: the message in wasi/abort.ts(4:3)\n") failed = "unexpected message: " + message;
},
proc_exit: function(code) {
if (code != 255) failed = "unexpected exit code: " + code;
}
};
if (failed) throw Error(failed);
};
exports.postInstantiate = function(instance) {
const exports = instance.exports;
memory = exports.memory;
var thrown = false;
try {
exports.test();
} catch (e) {
thrown = true;
}
if (!thrown) failed = "unexpected missing throw";
if (failed) throw Error(failed);
};