-
Notifications
You must be signed in to change notification settings - Fork 117
Add crate docstring and two code examples #489
Conversation
☔ The latest upstream changes (presumably #493) made this pull request unmergeable. Please resolve the merge conflicts. |
I've fought with this quite a bit, but it's really a struggle. I can't figure out how to make a global object (and a null pointer anywhere results in a crash), and the API is really hard to use. My attempts to figure out how Servo uses this library -- the only working code I know of -- seem futile. Surely I am looking at this API upside down and this is not as difficult as it seems. Any guidance on offer? What am I missing? EDIT: I was actually quite close, according to #481. Let me see if I can finish it... |
It's still a bit kludgy, I think, but should work and demonstrate the basics of the API pretty well. Ready for review. |
Thanks, @jdm. I didn't know CI didn't run doc tests. Given that, I agree that examples make sense. I could not figure out how to make the examples get their own doc pages, so did my best to generate links to the source files in the crate root, since I feel those should be mentioned. If you know of a trick or prefer I remove them, let me know. |
(Note to self: there is a request review button at the bottom, when GitHub doesn't detect that I have fixed all the changes sometimes.) |
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.
Thanks! This is definitely an improvement over the status quo.
Thanks, @jdm! I have fixed one of the comments, but the other one tells me that I am missing something. I have two questions. The line you commented on I presume creating a global like this in Rust is intentionally difficult, because Rust wants in-depth knowledge of lifetimes. Thus, my first question: does this mean that is a bad example for Rust? Or is there a better way to do this I missed? Regarding Why is it is there? Because I read a "global root object" is used as a compartment -- at least, in the C++ version. In Rust, I only know that if I mess up that object creation, lots of ugly UB happens. That is my second question: does that need to be in Thanks for your patience! |
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 don't know that intentionally difficult is really a goal; it's a reflection of writing just enough Rust bindings to wrap some of the most basic or tricky parts of the SpiderMonkey API. In any case I don't see how we can make a better example, because we can't do anything with spidermonkey without creating a global object!
Thanks for the pointers and comments, @jdm! All fixed! I also ran Rustfmt on it to make sure it's nice and clean. ✨ |
Uh... the AppVeyor run seems to have a broken mozjs_sys on win32:
I can't imagine it's related to my simple change... |
Yeah, that's a known intermittent error that occurs. |
@bors-servo r+ |
📌 Commit 58bc43c has been approved by |
💔 Test failed - checks-travis |
☀️ Test successful - checks-travis, status-appveyor |
In the hopes of embedding SpiderMonkey into a non-Servo Rust project, I spent some time digging into these bindings. Unfortunately, it was very easy to get lost.
This PR is my attempt to make it easier for the next person who attempts my exercise by adding a few sign posts I would have found helpful, and translating one of the basic examples from the SpiderMonkey User Guide on MDN to Rust. Documenting the entire crate (and where it dips directly into
mozjs_sys
) is a task too big for any one person, I think.EDIT: removed WIP comment