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 "platform/globals.h" | 5 #include "platform/globals.h" |
6 | 6 |
7 #include "include/dart_tools_api.h" | 7 #include "include/dart_tools_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/clustered_snapshot.h" | 10 #include "vm/clustered_snapshot.h" |
(...skipping 1381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1392 | 1392 |
1393 EXPECT_EQ(expected_num_libs, actual_num_libs); | 1393 EXPECT_EQ(expected_num_libs, actual_num_libs); |
1394 | 1394 |
1395 // Invoke a function which returns an object. | 1395 // Invoke a function which returns an object. |
1396 Dart_Handle cls = Dart_GetClass(result, NewString("FieldsTest")); | 1396 Dart_Handle cls = Dart_GetClass(result, NewString("FieldsTest")); |
1397 result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); | 1397 result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); |
1398 EXPECT_VALID(result); | 1398 EXPECT_VALID(result); |
1399 Dart_ExitScope(); | 1399 Dart_ExitScope(); |
1400 Dart_ShutdownIsolate(); | 1400 Dart_ShutdownIsolate(); |
1401 } | 1401 } |
1402 free(script_snapshot); | |
1403 | |
1404 // Test for Dart_CreateLibrarySnapshot. | |
1405 { | |
1406 // Create an Isolate using the full snapshot, load a script and create | |
1407 // a script snapshot of the script. | |
1408 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); | |
1409 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. | |
1410 | |
1411 // Load the library. | |
1412 Dart_Handle lib = Dart_LoadLibrary(NewString("dart_lib"), Dart_Null(), | |
1413 NewString(kScriptChars), 0, 0); | |
1414 EXPECT_VALID(lib); | |
1415 | |
1416 // Write out the script snapshot. | |
1417 result = Dart_CreateLibrarySnapshot(lib, &buffer, &size); | |
1418 EXPECT_VALID(result); | |
1419 script_snapshot = reinterpret_cast<uint8_t*>(malloc(size)); | |
1420 memmove(script_snapshot, buffer, size); | |
1421 Dart_ExitScope(); | |
1422 Dart_ShutdownIsolate(); | |
1423 } | |
1424 | |
1425 { | |
1426 // Now Create an Isolate using the full snapshot and load the | |
1427 // script snapshot created above and execute it. | |
1428 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); | |
1429 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. | |
1430 | |
1431 // Load the test library from the snapshot. | |
1432 EXPECT(script_snapshot != NULL); | |
1433 result = Dart_LoadScriptFromSnapshot(script_snapshot, size); | |
1434 EXPECT_VALID(result); | |
1435 | |
1436 // Invoke a function which returns an object. | |
1437 Dart_Handle cls = Dart_GetClass(result, NewString("FieldsTest")); | |
1438 result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); | |
1439 EXPECT_VALID(result); | |
1440 Dart_ExitScope(); | |
1441 Dart_ShutdownIsolate(); | |
1442 } | |
1443 free(full_snapshot); | 1402 free(full_snapshot); |
1444 free(script_snapshot); | 1403 free(script_snapshot); |
1445 } | 1404 } |
1446 | 1405 |
1447 | 1406 |
1448 UNIT_TEST_CASE(ScriptSnapshot1) { | 1407 UNIT_TEST_CASE(ScriptSnapshot1) { |
1449 const char* kScriptChars = | 1408 const char* kScriptChars = |
1450 "class _SimpleNumEnumerable<T extends num> {" | 1409 "class _SimpleNumEnumerable<T extends num> {" |
1451 "final Iterable<T> _source;" | 1410 "final Iterable<T> _source;" |
1452 "const _SimpleNumEnumerable(this._source) : super();" | 1411 "const _SimpleNumEnumerable(this._source) : super();" |
(...skipping 1575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3028 StackZone zone(Thread::Current()); | 2987 StackZone zone(Thread::Current()); |
3029 uint8_t* buffer; | 2988 uint8_t* buffer; |
3030 MessageWriter writer(&buffer, &zone_allocator, true); | 2989 MessageWriter writer(&buffer, &zone_allocator, true); |
3031 writer.WriteInlinedObjectHeader(kOmittedObjectId); | 2990 writer.WriteInlinedObjectHeader(kOmittedObjectId); |
3032 // For performance, we'd like single-byte headers when ids are omitted. | 2991 // For performance, we'd like single-byte headers when ids are omitted. |
3033 // If this starts failing, consider renumbering the snapshot ids. | 2992 // If this starts failing, consider renumbering the snapshot ids. |
3034 EXPECT_EQ(1, writer.BytesWritten()); | 2993 EXPECT_EQ(1, writer.BytesWritten()); |
3035 } | 2994 } |
3036 | 2995 |
3037 } // namespace dart | 2996 } // namespace dart |
OLD | NEW |