-
-
Notifications
You must be signed in to change notification settings - Fork 404
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
Add JsNativeObject
wrapper
#3479
base: main
Are you sure you want to change the base?
Conversation
ae8fb11
to
5e459a5
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #3479 +/- ##
==========================================
- Coverage 44.59% 44.55% -0.04%
==========================================
Files 487 488 +1
Lines 50601 50641 +40
==========================================
Hits 22563 22563
- Misses 28038 28078 +40 ☔ View full report in Codecov by Sentry. |
Are doc tests not covered by codecov? |
Nope, and I'm not sure if tarpaulin supports testing docs. |
@jedel1043, @raskad and @HalidOdat will try to review this. |
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.
Nice addition! Thanks for the contribution @johnyob :)
pub fn new(native_object: T, context: &mut Context) -> JsResult<Self> | ||
where | ||
T: Class, | ||
{ | ||
let class = context.get_global_class::<T>().ok_or_else(|| { | ||
JsNativeError::typ().with_message(format!( | ||
"could not find native class `{}` in the map of registered classes", | ||
T::NAME | ||
)) | ||
})?; | ||
|
||
Ok(Self::new_with_proto( | ||
class.prototype(), | ||
native_object, | ||
context, | ||
)) | ||
} |
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.
Now that #3488 is merged, this functionality should be replaced by returning a JsNativeObject
on Class
itself. That should also ensure that any new additions to Class
are correctly called (this implementation skips calling the Class::object_constructor
method).
This PR adds a
JsNativeObject
wrapper aroundJsObject
with the invariant that the underlying object data is a native object of some typeT
.