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

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

Issue 2081853004: Do not use Dart_DefaultCanonicalizeUrl for resolving a script uri in the current working directory … (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Do not use Dart_DefaultCanonicalizeUrl for resolving a script uri in the current working directory … 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.cc ('k') | no next file » | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 // Generate a snapshot file after loading all the scripts specified on the 5 // Generate a snapshot file after loading all the scripts specified on the
6 // command line. 6 // command line.
7 7
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 result = Dart_NewStringFromUTF8(payload, payload_length); 444 result = Dart_NewStringFromUTF8(payload, payload_length);
445 free(payload); 445 free(payload);
446 } else { 446 } else {
447 result = DartUtils::NewString(result_string); 447 result = DartUtils::NewString(result_string);
448 free(result_string); 448 free(result_string);
449 } 449 }
450 return result; 450 return result;
451 } 451 }
452 452
453 453
454 static Dart_Handle ResolveUriInWorkingDirectory(const char* script_uri) {
455 bool failed = false;
456 char* result_string = NULL;
457
458 {
459 UriResolverIsolateScope scope;
460
461 // Run DartUtils::ResolveUriInWorkingDirectory in context of uri resolver
462 // isolate.
463 Dart_Handle result = DartUtils::ResolveUriInWorkingDirectory(
464 DartUtils::NewString(script_uri));
465 if (Dart_IsError(result)) {
466 failed = true;
467 result_string = strdup(Dart_GetError(result));
468 } else {
469 result_string = strdup(DartUtils::GetStringValue(result));
470 }
471 }
472
473 Dart_Handle result = failed ? Dart_NewApiError(result_string) :
474 DartUtils::NewString(result_string);
475 free(result_string);
476 return result;
477 }
478
479
454 static Dart_Handle LoadSnapshotCreationScript(const char* script_name) { 480 static Dart_Handle LoadSnapshotCreationScript(const char* script_name) {
455 // First resolve the specified script uri with respect to the original 481 // First resolve the specified script uri with respect to the original
456 // working directory. 482 // working directory.
457 Dart_Handle resolved_uri = Dart_DefaultCanonicalizeUrl( 483 Dart_Handle resolved_uri = ResolveUriInWorkingDirectory(script_name);
458 DartUtils::GetCanonicalizableWorkingDirectory(),
459 Dart_NewStringFromCString(script_name));
460 if (Dart_IsError(resolved_uri)) { 484 if (Dart_IsError(resolved_uri)) {
461 return resolved_uri; 485 return resolved_uri;
462 } 486 }
463 // Now load the contents of the specified uri. 487 // Now load the contents of the specified uri.
464 const char* resolved_uri_string = DartUtils::GetStringValue(resolved_uri); 488 const char* resolved_uri_string = DartUtils::GetStringValue(resolved_uri);
465 Dart_Handle source = LoadUrlContents(resolved_uri_string); 489 Dart_Handle source = LoadUrlContents(resolved_uri_string);
466 if (Dart_IsError(source)) { 490 if (Dart_IsError(source)) {
467 return source; 491 return source;
468 } 492 }
469 if (IsSnapshottingForPrecompilation()) { 493 if (IsSnapshottingForPrecompilation()) {
(...skipping 22 matching lines...) Expand all
492 return Dart_NewApiError("not a library"); 516 return Dart_NewApiError("not a library");
493 } 517 }
494 Dart_Handle library_url = Dart_LibraryUrl(library); 518 Dart_Handle library_url = Dart_LibraryUrl(library);
495 if (Dart_IsError(library_url)) { 519 if (Dart_IsError(library_url)) {
496 return Dart_NewApiError("accessing library url failed"); 520 return Dart_NewApiError("accessing library url failed");
497 } 521 }
498 const char* library_url_string = DartUtils::GetStringValue(library_url); 522 const char* library_url_string = DartUtils::GetStringValue(library_url);
499 const char* mapped_library_url_string = DartUtils::MapLibraryUrl( 523 const char* mapped_library_url_string = DartUtils::MapLibraryUrl(
500 library_url_string); 524 library_url_string);
501 if (mapped_library_url_string != NULL) { 525 if (mapped_library_url_string != NULL) {
502 library_url = Dart_DefaultCanonicalizeUrl( 526 library_url = ResolveUriInWorkingDirectory(mapped_library_url_string);
503 DartUtils::GetCanonicalizableWorkingDirectory(),
504 Dart_NewStringFromCString(mapped_library_url_string));
505 library_url_string = DartUtils::GetStringValue(library_url); 527 library_url_string = DartUtils::GetStringValue(library_url);
506 } 528 }
507 529
508 if (!Dart_IsString(url)) { 530 if (!Dart_IsString(url)) {
509 return Dart_NewApiError("url is not a string"); 531 return Dart_NewApiError("url is not a string");
510 } 532 }
511 const char* url_string = DartUtils::GetStringValue(url); 533 const char* url_string = DartUtils::GetStringValue(url);
512 const char* mapped_url_string = DartUtils::MapLibraryUrl(url_string); 534 const char* mapped_url_string = DartUtils::MapLibraryUrl(url_string);
513 535
514 Builtin::BuiltinLibraryId libraryBuiltinId = BuiltinId(library_url_string); 536 Builtin::BuiltinLibraryId libraryBuiltinId = BuiltinId(library_url_string);
(...skipping 24 matching lines...) Expand all
539 return Dart_LoadSource(library, url, 561 return Dart_LoadSource(library, url,
540 Builtin::PartSource(libraryBuiltinId, url_string), 0, 0); 562 Builtin::PartSource(libraryBuiltinId, url_string), 0, 0);
541 } 563 }
542 ASSERT(tag == Dart_kImportTag); 564 ASSERT(tag == Dart_kImportTag);
543 return DartUtils::NewError("Unable to import '%s' ", url_string); 565 return DartUtils::NewError("Unable to import '%s' ", url_string);
544 } 566 }
545 567
546 Dart_Handle resolved_url = url; 568 Dart_Handle resolved_url = url;
547 if (mapped_url_string != NULL) { 569 if (mapped_url_string != NULL) {
548 // Mapped urls are relative to working directory. 570 // Mapped urls are relative to working directory.
549 resolved_url = Dart_DefaultCanonicalizeUrl( 571 resolved_url = ResolveUriInWorkingDirectory(mapped_url_string);
550 DartUtils::GetCanonicalizableWorkingDirectory(),
551 Dart_NewStringFromCString(mapped_url_string));
552 if (Dart_IsError(resolved_url)) { 572 if (Dart_IsError(resolved_url)) {
553 return resolved_url; 573 return resolved_url;
554 } 574 }
555 } 575 }
556 const char* resolved_uri_string = DartUtils::GetStringValue(resolved_url); 576 const char* resolved_uri_string = DartUtils::GetStringValue(resolved_url);
557 Dart_Handle source = LoadUrlContents(resolved_uri_string); 577 Dart_Handle source = LoadUrlContents(resolved_uri_string);
558 if (Dart_IsError(source)) { 578 if (Dart_IsError(source)) {
559 return source; 579 return source;
560 } 580 }
561 if (tag == Dart_kImportTag) { 581 if (tag == Dart_kImportTag) {
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 EventHandler::Stop(); 1350 EventHandler::Stop();
1331 return 0; 1351 return 0;
1332 } 1352 }
1333 1353
1334 } // namespace bin 1354 } // namespace bin
1335 } // namespace dart 1355 } // namespace dart
1336 1356
1337 int main(int argc, char** argv) { 1357 int main(int argc, char** argv) {
1338 return dart::bin::main(argc, argv); 1358 return dart::bin::main(argc, argv);
1339 } 1359 }
OLDNEW
« no previous file with comments | « runtime/bin/dartutils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698