-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expanding on Root and a potential common-case #703
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,21 @@ impl<T: Object> Root<T> { | |
/// The caller _must_ ensure `Root::into_inner` or `Root::drop` is called | ||
/// to properly dispose of the `Root<T>`. If the value is dropped without | ||
/// calling one of these methods, it will *panic*. | ||
/// | ||
/// Be careful that you aren't short-circuiting with an early return before | ||
/// your Root value gets into_inner'd or dropped. The following will cause | ||
/// a runtime panic when your error case gets triggered: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is no longer strictly accurate after merging #700 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've changed it to delineate panic prior to 0.8, slow path otherwise. |
||
/// ``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is failing doc tests for me locally. I'm not sure why it's not failing in CI. 😕 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I have fixed this, I wasn't even thinking about doc tests when I wrote the code. |
||
/// let callback = cx.argument::<JsFunction>(1)?.root(&mut cx); | ||
/// let my_log = match (create_log_entry(&id_generator, "log-emitter")) { | ||
/// Err(_err) => { | ||
/// return cx.throw_error("Couldn't construct log"); | ||
/// }, | ||
/// Ok(log) => log, | ||
/// }; | ||
/// ``` | ||
/// The solution in the original case for this was to bind the callback | ||
/// after the fallible code, right before spawning an async task. | ||
pub fn new<'a, C: Context<'a>>(cx: &mut C, value: &T) -> Self { | ||
let env = cx.env().to_raw(); | ||
let internal = unsafe { reference::new(env, value.to_raw()) }; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this communicates the same as above, can it be reworded to present it as an example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've attempted a rewording along the lines suggested here.