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

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

Issue 9956133: Remove many calls to Isolate::Current() in the dart embedding api by (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 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
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/debugger_api_impl.cc » ('j') | 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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "platform/assert.h" 6 #include "platform/assert.h"
7 #include "platform/utils.h" 7 #include "platform/utils.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_api_state.h" 10 #include "vm/dart_api_state.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 // Equal objects. 156 // Equal objects.
157 EXPECT_VALID(Dart_IsSame(five, five_again, &same)); 157 EXPECT_VALID(Dart_IsSame(five, five_again, &same));
158 EXPECT(!same); 158 EXPECT(!same);
159 159
160 // Different objects. 160 // Different objects.
161 EXPECT_VALID(Dart_IsSame(five, seven, &same)); 161 EXPECT_VALID(Dart_IsSame(five, seven, &same));
162 EXPECT(!same); 162 EXPECT(!same);
163 163
164 // Non-instance objects. 164 // Non-instance objects.
165 { 165 {
166 DARTSCOPE_NOCHECKS(Isolate::Current()); 166 Isolate* isolate = Isolate::Current();
167 DARTSCOPE_NOCHECKS(isolate);
167 const Object& cls1 = Object::Handle(Object::null_class()); 168 const Object& cls1 = Object::Handle(Object::null_class());
168 const Object& cls2 = Object::Handle(Object::class_class()); 169 const Object& cls2 = Object::Handle(Object::class_class());
169 Dart_Handle class1 = Api::NewLocalHandle(cls1); 170 Dart_Handle class1 = Api::NewLocalHandle(isolate, cls1);
170 Dart_Handle class2 = Api::NewLocalHandle(cls2); 171 Dart_Handle class2 = Api::NewLocalHandle(isolate, cls2);
171 172
172 EXPECT_VALID(Dart_IsSame(class1, class1, &same)); 173 EXPECT_VALID(Dart_IsSame(class1, class1, &same));
173 EXPECT(same); 174 EXPECT(same);
174 175
175 EXPECT_VALID(Dart_IsSame(class1, class2, &same)); 176 EXPECT_VALID(Dart_IsSame(class1, class2, &same));
176 EXPECT(!same); 177 EXPECT(!same);
177 } 178 }
178 } 179 }
179 180
180 181
(...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 Isolate* isolate = Isolate::Current(); 1122 Isolate* isolate = Isolate::Current();
1122 EXPECT(isolate != NULL); 1123 EXPECT(isolate != NULL);
1123 ApiState* state = isolate->api_state(); 1124 ApiState* state = isolate->api_state();
1124 EXPECT(state != NULL); 1125 EXPECT(state != NULL);
1125 ApiLocalScope* scope = state->top_scope(); 1126 ApiLocalScope* scope = state->top_scope();
1126 Dart_EnterScope(); 1127 Dart_EnterScope();
1127 { 1128 {
1128 EXPECT(state->top_scope() != NULL); 1129 EXPECT(state->top_scope() != NULL);
1129 DARTSCOPE_NOCHECKS(isolate); 1130 DARTSCOPE_NOCHECKS(isolate);
1130 const String& str1 = String::Handle(String::New("Test String")); 1131 const String& str1 = String::Handle(String::New("Test String"));
1131 Dart_Handle ref = Api::NewLocalHandle(str1); 1132 Dart_Handle ref = Api::NewLocalHandle(isolate, str1);
1132 String& str2 = String::Handle(); 1133 String& str2 = String::Handle();
1133 str2 ^= Api::UnwrapHandle(ref); 1134 str2 ^= Api::UnwrapHandle(ref);
1134 EXPECT(str1.Equals(str2)); 1135 EXPECT(str1.Equals(str2));
1135 } 1136 }
1136 Dart_ExitScope(); 1137 Dart_ExitScope();
1137 EXPECT(scope == state->top_scope()); 1138 EXPECT(scope == state->top_scope());
1138 } 1139 }
1139 1140
1140 1141
1141 // Unit test for creating and deleting persistent handles. 1142 // Unit test for creating and deleting persistent handles.
1142 UNIT_TEST_CASE(PersistentHandles) { 1143 UNIT_TEST_CASE(PersistentHandles) {
1143 const char* kTestString1 = "Test String1"; 1144 const char* kTestString1 = "Test String1";
1144 const char* kTestString2 = "Test String2"; 1145 const char* kTestString2 = "Test String2";
1145 TestCase::CreateTestIsolate(); 1146 TestCase::CreateTestIsolate();
1146 Isolate* isolate = Isolate::Current(); 1147 Isolate* isolate = Isolate::Current();
1147 EXPECT(isolate != NULL); 1148 EXPECT(isolate != NULL);
1148 ApiState* state = isolate->api_state(); 1149 ApiState* state = isolate->api_state();
1149 EXPECT(state != NULL); 1150 EXPECT(state != NULL);
1150 ApiLocalScope* scope = state->top_scope(); 1151 ApiLocalScope* scope = state->top_scope();
1151 Dart_Handle handles[2000]; 1152 Dart_Handle handles[2000];
1152 Dart_EnterScope(); 1153 Dart_EnterScope();
1153 { 1154 {
1154 DARTSCOPE_NOCHECKS(isolate); 1155 DARTSCOPE_NOCHECKS(isolate);
1155 const String& str1 = String::Handle(String::New(kTestString1)); 1156 const String& str1 = String::Handle(String::New(kTestString1));
1156 Dart_Handle ref1 = Api::NewLocalHandle(str1); 1157 Dart_Handle ref1 = Api::NewLocalHandle(isolate, str1);
1157 for (int i = 0; i < 1000; i++) { 1158 for (int i = 0; i < 1000; i++) {
1158 handles[i] = Dart_NewPersistentHandle(ref1); 1159 handles[i] = Dart_NewPersistentHandle(ref1);
1159 } 1160 }
1160 Dart_EnterScope(); 1161 Dart_EnterScope();
1161 const String& str2 = String::Handle(String::New(kTestString2)); 1162 const String& str2 = String::Handle(String::New(kTestString2));
1162 Dart_Handle ref2 = Api::NewLocalHandle(str2); 1163 Dart_Handle ref2 = Api::NewLocalHandle(isolate, str2);
1163 for (int i = 1000; i < 2000; i++) { 1164 for (int i = 1000; i < 2000; i++) {
1164 handles[i] = Dart_NewPersistentHandle(ref2); 1165 handles[i] = Dart_NewPersistentHandle(ref2);
1165 } 1166 }
1166 for (int i = 500; i < 1500; i++) { 1167 for (int i = 500; i < 1500; i++) {
1167 Dart_DeletePersistentHandle(handles[i]); 1168 Dart_DeletePersistentHandle(handles[i]);
1168 } 1169 }
1169 for (int i = 500; i < 1000; i++) { 1170 for (int i = 500; i < 1000; i++) {
1170 handles[i] = Dart_NewPersistentHandle(ref2); 1171 handles[i] = Dart_NewPersistentHandle(ref2);
1171 } 1172 }
1172 for (int i = 1000; i < 1500; i++) { 1173 for (int i = 1000; i < 1500; i++) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 { 1248 {
1248 Dart_EnterScope(); 1249 Dart_EnterScope();
1249 1250
1250 // create an object in new space 1251 // create an object in new space
1251 Dart_Handle new_ref = Dart_NewString("new string"); 1252 Dart_Handle new_ref = Dart_NewString("new string");
1252 EXPECT_VALID(new_ref); 1253 EXPECT_VALID(new_ref);
1253 1254
1254 // create an object in old space 1255 // create an object in old space
1255 Dart_Handle old_ref; 1256 Dart_Handle old_ref;
1256 { 1257 {
1257 DARTSCOPE(Isolate::Current()); 1258 Isolate* isolate = Isolate::Current();
1259 DARTSCOPE(isolate);
1258 const String& str = 1260 const String& str =
1259 String::Handle(String::New("old string", Heap::kOld)); 1261 String::Handle(String::New("old string", Heap::kOld));
1260 old_ref = Api::NewLocalHandle(str); 1262 old_ref = Api::NewLocalHandle(isolate, str);
1261 EXPECT_VALID(old_ref); 1263 EXPECT_VALID(old_ref);
1262 } 1264 }
1263 1265
1264 // create a weak ref to the new space object 1266 // create a weak ref to the new space object
1265 weak_new_ref = Dart_NewWeakPersistentHandle(new_ref, NULL, NULL); 1267 weak_new_ref = Dart_NewWeakPersistentHandle(new_ref, NULL, NULL);
1266 EXPECT_VALID(weak_new_ref); 1268 EXPECT_VALID(weak_new_ref);
1267 EXPECT(!Dart_IsNull(weak_new_ref)); 1269 EXPECT(!Dart_IsNull(weak_new_ref));
1268 1270
1269 // create a weak ref to the old space object 1271 // create a weak ref to the old space object
1270 weak_old_ref = Dart_NewWeakPersistentHandle(old_ref, NULL, NULL); 1272 weak_old_ref = Dart_NewWeakPersistentHandle(old_ref, NULL, NULL);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 EXPECT(Dart_IsNull(weak2)); 1385 EXPECT(Dart_IsNull(weak2));
1384 1386
1385 Dart_Handle weak3 = Dart_Null(); 1387 Dart_Handle weak3 = Dart_Null();
1386 EXPECT(Dart_IsNull(weak3)); 1388 EXPECT(Dart_IsNull(weak3));
1387 1389
1388 Dart_Handle weak4 = Dart_Null(); 1390 Dart_Handle weak4 = Dart_Null();
1389 EXPECT(Dart_IsNull(weak4)); 1391 EXPECT(Dart_IsNull(weak4));
1390 1392
1391 Dart_EnterScope(); 1393 Dart_EnterScope();
1392 { 1394 {
1393 DARTSCOPE(Isolate::Current()); 1395 Isolate* isolate = Isolate::Current();
1396 DARTSCOPE(isolate);
1394 String& str = String::Handle(); 1397 String& str = String::Handle();
1395 1398
1396 str ^= String::New("strongly reachable", Heap::kOld); 1399 str ^= String::New("strongly reachable", Heap::kOld);
1397 strong = Dart_NewPersistentHandle(Api::NewLocalHandle(str)); 1400 strong = Dart_NewPersistentHandle(Api::NewLocalHandle(isolate, str));
1398 EXPECT_VALID(strong); 1401 EXPECT_VALID(strong);
1399 EXPECT(!Dart_IsNull(strong)); 1402 EXPECT(!Dart_IsNull(strong));
1400 1403
1401 str ^= String::New("weakly reachable 1", Heap::kOld); 1404 str ^= String::New("weakly reachable 1", Heap::kOld);
1402 weak1 = Dart_NewWeakPersistentHandle(Api::NewLocalHandle(str), NULL, NULL); 1405 weak1 = Dart_NewWeakPersistentHandle(
1406 Api::NewLocalHandle(isolate, str), NULL, NULL);
1403 EXPECT_VALID(weak1); 1407 EXPECT_VALID(weak1);
1404 EXPECT(!Dart_IsNull(weak1)); 1408 EXPECT(!Dart_IsNull(weak1));
1405 1409
1406 str ^= String::New("weakly reachable 2", Heap::kOld); 1410 str ^= String::New("weakly reachable 2", Heap::kOld);
1407 weak2 = Dart_NewWeakPersistentHandle(Api::NewLocalHandle(str), NULL, NULL); 1411 weak2 = Dart_NewWeakPersistentHandle(
1412 Api::NewLocalHandle(isolate, str), NULL, NULL);
1408 EXPECT_VALID(weak2); 1413 EXPECT_VALID(weak2);
1409 EXPECT(!Dart_IsNull(weak2)); 1414 EXPECT(!Dart_IsNull(weak2));
1410 1415
1411 str ^= String::New("weakly reachable 3", Heap::kOld); 1416 str ^= String::New("weakly reachable 3", Heap::kOld);
1412 weak3 = Dart_NewWeakPersistentHandle(Api::NewLocalHandle(str), NULL, NULL); 1417 weak3 = Dart_NewWeakPersistentHandle(
1418 Api::NewLocalHandle(isolate, str), NULL, NULL);
1413 EXPECT_VALID(weak3); 1419 EXPECT_VALID(weak3);
1414 EXPECT(!Dart_IsNull(weak3)); 1420 EXPECT(!Dart_IsNull(weak3));
1415 1421
1416 str ^= String::New("weakly reachable 4", Heap::kOld); 1422 str ^= String::New("weakly reachable 4", Heap::kOld);
1417 weak4 = Dart_NewWeakPersistentHandle(Api::NewLocalHandle(str), NULL, NULL); 1423 weak4 = Dart_NewWeakPersistentHandle(
1424 Api::NewLocalHandle(isolate, str), NULL, NULL);
1418 EXPECT_VALID(weak4); 1425 EXPECT_VALID(weak4);
1419 EXPECT(!Dart_IsNull(weak4)); 1426 EXPECT(!Dart_IsNull(weak4));
1420 } 1427 }
1421 Dart_ExitScope(); 1428 Dart_ExitScope();
1422 1429
1423 EXPECT_VALID(strong); 1430 EXPECT_VALID(strong);
1424 1431
1425 EXPECT_VALID(weak1); 1432 EXPECT_VALID(weak1);
1426 EXPECT_VALID(weak2); 1433 EXPECT_VALID(weak2);
1427 EXPECT_VALID(weak3); 1434 EXPECT_VALID(weak3);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1561 } 1568 }
1562 1569
1563 1570
1564 TEST_CASE(PrologueWeakPersistentHandles) { 1571 TEST_CASE(PrologueWeakPersistentHandles) {
1565 Dart_Handle old_pwph = Dart_Null(); 1572 Dart_Handle old_pwph = Dart_Null();
1566 EXPECT(Dart_IsNull(old_pwph)); 1573 EXPECT(Dart_IsNull(old_pwph));
1567 Dart_Handle new_pwph = Dart_Null(); 1574 Dart_Handle new_pwph = Dart_Null();
1568 EXPECT(Dart_IsNull(new_pwph)); 1575 EXPECT(Dart_IsNull(new_pwph));
1569 Dart_EnterScope(); 1576 Dart_EnterScope();
1570 { 1577 {
1571 DARTSCOPE(Isolate::Current()); 1578 Isolate* isolate = Isolate::Current();
1579 DARTSCOPE(isolate);
1572 String& str = String::Handle(); 1580 String& str = String::Handle();
1573 str ^= String::New("new space prologue weak", Heap::kNew); 1581 str ^= String::New("new space prologue weak", Heap::kNew);
1574 new_pwph = Dart_NewPrologueWeakPersistentHandle(Api::NewLocalHandle(str), 1582 new_pwph = Dart_NewPrologueWeakPersistentHandle(
1575 NULL, 1583 Api::NewLocalHandle(isolate, str), NULL, NULL);
1576 NULL);
1577 EXPECT_VALID(new_pwph); 1584 EXPECT_VALID(new_pwph);
1578 EXPECT(!Dart_IsNull(new_pwph)); 1585 EXPECT(!Dart_IsNull(new_pwph));
1579 str ^= String::New("old space prologue weak", Heap::kOld); 1586 str ^= String::New("old space prologue weak", Heap::kOld);
1580 old_pwph = Dart_NewPrologueWeakPersistentHandle(Api::NewLocalHandle(str), 1587 old_pwph = Dart_NewPrologueWeakPersistentHandle(
1581 NULL, 1588 Api::NewLocalHandle(isolate, str), NULL, NULL);
1582 NULL);
1583 EXPECT_VALID(old_pwph); 1589 EXPECT_VALID(old_pwph);
1584 EXPECT(!Dart_IsNull(old_pwph)); 1590 EXPECT(!Dart_IsNull(old_pwph));
1585 str ^= String::null(); 1591 str ^= String::null();
1586 } 1592 }
1587 Dart_ExitScope(); 1593 Dart_ExitScope();
1588 EXPECT_VALID(new_pwph); 1594 EXPECT_VALID(new_pwph);
1589 EXPECT(!Dart_IsNull(new_pwph)); 1595 EXPECT(!Dart_IsNull(new_pwph));
1590 EXPECT(Dart_IsPrologueWeakPersistentHandle(new_pwph)); 1596 EXPECT(Dart_IsPrologueWeakPersistentHandle(new_pwph));
1591 EXPECT_VALID(old_pwph); 1597 EXPECT_VALID(old_pwph);
1592 EXPECT(!Dart_IsNull(old_pwph)); 1598 EXPECT(!Dart_IsNull(old_pwph));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 1634
1629 Dart_Handle weak2 = Dart_Null(); 1635 Dart_Handle weak2 = Dart_Null();
1630 EXPECT(Dart_IsNull(weak2)); 1636 EXPECT(Dart_IsNull(weak2));
1631 1637
1632 Dart_Handle weak3 = Dart_Null(); 1638 Dart_Handle weak3 = Dart_Null();
1633 EXPECT(Dart_IsNull(weak3)); 1639 EXPECT(Dart_IsNull(weak3));
1634 1640
1635 1641
1636 Dart_EnterScope(); 1642 Dart_EnterScope();
1637 { 1643 {
1638 DARTSCOPE(Isolate::Current()); 1644 Isolate* isolate = Isolate::Current();
1645 DARTSCOPE(isolate);
1639 String& str = String::Handle(); 1646 String& str = String::Handle();
1640 1647
1641 str ^= String::New("strongly reachable", Heap::kOld); 1648 str ^= String::New("strongly reachable", Heap::kOld);
1642 strong = Dart_NewPersistentHandle(Api::NewLocalHandle(str)); 1649 strong = Dart_NewPersistentHandle(Api::NewLocalHandle(isolate, str));
1643 EXPECT(!Dart_IsNull(strong)); 1650 EXPECT(!Dart_IsNull(strong));
1644 EXPECT_VALID(strong); 1651 EXPECT_VALID(strong);
1645 1652
1646 str ^= String::New("weakly reachable 1", Heap::kOld); 1653 str ^= String::New("weakly reachable 1", Heap::kOld);
1647 weak1 = Dart_NewWeakPersistentHandle(Api::NewLocalHandle(str), NULL, NULL); 1654 weak1 = Dart_NewWeakPersistentHandle(
1655 Api::NewLocalHandle(isolate, str), NULL, NULL);
1648 EXPECT(!Dart_IsNull(weak1)); 1656 EXPECT(!Dart_IsNull(weak1));
1649 EXPECT_VALID(weak1); 1657 EXPECT_VALID(weak1);
1650 1658
1651 str ^= String::New("weakly reachable 2", Heap::kOld); 1659 str ^= String::New("weakly reachable 2", Heap::kOld);
1652 weak2 = Dart_NewWeakPersistentHandle(Api::NewLocalHandle(str), NULL, NULL); 1660 weak2 = Dart_NewWeakPersistentHandle(
1661 Api::NewLocalHandle(isolate, str), NULL, NULL);
1653 EXPECT(!Dart_IsNull(weak2)); 1662 EXPECT(!Dart_IsNull(weak2));
1654 EXPECT_VALID(weak2); 1663 EXPECT_VALID(weak2);
1655 1664
1656 str ^= String::New("weakly reachable 3", Heap::kOld); 1665 str ^= String::New("weakly reachable 3", Heap::kOld);
1657 weak3 = Dart_NewWeakPersistentHandle(Api::NewLocalHandle(str), NULL, NULL); 1666 weak3 = Dart_NewWeakPersistentHandle(
1667 Api::NewLocalHandle(isolate, str), NULL, NULL);
1658 EXPECT(!Dart_IsNull(weak3)); 1668 EXPECT(!Dart_IsNull(weak3));
1659 EXPECT_VALID(weak3); 1669 EXPECT_VALID(weak3);
1660 } 1670 }
1661 Dart_ExitScope(); 1671 Dart_ExitScope();
1662 1672
1663 EXPECT_VALID(strong); 1673 EXPECT_VALID(strong);
1664 1674
1665 EXPECT_VALID(weak1); 1675 EXPECT_VALID(weak1);
1666 EXPECT_VALID(weak2); 1676 EXPECT_VALID(weak2);
1667 EXPECT_VALID(weak3); 1677 EXPECT_VALID(weak3);
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
1968 ApiLocalScope* scope = state->top_scope(); 1978 ApiLocalScope* scope = state->top_scope();
1969 Dart_Handle handles[300]; 1979 Dart_Handle handles[300];
1970 { 1980 {
1971 DARTSCOPE_NOCHECKS(isolate); 1981 DARTSCOPE_NOCHECKS(isolate);
1972 Smi& val = Smi::Handle(); 1982 Smi& val = Smi::Handle();
1973 1983
1974 // Start a new scope and allocate some local handles. 1984 // Start a new scope and allocate some local handles.
1975 Dart_EnterScope(); 1985 Dart_EnterScope();
1976 for (int i = 0; i < 100; i++) { 1986 for (int i = 0; i < 100; i++) {
1977 val ^= Smi::New(i); 1987 val ^= Smi::New(i);
1978 handles[i] = Api::NewLocalHandle(val); 1988 handles[i] = Api::NewLocalHandle(isolate, val);
1979 } 1989 }
1980 EXPECT_EQ(100, state->CountLocalHandles()); 1990 EXPECT_EQ(100, state->CountLocalHandles());
1981 for (int i = 0; i < 100; i++) { 1991 for (int i = 0; i < 100; i++) {
1982 val ^= Api::UnwrapHandle(handles[i]); 1992 val ^= Api::UnwrapHandle(handles[i]);
1983 EXPECT_EQ(i, val.Value()); 1993 EXPECT_EQ(i, val.Value());
1984 } 1994 }
1985 // Start another scope and allocate some more local handles. 1995 // Start another scope and allocate some more local handles.
1986 { 1996 {
1987 Dart_EnterScope(); 1997 Dart_EnterScope();
1988 for (int i = 100; i < 200; i++) { 1998 for (int i = 100; i < 200; i++) {
1989 val ^= Smi::New(i); 1999 val ^= Smi::New(i);
1990 handles[i] = Api::NewLocalHandle(val); 2000 handles[i] = Api::NewLocalHandle(isolate, val);
1991 } 2001 }
1992 EXPECT_EQ(200, state->CountLocalHandles()); 2002 EXPECT_EQ(200, state->CountLocalHandles());
1993 for (int i = 100; i < 200; i++) { 2003 for (int i = 100; i < 200; i++) {
1994 val ^= Api::UnwrapHandle(handles[i]); 2004 val ^= Api::UnwrapHandle(handles[i]);
1995 EXPECT_EQ(i, val.Value()); 2005 EXPECT_EQ(i, val.Value());
1996 } 2006 }
1997 2007
1998 // Start another scope and allocate some more local handles. 2008 // Start another scope and allocate some more local handles.
1999 { 2009 {
2000 Dart_EnterScope(); 2010 Dart_EnterScope();
2001 for (int i = 200; i < 300; i++) { 2011 for (int i = 200; i < 300; i++) {
2002 val ^= Smi::New(i); 2012 val ^= Smi::New(i);
2003 handles[i] = Api::NewLocalHandle(val); 2013 handles[i] = Api::NewLocalHandle(isolate, val);
2004 } 2014 }
2005 EXPECT_EQ(300, state->CountLocalHandles()); 2015 EXPECT_EQ(300, state->CountLocalHandles());
2006 for (int i = 200; i < 300; i++) { 2016 for (int i = 200; i < 300; i++) {
2007 val ^= Api::UnwrapHandle(handles[i]); 2017 val ^= Api::UnwrapHandle(handles[i]);
2008 EXPECT_EQ(i, val.Value()); 2018 EXPECT_EQ(i, val.Value());
2009 } 2019 }
2010 EXPECT_EQ(300, state->CountLocalHandles()); 2020 EXPECT_EQ(300, state->CountLocalHandles());
2011 VERIFY_ON_TRANSITION; 2021 VERIFY_ON_TRANSITION;
2012 Dart_ExitScope(); 2022 Dart_ExitScope();
2013 } 2023 }
(...skipping 16 matching lines...) Expand all
2030 TestCase::CreateTestIsolate(); 2040 TestCase::CreateTestIsolate();
2031 Isolate* isolate = Isolate::Current(); 2041 Isolate* isolate = Isolate::Current();
2032 EXPECT(isolate != NULL); 2042 EXPECT(isolate != NULL);
2033 ApiState* state = isolate->api_state(); 2043 ApiState* state = isolate->api_state();
2034 EXPECT(state != NULL); 2044 EXPECT(state != NULL);
2035 ApiLocalScope* scope = state->top_scope(); 2045 ApiLocalScope* scope = state->top_scope();
2036 { 2046 {
2037 // Start a new scope and allocate some memory. 2047 // Start a new scope and allocate some memory.
2038 Dart_EnterScope(); 2048 Dart_EnterScope();
2039 for (int i = 0; i < 100; i++) { 2049 for (int i = 0; i < 100; i++) {
2040 Api::Allocate(16); 2050 Api::Allocate(isolate, 16);
2041 } 2051 }
2042 EXPECT_EQ(1600, state->ZoneSizeInBytes()); 2052 EXPECT_EQ(1600, state->ZoneSizeInBytes());
2043 // Start another scope and allocate some more memory. 2053 // Start another scope and allocate some more memory.
2044 { 2054 {
2045 Dart_EnterScope(); 2055 Dart_EnterScope();
2046 for (int i = 0; i < 100; i++) { 2056 for (int i = 0; i < 100; i++) {
2047 Api::Allocate(16); 2057 Api::Allocate(isolate, 16);
2048 } 2058 }
2049 EXPECT_EQ(3200, state->ZoneSizeInBytes()); 2059 EXPECT_EQ(3200, state->ZoneSizeInBytes());
2050 { 2060 {
2051 // Start another scope and allocate some more memory. 2061 // Start another scope and allocate some more memory.
2052 { 2062 {
2053 Dart_EnterScope(); 2063 Dart_EnterScope();
2054 for (int i = 0; i < 200; i++) { 2064 for (int i = 0; i < 200; i++) {
2055 Api::Allocate(16); 2065 Api::Allocate(isolate, 16);
2056 } 2066 }
2057 EXPECT_EQ(6400, state->ZoneSizeInBytes()); 2067 EXPECT_EQ(6400, state->ZoneSizeInBytes());
2058 Dart_ExitScope(); 2068 Dart_ExitScope();
2059 } 2069 }
2060 } 2070 }
2061 EXPECT_EQ(3200, state->ZoneSizeInBytes()); 2071 EXPECT_EQ(3200, state->ZoneSizeInBytes());
2062 Dart_ExitScope(); 2072 Dart_ExitScope();
2063 } 2073 }
2064 EXPECT_EQ(1600, state->ZoneSizeInBytes()); 2074 EXPECT_EQ(1600, state->ZoneSizeInBytes());
2065 Dart_ExitScope(); 2075 Dart_ExitScope();
(...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after
3316 dart_arguments[0] = Dart_NewInteger(1); 3326 dart_arguments[0] = Dart_NewInteger(1);
3317 result = Dart_InvokeClosure(retobj, 1, dart_arguments); 3327 result = Dart_InvokeClosure(retobj, 1, dart_arguments);
3318 EXPECT(Dart_IsError(result)); 3328 EXPECT(Dart_IsError(result));
3319 EXPECT(Dart_ErrorHasException(result)); 3329 EXPECT(Dart_ErrorHasException(result));
3320 } 3330 }
3321 3331
3322 3332
3323 void ExceptionNative(Dart_NativeArguments args) { 3333 void ExceptionNative(Dart_NativeArguments args) {
3324 Dart_Handle param = Dart_GetNativeArgument(args, 0); 3334 Dart_Handle param = Dart_GetNativeArgument(args, 0);
3325 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 3335 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
3326 char* str = reinterpret_cast<char*>(Api::Allocate(1024));
3327 str[0] = 0;
3328 Dart_ThrowException(param); 3336 Dart_ThrowException(param);
3329 UNREACHABLE(); 3337 UNREACHABLE();
3330 } 3338 }
3331 3339
3332 3340
3333 static Dart_NativeFunction native_lookup(Dart_Handle name, int argument_count) { 3341 static Dart_NativeFunction native_lookup(Dart_Handle name, int argument_count) {
3334 return reinterpret_cast<Dart_NativeFunction>(&ExceptionNative); 3342 return reinterpret_cast<Dart_NativeFunction>(&ExceptionNative);
3335 } 3343 }
3336 3344
3337 3345
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
3523 EXPECT_VALID(result); 3531 EXPECT_VALID(result);
3524 EXPECT(!is_instance); 3532 EXPECT(!is_instance);
3525 3533
3526 // Check that error is returned if null is passed as a class argument. 3534 // Check that error is returned if null is passed as a class argument.
3527 result = Dart_ObjectIsType(null, null, &is_instance); 3535 result = Dart_ObjectIsType(null, null, &is_instance);
3528 EXPECT(Dart_IsError(result)); 3536 EXPECT(Dart_IsError(result));
3529 } 3537 }
3530 3538
3531 3539
3532 TEST_CASE(NullReceiver) { 3540 TEST_CASE(NullReceiver) {
3533 DARTSCOPE_NOCHECKS(Isolate::Current()); 3541 Isolate* isolate = Isolate::Current();
3542 DARTSCOPE_NOCHECKS(isolate);
3534 3543
3535 Dart_Handle function_name = Dart_NewString("toString"); 3544 Dart_Handle function_name = Dart_NewString("toString");
3536 const int number_of_arguments = 0; 3545 const int number_of_arguments = 0;
3537 Dart_Handle null_receiver = Api::NewLocalHandle(Object::Handle()); 3546 Dart_Handle null_receiver = Api::NewLocalHandle(isolate, Object::Handle());
3538 Dart_Handle result = Dart_InvokeDynamic(null_receiver, 3547 Dart_Handle result = Dart_InvokeDynamic(null_receiver,
3539 function_name, 3548 function_name,
3540 number_of_arguments, 3549 number_of_arguments,
3541 NULL); 3550 NULL);
3542 EXPECT_VALID(result); 3551 EXPECT_VALID(result);
3543 EXPECT(Dart_IsString(result)); 3552 EXPECT(Dart_IsString(result));
3544 3553
3545 // Should throw a NullPointerException. Disabled due to bug 5415268. 3554 // Should throw a NullPointerException. Disabled due to bug 5415268.
3546 /* 3555 /*
3547 Dart_Handle function_name2 = Dart_NewString("NoNoNo"); 3556 Dart_Handle function_name2 = Dart_NewString("NoNoNo");
3548 result = Dart_InvokeDynamic(null_receiver, 3557 result = Dart_InvokeDynamic(null_receiver,
3549 function_name2, 3558 function_name2,
3550 number_of_arguments, 3559 number_of_arguments,
3551 dart_arguments); 3560 dart_arguments);
3552 EXPECT(Dart_IsError(result)); 3561 EXPECT(Dart_IsError(result));
3553 EXPECT(Dart_ErrorHasException(result)); */ 3562 EXPECT(Dart_ErrorHasException(result)); */
3554 } 3563 }
3555 3564
3556 3565
3557 static Dart_Handle library_handler(Dart_LibraryTag tag, 3566 static Dart_Handle library_handler(Dart_LibraryTag tag,
3558 Dart_Handle library, 3567 Dart_Handle library,
3559 Dart_Handle url, 3568 Dart_Handle url,
3560 Dart_Handle import_url_map) { 3569 Dart_Handle import_url_map) {
3561 if (tag == kCanonicalizeUrl) { 3570 if (tag == kCanonicalizeUrl) {
3562 return url; 3571 return url;
3563 } 3572 }
3564 return Api::Success(); 3573 return Api::Success(Isolate::Current());
3565 } 3574 }
3566 3575
3567 3576
3568 TEST_CASE(LoadScript) { 3577 TEST_CASE(LoadScript) {
3569 const char* kScriptChars = 3578 const char* kScriptChars =
3570 "main() {" 3579 "main() {"
3571 " return 12345;" 3580 " return 12345;"
3572 "}"; 3581 "}";
3573 Dart_Handle url = Dart_NewString(TestCase::url()); 3582 Dart_Handle url = Dart_NewString(TestCase::url());
3574 Dart_Handle source = Dart_NewString(kScriptChars); 3583 Dart_Handle source = Dart_NewString(kScriptChars);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
3662 EXPECT_STREQ("abclaladef/extra_weird.dart", cstr); 3671 EXPECT_STREQ("abclaladef/extra_weird.dart", cstr);
3663 break; 3672 break;
3664 case 4: 3673 case 4:
3665 EXPECT_STREQ("winnerwinner", cstr); 3674 EXPECT_STREQ("winnerwinner", cstr);
3666 break; 3675 break;
3667 default: 3676 default:
3668 EXPECT(false); 3677 EXPECT(false);
3669 return Api::NewError("invalid callback"); 3678 return Api::NewError("invalid callback");
3670 } 3679 }
3671 index += 1; 3680 index += 1;
3672 return Api::Success(); 3681 return Api::Success(Isolate::Current());
3673 } 3682 }
3674 3683
3675 3684
3676 TEST_CASE(LoadImportScript) { 3685 TEST_CASE(LoadImportScript) {
3677 const char* kScriptChars = 3686 const char* kScriptChars =
3678 "#import('$GOOGLE3/weird.dart');" 3687 "#import('$GOOGLE3/weird.dart');"
3679 "#import('abc${ABC}def');" 3688 "#import('abc${ABC}def');"
3680 "#import('${var1}$var2');" 3689 "#import('${var1}$var2');"
3681 "#import('abc${ABC}def/extra_weird.dart');" 3690 "#import('abc${ABC}def/extra_weird.dart');"
3682 "#import('$var2$var2');" 3691 "#import('$var2$var2');"
(...skipping 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after
4841 EXPECT_VALID(result); 4850 EXPECT_VALID(result);
4842 EXPECT(Dart_IsDouble(result)); 4851 EXPECT(Dart_IsDouble(result));
4843 double out; 4852 double out;
4844 result = Dart_DoubleValue(result, &out); 4853 result = Dart_DoubleValue(result, &out);
4845 fprintf(stderr, "Benchmark_UseDartApi: %f us per iteration\n", out); 4854 fprintf(stderr, "Benchmark_UseDartApi: %f us per iteration\n", out);
4846 } 4855 }
4847 4856
4848 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 4857 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
4849 4858
4850 } // namespace dart 4859 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/debugger_api_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698