Skip to content
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

js_namespace = "chrome.tabs" error expected an identifier #1911

Closed
ctaggart opened this issue Dec 14, 2019 · 3 comments
Closed

js_namespace = "chrome.tabs" error expected an identifier #1911

ctaggart opened this issue Dec 14, 2019 · 3 comments
Labels

Comments

@ctaggart
Copy link
Contributor

I'm trying to map functions from the chrome.tabs JavaScript namespace, but when I do:

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(js_namespace = "chrome.tabs")]
    pub fn query(query_info: &JsValue, callback: &dyn Fn(JsValue));
}

I get the error:

error: expected an identifier
  --> src/chrome_tabs.rs:23:35
   |
23 |     #[wasm_bindgen(js_namespace = "chrome.tabs")]
   |                                   ^^^^^^^^^^^^^

May be related code:

pub js_namespace: Option<Ident>,

@ctaggart ctaggart added the bug label Dec 14, 2019
@Pauan
Copy link
Contributor

Pauan commented Dec 14, 2019

Yeah, this is covered by #951

As a workaround, you can do this:

#[wasm_bindgen]
extern "C" {
    pub type Tabs;

    #[wasm_bindgen(method)]
    pub fn query(this: &Tabs, query_info: &JsValue, callback: &dyn Fn(JsValue));
}

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(js_namespace = chrome)]
    pub fn tabs() -> Tabs;
}

Now you can use tabs().query(...)

@ctaggart
Copy link
Contributor Author

That gave Uncaught TypeError: chrome.tabs is not a function

but with static like #951 worked:

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(js_namespace = chrome)]
    static tabs: Tabs;
}

Thanks again!

@Pauan
Copy link
Contributor

Pauan commented Dec 15, 2019

Oops, I forgot to add getter, though static works as well.

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

No branches or pull requests

2 participants