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

Side by Side Diff: runtime/vm/dart_api_impl_test.cc

Issue 116473004: Add Dart API method Dart_SetPersistentHandle to enable setting the value of (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« runtime/vm/dart_api_impl.cc ('K') | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_Handle result = Dart_SetPersistentHandle(obj, ref2);
1923 EXPECT_VALID(result);
1924 str ^= Api::UnwrapAsPersistentHandle(obj)->raw();
1925 EXPECT(str.Equals(kTestString2));
1926
1927 // Now assign Null to the persistent handle and check.
1928 result = Dart_SetPersistentHandle(obj, Dart_Null());
1929 EXPECT_VALID(result);
1930 EXPECT(Dart_IsNull(obj));
1931
1932 // Negative test.
1933 result = Dart_SetPersistentHandle(ref2, ref1);
1934 EXPECT(Dart_IsError(result));
1935 }
1936
1937
1900 // Helper class to ensure new gen GC is triggered without any side effects. 1938 // Helper class to ensure new gen GC is triggered without any side effects.
1901 // The normal call to CollectGarbage(Heap::kNew) could potentially trigger 1939 // The normal call to CollectGarbage(Heap::kNew) could potentially trigger
1902 // an old gen collection if there is a promotion failure and this could 1940 // an old gen collection if there is a promotion failure and this could
1903 // perturb the test. 1941 // perturb the test.
1904 class GCTestHelper : public AllStatic { 1942 class GCTestHelper : public AllStatic {
1905 public: 1943 public:
1906 static void CollectNewSpace(Heap::ApiCallbacks api_callbacks) { 1944 static void CollectNewSpace(Heap::ApiCallbacks api_callbacks) {
1907 bool invoke_api_callbacks = (api_callbacks == Heap::kInvokeApiCallbacks); 1945 bool invoke_api_callbacks = (api_callbacks == Heap::kInvokeApiCallbacks);
1908 Isolate::Current()->heap()->new_space_->Scavenge(invoke_api_callbacks); 1946 Isolate::Current()->heap()->new_space_->Scavenge(invoke_api_callbacks);
1909 } 1947 }
(...skipping 5887 matching lines...) Expand 10 before | Expand all | Expand 10 after
7797 NewString("main"), 7835 NewString("main"),
7798 1, 7836 1,
7799 dart_args); 7837 dart_args);
7800 int64_t value = 0; 7838 int64_t value = 0;
7801 result = Dart_IntegerToInt64(result, &value); 7839 result = Dart_IntegerToInt64(result, &value);
7802 EXPECT_VALID(result); 7840 EXPECT_VALID(result);
7803 EXPECT_EQ(6, value); 7841 EXPECT_EQ(6, value);
7804 } 7842 }
7805 7843
7806 } // namespace dart 7844 } // namespace dart
OLDNEW
« runtime/vm/dart_api_impl.cc ('K') | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698