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