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