summaryrefslogtreecommitdiff
path: root/src/js/binaryen.js-post.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/binaryen.js-post.js')
-rw-r--r--src/js/binaryen.js-post.js48
1 files changed, 42 insertions, 6 deletions
diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js
index fd121b8af..d7c1878fd 100644
--- a/src/js/binaryen.js-post.js
+++ b/src/js/binaryen.js-post.js
@@ -3061,18 +3061,18 @@ function makeExpressionWrapper(ownStaticMembers) {
// inherit from Expression
(SpecificExpression.prototype = Object.create(Expression.prototype)).constructor = SpecificExpression;
// make own instance members
- makeExpressionWrapperInstanceMembers(SpecificExpression.prototype, ownStaticMembers);
+ makeWrapperInstanceMembers(SpecificExpression.prototype, ownStaticMembers);
return SpecificExpression;
}
// Makes instance members from the given static members
-function makeExpressionWrapperInstanceMembers(prototype, staticMembers) {
+function makeWrapperInstanceMembers(prototype, staticMembers, ref = 'expr') {
Object.keys(staticMembers).forEach(memberName => {
const member = staticMembers[memberName];
if (typeof member === "function") {
// Instance method calls the respective static method
prototype[memberName] = function(...args) {
- return this.constructor[memberName](this['expr'], ...args);
+ return this.constructor[memberName](this[ref], ...args);
};
// Instance accessor calls the respective static methods
let match;
@@ -3082,10 +3082,10 @@ function makeExpressionWrapperInstanceMembers(prototype, staticMembers) {
const setterIfAny = staticMembers["set" + memberName.substring(index)];
Object.defineProperty(prototype, propertyName, {
get() {
- return member(this['expr']);
+ return member(this[ref]);
},
set(value) {
- if (setterIfAny) setterIfAny(this['expr'], value);
+ if (setterIfAny) setterIfAny(this[ref], value);
else throw Error("property '" + propertyName + "' has no setter");
}
});
@@ -3114,7 +3114,7 @@ Expression['finalize'] = function(expr) {
Expression['toText'] = function(expr) {
return Module['emitText'](expr);
};
-makeExpressionWrapperInstanceMembers(Expression.prototype, Expression);
+makeWrapperInstanceMembers(Expression.prototype, Expression);
Expression.prototype['valueOf'] = function() {
return this['expr'];
};
@@ -4281,6 +4281,42 @@ Module['TupleExtract'] = makeExpressionWrapper({
}
});
+// Function wrapper
+
+Module['Function'] = (() => {
+ function Function(func) {
+ if (!(this instanceof Function)) {
+ if (!func) return null;
+ return new Function(func);
+ }
+ if (!func) throw Error("function reference must not be null");
+ this['func'] = func;
+ }
+ Function['getName'] = function(func) {
+ return Module['_BinaryenFunctionGetName'](func);
+ };
+ Function['getNumLocals'] = function(func) {
+ return Module['_BinaryenFunctionGetNumLocals'](func);
+ };
+ Function['hasLocalName'] = function(func, index) {
+ return Boolean(Module['_BinaryenFunctionHasLocalName'](func, index));
+ };
+ Function['getLocalName'] = function(func, index) {
+ return UTF8ToString(Module['_BinaryenFunctionGetLocalName'](func, index));
+ };
+ Function['setLocalName'] = function(func, index, name) {
+ preserveStack(() => {
+ Module['_BinaryenFunctionSetLocalName'](func, index, strToStack(name));
+ });
+ };
+ // TODO: add more methods
+ makeWrapperInstanceMembers(Function.prototype, Function, 'func');
+ Function.prototype['valueOf'] = function() {
+ return this['func'];
+ };
+ return Function;
+})();
+
// Additional customizations
Module['exit'] = function(status) {