/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ // check-tidy: no specs after this line use std::borrow::ToOwned; use std::ptr::{self, NonNull}; use std::rc::Rc; use dom_struct::dom_struct; use js::jsapi::{Heap, JSObject, JS_NewPlainObject}; use js::jsval::{JSVal, NullValue}; use js::rust::{CustomAutoRooterGuard, HandleObject, HandleValue}; use js::typedarray::{self, Uint8ClampedArray}; use script_traits::serializable::BlobImpl; use script_traits::MsDuration; use servo_config::prefs; use crate::dom::bindings::buffer_source::create_buffer_source; use crate::dom::bindings::callback::ExceptionHandling; use crate::dom::bindings::codegen::Bindings::EventListenerBinding::EventListener; use crate::dom::bindings::codegen::Bindings::FunctionBinding::Function; use crate::dom::bindings::codegen::Bindings::TestBindingBinding::{ SimpleCallback, TestBindingMethods, TestDictionary, TestDictionaryDefaults, TestDictionaryParent, TestDictionaryWithParent, TestEnum, TestURLLike, }; use crate::dom::bindings::codegen::UnionTypes; use crate::dom::bindings::codegen::UnionTypes::{ BlobOrBlobSequence, BlobOrBoolean, BlobOrString, BlobOrUnsignedLong, ByteStringOrLong, ByteStringSequenceOrLong, ByteStringSequenceOrLongOrString, EventOrString, EventOrUSVString, HTMLElementOrLong, HTMLElementOrUnsignedLongOrStringOrBoolean, LongOrLongSequenceSequence, LongSequenceOrBoolean, StringOrBoolean, StringOrLongSequence, StringOrStringSequence, StringOrUnsignedLong, StringSequenceOrUnsignedLong, UnsignedLongOrBoolean, }; use crate::dom::bindings::error::{Error, Fallible}; use crate::dom::bindings::num::Finite; use crate::dom::bindings::record::Record; use crate::dom::bindings::refcounted::TrustedPromise; use crate::dom::bindings::reflector::{reflect_dom_object_with_proto, DomObject, Reflector}; use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::str::{ByteString, DOMString, USVString}; use crate::dom::bindings::trace::RootedTraceableBox; use crate::dom::bindings::weakref::MutableWeakRef; use crate::dom::blob::Blob; use crate::dom::globalscope::GlobalScope; use crate::dom::node::Node; use crate::dom::promise::Promise; use crate::dom::promisenativehandler::{Callback, PromiseNativeHandler}; use crate::dom::url::URL; use crate::realms::InRealm; use crate::script_runtime::JSContext as SafeJSContext; use crate::timers::OneshotTimerCallback; #[dom_struct] pub struct TestBinding { reflector_: Reflector, url: MutableWeakRef, } #[allow(non_snake_case)] impl TestBinding { fn new_inherited() -> TestBinding { TestBinding { reflector_: Reflector::new(), url: MutableWeakRef::new(None), } } fn new(global: &GlobalScope, proto: Option) -> DomRoot { reflect_dom_object_with_proto(Box::new(TestBinding::new_inherited()), global, proto) } pub fn Constructor( global: &GlobalScope, proto: Option, ) -> Fallible> { Ok(TestBinding::new(global, proto)) } #[allow(unused_variables)] pub fn Constructor_( global: &GlobalScope, proto: Option, nums: Vec, ) -> Fallible> { Ok(TestBinding::new(global, proto)) } #[allow(unused_variables)] pub fn Constructor__( global: &GlobalScope, proto: Option, num: f64, ) -> Fallible> { Ok(TestBinding::new(global, proto)) } } impl TestBindingMethods for TestBinding { fn BooleanAttribute(&self) -> bool { false } fn SetBooleanAttribute(&self, _: bool) {} fn ByteAttribute(&self) -> i8 { 0 } fn SetByteAttribute(&self, _: i8) {} fn OctetAttribute(&self) -> u8 { 0 } fn SetOctetAttribute(&self, _: u8) {} fn ShortAttribute(&self) -> i16 { 0 } fn SetShortAttribute(&self, _: i16) {} fn UnsignedShortAttribute(&self) -> u16 { 0 } fn SetUnsignedShortAttribute(&self, _: u16) {} fn LongAttribute(&self) -> i32 { 0 } fn SetLongAttribute(&self, _: i32) {} fn UnsignedLongAttribute(&self) -> u32 { 0 } fn SetUnsignedLongAttribute(&self, _: u32) {} fn LongLongAttribute(&self) -> i64 { 0 } fn SetLongLongAttribute(&self, _: i64) {} fn UnsignedLongLongAttribute(&self) -> u64 { 0 } fn SetUnsignedLongLongAttribute(&self, _: u64) {} fn UnrestrictedFloatAttribute(&self) -> f32 { 0. } fn SetUnrestrictedFloatAttribute(&self, _: f32) {} fn FloatAttribute(&self) -> Finite { Finite::wrap(0.) } fn SetFloatAttribute(&self, _: Finite) {} fn UnrestrictedDoubleAttribute(&self) -> f64 { 0. } fn SetUnrestrictedDoubleAttribute(&self, _: f64) {} fn DoubleAttribute(&self) -> Finite { Finite::wrap(0.) } fn SetDoubleAttribute(&self, _: Finite) {} fn StringAttribute(&self) -> DOMString { DOMString::new() } fn SetStringAttribute(&self, _: DOMString) {} fn UsvstringAttribute(&self) -> USVString { USVString("".to_owned()) } fn SetUsvstringAttribute(&self, _: USVString) {} fn ByteStringAttribute(&self) -> ByteString { ByteString::new(vec![]) } fn SetByteStringAttribute(&self, _: ByteString) {} fn EnumAttribute(&self) -> TestEnum { TestEnum::_empty } fn SetEnumAttribute(&self, _: TestEnum) {} fn InterfaceAttribute(&self) -> DomRoot { Blob::new( &self.global(), BlobImpl::new_from_bytes(vec![], "".to_owned()), ) } fn SetInterfaceAttribute(&self, _: &Blob) {} fn UnionAttribute(&self) -> HTMLElementOrLong { HTMLElementOrLong::Long(0) } fn SetUnionAttribute(&self, _: HTMLElementOrLong) {} fn Union2Attribute(&self) -> EventOrString { EventOrString::String(DOMString::new()) } fn SetUnion2Attribute(&self, _: EventOrString) {} fn Union3Attribute(&self) -> EventOrUSVString { EventOrUSVString::USVString(USVString("".to_owned())) } fn SetUnion3Attribute(&self, _: EventOrUSVString) {} fn Union4Attribute(&self) -> StringOrUnsignedLong { StringOrUnsignedLong::UnsignedLong(0u32) } fn SetUnion4Attribute(&self, _: StringOrUnsignedLong) {} fn Union5Attribute(&self) -> StringOrBoolean { StringOrBoolean::Boolean(true) } fn SetUnion5Attribute(&self, _: StringOrBoolean) {} fn Union6Attribute(&self) -> UnsignedLongOrBoolean { UnsignedLongOrBoolean::Boolean(true) } fn SetUnion6Attribute(&self, _: UnsignedLongOrBoolean) {} fn Union7Attribute(&self) -> BlobOrBoolean { BlobOrBoolean::Boolean(true) } fn SetUnion7Attribute(&self, _: BlobOrBoolean) {} fn Union8Attribute(&self) -> BlobOrUnsignedLong { BlobOrUnsignedLong::UnsignedLong(0u32) } fn SetUnion8Attribute(&self, _: BlobOrUnsignedLong) {} fn Union9Attribute(&self) -> ByteStringOrLong { ByteStringOrLong::ByteString(ByteString::new(vec![])) } fn SetUnion9Attribute(&self, _: ByteStringOrLong) {} fn ArrayAttribute(&self, cx: SafeJSContext) -> Uint8ClampedArray { let data: [u8; 16] = [0; 16]; rooted!(in (*cx) let mut array = ptr::null_mut::()); create_buffer_source(cx, &data, array.handle_mut()) .expect("Creating ClampedU8 array should never fail") } fn AnyAttribute(&self, _: SafeJSContext) -> JSVal { NullValue() } fn SetAnyAttribute(&self, _: SafeJSContext, _: HandleValue) {} #[allow(unsafe_code)] fn ObjectAttribute(&self, cx: SafeJSContext) -> NonNull { unsafe { rooted!(in(*cx) let obj = JS_NewPlainObject(*cx)); NonNull::new(obj.get()).expect("got a null pointer") } } fn SetObjectAttribute(&self, _: SafeJSContext, _: *mut JSObject) {} fn GetBooleanAttributeNullable(&self) -> Option { Some(false) } fn SetBooleanAttributeNullable(&self, _: Option) {} fn GetByteAttributeNullable(&self) -> Option { Some(0) } fn SetByteAttributeNullable(&self, _: Option) {} fn GetOctetAttributeNullable(&self) -> Option { Some(0) } fn SetOctetAttributeNullable(&self, _: Option) {} fn GetShortAttributeNullable(&self) -> Option { Some(0) } fn SetShortAttributeNullable(&self, _: Option) {} fn GetUnsignedShortAttributeNullable(&self) -> Option { Some(0) } fn SetUnsignedShortAttributeNullable(&self, _: Option) {} fn GetLongAttributeNullable(&self) -> Option { Some(0) } fn SetLongAttributeNullable(&self, _: Option) {} fn GetUnsignedLongAttributeNullable(&self) -> Option { Some(0) } fn SetUnsignedLongAttributeNullable(&self, _: Option) {} fn GetLongLongAttributeNullable(&self) -> Option { Some(0) } fn SetLongLongAttributeNullable(&self, _: Option) {} fn GetUnsignedLongLongAttributeNullable(&self) -> Option { Some(0) } fn SetUnsignedLongLongAttributeNullable(&self, _: Option) {} fn GetUnrestrictedFloatAttributeNullable(&self) -> Option { Some(0.) } fn SetUnrestrictedFloatAttributeNullable(&self, _: Option) {} fn GetFloatAttributeNullable(&self) -> Option> { Some(Finite::wrap(0.)) } fn SetFloatAttributeNullable(&self, _: Option>) {} fn GetUnrestrictedDoubleAttributeNullable(&self) -> Option { Some(0.) } fn SetUnrestrictedDoubleAttributeNullable(&self, _: Option) {} fn GetDoubleAttributeNullable(&self) -> Option> { Some(Finite::wrap(0.)) } fn SetDoubleAttributeNullable(&self, _: Option>) {} fn GetByteStringAttributeNullable(&self) -> Option { Some(ByteString::new(vec![])) } fn SetByteStringAttributeNullable(&self, _: Option) {} fn GetStringAttributeNullable(&self) -> Option { Some(DOMString::new()) } fn SetStringAttributeNullable(&self, _: Option) {} fn GetUsvstringAttributeNullable(&self) -> Option { Some(USVString("".to_owned())) } fn SetUsvstringAttributeNullable(&self, _: Option) {} fn SetBinaryRenamedAttribute(&self, _: DOMString) {} fn ForwardedAttribute(&self) -> DomRoot { DomRoot::from_ref(self) } fn BinaryRenamedAttribute(&self) -> DOMString { DOMString::new() } fn SetBinaryRenamedAttribute2(&self, _: DOMString) {} fn BinaryRenamedAttribute2(&self) -> DOMString { DOMString::new() } fn Attr_to_automatically_rename(&self) -> DOMString { DOMString::new() } fn SetAttr_to_automatically_rename(&self, _: DOMString) {} fn GetEnumAttributeNullable(&self) -> Option { Some(TestEnum::_empty) } fn GetInterfaceAttributeNullable(&self) -> Option> { Some(Blob::new( &self.global(), BlobImpl::new_from_bytes(vec![], "".to_owned()), )) } fn SetInterfaceAttributeNullable(&self, _: Option<&Blob>) {} fn GetInterfaceAttributeWeak(&self) -> Option> { self.url.root() } fn SetInterfaceAttributeWeak(&self, url: Option<&URL>) { self.url.set(url); } fn GetObjectAttributeNullable(&self, _: SafeJSContext) -> Option> { None } fn SetObjectAttributeNullable(&self, _: SafeJSContext, _: *mut JSObject) {} fn GetUnionAttributeNullable(&self) -> Option { Some(HTMLElementOrLong::Long(0)) } fn SetUnionAttributeNullable(&self, _: Option) {} fn GetUnion2AttributeNullable(&self) -> Option { Some(EventOrString::String(DOMString::new())) } fn SetUnion2AttributeNullable(&self, _: Option) {} fn GetUnion3AttributeNullable(&self) -> Option { Some(BlobOrBoolean::Boolean(true)) } fn SetUnion3AttributeNullable(&self, _: Option) {} fn GetUnion4AttributeNullable(&self) -> Option { Some(UnsignedLongOrBoolean::Boolean(true)) } fn SetUnion4AttributeNullable(&self, _: Option) {} fn GetUnion5AttributeNullable(&self) -> Option { Some(StringOrBoolean::Boolean(true)) } fn SetUnion5AttributeNullable(&self, _: Option) {} fn GetUnion6AttributeNullable(&self) -> Option { Some(ByteStringOrLong::ByteString(ByteString::new(vec![]))) } fn SetUnion6AttributeNullable(&self, _: Option) {} fn BinaryRenamedMethod(&self) {} fn ReceiveVoid(&self) {} fn ReceiveBoolean(&self) -> bool { false } fn ReceiveByte(&self) -> i8 { 0 } fn ReceiveOctet(&self) -> u8 { 0 } fn ReceiveShort(&self) -> i16 { 0 } fn ReceiveUnsignedShort(&self) -> u16 { 0 } fn ReceiveLong(&self) -> i32 { 0 } fn ReceiveUnsignedLong(&self) -> u32 { 0 } fn ReceiveLongLong(&self) -> i64 { 0 } fn ReceiveUnsignedLongLong(&self) -> u64 { 0 } fn ReceiveUnrestrictedFloat(&self) -> f32 { 0. } fn ReceiveFloat(&self) -> Finite { Finite::wrap(0.) } fn ReceiveUnrestrictedDouble(&self) -> f64 { 0. } fn ReceiveDouble(&self) -> Finite { Finite::wrap(0.) } fn ReceiveString(&self) -> DOMString { DOMString::new() } fn ReceiveUsvstring(&self) -> USVString { USVString("".to_owned()) } fn ReceiveByteString(&self) -> ByteString { ByteString::new(vec![]) } fn ReceiveEnum(&self) -> TestEnum { TestEnum::_empty } fn ReceiveInterface(&self) -> DomRoot { Blob::new( &self.global(), BlobImpl::new_from_bytes(vec![], "".to_owned()), ) } fn ReceiveAny(&self, _: SafeJSContext) -> JSVal { NullValue() } fn ReceiveObject(&self, cx: SafeJSContext) -> NonNull { self.ObjectAttribute(cx) } fn ReceiveUnion(&self) -> HTMLElementOrLong { HTMLElementOrLong::Long(0) } fn ReceiveUnion2(&self) -> EventOrString { EventOrString::String(DOMString::new()) } fn ReceiveUnion3(&self) -> StringOrLongSequence { StringOrLongSequence::LongSequence(vec![]) } fn ReceiveUnion4(&self) -> StringOrStringSequence { StringOrStringSequence::StringSequence(vec![]) } fn ReceiveUnion5(&self) -> BlobOrBlobSequence { BlobOrBlobSequence::BlobSequence(vec![]) } fn ReceiveUnion6(&self) -> StringOrUnsignedLong { StringOrUnsignedLong::String(DOMString::new()) } fn ReceiveUnion7(&self) -> StringOrBoolean { StringOrBoolean::Boolean(true) } fn ReceiveUnion8(&self) -> UnsignedLongOrBoolean { UnsignedLongOrBoolean::UnsignedLong(0u32) } fn ReceiveUnion9(&self) -> HTMLElementOrUnsignedLongOrStringOrBoolean { HTMLElementOrUnsignedLongOrStringOrBoolean::Boolean(true) } fn ReceiveUnion10(&self) -> ByteStringOrLong { ByteStringOrLong::ByteString(ByteString::new(vec![])) } fn ReceiveUnion11(&self) -> ByteStringSequenceOrLongOrString { ByteStringSequenceOrLongOrString::ByteStringSequence(vec![ByteString::new(vec![])]) } fn ReceiveSequence(&self) -> Vec { vec![1] } fn ReceiveInterfaceSequence(&self) -> Vec> { vec![Blob::new( &self.global(), BlobImpl::new_from_bytes(vec![], "".to_owned()), )] } fn ReceiveUnionIdentity( &self, _: SafeJSContext, arg: UnionTypes::StringOrObject, ) -> UnionTypes::StringOrObject { arg } fn ReceiveNullableBoolean(&self) -> Option { Some(false) } fn ReceiveNullableByte(&self) -> Option { Some(0) } fn ReceiveNullableOctet(&self) -> Option { Some(0) } fn ReceiveNullableShort(&self) -> Option { Some(0) } fn ReceiveNullableUnsignedShort(&self) -> Option { Some(0) } fn ReceiveNullableLong(&self) -> Option { Some(0) } fn ReceiveNullableUnsignedLong(&self) -> Option { Some(0) } fn ReceiveNullableLongLong(&self) -> Option { Some(0) } fn ReceiveNullableUnsignedLongLong(&self) -> Option { Some(0) } fn ReceiveNullableUnrestrictedFloat(&self) -> Option { Some(0.) } fn ReceiveNullableFloat(&self) -> Option> { Some(Finite::wrap(0.)) } fn ReceiveNullableUnrestrictedDouble(&self) -> Option { Some(0.) } fn ReceiveNullableDouble(&self) -> Option> { Some(Finite::wrap(0.)) } fn ReceiveNullableString(&self) -> Option { Some(DOMString::new()) } fn ReceiveNullableUsvstring(&self) -> Option { Some(USVString("".to_owned())) } fn ReceiveNullableByteString(&self) -> Option { Some(ByteString::new(vec![])) } fn ReceiveNullableEnum(&self) -> Option { Some(TestEnum::_empty) } fn ReceiveNullableInterface(&self) -> Option> { Some(Blob::new( &self.global(), BlobImpl::new_from_bytes(vec![], "".to_owned()), )) } fn ReceiveNullableObject(&self, cx: SafeJSContext) -> Option> { self.GetObjectAttributeNullable(cx) } fn ReceiveNullableUnion(&self) -> Option { Some(HTMLElementOrLong::Long(0)) } fn ReceiveNullableUnion2(&self) -> Option { Some(EventOrString::String(DOMString::new())) } fn ReceiveNullableUnion3(&self) -> Option { Some(StringOrLongSequence::String(DOMString::new())) } fn ReceiveNullableUnion4(&self) -> Option { Some(LongSequenceOrBoolean::Boolean(true)) } fn ReceiveNullableUnion5(&self) -> Option { Some(UnsignedLongOrBoolean::UnsignedLong(0u32)) } fn ReceiveNullableUnion6(&self) -> Option { Some(ByteStringOrLong::ByteString(ByteString::new(vec![]))) } fn ReceiveNullableSequence(&self) -> Option> { Some(vec![1]) } fn ReceiveTestDictionaryWithSuccessOnKeyword(&self) -> RootedTraceableBox { RootedTraceableBox::new(TestDictionary { anyValue: RootedTraceableBox::new(Heap::default()), booleanValue: None, byteValue: None, dict: RootedTraceableBox::new(TestDictionaryDefaults { UnrestrictedDoubleValue: 0.0, anyValue: RootedTraceableBox::new(Heap::default()), arrayValue: Vec::new(), booleanValue: false, bytestringValue: ByteString::new(vec![]), byteValue: 0, doubleValue: Finite::new(1.0).unwrap(), enumValue: TestEnum::Foo, floatValue: Finite::new(1.0).unwrap(), longLongValue: 54, longValue: 12, nullableBooleanValue: None, nullableBytestringValue: None, nullableByteValue: None, nullableDoubleValue: None, nullableFloatValue: None, nullableLongLongValue: None, nullableLongValue: None, nullableObjectValue: RootedTraceableBox::new(Heap::default()), nullableOctetValue: None, nullableShortValue: None, nullableStringValue: None, nullableUnrestrictedDoubleValue: None, nullableUnrestrictedFloatValue: None, nullableUnsignedLongLongValue: None, nullableUnsignedLongValue: None, nullableUnsignedShortValue: None, nullableUsvstringValue: None, octetValue: 0, shortValue: 0, stringValue: DOMString::new(), unrestrictedFloatValue: 0.0, unsignedLongLongValue: 0, unsignedLongValue: 0, unsignedShortValue: 0, usvstringValue: USVString("".to_owned()), }), doubleValue: None, enumValue: None, floatValue: None, interfaceValue: None, longLongValue: None, longValue: None, objectValue: None, octetValue: None, requiredValue: true, seqDict: None, elementSequence: None, shortValue: None, stringValue: None, type_: Some(DOMString::from("success")), unrestrictedDoubleValue: None, unrestrictedFloatValue: None, unsignedLongLongValue: None, unsignedLongValue: None, unsignedShortValue: None, usvstringValue: None, nonRequiredNullable: None, nonRequiredNullable2: Some(None), noCallbackImport: None, noCallbackImport2: None, }) } fn DictMatchesPassedValues(&self, arg: RootedTraceableBox) -> bool { arg.type_.as_ref().map(|s| s == "success").unwrap_or(false) && arg.nonRequiredNullable.is_none() && arg.nonRequiredNullable2 == Some(None) && arg.noCallbackImport == None && arg.noCallbackImport2 == None } fn PassBoolean(&self, _: bool) {} fn PassByte(&self, _: i8) {} fn PassOctet(&self, _: u8) {} fn PassShort(&self, _: i16) {} fn PassUnsignedShort(&self, _: u16) {} fn PassLong(&self, _: i32) {} fn PassUnsignedLong(&self, _: u32) {} fn PassLongLong(&self, _: i64) {} fn PassUnsignedLongLong(&self, _: u64) {} fn PassUnrestrictedFloat(&self, _: f32) {} fn PassFloat(&self, _: Finite) {} fn PassUnrestrictedDouble(&self, _: f64) {} fn PassDouble(&self, _: Finite) {} fn PassString(&self, _: DOMString) {} fn PassUsvstring(&self, _: USVString) {} fn PassByteString(&self, _: ByteString) {} fn PassEnum(&self, _: TestEnum) {} fn PassInterface(&self, _: &Blob) {} fn PassTypedArray(&self, _: CustomAutoRooterGuard) {} fn PassTypedArray2(&self, _: CustomAutoRooterGuard) {} fn PassTypedArray3(&self, _: CustomAutoRooterGuard) {} fn PassUnion(&self, _: HTMLElementOrLong) {} fn PassUnion2(&self, _: EventOrString) {} fn PassUnion3(&self, _: BlobOrString) {} fn PassUnion4(&self, _: StringOrStringSequence) {} fn PassUnion5(&self, _: StringOrBoolean) {} fn PassUnion6(&self, _: UnsignedLongOrBoolean) {} fn PassUnion7(&self, _: StringSequenceOrUnsignedLong) {} fn PassUnion8(&self, _: ByteStringSequenceOrLong) {} fn PassUnion9(&self, _: UnionTypes::TestDictionaryOrLong) {} fn PassUnion10(&self, _: SafeJSContext, _: UnionTypes::StringOrObject) {} fn PassUnion11(&self, _: UnionTypes::ArrayBufferOrArrayBufferView) {} fn PassUnionWithTypedef(&self, _: UnionTypes::DocumentOrStringOrURLOrBlob) {} fn PassUnionWithTypedef2(&self, _: UnionTypes::LongSequenceOrStringOrURLOrBlob) {} fn PassAny(&self, _: SafeJSContext, _: HandleValue) {} fn PassObject(&self, _: SafeJSContext, _: *mut JSObject) {} fn PassCallbackFunction(&self, _: Rc) {} fn PassCallbackInterface(&self, _: Rc) {} fn PassSequence(&self, _: Vec) {} fn PassAnySequence(&self, _: SafeJSContext, _: CustomAutoRooterGuard>) {} fn AnySequencePassthrough( &self, _: SafeJSContext, seq: CustomAutoRooterGuard>, ) -> Vec { (*seq).clone() } fn PassObjectSequence(&self, _: SafeJSContext, _: CustomAutoRooterGuard>) {} fn PassStringSequence(&self, _: Vec) {} fn PassInterfaceSequence(&self, _: Vec>) {} fn PassOverloaded(&self, _: CustomAutoRooterGuard) {} fn PassOverloaded_(&self, _: DOMString) {} fn PassOverloadedDict(&self, _: &Node) -> DOMString { "node".into() } fn PassOverloadedDict_(&self, u: &TestURLLike) -> DOMString { u.href.clone() } fn PassNullableBoolean(&self, _: Option) {} fn PassNullableByte(&self, _: Option) {} fn PassNullableOctet(&self, _: Option) {} fn PassNullableShort(&self, _: Option) {} fn PassNullableUnsignedShort(&self, _: Option) {} fn PassNullableLong(&self, _: Option) {} fn PassNullableUnsignedLong(&self, _: Option) {} fn PassNullableLongLong(&self, _: Option) {} fn PassNullableUnsignedLongLong(&self, _: Option) {} fn PassNullableUnrestrictedFloat(&self, _: Option) {} fn PassNullableFloat(&self, _: Option>) {} fn PassNullableUnrestrictedDouble(&self, _: Option) {} fn PassNullableDouble(&self, _: Option>) {} fn PassNullableString(&self, _: Option) {} fn PassNullableUsvstring(&self, _: Option) {} fn PassNullableByteString(&self, _: Option) {} // fn PassNullableEnum(self, _: Option) {} fn PassNullableInterface(&self, _: Option<&Blob>) {} fn PassNullableObject(&self, _: SafeJSContext, _: *mut JSObject) {} fn PassNullableTypedArray(&self, _: CustomAutoRooterGuard>) {} fn PassNullableUnion(&self, _: Option) {} fn PassNullableUnion2(&self, _: Option) {} fn PassNullableUnion3(&self, _: Option) {} fn PassNullableUnion4(&self, _: Option) {} fn PassNullableUnion5(&self, _: Option) {} fn PassNullableUnion6(&self, _: Option) {} fn PassNullableCallbackFunction(&self, _: Option>) {} fn PassNullableCallbackInterface(&self, _: Option>) {} fn PassNullableSequence(&self, _: Option>) {} fn PassOptionalBoolean(&self, _: Option) {} fn PassOptionalByte(&self, _: Option) {} fn PassOptionalOctet(&self, _: Option) {} fn PassOptionalShort(&self, _: Option) {} fn PassOptionalUnsignedShort(&self, _: Option) {} fn PassOptionalLong(&self, _: Option) {} fn PassOptionalUnsignedLong(&self, _: Option) {} fn PassOptionalLongLong(&self, _: Option) {} fn PassOptionalUnsignedLongLong(&self, _: Option) {} fn PassOptionalUnrestrictedFloat(&self, _: Option) {} fn PassOptionalFloat(&self, _: Option>) {} fn PassOptionalUnrestrictedDouble(&self, _: Option) {} fn PassOptionalDouble(&self, _: Option>) {} fn PassOptionalString(&self, _: Option) {} fn PassOptionalUsvstring(&self, _: Option) {} fn PassOptionalByteString(&self, _: Option) {} fn PassOptionalEnum(&self, _: Option) {} fn PassOptionalInterface(&self, _: Option<&Blob>) {} fn PassOptionalUnion(&self, _: Option) {} fn PassOptionalUnion2(&self, _: Option) {} fn PassOptionalUnion3(&self, _: Option) {} fn PassOptionalUnion4(&self, _: Option) {} fn PassOptionalUnion5(&self, _: Option) {} fn PassOptionalUnion6(&self, _: Option) {} fn PassOptionalAny(&self, _: SafeJSContext, _: HandleValue) {} fn PassOptionalObject(&self, _: SafeJSContext, _: Option<*mut JSObject>) {} fn PassOptionalCallbackFunction(&self, _: Option>) {} fn PassOptionalCallbackInterface(&self, _: Option>) {} fn PassOptionalSequence(&self, _: Option>) {} fn PassOptionalNullableBoolean(&self, _: Option>) {} fn PassOptionalNullableByte(&self, _: Option>) {} fn PassOptionalNullableOctet(&self, _: Option>) {} fn PassOptionalNullableShort(&self, _: Option>) {} fn PassOptionalNullableUnsignedShort(&self, _: Option>) {} fn PassOptionalNullableLong(&self, _: Option>) {} fn PassOptionalNullableUnsignedLong(&self, _: Option>) {} fn PassOptionalNullableLongLong(&self, _: Option>) {} fn PassOptionalNullableUnsignedLongLong(&self, _: Option>) {} fn PassOptionalNullableUnrestrictedFloat(&self, _: Option>) {} fn PassOptionalNullableFloat(&self, _: Option>>) {} fn PassOptionalNullableUnrestrictedDouble(&self, _: Option>) {} fn PassOptionalNullableDouble(&self, _: Option>>) {} fn PassOptionalNullableString(&self, _: Option>) {} fn PassOptionalNullableUsvstring(&self, _: Option>) {} fn PassOptionalNullableByteString(&self, _: Option>) {} // fn PassOptionalNullableEnum(self, _: Option>) {} fn PassOptionalNullableInterface(&self, _: Option>) {} fn PassOptionalNullableObject(&self, _: SafeJSContext, _: Option<*mut JSObject>) {} fn PassOptionalNullableUnion(&self, _: Option>) {} fn PassOptionalNullableUnion2(&self, _: Option>) {} fn PassOptionalNullableUnion3(&self, _: Option>) {} fn PassOptionalNullableUnion4(&self, _: Option>) {} fn PassOptionalNullableUnion5(&self, _: Option>) {} fn PassOptionalNullableUnion6(&self, _: Option>) {} fn PassOptionalNullableCallbackFunction(&self, _: Option>>) {} fn PassOptionalNullableCallbackInterface(&self, _: Option>>) {} fn PassOptionalNullableSequence(&self, _: Option>>) {} fn PassOptionalBooleanWithDefault(&self, _: bool) {} fn PassOptionalByteWithDefault(&self, _: i8) {} fn PassOptionalOctetWithDefault(&self, _: u8) {} fn PassOptionalShortWithDefault(&self, _: i16) {} fn PassOptionalUnsignedShortWithDefault(&self, _: u16) {} fn PassOptionalLongWithDefault(&self, _: i32) {} fn PassOptionalUnsignedLongWithDefault(&self, _: u32) {} fn PassOptionalLongLongWithDefault(&self, _: i64) {} fn PassOptionalUnsignedLongLongWithDefault(&self, _: u64) {} fn PassOptionalStringWithDefault(&self, _: DOMString) {} fn PassOptionalUsvstringWithDefault(&self, _: USVString) {} fn PassOptionalBytestringWithDefault(&self, _: ByteString) {} fn PassOptionalEnumWithDefault(&self, _: TestEnum) {} fn PassOptionalSequenceWithDefault(&self, _: Vec) {} fn PassOptionalNullableBooleanWithDefault(&self, _: Option) {} fn PassOptionalNullableByteWithDefault(&self, _: Option) {} fn PassOptionalNullableOctetWithDefault(&self, _: Option) {} fn PassOptionalNullableShortWithDefault(&self, _: Option) {} fn PassOptionalNullableUnsignedShortWithDefault(&self, _: Option) {} fn PassOptionalNullableLongWithDefault(&self, _: Option) {} fn PassOptionalNullableUnsignedLongWithDefault(&self, _: Option) {} fn PassOptionalNullableLongLongWithDefault(&self, _: Option) {} fn PassOptionalNullableUnsignedLongLongWithDefault(&self, _: Option) {} // fn PassOptionalNullableUnrestrictedFloatWithDefault(self, _: Option) {} // fn PassOptionalNullableFloatWithDefault(self, _: Option>) {} // fn PassOptionalNullableUnrestrictedDoubleWithDefault(self, _: Option) {} // fn PassOptionalNullableDoubleWithDefault(self, _: Option>) {} fn PassOptionalNullableStringWithDefault(&self, _: Option) {} fn PassOptionalNullableUsvstringWithDefault(&self, _: Option) {} fn PassOptionalNullableByteStringWithDefault(&self, _: Option) {} // fn PassOptionalNullableEnumWithDefault(self, _: Option) {} fn PassOptionalNullableInterfaceWithDefault(&self, _: Option<&Blob>) {} fn PassOptionalNullableObjectWithDefault(&self, _: SafeJSContext, _: *mut JSObject) {} fn PassOptionalNullableUnionWithDefault(&self, _: Option) {} fn PassOptionalNullableUnion2WithDefault(&self, _: Option) {} // fn PassOptionalNullableCallbackFunctionWithDefault(self, _: Option) {} fn PassOptionalNullableCallbackInterfaceWithDefault(&self, _: Option>) {} fn PassOptionalAnyWithDefault(&self, _: SafeJSContext, _: HandleValue) {} fn PassOptionalNullableBooleanWithNonNullDefault(&self, _: Option) {} fn PassOptionalNullableByteWithNonNullDefault(&self, _: Option) {} fn PassOptionalNullableOctetWithNonNullDefault(&self, _: Option) {} fn PassOptionalNullableShortWithNonNullDefault(&self, _: Option) {} fn PassOptionalNullableUnsignedShortWithNonNullDefault(&self, _: Option) {} fn PassOptionalNullableLongWithNonNullDefault(&self, _: Option) {} fn PassOptionalNullableUnsignedLongWithNonNullDefault(&self, _: Option) {} fn PassOptionalNullableLongLongWithNonNullDefault(&self, _: Option) {} fn PassOptionalNullableUnsignedLongLongWithNonNullDefault(&self, _: Option) {} // fn PassOptionalNullableUnrestrictedFloatWithNonNullDefault(self, _: Option) {} // fn PassOptionalNullableFloatWithNonNullDefault(self, _: Option>) {} // fn PassOptionalNullableUnrestrictedDoubleWithNonNullDefault(self, _: Option) {} // fn PassOptionalNullableDoubleWithNonNullDefault(self, _: Option>) {} fn PassOptionalNullableStringWithNonNullDefault(&self, _: Option) {} fn PassOptionalNullableUsvstringWithNonNullDefault(&self, _: Option) {} // fn PassOptionalNullableEnumWithNonNullDefault(self, _: Option) {} fn PassOptionalOverloaded(&self, a: &TestBinding, _: u32, _: u32) -> DomRoot { DomRoot::from_ref(a) } fn PassOptionalOverloaded_(&self, _: &Blob, _: u32) {} fn PassVariadicBoolean(&self, _: Vec) {} fn PassVariadicBooleanAndDefault(&self, _: bool, _: Vec) {} fn PassVariadicByte(&self, _: Vec) {} fn PassVariadicOctet(&self, _: Vec) {} fn PassVariadicShort(&self, _: Vec) {} fn PassVariadicUnsignedShort(&self, _: Vec) {} fn PassVariadicLong(&self, _: Vec) {} fn PassVariadicUnsignedLong(&self, _: Vec) {} fn PassVariadicLongLong(&self, _: Vec) {} fn PassVariadicUnsignedLongLong(&self, _: Vec) {} fn PassVariadicUnrestrictedFloat(&self, _: Vec) {} fn PassVariadicFloat(&self, _: Vec>) {} fn PassVariadicUnrestrictedDouble(&self, _: Vec) {} fn PassVariadicDouble(&self, _: Vec>) {} fn PassVariadicString(&self, _: Vec) {} fn PassVariadicUsvstring(&self, _: Vec) {} fn PassVariadicByteString(&self, _: Vec) {} fn PassVariadicEnum(&self, _: Vec) {} fn PassVariadicInterface(&self, _: &[&Blob]) {} fn PassVariadicUnion(&self, _: Vec) {} fn PassVariadicUnion2(&self, _: Vec) {} fn PassVariadicUnion3(&self, _: Vec) {} fn PassVariadicUnion4(&self, _: Vec) {} fn PassVariadicUnion5(&self, _: Vec) {} fn PassVariadicUnion6(&self, _: Vec) {} fn PassVariadicUnion7(&self, _: Vec) {} fn PassVariadicAny(&self, _: SafeJSContext, _: Vec) {} fn PassVariadicObject(&self, _: SafeJSContext, _: Vec<*mut JSObject>) {} fn BooleanMozPreference(&self, pref_name: DOMString) -> bool { prefs::pref_map() .get(pref_name.as_ref()) .as_bool() .unwrap_or(false) } fn StringMozPreference(&self, pref_name: DOMString) -> DOMString { prefs::pref_map() .get(pref_name.as_ref()) .as_str() .map(DOMString::from) .unwrap_or_default() } fn PrefControlledAttributeDisabled(&self) -> bool { false } fn PrefControlledAttributeEnabled(&self) -> bool { false } fn PrefControlledMethodDisabled(&self) {} fn PrefControlledMethodEnabled(&self) {} fn FuncControlledAttributeDisabled(&self) -> bool { false } fn FuncControlledAttributeEnabled(&self) -> bool { false } fn FuncControlledMethodDisabled(&self) {} fn FuncControlledMethodEnabled(&self) {} fn PassRecord(&self, _: Record) {} fn PassRecordWithUSVStringKey(&self, _: Record) {} fn PassRecordWithByteStringKey(&self, _: Record) {} fn PassNullableRecord(&self, _: Option>) {} fn PassRecordOfNullableInts(&self, _: Record>) {} fn PassOptionalRecordOfNullableInts(&self, _: Option>>) {} fn PassOptionalNullableRecordOfNullableInts( &self, _: Option>>>, ) { } fn PassCastableObjectRecord(&self, _: Record>) {} fn PassNullableCastableObjectRecord(&self, _: Record>>) { } fn PassCastableObjectNullableRecord(&self, _: Option>>) { } fn PassNullableCastableObjectNullableRecord( &self, _: Option>>>, ) { } fn PassOptionalRecord(&self, _: Option>) {} fn PassOptionalNullableRecord(&self, _: Option>>) {} fn PassOptionalNullableRecordWithDefaultValue(&self, _: Option>) {} fn PassOptionalObjectRecord(&self, _: Option>>) {} fn PassStringRecord(&self, _: Record) {} fn PassByteStringRecord(&self, _: Record) {} fn PassRecordOfRecords(&self, _: Record>) {} fn PassRecordUnion(&self, _: UnionTypes::LongOrStringByteStringRecord) {} fn PassRecordUnion2(&self, _: UnionTypes::TestBindingOrStringByteStringRecord) {} fn PassRecordUnion3( &self, _: UnionTypes::TestBindingOrByteStringSequenceSequenceOrStringByteStringRecord, ) { } fn ReceiveRecord(&self) -> Record { Record::new() } fn ReceiveRecordWithUSVStringKey(&self) -> Record { Record::new() } fn ReceiveRecordWithByteStringKey(&self) -> Record { Record::new() } fn ReceiveNullableRecord(&self) -> Option> { Some(Record::new()) } fn ReceiveRecordOfNullableInts(&self) -> Record> { Record::new() } fn ReceiveNullableRecordOfNullableInts(&self) -> Option>> { Some(Record::new()) } fn ReceiveRecordOfRecords(&self) -> Record> { Record::new() } fn ReceiveAnyRecord(&self) -> Record { Record::new() } #[allow(crown::unrooted_must_root)] fn ReturnResolvedPromise(&self, cx: SafeJSContext, v: HandleValue) -> Fallible> { Promise::new_resolved(&self.global(), cx, v) } #[allow(crown::unrooted_must_root)] fn ReturnRejectedPromise(&self, cx: SafeJSContext, v: HandleValue) -> Fallible> { Promise::new_rejected(&self.global(), cx, v) } fn PromiseResolveNative(&self, cx: SafeJSContext, p: &Promise, v: HandleValue) { p.resolve(cx, v); } fn PromiseRejectNative(&self, cx: SafeJSContext, p: &Promise, v: HandleValue) { p.reject(cx, v); } fn PromiseRejectWithTypeError(&self, p: &Promise, s: USVString) { p.reject_error(Error::Type(s.0)); } #[allow(crown::unrooted_must_root)] fn ResolvePromiseDelayed(&self, p: &Promise, value: DOMString, delay: u64) { let promise = p.duplicate(); let cb = TestBindingCallback { promise: TrustedPromise::new(promise), value, }; let _ = self.global().schedule_callback( OneshotTimerCallback::TestBindingCallback(cb), MsDuration::new(delay), ); } fn PromiseNativeHandler( &self, resolve: Option>, reject: Option>, comp: InRealm, ) -> Rc { let global = self.global(); let handler = PromiseNativeHandler::new( &global, resolve.map(SimpleHandler::new), reject.map(SimpleHandler::new), ); let p = Promise::new_in_current_realm(comp); p.append_native_handler(&handler, comp); return p; #[derive(JSTraceable, MallocSizeOf)] struct SimpleHandler { #[ignore_malloc_size_of = "Rc has unclear ownership semantics"] handler: Rc, } impl SimpleHandler { fn new(callback: Rc) -> Box { Box::new(SimpleHandler { handler: callback }) } } impl Callback for SimpleHandler { fn callback(&self, cx: SafeJSContext, v: HandleValue, realm: InRealm) { let global = GlobalScope::from_safe_context(cx, realm); let _ = self.handler.Call_(&*global, v, ExceptionHandling::Report); } } } fn PromiseAttribute(&self, comp: InRealm) -> Rc { Promise::new_in_current_realm(comp) } fn AcceptPromise(&self, _promise: &Promise) {} fn PassSequenceSequence(&self, _seq: Vec>) {} fn ReturnSequenceSequence(&self) -> Vec> { vec![] } fn PassUnionSequenceSequence(&self, seq: LongOrLongSequenceSequence) { match seq { LongOrLongSequenceSequence::Long(_) => (), LongOrLongSequenceSequence::LongSequenceSequence(seq) => { let _seq: Vec> = seq; }, } } #[allow(unsafe_code)] fn CrashHard(&self) { unsafe { std::ptr::null_mut::().write(42) } } fn AdvanceClock(&self, ms: i32) { self.global().as_window().advance_animation_clock(ms); } fn Panic(&self) { panic!("explicit panic from script") } fn EntryGlobal(&self) -> DomRoot { GlobalScope::entry() } fn IncumbentGlobal(&self) -> DomRoot { GlobalScope::incumbent().unwrap() } fn SemiExposedBoolFromInterface(&self) -> bool { true } fn BoolFromSemiExposedPartialInterface(&self) -> bool { true } fn SemiExposedBoolFromPartialInterface(&self) -> bool { true } fn GetDictionaryWithParent(&self, s1: DOMString, s2: DOMString) -> TestDictionaryWithParent { TestDictionaryWithParent { parent: TestDictionaryParent { parentStringMember: Some(s1), }, stringMember: Some(s2), } } } #[allow(non_snake_case)] impl TestBinding { pub fn BooleanAttributeStatic(_: &GlobalScope) -> bool { false } pub fn SetBooleanAttributeStatic(_: &GlobalScope, _: bool) {} pub fn ReceiveVoidStatic(_: &GlobalScope) {} pub fn PrefControlledStaticAttributeDisabled(_: &GlobalScope) -> bool { false } pub fn PrefControlledStaticAttributeEnabled(_: &GlobalScope) -> bool { false } pub fn PrefControlledStaticMethodDisabled(_: &GlobalScope) {} pub fn PrefControlledStaticMethodEnabled(_: &GlobalScope) {} pub fn FuncControlledStaticAttributeDisabled(_: &GlobalScope) -> bool { false } pub fn FuncControlledStaticAttributeEnabled(_: &GlobalScope) -> bool { false } pub fn FuncControlledStaticMethodDisabled(_: &GlobalScope) {} pub fn FuncControlledStaticMethodEnabled(_: &GlobalScope) {} } impl TestBinding { pub fn condition_satisfied(_: SafeJSContext, _: HandleObject) -> bool { true } pub fn condition_unsatisfied(_: SafeJSContext, _: HandleObject) -> bool { false } } #[derive(JSTraceable, MallocSizeOf)] pub struct TestBindingCallback { #[ignore_malloc_size_of = "unclear ownership semantics"] promise: TrustedPromise, value: DOMString, } impl TestBindingCallback { #[allow(crown::unrooted_must_root)] pub fn invoke(self) { self.promise.root().resolve_native(&self.value); } }