| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/unit_test.h" | 5 #include "vm/unit_test.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include "bin/builtin.h" | 9 #include "bin/builtin.h" |
| 10 #include "bin/dartutils.h" | 10 #include "bin/dartutils.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 } | 74 } |
| 75 | 75 |
| 76 | 76 |
| 77 static bool IsImportableTestLib(const char* url_name) { | 77 static bool IsImportableTestLib(const char* url_name) { |
| 78 const char* kImportTestLibUri = "test:importable_lib"; | 78 const char* kImportTestLibUri = "test:importable_lib"; |
| 79 static const intptr_t kImportTestLibUriLen = strlen(kImportTestLibUri); | 79 static const intptr_t kImportTestLibUriLen = strlen(kImportTestLibUri); |
| 80 return (strncmp(url_name, kImportTestLibUri, kImportTestLibUriLen) == 0); | 80 return (strncmp(url_name, kImportTestLibUri, kImportTestLibUriLen) == 0); |
| 81 } | 81 } |
| 82 | 82 |
| 83 | 83 |
| 84 const char* kDefaultImportableTestLibScript = |
| 85 "importedFunc() => 'a';\n" |
| 86 "importedIntFunc() => 4;\n" |
| 87 "class ImportedMixin {\n" |
| 88 " mixinFunc() => 'mixin';\n" |
| 89 "}\n"; |
| 90 const char* importable_test_lib_script = kDefaultImportableTestLibScript; |
| 91 |
| 92 |
| 93 void TestCase::SetImportableTestLibScript(const char* source) { |
| 94 importable_test_lib_script = source; |
| 95 } |
| 96 |
| 97 |
| 98 void TestCase::RestoreImportableTestLibScript() { |
| 99 importable_test_lib_script = kDefaultImportableTestLibScript; |
| 100 } |
| 101 |
| 102 |
| 84 static Dart_Handle ImportableTestLibSource() { | 103 static Dart_Handle ImportableTestLibSource() { |
| 85 const char* kScript = | 104 return DartUtils::NewString(importable_test_lib_script); |
| 86 "importedFunc() => 'a';\n" | |
| 87 "importedIntFunc() => 4;\n" | |
| 88 "class ImportedMixin {\n" | |
| 89 " mixinFunc() => 'mixin';\n" | |
| 90 "}\n"; | |
| 91 return DartUtils::NewString(kScript); | |
| 92 } | 105 } |
| 93 | 106 |
| 94 | 107 |
| 95 #ifndef PRODUCT | 108 #ifndef PRODUCT |
| 96 static bool IsIsolateReloadTestLib(const char* url_name) { | 109 static bool IsIsolateReloadTestLib(const char* url_name) { |
| 97 const char* kIsolateReloadTestLibUri = "test:isolate_reload_helper"; | 110 const char* kIsolateReloadTestLibUri = "test:isolate_reload_helper"; |
| 98 static const intptr_t kIsolateReloadTestLibUriLen = | 111 static const intptr_t kIsolateReloadTestLibUriLen = |
| 99 strlen(kIsolateReloadTestLibUri); | 112 strlen(kIsolateReloadTestLibUri); |
| 100 return (strncmp(url_name, | 113 return (strncmp(url_name, |
| 101 kIsolateReloadTestLibUri, | 114 kIsolateReloadTestLibUri, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 } | 161 } |
| 149 if (tag == Dart_kScriptTag) { | 162 if (tag == Dart_kScriptTag) { |
| 150 // Reload request. | 163 // Reload request. |
| 151 ASSERT(script_reload_key != kUnsetThreadLocalKey); | 164 ASSERT(script_reload_key != kUnsetThreadLocalKey); |
| 152 const char* script_source = | 165 const char* script_source = |
| 153 reinterpret_cast<const char*>( | 166 reinterpret_cast<const char*>( |
| 154 OSThread::GetThreadLocal(script_reload_key)); | 167 OSThread::GetThreadLocal(script_reload_key)); |
| 155 ASSERT(script_source != NULL); | 168 ASSERT(script_source != NULL); |
| 156 OSThread::SetThreadLocal(script_reload_key, 0); | 169 OSThread::SetThreadLocal(script_reload_key, 0); |
| 157 return Dart_LoadScript(url, | 170 return Dart_LoadScript(url, |
| 171 Dart_Null(), |
| 158 NewString(script_source), | 172 NewString(script_source), |
| 159 0, | 173 0, |
| 160 0); | 174 0); |
| 161 } | 175 } |
| 162 if (!Dart_IsLibrary(library)) { | 176 if (!Dart_IsLibrary(library)) { |
| 163 return Dart_NewApiError("not a library"); | 177 return Dart_NewApiError("not a library"); |
| 164 } | 178 } |
| 165 if (!Dart_IsString(url)) { | 179 if (!Dart_IsString(url)) { |
| 166 return Dart_NewApiError("url is not a string"); | 180 return Dart_NewApiError("url is not a string"); |
| 167 } | 181 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 184 // Handle imports of other built-in libraries present in the SDK. | 198 // Handle imports of other built-in libraries present in the SDK. |
| 185 if (DartUtils::IsDartIOLibURL(url_chars)) { | 199 if (DartUtils::IsDartIOLibURL(url_chars)) { |
| 186 return Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); | 200 return Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); |
| 187 } else if (DartUtils::IsDartBuiltinLibURL(url_chars)) { | 201 } else if (DartUtils::IsDartBuiltinLibURL(url_chars)) { |
| 188 return Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 202 return Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
| 189 } else { | 203 } else { |
| 190 return DartUtils::NewError("Do not know how to load '%s'", url_chars); | 204 return DartUtils::NewError("Do not know how to load '%s'", url_chars); |
| 191 } | 205 } |
| 192 } | 206 } |
| 193 if (IsImportableTestLib(url_chars)) { | 207 if (IsImportableTestLib(url_chars)) { |
| 194 return Dart_LoadLibrary(url, ImportableTestLibSource(), 0, 0); | 208 return Dart_LoadLibrary(url, Dart_Null(), ImportableTestLibSource(), 0, 0); |
| 195 } | 209 } |
| 196 NOT_IN_PRODUCT( | 210 NOT_IN_PRODUCT( |
| 197 if (IsIsolateReloadTestLib(url_chars)) { | 211 if (IsIsolateReloadTestLib(url_chars)) { |
| 198 Dart_Handle library = | 212 Dart_Handle library = |
| 199 Dart_LoadLibrary(url, IsolateReloadTestLibSource(), 0, 0); | 213 Dart_LoadLibrary(url, Dart_Null(), IsolateReloadTestLibSource(), 0, 0); |
| 200 DART_CHECK_VALID(library); | 214 DART_CHECK_VALID(library); |
| 201 Dart_SetNativeResolver(library, IsolateReloadTestNativeResolver, 0); | 215 Dart_SetNativeResolver(library, IsolateReloadTestNativeResolver, 0); |
| 202 return library; | 216 return library; |
| 203 }) | 217 }) |
| 204 if (is_io_library) { | 218 if (is_io_library) { |
| 205 ASSERT(tag == Dart_kSourceTag); | 219 ASSERT(tag == Dart_kSourceTag); |
| 206 return Dart_LoadSource(library, | 220 return Dart_LoadSource(library, |
| 207 url, | 221 url, Dart_Null(), |
| 208 Builtin::PartSource(Builtin::kIOLibrary, | 222 Builtin::PartSource(Builtin::kIOLibrary, |
| 209 url_chars), | 223 url_chars), |
| 210 0, 0); | 224 0, 0); |
| 211 } | 225 } |
| 226 Dart_Handle resolved_url = url; |
| 227 const char* resolved_url_chars = url_chars; |
| 212 if (IsPackageSchemeURL(url_chars)) { | 228 if (IsPackageSchemeURL(url_chars)) { |
| 213 Dart_Handle resolved_uri = ResolvePackageUri(url_chars); | 229 resolved_url = ResolvePackageUri(url_chars); |
| 214 DART_CHECK_VALID(resolved_uri); | 230 DART_CHECK_VALID(resolved_url); |
| 215 url_chars = NULL; | 231 if (Dart_IsError(Dart_StringToCString(resolved_url, &resolved_url_chars))) { |
| 216 Dart_Handle result = Dart_StringToCString(resolved_uri, &url_chars); | 232 return Dart_NewApiError("unable to convert resolved uri to string"); |
| 217 if (Dart_IsError(result)) { | |
| 218 return Dart_NewApiError("accessing url characters failed"); | |
| 219 } | 233 } |
| 220 } | 234 } |
| 221 // Do sync loading since unit_test doesn't support async. | 235 // Do sync loading since unit_test doesn't support async. |
| 222 Dart_Handle source = DartUtils::ReadStringFromFile(url_chars); | 236 Dart_Handle source = DartUtils::ReadStringFromFile(resolved_url_chars); |
| 223 EXPECT_VALID(source); | 237 EXPECT_VALID(source); |
| 224 if (tag == Dart_kImportTag) { | 238 if (tag == Dart_kImportTag) { |
| 225 return Dart_LoadLibrary(url, source, 0, 0); | 239 return Dart_LoadLibrary(url, resolved_url, source, 0, 0); |
| 226 } else { | 240 } else { |
| 227 ASSERT(tag == Dart_kSourceTag); | 241 ASSERT(tag == Dart_kSourceTag); |
| 228 return Dart_LoadSource(library, url, source, 0, 0); | 242 return Dart_LoadSource(library, url, resolved_url, source, 0, 0); |
| 229 } | 243 } |
| 230 } | 244 } |
| 231 | 245 |
| 232 | 246 |
| 233 Dart_Handle TestCase::LoadTestScript(const char* script, | 247 Dart_Handle TestCase::LoadTestScript(const char* script, |
| 234 Dart_NativeEntryResolver resolver, | 248 Dart_NativeEntryResolver resolver, |
| 235 const char* lib_url, | 249 const char* lib_url, |
| 236 bool finalize_classes) { | 250 bool finalize_classes) { |
| 237 Dart_Handle url = NewString(lib_url); | 251 Dart_Handle url = NewString(lib_url); |
| 238 Dart_Handle source = NewString(script); | 252 Dart_Handle source = NewString(script); |
| 239 Dart_Handle result = Dart_SetLibraryTagHandler(LibraryTagHandler); | 253 Dart_Handle result = Dart_SetLibraryTagHandler(LibraryTagHandler); |
| 240 EXPECT_VALID(result); | 254 EXPECT_VALID(result); |
| 241 Dart_Handle lib = Dart_LoadScript(url, source, 0, 0); | 255 Dart_Handle lib = Dart_LoadScript(url, Dart_Null(), source, 0, 0); |
| 242 DART_CHECK_VALID(lib); | 256 DART_CHECK_VALID(lib); |
| 243 result = Dart_SetNativeResolver(lib, resolver, NULL); | 257 result = Dart_SetNativeResolver(lib, resolver, NULL); |
| 244 DART_CHECK_VALID(result); | 258 DART_CHECK_VALID(result); |
| 245 if (finalize_classes) { | 259 if (finalize_classes) { |
| 246 result = Dart_FinalizeLoading(false); | 260 result = Dart_FinalizeLoading(false); |
| 247 DART_CHECK_VALID(result); | 261 DART_CHECK_VALID(result); |
| 248 } | 262 } |
| 249 return lib; | 263 return lib; |
| 250 } | 264 } |
| 251 | 265 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 262 // Store the new script in TLS. | 276 // Store the new script in TLS. |
| 263 OSThread::SetThreadLocal(script_reload_key, reinterpret_cast<uword>(script)); | 277 OSThread::SetThreadLocal(script_reload_key, reinterpret_cast<uword>(script)); |
| 264 } | 278 } |
| 265 | 279 |
| 266 | 280 |
| 267 Dart_Handle TestCase::TriggerReload() { | 281 Dart_Handle TestCase::TriggerReload() { |
| 268 Isolate* isolate = Isolate::Current(); | 282 Isolate* isolate = Isolate::Current(); |
| 269 | 283 |
| 270 { | 284 { |
| 271 TransitionNativeToVM transition(Thread::Current()); | 285 TransitionNativeToVM transition(Thread::Current()); |
| 272 isolate->ReloadSources(/* dont_delete_reload_context = */ true); | 286 isolate->ReloadSources(false, // force_reload |
| 287 true); // dont_delete_reload_context |
| 273 } | 288 } |
| 274 | 289 |
| 275 return Dart_FinalizeLoading(false); | 290 return Dart_FinalizeLoading(false); |
| 276 } | 291 } |
| 277 | 292 |
| 278 | 293 |
| 279 Dart_Handle TestCase::GetReloadErrorOrRootLibrary() { | 294 Dart_Handle TestCase::GetReloadErrorOrRootLibrary() { |
| 280 Isolate* isolate = Isolate::Current(); | 295 Isolate* isolate = Isolate::Current(); |
| 281 | 296 |
| 282 if (isolate->reload_context() != NULL && | 297 if (isolate->reload_context() != NULL && |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 } | 474 } |
| 460 // Copy the remainder of in to out. | 475 // Copy the remainder of in to out. |
| 461 while (*in != '\0') { | 476 while (*in != '\0') { |
| 462 *out++ = *in++; | 477 *out++ = *in++; |
| 463 } | 478 } |
| 464 *out = '\0'; | 479 *out = '\0'; |
| 465 } | 480 } |
| 466 | 481 |
| 467 | 482 |
| 468 } // namespace dart | 483 } // namespace dart |
| OLD | NEW |