script_bindings/home/runner/work/servo/servo/target/debug/build/script_bindings-d55f55d5af1efaee/out/Bindings/
AudioBufferBinding.rs

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