-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add basic support for String.prototype.char_at() #286
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
import * as assert from "assert"; | ||
import * as wasm from "./out"; | ||
|
||
var anyString = 'Brave new world'; |
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.
This is taken from the documentation. I haven't added a test case for default index = 0
as I am not sure currently it's possible
Nice :). I was trying to make either, .length or .includes() work for String. But got obscure errors for both. If you happen to solve one of those I'd be interested to see what went wrong. Code for Also it looks like you're getting some errors on array for types, it's now expecting |
Can you give me more details about that change, I am not sure how to use the appropriate |
Regarding defaults and optional parameters: because we don't currently have good support for these features, we have to make a decision about what to do on a per-case basis. In this case, I don't think the default behavior is useful enough that we want to expose it, and should simply require that folks provide the index.
These errors are occurring because the new Eventually, there is a more fundamental question of whether we should eagerly copy JS strings into the wasm heap as Rust strings or not. Right now, we should continue following the existing behavior. We can do that by calling JS strings #[wasm_bindgen]
extern {
#[wasm_bindgen(js_name = String)]
pub extern type JsString;
} If this doesn't work, then I think we should skip adding |
@fitzgen It does not seem to work to call it |
I agree, I still can't make it work like this. |
Ok, let's skip bindings for JS |
Filed #287 to track fixing the underlying issues here. |
I really would love to get some feedback.
Also one question I couldn't answer myself - what about optional parameters?
char_at()
has index, which by default should be 0, but in Rust there is no way to do it and I am not quite sure I understand thewasn-bindgen
enough for that. Also some other implementations with optional value don't have it yet, e.g.Array.prototype.includes()
I hope I can fully finish this PR.
PS: Currently the Array and Object are not in Alphabetical order as in the Guidelines.