CString/CArray was an illusion; Update and test tsconfig files

This commit is contained in:
dcodeIO
2017-12-11 02:03:15 +01:00
parent 0228ab91d9
commit d0b189b437
33 changed files with 477 additions and 509 deletions

View File

@ -1,7 +1,7 @@
require("../../portable-assembly");
require("../../portable-assembly"); // not inherited from tsconfig by ts-node otherwise :(
// Copy Binaryen exports to global scope
var globalScope = typeof window !== "undefined" && window || typeof global !== "undefined" && global || self;
var binaryen;
try {
binaryen = require("binaryen");
@ -9,29 +9,36 @@ try {
binaryen = globalScope["Binaryen"];
}
for (var key in binaryen)
if (/^_(?:Binaryen|Relooper|malloc$|free$)/.test(key))
if (/^_(?:Binaryen|Relooper)/.test(key))
globalScope[key] = binaryen[key];
// Use Binaryen's heap
Object.defineProperties(globalScope['Heap'] = {
allocate: binaryen._malloc,
dispose: binaryen._free
}, {
free: { get: function() { return binaryen.HEAPU8.length; } },
used: { get: function() { return 0; } },
size: { get: function() { return binaryen.HEAPU8.length; } }
});
globalScope["store"] = function store(ptr, val) {
binaryen.HEAPU8[ptr] = val;
};
globalScope["load"] = function load_u8(ptr) {
return binaryen.HEAPU8[ptr];
};
// Implement module stubs
var Module = require("../module").Module;
Module.prototype.toBinary = function toBinary(bufferSize) {
if (!bufferSize) bufferSize = 1024 * 1024;
if (!bufferSize) bufferSize = 1024 * 1024; // FIXME: see binaryen.js-post.js in Binaryen
var ptr = _malloc(bufferSize);
var len = this.write(ptr, bufferSize);
var ret = new Uint8Array(len);
ret.set(binaryen.HEAPU8.subarray(ptr, ptr + len));
_free(ptr);
return ret;
}
};
Module.prototype.toText = function toText() {
var previousPrint = binaryen.print;
var ret = "";
@ -39,8 +46,7 @@ Module.prototype.toText = function toText() {
this.print();
binaryen.print = previousPrint;
return ret;
}
};
Module.prototype.toAsmjs = function toAsmjs() {
var previousPrint = binaryen.print;
var ret = "";
@ -48,4 +54,4 @@ Module.prototype.toAsmjs = function toAsmjs() {
this.printAsmjs();
binaryen.print = previousPrint;
return ret;
}
};