mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-09 13:01:26 +00:00
Improve demangling of class methods when using the loader (#363)
This commit is contained in:
parent
934f05eed9
commit
429435c5b1
@ -265,7 +265,7 @@ function demangle(exports, baseModule) {
|
||||
let classElem = curr[className];
|
||||
if (typeof classElem === "undefined" || !classElem.prototype) {
|
||||
let ctor = function(...args) {
|
||||
return ctor.wrap(ctor.prototype.constructor(...args));
|
||||
return ctor.wrap(ctor.prototype.constructor(0, ...args));
|
||||
};
|
||||
ctor.prototype = {};
|
||||
ctor.wrap = function(thisValue) {
|
||||
@ -289,7 +289,16 @@ function demangle(exports, baseModule) {
|
||||
});
|
||||
}
|
||||
} else {
|
||||
curr[name] = wrapFunction(elem, setargc);
|
||||
if (name === 'constructor') {
|
||||
curr[name] = wrapFunction(elem, setargc);
|
||||
} else { // for methods
|
||||
Object.defineProperty(curr, name, {
|
||||
value: function (...args) {
|
||||
setargc(args.length);
|
||||
return elem(this.this, ...args);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (/^(get|set):/.test(name)) {
|
||||
|
@ -60,5 +60,14 @@ assert.strictEqual(fn(2), 4);
|
||||
ptr = module.newFunction(module.varadd);
|
||||
assert.strictEqual(module.calladd(ptr, 2, 3), 5);
|
||||
|
||||
// should be able to use a class
|
||||
var car = new module.Car(5);
|
||||
assert.strictEqual(car.numDoors, 5);
|
||||
assert.strictEqual(car.isDoorsOpen, 0);
|
||||
car.openDoors();
|
||||
assert.strictEqual(car.isDoorsOpen, 1);
|
||||
car.closeDoors();
|
||||
assert.strictEqual(car.isDoorsOpen, 0);
|
||||
|
||||
// should be able to use trace
|
||||
module.dotrace(42);
|
||||
module.dotrace(42);
|
Loading…
x
Reference in New Issue
Block a user