| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 "vm/snapshot.h" | 5 #include "vm/snapshot.h" |
| 6 | 6 |
| 7 #include "vm/assert.h" | 7 #include "vm/assert.h" |
| 8 #include "vm/bigint_operations.h" | 8 #include "vm/bigint_operations.h" |
| 9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
| 10 #include "vm/unit_test.h" | 10 #include "vm/unit_test.h" |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 timer2.Stop(); | 361 timer2.Stop(); |
| 362 OS::PrintErr("From Snapshot: %dus\n", timer2.TotalElapsedTime()); | 362 OS::PrintErr("From Snapshot: %dus\n", timer2.TotalElapsedTime()); |
| 363 | 363 |
| 364 // Invoke a function which returns an object. | 364 // Invoke a function which returns an object. |
| 365 result = Dart_InvokeStatic(TestCase::lib(), | 365 result = Dart_InvokeStatic(TestCase::lib(), |
| 366 Dart_NewString("FieldsTest"), | 366 Dart_NewString("FieldsTest"), |
| 367 Dart_NewString("testMain"), | 367 Dart_NewString("testMain"), |
| 368 0, | 368 0, |
| 369 NULL); | 369 NULL); |
| 370 EXPECT_VALID(result); | 370 EXPECT_VALID(result); |
| 371 EXPECT(!Dart_ExceptionOccurred(result)); | |
| 372 | 371 |
| 373 Dart_ExitScope(); // Exit the Dart API scope. | 372 Dart_ExitScope(); // Exit the Dart API scope. |
| 374 } | 373 } |
| 375 Dart_ShutdownIsolate(); | 374 Dart_ShutdownIsolate(); |
| 376 | 375 |
| 377 free(buffer); | 376 free(buffer); |
| 378 } | 377 } |
| 379 | 378 |
| 380 | 379 |
| 381 UNIT_TEST_CASE(FullSnapshot1) { | 380 UNIT_TEST_CASE(FullSnapshot1) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 408 SnapshotWriter writer(true, &buffer, &allocator); | 407 SnapshotWriter writer(true, &buffer, &allocator); |
| 409 writer.WriteFullSnapshot(); | 408 writer.WriteFullSnapshot(); |
| 410 | 409 |
| 411 // Invoke a function which returns an object. | 410 // Invoke a function which returns an object. |
| 412 Dart_Handle result = Dart_InvokeStatic(lib, | 411 Dart_Handle result = Dart_InvokeStatic(lib, |
| 413 Dart_NewString("FieldsTest"), | 412 Dart_NewString("FieldsTest"), |
| 414 Dart_NewString("testMain"), | 413 Dart_NewString("testMain"), |
| 415 0, | 414 0, |
| 416 NULL); | 415 NULL); |
| 417 EXPECT_VALID(result); | 416 EXPECT_VALID(result); |
| 418 EXPECT(!Dart_ExceptionOccurred(result)); | |
| 419 | 417 |
| 420 Dart_ExitScope(); // Exit the Dart API scope. | 418 Dart_ExitScope(); // Exit the Dart API scope. |
| 421 } | 419 } |
| 422 Dart_ShutdownIsolate(); | 420 Dart_ShutdownIsolate(); |
| 423 | 421 |
| 424 // Now Create another isolate using the snapshot and execute a method | 422 // Now Create another isolate using the snapshot and execute a method |
| 425 // from the script. | 423 // from the script. |
| 426 Timer timer2(true, "Snapshot_test"); | 424 Timer timer2(true, "Snapshot_test"); |
| 427 timer2.Start(); | 425 timer2.Start(); |
| 428 Dart_CreateIsolate(buffer, NULL); | 426 Dart_CreateIsolate(buffer, NULL); |
| 429 { | 427 { |
| 430 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. | 428 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
| 431 timer2.Stop(); | 429 timer2.Stop(); |
| 432 OS::PrintErr("From Snapshot: %dus\n", timer2.TotalElapsedTime()); | 430 OS::PrintErr("From Snapshot: %dus\n", timer2.TotalElapsedTime()); |
| 433 | 431 |
| 434 // Invoke a function which returns an object. | 432 // Invoke a function which returns an object. |
| 435 Dart_Handle result = Dart_InvokeStatic(TestCase::lib(), | 433 Dart_Handle result = Dart_InvokeStatic(TestCase::lib(), |
| 436 Dart_NewString("FieldsTest"), | 434 Dart_NewString("FieldsTest"), |
| 437 Dart_NewString("testMain"), | 435 Dart_NewString("testMain"), |
| 438 0, | 436 0, |
| 439 NULL); | 437 NULL); |
| 438 if (Dart_IsError(result)) { |
| 439 // Print the error. It is probably an unhandled exception. |
| 440 fprintf(stderr, "%s\n", Dart_GetError(result)); |
| 441 } |
| 440 EXPECT_VALID(result); | 442 EXPECT_VALID(result); |
| 441 if (Dart_ExceptionOccurred(result)) { | |
| 442 // Print the exception object. | |
| 443 fprintf(stderr, "An unhandled exception has been thrown\n"); | |
| 444 Dart_Handle exception_result = Dart_GetException(result); | |
| 445 assert(Dart_IsValid(exception_result)); | |
| 446 const char* obj_cstring = NULL; | |
| 447 Dart_Handle retstr = Dart_StringToCString(exception_result, &obj_cstring); | |
| 448 if (!Dart_IsValid(retstr)) { | |
| 449 obj_cstring = Dart_GetError(retstr); | |
| 450 } | |
| 451 fprintf(stderr, "%s", obj_cstring); | |
| 452 } | |
| 453 EXPECT(!Dart_ExceptionOccurred(result)); | |
| 454 | 443 |
| 455 Dart_ExitScope(); // Exit the Dart API scope. | 444 Dart_ExitScope(); // Exit the Dart API scope. |
| 456 } | 445 } |
| 457 Dart_ShutdownIsolate(); | 446 Dart_ShutdownIsolate(); |
| 458 | 447 |
| 459 free(buffer); | 448 free(buffer); |
| 460 } | 449 } |
| 461 #endif // TARGET_ARCH_IA32. | 450 #endif // TARGET_ARCH_IA32. |
| 462 | 451 |
| 463 } // namespace dart | 452 } // namespace dart |
| OLD | NEW |