Skip to content
This repository has been archived by the owner on Nov 12, 2022. It is now read-only.

Better documentation #436

Open
Neurrone opened this issue Aug 22, 2018 · 8 comments
Open

Better documentation #436

Neurrone opened this issue Aug 22, 2018 · 8 comments

Comments

@Neurrone
Copy link

Hi,

I've just started learning how to use these bindings, and a lot of what I learnt was purely from reading the tests. Having at least the methods in the rust module documented would be really helpful, together with tutorials for getting started.

For example, the runtime struct appears to do JS_Init, the creation of the runtime and also assigning a context to it, which I investigated because the latest version of this crate was missing bindings to the JS_NewRuntime and JS_DestroyRuntime functions. These functions show up on the documentation link but not in the latest version of the crate.

@jdm
Copy link
Member

jdm commented Aug 22, 2018

Yeah, our documentation builds have been failing for some time so they haven't caught up to the most recent mammoth upgrade to this crate.

@Neurrone
Copy link
Author

Neurrone commented Aug 23, 2018 via email

@jdm
Copy link
Member

jdm commented Aug 23, 2018

We upgraded from a version of SpiderMonkey that was two years old. A huge amount changed, unfortunately.

@Neurrone
Copy link
Author

@jdm does Servo or any other Mozilla project use this internally? I'm trying to find out how to easily expose functions and objects to js, so examples of how this is used would be great.

@jdm
Copy link
Member

jdm commented Aug 26, 2018

I think the unit tests in this repository might be enough to get you started, however.

@jdm
Copy link
Member

jdm commented Aug 30, 2018

Also, we fixed our documentation builds so the link in the readme is once more accurate and up to date.

@Neurrone
Copy link
Author

Hi,

I'm trying to create a function that returns the result of compiling a script using jsapi_wrapped::compile1 without having it GCed.

  • How do I create the Rust::MutableHandleScript handle? Do I need to root it to prevent GC, convert it into a mutable handle, then return the rooted script? Something like
let script = jsapi::JSScript { }; // I couldn't find any functions that created this
mozjs::rooted!(in(cx) let rooted_script = script);
jsapi_wrapped::compile1(cx, options.ptr, script_cstr.as_ptr(), script_cstr.len(), rooted_script.handle_mut())
rooted_script
  • I noticed that the mozjs::rooted! macro expands in this case to
let mut __root = ::jsapi::Rooted::new_unrooted();
let mut rooted_script = ::rust::RootedGuard::new(cx, &mut __root, script);

Do I need to keep both __root and rooted_script alive to prevent GC?

I'll need to execute these scripts later.

  • What do compartments do, and do i need to create a compartment for every script executed?
  • Can you specify more compilation options than just the filename and line number? CompileOptionsWrapper doesn't have ways to do that. E.g, use of ES6, and the path to a source map in the local filesystem.

If there's a better forum for these questions such as a mailing list, let me know.

@Neurrone
Copy link
Author

Neurrone commented Sep 23, 2018

Also, how do you store a RootGuard for the global object in a struct to prevent garbage collection?

The global is created with

let global : *mut JSObject = JS_NewGlobalObject(...);
mozjs::rooted!(in(cx) let rooted_global = global);

Attempting to store rooted_global causes a missing lifetime error.

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

No branches or pull requests

2 participants