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