mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-12-26 09:13:46 -05:00
add v8::ReturnValue (#66)
This commit is contained in:
parent
f37085c370
commit
7b094328ea
4 changed files with 41 additions and 3 deletions
|
@ -39,4 +39,11 @@ void v8__FunctionCallbackInfo__SetReturnValue(v8::FunctionCallbackInfo<v8::Value
|
||||||
auto rv = self->GetReturnValue();
|
auto rv = self->GetReturnValue();
|
||||||
rv.Set(value);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::isolate::{CxxIsolate, LockedIsolate};
|
use crate::isolate::{CxxIsolate, LockedIsolate};
|
||||||
use crate::support::{int, Opaque};
|
use crate::support::{int, Opaque};
|
||||||
use crate::Context;
|
use crate::Context;
|
||||||
|
use crate::HandleScope;
|
||||||
use crate::Local;
|
use crate::Local;
|
||||||
use crate::Value;
|
use crate::Value;
|
||||||
|
|
||||||
|
@ -34,6 +35,32 @@ extern "C" {
|
||||||
info: &FunctionCallbackInfo,
|
info: &FunctionCallbackInfo,
|
||||||
value: *mut Value,
|
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)]
|
#[repr(C)]
|
||||||
|
@ -44,6 +71,10 @@ impl FunctionCallbackInfo {
|
||||||
unsafe { v8__FunctionCallbackInfo__SetReturnValue(&*self, &mut *value) };
|
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 {
|
pub fn get_isolate(&self) -> &mut CxxIsolate {
|
||||||
unsafe { v8__FunctionCallbackInfo__GetIsolate(self) }
|
unsafe { v8__FunctionCallbackInfo__GetIsolate(self) }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
use crate::value::Value;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::ops::DerefMut;
|
use std::ops::DerefMut;
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
use crate::value::Value;
|
|
||||||
|
|
||||||
pub struct Local<'sc, T>(NonNull<T>, PhantomData<&'sc ()>);
|
pub struct Local<'sc, T>(NonNull<T>, PhantomData<&'sc ()>);
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,9 @@ use std::ops::Deref;
|
||||||
use crate::isolate::CxxIsolate;
|
use crate::isolate::CxxIsolate;
|
||||||
use crate::isolate::LockedIsolate;
|
use crate::isolate::LockedIsolate;
|
||||||
use crate::support::Opaque;
|
use crate::support::Opaque;
|
||||||
|
use crate::value::Value;
|
||||||
use crate::HandleScope;
|
use crate::HandleScope;
|
||||||
use crate::Local;
|
use crate::Local;
|
||||||
use crate::value::Value;
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
fn v8__Number__New(isolate: &mut CxxIsolate, value: f64) -> *mut Number;
|
fn v8__Number__New(isolate: &mut CxxIsolate, value: f64) -> *mut Number;
|
||||||
|
|
Loading…
Reference in a new issue