Index: runtime/vm/dart_api_impl.cc |
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc |
index 070d646c975b60b8603d4836301f084ec22aca7d..3fd21df97db5f576021cb6e5c7e6954baffaa6f6 100644 |
--- a/runtime/vm/dart_api_impl.cc |
+++ b/runtime/vm/dart_api_impl.cc |
@@ -599,6 +599,50 @@ DART_EXPORT bool Dart_IdentityEquals(Dart_Handle obj1, Dart_Handle obj2) { |
} |
+DART_EXPORT uint64_t Dart_IdentityHash(Dart_Handle obj) { |
+ Isolate* isolate = Isolate::Current(); |
+ DARTSCOPE(isolate); |
+ |
+ const Object& object = Object::Handle(isolate, Api::UnwrapHandle(obj)); |
+ if (!object.IsInstance() && !object.IsNull()) { |
+ return 0; |
+ } |
+ |
+ const Library& libcore = Library::Handle(isolate, Library::CoreLibrary()); |
+ const String& function_name = String::Handle(isolate, |
+ String::New("identityHashCode")); |
+ const Function& function = |
+ Function::Handle(isolate, |
+ libcore.LookupFunctionAllowPrivate(function_name)); |
+ if (function.IsNull()) { |
+ UNREACHABLE(); |
+ return 0; |
+ } |
+ |
+ const Array& arguments = Array::Handle(isolate, Array::New(1)); |
+ arguments.SetAt(0, object); |
+ const Object& result = |
+ Object::Handle(isolate, DartEntry::InvokeFunction(function, arguments)); |
+ |
+ if (result.IsSmi()) { |
+ return Smi::Cast(result).Value(); |
+ } |
+ if (result.IsMint()) { |
+ const Mint& mint = Mint::Cast(result); |
+ if (!mint.IsNegative()) { |
+ return mint.AsInt64Value(); |
+ } |
+ } |
+ if (result.IsBigint()) { |
+ const Bigint& bigint = Bigint::Cast(result); |
+ if (BigintOperations::FitsIntoUint64(bigint)) { |
+ return BigintOperations::ToUint64(bigint); |
+ } |
+ } |
+ return 0; |
+} |
+ |
+ |
DART_EXPORT Dart_Handle Dart_HandleFromPersistent( |
Dart_PersistentHandle object) { |
Isolate* isolate = Isolate::Current(); |