Skip to content

Commit 577f32b

Browse files
committed
servo: Merge #15715 - Make #[dom_struct] a proc_macro attribute (from nox:custom-derive); r=SimonSapin
The rustup is needed for rust-lang/rust#40039. Source-Repo: https://github.com/servo/servo Source-Revision: a204c4176dcccdad8ec99d74055c66794c3f64ba
1 parent 18031b5 commit 577f32b

File tree

253 files changed

+307
-45
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

253 files changed

+307
-45
lines changed

servo/Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "dom_struct"
3+
version = "0.0.1"
4+
authors = ["The Servo Project Developers"]
5+
license = "MPL-2.0"
6+
publish = false
7+
8+
[lib]
9+
path = "lib.rs"
10+
proc-macro = true
11+
12+
[dependencies]
13+
quote = "0.3"

servo/components/dom_struct/lib.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
#![feature(proc_macro)]
6+
7+
extern crate proc_macro;
8+
#[macro_use] extern crate quote;
9+
10+
use proc_macro::TokenStream;
11+
12+
#[proc_macro_attribute]
13+
pub fn dom_struct(args: TokenStream, input: TokenStream) -> TokenStream {
14+
if !args.to_string().is_empty() {
15+
panic!("#[dom_struct] takes no arguments");
16+
}
17+
expand_string(&input.to_string()).parse().unwrap()
18+
}
19+
20+
fn expand_string(input: &str) -> String {
21+
let mut tokens = quote! {
22+
#[derive(DenyPublicFields, DomObject, HeapSizeOf, JSTraceable)]
23+
#[must_root]
24+
#[repr(C)]
25+
};
26+
tokens.append(input);
27+
tokens.to_string()
28+
}

servo/components/script/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ cookie = "0.2.5"
3737
cssparser = {version = "0.10", features = ["heapsize", "serde"]}
3838
deny_public_fields = {path = "../deny_public_fields"}
3939
devtools_traits = {path = "../devtools_traits"}
40+
dom_struct = {path = "../dom_struct"}
4041
domobject_derive = {path = "../domobject_derive"}
4142
encoding = "0.2"
4243
euclid = "0.11"

servo/components/script/docs/JS-Servos-only-GC.md

Lines changed: 2 additions & 0 deletions

servo/components/script/dom/attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use dom::bindings::str::DOMString;
1212
use dom::element::{AttributeMutation, Element};
1313
use dom::virtualmethods::vtable_for;
1414
use dom::window::Window;
15+
use dom_struct::dom_struct;
1516
use html5ever_atoms::{Prefix, LocalName, Namespace};
1617
use servo_atoms::Atom;
1718
use std::borrow::ToOwned;

servo/components/script/dom/beforeunloadevent.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use dom::bindings::reflector::reflect_dom_object;
1414
use dom::bindings::str::DOMString;
1515
use dom::event::{Event, EventBubbles, EventCancelable};
1616
use dom::window::Window;
17+
use dom_struct::dom_struct;
1718
use servo_atoms::Atom;
1819

1920
// https://html.spec.whatwg.org/multipage/#beforeunloadevent

servo/components/script/dom/bindings/iterable.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use dom::bindings::js::{JS, Root};
1414
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
1515
use dom::bindings::trace::JSTraceable;
1616
use dom::globalscope::GlobalScope;
17+
use dom_struct::dom_struct;
1718
use js::conversions::ToJSValConvertible;
1819
use js::jsapi::{HandleValue, Heap, JSContext, JSObject, MutableHandleObject};
1920
use js::jsval::UndefinedValue;

servo/components/script/dom/blob.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use dom::bindings::js::{JS, Root};
1111
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
1212
use dom::bindings::str::DOMString;
1313
use dom::globalscope::GlobalScope;
14+
use dom_struct::dom_struct;
1415
use encoding::all::UTF_8;
1516
use encoding::types::{EncoderTrap, Encoding};
1617
use ipc_channel::ipc;

servo/components/script/dom/bluetooth.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use dom::eventtarget::EventTarget;
3030
use dom::globalscope::GlobalScope;
3131
use dom::permissions::{get_descriptor_permission_state, PermissionAlgorithm};
3232
use dom::promise::Promise;
33+
use dom_struct::dom_struct;
3334
use ipc_channel::ipc::{self, IpcSender};
3435
use ipc_channel::router::ROUTER;
3536
use js::conversions::ConversionResult;

0 commit comments

Comments
 (0)