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::import::base::*;
7
8pub use self::XMLSerializer_Binding::{Wrap, XMLSerializerMethods, GetProtoObject, DefineDOMInterface};
9pub mod XMLSerializer_Binding {
10use crate::codegen::GenericBindings::EventTargetBinding::EventTarget_Binding;
11use crate::import::module::*;
12
13unsafe extern "C" fn serializeToString<D: DomTypes>
14(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: *const JSJitMethodCallArgs) -> bool{
15 let mut result = false;
16 wrap_panic(&mut || result = (|| {
17 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
18 let this = &*(this as *const D::XMLSerializer);
19 let args = &*args;
20 let argc = args.argc_;
21
22 if argc < 1 {
23 throw_type_error(cx.raw_cx(), "Not enough arguments to \"XMLSerializer.serializeToString\".");
24 return false;
25 }
26 let arg0: DomRoot<D::Node> = if HandleValue::from_raw(args.get(0)).get().is_object() {
27 match root_from_handlevalue(HandleValue::from_raw(args.get(0)), SafeJSContext::from_ptr(cx.raw_cx())) {
28 Ok(val) => val,
29 Err(()) => {
30 throw_type_error(cx.raw_cx(), "value does not implement interface Node.");
31 return false;
32
33 }
34 }
35
36 } else {
37 throw_type_error(cx.raw_cx(), "Value is not an object.");
38 return false;
39
40 };
41 let result: Result<DOMString, Error> = this.SerializeToString(&arg0);
42 let result = match result {
43 Ok(result) => result,
44 Err(e) => {
45 <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());
46 return false;
47 },
48 };
49
50 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
51 return true;
52 })());
53 result
54}
55
56
57static serializeToString_methodinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
58
59pub(crate) fn init_serializeToString_methodinfo<D: DomTypes>() {
60 serializeToString_methodinfo.set(JSJitInfo {
61 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
62 method: Some(serializeToString::<D>)
63 },
64 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
65 protoID: PrototypeList::ID::XMLSerializer as u16,
66 },
67 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 0 },
68 _bitfield_align_1: [],
69 _bitfield_1: __BindgenBitfieldUnit::new(
70 new_jsjitinfo_bitfield_1!(
71 JSJitInfo_OpType::Method as u8,
72 JSJitInfo_AliasSet::AliasEverything as u8,
73 JSValueType::JSVAL_TYPE_STRING as u8,
74 false,
75 false,
76 false,
77 false,
78 false,
79 false,
80 0,
81 ).to_ne_bytes()
82 ),
83});
84}
85unsafe extern "C" fn _finalize<D: DomTypes>
86(_cx: *mut GCContext, obj: *mut JSObject){
87 wrap_panic(&mut || {
88
89 let this = native_from_object_static::<D::XMLSerializer>(obj).unwrap();
90 finalize_common(this);
91 })
92}
93
94unsafe extern "C" fn _trace<D: DomTypes>
95(trc: *mut JSTracer, obj: *mut JSObject){
96 wrap_panic(&mut || {
97
98 let this = native_from_object_static::<D::XMLSerializer>(obj).unwrap();
99 if this.is_null() { return; } (*this).trace(trc);
101 })
102}
103
104
105static CLASS_OPS: ThreadUnsafeOnceLock<JSClassOps> = ThreadUnsafeOnceLock::new();
106
107pub(crate) fn init_class_ops<D: DomTypes>() {
108 CLASS_OPS.set(JSClassOps {
109 addProperty: None,
110 delProperty: None,
111 enumerate: None,
112 newEnumerate: None,
113 resolve: None,
114 mayResolve: None,
115 finalize: Some(_finalize::<D>),
116 call: None,
117 construct: None,
118 trace: Some(_trace::<D>),
119 });
120}
121
122pub static Class: ThreadUnsafeOnceLock<DOMJSClass> = ThreadUnsafeOnceLock::new();
123
124pub(crate) fn init_domjs_class<D: DomTypes>() {
125 init_class_ops::<D>();
126 Class.set(DOMJSClass {
127 base: JSClass {
128 name: c"XMLSerializer".as_ptr(),
129 flags: JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE |
130 (((1) & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT)
131 ,
132 cOps: unsafe { CLASS_OPS.get() },
133 spec: ptr::null(),
134 ext: ptr::null(),
135 oOps: ptr::null(),
136 },
137 dom_class:
138DOMClass {
139 interface_chain: [ PrototypeList::ID::XMLSerializer, PrototypeList::ID::Last, PrototypeList::ID::Last, PrototypeList::ID::Last, PrototypeList::ID::Last, PrototypeList::ID::Last ],
140 depth: 0,
141 type_id: crate::codegen::InheritTypes::TopTypeId { alone: () },
142 malloc_size_of: malloc_size_of_including_raw_self::<D::XMLSerializer> as unsafe fn(&mut _, _) -> _,
143 global: Globals::EMPTY,
144},
145 });
146}
147
148#[cfg_attr(crown, allow(crown::unrooted_must_root))] pub unsafe fn Wrap<D: DomTypes>
149(cx: SafeJSContext, scope: &D::GlobalScope, given_proto: Option<HandleObject>, object: Box<D::XMLSerializer>, _can_gc: CanGc) -> DomRoot<D::XMLSerializer>{
150
151 let raw = Root::new(MaybeUnreflectedDom::from_box(object));
152
153 let scope = scope.reflector().get_jsobject();
154 assert!(!scope.get().is_null());
155 assert!(((*get_object_class(scope.get())).flags & JSCLASS_IS_GLOBAL) != 0);
156 let _ac = JSAutoRealm::new(cx.raw_cx(), scope.get());
157
158 rooted!(&in(cx) let mut canonical_proto = ptr::null_mut::<JSObject>());
159 GetProtoObject::<D>(cx, scope, canonical_proto.handle_mut());
160 assert!(!canonical_proto.is_null());
161
162
163 rooted!(&in(cx) let mut proto = ptr::null_mut::<JSObject>());
164 if let Some(given) = given_proto {
165 proto.set(*given);
166 if get_context_realm(cx.raw_cx()) != get_object_realm(*given) {
167 assert!(JS_WrapObject(cx.raw_cx(), proto.handle_mut()));
168 }
169 } else {
170 proto.set(*canonical_proto);
171 }
172 rooted!(&in(cx) let obj = JS_NewObjectWithGivenProto(
173 cx.raw_cx(),
174 &Class.get().base,
175 proto.handle(),
176 ));
177 assert!(!obj.is_null());
178 JS_SetReservedSlot(
179 obj.get(),
180 DOM_OBJECT_SLOT,
181 &PrivateValue(raw.as_ptr() as *const libc::c_void),
182 );
183
184 let root = raw.reflect_with(obj.get());
185
186
187
188 DomRoot::from_ref(&*root)
189}
190
191pub trait XMLSerializerMethods<D: DomTypes> {
192 fn SerializeToString(&self, r#root: &D::Node) -> Fallible<DOMString>;
193 fn Constructor(r#global: &D::Window, r#proto: Option<HandleObject>, r#can_gc: CanGc) -> Fallible<DomRoot<D::XMLSerializer>>;
194}
195static sMethods_specs: ThreadUnsafeOnceLock<&[&[JSFunctionSpec]]> = ThreadUnsafeOnceLock::new();
196
197pub(crate) fn init_sMethods_specs<D: DomTypes>() {
198 sMethods_specs.set(Box::leak(Box::new([&Box::leak(Box::new([
199 JSFunctionSpec {
200 name: JSPropertySpec_Name { string_: c"serializeToString".as_ptr() },
201 call: JSNativeWrapper { op: Some(generic_method::<false>), info: unsafe { serializeToString_methodinfo.get() } as *const _ as *const JSJitInfo },
202 nargs: 1,
203 flags: (JSPROP_ENUMERATE) as u16,
204 selfHostedName: ptr::null()
205 },
206 JSFunctionSpec {
207 name: JSPropertySpec_Name { string_: ptr::null() },
208 call: JSNativeWrapper { op: None, info: ptr::null() },
209 nargs: 0,
210 flags: 0,
211 selfHostedName: ptr::null()
212 }]))[..]
213])));
214}static sMethods: ThreadUnsafeOnceLock<&[Guard<&[JSFunctionSpec]>]> = ThreadUnsafeOnceLock::new();
215
216pub(crate) fn init_sMethods_prefs<D: DomTypes>() {
217 sMethods.set(Box::leak(Box::new([ Guard::new(&[Condition::Exposed(Globals::WINDOW)], (unsafe { sMethods_specs.get() })[0])])));
218}static sAttributes_specs: ThreadUnsafeOnceLock<&[&[JSPropertySpec]]> = ThreadUnsafeOnceLock::new();
219
220pub(crate) fn init_sAttributes_specs<D: DomTypes>() {
221 sAttributes_specs.set(Box::leak(Box::new([&Box::leak(Box::new([
222 JSPropertySpec {
223 name: JSPropertySpec_Name { symbol_: SymbolCode::toStringTag as usize + 1 },
224 attributes_: (JSPROP_READONLY),
225 kind_: (JSPropertySpec_Kind::Value),
226 u: JSPropertySpec_AccessorsOrValue {
227 value: JSPropertySpec_ValueWrapper {
228 type_: JSPropertySpec_ValueWrapper_Type::String,
229 __bindgen_anon_1: JSPropertySpec_ValueWrapper__bindgen_ty_1 {
230 string: c"XMLSerializer".as_ptr(),
231 }
232 }
233 }
234 }
235,
236 JSPropertySpec::ZERO]))[..]
237])));
238}static sAttributes: ThreadUnsafeOnceLock<&[Guard<&[JSPropertySpec]>]> = ThreadUnsafeOnceLock::new();
239
240pub(crate) fn init_sAttributes_prefs<D: DomTypes>() {
241 sAttributes.set(Box::leak(Box::new([ Guard::new(&[Condition::Satisfied], (unsafe { sAttributes_specs.get() })[0])])));
242}
243pub fn GetProtoObject<D: DomTypes>
244(cx: SafeJSContext, global: HandleObject, mut rval: MutableHandleObject){
245 get_per_interface_object_handle(cx, global, ProtoOrIfaceIndex::ID(PrototypeList::ID::XMLSerializer), CreateInterfaceObjects::<D>, rval)
247}
248
249
250static PrototypeClass: JSClass = JSClass {
251 name: c"XMLSerializerPrototype".as_ptr(),
252 flags:
253 (0 ) << JSCLASS_RESERVED_SLOTS_SHIFT,
255 cOps: ptr::null(),
256 spec: ptr::null(),
257 ext: ptr::null(),
258 oOps: ptr::null(),
259};
260
261unsafe extern "C" fn _constructor<D: DomTypes>
262(cx: *mut RawJSContext, argc: u32, vp: *mut JSVal) -> bool{
263 let mut result = false;
264 wrap_panic(&mut || result = {
265 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
266 let args = CallArgs::from_vp(vp, argc);
267 let global = D::GlobalScope::from_object(JS_CALLEE(cx.raw_cx(), vp).to_object());
268
269 call_default_constructor::<D>(
270 SafeJSContext::from_ptr(cx.raw_cx()),
271 &args,
272 &global,
273 PrototypeList::ID::XMLSerializer,
274 "XMLSerializer",
275 CreateInterfaceObjects::<D>,
276 |cx: SafeJSContext, args: &CallArgs, global: &D::GlobalScope, desired_proto: HandleObject| {
277 let result: Result<DomRoot<D::XMLSerializer>, Error> = <D::XMLSerializer>::Constructor(global.downcast::<D::Window>().unwrap(), Some(desired_proto), CanGc::note());
278 let result = match result {
279 Ok(result) => result,
280 Err(e) => {
281 <D as DomHelpers<D>>::throw_dom_exception(SafeJSContext::from_ptr(cx.raw_cx()), global.upcast::<D::GlobalScope>(), e, CanGc::note());
282 return false;
283 },
284 };
285
286 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
287 return true;
288 }
289 )
290
291 });
292 result
293}
294
295
296static INTERFACE_OBJECT_CLASS: ThreadUnsafeOnceLock<NonCallbackInterfaceObjectClass> = ThreadUnsafeOnceLock::new();
297
298pub(crate) fn init_interface_object<D: DomTypes>() {
299 INTERFACE_OBJECT_CLASS.set(NonCallbackInterfaceObjectClass::new(
300 Box::leak(Box::new(InterfaceConstructorBehavior::call(_constructor::<D>))),
301 b"function XMLSerializer() {\n [native code]\n}",
302 PrototypeList::ID::XMLSerializer,
303 0,
304 ));
305}
306
307pub fn DefineDOMInterface<D: DomTypes>
308(cx: SafeJSContext, global: HandleObject){
309 define_dom_interface(cx, global, ProtoOrIfaceIndex::ID(PrototypeList::ID::XMLSerializer),CreateInterfaceObjects::<D>, ConstructorEnabled::<D>)
310}
311
312pub fn ConstructorEnabled<D: DomTypes>
313(aCx: SafeJSContext, aObj: HandleObject) -> bool{
314 is_exposed_in(aObj, Globals::WINDOW)
315}
316
317unsafe fn CreateInterfaceObjects<D: DomTypes>
318(cx: SafeJSContext, global: HandleObject, cache: *mut ProtoOrIfaceArray){
319
320 rooted!(&in(cx) let mut prototype_proto = ptr::null_mut::<JSObject>());
321 prototype_proto.set(GetRealmObjectPrototype(cx.raw_cx()));
322 assert!(!prototype_proto.is_null());
323
324 rooted!(&in(cx) let mut prototype = ptr::null_mut::<JSObject>());
325 create_interface_prototype_object::<D>(cx,
326 global,
327 prototype_proto.handle(),
328 &PrototypeClass,
329 sMethods.get(),
330 sAttributes.get(),
331 &[],
332 &[],
333 prototype.handle_mut());
334 assert!(!prototype.is_null());
335 assert!((*cache)[PrototypeList::ID::XMLSerializer as usize].is_null());
336 (*cache)[PrototypeList::ID::XMLSerializer as usize] = prototype.get();
337 <*mut JSObject>::post_barrier((*cache).as_mut_ptr().offset(PrototypeList::ID::XMLSerializer as isize),
338 ptr::null_mut(),
339 prototype.get());
340
341 rooted!(&in(cx) let mut interface_proto = ptr::null_mut::<JSObject>());
342 interface_proto.set(GetRealmFunctionPrototype(cx.raw_cx()));
343
344 assert!(!interface_proto.is_null());
345
346 rooted!(&in(cx) let mut interface = ptr::null_mut::<JSObject>());
347 create_noncallback_interface_object::<D>(cx,
348 global,
349 interface_proto.handle(),
350 INTERFACE_OBJECT_CLASS.get(),
351 &[],
352 &[],
353 &[],
354 prototype.handle(),
355 c"XMLSerializer",
356 0,
357 &[],
358 interface.handle_mut());
359 assert!(!interface.is_null());
360}
361
362
363 pub(crate) fn init_statics<D: DomTypes>() {
364 init_interface_object::<D>();
365 init_domjs_class::<D>();
366 crate::codegen::GenericBindings::XMLSerializerBinding::XMLSerializer_Binding::init_serializeToString_methodinfo::<D>();
367
368
369
370 init_sMethods_specs::<D>();
371init_sMethods_prefs::<D>();
372init_sAttributes_specs::<D>();
373init_sAttributes_prefs::<D>();
374 }
375 }