0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-12-25 08:39:15 -05:00

add v8::ReturnValue (#66)

This commit is contained in:
Bartek Iwańczuk 2019-12-14 23:14:09 +01:00 committed by Ry Dahl
parent f37085c370
commit 7b094328ea
4 changed files with 41 additions and 3 deletions

View file

@ -39,4 +39,11 @@ void v8__FunctionCallbackInfo__SetReturnValue(v8::FunctionCallbackInfo<v8::Value
auto rv = self->GetReturnValue();
rv.Set(value);
}
v8::ReturnValue<v8::Value> *v8__FunctionCallbackInfo__GetReturnValue(v8::FunctionCallbackInfo<v8::Value> *self)
{
v8::ReturnValue<v8::Value>* return_value = nullptr;
*return_value = self->GetReturnValue();
return return_value;
}
}

View file

@ -1,6 +1,7 @@
use crate::isolate::{CxxIsolate, LockedIsolate};
use crate::support::{int, Opaque};
use crate::Context;
use crate::HandleScope;
use crate::Local;
use crate::Value;
@ -34,6 +35,32 @@ extern "C" {
info: &FunctionCallbackInfo,
value: *mut Value,
);
fn v8__FunctionCallbackInfo__GetReturnValue(
info: &FunctionCallbackInfo,
) -> ReturnValue<Value>;
}
#[repr(C)]
pub struct ReturnValue<T>(T, Opaque);
impl <T>ReturnValue<T> {
// NOTE: simplest setter, possibly we'll need to add
// more setters specialized per type
pub fn set<U>(&self, _value: Local<'_, U>) {
unimplemented!();
}
/// Convenience getter for Isolate
pub fn get_isolate(&self) -> &mut CxxIsolate {
unimplemented!();
}
/// Getter. Creates a new Local<> so it comes with a certain performance
/// hit. If the ReturnValue was not yet set, this will return the undefined
/// value.
pub fn get<'sc>(&self, _scope: &mut HandleScope<'sc>) -> Local<'sc, Value> {
unimplemented!();
}
}
#[repr(C)]
@ -44,6 +71,10 @@ impl FunctionCallbackInfo {
unsafe { v8__FunctionCallbackInfo__SetReturnValue(&*self, &mut *value) };
}
pub fn get_return_value(&self) -> ReturnValue<Value> {
unsafe { v8__FunctionCallbackInfo__GetReturnValue(&*self) }
}
pub fn get_isolate(&self) -> &mut CxxIsolate {
unsafe { v8__FunctionCallbackInfo__GetIsolate(self) }
}

View file

@ -1,8 +1,8 @@
use crate::value::Value;
use std::marker::PhantomData;
use std::ops::Deref;
use std::ops::DerefMut;
use std::ptr::NonNull;
use crate::value::Value;
pub struct Local<'sc, T>(NonNull<T>, PhantomData<&'sc ()>);
@ -33,7 +33,7 @@ impl<'sc, T> DerefMut for Local<'sc, T> {
}
}
// TODO make it possible for targets other than Local<Value>. For example
// TODO make it possible for targets other than Local<Value>. For example
// Local<String> should be able to be down cast to Local<Name>.
impl<'sc, T> From<Local<'sc, T>> for Local<'sc, Value>
where

View file

@ -3,9 +3,9 @@ use std::ops::Deref;
use crate::isolate::CxxIsolate;
use crate::isolate::LockedIsolate;
use crate::support::Opaque;
use crate::value::Value;
use crate::HandleScope;
use crate::Local;
use crate::value::Value;
extern "C" {
fn v8__Number__New(isolate: &mut CxxIsolate, value: f64) -> *mut Number;