diff --git a/src/binding.cc b/src/binding.cc index bc1dc7f3..774ed23c 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -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)); } diff --git a/src/object.rs b/src/object.rs index f342bdc0..ce89da52 100644 --- a/src/object.rs +++ b/src/object.rs @@ -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 { diff --git a/tests/test_api.rs b/tests/test_api.rs index e476af8f..59c73c46 100644 --- a/tests/test_api.rs +++ b/tests/test_api.rs @@ -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);