Skip to content

Commit

Permalink
rebase: {Bind,Prop}Options take Cx instead of generic C: Context
Browse files Browse the repository at this point in the history
  • Loading branch information
dherman committed Sep 8, 2024
1 parent db27665 commit a3f084d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
16 changes: 8 additions & 8 deletions crates/neon/src/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
//! [symbol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol

use crate::{
context::Context,
context::{Cx, Context, internal::ContextInternal},
handle::{Handle, Root},
result::{NeonResult, Throw},
sys::{self, raw},
Expand Down Expand Up @@ -161,13 +161,13 @@ impl<'a> PropertyKey for &'a str {
/// # Ok(cx.string(s))
/// # }
/// ```
pub struct PropOptions<'a, 'cx: 'a, C: Context<'cx>, O: Object, K: PropertyKey> {
pub(crate) cx: &'a mut C,
pub struct PropOptions<'a, 'cx: 'a, O: Object, K: PropertyKey> {
pub(crate) cx: &'a mut Cx<'cx>,
pub(crate) this: Handle<'cx, O>,
pub(crate) key: K,
}

impl<'a, 'cx: 'a, C: Context<'cx>, O: Object, K: PropertyKey> PropOptions<'a, 'cx, C, O, K> {
impl<'a, 'cx: 'a, O: Object, K: PropertyKey> PropOptions<'a, 'cx, O, K> {
/// Gets the property from the object and attempts to convert it to a Rust value.
/// Equivalent to calling `R::from_js(cx, obj.get(cx)?)`.
///
Expand All @@ -191,7 +191,7 @@ impl<'a, 'cx: 'a, C: Context<'cx>, O: Object, K: PropertyKey> PropOptions<'a, 'c
///
/// May throw an exception either during accessing the property or downcasting it
/// to a function.
pub fn bind(&'a mut self) -> NeonResult<BindOptions<'a, 'cx, C>> {
pub fn bind(&'a mut self) -> NeonResult<BindOptions<'a, 'cx>> {
let callee: Handle<JsFunction> = self.this.get(self.cx, self.key)?;
let mut bind = callee.bind(self.cx);
bind.this(self.this);
Expand All @@ -202,11 +202,11 @@ impl<'a, 'cx: 'a, C: Context<'cx>, O: Object, K: PropertyKey> PropOptions<'a, 'c
/// The trait of all object types.
pub trait Object: Value {
/// Create a [`PropOptions`] for accessing a property.
fn prop<'a, 'cx: 'a, C: Context<'cx>, K: PropertyKey>(
fn prop<'a, 'cx: 'a, K: PropertyKey>(
&self,
cx: &'a mut C,
cx: &'a mut Cx<'cx>,
key: K,
) -> PropOptions<'a, 'cx, C, Self, K> {
) -> PropOptions<'a, 'cx, Self, K> {
let this = Handle::new_internal(unsafe { Self::from_local(cx.env(), self.to_local()) });
PropOptions { cx, this, key }
}
Expand Down
14 changes: 7 additions & 7 deletions crates/neon/src/types_impl/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use smallvec::smallvec;

use crate::{
context::Context,
context::{Context, Cx},
handle::Handle,
object::Object,
result::{JsResult, NeonResult},
Expand Down Expand Up @@ -31,14 +31,14 @@ pub(crate) mod private;
/// # Ok(cx.number(x))
/// # }
/// ```
pub struct BindOptions<'a, 'cx: 'a, C: Context<'cx>> {
pub(crate) cx: &'a mut C,
pub struct BindOptions<'a, 'cx: 'a> {
pub(crate) cx: &'a mut Cx<'cx>,
pub(crate) callee: Handle<'cx, JsValue>,
pub(crate) this: Option<Handle<'cx, JsValue>>,
pub(crate) args: private::ArgsVec<'cx>,
}

impl<'a, 'cx: 'a, C: Context<'cx>> BindOptions<'a, 'cx, C> {
impl<'a, 'cx: 'a> BindOptions<'a, 'cx> {
/// Set the value of `this` for the function call.
pub fn this<V: Value>(&mut self, this: Handle<'cx, V>) -> &mut Self {
self.this = Some(this.upcast());
Expand All @@ -62,7 +62,7 @@ impl<'a, 'cx: 'a, C: Context<'cx>> BindOptions<'a, 'cx, C> {
pub fn arg_with<R, F>(&mut self, f: F) -> NeonResult<&mut Self>
where
R: TryIntoJs<'cx>,
F: FnOnce(&mut C) -> NeonResult<R>,
F: FnOnce(&mut Cx<'cx>) -> NeonResult<R>,
{
let v = f(self.cx)?.try_into_js(self.cx)?;
self.args.push(v.upcast());
Expand Down Expand Up @@ -187,7 +187,7 @@ impl<'a> ConstructOptions<'a> {
pub trait TryIntoArguments<'cx>: private::TryIntoArgumentsInternal<'cx> {}

impl<'cx> private::TryIntoArgumentsInternal<'cx> for () {
fn try_into_args_vec<C: Context<'cx>>(self, _cx: &mut C) -> NeonResult<private::ArgsVec<'cx>> {
fn try_into_args_vec(self, _cx: &mut Cx<'cx>) -> NeonResult<private::ArgsVec<'cx>> {
Ok(smallvec![])
}
}
Expand All @@ -204,7 +204,7 @@ macro_rules! impl_into_arguments {
} => {
$(#[$attr1])?
impl<'cx, $($tprefix: TryIntoJs<'cx> + 'cx, )* $tname1: TryIntoJs<'cx> + 'cx> private::TryIntoArgumentsInternal<'cx> for ($($tprefix, )* $tname1, ) {
fn try_into_args_vec<C: Context<'cx>>(self, cx: &mut C) -> NeonResult<private::ArgsVec<'cx>> {
fn try_into_args_vec(self, cx: &mut Cx<'cx>) -> NeonResult<private::ArgsVec<'cx>> {
let ($($vprefix, )* $vname1, ) = self;
Ok(smallvec![ $($vprefix.try_into_js(cx)?.upcast(),)* $vname1.try_into_js(cx)?.upcast() ])
}
Expand Down
4 changes: 2 additions & 2 deletions crates/neon/src/types_impl/function/private.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use smallvec::SmallVec;

use crate::{context::Context, handle::Handle, result::NeonResult, types::JsValue};
use crate::{context::Cx, handle::Handle, result::NeonResult, types::JsValue};

pub type ArgsVec<'a> = SmallVec<[Handle<'a, JsValue>; 8]>;

/// This type marks the `TryIntoArguments` trait as sealed.
pub trait TryIntoArgumentsInternal<'cx> {
fn try_into_args_vec<C: Context<'cx>>(self, cx: &mut C) -> NeonResult<ArgsVec<'cx>>;
fn try_into_args_vec(self, cx: &mut Cx<'cx>) -> NeonResult<ArgsVec<'cx>>;
}

/// This type marks the `Arguments` trait as sealed.
Expand Down
4 changes: 2 additions & 2 deletions crates/neon/src/types_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::{
use smallvec::smallvec;

use crate::{
context::{internal::Env, Context, FunctionContext},
context::{internal::Env, Context, Cx, FunctionContext},
handle::{
internal::{SuperType, TransparentNoCopyWrapper},
Handle,
Expand Down Expand Up @@ -1227,7 +1227,7 @@ impl JsFunction {
}

impl JsFunction {
pub fn bind<'a, 'cx: 'a, C: Context<'cx>>(&self, cx: &'a mut C) -> BindOptions<'a, 'cx, C> {
pub fn bind<'a, 'cx: 'a>(&self, cx: &'a mut Cx<'cx>) -> BindOptions<'a, 'cx> {
BindOptions {
cx,
callee: Handle::new_internal(JsValue(self.to_local())),
Expand Down

0 comments on commit a3f084d

Please sign in to comment.