Skip to main content

script/dom/testing/
testbinding.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5// check-tidy: no specs after this line
6
7use std::borrow::ToOwned;
8use std::ptr;
9use std::rc::Rc;
10use std::time::Duration;
11
12use dom_struct::dom_struct;
13use js::context::JSContext;
14use js::gc::RootedVec;
15use js::jsapi::{Heap, JS_NewPlainObject, JSObject};
16use js::jsval::JSVal;
17use js::realm::CurrentRealm;
18use js::rust::{
19    CustomAutoRooterGuard, HandleObject, HandleValue, MutableHandleObject, MutableHandleValue,
20};
21use js::typedarray::{self, HeapUint8ClampedArray};
22use script_bindings::cformat;
23use script_bindings::interfaces::TestBindingHelpers;
24use script_bindings::record::Record;
25use script_bindings::reflector::{Reflector, reflect_dom_object_with_proto_and_cx};
26use servo_config::prefs;
27use servo_constellation_traits::BlobImpl;
28
29use crate::dom::bindings::buffer_source::create_buffer_source;
30use crate::dom::bindings::callback::ExceptionHandling;
31use crate::dom::bindings::codegen::Bindings::EventListenerBinding::EventListener;
32use crate::dom::bindings::codegen::Bindings::FunctionBinding::Function;
33use crate::dom::bindings::codegen::Bindings::TestBindingBinding::{
34    SimpleCallback, TestBindingMethods, TestDictionary, TestDictionaryDefaults,
35    TestDictionaryParent, TestDictionaryWithParent, TestDictionaryWithTypedArray, TestEnum,
36    TestURLLike,
37};
38use crate::dom::bindings::codegen::UnionTypes::{
39    self, BlobOrBlobSequence, BlobOrBoolean, BlobOrString, BlobOrUnsignedLong, ByteStringOrLong,
40    ByteStringSequenceOrLong, ByteStringSequenceOrLongOrString, EventOrString, EventOrUSVString,
41    HTMLElementOrLong, HTMLElementOrUnsignedLongOrStringOrBoolean, LongOrBoolean,
42    LongOrLongSequenceSequence, LongSequenceOrBoolean, ObjectOrBoolean, ObjectOrLong,
43    ObjectOrString, StringOrBoolean, StringOrLong, StringOrLongSequence, StringOrStringSequence,
44    StringOrUnsignedLong, StringSequenceOrUnsignedLong, UnsignedLongOrBoolean,
45};
46use crate::dom::bindings::error::{Error, Fallible};
47use crate::dom::bindings::num::Finite;
48use crate::dom::bindings::refcounted::TrustedPromise;
49use crate::dom::bindings::reflector::DomGlobal;
50use crate::dom::bindings::root::DomRoot;
51use crate::dom::bindings::str::{ByteString, DOMString, USVString};
52use crate::dom::bindings::trace::RootedTraceableBox;
53use crate::dom::bindings::weakref::MutableWeakRef;
54use crate::dom::blob::Blob;
55use crate::dom::globalscope::GlobalScope;
56use crate::dom::node::Node;
57use crate::dom::promise::Promise;
58use crate::dom::promisenativehandler::{Callback, PromiseNativeHandler};
59use crate::dom::url::URL;
60use crate::script_runtime::JSContext as SafeJSContext;
61use crate::timers::OneshotTimerCallback;
62
63#[dom_struct]
64pub(crate) struct TestBinding {
65    reflector_: Reflector,
66    url: MutableWeakRef<URL>,
67}
68
69impl TestBinding {
70    fn new_inherited() -> TestBinding {
71        TestBinding {
72            reflector_: Reflector::new(),
73            url: MutableWeakRef::new(None),
74        }
75    }
76
77    pub(crate) fn new(
78        cx: &mut JSContext,
79        global: &GlobalScope,
80        proto: Option<HandleObject>,
81    ) -> DomRoot<TestBinding> {
82        reflect_dom_object_with_proto_and_cx(
83            Box::new(TestBinding::new_inherited()),
84            global,
85            proto,
86            cx,
87        )
88    }
89}
90
91impl TestBindingMethods<crate::DomTypeHolder> for TestBinding {
92    fn Constructor(
93        cx: &mut JSContext,
94        global: &GlobalScope,
95        proto: Option<HandleObject>,
96    ) -> Fallible<DomRoot<TestBinding>> {
97        Ok(TestBinding::new(cx, global, proto))
98    }
99
100    #[expect(unused_variables)]
101    fn Constructor_(
102        cx: &mut JSContext,
103        global: &GlobalScope,
104        proto: Option<HandleObject>,
105        nums: Vec<f64>,
106    ) -> Fallible<DomRoot<TestBinding>> {
107        Ok(TestBinding::new(cx, global, proto))
108    }
109
110    #[expect(unused_variables)]
111    fn Constructor__(
112        cx: &mut JSContext,
113        global: &GlobalScope,
114        proto: Option<HandleObject>,
115        num: f64,
116    ) -> Fallible<DomRoot<TestBinding>> {
117        Ok(TestBinding::new(cx, global, proto))
118    }
119
120    fn BooleanAttribute(&self) -> bool {
121        false
122    }
123    fn SetBooleanAttribute(&self, _: bool) {}
124    fn ByteAttribute(&self) -> i8 {
125        0
126    }
127    fn SetByteAttribute(&self, _: i8) {}
128    fn OctetAttribute(&self) -> u8 {
129        0
130    }
131    fn SetOctetAttribute(&self, _: u8) {}
132    fn ShortAttribute(&self) -> i16 {
133        0
134    }
135    fn SetShortAttribute(&self, _: i16) {}
136    fn UnsignedShortAttribute(&self) -> u16 {
137        0
138    }
139    fn SetUnsignedShortAttribute(&self, _: u16) {}
140    fn LongAttribute(&self) -> i32 {
141        0
142    }
143    fn SetLongAttribute(&self, _: i32) {}
144    fn UnsignedLongAttribute(&self) -> u32 {
145        0
146    }
147    fn SetUnsignedLongAttribute(&self, _: u32) {}
148    fn LongLongAttribute(&self) -> i64 {
149        0
150    }
151    fn SetLongLongAttribute(&self, _: i64) {}
152    fn UnsignedLongLongAttribute(&self) -> u64 {
153        0
154    }
155    fn SetUnsignedLongLongAttribute(&self, _: u64) {}
156    fn UnrestrictedFloatAttribute(&self) -> f32 {
157        0.
158    }
159    fn SetUnrestrictedFloatAttribute(&self, _: f32) {}
160    fn FloatAttribute(&self) -> Finite<f32> {
161        Finite::wrap(0.)
162    }
163    fn SetFloatAttribute(&self, _: Finite<f32>) {}
164    fn UnrestrictedDoubleAttribute(&self) -> f64 {
165        0.
166    }
167    fn SetUnrestrictedDoubleAttribute(&self, _: f64) {}
168    fn DoubleAttribute(&self) -> Finite<f64> {
169        Finite::wrap(0.)
170    }
171    fn SetDoubleAttribute(&self, _: Finite<f64>) {}
172    fn StringAttribute(&self) -> DOMString {
173        DOMString::new()
174    }
175    fn SetStringAttribute(&self, _: DOMString) {}
176    fn UsvstringAttribute(&self) -> USVString {
177        USVString("".to_owned())
178    }
179    fn SetUsvstringAttribute(&self, _: USVString) {}
180    fn ByteStringAttribute(&self) -> ByteString {
181        ByteString::new(vec![])
182    }
183    fn SetByteStringAttribute(&self, _: ByteString) {}
184    fn EnumAttribute(&self) -> TestEnum {
185        TestEnum::_empty
186    }
187    fn SetEnumAttribute(&self, _: TestEnum) {}
188    fn InterfaceAttribute(&self, cx: &mut JSContext) -> DomRoot<Blob> {
189        Blob::new(
190            cx,
191            &self.global(),
192            BlobImpl::new_from_bytes(vec![], "".to_owned()),
193        )
194    }
195    fn SetInterfaceAttribute(&self, _: &Blob) {}
196    fn UnionAttribute(&self) -> HTMLElementOrLong {
197        HTMLElementOrLong::Long(0)
198    }
199    fn SetUnionAttribute(&self, _: HTMLElementOrLong) {}
200    fn Union2Attribute(&self) -> EventOrString {
201        EventOrString::String(DOMString::new())
202    }
203    fn SetUnion2Attribute(&self, _: EventOrString) {}
204    fn Union3Attribute(&self) -> EventOrUSVString {
205        EventOrUSVString::USVString(USVString("".to_owned()))
206    }
207    fn SetUnion3Attribute(&self, _: EventOrUSVString) {}
208    fn Union4Attribute(&self) -> StringOrUnsignedLong {
209        StringOrUnsignedLong::UnsignedLong(0u32)
210    }
211    fn SetUnion4Attribute(&self, _: StringOrUnsignedLong) {}
212    fn Union5Attribute(&self) -> StringOrBoolean {
213        StringOrBoolean::Boolean(true)
214    }
215    fn SetUnion5Attribute(&self, _: StringOrBoolean) {}
216    fn Union6Attribute(&self) -> UnsignedLongOrBoolean {
217        UnsignedLongOrBoolean::Boolean(true)
218    }
219    fn SetUnion6Attribute(&self, _: UnsignedLongOrBoolean) {}
220    fn Union7Attribute(&self) -> BlobOrBoolean {
221        BlobOrBoolean::Boolean(true)
222    }
223    fn SetUnion7Attribute(&self, _: BlobOrBoolean) {}
224    fn Union8Attribute(&self) -> BlobOrUnsignedLong {
225        BlobOrUnsignedLong::UnsignedLong(0u32)
226    }
227    fn SetUnion8Attribute(&self, _: BlobOrUnsignedLong) {}
228    fn Union9Attribute(&self) -> ByteStringOrLong {
229        ByteStringOrLong::ByteString(ByteString::new(vec![]))
230    }
231    fn SetUnion9Attribute(&self, _: ByteStringOrLong) {}
232    fn ArrayAttribute(&self, cx: &mut JSContext) -> RootedTraceableBox<HeapUint8ClampedArray> {
233        let data: [u8; 16] = [0; 16];
234
235        rooted!(&in(cx) let mut array = ptr::null_mut::<JSObject>());
236        create_buffer_source(cx, &data, array.handle_mut())
237            .expect("Creating ClampedU8 array should never fail")
238    }
239    fn AnyAttribute(&self, _: SafeJSContext, _: MutableHandleValue) {}
240    fn SetAnyAttribute(&self, _: SafeJSContext, _: HandleValue) {}
241    #[expect(unsafe_code)]
242    fn ObjectAttribute(&self, cx: SafeJSContext, mut return_value: MutableHandleObject) {
243        return_value.set(unsafe { JS_NewPlainObject(*cx) });
244    }
245    fn SetObjectAttribute(&self, _: SafeJSContext, _: *mut JSObject) {}
246
247    fn GetBooleanAttributeNullable(&self) -> Option<bool> {
248        Some(false)
249    }
250    fn SetBooleanAttributeNullable(&self, _: Option<bool>) {}
251    fn GetByteAttributeNullable(&self) -> Option<i8> {
252        Some(0)
253    }
254    fn SetByteAttributeNullable(&self, _: Option<i8>) {}
255    fn GetOctetAttributeNullable(&self) -> Option<u8> {
256        Some(0)
257    }
258    fn SetOctetAttributeNullable(&self, _: Option<u8>) {}
259    fn GetShortAttributeNullable(&self) -> Option<i16> {
260        Some(0)
261    }
262    fn SetShortAttributeNullable(&self, _: Option<i16>) {}
263    fn GetUnsignedShortAttributeNullable(&self) -> Option<u16> {
264        Some(0)
265    }
266    fn SetUnsignedShortAttributeNullable(&self, _: Option<u16>) {}
267    fn GetLongAttributeNullable(&self) -> Option<i32> {
268        Some(0)
269    }
270    fn SetLongAttributeNullable(&self, _: Option<i32>) {}
271    fn GetUnsignedLongAttributeNullable(&self) -> Option<u32> {
272        Some(0)
273    }
274    fn SetUnsignedLongAttributeNullable(&self, _: Option<u32>) {}
275    fn GetLongLongAttributeNullable(&self) -> Option<i64> {
276        Some(0)
277    }
278    fn SetLongLongAttributeNullable(&self, _: Option<i64>) {}
279    fn GetUnsignedLongLongAttributeNullable(&self) -> Option<u64> {
280        Some(0)
281    }
282    fn SetUnsignedLongLongAttributeNullable(&self, _: Option<u64>) {}
283    fn GetUnrestrictedFloatAttributeNullable(&self) -> Option<f32> {
284        Some(0.)
285    }
286    fn SetUnrestrictedFloatAttributeNullable(&self, _: Option<f32>) {}
287    fn GetFloatAttributeNullable(&self) -> Option<Finite<f32>> {
288        Some(Finite::wrap(0.))
289    }
290    fn SetFloatAttributeNullable(&self, _: Option<Finite<f32>>) {}
291    fn GetUnrestrictedDoubleAttributeNullable(&self) -> Option<f64> {
292        Some(0.)
293    }
294    fn SetUnrestrictedDoubleAttributeNullable(&self, _: Option<f64>) {}
295    fn GetDoubleAttributeNullable(&self) -> Option<Finite<f64>> {
296        Some(Finite::wrap(0.))
297    }
298    fn SetDoubleAttributeNullable(&self, _: Option<Finite<f64>>) {}
299    fn GetByteStringAttributeNullable(&self) -> Option<ByteString> {
300        Some(ByteString::new(vec![]))
301    }
302    fn SetByteStringAttributeNullable(&self, _: Option<ByteString>) {}
303    fn GetStringAttributeNullable(&self) -> Option<DOMString> {
304        Some(DOMString::new())
305    }
306    fn SetStringAttributeNullable(&self, _: Option<DOMString>) {}
307    fn GetUsvstringAttributeNullable(&self) -> Option<USVString> {
308        Some(USVString("".to_owned()))
309    }
310    fn SetUsvstringAttributeNullable(&self, _: Option<USVString>) {}
311    fn SetBinaryRenamedAttribute(&self, _: DOMString) {}
312    fn ForwardedAttribute(&self) -> DomRoot<TestBinding> {
313        DomRoot::from_ref(self)
314    }
315    fn BinaryRenamedAttribute(&self) -> DOMString {
316        DOMString::new()
317    }
318    fn SetBinaryRenamedAttribute2(&self, _: DOMString) {}
319    fn BinaryRenamedAttribute2(&self) -> DOMString {
320        DOMString::new()
321    }
322    fn Attr_to_automatically_rename(&self) -> DOMString {
323        DOMString::new()
324    }
325    fn SetAttr_to_automatically_rename(&self, _: DOMString) {}
326    fn GetEnumAttributeNullable(&self) -> Option<TestEnum> {
327        Some(TestEnum::_empty)
328    }
329    fn GetInterfaceAttributeNullable(&self, cx: &mut JSContext) -> Option<DomRoot<Blob>> {
330        Some(Blob::new(
331            cx,
332            &self.global(),
333            BlobImpl::new_from_bytes(vec![], "".to_owned()),
334        ))
335    }
336    fn SetInterfaceAttributeNullable(&self, _: Option<&Blob>) {}
337    fn GetInterfaceAttributeWeak(&self) -> Option<DomRoot<URL>> {
338        self.url.root()
339    }
340    fn SetInterfaceAttributeWeak(&self, url: Option<&URL>) {
341        self.url.set(url);
342    }
343    fn GetObjectAttributeNullable(&self, _: SafeJSContext, mut return_value: MutableHandleObject) {
344        return_value.set(ptr::null_mut());
345    }
346    fn SetObjectAttributeNullable(&self, _: SafeJSContext, _: *mut JSObject) {}
347    fn GetUnionAttributeNullable(&self) -> Option<HTMLElementOrLong> {
348        Some(HTMLElementOrLong::Long(0))
349    }
350    fn SetUnionAttributeNullable(&self, _: Option<HTMLElementOrLong>) {}
351    fn GetUnion2AttributeNullable(&self) -> Option<EventOrString> {
352        Some(EventOrString::String(DOMString::new()))
353    }
354    fn SetUnion2AttributeNullable(&self, _: Option<EventOrString>) {}
355    fn GetUnion3AttributeNullable(&self) -> Option<BlobOrBoolean> {
356        Some(BlobOrBoolean::Boolean(true))
357    }
358    fn SetUnion3AttributeNullable(&self, _: Option<BlobOrBoolean>) {}
359    fn GetUnion4AttributeNullable(&self) -> Option<UnsignedLongOrBoolean> {
360        Some(UnsignedLongOrBoolean::Boolean(true))
361    }
362    fn SetUnion4AttributeNullable(&self, _: Option<UnsignedLongOrBoolean>) {}
363    fn GetUnion5AttributeNullable(&self) -> Option<StringOrBoolean> {
364        Some(StringOrBoolean::Boolean(true))
365    }
366    fn SetUnion5AttributeNullable(&self, _: Option<StringOrBoolean>) {}
367    fn GetUnion6AttributeNullable(&self) -> Option<ByteStringOrLong> {
368        Some(ByteStringOrLong::ByteString(ByteString::new(vec![])))
369    }
370    fn SetUnion6AttributeNullable(&self, _: Option<ByteStringOrLong>) {}
371    fn BinaryRenamedMethod(&self) {}
372    fn ReceiveVoid(&self) {}
373    fn ReceiveBoolean(&self) -> bool {
374        false
375    }
376    fn ReceiveByte(&self) -> i8 {
377        0
378    }
379    fn ReceiveOctet(&self) -> u8 {
380        0
381    }
382    fn ReceiveShort(&self) -> i16 {
383        0
384    }
385    fn ReceiveUnsignedShort(&self) -> u16 {
386        0
387    }
388    fn ReceiveLong(&self) -> i32 {
389        0
390    }
391    fn ReceiveUnsignedLong(&self) -> u32 {
392        0
393    }
394    fn ReceiveLongLong(&self) -> i64 {
395        0
396    }
397    fn ReceiveUnsignedLongLong(&self) -> u64 {
398        0
399    }
400    fn ReceiveUnrestrictedFloat(&self) -> f32 {
401        0.
402    }
403    fn ReceiveFloat(&self) -> Finite<f32> {
404        Finite::wrap(0.)
405    }
406    fn ReceiveUnrestrictedDouble(&self) -> f64 {
407        0.
408    }
409    fn ReceiveDouble(&self) -> Finite<f64> {
410        Finite::wrap(0.)
411    }
412    fn ReceiveString(&self) -> DOMString {
413        DOMString::new()
414    }
415    fn ReceiveUsvstring(&self) -> USVString {
416        USVString("".to_owned())
417    }
418    fn ReceiveByteString(&self) -> ByteString {
419        ByteString::new(vec![])
420    }
421    fn ReceiveEnum(&self) -> TestEnum {
422        TestEnum::_empty
423    }
424    fn ReceiveInterface(&self, cx: &mut JSContext) -> DomRoot<Blob> {
425        Blob::new(
426            cx,
427            &self.global(),
428            BlobImpl::new_from_bytes(vec![], "".to_owned()),
429        )
430    }
431    fn ReceiveAny(&self, _: SafeJSContext, _: MutableHandleValue) {}
432    fn ReceiveObject(&self, cx: SafeJSContext, return_value: MutableHandleObject) {
433        self.ObjectAttribute(cx, return_value);
434    }
435    fn ReceiveUnion(&self) -> HTMLElementOrLong {
436        HTMLElementOrLong::Long(0)
437    }
438    fn ReceiveUnion2(&self) -> EventOrString {
439        EventOrString::String(DOMString::new())
440    }
441    fn ReceiveUnion3(&self) -> StringOrLongSequence {
442        StringOrLongSequence::LongSequence(vec![])
443    }
444    fn ReceiveUnion4(&self) -> StringOrStringSequence {
445        StringOrStringSequence::StringSequence(vec![])
446    }
447    fn ReceiveUnion5(&self) -> BlobOrBlobSequence {
448        BlobOrBlobSequence::BlobSequence(vec![])
449    }
450    fn ReceiveUnion6(&self) -> StringOrUnsignedLong {
451        StringOrUnsignedLong::String(DOMString::new())
452    }
453    fn ReceiveUnion7(&self) -> StringOrBoolean {
454        StringOrBoolean::Boolean(true)
455    }
456    fn ReceiveUnion8(&self) -> UnsignedLongOrBoolean {
457        UnsignedLongOrBoolean::UnsignedLong(0u32)
458    }
459    fn ReceiveUnion9(&self) -> HTMLElementOrUnsignedLongOrStringOrBoolean {
460        HTMLElementOrUnsignedLongOrStringOrBoolean::Boolean(true)
461    }
462    fn ReceiveUnion10(&self) -> ByteStringOrLong {
463        ByteStringOrLong::ByteString(ByteString::new(vec![]))
464    }
465    fn ReceiveUnion11(&self) -> ByteStringSequenceOrLongOrString {
466        ByteStringSequenceOrLongOrString::ByteStringSequence(vec![ByteString::new(vec![])])
467    }
468    fn ReceiveSequence(&self) -> Vec<i32> {
469        vec![1]
470    }
471    fn ReceiveInterfaceSequence(&self, cx: &mut JSContext) -> Vec<DomRoot<Blob>> {
472        vec![Blob::new(
473            cx,
474            &self.global(),
475            BlobImpl::new_from_bytes(vec![], "".to_owned()),
476        )]
477    }
478    fn ReceiveUnionIdentity(
479        &self,
480        _: SafeJSContext,
481        arg: UnionTypes::StringOrObject,
482    ) -> UnionTypes::StringOrObject {
483        arg
484    }
485
486    fn ReceiveNullableBoolean(&self) -> Option<bool> {
487        Some(false)
488    }
489    fn ReceiveNullableByte(&self) -> Option<i8> {
490        Some(0)
491    }
492    fn ReceiveNullableOctet(&self) -> Option<u8> {
493        Some(0)
494    }
495    fn ReceiveNullableShort(&self) -> Option<i16> {
496        Some(0)
497    }
498    fn ReceiveNullableUnsignedShort(&self) -> Option<u16> {
499        Some(0)
500    }
501    fn ReceiveNullableLong(&self) -> Option<i32> {
502        Some(0)
503    }
504    fn ReceiveNullableUnsignedLong(&self) -> Option<u32> {
505        Some(0)
506    }
507    fn ReceiveNullableLongLong(&self) -> Option<i64> {
508        Some(0)
509    }
510    fn ReceiveNullableUnsignedLongLong(&self) -> Option<u64> {
511        Some(0)
512    }
513    fn ReceiveNullableUnrestrictedFloat(&self) -> Option<f32> {
514        Some(0.)
515    }
516    fn ReceiveNullableFloat(&self) -> Option<Finite<f32>> {
517        Some(Finite::wrap(0.))
518    }
519    fn ReceiveNullableUnrestrictedDouble(&self) -> Option<f64> {
520        Some(0.)
521    }
522    fn ReceiveNullableDouble(&self) -> Option<Finite<f64>> {
523        Some(Finite::wrap(0.))
524    }
525    fn ReceiveNullableString(&self) -> Option<DOMString> {
526        Some(DOMString::new())
527    }
528    fn ReceiveNullableUsvstring(&self) -> Option<USVString> {
529        Some(USVString("".to_owned()))
530    }
531    fn ReceiveNullableByteString(&self) -> Option<ByteString> {
532        Some(ByteString::new(vec![]))
533    }
534    fn ReceiveNullableEnum(&self) -> Option<TestEnum> {
535        Some(TestEnum::_empty)
536    }
537    fn ReceiveNullableInterface(&self, cx: &mut JSContext) -> Option<DomRoot<Blob>> {
538        Some(Blob::new(
539            cx,
540            &self.global(),
541            BlobImpl::new_from_bytes(vec![], "".to_owned()),
542        ))
543    }
544    fn ReceiveNullableObject(&self, cx: SafeJSContext, return_value: MutableHandleObject) {
545        self.GetObjectAttributeNullable(cx, return_value)
546    }
547    fn ReceiveNullableUnion(&self) -> Option<HTMLElementOrLong> {
548        Some(HTMLElementOrLong::Long(0))
549    }
550    fn ReceiveNullableUnion2(&self) -> Option<EventOrString> {
551        Some(EventOrString::String(DOMString::new()))
552    }
553    fn ReceiveNullableUnion3(&self) -> Option<StringOrLongSequence> {
554        Some(StringOrLongSequence::String(DOMString::new()))
555    }
556    fn ReceiveNullableUnion4(&self) -> Option<LongSequenceOrBoolean> {
557        Some(LongSequenceOrBoolean::Boolean(true))
558    }
559    fn ReceiveNullableUnion5(&self) -> Option<UnsignedLongOrBoolean> {
560        Some(UnsignedLongOrBoolean::UnsignedLong(0u32))
561    }
562    fn ReceiveNullableUnion6(&self) -> Option<ByteStringOrLong> {
563        Some(ByteStringOrLong::ByteString(ByteString::new(vec![])))
564    }
565    fn ReceiveNullableSequence(&self) -> Option<Vec<i32>> {
566        Some(vec![1])
567    }
568    #[expect(unsafe_code)]
569    fn ReceiveObjectSequence(
570        &self,
571        cx: SafeJSContext,
572        return_value: &mut RootedVec<'_, Box<Heap<*mut JSObject>>>,
573    ) {
574        return_value.push(Heap::boxed(unsafe { JS_NewPlainObject(*cx) }));
575    }
576    fn GetDictionaryWithTypedArray(
577        &self,
578        cx: &mut JSContext,
579        _dictionary: RootedTraceableBox<TestDictionaryWithTypedArray>,
580    ) {
581        self.global().as_window().gc(cx);
582    }
583    fn ReceiveTestDictionaryWithSuccessOnKeyword(&self) -> RootedTraceableBox<TestDictionary> {
584        RootedTraceableBox::new(TestDictionary {
585            anyValue: RootedTraceableBox::new(Heap::default()),
586            booleanValue: None,
587            byteValue: None,
588            dict: RootedTraceableBox::new(TestDictionaryDefaults {
589                UnrestrictedDoubleValue: 0.0,
590                anyValue: RootedTraceableBox::new(Heap::default()),
591                arrayValue: Vec::new(),
592                booleanValue: false,
593                bytestringValue: ByteString::new(vec![]),
594                byteValue: 0,
595                doubleValue: Finite::new(1.0).unwrap(),
596                enumValue: TestEnum::Foo,
597                floatValue: Finite::new(1.0).unwrap(),
598                longLongValue: 54,
599                longValue: 12,
600                nullableBooleanValue: None,
601                nullableBytestringValue: None,
602                nullableByteValue: None,
603                nullableDoubleValue: None,
604                nullableFloatValue: None,
605                nullableLongLongValue: None,
606                nullableLongValue: None,
607                nullableObjectValue: RootedTraceableBox::new(Heap::default()),
608                nullableOctetValue: None,
609                nullableShortValue: None,
610                nullableStringValue: None,
611                nullableUnrestrictedDoubleValue: None,
612                nullableUnrestrictedFloatValue: None,
613                nullableUnsignedLongLongValue: None,
614                nullableUnsignedLongValue: None,
615                nullableUnsignedShortValue: None,
616                nullableUsvstringValue: None,
617                octetValue: 0,
618                shortValue: 0,
619                stringValue: DOMString::new(),
620                unrestrictedFloatValue: 0.0,
621                unsignedLongLongValue: 0,
622                unsignedLongValue: 0,
623                unsignedShortValue: 0,
624                usvstringValue: USVString("".to_owned()),
625            }),
626            doubleValue: None,
627            enumValue: None,
628            floatValue: None,
629            interfaceValue: None,
630            longLongValue: None,
631            longValue: None,
632            objectValue: None,
633            octetValue: None,
634            requiredValue: true,
635            seqDict: None,
636            elementSequence: None,
637            shortValue: None,
638            stringValue: None,
639            type_: Some(DOMString::from("success")),
640            unrestrictedDoubleValue: None,
641            unrestrictedFloatValue: None,
642            unsignedLongLongValue: None,
643            unsignedLongValue: None,
644            unsignedShortValue: None,
645            usvstringValue: None,
646            nonRequiredNullable: None,
647            nonRequiredNullable2: Some(None),
648            noCallbackImport: None,
649            noCallbackImport2: None,
650        })
651    }
652
653    fn DictMatchesPassedValues(&self, arg: RootedTraceableBox<TestDictionary>) -> bool {
654        arg.type_.as_ref().is_some_and(|s| s == "success") &&
655            arg.nonRequiredNullable.is_none() &&
656            arg.nonRequiredNullable2 == Some(None) &&
657            arg.noCallbackImport.is_none() &&
658            arg.noCallbackImport2.is_none()
659    }
660
661    fn PassBoolean(&self, _: bool) {}
662    fn PassByte(&self, _: i8) {}
663    fn PassOctet(&self, _: u8) {}
664    fn PassShort(&self, _: i16) {}
665    fn PassUnsignedShort(&self, _: u16) {}
666    fn PassLong(&self, _: i32) {}
667    fn PassUnsignedLong(&self, _: u32) {}
668    fn PassLongLong(&self, _: i64) {}
669    fn PassUnsignedLongLong(&self, _: u64) {}
670    fn PassUnrestrictedFloat(&self, _: f32) {}
671    fn PassFloat(&self, _: Finite<f32>) {}
672    fn PassUnrestrictedDouble(&self, _: f64) {}
673    fn PassDouble(&self, _: Finite<f64>) {}
674    fn PassString(&self, _: DOMString) {}
675    fn PassUsvstring(&self, _: USVString) {}
676    fn PassByteString(&self, _: ByteString) {}
677    fn PassEnum(&self, _: TestEnum) {}
678    fn PassInterface(&self, _: &Blob) {}
679    fn PassTypedArray(&self, _: CustomAutoRooterGuard<typedarray::Int8Array>) {}
680    fn PassTypedArray2(&self, _: CustomAutoRooterGuard<typedarray::ArrayBuffer>) {}
681    fn PassTypedArray3(&self, _: CustomAutoRooterGuard<typedarray::ArrayBufferView>) {}
682    fn PassUnion(&self, _: HTMLElementOrLong) {}
683    fn PassUnion2(&self, _: EventOrString) {}
684    fn PassUnion3(&self, _: BlobOrString) {}
685    fn PassUnion4(&self, _: StringOrStringSequence) {}
686    fn PassUnion5(&self, _: StringOrBoolean) {}
687    fn PassUnion6(&self, _: UnsignedLongOrBoolean) {}
688    fn PassUnion7(&self, _: StringSequenceOrUnsignedLong) {}
689    fn PassUnion8(&self, _: ByteStringSequenceOrLong) {}
690    fn PassUnion9(&self, _: UnionTypes::TestDictionaryOrLong) {}
691    fn PassUnion10(&self, _: SafeJSContext, _: UnionTypes::StringOrObject) {}
692    fn PassUnion11(&self, _: UnionTypes::ArrayBufferOrArrayBufferView) {}
693    fn PassUnionWithTypedef(&self, _: UnionTypes::DocumentOrStringOrURLOrBlob) {}
694    fn PassUnionWithTypedef2(&self, _: UnionTypes::LongSequenceOrStringOrURLOrBlob) {}
695    fn PassAny(&self, _: SafeJSContext, _: HandleValue) {}
696    fn PassObject(&self, _: SafeJSContext, _: *mut JSObject) {}
697    fn PassCallbackFunction(&self, _: Rc<Function>) {}
698    fn PassCallbackInterface(&self, _: Rc<EventListener>) {}
699    fn PassSequence(&self, _: Vec<i32>) {}
700    fn PassAnySequence(&self, _: SafeJSContext, _: CustomAutoRooterGuard<Vec<JSVal>>) {}
701    fn AnySequencePassthrough(
702        &self,
703        _: SafeJSContext,
704        seq: CustomAutoRooterGuard<Vec<JSVal>>,
705        return_value: &mut RootedVec<'_, Box<Heap<JSVal>>>,
706    ) {
707        return_value.extend(seq.handle().iter().map(|value| Heap::boxed(*value)));
708    }
709    fn PassObjectSequence(&self, _: SafeJSContext, _: CustomAutoRooterGuard<Vec<*mut JSObject>>) {}
710    fn PassStringSequence(&self, _: Vec<DOMString>) {}
711    fn PassInterfaceSequence(&self, _: Vec<DomRoot<Blob>>) {}
712
713    fn PassOverloaded(&self, _: CustomAutoRooterGuard<typedarray::ArrayBuffer>) {}
714    fn PassOverloaded_(&self, _: DOMString) {}
715
716    fn PassOverloadedDict(&self, _: &Node) -> DOMString {
717        "node".into()
718    }
719
720    fn PassOverloadedDict_(&self, u: &TestURLLike) -> DOMString {
721        u.href.clone()
722    }
723
724    fn PassOverloadedUnionOfObjectAndString(
725        &self,
726        _: SafeJSContext,
727        _: ObjectOrString,
728    ) -> DOMString {
729        "union".into()
730    }
731    fn PassOverloadedUnionOfObjectAndString_(&self, _: bool) -> DOMString {
732        "boolean".into()
733    }
734    fn PassOverloadedUnionOfObjectAndNumber(&self, _: SafeJSContext, _: ObjectOrLong) -> DOMString {
735        "union".into()
736    }
737    fn PassOverloadedUnionOfObjectAndNumber_(&self, _: bool) -> DOMString {
738        "boolean".into()
739    }
740    fn PassOverloadedUnionOfObjectAndBoolean(
741        &self,
742        _: SafeJSContext,
743        _: ObjectOrBoolean,
744    ) -> DOMString {
745        "union".into()
746    }
747    fn PassOverloadedUnionOfObjectAndBoolean_(&self, _: i32) -> DOMString {
748        "number".into()
749    }
750    fn PassOverloadedUnionOfStringAndNumber(&self, _: StringOrLong) -> DOMString {
751        "union".into()
752    }
753    fn PassOverloadedUnionOfStringAndNumber_(&self, _: bool) -> DOMString {
754        "boolean".into()
755    }
756    fn PassOverloadedUnionOfStringAndBoolean(&self, _: StringOrBoolean) -> DOMString {
757        "union".into()
758    }
759    fn PassOverloadedUnionOfStringAndBoolean_(&self, _: i32) -> DOMString {
760        "number".into()
761    }
762    fn PassOverloadedUnionOfNumberAndBoolean(&self, _: LongOrBoolean) -> DOMString {
763        "union".into()
764    }
765    fn PassOverloadedUnionOfNumberAndBoolean_(&self, _: DOMString) -> DOMString {
766        "string".into()
767    }
768
769    fn PassNullableBoolean(&self, _: Option<bool>) {}
770    fn PassNullableByte(&self, _: Option<i8>) {}
771    fn PassNullableOctet(&self, _: Option<u8>) {}
772    fn PassNullableShort(&self, _: Option<i16>) {}
773    fn PassNullableUnsignedShort(&self, _: Option<u16>) {}
774    fn PassNullableLong(&self, _: Option<i32>) {}
775    fn PassNullableUnsignedLong(&self, _: Option<u32>) {}
776    fn PassNullableLongLong(&self, _: Option<i64>) {}
777    fn PassNullableUnsignedLongLong(&self, _: Option<u64>) {}
778    fn PassNullableUnrestrictedFloat(&self, _: Option<f32>) {}
779    fn PassNullableFloat(&self, _: Option<Finite<f32>>) {}
780    fn PassNullableUnrestrictedDouble(&self, _: Option<f64>) {}
781    fn PassNullableDouble(&self, _: Option<Finite<f64>>) {}
782    fn PassNullableString(&self, _: Option<DOMString>) {}
783    fn PassNullableUsvstring(&self, _: Option<USVString>) {}
784    fn PassNullableByteString(&self, _: Option<ByteString>) {}
785    // fn PassNullableEnum(self, _: Option<TestEnum>) {}
786    fn PassNullableInterface(&self, _: Option<&Blob>) {}
787    fn PassNullableObject(&self, _: SafeJSContext, _: *mut JSObject) {}
788    fn PassNullableTypedArray(&self, _: CustomAutoRooterGuard<Option<typedarray::Int8Array>>) {}
789    fn PassNullableUnion(&self, _: Option<HTMLElementOrLong>) {}
790    fn PassNullableUnion2(&self, _: Option<EventOrString>) {}
791    fn PassNullableUnion3(&self, _: Option<StringOrLongSequence>) {}
792    fn PassNullableUnion4(&self, _: Option<LongSequenceOrBoolean>) {}
793    fn PassNullableUnion5(&self, _: Option<UnsignedLongOrBoolean>) {}
794    fn PassNullableUnion6(&self, _: Option<ByteStringOrLong>) {}
795    fn PassNullableCallbackFunction(&self, _: Option<Rc<Function>>) {}
796    fn PassNullableCallbackInterface(&self, _: Option<Rc<EventListener>>) {}
797    fn PassNullableSequence(&self, _: Option<Vec<i32>>) {}
798
799    fn PassOptionalBoolean(&self, _: Option<bool>) {}
800    fn PassOptionalByte(&self, _: Option<i8>) {}
801    fn PassOptionalOctet(&self, _: Option<u8>) {}
802    fn PassOptionalShort(&self, _: Option<i16>) {}
803    fn PassOptionalUnsignedShort(&self, _: Option<u16>) {}
804    fn PassOptionalLong(&self, _: Option<i32>) {}
805    fn PassOptionalUnsignedLong(&self, _: Option<u32>) {}
806    fn PassOptionalLongLong(&self, _: Option<i64>) {}
807    fn PassOptionalUnsignedLongLong(&self, _: Option<u64>) {}
808    fn PassOptionalUnrestrictedFloat(&self, _: Option<f32>) {}
809    fn PassOptionalFloat(&self, _: Option<Finite<f32>>) {}
810    fn PassOptionalUnrestrictedDouble(&self, _: Option<f64>) {}
811    fn PassOptionalDouble(&self, _: Option<Finite<f64>>) {}
812    fn PassOptionalString(&self, _: Option<DOMString>) {}
813    fn PassOptionalUsvstring(&self, _: Option<USVString>) {}
814    fn PassOptionalByteString(&self, _: Option<ByteString>) {}
815    fn PassOptionalEnum(&self, _: Option<TestEnum>) {}
816    fn PassOptionalInterface(&self, _: Option<&Blob>) {}
817    fn PassOptionalUnion(&self, _: Option<HTMLElementOrLong>) {}
818    fn PassOptionalUnion2(&self, _: Option<EventOrString>) {}
819    fn PassOptionalUnion3(&self, _: Option<StringOrLongSequence>) {}
820    fn PassOptionalUnion4(&self, _: Option<LongSequenceOrBoolean>) {}
821    fn PassOptionalUnion5(&self, _: Option<UnsignedLongOrBoolean>) {}
822    fn PassOptionalUnion6(&self, _: Option<ByteStringOrLong>) {}
823    fn PassOptionalAny(&self, _: SafeJSContext, _: HandleValue) {}
824    fn PassOptionalObject(&self, _: SafeJSContext, _: Option<*mut JSObject>) {}
825    fn PassOptionalCallbackFunction(&self, _: Option<Rc<Function>>) {}
826    fn PassOptionalCallbackInterface(&self, _: Option<Rc<EventListener>>) {}
827    fn PassOptionalSequence(&self, _: Option<Vec<i32>>) {}
828
829    fn PassOptionalNullableBoolean(&self, _: Option<Option<bool>>) {}
830    fn PassOptionalNullableByte(&self, _: Option<Option<i8>>) {}
831    fn PassOptionalNullableOctet(&self, _: Option<Option<u8>>) {}
832    fn PassOptionalNullableShort(&self, _: Option<Option<i16>>) {}
833    fn PassOptionalNullableUnsignedShort(&self, _: Option<Option<u16>>) {}
834    fn PassOptionalNullableLong(&self, _: Option<Option<i32>>) {}
835    fn PassOptionalNullableUnsignedLong(&self, _: Option<Option<u32>>) {}
836    fn PassOptionalNullableLongLong(&self, _: Option<Option<i64>>) {}
837    fn PassOptionalNullableUnsignedLongLong(&self, _: Option<Option<u64>>) {}
838    fn PassOptionalNullableUnrestrictedFloat(&self, _: Option<Option<f32>>) {}
839    fn PassOptionalNullableFloat(&self, _: Option<Option<Finite<f32>>>) {}
840    fn PassOptionalNullableUnrestrictedDouble(&self, _: Option<Option<f64>>) {}
841    fn PassOptionalNullableDouble(&self, _: Option<Option<Finite<f64>>>) {}
842    fn PassOptionalNullableString(&self, _: Option<Option<DOMString>>) {}
843    fn PassOptionalNullableUsvstring(&self, _: Option<Option<USVString>>) {}
844    fn PassOptionalNullableByteString(&self, _: Option<Option<ByteString>>) {}
845    // fn PassOptionalNullableEnum(self, _: Option<Option<TestEnum>>) {}
846    fn PassOptionalNullableInterface(&self, _: Option<Option<&Blob>>) {}
847    fn PassOptionalNullableObject(&self, _: SafeJSContext, _: Option<*mut JSObject>) {}
848    fn PassOptionalNullableUnion(&self, _: Option<Option<HTMLElementOrLong>>) {}
849    fn PassOptionalNullableUnion2(&self, _: Option<Option<EventOrString>>) {}
850    fn PassOptionalNullableUnion3(&self, _: Option<Option<StringOrLongSequence>>) {}
851    fn PassOptionalNullableUnion4(&self, _: Option<Option<LongSequenceOrBoolean>>) {}
852    fn PassOptionalNullableUnion5(&self, _: Option<Option<UnsignedLongOrBoolean>>) {}
853    fn PassOptionalNullableUnion6(&self, _: Option<Option<ByteStringOrLong>>) {}
854    fn PassOptionalNullableCallbackFunction(&self, _: Option<Option<Rc<Function>>>) {}
855    fn PassOptionalNullableCallbackInterface(&self, _: Option<Option<Rc<EventListener>>>) {}
856    fn PassOptionalNullableSequence(&self, _: Option<Option<Vec<i32>>>) {}
857
858    fn PassOptionalBooleanWithDefault(&self, _: bool) {}
859    fn PassOptionalByteWithDefault(&self, _: i8) {}
860    fn PassOptionalOctetWithDefault(&self, _: u8) {}
861    fn PassOptionalShortWithDefault(&self, _: i16) {}
862    fn PassOptionalUnsignedShortWithDefault(&self, _: u16) {}
863    fn PassOptionalLongWithDefault(&self, _: i32) {}
864    fn PassOptionalUnsignedLongWithDefault(&self, _: u32) {}
865    fn PassOptionalLongLongWithDefault(&self, _: i64) {}
866    fn PassOptionalUnsignedLongLongWithDefault(&self, _: u64) {}
867    fn PassOptionalStringWithDefault(&self, _: DOMString) {}
868    fn PassOptionalUsvstringWithDefault(&self, _: USVString) {}
869    fn PassOptionalBytestringWithDefault(&self, _: ByteString) {}
870    fn PassOptionalEnumWithDefault(&self, _: TestEnum) {}
871    fn PassOptionalSequenceWithDefault(&self, _: Vec<i32>) {}
872
873    fn PassOptionalNullableBooleanWithDefault(&self, _: Option<bool>) {}
874    fn PassOptionalNullableByteWithDefault(&self, _: Option<i8>) {}
875    fn PassOptionalNullableOctetWithDefault(&self, _: Option<u8>) {}
876    fn PassOptionalNullableShortWithDefault(&self, _: Option<i16>) {}
877    fn PassOptionalNullableUnsignedShortWithDefault(&self, _: Option<u16>) {}
878    fn PassOptionalNullableLongWithDefault(&self, _: Option<i32>) {}
879    fn PassOptionalNullableUnsignedLongWithDefault(&self, _: Option<u32>) {}
880    fn PassOptionalNullableLongLongWithDefault(&self, _: Option<i64>) {}
881    fn PassOptionalNullableUnsignedLongLongWithDefault(&self, _: Option<u64>) {}
882    // fn PassOptionalNullableUnrestrictedFloatWithDefault(self, _: Option<f32>) {}
883    // fn PassOptionalNullableFloatWithDefault(self, _: Option<Finite<f32>>) {}
884    // fn PassOptionalNullableUnrestrictedDoubleWithDefault(self, _: Option<f64>) {}
885    // fn PassOptionalNullableDoubleWithDefault(self, _: Option<Finite<f64>>) {}
886    fn PassOptionalNullableStringWithDefault(&self, _: Option<DOMString>) {}
887    fn PassOptionalNullableUsvstringWithDefault(&self, _: Option<USVString>) {}
888    fn PassOptionalNullableByteStringWithDefault(&self, _: Option<ByteString>) {}
889    // fn PassOptionalNullableEnumWithDefault(self, _: Option<TestEnum>) {}
890    fn PassOptionalNullableInterfaceWithDefault(&self, _: Option<&Blob>) {}
891    fn PassOptionalNullableObjectWithDefault(&self, _: SafeJSContext, _: *mut JSObject) {}
892    fn PassOptionalNullableUnionWithDefault(&self, _: Option<HTMLElementOrLong>) {}
893    fn PassOptionalNullableUnion2WithDefault(&self, _: Option<EventOrString>) {}
894    // fn PassOptionalNullableCallbackFunctionWithDefault(self, _: Option<Function>) {}
895    fn PassOptionalNullableCallbackInterfaceWithDefault(&self, _: Option<Rc<EventListener>>) {}
896    fn PassOptionalAnyWithDefault(&self, _: SafeJSContext, _: HandleValue) {}
897
898    fn PassOptionalNullableBooleanWithNonNullDefault(&self, _: Option<bool>) {}
899    fn PassOptionalNullableByteWithNonNullDefault(&self, _: Option<i8>) {}
900    fn PassOptionalNullableOctetWithNonNullDefault(&self, _: Option<u8>) {}
901    fn PassOptionalNullableShortWithNonNullDefault(&self, _: Option<i16>) {}
902    fn PassOptionalNullableUnsignedShortWithNonNullDefault(&self, _: Option<u16>) {}
903    fn PassOptionalNullableLongWithNonNullDefault(&self, _: Option<i32>) {}
904    fn PassOptionalNullableUnsignedLongWithNonNullDefault(&self, _: Option<u32>) {}
905    fn PassOptionalNullableLongLongWithNonNullDefault(&self, _: Option<i64>) {}
906    fn PassOptionalNullableUnsignedLongLongWithNonNullDefault(&self, _: Option<u64>) {}
907    // fn PassOptionalNullableUnrestrictedFloatWithNonNullDefault(self, _: Option<f32>) {}
908    // fn PassOptionalNullableFloatWithNonNullDefault(self, _: Option<Finite<f32>>) {}
909    // fn PassOptionalNullableUnrestrictedDoubleWithNonNullDefault(self, _: Option<f64>) {}
910    // fn PassOptionalNullableDoubleWithNonNullDefault(self, _: Option<Finite<f64>>) {}
911    fn PassOptionalNullableStringWithNonNullDefault(&self, _: Option<DOMString>) {}
912    fn PassOptionalNullableUsvstringWithNonNullDefault(&self, _: Option<USVString>) {}
913    // fn PassOptionalNullableEnumWithNonNullDefault(self, _: Option<TestEnum>) {}
914    fn PassOptionalOverloaded(&self, a: &TestBinding, _: u32, _: u32) -> DomRoot<TestBinding> {
915        DomRoot::from_ref(a)
916    }
917    fn PassOptionalOverloaded_(&self, _: &Blob, _: u32) {}
918
919    fn PassVariadicBoolean(&self, _: Vec<bool>) {}
920    fn PassVariadicBooleanAndDefault(&self, _: bool, _: Vec<bool>) {}
921    fn PassVariadicByte(&self, _: Vec<i8>) {}
922    fn PassVariadicOctet(&self, _: Vec<u8>) {}
923    fn PassVariadicShort(&self, _: Vec<i16>) {}
924    fn PassVariadicUnsignedShort(&self, _: Vec<u16>) {}
925    fn PassVariadicLong(&self, _: Vec<i32>) {}
926    fn PassVariadicUnsignedLong(&self, _: Vec<u32>) {}
927    fn PassVariadicLongLong(&self, _: Vec<i64>) {}
928    fn PassVariadicUnsignedLongLong(&self, _: Vec<u64>) {}
929    fn PassVariadicUnrestrictedFloat(&self, _: Vec<f32>) {}
930    fn PassVariadicFloat(&self, _: Vec<Finite<f32>>) {}
931    fn PassVariadicUnrestrictedDouble(&self, _: Vec<f64>) {}
932    fn PassVariadicDouble(&self, _: Vec<Finite<f64>>) {}
933    fn PassVariadicString(&self, _: Vec<DOMString>) {}
934    fn PassVariadicUsvstring(&self, _: Vec<USVString>) {}
935    fn PassVariadicByteString(&self, _: Vec<ByteString>) {}
936    fn PassVariadicEnum(&self, _: Vec<TestEnum>) {}
937    fn PassVariadicInterface(&self, _: &[&Blob]) {}
938    fn PassVariadicUnion(&self, _: Vec<HTMLElementOrLong>) {}
939    fn PassVariadicUnion2(&self, _: Vec<EventOrString>) {}
940    fn PassVariadicUnion3(&self, _: Vec<BlobOrString>) {}
941    fn PassVariadicUnion4(&self, _: Vec<BlobOrBoolean>) {}
942    fn PassVariadicUnion5(&self, _: Vec<StringOrUnsignedLong>) {}
943    fn PassVariadicUnion6(&self, _: Vec<UnsignedLongOrBoolean>) {}
944    fn PassVariadicUnion7(&self, _: Vec<ByteStringOrLong>) {}
945    fn PassVariadicAny(&self, _: SafeJSContext, _: Vec<HandleValue>) {}
946    fn PassVariadicObject(&self, _: SafeJSContext, _: Vec<*mut JSObject>) {}
947    fn BooleanMozPreference(&self, pref_name: DOMString) -> bool {
948        prefs::get()
949            .get_value(&pref_name.str())
950            .try_into()
951            .unwrap_or(false)
952    }
953    fn StringMozPreference(&self, pref_name: DOMString) -> DOMString {
954        let string: String = prefs::get()
955            .get_value(&pref_name.str())
956            .try_into()
957            .unwrap_or_default();
958        string.into()
959    }
960    fn PrefControlledAttributeDisabled(&self) -> bool {
961        false
962    }
963    fn PrefControlledAttributeEnabled(&self) -> bool {
964        false
965    }
966    fn PrefControlledMethodDisabled(&self) {}
967    fn PrefControlledMethodEnabled(&self) {}
968    fn FuncControlledAttributeDisabled(&self) -> bool {
969        false
970    }
971    fn FuncControlledAttributeEnabled(&self) -> bool {
972        false
973    }
974    fn FuncControlledMethodDisabled(&self) {}
975    fn FuncControlledMethodEnabled(&self) {}
976
977    fn PassRecordPromise(&self, _: Record<DOMString, Rc<Promise>>) {}
978    fn PassRecord(&self, _: Record<DOMString, i32>) {}
979    fn PassRecordWithUSVStringKey(&self, _: Record<USVString, i32>) {}
980    fn PassRecordWithByteStringKey(&self, _: Record<ByteString, i32>) {}
981    fn PassNullableRecord(&self, _: Option<Record<DOMString, i32>>) {}
982    fn PassRecordOfNullableInts(&self, _: Record<DOMString, Option<i32>>) {}
983    fn PassOptionalRecordOfNullableInts(&self, _: Option<Record<DOMString, Option<i32>>>) {}
984    fn PassOptionalNullableRecordOfNullableInts(
985        &self,
986        _: Option<Option<Record<DOMString, Option<i32>>>>,
987    ) {
988    }
989    fn PassCastableObjectRecord(&self, _: Record<DOMString, DomRoot<TestBinding>>) {}
990    fn PassNullableCastableObjectRecord(&self, _: Record<DOMString, Option<DomRoot<TestBinding>>>) {
991    }
992    fn PassCastableObjectNullableRecord(&self, _: Option<Record<DOMString, DomRoot<TestBinding>>>) {
993    }
994    fn PassNullableCastableObjectNullableRecord(
995        &self,
996        _: Option<Record<DOMString, Option<DomRoot<TestBinding>>>>,
997    ) {
998    }
999    fn PassOptionalRecord(&self, _: Option<Record<DOMString, i32>>) {}
1000    fn PassOptionalNullableRecord(&self, _: Option<Option<Record<DOMString, i32>>>) {}
1001    fn PassOptionalNullableRecordWithDefaultValue(&self, _: Option<Record<DOMString, i32>>) {}
1002    fn PassOptionalObjectRecord(&self, _: Option<Record<DOMString, DomRoot<TestBinding>>>) {}
1003    fn PassStringRecord(&self, _: Record<DOMString, DOMString>) {}
1004    fn PassByteStringRecord(&self, _: Record<DOMString, ByteString>) {}
1005    fn PassRecordOfRecords(&self, _: Record<DOMString, Record<DOMString, i32>>) {}
1006    fn PassRecordUnion(&self, _: UnionTypes::LongOrStringByteStringRecord) {}
1007    fn PassRecordUnion2(&self, _: UnionTypes::TestBindingOrStringByteStringRecord) {}
1008    fn PassRecordUnion3(
1009        &self,
1010        _: UnionTypes::TestBindingOrByteStringSequenceSequenceOrStringByteStringRecord,
1011    ) {
1012    }
1013    fn ReceiveRecord(&self) -> Record<DOMString, i32> {
1014        Record::new()
1015    }
1016    fn ReceiveRecordWithUSVStringKey(&self) -> Record<USVString, i32> {
1017        Record::new()
1018    }
1019    fn ReceiveRecordWithByteStringKey(&self) -> Record<ByteString, i32> {
1020        Record::new()
1021    }
1022    fn ReceiveNullableRecord(&self) -> Option<Record<DOMString, i32>> {
1023        Some(Record::new())
1024    }
1025    fn ReceiveRecordOfNullableInts(&self) -> Record<DOMString, Option<i32>> {
1026        Record::new()
1027    }
1028    fn ReceiveNullableRecordOfNullableInts(&self) -> Option<Record<DOMString, Option<i32>>> {
1029        Some(Record::new())
1030    }
1031    fn ReceiveRecordOfRecords(&self) -> Record<DOMString, Record<DOMString, i32>> {
1032        Record::new()
1033    }
1034    fn ReceiveAnyRecord(&self) -> Record<DOMString, JSVal> {
1035        Record::new()
1036    }
1037
1038    fn ReturnResolvedPromise(&self, cx: &mut JSContext, v: HandleValue) -> Rc<Promise> {
1039        Promise::new_resolved(cx, &self.global(), v)
1040    }
1041
1042    fn ReturnRejectedPromise(&self, cx: &mut JSContext, v: HandleValue) -> Rc<Promise> {
1043        Promise::new_rejected(cx, &self.global(), v)
1044    }
1045
1046    fn PromiseResolveNative(&self, cx: &mut JSContext, p: &Promise, v: HandleValue) {
1047        p.resolve(cx, v);
1048    }
1049
1050    fn PromiseRejectNative(&self, cx: &mut JSContext, p: &Promise, v: HandleValue) {
1051        p.reject(cx, v);
1052    }
1053
1054    fn PromiseRejectWithTypeError(&self, cx: &mut JSContext, p: &Promise, s: USVString) {
1055        p.reject_error(cx, Error::Type(cformat!("{}", s.0)));
1056    }
1057
1058    fn ResolvePromiseDelayed(&self, cx: &mut JSContext, p: &Promise, value: DOMString, delay: u64) {
1059        let promise = p.duplicate(cx);
1060        let cb = TestBindingCallback {
1061            promise: TrustedPromise::new(promise),
1062            value,
1063        };
1064        let _ = self.global().schedule_callback(
1065            OneshotTimerCallback::TestBindingCallback(cb),
1066            Duration::from_millis(delay),
1067        );
1068    }
1069
1070    fn PromiseNativeHandler(
1071        &self,
1072        realm: &mut CurrentRealm,
1073        resolve: Option<Rc<SimpleCallback>>,
1074        reject: Option<Rc<SimpleCallback>>,
1075    ) -> Rc<Promise> {
1076        let global = self.global();
1077        let handler = PromiseNativeHandler::new(
1078            realm,
1079            &global,
1080            resolve.map(SimpleHandler::new_boxed),
1081            reject.map(SimpleHandler::new_boxed),
1082        );
1083
1084        let p = Promise::new_in_realm(realm);
1085        p.append_native_handler(realm, &handler);
1086        return p;
1087
1088        #[derive(JSTraceable, MallocSizeOf)]
1089        struct SimpleHandler {
1090            #[conditional_malloc_size_of]
1091            handler: Rc<SimpleCallback>,
1092        }
1093        impl SimpleHandler {
1094            fn new_boxed(callback: Rc<SimpleCallback>) -> Box<dyn Callback> {
1095                Box::new(SimpleHandler { handler: callback })
1096            }
1097        }
1098        impl Callback for SimpleHandler {
1099            fn callback(&self, cx: &mut CurrentRealm, v: HandleValue) {
1100                let global = GlobalScope::from_current_realm(cx);
1101                let _ = self
1102                    .handler
1103                    .Call_(cx, &*global, v, ExceptionHandling::Report);
1104            }
1105        }
1106    }
1107
1108    fn PromiseAttribute(&self, cx: &mut CurrentRealm) -> Rc<Promise> {
1109        Promise::new_in_realm(cx)
1110    }
1111
1112    fn AcceptPromise(&self, _promise: &Promise) {}
1113
1114    fn PassSequenceSequence(&self, _seq: Vec<Vec<i32>>) {}
1115    fn ReturnSequenceSequence(&self) -> Vec<Vec<i32>> {
1116        vec![]
1117    }
1118    fn PassUnionSequenceSequence(&self, seq: LongOrLongSequenceSequence) {
1119        match seq {
1120            LongOrLongSequenceSequence::Long(_) => (),
1121            LongOrLongSequenceSequence::LongSequenceSequence(seq) => {
1122                let _seq: Vec<Vec<i32>> = seq;
1123            },
1124        }
1125    }
1126
1127    fn EntryGlobal(&self) -> DomRoot<GlobalScope> {
1128        GlobalScope::entry()
1129    }
1130    fn IncumbentGlobal(&self) -> DomRoot<GlobalScope> {
1131        GlobalScope::incumbent().unwrap()
1132    }
1133
1134    fn SemiExposedBoolFromInterface(&self) -> bool {
1135        true
1136    }
1137
1138    fn BoolFromSemiExposedPartialInterface(&self) -> bool {
1139        true
1140    }
1141
1142    fn SemiExposedBoolFromPartialInterface(&self) -> bool {
1143        true
1144    }
1145
1146    fn GetDictionaryWithParent(&self, s1: DOMString, s2: DOMString) -> TestDictionaryWithParent {
1147        TestDictionaryWithParent {
1148            parent: TestDictionaryParent {
1149                parentStringMember: Some(s1),
1150            },
1151            stringMember: Some(s2),
1152        }
1153    }
1154
1155    fn MethodThrowToRejectPromise(&self) -> Fallible<Rc<Promise>> {
1156        Err(Error::Type(c"test".to_owned()))
1157    }
1158
1159    fn GetGetterThrowToRejectPromise(&self) -> Fallible<Rc<Promise>> {
1160        Err(Error::Type(c"test".to_owned()))
1161    }
1162
1163    fn MethodInternalThrowToRejectPromise(&self, _arg: u64) -> Rc<Promise> {
1164        unreachable!("Method should already throw")
1165    }
1166
1167    fn StaticThrowToRejectPromise(_: &GlobalScope) -> Fallible<Rc<Promise>> {
1168        Err(Error::Type(c"test".to_owned()))
1169    }
1170
1171    fn StaticInternalThrowToRejectPromise(_: &GlobalScope, _arg: u64) -> Rc<Promise> {
1172        unreachable!("Method should already throw")
1173    }
1174
1175    fn BooleanAttributeStatic(_: &GlobalScope) -> bool {
1176        false
1177    }
1178    fn SetBooleanAttributeStatic(_: &GlobalScope, _: bool) {}
1179    fn ReceiveVoidStatic(_: &GlobalScope) {}
1180    fn PrefControlledStaticAttributeDisabled(_: &GlobalScope) -> bool {
1181        false
1182    }
1183    fn PrefControlledStaticAttributeEnabled(_: &GlobalScope) -> bool {
1184        false
1185    }
1186    fn PrefControlledStaticMethodDisabled(_: &GlobalScope) {}
1187    fn PrefControlledStaticMethodEnabled(_: &GlobalScope) {}
1188    fn FuncControlledStaticAttributeDisabled(_: &GlobalScope) -> bool {
1189        false
1190    }
1191    fn FuncControlledStaticAttributeEnabled(_: &GlobalScope) -> bool {
1192        false
1193    }
1194    fn FuncControlledStaticMethodDisabled(_: &GlobalScope) {}
1195    fn FuncControlledStaticMethodEnabled(_: &GlobalScope) {}
1196}
1197
1198impl TestBinding {
1199    pub(crate) fn condition_satisfied(_: &mut JSContext, _: HandleObject) -> bool {
1200        true
1201    }
1202    pub(crate) fn condition_unsatisfied(_: &mut JSContext, _: HandleObject) -> bool {
1203        false
1204    }
1205}
1206
1207#[derive(JSTraceable, MallocSizeOf)]
1208pub(crate) struct TestBindingCallback {
1209    #[ignore_malloc_size_of = "unclear ownership semantics"]
1210    promise: TrustedPromise,
1211    value: DOMString,
1212}
1213
1214impl TestBindingCallback {
1215    pub(crate) fn invoke(self, cx: &mut JSContext) {
1216        self.promise.root().resolve_native(cx, &self.value);
1217    }
1218}
1219
1220impl TestBindingHelpers for TestBinding {
1221    fn condition_satisfied(cx: &mut JSContext, global: HandleObject) -> bool {
1222        Self::condition_satisfied(cx, global)
1223    }
1224    fn condition_unsatisfied(cx: &mut JSContext, global: HandleObject) -> bool {
1225        Self::condition_unsatisfied(cx, global)
1226    }
1227}