No bug - Revendor rust dependencies

This commit is contained in:
Servo VCS Sync 2017-04-25 00:10:45 +00:00
Родитель c23b19c46c
Коммит f14375be16
14 изменённых файлов: 122 добавлений и 176 удалений

Просмотреть файл

@ -1 +1 @@
{"files":{".cargo-ok":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","Cargo.toml":"e740a473ab5e2339d639a86f1996b1ecc72f25b25f23b2789c836bff1455cf5a","lib.rs":"2b54cf96da2049eb03e4b30a223124e7f5a9c067975d54ec0ecf92f0245777a1"},"package":"b8f0415de0bdbce823c0db204e00a62c8240fa2d3e04cd13ff7c6396e4446b95"}
{"files":{".cargo-ok":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","Cargo.toml":"3080a72e897022e23ede1dd38cf28049e74a077518cc25d91f559c3b575aa3e3","lib.rs":"17331a3a0b0be3c05fe360e08538baf26b343ae61feec9062429a34a1c1eb1e2"},"package":"079adec4af52bb5275eadd004292028c79eb3c5f5b4ee8086a36d4197032f6df"}

Просмотреть файл

@ -1,6 +1,6 @@
[package]
name = "cssparser-macros"
version = "0.2.0"
version = "0.3.0"
authors = ["Simon Sapin <simon.sapin@exyr.org>"]
description = "Procedural macros for cssparser"
documentation = "https://docs.rs/cssparser-macros/"

10
third_party/rust/cssparser-macros/lib.rs поставляемый
Просмотреть файл

@ -26,17 +26,9 @@ define_proc_macros! {
};
max_len(arms.iter().flat_map(|arm| &arm.pats).filter_map(|pattern| {
let expr = match *pattern {
syn::Pat::Lit(ref expr) => expr,
syn::Pat::Wild |
syn::Pat::Ident(_, _, None) => return None,
syn::Pat::Ident(_, _, Some(ref sub_pattern)) => {
match **sub_pattern {
syn::Pat::Lit(ref expr) => expr,
syn::Pat::Wild => return None,
_ => panic!("expected string or wildcard pattern, got {:?}", pattern)
}
}
_ => panic!("expected string or wildcard pattern, got {:?}", pattern)
};
match **expr {
syn::Expr { node: syn::ExprKind::Lit(syn::Lit::Str(ref string, _)), .. } => {
@ -62,7 +54,7 @@ define_proc_macros! {
/// and the corresponding value as a const expression.
///
/// Output: a rust-phf map, with keys ASCII-lowercased:
/// ```
/// ```text
/// static MAP: &'static ::cssparser::phf::Map<&'static str, $ValueType> = …;
/// ```
#[allow(non_snake_case)]

Просмотреть файл

@ -1 +1 @@
{"files":{".cargo-ok":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",".gitignore":"e32812a8f09b0c5b0b972e2e090f8929eb5b600a37ca7aac2ed07ba10c30291e",".travis.yml":"f1fb4b65964c81bc1240544267ea334f554ca38ae7a74d57066f4d47d2b5d568","Cargo.toml":"410baf41d446e2e281eabe0c52a0b094b457dbb5d7c096fcfbd6ce4e5e01b998","LICENSE":"fab3dd6bdab226f1c08630b1dd917e11fcb4ec5e1e020e2c16f83a0a13863e85","README.md":"9afe084d70a5d9396674a2624012d6ac749df35f81e322d2d75b042bf208f523","build.rs":"950bcc47a196f07f99f59637c28cc65e02a885130011f90a2b2608248b4724a2","build/match_byte.rs":"89e8b941af74df2c204abf808672d3ff278bdec75abc918c41a843260b924677","docs/.nojekyll":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","docs/404.html":"025861f76f8d1f6d67c20ab624c6e418f4f824385e2dd8ad8732c4ea563c6a2e","docs/index.html":"025861f76f8d1f6d67c20ab624c6e418f4f824385e2dd8ad8732c4ea563c6a2e","src/big-data-url.css":"04a8f6197ea1181123bca48bd1ebd016268e1da40f01b8f21055814e44bf62b8","src/color.rs":"09249793df09c51ce0f2a8eabae85405cfdbd8c23330bb121f8b61665df853fd","src/css-parsing-tests/An+B.json":"d24559c1dad55d3da9d1fca29383edefdfc6046988435d6388a9bc0f28850257","src/css-parsing-tests/LICENSE":"5f9019a92f4aa8917aadc8e035aa673c2c1bf08d5ca2e535a0564106599f44eb","src/css-parsing-tests/README.rst":"775c5f957dd1d46d3ce954aaad219c821d2b64b4a9fb93c42e9737a11131ca44","src/css-parsing-tests/color3.json":"5104348cc58a10d113ad4c20f05bdba846ecb4920ee606203fe5d28a6a9f0a13","src/css-parsing-tests/color3_hsl.json":"88936185b3ead36f8613372bf595024073d7787adbf659a62446789a2504b59f","src/css-parsing-tests/color3_keywords.json":"95609bf9fe762c316878a30f371fa375a2e51c21a6fda24fa188a95cd9118f5c","src/css-parsing-tests/component_value_list.json":"dda7244eb3a4fcf6d296762e285f7031028837d987065a09e584e8d973edc7f3","src/css-parsing-tests/declaration_list.json":"0b85cc3f19e945f838432acbfb9edb003abea13debc4ea27bcdcef25d117eac5","src/css-parsing-tests/make_color3_hsl.py":"6297d9fb7b23875ccf99111a56a8e971a37c4206d7d6782001e95a7194fa6182","src/css-parsing-tests/make_color3_keywords.py":"66bccab3f1dea18698fcfd854be79b1fd1cd724dd487e25b1f057b522163aad2","src/css-parsing-tests/one_component_value.json":"8798017709002e14cf11e203c9d716f82d308ce6ba0f6e64ee4eea331b8485c6","src/css-parsing-tests/one_declaration.json":"a34c9da56edfff9e2e21615f059e141b0e878e90f794dc8fa58d65b47cd193ed","src/css-parsing-tests/one_rule.json":"88f7b1b6049be88e1e2827673b75fc9261986b216e8ee6bf09621fecbe274e3c","src/css-parsing-tests/rule_list.json":"97c45e80fb83abef149a4016c5625a74f053e7ad70a2ce5a95c02fce1c195686","src/css-parsing-tests/stylesheet.json":"05f1e10fc486bfbda2c059c313a74ff78c0063c0768b99737cab41969c0c87ce","src/css-parsing-tests/stylesheet_bytes.json":"890fd856a596e61f82cf7ed77920ffe95df89209fdb5ee0afe0b26bdfdb80a42","src/css-parsing-tests/urange.json":"90a0348cb785f8761d956458880486136de75f2c7ce44ec66da233f73d9098bf","src/from_bytes.rs":"331fe63af2123ae3675b61928a69461b5ac77799fff3ce9978c55cf2c558f4ff","src/lib.rs":"ccc0f04541147d4fb90d3fe70591bacfb0c7030706c9be8fa60b80533e522bbc","src/macros.rs":"bd492479eee8c65850bdfc2c9de100eddc224e5d6629cd583219058901cd0ca7","src/nth.rs":"0a5e68bd8a597403e184ebf34e69230ae1e955f92b16b99b3f67cf8730a180a9","src/parser.rs":"a41b1d885389d34b4d81176f844ae3c4100e621628dd50d7348c42b08cdd13ae","src/rules_and_declarations.rs":"6b66a986e411a56998546ab0e64de5285df3368d7c4018c7230a1b6cf6bcc532","src/serializer.rs":"480043750508944fb75295d8638b6b33665273a2ac5791ec8261ae1fe63c0fcd","src/tests.rs":"80e4fec507258fe4e63a590f842f3213b44418cd69d755f78f938894966037db","src/tokenizer.rs":"945c29ff9f4a79d58aee956e27c8b476068859d878ead7c7fed83a9e89d2159f","src/unicode_range.rs":"fa0198eb00a68cd71d009551194a3f6d2cb0501513b77d9ea2fea22bfa45c141"},"package":"fb067f9d88368ca9053aea00581556151ef96f2591e32ad44f3312d7e6b67392"}
{"files":{".cargo-ok":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",".gitignore":"0b944a5f5edfe3dca4796907e63f537a0e919630df66dca7945d51ba4e3c8051",".travis.yml":"f1fb4b65964c81bc1240544267ea334f554ca38ae7a74d57066f4d47d2b5d568","Cargo.toml":"a6a5eab45b7398c4930ad529f4bf3f77b70fd4a3ea8c82fff5bb93ae305eacf9","LICENSE":"fab3dd6bdab226f1c08630b1dd917e11fcb4ec5e1e020e2c16f83a0a13863e85","README.md":"9afe084d70a5d9396674a2624012d6ac749df35f81e322d2d75b042bf208f523","build.rs":"950bcc47a196f07f99f59637c28cc65e02a885130011f90a2b2608248b4724a2","build/match_byte.rs":"89e8b941af74df2c204abf808672d3ff278bdec75abc918c41a843260b924677","docs/.nojekyll":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","docs/404.html":"025861f76f8d1f6d67c20ab624c6e418f4f824385e2dd8ad8732c4ea563c6a2e","docs/index.html":"025861f76f8d1f6d67c20ab624c6e418f4f824385e2dd8ad8732c4ea563c6a2e","src/big-data-url.css":"04a8f6197ea1181123bca48bd1ebd016268e1da40f01b8f21055814e44bf62b8","src/color.rs":"0751c51a39a2d5d03dd5c41405bafc791eb12b508b7347d3a48ebddd97b67ba3","src/css-parsing-tests/An+B.json":"d24559c1dad55d3da9d1fca29383edefdfc6046988435d6388a9bc0f28850257","src/css-parsing-tests/LICENSE":"5f9019a92f4aa8917aadc8e035aa673c2c1bf08d5ca2e535a0564106599f44eb","src/css-parsing-tests/README.rst":"775c5f957dd1d46d3ce954aaad219c821d2b64b4a9fb93c42e9737a11131ca44","src/css-parsing-tests/color3.json":"6a09e71e7095374a6b44b9cb4341b7f675afe66a93427c62a9a0ff5f8c20ac6f","src/css-parsing-tests/color3_hsl.json":"88936185b3ead36f8613372bf595024073d7787adbf659a62446789a2504b59f","src/css-parsing-tests/color3_keywords.json":"95609bf9fe762c316878a30f371fa375a2e51c21a6fda24fa188a95cd9118f5c","src/css-parsing-tests/component_value_list.json":"dda7244eb3a4fcf6d296762e285f7031028837d987065a09e584e8d973edc7f3","src/css-parsing-tests/declaration_list.json":"0b85cc3f19e945f838432acbfb9edb003abea13debc4ea27bcdcef25d117eac5","src/css-parsing-tests/make_color3_hsl.py":"d7c3533f5f7158da10fa5c34ae5e1bd2b3b0da5d2ca90c16b6cd76f310f22941","src/css-parsing-tests/make_color3_keywords.py":"66bccab3f1dea18698fcfd854be79b1fd1cd724dd487e25b1f057b522163aad2","src/css-parsing-tests/one_component_value.json":"8798017709002e14cf11e203c9d716f82d308ce6ba0f6e64ee4eea331b8485c6","src/css-parsing-tests/one_declaration.json":"a34c9da56edfff9e2e21615f059e141b0e878e90f794dc8fa58d65b47cd193ed","src/css-parsing-tests/one_rule.json":"88f7b1b6049be88e1e2827673b75fc9261986b216e8ee6bf09621fecbe274e3c","src/css-parsing-tests/rule_list.json":"97c45e80fb83abef149a4016c5625a74f053e7ad70a2ce5a95c02fce1c195686","src/css-parsing-tests/stylesheet.json":"05f1e10fc486bfbda2c059c313a74ff78c0063c0768b99737cab41969c0c87ce","src/css-parsing-tests/stylesheet_bytes.json":"890fd856a596e61f82cf7ed77920ffe95df89209fdb5ee0afe0b26bdfdb80a42","src/css-parsing-tests/urange.json":"62720b143ddf52508baad42921473dd69519aad6c1cd49f37f3f264dc29e1c13","src/from_bytes.rs":"331fe63af2123ae3675b61928a69461b5ac77799fff3ce9978c55cf2c558f4ff","src/lib.rs":"ccc0f04541147d4fb90d3fe70591bacfb0c7030706c9be8fa60b80533e522bbc","src/macros.rs":"adb9773c157890381556ea83d7942dcc676f99eea71abbb6afeffee1e3f28960","src/nth.rs":"0a5e68bd8a597403e184ebf34e69230ae1e955f92b16b99b3f67cf8730a180a9","src/parser.rs":"a41b1d885389d34b4d81176f844ae3c4100e621628dd50d7348c42b08cdd13ae","src/rules_and_declarations.rs":"6b66a986e411a56998546ab0e64de5285df3368d7c4018c7230a1b6cf6bcc532","src/serializer.rs":"480043750508944fb75295d8638b6b33665273a2ac5791ec8261ae1fe63c0fcd","src/tests.rs":"80e4fec507258fe4e63a590f842f3213b44418cd69d755f78f938894966037db","src/tokenizer.rs":"945c29ff9f4a79d58aee956e27c8b476068859d878ead7c7fed83a9e89d2159f","src/unicode_range.rs":"f1f1dee3cc4efb6647557c6166aa5a93354fc0ee9beba53c1d63427beffe5a8d"},"package":"b39404c5e04492194e3c69f1a10964b980f2c95c884a940f7903446779f6b027"}

2
third_party/rust/cssparser/.gitignore поставляемый
Просмотреть файл

@ -1,3 +1,3 @@
/target
target
/Cargo.lock
/.cargo/config

4
third_party/rust/cssparser/Cargo.toml поставляемый
Просмотреть файл

@ -1,7 +1,7 @@
[package]
name = "cssparser"
version = "0.12.2"
version = "0.13.1"
authors = [ "Simon Sapin <simon.sapin@exyr.org>" ]
description = "Rust implementation of CSS Syntax Level 3"
@ -20,7 +20,7 @@ difference = "1.0"
encoding_rs = "0.5"
[dependencies]
cssparser-macros = {path = "./macros", version = "0.2"}
cssparser-macros = {path = "./macros", version = "0.3"}
heapsize = {version = "0.3", optional = true}
matches = "0.1"
phf = "0.7"

59
third_party/rust/cssparser/src/color.rs поставляемый
Просмотреть файл

@ -2,7 +2,6 @@
* 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::cmp;
use std::fmt;
use std::f32::consts::PI;
@ -31,7 +30,12 @@ impl RGBA {
/// clamped to the 0.0 ... 1.0 range.
#[inline]
pub fn from_floats(red: f32, green: f32, blue: f32, alpha: f32) -> Self {
Self::new(clamp_f32(red), clamp_f32(green), clamp_f32(blue), clamp_f32(alpha))
Self::new(
clamp_unit_f32(red),
clamp_unit_f32(green),
clamp_unit_f32(blue),
clamp_unit_f32(alpha),
)
}
/// Returns a transparent color.
@ -99,7 +103,7 @@ impl ToCss for RGBA {
{
// Try first with two decimal places, then with three.
let mut rounded_alpha = (self.alpha_f32() * 100.).round() / 100.;
if clamp_f32(rounded_alpha) != self.alpha {
if clamp_unit_f32(rounded_alpha) != self.alpha {
rounded_alpha = (self.alpha_f32() * 1000.).round() / 1000.;
}
@ -381,12 +385,7 @@ fn parse_color_hash(value: &str) -> Result<Color, ()> {
}
}
fn clamp_i32(val: i32) -> u8 {
cmp::min(cmp::max(0, val), 255) as u8
}
fn clamp_f32(val: f32) -> u8 {
fn clamp_unit_f32(val: f32) -> u8 {
// Scale by 256, not 255, so that each of the 256 u8 values has an equal range
// of f32 values mapping to it. Floor before clamping.
//
@ -394,23 +393,21 @@ fn clamp_f32(val: f32) -> u8 {
// `256.0_f32 as u8` is undefined behavior:
//
// https://github.com/rust-lang/rust/issues/10184
(val * 256.).floor().max(0.).min(255.) as u8
clamp_256_f32(val * 256.)
}
fn clamp_256_f32(val: f32) -> u8 {
val.floor().max(0.).min(255.) as u8
}
#[inline]
fn parse_color_function(name: &str, arguments: &mut Parser) -> Result<Color, ()> {
let is_rgb = match_ignore_ascii_case! { name,
"rgb" | "rgba" => true,
"hsl" | "hsla" => false,
let (red, green, blue, uses_commas) = match_ignore_ascii_case! { name,
"rgb" | "rgba" => parse_rgb_components_rgb(arguments)?,
"hsl" | "hsla" => parse_rgb_components_hsl(arguments)?,
_ => return Err(())
};
let (red, green, blue, uses_commas) = if is_rgb {
parse_rgb_components_rgb(arguments)?
} else {
parse_rgb_components_hsl(arguments)?
};
let alpha = if !arguments.is_exhausted() {
if uses_commas {
try!(arguments.expect_comma());
@ -423,10 +420,10 @@ fn parse_color_function(name: &str, arguments: &mut Parser) -> Result<Color, ()>
let token = try!(arguments.next());
match token {
Token::Number(NumericValue { value: v, .. }) => {
clamp_f32(v)
clamp_unit_f32(v)
}
Token::Percentage(ref v) => {
clamp_f32(v.unit_value)
clamp_unit_f32(v.unit_value)
}
_ => {
return Err(())
@ -452,23 +449,23 @@ fn parse_rgb_components_rgb(arguments: &mut Parser) -> Result<(u8, u8, u8, bool)
// https://drafts.csswg.org/css-color/#rgb-functions
match try!(arguments.next()) {
Token::Number(NumericValue { value: v, .. }) => {
red = clamp_i32(v as i32);
green = clamp_i32(match try!(arguments.next()) {
red = clamp_256_f32(v);
green = clamp_256_f32(match try!(arguments.next()) {
Token::Number(NumericValue { value: v, .. }) => v,
Token::Comma => {
uses_commas = true;
try!(arguments.expect_number())
}
_ => return Err(())
} as i32);
});
if uses_commas {
try!(arguments.expect_comma());
}
blue = clamp_i32(try!(arguments.expect_number()) as i32);
blue = clamp_256_f32(try!(arguments.expect_number()));
}
Token::Percentage(ref v) => {
red = clamp_f32(v.unit_value);
green = clamp_f32(match try!(arguments.next()) {
red = clamp_unit_f32(v.unit_value);
green = clamp_unit_f32(match try!(arguments.next()) {
Token::Percentage(ref v) => v.unit_value,
Token::Comma => {
uses_commas = true;
@ -479,7 +476,7 @@ fn parse_rgb_components_rgb(arguments: &mut Parser) -> Result<(u8, u8, u8, bool)
if uses_commas {
try!(arguments.expect_comma());
}
blue = clamp_f32(try!(arguments.expect_percentage()));
blue = clamp_unit_f32(try!(arguments.expect_percentage()));
}
_ => return Err(())
};
@ -542,8 +539,8 @@ fn parse_rgb_components_hsl(arguments: &mut Parser) -> Result<(u8, u8, u8, bool)
else { lightness + saturation - lightness * saturation };
let m1 = lightness * 2. - m2;
let hue_times_3 = hue * 3.;
let red = clamp_f32(hue_to_rgb(m1, m2, hue_times_3 + 1.));
let green = clamp_f32(hue_to_rgb(m1, m2, hue_times_3));
let blue = clamp_f32(hue_to_rgb(m1, m2, hue_times_3 - 1.));
let red = clamp_unit_f32(hue_to_rgb(m1, m2, hue_times_3 + 1.));
let green = clamp_unit_f32(hue_to_rgb(m1, m2, hue_times_3));
let blue = clamp_unit_f32(hue_to_rgb(m1, m2, hue_times_3 - 1.));
return Ok((red, green, blue, uses_commas));
}

Просмотреть файл

@ -253,5 +253,8 @@
"hsl(10.4719755118rad, 75%, 50%)", [32, 32, 224, 255],
"hsl(2.6666666666turn, 75%, 50%)", [32, 32, 224, 255],
"rgb(-2147483649, 4294967298, -18446744073709551619) /* https://github.com/w3c/web-platform-tests/blob/master/2dcontext/fill-and-stroke-styles/2d.fillStyle.parse.rgb-clamp-3.html */",
[0, 255, 0, 255],
"cmyk(0, 0, 0, 0)", null
]

Просмотреть файл

@ -2,18 +2,32 @@ import colorsys # It turns out Python already does HSL -> RGB!
trim = lambda s: s if not s.endswith('.0') else s[:-2]
print('[')
print(',\n'.join(
f[0] % (
(n, h, trim(str(s/10.)), trim(str(l/10.)),
f[1] % round(a / 255., 2) if a is not None else '')
+ tuple(trim(str(min(255, v * 256)))
for v in colorsys.hls_to_rgb(h/360., l/1000., s/1000.))
+ (a if a is not None else 255,)
function_format % tuple(
[
function_name,
hue,
trim(str(saturation / 10.)),
trim(str(lightness / 10.)),
alpha_format % round(alpha / 255., 2) if alpha is not None else ''
] + [
trim(str(min(255, component * 256)))
for component in colorsys.hls_to_rgb(
hue / 360.,
lightness / 1000.,
saturation / 1000.
)
for f in [('"%s(%s, %s%%, %s%%%s)", [%s, %s, %s, %s]', ', %s'), ('"%s(%s %s%% %s%%%s)", [%s, %s, %s, %s]', ' / %s')]
for n in ["hsl", "hsla"]
for a in [None, 255, 64, 0]
for l in range(0, 1001, 125)
for s in range(0, 1001, 125)
for h in range(0, 360, 30)
] + [
alpha if alpha is not None else 255
]
)
for function_format, alpha_format in [
('"%s(%s, %s%%, %s%%%s)", [%s, %s, %s, %s]', ', %s'),
('"%s(%s %s%% %s%%%s)", [%s, %s, %s, %s]', ' / %s')
]
for function_name in ["hsl", "hsla"]
for alpha in [None, 255, 64, 0]
for lightness in range(0, 1001, 125)
for saturation in range(0, 1001, 125)
for hue in range(0, 360, 30)
))
print(']')

Просмотреть файл

@ -60,6 +60,10 @@
[0, 4095]
],
"U+4E-9F", [
[78, 159]
],
"u+20-3F, u+3F-3F, u+3F-3E, U+0-110000, U+0-10FFFF, U+100000-2, U+1000000-2, U+10-200000", [
[32, 63],
[63, 63],

4
third_party/rust/cssparser/src/macros.rs поставляемый
Просмотреть файл

@ -22,7 +22,7 @@ define_invoke_proc_macro!(cssparser_internal__invoke_proc_macro);
/// "rgba" => parse_rgba(..),
/// "hsl" => parse_hsl(..),
/// "hsla" => parse_hsla(..),
/// name @ _ => Err(format!("unknown function: {}", name))
/// _ => Err(format!("unknown function: {}", function_name))
/// }
/// # ;}
/// # use std::ops::RangeFull;
@ -82,7 +82,7 @@ macro_rules! ascii_case_insensitive_phf_map {
ascii_case_insensitive_phf_map!($name -> $ValueType = { $( $key => $value, )* })
};
($name: ident -> $ValueType: ty = { $( $key: expr => $value: expr, )* }) => {
fn $name(input: &str) -> Option<&'static $ValueType> {
pub fn $name(input: &str) -> Option<&'static $ValueType> {
cssparser_internal__invoke_proc_macro! {
cssparser_internal__phf_map!( ($ValueType) $( $key ($value) )+ )
}

Просмотреть файл

@ -8,8 +8,7 @@ use {Parser, ToCss};
use std::char;
use std::cmp;
use std::fmt;
use std::io::{self, Write};
use tokenizer::{Token, NumericValue};
use tokenizer::Token;
/// One contiguous range of code points.
///
@ -35,22 +34,15 @@ impl UnicodeRange {
// u '+' '?'+
input.expect_ident_matching("u")?;
let after_u = input.position();
parse_tokens(input)?;
// Since start or end cant be above 0x10FFFF, they cant have more than 6 hex digits
// Conversely, input with more digits would end up returning Err anyway.
const MAX_LENGTH_AFTER_U_PLUS: usize = 6 + 1 + 6; // 6 digits, '-', 6 digits
let mut buffer = [0; MAX_LENGTH_AFTER_U_PLUS];
// This deviates from the spec in case there are CSS comments
// between tokens in the middle of one <unicode-range>,
// but oh well…
let concatenated_tokens = input.slice_from(after_u);
let remaining_len;
{
let mut remaining = &mut buffer[..];
concatenate_tokens(input, &mut remaining)?;
remaining_len = remaining.len();
}
let text_len = buffer.len() - remaining_len;
let text = &buffer[..text_len];
let range = parse_concatenated(text)?;
let range = parse_concatenated(concatenated_tokens.as_bytes())?;
if range.end > char::MAX as u32 || range.start > range.end {
Err(())
} else {
@ -59,93 +51,52 @@ impl UnicodeRange {
}
}
fn concatenate_tokens(input: &mut Parser, remaining: &mut &mut [u8]) -> Result<(), Error> {
fn parse_tokens(input: &mut Parser) -> Result<(), ()> {
match input.next_including_whitespace()? {
Token::Delim('+') => {
match input.next_including_whitespace()? {
Token::Ident(ident) => remaining.write_all(ident.as_bytes())?,
Token::Delim('?') => remaining.write_all(b"?")?,
_ => return Err(Error)
Token::Ident(_) => {}
Token::Delim('?') => {}
_ => return Err(())
}
parse_question_marks(input, remaining)
parse_question_marks(input)
}
Token::Dimension(ref value, ref unit) => {
// Require a '+' sign as part of the number
let int_value = positive_integer_with_plus_sign(value)?;
write!(remaining, "{}{}", int_value, unit)?;
parse_question_marks(input, remaining)
Token::Dimension(..) => {
parse_question_marks(input)
}
Token::Number(ref value) => {
// Require a '+' sign as part of the number
let int_value = positive_integer_with_plus_sign(value)?;
write!(remaining, "{}", int_value)?;
Token::Number(_) => {
let after_number = input.position();
match input.next_including_whitespace() {
Ok(Token::Delim('?')) => {
// If `remaining` is already full, `int_value` has too many digits
// so we can use `result?` Rust syntax.
remaining.write_all(b"?")?;
parse_question_marks(input, remaining)
}
Ok(Token::Dimension(ref value, ref unit)) => {
// Require a '-' sign as part of the number
let int_value = negative_integer(value)?;
write!(remaining, "{}{}", int_value, unit)?
}
Ok(Token::Number(ref value)) => {
// Require a '-' sign as part of the number
let int_value = negative_integer(value)?;
write!(remaining, "{}", int_value)?
}
Ok(Token::Delim('?')) => parse_question_marks(input),
Ok(Token::Dimension(..)) => {}
Ok(Token::Number(_)) => {}
_ => input.reset(after_number)
}
}
_ => return Err(Error)
_ => return Err(())
}
Ok(())
}
/// Consume as many '?' as possible and write them to `remaining` until its full
fn parse_question_marks(input: &mut Parser, remaining: &mut &mut [u8]) {
/// Consume as many '?' as possible
fn parse_question_marks(input: &mut Parser) {
loop {
let result = input.try(|input| {
let position = input.position();
match input.next_including_whitespace() {
Ok(Token::Delim('?')) => remaining.write_all(b"?").map_err(|_| ()),
_ => Err(())
}
});
if result.is_err() {
Ok(Token::Delim('?')) => {}
_ => {
input.reset(position);
return
}
}
}
fn positive_integer_with_plus_sign(value: &NumericValue) -> Result<i32, ()> {
let int_value = value.int_value.ok_or(())?;
if value.has_sign && int_value >= 0 {
Ok(int_value)
} else {
Err(())
}
}
fn negative_integer(value: &NumericValue) -> Result<i32, ()> { // Necessarily had a negative sign.
let int_value = value.int_value.ok_or(())?;
if int_value <= 0 {
Ok(int_value)
} else {
Err(())
}
}
fn parse_concatenated(mut text: &[u8]) -> Result<UnicodeRange, ()> {
fn parse_concatenated(text: &[u8]) -> Result<UnicodeRange, ()> {
let mut text = match text.split_first() {
Some((&b'+', text)) => text,
_ => return Err(())
};
let (first_hex_value, hex_digit_count) = consume_hex(&mut text);
let question_marks = consume_question_marks(&mut text);
let consumed = hex_digit_count + question_marks;
@ -241,18 +192,3 @@ impl ToCss for UnicodeRange {
Ok(())
}
}
/// Make conversions from io::Error implicit in `?` syntax.
struct Error;
impl From<Error> for () {
fn from(_: Error) -> Self { () }
}
impl From<()> for Error {
fn from(_: ()) -> Self { Error }
}
impl From<io::Error> for Error {
fn from(_: io::Error) -> Self { Error }
}

18
toolkit/library/gtest/rust/Cargo.lock сгенерированный
Просмотреть файл

@ -181,10 +181,10 @@ dependencies = [
[[package]]
name = "cssparser"
version = "0.12.2"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cssparser-macros 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser-macros 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
"procedural-masquerade 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -194,7 +194,7 @@ dependencies = [
[[package]]
name = "cssparser-macros"
version = "0.2.0"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"phf_codegen 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
@ -302,7 +302,7 @@ name = "geckoservo"
version = "0.0.1"
dependencies = [
"atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
@ -687,7 +687,7 @@ name = "selectors"
version = "0.18.0"
dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"precomputed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -767,7 +767,7 @@ dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -797,7 +797,7 @@ name = "style_traits"
version = "0.0.1"
dependencies = [
"app_units 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -1093,8 +1093,8 @@ dependencies = [
"checksum core-foundation-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "41115a6aa5d3e1e5ef98148373f25971d1fad53818553f216495f9e67e90a624"
"checksum core-graphics 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ead017dcf77f503dc991f6b52de6084eeea60a94b0a652baa9bf88654a28e83f"
"checksum core-text 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0e9719616a10f717628e074744f8c55df7b450f7a34d29c196d14f4498aad05d"
"checksum cssparser 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fb067f9d88368ca9053aea00581556151ef96f2591e32ad44f3312d7e6b67392"
"checksum cssparser-macros 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f0415de0bdbce823c0db204e00a62c8240fa2d3e04cd13ff7c6396e4446b95"
"checksum cssparser 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b39404c5e04492194e3c69f1a10964b980f2c95c884a940f7903446779f6b027"
"checksum cssparser-macros 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "079adec4af52bb5275eadd004292028c79eb3c5f5b4ee8086a36d4197032f6df"
"checksum deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1614659040e711785ed8ea24219140654da1729f3ec8a47a9719d041112fe7bf"
"checksum dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "80c8b71fd71146990a9742fc06dcbbde19161a267e0ad4e572c35162f4578c90"
"checksum dwrote 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "74114b6b49d6731835da7a28a3642651451e315f7f9b9d04e907e65a45681796"

18
toolkit/library/rust/Cargo.lock сгенерированный
Просмотреть файл

@ -179,10 +179,10 @@ dependencies = [
[[package]]
name = "cssparser"
version = "0.12.2"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cssparser-macros 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser-macros 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
"procedural-masquerade 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -192,7 +192,7 @@ dependencies = [
[[package]]
name = "cssparser-macros"
version = "0.2.0"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"phf_codegen 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
@ -300,7 +300,7 @@ name = "geckoservo"
version = "0.0.1"
dependencies = [
"atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
@ -674,7 +674,7 @@ name = "selectors"
version = "0.18.0"
dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"precomputed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -754,7 +754,7 @@ dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -784,7 +784,7 @@ name = "style_traits"
version = "0.0.1"
dependencies = [
"app_units 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -1080,8 +1080,8 @@ dependencies = [
"checksum core-foundation-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "41115a6aa5d3e1e5ef98148373f25971d1fad53818553f216495f9e67e90a624"
"checksum core-graphics 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ead017dcf77f503dc991f6b52de6084eeea60a94b0a652baa9bf88654a28e83f"
"checksum core-text 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0e9719616a10f717628e074744f8c55df7b450f7a34d29c196d14f4498aad05d"
"checksum cssparser 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fb067f9d88368ca9053aea00581556151ef96f2591e32ad44f3312d7e6b67392"
"checksum cssparser-macros 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f0415de0bdbce823c0db204e00a62c8240fa2d3e04cd13ff7c6396e4446b95"
"checksum cssparser 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b39404c5e04492194e3c69f1a10964b980f2c95c884a940f7903446779f6b027"
"checksum cssparser-macros 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "079adec4af52bb5275eadd004292028c79eb3c5f5b4ee8086a36d4197032f6df"
"checksum deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1614659040e711785ed8ea24219140654da1729f3ec8a47a9719d041112fe7bf"
"checksum dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "80c8b71fd71146990a9742fc06dcbbde19161a267e0ad4e572c35162f4578c90"
"checksum dwrote 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "74114b6b49d6731835da7a28a3642651451e315f7f9b9d04e907e65a45681796"