Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1176)

Unified Diff: runtime/vm/kernel_reader.cc

Issue 2786083002: Read platform.dill in the VM. (Closed)
Patch Set: Allow main to be a field or getter. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/vm/kernel_reader.cc
diff --git a/runtime/vm/kernel_reader.cc b/runtime/vm/kernel_reader.cc
index 231300e595be74842e241850bdf2144a308c403b..d896becf14c95de000e172b4ca637fbdf0ede750 100644
--- a/runtime/vm/kernel_reader.cc
+++ b/runtime/vm/kernel_reader.cc
@@ -135,12 +135,39 @@ Object& KernelReader::ReadProgram() {
if (ClassFinalizer::ProcessPendingClasses(/*from_kernel=*/true)) {
CanonicalName* main = program_->main_method();
- dart::Library& library = LookupLibrary(main->EnclosingName());
+ if (main == NULL) {
+ return dart::Library::Handle(Z);
+ }
+ CanonicalName* main_library = main->EnclosingName();
+ dart::Library& library = LookupLibrary(main_library);
// Sanity check that we can find the main entrypoint.
Object& main_obj = Object::Handle(
Z, library.LookupObjectAllowPrivate(H.DartSymbol("main")));
ASSERT(!main_obj.IsNull());
+
+ // There is a function _getMainClosure in dart:_builtin that returns the
Kevin Millikin (Google) 2017/03/31 10:05:42 I'm aware that this is ugly. It would be better t
Vyacheslav Egorov (Google) 2017/04/05 12:21:23 We would also need to come up with solution for th
Kevin Millikin (Google) 2017/04/25 18:20:29 I know, and those changes started landing before t
+ // main procedure. Since the platform libraries are compiled before the
+ // program script, this function is patched here.
+ dart::Library& builtin_library =
+ dart::Library::Handle(Z, I->object_store()->builtin_library());
+ Function& to_patch =
+ Function::Handle(builtin_library.LookupFunctionAllowPrivate(
kustermann 2017/04/05 11:47:07 Handle(Z,
Kevin Millikin (Google) 2017/04/25 18:20:29 Done.
+ dart::String::Handle(dart::String::New("_getMainClosure"))));
+
+ // Build a canonical name tree instead of sharing main's canonical name.
+ CanonicalName* name = CanonicalName::NewRoot();
kustermann 2017/04/05 11:47:07 This will leak [name], right? Please add a commen
+ name = name->AddChild(new String(main_library->name()->buffer(),
+ main_library->name()->size()));
kustermann 2017/04/05 11:47:07 This "new String()" will never be freed afaik! (al
Kevin Millikin (Google) 2017/04/25 18:20:29 Comment added that we are leaking the whole body.
+ CanonicalName* kind = main->parent();
+ name = name->AddChild(
+ new String(kind->name()->buffer(), kind->name()->size()));
+ name = name->AddChild(new String("main"));
+
+ Procedure* procedure =
+ reinterpret_cast<Procedure*>(to_patch.kernel_function());
+ procedure->function()->set_body(new ReturnStatement(new StaticGet(name)));
kustermann 2017/04/05 11:47:07 I assume the function has already a body (like nsm
Kevin Millikin (Google) 2017/04/25 18:20:29 It doesn't have a body, it's treated as if it were
+
return library;
}
}
@@ -211,7 +238,7 @@ void KernelReader::ReadLibrary(Library* kernel_library) {
toplevel_class.SetFunctions(Array::Handle(MakeFunctionsArray()));
const GrowableObjectArray& classes =
- GrowableObjectArray::Handle(I->object_store()->pending_classes());
+ GrowableObjectArray::Handle(Z, I->object_store()->pending_classes());
// Load all classes.
for (intptr_t i = 0; i < kernel_library->classes().length(); i++) {

Powered by Google App Engine
This is Rietveld 408576698