-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Returning Result<Vec<u8>, JsError>
from an async
function doesn't work
#3155
Comments
This issue is unpleasant. Any chance of extending to functionality for |
I didn't look into it, but I don't think this requires any design work, so PRs are welcome. |
I created a custom type to wrap around the Vec. Was asking about future prospects. |
I'm not aware of any current maintainers interested in working on something like this. |
Fyi I ran into the same and would welcome a fix. For |
Hi @daxpedda I would like to work on this bug if no one is working on it! Thanks ~ |
Go right ahead 😃! |
Hi @daxpedda this currently solution I can think about is like impl<T> From<Vec<T>> for JsValue {
#[inline]
fn from(s: Vec<T>) -> JsValue {
JsValue::from(s.as_ptr() as usize)
}
} but this would first convert the raw pointer into f64 , /// Creates a new JS value which is a number.
///
/// This function creates a JS value representing a number (a heap
/// allocated number) and returns a handle to the JS version of it.
#[inline]
pub fn from_f64(n: f64) -> JsValue {
unsafe { JsValue::_new(__wbindgen_number_new(n)) }
} then pass it to the JS function which adds it to heap module.exports.__wbindgen_number_new = function(arg0) {
const ret = arg0;
return addHeapObject(ret);
};
function addHeapObject(obj) {
if (heap_next === heap.length) heap.push(heap.length + 1);
const idx = heap_next;
heap_next = heap[idx];
heap[idx] = obj;
return idx;
} I do not know if the behavior is correct or not, since it just adds the address of vec to the JS heap, but in It seems like we need to convert vec into JS Array ? |
Oh, I'm actually already partway through implementing this. I'd forgotten that this issue existed, I was working on it because I was fixing the issue @cschramm pointed out in #3554 (comment) that #3554 didn't cover async functions. But I should probably put more effort into making sure I've self-assigned myself to anything I'm working on. |
Sorry @Solo-steven, poor communication on our part here ... |
It is OK, and thanks @Liamolucko for giving me the link to related PR so that I can learn from it! thanks |
This means that `Vec`s can now be returned from `async` functions. Fixes rustwasm#3155. I had to add a new `VectorIntoJsValue` trait, since similarly to `VectorIntoWasmAbi` the orphan rule won't let us directly implement `From<Vec<T>>` for `JsValue` outside of `wasm-bindgen`.
This means that `Vec`s can now be returned from `async` functions. Fixes rustwasm#3155. I had to add a new `VectorIntoJsValue` trait, since similarly to `VectorIntoWasmAbi` the orphan rule won't let us directly implement `From<Vec<T>>` for `JsValue` outside of `wasm-bindgen`.
* Implement `Into<JsValue>` for `Vec` This means that `Vec`s can now be returned from `async` functions. Fixes #3155. I had to add a new `VectorIntoJsValue` trait, since similarly to `VectorIntoWasmAbi` the orphan rule won't let us directly implement `From<Vec<T>>` for `JsValue` outside of `wasm-bindgen`. * Implement Into<JsValue> for boxed slices of numbers as well * Add changelog entry * Fix memory leak * Add missing if_std! * Move the changelog entry to the right spot
Describe the Bug
The following compiles:
While the following does not:
Steps to Reproduce
cargo check
Expected Behavior
Whatever works without
async
works the same withasync
.Actual Behavior
Sometimes, it does not 😔.
Additional Context
Not the first instance of this issue (see #3059).
The text was updated successfully, but these errors were encountered: