Chromium Code Reviews| Index: vm/dart_api_impl.cc |
| =================================================================== |
| --- vm/dart_api_impl.cc (revision 2043) |
| +++ vm/dart_api_impl.cc (working copy) |
| @@ -609,12 +609,12 @@ |
| } |
| -DART_EXPORT Dart_Handle Dart_CreateSnapshot(uint8_t** snapshot_buffer, |
| - intptr_t* snapshot_size) { |
| +DART_EXPORT Dart_Handle Dart_CreateSnapshot(uint8_t** buffer, |
| + intptr_t* size) { |
| Isolate* isolate = Isolate::Current(); |
| DARTSCOPE(isolate); |
| - if (snapshot_buffer == NULL || snapshot_size == NULL) { |
| - return Api::Error("Invalid input parameters to Dart_CreateSnapshot"); |
| + if (buffer == NULL || size == NULL) { |
| + return Api::Error("Invalid input parameters to %s", CURRENT_FUNC); |
|
turnidge
2011/12/05 18:49:00
If you are wanting to make this error message cons
siva
2011/12/05 21:35:37
Done.
|
| } |
| const char* msg = CheckIsolateState(isolate, |
| ClassFinalizer::kGeneratingSnapshot); |
| @@ -623,13 +623,36 @@ |
| } |
| // Since this is only a snapshot the root library should not be set. |
| isolate->object_store()->set_root_library(Library::Handle()); |
| - SnapshotWriter writer(true, snapshot_buffer, ApiAllocator); |
| + SnapshotWriter writer(Snapshot::kFull, buffer, ApiAllocator); |
| writer.WriteFullSnapshot(); |
| - *snapshot_size = writer.Size(); |
| + *size = writer.Size(); |
| return Api::Success(); |
| } |
| +DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(Dart_Handle library, |
| + uint8_t** buffer, |
| + intptr_t* size) { |
| + Isolate* isolate = Isolate::Current(); |
| + DARTSCOPE(isolate); |
| + if (buffer == NULL || size == NULL) { |
| + return Api::Error("Invalid input parameters to %s", CURRENT_FUNC); |
|
turnidge
2011/12/05 18:49:00
Ditto above.
siva
2011/12/05 21:35:37
Done.
|
| + } |
| + const Library& root_lib = Api::UnwrapLibraryHandle(library); |
| + if (root_lib.IsNull()) { |
| + RETURN_TYPE_ERROR(library, Library); |
| + } |
| + const char* msg = CheckIsolateState(isolate); |
| + if (msg != NULL) { |
| + return Api::Error(msg); |
| + } |
| + ScriptSnapshotWriter writer(root_lib, buffer, ApiAllocator); |
| + writer.WriteScriptSnapshot(); |
| + *size = writer.Size(); |
| + return Api::Success(); |
|
turnidge
2011/12/05 18:49:00
Once this works, it would be great to have a unit
siva
2011/12/05 21:35:37
I had already added a unit test in snapshot_test.c
|
| +} |
| + |
| + |
| // --- Messages and Ports --- |
| @@ -648,7 +671,7 @@ |
| static RawInstance* DeserializeMessage(void* data) { |
| // Create a snapshot object using the buffer. |
| const Snapshot* snapshot = Snapshot::SetupFromBuffer(data); |
| - ASSERT(snapshot->IsPartialSnapshot()); |
| + ASSERT(snapshot->IsMessageSnapshot()); |
| // Read object back from the snapshot. |
| Isolate* isolate = Isolate::Current(); |
| @@ -744,7 +767,7 @@ |
| DARTSCOPE_NOCHECKS(isolate); |
| const Object& object = Object::Handle(Api::UnwrapHandle(handle)); |
| uint8_t* data = NULL; |
| - SnapshotWriter writer(false, &data, &allocator); |
| + SnapshotWriter writer(Snapshot::kMessage, &data, &allocator); |
| writer.WriteObject(object.raw()); |
| writer.FinalizeBuffer(); |
| return PortMap::PostMessage(port_id, kNoReplyPort, Api::CastMessage(data)); |
| @@ -2179,6 +2202,29 @@ |
| } |
| +DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* data) { |
| + Isolate* isolate = Isolate::Current(); |
| + DARTSCOPE(isolate); |
| + if (data == NULL) { |
| + return Api::Error("Invalid input parameters to %s", CURRENT_FUNC); |
|
turnidge
2011/12/05 18:49:00
Ditto above.
siva
2011/12/05 21:35:37
Done.
|
| + } |
| + const Snapshot* snapshot = Snapshot::SetupFromBuffer(data); |
| + if (!snapshot->IsScriptSnapshot()) { |
| + return Api::Error("Expected a script type snapshot to %s", CURRENT_FUNC); |
|
turnidge
2011/12/05 18:49:00
"%s expects parameter 'data' to be a script snapsh
siva
2011/12/05 21:35:37
Done.
|
| + } |
|
turnidge
2011/12/05 18:49:00
Should we check to see if a script has already bee
siva
2011/12/05 21:35:37
Good point.
On 2011/12/05 18:49:00, turnidge wrot
|
| + SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store()); |
| + const Object& tmp = Object::Handle(reader.ReadObject()); |
| + if (!tmp.IsLibrary()) { |
| + return Api::Error("Unable to deserialize snapshot passed to %s correctly", |
| + CURRENT_FUNC); |
|
turnidge
2011/12/05 18:49:00
"%s: Unable to deserialize snapshot correctly.", C
siva
2011/12/05 21:35:37
Done.
|
| + } |
| + Library& lib = Library::Handle(); |
| + lib ^= tmp.raw(); |
| + isolate->object_store()->set_root_library(lib); |
| + return Api::NewLocalHandle(lib); |
| +} |
| + |
| + |
| DEFINE_FLAG(bool, compile_all, false, "Eagerly compile all code."); |
| static void CompileAll(Isolate* isolate, Dart_Handle* result) { |