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::CharacterDataBinding::CharacterData_Binding;
6use crate::codegen::GenericBindings::ElementBinding::Element_Binding;
7use crate::codegen::GenericBindings::EventTargetBinding::EventTarget_Binding;
8use crate::codegen::GenericBindings::HTMLElementBinding::HTMLElement_Binding;
9use crate::codegen::GenericBindings::NodeBinding::Node_Binding;
10use crate::import::base::*;
11
12pub use self::Text_Binding::{Wrap, TextMethods, GetProtoObject, GetConstructorObject, DefineDOMInterface};
13pub mod Text_Binding {
14use crate::codegen::GenericBindings::CharacterDataBinding::CharacterData_Binding;
15use crate::codegen::GenericBindings::ElementBinding::Element_Binding;
16use crate::codegen::GenericBindings::EventTargetBinding::EventTarget_Binding;
17use crate::codegen::GenericBindings::HTMLElementBinding::HTMLElement_Binding;
18use crate::codegen::GenericBindings::NodeBinding::Node_Binding;
19use crate::import::module::*;
20
21unsafe extern "C" fn splitText<D: DomTypes>
22(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: *const JSJitMethodCallArgs) -> bool{
23 let mut result = false;
24 wrap_panic(&mut || result = (|| {
25 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
26 let this = &*(this as *const D::Text);
27 let args = &*args;
28 let argc = args.argc_;
29
30 if argc < 1 {
31 throw_type_error(cx.raw_cx(), "Not enough arguments to \"Text.splitText\".");
32 return false;
33 }
34 let arg0: u32 = match FromJSValConvertible::from_jsval(cx.raw_cx(), HandleValue::from_raw(args.get(0)), ConversionBehavior::Default) {
35 Ok(ConversionResult::Success(value)) => value,
36 Ok(ConversionResult::Failure(error)) => {
37 throw_type_error(cx.raw_cx(), &error);
38 return false;
39
40 }
41 _ => {
42 return false;
43
44 },
45 }
46 ;
47 let result: Result<DomRoot<D::Text>, Error> = this.SplitText(arg0, CanGc::note());
48 let result = match result {
49 Ok(result) => result,
50 Err(e) => {
51 <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());
52 return false;
53 },
54 };
55
56 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
57 return true;
58 })());
59 result
60}
61
62
63static splitText_methodinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
64
65pub(crate) fn init_splitText_methodinfo<D: DomTypes>() {
66 splitText_methodinfo.set(JSJitInfo {
67 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
68 method: Some(splitText::<D>)
69 },
70 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
71 protoID: PrototypeList::ID::Text as u16,
72 },
73 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 3 },
74 _bitfield_align_1: [],
75 _bitfield_1: __BindgenBitfieldUnit::new(
76 new_jsjitinfo_bitfield_1!(
77 JSJitInfo_OpType::Method as u8,
78 JSJitInfo_AliasSet::AliasEverything as u8,
79 JSValueType::JSVAL_TYPE_OBJECT as u8,
80 false,
81 false,
82 false,
83 false,
84 false,
85 false,
86 0,
87 ).to_ne_bytes()
88 ),
89});
90}
91unsafe extern "C" fn get_wholeText<D: DomTypes>
92(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: JSJitGetterCallArgs) -> bool{
93 let mut result = false;
94 wrap_panic(&mut || result = (|| {
95 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
96 let this = &*(this as *const D::Text);
97 let result: DOMString = this.WholeText();
98
99 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
100 return true;
101 })());
102 result
103}
104
105
106static wholeText_getterinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
107
108pub(crate) fn init_wholeText_getterinfo<D: DomTypes>() {
109 wholeText_getterinfo.set(JSJitInfo {
110 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
111 getter: Some(get_wholeText::<D>)
112 },
113 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
114 protoID: PrototypeList::ID::Text as u16,
115 },
116 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 3 },
117 _bitfield_align_1: [],
118 _bitfield_1: __BindgenBitfieldUnit::new(
119 new_jsjitinfo_bitfield_1!(
120 JSJitInfo_OpType::Getter as u8,
121 JSJitInfo_AliasSet::AliasDOMSets as u8,
122 JSValueType::JSVAL_TYPE_STRING as u8,
123 true,
124 true,
125 false,
126 false,
127 false,
128 false,
129 0,
130 ).to_ne_bytes()
131 ),
132});
133}
134unsafe extern "C" fn get_assignedSlot<D: DomTypes>
135(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: JSJitGetterCallArgs) -> bool{
136 let mut result = false;
137 wrap_panic(&mut || result = (|| {
138 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
139 let this = &*(this as *const D::Text);
140 let result: Option<DomRoot<D::HTMLSlotElement>> = this.GetAssignedSlot();
141
142 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
143 return true;
144 })());
145 result
146}
147
148
149static assignedSlot_getterinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
150
151pub(crate) fn init_assignedSlot_getterinfo<D: DomTypes>() {
152 assignedSlot_getterinfo.set(JSJitInfo {
153 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
154 getter: Some(get_assignedSlot::<D>)
155 },
156 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
157 protoID: PrototypeList::ID::Text as u16,
158 },
159 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 3 },
160 _bitfield_align_1: [],
161 _bitfield_1: __BindgenBitfieldUnit::new(
162 new_jsjitinfo_bitfield_1!(
163 JSJitInfo_OpType::Getter as u8,
164 JSJitInfo_AliasSet::AliasEverything as u8,
165 JSValueType::JSVAL_TYPE_UNKNOWN as u8,
166 true,
167 false,
168 false,
169 false,
170 false,
171 false,
172 0,
173 ).to_ne_bytes()
174 ),
175});
176}
177unsafe extern "C" fn _finalize<D: DomTypes>
178(_cx: *mut GCContext, obj: *mut JSObject){
179 wrap_panic(&mut || {
180
181 let this = native_from_object_static::<D::Text>(obj).unwrap();
182 finalize_common(this);
183 })
184}
185
186unsafe extern "C" fn _trace<D: DomTypes>
187(trc: *mut JSTracer, obj: *mut JSObject){
188 wrap_panic(&mut || {
189
190 let this = native_from_object_static::<D::Text>(obj).unwrap();
191 if this.is_null() { return; } (*this).trace(trc);
193 })
194}
195
196
197static CLASS_OPS: ThreadUnsafeOnceLock<JSClassOps> = ThreadUnsafeOnceLock::new();
198
199pub(crate) fn init_class_ops<D: DomTypes>() {
200 CLASS_OPS.set(JSClassOps {
201 addProperty: None,
202 delProperty: None,
203 enumerate: None,
204 newEnumerate: None,
205 resolve: None,
206 mayResolve: None,
207 finalize: Some(_finalize::<D>),
208 call: None,
209 construct: None,
210 trace: Some(_trace::<D>),
211 });
212}
213
214pub static Class: ThreadUnsafeOnceLock<DOMJSClass> = ThreadUnsafeOnceLock::new();
215
216pub(crate) fn init_domjs_class<D: DomTypes>() {
217 init_class_ops::<D>();
218 Class.set(DOMJSClass {
219 base: JSClass {
220 name: c"Text".as_ptr(),
221 flags: JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE |
222 (((1) & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT)
223 ,
224 cOps: unsafe { CLASS_OPS.get() },
225 spec: ptr::null(),
226 ext: ptr::null(),
227 oOps: ptr::null(),
228 },
229 dom_class:
230DOMClass {
231 interface_chain: [ PrototypeList::ID::EventTarget, PrototypeList::ID::Node, PrototypeList::ID::CharacterData, PrototypeList::ID::Text, PrototypeList::ID::Last, PrototypeList::ID::Last ],
232 depth: 3,
233 type_id: crate::codegen::InheritTypes::TopTypeId { eventtarget: (crate::codegen::InheritTypes::EventTargetTypeId::Node(crate::codegen::InheritTypes::NodeTypeId::CharacterData(crate::codegen::InheritTypes::CharacterDataTypeId::Text(crate::codegen::InheritTypes::TextTypeId::Text)))) },
234 malloc_size_of: malloc_size_of_including_raw_self::<D::Text> as unsafe fn(&mut _, _) -> _,
235 global: Globals::EMPTY,
236},
237 });
238}
239
240#[cfg_attr(crown, allow(crown::unrooted_must_root))] pub unsafe fn Wrap<D: DomTypes>
241(cx: SafeJSContext, scope: &D::GlobalScope, given_proto: Option<HandleObject>, object: Box<D::Text>, _can_gc: CanGc) -> DomRoot<D::Text>{
242
243 let raw = Root::new(MaybeUnreflectedDom::from_box(object));
244
245 let scope = scope.reflector().get_jsobject();
246 assert!(!scope.get().is_null());
247 assert!(((*get_object_class(scope.get())).flags & JSCLASS_IS_GLOBAL) != 0);
248 let _ac = JSAutoRealm::new(cx.raw_cx(), scope.get());
249
250 rooted!(&in(cx) let mut canonical_proto = ptr::null_mut::<JSObject>());
251 GetProtoObject::<D>(cx, scope, canonical_proto.handle_mut());
252 assert!(!canonical_proto.is_null());
253
254
255 rooted!(&in(cx) let mut proto = ptr::null_mut::<JSObject>());
256 if let Some(given) = given_proto {
257 proto.set(*given);
258 if get_context_realm(cx.raw_cx()) != get_object_realm(*given) {
259 assert!(JS_WrapObject(cx.raw_cx(), proto.handle_mut()));
260 }
261 } else {
262 proto.set(*canonical_proto);
263 }
264 rooted!(&in(cx) let obj = JS_NewObjectWithGivenProto(
265 cx.raw_cx(),
266 &Class.get().base,
267 proto.handle(),
268 ));
269 assert!(!obj.is_null());
270 JS_SetReservedSlot(
271 obj.get(),
272 DOM_OBJECT_SLOT,
273 &PrivateValue(raw.as_ptr() as *const libc::c_void),
274 );
275
276 let root = raw.reflect_with(obj.get());
277
278
279
280 DomRoot::from_ref(&*root)
281}
282
283pub trait TextMethods<D: DomTypes> {
284 fn SplitText(&self, r#offset: u32, r#_can_gc: CanGc) -> Fallible<DomRoot<D::Text>>;
285 fn WholeText(&self, ) -> DOMString;
286 fn GetAssignedSlot(&self, ) -> Option<DomRoot<D::HTMLSlotElement>>;
287 fn Constructor(r#global: &D::Window, r#proto: Option<HandleObject>, r#can_gc: CanGc, r#data: DOMString) -> Fallible<DomRoot<D::Text>>;
288}
289static sMethods_specs: ThreadUnsafeOnceLock<&[&[JSFunctionSpec]]> = ThreadUnsafeOnceLock::new();
290
291pub(crate) fn init_sMethods_specs<D: DomTypes>() {
292 sMethods_specs.set(Box::leak(Box::new([&Box::leak(Box::new([
293 JSFunctionSpec {
294 name: JSPropertySpec_Name { string_: c"splitText".as_ptr() },
295 call: JSNativeWrapper { op: Some(generic_method::<false>), info: unsafe { splitText_methodinfo.get() } as *const _ as *const JSJitInfo },
296 nargs: 1,
297 flags: (JSPROP_ENUMERATE) as u16,
298 selfHostedName: ptr::null()
299 },
300 JSFunctionSpec {
301 name: JSPropertySpec_Name { string_: ptr::null() },
302 call: JSNativeWrapper { op: None, info: ptr::null() },
303 nargs: 0,
304 flags: 0,
305 selfHostedName: ptr::null()
306 }]))[..]
307])));
308}static sMethods: ThreadUnsafeOnceLock<&[Guard<&[JSFunctionSpec]>]> = ThreadUnsafeOnceLock::new();
309
310pub(crate) fn init_sMethods_prefs<D: DomTypes>() {
311 sMethods.set(Box::leak(Box::new([ Guard::new(&[Condition::Exposed(Globals::WINDOW)], (unsafe { sMethods_specs.get() })[0])])));
312}static sAttributes_specs: ThreadUnsafeOnceLock<&[&[JSPropertySpec]]> = ThreadUnsafeOnceLock::new();
313
314pub(crate) fn init_sAttributes_specs<D: DomTypes>() {
315 sAttributes_specs.set(Box::leak(Box::new([&Box::leak(Box::new([
316 JSPropertySpec {
317 name: JSPropertySpec_Name { string_: c"wholeText".as_ptr() },
318 attributes_: (JSPROP_ENUMERATE),
319 kind_: (JSPropertySpec_Kind::NativeAccessor),
320 u: JSPropertySpec_AccessorsOrValue {
321 accessors: JSPropertySpec_AccessorsOrValue_Accessors {
322 getter: JSPropertySpec_Accessor {
323 native: JSNativeWrapper { op: Some(generic_getter::<false>), info: unsafe { wholeText_getterinfo.get() } },
324 },
325 setter: JSPropertySpec_Accessor {
326 native: JSNativeWrapper { op: None, info: ptr::null() },
327 }
328 }
329 }
330 }
331,
332 JSPropertySpec {
333 name: JSPropertySpec_Name { string_: c"assignedSlot".as_ptr() },
334 attributes_: (JSPROP_ENUMERATE),
335 kind_: (JSPropertySpec_Kind::NativeAccessor),
336 u: JSPropertySpec_AccessorsOrValue {
337 accessors: JSPropertySpec_AccessorsOrValue_Accessors {
338 getter: JSPropertySpec_Accessor {
339 native: JSNativeWrapper { op: Some(generic_getter::<false>), info: unsafe { assignedSlot_getterinfo.get() } },
340 },
341 setter: JSPropertySpec_Accessor {
342 native: JSNativeWrapper { op: None, info: ptr::null() },
343 }
344 }
345 }
346 }
347,
348 JSPropertySpec::ZERO]))[..]
349,
350&Box::leak(Box::new([
351 JSPropertySpec {
352 name: JSPropertySpec_Name { symbol_: SymbolCode::toStringTag as usize + 1 },
353 attributes_: (JSPROP_READONLY),
354 kind_: (JSPropertySpec_Kind::Value),
355 u: JSPropertySpec_AccessorsOrValue {
356 value: JSPropertySpec_ValueWrapper {
357 type_: JSPropertySpec_ValueWrapper_Type::String,
358 __bindgen_anon_1: JSPropertySpec_ValueWrapper__bindgen_ty_1 {
359 string: c"Text".as_ptr(),
360 }
361 }
362 }
363 }
364,
365 JSPropertySpec::ZERO]))[..]
366])));
367}static sAttributes: ThreadUnsafeOnceLock<&[Guard<&[JSPropertySpec]>]> = ThreadUnsafeOnceLock::new();
368
369pub(crate) fn init_sAttributes_prefs<D: DomTypes>() {
370 sAttributes.set(Box::leak(Box::new([ Guard::new(&[Condition::Exposed(Globals::WINDOW)], (unsafe { sAttributes_specs.get() })[0]),
371 Guard::new(&[Condition::Satisfied], (unsafe { sAttributes_specs.get() })[1])])));
372}
373pub fn GetProtoObject<D: DomTypes>
374(cx: SafeJSContext, global: HandleObject, mut rval: MutableHandleObject){
375 get_per_interface_object_handle(cx, global, ProtoOrIfaceIndex::ID(PrototypeList::ID::Text), CreateInterfaceObjects::<D>, rval)
377}
378
379
380static PrototypeClass: JSClass = JSClass {
381 name: c"TextPrototype".as_ptr(),
382 flags:
383 (0 ) << JSCLASS_RESERVED_SLOTS_SHIFT,
385 cOps: ptr::null(),
386 spec: ptr::null(),
387 ext: ptr::null(),
388 oOps: ptr::null(),
389};
390
391unsafe extern "C" fn _constructor<D: DomTypes>
392(cx: *mut RawJSContext, argc: u32, vp: *mut JSVal) -> bool{
393 let mut result = false;
394 wrap_panic(&mut || result = {
395 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
396 let args = CallArgs::from_vp(vp, argc);
397 let global = D::GlobalScope::from_object(JS_CALLEE(cx.raw_cx(), vp).to_object());
398
399 call_default_constructor::<D>(
400 SafeJSContext::from_ptr(cx.raw_cx()),
401 &args,
402 &global,
403 PrototypeList::ID::Text,
404 "Text",
405 CreateInterfaceObjects::<D>,
406 |cx: SafeJSContext, args: &CallArgs, global: &D::GlobalScope, desired_proto: HandleObject| {
407 let arg0: DOMString = if args.get(0).is_undefined() {
408 DOMString::from("")
409 } else {
410 match FromJSValConvertible::from_jsval(cx.raw_cx(), HandleValue::from_raw(args.get(0)), StringificationBehavior::Default) {
411 Ok(ConversionResult::Success(value)) => value,
412 Ok(ConversionResult::Failure(error)) => {
413 throw_type_error(cx.raw_cx(), &error);
414 return false;
415
416 }
417 _ => {
418 return false;
419
420 },
421 }
422
423 };
424 let result: Result<DomRoot<D::Text>, Error> = <D::Text>::Constructor(global.downcast::<D::Window>().unwrap(), Some(desired_proto), CanGc::note(), arg0);
425 let result = match result {
426 Ok(result) => result,
427 Err(e) => {
428 <D as DomHelpers<D>>::throw_dom_exception(SafeJSContext::from_ptr(cx.raw_cx()), global.upcast::<D::GlobalScope>(), e, CanGc::note());
429 return false;
430 },
431 };
432
433 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
434 return true;
435 }
436 )
437
438 });
439 result
440}
441
442
443static INTERFACE_OBJECT_CLASS: ThreadUnsafeOnceLock<NonCallbackInterfaceObjectClass> = ThreadUnsafeOnceLock::new();
444
445pub(crate) fn init_interface_object<D: DomTypes>() {
446 INTERFACE_OBJECT_CLASS.set(NonCallbackInterfaceObjectClass::new(
447 Box::leak(Box::new(InterfaceConstructorBehavior::call(_constructor::<D>))),
448 b"function Text() {\n [native code]\n}",
449 PrototypeList::ID::Text,
450 3,
451 ));
452}
453
454pub fn GetConstructorObject<D: DomTypes>
455(cx: SafeJSContext, global: HandleObject, mut rval: MutableHandleObject){
456 get_per_interface_object_handle(cx, global, ProtoOrIfaceIndex::Constructor(PrototypeList::Constructor::Text), CreateInterfaceObjects::<D>, rval)
458}
459
460pub fn DefineDOMInterface<D: DomTypes>
461(cx: SafeJSContext, global: HandleObject){
462 define_dom_interface(cx, global, ProtoOrIfaceIndex::ID(PrototypeList::ID::Text),CreateInterfaceObjects::<D>, ConstructorEnabled::<D>)
463}
464
465pub fn ConstructorEnabled<D: DomTypes>
466(aCx: SafeJSContext, aObj: HandleObject) -> bool{
467 is_exposed_in(aObj, Globals::WINDOW)
468}
469
470unsafe fn CreateInterfaceObjects<D: DomTypes>
471(cx: SafeJSContext, global: HandleObject, cache: *mut ProtoOrIfaceArray){
472
473 rooted!(&in(cx) let mut prototype_proto = ptr::null_mut::<JSObject>());
474 CharacterData_Binding::GetProtoObject::<D>(cx, global, prototype_proto.handle_mut());
475 assert!(!prototype_proto.is_null());
476
477 rooted!(&in(cx) let mut prototype = ptr::null_mut::<JSObject>());
478 create_interface_prototype_object::<D>(cx,
479 global,
480 prototype_proto.handle(),
481 &PrototypeClass,
482 sMethods.get(),
483 sAttributes.get(),
484 &[],
485 &[],
486 prototype.handle_mut());
487 assert!(!prototype.is_null());
488 assert!((*cache)[PrototypeList::ID::Text as usize].is_null());
489 (*cache)[PrototypeList::ID::Text as usize] = prototype.get();
490 <*mut JSObject>::post_barrier((*cache).as_mut_ptr().offset(PrototypeList::ID::Text as isize),
491 ptr::null_mut(),
492 prototype.get());
493
494 rooted!(&in(cx) let mut interface_proto = ptr::null_mut::<JSObject>());
495
496 CharacterData_Binding::GetConstructorObject::<D>(cx, global, interface_proto.handle_mut());
497
498 assert!(!interface_proto.is_null());
499
500 rooted!(&in(cx) let mut interface = ptr::null_mut::<JSObject>());
501 create_noncallback_interface_object::<D>(cx,
502 global,
503 interface_proto.handle(),
504 INTERFACE_OBJECT_CLASS.get(),
505 &[],
506 &[],
507 &[],
508 prototype.handle(),
509 c"Text",
510 0,
511 &[],
512 interface.handle_mut());
513 assert!(!interface.is_null());
514
515 assert!((*cache)[PrototypeList::Constructor::Text as usize].is_null());
516 (*cache)[PrototypeList::Constructor::Text as usize] = interface.get();
517 <*mut JSObject>::post_barrier((*cache).as_mut_ptr().offset(PrototypeList::Constructor::Text as isize),
518 ptr::null_mut(),
519 interface.get());
520
521}
522
523
524 pub(crate) fn init_statics<D: DomTypes>() {
525 init_interface_object::<D>();
526 init_domjs_class::<D>();
527 crate::codegen::GenericBindings::TextBinding::Text_Binding::init_splitText_methodinfo::<D>();
528 init_wholeText_getterinfo::<D>();
529init_assignedSlot_getterinfo::<D>();
530
531
532 init_sMethods_specs::<D>();
533init_sMethods_prefs::<D>();
534init_sAttributes_specs::<D>();
535init_sAttributes_prefs::<D>();
536 }
537 }