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 1879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1890 // Make sure that the value transferred. | 1890 // Make sure that the value transferred. |
1891 Dart_Handle obj4 = Dart_HandleFromPersistent(obj3); | 1891 Dart_Handle obj4 = Dart_HandleFromPersistent(obj3); |
1892 EXPECT(Dart_IsBoolean(obj4)); | 1892 EXPECT(Dart_IsBoolean(obj4)); |
1893 bool value = false; | 1893 bool value = false; |
1894 Dart_Handle result = Dart_BooleanValue(obj4, &value); | 1894 Dart_Handle result = Dart_BooleanValue(obj4, &value); |
1895 EXPECT_VALID(result); | 1895 EXPECT_VALID(result); |
1896 EXPECT(value); | 1896 EXPECT(value); |
1897 } | 1897 } |
1898 | 1898 |
1899 | 1899 |
| 1900 // Test that we can assign to a persistent handle. |
| 1901 UNIT_TEST_CASE(AssignToPersistentHandle) { |
| 1902 const char* kTestString1 = "Test String1"; |
| 1903 const char* kTestString2 = "Test String2"; |
| 1904 TestIsolateScope __test_isolate__; |
| 1905 |
| 1906 Isolate* isolate = Isolate::Current(); |
| 1907 EXPECT(isolate != NULL); |
| 1908 ApiState* state = isolate->api_state(); |
| 1909 EXPECT(state != NULL); |
| 1910 DARTSCOPE(isolate); |
| 1911 String& str = String::Handle(); |
| 1912 |
| 1913 // Start with a known persistent handle. |
| 1914 Dart_Handle ref1 = Api::NewHandle(isolate, String::New(kTestString1)); |
| 1915 Dart_PersistentHandle obj = Dart_NewPersistentHandle(ref1); |
| 1916 EXPECT(state->IsValidPersistentHandle(obj)); |
| 1917 str ^= Api::UnwrapAsPersistentHandle(obj)->raw(); |
| 1918 EXPECT(str.Equals(kTestString1)); |
| 1919 |
| 1920 // Now create another local handle and assign it to the persistent handle. |
| 1921 Dart_Handle ref2 = Api::NewHandle(isolate, String::New(kTestString2)); |
| 1922 Dart_SetPersistentHandle(obj, ref2); |
| 1923 str ^= Api::UnwrapAsPersistentHandle(obj)->raw(); |
| 1924 EXPECT(str.Equals(kTestString2)); |
| 1925 |
| 1926 // Now assign Null to the persistent handle and check. |
| 1927 Dart_SetPersistentHandle(obj, Dart_Null()); |
| 1928 EXPECT(Dart_IsNull(obj)); |
| 1929 } |
| 1930 |
| 1931 |
1900 // Helper class to ensure new gen GC is triggered without any side effects. | 1932 // Helper class to ensure new gen GC is triggered without any side effects. |
1901 // The normal call to CollectGarbage(Heap::kNew) could potentially trigger | 1933 // The normal call to CollectGarbage(Heap::kNew) could potentially trigger |
1902 // an old gen collection if there is a promotion failure and this could | 1934 // an old gen collection if there is a promotion failure and this could |
1903 // perturb the test. | 1935 // perturb the test. |
1904 class GCTestHelper : public AllStatic { | 1936 class GCTestHelper : public AllStatic { |
1905 public: | 1937 public: |
1906 static void CollectNewSpace(Heap::ApiCallbacks api_callbacks) { | 1938 static void CollectNewSpace(Heap::ApiCallbacks api_callbacks) { |
1907 bool invoke_api_callbacks = (api_callbacks == Heap::kInvokeApiCallbacks); | 1939 bool invoke_api_callbacks = (api_callbacks == Heap::kInvokeApiCallbacks); |
1908 Isolate::Current()->heap()->new_space_->Scavenge(invoke_api_callbacks); | 1940 Isolate::Current()->heap()->new_space_->Scavenge(invoke_api_callbacks); |
1909 } | 1941 } |
(...skipping 5887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7797 NewString("main"), | 7829 NewString("main"), |
7798 1, | 7830 1, |
7799 dart_args); | 7831 dart_args); |
7800 int64_t value = 0; | 7832 int64_t value = 0; |
7801 result = Dart_IntegerToInt64(result, &value); | 7833 result = Dart_IntegerToInt64(result, &value); |
7802 EXPECT_VALID(result); | 7834 EXPECT_VALID(result); |
7803 EXPECT_EQ(6, value); | 7835 EXPECT_EQ(6, value); |
7804 } | 7836 } |
7805 | 7837 |
7806 } // namespace dart | 7838 } // namespace dart |
OLD | NEW |