1#![allow(non_camel_case_types,non_upper_case_globals,unsafe_op_in_unsafe_fn,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)]
4
5use crate::codegen::GenericBindings::EventTargetBinding::EventTarget_Binding;
6use crate::codegen::GenericBindings::VoidFunctionBinding::VoidFunction;
7use crate::codegen::GenericBindings::WorkletGlobalScopeBinding::WorkletGlobalScope_Binding;
8use crate::import::base::*;
9
10pub use self::PaintWorkletGlobalScope_Binding::{Wrap, PaintWorkletGlobalScopeMethods, GetProtoObject, DefineDOMInterface};
11pub mod PaintWorkletGlobalScope_Binding {
12use crate::codegen::GenericBindings::EventTargetBinding::EventTarget_Binding;
13use crate::codegen::GenericBindings::VoidFunctionBinding::VoidFunction;
14use crate::codegen::GenericBindings::WorkletGlobalScopeBinding::WorkletGlobalScope_Binding;
15use crate::import::module::*;
16
17unsafe extern "C" fn registerPaint<D: DomTypes>
18(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: *const JSJitMethodCallArgs) -> bool{
19 let mut result = false;
20 wrap_panic(&mut || result = (|| {
21 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
22 let this = &*(this as *const D::PaintWorkletGlobalScope);
23 let args = &*args;
24 let argc = args.argc_;
25
26 if argc < 2 {
27 throw_type_error(cx.raw_cx(), "Not enough arguments to \"PaintWorkletGlobalScope.registerPaint\".");
28 return false;
29 }
30 let arg0: DOMString = match FromJSValConvertible::from_jsval(cx.raw_cx(), HandleValue::from_raw(args.get(0)), StringificationBehavior::Default) {
31 Ok(ConversionResult::Success(value)) => value,
32 Ok(ConversionResult::Failure(error)) => {
33 throw_type_error(cx.raw_cx(), &error);
34 return false;
35
36 }
37 _ => {
38 return false;
39
40 },
41 }
42 ;
43 let arg1: Rc<VoidFunction<D>> = if HandleValue::from_raw(args.get(1)).get().is_object() {
44 if IsCallable(HandleValue::from_raw(args.get(1)).get().to_object()) {
45 VoidFunction::<D>::new(SafeJSContext::from_ptr(cx.raw_cx()), HandleValue::from_raw(args.get(1)).get().to_object())
46 } else {
47 throw_type_error(cx.raw_cx(), "Value is not callable.");
48 return false;
49
50 }
51 } else {
52 throw_type_error(cx.raw_cx(), "Value is not an object.");
53 return false;
54
55 };
56 let result: Result<(), Error> = this.RegisterPaint(arg0, arg1);
57 let result = match result {
58 Ok(result) => result,
59 Err(e) => {
60 <D as DomHelpers<D>>::throw_dom_exception(SafeJSContext::from_ptr(cx.raw_cx()), &this.global_(InRealm::already(&AlreadyInRealm::assert_for_cx(SafeJSContext::from_ptr(cx.raw_cx())))), e, CanGc::note());
61 return false;
62 },
63 };
64
65 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
66 return true;
67 })());
68 result
69}
70
71
72static registerPaint_methodinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
73
74pub(crate) fn init_registerPaint_methodinfo<D: DomTypes>() {
75 registerPaint_methodinfo.set(JSJitInfo {
76 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
77 method: Some(registerPaint::<D>)
78 },
79 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
80 protoID: PrototypeList::ID::PaintWorkletGlobalScope as u16,
81 },
82 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 3 },
83 _bitfield_align_1: [],
84 _bitfield_1: __BindgenBitfieldUnit::new(
85 new_jsjitinfo_bitfield_1!(
86 JSJitInfo_OpType::Method as u8,
87 JSJitInfo_AliasSet::AliasEverything as u8,
88 JSValueType::JSVAL_TYPE_UNDEFINED as u8,
89 false,
90 false,
91 false,
92 false,
93 false,
94 false,
95 0,
96 ).to_ne_bytes()
97 ),
98});
99}
100unsafe extern "C" fn sleep<D: DomTypes>
101(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: *const JSJitMethodCallArgs) -> bool{
102 let mut result = false;
103 wrap_panic(&mut || result = (|| {
104 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
105 let this = &*(this as *const D::PaintWorkletGlobalScope);
106 let args = &*args;
107 let argc = args.argc_;
108
109 if argc < 1 {
110 throw_type_error(cx.raw_cx(), "Not enough arguments to \"PaintWorkletGlobalScope.sleep\".");
111 return false;
112 }
113 let arg0: u64 = match FromJSValConvertible::from_jsval(cx.raw_cx(), HandleValue::from_raw(args.get(0)), ConversionBehavior::Default) {
114 Ok(ConversionResult::Success(value)) => value,
115 Ok(ConversionResult::Failure(error)) => {
116 throw_type_error(cx.raw_cx(), &error);
117 return false;
118
119 }
120 _ => {
121 return false;
122
123 },
124 }
125 ;
126 let result: () = this.Sleep(arg0);
127
128 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
129 return true;
130 })());
131 result
132}
133
134
135static sleep_methodinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
136
137pub(crate) fn init_sleep_methodinfo<D: DomTypes>() {
138 sleep_methodinfo.set(JSJitInfo {
139 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
140 method: Some(sleep::<D>)
141 },
142 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
143 protoID: PrototypeList::ID::PaintWorkletGlobalScope as u16,
144 },
145 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 3 },
146 _bitfield_align_1: [],
147 _bitfield_1: __BindgenBitfieldUnit::new(
148 new_jsjitinfo_bitfield_1!(
149 JSJitInfo_OpType::Method as u8,
150 JSJitInfo_AliasSet::AliasEverything as u8,
151 JSValueType::JSVAL_TYPE_UNDEFINED as u8,
152 false,
153 false,
154 false,
155 false,
156 false,
157 false,
158 0,
159 ).to_ne_bytes()
160 ),
161});
162}
163unsafe extern "C" fn _finalize<D: DomTypes>
164(_cx: *mut GCContext, obj: *mut JSObject){
165 wrap_panic(&mut || {
166
167 let this = native_from_object_static::<D::PaintWorkletGlobalScope>(obj).unwrap();
168 finalize_global(obj, this);
169 })
170}
171
172unsafe extern "C" fn _trace<D: DomTypes>
173(trc: *mut JSTracer, obj: *mut JSObject){
174 wrap_panic(&mut || {
175
176 let this = native_from_object_static::<D::PaintWorkletGlobalScope>(obj).unwrap();
177 if this.is_null() { return; } (*this).trace(trc);
179 trace_global(trc, obj);
180 })
181}
182
183
184static CLASS_OPS: ThreadUnsafeOnceLock<JSClassOps> = ThreadUnsafeOnceLock::new();
185
186pub(crate) fn init_class_ops<D: DomTypes>() {
187 CLASS_OPS.set(JSClassOps {
188 addProperty: None,
189 delProperty: None,
190 enumerate: None,
191 newEnumerate: Some(enumerate_global),
192 resolve: Some(resolve_global),
193 mayResolve: Some(may_resolve_global),
194 finalize: Some(_finalize::<D>),
195 call: None,
196 construct: None,
197 trace: Some(js::jsapi::JS_GlobalObjectTraceHook),
198 });
199}
200
201pub static Class: ThreadUnsafeOnceLock<DOMJSClass> = ThreadUnsafeOnceLock::new();
202
203pub(crate) fn init_domjs_class<D: DomTypes>() {
204 init_class_ops::<D>();
205 Class.set(DOMJSClass {
206 base: JSClass {
207 name: c"PaintWorkletGlobalScope".as_ptr(),
208 flags: JSCLASS_IS_DOMJSCLASS | JSCLASS_IS_GLOBAL | JSCLASS_DOM_GLOBAL | JSCLASS_FOREGROUND_FINALIZE |
209 (((JSCLASS_GLOBAL_SLOT_COUNT + 1) & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT)
210 ,
211 cOps: unsafe { CLASS_OPS.get() },
212 spec: ptr::null(),
213 ext: ptr::null(),
214 oOps: ptr::null(),
215 },
216 dom_class:
217DOMClass {
218 interface_chain: [ PrototypeList::ID::EventTarget, PrototypeList::ID::GlobalScope, PrototypeList::ID::WorkletGlobalScope, PrototypeList::ID::PaintWorkletGlobalScope, PrototypeList::ID::Last, PrototypeList::ID::Last ],
219 depth: 3,
220 type_id: crate::codegen::InheritTypes::TopTypeId { eventtarget: (crate::codegen::InheritTypes::EventTargetTypeId::GlobalScope(crate::codegen::InheritTypes::GlobalScopeTypeId::WorkletGlobalScope(crate::codegen::InheritTypes::WorkletGlobalScopeTypeId::PaintWorkletGlobalScope))) },
221 malloc_size_of: malloc_size_of_including_raw_self::<D::PaintWorkletGlobalScope> as unsafe fn(&mut _, _) -> _,
222 global: Globals::PAINT_WORKLET_GLOBAL_SCOPE,
223},
224 });
225}
226
227#[cfg_attr(crown, allow(crown::unrooted_must_root))] pub fn Wrap<D: DomTypes>
228(cx: SafeJSContext, object: Box<D::PaintWorkletGlobalScope>) -> DomRoot<D::PaintWorkletGlobalScope>{
229
230 unsafe {
231 let raw = Root::new(MaybeUnreflectedDom::from_box(object));
232 let origin = (*raw.as_ptr()).upcast::<D::GlobalScope>().origin();
233
234 rooted!(&in(cx) let mut obj = ptr::null_mut::<JSObject>());
235 create_global_object::<D>(
236 cx,
237 &Class.get().base,
238 raw.as_ptr() as *const libc::c_void,
239 _trace::<D>,
240 obj.handle_mut(),
241 origin,
242 false);
243 assert!(!obj.is_null());
244
245 let root = raw.reflect_with(obj.get());
246
247 let _ac = JSAutoRealm::new(cx.raw_cx(), obj.get());
248 rooted!(&in(cx) let mut canonical_proto = ptr::null_mut::<JSObject>());
249 GetProtoObject::<D>(cx, obj.handle(), canonical_proto.handle_mut());
250 assert!(JS_SetPrototype(cx.raw_cx(), obj.handle(), canonical_proto.handle()));
251 let mut immutable = false;
252 assert!(JS_SetImmutablePrototype(cx.raw_cx(), obj.handle(), &mut immutable));
253 assert!(immutable);
254
255 define_guarded_properties::<D>(cx, obj.handle(), sAttributes.get(), obj.handle());
256 define_guarded_methods::<D>(cx, obj.handle(), sMethods.get(), obj.handle());
257
258
259
260 DomRoot::from_ref(&*root)
261 }
262
263}
264
265pub trait PaintWorkletGlobalScopeMethods<D: DomTypes> {
266 fn RegisterPaint(&self, r#name: DOMString, r#paintCtor: Rc<VoidFunction<D>>) -> Fallible<()>;
267 fn Sleep(&self, r#ms: u64);
268}
269static sMethods_specs: ThreadUnsafeOnceLock<&[&[JSFunctionSpec]]> = ThreadUnsafeOnceLock::new();
270
271pub(crate) fn init_sMethods_specs<D: DomTypes>() {
272 sMethods_specs.set(Box::leak(Box::new([&Box::leak(Box::new([
273 JSFunctionSpec {
274 name: JSPropertySpec_Name { string_: c"registerPaint".as_ptr() },
275 call: JSNativeWrapper { op: Some(generic_method::<false>), info: unsafe { registerPaint_methodinfo.get() } as *const _ as *const JSJitInfo },
276 nargs: 2,
277 flags: (JSPROP_ENUMERATE) as u16,
278 selfHostedName: ptr::null()
279 },
280 JSFunctionSpec {
281 name: JSPropertySpec_Name { string_: ptr::null() },
282 call: JSNativeWrapper { op: None, info: ptr::null() },
283 nargs: 0,
284 flags: 0,
285 selfHostedName: ptr::null()
286 }]))[..]
287,
288&Box::leak(Box::new([
289 JSFunctionSpec {
290 name: JSPropertySpec_Name { string_: c"sleep".as_ptr() },
291 call: JSNativeWrapper { op: Some(generic_method::<false>), info: unsafe { sleep_methodinfo.get() } as *const _ as *const JSJitInfo },
292 nargs: 1,
293 flags: (JSPROP_ENUMERATE) as u16,
294 selfHostedName: ptr::null()
295 },
296 JSFunctionSpec {
297 name: JSPropertySpec_Name { string_: ptr::null() },
298 call: JSNativeWrapper { op: None, info: ptr::null() },
299 nargs: 0,
300 flags: 0,
301 selfHostedName: ptr::null()
302 }]))[..]
303])));
304}static sMethods: ThreadUnsafeOnceLock<&[Guard<&[JSFunctionSpec]>]> = ThreadUnsafeOnceLock::new();
305
306pub(crate) fn init_sMethods_prefs<D: DomTypes>() {
307 sMethods.set(Box::leak(Box::new([ Guard::new(&[Condition::Exposed(Globals::PAINT_WORKLET_GLOBAL_SCOPE)], (unsafe { sMethods_specs.get() })[0]),
308 Guard::new(&[Condition::Pref("dom_worklet_blockingsleep_enabled"),Condition::Exposed(Globals::PAINT_WORKLET_GLOBAL_SCOPE)], (unsafe { sMethods_specs.get() })[1])])));
309}static sAttributes_specs: ThreadUnsafeOnceLock<&[&[JSPropertySpec]]> = ThreadUnsafeOnceLock::new();
310
311pub(crate) fn init_sAttributes_specs<D: DomTypes>() {
312 sAttributes_specs.set(Box::leak(Box::new([&Box::leak(Box::new([
313 JSPropertySpec {
314 name: JSPropertySpec_Name { symbol_: SymbolCode::toStringTag as usize + 1 },
315 attributes_: (JSPROP_READONLY),
316 kind_: (JSPropertySpec_Kind::Value),
317 u: JSPropertySpec_AccessorsOrValue {
318 value: JSPropertySpec_ValueWrapper {
319 type_: JSPropertySpec_ValueWrapper_Type::String,
320 __bindgen_anon_1: JSPropertySpec_ValueWrapper__bindgen_ty_1 {
321 string: c"PaintWorkletGlobalScope".as_ptr(),
322 }
323 }
324 }
325 }
326,
327 JSPropertySpec::ZERO]))[..]
328])));
329}static sAttributes: ThreadUnsafeOnceLock<&[Guard<&[JSPropertySpec]>]> = ThreadUnsafeOnceLock::new();
330
331pub(crate) fn init_sAttributes_prefs<D: DomTypes>() {
332 sAttributes.set(Box::leak(Box::new([ Guard::new(&[Condition::Satisfied], (unsafe { sAttributes_specs.get() })[0])])));
333}
334pub fn GetProtoObject<D: DomTypes>
335(cx: SafeJSContext, global: HandleObject, mut rval: MutableHandleObject){
336 get_per_interface_object_handle(cx, global, ProtoOrIfaceIndex::ID(PrototypeList::ID::PaintWorkletGlobalScope), CreateInterfaceObjects::<D>, rval)
338}
339
340
341static PrototypeClass: JSClass = JSClass {
342 name: c"PaintWorkletGlobalScopePrototype".as_ptr(),
343 flags:
344 (0 ) << JSCLASS_RESERVED_SLOTS_SHIFT,
346 cOps: ptr::null(),
347 spec: ptr::null(),
348 ext: ptr::null(),
349 oOps: ptr::null(),
350};
351
352
353static INTERFACE_OBJECT_CLASS: ThreadUnsafeOnceLock<NonCallbackInterfaceObjectClass> = ThreadUnsafeOnceLock::new();
354
355pub(crate) fn init_interface_object<D: DomTypes>() {
356 INTERFACE_OBJECT_CLASS.set(NonCallbackInterfaceObjectClass::new(
357 Box::leak(Box::new(InterfaceConstructorBehavior::throw())),
358 b"function PaintWorkletGlobalScope() {\n [native code]\n}",
359 PrototypeList::ID::PaintWorkletGlobalScope,
360 3,
361 ));
362}
363
364pub fn DefineDOMInterface<D: DomTypes>
365(cx: SafeJSContext, global: HandleObject){
366 define_dom_interface(cx, global, ProtoOrIfaceIndex::ID(PrototypeList::ID::PaintWorkletGlobalScope),CreateInterfaceObjects::<D>, ConstructorEnabled::<D>)
367}
368
369pub fn ConstructorEnabled<D: DomTypes>
370(aCx: SafeJSContext, aObj: HandleObject) -> bool{
371 is_exposed_in(aObj, Globals::PAINT_WORKLET_GLOBAL_SCOPE) &&
372 pref!(dom_worklet_enabled)
373}
374
375unsafe fn CreateInterfaceObjects<D: DomTypes>
376(cx: SafeJSContext, global: HandleObject, cache: *mut ProtoOrIfaceArray){
377
378 rooted!(&in(cx) let mut prototype_proto = ptr::null_mut::<JSObject>());
379 WorkletGlobalScope_Binding::GetProtoObject::<D>(cx, global, prototype_proto.handle_mut());
380 assert!(!prototype_proto.is_null());
381
382 rooted!(&in(cx) let mut prototype = ptr::null_mut::<JSObject>());
383 create_interface_prototype_object::<D>(cx,
384 global,
385 prototype_proto.handle(),
386 &PrototypeClass,
387 &[],
388 &[],
389 &[],
390 &[],
391 prototype.handle_mut());
392 assert!(!prototype.is_null());
393 assert!((*cache)[PrototypeList::ID::PaintWorkletGlobalScope as usize].is_null());
394 (*cache)[PrototypeList::ID::PaintWorkletGlobalScope as usize] = prototype.get();
395 <*mut JSObject>::post_barrier((*cache).as_mut_ptr().offset(PrototypeList::ID::PaintWorkletGlobalScope as isize),
396 ptr::null_mut(),
397 prototype.get());
398
399 rooted!(&in(cx) let mut interface_proto = ptr::null_mut::<JSObject>());
400
401 WorkletGlobalScope_Binding::GetConstructorObject::<D>(cx, global, interface_proto.handle_mut());
402
403 assert!(!interface_proto.is_null());
404
405 rooted!(&in(cx) let mut interface = ptr::null_mut::<JSObject>());
406 create_noncallback_interface_object::<D>(cx,
407 global,
408 interface_proto.handle(),
409 INTERFACE_OBJECT_CLASS.get(),
410 &[],
411 &[],
412 &[],
413 prototype.handle(),
414 c"PaintWorkletGlobalScope",
415 0,
416 &[],
417 interface.handle_mut());
418 assert!(!interface.is_null());
419}
420
421
422 pub(crate) fn init_statics<D: DomTypes>() {
423 init_interface_object::<D>();
424 init_domjs_class::<D>();
425 crate::codegen::GenericBindings::PaintWorkletGlobalScopeBinding::PaintWorkletGlobalScope_Binding::init_registerPaint_methodinfo::<D>();
426crate::codegen::GenericBindings::PaintWorkletGlobalScopeBinding::PaintWorkletGlobalScope_Binding::init_sleep_methodinfo::<D>();
427
428
429
430 init_sMethods_specs::<D>();
431init_sMethods_prefs::<D>();
432init_sAttributes_specs::<D>();
433init_sAttributes_prefs::<D>();
434 }
435 }