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

Side by Side Diff: runtime/vm/unit_test.cc

Issue 2011543002: Canonicalize uris in C++ instead of Dart for the standalone embedder. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: fixz release build Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « runtime/vm/isolate_reload_test.cc ('k') | runtime/vm/uri.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 static const char* kPackageScheme = "package:"; 68 static const char* kPackageScheme = "package:";
69 69
70 70
71 static bool IsPackageSchemeURL(const char* url_name) { 71 static bool IsPackageSchemeURL(const char* url_name) {
72 static const intptr_t kPackageSchemeLen = strlen(kPackageScheme); 72 static const intptr_t kPackageSchemeLen = strlen(kPackageScheme);
73 return (strncmp(url_name, kPackageScheme, kPackageSchemeLen) == 0); 73 return (strncmp(url_name, kPackageScheme, kPackageSchemeLen) == 0);
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 = "importable_test_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 static Dart_Handle ImportableTestLibSource() { 84 static Dart_Handle ImportableTestLibSource() {
85 const char* kScript = 85 const char* kScript =
86 "importedFunc() => 'a';\n" 86 "importedFunc() => 'a';\n"
87 "importedIntFunc() => 4;\n" 87 "importedIntFunc() => 4;\n"
88 "class ImportedMixin {\n" 88 "class ImportedMixin {\n"
89 " mixinFunc() => 'mixin';\n" 89 " mixinFunc() => 'mixin';\n"
90 "}\n"; 90 "}\n";
91 return DartUtils::NewString(kScript); 91 return DartUtils::NewString(kScript);
92 } 92 }
93 93
94 94
95 static bool IsIsolateReloadTestLib(const char* url_name) { 95 static bool IsIsolateReloadTestLib(const char* url_name) {
96 const char* kIsolateReloadTestLibUri = "isolate_reload_test_helper"; 96 const char* kIsolateReloadTestLibUri = "test:isolate_reload_helper";
97 static const intptr_t kIsolateReloadTestLibUriLen = 97 static const intptr_t kIsolateReloadTestLibUriLen =
98 strlen(kIsolateReloadTestLibUri); 98 strlen(kIsolateReloadTestLibUri);
99 return (strncmp(url_name, 99 return (strncmp(url_name,
100 kIsolateReloadTestLibUri, 100 kIsolateReloadTestLibUri,
101 kIsolateReloadTestLibUriLen) == 0); 101 kIsolateReloadTestLibUriLen) == 0);
102 } 102 }
103 103
104 104
105 #ifndef PRODUCT 105 #ifndef PRODUCT
106 static Dart_Handle IsolateReloadTestLibSource() { 106 static Dart_Handle IsolateReloadTestLibSource() {
(...skipping 25 matching lines...) Expand all
132 kNumArgs, 132 kNumArgs,
133 dart_args); 133 dart_args);
134 } 134 }
135 135
136 136
137 static ThreadLocalKey script_reload_key = kUnsetThreadLocalKey; 137 static ThreadLocalKey script_reload_key = kUnsetThreadLocalKey;
138 138
139 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, 139 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag,
140 Dart_Handle library, 140 Dart_Handle library,
141 Dart_Handle url) { 141 Dart_Handle url) {
142 if (tag == Dart_kCanonicalizeUrl) {
143 return Dart_DefaultCanonicalizeUrl(library, url);
144 }
142 if (tag == Dart_kScriptTag) { 145 if (tag == Dart_kScriptTag) {
143 // Reload request. 146 // Reload request.
144 ASSERT(script_reload_key != kUnsetThreadLocalKey); 147 ASSERT(script_reload_key != kUnsetThreadLocalKey);
145 const char* script_source = 148 const char* script_source =
146 reinterpret_cast<const char*>( 149 reinterpret_cast<const char*>(
147 OSThread::GetThreadLocal(script_reload_key)); 150 OSThread::GetThreadLocal(script_reload_key));
148 ASSERT(script_source != NULL); 151 ASSERT(script_source != NULL);
149 OSThread::SetThreadLocal(script_reload_key, 0); 152 OSThread::SetThreadLocal(script_reload_key, 0);
150 return Dart_LoadScript(url, 153 return Dart_LoadScript(url,
151 NewString(script_source), 154 NewString(script_source),
(...skipping 13 matching lines...) Expand all
165 } 168 }
166 Dart_Handle library_url = Dart_LibraryUrl(library); 169 Dart_Handle library_url = Dart_LibraryUrl(library);
167 const char* library_url_string = NULL; 170 const char* library_url_string = NULL;
168 result = Dart_StringToCString(library_url, &library_url_string); 171 result = Dart_StringToCString(library_url, &library_url_string);
169 if (Dart_IsError(result)) { 172 if (Dart_IsError(result)) {
170 return result; 173 return result;
171 } 174 }
172 175
173 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_chars); 176 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_chars);
174 bool is_io_library = DartUtils::IsDartIOLibURL(library_url_string); 177 bool is_io_library = DartUtils::IsDartIOLibURL(library_url_string);
175 if (tag == Dart_kCanonicalizeUrl) {
176 // Already canonicalized.
177 if (IsImportableTestLib(url_chars) || IsIsolateReloadTestLib(url_chars)) {
178 return url;
179 }
180 // If this is a Dart Scheme URL then it is not modified as it will be
181 // handled by the VM internally.
182 if (is_dart_scheme_url || is_io_library) {
183 return url;
184 }
185
186 Dart_Handle library_url = Dart_LibraryUrl(library);
187 if (Dart_IsError(library_url)) {
188 return library_url;
189 }
190 return DartUtils::ResolveUri(library_url, url);
191 }
192 if (is_dart_scheme_url) { 178 if (is_dart_scheme_url) {
193 ASSERT(tag == Dart_kImportTag); 179 ASSERT(tag == Dart_kImportTag);
194 // Handle imports of other built-in libraries present in the SDK. 180 // Handle imports of other built-in libraries present in the SDK.
195 if (DartUtils::IsDartIOLibURL(url_chars)) { 181 if (DartUtils::IsDartIOLibURL(url_chars)) {
196 return Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); 182 return Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary);
197 } else if (DartUtils::IsDartBuiltinLibURL(url_chars)) { 183 } else if (DartUtils::IsDartBuiltinLibURL(url_chars)) {
198 return Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); 184 return Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary);
199 } else { 185 } else {
200 return DartUtils::NewError("Do not know how to load '%s'", url_chars); 186 return DartUtils::NewError("Do not know how to load '%s'", url_chars);
201 } 187 }
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 } 447 }
462 // Copy the remainder of in to out. 448 // Copy the remainder of in to out.
463 while (*in != '\0') { 449 while (*in != '\0') {
464 *out++ = *in++; 450 *out++ = *in++;
465 } 451 }
466 *out = '\0'; 452 *out = '\0';
467 } 453 }
468 454
469 455
470 } // namespace dart 456 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/isolate_reload_test.cc ('k') | runtime/vm/uri.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698