#![allow(non_camel_case_types,non_upper_case_globals,unused_imports,unused_variables,unused_assignments,unused_mut,clippy::approx_constant,clippy::enum_variant_names,clippy::let_unit_value,clippy::needless_return,clippy::too_many_arguments,clippy::unnecessary_cast,clippy::upper_case_acronyms)]
use crate::dom::bindings::codegen::Bindings::RequestBinding::RequestCredentials;
use crate::dom::bindings::codegen::Bindings::RequestBinding::RequestCredentialsValues;
use crate::dom::bindings::import::base::*;
#[derive(JSTraceable)]
pub struct WorkletOptions {
pub credentials: RequestCredentials,
}
impl WorkletOptions {
pub fn empty() -> Self {
Self {
credentials: RequestCredentials::Omit,
}
}
pub fn new(cx: SafeJSContext, val: HandleValue)
-> Result<ConversionResult<WorkletOptions>, ()> {
unsafe {
let object = if val.get().is_null_or_undefined() {
ptr::null_mut()
} else if val.get().is_object() {
val.get().to_object()
} else {
return Ok(ConversionResult::Failure("Value is not an object.".into()));
};
rooted!(in(*cx) let object = object);
let dictionary = WorkletOptions {
credentials: {
rooted!(in(*cx) let mut rval = UndefinedValue());
if get_dictionary_property(*cx, object.handle(), "credentials", rval.handle_mut())? && !rval.is_undefined() {
match FromJSValConvertible::from_jsval(*cx, rval.handle(), ()) { Err(_) => { return Err(());
},
Ok(ConversionResult::Success(v)) => v,
Ok(ConversionResult::Failure(error)) => { throw_type_error(*cx, &error); return Err(());
},
}
} else {
RequestCredentials::Omit
}
},
};
Ok(ConversionResult::Success(dictionary))
}
}
}
impl FromJSValConvertible for WorkletOptions {
type Config = ();
unsafe fn from_jsval(cx: *mut JSContext, value: HandleValue, _option: ())
-> Result<ConversionResult<WorkletOptions>, ()> {
WorkletOptions::new(SafeJSContext::from_ptr(cx), value)
}
}
impl WorkletOptions {
pub(crate) unsafe fn to_jsobject(&self, cx: *mut JSContext, mut obj: MutableHandleObject) {
let credentials = &self.credentials;
rooted!(in(cx) let mut credentials_js = UndefinedValue());
credentials.to_jsval(cx, credentials_js.handle_mut());
set_dictionary_property(cx, obj.handle(), "credentials", credentials_js.handle()).unwrap();
}
}
impl ToJSValConvertible for WorkletOptions {
unsafe fn to_jsval(&self, cx: *mut JSContext, mut rval: MutableHandleValue) {
rooted!(in(cx) let mut obj = JS_NewObject(cx, ptr::null()));
self.to_jsobject(cx, obj.handle_mut());
rval.set(ObjectOrNullValue(obj.get()))
}
}
pub use self::Worklet_Binding::{Wrap, WorkletMethods, GetProtoObject, DefineDOMInterface};
pub mod Worklet_Binding {
use crate::dom;
use crate::dom::bindings::codegen::Bindings::RequestBinding::RequestCredentials;
use crate::dom::bindings::codegen::Bindings::RequestBinding::RequestCredentialsValues;
use crate::dom::bindings::codegen::Bindings::WorkletBinding::WorkletOptions;
use crate::dom::bindings::import::module::*;
use crate::dom::promise::Promise;
use crate::dom::types::Worklet;
unsafe extern fn addModule(cx: *mut JSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: *const JSJitMethodCallArgs) -> bool{
let mut result = false;
wrap_panic(&mut || result = (|| {
let cx = SafeJSContext::from_ptr(cx);
let this = &*(this as *const Worklet);
let args = &*args;
let argc = args.argc_;
if argc < 1 {
throw_type_error(*cx, "Not enough arguments to \"Worklet.addModule\".");
return false;
}
let arg0: USVString = match FromJSValConvertible::from_jsval(*cx, HandleValue::from_raw(args.get(0)), ()) {
Ok(ConversionResult::Success(strval)) => strval,
Ok(ConversionResult::Failure(error)) => {
throw_type_error(*cx, &error);
return false;
}
_ => { return false;
},
};
let arg1: crate::dom::bindings::codegen::Bindings::WorkletBinding::WorkletOptions = if args.get(1).is_undefined() {
crate::dom::bindings::codegen::Bindings::WorkletBinding::WorkletOptions::empty()
} else {
match FromJSValConvertible::from_jsval(*cx, HandleValue::from_raw(args.get(1)), ()) {
Ok(ConversionResult::Success(dictionary)) => dictionary,
Ok(ConversionResult::Failure(error)) => {
throw_type_error(*cx, &error);
return false;
}
_ => { return false;
},
}
};
let result: Rc<Promise> = this.AddModule(arg0, &arg1, InRealm::already(&AlreadyInRealm::assert_for_cx(cx)));
(result).to_jsval(*cx, MutableHandleValue::from_raw(args.rval()));
return true;
})());
result
}
unsafe extern fn addModule_promise_wrapper(cx: *mut JSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: *const JSJitMethodCallArgs) -> bool{
let mut result = false;
wrap_panic(&mut || result = (|| {
let ok = addModule(cx, _obj, this, args);
if ok {
return true;
}
return exception_to_promise(cx, (*args).rval());
})());
result
}
const addModule_methodinfo: JSJitInfo = JSJitInfo {
__bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
method: Some(addModule_promise_wrapper)
},
__bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
protoID: PrototypeList::ID::Worklet as u16,
},
__bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 0 },
_bitfield_align_1: [],
_bitfield_1: __BindgenBitfieldUnit::new(
new_jsjitinfo_bitfield_1!(
JSJitInfo_OpType::Method as u8,
JSJitInfo_AliasSet::AliasEverything as u8,
JSValueType::JSVAL_TYPE_OBJECT as u8,
false,
false,
false,
false,
false,
false,
0,
).to_ne_bytes()
),
};
unsafe extern fn _finalize(_cx: *mut GCContext, obj: *mut JSObject){
wrap_panic(&mut || {
let this = native_from_object_static::<Worklet>(obj).unwrap();
finalize_common(this);
})
}
unsafe extern fn _trace(trc: *mut JSTracer, obj: *mut JSObject){
wrap_panic(&mut || {
let this = native_from_object_static::<Worklet>(obj).unwrap();
if this.is_null() { return; } (*this).trace(trc);
})
}
static CLASS_OPS: JSClassOps = JSClassOps {
addProperty: None,
delProperty: None,
enumerate: None,
newEnumerate: None,
resolve: None,
mayResolve: None,
finalize: Some(_finalize),
call: None,
construct: None,
trace: Some(_trace),
};
static Class: DOMJSClass = DOMJSClass {
base: JSClass {
name: c"Worklet".as_ptr(),
flags: JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE |
(((1) & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT)
,
cOps: &CLASS_OPS,
spec: ptr::null(),
ext: ptr::null(),
oOps: ptr::null(),
},
dom_class:
DOMClass {
interface_chain: [ PrototypeList::ID::Worklet, PrototypeList::ID::Last, PrototypeList::ID::Last, PrototypeList::ID::Last, PrototypeList::ID::Last, PrototypeList::ID::Last ],
depth: 0,
type_id: crate::dom::bindings::codegen::InheritTypes::TopTypeId { alone: () },
malloc_size_of: malloc_size_of_including_raw_self::<Worklet> as unsafe fn(&mut _, _) -> _,
global: InterfaceObjectMap::Globals::EMPTY,
},
};
impl Worklet {
fn __assert_parent_type(&self) {
use crate::dom::bindings::inheritance::HasParent;
let _: &Reflector = self.as_parent();
}
}
pub unsafe fn Wrap(cx: SafeJSContext, scope: &GlobalScope, given_proto: Option<HandleObject>, object: Box<Worklet>, _can_gc: CanGc) -> DomRoot<Worklet>{
let raw = Root::new(MaybeUnreflectedDom::from_box(object));
let scope = scope.reflector().get_jsobject();
assert!(!scope.get().is_null());
assert!(((*get_object_class(scope.get())).flags & JSCLASS_IS_GLOBAL) != 0);
let _ac = JSAutoRealm::new(*cx, scope.get());
rooted!(in(*cx) let mut canonical_proto = ptr::null_mut::<JSObject>());
GetProtoObject(cx, scope, canonical_proto.handle_mut());
assert!(!canonical_proto.is_null());
rooted!(in(*cx) let mut proto = ptr::null_mut::<JSObject>());
if let Some(given) = given_proto {
*proto = *given;
if get_context_realm(*cx) != get_object_realm(*given) {
assert!(JS_WrapObject(*cx, proto.handle_mut()));
}
} else {
*proto = *canonical_proto;
}
rooted!(in(*cx) let obj = JS_NewObjectWithGivenProto(
*cx,
&Class.base,
proto.handle(),
));
assert!(!obj.is_null());
JS_SetReservedSlot(
obj.get(),
DOM_OBJECT_SLOT,
&PrivateValue(raw.as_ptr() as *const libc::c_void),
);
let root = raw.reflect_with(obj.get());
DomRoot::from_ref(&*root)
}
impl DomObjectWrap for dom::worklet::Worklet {
const WRAP: unsafe fn(
SafeJSContext,
&GlobalScope,
Option<HandleObject>,
Box<Self>,
CanGc,
) -> Root<Dom<Self>> = Wrap;
}
impl IDLInterface for Worklet {
#[inline]
fn derives(class: &'static DOMClass) -> bool {
ptr::eq(class, &Class.dom_class)
}
}
pub trait WorkletMethods {
fn AddModule(&self, moduleURL: USVString, options: &crate::dom::bindings::codegen::Bindings::WorkletBinding::WorkletOptions, _comp: InRealm) -> Rc<Promise>;
}
const sMethods_specs: &[&[JSFunctionSpec]] = &[
&[
JSFunctionSpec {
name: JSPropertySpec_Name { string_: c"addModule".as_ptr() },
call: JSNativeWrapper { op: Some(generic_method::<true>), info: &addModule_methodinfo as *const _ as *const JSJitInfo },
nargs: 1,
flags: (JSPROP_ENUMERATE) as u16,
selfHostedName: 0 as *const libc::c_char
},
JSFunctionSpec {
name: JSPropertySpec_Name { string_: ptr::null() },
call: JSNativeWrapper { op: None, info: ptr::null() },
nargs: 0,
flags: 0,
selfHostedName: ptr::null()
}]
];
const sMethods: &[Guard<&[JSFunctionSpec]>] = &[
Guard::new(Condition::Exposed(InterfaceObjectMap::Globals::WINDOW), sMethods_specs[0])
];
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: c"Worklet".as_ptr(),
}
}
}
}
,
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::Worklet), CreateInterfaceObjects, rval)
}
static PrototypeClass: JSClass = JSClass {
name: c"WorkletPrototype".as_ptr(),
flags:
(0 ) << JSCLASS_RESERVED_SLOTS_SHIFT,
cOps: 0 as *const _,
spec: ptr::null(),
ext: ptr::null(),
oOps: ptr::null(),
};
static INTERFACE_OBJECT_CLASS: NonCallbackInterfaceObjectClass =
NonCallbackInterfaceObjectClass::new(
{
const BEHAVIOR: InterfaceConstructorBehavior = InterfaceConstructorBehavior::throw();
&BEHAVIOR
},
b"function Worklet() {\n [native code]\n}",
PrototypeList::ID::Worklet,
0);
pub fn DefineDOMInterface(cx: SafeJSContext, global: HandleObject){
define_dom_interface(cx, global, ProtoOrIfaceIndex::ID(PrototypeList::ID::Worklet), CreateInterfaceObjects, ConstructorEnabled)
}
fn ConstructorEnabled(aCx: SafeJSContext, aObj: HandleObject) -> bool{
is_exposed_in(aObj, InterfaceObjectMap::Globals::WINDOW) &&
pref!(dom.worklet.enabled)
}
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,
sMethods,
sAttributes,
&[],
&[],
prototype.handle_mut());
assert!(!prototype.is_null());
assert!((*cache)[PrototypeList::ID::Worklet as usize].is_null());
(*cache)[PrototypeList::ID::Worklet as usize] = prototype.get();
<*mut JSObject>::post_barrier((*cache).as_mut_ptr().offset(PrototypeList::ID::Worklet as isize),
ptr::null_mut(),
prototype.get());
rooted!(in(*cx) let mut interface_proto = ptr::null_mut::<JSObject>());
interface_proto.set(GetRealmFunctionPrototype(*cx));
assert!(!interface_proto.is_null());
rooted!(in(*cx) let mut interface = ptr::null_mut::<JSObject>());
create_noncallback_interface_object(cx,
global,
interface_proto.handle(),
&INTERFACE_OBJECT_CLASS,
&[],
&[],
&[],
prototype.handle(),
c"Worklet",
0,
&[],
interface.handle_mut());
assert!(!interface.is_null());
}
}