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