mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Improve some TestBinding methods
We make them return sensical things in a sensical way.
This commit is contained in:
parent
2400b91d05
commit
897a81e95b
1 changed files with 23 additions and 4 deletions
|
@ -26,6 +26,7 @@ use dom::bindings::weakref::MutableWeakRef;
|
|||
use dom::blob::{Blob, BlobImpl};
|
||||
use dom::url::URL;
|
||||
use js::jsapi::{HandleObject, HandleValue, JSContext, JSObject};
|
||||
use js::jsapi::{JS_NewPlainObject, JS_NewUint8ClampedArray};
|
||||
use js::jsval::{JSVal, NullValue};
|
||||
use std::borrow::ToOwned;
|
||||
use std::ptr;
|
||||
|
@ -137,10 +138,24 @@ impl TestBindingMethods for TestBinding {
|
|||
ByteStringOrLong::ByteString(ByteString::new(vec!()))
|
||||
}
|
||||
fn SetUnion9Attribute(&self, _: ByteStringOrLong) {}
|
||||
fn ArrayAttribute(&self, _: *mut JSContext) -> *mut JSObject { NullValue().to_object_or_null() }
|
||||
#[allow(unsafe_code)]
|
||||
fn ArrayAttribute(&self, cx: *mut JSContext) -> *mut JSObject {
|
||||
unsafe {
|
||||
rooted!(in(cx) let array = JS_NewUint8ClampedArray(cx, 16));
|
||||
assert!(!array.is_null());
|
||||
array.get()
|
||||
}
|
||||
}
|
||||
fn AnyAttribute(&self, _: *mut JSContext) -> JSVal { NullValue() }
|
||||
fn SetAnyAttribute(&self, _: *mut JSContext, _: HandleValue) {}
|
||||
fn ObjectAttribute(&self, _: *mut JSContext) -> *mut JSObject { panic!() }
|
||||
#[allow(unsafe_code)]
|
||||
fn ObjectAttribute(&self, cx: *mut JSContext) -> *mut JSObject {
|
||||
unsafe {
|
||||
rooted!(in(cx) let obj = JS_NewPlainObject(cx));
|
||||
assert!(!obj.is_null());
|
||||
obj.get()
|
||||
}
|
||||
}
|
||||
fn SetObjectAttribute(&self, _: *mut JSContext, _: *mut JSObject) {}
|
||||
|
||||
fn GetBooleanAttributeNullable(&self) -> Option<bool> { Some(false) }
|
||||
|
@ -242,7 +257,9 @@ impl TestBindingMethods for TestBinding {
|
|||
Blob::new(self.global().r(), BlobImpl::new_from_bytes(vec![]), "".to_owned())
|
||||
}
|
||||
fn ReceiveAny(&self, _: *mut JSContext) -> JSVal { NullValue() }
|
||||
fn ReceiveObject(&self, _: *mut JSContext) -> *mut JSObject { panic!() }
|
||||
fn ReceiveObject(&self, cx: *mut JSContext) -> *mut JSObject {
|
||||
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![]) }
|
||||
|
@ -283,7 +300,9 @@ impl TestBindingMethods for TestBinding {
|
|||
fn ReceiveNullableInterface(&self) -> Option<Root<Blob>> {
|
||||
Some(Blob::new(self.global().r(), BlobImpl::new_from_bytes(vec![]), "".to_owned()))
|
||||
}
|
||||
fn ReceiveNullableObject(&self, _: *mut JSContext) -> *mut JSObject { ptr::null_mut() }
|
||||
fn ReceiveNullableObject(&self, cx: *mut JSContext) -> *mut JSObject {
|
||||
self.GetObjectAttributeNullable(cx)
|
||||
}
|
||||
fn ReceiveNullableUnion(&self) -> Option<HTMLElementOrLong> {
|
||||
Some(HTMLElementOrLong::Long(0))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue