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