-
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
Support WebIDL namespaces #253
Comments
I'm looking at this and I don't think the |
The webidl grammar does not allow nested namespaces. Inside a namespace only readonly attributes and regular operations are allowed. I had a look at this issue myself recently. Mostly just looking and trying to understand the existing code base. Here's what I got so far: I added support for parsing NonpartialNamespaces and added an AST node to store the namespace name and operations defined in the namespace. After that I added an ToToken impl for the namespace node. Now I'm stuck on how to get the codegen to render the function definitions inside the module. It is already possible to define the module correctly, but I don't understand enough of the TokenStream stuff yet to actually insert the functions into the module. I also had to introduce additional WebidlParse impls for the Operation nodes so I can add references of the functions to their respective namespace. The existing implementations simply add them to the program and the only connection to their class/interface seems to be the class name as a string. |
I had a look too but I didn't get as far as you. Is your code online somewhere? |
Everything I have so far is here: https://github.com/migerh/wasm-bindgen/tree/wip-namespace-and-console It'll build, but the console test will fail of course. The console module is there, but there are no functions in it. |
thankyou :) |
I'm glad you posted that. I'd independently duplicated a lot of your code :P. I'm not sure how to generate tokens for the module, but I'm guessing it will be like a struct/interface, in that there are an unknown collection of interior objects (in this case functions) inside an enclosing object (in this case mod). I'll have a look to see if I can finish your work if you like, or i'll leave it to you if you prefer? Or we can both work on it and see who can figure it out :P |
@derekdreery Maybe we can crack this together :) I can now generate something that at least somewhat resembles the suggestion above. Two issues are open atm:
|
ooh awesome. I've made some progress too, I'm not on my computer atm but
will post my updates when I am.
…On Thu, Jul 19, 2018 at 9:38 PM, Michael Gerhaeuser < ***@***.***> wrote:
@derekdreery <https://github.com/derekdreery> Maybe we can crack this
together :) I can now generate something that at least somewhat resembles
the suggestion above. Two issues are open atm:
- In the bindings.rs the js_namespace is enclosed with quotes.
wasm-bindgen can't parse that. For now I'm patching this manually by
removing the quotes from the generated bindings.rs.
- The test can't find the functions inside the module although they're
there.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#253 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABU-XkF_XmcMft3a5qvXd4bmTmfLXUMTks5uIO47gaJpZM4Ug30b>
.
|
Unimportant observation: I wonder if we should use |
If you want to look at my WIP it's at derekdreery/wasm-bindgen#wip-namespace-and-console. Something I find helpful is to run |
I think we can use an alternative codegen tactic for namespaces, the equivalent to: // namespace apollo {
// bool thirteen(x: unsigned long);
// }
#[wasm_bindgen]
extern {
type apollo;
#[wasm_bindgen(static_method_of = apollo)]
fn thirteen(x: u32) -> bool;
} Details here: #678 (comment) |
Implemented as modules in #678 . |
We still need support for namespace attributes, although that shouldn't be much work at this point. I'm going to leave this open for now. |
@ohanar perhaps we could open a separate issue for that with some updated instructions? |
Filed #746 for attributes within namespaces. Closing this issue! |
I think we want to emit a wrapper module around the emitted bindings for these, eg the equivalent of:
We will need to add support for this at the
backend::ast
level.The text was updated successfully, but these errors were encountered: