mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-14 21:41:23 +00:00
Support by-value self methods (#348)
Refactor slightly to use the same internal support that the other reference conversions are using. Closes #329
This commit is contained in:
@ -66,14 +66,22 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
|
||||
|
||||
/// Flag this shim as a method call into Rust, so the first Rust argument
|
||||
/// passed should be `this.ptr`.
|
||||
pub fn method(&mut self, method: bool) -> &mut Self {
|
||||
pub fn method(&mut self, method: bool, consumed: bool) -> &mut Self {
|
||||
if method {
|
||||
self.prelude(
|
||||
"if (this.ptr === 0) {
|
||||
throw new Error('Attempt to use a moved value');
|
||||
}",
|
||||
throw new Error('Attempt to use a moved value');
|
||||
}"
|
||||
);
|
||||
self.rust_arguments.insert(0, "this.ptr".to_string());
|
||||
if consumed {
|
||||
self.prelude("\
|
||||
const ptr = this.ptr;\n\
|
||||
this.ptr = 0;\n\
|
||||
");
|
||||
self.rust_arguments.insert(0, "ptr".to_string());
|
||||
} else {
|
||||
self.rust_arguments.insert(0, "this.ptr".to_string());
|
||||
}
|
||||
}
|
||||
self
|
||||
}
|
||||
|
Reference in New Issue
Block a user