Skip to content

Commit

Permalink
All tests passing again! \o/
Browse files Browse the repository at this point in the history
  • Loading branch information
dherman committed Mar 9, 2019
1 parent 9eb8bc5 commit 749cd6f
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 88 deletions.
6 changes: 3 additions & 3 deletions src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ pub trait Context<'a>: ContextInternal<'a> {
///
/// ```no_run
/// # use neon::prelude::*;
/// # fn my_neon_function(mut cx: FunctionContext) -> JsResult<JsUndefined> {
/// let mut b: &JsArrayBuffer = cx.argument(0)?;
/// cx.borrow_mut(&b, |data| {
/// # fn my_neon_function(mut cx: FunctionContext) -> NeonResult<&JsUndefined> {
/// let b: &JsArrayBuffer = cx.argument(0)?;
/// cx.borrow_mut(b, |data| {
/// let slice = data.as_mut_slice::<u32>();
/// slice[0] += 1;
/// });
Expand Down
2 changes: 1 addition & 1 deletion src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A convenience module that re-exports the most commonly-used Neon APIs.
pub use types::{JsBuffer, JsArrayBuffer, BinaryData, JsError, JsUndefined, JsNull, JsBoolean, JsString, JsNumber, JsObject, JsArray, JsFunction, Value};
pub use types::{JsBuffer, JsArrayBuffer, BinaryData, JsError, JsUndefined, JsNull, JsBoolean, JsString, JsNumber, JsObject, JsArray, JsFunction, JsValue, Value};
pub use object::{Object, Class};
pub use borrow::{Borrow, BorrowMut};
pub use context::{CallKind, Context, ModuleContext, ExecuteContext, ComputeContext, CallContext, FunctionContext, MethodContext, TaskContext};
Expand Down
12 changes: 6 additions & 6 deletions src/types/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ impl<'a> BinaryData<'a> {
///
/// ```no_run
/// # use neon::prelude::*;
/// # fn get_x_and_y(mut cx: FunctionContext) -> JsResult<JsUndefined> {
/// let b: Handle<JsArrayBuffer> = cx.argument(0)?;
/// let (x, y) = cx.borrow(&b, |data| {
/// # fn get_x_and_y(mut cx: FunctionContext) -> NeonResult<&JsUndefined> {
/// let b: &JsArrayBuffer = cx.argument(0)?;
/// let (x, y) = cx.borrow(b, |data| {
/// let slice = data.as_slice::<i32>();
/// (slice[0], slice[1])
/// });
Expand All @@ -141,9 +141,9 @@ impl<'a> BinaryData<'a> {
///
/// ```no_run
/// # use neon::prelude::*;
/// # fn modify_buffer(mut cx: FunctionContext) -> JsResult<JsUndefined> {
/// let mut b: Handle<JsArrayBuffer> = cx.argument(0)?;
/// cx.borrow_mut(&mut b, |data| {
/// # fn modify_buffer(mut cx: FunctionContext) -> NeonResult<&JsUndefined> {
/// let b: &JsArrayBuffer = cx.argument(0)?;
/// cx.borrow_mut(b, |data| {
/// let slice = data.as_mut_slice::<f64>();
/// slice[0] /= 2.0;
/// slice[1] *= 2.0;
Expand Down
6 changes: 3 additions & 3 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ pub trait Value: ValueInternal {
///
/// ```no_run
/// # use neon::prelude::*;
/// # fn my_neon_function(mut cx: FunctionContext) -> JsResult<JsUndefined> {
/// let v: Handle<JsValue> = cx.number(17).upcast();
/// # fn my_neon_function(mut cx: FunctionContext) -> NeonResult<&JsUndefined> {
/// let v: &JsValue = cx.number(17).upcast();
/// v.is_a::<JsString>(); // false
/// v.is_a::<JsNumber>(); // true
/// v.is_a::<JsValue>(); // true
Expand Down Expand Up @@ -287,7 +287,7 @@ impl JsString {
}
}

pub fn value(self) -> String {
pub fn value(&self) -> String {
unsafe {
let capacity = neon_runtime::string::utf8_len(self.to_raw());
let mut buffer: Vec<u8> = Vec::with_capacity(capacity as usize);
Expand Down
10 changes: 5 additions & 5 deletions test/dynamic/native/src/js/arrays.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use neon::prelude::*;

pub fn return_js_array(mut cx: FunctionContext) -> JsResult<JsArray> {
pub fn return_js_array(mut cx: FunctionContext) -> NeonResult<&JsArray> {
Ok(cx.empty_array())
}

pub fn return_js_array_with_number(mut cx: FunctionContext) -> JsResult<JsArray> {
let array: Handle<JsArray> = JsArray::new(&mut cx, 1);
pub fn return_js_array_with_number(mut cx: FunctionContext) -> NeonResult<&JsArray> {
let array: &JsArray = JsArray::new(&mut cx, 1);
let n = cx.number(9000.0);
array.set(&mut cx, 0, n)?;
Ok(array)
}

pub fn return_js_array_with_string(mut cx: FunctionContext) -> JsResult<JsArray> {
let array: Handle<JsArray> = JsArray::new(&mut cx, 1);
pub fn return_js_array_with_string(mut cx: FunctionContext) -> NeonResult<&JsArray> {
let array: &JsArray = JsArray::new(&mut cx, 1);
let s = cx.string("hello node");
array.set(&mut cx, 0, s)?;
Ok(array)
Expand Down
6 changes: 3 additions & 3 deletions test/dynamic/native/src/js/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ declare_types! {
pub class JsUser for User {
init(mut cx) {
let id = cx.argument::<JsNumber>(0)?;
let first_name: Handle<JsString> = cx.argument::<JsString>(1)?;
let last_name: Handle<JsString> = cx.argument::<JsString>(2)?;
let email: Handle<JsString> = cx.argument::<JsString>(3)?;
let first_name: &JsString = cx.argument::<JsString>(1)?;
let last_name: &JsString = cx.argument::<JsString>(2)?;
let email: &JsString = cx.argument::<JsString>(3)?;

Ok(User {
id: id.value() as i32,
Expand Down
37 changes: 19 additions & 18 deletions test/dynamic/native/src/js/functions.rs
Original file line number Diff line number Diff line change
@@ -1,84 +1,85 @@
use neon::prelude::*;
use neon::object::This;
use neon::result::NeonResultExt;

fn add1(mut cx: FunctionContext) -> JsResult<JsNumber> {
fn add1(mut cx: FunctionContext) -> NeonResult<&JsNumber> {
let x = cx.argument::<JsNumber>(0)?.value();
Ok(cx.number(x + 1.0))
}

pub fn return_js_function(mut cx: FunctionContext) -> JsResult<JsFunction> {
pub fn return_js_function(mut cx: FunctionContext) -> NeonResult<&JsFunction> {
JsFunction::new(&mut cx, add1)
}

pub fn call_js_function(mut cx: FunctionContext) -> JsResult<JsNumber> {
pub fn call_js_function(mut cx: FunctionContext) -> NeonResult<&JsNumber> {
let f = cx.argument::<JsFunction>(0)?;
let args: Vec<Handle<JsNumber>> = vec![cx.number(16.0)];
let args: Vec<&JsNumber> = vec![cx.number(16.0)];
let null = cx.null();
f.call(&mut cx, null, args)?.downcast::<JsNumber>().or_throw(&mut cx)
}

pub fn construct_js_function(mut cx: FunctionContext) -> JsResult<JsNumber> {
pub fn construct_js_function(mut cx: FunctionContext) -> NeonResult<&JsNumber> {
let f = cx.argument::<JsFunction>(0)?;
let zero = cx.number(0.0);
let o = f.construct(&mut cx, vec![zero])?;
let get_utc_full_year_method = o.get(&mut cx, "getUTCFullYear")?.downcast::<JsFunction>().or_throw(&mut cx)?;
let args: Vec<Handle<JsValue>> = vec![];
let args: Vec<&JsValue> = vec![];
get_utc_full_year_method.call(&mut cx, o.upcast::<JsValue>(), args)?.downcast::<JsNumber>().or_throw(&mut cx)
}

trait CheckArgument<'a> {
fn check_argument<V: Value>(&mut self, i: i32) -> JsResult<'a, V>;
fn check_argument<V: Value>(&mut self, i: i32) -> NeonResult<&'a V>;
}

impl<'a, T: This> CheckArgument<'a> for CallContext<'a, T> {
fn check_argument<V: Value>(&mut self, i: i32) -> JsResult<'a, V> {
fn check_argument<V: Value>(&mut self, i: i32) -> NeonResult<&'a V> {
self.argument::<V>(i)
}
}

pub fn check_string_and_number(mut cx: FunctionContext) -> JsResult<JsUndefined> {
pub fn check_string_and_number(mut cx: FunctionContext) -> NeonResult<&JsUndefined> {
cx.check_argument::<JsString>(0)?;
cx.check_argument::<JsNumber>(1)?;
Ok(cx.undefined())
}

pub fn panic(_: FunctionContext) -> JsResult<JsUndefined> {
pub fn panic(_: FunctionContext) -> NeonResult<&JsUndefined> {
panic!("zomg")
}

pub fn panic_after_throw(mut cx: FunctionContext) -> JsResult<JsUndefined> {
pub fn panic_after_throw(mut cx: FunctionContext) -> NeonResult<&JsUndefined> {
cx.throw_range_error::<_, ()>("entering throw state with a RangeError").unwrap_err();
panic!("this should override the RangeError")
}

pub fn num_arguments(mut cx: FunctionContext) -> JsResult<JsNumber> {
pub fn num_arguments(mut cx: FunctionContext) -> NeonResult<&JsNumber> {
let n = cx.len();
Ok(cx.number(n))
}

pub fn return_this(mut cx: FunctionContext) -> JsResult<JsValue> {
pub fn return_this(mut cx: FunctionContext) -> NeonResult<&JsValue> {
Ok(cx.this().upcast())
}

pub fn require_object_this(mut cx: FunctionContext) -> JsResult<JsUndefined> {
pub fn require_object_this(mut cx: FunctionContext) -> NeonResult<&JsUndefined> {
let this = cx.this();
let this = this.downcast::<JsObject>().or_throw(&mut cx)?;
let t = cx.boolean(true);
this.set(&mut cx, "modified", t)?;
Ok(cx.undefined())
}

pub fn is_argument_zero_some(mut cx: FunctionContext) -> JsResult<JsBoolean> {
pub fn is_argument_zero_some(mut cx: FunctionContext) -> NeonResult<&JsBoolean> {
let b = cx.argument_opt(0).is_some();
Ok(cx.boolean(b))
}

pub fn require_argument_zero_string(mut cx: FunctionContext) -> JsResult<JsString> {
pub fn require_argument_zero_string(mut cx: FunctionContext) -> NeonResult<&JsString> {
let s = cx.argument(0)?;
Ok(s)
}

pub fn execute_scoped(mut cx: FunctionContext) -> JsResult<JsNumber> {
pub fn execute_scoped(mut cx: FunctionContext) -> NeonResult<&JsNumber> {
let mut i = 0;
for _ in 1..100 {
cx.execute_scoped(|mut cx| {
Expand All @@ -89,7 +90,7 @@ pub fn execute_scoped(mut cx: FunctionContext) -> JsResult<JsNumber> {
Ok(cx.number(i))
}

pub fn compute_scoped(mut cx: FunctionContext) -> JsResult<JsNumber> {
pub fn compute_scoped(mut cx: FunctionContext) -> NeonResult<&JsNumber> {
let mut i = cx.number(0);
for _ in 1..100 {
i = cx.compute_scoped(|mut cx| {
Expand Down
26 changes: 13 additions & 13 deletions test/dynamic/native/src/js/numbers.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
use neon::prelude::*;

pub fn return_js_number(mut cx: FunctionContext) -> JsResult<JsNumber> {
pub fn return_js_number(mut cx: FunctionContext) -> NeonResult<&JsNumber> {
Ok(cx.number(9000_f64))
}

pub fn return_large_js_number(mut cx: FunctionContext) -> JsResult<JsNumber> {
pub fn return_large_js_number(mut cx: FunctionContext) -> NeonResult<&JsNumber> {
Ok(cx.number(4294967296_f64))
}

pub fn return_negative_js_number(mut cx: FunctionContext) -> JsResult<JsNumber> {
pub fn return_negative_js_number(mut cx: FunctionContext) -> NeonResult<&JsNumber> {
Ok(cx.number(-9000_f64))
}

pub fn return_float_js_number(mut cx: FunctionContext) -> JsResult<JsNumber> {
pub fn return_float_js_number(mut cx: FunctionContext) -> NeonResult<&JsNumber> {
Ok(cx.number(1.4747_f64))
}

pub fn return_negative_float_js_number(mut cx: FunctionContext) -> JsResult<JsNumber> {
pub fn return_negative_float_js_number(mut cx: FunctionContext) -> NeonResult<&JsNumber> {
Ok(cx.number(-1.4747_f64))
}

pub fn accept_and_return_js_number(mut cx: FunctionContext) -> JsResult<JsNumber> {
let number: Handle<JsNumber> = cx.argument(0)?;
pub fn accept_and_return_js_number(mut cx: FunctionContext) -> NeonResult<&JsNumber> {
let number: &JsNumber = cx.argument(0)?;
Ok(number)
}

pub fn accept_and_return_large_js_number(mut cx: FunctionContext) -> JsResult<JsNumber> {
let number: Handle<JsNumber> = cx.argument(0)?;
pub fn accept_and_return_large_js_number(mut cx: FunctionContext) -> NeonResult<&JsNumber> {
let number: &JsNumber = cx.argument(0)?;
Ok(number)
}

pub fn accept_and_return_float_js_number(mut cx: FunctionContext) -> JsResult<JsNumber> {
let number: Handle<JsNumber> = cx.argument(0)?;
pub fn accept_and_return_float_js_number(mut cx: FunctionContext) -> NeonResult<&JsNumber> {
let number: &JsNumber = cx.argument(0)?;
Ok(number)
}

pub fn accept_and_return_negative_js_number(mut cx: FunctionContext) -> JsResult<JsNumber> {
let number: Handle<JsNumber> = cx.argument(0)?;
pub fn accept_and_return_negative_js_number(mut cx: FunctionContext) -> NeonResult<&JsNumber> {
let number: &JsNumber = cx.argument(0)?;
Ok(number)
}
Loading

0 comments on commit 749cd6f

Please sign in to comment.