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_mirrors_api.h" | 7 #include "include/dart_mirrors_api.h" |
8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
9 #include "include/dart_tools_api.h" | 9 #include "include/dart_tools_api.h" |
10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 390 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
391 EXPECT_VALID(result); | 391 EXPECT_VALID(result); |
392 EXPECT(Dart_IsInteger(result)); | 392 EXPECT(Dart_IsInteger(result)); |
393 int64_t value = 0; | 393 int64_t value = 0; |
394 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 394 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
395 EXPECT_EQ(42, value); | 395 EXPECT_EQ(42, value); |
396 } | 396 } |
397 | 397 |
398 | 398 |
399 TEST_CASE(ErrorHandleTypes) { | 399 TEST_CASE(ErrorHandleTypes) { |
400 Isolate* isolate = Isolate::Current(); | |
401 const String& compile_message = String::Handle(String::New("CompileError")); | 400 const String& compile_message = String::Handle(String::New("CompileError")); |
402 const String& fatal_message = String::Handle(String::New("FatalError")); | 401 const String& fatal_message = String::Handle(String::New("FatalError")); |
403 | 402 |
404 Dart_Handle not_error = NewString("NotError"); | 403 Dart_Handle not_error = NewString("NotError"); |
405 Dart_Handle api_error = Api::NewError("Api%s", "Error"); | 404 Dart_Handle api_error = Api::NewError("Api%s", "Error"); |
406 Dart_Handle exception_error = | 405 Dart_Handle exception_error = |
407 Dart_NewUnhandledExceptionError(NewString("ExceptionError")); | 406 Dart_NewUnhandledExceptionError(NewString("ExceptionError")); |
408 Dart_Handle compile_error = | 407 Dart_Handle compile_error = |
409 Api::NewHandle(isolate, LanguageError::New(compile_message)); | 408 Api::NewHandle(thread, LanguageError::New(compile_message)); |
410 Dart_Handle fatal_error = | 409 Dart_Handle fatal_error = |
411 Api::NewHandle(isolate, UnwindError::New(fatal_message)); | 410 Api::NewHandle(thread, UnwindError::New(fatal_message)); |
412 | 411 |
413 EXPECT_VALID(not_error); | 412 EXPECT_VALID(not_error); |
414 EXPECT(Dart_IsError(api_error)); | 413 EXPECT(Dart_IsError(api_error)); |
415 EXPECT(Dart_IsError(exception_error)); | 414 EXPECT(Dart_IsError(exception_error)); |
416 EXPECT(Dart_IsError(compile_error)); | 415 EXPECT(Dart_IsError(compile_error)); |
417 EXPECT(Dart_IsError(fatal_error)); | 416 EXPECT(Dart_IsError(fatal_error)); |
418 | 417 |
419 EXPECT(!Dart_IsApiError(not_error)); | 418 EXPECT(!Dart_IsApiError(not_error)); |
420 EXPECT(Dart_IsApiError(api_error)); | 419 EXPECT(Dart_IsApiError(api_error)); |
421 EXPECT(!Dart_IsApiError(exception_error)); | 420 EXPECT(!Dart_IsApiError(exception_error)); |
(...skipping 21 matching lines...) Expand all Loading... |
443 EXPECT_STREQ("", Dart_GetError(not_error)); | 442 EXPECT_STREQ("", Dart_GetError(not_error)); |
444 EXPECT_STREQ("ApiError", Dart_GetError(api_error)); | 443 EXPECT_STREQ("ApiError", Dart_GetError(api_error)); |
445 EXPECT_SUBSTRING("Unhandled exception:\nExceptionError", | 444 EXPECT_SUBSTRING("Unhandled exception:\nExceptionError", |
446 Dart_GetError(exception_error)); | 445 Dart_GetError(exception_error)); |
447 EXPECT_STREQ("CompileError", Dart_GetError(compile_error)); | 446 EXPECT_STREQ("CompileError", Dart_GetError(compile_error)); |
448 EXPECT_STREQ("FatalError", Dart_GetError(fatal_error)); | 447 EXPECT_STREQ("FatalError", Dart_GetError(fatal_error)); |
449 } | 448 } |
450 | 449 |
451 | 450 |
452 TEST_CASE(UnhandleExceptionError) { | 451 TEST_CASE(UnhandleExceptionError) { |
453 Isolate* isolate = Isolate::Current(); | |
454 const char* exception_cstr = ""; | 452 const char* exception_cstr = ""; |
455 | 453 |
456 // Test with an API Error. | 454 // Test with an API Error. |
457 const char* kApiError = "Api Error Exception Test."; | 455 const char* kApiError = "Api Error Exception Test."; |
458 Dart_Handle api_error = Api::NewHandle( | 456 Dart_Handle api_error = Api::NewHandle( |
459 isolate, | 457 thread, |
460 ApiError::New(String::Handle(String::New(kApiError)))); | 458 ApiError::New(String::Handle(String::New(kApiError)))); |
461 Dart_Handle exception_error = Dart_NewUnhandledExceptionError(api_error); | 459 Dart_Handle exception_error = Dart_NewUnhandledExceptionError(api_error); |
462 EXPECT(!Dart_IsApiError(exception_error)); | 460 EXPECT(!Dart_IsApiError(exception_error)); |
463 EXPECT(Dart_IsUnhandledExceptionError(exception_error)); | 461 EXPECT(Dart_IsUnhandledExceptionError(exception_error)); |
464 EXPECT(Dart_IsString(Dart_ErrorGetException(exception_error))); | 462 EXPECT(Dart_IsString(Dart_ErrorGetException(exception_error))); |
465 EXPECT_VALID(Dart_StringToCString(Dart_ErrorGetException(exception_error), | 463 EXPECT_VALID(Dart_StringToCString(Dart_ErrorGetException(exception_error), |
466 &exception_cstr)); | 464 &exception_cstr)); |
467 EXPECT_STREQ(kApiError, exception_cstr); | 465 EXPECT_STREQ(kApiError, exception_cstr); |
468 | 466 |
469 // Test with a Compilation Error. | 467 // Test with a Compilation Error. |
470 const char* kCompileError = "CompileError Exception Test."; | 468 const char* kCompileError = "CompileError Exception Test."; |
471 const String& compile_message = | 469 const String& compile_message = |
472 String::Handle(String::New(kCompileError)); | 470 String::Handle(String::New(kCompileError)); |
473 Dart_Handle compile_error = | 471 Dart_Handle compile_error = |
474 Api::NewHandle(isolate, LanguageError::New(compile_message)); | 472 Api::NewHandle(thread, LanguageError::New(compile_message)); |
475 exception_error = Dart_NewUnhandledExceptionError(compile_error); | 473 exception_error = Dart_NewUnhandledExceptionError(compile_error); |
476 EXPECT(!Dart_IsApiError(exception_error)); | 474 EXPECT(!Dart_IsApiError(exception_error)); |
477 EXPECT(Dart_IsUnhandledExceptionError(exception_error)); | 475 EXPECT(Dart_IsUnhandledExceptionError(exception_error)); |
478 EXPECT(Dart_IsString(Dart_ErrorGetException(exception_error))); | 476 EXPECT(Dart_IsString(Dart_ErrorGetException(exception_error))); |
479 EXPECT_VALID(Dart_StringToCString(Dart_ErrorGetException(exception_error), | 477 EXPECT_VALID(Dart_StringToCString(Dart_ErrorGetException(exception_error), |
480 &exception_cstr)); | 478 &exception_cstr)); |
481 EXPECT_STREQ(kCompileError, exception_cstr); | 479 EXPECT_STREQ(kCompileError, exception_cstr); |
482 | 480 |
483 // Test with a Fatal Error. | 481 // Test with a Fatal Error. |
484 const String& fatal_message = | 482 const String& fatal_message = |
485 String::Handle(String::New("FatalError Exception Test.")); | 483 String::Handle(String::New("FatalError Exception Test.")); |
486 Dart_Handle fatal_error = | 484 Dart_Handle fatal_error = |
487 Api::NewHandle(isolate, UnwindError::New(fatal_message)); | 485 Api::NewHandle(thread, UnwindError::New(fatal_message)); |
488 exception_error = Dart_NewUnhandledExceptionError(fatal_error); | 486 exception_error = Dart_NewUnhandledExceptionError(fatal_error); |
489 EXPECT(Dart_IsError(exception_error)); | 487 EXPECT(Dart_IsError(exception_error)); |
490 EXPECT(!Dart_IsUnhandledExceptionError(exception_error)); | 488 EXPECT(!Dart_IsUnhandledExceptionError(exception_error)); |
491 | 489 |
492 // Test with a Regular object. | 490 // Test with a Regular object. |
493 const char* kRegularString = "Regular String Exception Test."; | 491 const char* kRegularString = "Regular String Exception Test."; |
494 Dart_Handle obj = Api::NewHandle(isolate, String::New(kRegularString)); | 492 Dart_Handle obj = Api::NewHandle(thread, String::New(kRegularString)); |
495 exception_error = Dart_NewUnhandledExceptionError(obj); | 493 exception_error = Dart_NewUnhandledExceptionError(obj); |
496 EXPECT(!Dart_IsApiError(exception_error)); | 494 EXPECT(!Dart_IsApiError(exception_error)); |
497 EXPECT(Dart_IsUnhandledExceptionError(exception_error)); | 495 EXPECT(Dart_IsUnhandledExceptionError(exception_error)); |
498 EXPECT(Dart_IsString(Dart_ErrorGetException(exception_error))); | 496 EXPECT(Dart_IsString(Dart_ErrorGetException(exception_error))); |
499 EXPECT_VALID(Dart_StringToCString(Dart_ErrorGetException(exception_error), | 497 EXPECT_VALID(Dart_StringToCString(Dart_ErrorGetException(exception_error), |
500 &exception_cstr)); | 498 &exception_cstr)); |
501 EXPECT_STREQ(kRegularString, exception_cstr); | 499 EXPECT_STREQ(kRegularString, exception_cstr); |
502 } | 500 } |
503 | 501 |
504 | 502 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 EXPECT(!Dart_IdentityEquals(five, mint)); | 608 EXPECT(!Dart_IdentityEquals(five, mint)); |
611 EXPECT(!Dart_IdentityEquals(abc, xyz)); | 609 EXPECT(!Dart_IdentityEquals(abc, xyz)); |
612 | 610 |
613 // Case where identical() is not the same as pointer equality. | 611 // Case where identical() is not the same as pointer equality. |
614 Dart_Handle nan1 = Dart_NewDouble(NAN); | 612 Dart_Handle nan1 = Dart_NewDouble(NAN); |
615 Dart_Handle nan2 = Dart_NewDouble(NAN); | 613 Dart_Handle nan2 = Dart_NewDouble(NAN); |
616 EXPECT(Dart_IdentityEquals(nan1, nan2)); | 614 EXPECT(Dart_IdentityEquals(nan1, nan2)); |
617 | 615 |
618 // Non-instance objects. | 616 // Non-instance objects. |
619 { | 617 { |
620 DARTSCOPE(Thread::Current()); | 618 DARTSCOPE(thread); |
621 Dart_Handle lib1 = Dart_LookupLibrary(dart_core); | 619 Dart_Handle lib1 = Dart_LookupLibrary(dart_core); |
622 Dart_Handle lib2 = Dart_LookupLibrary(dart_mirrors); | 620 Dart_Handle lib2 = Dart_LookupLibrary(dart_mirrors); |
623 | 621 |
624 EXPECT(Dart_IdentityEquals(lib1, lib1)); | 622 EXPECT(Dart_IdentityEquals(lib1, lib1)); |
625 EXPECT(Dart_IdentityEquals(lib2, lib2)); | 623 EXPECT(Dart_IdentityEquals(lib2, lib2)); |
626 EXPECT(!Dart_IdentityEquals(lib1, lib2)); | 624 EXPECT(!Dart_IdentityEquals(lib1, lib2)); |
627 | 625 |
628 // Mix instance and non-instance. | 626 // Mix instance and non-instance. |
629 EXPECT(!Dart_IdentityEquals(lib1, nan1)); | 627 EXPECT(!Dart_IdentityEquals(lib1, nan1)); |
630 EXPECT(!Dart_IdentityEquals(nan1, lib1)); | 628 EXPECT(!Dart_IdentityEquals(nan1, lib1)); |
(...skipping 24 matching lines...) Expand all Loading... |
655 | 653 |
656 // Note abc and abc_again are not required to have equal identity hashes. | 654 // Note abc and abc_again are not required to have equal identity hashes. |
657 | 655 |
658 // Case where identical() is not the same as pointer equality. | 656 // Case where identical() is not the same as pointer equality. |
659 Dart_Handle nan1 = Dart_NewDouble(NAN); | 657 Dart_Handle nan1 = Dart_NewDouble(NAN); |
660 Dart_Handle nan2 = Dart_NewDouble(NAN); | 658 Dart_Handle nan2 = Dart_NewDouble(NAN); |
661 EXPECT_EQ(Dart_IdentityHash(nan1), Dart_IdentityHash(nan2)); | 659 EXPECT_EQ(Dart_IdentityHash(nan1), Dart_IdentityHash(nan2)); |
662 | 660 |
663 // Non-instance objects. | 661 // Non-instance objects. |
664 { | 662 { |
665 DARTSCOPE(Thread::Current()); | 663 DARTSCOPE(thread); |
666 Dart_Handle lib1 = Dart_LookupLibrary(dart_core); | 664 Dart_Handle lib1 = Dart_LookupLibrary(dart_core); |
667 Dart_Handle lib2 = Dart_LookupLibrary(dart_mirrors); | 665 Dart_Handle lib2 = Dart_LookupLibrary(dart_mirrors); |
668 | 666 |
669 EXPECT_EQ(Dart_IdentityHash(lib1), Dart_IdentityHash(lib1)); | 667 EXPECT_EQ(Dart_IdentityHash(lib1), Dart_IdentityHash(lib1)); |
670 EXPECT_EQ(Dart_IdentityHash(lib2), Dart_IdentityHash(lib2)); | 668 EXPECT_EQ(Dart_IdentityHash(lib2), Dart_IdentityHash(lib2)); |
671 } | 669 } |
672 } | 670 } |
673 | 671 |
674 | 672 |
675 TEST_CASE(ObjectEquals) { | 673 TEST_CASE(ObjectEquals) { |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1219 NULL); | 1217 NULL); |
1220 EXPECT_VALID(small8); | 1218 EXPECT_VALID(small8); |
1221 static const uint16_t small_data16[] = {'b', 'a', 'r'}; | 1219 static const uint16_t small_data16[] = {'b', 'a', 'r'}; |
1222 Dart_Handle small16 = Dart_NewExternalUTF16String( | 1220 Dart_Handle small16 = Dart_NewExternalUTF16String( |
1223 small_data16, | 1221 small_data16, |
1224 ARRAY_SIZE(small_data16), | 1222 ARRAY_SIZE(small_data16), |
1225 NULL, | 1223 NULL, |
1226 NULL); | 1224 NULL); |
1227 EXPECT_VALID(small16); | 1225 EXPECT_VALID(small16); |
1228 { | 1226 { |
1229 DARTSCOPE(Thread::Current()); | 1227 DARTSCOPE(thread); |
1230 String& handle = String::Handle(); | 1228 String& handle = String::Handle(); |
1231 handle ^= Api::UnwrapHandle(big8); | 1229 handle ^= Api::UnwrapHandle(big8); |
1232 EXPECT(handle.IsOld()); | 1230 EXPECT(handle.IsOld()); |
1233 handle ^= Api::UnwrapHandle(big16); | 1231 handle ^= Api::UnwrapHandle(big16); |
1234 EXPECT(handle.IsOld()); | 1232 EXPECT(handle.IsOld()); |
1235 handle ^= Api::UnwrapHandle(small8); | 1233 handle ^= Api::UnwrapHandle(small8); |
1236 EXPECT(handle.IsNew()); | 1234 EXPECT(handle.IsNew()); |
1237 handle ^= Api::UnwrapHandle(small16); | 1235 handle ^= Api::UnwrapHandle(small16); |
1238 EXPECT(handle.IsNew()); | 1236 EXPECT(handle.IsNew()); |
1239 } | 1237 } |
(...skipping 13 matching lines...) Expand all Loading... |
1253 kBigLength); | 1251 kBigLength); |
1254 EXPECT_VALID(big); | 1252 EXPECT_VALID(big); |
1255 static const int kSmallLength = 16*KB/8; | 1253 static const int kSmallLength = 16*KB/8; |
1256 int64_t* small_data = new int64_t[kSmallLength](); | 1254 int64_t* small_data = new int64_t[kSmallLength](); |
1257 Dart_Handle small = Dart_NewExternalTypedData( | 1255 Dart_Handle small = Dart_NewExternalTypedData( |
1258 Dart_TypedData_kInt64, | 1256 Dart_TypedData_kInt64, |
1259 small_data, | 1257 small_data, |
1260 kSmallLength); | 1258 kSmallLength); |
1261 EXPECT_VALID(small); | 1259 EXPECT_VALID(small); |
1262 { | 1260 { |
1263 DARTSCOPE(Thread::Current()); | 1261 DARTSCOPE(thread); |
1264 ExternalTypedData& handle = ExternalTypedData::Handle(); | 1262 ExternalTypedData& handle = ExternalTypedData::Handle(); |
1265 handle ^= Api::UnwrapHandle(big); | 1263 handle ^= Api::UnwrapHandle(big); |
1266 EXPECT(handle.IsOld()); | 1264 EXPECT(handle.IsOld()); |
1267 handle ^= Api::UnwrapHandle(small); | 1265 handle ^= Api::UnwrapHandle(small); |
1268 EXPECT(handle.IsNew()); | 1266 EXPECT(handle.IsNew()); |
1269 } | 1267 } |
1270 Dart_ExitScope(); | 1268 Dart_ExitScope(); |
1271 delete[] big_data; | 1269 delete[] big_data; |
1272 delete[] small_data; | 1270 delete[] small_data; |
1273 } | 1271 } |
(...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2372 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 2370 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); |
2373 EXPECT(peer == 42); | 2371 EXPECT(peer == 42); |
2374 } | 2372 } |
2375 | 2373 |
2376 | 2374 |
2377 // Unit test for entering a scope, creating a local handle and exiting | 2375 // Unit test for entering a scope, creating a local handle and exiting |
2378 // the scope. | 2376 // the scope. |
2379 UNIT_TEST_CASE(EnterExitScope) { | 2377 UNIT_TEST_CASE(EnterExitScope) { |
2380 TestIsolateScope __test_isolate__; | 2378 TestIsolateScope __test_isolate__; |
2381 | 2379 |
2382 Isolate* isolate = Isolate::Current(); | 2380 Thread* thread = Thread::Current(); |
2383 EXPECT(isolate != NULL); | 2381 EXPECT(thread != NULL); |
2384 ApiState* state = isolate->api_state(); | 2382 ApiLocalScope* scope = thread->api_top_scope(); |
2385 EXPECT(state != NULL); | |
2386 ApiLocalScope* scope = state->top_scope(); | |
2387 Dart_EnterScope(); | 2383 Dart_EnterScope(); |
2388 { | 2384 { |
2389 EXPECT(state->top_scope() != NULL); | 2385 EXPECT(thread->api_top_scope() != NULL); |
2390 DARTSCOPE(Thread::Current()); | 2386 DARTSCOPE(Thread::Current()); |
2391 const String& str1 = String::Handle(String::New("Test String")); | 2387 const String& str1 = String::Handle(String::New("Test String")); |
2392 Dart_Handle ref = Api::NewHandle(isolate, str1.raw()); | 2388 Dart_Handle ref = Api::NewHandle(thread, str1.raw()); |
2393 String& str2 = String::Handle(); | 2389 String& str2 = String::Handle(); |
2394 str2 ^= Api::UnwrapHandle(ref); | 2390 str2 ^= Api::UnwrapHandle(ref); |
2395 EXPECT(str1.Equals(str2)); | 2391 EXPECT(str1.Equals(str2)); |
2396 } | 2392 } |
2397 Dart_ExitScope(); | 2393 Dart_ExitScope(); |
2398 EXPECT(scope == state->top_scope()); | 2394 EXPECT(scope == thread->api_top_scope()); |
2399 } | 2395 } |
2400 | 2396 |
2401 | 2397 |
2402 // Unit test for creating and deleting persistent handles. | 2398 // Unit test for creating and deleting persistent handles. |
2403 UNIT_TEST_CASE(PersistentHandles) { | 2399 UNIT_TEST_CASE(PersistentHandles) { |
2404 const char* kTestString1 = "Test String1"; | 2400 const char* kTestString1 = "Test String1"; |
2405 const char* kTestString2 = "Test String2"; | 2401 const char* kTestString2 = "Test String2"; |
2406 TestCase::CreateTestIsolate(); | 2402 TestCase::CreateTestIsolate(); |
2407 Thread* thread = Thread::Current(); | 2403 Thread* thread = Thread::Current(); |
2408 Isolate* isolate = thread->isolate(); | 2404 Isolate* isolate = thread->isolate(); |
2409 EXPECT(isolate != NULL); | 2405 EXPECT(isolate != NULL); |
2410 ApiState* state = isolate->api_state(); | 2406 ApiState* state = isolate->api_state(); |
2411 EXPECT(state != NULL); | 2407 EXPECT(state != NULL); |
2412 ApiLocalScope* scope = state->top_scope(); | 2408 ApiLocalScope* scope = thread->api_top_scope(); |
2413 Dart_PersistentHandle handles[2000]; | 2409 Dart_PersistentHandle handles[2000]; |
2414 Dart_EnterScope(); | 2410 Dart_EnterScope(); |
2415 { | 2411 { |
2416 DARTSCOPE(Thread::Current()); | 2412 DARTSCOPE(Thread::Current()); |
2417 Dart_Handle ref1 = Api::NewHandle(isolate, String::New(kTestString1)); | 2413 Dart_Handle ref1 = Api::NewHandle(thread, String::New(kTestString1)); |
2418 for (int i = 0; i < 1000; i++) { | 2414 for (int i = 0; i < 1000; i++) { |
2419 handles[i] = Dart_NewPersistentHandle(ref1); | 2415 handles[i] = Dart_NewPersistentHandle(ref1); |
2420 } | 2416 } |
2421 Dart_EnterScope(); | 2417 Dart_EnterScope(); |
2422 Dart_Handle ref2 = Api::NewHandle(isolate, String::New(kTestString2)); | 2418 Dart_Handle ref2 = Api::NewHandle(thread, String::New(kTestString2)); |
2423 for (int i = 1000; i < 2000; i++) { | 2419 for (int i = 1000; i < 2000; i++) { |
2424 handles[i] = Dart_NewPersistentHandle(ref2); | 2420 handles[i] = Dart_NewPersistentHandle(ref2); |
2425 } | 2421 } |
2426 for (int i = 500; i < 1500; i++) { | 2422 for (int i = 500; i < 1500; i++) { |
2427 Dart_DeletePersistentHandle(handles[i]); | 2423 Dart_DeletePersistentHandle(handles[i]); |
2428 } | 2424 } |
2429 for (int i = 500; i < 1000; i++) { | 2425 for (int i = 500; i < 1000; i++) { |
2430 handles[i] = Dart_NewPersistentHandle(ref2); | 2426 handles[i] = Dart_NewPersistentHandle(ref2); |
2431 } | 2427 } |
2432 for (int i = 1000; i < 1500; i++) { | 2428 for (int i = 1000; i < 1500; i++) { |
(...skipping 20 matching lines...) Expand all Loading... |
2453 String& str = String::Handle(); | 2449 String& str = String::Handle(); |
2454 str ^= PersistentHandle::Cast(handles[i])->raw(); | 2450 str ^= PersistentHandle::Cast(handles[i])->raw(); |
2455 EXPECT(str.Equals(kTestString1)); | 2451 EXPECT(str.Equals(kTestString1)); |
2456 } | 2452 } |
2457 for (int i = 1500; i < 2000; i++) { | 2453 for (int i = 1500; i < 2000; i++) { |
2458 String& str = String::Handle(); | 2454 String& str = String::Handle(); |
2459 str ^= PersistentHandle::Cast(handles[i])->raw(); | 2455 str ^= PersistentHandle::Cast(handles[i])->raw(); |
2460 EXPECT(str.Equals(kTestString2)); | 2456 EXPECT(str.Equals(kTestString2)); |
2461 } | 2457 } |
2462 } | 2458 } |
2463 EXPECT(scope == state->top_scope()); | 2459 EXPECT(scope == thread->api_top_scope()); |
2464 EXPECT_EQ(2001, state->CountPersistentHandles()); | 2460 EXPECT_EQ(2001, state->CountPersistentHandles()); |
2465 Dart_ShutdownIsolate(); | 2461 Dart_ShutdownIsolate(); |
2466 } | 2462 } |
2467 | 2463 |
2468 | 2464 |
2469 // Test that we are able to create a persistent handle from a | 2465 // Test that we are able to create a persistent handle from a |
2470 // persistent handle. | 2466 // persistent handle. |
2471 UNIT_TEST_CASE(NewPersistentHandle_FromPersistentHandle) { | 2467 UNIT_TEST_CASE(NewPersistentHandle_FromPersistentHandle) { |
2472 TestIsolateScope __test_isolate__; | 2468 TestIsolateScope __test_isolate__; |
2473 | 2469 |
(...skipping 21 matching lines...) Expand all Loading... |
2495 EXPECT(value); | 2491 EXPECT(value); |
2496 } | 2492 } |
2497 | 2493 |
2498 | 2494 |
2499 // Test that we can assign to a persistent handle. | 2495 // Test that we can assign to a persistent handle. |
2500 UNIT_TEST_CASE(AssignToPersistentHandle) { | 2496 UNIT_TEST_CASE(AssignToPersistentHandle) { |
2501 const char* kTestString1 = "Test String1"; | 2497 const char* kTestString1 = "Test String1"; |
2502 const char* kTestString2 = "Test String2"; | 2498 const char* kTestString2 = "Test String2"; |
2503 TestIsolateScope __test_isolate__; | 2499 TestIsolateScope __test_isolate__; |
2504 | 2500 |
2505 Isolate* isolate = Isolate::Current(); | 2501 DARTSCOPE(Thread::Current()); |
| 2502 Isolate* isolate = T->isolate(); |
2506 EXPECT(isolate != NULL); | 2503 EXPECT(isolate != NULL); |
2507 ApiState* state = isolate->api_state(); | 2504 ApiState* state = isolate->api_state(); |
2508 EXPECT(state != NULL); | 2505 EXPECT(state != NULL); |
2509 DARTSCOPE(Thread::Current()); | |
2510 String& str = String::Handle(); | 2506 String& str = String::Handle(); |
2511 | 2507 |
2512 // Start with a known persistent handle. | 2508 // Start with a known persistent handle. |
2513 Dart_Handle ref1 = Api::NewHandle(isolate, String::New(kTestString1)); | 2509 Dart_Handle ref1 = Api::NewHandle(T, String::New(kTestString1)); |
2514 Dart_PersistentHandle obj = Dart_NewPersistentHandle(ref1); | 2510 Dart_PersistentHandle obj = Dart_NewPersistentHandle(ref1); |
2515 EXPECT(state->IsValidPersistentHandle(obj)); | 2511 EXPECT(state->IsValidPersistentHandle(obj)); |
2516 str ^= PersistentHandle::Cast(obj)->raw(); | 2512 str ^= PersistentHandle::Cast(obj)->raw(); |
2517 EXPECT(str.Equals(kTestString1)); | 2513 EXPECT(str.Equals(kTestString1)); |
2518 | 2514 |
2519 // Now create another local handle and assign it to the persistent handle. | 2515 // Now create another local handle and assign it to the persistent handle. |
2520 Dart_Handle ref2 = Api::NewHandle(isolate, String::New(kTestString2)); | 2516 Dart_Handle ref2 = Api::NewHandle(T, String::New(kTestString2)); |
2521 Dart_SetPersistentHandle(obj, ref2); | 2517 Dart_SetPersistentHandle(obj, ref2); |
2522 str ^= PersistentHandle::Cast(obj)->raw(); | 2518 str ^= PersistentHandle::Cast(obj)->raw(); |
2523 EXPECT(str.Equals(kTestString2)); | 2519 EXPECT(str.Equals(kTestString2)); |
2524 | 2520 |
2525 // Now assign Null to the persistent handle and check. | 2521 // Now assign Null to the persistent handle and check. |
2526 Dart_SetPersistentHandle(obj, Dart_Null()); | 2522 Dart_SetPersistentHandle(obj, Dart_Null()); |
2527 EXPECT(Dart_IsNull(obj)); | 2523 EXPECT(Dart_IsNull(obj)); |
2528 } | 2524 } |
2529 | 2525 |
2530 | 2526 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2578 { | 2574 { |
2579 Dart_EnterScope(); | 2575 Dart_EnterScope(); |
2580 | 2576 |
2581 // Create an object in new space. | 2577 // Create an object in new space. |
2582 Dart_Handle new_ref = NewString("new string"); | 2578 Dart_Handle new_ref = NewString("new string"); |
2583 EXPECT_VALID(new_ref); | 2579 EXPECT_VALID(new_ref); |
2584 | 2580 |
2585 // Create an object in old space. | 2581 // Create an object in old space. |
2586 Dart_Handle old_ref; | 2582 Dart_Handle old_ref; |
2587 { | 2583 { |
2588 Isolate* isolate = Isolate::Current(); | |
2589 DARTSCOPE(Thread::Current()); | 2584 DARTSCOPE(Thread::Current()); |
2590 old_ref = Api::NewHandle(isolate, String::New("old string", Heap::kOld)); | 2585 old_ref = Api::NewHandle(thread, String::New("old string", Heap::kOld)); |
2591 EXPECT_VALID(old_ref); | 2586 EXPECT_VALID(old_ref); |
2592 } | 2587 } |
2593 | 2588 |
2594 // Create a weak ref to the new space object. | 2589 // Create a weak ref to the new space object. |
2595 weak_new_ref = Dart_NewWeakPersistentHandle(new_ref, | 2590 weak_new_ref = Dart_NewWeakPersistentHandle(new_ref, |
2596 NULL, | 2591 NULL, |
2597 0, | 2592 0, |
2598 WeakPersistentHandleCallback); | 2593 WeakPersistentHandleCallback); |
2599 EXPECT_VALID(AsHandle(weak_new_ref)); | 2594 EXPECT_VALID(AsHandle(weak_new_ref)); |
2600 EXPECT(!Dart_IsNull(AsHandle(weak_new_ref))); | 2595 EXPECT(!Dart_IsNull(AsHandle(weak_new_ref))); |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2825 Dart_DeleteWeakPersistentHandle(isolate, weak1); | 2820 Dart_DeleteWeakPersistentHandle(isolate, weak1); |
2826 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2821 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
2827 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); | 2822 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); |
2828 } | 2823 } |
2829 | 2824 |
2830 | 2825 |
2831 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOldspaceGC) { | 2826 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOldspaceGC) { |
2832 // Check that external allocation in old space can trigger GC. | 2827 // Check that external allocation in old space can trigger GC. |
2833 Isolate* isolate = Isolate::Current(); | 2828 Isolate* isolate = Isolate::Current(); |
2834 Dart_EnterScope(); | 2829 Dart_EnterScope(); |
2835 Dart_Handle live = Api::NewHandle(isolate, String::New("live", Heap::kOld)); | 2830 Dart_Handle live = Api::NewHandle(thread, String::New("live", Heap::kOld)); |
2836 EXPECT_VALID(live); | 2831 EXPECT_VALID(live); |
2837 Dart_WeakPersistentHandle weak = NULL; | 2832 Dart_WeakPersistentHandle weak = NULL; |
2838 EXPECT_EQ(0, isolate->heap()->ExternalInWords(Heap::kOld)); | 2833 EXPECT_EQ(0, isolate->heap()->ExternalInWords(Heap::kOld)); |
2839 const intptr_t kSmallExternalSize = 1 * KB; | 2834 const intptr_t kSmallExternalSize = 1 * KB; |
2840 { | 2835 { |
2841 Dart_EnterScope(); | 2836 Dart_EnterScope(); |
2842 Dart_Handle dead = Api::NewHandle(isolate, String::New("dead", Heap::kOld)); | 2837 Dart_Handle dead = Api::NewHandle(thread, String::New("dead", Heap::kOld)); |
2843 EXPECT_VALID(dead); | 2838 EXPECT_VALID(dead); |
2844 weak = Dart_NewWeakPersistentHandle(dead, | 2839 weak = Dart_NewWeakPersistentHandle(dead, |
2845 NULL, | 2840 NULL, |
2846 kSmallExternalSize, | 2841 kSmallExternalSize, |
2847 NopCallback); | 2842 NopCallback); |
2848 EXPECT_VALID(AsHandle(weak)); | 2843 EXPECT_VALID(AsHandle(weak)); |
2849 Dart_ExitScope(); | 2844 Dart_ExitScope(); |
2850 } | 2845 } |
2851 EXPECT_EQ(kSmallExternalSize, | 2846 EXPECT_EQ(kSmallExternalSize, |
2852 isolate->heap()->ExternalInWords(Heap::kOld) * kWordSize); | 2847 isolate->heap()->ExternalInWords(Heap::kOld) * kWordSize); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2913 } | 2908 } |
2914 } | 2909 } |
2915 | 2910 |
2916 | 2911 |
2917 TEST_CASE(ImplicitReferencesOldSpace) { | 2912 TEST_CASE(ImplicitReferencesOldSpace) { |
2918 Dart_PersistentHandle strong = NULL; | 2913 Dart_PersistentHandle strong = NULL; |
2919 Dart_WeakPersistentHandle strong_weak = NULL; | 2914 Dart_WeakPersistentHandle strong_weak = NULL; |
2920 | 2915 |
2921 Dart_EnterScope(); | 2916 Dart_EnterScope(); |
2922 { | 2917 { |
2923 Isolate* isolate = Isolate::Current(); | |
2924 DARTSCOPE(Thread::Current()); | 2918 DARTSCOPE(Thread::Current()); |
2925 | 2919 |
2926 Dart_Handle local = Api::NewHandle( | 2920 Dart_Handle local = Api::NewHandle( |
2927 isolate, String::New("strongly reachable", Heap::kOld)); | 2921 thread, String::New("strongly reachable", Heap::kOld)); |
2928 strong = Dart_NewPersistentHandle(local); | 2922 strong = Dart_NewPersistentHandle(local); |
2929 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, 0, NopCallback); | 2923 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, 0, NopCallback); |
2930 | 2924 |
2931 EXPECT(!Dart_IsNull(AsHandle(strong))); | 2925 EXPECT(!Dart_IsNull(AsHandle(strong))); |
2932 EXPECT_VALID(AsHandle(strong)); | 2926 EXPECT_VALID(AsHandle(strong)); |
2933 EXPECT(!Dart_IsNull(AsHandle(strong_weak))); | 2927 EXPECT(!Dart_IsNull(AsHandle(strong_weak))); |
2934 EXPECT_VALID(AsHandle(strong_weak)); | 2928 EXPECT_VALID(AsHandle(strong_weak)); |
2935 EXPECT(Dart_IdentityEquals(AsHandle(strong), AsHandle(strong_weak))) | 2929 EXPECT(Dart_IdentityEquals(AsHandle(strong), AsHandle(strong_weak))) |
2936 | 2930 |
2937 weak1 = Dart_NewWeakPersistentHandle( | 2931 weak1 = Dart_NewWeakPersistentHandle( |
2938 Api::NewHandle(isolate, String::New("weakly reachable 1", Heap::kOld)), | 2932 Api::NewHandle(thread, String::New("weakly reachable 1", Heap::kOld)), |
2939 NULL, 0, ImplicitReferencesCallback); | 2933 NULL, 0, ImplicitReferencesCallback); |
2940 EXPECT(!Dart_IsNull(AsHandle(weak1))); | 2934 EXPECT(!Dart_IsNull(AsHandle(weak1))); |
2941 EXPECT_VALID(AsHandle(weak1)); | 2935 EXPECT_VALID(AsHandle(weak1)); |
2942 | 2936 |
2943 weak2 = Dart_NewWeakPersistentHandle( | 2937 weak2 = Dart_NewWeakPersistentHandle( |
2944 Api::NewHandle(isolate, String::New("weakly reachable 2", Heap::kOld)), | 2938 Api::NewHandle(thread, String::New("weakly reachable 2", Heap::kOld)), |
2945 NULL, 0, ImplicitReferencesCallback); | 2939 NULL, 0, ImplicitReferencesCallback); |
2946 EXPECT(!Dart_IsNull(AsHandle(weak2))); | 2940 EXPECT(!Dart_IsNull(AsHandle(weak2))); |
2947 EXPECT_VALID(AsHandle(weak2)); | 2941 EXPECT_VALID(AsHandle(weak2)); |
2948 | 2942 |
2949 weak3 = Dart_NewWeakPersistentHandle( | 2943 weak3 = Dart_NewWeakPersistentHandle( |
2950 Api::NewHandle(isolate, String::New("weakly reachable 3", Heap::kOld)), | 2944 Api::NewHandle(thread, String::New("weakly reachable 3", Heap::kOld)), |
2951 NULL, 0, ImplicitReferencesCallback); | 2945 NULL, 0, ImplicitReferencesCallback); |
2952 EXPECT(!Dart_IsNull(AsHandle(weak3))); | 2946 EXPECT(!Dart_IsNull(AsHandle(weak3))); |
2953 EXPECT_VALID(AsHandle(weak3)); | 2947 EXPECT_VALID(AsHandle(weak3)); |
2954 } | 2948 } |
2955 Dart_ExitScope(); | 2949 Dart_ExitScope(); |
2956 | 2950 |
2957 { | 2951 { |
2958 Dart_EnterScope(); | 2952 Dart_EnterScope(); |
2959 EXPECT_VALID(AsHandle(strong_weak)); | 2953 EXPECT_VALID(AsHandle(strong_weak)); |
2960 EXPECT_VALID(AsHandle(weak1)); | 2954 EXPECT_VALID(AsHandle(weak1)); |
(...skipping 16 matching lines...) Expand all Loading... |
2977 } | 2971 } |
2978 | 2972 |
2979 | 2973 |
2980 TEST_CASE(ImplicitReferencesNewSpace) { | 2974 TEST_CASE(ImplicitReferencesNewSpace) { |
2981 Dart_PersistentHandle strong = NULL; | 2975 Dart_PersistentHandle strong = NULL; |
2982 Dart_WeakPersistentHandle strong_weak = NULL; | 2976 Dart_WeakPersistentHandle strong_weak = NULL; |
2983 | 2977 |
2984 | 2978 |
2985 Dart_EnterScope(); | 2979 Dart_EnterScope(); |
2986 { | 2980 { |
2987 Isolate* isolate = Isolate::Current(); | |
2988 DARTSCOPE(Thread::Current()); | 2981 DARTSCOPE(Thread::Current()); |
2989 | 2982 |
2990 Dart_Handle local = Api::NewHandle( | 2983 Dart_Handle local = Api::NewHandle( |
2991 isolate, String::New("strongly reachable", Heap::kOld)); | 2984 thread, String::New("strongly reachable", Heap::kOld)); |
2992 strong = Dart_NewPersistentHandle(local); | 2985 strong = Dart_NewPersistentHandle(local); |
2993 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, 0, NopCallback); | 2986 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, 0, NopCallback); |
2994 | 2987 |
2995 EXPECT(!Dart_IsNull(AsHandle(strong))); | 2988 EXPECT(!Dart_IsNull(AsHandle(strong))); |
2996 EXPECT_VALID(AsHandle(strong)); | 2989 EXPECT_VALID(AsHandle(strong)); |
2997 EXPECT(!Dart_IsNull(AsHandle(strong_weak))); | 2990 EXPECT(!Dart_IsNull(AsHandle(strong_weak))); |
2998 EXPECT_VALID(AsHandle(strong_weak)); | 2991 EXPECT_VALID(AsHandle(strong_weak)); |
2999 EXPECT(Dart_IdentityEquals(AsHandle(strong), AsHandle(strong_weak))) | 2992 EXPECT(Dart_IdentityEquals(AsHandle(strong), AsHandle(strong_weak))) |
3000 | 2993 |
3001 weak1 = Dart_NewWeakPersistentHandle( | 2994 weak1 = Dart_NewWeakPersistentHandle( |
3002 Api::NewHandle(isolate, String::New("weakly reachable 1", Heap::kNew)), | 2995 Api::NewHandle(thread, String::New("weakly reachable 1", Heap::kNew)), |
3003 NULL, 0, ImplicitReferencesCallback); | 2996 NULL, 0, ImplicitReferencesCallback); |
3004 EXPECT(!Dart_IsNull(AsHandle(weak1))); | 2997 EXPECT(!Dart_IsNull(AsHandle(weak1))); |
3005 EXPECT_VALID(AsHandle(weak1)); | 2998 EXPECT_VALID(AsHandle(weak1)); |
3006 | 2999 |
3007 weak2 = Dart_NewWeakPersistentHandle( | 3000 weak2 = Dart_NewWeakPersistentHandle( |
3008 Api::NewHandle(isolate, String::New("weakly reachable 2", Heap::kNew)), | 3001 Api::NewHandle(thread, String::New("weakly reachable 2", Heap::kNew)), |
3009 NULL, 0, ImplicitReferencesCallback); | 3002 NULL, 0, ImplicitReferencesCallback); |
3010 EXPECT(!Dart_IsNull(AsHandle(weak2))); | 3003 EXPECT(!Dart_IsNull(AsHandle(weak2))); |
3011 EXPECT_VALID(AsHandle(weak2)); | 3004 EXPECT_VALID(AsHandle(weak2)); |
3012 | 3005 |
3013 weak3 = Dart_NewWeakPersistentHandle( | 3006 weak3 = Dart_NewWeakPersistentHandle( |
3014 Api::NewHandle(isolate, String::New("weakly reachable 3", Heap::kNew)), | 3007 Api::NewHandle(thread, String::New("weakly reachable 3", Heap::kNew)), |
3015 NULL, 0, ImplicitReferencesCallback); | 3008 NULL, 0, ImplicitReferencesCallback); |
3016 EXPECT(!Dart_IsNull(AsHandle(weak3))); | 3009 EXPECT(!Dart_IsNull(AsHandle(weak3))); |
3017 EXPECT_VALID(AsHandle(weak3)); | 3010 EXPECT_VALID(AsHandle(weak3)); |
3018 } | 3011 } |
3019 Dart_ExitScope(); | 3012 Dart_ExitScope(); |
3020 | 3013 |
3021 { | 3014 { |
3022 Dart_EnterScope(); | 3015 Dart_EnterScope(); |
3023 EXPECT_VALID(AsHandle(strong_weak)); | 3016 EXPECT_VALID(AsHandle(strong_weak)); |
3024 EXPECT_VALID(AsHandle(weak1)); | 3017 EXPECT_VALID(AsHandle(weak1)); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3202 | 3195 |
3203 | 3196 |
3204 // Unit test for creating multiple scopes and local handles within them. | 3197 // Unit test for creating multiple scopes and local handles within them. |
3205 // Ensure that the local handles get all cleaned out when exiting the | 3198 // Ensure that the local handles get all cleaned out when exiting the |
3206 // scope. | 3199 // scope. |
3207 UNIT_TEST_CASE(LocalHandles) { | 3200 UNIT_TEST_CASE(LocalHandles) { |
3208 TestCase::CreateTestIsolate(); | 3201 TestCase::CreateTestIsolate(); |
3209 Thread* thread = Thread::Current(); | 3202 Thread* thread = Thread::Current(); |
3210 Isolate* isolate = thread->isolate(); | 3203 Isolate* isolate = thread->isolate(); |
3211 EXPECT(isolate != NULL); | 3204 EXPECT(isolate != NULL); |
3212 ApiState* state = isolate->api_state(); | 3205 ApiLocalScope* scope = thread->api_top_scope(); |
3213 EXPECT(state != NULL); | |
3214 ApiLocalScope* scope = state->top_scope(); | |
3215 Dart_Handle handles[300]; | 3206 Dart_Handle handles[300]; |
3216 { | 3207 { |
3217 StackZone zone(thread); | 3208 StackZone zone(thread); |
3218 HANDLESCOPE(thread); | 3209 HANDLESCOPE(thread); |
3219 Smi& val = Smi::Handle(); | 3210 Smi& val = Smi::Handle(); |
3220 | 3211 |
3221 // Start a new scope and allocate some local handles. | 3212 // Start a new scope and allocate some local handles. |
3222 Dart_EnterScope(); | 3213 Dart_EnterScope(); |
3223 for (int i = 0; i < 100; i++) { | 3214 for (int i = 0; i < 100; i++) { |
3224 handles[i] = Api::NewHandle(isolate, Smi::New(i)); | 3215 handles[i] = Api::NewHandle(thread, Smi::New(i)); |
3225 } | 3216 } |
3226 EXPECT_EQ(100, state->CountLocalHandles()); | 3217 EXPECT_EQ(100, thread->CountLocalHandles()); |
3227 for (int i = 0; i < 100; i++) { | 3218 for (int i = 0; i < 100; i++) { |
3228 val ^= Api::UnwrapHandle(handles[i]); | 3219 val ^= Api::UnwrapHandle(handles[i]); |
3229 EXPECT_EQ(i, val.Value()); | 3220 EXPECT_EQ(i, val.Value()); |
3230 } | 3221 } |
3231 // Start another scope and allocate some more local handles. | 3222 // Start another scope and allocate some more local handles. |
3232 { | 3223 { |
3233 Dart_EnterScope(); | 3224 Dart_EnterScope(); |
3234 for (int i = 100; i < 200; i++) { | 3225 for (int i = 100; i < 200; i++) { |
3235 handles[i] = Api::NewHandle(isolate, Smi::New(i)); | 3226 handles[i] = Api::NewHandle(thread, Smi::New(i)); |
3236 } | 3227 } |
3237 EXPECT_EQ(200, state->CountLocalHandles()); | 3228 EXPECT_EQ(200, thread->CountLocalHandles()); |
3238 for (int i = 100; i < 200; i++) { | 3229 for (int i = 100; i < 200; i++) { |
3239 val ^= Api::UnwrapHandle(handles[i]); | 3230 val ^= Api::UnwrapHandle(handles[i]); |
3240 EXPECT_EQ(i, val.Value()); | 3231 EXPECT_EQ(i, val.Value()); |
3241 } | 3232 } |
3242 | 3233 |
3243 // Start another scope and allocate some more local handles. | 3234 // Start another scope and allocate some more local handles. |
3244 { | 3235 { |
3245 Dart_EnterScope(); | 3236 Dart_EnterScope(); |
3246 for (int i = 200; i < 300; i++) { | 3237 for (int i = 200; i < 300; i++) { |
3247 handles[i] = Api::NewHandle(isolate, Smi::New(i)); | 3238 handles[i] = Api::NewHandle(thread, Smi::New(i)); |
3248 } | 3239 } |
3249 EXPECT_EQ(300, state->CountLocalHandles()); | 3240 EXPECT_EQ(300, thread->CountLocalHandles()); |
3250 for (int i = 200; i < 300; i++) { | 3241 for (int i = 200; i < 300; i++) { |
3251 val ^= Api::UnwrapHandle(handles[i]); | 3242 val ^= Api::UnwrapHandle(handles[i]); |
3252 EXPECT_EQ(i, val.Value()); | 3243 EXPECT_EQ(i, val.Value()); |
3253 } | 3244 } |
3254 EXPECT_EQ(300, state->CountLocalHandles()); | 3245 EXPECT_EQ(300, thread->CountLocalHandles()); |
3255 VERIFY_ON_TRANSITION; | 3246 VERIFY_ON_TRANSITION; |
3256 Dart_ExitScope(); | 3247 Dart_ExitScope(); |
3257 } | 3248 } |
3258 EXPECT_EQ(200, state->CountLocalHandles()); | 3249 EXPECT_EQ(200, thread->CountLocalHandles()); |
3259 Dart_ExitScope(); | 3250 Dart_ExitScope(); |
3260 } | 3251 } |
3261 EXPECT_EQ(100, state->CountLocalHandles()); | 3252 EXPECT_EQ(100, thread->CountLocalHandles()); |
3262 Dart_ExitScope(); | 3253 Dart_ExitScope(); |
3263 } | 3254 } |
3264 EXPECT_EQ(0, state->CountLocalHandles()); | 3255 EXPECT_EQ(0, thread->CountLocalHandles()); |
3265 EXPECT(scope == state->top_scope()); | 3256 EXPECT(scope == thread->api_top_scope()); |
3266 Dart_ShutdownIsolate(); | 3257 Dart_ShutdownIsolate(); |
3267 } | 3258 } |
3268 | 3259 |
3269 | 3260 |
3270 // Unit test for creating multiple scopes and allocating objects in the | 3261 // Unit test for creating multiple scopes and allocating objects in the |
3271 // zone for the scope. Ensure that the memory is freed when the scope | 3262 // zone for the scope. Ensure that the memory is freed when the scope |
3272 // exits. | 3263 // exits. |
3273 UNIT_TEST_CASE(LocalZoneMemory) { | 3264 UNIT_TEST_CASE(LocalZoneMemory) { |
3274 TestCase::CreateTestIsolate(); | 3265 TestCase::CreateTestIsolate(); |
3275 Isolate* isolate = Isolate::Current(); | 3266 Thread* thread = Thread::Current(); |
3276 EXPECT(isolate != NULL); | 3267 EXPECT(thread != NULL); |
3277 ApiState* state = isolate->api_state(); | 3268 ApiLocalScope* scope = thread->api_top_scope(); |
3278 EXPECT(state != NULL); | |
3279 ApiLocalScope* scope = state->top_scope(); | |
3280 { | 3269 { |
3281 // Start a new scope and allocate some memory. | 3270 // Start a new scope and allocate some memory. |
3282 Dart_EnterScope(); | 3271 Dart_EnterScope(); |
3283 for (int i = 0; i < 100; i++) { | 3272 for (int i = 0; i < 100; i++) { |
3284 Dart_ScopeAllocate(16); | 3273 Dart_ScopeAllocate(16); |
3285 } | 3274 } |
3286 EXPECT_EQ(1600, state->ZoneSizeInBytes()); | 3275 EXPECT_EQ(1600, thread->ZoneSizeInBytes()); |
3287 // Start another scope and allocate some more memory. | 3276 // Start another scope and allocate some more memory. |
3288 { | 3277 { |
3289 Dart_EnterScope(); | 3278 Dart_EnterScope(); |
3290 for (int i = 0; i < 100; i++) { | 3279 for (int i = 0; i < 100; i++) { |
3291 Dart_ScopeAllocate(16); | 3280 Dart_ScopeAllocate(16); |
3292 } | 3281 } |
3293 EXPECT_EQ(3200, state->ZoneSizeInBytes()); | 3282 EXPECT_EQ(3200, thread->ZoneSizeInBytes()); |
3294 { | 3283 { |
3295 // Start another scope and allocate some more memory. | 3284 // Start another scope and allocate some more memory. |
3296 { | 3285 { |
3297 Dart_EnterScope(); | 3286 Dart_EnterScope(); |
3298 for (int i = 0; i < 200; i++) { | 3287 for (int i = 0; i < 200; i++) { |
3299 Dart_ScopeAllocate(16); | 3288 Dart_ScopeAllocate(16); |
3300 } | 3289 } |
3301 EXPECT_EQ(6400, state->ZoneSizeInBytes()); | 3290 EXPECT_EQ(6400, thread->ZoneSizeInBytes()); |
3302 Dart_ExitScope(); | 3291 Dart_ExitScope(); |
3303 } | 3292 } |
3304 } | 3293 } |
3305 EXPECT_EQ(3200, state->ZoneSizeInBytes()); | 3294 EXPECT_EQ(3200, thread->ZoneSizeInBytes()); |
3306 Dart_ExitScope(); | 3295 Dart_ExitScope(); |
3307 } | 3296 } |
3308 EXPECT_EQ(1600, state->ZoneSizeInBytes()); | 3297 EXPECT_EQ(1600, thread->ZoneSizeInBytes()); |
3309 Dart_ExitScope(); | 3298 Dart_ExitScope(); |
3310 } | 3299 } |
3311 EXPECT_EQ(0, state->ZoneSizeInBytes()); | 3300 EXPECT_EQ(0, thread->ZoneSizeInBytes()); |
3312 EXPECT(scope == state->top_scope()); | 3301 EXPECT(scope == thread->api_top_scope()); |
3313 Dart_ShutdownIsolate(); | 3302 Dart_ShutdownIsolate(); |
3314 } | 3303 } |
3315 | 3304 |
3316 | 3305 |
3317 UNIT_TEST_CASE(Isolates) { | 3306 UNIT_TEST_CASE(Isolates) { |
3318 // This test currently assumes that the Dart_Isolate type is an opaque | 3307 // This test currently assumes that the Dart_Isolate type is an opaque |
3319 // representation of Isolate*. | 3308 // representation of Isolate*. |
3320 Dart_Isolate iso_1 = TestCase::CreateTestIsolate(); | 3309 Dart_Isolate iso_1 = TestCase::CreateTestIsolate(); |
3321 EXPECT_EQ(iso_1, Api::CastIsolate(Isolate::Current())); | 3310 EXPECT_EQ(iso_1, Api::CastIsolate(Isolate::Current())); |
3322 Dart_Isolate isolate = Dart_CurrentIsolate(); | 3311 Dart_Isolate isolate = Dart_CurrentIsolate(); |
(...skipping 1508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4831 EXPECT_VALID(list_obj); | 4820 EXPECT_VALID(list_obj); |
4832 EXPECT(Dart_IsList(list_obj)); | 4821 EXPECT(Dart_IsList(list_obj)); |
4833 } | 4822 } |
4834 | 4823 |
4835 | 4824 |
4836 static Dart_Handle PrivateLibName(Dart_Handle lib, const char* str) { | 4825 static Dart_Handle PrivateLibName(Dart_Handle lib, const char* str) { |
4837 EXPECT(Dart_IsLibrary(lib)); | 4826 EXPECT(Dart_IsLibrary(lib)); |
4838 Thread* thread = Thread::Current(); | 4827 Thread* thread = Thread::Current(); |
4839 const Library& library_obj = Api::UnwrapLibraryHandle(thread->zone(), lib); | 4828 const Library& library_obj = Api::UnwrapLibraryHandle(thread->zone(), lib); |
4840 const String& name = String::Handle(String::New(str)); | 4829 const String& name = String::Handle(String::New(str)); |
4841 return Api::NewHandle(thread->isolate(), library_obj.PrivateName(name)); | 4830 return Api::NewHandle(thread, library_obj.PrivateName(name)); |
4842 } | 4831 } |
4843 | 4832 |
4844 | 4833 |
4845 TEST_CASE(Invoke) { | 4834 TEST_CASE(Invoke) { |
4846 const char* kScriptChars = | 4835 const char* kScriptChars = |
4847 "class BaseMethods {\n" | 4836 "class BaseMethods {\n" |
4848 " inheritedMethod(arg) => 'inherited $arg';\n" | 4837 " inheritedMethod(arg) => 'inherited $arg';\n" |
4849 " static nonInheritedMethod(arg) => 'noninherited $arg';\n" | 4838 " static nonInheritedMethod(arg) => 'noninherited $arg';\n" |
4850 "}\n" | 4839 "}\n" |
4851 "\n" | 4840 "\n" |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5242 ASSERT(auto_setup_scope != NULL); | 5231 ASSERT(auto_setup_scope != NULL); |
5243 *auto_setup_scope = false; | 5232 *auto_setup_scope = false; |
5244 return reinterpret_cast<Dart_NativeFunction>(&ExceptionNative); | 5233 return reinterpret_cast<Dart_NativeFunction>(&ExceptionNative); |
5245 } | 5234 } |
5246 | 5235 |
5247 | 5236 |
5248 TEST_CASE(ThrowException) { | 5237 TEST_CASE(ThrowException) { |
5249 const char* kScriptChars = | 5238 const char* kScriptChars = |
5250 "int test() native \"ThrowException_native\";"; | 5239 "int test() native \"ThrowException_native\";"; |
5251 Dart_Handle result; | 5240 Dart_Handle result; |
5252 Isolate* isolate = Isolate::Current(); | 5241 intptr_t size = thread->ZoneSizeInBytes(); |
5253 EXPECT(isolate != NULL); | |
5254 ApiState* state = isolate->api_state(); | |
5255 EXPECT(state != NULL); | |
5256 intptr_t size = state->ZoneSizeInBytes(); | |
5257 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. | 5242 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
5258 | 5243 |
5259 // Load up a test script which extends the native wrapper class. | 5244 // Load up a test script which extends the native wrapper class. |
5260 Dart_Handle lib = TestCase::LoadTestScript( | 5245 Dart_Handle lib = TestCase::LoadTestScript( |
5261 kScriptChars, | 5246 kScriptChars, |
5262 reinterpret_cast<Dart_NativeEntryResolver>(native_lookup)); | 5247 reinterpret_cast<Dart_NativeEntryResolver>(native_lookup)); |
5263 | 5248 |
5264 // Throwing an exception here should result in an error. | 5249 // Throwing an exception here should result in an error. |
5265 result = Dart_ThrowException(NewString("This doesn't work")); | 5250 result = Dart_ThrowException(NewString("This doesn't work")); |
5266 EXPECT_ERROR(result, "No Dart frames on stack, cannot throw exception"); | 5251 EXPECT_ERROR(result, "No Dart frames on stack, cannot throw exception"); |
5267 EXPECT(!Dart_ErrorHasException(result)); | 5252 EXPECT(!Dart_ErrorHasException(result)); |
5268 | 5253 |
5269 // Invoke 'test' and check for an uncaught exception. | 5254 // Invoke 'test' and check for an uncaught exception. |
5270 result = Dart_Invoke(lib, NewString("test"), 0, NULL); | 5255 result = Dart_Invoke(lib, NewString("test"), 0, NULL); |
5271 EXPECT_ERROR(result, "Hello from ExceptionNative!"); | 5256 EXPECT_ERROR(result, "Hello from ExceptionNative!"); |
5272 EXPECT(Dart_ErrorHasException(result)); | 5257 EXPECT(Dart_ErrorHasException(result)); |
5273 | 5258 |
5274 Dart_ExitScope(); // Exit the Dart API scope. | 5259 Dart_ExitScope(); // Exit the Dart API scope. |
5275 EXPECT_EQ(size, state->ZoneSizeInBytes()); | 5260 EXPECT_EQ(size, thread->ZoneSizeInBytes()); |
5276 } | 5261 } |
5277 | 5262 |
5278 | 5263 |
5279 static intptr_t kNativeArgumentNativeField1Value = 30; | 5264 static intptr_t kNativeArgumentNativeField1Value = 30; |
5280 static intptr_t kNativeArgumentNativeField2Value = 40; | 5265 static intptr_t kNativeArgumentNativeField2Value = 40; |
5281 static intptr_t native_arg_str_peer = 100; | 5266 static intptr_t native_arg_str_peer = 100; |
5282 static void NativeArgumentCreate(Dart_NativeArguments args) { | 5267 static void NativeArgumentCreate(Dart_NativeArguments args) { |
5283 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url())); | 5268 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url())); |
5284 Dart_Handle type = Dart_GetType(lib, NewString("MyObject"), 0, NULL); | 5269 Dart_Handle type = Dart_GetType(lib, NewString("MyObject"), 0, NULL); |
5285 EXPECT_VALID(type); | 5270 EXPECT_VALID(type); |
(...skipping 2801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8087 EXPECT(out == NULL); | 8072 EXPECT(out == NULL); |
8088 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8073 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8089 } | 8074 } |
8090 | 8075 |
8091 | 8076 |
8092 // Allocates an object in old space and assigns it a peer. Removes | 8077 // Allocates an object in old space and assigns it a peer. Removes |
8093 // the peer and checks that the count of peer objects is decremented | 8078 // the peer and checks that the count of peer objects is decremented |
8094 // by one. | 8079 // by one. |
8095 TEST_CASE(OneOldSpacePeer) { | 8080 TEST_CASE(OneOldSpacePeer) { |
8096 Isolate* isolate = Isolate::Current(); | 8081 Isolate* isolate = Isolate::Current(); |
8097 Dart_Handle str = Api::NewHandle(isolate, String::New("str", Heap::kOld)); | 8082 Dart_Handle str = Api::NewHandle(thread, String::New("str", Heap::kOld)); |
8098 EXPECT_VALID(str); | 8083 EXPECT_VALID(str); |
8099 EXPECT(Dart_IsString(str)); | 8084 EXPECT(Dart_IsString(str)); |
8100 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8085 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8101 void* out = &out; | 8086 void* out = &out; |
8102 EXPECT(Dart_GetPeer(str, &out)); | 8087 EXPECT(Dart_GetPeer(str, &out)); |
8103 EXPECT(out == NULL); | 8088 EXPECT(out == NULL); |
8104 int peer = 1234; | 8089 int peer = 1234; |
8105 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 8090 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
8106 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8091 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
8107 out = &out; | 8092 out = &out; |
(...skipping 12 matching lines...) Expand all Loading... |
8120 | 8105 |
8121 | 8106 |
8122 // Allocates an object in old space and assigns it a peer. Allow the | 8107 // Allocates an object in old space and assigns it a peer. Allow the |
8123 // peer referent to be garbage collected and check that the count of | 8108 // peer referent to be garbage collected and check that the count of |
8124 // peer objects is decremented by one. | 8109 // peer objects is decremented by one. |
8125 TEST_CASE(CollectOneOldSpacePeer) { | 8110 TEST_CASE(CollectOneOldSpacePeer) { |
8126 Isolate* isolate = Isolate::Current(); | 8111 Isolate* isolate = Isolate::Current(); |
8127 Dart_EnterScope(); | 8112 Dart_EnterScope(); |
8128 { | 8113 { |
8129 DARTSCOPE(Thread::Current()); | 8114 DARTSCOPE(Thread::Current()); |
8130 Dart_Handle str = Api::NewHandle(isolate, String::New("str", Heap::kOld)); | 8115 Dart_Handle str = Api::NewHandle(T, String::New("str", Heap::kOld)); |
8131 EXPECT_VALID(str); | 8116 EXPECT_VALID(str); |
8132 EXPECT(Dart_IsString(str)); | 8117 EXPECT(Dart_IsString(str)); |
8133 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8118 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8134 void* out = &out; | 8119 void* out = &out; |
8135 EXPECT(Dart_GetPeer(str, &out)); | 8120 EXPECT(Dart_GetPeer(str, &out)); |
8136 EXPECT(out == NULL); | 8121 EXPECT(out == NULL); |
8137 int peer = 1234; | 8122 int peer = 1234; |
8138 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 8123 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
8139 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8124 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
8140 out = &out; | 8125 out = &out; |
8141 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8126 EXPECT_VALID(Dart_GetPeer(str, &out)); |
8142 EXPECT(out == reinterpret_cast<void*>(&peer)); | 8127 EXPECT(out == reinterpret_cast<void*>(&peer)); |
8143 isolate->heap()->CollectGarbage(Heap::kOld); | 8128 isolate->heap()->CollectGarbage(Heap::kOld); |
8144 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8129 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
8145 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8130 EXPECT_VALID(Dart_GetPeer(str, &out)); |
8146 EXPECT(out == reinterpret_cast<void*>(&peer)); | 8131 EXPECT(out == reinterpret_cast<void*>(&peer)); |
8147 } | 8132 } |
8148 Dart_ExitScope(); | 8133 Dart_ExitScope(); |
8149 isolate->heap()->CollectGarbage(Heap::kOld); | 8134 isolate->heap()->CollectGarbage(Heap::kOld); |
8150 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8135 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8151 } | 8136 } |
8152 | 8137 |
8153 | 8138 |
8154 // Allocates two objects in old space and assigns them peers. Removes | 8139 // Allocates two objects in old space and assigns them peers. Removes |
8155 // the peers and checks that the count of peer objects is decremented | 8140 // the peers and checks that the count of peer objects is decremented |
8156 // by two. | 8141 // by two. |
8157 TEST_CASE(TwoOldSpacePeers) { | 8142 TEST_CASE(TwoOldSpacePeers) { |
8158 Isolate* isolate = Isolate::Current(); | 8143 Isolate* isolate = Isolate::Current(); |
8159 Dart_Handle s1 = Api::NewHandle(isolate, String::New("s1", Heap::kOld)); | 8144 Dart_Handle s1 = Api::NewHandle(thread, String::New("s1", Heap::kOld)); |
8160 EXPECT_VALID(s1); | 8145 EXPECT_VALID(s1); |
8161 EXPECT(Dart_IsString(s1)); | 8146 EXPECT(Dart_IsString(s1)); |
8162 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8147 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8163 void* o1 = &o1; | 8148 void* o1 = &o1; |
8164 EXPECT(Dart_GetPeer(s1, &o1)); | 8149 EXPECT(Dart_GetPeer(s1, &o1)); |
8165 EXPECT(o1 == NULL); | 8150 EXPECT(o1 == NULL); |
8166 int p1 = 1234; | 8151 int p1 = 1234; |
8167 EXPECT_VALID(Dart_SetPeer(s1, &p1)); | 8152 EXPECT_VALID(Dart_SetPeer(s1, &p1)); |
8168 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8153 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
8169 o1 = &o1; | 8154 o1 = &o1; |
8170 EXPECT_VALID(Dart_GetPeer(s1, &o1)); | 8155 EXPECT_VALID(Dart_GetPeer(s1, &o1)); |
8171 EXPECT(o1 == reinterpret_cast<void*>(&p1)); | 8156 EXPECT(o1 == reinterpret_cast<void*>(&p1)); |
8172 Dart_Handle s2 = Api::NewHandle(isolate, String::New("s2", Heap::kOld)); | 8157 Dart_Handle s2 = Api::NewHandle(thread, String::New("s2", Heap::kOld)); |
8173 EXPECT_VALID(s2); | 8158 EXPECT_VALID(s2); |
8174 EXPECT(Dart_IsString(s2)); | 8159 EXPECT(Dart_IsString(s2)); |
8175 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8160 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
8176 void* o2 = &o2; | 8161 void* o2 = &o2; |
8177 EXPECT(Dart_GetPeer(s2, &o2)); | 8162 EXPECT(Dart_GetPeer(s2, &o2)); |
8178 EXPECT(o2 == NULL); | 8163 EXPECT(o2 == NULL); |
8179 int p2 = 5678; | 8164 int p2 = 5678; |
8180 EXPECT_VALID(Dart_SetPeer(s2, &p2)); | 8165 EXPECT_VALID(Dart_SetPeer(s2, &p2)); |
8181 EXPECT_EQ(2, isolate->heap()->PeerCount()); | 8166 EXPECT_EQ(2, isolate->heap()->PeerCount()); |
8182 o2 = &o2; | 8167 o2 = &o2; |
(...skipping 13 matching lines...) Expand all Loading... |
8196 | 8181 |
8197 | 8182 |
8198 // Allocates two objects in old space and assigns them a peer. Allows | 8183 // Allocates two objects in old space and assigns them a peer. Allows |
8199 // the peer referents to be garbage collected and checks that the | 8184 // the peer referents to be garbage collected and checks that the |
8200 // count of peer objects is decremented by two. | 8185 // count of peer objects is decremented by two. |
8201 TEST_CASE(CollectTwoOldSpacePeers) { | 8186 TEST_CASE(CollectTwoOldSpacePeers) { |
8202 Isolate* isolate = Isolate::Current(); | 8187 Isolate* isolate = Isolate::Current(); |
8203 Dart_EnterScope(); | 8188 Dart_EnterScope(); |
8204 { | 8189 { |
8205 DARTSCOPE(Thread::Current()); | 8190 DARTSCOPE(Thread::Current()); |
8206 Dart_Handle s1 = Api::NewHandle(isolate, String::New("s1", Heap::kOld)); | 8191 Dart_Handle s1 = Api::NewHandle(T, String::New("s1", Heap::kOld)); |
8207 EXPECT_VALID(s1); | 8192 EXPECT_VALID(s1); |
8208 EXPECT(Dart_IsString(s1)); | 8193 EXPECT(Dart_IsString(s1)); |
8209 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8194 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8210 void* o1 = &o1; | 8195 void* o1 = &o1; |
8211 EXPECT(Dart_GetPeer(s1, &o1)); | 8196 EXPECT(Dart_GetPeer(s1, &o1)); |
8212 EXPECT(o1 == NULL); | 8197 EXPECT(o1 == NULL); |
8213 int p1 = 1234; | 8198 int p1 = 1234; |
8214 EXPECT_VALID(Dart_SetPeer(s1, &p1)); | 8199 EXPECT_VALID(Dart_SetPeer(s1, &p1)); |
8215 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8200 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
8216 o1 = &o1; | 8201 o1 = &o1; |
8217 EXPECT_VALID(Dart_GetPeer(s1, &o1)); | 8202 EXPECT_VALID(Dart_GetPeer(s1, &o1)); |
8218 EXPECT(o1 == reinterpret_cast<void*>(&p1)); | 8203 EXPECT(o1 == reinterpret_cast<void*>(&p1)); |
8219 Dart_Handle s2 = Api::NewHandle(isolate, String::New("s2", Heap::kOld)); | 8204 Dart_Handle s2 = Api::NewHandle(T, String::New("s2", Heap::kOld)); |
8220 EXPECT_VALID(s2); | 8205 EXPECT_VALID(s2); |
8221 EXPECT(Dart_IsString(s2)); | 8206 EXPECT(Dart_IsString(s2)); |
8222 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8207 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
8223 void* o2 = &o2; | 8208 void* o2 = &o2; |
8224 EXPECT(Dart_GetPeer(s2, &o2)); | 8209 EXPECT(Dart_GetPeer(s2, &o2)); |
8225 EXPECT(o2 == NULL); | 8210 EXPECT(o2 == NULL); |
8226 int p2 = 5678; | 8211 int p2 = 5678; |
8227 EXPECT_VALID(Dart_SetPeer(s2, &p2)); | 8212 EXPECT_VALID(Dart_SetPeer(s2, &p2)); |
8228 EXPECT_EQ(2, isolate->heap()->PeerCount()); | 8213 EXPECT_EQ(2, isolate->heap()->PeerCount()); |
8229 o2 = &o2; | 8214 o2 = &o2; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8302 EXPECT(Dart_IsString(empty_str)); | 8287 EXPECT(Dart_IsString(empty_str)); |
8303 EXPECT(Dart_IsStringLatin1(str)); | 8288 EXPECT(Dart_IsStringLatin1(str)); |
8304 EXPECT(Dart_IsStringLatin1(empty_str)); | 8289 EXPECT(Dart_IsStringLatin1(empty_str)); |
8305 EXPECT(Dart_IsExternalString(str)); | 8290 EXPECT(Dart_IsExternalString(str)); |
8306 EXPECT(Dart_IsExternalString(empty_str)); | 8291 EXPECT(Dart_IsExternalString(empty_str)); |
8307 EXPECT_VALID(Dart_StringLength(str, &length)); | 8292 EXPECT_VALID(Dart_StringLength(str, &length)); |
8308 EXPECT_EQ(0, length); | 8293 EXPECT_EQ(0, length); |
8309 | 8294 |
8310 // Test with single character canonical string, it should not become | 8295 // Test with single character canonical string, it should not become |
8311 // external string but the peer should be setup for it. | 8296 // external string but the peer should be setup for it. |
8312 Isolate* isolate = Isolate::Current(); | 8297 Dart_Handle canonical_str = Api::NewHandle(thread, Symbols::New("*")); |
8313 Dart_Handle canonical_str = Api::NewHandle(isolate, Symbols::New("*")); | |
8314 EXPECT(Dart_IsString(canonical_str)); | 8298 EXPECT(Dart_IsString(canonical_str)); |
8315 EXPECT(!Dart_IsExternalString(canonical_str)); | 8299 EXPECT(!Dart_IsExternalString(canonical_str)); |
8316 uint8_t ext_canonical_str[kLength]; | 8300 uint8_t ext_canonical_str[kLength]; |
8317 str = Dart_MakeExternalString(canonical_str, | 8301 str = Dart_MakeExternalString(canonical_str, |
8318 ext_canonical_str, | 8302 ext_canonical_str, |
8319 kLength, | 8303 kLength, |
8320 &canonical_str_peer, | 8304 &canonical_str_peer, |
8321 MakeExternalCback); | 8305 MakeExternalCback); |
8322 EXPECT(Dart_IsString(str)); | 8306 EXPECT(Dart_IsString(str)); |
8323 EXPECT(!Dart_IsExternalString(canonical_str)); | 8307 EXPECT(!Dart_IsExternalString(canonical_str)); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8394 EXPECT(Dart_IdentityEquals(str, utf16_str)); | 8378 EXPECT(Dart_IdentityEquals(str, utf16_str)); |
8395 for (intptr_t i = 0; i < length; i++) { | 8379 for (intptr_t i = 0; i < length; i++) { |
8396 EXPECT_EQ(0x4e8c, ext_utf16_str[i]); | 8380 EXPECT_EQ(0x4e8c, ext_utf16_str[i]); |
8397 } | 8381 } |
8398 | 8382 |
8399 Zone* zone = thread->zone(); | 8383 Zone* zone = thread->zone(); |
8400 // Test with a symbol (hash value should be preserved on externalization). | 8384 // Test with a symbol (hash value should be preserved on externalization). |
8401 const char* symbol_ascii = "?unseen"; | 8385 const char* symbol_ascii = "?unseen"; |
8402 expected_length = strlen(symbol_ascii); | 8386 expected_length = strlen(symbol_ascii); |
8403 Dart_Handle symbol_str = | 8387 Dart_Handle symbol_str = |
8404 Api::NewHandle(isolate, Symbols::New(symbol_ascii, expected_length)); | 8388 Api::NewHandle(thread, Symbols::New(symbol_ascii, expected_length)); |
8405 EXPECT_VALID(symbol_str); | 8389 EXPECT_VALID(symbol_str); |
8406 EXPECT(Dart_IsString(symbol_str)); | 8390 EXPECT(Dart_IsString(symbol_str)); |
8407 EXPECT(Dart_IsStringLatin1(symbol_str)); | 8391 EXPECT(Dart_IsStringLatin1(symbol_str)); |
8408 EXPECT(!Dart_IsExternalString(symbol_str)); | 8392 EXPECT(!Dart_IsExternalString(symbol_str)); |
8409 EXPECT_VALID(Dart_StringLength(symbol_str, &length)); | 8393 EXPECT_VALID(Dart_StringLength(symbol_str, &length)); |
8410 EXPECT_EQ(expected_length, length); | 8394 EXPECT_EQ(expected_length, length); |
8411 EXPECT(Api::UnwrapStringHandle(zone, symbol_str).HasHash()); | 8395 EXPECT(Api::UnwrapStringHandle(zone, symbol_str).HasHash()); |
8412 | 8396 |
8413 uint8_t ext_symbol_ascii[kLength]; | 8397 uint8_t ext_symbol_ascii[kLength]; |
8414 EXPECT_VALID(Dart_StringStorageSize(symbol_str, &size)); | 8398 EXPECT_VALID(Dart_StringStorageSize(symbol_str, &size)); |
(...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9337 | 9321 |
9338 // Heartbeat test for new events. | 9322 // Heartbeat test for new events. |
9339 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); | 9323 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); |
9340 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); | 9324 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); |
9341 | 9325 |
9342 // Free buffer allocated by AppendStreamConsumer | 9326 // Free buffer allocated by AppendStreamConsumer |
9343 free(data.buffer); | 9327 free(data.buffer); |
9344 } | 9328 } |
9345 | 9329 |
9346 } // namespace dart | 9330 } // namespace dart |
OLD | NEW |