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 "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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 const int kNumArgs = 1; | 360 const int kNumArgs = 1; |
361 Dart_Handle dart_args[kNumArgs]; | 361 Dart_Handle dart_args[kNumArgs]; |
362 dart_args[0] = library_uri; | 362 dart_args[0] = library_uri; |
363 return Dart_Invoke(DartUtils::BuiltinLib(), | 363 return Dart_Invoke(DartUtils::BuiltinLib(), |
364 NewString("_libraryFilePath"), | 364 NewString("_libraryFilePath"), |
365 kNumArgs, | 365 kNumArgs, |
366 dart_args); | 366 dart_args); |
367 } | 367 } |
368 | 368 |
369 | 369 |
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 static Dart_Handle LoadDataAsync_Invoke(Dart_Handle tag, | 370 static Dart_Handle LoadDataAsync_Invoke(Dart_Handle tag, |
383 Dart_Handle url, | 371 Dart_Handle url, |
384 Dart_Handle library_url) { | 372 Dart_Handle library_url) { |
385 const int kNumArgs = 3; | 373 const int kNumArgs = 3; |
386 Dart_Handle dart_args[kNumArgs]; | 374 Dart_Handle dart_args[kNumArgs]; |
387 dart_args[0] = tag; | 375 dart_args[0] = tag; |
388 dart_args[1] = url; | 376 dart_args[1] = url; |
389 dart_args[2] = library_url; | 377 dart_args[2] = library_url; |
390 return Dart_Invoke(DartUtils::BuiltinLib(), | 378 return Dart_Invoke(DartUtils::BuiltinLib(), |
391 DartUtils::NewString("_loadDataAsync"), | 379 DartUtils::NewString("_loadDataAsync"), |
392 kNumArgs, | 380 kNumArgs, |
393 dart_args); | 381 dart_args); |
394 } | 382 } |
395 | 383 |
396 | 384 |
397 Dart_Handle DartUtils::LibraryTagHandler(Dart_LibraryTag tag, | 385 Dart_Handle DartUtils::LibraryTagHandler(Dart_LibraryTag tag, |
398 Dart_Handle library, | 386 Dart_Handle library, |
399 Dart_Handle url) { | 387 Dart_Handle url) { |
| 388 if (tag == Dart_kCanonicalizeUrl) { |
| 389 return Dart_DefaultCanonicalizeUrl(library, url); |
| 390 } |
400 if (!Dart_IsLibrary(library)) { | 391 if (!Dart_IsLibrary(library)) { |
401 return Dart_NewApiError("not a library"); | 392 return Dart_NewApiError("not a library"); |
402 } | 393 } |
403 if (!Dart_IsString(url)) { | 394 if (!Dart_IsString(url)) { |
404 return Dart_NewApiError("url is not a string"); | 395 return Dart_NewApiError("url is not a string"); |
405 } | 396 } |
406 const char* url_string = NULL; | 397 const char* url_string = NULL; |
407 Dart_Handle result = Dart_StringToCString(url, &url_string); | 398 Dart_Handle result = Dart_StringToCString(url, &url_string); |
408 if (Dart_IsError(result)) { | 399 if (Dart_IsError(result)) { |
409 return result; | 400 return result; |
410 } | 401 } |
411 Dart_Handle library_url = Dart_LibraryUrl(library); | 402 Dart_Handle library_url = Dart_LibraryUrl(library); |
412 const char* library_url_string = NULL; | 403 const char* library_url_string = NULL; |
413 result = Dart_StringToCString(library_url, &library_url_string); | 404 result = Dart_StringToCString(library_url, &library_url_string); |
414 if (Dart_IsError(result)) { | 405 if (Dart_IsError(result)) { |
415 return result; | 406 return result; |
416 } | 407 } |
417 | 408 |
418 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string); | 409 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string); |
419 bool is_dart_library = DartUtils::IsDartSchemeURL(library_url_string); | 410 bool is_dart_library = DartUtils::IsDartSchemeURL(library_url_string); |
420 | 411 |
421 // Handle canonicalization, 'import' and 'part' of 'dart:' libraries. | 412 // Handle canonicalization, 'import' and 'part' of 'dart:' libraries. |
422 if (is_dart_scheme_url || is_dart_library) { | 413 if (is_dart_scheme_url || is_dart_library) { |
423 if (tag == Dart_kCanonicalizeUrl) { | 414 if (tag == Dart_kImportTag) { |
424 // These will be handled internally. | |
425 return url; | |
426 } else if (tag == Dart_kImportTag) { | |
427 Builtin::BuiltinLibraryId id = Builtin::FindId(url_string); | 415 Builtin::BuiltinLibraryId id = Builtin::FindId(url_string); |
428 if (id == Builtin::kInvalidLibrary) { | 416 if (id == Builtin::kInvalidLibrary) { |
429 return NewError("The built-in library '%s' is not available" | 417 return NewError("The built-in library '%s' is not available" |
430 " on the stand-alone VM.\n", url_string); | 418 " on the stand-alone VM.\n", url_string); |
431 } | 419 } |
432 return Builtin::LoadLibrary(url, id); | 420 return Builtin::LoadLibrary(url, id); |
433 } else { | 421 } else { |
434 ASSERT(tag == Dart_kSourceTag); | 422 ASSERT(tag == Dart_kSourceTag); |
435 Builtin::BuiltinLibraryId id = Builtin::FindId(library_url_string); | 423 Builtin::BuiltinLibraryId id = Builtin::FindId(library_url_string); |
436 if (id == Builtin::kInvalidLibrary) { | 424 if (id == Builtin::kInvalidLibrary) { |
437 return NewError("The built-in library '%s' is not available" | 425 return NewError("The built-in library '%s' is not available" |
438 " on the stand-alone VM. Trying to load" | 426 " on the stand-alone VM. Trying to load" |
439 " '%s'.\n", library_url_string, url_string); | 427 " '%s'.\n", library_url_string, url_string); |
440 } | 428 } |
441 // Prepend the library URI to form a unique script URI for the part. | 429 // Prepend the library URI to form a unique script URI for the part. |
442 intptr_t len = snprintf(NULL, 0, "%s/%s", library_url_string, url_string); | 430 intptr_t len = snprintf(NULL, 0, "%s/%s", library_url_string, url_string); |
443 char* part_uri = reinterpret_cast<char*>(malloc(len + 1)); | 431 char* part_uri = reinterpret_cast<char*>(malloc(len + 1)); |
444 snprintf(part_uri, len + 1, "%s/%s", library_url_string, url_string); | 432 snprintf(part_uri, len + 1, "%s/%s", library_url_string, url_string); |
445 Dart_Handle part_uri_obj = DartUtils::NewString(part_uri); | 433 Dart_Handle part_uri_obj = DartUtils::NewString(part_uri); |
446 free(part_uri); | 434 free(part_uri); |
447 return Dart_LoadSource(library, | 435 return Dart_LoadSource(library, |
448 part_uri_obj, | 436 part_uri_obj, |
449 Builtin::PartSource(id, url_string), 0, 0); | 437 Builtin::PartSource(id, url_string), 0, 0); |
450 } | 438 } |
451 // All cases should have been handled above. | 439 // All cases should have been handled above. |
452 UNREACHABLE(); | 440 UNREACHABLE(); |
453 } | 441 } |
454 | 442 |
455 if (tag == Dart_kCanonicalizeUrl) { | |
456 // Resolve the url within the context of the library's URL. | |
457 return ResolveUri(library_url, url); | |
458 } | |
459 | |
460 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { | 443 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { |
461 // Load a native code shared library to use in a native extension | 444 // Load a native code shared library to use in a native extension |
462 if (tag != Dart_kImportTag) { | 445 if (tag != Dart_kImportTag) { |
463 return NewError("Dart extensions must use import: '%s'", url_string); | 446 return NewError("Dart extensions must use import: '%s'", url_string); |
464 } | 447 } |
465 Dart_Handle library_file_path = DartUtils::LibraryFilePath(library_url); | 448 Dart_Handle library_file_path = DartUtils::LibraryFilePath(library_url); |
466 const char* lib_path_str = NULL; | 449 const char* lib_path_str = NULL; |
467 Dart_StringToCString(library_file_path, &lib_path_str); | 450 Dart_StringToCString(library_file_path, &lib_path_str); |
468 const char* extension_path = DartUtils::RemoveScheme(url_string); | 451 const char* extension_path = DartUtils::RemoveScheme(url_string); |
469 if (strchr(extension_path, '/') != NULL || | 452 if (strchr(extension_path, '/') != NULL || |
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1264 new CObjectString(CObject::NewString(os_error->message())); | 1247 new CObjectString(CObject::NewString(os_error->message())); |
1265 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 1248 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
1266 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 1249 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
1267 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 1250 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
1268 result->SetAt(2, error_message); | 1251 result->SetAt(2, error_message); |
1269 return result; | 1252 return result; |
1270 } | 1253 } |
1271 | 1254 |
1272 } // namespace bin | 1255 } // namespace bin |
1273 } // namespace dart | 1256 } // namespace dart |
OLD | NEW |