Skip to content

add js_class attribute for defining what class an imported method is for #295

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

Merged
merged 2 commits into from
Jun 23, 2018
Merged

add js_class attribute for defining what class an imported method is for #295

merged 2 commits into from
Jun 23, 2018

Conversation

kzvi
Copy link
Contributor

@kzvi kzvi commented Jun 22, 2018

Allows this to work:

#[wasm_bindgen]
extern {
    #[wasm_bindgen(js_name = String)]
    pub type JsString;

    #[wasm_bindgen(method, js_class = "String")] // <-- here
    pub fn slice(this: &JsString, start: u32, end: u32) -> JsString;
}


#[wasm_bindgen]
pub fn f(x: JsString) -> JsString {
    x.slice(1, 3)
}

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look great!

But before we merge this, can you add test coverage for this? A great way to do that would be to add the JsString bindings from your comment to src/js.rs and a corresponding test to tests/all/js_globals/JsString.rs similar to Array.rs in that same directory.

Thanks again @kzvi :)

@kzvi
Copy link
Contributor Author

kzvi commented Jun 23, 2018

Done.

@ohanar
Copy link
Member

ohanar commented Jun 23, 2018

Great thanks @kzvi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants