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

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

Issue 14752008: Final step towards loading core library scripts directly from the sources (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « runtime/bin/dartutils.h ('k') | runtime/bin/eventhandler_patch.dart » ('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 "include/dart_api.h"
8
9 #include "platform/assert.h"
10 #include "platform/globals.h"
11
7 #include "bin/extensions.h" 12 #include "bin/extensions.h"
8 #include "bin/directory.h" 13 #include "bin/directory.h"
9 #include "bin/file.h" 14 #include "bin/file.h"
10 #include "bin/io_buffer.h" 15 #include "bin/io_buffer.h"
11 #include "include/dart_api.h" 16 #include "bin/utils.h"
12 #include "platform/assert.h"
13 #include "platform/globals.h"
14 17
15 namespace dart { 18 namespace dart {
16 namespace bin { 19 namespace bin {
17 20
18 const char* DartUtils::original_working_directory = NULL; 21 const char* DartUtils::original_working_directory = NULL;
19 const char* DartUtils::kDartScheme = "dart:"; 22 const char* DartUtils::kDartScheme = "dart:";
20 const char* DartUtils::kDartExtensionScheme = "dart-ext:"; 23 const char* DartUtils::kDartExtensionScheme = "dart-ext:";
21 const char* DartUtils::kAsyncLibURL = "dart:async"; 24 const char* DartUtils::kAsyncLibURL = "dart:async";
22 const char* DartUtils::kBuiltinLibURL = "dart:builtin"; 25 const char* DartUtils::kBuiltinLibURL = "dart:builtin";
23 const char* DartUtils::kCoreLibURL = "dart:core"; 26 const char* DartUtils::kCoreLibURL = "dart:core";
24 const char* DartUtils::kIOLibURL = "dart:io"; 27 const char* DartUtils::kIOLibURL = "dart:io";
25 const char* DartUtils::kIOLibPatchURL = "dart:io-patch"; 28 const char* DartUtils::kIOLibPatchURL = "dart:io-patch";
26 const char* DartUtils::kUriLibURL = "dart:uri"; 29 const char* DartUtils::kUriLibURL = "dart:uri";
27 const char* DartUtils::kUtfLibURL = "dart:utf";
28 30
29 const char* DartUtils::kIdFieldName = "_id"; 31 const char* DartUtils::kIdFieldName = "_id";
30 32
31 uint8_t DartUtils::magic_number[] = { 0xf5, 0xf5, 0xdc, 0xdc }; 33 uint8_t DartUtils::magic_number[] = { 0xf5, 0xf5, 0xdc, 0xdc };
32 34
33 static bool IsWindowsHost() { 35 static bool IsWindowsHost() {
34 #if defined(TARGET_OS_WINDOWS) 36 #if defined(TARGET_OS_WINDOWS)
35 return true; 37 return true;
36 #else // defined(TARGET_OS_WINDOWS) 38 #else // defined(TARGET_OS_WINDOWS)
37 return false; 39 return false;
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 return Dart_Error("not a library"); 318 return Dart_Error("not a library");
317 } 319 }
318 if (!Dart_IsString(url)) { 320 if (!Dart_IsString(url)) {
319 return Dart_Error("url is not a string"); 321 return Dart_Error("url is not a string");
320 } 322 }
321 const char* url_string = NULL; 323 const char* url_string = NULL;
322 Dart_Handle result = Dart_StringToCString(url, &url_string); 324 Dart_Handle result = Dart_StringToCString(url, &url_string);
323 if (Dart_IsError(result)) { 325 if (Dart_IsError(result)) {
324 return result; 326 return result;
325 } 327 }
328 Dart_Handle library_url = Dart_LibraryUrl(library);
329 const char* library_url_string = NULL;
330 result = Dart_StringToCString(library_url, &library_url_string);
331 if (Dart_IsError(result)) {
332 return result;
333 }
334
326 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string); 335 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string);
336 bool is_io_library = DartUtils::IsDartIOLibURL(library_url_string);
327 bool is_dart_extension_url = DartUtils::IsDartExtensionSchemeURL(url_string); 337 bool is_dart_extension_url = DartUtils::IsDartExtensionSchemeURL(url_string);
338
339 // Handle URI canonicalization requests.
328 if (tag == kCanonicalizeUrl) { 340 if (tag == kCanonicalizeUrl) {
329 // If this is a Dart Scheme URL then it is not modified as it will be 341 // If this is a Dart Scheme URL or 'part' of a io library
330 // handled by the VM internally. 342 // then it is not modified as it will be handled internally.
331 if (is_dart_scheme_url) { 343 if (is_dart_scheme_url || is_io_library) {
332 return url; 344 return url;
333 } 345 }
334 // Resolve the url within the context of the library's URL. 346 // Resolve the url within the context of the library's URL.
335 Dart_Handle builtin_lib = 347 Dart_Handle builtin_lib =
336 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); 348 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary);
337 Dart_Handle library_url = Dart_LibraryUrl(library); 349 Dart_Handle library_url = Dart_LibraryUrl(library);
338 if (Dart_IsError(library_url)) { 350 if (Dart_IsError(library_url)) {
339 return library_url; 351 return library_url;
340 } 352 }
341 return ResolveUri(library_url, url, builtin_lib); 353 return ResolveUri(library_url, url, builtin_lib);
342 } 354 }
355
356 // Handle 'import' of dart scheme URIs (i.e they start with 'dart:').
343 if (is_dart_scheme_url) { 357 if (is_dart_scheme_url) {
344 if (tag == kImportTag) { 358 if (tag == kImportTag) {
345 // Handle imports of other built-in libraries present in the SDK. 359 // Handle imports of other built-in libraries present in the SDK.
346 Builtin::BuiltinLibraryId id;
347 if (DartUtils::IsDartIOLibURL(url_string)) { 360 if (DartUtils::IsDartIOLibURL(url_string)) {
348 id = Builtin::kIOLibrary; 361 return Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary);
349 } else {
350 return Dart_Error("Do not know how to load '%s'", url_string);
351 } 362 }
352 return Builtin::LoadAndCheckLibrary(id); 363 return Dart_Error("Do not know how to load '%s'", url_string);
353 } else { 364 } else {
354 ASSERT(tag == kSourceTag); 365 ASSERT(tag == kSourceTag);
355 return Dart_Error("Unable to load source '%s' ", url_string); 366 return Dart_Error("Unable to load source '%s' ", url_string);
356 } 367 }
357 } else { 368 }
358 // Get the file path out of the url. 369
359 Dart_Handle builtin_lib = 370 // Handle 'part' of IO library.
360 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); 371 if (is_io_library) {
361 Dart_Handle file_path = FilePathFromUri(url, builtin_lib); 372 if (tag == kSourceTag) {
362 if (Dart_IsError(file_path)) { 373 return Dart_LoadSource(
363 return file_path; 374 library, url, Builtin::PartSource(Builtin::kIOLibrary, url_string));
375 } else {
376 ASSERT(tag == kImportTag);
377 return Dart_Error("Unable to import '%s' ", url_string);
364 } 378 }
365 Dart_StringToCString(file_path, &url_string);
366 } 379 }
380
381 // Handle 'import' or 'part' requests for all other URIs.
382 // Get the file path out of the url.
383 Dart_Handle builtin_lib =
384 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary);
385 Dart_Handle file_path = FilePathFromUri(url, builtin_lib);
386 if (Dart_IsError(file_path)) {
387 return file_path;
388 }
389 Dart_StringToCString(file_path, &url_string);
367 if (is_dart_extension_url) { 390 if (is_dart_extension_url) {
368 if (tag != kImportTag) { 391 if (tag != kImportTag) {
369 return Dart_Error("Dart extensions must use import: '%s'", url_string); 392 return Dart_Error("Dart extensions must use import: '%s'", url_string);
370 } 393 }
371 return Extensions::LoadExtension(url_string, library); 394 return Extensions::LoadExtension(url_string, library);
372 } 395 }
373 result = DartUtils::LoadSource(NULL, 396 result = DartUtils::LoadSource(NULL,
374 library, 397 library,
375 url, 398 url,
376 tag, 399 tag,
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 new CObjectString(CObject::NewString(os_error->message())); 812 new CObjectString(CObject::NewString(os_error->message()));
790 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); 813 CObjectArray* result = new CObjectArray(CObject::NewArray(3));
791 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); 814 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError)));
792 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); 815 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code())));
793 result->SetAt(2, error_message); 816 result->SetAt(2, error_message);
794 return result; 817 return result;
795 } 818 }
796 819
797 } // namespace bin 820 } // namespace bin
798 } // namespace dart 821 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/dartutils.h ('k') | runtime/bin/eventhandler_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698