mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-12-26 00:59:28 -05:00
add Object::get_identity_hash (#169)
This commit is contained in:
parent
65f12fbdc0
commit
6c5f189063
3 changed files with 16 additions and 1 deletions
|
@ -610,6 +610,10 @@ v8::Isolate* v8__Object__GetIsolate(v8::Object& self) {
|
|||
return self.GetIsolate();
|
||||
}
|
||||
|
||||
int v8__Object__GetIdentityHash(v8::Object& self) {
|
||||
return self.GetIdentityHash();
|
||||
}
|
||||
|
||||
v8::Array* v8__Array__New(v8::Isolate* isolate, int length) {
|
||||
return local_to_ptr(v8::Array::New(isolate, length));
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ extern "C" {
|
|||
key: *const Name,
|
||||
value: *const Value,
|
||||
) -> MaybeBool;
|
||||
fn v8__Object__GetIdentityHash(object: &Object) -> int;
|
||||
|
||||
fn v8__Array__New(isolate: *mut Isolate, length: int) -> *mut Array;
|
||||
}
|
||||
|
@ -148,6 +149,15 @@ impl Object {
|
|||
pub fn get_isolate(&mut self) -> &Isolate {
|
||||
unsafe { v8__Object__GetIsolate(self) }
|
||||
}
|
||||
|
||||
/// Returns the identity hash for this object. The current implementation
|
||||
/// uses a hidden property on the object to store the identity hash.
|
||||
///
|
||||
/// The return value will never be 0. Also, it is not guaranteed to be
|
||||
/// unique.
|
||||
pub fn get_identity_hash(&self) -> int {
|
||||
unsafe { v8__Object__GetIdentityHash(self) }
|
||||
}
|
||||
}
|
||||
|
||||
impl Array {
|
||||
|
|
|
@ -827,7 +827,8 @@ fn object() {
|
|||
|
||||
let object_ = v8::Object::new(scope);
|
||||
assert!(!object_.is_null_or_undefined());
|
||||
|
||||
let id = object_.get_identity_hash();
|
||||
assert_ne!(id, 0);
|
||||
context.exit();
|
||||
}
|
||||
drop(locker);
|
||||
|
|
Loading…
Reference in a new issue