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

Side by Side Diff: runtime/bin/dartutils.cc

Issue 2073173002: Use the new loader mechanism to resolve URIs and load script files in gen_snapshot. This should all… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address issues that were found while testing with the flutter engine. 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/bin/dartutils.h ('k') | runtime/bin/gen_snapshot.cc » ('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 "bin/dartutils.h" 5 #include "bin/dartutils.h"
6 6
7 #include "bin/crypto.h" 7 #include "bin/crypto.h"
8 #include "bin/directory.h" 8 #include "bin/directory.h"
9 #include "bin/extensions.h" 9 #include "bin/extensions.h"
10 #include "bin/file.h" 10 #include "bin/file.h"
(...skipping 14 matching lines...) Expand all
25 Dart_Handle __handle = handle; \ 25 Dart_Handle __handle = handle; \
26 if (Dart_IsError((__handle))) { \ 26 if (Dart_IsError((__handle))) { \
27 return __handle; \ 27 return __handle; \
28 } \ 28 } \
29 } 29 }
30 30
31 namespace dart { 31 namespace dart {
32 namespace bin { 32 namespace bin {
33 33
34 const char* DartUtils::original_working_directory = NULL; 34 const char* DartUtils::original_working_directory = NULL;
35 CommandLineOptions* DartUtils::url_mapping = NULL;
35 const char* const DartUtils::kDartScheme = "dart:"; 36 const char* const DartUtils::kDartScheme = "dart:";
36 const char* const DartUtils::kDartExtensionScheme = "dart-ext:"; 37 const char* const DartUtils::kDartExtensionScheme = "dart-ext:";
37 const char* const DartUtils::kAsyncLibURL = "dart:async"; 38 const char* const DartUtils::kAsyncLibURL = "dart:async";
38 const char* const DartUtils::kBuiltinLibURL = "dart:_builtin"; 39 const char* const DartUtils::kBuiltinLibURL = "dart:_builtin";
39 const char* const DartUtils::kCoreLibURL = "dart:core"; 40 const char* const DartUtils::kCoreLibURL = "dart:core";
40 const char* const DartUtils::kInternalLibURL = "dart:_internal"; 41 const char* const DartUtils::kInternalLibURL = "dart:_internal";
41 const char* const DartUtils::kIsolateLibURL = "dart:isolate"; 42 const char* const DartUtils::kIsolateLibURL = "dart:isolate";
42 const char* const DartUtils::kIOLibURL = "dart:io"; 43 const char* const DartUtils::kIOLibURL = "dart:io";
43 const char* const DartUtils::kIOLibPatchURL = "dart:io-patch"; 44 const char* const DartUtils::kIOLibPatchURL = "dart:io-patch";
44 const char* const DartUtils::kUriLibURL = "dart:uri"; 45 const char* const DartUtils::kUriLibURL = "dart:uri";
45 const char* const DartUtils::kHttpScheme = "http:"; 46 const char* const DartUtils::kHttpScheme = "http:";
46 const char* const DartUtils::kVMServiceLibURL = "dart:vmservice"; 47 const char* const DartUtils::kVMServiceLibURL = "dart:vmservice";
47 48
48 const uint8_t DartUtils::magic_number[] = { 0xf5, 0xf5, 0xdc, 0xdc }; 49 const uint8_t DartUtils::magic_number[] = { 0xf5, 0xf5, 0xdc, 0xdc };
49 50
51
50 static bool IsWindowsHost() { 52 static bool IsWindowsHost() {
51 #if defined(TARGET_OS_WINDOWS) 53 #if defined(TARGET_OS_WINDOWS)
52 return true; 54 return true;
53 #else // defined(TARGET_OS_WINDOWS) 55 #else // defined(TARGET_OS_WINDOWS)
54 return false; 56 return false;
55 #endif // defined(TARGET_OS_WINDOWS) 57 #endif // defined(TARGET_OS_WINDOWS)
56 } 58 }
57 59
58 60
59 const char* DartUtils::MapLibraryUrl(CommandLineOptions* url_mapping, 61 const char* DartUtils::MapLibraryUrl(const char* url_string) {
60 const char* url_string) {
61 ASSERT(url_mapping != NULL); 62 ASSERT(url_mapping != NULL);
62 // We need to check if the passed in url is found in the url_mapping array, 63 // We need to check if the passed in url is found in the url_mapping array,
63 // in that case use the mapped entry. 64 // in that case use the mapped entry.
64 intptr_t len = strlen(url_string); 65 intptr_t len = strlen(url_string);
65 for (intptr_t idx = 0; idx < url_mapping->count(); idx++) { 66 for (intptr_t idx = 0; idx < url_mapping->count(); idx++) {
66 const char* url_name = url_mapping->GetArgument(idx); 67 const char* url_name = url_mapping->GetArgument(idx);
67 if (!strncmp(url_string, url_name, len) && (url_name[len] == ',')) { 68 if (!strncmp(url_string, url_name, len) && (url_name[len] == ',')) {
68 const char* url_mapped_name = url_name + len + 1; 69 const char* url_mapped_name = url_name + len + 1;
69 if (strlen(url_mapped_name) != 0) { 70 if (strlen(url_mapped_name) != 0) {
70 return url_mapped_name; // Found a mapping for this URL. 71 return url_mapped_name; // Found a mapping for this URL.
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 328
328 Dart_Handle DartUtils::SetWorkingDirectory() { 329 Dart_Handle DartUtils::SetWorkingDirectory() {
329 IsolateData* isolate_data = 330 IsolateData* isolate_data =
330 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); 331 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData());
331 Dart_Handle builtin_lib = isolate_data->builtin_lib(); 332 Dart_Handle builtin_lib = isolate_data->builtin_lib();
332 Dart_Handle directory = NewString(original_working_directory); 333 Dart_Handle directory = NewString(original_working_directory);
333 return SingleArgDart_Invoke(builtin_lib, "_setWorkingDirectory", directory); 334 return SingleArgDart_Invoke(builtin_lib, "_setWorkingDirectory", directory);
334 } 335 }
335 336
336 337
337 Dart_Handle DartUtils::ResolveUriInWorkingDirectory(Dart_Handle script_uri) {
338 const int kNumArgs = 1;
339 Dart_Handle dart_args[kNumArgs];
340 dart_args[0] = script_uri;
341 return Dart_Invoke(DartUtils::BuiltinLib(),
342 NewString("_resolveInWorkingDirectory"),
343 kNumArgs,
344 dart_args);
345 }
346
347
348 Dart_Handle DartUtils::FilePathFromUri(Dart_Handle script_uri) {
349 const int kNumArgs = 1;
350 Dart_Handle dart_args[kNumArgs];
351 dart_args[0] = script_uri;
352 return Dart_Invoke(DartUtils::BuiltinLib(),
353 NewString("_filePathFromUri"),
354 kNumArgs,
355 dart_args);
356 }
357
358
359 Dart_Handle DartUtils::LibraryFilePath(Dart_Handle library_uri) { 338 Dart_Handle DartUtils::LibraryFilePath(Dart_Handle library_uri) {
360 const int kNumArgs = 1; 339 const int kNumArgs = 1;
361 Dart_Handle dart_args[kNumArgs]; 340 Dart_Handle dart_args[kNumArgs];
362 dart_args[0] = library_uri; 341 dart_args[0] = library_uri;
363 return Dart_Invoke(DartUtils::BuiltinLib(), 342 return Dart_Invoke(DartUtils::BuiltinLib(),
364 NewString("_libraryFilePath"), 343 NewString("_libraryFilePath"),
365 kNumArgs, 344 kNumArgs,
366 dart_args); 345 dart_args);
367 } 346 }
368 347
369 348
370 Dart_Handle DartUtils::ResolveUri(Dart_Handle library_url, Dart_Handle url) {
371 const int kNumArgs = 2;
372 Dart_Handle dart_args[kNumArgs];
373 dart_args[0] = library_url;
374 dart_args[1] = url;
375 return Dart_Invoke(DartUtils::BuiltinLib(),
376 NewString("_resolveUri"),
377 kNumArgs,
378 dart_args);
379 }
380
381
382 Dart_Handle DartUtils::ResolveScript(Dart_Handle url) { 349 Dart_Handle DartUtils::ResolveScript(Dart_Handle url) {
383 const int kNumArgs = 1; 350 const int kNumArgs = 1;
384 Dart_Handle dart_args[kNumArgs]; 351 Dart_Handle dart_args[kNumArgs];
385 dart_args[0] = url; 352 dart_args[0] = url;
386 return Dart_Invoke(DartUtils::BuiltinLib(), 353 return Dart_Invoke(DartUtils::BuiltinLib(),
387 NewString("_resolveScriptUri"), 354 NewString("_resolveScriptUri"),
388 kNumArgs, 355 kNumArgs,
389 dart_args); 356 dart_args);
390 } 357 }
391 358
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 new CObjectString(CObject::NewString(os_error->message())); 1237 new CObjectString(CObject::NewString(os_error->message()));
1271 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); 1238 CObjectArray* result = new CObjectArray(CObject::NewArray(3));
1272 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); 1239 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError)));
1273 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); 1240 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code())));
1274 result->SetAt(2, error_message); 1241 result->SetAt(2, error_message);
1275 return result; 1242 return result;
1276 } 1243 }
1277 1244
1278 } // namespace bin 1245 } // namespace bin
1279 } // namespace dart 1246 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/dartutils.h ('k') | runtime/bin/gen_snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698