OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "include/dart_api.h" | 5 #include "include/dart_api.h" |
6 #include "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
8 | 8 |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "vm/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 } | 592 } |
593 const Object& object1 = Object::Handle(isolate, Api::UnwrapHandle(obj1)); | 593 const Object& object1 = Object::Handle(isolate, Api::UnwrapHandle(obj1)); |
594 const Object& object2 = Object::Handle(isolate, Api::UnwrapHandle(obj2)); | 594 const Object& object2 = Object::Handle(isolate, Api::UnwrapHandle(obj2)); |
595 if (object1.IsInstance() && object2.IsInstance()) { | 595 if (object1.IsInstance() && object2.IsInstance()) { |
596 return Instance::Cast(object1).IsIdenticalTo(Instance::Cast(object2)); | 596 return Instance::Cast(object1).IsIdenticalTo(Instance::Cast(object2)); |
597 } | 597 } |
598 return false; | 598 return false; |
599 } | 599 } |
600 | 600 |
601 | 601 |
| 602 DART_EXPORT uint64_t Dart_IdentityHash(Dart_Handle obj) { |
| 603 Isolate* isolate = Isolate::Current(); |
| 604 DARTSCOPE(isolate); |
| 605 |
| 606 const Object& object = Object::Handle(isolate, Api::UnwrapHandle(obj)); |
| 607 if (!object.IsInstance() && !object.IsNull()) { |
| 608 return 0; |
| 609 } |
| 610 |
| 611 const Library& libcore = Library::Handle(isolate, Library::CoreLibrary()); |
| 612 const String& function_name = String::Handle(isolate, |
| 613 String::New("identityHashCode")); |
| 614 const Function& function = |
| 615 Function::Handle(isolate, |
| 616 libcore.LookupFunctionAllowPrivate(function_name)); |
| 617 if (function.IsNull()) { |
| 618 UNREACHABLE(); |
| 619 return 0; |
| 620 } |
| 621 |
| 622 const Array& arguments = Array::Handle(isolate, Array::New(1)); |
| 623 arguments.SetAt(0, object); |
| 624 const Object& result = |
| 625 Object::Handle(isolate, DartEntry::InvokeFunction(function, arguments)); |
| 626 |
| 627 if (result.IsSmi()) { |
| 628 return Smi::Cast(result).Value(); |
| 629 } |
| 630 if (result.IsMint()) { |
| 631 const Mint& mint = Mint::Cast(result); |
| 632 if (!mint.IsNegative()) { |
| 633 return mint.AsInt64Value(); |
| 634 } |
| 635 } |
| 636 if (result.IsBigint()) { |
| 637 const Bigint& bigint = Bigint::Cast(result); |
| 638 if (BigintOperations::FitsIntoUint64(bigint)) { |
| 639 return BigintOperations::ToUint64(bigint); |
| 640 } |
| 641 } |
| 642 return 0; |
| 643 } |
| 644 |
| 645 |
602 DART_EXPORT Dart_Handle Dart_HandleFromPersistent( | 646 DART_EXPORT Dart_Handle Dart_HandleFromPersistent( |
603 Dart_PersistentHandle object) { | 647 Dart_PersistentHandle object) { |
604 Isolate* isolate = Isolate::Current(); | 648 Isolate* isolate = Isolate::Current(); |
605 CHECK_ISOLATE(isolate); | 649 CHECK_ISOLATE(isolate); |
606 ApiState* state = isolate->api_state(); | 650 ApiState* state = isolate->api_state(); |
607 ASSERT(state != NULL); | 651 ASSERT(state != NULL); |
608 PersistentHandle* ref = PersistentHandle::Cast(object); | 652 PersistentHandle* ref = PersistentHandle::Cast(object); |
609 return Api::NewHandle(isolate, ref->raw()); | 653 return Api::NewHandle(isolate, ref->raw()); |
610 } | 654 } |
611 | 655 |
(...skipping 4127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4739 | 4783 |
4740 | 4784 |
4741 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 4785 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
4742 const char* name, | 4786 const char* name, |
4743 Dart_ServiceRequestCallback callback, | 4787 Dart_ServiceRequestCallback callback, |
4744 void* user_data) { | 4788 void* user_data) { |
4745 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 4789 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
4746 } | 4790 } |
4747 | 4791 |
4748 } // namespace dart | 4792 } // namespace dart |
OLD | NEW |