Index: runtime/vm/unit_test.cc |
diff --git a/runtime/vm/unit_test.cc b/runtime/vm/unit_test.cc |
index f7e71d73a7c5945224f5a4c0028c0da20232671b..e49a3d3570d9e0d38d25acfebb43fa640d3556e7 100644 |
--- a/runtime/vm/unit_test.cc |
+++ b/runtime/vm/unit_test.cc |
@@ -164,12 +164,11 @@ static Dart_Handle ResolvePackageUri(const char* uri_chars) { |
} |
static ThreadLocalKey script_reload_key = kUnsetThreadLocalKey; |
-static ThreadLocalKey kernel_reload_key = kUnsetThreadLocalKey; |
char* TestCase::CompileTestScriptWithDFE(const char* url, |
const char* source, |
- void** kernel_pgm, |
- bool incrementally) { |
+ void** kernel_pgm) { |
+ Zone* zone = Thread::Current()->zone(); |
// clang-format off |
Dart_SourceFile sourcefiles[] = { |
{ |
@@ -179,19 +178,9 @@ char* TestCase::CompileTestScriptWithDFE(const char* url, |
"file:///.packages", "untitled:/" |
}}; |
// clang-format on |
- return CompileTestScriptWithDFE(url, |
- sizeof(sourcefiles) / sizeof(Dart_SourceFile), |
- sourcefiles, kernel_pgm, incrementally); |
-} |
- |
-char* TestCase::CompileTestScriptWithDFE(const char* url, |
- int sourcefiles_count, |
- Dart_SourceFile sourcefiles[], |
- void** kernel_pgm, |
- bool incrementally) { |
- Zone* zone = Thread::Current()->zone(); |
- Dart_KernelCompilationResult compilation_result = Dart_CompileSourcesToKernel( |
- url, sourcefiles_count, sourcefiles, incrementally); |
+ int sourcefiles_count = sizeof(sourcefiles) / sizeof(Dart_SourceFile); |
+ Dart_KernelCompilationResult compilation_result = |
+ Dart_CompileSourcesToKernel(url, sourcefiles_count, sourcefiles); |
if (compilation_result.status != Dart_KernelCompilationStatus_Ok) { |
return OS::SCreate(zone, "Compilation failed %s", compilation_result.error); |
@@ -213,35 +202,25 @@ static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, |
Dart_Handle url) { |
if (FLAG_use_dart_frontend) { |
// Reload request. |
- |
+ ASSERT(script_reload_key != kUnsetThreadLocalKey); |
+ const char* script_source = reinterpret_cast<const char*>( |
+ OSThread::GetThreadLocal(script_reload_key)); |
+ ASSERT(script_source != NULL); |
+ OSThread::SetThreadLocal(script_reload_key, 0); |
const char* urlstr = NULL; |
Dart_Handle result = Dart_StringToCString(url, &urlstr); |
if (Dart_IsError(result)) { |
return Dart_NewApiError("accessing url characters failed"); |
} |
- |
- // Updated library either arrives as dart source or as |
- // a precompiled kernel binary. |
void* kernel_pgm; |
- if (script_reload_key != kUnsetThreadLocalKey) { |
- const char* script_source = reinterpret_cast<const char*>( |
- OSThread::GetThreadLocal(script_reload_key)); |
- ASSERT(script_source != NULL); |
- OSThread::SetThreadLocal(script_reload_key, 0); |
- char* error = TestCase::CompileTestScriptWithDFE(urlstr, script_source, |
- &kernel_pgm); |
- if (error != NULL) { |
- return Dart_NewApiError(error); |
- } |
+ char* error = |
+ TestCase::CompileTestScriptWithDFE(urlstr, script_source, &kernel_pgm); |
+ if (error == NULL) { |
+ return Dart_LoadScript(url, Dart_Null(), |
+ reinterpret_cast<Dart_Handle>(kernel_pgm), 0, 0); |
} else { |
- ASSERT(kernel_reload_key != kUnsetThreadLocalKey); |
- kernel_pgm = |
- reinterpret_cast<void*>(OSThread::GetThreadLocal(kernel_reload_key)); |
- ASSERT(kernel_pgm != NULL); |
- OSThread::SetThreadLocal(kernel_reload_key, 0); |
+ return Dart_NewApiError(error); |
} |
- return Dart_LoadScript(url, Dart_Null(), |
- reinterpret_cast<Dart_Handle>(kernel_pgm), 0, 0); |
} |
if (tag == Dart_kCanonicalizeUrl) { |
Dart_Handle library_url = Dart_LibraryUrl(library); |
@@ -349,47 +328,45 @@ static Dart_Handle LoadTestScriptWithVMParser(const char* script, |
return lib; |
} |
-Dart_Handle TestCase::LoadTestScript(const char* script, |
- Dart_NativeEntryResolver resolver, |
- const char* lib_url, |
- bool finalize_classes) { |
- return FLAG_use_dart_frontend |
- ? LoadTestScriptWithDFE( |
- 1, |
- (Dart_SourceFile[1]){{OS::SCreate(Thread::Current()->zone(), |
- "file:///%s", lib_url), |
- script}}, |
- resolver, finalize_classes) |
- : LoadTestScriptWithVMParser(script, resolver, lib_url, |
- finalize_classes); |
-} |
- |
-Dart_Handle TestCase::LoadTestScriptWithDFE(int sourcefiles_count, |
- Dart_SourceFile sourcefiles[], |
- Dart_NativeEntryResolver resolver, |
- bool finalize, |
- bool incrementally) { |
- // First script is the main script. |
- Dart_Handle url = NewString(sourcefiles[0].uri); |
+static Dart_Handle LoadTestScriptWithDFE(const char* script, |
+ Dart_NativeEntryResolver resolver, |
+ const char* lib_url, |
+ bool finalize_classes) { |
+ Dart_Handle url = NewString(lib_url); |
Dart_Handle result = Dart_SetLibraryTagHandler(LibraryTagHandler); |
EXPECT_VALID(result); |
void* kernel_pgm = NULL; |
- char* error = TestCase::CompileTestScriptWithDFE( |
- sourcefiles[0].uri, sourcefiles_count, sourcefiles, &kernel_pgm, |
- incrementally); |
- if (error != NULL) { |
+ char* error = |
+ TestCase::CompileTestScriptWithDFE(lib_url, script, &kernel_pgm); |
+ if (error == NULL) { |
+ Dart_Handle lib = Dart_LoadScript( |
+ url, Dart_Null(), reinterpret_cast<Dart_Handle>(kernel_pgm), 0, 0); |
+ DART_CHECK_VALID(lib); |
+ result = Dart_SetNativeResolver(lib, resolver, NULL); |
+ DART_CHECK_VALID(result); |
+ if (finalize_classes) { |
+ result = Dart_FinalizeLoading(false); |
+ DART_CHECK_VALID(result); |
+ } |
+ return lib; |
+ } else { |
return Dart_NewApiError(error); |
} |
- Dart_Handle lib = Dart_LoadScript( |
- url, Dart_Null(), reinterpret_cast<Dart_Handle>(kernel_pgm), 0, 0); |
- DART_CHECK_VALID(lib); |
- result = Dart_SetNativeResolver(lib, resolver, NULL); |
- DART_CHECK_VALID(result); |
- if (finalize) { |
- result = Dart_FinalizeLoading(false); |
- DART_CHECK_VALID(result); |
+} |
+ |
+Dart_Handle TestCase::LoadTestScript(const char* script, |
+ Dart_NativeEntryResolver resolver, |
+ const char* lib_url, |
+ bool finalize_classes) { |
+ if (!FLAG_use_dart_frontend) { |
+ return LoadTestScriptWithVMParser(script, resolver, lib_url, |
+ finalize_classes); |
+ } else { |
+ Zone* zone = Thread::Current()->zone(); |
+ char* resolved_lib_url = OS::SCreate(zone, "file:///%s", lib_url); |
+ return LoadTestScriptWithDFE(script, resolver, resolved_lib_url, |
+ finalize_classes); |
} |
- return lib; |
} |
#ifndef PRODUCT |
@@ -404,16 +381,6 @@ void TestCase::SetReloadTestScript(const char* script) { |
OSThread::SetThreadLocal(script_reload_key, reinterpret_cast<uword>(script)); |
} |
-void TestCase::SetReloadTestKernel(const void* kernel) { |
- if (kernel_reload_key == kUnsetThreadLocalKey) { |
- kernel_reload_key = OSThread::CreateThreadLocal(); |
- } |
- ASSERT(kernel_reload_key != kUnsetThreadLocalKey); |
- ASSERT(OSThread::GetThreadLocal(kernel_reload_key) == 0); |
- // Store the new script in TLS. |
- OSThread::SetThreadLocal(kernel_reload_key, reinterpret_cast<uword>(kernel)); |
-} |
- |
Dart_Handle TestCase::TriggerReload() { |
Isolate* isolate = Isolate::Current(); |
JSONStream js; |
@@ -468,28 +435,6 @@ Dart_Handle TestCase::ReloadTestScript(const char* script) { |
return result; |
} |
-Dart_Handle TestCase::ReloadTestKernel(const void* kernel) { |
- SetReloadTestKernel(kernel); |
- |
- Dart_Handle result = TriggerReload(); |
- if (Dart_IsError(result)) { |
- return result; |
- } |
- |
- result = GetReloadErrorOrRootLibrary(); |
- |
- { |
- Thread* thread = Thread::Current(); |
- TransitionNativeToVM transition(thread); |
- Isolate* isolate = thread->isolate(); |
- if (isolate->reload_context() != NULL) { |
- isolate->DeleteReloadContext(); |
- } |
- } |
- |
- return result; |
-} |
- |
#endif // !PRODUCT |
Dart_Handle TestCase::LoadCoreTestScript(const char* script, |