-
Notifications
You must be signed in to change notification settings - Fork 121
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
Add wasm example #344
Add wasm example #344
Conversation
rust-mozjs/examples/wasm.rs
Outdated
env_import.handle() | ||
)); | ||
|
||
let args = HandleValueArray::from_rooted_slice(&[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment about this slice. from_rooted_slice is so easy to misuse ;_;
rust-mozjs/examples/wasm.rs
Outdated
let args_slice = [ObjectValue(module.get()), ObjectValue(imports.get())]; | ||
let args = HandleValueArray::from_rooted_slice(&args_slice); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not 100% sure about this one, I did it like it is done in servo/components/script/dom/paintworkletglobalscope.rs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That code needs to be fixed as well ;_;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a Rust unsafe experienced but wrapping [ObjectValue(module.get()), ObjectValue(imports.get())]
in ManuallyDrop
should be enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The safety risk here is that the garbage collector does not know about the slice that contains those JS values, so if they are moved for any reason (like if a GC occurs during the next spidermonkey API call), the JS values will not be updated with the new pointers. This means the handles passed as arguments would be invalid and could cause a crash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I filed #346 about the missing pieces to make this safe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, but we do have CustomTrace
and auto_root!
so
auto_root!(in(rt.cx()) let vec = vec![ObjectValue(module.get()), ObjectValue(imports.get())]);
should do it, right?
Oh, perhaps I reviewed this too hastily. Maybe @jdm would look at this one as well since there were some comments before. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
Rebased and one new commit added. |
Port of spidermonkey-embedding-examples/examples/wasm.cpp