mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-14 07:21:30 +00:00
Update Binaryen to latest; Various fixes
This commit is contained in:
@ -152,6 +152,30 @@ function postInstantiate(baseModule, instance) {
|
||||
|
||||
baseModule.freeArray = freeArray;
|
||||
|
||||
// Reference the table and remember where to insert the next function
|
||||
var table = exports.table;
|
||||
|
||||
/** Creates a new function in the module's table and returns its pointer. */
|
||||
function newFunction(fn) {
|
||||
var index = table.length;
|
||||
table.grow(1);
|
||||
table.set(index, fn);
|
||||
return index;
|
||||
}
|
||||
|
||||
baseModule.newFunction = newFunction;
|
||||
|
||||
/** Gets a function by its pointer. */
|
||||
function getFunction(ptr) {
|
||||
var fn = table.get(ptr);
|
||||
return (...args) => {
|
||||
exports._setargc(args.length);
|
||||
return fn(...args);
|
||||
};
|
||||
}
|
||||
|
||||
baseModule.getFunction = getFunction;
|
||||
|
||||
// Demangle exports and provide the usual utility on the prototype
|
||||
return demangle(instance.exports, Object.defineProperties(baseModule, {
|
||||
I8: { get: function() { checkMem(); return I8; } },
|
||||
@ -240,7 +264,9 @@ function demangle(exports, baseModule) {
|
||||
enumerable: true
|
||||
});
|
||||
}
|
||||
} else curr[name] = function(...args) { return elem(this.this, ...args); };
|
||||
} else {
|
||||
curr[name] = wrapFunction(elem);
|
||||
}
|
||||
} else {
|
||||
if (/^(get|set):/.test(name)) {
|
||||
if (!hasOwnProperty(curr, name = name.substring(4))) {
|
||||
@ -250,9 +276,25 @@ function demangle(exports, baseModule) {
|
||||
enumerable: true
|
||||
});
|
||||
}
|
||||
} else curr[name] = elem;
|
||||
} else if (typeof elem === "function") {
|
||||
curr[name] = wrapFunction(elem);
|
||||
} else {
|
||||
curr[name] = elem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function wrapFunction(fn) {
|
||||
var ret = function(...args) {
|
||||
exports._setargc(args.length);
|
||||
return fn(...args);
|
||||
};
|
||||
// adding a function to the table with `newFunction` is limited to actual exported WebAssembly
|
||||
// functions, hence we can't use the wrapper for that and instead need to pass a workaround:
|
||||
ret.constructor = fn;
|
||||
return ret;
|
||||
}
|
||||
|
||||
return module;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user