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