Skip to content

Commit

Permalink
cleanup:
Browse files Browse the repository at this point in the history
- rename "init" functions back to idiomatic "new" names, removing old versions
- rename "thin" functions back to idiomatic names, removing old versions
- implement function call/construct
- eliminate obsolete neon_runtime::convert module
  • Loading branch information
dherman committed Mar 9, 2019
1 parent 32cfdd3 commit 9eb8bc5
Show file tree
Hide file tree
Showing 20 changed files with 158 additions and 473 deletions.
10 changes: 3 additions & 7 deletions crates/neon-runtime/src/array.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
//! Facilities for working with `v8::Array`s.
use raw::{Local, Isolate, Persistent};
use raw::{Isolate, Persistent};

extern "C" {

/// Mutates the `out` argument provided to refer to a newly created `v8::Array`.
#[link_name = "Neon_Array_New"]
pub fn new(out: &mut Local, isolate: *mut Isolate, length: u32);

/// Initializes the `out` argument provided to refer to a newly created `v8::Array`.
#[link_name = "Neon_Array_Init"]
pub fn init(out: &Persistent, isolate: *mut Isolate, length: u32);
#[link_name = "Neon_Array_New"]
pub fn new(out: &Persistent, isolate: *mut Isolate, length: u32);

/// Gets the length of an `v8::Array`.
#[link_name = "Neon_Array_Length"]
Expand Down
12 changes: 3 additions & 9 deletions crates/neon-runtime/src/arraybuffer.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
//! Facilities for working with `v8::ArrayBuffer`s.
use raw::{Isolate, Local, Persistent};
use raw::{Isolate, Persistent};
use std::os::raw::c_void;

// FIXME: rename init_xxx functions back to new_xxx

extern "C" {

/// Initializes the `out` argument provided to refer to a newly created `v8::ArrayBuffer` object.
/// Returns `false` if the value couldn't be created.
#[link_name = "Neon_ArrayBuffer_Init"]
pub fn init(out: &Persistent, isolate: *mut Isolate, size: u32) -> bool;

/// Mutates the `out` argument provided to refer to a newly created `v8::ArrayBuffer` object.
/// Returns `false` if the value couldn't be created.
#[link_name = "Neon_ArrayBuffer_New"]
pub fn new(out: &mut Local, isolate: *mut c_void, size: u32) -> bool;
pub fn new(out: &Persistent, isolate: *mut Isolate, size: u32) -> bool;

/// Mutates the `base_out` and `size_out` arguments to access the data of a `v8::ArrayBuffer` object.
#[link_name = "Neon_ArrayBuffer_Data"]
pub fn data<'a, 'b>(base_out: &'a mut *mut c_void, size_out: &'a mut usize, obj: &Persistent);

}
20 changes: 4 additions & 16 deletions crates/neon-runtime/src/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
//! Facilities for working with `node::Buffer`s.
use raw::{Isolate, Local, Persistent};
use raw::{Isolate, Persistent};
use std::os::raw::c_void;

// FIXME: rename init_xxx functions back to new_xxx

extern "C" {

/// Mutates the `out` argument provided to refer to a newly created and zero-filled `node::Buffer` object.
/// Returns `false` if the value couldn't be created.
#[link_name = "Neon_Buffer_New"]
pub fn new(out: &mut Local, size: u32) -> bool;

/// Initializes the `out` argumnent with a newly created `v8::Buffer` using the safe constructor.
#[link_name = "Neon_Buffer_Init_Safe"]
pub fn init_safe(out: &Persistent, isolate: *mut Isolate, size: u32) -> bool;
#[link_name = "Neon_Buffer_New"]
pub fn new(out: &Persistent, isolate: *mut Isolate, size: u32) -> bool;

/// Initializes the `out` argumnent with a newly created `v8::Buffer` using the unsafe constructor.
#[link_name = "Neon_Buffer_Init_Unsafe"]
pub fn init_unsafe(out: &Persistent, isolate: *mut Isolate, size: u32) -> bool;

/// Mutates the `out` argument provided to refer to a newly created `node::Buffer` object.
/// Returns `false` if the value couldn't be created.
#[link_name = "Neon_Buffer_Uninitialized"]
pub fn uninitialized(out: &mut Local, size: u32) -> bool;
pub fn uninitialized(out: &Persistent, isolate: *mut Isolate, size: u32) -> bool;

/// Mutates the `base_out` and `size_out` arguments to access the data of a `node::Buffer` object.
#[link_name = "Neon_Buffer_Data"]
Expand Down
26 changes: 6 additions & 20 deletions crates/neon-runtime/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::os::raw::c_void;
use std::ptr::null_mut;
use raw::{FunctionCallbackInfo, Isolate, Local, Persistent};
use raw::{FunctionCallbackInfo, Isolate, Persistent};

#[repr(C)]
pub struct CCallback {
Expand All @@ -23,11 +23,7 @@ extern "C" {

/// Sets the return value of the function call.
#[link_name = "Neon_Call_SetReturn"]
pub fn set_return(info: &FunctionCallbackInfo, value: Local);

/// Sets the return value of the function call.
#[link_name = "Neon_Call_SetReturnThin"]
pub fn set_return_thin(info: &FunctionCallbackInfo, value: &Persistent);
pub fn set_return(info: &FunctionCallbackInfo, value: &Persistent);

/// Gets the isolate of the function call.
#[link_name = "Neon_Call_GetIsolate"]
Expand All @@ -46,27 +42,17 @@ extern "C" {
#[link_name = "Neon_Call_This"]
pub fn this(info: &FunctionCallbackInfo, out: &Persistent, isolate: *mut Isolate);

/// Mutates the `out` argument provided to refer to the `v8::Local` handle value of the
/// `v8::FunctionCallbackInfo` `Data`.
#[link_name = "Neon_Call_Data"]
pub fn data(info: &FunctionCallbackInfo, out: &mut Local);

/// Initializes the `out` argument provided to refer to the value of the
/// `v8::FunctionCallbackInfo` `Data`.
#[link_name = "Neon_Call_InitData"]
pub fn init_data(info: &FunctionCallbackInfo, out: &Persistent, isolate: *mut Isolate);
#[link_name = "Neon_Call_Data"]
pub fn data(info: &FunctionCallbackInfo, out: &Persistent, isolate: *mut Isolate);

/// Gets the number of arguments passed to the function.
#[link_name = "Neon_Call_Length"]
pub fn len(info: &FunctionCallbackInfo) -> i32;

/// Mutates the `out` argument provided to refer to the `v8::Local` handle value of the `i`th
/// argument passed to the function.
#[link_name = "Neon_Call_Get"]
pub fn get(info: &FunctionCallbackInfo, i: i32, out: &mut Local);

/// Initializes the `out` argument provided to refer to the `i`th argument passed to the function.
#[link_name = "Neon_Call_InitGet"]
pub fn init_get(info: &FunctionCallbackInfo, isolate: *mut Isolate, i: i32, out: &Persistent);
#[link_name = "Neon_Call_Get"]
pub fn get(info: &FunctionCallbackInfo, isolate: *mut Isolate, i: i32, out: &Persistent);

}
5 changes: 1 addition & 4 deletions crates/neon-runtime/src/class.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::os::raw::c_void;
use call::CCallback;
use raw::{Isolate, Local, Persistent};
use raw::{Isolate, Persistent};

extern "C" {

Expand Down Expand Up @@ -46,9 +46,6 @@ extern "C" {
#[link_name = "Neon_Class_GetCallKernel"]
pub fn get_call_kernel(obj: &Persistent) -> *mut c_void;

#[link_name = "Neon_Class_Constructor"]
pub fn constructor(out: &mut Local, ft: Local) -> bool;

#[link_name = "Neon_Class_HasInstance"]
pub fn has_instance(metadata: *mut c_void, v: &Persistent) -> bool;

Expand Down
19 changes: 0 additions & 19 deletions crates/neon-runtime/src/convert.rs

This file was deleted.

26 changes: 6 additions & 20 deletions crates/neon-runtime/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,24 @@
//! Facilities for creating and throwing JS errors.
use raw::{Isolate, Local, Persistent};

// FIXME: rename init_xxx functions back to new_xxx
use raw::{Isolate, Persistent};

extern "C" {

/// Throws an `Error` object in the current context.
#[link_name = "Neon_Error_Throw"]
pub fn throw(val: &Persistent);

/// Mutates the `out` argument provided to refer to a newly created `Error` object.
#[link_name = "Neon_Error_NewError"]
pub fn new_error(out: &mut Local, msg: &Persistent);

/// Initializes the `out` argument provided to refer to a newly created `Error` object.
#[link_name = "Neon_Error_InitError"]
pub fn init_error(out: &Persistent, isolate: *mut Isolate, msg: &Persistent);

/// Initializes the `out` argument provided to refer to a newly created `Error` object.
#[link_name = "Neon_Error_InitTypeError"]
pub fn init_type_error(out: &Persistent, isolate: *mut Isolate, msg: &Persistent);
#[link_name = "Neon_Error_NewError"]
pub fn new_error(out: &Persistent, isolate: *mut Isolate, msg: &Persistent);

/// Initializes the `out` argument provided to refer to a newly created `Error` object.
#[link_name = "Neon_Error_InitRangeError"]
pub fn init_range_error(out: &Persistent, isolate: *mut Isolate, msg: &Persistent);

/// Mutates the `out` argument provided to refer to a newly created `TypeError` object.
#[link_name = "Neon_Error_NewTypeError"]
pub fn new_type_error(out: &mut Local, msg: &Persistent);
pub fn new_type_error(out: &Persistent, isolate: *mut Isolate, msg: &Persistent);

/// Mutates the `out` argument provided to refer to a newly created `RangeError` object.
/// Initializes the `out` argument provided to refer to a newly created `Error` object.
#[link_name = "Neon_Error_NewRangeError"]
pub fn new_range_error(out: &mut Local, msg: &Persistent);
pub fn new_range_error(out: &Persistent, isolate: *mut Isolate, msg: &Persistent);

/// Throws an `Error` object in the current context.
#[link_name = "Neon_Error_ThrowErrorFromUtf8"]
Expand Down
26 changes: 5 additions & 21 deletions crates/neon-runtime/src/fun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@
use std::os::raw::c_void;
use call::CCallback;
use raw::{Local, Persistent};
use raw::Persistent;

extern "C" {

/// Mutates the `out` argument provided to refer to a newly created `v8::Function`. Returns
/// `false` if the value couldn't be created.
#[link_name = "Neon_Fun_New"]
pub fn new(out: &mut Local, isolate: *mut c_void, callback: CCallback) -> bool;

/// Initializes the `out` argument provided to refer to a newly created `v8::Function`. Returns
/// `false` if the value couldn't be created.
#[link_name = "Neon_Fun_Init"]
pub fn init(out: &Persistent, isolate: *mut c_void, callback: CCallback) -> bool;
#[link_name = "Neon_Fun_New"]
pub fn new(out: &Persistent, isolate: *mut c_void, callback: CCallback) -> bool;

/// Mutates the `out` argument provided to refer to a newly created `v8::FunctionTemplate`.
/// Returns `false` if the value couldn't be created.
Expand All @@ -28,23 +23,12 @@ extern "C" {
/// Calls the function provided (`fun`) and mutates the `out` argument provided to refer to the
/// result of the function call. Returns `false` if the result of the call was empty.
#[link_name = "Neon_Fun_Call"]
pub fn call(out: &mut Local, isolate: *mut c_void, fun: Local, this: Local, argc: i32, argv: *mut c_void) -> bool;

/// Calls the function provided (`fun`) and mutates the `out` argument provided to refer to the
/// result of the function call. Returns `false` if the result of the call was empty.
#[link_name = "Neon_Fun_CallThin"]
pub fn call_thin(out: &Persistent, isolate: *mut c_void, fun: &Persistent, this: &Persistent, argc: i32, argv: *mut c_void) -> bool;
pub fn call(out: &Persistent, isolate: *mut c_void, fun: &Persistent, this: &Persistent, argc: i32, argv: *mut c_void) -> bool;

/// Makes a constructor call to with the function provided (`fun`) and mutates the `out`
/// argument provided to refer to the result of the constructor call. Returns `false` if the
/// result of the call was empty.
#[link_name = "Neon_Fun_Construct"]
pub fn construct(out: &mut Local, isolate: *mut c_void, fun: Local, argc: i32, argv: *mut c_void) -> bool;

/// Makes a constructor call to with the function provided (`fun`) and mutates the `out`
/// argument provided to refer to the result of the constructor call. Returns `false` if the
/// result of the call was empty.
#[link_name = "Neon_Fun_ConstructThin"]
pub fn construct_thin(out: &Persistent, isolate: *mut c_void, fun: &Persistent, argc: i32, argv: *mut c_void) -> bool;
pub fn construct(out: &Persistent, isolate: *mut c_void, fun: &Persistent, argc: i32, argv: *mut c_void) -> bool;

}
1 change: 0 additions & 1 deletion crates/neon-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ pub mod tag;
pub mod module;
pub mod mem;
pub mod fun;
pub mod convert;
pub mod class;
pub mod task;
4 changes: 0 additions & 4 deletions crates/neon-runtime/src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ use raw::{Local, Persistent};

extern "C" {

/// Indicates if two `v8::Local` handles are the same.
#[link_name = "Neon_Mem_SameHandle"]
pub fn same_handle(h1: Local, h2: Local) -> bool;

/// Initializes a pointer as a `v8::Persistent`.
#[link_name = "Neon_Mem_NewPersistent"]
pub fn new_persistent(out: &mut Persistent);
Expand Down
Loading

0 comments on commit 9eb8bc5

Please sign in to comment.