mirror of
https://github.com/denoland/rusty_v8.git
synced 2025-02-02 04:37:35 -05:00
Add v8::Object::HasOwnProperty bindings (#897)
This commit is contained in:
parent
0f34359fb4
commit
378631e793
3 changed files with 28 additions and 2 deletions
|
@ -1164,6 +1164,12 @@ MaybeBool v8__Object__HasIndex(const v8::Object& self,
|
||||||
ptr_to_local(&self)->Has(ptr_to_local(&context), index));
|
ptr_to_local(&self)->Has(ptr_to_local(&context), index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MaybeBool v8__Object__HasOwnProperty(const v8::Object& self, const v8::Context& context,
|
||||||
|
const v8::Name& key) {
|
||||||
|
return maybe_to_maybe_bool(
|
||||||
|
ptr_to_local(&self)->HasOwnProperty(ptr_to_local(&context), ptr_to_local(&key)));
|
||||||
|
}
|
||||||
|
|
||||||
MaybeBool v8__Object__Delete(const v8::Object& self, const v8::Context& context,
|
MaybeBool v8__Object__Delete(const v8::Object& self, const v8::Context& context,
|
||||||
const v8::Value& key) {
|
const v8::Value& key) {
|
||||||
return maybe_to_maybe_bool(
|
return maybe_to_maybe_bool(
|
||||||
|
|
|
@ -99,6 +99,11 @@ extern "C" {
|
||||||
context: *const Context,
|
context: *const Context,
|
||||||
index: u32,
|
index: u32,
|
||||||
) -> MaybeBool;
|
) -> MaybeBool;
|
||||||
|
fn v8__Object__HasOwnProperty(
|
||||||
|
this: *const Object,
|
||||||
|
context: *const Context,
|
||||||
|
key: *const Name,
|
||||||
|
) -> MaybeBool;
|
||||||
fn v8__Object__Delete(
|
fn v8__Object__Delete(
|
||||||
this: *const Object,
|
this: *const Object,
|
||||||
context: *const Context,
|
context: *const Context,
|
||||||
|
@ -446,6 +451,18 @@ impl Object {
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// HasOwnProperty() is like JavaScript's Object.prototype.hasOwnProperty().
|
||||||
|
pub fn has_own_property<'s>(
|
||||||
|
&self,
|
||||||
|
scope: &mut HandleScope<'s>,
|
||||||
|
key: Local<Name>,
|
||||||
|
) -> Option<bool> {
|
||||||
|
unsafe {
|
||||||
|
v8__Object__HasOwnProperty(self, &*scope.get_current_context(), &*key)
|
||||||
|
}
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn delete<'s>(
|
pub fn delete<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
|
|
@ -1550,10 +1550,13 @@ fn object() {
|
||||||
assert_ne!(id, 0);
|
assert_ne!(id, 0);
|
||||||
|
|
||||||
assert!(object.has(scope, n1.into()).unwrap());
|
assert!(object.has(scope, n1.into()).unwrap());
|
||||||
let n_unused = v8::String::new(scope, "unused").unwrap().into();
|
assert!(object.has_own_property(scope, n1).unwrap());
|
||||||
assert!(!object.has(scope, n_unused).unwrap());
|
let n_unused = v8::String::new(scope, "unused").unwrap();
|
||||||
|
assert!(!object.has(scope, n_unused.into()).unwrap());
|
||||||
|
assert!(!object.has_own_property(scope, n_unused.into()).unwrap());
|
||||||
assert!(object.delete(scope, n1.into()).unwrap());
|
assert!(object.delete(scope, n1.into()).unwrap());
|
||||||
assert!(!object.has(scope, n1.into()).unwrap());
|
assert!(!object.has(scope, n1.into()).unwrap());
|
||||||
|
assert!(!object.has_own_property(scope, n1).unwrap());
|
||||||
|
|
||||||
let global = context.global(scope);
|
let global = context.global(scope);
|
||||||
let object_string = v8::String::new(scope, "o").unwrap().into();
|
let object_string = v8::String::new(scope, "o").unwrap().into();
|
||||||
|
|
Loading…
Add table
Reference in a new issue