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