Skip to content
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

feat(neon): Update try-catch to match the RFC; return a T: Sized instead of T: Value #631

Merged
merged 4 commits into from
Dec 9, 2020

Conversation

kjvalencik
Copy link
Member

@kjvalencik kjvalencik commented Nov 10, 2020

As requested by #630

  • Removes unnecessary UnwindSafe bound
  • Changes T: Value to T: Sized
  • Updates a test to leverage a non-JavaScript T (())

@@ -205,7 +204,7 @@ extern "C" fn try_catch_glue<'a, 'b: 'a, C, T, F>(rust_thunk: *mut c_void,
match catch_unwind(AssertUnwindSafe(|| f(cx))) {
// No Rust panic, no JS exception.
Ok(Ok(result)) => unsafe {
*returned = result.to_raw();
*(returned as *mut T) = result;

This comment was marked as resolved.

let mut unwind_value: MaybeUninit<*mut c_void> = MaybeUninit::zeroed();

let ctrl = unsafe {
neon_runtime::try_catch::with(try_catch_glue::<Self, T, F>,
rust_thunk as *mut c_void,
(self as *mut Self) as *mut c_void,
local.as_mut_ptr(),
ok.as_mut_ptr() as *mut c_void,

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

@kjvalencik kjvalencik force-pushed the kv/try-catch branch 2 times, most recently from 3c989e5 to a45812c Compare November 11, 2020 15:02
@kjvalencik kjvalencik changed the title RFC: try_catch return NeonResult<T> instead of JsResult feat(neon): Update try-catch to match the RFC; return a T: Sized instead of T: Value Dec 7, 2020
Copy link
Member

@goto-bus-stop goto-bus-stop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall

@@ -152,13 +152,13 @@ extern "C" {
// returns `CONTROL_RETURNED`.
// The `unwind_value` out-parameter can be assumed to be initialized if and only if this
// function returns `CONTROL_PANICKED`.
typedef try_catch_control_t (*Neon_TryCatchGlue)(void *rust_thunk, void *cx, v8::Local<v8::Value> *result, void **unwind_value);
typedef try_catch_control_t (*Neon_TryCatchGlue)(void *rust_thunk, void *cx, void *ok, void **unwind_value);

This comment was marked as resolved.


// The `result` out-parameter can be assumed to be initialized if and only if this function
// returns `CONTROL_RETURNED` or `CONTROL_THREW`.
// The `unwind_value` out-parameter can be assumed to be initialized if and only if this
// function returns `CONTROL_PANICKED`.
try_catch_control_t Neon_TryCatch_With(Neon_TryCatchGlue glue, void *rust_thunk, void *cx, v8::Local<v8::Value> *result, void **unwind_value);
try_catch_control_t Neon_TryCatch_With(Neon_TryCatchGlue glue, void *rust_thunk, void *cx, void *ok, v8::Local<v8::Value> *err, void **unwind_value);

This comment was marked as resolved.

Copy link
Collaborator

@dherman dherman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this changes behavior we should have a test for the new behavior, i.e. a result that produces a non-Value value.

Otherwise looks great!

Copy link
Collaborator

@dherman dherman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants