Skip to content

Commit 4f7121c

Browse files
committed
update to neon 0.10 – downcasting properties
- the newly generic `.get` method handles the downcast_or_throw step for us
1 parent b9d6362 commit 4f7121c

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

src/context/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ pub fn set_fontVariant(mut cx: FunctionContext) -> JsResult<JsUndefined> {
962962
let arg = cx.argument::<JsObject>(1)?;
963963

964964
let variant = string_for_key(&mut cx, &arg, "variant")?;
965-
let feat_obj = arg.get(&mut cx, "features")?.downcast_or_throw::<JsObject, _>(&mut cx)?;
965+
let feat_obj: Handle<JsObject> = arg.get(&mut cx, "features")?;
966966
let features = font_features(&mut cx, &feat_obj)?;
967967
this.set_font_variant(&variant, &features);
968968
Ok(cx.undefined())

src/typography.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub fn font_arg(cx: &mut FunctionContext, idx: i32) -> Result<Option<FontSpec>,
167167
let slant = to_slant(string_for_key(cx, &font_desc, "style")?.as_str());
168168
let width = to_width(string_for_key(cx, &font_desc, "stretch")?.as_str());
169169

170-
let feat_obj = font_desc.get(cx, "features")?.downcast::<JsObject, _>(cx).or_throw(cx)?;
170+
let feat_obj:Handle<JsObject> = font_desc.get(cx, "features")?;
171171
let features = font_features(cx, &feat_obj)?;
172172

173173
let style = FontStyle::new(weight, width, slant);

src/utils.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,15 @@ pub fn strings_in(cx: &mut FunctionContext, vals: &[Handle<JsValue>]) -> Vec<Str
9191
}
9292

9393
pub fn strings_at_key(cx: &mut FunctionContext, obj: &Handle<JsObject>, attr:&str) -> Result<Vec<String>, Throw>{
94-
let array = obj.get(cx, attr)?.downcast::<JsArray, _>(cx).or_throw(cx)?.to_vec(cx)?;
95-
Ok(strings_in(cx, &array))
94+
let array:Handle<JsArray> = obj.get(cx, attr)?;
95+
let list = array.to_vec(cx)?;
96+
Ok(strings_in(cx, &list))
9697
}
9798

9899
pub fn string_for_key(cx: &mut FunctionContext, obj: &Handle<JsObject>, attr:&str) -> Result<String, Throw>{
99100
let key = cx.string(attr);
100-
match obj.get(cx, key)?.downcast::<JsString, _>(cx){
101+
let val:Handle<JsValue> = obj.get(cx, key)?;
102+
match val.downcast::<JsString, _>(cx){
101103
Ok(s) => Ok(s.value(cx)),
102104
Err(_e) => cx.throw_type_error(format!("Exptected a string for \"{}\"", attr))
103105
}
@@ -191,7 +193,8 @@ pub fn bool_arg(cx: &mut FunctionContext, idx: usize, attr:&str) -> Result<bool,
191193

192194
pub fn float_for_key(cx: &mut FunctionContext, obj: &Handle<JsObject>, attr:&str) -> Result<f32, Throw>{
193195
let key = cx.string(attr);
194-
match obj.get(cx, key)?.downcast::<JsNumber, _>(cx){
196+
let val:Handle<JsValue> = obj.get(cx, key)?;
197+
match val.downcast::<JsNumber, _>(cx){
195198
Ok(num) => Ok(num.value(cx) as f32),
196199
Err(_e) => cx.throw_type_error(format!("Exptected a numerical value for \"{}\"", attr))
197200
}
@@ -303,7 +306,7 @@ pub fn color_in<'a>(cx: &mut FunctionContext<'a>, val: Handle<'a, JsValue>) -> O
303306
}
304307

305308
if let Ok(obj) = val.downcast::<JsObject, _>(cx){
306-
if let Ok(attr) = obj.get(cx, "toString"){
309+
if let Ok(attr) = obj.get::<JsValue, _, _>(cx, "toString"){
307310
if let Ok(to_string) = attr.downcast::<JsFunction, _>(cx){
308311
let args: Vec<Handle<JsValue>> = vec![];
309312
if let Ok(result) = to_string.call(cx, obj, args){
@@ -446,26 +449,26 @@ pub fn filter_arg(cx: &mut FunctionContext, idx: usize) -> Result<(String, Vec<F
446449
let arg = cx.argument::<JsObject>(idx as i32)?;
447450
let canonical = string_for_key(cx, &arg, "canonical")?;
448451

449-
let obj = arg.get(cx, "filters")?.downcast_or_throw::<JsObject, _>(cx)?;
452+
let obj:Handle<JsObject> = arg.get(cx, "filters")?;
450453
let keys = obj.get_own_property_names(cx)?.to_vec(cx)?;
451454
let mut filters = vec![];
452455
for (name, key) in strings_in(cx, &keys).iter().zip(keys) {
453456
match name.as_str() {
454457
"drop-shadow" => {
455-
let values = obj.get(cx, key)?.downcast_or_throw::<JsArray, _>(cx)?;
458+
let values = obj.get::<JsArray, _, _>(cx, key)?;
456459
let nums = values.to_vec(cx)?;
457460
let dims = floats_in(cx, &nums);
458-
let color_str = values.get(cx, 3)?.downcast_or_throw::<JsString, _>(cx)?.value(cx);
461+
let color_str = values.get::<JsString, _, _>(cx, 3)?.value(cx);
459462
if let Some(color) = css_to_color(cx, &color_str) {
460463
filters.push(FilterSpec::Shadow{
461464
offset: Point::new(dims[0], dims[1]), blur: dims[2], color
462465
});
463466
}
464467
},
465468
_ => {
466-
let value = obj.get(cx, key)?.downcast_or_throw::<JsNumber, _>(cx)?.value(cx);
469+
let value = obj.get::<JsNumber, _, _>(cx, key)?.value(cx) as f32;
467470
filters.push(FilterSpec::Plain{
468-
name:name.to_string(), value:value as f32
471+
name:name.to_string(), value
469472
})
470473
}
471474
}

0 commit comments

Comments
 (0)