Skip to content

Commit

Permalink
test: add out of range date test case
Browse files Browse the repository at this point in the history
  • Loading branch information
amilajack committed Jan 1, 2021
1 parent e49bb58 commit 072d5bf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions crates/neon-runtime/src/napi/bindings/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ generate!(extern "C" {

fn create_double(env: Env, value: f64, result: *mut Value) -> Status;

fn create_date(env: Env, value: f64, result: *mut Value) -> Status;

fn get_date_value(env: Env, value: Value, result: *mut f64) -> Status;

fn create_object(env: Env, result: *mut Value) -> Status;

fn get_value_bool(env: Env, value: Value, result: *mut bool) -> Status;
Expand Down Expand Up @@ -57,6 +61,7 @@ generate!(extern "C" {
fn is_buffer(env: Env, value: Value, result: *mut bool) -> Status;
fn is_error(env: Env, value: Value, result: *mut bool) -> Status;
fn is_array(env: Env, value: Value, result: *mut bool) -> Status;
fn is_date(env: Env, value: Value, result: *mut bool) -> Status;

fn get_value_string_utf8(
env: Env,
Expand Down
12 changes: 6 additions & 6 deletions crates/neon-runtime/src/napi/date.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use std::mem::MaybeUninit;
use nodejs_sys as napi;
use raw::{Env, Local};
use crate::napi::bindings as napi;
use crate::raw::{Env, Local};

pub unsafe fn new_date(env: Env, value: f64) -> Local {
let mut local = MaybeUninit::zeroed();
let status = napi::napi_create_date(env, value, local.as_mut_ptr());
assert_eq!(status, napi::napi_status::napi_ok);
let status = napi::create_date(env, value, local.as_mut_ptr());
assert_eq!(status, napi::Status::Ok);
local.assume_init()
}

pub unsafe fn value(env: Env, p: Local) -> f64 {
let mut value = 0.0;
let status = napi::napi_get_date_value(env, p, &mut value as *mut _);
assert_eq!(status, napi::napi_status::napi_ok);
let status = napi::get_date_value(env, p, &mut value as *mut _);
assert_eq!(status, napi::Status::Ok);
return value;
}
2 changes: 1 addition & 1 deletion crates/neon-runtime/src/napi/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ pub unsafe extern "C" fn is_arraybuffer(env: Env, val: Local) -> bool {

pub unsafe extern "C" fn is_date(env: Env, val: Local) -> bool {
let mut result = false;
assert_eq!(napi::napi_is_date(env, val, &mut result as *mut _), napi::napi_status::napi_ok);
assert_eq!(napi::is_date(env, val, &mut result as *mut _), napi::Status::Ok);
result
}
2 changes: 1 addition & 1 deletion test/napi/lib/date.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var addon = require('../native');
var addon = require('..');
var assert = require('chai').assert;

describe('JsDate', function() {
Expand Down

0 comments on commit 072d5bf

Please sign in to comment.