0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-11-21 15:04:33 -05:00

Add ReturnValue::set_bool (#1020)

This commit is contained in:
Divy Srivastava 2022-07-04 07:02:13 +05:30 committed by GitHub
parent 61714dd2b2
commit e6b443a6e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 4 deletions

View file

@ -1846,6 +1846,10 @@ void v8__ReturnValue__Set(v8::ReturnValue<v8::Value>* self,
self->Set(ptr_to_local(&value));
}
void v8__ReturnValue__Set__Bool(v8::ReturnValue<v8::Value>* self, bool i) {
self->Set(i);
}
void v8__ReturnValue__Set__Int32(v8::ReturnValue<v8::Value>* self, int32_t i) {
self->Set(i);
}
@ -1859,10 +1863,6 @@ void v8__ReturnValue__Set__Double(v8::ReturnValue<v8::Value>* self, double i) {
self->Set(i);
}
void v8__ReturnValue__Set__Bool(v8::ReturnValue<v8::Value>* self, bool value) {
self->Set(value);
}
void v8__ReturnValue__SetNull(v8::ReturnValue<v8::Value>* self) {
self->SetNull();
}

View file

@ -78,6 +78,7 @@ extern "C" {
) -> *const Object;
fn v8__ReturnValue__Set(this: *mut ReturnValue, value: *const Value);
fn v8__ReturnValue__Set__Bool(this: *mut ReturnValue, value: bool);
fn v8__ReturnValue__Set__Int32(this: *mut ReturnValue, value: i32);
fn v8__ReturnValue__Set__Uint32(this: *mut ReturnValue, value: u32);
fn v8__ReturnValue__Set__Double(this: *mut ReturnValue, value: f64);
@ -148,6 +149,10 @@ impl<'cb> ReturnValue<'cb> {
unsafe { v8__ReturnValue__Set(&mut *self, &*value) }
}
pub fn set_bool(&mut self, value: bool) {
unsafe { v8__ReturnValue__Set__Bool(&mut *self, value) }
}
pub fn set_int32(&mut self, value: i32) {
unsafe { v8__ReturnValue__Set__Int32(&mut *self, value) }
}

View file

@ -2324,6 +2324,29 @@ fn return_value() {
let global = context.global(scope);
let recv: v8::Local<v8::Value> = global.into();
// set_bool
{
let template = v8::FunctionTemplate::new(
scope,
|scope: &mut v8::HandleScope,
args: v8::FunctionCallbackArguments,
mut rv: v8::ReturnValue| {
assert_eq!(args.length(), 0);
assert!(rv.get(scope).is_undefined());
rv.set_bool(false);
},
);
let function = template
.get_function(scope)
.expect("Unable to create function");
let value = function
.call(scope, recv, &[])
.expect("Function call failed");
assert!(value.is_boolean());
assert!(!value.is_true());
}
// set_int32
{
let template = v8::FunctionTemplate::new(