Migration guide entry for Object::get_value() and Object::get_opt() - #868
Conversation
|
I can't find an issue for the original pub fn js_log<'a, C: Context<'a>>(cx: &mut C, s: String) -> NeonResult<()> {
let global = cx.global();
let console = global.get(cx, "console")?.downcast_or_throw::<JsObject, _>(cx)?;
let log = console.get(cx, "log")?.downcast_or_throw::<JsFunction, _>(cx)?;
let null = cx.null();
let args: Vec<Handle<JsString>> = vec![cx.string(s)];
log.call(cx, null, args)?;
Ok(())
}
pub fn js_log<'a, C: Context<'a>>(cx: &mut C, s: String) -> NeonResult<()> {
let global = cx.global();
let console = global.get(cx, "console")?.downcast_or_throw::<JsObject, _>(cx)?;
let log = console.get(cx, "log")?.downcast_or_throw::<JsFunction, _>(cx)?;
log.call_with(cx).arg(cx.string(s)).apply::<JsUndefined, C>(cx)?;
Ok(())
}
pub fn js_log<'a, C: Context<'a>>(cx: &mut C, s: String) -> NeonResult<()> {
let global = cx.global();
let console = global.get::<JsObject, _, _>(cx, "console")?;
let log = console.get::<JsFunction, _, _>(cx, "log")?;
log.call_with(cx).arg(cx.string(s)).apply::<JsUndefined, C>(cx)?;
Ok(())
}
BTW, |
|
Thanks for the feedback @thekingofcity! FYI, here's the PR for the migration guide.
You can simplify the pub fn js_log<'a, C: Context<'a>>(cx: &mut C, s: String) -> NeonResult<()> {
let global = cx.global();
let console = global.get::<JsObject, _, _>(cx, "console")?;
let log = console.get::<JsFunction, _, _>(cx, "log")?;
- log.call_with(cx).arg(cx.string(s)).apply::<JsUndefined, C>(cx)?;
+ log.call_with(cx).arg(cx.string(s)).exec(cx)?;
Ok(())
}It also looks like this could benefit from a recent proposal for |
|
Would be great to see that logging example merged! Of course an out-of-box crate or snippets will be even more user-friendly. I also changed PS I find a migration guide for 0.2 in the wiki, but the 0.10 guide is in the repo. Should we place them in one place? |
This PR adds information to the migration guide for
Object::get()use cases that encode optional or union types.