mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
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:
parent
bba4bef106
commit
0016b1839e
5 changed files with 119 additions and 88 deletions
|
@ -41,6 +41,7 @@ use js::jsfriendapi::bindgen::JS_NewObjectWithUniqueType;
|
|||
use js::jsval::JSVal;
|
||||
use js::jsval::{PrivateValue, ObjectValue, NullValue, ObjectOrNullValue};
|
||||
use js::jsval::{Int32Value, UInt32Value, DoubleValue, BooleanValue, UndefinedValue};
|
||||
use js::rust::with_compartment;
|
||||
use js::{JSPROP_ENUMERATE, JSCLASS_IS_GLOBAL, JSCLASS_IS_DOMJSCLASS};
|
||||
use js::JSPROP_PERMANENT;
|
||||
use js::{JSFUN_CONSTRUCTOR, JSPROP_READONLY};
|
||||
|
@ -583,7 +584,9 @@ pub fn CreateDOMGlobal(cx: *JSContext, class: *JSClass) -> *JSObject {
|
|||
if obj.is_null() {
|
||||
return ptr::null();
|
||||
}
|
||||
JS_InitStandardClasses(cx, obj);
|
||||
with_compartment(cx, obj, || {
|
||||
JS_InitStandardClasses(cx, obj);
|
||||
});
|
||||
initialize_global(obj);
|
||||
obj
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue