Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd a basic example #165
Add a basic example #165
Conversation
|
This example works and doesn't crash, but with SM assertions on, it fails:
|
|
Add in a |
|
Thanks! Getting a different one now, can't figure this one out...
Going to take a break and revisit this tomorrow. |
|
It wants JS_GlobalObjectTraceHook in trace, but you have trace set to None. Note that you'll need to use the mangled version of that. |
|
Don't forget the MPL2 header. |
|
Thanks! Bit horrible that you can't use the JS_GlobalObjectTraceHook wrapper :( Almost there, it's now failing an assert at the end of evaluate_script in rust.rs:
Looks like it's complaining about a guard object used as temporary, but I can't find one... |
|
|
|
https://github.com/servo/rust-mozjs/pull/165/files#diff-490a245ae6cc96c180d8cb9a9a8eaaa6R50 looks wrong to me - the RootedObject will only be a temporary that will live as long as that statement, and the Handle will point to invalid memory. |
|
You're making a handle in the puts functions. In general, you can't make manually make handles unless you know exactly what you're doing. I don't think I can help with the guard object issue without more information to figure out what object the guard object is embedded in. |
|
I believe I've fixed both the rooting / handle issues. Michael - I don't know how to figure out which object the guard object is embedded in. I tried adding a breakpoint on guard object creation but that was far too noisy to be useful. |
|
A stack on that assertion would help. |
|
This might be an issue with the C++ part of the glue being built without debug/debugmozjs enabled. Try clobbering target/ and building from scratch. |
|
That works! (And also explains why this code worked without crashing on my other machine...) Alright, the code compiles and runs with no errors, even with debugmozjs enabled. What's next? |
| let global_root = Rooted::new(context, global); | ||
| let global = global_root.handle(); | ||
| let _ac = JSAutoCompartment::new(context, global.get()); | ||
| JS_DefineFunction(context, global, CString::new("puts").unwrap().as_ptr(), Some(puts), 1, 0); |
This comment has been minimized.
This comment has been minimized.
| let args = CallArgs::from_vp(vp, argc); | ||
|
|
||
| if args.argc_ != 1 { | ||
| JS_ReportError(context, CString::new("puts() requires exactly 1 argument").unwrap().as_ptr()); |
This comment has been minimized.
This comment has been minimized.
|
It needs a |
|
I'd go with c_char. |
|
@bors-servo: r+ |
|
|
|
|
zofrex commentedJul 1, 2015
I am sure this still needs work, but it's a starting point for a basic example - #134. Credit to jdm, Ms2ger, and mbrubeck for helping me get this far!
Things that are missing compared to the SpiderMonkey documentation: