servo / rust-mozjs

DEPRECATED - moved to servo/mozjs instead.
Mozilla Public License 2.0
293 stars 117 forks source link

Crashes on Runtime::new() #163

Closed zofrex closed 9 years ago

zofrex commented 9 years ago

Test case:

extern crate js;

use js::rust::Runtime;

fn main() {
    let _r = Runtime::new();
}

Result: Crashes

This is where it crashes on my machine (OS X)

vers on IRC volunteered to try it too and got this slightly different crash on Fedora 22 (valgrind output)

michaelwu commented 9 years ago

A JS_Init call is necessary first.

zofrex commented 9 years ago

I'm annoyed at myself for wasting my time, and your time... I'm not sure at what point the JS_Init got lost out of my code (from which I prepared this sample) but of course it's necessary first.

Sorry!

Edit: Also, thanks for the super fast reply!

zofrex commented 9 years ago

Note to anyone else passing: Runtime::new() used to include a JS_Init call, now it no longer does. This works:

    unsafe {
        JS_Init();
    }
    let r = Runtime::new();
michaelwu commented 9 years ago

JS_Init is new with the SM upgrade we had recently - the tests in this code don't use them either.

I recommend building with --features js/debugmozjs while developing which will enable assertions in SM. Many jsapi issues can be caught with that. The rest are usually caught by running with JS_GC_ZEAL=4,1.

zofrex commented 9 years ago

Thanks Michael, that's very helpful to know!