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