Hi Tomás! Thanks for asking these questions; I'm unfortunately going to
throw a curve ball by stating that we shouldn't actually be creating new
WebIDL interfaces for this project. Such interfaces are defined in web
standards (e.g. the block under "DOM interface" at
https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element
) and any deviations (such as adding interfaces that don't exist in
other browsers) reduce our compatibility with other web browsers, thus
making the lives of web developers more complicated.
So, bearing in mind that this answer is hopefully no longer necessary,
the answer to your question about return values lies in our
documentation:
http://doc.servo.org/servo/script/dom/bindings/conversions/index.html .
WebIDL interface types are garbage-collected values, so we always need
to wrap them in garbage-collector-aware smart pointers when returning
them (i.e. Root<T>).
Cheers,
Josh
On 2015-11-27 5:01 AM, Tomás Barry wrote:
Hi Guys,
We're creating a new dom interface for Image Requests. We're looking to add a
new webidl file for imagerequest.rs (A file we just created) and we've been
following these steps:
http://doc.servo.org/script/dom/index.html#adding-a-new-dom-interface
And have implemented them all. However we're having issues with using custom
types, such as ImageData in it.
There seems to be other examples of using custom types in webidl files, we just
can't find where we need to add the type to make it accessible.
So we have this in our .webidl file:
```
interface ImageRequest {
readonly attribute ImageState state;
readonly attribute URL currentUrl;
readonly attribute ImageData imageData;
};
```
And our .rs file struct definition looks like this:
``` #[dom_struct]
pub struct ImageRequest {
reflector_: Reflector,
state : ImageState,
currentUrl : URL,
imageData : ImageData,
}
```
Our trait implmentation is this:
```
impl ImageRequestMethods for ImageRequest {
fn State(&self) -> ImageState {
self.state
}
fn CurrentUrl(&self) -> URL {
self.currentUrl
}
fn ImageData(&self) -> ImageData {
self.imageData
}
}
```
And an example of the error we are getting is this:
error: method `ImageData` has an incompatible type for trait:
expected struct `dom::bindings::js::Root`,
found struct `dom::imagedata::ImageData` [E0053]
We get similar errors for ImageState and URL.
So basically, we're a little unsure how to make the types accessible in the
webidl files and why the trait is expecting a 'dom::bindings::js::Root' struct
rather than the one we define. Our internal pull request for this task (to our
own fork) is here:
https://github.com/paterson/servo/pull/13/files
Previously, it seems like the Bindings.conf file was used for stuff related to
this. For example here is a previous version of it with custom types defined:
https://github.com/servo/servo/blob/22e02b573d546f9e0eea3318e2691d3144735fc5/src/components/script/dom/bindings/codegen/Bindings.conf
But that file is now quite different:
https://github.com/servo/servo/blob/master/components/script/dom/bindings/codegen/Bindings.conf
So we're guessing this has changed and is implemented. Any ideas/tips would be
really appreciated!
_______________________________________________
dev-servo mailing list
dev-servo@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-servo