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 "include/dart_api.h" | 5 #include "include/dart_api.h" |
6 #include "platform/assert.h" | 6 #include "platform/assert.h" |
7 #include "platform/json.h" | 7 #include "platform/json.h" |
8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
(...skipping 1230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1241 ApiState* state = isolate->api_state(); | 1241 ApiState* state = isolate->api_state(); |
1242 EXPECT(state != NULL); | 1242 EXPECT(state != NULL); |
1243 ApiLocalScope* scope = state->top_scope(); | 1243 ApiLocalScope* scope = state->top_scope(); |
1244 Dart_EnterScope(); | 1244 Dart_EnterScope(); |
1245 { | 1245 { |
1246 EXPECT(state->top_scope() != NULL); | 1246 EXPECT(state->top_scope() != NULL); |
1247 DARTSCOPE_NOCHECKS(isolate); | 1247 DARTSCOPE_NOCHECKS(isolate); |
1248 const String& str1 = String::Handle(String::New("Test String")); | 1248 const String& str1 = String::Handle(String::New("Test String")); |
1249 Dart_Handle ref = Api::NewHandle(isolate, str1.raw()); | 1249 Dart_Handle ref = Api::NewHandle(isolate, str1.raw()); |
1250 String& str2 = String::Handle(); | 1250 String& str2 = String::Handle(); |
1251 str2 |= Api::UnwrapHandle(ref); | 1251 str2 ^= Api::UnwrapHandle(ref); |
1252 EXPECT(str1.Equals(str2)); | 1252 EXPECT(str1.Equals(str2)); |
1253 } | 1253 } |
1254 Dart_ExitScope(); | 1254 Dart_ExitScope(); |
1255 EXPECT(scope == state->top_scope()); | 1255 EXPECT(scope == state->top_scope()); |
1256 } | 1256 } |
1257 | 1257 |
1258 | 1258 |
1259 // Unit test for creating and deleting persistent handles. | 1259 // Unit test for creating and deleting persistent handles. |
1260 UNIT_TEST_CASE(PersistentHandles) { | 1260 UNIT_TEST_CASE(PersistentHandles) { |
1261 const char* kTestString1 = "Test String1"; | 1261 const char* kTestString1 = "Test String1"; |
(...skipping 28 matching lines...) Expand all Loading... |
1290 } | 1290 } |
1291 VERIFY_ON_TRANSITION; | 1291 VERIFY_ON_TRANSITION; |
1292 Dart_ExitScope(); | 1292 Dart_ExitScope(); |
1293 } | 1293 } |
1294 Dart_ExitScope(); | 1294 Dart_ExitScope(); |
1295 { | 1295 { |
1296 StackZone zone(isolate); | 1296 StackZone zone(isolate); |
1297 DARTSCOPE_NOCHECKS(isolate); | 1297 DARTSCOPE_NOCHECKS(isolate); |
1298 for (int i = 0; i < 500; i++) { | 1298 for (int i = 0; i < 500; i++) { |
1299 String& str = String::Handle(); | 1299 String& str = String::Handle(); |
1300 str |= Api::UnwrapHandle(handles[i]); | 1300 str ^= Api::UnwrapHandle(handles[i]); |
1301 EXPECT(str.Equals(kTestString1)); | 1301 EXPECT(str.Equals(kTestString1)); |
1302 } | 1302 } |
1303 for (int i = 500; i < 1000; i++) { | 1303 for (int i = 500; i < 1000; i++) { |
1304 String& str = String::Handle(); | 1304 String& str = String::Handle(); |
1305 str |= Api::UnwrapHandle(handles[i]); | 1305 str ^= Api::UnwrapHandle(handles[i]); |
1306 EXPECT(str.Equals(kTestString2)); | 1306 EXPECT(str.Equals(kTestString2)); |
1307 } | 1307 } |
1308 for (int i = 1000; i < 1500; i++) { | 1308 for (int i = 1000; i < 1500; i++) { |
1309 String& str = String::Handle(); | 1309 String& str = String::Handle(); |
1310 str |= Api::UnwrapHandle(handles[i]); | 1310 str ^= Api::UnwrapHandle(handles[i]); |
1311 EXPECT(str.Equals(kTestString1)); | 1311 EXPECT(str.Equals(kTestString1)); |
1312 } | 1312 } |
1313 for (int i = 1500; i < 2000; i++) { | 1313 for (int i = 1500; i < 2000; i++) { |
1314 String& str = String::Handle(); | 1314 String& str = String::Handle(); |
1315 str |= Api::UnwrapHandle(handles[i]); | 1315 str ^= Api::UnwrapHandle(handles[i]); |
1316 EXPECT(str.Equals(kTestString2)); | 1316 EXPECT(str.Equals(kTestString2)); |
1317 } | 1317 } |
1318 } | 1318 } |
1319 EXPECT(scope == state->top_scope()); | 1319 EXPECT(scope == state->top_scope()); |
1320 EXPECT_EQ(2000, state->CountPersistentHandles()); | 1320 EXPECT_EQ(2000, state->CountPersistentHandles()); |
1321 Dart_ShutdownIsolate(); | 1321 Dart_ShutdownIsolate(); |
1322 } | 1322 } |
1323 | 1323 |
1324 | 1324 |
1325 // Test that we are able to create a persistent handle from a | 1325 // Test that we are able to create a persistent handle from a |
(...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2248 DARTSCOPE_NOCHECKS(isolate); | 2248 DARTSCOPE_NOCHECKS(isolate); |
2249 Smi& val = Smi::Handle(); | 2249 Smi& val = Smi::Handle(); |
2250 | 2250 |
2251 // Start a new scope and allocate some local handles. | 2251 // Start a new scope and allocate some local handles. |
2252 Dart_EnterScope(); | 2252 Dart_EnterScope(); |
2253 for (int i = 0; i < 100; i++) { | 2253 for (int i = 0; i < 100; i++) { |
2254 handles[i] = Api::NewHandle(isolate, Smi::New(i)); | 2254 handles[i] = Api::NewHandle(isolate, Smi::New(i)); |
2255 } | 2255 } |
2256 EXPECT_EQ(100, state->CountLocalHandles()); | 2256 EXPECT_EQ(100, state->CountLocalHandles()); |
2257 for (int i = 0; i < 100; i++) { | 2257 for (int i = 0; i < 100; i++) { |
2258 val |= Api::UnwrapHandle(handles[i]); | 2258 val ^= Api::UnwrapHandle(handles[i]); |
2259 EXPECT_EQ(i, val.Value()); | 2259 EXPECT_EQ(i, val.Value()); |
2260 } | 2260 } |
2261 // Start another scope and allocate some more local handles. | 2261 // Start another scope and allocate some more local handles. |
2262 { | 2262 { |
2263 Dart_EnterScope(); | 2263 Dart_EnterScope(); |
2264 for (int i = 100; i < 200; i++) { | 2264 for (int i = 100; i < 200; i++) { |
2265 handles[i] = Api::NewHandle(isolate, Smi::New(i)); | 2265 handles[i] = Api::NewHandle(isolate, Smi::New(i)); |
2266 } | 2266 } |
2267 EXPECT_EQ(200, state->CountLocalHandles()); | 2267 EXPECT_EQ(200, state->CountLocalHandles()); |
2268 for (int i = 100; i < 200; i++) { | 2268 for (int i = 100; i < 200; i++) { |
2269 val |= Api::UnwrapHandle(handles[i]); | 2269 val ^= Api::UnwrapHandle(handles[i]); |
2270 EXPECT_EQ(i, val.Value()); | 2270 EXPECT_EQ(i, val.Value()); |
2271 } | 2271 } |
2272 | 2272 |
2273 // Start another scope and allocate some more local handles. | 2273 // Start another scope and allocate some more local handles. |
2274 { | 2274 { |
2275 Dart_EnterScope(); | 2275 Dart_EnterScope(); |
2276 for (int i = 200; i < 300; i++) { | 2276 for (int i = 200; i < 300; i++) { |
2277 handles[i] = Api::NewHandle(isolate, Smi::New(i)); | 2277 handles[i] = Api::NewHandle(isolate, Smi::New(i)); |
2278 } | 2278 } |
2279 EXPECT_EQ(300, state->CountLocalHandles()); | 2279 EXPECT_EQ(300, state->CountLocalHandles()); |
2280 for (int i = 200; i < 300; i++) { | 2280 for (int i = 200; i < 300; i++) { |
2281 val |= Api::UnwrapHandle(handles[i]); | 2281 val ^= Api::UnwrapHandle(handles[i]); |
2282 EXPECT_EQ(i, val.Value()); | 2282 EXPECT_EQ(i, val.Value()); |
2283 } | 2283 } |
2284 EXPECT_EQ(300, state->CountLocalHandles()); | 2284 EXPECT_EQ(300, state->CountLocalHandles()); |
2285 VERIFY_ON_TRANSITION; | 2285 VERIFY_ON_TRANSITION; |
2286 Dart_ExitScope(); | 2286 Dart_ExitScope(); |
2287 } | 2287 } |
2288 EXPECT_EQ(200, state->CountLocalHandles()); | 2288 EXPECT_EQ(200, state->CountLocalHandles()); |
2289 Dart_ExitScope(); | 2289 Dart_ExitScope(); |
2290 } | 2290 } |
2291 EXPECT_EQ(100, state->CountLocalHandles()); | 2291 EXPECT_EQ(100, state->CountLocalHandles()); |
(...skipping 4779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7071 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 7071 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
7072 out = &out; | 7072 out = &out; |
7073 EXPECT(Dart_GetPeer(str, &out)); | 7073 EXPECT(Dart_GetPeer(str, &out)); |
7074 EXPECT(out == reinterpret_cast<void*>(&peer)); | 7074 EXPECT(out == reinterpret_cast<void*>(&peer)); |
7075 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 7075 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
7076 isolate->heap()->CollectGarbage(Heap::kNew); | 7076 isolate->heap()->CollectGarbage(Heap::kNew); |
7077 isolate->heap()->CollectGarbage(Heap::kNew); | 7077 isolate->heap()->CollectGarbage(Heap::kNew); |
7078 { | 7078 { |
7079 DARTSCOPE_NOCHECKS(isolate); | 7079 DARTSCOPE_NOCHECKS(isolate); |
7080 String& handle = String::Handle(); | 7080 String& handle = String::Handle(); |
7081 handle |= Api::UnwrapHandle(str); | 7081 handle ^= Api::UnwrapHandle(str); |
7082 EXPECT(handle.IsOld()); | 7082 EXPECT(handle.IsOld()); |
7083 } | 7083 } |
7084 EXPECT_VALID(Dart_GetPeer(str, &out)); | 7084 EXPECT_VALID(Dart_GetPeer(str, &out)); |
7085 EXPECT(out == reinterpret_cast<void*>(&peer)); | 7085 EXPECT(out == reinterpret_cast<void*>(&peer)); |
7086 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 7086 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
7087 EXPECT_VALID(Dart_SetPeer(str, NULL)); | 7087 EXPECT_VALID(Dart_SetPeer(str, NULL)); |
7088 out = &out; | 7088 out = &out; |
7089 EXPECT_VALID(Dart_GetPeer(str, &out)); | 7089 EXPECT_VALID(Dart_GetPeer(str, &out)); |
7090 EXPECT(out == NULL); | 7090 EXPECT(out == NULL); |
7091 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 7091 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7512 NULL); | 7512 NULL); |
7513 int64_t value = 0; | 7513 int64_t value = 0; |
7514 result = Dart_IntegerToInt64(result, &value); | 7514 result = Dart_IntegerToInt64(result, &value); |
7515 EXPECT_VALID(result); | 7515 EXPECT_VALID(result); |
7516 EXPECT_EQ(260, value); | 7516 EXPECT_EQ(260, value); |
7517 } | 7517 } |
7518 | 7518 |
7519 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 7519 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
7520 | 7520 |
7521 } // namespace dart | 7521 } // namespace dart |
OLD | NEW |