1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */

#![allow(non_camel_case_types,non_upper_case_globals,unused_imports,unused_variables,unused_assignments,unused_mut,clippy::approx_constant,clippy::let_unit_value,clippy::needless_return,clippy::too_many_arguments,clippy::unnecessary_cast,clippy::upper_case_acronyms)]

use crate::dom::bindings::import::base::*;

#[derive(JSTraceable, PartialEq)]
#[crown::unrooted_must_root_lint::allow_unrooted_interior]
pub struct VoidFunction {
    pub parent: CallbackFunction,
}

impl VoidFunction {
    pub unsafe fn new(aCx: SafeJSContext, aCallback: *mut JSObject) -> Rc<VoidFunction> {
        let mut ret = Rc::new(VoidFunction {
            parent: CallbackFunction::new()
        });
        // Note: callback cannot be moved after calling init.
        match Rc::get_mut(&mut ret) {
            Some(ref mut callback) => callback.parent.init(aCx, aCallback),
            None => unreachable!(),
        };
        ret
    }

    pub fn Call_<T: DomObject>(&self, thisObj: &T, aExceptionHandling: ExceptionHandling) -> Fallible<()> {
        let s = CallSetup::new(self, aExceptionHandling);
        rooted!(in(*s.get_context()) let mut thisObjJS = ptr::null_mut::<JSObject>());
        wrap_call_this_object(s.get_context(), thisObj, thisObjJS.handle_mut());
        if thisObjJS.is_null() {
            return Err(JSFailed);
        }
        unsafe { self.Call(s.get_context(), thisObjJS.handle()) }
    }

    pub fn Call__(&self, aExceptionHandling: ExceptionHandling) -> Fallible<()> {
        let s = CallSetup::new(self, aExceptionHandling);
        rooted!(in(*s.get_context()) let thisObjJS = ptr::null_mut::<JSObject>());
        unsafe { self.Call(s.get_context(), thisObjJS.handle()) }
    }

    unsafe fn Call(&self, cx: SafeJSContext, aThisObj: HandleObject) -> Fallible<()> {
        rooted!(in(*cx) let mut rval = UndefinedValue());



        rooted!(in(*cx) let callable = ObjectValue(self.callback()));
        rooted!(in(*cx) let rootedThis = aThisObj.get());
        let ok = JS_CallFunctionValue(
            *cx, rootedThis.handle(), callable.handle(),
            &HandleValueArray {
                length_: 0 as ::libc::size_t,
                elements_: ptr::null_mut()
            }, rval.handle_mut());
        maybe_resume_unwind();
        if !ok {
            return Err(JSFailed);
        }

        Ok(())

    }
}
impl CallbackContainer for VoidFunction {
    unsafe fn new(cx: SafeJSContext, callback: *mut JSObject) -> Rc<VoidFunction> {
        VoidFunction::new(cx, callback)
    }

    fn callback_holder(&self) -> &CallbackObject {
        self.parent.callback_holder()
    }
}

impl ToJSValConvertible for VoidFunction {
    unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
        self.callback().to_jsval(cx, rval);
    }
}