-
Notifications
You must be signed in to change notification settings - Fork 6
/
post.js
29 lines (26 loc) · 973 Bytes
/
post.js
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
(function() {
Module.ready = new Promise(function (resolve, reject) {
addOnPreMain(() => {
var init = Module.cwrap('init', 'number', ['string', 'number', 'string']);
var validate = Module.cwrap('validate', 'number', ['number', 'string']);
var jsInit = function(xsd, filename) {
var code = init(xsd, xsd.length, filename);
postMessage({ file: filename, loaded: code === 0 });
}
var jsValidate = function(xml, filename) {
var length = lengthBytesUTF8(xml) + 1;
var buf = Module._malloc(length);
stringToUTF8(xml, buf, length);
var code = validate(buf, filename);
postMessage({ file: filename, valid: code === 0, code: code });
Module._free(buf);
}
resolve({ init: jsInit, validate: jsValidate });
});
var origAbort = Module.abort;
Module.abort = function(reason) {
reject(Error(reason));
origAbort.call(this, reason);
}
});
})();