Index: runtime/vm/dart_api_impl.cc |
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc |
index f6f3ab841fbf2278defc14a570a591ded15f02dd..490d95f715c24c923ccf522a49d184a06b642fba 100644 |
--- a/runtime/vm/dart_api_impl.cc |
+++ b/runtime/vm/dart_api_impl.cc |
@@ -17,6 +17,9 @@ |
#include "vm/dart_api_state.h" |
#include "vm/dart_entry.h" |
#include "vm/debugger.h" |
+#if !defined(DART_PRECOMPILED_RUNTIME) |
+#include "vm/kernel_reader.h" |
+#endif |
#include "vm/exceptions.h" |
#include "vm/flags.h" |
#include "vm/growable_array.h" |
@@ -5392,6 +5395,41 @@ DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer, |
} |
+DART_EXPORT Dart_Handle Dart_LoadKernel(const uint8_t* buffer, |
+ intptr_t buffer_len) { |
+ API_TIMELINE_DURATION; |
+ DARTSCOPE(Thread::Current()); |
+ StackZone zone(T); |
+ |
+#if defined(DART_PRECOMPILED_RUNTIME) && !defined(DART_PRECOMPILER) |
+ return Api::NewError("%s: Can't load Kernel files from precompiled runtime.", |
+ CURRENT_FUNC); |
+#else |
+ Isolate* I = T->isolate(); |
+ |
+ Library& library = Library::Handle(Z, I->object_store()->root_library()); |
+ if (!library.IsNull()) { |
+ const String& library_url = String::Handle(Z, library.url()); |
+ return Api::NewError("%s: A script has already been loaded from '%s'.", |
+ CURRENT_FUNC, library_url.ToCString()); |
+ } |
+ CHECK_CALLBACK_STATE(T); |
+ CHECK_COMPILATION_ALLOWED(I); |
+ |
+ // TODO(27588): Memory leak! |
+ kernel::KernelReader* reader = new kernel::KernelReader(buffer, buffer_len); |
+ const Object& tmp = reader->ReadProgram(); |
+ if (tmp.IsError()) { |
+ return Api::NewHandle(T, tmp.raw()); |
+ } |
+ library ^= tmp.raw(); |
+ library.set_debuggable(false); |
+ I->object_store()->set_root_library(library); |
+ return Api::NewHandle(T, library.raw()); |
+#endif |
+} |
+ |
+ |
DART_EXPORT Dart_Handle Dart_RootLibrary() { |
Thread* thread = Thread::Current(); |
Isolate* isolate = thread->isolate(); |