| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "vm/dart_api_impl.h" | 5 #include "vm/dart_api_impl.h" |
| 6 #include "bin/builtin.h" | 6 #include "bin/builtin.h" |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "include/dart_mirrors_api.h" | 8 #include "include/dart_mirrors_api.h" |
| 9 #include "include/dart_native_api.h" | 9 #include "include/dart_native_api.h" |
| 10 #include "include/dart_tools_api.h" | 10 #include "include/dart_tools_api.h" |
| (...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 EXPECT(Dart_IdentityEquals(lib1, lib1)); | 652 EXPECT(Dart_IdentityEquals(lib1, lib1)); |
| 653 EXPECT(Dart_IdentityEquals(lib2, lib2)); | 653 EXPECT(Dart_IdentityEquals(lib2, lib2)); |
| 654 EXPECT(!Dart_IdentityEquals(lib1, lib2)); | 654 EXPECT(!Dart_IdentityEquals(lib1, lib2)); |
| 655 | 655 |
| 656 // Mix instance and non-instance. | 656 // Mix instance and non-instance. |
| 657 EXPECT(!Dart_IdentityEquals(lib1, nan1)); | 657 EXPECT(!Dart_IdentityEquals(lib1, nan1)); |
| 658 EXPECT(!Dart_IdentityEquals(nan1, lib1)); | 658 EXPECT(!Dart_IdentityEquals(nan1, lib1)); |
| 659 } | 659 } |
| 660 } | 660 } |
| 661 | 661 |
| 662 TEST_CASE(IdentityHash) { | |
| 663 Dart_Handle five = Dart_NewInteger(5); | |
| 664 Dart_Handle five_again = Dart_NewInteger(5); | |
| 665 Dart_Handle mint = Dart_NewInteger(0xFFFFFFFF); | |
| 666 Dart_Handle mint_again = Dart_NewInteger(0xFFFFFFFF); | |
| 667 Dart_Handle abc = NewString("abc"); | |
| 668 // Dart_Handle abc_again = NewString("abc"); | |
| 669 Dart_Handle xyz = NewString("xyz"); | |
| 670 Dart_Handle dart_core = NewString("dart:core"); | |
| 671 Dart_Handle dart_mirrors = NewString("dart:mirrors"); | |
| 672 | |
| 673 // Same objects. | |
| 674 EXPECT_EQ(Dart_IdentityHash(five), Dart_IdentityHash(five)); | |
| 675 EXPECT_EQ(Dart_IdentityHash(mint), Dart_IdentityHash(mint)); | |
| 676 EXPECT_EQ(Dart_IdentityHash(abc), Dart_IdentityHash(abc)); | |
| 677 EXPECT_EQ(Dart_IdentityHash(xyz), Dart_IdentityHash(xyz)); | |
| 678 | |
| 679 // Equal objects with special spec rules. | |
| 680 EXPECT_EQ(Dart_IdentityHash(five), Dart_IdentityHash(five_again)); | |
| 681 EXPECT_EQ(Dart_IdentityHash(mint), Dart_IdentityHash(mint_again)); | |
| 682 | |
| 683 // Note abc and abc_again are not required to have equal identity hashes. | |
| 684 | |
| 685 // Case where identical() is not the same as pointer equality. | |
| 686 Dart_Handle nan1 = Dart_NewDouble(NAN); | |
| 687 Dart_Handle nan2 = Dart_NewDouble(NAN); | |
| 688 EXPECT_EQ(Dart_IdentityHash(nan1), Dart_IdentityHash(nan2)); | |
| 689 | |
| 690 // Non-instance objects. | |
| 691 { | |
| 692 CHECK_API_SCOPE(thread); | |
| 693 HANDLESCOPE(thread); | |
| 694 Dart_Handle lib1 = Dart_LookupLibrary(dart_core); | |
| 695 Dart_Handle lib2 = Dart_LookupLibrary(dart_mirrors); | |
| 696 | |
| 697 EXPECT_EQ(Dart_IdentityHash(lib1), Dart_IdentityHash(lib1)); | |
| 698 EXPECT_EQ(Dart_IdentityHash(lib2), Dart_IdentityHash(lib2)); | |
| 699 } | |
| 700 } | |
| 701 | |
| 702 TEST_CASE(ObjectEquals) { | 662 TEST_CASE(ObjectEquals) { |
| 703 bool equal = false; | 663 bool equal = false; |
| 704 Dart_Handle five = NewString("5"); | 664 Dart_Handle five = NewString("5"); |
| 705 Dart_Handle five_again = NewString("5"); | 665 Dart_Handle five_again = NewString("5"); |
| 706 Dart_Handle seven = NewString("7"); | 666 Dart_Handle seven = NewString("7"); |
| 707 | 667 |
| 708 // Same objects. | 668 // Same objects. |
| 709 EXPECT_VALID(Dart_ObjectEquals(five, five, &equal)); | 669 EXPECT_VALID(Dart_ObjectEquals(five, five, &equal)); |
| 710 EXPECT(equal); | 670 EXPECT(equal); |
| 711 | 671 |
| (...skipping 8922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9634 EXPECT_VALID(result); | 9594 EXPECT_VALID(result); |
| 9635 result = Dart_FinalizeLoading(false); | 9595 result = Dart_FinalizeLoading(false); |
| 9636 EXPECT_VALID(result); | 9596 EXPECT_VALID(result); |
| 9637 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL); | 9597 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL); |
| 9638 EXPECT(Dart_IsError(result)); | 9598 EXPECT(Dart_IsError(result)); |
| 9639 } | 9599 } |
| 9640 | 9600 |
| 9641 #endif // !PRODUCT | 9601 #endif // !PRODUCT |
| 9642 | 9602 |
| 9643 } // namespace dart | 9603 } // namespace dart |
| OLD | NEW |