Hi Tomás,
You'll need a `#[derive(HeapSizeOf, JSTraceable)]` annotation above your
`struct ImageRequest` declaration. If there are any fields contained in
ImageRequest that do not themselves implement the HeapSizeOf and
JSTraceable traits, then you'll either need to add further annotations
like the above, or add new `no_jsmanaged_fields` like you discovered, or
add an `#[ignore_heap_size_of = "explanatory reason for ignoring the
field"]` for the particular field that is causing problems.
If this isn't documented somewhere, we should really do so. That being
said, I don't have a good idea for where I would expect to find such
documentation.
Cheers,
Josh
On 2015-12-08 7:15 AM, Tomás Barry wrote:
Hi,
We have a follow up question from our post here:
https://groups.google.com/forum/#!topic/mozilla.dev.servo/-rCycXAE52Q
We've tweaked the above to include the struct (ImageRequest) in
HTMLImageElement as an inner struct, however we're just having an issue with
JSTraceable and HeapSizeOf.
For reference here is the HTMLImageElement struct definition right now
(including our changes):
```
pub struct HTMLImageElement {
htmlelement: HTMLElement,
url: DOMRefCell<Option<Url>>,
image: DOMRefCell<Option<Arc<Image>>>,
currentRequest: DOMRefCell<Option<ImageRequest>>,
pendingRequest: DOMRefCell<Option<ImageRequest>>,
}
```
The current error is as follows:
```
./mach build --dev
error: no method named `trace` found for type
`dom::bindings::cell::DOMRefCell<core::option::Option<dom::htmlimageelement::ImageRequest>>`
in the current scope
/Users/niall/Desktop/projects/College/Software-Engineering/servo/components/script/dom/htmlimageelement.rs:41
currentRequest: DOMRefCell<Option<ImageRequest>>,
note: in this expansion of #[derive_JSTraceable] the method `trace` exists but the
following trait bounds were not satisfied:
`core::option::Option<dom::htmlimageelement::ImageRequest> :
dom::bindings::trace::JSTraceable`
```
We can see that Url and Image are included in bindings/trace.rs like this:
no_jsmanaged_fields!(bool, f32, f64, String, Url, AtomicBool);
Which we think handles ensuring that they do not need the trace method to be
implemented, and while we can add ImageRequest to this file, our feeling is
that this is not correct as there does not seem to be any other custom types in
this file. It's similar for the HeapSizeOf issue.
Our question is: How do we handle our custom type with JSTraceable and
HeapSizeOf?
Can anyone shed light on this issue?
Thanks,
Tomas.
_______________________________________________
dev-servo mailing list
dev-servo@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-servo