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::AbstractRangeBinding::AbstractRange_Binding;
6use crate::codegen::GenericBindings::EventBinding::Event_Binding;
7use crate::codegen::GenericBindings::EventTargetBinding::EventTarget_Binding;
8use crate::codegen::GenericBindings::UIEventBinding::UIEvent_Binding;
9use crate::import::base::*;
10
11#[derive(JSTraceable)]
12pub struct InputEventInit<D: DomTypes> {
13 pub parent: crate::codegen::GenericBindings::UIEventBinding::UIEventInit<D>,
14 pub data: Option<DOMString>,
15 pub dataTransfer: Option<DomRoot<D::DataTransfer>>,
16 pub inputType: DOMString,
17 pub isComposing: bool,
18 pub targetRanges: Vec<DomRoot<D::StaticRange>>,
19}
20impl<D: DomTypes> Default for InputEventInit<D> {
21 fn default() -> Self {
22 Self::empty()
23 }
24}
25
26impl<D: DomTypes> InputEventInit<D> {
27 pub fn empty() -> Self {
28 Self {
29 parent: crate::codegen::GenericBindings::UIEventBinding::UIEventInit::empty(),
30 data: None,
31 dataTransfer: None,
32 inputType: DOMString::from(""),
33 isComposing: false,
34 targetRanges: Vec::new(),
35 }
36 }
37 pub fn new(cx: SafeJSContext, val: HandleValue, can_gc: CanGc)
38 -> Result<ConversionResult<InputEventInit<D>>, ()> {
39 unsafe {
40 let object = if val.get().is_null_or_undefined() {
41 ptr::null_mut()
42 } else if val.get().is_object() {
43 val.get().to_object()
44 } else {
45 return Ok(ConversionResult::Failure("Value is not an object.".into()));
46 };
47 rooted!(&in(cx) let object = object);
48 let dictionary = InputEventInit {
49 parent: {
50 match crate::codegen::GenericBindings::UIEventBinding::UIEventInit::new(cx, val, can_gc)? {
51 ConversionResult::Success(v) => v,
52 ConversionResult::Failure(error) => {
53 throw_type_error(cx.raw_cx(), &error);
54 return Err(());
55 }
56 }
57 },
58 data: {
59 rooted!(&in(cx) let mut rval = UndefinedValue());
60 if get_dictionary_property(cx.raw_cx(), object.handle(), "data", rval.handle_mut(), can_gc)? && !rval.is_undefined() {
61 match FromJSValConvertible::from_jsval(cx.raw_cx(), rval.handle(), StringificationBehavior::Default) {
62 Ok(ConversionResult::Success(value)) => value,
63 Ok(ConversionResult::Failure(error)) => {
64 throw_type_error(cx.raw_cx(), &error);
65 return Err(());
66
67 }
68 _ => {
69 return Err(());
70
71 },
72 }
73
74 } else {
75 None
76 }
77 },
78 dataTransfer: {
79 rooted!(&in(cx) let mut rval = UndefinedValue());
80 if get_dictionary_property(cx.raw_cx(), object.handle(), "dataTransfer", rval.handle_mut(), can_gc)? && !rval.is_undefined() {
81 if rval.handle().get().is_object() {
82 Some(match root_from_handlevalue(rval.handle(), SafeJSContext::from_ptr(cx.raw_cx())) {
83 Ok(val) => val,
84 Err(()) => {
85 throw_type_error(cx.raw_cx(), "value does not implement interface DataTransfer.");
86 return Err(());
87
88 }
89 }
90 )
91 } else if rval.handle().get().is_null_or_undefined() {
92 None
93 } else {
94 throw_type_error(cx.raw_cx(), "Value is not an object.");
95 return Err(());
96
97 }
98 } else {
99 None
100 }
101 },
102 inputType: {
103 rooted!(&in(cx) let mut rval = UndefinedValue());
104 if get_dictionary_property(cx.raw_cx(), object.handle(), "inputType", rval.handle_mut(), can_gc)? && !rval.is_undefined() {
105 match FromJSValConvertible::from_jsval(cx.raw_cx(), rval.handle(), StringificationBehavior::Default) {
106 Ok(ConversionResult::Success(value)) => value,
107 Ok(ConversionResult::Failure(error)) => {
108 throw_type_error(cx.raw_cx(), &error);
109 return Err(());
110
111 }
112 _ => {
113 return Err(());
114
115 },
116 }
117
118 } else {
119 DOMString::from("")
120 }
121 },
122 isComposing: {
123 rooted!(&in(cx) let mut rval = UndefinedValue());
124 if get_dictionary_property(cx.raw_cx(), object.handle(), "isComposing", rval.handle_mut(), can_gc)? && !rval.is_undefined() {
125 match FromJSValConvertible::from_jsval(cx.raw_cx(), rval.handle(), ()) {
126 Ok(ConversionResult::Success(value)) => value,
127 Ok(ConversionResult::Failure(error)) => {
128 throw_type_error(cx.raw_cx(), &error);
129 return Err(());
130
131 }
132 _ => {
133 return Err(());
134
135 },
136 }
137
138 } else {
139 false
140 }
141 },
142 targetRanges: {
143 rooted!(&in(cx) let mut rval = UndefinedValue());
144 if get_dictionary_property(cx.raw_cx(), object.handle(), "targetRanges", rval.handle_mut(), can_gc)? && !rval.is_undefined() {
145 match FromJSValConvertible::from_jsval(cx.raw_cx(), rval.handle(), ()) {
146 Ok(ConversionResult::Success(value)) => value,
147 Ok(ConversionResult::Failure(error)) => {
148 throw_type_error(cx.raw_cx(), &error);
149 return Err(());
150
151 }
152 _ => {
153 return Err(());
154
155 },
156 }
157
158 } else {
159 Vec::new()
160 }
161 },
162 };
163 Ok(ConversionResult::Success(dictionary))
164 }
165 }
166}
167
168impl<D: DomTypes> FromJSValConvertible for InputEventInit<D> {
169 type Config = ();
170 unsafe fn from_jsval(cx: *mut RawJSContext, value: HandleValue, _option: ())
171 -> Result<ConversionResult<InputEventInit<D>>, ()> {
172 InputEventInit::new(SafeJSContext::from_ptr(cx), value, CanGc::note())
173 }
174}
175
176impl<D: DomTypes> InputEventInit<D> {
177 #[allow(clippy::wrong_self_convention)]
178 pub unsafe fn to_jsobject(&self, cx: *mut RawJSContext, mut obj: MutableHandleObject) {
179 self.parent.to_jsobject(cx, obj.reborrow());
180 let data = &self.data;
181 rooted!(in(cx) let mut data_js = UndefinedValue());
182 data.to_jsval(cx, data_js.handle_mut());
183 set_dictionary_property(SafeJSContext::from_ptr(cx), obj.handle(), "data", data_js.handle()).unwrap();
184 let dataTransfer = &self.dataTransfer;
185 rooted!(in(cx) let mut dataTransfer_js = UndefinedValue());
186 dataTransfer.to_jsval(cx, dataTransfer_js.handle_mut());
187 set_dictionary_property(SafeJSContext::from_ptr(cx), obj.handle(), "dataTransfer", dataTransfer_js.handle()).unwrap();
188 let inputType = &self.inputType;
189 rooted!(in(cx) let mut inputType_js = UndefinedValue());
190 inputType.to_jsval(cx, inputType_js.handle_mut());
191 set_dictionary_property(SafeJSContext::from_ptr(cx), obj.handle(), "inputType", inputType_js.handle()).unwrap();
192 let isComposing = &self.isComposing;
193 rooted!(in(cx) let mut isComposing_js = UndefinedValue());
194 isComposing.to_jsval(cx, isComposing_js.handle_mut());
195 set_dictionary_property(SafeJSContext::from_ptr(cx), obj.handle(), "isComposing", isComposing_js.handle()).unwrap();
196 let targetRanges = &self.targetRanges;
197 rooted!(in(cx) let mut targetRanges_js = UndefinedValue());
198 targetRanges.to_jsval(cx, targetRanges_js.handle_mut());
199 set_dictionary_property(SafeJSContext::from_ptr(cx), obj.handle(), "targetRanges", targetRanges_js.handle()).unwrap();
200 }
201}
202
203impl<D: DomTypes> ToJSValConvertible for InputEventInit<D> {
204 unsafe fn to_jsval(&self, cx: *mut RawJSContext, mut rval: MutableHandleValue) {
205 rooted!(in(cx) let mut obj = JS_NewObject(cx, ptr::null()));
206 self.to_jsobject(cx, obj.handle_mut());
207 rval.set(ObjectOrNullValue(obj.get()))
208 }
209}
210
211
212pub use self::InputEvent_Binding::{Wrap, InputEventMethods, GetProtoObject, DefineDOMInterface};
213pub mod InputEvent_Binding {
214use crate::codegen::GenericBindings::AbstractRangeBinding::AbstractRange_Binding;
215use crate::codegen::GenericBindings::EventBinding::Event_Binding;
216use crate::codegen::GenericBindings::EventTargetBinding::EventTarget_Binding;
217use crate::codegen::GenericBindings::InputEventBinding::InputEventInit;
218use crate::codegen::GenericBindings::UIEventBinding::UIEvent_Binding;
219use crate::import::module::*;
220
221unsafe extern "C" fn get_data<D: DomTypes>
222(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: JSJitGetterCallArgs) -> bool{
223 let mut result = false;
224 wrap_panic(&mut || result = (|| {
225 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
226 let this = &*(this as *const D::InputEvent);
227 let result: Option<DOMString> = this.GetData();
228
229 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
230 return true;
231 })());
232 result
233}
234
235
236static data_getterinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
237
238pub(crate) fn init_data_getterinfo<D: DomTypes>() {
239 data_getterinfo.set(JSJitInfo {
240 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
241 getter: Some(get_data::<D>)
242 },
243 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
244 protoID: PrototypeList::ID::InputEvent as u16,
245 },
246 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 2 },
247 _bitfield_align_1: [],
248 _bitfield_1: __BindgenBitfieldUnit::new(
249 new_jsjitinfo_bitfield_1!(
250 JSJitInfo_OpType::Getter as u8,
251 JSJitInfo_AliasSet::AliasEverything as u8,
252 JSValueType::JSVAL_TYPE_UNKNOWN as u8,
253 true,
254 false,
255 false,
256 false,
257 false,
258 false,
259 0,
260 ).to_ne_bytes()
261 ),
262});
263}
264unsafe extern "C" fn get_isComposing<D: DomTypes>
265(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: JSJitGetterCallArgs) -> bool{
266 let mut result = false;
267 wrap_panic(&mut || result = (|| {
268 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
269 let this = &*(this as *const D::InputEvent);
270 let result: bool = this.IsComposing();
271
272 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
273 return true;
274 })());
275 result
276}
277
278
279static isComposing_getterinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
280
281pub(crate) fn init_isComposing_getterinfo<D: DomTypes>() {
282 isComposing_getterinfo.set(JSJitInfo {
283 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
284 getter: Some(get_isComposing::<D>)
285 },
286 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
287 protoID: PrototypeList::ID::InputEvent as u16,
288 },
289 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 2 },
290 _bitfield_align_1: [],
291 _bitfield_1: __BindgenBitfieldUnit::new(
292 new_jsjitinfo_bitfield_1!(
293 JSJitInfo_OpType::Getter as u8,
294 JSJitInfo_AliasSet::AliasEverything as u8,
295 JSValueType::JSVAL_TYPE_BOOLEAN as u8,
296 true,
297 false,
298 false,
299 false,
300 false,
301 false,
302 0,
303 ).to_ne_bytes()
304 ),
305});
306}
307unsafe extern "C" fn get_inputType<D: DomTypes>
308(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: JSJitGetterCallArgs) -> bool{
309 let mut result = false;
310 wrap_panic(&mut || result = (|| {
311 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
312 let this = &*(this as *const D::InputEvent);
313 let result: DOMString = this.InputType();
314
315 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
316 return true;
317 })());
318 result
319}
320
321
322static inputType_getterinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
323
324pub(crate) fn init_inputType_getterinfo<D: DomTypes>() {
325 inputType_getterinfo.set(JSJitInfo {
326 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
327 getter: Some(get_inputType::<D>)
328 },
329 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
330 protoID: PrototypeList::ID::InputEvent as u16,
331 },
332 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 2 },
333 _bitfield_align_1: [],
334 _bitfield_1: __BindgenBitfieldUnit::new(
335 new_jsjitinfo_bitfield_1!(
336 JSJitInfo_OpType::Getter as u8,
337 JSJitInfo_AliasSet::AliasEverything as u8,
338 JSValueType::JSVAL_TYPE_STRING as u8,
339 true,
340 false,
341 false,
342 false,
343 false,
344 false,
345 0,
346 ).to_ne_bytes()
347 ),
348});
349}
350unsafe extern "C" fn get_dataTransfer<D: DomTypes>
351(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: JSJitGetterCallArgs) -> bool{
352 let mut result = false;
353 wrap_panic(&mut || result = (|| {
354 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
355 let this = &*(this as *const D::InputEvent);
356 let result: Option<DomRoot<D::DataTransfer>> = this.GetDataTransfer();
357
358 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
359 return true;
360 })());
361 result
362}
363
364
365static dataTransfer_getterinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
366
367pub(crate) fn init_dataTransfer_getterinfo<D: DomTypes>() {
368 dataTransfer_getterinfo.set(JSJitInfo {
369 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
370 getter: Some(get_dataTransfer::<D>)
371 },
372 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
373 protoID: PrototypeList::ID::InputEvent as u16,
374 },
375 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 2 },
376 _bitfield_align_1: [],
377 _bitfield_1: __BindgenBitfieldUnit::new(
378 new_jsjitinfo_bitfield_1!(
379 JSJitInfo_OpType::Getter as u8,
380 JSJitInfo_AliasSet::AliasEverything as u8,
381 JSValueType::JSVAL_TYPE_UNKNOWN as u8,
382 true,
383 false,
384 false,
385 false,
386 false,
387 false,
388 0,
389 ).to_ne_bytes()
390 ),
391});
392}
393unsafe extern "C" fn getTargetRanges<D: DomTypes>
394(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: *const JSJitMethodCallArgs) -> bool{
395 let mut result = false;
396 wrap_panic(&mut || result = (|| {
397 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
398 let this = &*(this as *const D::InputEvent);
399 let args = &*args;
400 let argc = args.argc_;
401 let result: Vec<DomRoot<D::StaticRange>> = this.GetTargetRanges();
402
403 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
404 return true;
405 })());
406 result
407}
408
409
410static getTargetRanges_methodinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
411
412pub(crate) fn init_getTargetRanges_methodinfo<D: DomTypes>() {
413 getTargetRanges_methodinfo.set(JSJitInfo {
414 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
415 method: Some(getTargetRanges::<D>)
416 },
417 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
418 protoID: PrototypeList::ID::InputEvent as u16,
419 },
420 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 2 },
421 _bitfield_align_1: [],
422 _bitfield_1: __BindgenBitfieldUnit::new(
423 new_jsjitinfo_bitfield_1!(
424 JSJitInfo_OpType::Method as u8,
425 JSJitInfo_AliasSet::AliasEverything as u8,
426 JSValueType::JSVAL_TYPE_OBJECT as u8,
427 true,
428 false,
429 false,
430 false,
431 false,
432 false,
433 0,
434 ).to_ne_bytes()
435 ),
436});
437}
438unsafe extern "C" fn get_isTrusted<D: DomTypes>
439(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: JSJitGetterCallArgs) -> bool{
440 let mut result = false;
441 wrap_panic(&mut || result = (|| {
442 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
443 let this = &*(this as *const D::InputEvent);
444 let result: bool = this.IsTrusted();
445
446 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
447 return true;
448 })());
449 result
450}
451
452
453static isTrusted_getterinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
454
455pub(crate) fn init_isTrusted_getterinfo<D: DomTypes>() {
456 isTrusted_getterinfo.set(JSJitInfo {
457 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
458 getter: Some(get_isTrusted::<D>)
459 },
460 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
461 protoID: PrototypeList::ID::InputEvent as u16,
462 },
463 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 2 },
464 _bitfield_align_1: [],
465 _bitfield_1: __BindgenBitfieldUnit::new(
466 new_jsjitinfo_bitfield_1!(
467 JSJitInfo_OpType::Getter as u8,
468 JSJitInfo_AliasSet::AliasEverything as u8,
469 JSValueType::JSVAL_TYPE_BOOLEAN as u8,
470 true,
471 false,
472 false,
473 false,
474 false,
475 false,
476 0,
477 ).to_ne_bytes()
478 ),
479});
480}
481unsafe extern "C" fn _finalize<D: DomTypes>
482(_cx: *mut GCContext, obj: *mut JSObject){
483 wrap_panic(&mut || {
484
485 let this = native_from_object_static::<D::InputEvent>(obj).unwrap();
486 finalize_common(this);
487 })
488}
489
490unsafe extern "C" fn _trace<D: DomTypes>
491(trc: *mut JSTracer, obj: *mut JSObject){
492 wrap_panic(&mut || {
493
494 let this = native_from_object_static::<D::InputEvent>(obj).unwrap();
495 if this.is_null() { return; } (*this).trace(trc);
497 })
498}
499
500
501static CLASS_OPS: ThreadUnsafeOnceLock<JSClassOps> = ThreadUnsafeOnceLock::new();
502
503pub(crate) fn init_class_ops<D: DomTypes>() {
504 CLASS_OPS.set(JSClassOps {
505 addProperty: None,
506 delProperty: None,
507 enumerate: None,
508 newEnumerate: None,
509 resolve: None,
510 mayResolve: None,
511 finalize: Some(_finalize::<D>),
512 call: None,
513 construct: None,
514 trace: Some(_trace::<D>),
515 });
516}
517
518pub static Class: ThreadUnsafeOnceLock<DOMJSClass> = ThreadUnsafeOnceLock::new();
519
520pub(crate) fn init_domjs_class<D: DomTypes>() {
521 init_class_ops::<D>();
522 Class.set(DOMJSClass {
523 base: JSClass {
524 name: c"InputEvent".as_ptr(),
525 flags: JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE |
526 (((1) & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT)
527 ,
528 cOps: unsafe { CLASS_OPS.get() },
529 spec: ptr::null(),
530 ext: ptr::null(),
531 oOps: ptr::null(),
532 },
533 dom_class:
534DOMClass {
535 interface_chain: [ PrototypeList::ID::Event, PrototypeList::ID::UIEvent, PrototypeList::ID::InputEvent, PrototypeList::ID::Last, PrototypeList::ID::Last, PrototypeList::ID::Last ],
536 depth: 2,
537 type_id: crate::codegen::InheritTypes::TopTypeId { event: (crate::codegen::InheritTypes::EventTypeId::UIEvent(crate::codegen::InheritTypes::UIEventTypeId::InputEvent)) },
538 malloc_size_of: malloc_size_of_including_raw_self::<D::InputEvent> as unsafe fn(&mut _, _) -> _,
539 global: Globals::EMPTY,
540},
541 });
542}
543
544#[cfg_attr(crown, allow(crown::unrooted_must_root))] pub unsafe fn Wrap<D: DomTypes>
545(cx: SafeJSContext, scope: &D::GlobalScope, given_proto: Option<HandleObject>, object: Box<D::InputEvent>, _can_gc: CanGc) -> DomRoot<D::InputEvent>{
546
547 let raw = Root::new(MaybeUnreflectedDom::from_box(object));
548
549 let scope = scope.reflector().get_jsobject();
550 assert!(!scope.get().is_null());
551 assert!(((*get_object_class(scope.get())).flags & JSCLASS_IS_GLOBAL) != 0);
552 let _ac = JSAutoRealm::new(cx.raw_cx(), scope.get());
553
554 rooted!(&in(cx) let mut canonical_proto = ptr::null_mut::<JSObject>());
555 GetProtoObject::<D>(cx, scope, canonical_proto.handle_mut());
556 assert!(!canonical_proto.is_null());
557
558
559 rooted!(&in(cx) let mut proto = ptr::null_mut::<JSObject>());
560 if let Some(given) = given_proto {
561 proto.set(*given);
562 if get_context_realm(cx.raw_cx()) != get_object_realm(*given) {
563 assert!(JS_WrapObject(cx.raw_cx(), proto.handle_mut()));
564 }
565 } else {
566 proto.set(*canonical_proto);
567 }
568 rooted!(&in(cx) let obj = JS_NewObjectWithGivenProto(
569 cx.raw_cx(),
570 &Class.get().base,
571 proto.handle(),
572 ));
573 assert!(!obj.is_null());
574 JS_SetReservedSlot(
575 obj.get(),
576 DOM_OBJECT_SLOT,
577 &PrivateValue(raw.as_ptr() as *const libc::c_void),
578 );
579
580 let root = raw.reflect_with(obj.get());
581
582
583 let mut slot = UndefinedValue();
584 JS_GetReservedSlot(canonical_proto.get(), DOM_PROTO_UNFORGEABLE_HOLDER_SLOT, &mut slot);
585 rooted!(&in(cx) let mut unforgeable_holder = ptr::null_mut::<JSObject>());
586 unforgeable_holder.handle_mut().set(slot.to_object());
587 assert!(JS_InitializePropertiesFromCompatibleNativeObject(cx.raw_cx(), obj.handle(), unforgeable_holder.handle()));
588
589
590 DomRoot::from_ref(&*root)
591}
592
593pub trait InputEventMethods<D: DomTypes> {
594 fn GetData(&self, ) -> Option<DOMString>;
595 fn IsComposing(&self, ) -> bool;
596 fn InputType(&self, ) -> DOMString;
597 fn GetDataTransfer(&self, ) -> Option<DomRoot<D::DataTransfer>>;
598 fn GetTargetRanges(&self, ) -> Vec<DomRoot<D::StaticRange>>;
599 fn IsTrusted(&self, ) -> bool;
600 fn Constructor(r#global: &D::Window, r#proto: Option<HandleObject>, r#can_gc: CanGc, r#type_: DOMString, r#eventInitDict: &crate::codegen::GenericBindings::InputEventBinding::InputEventInit<D>) -> Fallible<DomRoot<D::InputEvent>>;
601}
602static sMethods_specs: ThreadUnsafeOnceLock<&[&[JSFunctionSpec]]> = ThreadUnsafeOnceLock::new();
603
604pub(crate) fn init_sMethods_specs<D: DomTypes>() {
605 sMethods_specs.set(Box::leak(Box::new([&Box::leak(Box::new([
606 JSFunctionSpec {
607 name: JSPropertySpec_Name { string_: c"getTargetRanges".as_ptr() },
608 call: JSNativeWrapper { op: Some(generic_method::<false>), info: unsafe { getTargetRanges_methodinfo.get() } as *const _ as *const JSJitInfo },
609 nargs: 0,
610 flags: (JSPROP_ENUMERATE) as u16,
611 selfHostedName: ptr::null()
612 },
613 JSFunctionSpec {
614 name: JSPropertySpec_Name { string_: ptr::null() },
615 call: JSNativeWrapper { op: None, info: ptr::null() },
616 nargs: 0,
617 flags: 0,
618 selfHostedName: ptr::null()
619 }]))[..]
620])));
621}static sMethods: ThreadUnsafeOnceLock<&[Guard<&[JSFunctionSpec]>]> = ThreadUnsafeOnceLock::new();
622
623pub(crate) fn init_sMethods_prefs<D: DomTypes>() {
624 sMethods.set(Box::leak(Box::new([ Guard::new(&[Condition::Exposed(Globals::WINDOW)], (unsafe { sMethods_specs.get() })[0])])));
625}static sAttributes_specs: ThreadUnsafeOnceLock<&[&[JSPropertySpec]]> = ThreadUnsafeOnceLock::new();
626
627pub(crate) fn init_sAttributes_specs<D: DomTypes>() {
628 sAttributes_specs.set(Box::leak(Box::new([&Box::leak(Box::new([
629 JSPropertySpec {
630 name: JSPropertySpec_Name { string_: c"data".as_ptr() },
631 attributes_: (JSPROP_ENUMERATE),
632 kind_: (JSPropertySpec_Kind::NativeAccessor),
633 u: JSPropertySpec_AccessorsOrValue {
634 accessors: JSPropertySpec_AccessorsOrValue_Accessors {
635 getter: JSPropertySpec_Accessor {
636 native: JSNativeWrapper { op: Some(generic_getter::<false>), info: unsafe { data_getterinfo.get() } },
637 },
638 setter: JSPropertySpec_Accessor {
639 native: JSNativeWrapper { op: None, info: ptr::null() },
640 }
641 }
642 }
643 }
644,
645 JSPropertySpec {
646 name: JSPropertySpec_Name { string_: c"isComposing".as_ptr() },
647 attributes_: (JSPROP_ENUMERATE),
648 kind_: (JSPropertySpec_Kind::NativeAccessor),
649 u: JSPropertySpec_AccessorsOrValue {
650 accessors: JSPropertySpec_AccessorsOrValue_Accessors {
651 getter: JSPropertySpec_Accessor {
652 native: JSNativeWrapper { op: Some(generic_getter::<false>), info: unsafe { isComposing_getterinfo.get() } },
653 },
654 setter: JSPropertySpec_Accessor {
655 native: JSNativeWrapper { op: None, info: ptr::null() },
656 }
657 }
658 }
659 }
660,
661 JSPropertySpec {
662 name: JSPropertySpec_Name { string_: c"inputType".as_ptr() },
663 attributes_: (JSPROP_ENUMERATE),
664 kind_: (JSPropertySpec_Kind::NativeAccessor),
665 u: JSPropertySpec_AccessorsOrValue {
666 accessors: JSPropertySpec_AccessorsOrValue_Accessors {
667 getter: JSPropertySpec_Accessor {
668 native: JSNativeWrapper { op: Some(generic_getter::<false>), info: unsafe { inputType_getterinfo.get() } },
669 },
670 setter: JSPropertySpec_Accessor {
671 native: JSNativeWrapper { op: None, info: ptr::null() },
672 }
673 }
674 }
675 }
676,
677 JSPropertySpec {
678 name: JSPropertySpec_Name { string_: c"dataTransfer".as_ptr() },
679 attributes_: (JSPROP_ENUMERATE),
680 kind_: (JSPropertySpec_Kind::NativeAccessor),
681 u: JSPropertySpec_AccessorsOrValue {
682 accessors: JSPropertySpec_AccessorsOrValue_Accessors {
683 getter: JSPropertySpec_Accessor {
684 native: JSNativeWrapper { op: Some(generic_getter::<false>), info: unsafe { dataTransfer_getterinfo.get() } },
685 },
686 setter: JSPropertySpec_Accessor {
687 native: JSNativeWrapper { op: None, info: ptr::null() },
688 }
689 }
690 }
691 }
692,
693 JSPropertySpec::ZERO]))[..]
694,
695&Box::leak(Box::new([
696 JSPropertySpec {
697 name: JSPropertySpec_Name { symbol_: SymbolCode::toStringTag as usize + 1 },
698 attributes_: (JSPROP_READONLY),
699 kind_: (JSPropertySpec_Kind::Value),
700 u: JSPropertySpec_AccessorsOrValue {
701 value: JSPropertySpec_ValueWrapper {
702 type_: JSPropertySpec_ValueWrapper_Type::String,
703 __bindgen_anon_1: JSPropertySpec_ValueWrapper__bindgen_ty_1 {
704 string: c"InputEvent".as_ptr(),
705 }
706 }
707 }
708 }
709,
710 JSPropertySpec::ZERO]))[..]
711])));
712}static sAttributes: ThreadUnsafeOnceLock<&[Guard<&[JSPropertySpec]>]> = ThreadUnsafeOnceLock::new();
713
714pub(crate) fn init_sAttributes_prefs<D: DomTypes>() {
715 sAttributes.set(Box::leak(Box::new([ Guard::new(&[Condition::Exposed(Globals::WINDOW)], (unsafe { sAttributes_specs.get() })[0]),
716 Guard::new(&[Condition::Satisfied], (unsafe { sAttributes_specs.get() })[1])])));
717}static sLegacyUnforgeableAttributes_specs: ThreadUnsafeOnceLock<&[&[JSPropertySpec]]> = ThreadUnsafeOnceLock::new();
718
719pub(crate) fn init_sLegacyUnforgeableAttributes_specs<D: DomTypes>() {
720 sLegacyUnforgeableAttributes_specs.set(Box::leak(Box::new([&Box::leak(Box::new([
721 JSPropertySpec {
722 name: JSPropertySpec_Name { string_: c"isTrusted".as_ptr() },
723 attributes_: (JSPROP_ENUMERATE | JSPROP_PERMANENT),
724 kind_: (JSPropertySpec_Kind::NativeAccessor),
725 u: JSPropertySpec_AccessorsOrValue {
726 accessors: JSPropertySpec_AccessorsOrValue_Accessors {
727 getter: JSPropertySpec_Accessor {
728 native: JSNativeWrapper { op: Some(generic_getter::<false>), info: unsafe { isTrusted_getterinfo.get() } },
729 },
730 setter: JSPropertySpec_Accessor {
731 native: JSNativeWrapper { op: None, info: ptr::null() },
732 }
733 }
734 }
735 }
736,
737 JSPropertySpec::ZERO]))[..]
738])));
739}static sLegacyUnforgeableAttributes: ThreadUnsafeOnceLock<&[Guard<&[JSPropertySpec]>]> = ThreadUnsafeOnceLock::new();
740
741pub(crate) fn init_sLegacyUnforgeableAttributes_prefs<D: DomTypes>() {
742 sLegacyUnforgeableAttributes.set(Box::leak(Box::new([ Guard::new(&[Condition::Exposed(Globals::WINDOW),Condition::Exposed(Globals::SERVICE_WORKER_GLOBAL_SCOPE),Condition::Exposed(Globals::PAINT_WORKLET_GLOBAL_SCOPE),Condition::Exposed(Globals::DEDICATED_WORKER_GLOBAL_SCOPE),Condition::Exposed(Globals::DEBUGGER_GLOBAL_SCOPE),Condition::Exposed(Globals::DISSIMILAR_ORIGIN_WINDOW),Condition::Exposed(Globals::TEST_WORKLET_GLOBAL_SCOPE)], (unsafe { sLegacyUnforgeableAttributes_specs.get() })[0])])));
743}
744pub fn GetProtoObject<D: DomTypes>
745(cx: SafeJSContext, global: HandleObject, mut rval: MutableHandleObject){
746 get_per_interface_object_handle(cx, global, ProtoOrIfaceIndex::ID(PrototypeList::ID::InputEvent), CreateInterfaceObjects::<D>, rval)
748}
749
750
751static PrototypeClass: JSClass = JSClass {
752 name: c"InputEventPrototype".as_ptr(),
753 flags:
754 (1 & JSCLASS_RESERVED_SLOTS_MASK ) << JSCLASS_RESERVED_SLOTS_SHIFT,
756 cOps: ptr::null(),
757 spec: ptr::null(),
758 ext: ptr::null(),
759 oOps: ptr::null(),
760};
761
762unsafe extern "C" fn _constructor<D: DomTypes>
763(cx: *mut RawJSContext, argc: u32, vp: *mut JSVal) -> bool{
764 let mut result = false;
765 wrap_panic(&mut || result = {
766 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
767 let args = CallArgs::from_vp(vp, argc);
768 let global = D::GlobalScope::from_object(JS_CALLEE(cx.raw_cx(), vp).to_object());
769
770 call_default_constructor::<D>(
771 SafeJSContext::from_ptr(cx.raw_cx()),
772 &args,
773 &global,
774 PrototypeList::ID::InputEvent,
775 "InputEvent",
776 CreateInterfaceObjects::<D>,
777 |cx: SafeJSContext, args: &CallArgs, global: &D::GlobalScope, desired_proto: HandleObject| {
778
779 if argc < 1 {
780 throw_type_error(cx.raw_cx(), "Not enough arguments to \"InputEvent.constructor\".");
781 return false;
782 }
783 let arg0: DOMString = match FromJSValConvertible::from_jsval(cx.raw_cx(), HandleValue::from_raw(args.get(0)), StringificationBehavior::Default) {
784 Ok(ConversionResult::Success(value)) => value,
785 Ok(ConversionResult::Failure(error)) => {
786 throw_type_error(cx.raw_cx(), &error);
787 return false;
788
789 }
790 _ => {
791 return false;
792
793 },
794 }
795 ;
796 let arg1: crate::codegen::GenericBindings::InputEventBinding::InputEventInit<D> = if args.get(1).is_undefined() {
797 crate::codegen::GenericBindings::InputEventBinding::InputEventInit::empty()
798 } else {
799 match FromJSValConvertible::from_jsval(cx.raw_cx(), HandleValue::from_raw(args.get(1)), ()) {
800 Ok(ConversionResult::Success(value)) => value,
801 Ok(ConversionResult::Failure(error)) => {
802 throw_type_error(cx.raw_cx(), &error);
803 return false;
804
805 }
806 _ => {
807 return false;
808
809 },
810 }
811
812 };
813 let result: Result<DomRoot<D::InputEvent>, Error> = <D::InputEvent>::Constructor(global.downcast::<D::Window>().unwrap(), Some(desired_proto), CanGc::note(), arg0, &arg1);
814 let result = match result {
815 Ok(result) => result,
816 Err(e) => {
817 <D as DomHelpers<D>>::throw_dom_exception(SafeJSContext::from_ptr(cx.raw_cx()), global.upcast::<D::GlobalScope>(), e, CanGc::note());
818 return false;
819 },
820 };
821
822 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
823 return true;
824 }
825 )
826
827 });
828 result
829}
830
831
832static INTERFACE_OBJECT_CLASS: ThreadUnsafeOnceLock<NonCallbackInterfaceObjectClass> = ThreadUnsafeOnceLock::new();
833
834pub(crate) fn init_interface_object<D: DomTypes>() {
835 INTERFACE_OBJECT_CLASS.set(NonCallbackInterfaceObjectClass::new(
836 Box::leak(Box::new(InterfaceConstructorBehavior::call(_constructor::<D>))),
837 b"function InputEvent() {\n [native code]\n}",
838 PrototypeList::ID::InputEvent,
839 2,
840 ));
841}
842
843pub fn DefineDOMInterface<D: DomTypes>
844(cx: SafeJSContext, global: HandleObject){
845 define_dom_interface(cx, global, ProtoOrIfaceIndex::ID(PrototypeList::ID::InputEvent),CreateInterfaceObjects::<D>, ConstructorEnabled::<D>)
846}
847
848pub fn ConstructorEnabled<D: DomTypes>
849(aCx: SafeJSContext, aObj: HandleObject) -> bool{
850 is_exposed_in(aObj, Globals::WINDOW)
851}
852
853unsafe fn CreateInterfaceObjects<D: DomTypes>
854(cx: SafeJSContext, global: HandleObject, cache: *mut ProtoOrIfaceArray){
855
856 rooted!(&in(cx) let mut prototype_proto = ptr::null_mut::<JSObject>());
857 UIEvent_Binding::GetProtoObject::<D>(cx, global, prototype_proto.handle_mut());
858 assert!(!prototype_proto.is_null());
859
860 rooted!(&in(cx) let mut prototype = ptr::null_mut::<JSObject>());
861 create_interface_prototype_object::<D>(cx,
862 global,
863 prototype_proto.handle(),
864 &PrototypeClass,
865 sMethods.get(),
866 sAttributes.get(),
867 &[],
868 &[],
869 prototype.handle_mut());
870 assert!(!prototype.is_null());
871 assert!((*cache)[PrototypeList::ID::InputEvent as usize].is_null());
872 (*cache)[PrototypeList::ID::InputEvent as usize] = prototype.get();
873 <*mut JSObject>::post_barrier((*cache).as_mut_ptr().offset(PrototypeList::ID::InputEvent as isize),
874 ptr::null_mut(),
875 prototype.get());
876
877 rooted!(&in(cx) let mut interface_proto = ptr::null_mut::<JSObject>());
878
879 UIEvent_Binding::GetConstructorObject::<D>(cx, global, interface_proto.handle_mut());
880
881 assert!(!interface_proto.is_null());
882
883 rooted!(&in(cx) let mut interface = ptr::null_mut::<JSObject>());
884 create_noncallback_interface_object::<D>(cx,
885 global,
886 interface_proto.handle(),
887 INTERFACE_OBJECT_CLASS.get(),
888 &[],
889 &[],
890 &[],
891 prototype.handle(),
892 c"InputEvent",
893 1,
894 &[],
895 interface.handle_mut());
896 assert!(!interface.is_null());
897
898 rooted!(&in(cx) let mut unforgeable_holder = ptr::null_mut::<JSObject>());
899 unforgeable_holder.handle_mut().set(
900 JS_NewObjectWithoutMetadata(cx.raw_cx(), &Class.get().base as *const JSClass, prototype.handle()));
901 assert!(!unforgeable_holder.is_null());
902
903 define_guarded_properties::<D>(cx, unforgeable_holder.handle(), unsafe { sLegacyUnforgeableAttributes.get() }, global);
904 let val = ObjectValue(unforgeable_holder.get());
905 JS_SetReservedSlot(prototype.get(), DOM_PROTO_UNFORGEABLE_HOLDER_SLOT, &val)
906}
907
908
909 pub(crate) fn init_statics<D: DomTypes>() {
910 init_interface_object::<D>();
911 init_domjs_class::<D>();
912 crate::codegen::GenericBindings::InputEventBinding::InputEvent_Binding::init_getTargetRanges_methodinfo::<D>();
913 init_data_getterinfo::<D>();
914init_isComposing_getterinfo::<D>();
915init_inputType_getterinfo::<D>();
916init_dataTransfer_getterinfo::<D>();
917init_isTrusted_getterinfo::<D>();
918
919
920 init_sMethods_specs::<D>();
921init_sMethods_prefs::<D>();
922init_sAttributes_specs::<D>();
923init_sAttributes_prefs::<D>();
924init_sLegacyUnforgeableAttributes_specs::<D>();
925init_sLegacyUnforgeableAttributes_prefs::<D>();
926 }
927 }