mirror of
https://github.com/denoland/rusty_v8.git
synced 2025-01-12 09:04:02 -05:00
Add 'Object::has(_index)' and 'Object::delete(_index)' (#412)
This commit is contained in:
parent
b981aaceee
commit
8ebfb027c0
3 changed files with 102 additions and 0 deletions
|
@ -752,6 +752,30 @@ const v8::Array* v8__Object__GetPropertyNames(const v8::Object* self,
|
||||||
ptr_to_local(self)->GetPropertyNames(ptr_to_local(context)));
|
ptr_to_local(self)->GetPropertyNames(ptr_to_local(context)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MaybeBool v8__Object__Has(const v8::Object& self, const v8::Context& context,
|
||||||
|
const v8::Value& key) {
|
||||||
|
return maybe_to_maybe_bool(
|
||||||
|
ptr_to_local(&self)->Has(ptr_to_local(&context), ptr_to_local(&key)));
|
||||||
|
}
|
||||||
|
|
||||||
|
MaybeBool v8__Object__HasIndex(const v8::Object& self,
|
||||||
|
const v8::Context& context, uint32_t index) {
|
||||||
|
return maybe_to_maybe_bool(
|
||||||
|
ptr_to_local(&self)->Has(ptr_to_local(&context), index));
|
||||||
|
}
|
||||||
|
|
||||||
|
MaybeBool v8__Object__Delete(const v8::Object& self, const v8::Context& context,
|
||||||
|
const v8::Value& key) {
|
||||||
|
return maybe_to_maybe_bool(
|
||||||
|
ptr_to_local(&self)->Delete(ptr_to_local(&context), ptr_to_local(&key)));
|
||||||
|
}
|
||||||
|
|
||||||
|
MaybeBool v8__Object__DeleteIndex(const v8::Object& self,
|
||||||
|
const v8::Context& context, uint32_t index) {
|
||||||
|
return maybe_to_maybe_bool(
|
||||||
|
ptr_to_local(&self)->Delete(ptr_to_local(&context), index));
|
||||||
|
}
|
||||||
|
|
||||||
const v8::Array* v8__Array__New(v8::Isolate* isolate, int length) {
|
const v8::Array* v8__Array__New(v8::Isolate* isolate, int length) {
|
||||||
return local_to_ptr(v8::Array::New(isolate, length));
|
return local_to_ptr(v8::Array::New(isolate, length));
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,6 +79,26 @@ extern "C" {
|
||||||
this: *const Object,
|
this: *const Object,
|
||||||
context: *const Context,
|
context: *const Context,
|
||||||
) -> *const Array;
|
) -> *const Array;
|
||||||
|
fn v8__Object__Has(
|
||||||
|
this: *const Object,
|
||||||
|
context: *const Context,
|
||||||
|
key: *const Value,
|
||||||
|
) -> MaybeBool;
|
||||||
|
fn v8__Object__HasIndex(
|
||||||
|
this: *const Object,
|
||||||
|
context: *const Context,
|
||||||
|
index: u32,
|
||||||
|
) -> MaybeBool;
|
||||||
|
fn v8__Object__Delete(
|
||||||
|
this: *const Object,
|
||||||
|
context: *const Context,
|
||||||
|
key: *const Value,
|
||||||
|
) -> MaybeBool;
|
||||||
|
fn v8__Object__DeleteIndex(
|
||||||
|
this: *const Object,
|
||||||
|
context: *const Context,
|
||||||
|
index: u32,
|
||||||
|
) -> MaybeBool;
|
||||||
|
|
||||||
fn v8__Array__New(isolate: *mut Isolate, length: int) -> *const Array;
|
fn v8__Array__New(isolate: *mut Isolate, length: int) -> *const Array;
|
||||||
fn v8__Array__New_with_elements(
|
fn v8__Array__New_with_elements(
|
||||||
|
@ -311,6 +331,54 @@ impl Object {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calls the abstract operation HasProperty(O, P) described in ECMA-262,
|
||||||
|
// 7.3.10. Returns true, if the object has the property, either own or on the
|
||||||
|
// prototype chain. Interceptors, i.e., PropertyQueryCallbacks, are called if
|
||||||
|
// present.
|
||||||
|
//
|
||||||
|
// This function has the same side effects as JavaScript's variable in object.
|
||||||
|
// For example, calling this on a revoked proxy will throw an exception.
|
||||||
|
//
|
||||||
|
// Note: This function converts the key to a name, which possibly calls back
|
||||||
|
// into JavaScript.
|
||||||
|
pub fn has<'s>(
|
||||||
|
&self,
|
||||||
|
scope: &mut HandleScope<'s>,
|
||||||
|
key: Local<Value>,
|
||||||
|
) -> Option<bool> {
|
||||||
|
unsafe { v8__Object__Has(self, &*scope.get_current_context(), &*key) }
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn has_index<'s>(
|
||||||
|
&self,
|
||||||
|
scope: &mut HandleScope<'s>,
|
||||||
|
index: u32,
|
||||||
|
) -> Option<bool> {
|
||||||
|
unsafe { v8__Object__HasIndex(self, &*scope.get_current_context(), index) }
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn delete<'s>(
|
||||||
|
&self,
|
||||||
|
scope: &mut HandleScope<'s>,
|
||||||
|
key: Local<Value>,
|
||||||
|
) -> Option<bool> {
|
||||||
|
unsafe { v8__Object__Delete(self, &*scope.get_current_context(), &*key) }
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn delete_index<'s>(
|
||||||
|
&self,
|
||||||
|
scope: &mut HandleScope<'s>,
|
||||||
|
index: u32,
|
||||||
|
) -> Option<bool> {
|
||||||
|
unsafe {
|
||||||
|
v8__Object__DeleteIndex(self, &*scope.get_current_context(), index)
|
||||||
|
}
|
||||||
|
.into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Array {
|
impl Array {
|
||||||
|
|
|
@ -1190,6 +1190,12 @@ fn object() {
|
||||||
assert!(!object_.is_null_or_undefined());
|
assert!(!object_.is_null_or_undefined());
|
||||||
let id = object_.get_identity_hash();
|
let id = object_.get_identity_hash();
|
||||||
assert_ne!(id, 0);
|
assert_ne!(id, 0);
|
||||||
|
|
||||||
|
assert!(object.has(scope, n1.into()).unwrap());
|
||||||
|
let n_unused = v8::String::new(scope, "unused").unwrap().into();
|
||||||
|
assert!(!object.has(scope, n_unused).unwrap());
|
||||||
|
assert!(object.delete(scope, n1.into()).unwrap());
|
||||||
|
assert!(!object.has(scope, n1.into()).unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1230,6 +1236,10 @@ fn array() {
|
||||||
let maybe_v2 = array.get_index(scope, 1);
|
let maybe_v2 = array.get_index(scope, 1);
|
||||||
assert!(maybe_v2.is_some());
|
assert!(maybe_v2.is_some());
|
||||||
assert!(maybe_v2.unwrap().same_value(s2.into()));
|
assert!(maybe_v2.unwrap().same_value(s2.into()));
|
||||||
|
|
||||||
|
assert!(array.has_index(scope, 1).unwrap());
|
||||||
|
assert!(array.delete_index(scope, 1).unwrap());
|
||||||
|
assert!(!array.has_index(scope, 1).unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue