mirror of
https://github.com/servo/servo.git
synced 2025-08-08 23:15:33 +01:00
Make callbacks' new methods unsafe
They take raw pointers to contexts and objects.
This commit is contained in:
parent
9c13073075
commit
f903da0a7b
3 changed files with 58 additions and 30 deletions
|
@ -121,7 +121,8 @@ impl CustomElementRegistry {
|
|||
|
||||
/// <https://html.spec.whatwg.org/multipage/#dom-customelementregistry-define>
|
||||
/// Steps 10.3, 10.4
|
||||
fn get_callbacks(&self, prototype: HandleObject) -> Fallible<LifecycleCallbacks> {
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn get_callbacks(&self, prototype: HandleObject) -> Fallible<LifecycleCallbacks> {
|
||||
let cx = self.window.get_cx();
|
||||
|
||||
// Step 4
|
||||
|
@ -164,20 +165,21 @@ impl CustomElementRegistry {
|
|||
/// <https://html.spec.whatwg.org/multipage/#dom-customelementregistry-define>
|
||||
/// Step 10.4
|
||||
#[allow(unsafe_code)]
|
||||
fn get_callback(cx: *mut JSContext, prototype: HandleObject, name: &[u8]) -> Fallible<Option<Rc<Function>>> {
|
||||
unsafe fn get_callback(
|
||||
cx: *mut JSContext,
|
||||
prototype: HandleObject,
|
||||
name: &[u8],
|
||||
) -> Fallible<Option<Rc<Function>>> {
|
||||
rooted!(in(cx) let mut callback = UndefinedValue());
|
||||
|
||||
// Step 10.4.1
|
||||
if unsafe { !JS_GetProperty(cx,
|
||||
prototype,
|
||||
name.as_ptr() as *const _,
|
||||
callback.handle_mut()) } {
|
||||
if !JS_GetProperty(cx, prototype, name.as_ptr() as *const _, callback.handle_mut()) {
|
||||
return Err(Error::JSFailed);
|
||||
}
|
||||
|
||||
// Step 10.4.2
|
||||
if !callback.is_undefined() {
|
||||
if !callback.is_object() || unsafe { !IsCallable(callback.to_object()) } {
|
||||
if !callback.is_object() || !IsCallable(callback.to_object()) {
|
||||
return Err(Error::Type("Lifecycle callback is not callable".to_owned()));
|
||||
}
|
||||
Ok(Some(Function::new(cx, callback.to_object())))
|
||||
|
@ -265,7 +267,7 @@ impl CustomElementRegistryMethods for CustomElementRegistry {
|
|||
rooted!(in(cx) let proto_object = prototype.to_object());
|
||||
let callbacks = {
|
||||
let _ac = JSAutoCompartment::new(cx, proto_object.get());
|
||||
match self.get_callbacks(proto_object.handle()) {
|
||||
match unsafe { self.get_callbacks(proto_object.handle()) } {
|
||||
Ok(callbacks) => callbacks,
|
||||
Err(error) => {
|
||||
self.element_definition_is_running.set(false);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue