Skip to content

Commit

Permalink
Make #[dom_struct] a proc_macro attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
nox committed Feb 24, 2017
1 parent 64885c4 commit 31e9d81
Show file tree
Hide file tree
Showing 251 changed files with 298 additions and 35 deletions.
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions components/dom_struct/Cargo.toml
@@ -0,0 +1,13 @@
[package]
name = "dom_struct"
version = "0.0.1"
authors = ["The Servo Project Developers"]
license = "MPL-2.0"
publish = false

[lib]
path = "lib.rs"
proc-macro = true

[dependencies]
quote = "0.3"
28 changes: 28 additions & 0 deletions components/dom_struct/lib.rs
@@ -0,0 +1,28 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */

#![feature(proc_macro)]

extern crate proc_macro;
#[macro_use] extern crate quote;

use proc_macro::TokenStream;

#[proc_macro_attribute]
pub fn dom_struct(args: TokenStream, input: TokenStream) -> TokenStream {
if !args.to_string().is_empty() {
panic!("#[dom_struct] takes no arguments");
}
expand_string(&input.to_string()).parse().unwrap()
}

fn expand_string(input: &str) -> String {
let mut tokens = quote! {
#[derive(DenyPublicFields, DomObject, HeapSizeOf, JSTraceable)]
#[must_root]
#[repr(C)]
};
tokens.append(input);
tokens.to_string()
}
1 change: 1 addition & 0 deletions components/script/Cargo.toml
Expand Up @@ -37,6 +37,7 @@ cookie = {version = "0.2.5", features = ["serialize-rustc"]}
cssparser = {version = "0.10", features = ["heapsize", "serde"]}
deny_public_fields = {path = "../deny_public_fields"}
devtools_traits = {path = "../devtools_traits"}
dom_struct = {path = "../dom_struct"}
domobject_derive = {path = "../domobject_derive"}
encoding = "0.2"
euclid = "0.11"
Expand Down
2 changes: 2 additions & 0 deletions components/script/docs/JS-Servos-only-GC.md
Expand Up @@ -138,6 +138,8 @@ Let's look at [Servo's implementation][document-rs] of the DOM's
[document-mdn]: https://developer.mozilla.org/en-US/docs/Web/API/document

```rust
use dom_struct::dom_struct;

#[dom_struct]
pub struct Document {
node: Node,
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/attr.rs
Expand Up @@ -12,6 +12,7 @@ use dom::bindings::str::DOMString;
use dom::element::{AttributeMutation, Element};
use dom::virtualmethods::vtable_for;
use dom::window::Window;
use dom_struct::dom_struct;
use html5ever_atoms::{Prefix, LocalName, Namespace};
use servo_atoms::Atom;
use std::borrow::ToOwned;
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/beforeunloadevent.rs
Expand Up @@ -14,6 +14,7 @@ use dom::bindings::reflector::reflect_dom_object;
use dom::bindings::str::DOMString;
use dom::event::{Event, EventBubbles, EventCancelable};
use dom::window::Window;
use dom_struct::dom_struct;
use servo_atoms::Atom;

// https://html.spec.whatwg.org/multipage/#beforeunloadevent
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/bindings/iterable.rs
Expand Up @@ -14,6 +14,7 @@ use dom::bindings::js::{JS, Root};
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
use dom::bindings::trace::JSTraceable;
use dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
use js::conversions::ToJSValConvertible;
use js::jsapi::{HandleValue, Heap, JSContext, JSObject, MutableHandleObject};
use js::jsval::UndefinedValue;
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/blob.rs
Expand Up @@ -11,6 +11,7 @@ use dom::bindings::js::{JS, Root};
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
use dom::bindings::str::DOMString;
use dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
use encoding::all::UTF_8;
use encoding::types::{EncoderTrap, Encoding};
use ipc_channel::ipc;
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/bluetooth.rs
Expand Up @@ -30,6 +30,7 @@ use dom::eventtarget::EventTarget;
use dom::globalscope::GlobalScope;
use dom::permissions::{get_descriptor_permission_state, PermissionAlgorithm};
use dom::promise::Promise;
use dom_struct::dom_struct;
use ipc_channel::ipc::{self, IpcSender};
use ipc_channel::router::ROUTER;
use js::conversions::ConversionResult;
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/bluetoothadvertisingevent.rs
Expand Up @@ -14,6 +14,7 @@ use dom::bluetoothdevice::BluetoothDevice;
use dom::event::{Event, EventBubbles, EventCancelable};
use dom::globalscope::GlobalScope;
use dom::window::Window;
use dom_struct::dom_struct;
use servo_atoms::Atom;

// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothadvertisingevent
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/bluetoothcharacteristicproperties.rs
Expand Up @@ -8,6 +8,7 @@ use dom::bindings::codegen::Bindings::BluetoothCharacteristicPropertiesBinding::
use dom::bindings::js::Root;
use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::globalscope::GlobalScope;
use dom_struct::dom_struct;

// https://webbluetoothcg.github.io/web-bluetooth/#characteristicproperties
#[dom_struct]
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/bluetoothdevice.rs
Expand Up @@ -24,6 +24,7 @@ use dom::bluetoothremotegattservice::BluetoothRemoteGATTService;
use dom::eventtarget::EventTarget;
use dom::globalscope::GlobalScope;
use dom::promise::Promise;
use dom_struct::dom_struct;
use ipc_channel::ipc::{self, IpcSender};
use js::jsapi::JSContext;
use std::cell::Cell;
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/bluetoothpermissionresult.rs
Expand Up @@ -18,6 +18,7 @@ use dom::bluetoothdevice::BluetoothDevice;
use dom::globalscope::GlobalScope;
use dom::permissionstatus::PermissionStatus;
use dom::promise::Promise;
use dom_struct::dom_struct;
use ipc_channel::ipc::IpcSender;
use js::jsapi::JSContext;
use std::rc::Rc;
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/bluetoothremotegattcharacteristic.rs
Expand Up @@ -25,6 +25,7 @@ use dom::bluetoothuuid::{BluetoothDescriptorUUID, BluetoothUUID};
use dom::eventtarget::EventTarget;
use dom::globalscope::GlobalScope;
use dom::promise::Promise;
use dom_struct::dom_struct;
use ipc_channel::ipc::IpcSender;
use js::jsapi::JSContext;
use std::rc::Rc;
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/bluetoothremotegattdescriptor.rs
Expand Up @@ -19,6 +19,7 @@ use dom::bluetooth::{AsyncBluetoothListener, response_async};
use dom::bluetoothremotegattcharacteristic::{BluetoothRemoteGATTCharacteristic, MAXIMUM_ATTRIBUTE_LENGTH};
use dom::globalscope::GlobalScope;
use dom::promise::Promise;
use dom_struct::dom_struct;
use ipc_channel::ipc::IpcSender;
use js::jsapi::JSContext;
use std::rc::Rc;
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/bluetoothremotegattserver.rs
Expand Up @@ -15,6 +15,7 @@ use dom::bluetoothdevice::BluetoothDevice;
use dom::bluetoothuuid::{BluetoothServiceUUID, BluetoothUUID};
use dom::globalscope::GlobalScope;
use dom::promise::Promise;
use dom_struct::dom_struct;
use ipc_channel::ipc::IpcSender;
use js::jsapi::JSContext;
use std::cell::Cell;
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/bluetoothremotegattservice.rs
Expand Up @@ -17,6 +17,7 @@ use dom::bluetoothuuid::{BluetoothCharacteristicUUID, BluetoothServiceUUID, Blue
use dom::eventtarget::EventTarget;
use dom::globalscope::GlobalScope;
use dom::promise::Promise;
use dom_struct::dom_struct;
use js::jsapi::JSContext;
use std::rc::Rc;

Expand Down
1 change: 1 addition & 0 deletions components/script/dom/bluetoothuuid.rs
Expand Up @@ -8,6 +8,7 @@ use dom::bindings::error::Fallible;
use dom::bindings::reflector::Reflector;
use dom::bindings::str::DOMString;
use dom::window::Window;
use dom_struct::dom_struct;
use regex::Regex;

pub type UUID = DOMString;
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/browsingcontext.rs
Expand Up @@ -15,6 +15,7 @@ use dom::dissimilaroriginwindow::DissimilarOriginWindow;
use dom::element::Element;
use dom::globalscope::GlobalScope;
use dom::window::Window;
use dom_struct::dom_struct;
use js::JSCLASS_IS_GLOBAL;
use js::glue::{CreateWrapperProxyHandler, ProxyTraps, NewWindowProxy};
use js::glue::{GetProxyPrivate, SetProxyExtra, GetProxyExtra};
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/canvasgradient.rs
Expand Up @@ -14,6 +14,7 @@ use dom::bindings::num::Finite;
use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::str::DOMString;
use dom::globalscope::GlobalScope;
use dom_struct::dom_struct;

// https://html.spec.whatwg.org/multipage/#canvasgradient
#[dom_struct]
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/canvaspattern.rs
Expand Up @@ -8,6 +8,7 @@ use dom::bindings::js::Root;
use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::canvasgradient::ToFillOrStrokeStyle;
use dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
use euclid::size::Size2D;

// https://html.spec.whatwg.org/multipage/#canvaspattern
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/canvasrenderingcontext2d.rs
Expand Up @@ -33,6 +33,7 @@ use dom::htmlcanvaselement::utils as canvas_utils;
use dom::htmlimageelement::HTMLImageElement;
use dom::imagedata::ImageData;
use dom::node::{Node, NodeDamage, window_from_node};
use dom_struct::dom_struct;
use euclid::matrix2d::Matrix2D;
use euclid::point::Point2D;
use euclid::rect::Rect;
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/characterdata.rs
Expand Up @@ -19,6 +19,7 @@ use dom::element::Element;
use dom::node::{Node, NodeDamage};
use dom::processinginstruction::ProcessingInstruction;
use dom::text::Text;
use dom_struct::dom_struct;
use servo_config::opts;
use std::cell::Ref;

Expand Down
1 change: 1 addition & 0 deletions components/script/dom/client.rs
Expand Up @@ -9,6 +9,7 @@ use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::str::{DOMString, USVString};
use dom::serviceworker::ServiceWorker;
use dom::window::Window;
use dom_struct::dom_struct;
use servo_url::ServoUrl;
use std::default::Default;
use uuid::Uuid;
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/closeevent.rs
Expand Up @@ -12,6 +12,7 @@ use dom::bindings::reflector::reflect_dom_object;
use dom::bindings::str::DOMString;
use dom::event::{Event, EventBubbles, EventCancelable};
use dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
use servo_atoms::Atom;

#[dom_struct]
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/comment.rs
Expand Up @@ -11,6 +11,7 @@ use dom::characterdata::CharacterData;
use dom::document::Document;
use dom::node::Node;
use dom::window::Window;
use dom_struct::dom_struct;

/// An HTML comment.
#[dom_struct]
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/crypto.rs
Expand Up @@ -10,6 +10,7 @@ use dom::bindings::error::{Error, Fallible};
use dom::bindings::js::Root;
use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
use js::jsapi::{JSContext, JSObject};
use js::jsapi::Type;
use servo_rand::{ServoRng, Rng};
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/css.rs
Expand Up @@ -8,6 +8,7 @@ use dom::bindings::error::Fallible;
use dom::bindings::reflector::Reflector;
use dom::bindings::str::DOMString;
use dom::window::Window;
use dom_struct::dom_struct;
use style::parser::ParserContext;
use style::supports::{Declaration, parse_condition_or_declaration};

Expand Down
1 change: 1 addition & 0 deletions components/script/dom/cssconditionrule.rs
Expand Up @@ -9,6 +9,7 @@ use dom::cssgroupingrule::CSSGroupingRule;
use dom::cssmediarule::CSSMediaRule;
use dom::cssstylesheet::CSSStyleSheet;
use dom::csssupportsrule::CSSSupportsRule;
use dom_struct::dom_struct;
use parking_lot::RwLock;
use std::sync::Arc;
use style::stylesheets::CssRules as StyleCssRules;
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/cssfontfacerule.rs
Expand Up @@ -9,6 +9,7 @@ use dom::bindings::str::DOMString;
use dom::cssrule::{CSSRule, SpecificCSSRule};
use dom::cssstylesheet::CSSStyleSheet;
use dom::window::Window;
use dom_struct::dom_struct;
use parking_lot::RwLock;
use std::sync::Arc;
use style::font_face::FontFaceRule;
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/cssgroupingrule.rs
Expand Up @@ -11,6 +11,7 @@ use dom::bindings::str::DOMString;
use dom::cssrule::CSSRule;
use dom::cssrulelist::{CSSRuleList, RulesSource};
use dom::cssstylesheet::CSSStyleSheet;
use dom_struct::dom_struct;
use parking_lot::RwLock;
use std::sync::Arc;
use style::stylesheets::CssRules as StyleCssRules;
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/cssimportrule.rs
Expand Up @@ -9,6 +9,7 @@ use dom::bindings::str::DOMString;
use dom::cssrule::{CSSRule, SpecificCSSRule};
use dom::cssstylesheet::CSSStyleSheet;
use dom::window::Window;
use dom_struct::dom_struct;
use parking_lot::RwLock;
use std::sync::Arc;
use style::stylesheets::ImportRule;
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/csskeyframerule.rs
Expand Up @@ -11,6 +11,7 @@ use dom::cssrule::{CSSRule, SpecificCSSRule};
use dom::cssstyledeclaration::{CSSModificationAccess, CSSStyleDeclaration, CSSStyleOwner};
use dom::cssstylesheet::CSSStyleSheet;
use dom::window::Window;
use dom_struct::dom_struct;
use parking_lot::RwLock;
use std::sync::Arc;
use style::keyframes::Keyframe;
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/csskeyframesrule.rs
Expand Up @@ -15,6 +15,7 @@ use dom::cssrule::{CSSRule, SpecificCSSRule};
use dom::cssrulelist::{CSSRuleList, RulesSource};
use dom::cssstylesheet::CSSStyleSheet;
use dom::window::Window;
use dom_struct::dom_struct;
use parking_lot::RwLock;
use servo_atoms::Atom;
use std::sync::Arc;
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/cssmediarule.rs
Expand Up @@ -13,6 +13,7 @@ use dom::cssrule::SpecificCSSRule;
use dom::cssstylesheet::CSSStyleSheet;
use dom::medialist::MediaList;
use dom::window::Window;
use dom_struct::dom_struct;
use parking_lot::RwLock;
use std::sync::Arc;
use style::media_queries::parse_media_query_list;
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/cssnamespacerule.rs
Expand Up @@ -10,6 +10,7 @@ use dom::bindings::str::DOMString;
use dom::cssrule::{CSSRule, SpecificCSSRule};
use dom::cssstylesheet::CSSStyleSheet;
use dom::window::Window;
use dom_struct::dom_struct;
use parking_lot::RwLock;
use std::sync::Arc;
use style::stylesheets::NamespaceRule;
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/cssrule.rs
Expand Up @@ -18,6 +18,7 @@ use dom::cssstylesheet::CSSStyleSheet;
use dom::csssupportsrule::CSSSupportsRule;
use dom::cssviewportrule::CSSViewportRule;
use dom::window::Window;
use dom_struct::dom_struct;
use std::cell::Cell;
use style::stylesheets::CssRule as StyleCssRule;

Expand Down
1 change: 1 addition & 0 deletions components/script/dom/cssrulelist.rs
Expand Up @@ -12,6 +12,7 @@ use dom::csskeyframerule::CSSKeyframeRule;
use dom::cssrule::CSSRule;
use dom::cssstylesheet::CSSStyleSheet;
use dom::window::Window;
use dom_struct::dom_struct;
use parking_lot::RwLock;
use std::sync::Arc;
use style::stylesheets::{CssRules, KeyframesRule, RulesMutateError};
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/cssstyledeclaration.rs
Expand Up @@ -13,6 +13,7 @@ use dom::cssrule::CSSRule;
use dom::element::Element;
use dom::node::{Node, window_from_node};
use dom::window::Window;
use dom_struct::dom_struct;
use parking_lot::RwLock;
use servo_url::ServoUrl;
use std::ascii::AsciiExt;
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/cssstylerule.rs
Expand Up @@ -11,6 +11,7 @@ use dom::cssrule::{CSSRule, SpecificCSSRule};
use dom::cssstyledeclaration::{CSSModificationAccess, CSSStyleDeclaration, CSSStyleOwner};
use dom::cssstylesheet::CSSStyleSheet;
use dom::window::Window;
use dom_struct::dom_struct;
use parking_lot::RwLock;
use std::sync::Arc;
use style::stylesheets::StyleRule;
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/cssstylesheet.rs
Expand Up @@ -13,6 +13,7 @@ use dom::cssrulelist::{CSSRuleList, RulesSource};
use dom::element::Element;
use dom::stylesheet::StyleSheet;
use dom::window::Window;
use dom_struct::dom_struct;
use std::cell::Cell;
use std::sync::Arc;
use style::stylesheets::Stylesheet as StyleStyleSheet;
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/csssupportsrule.rs
Expand Up @@ -12,6 +12,7 @@ use dom::cssconditionrule::CSSConditionRule;
use dom::cssrule::SpecificCSSRule;
use dom::cssstylesheet::CSSStyleSheet;
use dom::window::Window;
use dom_struct::dom_struct;
use parking_lot::RwLock;
use std::sync::Arc;
use style::parser::ParserContext;
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/cssviewportrule.rs
Expand Up @@ -9,6 +9,7 @@ use dom::bindings::str::DOMString;
use dom::cssrule::{CSSRule, SpecificCSSRule};
use dom::cssstylesheet::CSSStyleSheet;
use dom::window::Window;
use dom_struct::dom_struct;
use parking_lot::RwLock;
use std::sync::Arc;
use style::viewport::ViewportRule;
Expand Down

0 comments on commit 31e9d81

Please sign in to comment.