| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 if (Dart_IsError(result)) { | 63 if (Dart_IsError(result)) { |
| 64 return Dart_NewApiError("accessing url characters failed"); | 64 return Dart_NewApiError("accessing url characters failed"); |
| 65 } | 65 } |
| 66 Dart_Handle library_url = Dart_LibraryUrl(library); | 66 Dart_Handle library_url = Dart_LibraryUrl(library); |
| 67 const char* library_url_string = NULL; | 67 const char* library_url_string = NULL; |
| 68 result = Dart_StringToCString(library_url, &library_url_string); | 68 result = Dart_StringToCString(library_url, &library_url_string); |
| 69 if (Dart_IsError(result)) { | 69 if (Dart_IsError(result)) { |
| 70 return result; | 70 return result; |
| 71 } | 71 } |
| 72 | 72 |
| 73 Dart_Handle builtin_lib = |
| 74 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
| 75 DART_CHECK_VALID(builtin_lib); |
| 76 |
| 73 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_chars); | 77 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_chars); |
| 74 bool is_io_library = DartUtils::IsDartIOLibURL(library_url_string); | 78 bool is_io_library = DartUtils::IsDartIOLibURL(library_url_string); |
| 75 if (tag == Dart_kCanonicalizeUrl) { | 79 if (tag == Dart_kCanonicalizeUrl) { |
| 76 // If this is a Dart Scheme URL then it is not modified as it will be | 80 // If this is a Dart Scheme URL then it is not modified as it will be |
| 77 // handled by the VM internally. | 81 // handled by the VM internally. |
| 78 if (is_dart_scheme_url || is_io_library) { | 82 if (is_dart_scheme_url || is_io_library) { |
| 79 return url; | 83 return url; |
| 80 } | 84 } |
| 81 Dart_Handle builtin_lib = | |
| 82 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | |
| 83 DART_CHECK_VALID(builtin_lib); | |
| 84 | 85 |
| 85 Dart_Handle library_url = Dart_LibraryUrl(library); | 86 Dart_Handle library_url = Dart_LibraryUrl(library); |
| 86 if (Dart_IsError(library_url)) { | 87 if (Dart_IsError(library_url)) { |
| 87 return library_url; | 88 return library_url; |
| 88 } | 89 } |
| 89 return DartUtils::ResolveUri(library_url, url, builtin_lib); | 90 return DartUtils::ResolveUri(library_url, url, builtin_lib); |
| 90 } | 91 } |
| 91 if (is_dart_scheme_url) { | 92 if (is_dart_scheme_url) { |
| 92 ASSERT(tag == Dart_kImportTag); | 93 ASSERT(tag == Dart_kImportTag); |
| 93 // Handle imports of other built-in libraries present in the SDK. | 94 // Handle imports of other built-in libraries present in the SDK. |
| 94 if (DartUtils::IsDartIOLibURL(url_chars)) { | 95 if (DartUtils::IsDartIOLibURL(url_chars)) { |
| 95 return Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); | 96 return Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); |
| 96 } else if (DartUtils::IsDartBuiltinLibURL(url_chars)) { | 97 } else if (DartUtils::IsDartBuiltinLibURL(url_chars)) { |
| 97 return Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 98 return builtin_lib; |
| 98 } else { | 99 } else { |
| 99 return DartUtils::NewError("Do not know how to load '%s'", url_chars); | 100 return DartUtils::NewError("Do not know how to load '%s'", url_chars); |
| 100 } | 101 } |
| 101 } | 102 } |
| 102 if (is_io_library) { | 103 if (is_io_library) { |
| 103 ASSERT(tag == Dart_kSourceTag); | 104 ASSERT(tag == Dart_kSourceTag); |
| 104 return Dart_LoadSource(library, | 105 return Dart_LoadSource(library, |
| 105 url, | 106 url, |
| 106 Builtin::PartSource(Builtin::kIOLibrary, | 107 Builtin::PartSource(Builtin::kIOLibrary, |
| 107 url_chars), | 108 url_chars), |
| 108 0, 0); | 109 0, 0); |
| 109 } | 110 } |
| 110 return DartUtils::LoadSource(library, url, tag, url_chars); | 111 // Do sync loading since unit_test doesn't support async. |
| 112 Dart_Handle source = DartUtils::ReadStringFromFile(url_chars); |
| 113 EXPECT_VALID(source); |
| 114 if (tag == Dart_kImportTag) { |
| 115 return Dart_LoadLibrary(url, source, 0, 0); |
| 116 } else { |
| 117 ASSERT(tag == Dart_kSourceTag); |
| 118 return Dart_LoadSource(library, url, source, 0, 0); |
| 119 } |
| 111 } | 120 } |
| 112 | 121 |
| 113 | 122 |
| 114 Dart_Handle TestCase::LoadTestScript(const char* script, | 123 Dart_Handle TestCase::LoadTestScript(const char* script, |
| 115 Dart_NativeEntryResolver resolver, | 124 Dart_NativeEntryResolver resolver, |
| 116 const char* lib_url, | 125 const char* lib_url, |
| 117 bool finalize_classes) { | 126 bool finalize_classes) { |
| 118 Dart_Handle url = NewString(lib_url); | 127 Dart_Handle url = NewString(lib_url); |
| 119 Dart_Handle source = NewString(script); | 128 Dart_Handle source = NewString(script); |
| 120 Dart_Handle result = Dart_SetLibraryTagHandler(LibraryTagHandler); | 129 Dart_Handle result = Dart_SetLibraryTagHandler(LibraryTagHandler); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 Isolate* isolate = Isolate::Current(); | 256 Isolate* isolate = Isolate::Current(); |
| 248 ASSERT(isolate != NULL); | 257 ASSERT(isolate != NULL); |
| 249 ASSERT(ClassFinalizer::AllClassesFinalized()); | 258 ASSERT(ClassFinalizer::AllClassesFinalized()); |
| 250 const Error& error = Error::Handle(Compiler::CompileFunction(isolate, | 259 const Error& error = Error::Handle(Compiler::CompileFunction(isolate, |
| 251 function)); | 260 function)); |
| 252 return error.IsNull(); | 261 return error.IsNull(); |
| 253 } | 262 } |
| 254 | 263 |
| 255 | 264 |
| 256 } // namespace dart | 265 } // namespace dart |
| OLD | NEW |