mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Auto merge of #8226 - froydnj:gc-zeal, r=Ms2ger
unblock using JS_GC_ZEAL I think these patches move the `JS_SetReservedSlot` call to the right place for #6057. I'm not sure that the interface to `create_dom_global` is the best; passing a `JSVal` or a `*libc::c_void` seemed about equal, so I'd welcome feedback there. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8226) <!-- Reviewable:end -->
This commit is contained in:
commit
3efa749976
2 changed files with 23 additions and 21 deletions
|
@ -2161,27 +2161,27 @@ let obj = {
|
||||||
assert!(!obj.is_null());
|
assert!(!obj.is_null());
|
||||||
let obj = RootedObject::new(cx, obj);\
|
let obj = RootedObject::new(cx, obj);\
|
||||||
""" % (descriptor.name, parent)
|
""" % (descriptor.name, parent)
|
||||||
|
elif descriptor.isGlobal():
|
||||||
|
create += ("let obj = RootedObject::new(\n"
|
||||||
|
" cx,\n"
|
||||||
|
" create_dom_global(\n"
|
||||||
|
" cx,\n"
|
||||||
|
" &Class.base as *const js::jsapi::Class as *const JSClass,\n"
|
||||||
|
" raw as *const libc::c_void,\n"
|
||||||
|
" Some(%s))\n"
|
||||||
|
");\n"
|
||||||
|
"assert!(!obj.ptr.is_null());" % TRACE_HOOK_NAME)
|
||||||
else:
|
else:
|
||||||
if descriptor.isGlobal():
|
create += ("let obj = {\n"
|
||||||
create += ("let obj = RootedObject::new(\n"
|
" let _ac = JSAutoCompartment::new(cx, proto.ptr);\n"
|
||||||
" cx,\n"
|
" JS_NewObjectWithGivenProto(\n"
|
||||||
" create_dom_global(\n"
|
" cx, &Class.base as *const js::jsapi::Class as *const JSClass, proto.handle())\n"
|
||||||
" cx,\n"
|
"};\n"
|
||||||
" &Class.base as *const js::jsapi::Class as *const JSClass,\n"
|
"let obj = RootedObject::new(cx, obj);\n"
|
||||||
" Some(%s))\n"
|
"assert!(!obj.ptr.is_null());\n"
|
||||||
");\n" % TRACE_HOOK_NAME)
|
"\n"
|
||||||
else:
|
"JS_SetReservedSlot(obj.ptr, DOM_OBJECT_SLOT,\n"
|
||||||
create += ("let obj = {\n"
|
" PrivateValue(raw as *const libc::c_void));")
|
||||||
" let _ac = JSAutoCompartment::new(cx, proto.ptr);\n"
|
|
||||||
" JS_NewObjectWithGivenProto(\n"
|
|
||||||
" cx, &Class.base as *const js::jsapi::Class as *const JSClass, proto.handle())\n"
|
|
||||||
"};\n"
|
|
||||||
"let obj = RootedObject::new(cx, obj);\n")
|
|
||||||
create += """\
|
|
||||||
assert!(!obj.ptr.is_null());
|
|
||||||
|
|
||||||
JS_SetReservedSlot(obj.ptr, DOM_OBJECT_SLOT,
|
|
||||||
PrivateValue(raw as *const libc::c_void));"""
|
|
||||||
return create
|
return create
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ use dom::bindings::codegen::PrototypeList;
|
||||||
use dom::bindings::codegen::PrototypeList::MAX_PROTO_CHAIN_LENGTH;
|
use dom::bindings::codegen::PrototypeList::MAX_PROTO_CHAIN_LENGTH;
|
||||||
use dom::bindings::conversions::native_from_handleobject;
|
use dom::bindings::conversions::native_from_handleobject;
|
||||||
use dom::bindings::conversions::private_from_proto_check;
|
use dom::bindings::conversions::private_from_proto_check;
|
||||||
use dom::bindings::conversions::{is_dom_class, jsstring_to_str};
|
use dom::bindings::conversions::{is_dom_class, jsstring_to_str, DOM_OBJECT_SLOT};
|
||||||
use dom::bindings::error::throw_type_error;
|
use dom::bindings::error::throw_type_error;
|
||||||
use dom::bindings::error::{Error, ErrorResult, Fallible, throw_invalid_this};
|
use dom::bindings::error::{Error, ErrorResult, Fallible, throw_invalid_this};
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
|
@ -625,6 +625,7 @@ pub fn has_property_on_prototype(cx: *mut JSContext, proxy: HandleObject,
|
||||||
|
|
||||||
/// Create a DOM global object with the given class.
|
/// Create a DOM global object with the given class.
|
||||||
pub fn create_dom_global(cx: *mut JSContext, class: *const JSClass,
|
pub fn create_dom_global(cx: *mut JSContext, class: *const JSClass,
|
||||||
|
private: *const libc::c_void,
|
||||||
trace: JSTraceOp)
|
trace: JSTraceOp)
|
||||||
-> *mut JSObject {
|
-> *mut JSObject {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -640,6 +641,7 @@ pub fn create_dom_global(cx: *mut JSContext, class: *const JSClass,
|
||||||
return ptr::null_mut();
|
return ptr::null_mut();
|
||||||
}
|
}
|
||||||
let _ac = JSAutoCompartment::new(cx, obj.ptr);
|
let _ac = JSAutoCompartment::new(cx, obj.ptr);
|
||||||
|
JS_SetReservedSlot(obj.ptr, DOM_OBJECT_SLOT, PrivateValue(private));
|
||||||
JS_InitStandardClasses(cx, obj.handle());
|
JS_InitStandardClasses(cx, obj.handle());
|
||||||
initialize_global(obj.ptr);
|
initialize_global(obj.ptr);
|
||||||
JS_FireOnNewGlobalObject(cx, obj.handle());
|
JS_FireOnNewGlobalObject(cx, obj.handle());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue