1use std::borrow::ToOwned;
8use std::ptr::{self, NonNull};
9use std::rc::Rc;
10use std::time::Duration;
11
12use dom_struct::dom_struct;
13use js::jsapi::{Heap, JS_NewPlainObject, JSObject};
14use js::jsval::JSVal;
15use js::realm::CurrentRealm;
16use js::rust::{CustomAutoRooterGuard, HandleObject, HandleValue, MutableHandleValue};
17use js::typedarray::{self, HeapUint8ClampedArray};
18use script_bindings::cformat;
19use script_bindings::interfaces::TestBindingHelpers;
20use script_bindings::record::Record;
21use servo_config::prefs;
22use servo_constellation_traits::BlobImpl;
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::{
34 self, BlobOrBlobSequence, BlobOrBoolean, BlobOrString, BlobOrUnsignedLong, ByteStringOrLong,
35 ByteStringSequenceOrLong, ByteStringSequenceOrLongOrString, EventOrString, EventOrUSVString,
36 HTMLElementOrLong, HTMLElementOrUnsignedLongOrStringOrBoolean, LongOrBoolean,
37 LongOrLongSequenceSequence, LongSequenceOrBoolean, ObjectOrBoolean, ObjectOrLong,
38 ObjectOrString, StringOrBoolean, StringOrLong, 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 PassOverloadedUnionOfObjectAndString(
714 &self,
715 _: SafeJSContext,
716 _: ObjectOrString,
717 ) -> DOMString {
718 "union".into()
719 }
720 fn PassOverloadedUnionOfObjectAndString_(&self, _: bool) -> DOMString {
721 "boolean".into()
722 }
723 fn PassOverloadedUnionOfObjectAndNumber(&self, _: SafeJSContext, _: ObjectOrLong) -> DOMString {
724 "union".into()
725 }
726 fn PassOverloadedUnionOfObjectAndNumber_(&self, _: bool) -> DOMString {
727 "boolean".into()
728 }
729 fn PassOverloadedUnionOfObjectAndBoolean(
730 &self,
731 _: SafeJSContext,
732 _: ObjectOrBoolean,
733 ) -> DOMString {
734 "union".into()
735 }
736 fn PassOverloadedUnionOfObjectAndBoolean_(&self, _: i32) -> DOMString {
737 "number".into()
738 }
739 fn PassOverloadedUnionOfStringAndNumber(&self, _: StringOrLong) -> DOMString {
740 "union".into()
741 }
742 fn PassOverloadedUnionOfStringAndNumber_(&self, _: bool) -> DOMString {
743 "boolean".into()
744 }
745 fn PassOverloadedUnionOfStringAndBoolean(&self, _: StringOrBoolean) -> DOMString {
746 "union".into()
747 }
748 fn PassOverloadedUnionOfStringAndBoolean_(&self, _: i32) -> DOMString {
749 "number".into()
750 }
751 fn PassOverloadedUnionOfNumberAndBoolean(&self, _: LongOrBoolean) -> DOMString {
752 "union".into()
753 }
754 fn PassOverloadedUnionOfNumberAndBoolean_(&self, _: DOMString) -> DOMString {
755 "string".into()
756 }
757
758 fn PassNullableBoolean(&self, _: Option<bool>) {}
759 fn PassNullableByte(&self, _: Option<i8>) {}
760 fn PassNullableOctet(&self, _: Option<u8>) {}
761 fn PassNullableShort(&self, _: Option<i16>) {}
762 fn PassNullableUnsignedShort(&self, _: Option<u16>) {}
763 fn PassNullableLong(&self, _: Option<i32>) {}
764 fn PassNullableUnsignedLong(&self, _: Option<u32>) {}
765 fn PassNullableLongLong(&self, _: Option<i64>) {}
766 fn PassNullableUnsignedLongLong(&self, _: Option<u64>) {}
767 fn PassNullableUnrestrictedFloat(&self, _: Option<f32>) {}
768 fn PassNullableFloat(&self, _: Option<Finite<f32>>) {}
769 fn PassNullableUnrestrictedDouble(&self, _: Option<f64>) {}
770 fn PassNullableDouble(&self, _: Option<Finite<f64>>) {}
771 fn PassNullableString(&self, _: Option<DOMString>) {}
772 fn PassNullableUsvstring(&self, _: Option<USVString>) {}
773 fn PassNullableByteString(&self, _: Option<ByteString>) {}
774 fn PassNullableInterface(&self, _: Option<&Blob>) {}
776 fn PassNullableObject(&self, _: SafeJSContext, _: *mut JSObject) {}
777 fn PassNullableTypedArray(&self, _: CustomAutoRooterGuard<Option<typedarray::Int8Array>>) {}
778 fn PassNullableUnion(&self, _: Option<HTMLElementOrLong>) {}
779 fn PassNullableUnion2(&self, _: Option<EventOrString>) {}
780 fn PassNullableUnion3(&self, _: Option<StringOrLongSequence>) {}
781 fn PassNullableUnion4(&self, _: Option<LongSequenceOrBoolean>) {}
782 fn PassNullableUnion5(&self, _: Option<UnsignedLongOrBoolean>) {}
783 fn PassNullableUnion6(&self, _: Option<ByteStringOrLong>) {}
784 fn PassNullableCallbackFunction(&self, _: Option<Rc<Function>>) {}
785 fn PassNullableCallbackInterface(&self, _: Option<Rc<EventListener>>) {}
786 fn PassNullableSequence(&self, _: Option<Vec<i32>>) {}
787
788 fn PassOptionalBoolean(&self, _: Option<bool>) {}
789 fn PassOptionalByte(&self, _: Option<i8>) {}
790 fn PassOptionalOctet(&self, _: Option<u8>) {}
791 fn PassOptionalShort(&self, _: Option<i16>) {}
792 fn PassOptionalUnsignedShort(&self, _: Option<u16>) {}
793 fn PassOptionalLong(&self, _: Option<i32>) {}
794 fn PassOptionalUnsignedLong(&self, _: Option<u32>) {}
795 fn PassOptionalLongLong(&self, _: Option<i64>) {}
796 fn PassOptionalUnsignedLongLong(&self, _: Option<u64>) {}
797 fn PassOptionalUnrestrictedFloat(&self, _: Option<f32>) {}
798 fn PassOptionalFloat(&self, _: Option<Finite<f32>>) {}
799 fn PassOptionalUnrestrictedDouble(&self, _: Option<f64>) {}
800 fn PassOptionalDouble(&self, _: Option<Finite<f64>>) {}
801 fn PassOptionalString(&self, _: Option<DOMString>) {}
802 fn PassOptionalUsvstring(&self, _: Option<USVString>) {}
803 fn PassOptionalByteString(&self, _: Option<ByteString>) {}
804 fn PassOptionalEnum(&self, _: Option<TestEnum>) {}
805 fn PassOptionalInterface(&self, _: Option<&Blob>) {}
806 fn PassOptionalUnion(&self, _: Option<HTMLElementOrLong>) {}
807 fn PassOptionalUnion2(&self, _: Option<EventOrString>) {}
808 fn PassOptionalUnion3(&self, _: Option<StringOrLongSequence>) {}
809 fn PassOptionalUnion4(&self, _: Option<LongSequenceOrBoolean>) {}
810 fn PassOptionalUnion5(&self, _: Option<UnsignedLongOrBoolean>) {}
811 fn PassOptionalUnion6(&self, _: Option<ByteStringOrLong>) {}
812 fn PassOptionalAny(&self, _: SafeJSContext, _: HandleValue) {}
813 fn PassOptionalObject(&self, _: SafeJSContext, _: Option<*mut JSObject>) {}
814 fn PassOptionalCallbackFunction(&self, _: Option<Rc<Function>>) {}
815 fn PassOptionalCallbackInterface(&self, _: Option<Rc<EventListener>>) {}
816 fn PassOptionalSequence(&self, _: Option<Vec<i32>>) {}
817
818 fn PassOptionalNullableBoolean(&self, _: Option<Option<bool>>) {}
819 fn PassOptionalNullableByte(&self, _: Option<Option<i8>>) {}
820 fn PassOptionalNullableOctet(&self, _: Option<Option<u8>>) {}
821 fn PassOptionalNullableShort(&self, _: Option<Option<i16>>) {}
822 fn PassOptionalNullableUnsignedShort(&self, _: Option<Option<u16>>) {}
823 fn PassOptionalNullableLong(&self, _: Option<Option<i32>>) {}
824 fn PassOptionalNullableUnsignedLong(&self, _: Option<Option<u32>>) {}
825 fn PassOptionalNullableLongLong(&self, _: Option<Option<i64>>) {}
826 fn PassOptionalNullableUnsignedLongLong(&self, _: Option<Option<u64>>) {}
827 fn PassOptionalNullableUnrestrictedFloat(&self, _: Option<Option<f32>>) {}
828 fn PassOptionalNullableFloat(&self, _: Option<Option<Finite<f32>>>) {}
829 fn PassOptionalNullableUnrestrictedDouble(&self, _: Option<Option<f64>>) {}
830 fn PassOptionalNullableDouble(&self, _: Option<Option<Finite<f64>>>) {}
831 fn PassOptionalNullableString(&self, _: Option<Option<DOMString>>) {}
832 fn PassOptionalNullableUsvstring(&self, _: Option<Option<USVString>>) {}
833 fn PassOptionalNullableByteString(&self, _: Option<Option<ByteString>>) {}
834 fn PassOptionalNullableInterface(&self, _: Option<Option<&Blob>>) {}
836 fn PassOptionalNullableObject(&self, _: SafeJSContext, _: Option<*mut JSObject>) {}
837 fn PassOptionalNullableUnion(&self, _: Option<Option<HTMLElementOrLong>>) {}
838 fn PassOptionalNullableUnion2(&self, _: Option<Option<EventOrString>>) {}
839 fn PassOptionalNullableUnion3(&self, _: Option<Option<StringOrLongSequence>>) {}
840 fn PassOptionalNullableUnion4(&self, _: Option<Option<LongSequenceOrBoolean>>) {}
841 fn PassOptionalNullableUnion5(&self, _: Option<Option<UnsignedLongOrBoolean>>) {}
842 fn PassOptionalNullableUnion6(&self, _: Option<Option<ByteStringOrLong>>) {}
843 fn PassOptionalNullableCallbackFunction(&self, _: Option<Option<Rc<Function>>>) {}
844 fn PassOptionalNullableCallbackInterface(&self, _: Option<Option<Rc<EventListener>>>) {}
845 fn PassOptionalNullableSequence(&self, _: Option<Option<Vec<i32>>>) {}
846
847 fn PassOptionalBooleanWithDefault(&self, _: bool) {}
848 fn PassOptionalByteWithDefault(&self, _: i8) {}
849 fn PassOptionalOctetWithDefault(&self, _: u8) {}
850 fn PassOptionalShortWithDefault(&self, _: i16) {}
851 fn PassOptionalUnsignedShortWithDefault(&self, _: u16) {}
852 fn PassOptionalLongWithDefault(&self, _: i32) {}
853 fn PassOptionalUnsignedLongWithDefault(&self, _: u32) {}
854 fn PassOptionalLongLongWithDefault(&self, _: i64) {}
855 fn PassOptionalUnsignedLongLongWithDefault(&self, _: u64) {}
856 fn PassOptionalStringWithDefault(&self, _: DOMString) {}
857 fn PassOptionalUsvstringWithDefault(&self, _: USVString) {}
858 fn PassOptionalBytestringWithDefault(&self, _: ByteString) {}
859 fn PassOptionalEnumWithDefault(&self, _: TestEnum) {}
860 fn PassOptionalSequenceWithDefault(&self, _: Vec<i32>) {}
861
862 fn PassOptionalNullableBooleanWithDefault(&self, _: Option<bool>) {}
863 fn PassOptionalNullableByteWithDefault(&self, _: Option<i8>) {}
864 fn PassOptionalNullableOctetWithDefault(&self, _: Option<u8>) {}
865 fn PassOptionalNullableShortWithDefault(&self, _: Option<i16>) {}
866 fn PassOptionalNullableUnsignedShortWithDefault(&self, _: Option<u16>) {}
867 fn PassOptionalNullableLongWithDefault(&self, _: Option<i32>) {}
868 fn PassOptionalNullableUnsignedLongWithDefault(&self, _: Option<u32>) {}
869 fn PassOptionalNullableLongLongWithDefault(&self, _: Option<i64>) {}
870 fn PassOptionalNullableUnsignedLongLongWithDefault(&self, _: Option<u64>) {}
871 fn PassOptionalNullableStringWithDefault(&self, _: Option<DOMString>) {}
876 fn PassOptionalNullableUsvstringWithDefault(&self, _: Option<USVString>) {}
877 fn PassOptionalNullableByteStringWithDefault(&self, _: Option<ByteString>) {}
878 fn PassOptionalNullableInterfaceWithDefault(&self, _: Option<&Blob>) {}
880 fn PassOptionalNullableObjectWithDefault(&self, _: SafeJSContext, _: *mut JSObject) {}
881 fn PassOptionalNullableUnionWithDefault(&self, _: Option<HTMLElementOrLong>) {}
882 fn PassOptionalNullableUnion2WithDefault(&self, _: Option<EventOrString>) {}
883 fn PassOptionalNullableCallbackInterfaceWithDefault(&self, _: Option<Rc<EventListener>>) {}
885 fn PassOptionalAnyWithDefault(&self, _: SafeJSContext, _: HandleValue) {}
886
887 fn PassOptionalNullableBooleanWithNonNullDefault(&self, _: Option<bool>) {}
888 fn PassOptionalNullableByteWithNonNullDefault(&self, _: Option<i8>) {}
889 fn PassOptionalNullableOctetWithNonNullDefault(&self, _: Option<u8>) {}
890 fn PassOptionalNullableShortWithNonNullDefault(&self, _: Option<i16>) {}
891 fn PassOptionalNullableUnsignedShortWithNonNullDefault(&self, _: Option<u16>) {}
892 fn PassOptionalNullableLongWithNonNullDefault(&self, _: Option<i32>) {}
893 fn PassOptionalNullableUnsignedLongWithNonNullDefault(&self, _: Option<u32>) {}
894 fn PassOptionalNullableLongLongWithNonNullDefault(&self, _: Option<i64>) {}
895 fn PassOptionalNullableUnsignedLongLongWithNonNullDefault(&self, _: Option<u64>) {}
896 fn PassOptionalNullableStringWithNonNullDefault(&self, _: Option<DOMString>) {}
901 fn PassOptionalNullableUsvstringWithNonNullDefault(&self, _: Option<USVString>) {}
902 fn PassOptionalOverloaded(&self, a: &TestBinding, _: u32, _: u32) -> DomRoot<TestBinding> {
904 DomRoot::from_ref(a)
905 }
906 fn PassOptionalOverloaded_(&self, _: &Blob, _: u32) {}
907
908 fn PassVariadicBoolean(&self, _: Vec<bool>) {}
909 fn PassVariadicBooleanAndDefault(&self, _: bool, _: Vec<bool>) {}
910 fn PassVariadicByte(&self, _: Vec<i8>) {}
911 fn PassVariadicOctet(&self, _: Vec<u8>) {}
912 fn PassVariadicShort(&self, _: Vec<i16>) {}
913 fn PassVariadicUnsignedShort(&self, _: Vec<u16>) {}
914 fn PassVariadicLong(&self, _: Vec<i32>) {}
915 fn PassVariadicUnsignedLong(&self, _: Vec<u32>) {}
916 fn PassVariadicLongLong(&self, _: Vec<i64>) {}
917 fn PassVariadicUnsignedLongLong(&self, _: Vec<u64>) {}
918 fn PassVariadicUnrestrictedFloat(&self, _: Vec<f32>) {}
919 fn PassVariadicFloat(&self, _: Vec<Finite<f32>>) {}
920 fn PassVariadicUnrestrictedDouble(&self, _: Vec<f64>) {}
921 fn PassVariadicDouble(&self, _: Vec<Finite<f64>>) {}
922 fn PassVariadicString(&self, _: Vec<DOMString>) {}
923 fn PassVariadicUsvstring(&self, _: Vec<USVString>) {}
924 fn PassVariadicByteString(&self, _: Vec<ByteString>) {}
925 fn PassVariadicEnum(&self, _: Vec<TestEnum>) {}
926 fn PassVariadicInterface(&self, _: &[&Blob]) {}
927 fn PassVariadicUnion(&self, _: Vec<HTMLElementOrLong>) {}
928 fn PassVariadicUnion2(&self, _: Vec<EventOrString>) {}
929 fn PassVariadicUnion3(&self, _: Vec<BlobOrString>) {}
930 fn PassVariadicUnion4(&self, _: Vec<BlobOrBoolean>) {}
931 fn PassVariadicUnion5(&self, _: Vec<StringOrUnsignedLong>) {}
932 fn PassVariadicUnion6(&self, _: Vec<UnsignedLongOrBoolean>) {}
933 fn PassVariadicUnion7(&self, _: Vec<ByteStringOrLong>) {}
934 fn PassVariadicAny(&self, _: SafeJSContext, _: Vec<HandleValue>) {}
935 fn PassVariadicObject(&self, _: SafeJSContext, _: Vec<*mut JSObject>) {}
936 fn BooleanMozPreference(&self, pref_name: DOMString) -> bool {
937 prefs::get()
938 .get_value(&pref_name.str())
939 .try_into()
940 .unwrap_or(false)
941 }
942 fn StringMozPreference(&self, pref_name: DOMString) -> DOMString {
943 let string: String = prefs::get()
944 .get_value(&pref_name.str())
945 .try_into()
946 .unwrap_or_default();
947 string.into()
948 }
949 fn PrefControlledAttributeDisabled(&self) -> bool {
950 false
951 }
952 fn PrefControlledAttributeEnabled(&self) -> bool {
953 false
954 }
955 fn PrefControlledMethodDisabled(&self) {}
956 fn PrefControlledMethodEnabled(&self) {}
957 fn FuncControlledAttributeDisabled(&self) -> bool {
958 false
959 }
960 fn FuncControlledAttributeEnabled(&self) -> bool {
961 false
962 }
963 fn FuncControlledMethodDisabled(&self) {}
964 fn FuncControlledMethodEnabled(&self) {}
965
966 fn PassRecordPromise(&self, _: Record<DOMString, Rc<Promise>>) {}
967 fn PassRecord(&self, _: Record<DOMString, i32>) {}
968 fn PassRecordWithUSVStringKey(&self, _: Record<USVString, i32>) {}
969 fn PassRecordWithByteStringKey(&self, _: Record<ByteString, i32>) {}
970 fn PassNullableRecord(&self, _: Option<Record<DOMString, i32>>) {}
971 fn PassRecordOfNullableInts(&self, _: Record<DOMString, Option<i32>>) {}
972 fn PassOptionalRecordOfNullableInts(&self, _: Option<Record<DOMString, Option<i32>>>) {}
973 fn PassOptionalNullableRecordOfNullableInts(
974 &self,
975 _: Option<Option<Record<DOMString, Option<i32>>>>,
976 ) {
977 }
978 fn PassCastableObjectRecord(&self, _: Record<DOMString, DomRoot<TestBinding>>) {}
979 fn PassNullableCastableObjectRecord(&self, _: Record<DOMString, Option<DomRoot<TestBinding>>>) {
980 }
981 fn PassCastableObjectNullableRecord(&self, _: Option<Record<DOMString, DomRoot<TestBinding>>>) {
982 }
983 fn PassNullableCastableObjectNullableRecord(
984 &self,
985 _: Option<Record<DOMString, Option<DomRoot<TestBinding>>>>,
986 ) {
987 }
988 fn PassOptionalRecord(&self, _: Option<Record<DOMString, i32>>) {}
989 fn PassOptionalNullableRecord(&self, _: Option<Option<Record<DOMString, i32>>>) {}
990 fn PassOptionalNullableRecordWithDefaultValue(&self, _: Option<Record<DOMString, i32>>) {}
991 fn PassOptionalObjectRecord(&self, _: Option<Record<DOMString, DomRoot<TestBinding>>>) {}
992 fn PassStringRecord(&self, _: Record<DOMString, DOMString>) {}
993 fn PassByteStringRecord(&self, _: Record<DOMString, ByteString>) {}
994 fn PassRecordOfRecords(&self, _: Record<DOMString, Record<DOMString, i32>>) {}
995 fn PassRecordUnion(&self, _: UnionTypes::LongOrStringByteStringRecord) {}
996 fn PassRecordUnion2(&self, _: UnionTypes::TestBindingOrStringByteStringRecord) {}
997 fn PassRecordUnion3(
998 &self,
999 _: UnionTypes::TestBindingOrByteStringSequenceSequenceOrStringByteStringRecord,
1000 ) {
1001 }
1002 fn ReceiveRecord(&self) -> Record<DOMString, i32> {
1003 Record::new()
1004 }
1005 fn ReceiveRecordWithUSVStringKey(&self) -> Record<USVString, i32> {
1006 Record::new()
1007 }
1008 fn ReceiveRecordWithByteStringKey(&self) -> Record<ByteString, i32> {
1009 Record::new()
1010 }
1011 fn ReceiveNullableRecord(&self) -> Option<Record<DOMString, i32>> {
1012 Some(Record::new())
1013 }
1014 fn ReceiveRecordOfNullableInts(&self) -> Record<DOMString, Option<i32>> {
1015 Record::new()
1016 }
1017 fn ReceiveNullableRecordOfNullableInts(&self) -> Option<Record<DOMString, Option<i32>>> {
1018 Some(Record::new())
1019 }
1020 fn ReceiveRecordOfRecords(&self) -> Record<DOMString, Record<DOMString, i32>> {
1021 Record::new()
1022 }
1023 fn ReceiveAnyRecord(&self) -> Record<DOMString, JSVal> {
1024 Record::new()
1025 }
1026
1027 fn ReturnResolvedPromise(&self, cx: SafeJSContext, v: HandleValue) -> Rc<Promise> {
1028 Promise::new_resolved(&self.global(), cx, v, CanGc::note())
1029 }
1030
1031 fn ReturnRejectedPromise(&self, cx: SafeJSContext, v: HandleValue) -> Rc<Promise> {
1032 Promise::new_rejected(&self.global(), cx, v, CanGc::note())
1033 }
1034
1035 fn PromiseResolveNative(&self, cx: SafeJSContext, p: &Promise, v: HandleValue, can_gc: CanGc) {
1036 p.resolve(cx, v, can_gc);
1037 }
1038
1039 fn PromiseRejectNative(&self, cx: SafeJSContext, p: &Promise, v: HandleValue, can_gc: CanGc) {
1040 p.reject(cx, v, can_gc);
1041 }
1042
1043 fn PromiseRejectWithTypeError(&self, p: &Promise, s: USVString, can_gc: CanGc) {
1044 p.reject_error(Error::Type(cformat!("{}", s.0)), can_gc);
1045 }
1046
1047 fn ResolvePromiseDelayed(&self, p: &Promise, value: DOMString, delay: u64) {
1048 let promise = p.duplicate();
1049 let cb = TestBindingCallback {
1050 promise: TrustedPromise::new(promise),
1051 value,
1052 };
1053 let _ = self.global().schedule_callback(
1054 OneshotTimerCallback::TestBindingCallback(cb),
1055 Duration::from_millis(delay),
1056 );
1057 }
1058
1059 fn PromiseNativeHandler(
1060 &self,
1061 resolve: Option<Rc<SimpleCallback>>,
1062 reject: Option<Rc<SimpleCallback>>,
1063 comp: InRealm,
1064 can_gc: CanGc,
1065 ) -> Rc<Promise> {
1066 let global = self.global();
1067 let handler = PromiseNativeHandler::new(
1068 &global,
1069 resolve.map(SimpleHandler::new_boxed),
1070 reject.map(SimpleHandler::new_boxed),
1071 can_gc,
1072 );
1073 let p = Promise::new_in_current_realm(comp, can_gc);
1074 p.append_native_handler(&handler, comp, can_gc);
1075 return p;
1076
1077 #[derive(JSTraceable, MallocSizeOf)]
1078 struct SimpleHandler {
1079 #[conditional_malloc_size_of]
1080 handler: Rc<SimpleCallback>,
1081 }
1082 impl SimpleHandler {
1083 fn new_boxed(callback: Rc<SimpleCallback>) -> Box<dyn Callback> {
1084 Box::new(SimpleHandler { handler: callback })
1085 }
1086 }
1087 impl Callback for SimpleHandler {
1088 fn callback(&self, cx: &mut CurrentRealm, v: HandleValue) {
1089 let can_gc = CanGc::from_cx(cx);
1090 let global = GlobalScope::from_current_realm(cx);
1091 let _ = self
1092 .handler
1093 .Call_(&*global, v, ExceptionHandling::Report, can_gc);
1094 }
1095 }
1096 }
1097
1098 fn PromiseAttribute(&self, comp: InRealm, can_gc: CanGc) -> Rc<Promise> {
1099 Promise::new_in_current_realm(comp, can_gc)
1100 }
1101
1102 fn AcceptPromise(&self, _promise: &Promise) {}
1103
1104 fn PassSequenceSequence(&self, _seq: Vec<Vec<i32>>) {}
1105 fn ReturnSequenceSequence(&self) -> Vec<Vec<i32>> {
1106 vec![]
1107 }
1108 fn PassUnionSequenceSequence(&self, seq: LongOrLongSequenceSequence) {
1109 match seq {
1110 LongOrLongSequenceSequence::Long(_) => (),
1111 LongOrLongSequenceSequence::LongSequenceSequence(seq) => {
1112 let _seq: Vec<Vec<i32>> = seq;
1113 },
1114 }
1115 }
1116
1117 fn EntryGlobal(&self) -> DomRoot<GlobalScope> {
1118 GlobalScope::entry()
1119 }
1120 fn IncumbentGlobal(&self) -> DomRoot<GlobalScope> {
1121 GlobalScope::incumbent().unwrap()
1122 }
1123
1124 fn SemiExposedBoolFromInterface(&self) -> bool {
1125 true
1126 }
1127
1128 fn BoolFromSemiExposedPartialInterface(&self) -> bool {
1129 true
1130 }
1131
1132 fn SemiExposedBoolFromPartialInterface(&self) -> bool {
1133 true
1134 }
1135
1136 fn GetDictionaryWithParent(&self, s1: DOMString, s2: DOMString) -> TestDictionaryWithParent {
1137 TestDictionaryWithParent {
1138 parent: TestDictionaryParent {
1139 parentStringMember: Some(s1),
1140 },
1141 stringMember: Some(s2),
1142 }
1143 }
1144
1145 fn MethodThrowToRejectPromise(&self) -> Fallible<Rc<Promise>> {
1146 Err(Error::Type(c"test".to_owned()))
1147 }
1148
1149 fn GetGetterThrowToRejectPromise(&self) -> Fallible<Rc<Promise>> {
1150 Err(Error::Type(c"test".to_owned()))
1151 }
1152
1153 fn MethodInternalThrowToRejectPromise(&self, _arg: u64) -> Rc<Promise> {
1154 unreachable!("Method should already throw")
1155 }
1156
1157 fn StaticThrowToRejectPromise(_: &GlobalScope) -> Fallible<Rc<Promise>> {
1158 Err(Error::Type(c"test".to_owned()))
1159 }
1160
1161 fn StaticInternalThrowToRejectPromise(_: &GlobalScope, _arg: u64) -> Rc<Promise> {
1162 unreachable!("Method should already throw")
1163 }
1164
1165 fn BooleanAttributeStatic(_: &GlobalScope) -> bool {
1166 false
1167 }
1168 fn SetBooleanAttributeStatic(_: &GlobalScope, _: bool) {}
1169 fn ReceiveVoidStatic(_: &GlobalScope) {}
1170 fn PrefControlledStaticAttributeDisabled(_: &GlobalScope) -> bool {
1171 false
1172 }
1173 fn PrefControlledStaticAttributeEnabled(_: &GlobalScope) -> bool {
1174 false
1175 }
1176 fn PrefControlledStaticMethodDisabled(_: &GlobalScope) {}
1177 fn PrefControlledStaticMethodEnabled(_: &GlobalScope) {}
1178 fn FuncControlledStaticAttributeDisabled(_: &GlobalScope) -> bool {
1179 false
1180 }
1181 fn FuncControlledStaticAttributeEnabled(_: &GlobalScope) -> bool {
1182 false
1183 }
1184 fn FuncControlledStaticMethodDisabled(_: &GlobalScope) {}
1185 fn FuncControlledStaticMethodEnabled(_: &GlobalScope) {}
1186}
1187
1188impl TestBinding {
1189 pub(crate) fn condition_satisfied(_: SafeJSContext, _: HandleObject) -> bool {
1190 true
1191 }
1192 pub(crate) fn condition_unsatisfied(_: SafeJSContext, _: HandleObject) -> bool {
1193 false
1194 }
1195}
1196
1197#[derive(JSTraceable, MallocSizeOf)]
1198pub(crate) struct TestBindingCallback {
1199 #[ignore_malloc_size_of = "unclear ownership semantics"]
1200 promise: TrustedPromise,
1201 value: DOMString,
1202}
1203
1204impl TestBindingCallback {
1205 pub(crate) fn invoke(self) {
1206 self.promise
1207 .root()
1208 .resolve_native(&self.value, CanGc::note());
1209 }
1210}
1211
1212impl TestBindingHelpers for TestBinding {
1213 fn condition_satisfied(cx: SafeJSContext, global: HandleObject) -> bool {
1214 Self::condition_satisfied(cx, global)
1215 }
1216 fn condition_unsatisfied(cx: SafeJSContext, global: HandleObject) -> bool {
1217 Self::condition_unsatisfied(cx, global)
1218 }
1219}