OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
8 | 8 |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
(...skipping 1457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1468 FullSnapshotWriter writer(vm_isolate_snapshot_buffer, | 1468 FullSnapshotWriter writer(vm_isolate_snapshot_buffer, |
1469 isolate_snapshot_buffer, | 1469 isolate_snapshot_buffer, |
1470 ApiReallocate); | 1470 ApiReallocate); |
1471 writer.WriteFullSnapshot(); | 1471 writer.WriteFullSnapshot(); |
1472 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); | 1472 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); |
1473 *isolate_snapshot_size = writer.IsolateSnapshotSize(); | 1473 *isolate_snapshot_size = writer.IsolateSnapshotSize(); |
1474 return Api::Success(); | 1474 return Api::Success(); |
1475 } | 1475 } |
1476 | 1476 |
1477 | 1477 |
1478 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, | 1478 static Dart_Handle createLibrarySnapshot(Dart_Handle library, |
1479 intptr_t* size) { | 1479 uint8_t** buffer, |
| 1480 intptr_t* size) { |
1480 Isolate* isolate = Isolate::Current(); | 1481 Isolate* isolate = Isolate::Current(); |
1481 DARTSCOPE(isolate); | 1482 DARTSCOPE(isolate); |
1482 TIMERSCOPE(isolate, time_creating_snapshot); | 1483 TIMERSCOPE(isolate, time_creating_snapshot); |
1483 if (buffer == NULL) { | 1484 if (buffer == NULL) { |
1484 RETURN_NULL_ERROR(buffer); | 1485 RETURN_NULL_ERROR(buffer); |
1485 } | 1486 } |
1486 if (size == NULL) { | 1487 if (size == NULL) { |
1487 RETURN_NULL_ERROR(size); | 1488 RETURN_NULL_ERROR(size); |
1488 } | 1489 } |
1489 // Finalize all classes if needed. | 1490 // Finalize all classes if needed. |
1490 Dart_Handle state = Api::CheckAndFinalizePendingClasses(isolate); | 1491 Dart_Handle state = Api::CheckAndFinalizePendingClasses(isolate); |
1491 if (::Dart_IsError(state)) { | 1492 if (::Dart_IsError(state)) { |
1492 return state; | 1493 return state; |
1493 } | 1494 } |
1494 Library& library = | 1495 Library& lib = Library::Handle(isolate); |
1495 Library::Handle(isolate, isolate->object_store()->root_library()); | 1496 if (library == Dart_Null()) { |
1496 if (library.IsNull()) { | 1497 lib ^= isolate->object_store()->root_library(); |
1497 return | 1498 } else { |
1498 Api::NewError("%s expects the isolate to have a script loaded in it.", | 1499 lib ^= Api::UnwrapHandle(library); |
1499 CURRENT_FUNC); | |
1500 } | 1500 } |
1501 ScriptSnapshotWriter writer(buffer, ApiReallocate); | 1501 ScriptSnapshotWriter writer(buffer, ApiReallocate); |
1502 writer.WriteScriptSnapshot(library); | 1502 writer.WriteScriptSnapshot(lib); |
1503 *size = writer.BytesWritten(); | 1503 *size = writer.BytesWritten(); |
1504 return Api::Success(); | 1504 return Api::Success(); |
1505 } | 1505 } |
1506 | 1506 |
1507 | 1507 |
| 1508 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, |
| 1509 intptr_t* size) { |
| 1510 return createLibrarySnapshot(Dart_Null(), buffer, size); |
| 1511 } |
| 1512 |
| 1513 |
| 1514 DART_EXPORT Dart_Handle Dart_CreateLibrarySnapshot(Dart_Handle library, |
| 1515 uint8_t** buffer, |
| 1516 intptr_t* size) { |
| 1517 return createLibrarySnapshot(library, buffer, size); |
| 1518 } |
| 1519 |
| 1520 |
1508 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { | 1521 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { |
1509 TRACE_API_CALL(CURRENT_FUNC); | 1522 TRACE_API_CALL(CURRENT_FUNC); |
1510 if (isolate == NULL) { | 1523 if (isolate == NULL) { |
1511 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); | 1524 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); |
1512 } | 1525 } |
1513 // TODO(16615): Validate isolate parameter. | 1526 // TODO(16615): Validate isolate parameter. |
1514 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 1527 Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
1515 iso->ScheduleInterrupts(Isolate::kApiInterrupt); | 1528 iso->ScheduleInterrupts(Isolate::kApiInterrupt); |
1516 // Can't use Dart_Post() since there isn't a current isolate. | 1529 // Can't use Dart_Post() since there isn't a current isolate. |
1517 Dart_CObject api_null = { Dart_CObject_kNull , { 0 } }; | 1530 Dart_CObject api_null = { Dart_CObject_kNull , { 0 } }; |
(...skipping 4075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5593 | 5606 |
5594 | 5607 |
5595 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 5608 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
5596 const char* name, | 5609 const char* name, |
5597 Dart_ServiceRequestCallback callback, | 5610 Dart_ServiceRequestCallback callback, |
5598 void* user_data) { | 5611 void* user_data) { |
5599 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 5612 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
5600 } | 5613 } |
5601 | 5614 |
5602 } // namespace dart | 5615 } // namespace dart |
OLD | NEW |