mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Assert that DOM structs have the correct first field
DOM structs embed their parent type as their first field. This introduces a `.parent()` method to the DOM struct that returns its first field, and codegens a type assert that ensures that `.parent()` returns the parent struct. This generates: On `#[dom_struct]`: ```rust impl HasParent for Type { type Parent = ParentType; fn as_parent(&self) -> ParentType { &self.first_field } } ``` In the codegen files: ```rust impl Type { fn __assert_parent_type(&self) { let _: &ParentType = self.as_parent(); } } ````
This commit is contained in:
parent
e2fca1b228
commit
ad198993b1
6 changed files with 109 additions and 9 deletions
|
@ -5,11 +5,10 @@
|
|||
use dom::bindings::codegen::Bindings::BlobBinding::BlobMethods;
|
||||
use dom::bindings::codegen::Bindings::FileReaderSyncBinding::{FileReaderSyncBinding, FileReaderSyncMethods};
|
||||
use dom::bindings::error::{Error, Fallible};
|
||||
use dom::bindings::reflector::reflect_dom_object;
|
||||
use dom::bindings::reflector::{Reflector, reflect_dom_object};
|
||||
use dom::bindings::root::DomRoot;
|
||||
use dom::bindings::str::DOMString;
|
||||
use dom::blob::Blob;
|
||||
use dom::eventtarget::EventTarget;
|
||||
use dom::filereader::FileReaderSharedFunctionality;
|
||||
use dom::globalscope::GlobalScope;
|
||||
use dom_struct::dom_struct;
|
||||
|
@ -20,13 +19,13 @@ use std::ptr::NonNull;
|
|||
|
||||
#[dom_struct]
|
||||
pub struct FileReaderSync {
|
||||
eventtarget: EventTarget,
|
||||
reflector: Reflector,
|
||||
}
|
||||
|
||||
impl FileReaderSync {
|
||||
pub fn new_inherited() -> FileReaderSync {
|
||||
FileReaderSync {
|
||||
eventtarget: EventTarget::new_inherited(),
|
||||
reflector: Reflector::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue