mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Modify *::get_cx methods to return a safe JSContext instead of a raw one
This commit is contained in:
parent
2c5d0a6ebc
commit
88cacfb009
43 changed files with 306 additions and 321 deletions
|
@ -255,8 +255,8 @@ impl CallSetup {
|
|||
let ais = callback.incumbent().map(AutoIncumbentScript::new);
|
||||
CallSetup {
|
||||
exception_global: global,
|
||||
cx: cx,
|
||||
old_realm: unsafe { EnterRealm(cx, callback.callback()) },
|
||||
cx: *cx,
|
||||
old_realm: unsafe { EnterRealm(*cx, callback.callback()) },
|
||||
handling: handling,
|
||||
entry_script: Some(aes),
|
||||
incumbent_script: ais,
|
||||
|
|
|
@ -100,7 +100,7 @@ where
|
|||
// Step 2 is checked in the generated caller code
|
||||
|
||||
// Step 3
|
||||
rooted!(in(window.get_cx()) let new_target = call_args.new_target().to_object());
|
||||
rooted!(in(*window.get_cx()) let new_target = call_args.new_target().to_object());
|
||||
let definition = match registry.lookup_definition_by_constructor(new_target.handle()) {
|
||||
Some(definition) => definition,
|
||||
None => {
|
||||
|
@ -110,15 +110,15 @@ where
|
|||
},
|
||||
};
|
||||
|
||||
rooted!(in(window.get_cx()) let callee = UnwrapObjectStatic(call_args.callee()));
|
||||
rooted!(in(*window.get_cx()) let callee = UnwrapObjectStatic(call_args.callee()));
|
||||
if callee.is_null() {
|
||||
return Err(Error::Security);
|
||||
}
|
||||
|
||||
{
|
||||
let _ac = JSAutoRealm::new(window.get_cx(), callee.get());
|
||||
rooted!(in(window.get_cx()) let mut constructor = ptr::null_mut::<JSObject>());
|
||||
rooted!(in(window.get_cx()) let global_object = CurrentGlobalOrNull(window.get_cx()));
|
||||
let _ac = JSAutoRealm::new(*window.get_cx(), callee.get());
|
||||
rooted!(in(*window.get_cx()) let mut constructor = ptr::null_mut::<JSObject>());
|
||||
rooted!(in(*window.get_cx()) let global_object = CurrentGlobalOrNull(*window.get_cx()));
|
||||
|
||||
if definition.is_autonomous() {
|
||||
// Step 4
|
||||
|
@ -126,7 +126,7 @@ where
|
|||
|
||||
// Retrieve the constructor object for HTMLElement
|
||||
HTMLElementBinding::GetConstructorObject(
|
||||
SafeJSContext::from_ptr(window.get_cx()),
|
||||
window.get_cx(),
|
||||
global_object.handle(),
|
||||
constructor.handle_mut(),
|
||||
);
|
||||
|
@ -134,7 +134,7 @@ where
|
|||
// Step 5
|
||||
get_constructor_object_from_local_name(
|
||||
definition.local_name.clone(),
|
||||
window.get_cx(),
|
||||
*window.get_cx(),
|
||||
global_object.handle(),
|
||||
constructor.handle_mut(),
|
||||
);
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
use crate::dom::bindings::conversions::DerivedFrom;
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::script_runtime::JSContext as SafeJSContext;
|
||||
use crate::script_runtime::JSContext;
|
||||
use js::jsapi::{Heap, JSObject};
|
||||
use js::rust::HandleObject;
|
||||
use std::default::Default;
|
||||
|
@ -17,20 +17,14 @@ use std::default::Default;
|
|||
pub fn reflect_dom_object<T, U>(
|
||||
obj: Box<T>,
|
||||
global: &U,
|
||||
wrap_fn: unsafe fn(SafeJSContext, &GlobalScope, Box<T>) -> DomRoot<T>,
|
||||
wrap_fn: unsafe fn(JSContext, &GlobalScope, Box<T>) -> DomRoot<T>,
|
||||
) -> DomRoot<T>
|
||||
where
|
||||
T: DomObject,
|
||||
U: DerivedFrom<GlobalScope>,
|
||||
{
|
||||
let global_scope = global.upcast();
|
||||
unsafe {
|
||||
wrap_fn(
|
||||
SafeJSContext::from_ptr(global_scope.get_cx()),
|
||||
global_scope,
|
||||
obj,
|
||||
)
|
||||
}
|
||||
unsafe { wrap_fn(global_scope.get_cx(), global_scope, obj) }
|
||||
}
|
||||
|
||||
/// A struct to store a reference to the reflector of a DOM object.
|
||||
|
|
|
@ -321,7 +321,7 @@ impl StructuredCloneData {
|
|||
WriteBytesToJSStructuredCloneData(data as *const u8, nbytes, scdata);
|
||||
|
||||
assert!(JS_ReadStructuredClone(
|
||||
cx,
|
||||
*cx,
|
||||
scdata,
|
||||
JS_STRUCTURED_CLONE_VERSION,
|
||||
StructuredCloneScope::DifferentProcess,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue