mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Remove the url! plugin.
In rust-url 1.0 the `Url` struct is going to have private fields, and there is no way to to create an aribitrary one without going through the parser. The plugin never had a clear demonstrated performance benefit, it was made mostly because it was possible and relatively easy at the time.
This commit is contained in:
parent
87d5424d4d
commit
6889f37d9e
27 changed files with 84 additions and 296 deletions
|
@ -868,7 +868,7 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF>
|
|||
parent_info,
|
||||
window_size,
|
||||
None,
|
||||
LoadData::new(url!("about:failure")));
|
||||
LoadData::new(Url::parse("about:failure").unwrap()));
|
||||
|
||||
self.push_pending_frame(new_pipeline_id, Some(pipeline_id));
|
||||
|
||||
|
@ -951,7 +951,7 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF>
|
|||
// If no url is specified, reload.
|
||||
let new_url = load_info.url.clone()
|
||||
.or_else(|| old_pipeline.map(|old_pipeline| old_pipeline.url.clone()))
|
||||
.unwrap_or_else(|| url!("about:blank"));
|
||||
.unwrap_or_else(|| Url::parse("about:blank").unwrap());
|
||||
|
||||
// Compare the pipeline's url to the new url. If the origin is the same,
|
||||
// then reuse the script thread in creating the new pipeline
|
||||
|
|
|
@ -16,7 +16,6 @@ optional = true
|
|||
|
||||
[dependencies]
|
||||
tenacious = "0.1.2"
|
||||
url = {version = "0.5.7", features = ["heap_size"]}
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
|
|
@ -28,8 +28,6 @@ extern crate syntax;
|
|||
extern crate syntax_ext;
|
||||
extern crate tenacious;
|
||||
|
||||
extern crate url;
|
||||
|
||||
use rustc_plugin::Registry;
|
||||
use syntax::ext::base::*;
|
||||
use syntax::feature_gate::AttributeType::Whitelisted;
|
||||
|
@ -41,8 +39,6 @@ pub mod jstraceable;
|
|||
pub mod lints;
|
||||
/// Autogenerates implementations of Reflectable on DOM structs
|
||||
pub mod reflector;
|
||||
/// The `url!` plugin.
|
||||
mod url_plugin;
|
||||
/// Utilities for writing plugins
|
||||
pub mod utils;
|
||||
|
||||
|
@ -51,7 +47,6 @@ pub fn plugin_registrar(reg: &mut Registry) {
|
|||
reg.register_syntax_extension(intern("dom_struct"), MultiModifier(box jstraceable::expand_dom_struct));
|
||||
reg.register_syntax_extension(intern("derive_JSTraceable"), MultiDecorator(box jstraceable::expand_jstraceable));
|
||||
reg.register_syntax_extension(intern("_generate_reflector"), MultiDecorator(box reflector::expand_reflector));
|
||||
reg.register_macro("url", url_plugin::expand_url);
|
||||
reg.register_late_lint_pass(box lints::transmute_type::TransmutePass);
|
||||
reg.register_late_lint_pass(box lints::unrooted_must_root::UnrootedPass::new());
|
||||
reg.register_late_lint_pass(box lints::privatize::PrivatizePass);
|
||||
|
|
|
@ -1,146 +0,0 @@
|
|||
/* 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/. */
|
||||
|
||||
use std::error::Error;
|
||||
use syntax;
|
||||
use syntax::ast::{Expr, ExprKind, LitKind, TokenTree};
|
||||
use syntax::codemap::Span;
|
||||
use syntax::ext::base::{ExtCtxt, MacResult, MacEager, DummyResult};
|
||||
use syntax::ext::build::AstBuilder;
|
||||
use syntax::fold::Folder;
|
||||
use syntax::parse;
|
||||
use syntax::parse::token::InternedString;
|
||||
use url::{Url, Host, RelativeSchemeData, SchemeData};
|
||||
|
||||
pub fn expand_url(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
|
||||
-> Box<MacResult + 'static> {
|
||||
let mut parser = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), tts.to_vec());
|
||||
let query_expr = cx.expander().fold_expr(parser.parse_expr().unwrap());
|
||||
|
||||
// Ensure a str literal was passed to the macro
|
||||
let query = match parse_str_lit(&query_expr) {
|
||||
Some(query) => query,
|
||||
None => {
|
||||
cx.span_err(query_expr.span, "'url!' expected string literal");
|
||||
return DummyResult::any(sp)
|
||||
},
|
||||
};
|
||||
|
||||
// Parse the str literal
|
||||
let Url { scheme, scheme_data, query, fragment } = match Url::parse(&query) {
|
||||
Ok(url) => url,
|
||||
Err(error) => {
|
||||
cx.span_err(query_expr.span, error.description());
|
||||
return DummyResult::any(sp)
|
||||
}
|
||||
};
|
||||
|
||||
let scheme_data_expr = cx.expr_scheme_data(sp, scheme_data);
|
||||
let query_expr = cx.expr_option_string(sp, query);
|
||||
let fragment_expr = cx.expr_option_string(sp, fragment);
|
||||
|
||||
let url_expr = quote_expr!(cx, {
|
||||
::url::Url {
|
||||
scheme: $scheme.to_owned(),
|
||||
scheme_data: $scheme_data_expr,
|
||||
query: $query_expr,
|
||||
fragment: $fragment_expr,
|
||||
}
|
||||
});
|
||||
|
||||
MacEager::expr(url_expr)
|
||||
}
|
||||
|
||||
fn parse_str_lit(e: &Expr) -> Option<InternedString> {
|
||||
if let ExprKind::Lit(ref lit) = e.node {
|
||||
if let LitKind::Str(ref s, _) = lit.node {
|
||||
return Some(s.clone());
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
trait ExtCtxtHelpers {
|
||||
fn expr_scheme_data(&self, sp: Span, scheme_data: SchemeData) -> syntax::ptr::P<Expr>;
|
||||
fn expr_option_string(&self, sp: Span, string: Option<String>) -> syntax::ptr::P<Expr>;
|
||||
fn expr_option_u16(&self, sp: Span, unsigned: Option<u16>) -> syntax::ptr::P<Expr>;
|
||||
fn expr_host(&self, sp: Span, host: Host) -> syntax::ptr::P<Expr>;
|
||||
fn expr_slice_u16(&self, sp: Span, unsigned: &[u16]) -> syntax::ptr::P<Expr>;
|
||||
fn expr_vec_string(&self, sp: Span, strings: Vec<String>) -> syntax::ptr::P<Expr>;
|
||||
}
|
||||
|
||||
impl<'a> ExtCtxtHelpers for ExtCtxt<'a> {
|
||||
fn expr_scheme_data(&self, sp: Span, scheme_data: SchemeData) -> syntax::ptr::P<Expr> {
|
||||
match scheme_data {
|
||||
SchemeData::Relative(
|
||||
RelativeSchemeData { username, password, host, port, default_port, path }) =>
|
||||
{
|
||||
let password_expr = self.expr_option_string(sp, password);
|
||||
let host_expr = self.expr_host(sp, host);
|
||||
let port_expr = self.expr_option_u16(sp, port);
|
||||
let default_port_expr = self.expr_option_u16(sp, default_port);
|
||||
let path_expr = self.expr_vec_string(sp, path);
|
||||
|
||||
quote_expr!(self,
|
||||
::url::SchemeData::Relative(
|
||||
::url::RelativeSchemeData {
|
||||
username: $username.to_owned(),
|
||||
password: $password_expr,
|
||||
host: $host_expr,
|
||||
port: $port_expr,
|
||||
default_port: $default_port_expr,
|
||||
path: $path_expr.to_owned(),
|
||||
}
|
||||
))
|
||||
},
|
||||
SchemeData::NonRelative(ref scheme_data) => {
|
||||
quote_expr!(self, ::url::SchemeData::NonRelative($scheme_data.to_owned()))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn expr_option_string(&self, sp: Span, string: Option<String>) -> syntax::ptr::P<Expr> {
|
||||
match string {
|
||||
Some(string) => quote_expr!(self, Some($string.to_owned())),
|
||||
None => self.expr_none(sp),
|
||||
}
|
||||
}
|
||||
|
||||
fn expr_option_u16(&self, sp: Span, unsigned: Option<u16>) -> syntax::ptr::P<Expr> {
|
||||
match unsigned {
|
||||
Some(unsigned) => quote_expr!(self, Some($unsigned)),
|
||||
None => self.expr_none(sp),
|
||||
}
|
||||
}
|
||||
|
||||
fn expr_host(&self, _sp: Span, host: Host) -> syntax::ptr::P<Expr> {
|
||||
match host {
|
||||
Host::Domain(domain) => quote_expr!(self, ::url::Host::Domain(String::from($domain))),
|
||||
Host::Ipv6(address) => {
|
||||
let [a, b, c, d, e, f, g, h] = address.segments();
|
||||
quote_expr!(self,
|
||||
::url::Host::Ipv6(::std::net::Ipv6Addr::new(
|
||||
$a, $b, $c, $d, $e, $f, $g, $h
|
||||
)))
|
||||
},
|
||||
Host::Ipv4(address) => {
|
||||
let [a, b, c, d] = address.octets();
|
||||
quote_expr!(self,
|
||||
::url::Host::Ipv4(::std::net::Ipv4Addr::new(
|
||||
$a, $b, $c, $d
|
||||
)))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn expr_slice_u16(&self, sp: Span, unsigned: &[u16]) -> syntax::ptr::P<Expr> {
|
||||
let unsigned = unsigned.iter().map(|p| quote_expr!(self, $p)).collect();
|
||||
self.expr_vec_slice(sp, unsigned)
|
||||
}
|
||||
|
||||
fn expr_vec_string(&self, sp: Span, strings: Vec<String>) -> syntax::ptr::P<Expr> {
|
||||
let strings = strings.iter().map(|p| quote_expr!(self, $p.to_owned())).collect();
|
||||
self.expr_vec(sp, strings)
|
||||
}
|
||||
}
|
|
@ -1603,7 +1603,7 @@ impl Document {
|
|||
source: DocumentSource,
|
||||
doc_loader: DocumentLoader)
|
||||
-> Document {
|
||||
let url = url.unwrap_or_else(|| url!("about:blank"));
|
||||
let url = url.unwrap_or_else(|| Url::parse("about:blank").unwrap());
|
||||
|
||||
let (ready_state, domcontentloaded_dispatched) = if source == DocumentSource::FromParser {
|
||||
(DocumentReadyState::Loading, false)
|
||||
|
|
|
@ -146,7 +146,7 @@ impl HTMLIFrameElement {
|
|||
pub fn process_the_iframe_attributes(&self) {
|
||||
let url = match self.get_url() {
|
||||
Some(url) => url.clone(),
|
||||
None => url!("about:blank"),
|
||||
None => Url::parse("about:blank").unwrap(),
|
||||
};
|
||||
|
||||
self.navigate_or_reload_child_browsing_context(Some(url));
|
||||
|
|
|
@ -1880,7 +1880,7 @@ impl ScriptThread {
|
|||
};
|
||||
|
||||
if load_data.url.scheme == "javascript" {
|
||||
load_data.url = url!("about:blank");
|
||||
load_data.url = Url::parse("about:blank").unwrap();
|
||||
}
|
||||
|
||||
resource_thread.send(ControlMsg::Load(NetLoadData {
|
||||
|
|
10
components/servo/Cargo.lock
generated
10
components/servo/Cargo.lock
generated
|
@ -32,7 +32,6 @@ dependencies = [
|
|||
"net_traits_tests 0.0.1",
|
||||
"offscreen_gl_context 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"plugin_compiletest 0.0.1",
|
||||
"plugin_tests 0.0.1",
|
||||
"profile 0.0.1",
|
||||
"profile_traits 0.0.1",
|
||||
"script 0.0.1",
|
||||
|
@ -1526,20 +1525,11 @@ dependencies = [
|
|||
"script 0.0.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "plugin_tests"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"plugins 0.0.1",
|
||||
"url 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "plugins"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"tenacious 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -33,9 +33,6 @@ path = "../../tests/unit/net"
|
|||
[dev-dependencies.net_traits_tests]
|
||||
path = "../../tests/unit/net_traits"
|
||||
|
||||
[dev-dependencies.plugin_tests]
|
||||
path = "../../tests/unit/plugin"
|
||||
|
||||
[dev-dependencies.script_tests]
|
||||
path = "../../tests/unit/script"
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ fn parse_one_src(context: &ParserContext, input: &mut Parser) -> Result<Source,
|
|||
}
|
||||
let url = try!(input.expect_url());
|
||||
let url = context.base_url.join(&url).unwrap_or_else(
|
||||
|_error| url!("about:invalid"));
|
||||
|_error| Url::parse("about:invalid").unwrap());
|
||||
|
||||
// Parsing optional format()
|
||||
let format_hints = if input.try(|input| input.expect_function_matching("format")).is_ok() {
|
||||
|
|
|
@ -34,7 +34,7 @@ impl<'a> ParserContext<'a> {
|
|||
impl<'a> ParserContext<'a> {
|
||||
pub fn parse_url(&self, input: &str) -> Url {
|
||||
self.base_url.join(input)
|
||||
.unwrap_or_else(|_| url!("about:invalid"))
|
||||
.unwrap_or_else(|_| Url::parse("about:invalid").unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ lazy_static! {
|
|||
Ok(res) => {
|
||||
Stylesheet::from_bytes(
|
||||
&res,
|
||||
url!("chrome:///quirks-mode.css"),
|
||||
Url::parse("chrome:///quirks-mode.css").unwrap(),
|
||||
None,
|
||||
None,
|
||||
Origin::UserAgent,
|
||||
|
|
|
@ -463,7 +463,7 @@ const DEFAULT_USER_AGENT: UserAgent = UserAgent::Desktop;
|
|||
pub fn default_opts() -> Opts {
|
||||
Opts {
|
||||
is_running_problem_test: false,
|
||||
url: Some(url!("about:blank")),
|
||||
url: Some(Url::parse("about:blank").unwrap()),
|
||||
paint_threads: 1,
|
||||
gpu_painting: false,
|
||||
tile_size: 512,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue