Skip to content

Commit

Permalink
Move mem into js.
Browse files Browse the repository at this point in the history
  • Loading branch information
dherman committed Jul 9, 2018
1 parent bfc9e89 commit 9b0a6b3
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 31 deletions.
3 changes: 2 additions & 1 deletion src/js/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use std::marker::PhantomData;
use std::mem;
use std::os::raw::c_void;
use std::slice;
use vm::{Context, JsResult, Managed};
use vm::{Context, JsResult};
use js::{Value, Object, Borrow, BorrowMut, Ref, RefMut, LoanError, build};
use js::mem::Managed;
use js::internal::ValueInternal;
use vm::VmGuard;
use vm::internal::Pointer;
Expand Down
8 changes: 4 additions & 4 deletions src/js/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use std::os::raw::c_void;
use std::slice;
use neon_runtime;
use neon_runtime::raw;
use vm::{JsResult, VmResult, Throw, This, Context, VmGuard, Callback, Handle, Managed};
use vm::{JsResult, VmResult, Throw, This, Context, VmGuard, Callback};
use vm::internal::Isolate;
use js::{Value, JsFunction, Object, JsValue, Borrow, BorrowMut, Ref, RefMut, LoanError, build};
use js::{Value, JsFunction, Object, JsValue, Handle, Managed, Borrow, BorrowMut, Ref, RefMut, LoanError, build};
use js::internal::ValueInternal;
use self::internal::{ClassMetadata, MethodCallback, ConstructorCallCallback, AllocateCallback, ConstructCallback};

Expand All @@ -19,8 +19,8 @@ pub(crate) mod internal {
use neon_runtime;
use neon_runtime::raw;
use super::{Class, ClassInternal};
use js::{JsValue, JsObject, JsFunction, JsUndefined, build};
use vm::{JsResult, VmResult, CallbackInfo, Callback, CallContext, Context, Throw, Handle, Managed};
use js::{JsValue, JsObject, JsFunction, JsUndefined, Handle, Managed, build};
use vm::{JsResult, VmResult, CallbackInfo, Callback, CallContext, Context, Throw};
use vm::internal::ContextInternal;
use js::error::convert_panics;

Expand Down
4 changes: 2 additions & 2 deletions src/js/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use std::panic::{UnwindSafe, catch_unwind};
use neon_runtime;
use neon_runtime::raw;

use vm::{Throw, Context, VmResult, Handle, Managed};
use js::{Value, Object, ToJsString, build};
use vm::{Throw, Context, VmResult};
use js::{Value, Object, ToJsString, Handle, Managed, build};
use js::internal::ValueInternal;

/// A JS `Error` object.
Expand Down
File renamed without changes.
34 changes: 18 additions & 16 deletions src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,32 @@
pub(crate) mod binary;
pub(crate) mod error;
pub(crate) mod class;
pub(crate) mod mem;

use std;
use std::fmt;
use std::mem;
use std::os::raw::c_void;
use std::marker::PhantomData;
use std::ops::{Deref, DerefMut, Drop};
use neon_runtime;
use neon_runtime::raw;
use vm::{Context, VmGuard, FunctionContext, Callback, VmResult, Throw, JsResult, JsResultExt, This, Handle, Managed};
use vm::{Context, VmGuard, FunctionContext, Callback, VmResult, Throw, JsResult, JsResultExt, This};
use vm::internal::{Isolate, Pointer};
use self::internal::{ValueInternal, SuperType, FunctionCallback};

pub use self::binary::{JsBuffer, JsArrayBuffer, BinaryData, BinaryViewType};
pub use self::class::{Class, ClassDescriptor};
pub use self::error::{JsError, ErrorKind};
pub use self::mem::{Handle, Managed, DowncastError, DowncastResult};

pub(crate) mod internal {
use std::mem;
use std::os::raw::c_void;
use neon_runtime;
use neon_runtime::raw;
use vm::{JsResult, CallbackInfo, FunctionContext, Callback, Handle, Managed};
use vm::{JsResult, CallbackInfo, FunctionContext, Callback};
use js::error::convert_panics;
use js::JsObject;
use js::{JsObject, Handle, Managed};
use super::Value;

pub trait ValueInternal: Managed + 'static {
Expand Down Expand Up @@ -76,7 +78,7 @@ pub(crate) mod internal {

pub(crate) fn build<'a, T: Managed, F: FnOnce(&mut raw::Local) -> bool>(init: F) -> JsResult<'a, T> {
unsafe {
let mut local: raw::Local = mem::zeroed();
let mut local: raw::Local = std::mem::zeroed();
if init(&mut local) {
Ok(Handle::new_internal(T::from_raw(local)))
} else {
Expand Down Expand Up @@ -153,7 +155,7 @@ impl JsUndefined {

pub(crate) fn new_internal<'a>() -> Handle<'a, JsUndefined> {
unsafe {
let mut local: raw::Local = mem::zeroed();
let mut local: raw::Local = std::mem::zeroed();
neon_runtime::primitive::undefined(&mut local);
Handle::new_internal(JsUndefined(local))
}
Expand All @@ -171,7 +173,7 @@ impl Managed for JsUndefined {
unsafe impl This for JsUndefined {
fn as_this(_: raw::Local) -> Self {
unsafe {
let mut local: raw::Local = mem::zeroed();
let mut local: raw::Local = std::mem::zeroed();
neon_runtime::primitive::undefined(&mut local);
JsUndefined(local)
}
Expand All @@ -198,7 +200,7 @@ impl JsNull {

pub(crate) fn new_internal<'a>() -> Handle<'a, JsNull> {
unsafe {
let mut local: raw::Local = mem::zeroed();
let mut local: raw::Local = std::mem::zeroed();
neon_runtime::primitive::null(&mut local);
Handle::new_internal(JsNull(local))
}
Expand Down Expand Up @@ -233,7 +235,7 @@ impl JsBoolean {

pub(crate) fn new_internal<'a>(b: bool) -> Handle<'a, JsBoolean> {
unsafe {
let mut local: raw::Local = mem::zeroed();
let mut local: raw::Local = std::mem::zeroed();
neon_runtime::primitive::boolean(&mut local, b);
Handle::new_internal(JsBoolean(local))
}
Expand Down Expand Up @@ -315,7 +317,7 @@ impl JsString {
let capacity = neon_runtime::string::utf8_len(self.to_raw());
let mut buffer: Vec<u8> = Vec::with_capacity(capacity as usize);
let p = buffer.as_mut_ptr();
mem::forget(buffer);
std::mem::forget(buffer);
let len = neon_runtime::string::data(p, capacity, self.to_raw());
String::from_raw_parts(p, len as usize, capacity as usize)
}
Expand All @@ -339,7 +341,7 @@ impl JsString {
None => { return None; }
};
unsafe {
let mut local: raw::Local = mem::zeroed();
let mut local: raw::Local = std::mem::zeroed();
if neon_runtime::string::new(&mut local, isolate.to_raw(), ptr, len) {
Some(Handle::new_internal(JsString(local)))
} else {
Expand Down Expand Up @@ -401,7 +403,7 @@ impl JsNumber {

pub(crate) fn new_internal<'a>(isolate: Isolate, v: f64) -> Handle<'a, JsNumber> {
unsafe {
let mut local: raw::Local = mem::zeroed();
let mut local: raw::Local = std::mem::zeroed();
neon_runtime::primitive::number(&mut local, isolate.to_raw(), v);
Handle::new_internal(JsNumber(local))
}
Expand Down Expand Up @@ -526,7 +528,7 @@ impl JsObject {

pub(crate) fn build<'a, F: FnOnce(&mut raw::Local)>(init: F) -> Handle<'a, JsObject> {
unsafe {
let mut local: raw::Local = mem::zeroed();
let mut local: raw::Local = std::mem::zeroed();
init(&mut local);
Handle::new_internal(JsObject(local))
}
Expand All @@ -546,7 +548,7 @@ impl JsArray {

pub(crate) fn new_internal<'a>(isolate: Isolate, len: u32) -> Handle<'a, JsArray> {
unsafe {
let mut local: raw::Local = mem::zeroed();
let mut local: raw::Local = std::mem::zeroed();
neon_runtime::array::new(&mut local, isolate.to_raw(), len);
Handle::new_internal(JsArray(local))
}
Expand Down Expand Up @@ -612,7 +614,7 @@ unsafe fn prepare_call<'a, 'b, C: Context<'a>, A>(cx: &mut C, args: &mut [Handle
if argc > V8_ARGC_LIMIT {
return JsError::throw(cx, ErrorKind::RangeError, "too many arguments");
}
let isolate: *mut c_void = mem::transmute(cx.isolate().to_raw());
let isolate: *mut c_void = std::mem::transmute(cx.isolate().to_raw());
Ok((isolate, argc as i32, argv as *mut c_void))
}

Expand All @@ -623,7 +625,7 @@ impl JsFunction {
{
build(|out| {
unsafe {
let isolate: *mut c_void = mem::transmute(cx.isolate().to_raw());
let isolate: *mut c_void = std::mem::transmute(cx.isolate().to_raw());
let callback = FunctionCallback(f).into_c_callback();
neon_runtime::fun::new(out, isolate, callback)
}
Expand Down
4 changes: 2 additions & 2 deletions src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! The Neon "prelude," a re-exported collection of the most commonly-used Neon APIs.
pub use js::{JsBuffer, JsArrayBuffer, BinaryData, Class, JsError, ErrorKind, Value, JsValue, JsUndefined, JsNull, JsBoolean, JsString, ToJsString, JsNumber, JsObject, Object, JsArray, JsFunction, Borrow, BorrowMut};
pub use vm::{Handle, DowncastError, DowncastResult, VmResult, JsResult, JsResultExt, CallKind, Context, ModuleContext, ExecuteContext, ComputeContext, CallContext, FunctionContext, MethodContext};
pub use js::{Handle, JsBuffer, JsArrayBuffer, BinaryData, Class, JsError, ErrorKind, Value, JsValue, JsUndefined, JsNull, JsBoolean, JsString, ToJsString, JsNumber, JsObject, Object, JsArray, JsFunction, Borrow, BorrowMut};
pub use vm::{VmResult, JsResult, JsResultExt, CallKind, Context, ModuleContext, ExecuteContext, ComputeContext, CallContext, FunctionContext, MethodContext};
3 changes: 2 additions & 1 deletion src/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use std::mem;
use std::os::raw::c_void;

use js::{Value, JsFunction};
use vm::{TaskContext, JsResult, Handle, Managed};
use js::mem::{Handle, Managed};
use vm::{TaskContext, JsResult};
use neon_runtime;
use neon_runtime::raw;

Expand Down
7 changes: 2 additions & 5 deletions src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ use neon_runtime;
use neon_runtime::raw;
use neon_runtime::call::CCallback;
use js::{JsValue, Value, Object, JsObject, JsArray, JsFunction, JsBoolean, JsNumber, JsString, StringResult, JsNull, JsUndefined, Ref, RefMut, Borrow, BorrowMut};
use js::mem::{Managed, Handle};
use js::binary::{JsArrayBuffer, JsBuffer};
use js::class::internal::ClassMetadata;
use js::class::Class;
use js::error::{JsError, ErrorKind};
use self::internal::{Ledger, ContextInternal, Scope, ScopeMetadata};

pub(crate) mod mem;

pub use self::mem::{Managed, Handle, DowncastError, DowncastResult};

pub(crate) mod internal {
use std;
use std::cell::Cell;
Expand All @@ -32,7 +29,7 @@ pub(crate) mod internal {
use neon_runtime;
use neon_runtime::raw;
use neon_runtime::scope::Root;
use super::mem::Handle;
use js::mem::Handle;
use vm::VmResult;
use js::{JsObject, LoanError};
use super::{ClassMap, ModuleContext};
Expand Down

0 comments on commit 9b0a6b3

Please sign in to comment.