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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 2948273002: Correctly set root_library based on the application script URI instead of looking for the library t… (Closed)
Patch Set: Integrate cl from Siggi for front end change to not require a 'main' method when using the memory f… Created 3 years, 5 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
« no previous file with comments | « runtime/tests/vm/vm.status ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl.cc
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc
index b33699429fef3dc04ca5fd0d2bd464a9cafdb199..18f9280e68b3c3fd31caa4ed6b1ce046bdb3dcc4 100644
--- a/runtime/vm/dart_api_impl.cc
+++ b/runtime/vm/dart_api_impl.cc
@@ -62,6 +62,7 @@ namespace dart {
DECLARE_FLAG(bool, use_dart_frontend);
DECLARE_FLAG(bool, print_class_table);
DECLARE_FLAG(bool, verify_handles);
+DECLARE_FLAG(bool, use_dart_frontend);
#if defined(DART_NO_SNAPSHOT)
DEFINE_FLAG(bool,
check_function_fingerprints,
@@ -5006,6 +5007,22 @@ static void CompileSource(Thread* thread,
}
}
+#if !defined(DART_PRECOMPILED_RUNTIME)
+static Dart_Handle LoadKernelProgram(Thread* T,
+ const String& url,
+ void* kernel) {
+ // NOTE: Now the VM owns the [kernel_program] memory! Currently we do not
+ // free it because (similar to the token stream) it will be used to repeatedly
+ // run the `kernel::FlowGraphBuilder()`.
+ kernel::KernelReader reader(reinterpret_cast<kernel::Program*>(kernel));
+ const Object& tmp = reader.ReadProgram();
+ if (tmp.IsError()) {
+ return Api::NewHandle(T, tmp.raw());
+ }
+ return Dart_Null();
+}
+#endif
+
DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url,
Dart_Handle resolved_url,
Dart_Handle source,
@@ -5025,10 +5042,6 @@ DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url,
if (resolved_url_str.IsNull()) {
RETURN_TYPE_ERROR(Z, resolved_url, String);
}
- const String& source_str = Api::UnwrapStringHandle(Z, source);
- if (source_str.IsNull()) {
- RETURN_TYPE_ERROR(Z, source, String);
- }
Library& library = Library::Handle(Z, I->object_store()->root_library());
if (!library.IsNull()) {
const String& library_url = String::Handle(Z, library.url());
@@ -5046,6 +5059,32 @@ DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url,
CHECK_CALLBACK_STATE(T);
CHECK_COMPILATION_ALLOWED(I);
+ Dart_Handle result;
+#if !defined(DART_PRECOMPILED_RUNTIME)
+ if (FLAG_use_dart_frontend && !KernelIsolate::IsKernelIsolate(I)) {
+ if ((source == Api::Null()) || (source == NULL)) {
+ RETURN_NULL_ERROR(source);
+ }
+ void* kernel_pgm = reinterpret_cast<void*>(source);
+ result = LoadKernelProgram(T, resolved_url_str, kernel_pgm);
+ if (Dart_IsError(result)) {
+ return result;
+ }
+ library ^= Library::LookupLibrary(T, resolved_url_str);
+ if (library.IsNull()) {
+ return Api::NewError("%s: Unable to load script '%s' correctly.",
+ CURRENT_FUNC, resolved_url_str.ToCString());
+ }
+ I->object_store()->set_root_library(library);
+ return Api::NewHandle(T, library.raw());
+ }
+#endif
+
+ const String& source_str = Api::UnwrapStringHandle(Z, source);
+ if (source_str.IsNull()) {
+ RETURN_TYPE_ERROR(Z, source, String);
+ }
+
NoHeapGrowthControlScope no_growth_control;
library = Library::New(url_str);
@@ -5057,7 +5096,6 @@ DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url,
Script::Handle(Z, Script::New(url_str, resolved_url_str, source_str,
RawScript::kScriptTag));
script.SetLocationOffset(line_offset, column_offset);
- Dart_Handle result;
CompileSource(T, library, script, &result);
return result;
}
@@ -5362,21 +5400,6 @@ DART_EXPORT Dart_Handle Dart_LibraryHandleError(Dart_Handle library_in,
return error_in;
}
-#if !defined(DART_PRECOMPILED_RUNTIME)
-static Dart_Handle LoadKernelProgram(Dart_Handle url, Thread* T, void* kernel) {
- kernel::KernelReader reader(reinterpret_cast<kernel::Program*>(kernel));
- const Object& tmp = reader.ReadProgram();
- if (tmp.IsError()) {
- return Api::NewHandle(T, tmp.raw());
- }
-
- const String& url_str = Api::UnwrapStringHandle(Z, url);
- Library& library =
- Library::Handle(T->zone(), Library::LookupLibrary(T, url_str));
- return Api::NewHandle(T, library.raw());
-}
-#endif
-
DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url,
Dart_Handle resolved_url,
Dart_Handle source,
@@ -5386,19 +5409,23 @@ DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url,
DARTSCOPE(Thread::Current());
Isolate* I = T->isolate();
+ const String& url_str = Api::UnwrapStringHandle(Z, url);
+ if (url_str.IsNull()) {
+ RETURN_TYPE_ERROR(Z, url, String);
+ }
+ Dart_Handle result;
#if !defined(DART_PRECOMPILED_RUNTIME)
// Kernel isolate is loaded from script in case of dart_bootstrap
// even when FLAG_use_dart_frontend is true. Hence, do not interpret
// |source| as a kernel if the current isolate is the kernel isolate.
if (FLAG_use_dart_frontend && !KernelIsolate::IsKernelIsolate(I)) {
- return LoadKernelProgram(url, T, reinterpret_cast<void*>(source));
+ result = LoadKernelProgram(T, url_str, reinterpret_cast<void*>(source));
+ if (Dart_IsError(result)) {
+ return result;
+ }
+ return Api::NewHandle(T, Library::LookupLibrary(T, url_str));
}
#endif
-
- const String& url_str = Api::UnwrapStringHandle(Z, url);
- if (url_str.IsNull()) {
- RETURN_TYPE_ERROR(Z, url, String);
- }
if (::Dart_IsNull(resolved_url)) {
resolved_url = url;
}
@@ -5438,7 +5465,6 @@ DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url,
Script::Handle(Z, Script::New(url_str, resolved_url_str, source_str,
RawScript::kLibraryTag));
script.SetLocationOffset(line_offset, column_offset);
- Dart_Handle result;
CompileSource(T, library, script, &result);
// Propagate the error out right now.
if (::Dart_IsError(result)) {
« no previous file with comments | « runtime/tests/vm/vm.status ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698