-
-
Notifications
You must be signed in to change notification settings - Fork 670
Passing Instance through an Object Literal Causes a runtime error on exit #1272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Translated your example to this test case: class OtherClass {
stuff: i32;
constructor(newStuff: i32) {
this.stuff = newStuff;
}
}
class MyClassInit {
otherClass: OtherClass;
}
class MyClass {
_myParam: i32;
_otherClass: OtherClass;
constructor(param: i32, init: MyClassInit) {
this._myParam = param;
this._otherClass = init.otherClass;
}
toString(): string {
return this._otherClass.stuff.toString();
}
}
function start(): void {
// Make our Other class
let otherClass = new OtherClass(24);
// Pass to my class as an object literal
let myClass = new MyClass(2424, {
otherClass: otherClass
});
trace("Logging myClass.toString() ...");
trace(myClass.toString());
}
start(); Running this on master, with rtrace enabled, doesn't show any problems. Might this have been fixed since the last release? |
Hmm, I don't see any issues in browser ( It could be problem with |
@dcodeIO I guess need test with node.js and as-wasi for reproduce full picture. |
@torch2424 btw you use pretty old assemblyscript version in your playground: https://github.com/torch2424/as-playground/blob/master/object-literal-pass-instance/package-lock.json#L12 |
writeStringLn(s: string): void {
let s_utf8_buf = String.UTF8.encode(s); // __retain
let s_utf8_len: usize = s_utf8_buf.byteLength;
let iov = changetype<ArrayBufferView>(mem256).dataStart;
store<u32>(iov, changetype<usize>(s_utf8_buf)); // mem256 = [s_utf8_buf]
store<u32>(iov, s_utf8_len, sizeof<usize>()); // mem256 = [s_utf8_buf, s_utf8_len]
let lf = changetype<ArrayBufferView>(mem64).dataStart;
store<u8>(lf, 10); // mem64 = [10]
store<u32>(iov, lf, sizeof<usize>() * 2); // mem256 = [s_utf8_buf, s_utf8_len, lf]
store<u32>(iov, 1, sizeof<usize>() * 3); // mem256 = [s_utf8_buf, s_utf8_len, lf, 1]
let written_ptr = changetype<ArrayBufferView>(mem64).dataStart;
fd_write(this.rawfd, iov, 2, written_ptr);
// ^ writes to mem64 at 0 (undefined behavior)
// __release(s_utf8_buf)
} Looks fine from a runtime perspective, with the UB depending on the implementation of |
Oh Wow that was fast haha! 😄 Thanks y'all!
So I tried installing the latest master with my example and it didn't work 😢
Two minors is old? 😂 But thanks for catching that! I updated to
So I replaced out as-wasi and the console logging and it didn't work: So It may be an issue with Wasmtime? Though, I originally found this bug running AS on Lucet 🤔
I think your responding to Max here, but just in case: I don't think there's anything wrong with the Logging. Because I can totally add some more logs after my testing logs, or do whatever I need to do, and it's fine. I think we may have some dangling memory or something weird after the |
In my test, what might have happened is that since I'm not importing |
Tried to compile your exact snippet using as-wasi from Git and AS master, but that doesn't compile due to
Are you sure you tried with master? I think you should have seen that error as well then. |
Updating the snippet to AS 0.10.0 (incl. adding import "wasi";
import {Console} from "as-wasi";
class OtherClass {
stuff: i32;
constructor(newStuff: i32) {
this.stuff = newStuff;
}
}
class MyClassInit {
otherClass: OtherClass;
}
class MyClass {
_myParam: i32;
_otherClass: OtherClass;
constructor(param: i32, init: MyClassInit) {
this._myParam = param;
this._otherClass = init.otherClass;
}
toString(): string {
return this._otherClass.stuff.toString();
}
}
// Make our Other class
let otherClass = new OtherClass(24);
// Pass to my class as an object literal
let myClass = new MyClass(2424, {
otherClass: otherClass
});
Console.log("Logging myClass.toString() ...\n");
Console.log(myClass.toString());
Console.log("\n"); compiling with
and then running it in wasmtime v0.16.0
seems to work:
|
Oh huh :o I installed from git using like the syntax of:
Maybe that doesn't install master for you? 🤔
Just tested this, and yep, Closing this... |
Hello!
So I noticed another thing weird with Object literals. If I try to pass a class into my init object, to construct my other class. Everything works fine, but when everything is done, the runtime will throw a memory error.
Here is the test case code:
Here is a reproducable test case: https://github.com/torch2424/as-playground/tree/master/object-literal-pass-instance
cc @dcodeIO or @MaxGraey , if you can point me to where this would be fixed in the compiler (would this object literal be fixed in the same place as #1229 ), I can make this fix 😄
Screenshot
The text was updated successfully, but these errors were encountered: