-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Implement Array.prototype.filter and Array.prototype.find #300
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
Conversation
Yeah, I would say that is a good idea, since filter will throw an error if it is not a function in normal javascript. You can have a look at #299 for how I handled the case of Result in the tests as an example perhaps. |
@jonathan-s ah I see. Will implement something similar. Thanks! |
Hmm looks like I will need to return |
For type mismatch errors that we can statically ensure we won't ever trigger via Rust's type system, there is no need to If we are going the other way -- exporting a Rust function that takes a JS function as input (which is also not even implemented yet) -- then we do have to do the dynamic type checks because there is no statically typed compiler checking the JS side of things, like there is on the Rust side in the previous example. |
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 think we should make these take functions as input rather than JsValue
, see https://rustwasm.github.io/wasm-bindgen/closures.html for details.
Ah yes @fitzgen thanks that makes a lot more sense. This makes more sense logically: pub fn find(this: &Array, function: &Fn(JsValue) -> bool) -> JsValue; However, I end up getting this error:
which, if I remember correctly @jonathan-s also received. |
Yeah, got that too
On Sun 24. Jun 2018 at 01:41, Robert Durst ***@***.***> wrote:
Ah yes @fitzgen <https://github.com/fitzgen> thanks that makes a lot more
sense.
This makes more sense logically:
pub fn find(this: &Array, function: &Fn(JsValue) -> bool) -> JsValue;
However, I end up getting this error:
the trait `wasm_bindgen::convert::RefFromWasmAbi` is not implemented for `std::ops::Fn(wasm_bindgen::JsValue) -> bool + 'static`
which, if I remember correctly @jonathan-s <https://github.com/jonathan-s>
also received.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#300 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACBsEjUSSZm83qUIgtA8N5XuvMaCOohIks5t_tI6gaJpZM4U03uC>
.
--
Sent from Gmail Mobile
|
I can confirm this error. Also tried with |
What is the solution here? Should we implement |
I'm not 100% sure -- I need to dig in a little more to figure out why the existing function support isn't working here. |
Closing for now since |
For both of these, I use
JsValue
to capture a function as input -- which is possible since functions are values in JS. However, these fail if the user does not input a function. What is the recommended way to safe guard against this? Should I use the#[wasm_bindgen(catch)]
with-> Result<JsValue, JsValue>
?