Index: runtime/vm/dart_api_impl.cc |
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc |
index bc36704424b32c1b9ab8117fa09ca7ccdb760420..9562941a55c1c60df280fc5fbc503b0682092fa2 100644 |
--- a/runtime/vm/dart_api_impl.cc |
+++ b/runtime/vm/dart_api_impl.cc |
@@ -1475,8 +1475,9 @@ DART_EXPORT Dart_Handle Dart_CreateSnapshot( |
} |
-DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, |
- intptr_t* size) { |
+static Dart_Handle createLibrarySnapshot(Dart_Handle library, |
+ uint8_t** buffer, |
+ intptr_t* size) { |
Isolate* isolate = Isolate::Current(); |
DARTSCOPE(isolate); |
TIMERSCOPE(isolate, time_creating_snapshot); |
@@ -1491,20 +1492,32 @@ DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, |
if (::Dart_IsError(state)) { |
return state; |
} |
- Library& library = |
- Library::Handle(isolate, isolate->object_store()->root_library()); |
- if (library.IsNull()) { |
- return |
- Api::NewError("%s expects the isolate to have a script loaded in it.", |
- CURRENT_FUNC); |
+ Library& lib = Library::Handle(isolate); |
+ if (library == Dart_Null()) { |
+ lib ^= isolate->object_store()->root_library(); |
+ } else { |
+ lib ^= Api::UnwrapHandle(library); |
} |
ScriptSnapshotWriter writer(buffer, ApiReallocate); |
- writer.WriteScriptSnapshot(library); |
+ writer.WriteScriptSnapshot(lib); |
*size = writer.BytesWritten(); |
return Api::Success(); |
} |
+DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, |
+ intptr_t* size) { |
+ return createLibrarySnapshot(Dart_Null(), buffer, size); |
+} |
+ |
+ |
+DART_EXPORT Dart_Handle Dart_CreateLibrarySnapshot(Dart_Handle library, |
+ uint8_t** buffer, |
+ intptr_t* size) { |
+ return createLibrarySnapshot(library, buffer, size); |
+} |
+ |
+ |
DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { |
TRACE_API_CALL(CURRENT_FUNC); |
if (isolate == NULL) { |