Skip to content
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

Experimental version of API that replaces Handle<'a, V> with &V #347

Closed
wants to merge 11 commits into from
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ lazy_static = "0.2.8"
[dependencies]
cslice = "0.2"
semver = "0.9.0"
typed-arena = "1.4.1"
neon-runtime = { version = "=0.2.0", path = "crates/neon-runtime" }

[workspace]
Expand Down
8 changes: 4 additions & 4 deletions crates/neon-runtime/src/array.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//! Facilities for working with `v8::Array`s.

use raw::{Local, Isolate};
use raw::{Isolate, Persistent};

extern "C" {

/// Mutates the `out` argument provided to refer to a newly created `v8::Array`.
/// Initializes 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);
pub fn new(out: &Persistent, isolate: *mut Isolate, length: u32);

/// Gets the length of an `v8::Array`.
#[link_name = "Neon_Array_Length"]
pub fn len(array: Local) -> u32;
pub fn len(array: &Persistent) -> u32;

}
9 changes: 5 additions & 4 deletions crates/neon-runtime/src/arraybuffer.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
//! Facilities for working with `v8::ArrayBuffer`s.

use raw::Local;
use raw::{Isolate, Persistent};
use std::os::raw::c_void;

extern "C" {

/// Mutates the `out` argument provided to refer to a newly created `v8::ArrayBuffer` object.
/// 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_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: Local);
pub fn data<'a, 'b>(base_out: &'a mut *mut c_void, size_out: &'a mut usize, obj: &Persistent);

}
14 changes: 6 additions & 8 deletions crates/neon-runtime/src/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
//! Facilities for working with `node::Buffer`s.

use raw::Local;
use raw::{Isolate, Persistent};
use std::os::raw::c_void;

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.
/// Initializes the `out` argumnent with a newly created `v8::Buffer` using the safe constructor.
#[link_name = "Neon_Buffer_New"]
pub fn new(out: &mut Local, size: u32) -> bool;
pub fn new(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.
/// Initializes the `out` argumnent with a newly created `v8::Buffer` using the unsafe constructor.
#[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"]
pub fn data<'a, 'b>(base_out: &'a mut *mut c_void, size_out: &'a mut usize, obj: Local);
pub fn data<'a, 'b>(base_out: &'a mut *mut c_void, size_out: &'a mut usize, obj: &Persistent);

}
15 changes: 7 additions & 8 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};
use raw::{FunctionCallbackInfo, Isolate, Persistent};

#[repr(C)]
pub struct CCallback {
Expand All @@ -23,7 +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);
pub fn set_return(info: &FunctionCallbackInfo, value: &Persistent);

/// Gets the isolate of the function call.
#[link_name = "Neon_Call_GetIsolate"]
Expand All @@ -40,20 +40,19 @@ extern "C" {
/// Mutates the `out` argument provided to refer to the `v8::Local` handle value of the object
/// the function is bound to.
#[link_name = "Neon_Call_This"]
pub fn this(info: &FunctionCallbackInfo, out: &mut Local);
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
/// Initializes the `out` argument provided to refer to the value of the
/// `v8::FunctionCallbackInfo` `Data`.
#[link_name = "Neon_Call_Data"]
pub fn data(info: &FunctionCallbackInfo, out: &mut Local);
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.
/// Initializes the `out` argument provided to refer to the `i`th argument passed to the function.
#[link_name = "Neon_Call_Get"]
pub fn get(info: &FunctionCallbackInfo, i: i32, out: &mut Local);
pub fn get(info: &FunctionCallbackInfo, isolate: *mut Isolate, i: i32, out: &Persistent);

}
19 changes: 8 additions & 11 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};
use raw::{Isolate, Persistent};

extern "C" {

Expand Down Expand Up @@ -30,29 +30,26 @@ extern "C" {
pub fn throw_this_error(isolate: *mut Isolate, metadata: *mut c_void);

#[link_name = "Neon_Class_AddMethod"]
pub fn add_method(isolate: *mut Isolate, metadata: *mut c_void, name: *const u8, byte_length: u32, method: Local) -> bool;
pub fn add_method(isolate: *mut Isolate, metadata: *mut c_void, name: *const u8, byte_length: u32, method: &Persistent) -> bool;

#[link_name = "Neon_Class_MetadataToConstructor"]
pub fn metadata_to_constructor(out: &mut Local, isolate: *mut Isolate, metadata: *mut c_void) -> bool;
pub fn metadata_to_constructor(out: &Persistent, isolate: *mut Isolate, metadata: *mut c_void) -> bool;

// FIXME: get rid of all the "kernel" nomenclature

#[link_name = "Neon_Class_GetAllocateKernel"]
pub fn get_allocate_kernel(obj: Local) -> *mut c_void;
pub fn get_allocate_kernel(obj: &Persistent) -> *mut c_void;

#[link_name = "Neon_Class_GetConstructKernel"]
pub fn get_construct_kernel(obj: Local) -> *mut c_void;
pub fn get_construct_kernel(obj: &Persistent) -> *mut c_void;

#[link_name = "Neon_Class_GetCallKernel"]
pub fn get_call_kernel(obj: Local) -> *mut c_void;

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

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

#[link_name = "Neon_Class_GetInstanceInternals"]
pub fn get_instance_internals(obj: Local) -> *mut c_void;
pub fn get_instance_internals(obj: &Persistent) -> *mut c_void;

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

This file was deleted.

16 changes: 8 additions & 8 deletions crates/neon-runtime/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
//! Facilities for creating and throwing JS errors.

use raw::Local;
use raw::{Isolate, Persistent};

extern "C" {

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

/// Mutates the `out` argument provided to refer to a newly created `Error` object.
/// Initializes 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: Local);
pub fn new_error(out: &Persistent, isolate: *mut Isolate, msg: &Persistent);

/// Mutates the `out` argument provided to refer to a newly created `TypeError` object.
/// Initializes the `out` argument provided to refer to a newly created `Error` object.
#[link_name = "Neon_Error_NewTypeError"]
pub fn new_type_error(out: &mut Local, msg: Local);
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: Local);
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
14 changes: 7 additions & 7 deletions crates/neon-runtime/src/fun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@

use std::os::raw::c_void;
use call::CCallback;
use raw::Local;
use raw::Persistent;

extern "C" {

/// Mutates the `out` argument provided to refer to a newly created `v8::Function`. Returns
/// 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_New"]
pub fn new(out: &mut Local, isolate: *mut c_void, callback: CCallback) -> bool;
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.
#[link_name = "Neon_Fun_Template_New"]
pub fn new_template(out: &mut Local, isolate: *mut c_void, callback: CCallback) -> bool;
pub fn new_template(out: &Persistent, isolate: *mut c_void, callback: CCallback) -> bool;

/// Gets the reference to the `v8::Local<v8::External>` handle provided.
#[link_name = "Neon_Fun_GetDynamicCallback"]
pub fn get_dynamic_callback(obj: Local) -> *mut c_void;
pub fn get_dynamic_callback(obj: &Persistent) -> *mut c_void;

/// 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;
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;
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;
20 changes: 16 additions & 4 deletions crates/neon-runtime/src/mem.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
//! A helper function for comparing `v8::Local` handles.
use raw::Local;
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);

/// Deallocates a `v8::Persistent`.
#[link_name = "Neon_Mem_DropPersistent"]
pub fn drop_persistent(p: &mut Persistent);

/// Resets a `v8::Persistent` to the given handle.
#[link_name = "Neon_Mem_ResetPersistent"]
pub fn reset_persistent(p: &Persistent, h: Local);

/// Initializes a local handle with the value of a persistent handle.
#[link_name = "Neon_Mem_ReadPersistent"]
pub fn read_persistent(out: &mut Local, p: &Persistent);

}
Loading