script_bindings/home/runner/work/servo/servo/target/debug/build/script_bindings-d55f55d5af1efaee/out/Bindings/
GainNodeBinding.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::AudioNodeBinding::AudioNode_Binding;
6use crate::codegen::GenericBindings::AudioNodeBinding::ChannelCountMode;
7use crate::codegen::GenericBindings::AudioNodeBinding::ChannelCountModeValues;
8use crate::codegen::GenericBindings::AudioNodeBinding::ChannelInterpretation;
9use crate::codegen::GenericBindings::AudioNodeBinding::ChannelInterpretationValues;
10use crate::codegen::GenericBindings::EventTargetBinding::EventTarget_Binding;
11use crate::import::base::*;
12
13#[derive(JSTraceable, Clone, Copy)]
14pub struct GainOptions {
15    pub parent: crate::codegen::GenericBindings::AudioNodeBinding::AudioNodeOptions,
16    pub gain: Finite<f32>,
17}
18impl Default for GainOptions {
19    fn default() -> Self {
20        Self::empty()
21    }
22}
23
24impl GainOptions {
25    pub fn empty() -> Self {
26        Self {
27                parent: crate::codegen::GenericBindings::AudioNodeBinding::AudioNodeOptions::empty(),
28                gain: Finite::wrap(1.0),
29        }
30    }
31    pub fn new(cx: SafeJSContext, val: HandleValue, can_gc: CanGc)
32                      -> Result<ConversionResult<GainOptions>, ()> {
33        unsafe {
34            let object = if val.get().is_null_or_undefined() {
35                ptr::null_mut()
36            } else if val.get().is_object() {
37                val.get().to_object()
38            } else {
39                return Ok(ConversionResult::Failure("Value is not an object.".into()));
40            };
41            rooted!(&in(cx) let object = object);
42        let dictionary = GainOptions {
43                parent: {
44                    match crate::codegen::GenericBindings::AudioNodeBinding::AudioNodeOptions::new(cx, val, can_gc)? {
45                        ConversionResult::Success(v) => v,
46                        ConversionResult::Failure(error) => {
47                            throw_type_error(cx.raw_cx(), &error);
48                            return Err(());
49                        }
50                    }
51                },
52                gain: {
53                    rooted!(&in(cx) let mut rval = UndefinedValue());
54                    if get_dictionary_property(cx.raw_cx(), object.handle(), "gain", rval.handle_mut(), can_gc)? && !rval.is_undefined() {
55                            match FromJSValConvertible::from_jsval(cx.raw_cx(), rval.handle(), ()) {
56                                Ok(ConversionResult::Success(value)) => value,
57                                Ok(ConversionResult::Failure(error)) => {
58                                    throw_type_error(cx.raw_cx(), &error);
59                            return Err(());
60
61                                }
62                                _ => {
63                                    return Err(());
64
65                                },
66                            }
67
68                    } else {
69                            Finite::wrap(1.0)
70                    }
71                },
72        };
73            Ok(ConversionResult::Success(dictionary))
74        }
75    }
76}
77
78impl FromJSValConvertible for GainOptions {
79    type Config = ();
80    unsafe fn from_jsval(cx: *mut RawJSContext, value: HandleValue, _option: ())
81                         -> Result<ConversionResult<GainOptions>, ()> {
82        GainOptions::new(SafeJSContext::from_ptr(cx), value, CanGc::note())
83    }
84}
85
86impl GainOptions {
87    #[allow(clippy::wrong_self_convention)]
88    pub unsafe fn to_jsobject(&self, cx: *mut RawJSContext, mut obj: MutableHandleObject) {
89        self.parent.to_jsobject(cx, obj.reborrow());
90        let gain = &self.gain;
91        rooted!(in(cx) let mut gain_js = UndefinedValue());
92        gain.to_jsval(cx, gain_js.handle_mut());
93        set_dictionary_property(SafeJSContext::from_ptr(cx), obj.handle(), "gain", gain_js.handle()).unwrap();
94    }
95}
96
97impl ToJSValConvertible for GainOptions {
98    unsafe fn to_jsval(&self, cx: *mut RawJSContext, mut rval: MutableHandleValue) {
99        rooted!(in(cx) let mut obj = JS_NewObject(cx, ptr::null()));
100        self.to_jsobject(cx, obj.handle_mut());
101        rval.set(ObjectOrNullValue(obj.get()))
102    }
103}
104
105
106pub use self::GainNode_Binding::{Wrap, GainNodeMethods, GetProtoObject, DefineDOMInterface};
107pub mod GainNode_Binding {
108use crate::codegen::GenericBindings::AudioNodeBinding::AudioNode_Binding;
109use crate::codegen::GenericBindings::AudioNodeBinding::ChannelCountMode;
110use crate::codegen::GenericBindings::AudioNodeBinding::ChannelCountModeValues;
111use crate::codegen::GenericBindings::AudioNodeBinding::ChannelInterpretation;
112use crate::codegen::GenericBindings::AudioNodeBinding::ChannelInterpretationValues;
113use crate::codegen::GenericBindings::EventTargetBinding::EventTarget_Binding;
114use crate::codegen::GenericBindings::GainNodeBinding::GainOptions;
115use crate::import::module::*;
116
117unsafe extern "C" fn get_gain<D: DomTypes>
118(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: JSJitGetterCallArgs) -> bool{
119    let mut result = false;
120    wrap_panic(&mut || result = (|| {
121        let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
122        let this = &*(this as *const D::GainNode);
123        let result: DomRoot<D::AudioParam> = this.Gain();
124
125        (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
126        return true;
127    })());
128    result
129}
130
131
132static gain_getterinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
133
134pub(crate) fn init_gain_getterinfo<D: DomTypes>() {
135    gain_getterinfo.set(JSJitInfo {
136    __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
137        getter: Some(get_gain::<D>)
138    },
139    __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
140        protoID: PrototypeList::ID::GainNode as u16,
141    },
142    __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 2 },
143    _bitfield_align_1: [],
144    _bitfield_1: __BindgenBitfieldUnit::new(
145        new_jsjitinfo_bitfield_1!(
146            JSJitInfo_OpType::Getter as u8,
147            JSJitInfo_AliasSet::AliasEverything as u8,
148            JSValueType::JSVAL_TYPE_OBJECT as u8,
149            true,
150            false,
151            false,
152            false,
153            false,
154            false,
155            0,
156        ).to_ne_bytes()
157    ),
158});
159}
160unsafe extern "C" fn _finalize<D: DomTypes>
161(_cx: *mut GCContext, obj: *mut JSObject){
162    wrap_panic(&mut || {
163
164        let this = native_from_object_static::<D::GainNode>(obj).unwrap();
165        finalize_common(this);
166    })
167}
168
169unsafe extern "C" fn _trace<D: DomTypes>
170(trc: *mut JSTracer, obj: *mut JSObject){
171    wrap_panic(&mut || {
172
173        let this = native_from_object_static::<D::GainNode>(obj).unwrap();
174        if this.is_null() { return; } // GC during obj creation
175        (*this).trace(trc);
176    })
177}
178
179
180static CLASS_OPS: ThreadUnsafeOnceLock<JSClassOps> = ThreadUnsafeOnceLock::new();
181
182pub(crate) fn init_class_ops<D: DomTypes>() {
183    CLASS_OPS.set(JSClassOps {
184        addProperty: None,
185        delProperty: None,
186        enumerate: None,
187        newEnumerate: None,
188        resolve: None,
189        mayResolve: None,
190        finalize: Some(_finalize::<D>),
191        call: None,
192        construct: None,
193        trace: Some(_trace::<D>),
194    });
195}
196
197pub static Class: ThreadUnsafeOnceLock<DOMJSClass> = ThreadUnsafeOnceLock::new();
198
199pub(crate) fn init_domjs_class<D: DomTypes>() {
200    init_class_ops::<D>();
201    Class.set(DOMJSClass {
202        base: JSClass {
203            name: c"GainNode".as_ptr(),
204            flags: JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE |
205                   (((1) & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT)
206                   /* JSCLASS_HAS_RESERVED_SLOTS(1) */,
207            cOps: unsafe { CLASS_OPS.get() },
208            spec: ptr::null(),
209            ext: ptr::null(),
210            oOps: ptr::null(),
211        },
212        dom_class:
213DOMClass {
214    interface_chain: [ PrototypeList::ID::EventTarget, PrototypeList::ID::AudioNode, PrototypeList::ID::GainNode, PrototypeList::ID::Last, PrototypeList::ID::Last, PrototypeList::ID::Last ],
215    depth: 2,
216    type_id: crate::codegen::InheritTypes::TopTypeId { eventtarget: (crate::codegen::InheritTypes::EventTargetTypeId::AudioNode(crate::codegen::InheritTypes::AudioNodeTypeId::GainNode)) },
217    malloc_size_of: malloc_size_of_including_raw_self::<D::GainNode> as unsafe fn(&mut _, _) -> _,
218    global: Globals::EMPTY,
219},
220    });
221}
222
223#[cfg_attr(crown, allow(crown::unrooted_must_root))] pub unsafe fn Wrap<D: DomTypes>
224(cx: SafeJSContext, scope: &D::GlobalScope, given_proto: Option<HandleObject>, object: Box<D::GainNode>, _can_gc: CanGc) -> DomRoot<D::GainNode>{
225
226    let raw = Root::new(MaybeUnreflectedDom::from_box(object));
227
228    let scope = scope.reflector().get_jsobject();
229    assert!(!scope.get().is_null());
230    assert!(((*get_object_class(scope.get())).flags & JSCLASS_IS_GLOBAL) != 0);
231    let _ac = JSAutoRealm::new(cx.raw_cx(), scope.get());
232
233    rooted!(&in(cx) let mut canonical_proto = ptr::null_mut::<JSObject>());
234    GetProtoObject::<D>(cx, scope, canonical_proto.handle_mut());
235    assert!(!canonical_proto.is_null());
236
237
238    rooted!(&in(cx) let mut proto = ptr::null_mut::<JSObject>());
239    if let Some(given) = given_proto {
240        proto.set(*given);
241        if get_context_realm(cx.raw_cx()) != get_object_realm(*given) {
242            assert!(JS_WrapObject(cx.raw_cx(), proto.handle_mut()));
243        }
244    } else {
245        proto.set(*canonical_proto);
246    }
247    rooted!(&in(cx) let obj = JS_NewObjectWithGivenProto(
248        cx.raw_cx(),
249        &Class.get().base,
250        proto.handle(),
251    ));
252    assert!(!obj.is_null());
253    JS_SetReservedSlot(
254        obj.get(),
255        DOM_OBJECT_SLOT,
256        &PrivateValue(raw.as_ptr() as *const libc::c_void),
257    );
258
259    let root = raw.reflect_with(obj.get());
260
261
262
263    DomRoot::from_ref(&*root)
264}
265
266pub trait GainNodeMethods<D: DomTypes> {
267    fn Gain(&self, ) -> DomRoot<D::AudioParam>;
268    fn Constructor(r#global: &D::Window, r#proto: Option<HandleObject>, r#can_gc: CanGc, r#context: &D::BaseAudioContext, r#options: &crate::codegen::GenericBindings::GainNodeBinding::GainOptions) -> Fallible<DomRoot<D::GainNode>>;
269}
270static sAttributes_specs: ThreadUnsafeOnceLock<&[&[JSPropertySpec]]> = ThreadUnsafeOnceLock::new();
271
272pub(crate) fn init_sAttributes_specs<D: DomTypes>() {
273    sAttributes_specs.set(Box::leak(Box::new([&Box::leak(Box::new([
274    JSPropertySpec {
275                    name: JSPropertySpec_Name { string_: c"gain".as_ptr() },
276                    attributes_: (JSPROP_ENUMERATE),
277                    kind_: (JSPropertySpec_Kind::NativeAccessor),
278                    u: JSPropertySpec_AccessorsOrValue {
279                        accessors: JSPropertySpec_AccessorsOrValue_Accessors {
280                            getter: JSPropertySpec_Accessor {
281                                native: JSNativeWrapper { op: Some(generic_getter::<false>), info: unsafe { gain_getterinfo.get() } },
282                            },
283                            setter: JSPropertySpec_Accessor {
284                                native: JSNativeWrapper { op: None, info: ptr::null() },
285                            }
286                        }
287                    }
288                }
289,
290    JSPropertySpec::ZERO]))[..]
291,
292&Box::leak(Box::new([
293    JSPropertySpec {
294                    name: JSPropertySpec_Name { symbol_: SymbolCode::toStringTag as usize + 1 },
295                    attributes_: (JSPROP_READONLY),
296                    kind_: (JSPropertySpec_Kind::Value),
297                    u: JSPropertySpec_AccessorsOrValue {
298                        value: JSPropertySpec_ValueWrapper {
299                            type_: JSPropertySpec_ValueWrapper_Type::String,
300                            __bindgen_anon_1: JSPropertySpec_ValueWrapper__bindgen_ty_1 {
301                                string: c"GainNode".as_ptr(),
302                            }
303                        }
304                    }
305                }
306,
307    JSPropertySpec::ZERO]))[..]
308])));
309}static sAttributes: ThreadUnsafeOnceLock<&[Guard<&[JSPropertySpec]>]> = ThreadUnsafeOnceLock::new();
310
311pub(crate) fn init_sAttributes_prefs<D: DomTypes>() {
312    sAttributes.set(Box::leak(Box::new([    Guard::new(&[Condition::Exposed(Globals::WINDOW)], (unsafe { sAttributes_specs.get() })[0]),
313    Guard::new(&[Condition::Satisfied], (unsafe { sAttributes_specs.get() })[1])])));
314}
315pub fn GetProtoObject<D: DomTypes>
316(cx: SafeJSContext, global: HandleObject, mut rval: MutableHandleObject){
317    /* Get the interface prototype object for this class.  This will create the
318       object as needed. */get_per_interface_object_handle(cx, global, ProtoOrIfaceIndex::ID(PrototypeList::ID::GainNode), CreateInterfaceObjects::<D>, rval)
319}
320
321
322static PrototypeClass: JSClass = JSClass {
323    name: c"GainNodePrototype".as_ptr(),
324    flags:
325        // JSCLASS_HAS_RESERVED_SLOTS()
326        (0 ) << JSCLASS_RESERVED_SLOTS_SHIFT,
327    cOps: ptr::null(),
328    spec: ptr::null(),
329    ext: ptr::null(),
330    oOps: ptr::null(),
331};
332
333unsafe extern "C" fn _constructor<D: DomTypes>
334(cx: *mut RawJSContext, argc: u32, vp: *mut JSVal) -> bool{
335    let mut result = false;
336    wrap_panic(&mut || result = {
337        let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
338        let args = CallArgs::from_vp(vp, argc);
339        let global = D::GlobalScope::from_object(JS_CALLEE(cx.raw_cx(), vp).to_object());
340
341                    call_default_constructor::<D>(
342                        SafeJSContext::from_ptr(cx.raw_cx()),
343                        &args,
344                        &global,
345                        PrototypeList::ID::GainNode,
346                        "GainNode",
347                        CreateInterfaceObjects::<D>,
348                        |cx: SafeJSContext, args: &CallArgs, global: &D::GlobalScope, desired_proto: HandleObject| {
349
350        if argc < 1 {
351            throw_type_error(cx.raw_cx(), "Not enough arguments to \"GainNode.constructor\".");
352            return false;
353        }
354        let arg0: DomRoot<D::BaseAudioContext> = if HandleValue::from_raw(args.get(0)).get().is_object() {
355            match root_from_handlevalue(HandleValue::from_raw(args.get(0)), SafeJSContext::from_ptr(cx.raw_cx())) {
356                Ok(val) => val,
357                Err(()) => {
358                    throw_type_error(cx.raw_cx(), "value does not implement interface BaseAudioContext.");
359                    return false;
360
361                }
362            }
363
364        } else {
365            throw_type_error(cx.raw_cx(), "Value is not an object.");
366            return false;
367
368        };
369        let arg1: crate::codegen::GenericBindings::GainNodeBinding::GainOptions = if args.get(1).is_undefined() {
370            crate::codegen::GenericBindings::GainNodeBinding::GainOptions::empty()
371        } else {
372            match FromJSValConvertible::from_jsval(cx.raw_cx(), HandleValue::from_raw(args.get(1)), ()) {
373                Ok(ConversionResult::Success(value)) => value,
374                Ok(ConversionResult::Failure(error)) => {
375                    throw_type_error(cx.raw_cx(), &error);
376            return false;
377
378                }
379                _ => {
380                    return false;
381
382                },
383            }
384
385        };
386        let result: Result<DomRoot<D::GainNode>, Error> = <D::GainNode>::Constructor(global.downcast::<D::Window>().unwrap(), Some(desired_proto), CanGc::note(), &arg0, &arg1);
387        let result = match result {
388            Ok(result) => result,
389            Err(e) => {
390                <D as DomHelpers<D>>::throw_dom_exception(SafeJSContext::from_ptr(cx.raw_cx()), global.upcast::<D::GlobalScope>(), e, CanGc::note());
391                return false;
392            },
393        };
394
395        (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
396        return true;
397                        }
398                    )
399
400    });
401    result
402}
403
404
405static INTERFACE_OBJECT_CLASS: ThreadUnsafeOnceLock<NonCallbackInterfaceObjectClass> = ThreadUnsafeOnceLock::new();
406
407pub(crate) fn init_interface_object<D: DomTypes>() {
408    INTERFACE_OBJECT_CLASS.set(NonCallbackInterfaceObjectClass::new(
409        Box::leak(Box::new(InterfaceConstructorBehavior::call(_constructor::<D>))),
410        b"function GainNode() {\n    [native code]\n}",
411        PrototypeList::ID::GainNode,
412        2,
413    ));
414}
415
416pub fn DefineDOMInterface<D: DomTypes>
417(cx: SafeJSContext, global: HandleObject){
418    define_dom_interface(cx, global, ProtoOrIfaceIndex::ID(PrototypeList::ID::GainNode),CreateInterfaceObjects::<D>, ConstructorEnabled::<D>)
419}
420
421pub fn ConstructorEnabled<D: DomTypes>
422(aCx: SafeJSContext, aObj: HandleObject) -> bool{
423    is_exposed_in(aObj, Globals::WINDOW)
424}
425
426unsafe fn CreateInterfaceObjects<D: DomTypes>
427(cx: SafeJSContext, global: HandleObject, cache: *mut ProtoOrIfaceArray){
428
429    rooted!(&in(cx) let mut prototype_proto = ptr::null_mut::<JSObject>());
430    AudioNode_Binding::GetProtoObject::<D>(cx, global, prototype_proto.handle_mut());
431    assert!(!prototype_proto.is_null());
432
433    rooted!(&in(cx) let mut prototype = ptr::null_mut::<JSObject>());
434    create_interface_prototype_object::<D>(cx,
435                                      global,
436                                      prototype_proto.handle(),
437                                      &PrototypeClass,
438                                      &[],
439                                      sAttributes.get(),
440                                      &[],
441                                      &[],
442                                      prototype.handle_mut());
443    assert!(!prototype.is_null());
444    assert!((*cache)[PrototypeList::ID::GainNode as usize].is_null());
445    (*cache)[PrototypeList::ID::GainNode as usize] = prototype.get();
446    <*mut JSObject>::post_barrier((*cache).as_mut_ptr().offset(PrototypeList::ID::GainNode as isize),
447                                  ptr::null_mut(),
448                                  prototype.get());
449
450    rooted!(&in(cx) let mut interface_proto = ptr::null_mut::<JSObject>());
451
452    AudioNode_Binding::GetConstructorObject::<D>(cx, global, interface_proto.handle_mut());
453
454    assert!(!interface_proto.is_null());
455
456    rooted!(&in(cx) let mut interface = ptr::null_mut::<JSObject>());
457    create_noncallback_interface_object::<D>(cx,
458                                        global,
459                                        interface_proto.handle(),
460                                        INTERFACE_OBJECT_CLASS.get(),
461                                        &[],
462                                        &[],
463                                        &[],
464                                        prototype.handle(),
465                                        c"GainNode",
466                                        1,
467                                        &[],
468                                        interface.handle_mut());
469    assert!(!interface.is_null());
470}
471
472
473        pub(crate) fn init_statics<D: DomTypes>() {
474            init_interface_object::<D>();
475            init_domjs_class::<D>();
476
477            init_gain_getterinfo::<D>();
478
479
480            init_sAttributes_specs::<D>();
481init_sAttributes_prefs::<D>();
482        }
483        } // mod GainNode_Binding
484
485