mirror of
https://github.com/servo/servo.git
synced 2025-07-16 03:43:38 +01:00
Derive the Default trait for dictionaries containing GC values.
This commit is contained in:
parent
b169689f32
commit
16166d6673
6 changed files with 49 additions and 7 deletions
|
@ -4028,12 +4028,18 @@ impl super::%s {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for super::%s {
|
||||
fn default() -> super::%s {
|
||||
pairs[0].1
|
||||
}
|
||||
}
|
||||
|
||||
impl ToJSValConvertible for super::%s {
|
||||
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
|
||||
pairs[*self as usize].0.to_jsval(cx, rval);
|
||||
}
|
||||
}
|
||||
""" % (ident, pairs, ident, ident)
|
||||
""" % (ident, pairs, ident, ident, ident, ident)
|
||||
self.cgRoot = CGList([
|
||||
CGGeneric(decl),
|
||||
CGNamespace.build([ident + "Values"],
|
||||
|
@ -6038,17 +6044,22 @@ class CGDictionary(CGThing):
|
|||
(self.makeMemberName(m[0].identifier.name), self.getMemberType(m))
|
||||
for m in self.memberInfo]
|
||||
|
||||
mustRoot = "#[must_root]\n" if self.membersNeedTracing() else ""
|
||||
derive = ["JSTraceable"]
|
||||
mustRoot = ""
|
||||
if self.membersNeedTracing():
|
||||
mustRoot = "#[must_root]\n"
|
||||
derive += ["Default"]
|
||||
|
||||
return (string.Template(
|
||||
"#[derive(JSTraceable)]\n"
|
||||
"#[derive(${derive})]\n"
|
||||
"${mustRoot}" +
|
||||
"pub struct ${selfName} {\n" +
|
||||
"${inheritance}" +
|
||||
"\n".join(memberDecls) + "\n" +
|
||||
"}").substitute({"selfName": self.makeClassName(d),
|
||||
"inheritance": inheritance,
|
||||
"mustRoot": mustRoot}))
|
||||
"mustRoot": mustRoot,
|
||||
"derive": ', '.join(derive)}))
|
||||
|
||||
def impl(self):
|
||||
d = self.dictionary
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
use heapsize::HeapSizeOf;
|
||||
use num_traits::Float;
|
||||
use std::default::Default;
|
||||
use std::ops::Deref;
|
||||
|
||||
/// Encapsulates the IDL restricted float type.
|
||||
|
@ -45,3 +46,9 @@ impl<T: Float + HeapSizeOf> HeapSizeOf for Finite<T> {
|
|||
(**self).heap_size_of_children()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float + Default> Default for Finite<T> {
|
||||
fn default() -> Finite<T> {
|
||||
Finite::wrap(T::default())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ use html5ever::{LocalName, Namespace};
|
|||
use servo_atoms::Atom;
|
||||
use std::ascii::AsciiExt;
|
||||
use std::borrow::{Borrow, Cow, ToOwned};
|
||||
use std::default::Default;
|
||||
use std::fmt;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::marker::PhantomData;
|
||||
|
@ -18,7 +19,7 @@ use std::str;
|
|||
use std::str::{Bytes, FromStr};
|
||||
|
||||
/// Encapsulates the IDL `ByteString` type.
|
||||
#[derive(Clone, Debug, Eq, HeapSizeOf, JSTraceable, PartialEq)]
|
||||
#[derive(Clone, Debug, Default, Eq, HeapSizeOf, JSTraceable, PartialEq)]
|
||||
pub struct ByteString(Vec<u8>);
|
||||
|
||||
impl ByteString {
|
||||
|
@ -77,7 +78,7 @@ impl ops::Deref for ByteString {
|
|||
|
||||
/// A string that is constructed from a UCS-2 buffer by replacing invalid code
|
||||
/// points with the replacement character.
|
||||
#[derive(Clone, HeapSizeOf)]
|
||||
#[derive(Clone, Default, HeapSizeOf)]
|
||||
pub struct USVString(pub String);
|
||||
|
||||
|
||||
|
|
|
@ -769,6 +769,12 @@ impl<T: JSTraceable + 'static> RootedTraceableBox<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: JSTraceable + Default> Default for RootedTraceableBox<T> {
|
||||
fn default() -> RootedTraceableBox<T> {
|
||||
RootedTraceableBox::new(T::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: JSTraceable> Deref for RootedTraceableBox<T> {
|
||||
type Target = T;
|
||||
fn deref(&self) -> &T {
|
||||
|
|
|
@ -522,3 +522,12 @@ fn inner_invoke(window: Option<&Window>,
|
|||
// Step 3.
|
||||
found
|
||||
}
|
||||
|
||||
impl Default for EventBinding::EventInit {
|
||||
fn default() -> EventBinding::EventInit {
|
||||
EventBinding::EventInit {
|
||||
bubbles: false,
|
||||
cancelable: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
||||
use dom::bindings::codegen::Bindings::EventBinding::{self, EventMethods};
|
||||
use dom::bindings::codegen::Bindings::ExtendableEventBinding;
|
||||
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||
use dom::bindings::inheritance::Castable;
|
||||
|
@ -67,3 +67,11 @@ impl ExtendableEvent {
|
|||
self.event.IsTrusted()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ExtendableEventBinding::ExtendableEventInit {
|
||||
fn default() -> ExtendableEventBinding::ExtendableEventInit {
|
||||
ExtendableEventBinding::ExtendableEventInit {
|
||||
parent: EventBinding::EventInit::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue