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

Remove and feature flag features that are being removed in N-API #663

Merged
merged 2 commits into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions crates/neon-runtime/src/napi/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ impl Default for CCallback {
}
}

pub unsafe extern "C" fn set_return(_info: FunctionCallbackInfo, _value: Local) {

}

pub unsafe extern "C" fn get_isolate(_info: FunctionCallbackInfo) -> Env { unimplemented!() }

// FIXME: Remove. This will never be implemented
pub unsafe extern "C" fn current_isolate() -> Env { panic!("current_isolate won't be implemented in n-api") }

pub unsafe extern "C" fn is_construct(env: Env, info: FunctionCallbackInfo) -> bool {
let mut target: MaybeUninit<Local> = MaybeUninit::zeroed();

Expand Down
39 changes: 0 additions & 39 deletions crates/neon-runtime/src/napi/class.rs

This file was deleted.

4 changes: 0 additions & 4 deletions crates/neon-runtime/src/napi/fun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ pub unsafe extern "C" fn new(out: &mut Local, env: Env, callback: CCallback) ->
status == napi::Status::Ok
}

pub unsafe extern "C" fn new_template(_out: &mut Local, _env: Env, _callback: CCallback) -> bool {
unimplemented!()
}

pub unsafe extern "C" fn get_dynamic_callback(_env: Env, data: *mut c_void) -> *mut c_void {
data
}
Expand Down
7 changes: 0 additions & 7 deletions crates/neon-runtime/src/napi/handler.rs

This file was deleted.

3 changes: 0 additions & 3 deletions crates/neon-runtime/src/napi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ pub mod array;
pub mod arraybuffer;
pub mod buffer;
pub mod call;
pub mod class;
pub mod convert;
pub mod error;
pub mod external;
Expand All @@ -14,8 +13,6 @@ pub mod raw;
pub mod scope;
pub mod string;
pub mod tag;
pub mod task;
pub mod handler;
pub mod reference;
#[cfg(feature = "napi-4")]
pub mod tsfn;
Expand Down
5 changes: 0 additions & 5 deletions crates/neon-runtime/src/napi/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ pub unsafe extern "C" fn get_own_property_names(out: &mut Local, env: Env, objec
true
}

// Unused.
pub unsafe extern "C" fn get_isolate(_obj: Local) -> Env {
unimplemented!()
}

/// Mutate the `out` argument to refer to the value at `index` in the given `object`. Returns `false` if the value couldn't be retrieved.
pub unsafe extern "C" fn get_index(out: &mut Local, env: Env, object: Local, index: u32) -> bool {
let status = napi::get_element(env, object, index, out as *mut _);
Expand Down
10 changes: 0 additions & 10 deletions crates/neon-runtime/src/napi/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,6 @@ pub unsafe extern "C" fn boolean_value(env: Env, p: Local) -> bool {
value
}

// DEPRECATE(0.2)
pub unsafe extern "C" fn integer(_out: &mut Local, _isolate: Env, _x: i32) { unimplemented!() }

pub unsafe extern "C" fn is_u32(_p: Local) -> bool { unimplemented!() }

pub unsafe extern "C" fn is_i32(_p: Local) -> bool { unimplemented!() }

// DEPRECATE(0.2)
pub unsafe extern "C" fn integer_value(_p: Local) -> i64 { unimplemented!() }

/// Mutates the `out` argument provided to refer to a newly created `Local` containing a
/// JavaScript number.
pub unsafe extern "C" fn number(out: &mut Local, env: Env, v: f64) {
Expand Down
7 changes: 0 additions & 7 deletions crates/neon-runtime/src/napi/task.rs

This file was deleted.

11 changes: 4 additions & 7 deletions src/context/internal.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std;
#[cfg(feature = "legacy-runtime")]
use std::any::Any;
use std::boxed::Box;
use std::cell::Cell;
use std::mem::MaybeUninit;
#[cfg(feature = "legacy-runtime")]
use std::os::raw::c_void;
#[cfg(feature = "legacy-runtime")]
use std::panic::{AssertUnwindSafe, catch_unwind, resume_unwind};
Expand All @@ -14,6 +13,7 @@ use neon_runtime::scope::Root;
use neon_runtime::try_catch::TryCatchControl;
use types::{JsObject, JsValue};
use handle::Handle;
#[cfg(feature = "legacy-runtime")]
use object::class::ClassMap;
use result::NeonResult;
use super::ModuleContext;
Expand All @@ -28,6 +28,7 @@ pub struct Env(raw::Isolate);
#[derive(Clone, Copy)]
pub struct Env(raw::Env);

#[cfg(feature = "legacy-runtime")]
extern "C" fn drop_class_map(map: Box<ClassMap>) {
std::mem::drop(map);
}
Expand All @@ -45,6 +46,7 @@ impl Env {
ptr
}

#[cfg(feature = "legacy-runtime")]
pub(crate) fn class_map(&mut self) -> &mut ClassMap {
let mut ptr: *mut c_void = unsafe { neon_runtime::class::get_class_map(self.to_raw()) };
if ptr.is_null() {
Expand All @@ -59,11 +61,6 @@ impl Env {
unsafe { std::mem::transmute(ptr) }
}

#[cfg(feature = "napi-1")]
pub(crate) fn current() -> Env {
panic!("Context::current() will not implemented with n-api")
}

#[cfg(feature = "legacy-runtime")]
pub(crate) fn current() -> Env {
unsafe {
Expand Down
4 changes: 4 additions & 0 deletions src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use types::boxed::{Finalize, JsBox};
use types::binary::{JsArrayBuffer, JsBuffer};
use types::error::JsError;
use object::{Object, This};
#[cfg(feature = "legacy-runtime")]
use object::class::Class;
use result::{NeonResult, JsResult, Throw};
#[cfg(feature = "napi-1")]
Expand All @@ -47,6 +48,7 @@ impl CallbackInfo<'_> {
CallContext::<T>::with(env, self, f)
}

#[cfg(feature = "legacy-runtime")]
pub fn set_return<'a, 'b, T: Value>(&'a self, value: Handle<'b, T>) {
unsafe {
neon_runtime::call::set_return(self.info, value.to_raw())
Expand Down Expand Up @@ -421,6 +423,7 @@ impl<'a> ModuleContext<'a> {
Ok(())
}

#[cfg(feature = "legacy-runtime")]
/// Convenience method for exporting a Neon class constructor from a module.
pub fn export_class<T: Class>(&mut self, key: &str) -> NeonResult<()> {
let constructor = T::constructor(self)?;
Expand Down Expand Up @@ -598,6 +601,7 @@ pub struct TaskContext<'a> {
}

impl<'a> TaskContext<'a> {
#[cfg(feature = "legacy-runtime")]
pub(crate) fn with<T, F: for<'b> FnOnce(TaskContext<'b>) -> T>(f: F) -> T {
let env = Env::current();
Scope::with(env, |scope| {
Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub mod types;
pub mod object;
pub mod borrow;
pub mod result;
#[cfg(feature = "legacy-runtime")]
pub mod task;
#[cfg(any(feature = "event-handler-api", all(feature = "napi-4", feature = "event-queue-api")))]
pub mod event;
Expand Down Expand Up @@ -171,6 +172,7 @@ macro_rules! register_module {
}
}

#[cfg(feature = "legacy-runtime")]
#[doc(hidden)]
#[macro_export(local_inner_macros)]
macro_rules! class_definition {
Expand Down Expand Up @@ -260,6 +262,7 @@ macro_rules! class_definition {
};
}

#[cfg(feature = "legacy-runtime")]
#[doc(hidden)]
#[macro_export(local_inner_macros)]
macro_rules! impl_managed {
Expand All @@ -280,6 +283,7 @@ macro_rules! impl_managed {
}
}

#[cfg(feature = "legacy-runtime")]
/// Declare custom native JavaScript types with Rust implementations.
///
/// Example:
Expand Down Expand Up @@ -362,6 +366,7 @@ macro_rules! declare_types {
{ } => { };
}

#[cfg(feature = "legacy-runtime")]
#[doc(hidden)]
#[macro_export]
macro_rules! neon_stringify {
Expand Down
1 change: 1 addition & 0 deletions src/macro_internal/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Internals needed by macros. These have to be exported for the macros to work
/// but are subject to change and should never be explicitly used.

#[cfg(feature = "legacy-runtime")]
// Used by the class macro.
pub use object::class::internal::{AllocateCallback, ConstructCallback, ConstructorCallCallback, MethodCallback};
pub use context::internal::{initialize_module, Env};
Expand Down
40 changes: 2 additions & 38 deletions src/object/class/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ use std::slice;
use std::collections::HashMap;
use neon_runtime;
use neon_runtime::raw;
use neon_runtime::call::CCallback;
use context::{Context, Lock, CallbackInfo};
use context::{Context, Lock};
use context::internal::Env;
use result::{NeonResult, JsResult, Throw};
use borrow::{Borrow, BorrowMut, Ref, RefMut, LoanError};
use handle::{Handle, Managed};
use types::{Value, JsFunction, JsValue, build};
use types::internal::ValueInternal;
use types::internal::{Callback, ValueInternal};
use object::{Object, This};
use self::internal::{ClassMetadata, MethodCallback, ConstructorCallCallback, AllocateCallback, ConstructCallback};

Expand Down Expand Up @@ -260,38 +259,3 @@ impl<'a, T: Class> BorrowMut for &'a mut T {
}
}
}

/// A dynamically computed callback that can be passed through C to the engine.
/// This type makes it possible to export a dynamically computed Rust function
/// as a pair of 1) a raw pointer to the dynamically computed function, and 2)
/// a static function that knows how to transmute that raw pointer and call it.
pub(crate) trait Callback<T: Clone + Copy + Sized>: Sized {
/// Extracts the computed Rust function and invokes it. The Neon runtime
/// ensures that the computed function is provided as the extra data field,
/// wrapped as a V8 External, in the `CallbackInfo` argument.
extern "C" fn invoke(env: Env, info: CallbackInfo<'_>) -> T;

/// See `invoke`. This is used by the non-n-api implementation, so that every impl for this
/// trait doesn't need to provide two versions of `invoke`.
#[cfg(feature = "legacy-runtime")]
#[doc(hidden)]
extern "C" fn invoke_compat(info: CallbackInfo<'_>) -> T {
Self::invoke(Env::current(), info)
}

/// Converts the callback to a raw void pointer.
fn as_ptr(self) -> *mut c_void;

/// Exports the callback as a pair consisting of the static `Self::invoke`
/// method and the computed callback, both converted to raw void pointers.
fn into_c_callback(self) -> CCallback {
#[cfg(feature = "napi-1")]
let invoke = Self::invoke;
#[cfg(feature = "legacy-runtime")]
let invoke = Self::invoke_compat;
CCallback {
static_callback: unsafe { mem::transmute(invoke as usize) },
dynamic_callback: self.as_ptr()
}
}
}
2 changes: 2 additions & 0 deletions src/object/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! Traits for working with JavaScript objects.

#[cfg(feature = "legacy-runtime")]
pub(crate) mod class;

#[cfg(feature = "legacy-runtime")]
pub use self::class::{Class, ClassDescriptor};
pub use self::traits::*;

Expand Down
9 changes: 7 additions & 2 deletions src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@

pub use handle::Handle;
pub use types::{JsBuffer, JsArrayBuffer, BinaryData, JsError, Value, JsValue, JsUndefined, JsNull, JsBoolean, JsString, JsNumber, JsObject, JsArray, JsFunction};
pub use object::{Object, Class};
pub use object::Object;
#[cfg(feature = "legacy-runtime")]
pub use object::Class;
pub use borrow::{Borrow, BorrowMut};
pub use context::{CallKind, Context, ModuleContext, ExecuteContext, ComputeContext, CallContext, FunctionContext, MethodContext, TaskContext};
pub use result::{NeonResult, JsResult, JsResultExt};
#[cfg(feature = "legacy-runtime")]
pub use task::Task;
#[cfg(all(not(feature = "napi-1"), feature = "event-handler-api"))]
pub use event::EventHandler;
pub use crate::{register_module, declare_types};
pub use crate::register_module;
#[cfg(feature = "legacy-runtime")]
pub use crate::declare_types;
#[cfg(feature = "napi-1")]
pub use crate::{
handle::Root,
Expand Down
37 changes: 36 additions & 1 deletion src/types/internal.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::mem;
use std::os::raw::c_void;
use neon_runtime;
use neon_runtime::call::CCallback;
use neon_runtime::raw;
use context::{CallbackInfo, FunctionContext};
use context::internal::Env;
use types::error::convert_panics;
use types::{JsObject, Handle, Managed};
use result::JsResult;
use object::class::Callback;
use super::Value;

pub trait ValueInternal: Managed + 'static {
Expand Down Expand Up @@ -78,3 +78,38 @@ impl<T: Value> Callback<raw::Local> for FunctionCallback<T> {
unsafe { mem::transmute(self.0) }
}
}

/// A dynamically computed callback that can be passed through C to the engine.
/// This type makes it possible to export a dynamically computed Rust function
/// as a pair of 1) a raw pointer to the dynamically computed function, and 2)
/// a static function that knows how to transmute that raw pointer and call it.
pub(crate) trait Callback<T: Clone + Copy + Sized>: Sized {
/// Extracts the computed Rust function and invokes it. The Neon runtime
/// ensures that the computed function is provided as the extra data field,
/// wrapped as a V8 External, in the `CallbackInfo` argument.
extern "C" fn invoke(env: Env, info: CallbackInfo<'_>) -> T;

/// See `invoke`. This is used by the non-n-api implementation, so that every impl for this
/// trait doesn't need to provide two versions of `invoke`.
#[cfg(feature = "legacy-runtime")]
#[doc(hidden)]
extern "C" fn invoke_compat(info: CallbackInfo<'_>) -> T {
Self::invoke(Env::current(), info)
}

/// Converts the callback to a raw void pointer.
fn as_ptr(self) -> *mut c_void;

/// Exports the callback as a pair consisting of the static `Self::invoke`
/// method and the computed callback, both converted to raw void pointers.
fn into_c_callback(self) -> CCallback {
#[cfg(feature = "napi-1")]
let invoke = Self::invoke;
#[cfg(feature = "legacy-runtime")]
let invoke = Self::invoke_compat;
CCallback {
static_callback: unsafe { mem::transmute(invoke as usize) },
dynamic_callback: self.as_ptr()
}
}
}
Loading