Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 263823004: Add Dart_IdentityHash to the embedding API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: doc Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698