mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-11-21 15:04:33 -05:00
Add v8::Value::InstanceOf bindings (#879)
This commit is contained in:
parent
cc41870e68
commit
0f34359fb4
3 changed files with 48 additions and 1 deletions
|
@ -682,6 +682,12 @@ const v8::Boolean* v8__Value__ToBoolean(const v8::Value& self,
|
|||
return local_to_ptr(self.ToBoolean(isolate));
|
||||
}
|
||||
|
||||
void v8__Value__InstanceOf(const v8::Value& self, const v8::Context& context,
|
||||
const v8::Object& object, v8::Maybe<bool>* out) {
|
||||
v8::Value* self_non_const = const_cast<v8::Value*>(&self);
|
||||
*out = self_non_const->InstanceOf(ptr_to_local(&context), ptr_to_local(&object));
|
||||
}
|
||||
|
||||
void v8__Value__NumberValue(const v8::Value& self, const v8::Context& context,
|
||||
v8::Maybe<double>* out) {
|
||||
*out = self.NumberValue(ptr_to_local(&context));
|
||||
|
|
24
src/value.rs
24
src/value.rs
|
@ -72,7 +72,12 @@ extern "C" {
|
|||
fn v8__Value__IsModuleNamespaceObject(this: *const Value) -> bool;
|
||||
fn v8__Value__StrictEquals(this: *const Value, that: *const Value) -> bool;
|
||||
fn v8__Value__SameValue(this: *const Value, that: *const Value) -> bool;
|
||||
|
||||
fn v8__Value__InstanceOf(
|
||||
this: *const Value,
|
||||
context: *const Context,
|
||||
object: *const Object,
|
||||
out: *mut Maybe<bool>,
|
||||
);
|
||||
fn v8__Value__ToBigInt(
|
||||
this: *const Value,
|
||||
context: *const Context,
|
||||
|
@ -551,6 +556,23 @@ impl Value {
|
|||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn instance_of<'s>(
|
||||
&self,
|
||||
scope: &mut HandleScope<'s>,
|
||||
object: Local<Object>,
|
||||
) -> Option<bool> {
|
||||
let mut out = Maybe::<bool>::default();
|
||||
unsafe {
|
||||
v8__Value__InstanceOf(
|
||||
self,
|
||||
&*scope.get_current_context(),
|
||||
&*object,
|
||||
&mut out,
|
||||
);
|
||||
}
|
||||
out.into()
|
||||
}
|
||||
|
||||
pub fn number_value<'s>(&self, scope: &mut HandleScope<'s>) -> Option<f64> {
|
||||
let mut out = Maybe::<f64>::default();
|
||||
unsafe {
|
||||
|
|
|
@ -5884,3 +5884,22 @@ fn current_stack_trace() {
|
|||
.unwrap();
|
||||
assert_eq!(too_deep, 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn instance_of() {
|
||||
let _setup_guard = setup();
|
||||
|
||||
let mut isolate = v8::Isolate::new(Default::default());
|
||||
let mut scope = v8::HandleScope::new(&mut isolate);
|
||||
let context = v8::Context::new(&mut scope);
|
||||
let mut scope = v8::ContextScope::new(&mut scope, context);
|
||||
let global = context.global(&mut scope);
|
||||
let array_name = v8::String::new(&mut scope, "Array").unwrap();
|
||||
let array_constructor = global.get(&mut scope, array_name.into()).unwrap();
|
||||
let array_constructor =
|
||||
v8::Local::<v8::Object>::try_from(array_constructor).unwrap();
|
||||
let array: v8::Local<v8::Value> =
|
||||
v8::Array::new_with_elements(&mut scope, &[]).into();
|
||||
|
||||
assert!(array.instance_of(&mut scope, array_constructor).unwrap());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue