| 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" |
| 11 | 11 |
| 12 #include "platform/globals.h" | 12 #include "platform/globals.h" |
| 13 |
| 13 #include "vm/assembler.h" | 14 #include "vm/assembler.h" |
| 14 #include "vm/ast_printer.h" | 15 #include "vm/ast_printer.h" |
| 15 #include "vm/compiler.h" | 16 #include "vm/compiler.h" |
| 16 #include "vm/dart_api_impl.h" | 17 #include "vm/dart_api_impl.h" |
| 17 #include "vm/disassembler.h" | 18 #include "vm/disassembler.h" |
| 18 #include "vm/parser.h" | 19 #include "vm/parser.h" |
| 19 #include "vm/symbols.h" | 20 #include "vm/symbols.h" |
| 20 #include "vm/thread.h" | 21 #include "vm/thread.h" |
| 21 #include "vm/virtual_memory.h" | 22 #include "vm/virtual_memory.h" |
| 22 | 23 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 49 } | 50 } |
| 50 } | 51 } |
| 51 | 52 |
| 52 static const char* kPackageScheme = "package:"; | 53 static const char* kPackageScheme = "package:"; |
| 53 | 54 |
| 54 static bool IsPackageSchemeURL(const char* url_name) { | 55 static bool IsPackageSchemeURL(const char* url_name) { |
| 55 static const intptr_t kPackageSchemeLen = strlen(kPackageScheme); | 56 static const intptr_t kPackageSchemeLen = strlen(kPackageScheme); |
| 56 return (strncmp(url_name, kPackageScheme, kPackageSchemeLen) == 0); | 57 return (strncmp(url_name, kPackageScheme, kPackageSchemeLen) == 0); |
| 57 } | 58 } |
| 58 | 59 |
| 59 static Dart_Handle ResolvePackageUri(Dart_Handle builtin_lib, | 60 static Dart_Handle ResolvePackageUri(const char* uri_chars) { |
| 60 const char* uri_chars) { | 61 bin::IsolateData* isolate_data = |
| 62 reinterpret_cast<bin::IsolateData*>(Dart_CurrentIsolateData()); |
| 63 Dart_Handle builtin_lib = isolate_data->builtin_lib(); |
| 61 const int kNumArgs = 1; | 64 const int kNumArgs = 1; |
| 62 Dart_Handle dart_args[kNumArgs]; | 65 Dart_Handle dart_args[kNumArgs]; |
| 63 dart_args[0] = DartUtils::NewString(uri_chars); | 66 dart_args[0] = DartUtils::NewString(uri_chars); |
| 64 return Dart_Invoke(builtin_lib, | 67 return Dart_Invoke(builtin_lib, |
| 65 DartUtils::NewString("_filePathFromUri"), | 68 DartUtils::NewString("_filePathFromUri"), |
| 66 kNumArgs, | 69 kNumArgs, |
| 67 dart_args); | 70 dart_args); |
| 68 } | 71 } |
| 69 | 72 |
| 70 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, | 73 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 81 if (Dart_IsError(result)) { | 84 if (Dart_IsError(result)) { |
| 82 return Dart_NewApiError("accessing url characters failed"); | 85 return Dart_NewApiError("accessing url characters failed"); |
| 83 } | 86 } |
| 84 Dart_Handle library_url = Dart_LibraryUrl(library); | 87 Dart_Handle library_url = Dart_LibraryUrl(library); |
| 85 const char* library_url_string = NULL; | 88 const char* library_url_string = NULL; |
| 86 result = Dart_StringToCString(library_url, &library_url_string); | 89 result = Dart_StringToCString(library_url, &library_url_string); |
| 87 if (Dart_IsError(result)) { | 90 if (Dart_IsError(result)) { |
| 88 return result; | 91 return result; |
| 89 } | 92 } |
| 90 | 93 |
| 91 Dart_Handle builtin_lib = | |
| 92 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | |
| 93 DART_CHECK_VALID(builtin_lib); | |
| 94 | |
| 95 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_chars); | 94 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_chars); |
| 96 bool is_io_library = DartUtils::IsDartIOLibURL(library_url_string); | 95 bool is_io_library = DartUtils::IsDartIOLibURL(library_url_string); |
| 97 if (tag == Dart_kCanonicalizeUrl) { | 96 if (tag == Dart_kCanonicalizeUrl) { |
| 98 // If this is a Dart Scheme URL then it is not modified as it will be | 97 // If this is a Dart Scheme URL then it is not modified as it will be |
| 99 // handled by the VM internally. | 98 // handled by the VM internally. |
| 100 if (is_dart_scheme_url || is_io_library) { | 99 if (is_dart_scheme_url || is_io_library) { |
| 101 return url; | 100 return url; |
| 102 } | 101 } |
| 103 | 102 |
| 104 Dart_Handle library_url = Dart_LibraryUrl(library); | 103 Dart_Handle library_url = Dart_LibraryUrl(library); |
| 105 if (Dart_IsError(library_url)) { | 104 if (Dart_IsError(library_url)) { |
| 106 return library_url; | 105 return library_url; |
| 107 } | 106 } |
| 108 return DartUtils::ResolveUri(library_url, url, builtin_lib); | 107 return DartUtils::ResolveUri(library_url, url); |
| 109 } | 108 } |
| 110 if (is_dart_scheme_url) { | 109 if (is_dart_scheme_url) { |
| 111 ASSERT(tag == Dart_kImportTag); | 110 ASSERT(tag == Dart_kImportTag); |
| 112 // Handle imports of other built-in libraries present in the SDK. | 111 // Handle imports of other built-in libraries present in the SDK. |
| 113 if (DartUtils::IsDartIOLibURL(url_chars)) { | 112 if (DartUtils::IsDartIOLibURL(url_chars)) { |
| 114 return Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); | 113 return Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); |
| 115 } else if (DartUtils::IsDartBuiltinLibURL(url_chars)) { | 114 } else if (DartUtils::IsDartBuiltinLibURL(url_chars)) { |
| 116 return builtin_lib; | 115 return Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
| 117 } else { | 116 } else { |
| 118 return DartUtils::NewError("Do not know how to load '%s'", url_chars); | 117 return DartUtils::NewError("Do not know how to load '%s'", url_chars); |
| 119 } | 118 } |
| 120 } | 119 } |
| 121 if (is_io_library) { | 120 if (is_io_library) { |
| 122 ASSERT(tag == Dart_kSourceTag); | 121 ASSERT(tag == Dart_kSourceTag); |
| 123 return Dart_LoadSource(library, | 122 return Dart_LoadSource(library, |
| 124 url, | 123 url, |
| 125 Builtin::PartSource(Builtin::kIOLibrary, | 124 Builtin::PartSource(Builtin::kIOLibrary, |
| 126 url_chars), | 125 url_chars), |
| 127 0, 0); | 126 0, 0); |
| 128 } | 127 } |
| 129 if (IsPackageSchemeURL(url_chars)) { | 128 if (IsPackageSchemeURL(url_chars)) { |
| 130 Dart_Handle resolved_uri = ResolvePackageUri(builtin_lib, url_chars); | 129 Dart_Handle resolved_uri = ResolvePackageUri(url_chars); |
| 131 DART_CHECK_VALID(resolved_uri); | 130 DART_CHECK_VALID(resolved_uri); |
| 132 url_chars = NULL; | 131 url_chars = NULL; |
| 133 Dart_Handle result = Dart_StringToCString(resolved_uri, &url_chars); | 132 Dart_Handle result = Dart_StringToCString(resolved_uri, &url_chars); |
| 134 if (Dart_IsError(result)) { | 133 if (Dart_IsError(result)) { |
| 135 return Dart_NewApiError("accessing url characters failed"); | 134 return Dart_NewApiError("accessing url characters failed"); |
| 136 } | 135 } |
| 137 } | 136 } |
| 138 // Do sync loading since unit_test doesn't support async. | 137 // Do sync loading since unit_test doesn't support async. |
| 139 Dart_Handle source = DartUtils::ReadStringFromFile(url_chars); | 138 Dart_Handle source = DartUtils::ReadStringFromFile(url_chars); |
| 140 EXPECT_VALID(source); | 139 EXPECT_VALID(source); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 } | 299 } |
| 301 // Copy the remainder of in to out. | 300 // Copy the remainder of in to out. |
| 302 while (*in != '\0') { | 301 while (*in != '\0') { |
| 303 *out++ = *in++; | 302 *out++ = *in++; |
| 304 } | 303 } |
| 305 *out = '\0'; | 304 *out = '\0'; |
| 306 } | 305 } |
| 307 | 306 |
| 308 | 307 |
| 309 } // namespace dart | 308 } // namespace dart |
| OLD | NEW |