#![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 PromiseJobCallback {
pub parent: CallbackFunction,
}
impl PromiseJobCallback {
pub unsafe fn new(aCx: SafeJSContext, aCallback: *mut JSObject) -> Rc<PromiseJobCallback> {
let mut ret = Rc::new(PromiseJobCallback {
parent: CallbackFunction::new()
});
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 PromiseJobCallback {
unsafe fn new(cx: SafeJSContext, callback: *mut JSObject) -> Rc<PromiseJobCallback> {
PromiseJobCallback::new(cx, callback)
}
fn callback_holder(&self) -> &CallbackObject {
self.parent.callback_holder()
}
}
impl ToJSValConvertible for PromiseJobCallback {
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
self.callback().to_jsval(cx, rval);
}
}
#[derive(JSTraceable, PartialEq)]
#[crown::unrooted_must_root_lint::allow_unrooted_interior]
pub struct AnyCallback {
pub parent: CallbackFunction,
}
impl AnyCallback {
pub unsafe fn new(aCx: SafeJSContext, aCallback: *mut JSObject) -> Rc<AnyCallback> {
let mut ret = Rc::new(AnyCallback {
parent: CallbackFunction::new()
});
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, value: HandleValue, aExceptionHandling: ExceptionHandling) -> Fallible<JSVal> {
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(), value) }
}
pub fn Call__(&self, value: HandleValue, aExceptionHandling: ExceptionHandling) -> Fallible<JSVal> {
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(), value) }
}
unsafe fn Call(&self, cx: SafeJSContext, aThisObj: HandleObject, value: HandleValue) -> Fallible<JSVal> {
rooted!(in(*cx) let mut rval = UndefinedValue());
rooted_vec!(let mut argv);
argv.extend((0..1).map(|_| Heap::default()));
let argc = 1;
rooted!(in(*cx) let mut argv_root = UndefinedValue());
(value).to_jsval(*cx, argv_root.handle_mut());
{
let arg = &mut argv[0];
*arg = Heap::default();
arg.set(argv_root.get());
}
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_: argc as ::libc::size_t,
elements_: argv.as_ptr() as *const JSVal
}, rval.handle_mut());
maybe_resume_unwind();
if !ok {
return Err(JSFailed);
}
let rvalDecl: HandleValue = rval.handle();
Ok(rvalDecl.get())
}
}
impl CallbackContainer for AnyCallback {
unsafe fn new(cx: SafeJSContext, callback: *mut JSObject) -> Rc<AnyCallback> {
AnyCallback::new(cx, callback)
}
fn callback_holder(&self) -> &CallbackObject {
self.parent.callback_holder()
}
}
impl ToJSValConvertible for AnyCallback {
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
self.callback().to_jsval(cx, rval);
}
}
pub use self::Promise_Binding::{GetProtoObject};
pub mod Promise_Binding {
use crate::dom;
use crate::dom::bindings::import::module::*;
use crate::dom::types::Promise;
const sAttributes_specs: &[&[JSPropertySpec]] = &[
&[
JSPropertySpec {
name: JSPropertySpec_Name { symbol_: SymbolCode::toStringTag as usize + 1 },
attributes_: (JSPROP_READONLY),
kind_: (JSPropertySpec_Kind::Value),
u: JSPropertySpec_AccessorsOrValue {
value: JSPropertySpec_ValueWrapper {
type_: JSPropertySpec_ValueWrapper_Type::String,
__bindgen_anon_1: JSPropertySpec_ValueWrapper__bindgen_ty_1 {
string: b"Promise\0" as *const u8 as *const libc::c_char,
}
}
}
}
,
JSPropertySpec::ZERO]
];
const sAttributes: &[Guard<&[JSPropertySpec]>] = &[
Guard::new(Condition::Satisfied, sAttributes_specs[0])
];
pub fn GetProtoObject(cx: SafeJSContext, global: HandleObject, mut rval: MutableHandleObject) {
get_per_interface_object_handle(cx, global, ProtoOrIfaceIndex::ID(PrototypeList::ID::Promise), CreateInterfaceObjects, rval)
}
static PrototypeClass: JSClass = JSClass {
name: b"PromisePrototype\0" as *const u8 as *const libc::c_char,
flags:
(0 ) << JSCLASS_RESERVED_SLOTS_SHIFT,
cOps: 0 as *const _,
spec: ptr::null(),
ext: ptr::null(),
oOps: ptr::null(),
};
unsafe fn CreateInterfaceObjects(cx: SafeJSContext, global: HandleObject, cache: *mut ProtoOrIfaceArray) {
rooted!(in(*cx) let mut prototype_proto = ptr::null_mut::<JSObject>());
prototype_proto.set(GetRealmObjectPrototype(*cx));
assert!(!prototype_proto.is_null());
rooted!(in(*cx) let mut prototype = ptr::null_mut::<JSObject>());
create_interface_prototype_object(cx,
global,
prototype_proto.handle(),
&PrototypeClass,
&[],
sAttributes,
&[],
&[],
prototype.handle_mut());
assert!(!prototype.is_null());
assert!((*cache)[PrototypeList::ID::Promise as usize].is_null());
(*cache)[PrototypeList::ID::Promise as usize] = prototype.get();
<*mut JSObject>::post_barrier((*cache).as_mut_ptr().offset(PrototypeList::ID::Promise as isize),
ptr::null_mut(),
prototype.get());
}
}