Use a single JSContext per JSRuntime.

The long-term plan for SpiderMonkey is to eliminate JSContexts by merging
(most of) it into JSRuntime, so to future-proof our code, we should avoid
creating multiple JSContexts for the same JSRuntime.

However, this implies we'll have to use the same JSContext for objects in
different compartments, so we need to enter compartments. This is done by
using the with_compartment function.
This commit is contained in:
Ms2ger 2014-04-21 12:38:23 +02:00
parent bba4bef106
commit 0016b1839e
5 changed files with 119 additions and 88 deletions

View file

@ -10,6 +10,7 @@ use dom::window::Window;
use js::jsapi::JSObject;
use js::glue::{WrapperNew, CreateWrapperProxyHandler, ProxyTraps};
use js::rust::with_compartment;
use libc::c_void;
use std::ptr;
@ -56,9 +57,9 @@ impl BrowserContext {
let parent = win.deref().reflector().get_jsobject();
let cx = js_info.get_ref().js_context.deref().deref().ptr;
let wrapper = unsafe {
let wrapper = with_compartment(cx, parent, || unsafe {
WrapperNew(cx, parent, *handler.deref())
};
});
assert!(wrapper.is_not_null());
wrapper
}