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 "bin/builtin.h" | 5 #include "bin/builtin.h" |
6 #include "include/dart_api.h" | 6 #include "include/dart_api.h" |
7 #include "include/dart_debugger_api.h" | 7 #include "include/dart_debugger_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 "platform/assert.h" | 10 #include "platform/assert.h" |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 // Different objects. | 536 // Different objects. |
537 EXPECT(!Dart_IdentityEquals(five, seven)); | 537 EXPECT(!Dart_IdentityEquals(five, seven)); |
538 | 538 |
539 // Case where identical() is not the same as pointer equality. | 539 // Case where identical() is not the same as pointer equality. |
540 Dart_Handle nan1 = Dart_NewDouble(NAN); | 540 Dart_Handle nan1 = Dart_NewDouble(NAN); |
541 Dart_Handle nan2 = Dart_NewDouble(NAN); | 541 Dart_Handle nan2 = Dart_NewDouble(NAN); |
542 EXPECT(Dart_IdentityEquals(nan1, nan2)); | 542 EXPECT(Dart_IdentityEquals(nan1, nan2)); |
543 | 543 |
544 // Non-instance objects. | 544 // Non-instance objects. |
545 { | 545 { |
546 Isolate* isolate = Isolate::Current(); | |
547 DARTSCOPE(isolate); | |
548 Dart_Handle lib1 = Dart_LookupLibrary(dart_core); | 546 Dart_Handle lib1 = Dart_LookupLibrary(dart_core); |
549 Dart_Handle lib2 = Dart_LookupLibrary(dart_mirrors); | 547 Dart_Handle lib2 = Dart_LookupLibrary(dart_mirrors); |
550 | 548 |
551 EXPECT(Dart_IdentityEquals(lib1, lib1)); | 549 EXPECT(Dart_IdentityEquals(lib1, lib1)); |
552 EXPECT(Dart_IdentityEquals(lib2, lib2)); | 550 EXPECT(Dart_IdentityEquals(lib2, lib2)); |
553 EXPECT(!Dart_IdentityEquals(lib1, lib2)); | 551 EXPECT(!Dart_IdentityEquals(lib1, lib2)); |
554 | 552 |
555 // Mix instance and non-instance. | 553 // Mix instance and non-instance. |
556 EXPECT(!Dart_IdentityEquals(lib1, nan1)); | 554 EXPECT(!Dart_IdentityEquals(lib1, nan1)); |
557 EXPECT(!Dart_IdentityEquals(nan1, lib1)); | 555 EXPECT(!Dart_IdentityEquals(nan1, lib1)); |
(...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1782 TestIsolateScope __test_isolate__; | 1780 TestIsolateScope __test_isolate__; |
1783 | 1781 |
1784 Isolate* isolate = Isolate::Current(); | 1782 Isolate* isolate = Isolate::Current(); |
1785 EXPECT(isolate != NULL); | 1783 EXPECT(isolate != NULL); |
1786 ApiState* state = isolate->api_state(); | 1784 ApiState* state = isolate->api_state(); |
1787 EXPECT(state != NULL); | 1785 EXPECT(state != NULL); |
1788 ApiLocalScope* scope = state->top_scope(); | 1786 ApiLocalScope* scope = state->top_scope(); |
1789 Dart_EnterScope(); | 1787 Dart_EnterScope(); |
1790 { | 1788 { |
1791 EXPECT(state->top_scope() != NULL); | 1789 EXPECT(state->top_scope() != NULL); |
1792 DARTSCOPE(isolate); | 1790 HANDLESCOPE(isolate); |
1793 const String& str1 = String::Handle(String::New("Test String")); | 1791 const String& str1 = String::Handle(String::New("Test String")); |
1794 Dart_Handle ref = Api::NewHandle(isolate, str1.raw()); | 1792 Dart_Handle ref = Api::NewHandle(isolate, str1.raw()); |
1795 String& str2 = String::Handle(); | 1793 String& str2 = String::Handle(); |
1796 str2 ^= Api::UnwrapHandle(ref); | 1794 str2 ^= Api::UnwrapHandle(ref); |
1797 EXPECT(str1.Equals(str2)); | 1795 EXPECT(str1.Equals(str2)); |
1798 } | 1796 } |
1799 Dart_ExitScope(); | 1797 Dart_ExitScope(); |
1800 EXPECT(scope == state->top_scope()); | 1798 EXPECT(scope == state->top_scope()); |
1801 } | 1799 } |
1802 | 1800 |
1803 | 1801 |
1804 // Unit test for creating and deleting persistent handles. | 1802 // Unit test for creating and deleting persistent handles. |
1805 UNIT_TEST_CASE(PersistentHandles) { | 1803 UNIT_TEST_CASE(PersistentHandles) { |
1806 const char* kTestString1 = "Test String1"; | 1804 const char* kTestString1 = "Test String1"; |
1807 const char* kTestString2 = "Test String2"; | 1805 const char* kTestString2 = "Test String2"; |
1808 TestCase::CreateTestIsolate(); | 1806 TestCase::CreateTestIsolate(); |
1809 Isolate* isolate = Isolate::Current(); | 1807 Isolate* isolate = Isolate::Current(); |
1810 EXPECT(isolate != NULL); | 1808 EXPECT(isolate != NULL); |
1811 ApiState* state = isolate->api_state(); | 1809 ApiState* state = isolate->api_state(); |
1812 EXPECT(state != NULL); | 1810 EXPECT(state != NULL); |
1813 ApiLocalScope* scope = state->top_scope(); | 1811 ApiLocalScope* scope = state->top_scope(); |
1814 Dart_PersistentHandle handles[2000]; | 1812 Dart_PersistentHandle handles[2000]; |
1815 Dart_EnterScope(); | 1813 Dart_EnterScope(); |
1816 { | 1814 { |
1817 DARTSCOPE(isolate); | 1815 HANDLESCOPE(isolate); |
1818 Dart_Handle ref1 = Api::NewHandle(isolate, String::New(kTestString1)); | 1816 Dart_Handle ref1 = Api::NewHandle(isolate, String::New(kTestString1)); |
1819 for (int i = 0; i < 1000; i++) { | 1817 for (int i = 0; i < 1000; i++) { |
1820 handles[i] = Dart_NewPersistentHandle(ref1); | 1818 handles[i] = Dart_NewPersistentHandle(ref1); |
1821 } | 1819 } |
1822 Dart_EnterScope(); | 1820 Dart_EnterScope(); |
1823 Dart_Handle ref2 = Api::NewHandle(isolate, String::New(kTestString2)); | 1821 Dart_Handle ref2 = Api::NewHandle(isolate, String::New(kTestString2)); |
1824 for (int i = 1000; i < 2000; i++) { | 1822 for (int i = 1000; i < 2000; i++) { |
1825 handles[i] = Dart_NewPersistentHandle(ref2); | 1823 handles[i] = Dart_NewPersistentHandle(ref2); |
1826 } | 1824 } |
1827 for (int i = 500; i < 1500; i++) { | 1825 for (int i = 500; i < 1500; i++) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1869 | 1867 |
1870 // Test that we are able to create a persistent handle from a | 1868 // Test that we are able to create a persistent handle from a |
1871 // persistent handle. | 1869 // persistent handle. |
1872 UNIT_TEST_CASE(NewPersistentHandle_FromPersistentHandle) { | 1870 UNIT_TEST_CASE(NewPersistentHandle_FromPersistentHandle) { |
1873 TestIsolateScope __test_isolate__; | 1871 TestIsolateScope __test_isolate__; |
1874 | 1872 |
1875 Isolate* isolate = Isolate::Current(); | 1873 Isolate* isolate = Isolate::Current(); |
1876 EXPECT(isolate != NULL); | 1874 EXPECT(isolate != NULL); |
1877 ApiState* state = isolate->api_state(); | 1875 ApiState* state = isolate->api_state(); |
1878 EXPECT(state != NULL); | 1876 EXPECT(state != NULL); |
1879 DARTSCOPE(isolate); | |
1880 | 1877 |
1881 // Start with a known persistent handle. | 1878 // Start with a known persistent handle. |
1882 Dart_PersistentHandle obj1 = Dart_NewPersistentHandle(Dart_True()); | 1879 Dart_PersistentHandle obj1 = Dart_NewPersistentHandle(Dart_True()); |
1883 EXPECT(state->IsValidPersistentHandle(obj1)); | 1880 EXPECT(state->IsValidPersistentHandle(obj1)); |
1884 | 1881 |
1885 // And use it to allocate a second persistent handle. | 1882 // And use it to allocate a second persistent handle. |
1886 Dart_Handle obj2 = Dart_HandleFromPersistent(obj1); | 1883 Dart_Handle obj2 = Dart_HandleFromPersistent(obj1); |
1887 Dart_PersistentHandle obj3 = Dart_NewPersistentHandle(obj2); | 1884 Dart_PersistentHandle obj3 = Dart_NewPersistentHandle(obj2); |
1888 EXPECT(state->IsValidPersistentHandle(obj3)); | 1885 EXPECT(state->IsValidPersistentHandle(obj3)); |
1889 | 1886 |
(...skipping 10 matching lines...) Expand all Loading... |
1900 // Test that we can assign to a persistent handle. | 1897 // Test that we can assign to a persistent handle. |
1901 UNIT_TEST_CASE(AssignToPersistentHandle) { | 1898 UNIT_TEST_CASE(AssignToPersistentHandle) { |
1902 const char* kTestString1 = "Test String1"; | 1899 const char* kTestString1 = "Test String1"; |
1903 const char* kTestString2 = "Test String2"; | 1900 const char* kTestString2 = "Test String2"; |
1904 TestIsolateScope __test_isolate__; | 1901 TestIsolateScope __test_isolate__; |
1905 | 1902 |
1906 Isolate* isolate = Isolate::Current(); | 1903 Isolate* isolate = Isolate::Current(); |
1907 EXPECT(isolate != NULL); | 1904 EXPECT(isolate != NULL); |
1908 ApiState* state = isolate->api_state(); | 1905 ApiState* state = isolate->api_state(); |
1909 EXPECT(state != NULL); | 1906 EXPECT(state != NULL); |
1910 DARTSCOPE(isolate); | 1907 HANDLESCOPE(isolate); |
1911 String& str = String::Handle(); | 1908 String& str = String::Handle(); |
1912 | 1909 |
1913 // Start with a known persistent handle. | 1910 // Start with a known persistent handle. |
1914 Dart_Handle ref1 = Api::NewHandle(isolate, String::New(kTestString1)); | 1911 Dart_Handle ref1 = Api::NewHandle(isolate, String::New(kTestString1)); |
1915 Dart_PersistentHandle obj = Dart_NewPersistentHandle(ref1); | 1912 Dart_PersistentHandle obj = Dart_NewPersistentHandle(ref1); |
1916 EXPECT(state->IsValidPersistentHandle(obj)); | 1913 EXPECT(state->IsValidPersistentHandle(obj)); |
1917 str ^= Api::UnwrapAsPersistentHandle(obj)->raw(); | 1914 str ^= Api::UnwrapAsPersistentHandle(obj)->raw(); |
1918 EXPECT(str.Equals(kTestString1)); | 1915 EXPECT(str.Equals(kTestString1)); |
1919 | 1916 |
1920 // Now create another local handle and assign it to the persistent handle. | 1917 // Now create another local handle and assign it to the persistent handle. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1965 Dart_EnterScope(); | 1962 Dart_EnterScope(); |
1966 | 1963 |
1967 // Create an object in new space. | 1964 // Create an object in new space. |
1968 Dart_Handle new_ref = NewString("new string"); | 1965 Dart_Handle new_ref = NewString("new string"); |
1969 EXPECT_VALID(new_ref); | 1966 EXPECT_VALID(new_ref); |
1970 | 1967 |
1971 // Create an object in old space. | 1968 // Create an object in old space. |
1972 Dart_Handle old_ref; | 1969 Dart_Handle old_ref; |
1973 { | 1970 { |
1974 Isolate* isolate = Isolate::Current(); | 1971 Isolate* isolate = Isolate::Current(); |
1975 DARTSCOPE(isolate); | 1972 HANDLESCOPE(isolate); |
1976 old_ref = Api::NewHandle(isolate, String::New("old string", Heap::kOld)); | 1973 old_ref = Api::NewHandle(isolate, String::New("old string", Heap::kOld)); |
1977 EXPECT_VALID(old_ref); | 1974 EXPECT_VALID(old_ref); |
1978 } | 1975 } |
1979 | 1976 |
1980 // Create a weak ref to the new space object. | 1977 // Create a weak ref to the new space object. |
1981 weak_new_ref = Dart_NewWeakPersistentHandle(new_ref, NULL, NULL); | 1978 weak_new_ref = Dart_NewWeakPersistentHandle(new_ref, NULL, NULL); |
1982 EXPECT_VALID(AsHandle(weak_new_ref)); | 1979 EXPECT_VALID(AsHandle(weak_new_ref)); |
1983 EXPECT(!Dart_IsNull(AsHandle(weak_new_ref))); | 1980 EXPECT(!Dart_IsNull(AsHandle(weak_new_ref))); |
1984 | 1981 |
1985 // Create a weak ref to the old space object. | 1982 // Create a weak ref to the old space object. |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2127 Dart_WeakPersistentHandle strong_weak = NULL; | 2124 Dart_WeakPersistentHandle strong_weak = NULL; |
2128 | 2125 |
2129 Dart_WeakPersistentHandle weak1 = NULL; | 2126 Dart_WeakPersistentHandle weak1 = NULL; |
2130 Dart_WeakPersistentHandle weak2 = NULL; | 2127 Dart_WeakPersistentHandle weak2 = NULL; |
2131 Dart_WeakPersistentHandle weak3 = NULL; | 2128 Dart_WeakPersistentHandle weak3 = NULL; |
2132 Dart_WeakPersistentHandle weak4 = NULL; | 2129 Dart_WeakPersistentHandle weak4 = NULL; |
2133 | 2130 |
2134 Dart_EnterScope(); | 2131 Dart_EnterScope(); |
2135 { | 2132 { |
2136 Isolate* isolate = Isolate::Current(); | 2133 Isolate* isolate = Isolate::Current(); |
2137 DARTSCOPE(isolate); | |
2138 | |
2139 Dart_Handle local = Api::NewHandle( | 2134 Dart_Handle local = Api::NewHandle( |
2140 isolate, String::New("strongly reachable", Heap::kOld)); | 2135 isolate, String::New("strongly reachable", Heap::kOld)); |
2141 strong = Dart_NewPersistentHandle(local); | 2136 strong = Dart_NewPersistentHandle(local); |
2142 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, NULL); | 2137 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, NULL); |
2143 EXPECT_VALID(AsHandle(strong)); | 2138 EXPECT_VALID(AsHandle(strong)); |
2144 EXPECT(!Dart_IsNull(AsHandle(strong))); | 2139 EXPECT(!Dart_IsNull(AsHandle(strong))); |
2145 | 2140 |
2146 weak1 = Dart_NewWeakPersistentHandle( | 2141 weak1 = Dart_NewWeakPersistentHandle( |
2147 Api::NewHandle(isolate, String::New("weakly reachable 1", Heap::kOld)), | 2142 Api::NewHandle(isolate, String::New("weakly reachable 1", Heap::kOld)), |
2148 NULL, NULL); | 2143 NULL, NULL); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2345 } | 2340 } |
2346 | 2341 |
2347 | 2342 |
2348 TEST_CASE(PrologueWeakPersistentHandles) { | 2343 TEST_CASE(PrologueWeakPersistentHandles) { |
2349 Dart_WeakPersistentHandle old_pwph = NULL; | 2344 Dart_WeakPersistentHandle old_pwph = NULL; |
2350 Dart_WeakPersistentHandle new_pwph = NULL; | 2345 Dart_WeakPersistentHandle new_pwph = NULL; |
2351 | 2346 |
2352 Dart_EnterScope(); | 2347 Dart_EnterScope(); |
2353 { | 2348 { |
2354 Isolate* isolate = Isolate::Current(); | 2349 Isolate* isolate = Isolate::Current(); |
2355 DARTSCOPE(isolate); | |
2356 new_pwph = Dart_NewPrologueWeakPersistentHandle( | 2350 new_pwph = Dart_NewPrologueWeakPersistentHandle( |
2357 Api::NewHandle(isolate, | 2351 Api::NewHandle(isolate, |
2358 String::New("new space prologue weak", Heap::kNew)), | 2352 String::New("new space prologue weak", Heap::kNew)), |
2359 NULL, NULL); | 2353 NULL, NULL); |
2360 EXPECT_VALID(AsHandle(new_pwph)); | 2354 EXPECT_VALID(AsHandle(new_pwph)); |
2361 EXPECT(!Dart_IsNull(AsHandle(new_pwph))); | 2355 EXPECT(!Dart_IsNull(AsHandle(new_pwph))); |
2362 old_pwph = Dart_NewPrologueWeakPersistentHandle( | 2356 old_pwph = Dart_NewPrologueWeakPersistentHandle( |
2363 Api::NewHandle(isolate, | 2357 Api::NewHandle(isolate, |
2364 String::New("old space prologue weak", Heap::kOld)), | 2358 String::New("old space prologue weak", Heap::kOld)), |
2365 NULL, NULL); | 2359 NULL, NULL); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2432 Dart_PersistentHandle strong = NULL; | 2426 Dart_PersistentHandle strong = NULL; |
2433 Dart_WeakPersistentHandle strong_weak = NULL; | 2427 Dart_WeakPersistentHandle strong_weak = NULL; |
2434 | 2428 |
2435 Dart_WeakPersistentHandle weak1 = NULL; | 2429 Dart_WeakPersistentHandle weak1 = NULL; |
2436 Dart_WeakPersistentHandle weak2 = NULL; | 2430 Dart_WeakPersistentHandle weak2 = NULL; |
2437 Dart_WeakPersistentHandle weak3 = NULL; | 2431 Dart_WeakPersistentHandle weak3 = NULL; |
2438 | 2432 |
2439 Dart_EnterScope(); | 2433 Dart_EnterScope(); |
2440 { | 2434 { |
2441 Isolate* isolate = Isolate::Current(); | 2435 Isolate* isolate = Isolate::Current(); |
2442 DARTSCOPE(isolate); | |
2443 | |
2444 Dart_Handle local = Api::NewHandle( | 2436 Dart_Handle local = Api::NewHandle( |
2445 isolate, String::New("strongly reachable", Heap::kOld)); | 2437 isolate, String::New("strongly reachable", Heap::kOld)); |
2446 strong = Dart_NewPersistentHandle(local); | 2438 strong = Dart_NewPersistentHandle(local); |
2447 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, NULL); | 2439 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, NULL); |
2448 | 2440 |
2449 EXPECT(!Dart_IsNull(AsHandle(strong))); | 2441 EXPECT(!Dart_IsNull(AsHandle(strong))); |
2450 EXPECT_VALID(AsHandle(strong)); | 2442 EXPECT_VALID(AsHandle(strong)); |
2451 EXPECT(!Dart_IsNull(AsHandle(strong_weak))); | 2443 EXPECT(!Dart_IsNull(AsHandle(strong_weak))); |
2452 EXPECT_VALID(AsHandle(strong_weak)); | 2444 EXPECT_VALID(AsHandle(strong_weak)); |
2453 EXPECT(Dart_IdentityEquals(AsHandle(strong), AsHandle(strong_weak))) | 2445 EXPECT(Dart_IdentityEquals(AsHandle(strong), AsHandle(strong_weak))) |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2538 Dart_PersistentHandle strong = NULL; | 2530 Dart_PersistentHandle strong = NULL; |
2539 Dart_WeakPersistentHandle strong_weak = NULL; | 2531 Dart_WeakPersistentHandle strong_weak = NULL; |
2540 | 2532 |
2541 Dart_WeakPersistentHandle weak1 = NULL; | 2533 Dart_WeakPersistentHandle weak1 = NULL; |
2542 Dart_WeakPersistentHandle weak2 = NULL; | 2534 Dart_WeakPersistentHandle weak2 = NULL; |
2543 Dart_WeakPersistentHandle weak3 = NULL; | 2535 Dart_WeakPersistentHandle weak3 = NULL; |
2544 | 2536 |
2545 Dart_EnterScope(); | 2537 Dart_EnterScope(); |
2546 { | 2538 { |
2547 Isolate* isolate = Isolate::Current(); | 2539 Isolate* isolate = Isolate::Current(); |
2548 DARTSCOPE(isolate); | |
2549 | |
2550 Dart_Handle local = Api::NewHandle( | 2540 Dart_Handle local = Api::NewHandle( |
2551 isolate, String::New("strongly reachable", Heap::kOld)); | 2541 isolate, String::New("strongly reachable", Heap::kOld)); |
2552 strong = Dart_NewPersistentHandle(local); | 2542 strong = Dart_NewPersistentHandle(local); |
2553 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, NULL); | 2543 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, NULL); |
2554 | 2544 |
2555 EXPECT(!Dart_IsNull(AsHandle(strong))); | 2545 EXPECT(!Dart_IsNull(AsHandle(strong))); |
2556 EXPECT_VALID(AsHandle(strong)); | 2546 EXPECT_VALID(AsHandle(strong)); |
2557 EXPECT(!Dart_IsNull(AsHandle(strong_weak))); | 2547 EXPECT(!Dart_IsNull(AsHandle(strong_weak))); |
2558 EXPECT_VALID(AsHandle(strong_weak)); | 2548 EXPECT_VALID(AsHandle(strong_weak)); |
2559 EXPECT(Dart_IdentityEquals(AsHandle(strong), AsHandle(strong_weak))) | 2549 EXPECT(Dart_IdentityEquals(AsHandle(strong), AsHandle(strong_weak))) |
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3654 result = Dart_CreateNativeWrapperClass( | 3644 result = Dart_CreateNativeWrapperClass( |
3655 lib, | 3645 lib, |
3656 NewString("NativeFieldsWrapper"), | 3646 NewString("NativeFieldsWrapper"), |
3657 kNumNativeFields); | 3647 kNumNativeFields); |
3658 | 3648 |
3659 // Load up a test script in the test library. | 3649 // Load up a test script in the test library. |
3660 | 3650 |
3661 // Invoke a function which returns an object of type NativeFields. | 3651 // Invoke a function which returns an object of type NativeFields. |
3662 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 3652 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
3663 EXPECT_VALID(result); | 3653 EXPECT_VALID(result); |
3664 DARTSCOPE(Isolate::Current()); | 3654 HANDLESCOPE(Isolate::Current()); |
3665 Instance& obj = Instance::Handle(); | 3655 Instance& obj = Instance::Handle(); |
3666 obj ^= Api::UnwrapHandle(result); | 3656 obj ^= Api::UnwrapHandle(result); |
3667 const Class& cls = Class::Handle(obj.clazz()); | 3657 const Class& cls = Class::Handle(obj.clazz()); |
3668 // We expect the newly created "NativeFields" object to have | 3658 // We expect the newly created "NativeFields" object to have |
3669 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. | 3659 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. |
3670 // Hence the size of an instance of "NativeFields" should be | 3660 // Hence the size of an instance of "NativeFields" should be |
3671 // (1 + 2) * kWordSize + size of object header. | 3661 // (1 + 2) * kWordSize + size of object header. |
3672 // We check to make sure the instance size computed by the VM matches | 3662 // We check to make sure the instance size computed by the VM matches |
3673 // our expectations. | 3663 // our expectations. |
3674 intptr_t header_size = sizeof(RawObject); | 3664 intptr_t header_size = sizeof(RawObject); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3723 Dart_Handle result; | 3713 Dart_Handle result; |
3724 const int kNumNativeFields = 2; | 3714 const int kNumNativeFields = 2; |
3725 | 3715 |
3726 // Load up a test script in the test library. | 3716 // Load up a test script in the test library. |
3727 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, | 3717 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, |
3728 native_field_lookup); | 3718 native_field_lookup); |
3729 | 3719 |
3730 // Invoke a function which returns an object of type NativeFields. | 3720 // Invoke a function which returns an object of type NativeFields. |
3731 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 3721 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
3732 EXPECT_VALID(result); | 3722 EXPECT_VALID(result); |
3733 DARTSCOPE(Isolate::Current()); | 3723 HANDLESCOPE(Isolate::Current()); |
3734 Instance& obj = Instance::Handle(); | 3724 Instance& obj = Instance::Handle(); |
3735 obj ^= Api::UnwrapHandle(result); | 3725 obj ^= Api::UnwrapHandle(result); |
3736 const Class& cls = Class::Handle(obj.clazz()); | 3726 const Class& cls = Class::Handle(obj.clazz()); |
3737 // We expect the newly created "NativeFields" object to have | 3727 // We expect the newly created "NativeFields" object to have |
3738 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. | 3728 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. |
3739 // Hence the size of an instance of "NativeFields" should be | 3729 // Hence the size of an instance of "NativeFields" should be |
3740 // (1 + 2) * kWordSize + size of object header. | 3730 // (1 + 2) * kWordSize + size of object header. |
3741 // We check to make sure the instance size computed by the VM matches | 3731 // We check to make sure the instance size computed by the VM matches |
3742 // our expectations. | 3732 // our expectations. |
3743 intptr_t header_size = sizeof(RawObject); | 3733 intptr_t header_size = sizeof(RawObject); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3982 " static const int fld4 = 10;\n" | 3972 " static const int fld4 = 10;\n" |
3983 "}\n" | 3973 "}\n" |
3984 "NativeFields testMain1() {\n" | 3974 "NativeFields testMain1() {\n" |
3985 " NativeFields obj = new NativeFields(10, 20);\n" | 3975 " NativeFields obj = new NativeFields(10, 20);\n" |
3986 " return obj;\n" | 3976 " return obj;\n" |
3987 "}\n" | 3977 "}\n" |
3988 "Function testMain2() {\n" | 3978 "Function testMain2() {\n" |
3989 " return () {};\n" | 3979 " return () {};\n" |
3990 "}\n"; | 3980 "}\n"; |
3991 Dart_Handle result; | 3981 Dart_Handle result; |
3992 DARTSCOPE(Isolate::Current()); | |
3993 | 3982 |
3994 // Create a test library and Load up a test script in it. | 3983 // Create a test library and Load up a test script in it. |
3995 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 3984 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
3996 | 3985 |
3997 // Invoke a function which returns an object of type NativeFields. | 3986 // Invoke a function which returns an object of type NativeFields. |
3998 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); | 3987 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); |
3999 EXPECT_VALID(retobj); | 3988 EXPECT_VALID(retobj); |
4000 | 3989 |
4001 // Now access and set various native instance fields of the returned object. | 3990 // Now access and set various native instance fields of the returned object. |
4002 // All of these tests are expected to return failure as there are no | 3991 // All of these tests are expected to return failure as there are no |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4060 " var port = new RawReceivePort();\n" | 4049 " var port = new RawReceivePort();\n" |
4061 " var obj = new Test(1,2);\n" | 4050 " var obj = new Test(1,2);\n" |
4062 " var msg = [obj, port.sendPort];\n" | 4051 " var msg = [obj, port.sendPort];\n" |
4063 " var snd = Isolate.spawn(echo, msg);\n" | 4052 " var snd = Isolate.spawn(echo, msg);\n" |
4064 " port.handler = (msg) {\n" | 4053 " port.handler = (msg) {\n" |
4065 " port.close();\n" | 4054 " port.close();\n" |
4066 " print('from worker ${msg}');\n" | 4055 " print('from worker ${msg}');\n" |
4067 " };\n" | 4056 " };\n" |
4068 "}\n"; | 4057 "}\n"; |
4069 | 4058 |
4070 DARTSCOPE(Isolate::Current()); | |
4071 | |
4072 // Create a test library and Load up a test script in it. | 4059 // Create a test library and Load up a test script in it. |
4073 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 4060 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
4074 | 4061 |
4075 // Invoke 'main' which should spawn an isolate and try to send an | 4062 // Invoke 'main' which should spawn an isolate and try to send an |
4076 // object with native fields over to the spawned isolate. This | 4063 // object with native fields over to the spawned isolate. This |
4077 // should result in an unhandled exception which is checked. | 4064 // should result in an unhandled exception which is checked. |
4078 Dart_Handle retobj = Dart_Invoke(lib, NewString("main"), 0, NULL); | 4065 Dart_Handle retobj = Dart_Invoke(lib, NewString("main"), 0, NULL); |
4079 EXPECT(Dart_IsError(retobj)); | 4066 EXPECT(Dart_IsError(retobj)); |
4080 } | 4067 } |
4081 | 4068 |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4732 " static const int fld4 = 10;\n" | 4719 " static const int fld4 = 10;\n" |
4733 "}\n" | 4720 "}\n" |
4734 "Function testMain1() {\n" | 4721 "Function testMain1() {\n" |
4735 " InvokeClosure obj = new InvokeClosure(10, 20);\n" | 4722 " InvokeClosure obj = new InvokeClosure(10, 20);\n" |
4736 " return obj.method1(10);\n" | 4723 " return obj.method1(10);\n" |
4737 "}\n" | 4724 "}\n" |
4738 "Function testMain2() {\n" | 4725 "Function testMain2() {\n" |
4739 " return InvokeClosure.method2(10);\n" | 4726 " return InvokeClosure.method2(10);\n" |
4740 "}\n"; | 4727 "}\n"; |
4741 Dart_Handle result; | 4728 Dart_Handle result; |
4742 DARTSCOPE(Isolate::Current()); | |
4743 | 4729 |
4744 // Create a test library and Load up a test script in it. | 4730 // Create a test library and Load up a test script in it. |
4745 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 4731 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
4746 | 4732 |
4747 // Invoke a function which returns a closure. | 4733 // Invoke a function which returns a closure. |
4748 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); | 4734 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); |
4749 EXPECT_VALID(retobj); | 4735 EXPECT_VALID(retobj); |
4750 | 4736 |
4751 EXPECT(Dart_IsClosure(retobj)); | 4737 EXPECT(Dart_IsClosure(retobj)); |
4752 EXPECT(!Dart_IsClosure(Dart_NewInteger(101))); | 4738 EXPECT(!Dart_IsClosure(Dart_NewInteger(101))); |
(...skipping 2313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7066 } | 7052 } |
7067 | 7053 |
7068 | 7054 |
7069 // Allocates an object in new space and assigns it a peer. Allows the | 7055 // Allocates an object in new space and assigns it a peer. Allows the |
7070 // peer referent to be garbage collected and checks that the count of | 7056 // peer referent to be garbage collected and checks that the count of |
7071 // peer objects is decremented by one. | 7057 // peer objects is decremented by one. |
7072 TEST_CASE(CollectOneNewSpacePeer) { | 7058 TEST_CASE(CollectOneNewSpacePeer) { |
7073 Isolate* isolate = Isolate::Current(); | 7059 Isolate* isolate = Isolate::Current(); |
7074 Dart_EnterScope(); | 7060 Dart_EnterScope(); |
7075 { | 7061 { |
7076 DARTSCOPE(isolate); | |
7077 Dart_Handle str = NewString("a string"); | 7062 Dart_Handle str = NewString("a string"); |
7078 EXPECT_VALID(str); | 7063 EXPECT_VALID(str); |
7079 EXPECT(Dart_IsString(str)); | 7064 EXPECT(Dart_IsString(str)); |
7080 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 7065 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
7081 void* out = &out; | 7066 void* out = &out; |
7082 EXPECT_VALID(Dart_GetPeer(str, &out)); | 7067 EXPECT_VALID(Dart_GetPeer(str, &out)); |
7083 EXPECT(out == NULL); | 7068 EXPECT(out == NULL); |
7084 int peer = 1234; | 7069 int peer = 1234; |
7085 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 7070 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
7086 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 7071 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7139 } | 7124 } |
7140 | 7125 |
7141 | 7126 |
7142 // Allocates two objects in new space and assigns them a peer. Allow | 7127 // Allocates two objects in new space and assigns them a peer. Allow |
7143 // the peer referents to be garbage collected and check that the count | 7128 // the peer referents to be garbage collected and check that the count |
7144 // of peer objects is decremented by two. | 7129 // of peer objects is decremented by two. |
7145 TEST_CASE(CollectTwoNewSpacePeers) { | 7130 TEST_CASE(CollectTwoNewSpacePeers) { |
7146 Isolate* isolate = Isolate::Current(); | 7131 Isolate* isolate = Isolate::Current(); |
7147 Dart_EnterScope(); | 7132 Dart_EnterScope(); |
7148 { | 7133 { |
7149 DARTSCOPE(isolate); | |
7150 Dart_Handle s1 = NewString("s1"); | 7134 Dart_Handle s1 = NewString("s1"); |
7151 EXPECT_VALID(s1); | 7135 EXPECT_VALID(s1); |
7152 EXPECT(Dart_IsString(s1)); | 7136 EXPECT(Dart_IsString(s1)); |
7153 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 7137 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
7154 void* o1 = &o1; | 7138 void* o1 = &o1; |
7155 EXPECT(Dart_GetPeer(s1, &o1)); | 7139 EXPECT(Dart_GetPeer(s1, &o1)); |
7156 EXPECT(o1 == NULL); | 7140 EXPECT(o1 == NULL); |
7157 int p1 = 1234; | 7141 int p1 = 1234; |
7158 EXPECT_VALID(Dart_SetPeer(s1, &p1)); | 7142 EXPECT_VALID(Dart_SetPeer(s1, &p1)); |
7159 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 7143 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7223 EXPECT(out == NULL); | 7207 EXPECT(out == NULL); |
7224 int peer = 1234; | 7208 int peer = 1234; |
7225 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 7209 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
7226 out = &out; | 7210 out = &out; |
7227 EXPECT(Dart_GetPeer(str, &out)); | 7211 EXPECT(Dart_GetPeer(str, &out)); |
7228 EXPECT(out == reinterpret_cast<void*>(&peer)); | 7212 EXPECT(out == reinterpret_cast<void*>(&peer)); |
7229 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 7213 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
7230 isolate->heap()->CollectGarbage(Heap::kNew); | 7214 isolate->heap()->CollectGarbage(Heap::kNew); |
7231 isolate->heap()->CollectGarbage(Heap::kNew); | 7215 isolate->heap()->CollectGarbage(Heap::kNew); |
7232 { | 7216 { |
7233 DARTSCOPE(isolate); | 7217 HANDLESCOPE(isolate); |
7234 String& handle = String::Handle(); | 7218 String& handle = String::Handle(); |
7235 handle ^= Api::UnwrapHandle(str); | 7219 handle ^= Api::UnwrapHandle(str); |
7236 EXPECT(handle.IsOld()); | 7220 EXPECT(handle.IsOld()); |
7237 } | 7221 } |
7238 EXPECT_VALID(Dart_GetPeer(str, &out)); | 7222 EXPECT_VALID(Dart_GetPeer(str, &out)); |
7239 EXPECT(out == reinterpret_cast<void*>(&peer)); | 7223 EXPECT(out == reinterpret_cast<void*>(&peer)); |
7240 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 7224 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
7241 EXPECT_VALID(Dart_SetPeer(str, NULL)); | 7225 EXPECT_VALID(Dart_SetPeer(str, NULL)); |
7242 out = &out; | 7226 out = &out; |
7243 EXPECT_VALID(Dart_GetPeer(str, &out)); | 7227 EXPECT_VALID(Dart_GetPeer(str, &out)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7276 } | 7260 } |
7277 | 7261 |
7278 | 7262 |
7279 // Allocates an object in old space and assigns it a peer. Allow the | 7263 // Allocates an object in old space and assigns it a peer. Allow the |
7280 // peer referent to be garbage collected and check that the count of | 7264 // peer referent to be garbage collected and check that the count of |
7281 // peer objects is decremented by one. | 7265 // peer objects is decremented by one. |
7282 TEST_CASE(CollectOneOldSpacePeer) { | 7266 TEST_CASE(CollectOneOldSpacePeer) { |
7283 Isolate* isolate = Isolate::Current(); | 7267 Isolate* isolate = Isolate::Current(); |
7284 Dart_EnterScope(); | 7268 Dart_EnterScope(); |
7285 { | 7269 { |
7286 DARTSCOPE(isolate); | 7270 HANDLESCOPE(isolate); |
7287 Dart_Handle str = Api::NewHandle(isolate, String::New("str", Heap::kOld)); | 7271 Dart_Handle str = Api::NewHandle(isolate, String::New("str", Heap::kOld)); |
7288 EXPECT_VALID(str); | 7272 EXPECT_VALID(str); |
7289 EXPECT(Dart_IsString(str)); | 7273 EXPECT(Dart_IsString(str)); |
7290 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 7274 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
7291 void* out = &out; | 7275 void* out = &out; |
7292 EXPECT(Dart_GetPeer(str, &out)); | 7276 EXPECT(Dart_GetPeer(str, &out)); |
7293 EXPECT(out == NULL); | 7277 EXPECT(out == NULL); |
7294 int peer = 1234; | 7278 int peer = 1234; |
7295 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 7279 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
7296 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 7280 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7352 } | 7336 } |
7353 | 7337 |
7354 | 7338 |
7355 // Allocates two objects in old space and assigns them a peer. Allows | 7339 // Allocates two objects in old space and assigns them a peer. Allows |
7356 // the peer referents to be garbage collected and checks that the | 7340 // the peer referents to be garbage collected and checks that the |
7357 // count of peer objects is decremented by two. | 7341 // count of peer objects is decremented by two. |
7358 TEST_CASE(CollectTwoOldSpacePeers) { | 7342 TEST_CASE(CollectTwoOldSpacePeers) { |
7359 Isolate* isolate = Isolate::Current(); | 7343 Isolate* isolate = Isolate::Current(); |
7360 Dart_EnterScope(); | 7344 Dart_EnterScope(); |
7361 { | 7345 { |
7362 DARTSCOPE(isolate); | 7346 HANDLESCOPE(isolate); |
7363 Dart_Handle s1 = Api::NewHandle(isolate, String::New("s1", Heap::kOld)); | 7347 Dart_Handle s1 = Api::NewHandle(isolate, String::New("s1", Heap::kOld)); |
7364 EXPECT_VALID(s1); | 7348 EXPECT_VALID(s1); |
7365 EXPECT(Dart_IsString(s1)); | 7349 EXPECT(Dart_IsString(s1)); |
7366 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 7350 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
7367 void* o1 = &o1; | 7351 void* o1 = &o1; |
7368 EXPECT(Dart_GetPeer(s1, &o1)); | 7352 EXPECT(Dart_GetPeer(s1, &o1)); |
7369 EXPECT(o1 == NULL); | 7353 EXPECT(o1 == NULL); |
7370 int p1 = 1234; | 7354 int p1 = 1234; |
7371 EXPECT_VALID(Dart_SetPeer(s1, &p1)); | 7355 EXPECT_VALID(Dart_SetPeer(s1, &p1)); |
7372 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 7356 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7829 NewString("main"), | 7813 NewString("main"), |
7830 1, | 7814 1, |
7831 dart_args); | 7815 dart_args); |
7832 int64_t value = 0; | 7816 int64_t value = 0; |
7833 result = Dart_IntegerToInt64(result, &value); | 7817 result = Dart_IntegerToInt64(result, &value); |
7834 EXPECT_VALID(result); | 7818 EXPECT_VALID(result); |
7835 EXPECT_EQ(6, value); | 7819 EXPECT_EQ(6, value); |
7836 } | 7820 } |
7837 | 7821 |
7838 } // namespace dart | 7822 } // namespace dart |
OLD | NEW |