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 "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 | 8 |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "platform/globals.h" | 10 #include "platform/globals.h" |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
394 ASSERT(port_int != NULL); | 394 ASSERT(port_int != NULL); |
395 ASSERT(path_str != NULL); | 395 ASSERT(path_str != NULL); |
396 Dart_Handle result; | 396 Dart_Handle result; |
397 Dart_Handle uri = DartUtils::NewString(script_uri); | 397 Dart_Handle uri = DartUtils::NewString(script_uri); |
398 Dart_Handle builtin_lib = | 398 Dart_Handle builtin_lib = |
399 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 399 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
400 Dart_Handle path = DartUtils::PathFromUri(uri, builtin_lib); | 400 Dart_Handle path = DartUtils::PathFromUri(uri, builtin_lib); |
401 if (Dart_IsError(path)) { | 401 if (Dart_IsError(path)) { |
402 return path; | 402 return path; |
403 } | 403 } |
404 Dart_Handle host = DartUtils::DomainFromUri(uri, builtin_lib); | 404 Dart_Handle host = DartUtils::HostFromUri(uri, builtin_lib); |
405 if (Dart_IsError(host)) { | 405 if (Dart_IsError(host)) { |
406 return host; | 406 return host; |
407 } | 407 } |
408 Dart_Handle port = DartUtils::PortFromUri(uri, builtin_lib); | 408 Dart_Handle port = DartUtils::PortFromUri(uri, builtin_lib); |
409 if (Dart_IsError(port)) { | 409 if (Dart_IsError(port)) { |
410 return port; | 410 return port; |
411 } | 411 } |
siva
2013/05/31 20:36:29
We seem to parse the URI 3 times here once to extr
Cutch
2013/05/31 22:37:19
Done.
| |
412 result = Dart_StringToCString(path, path_str); | 412 result = Dart_StringToCString(path, path_str); |
413 if (Dart_IsError(result)) { | 413 if (Dart_IsError(result)) { |
414 return result; | 414 return result; |
415 } | 415 } |
416 result = Dart_StringToCString(host, host_str); | 416 result = Dart_StringToCString(host, host_str); |
417 if (Dart_IsError(result)) { | 417 if (Dart_IsError(result)) { |
418 return result; | 418 return result; |
419 } | 419 } |
420 if (DartUtils::GetInt64Value(port, port_int) == false) { | 420 if (DartUtils::GetInt64Value(port, port_int) == false) { |
421 return Dart_Error("Invalid port"); | 421 return Dart_Error("Invalid port"); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 dart_args[0] = arg; | 519 dart_args[0] = arg; |
520 return Dart_Invoke(lib, DartUtils::NewString(method), kNumArgs, dart_args); | 520 return Dart_Invoke(lib, DartUtils::NewString(method), kNumArgs, dart_args); |
521 } | 521 } |
522 | 522 |
523 Dart_Handle DartUtils::PathFromUri(Dart_Handle script_uri, | 523 Dart_Handle DartUtils::PathFromUri(Dart_Handle script_uri, |
524 Dart_Handle builtin_lib) { | 524 Dart_Handle builtin_lib) { |
525 return SingleArgDart_Invoke(script_uri, builtin_lib, "_pathFromHttpUri"); | 525 return SingleArgDart_Invoke(script_uri, builtin_lib, "_pathFromHttpUri"); |
526 } | 526 } |
527 | 527 |
528 | 528 |
529 Dart_Handle DartUtils::DomainFromUri(Dart_Handle script_uri, | 529 Dart_Handle DartUtils::HostFromUri(Dart_Handle script_uri, |
530 Dart_Handle builtin_lib) { | 530 Dart_Handle builtin_lib) { |
531 return SingleArgDart_Invoke(script_uri, builtin_lib, "_domainFromHttpUri"); | 531 return SingleArgDart_Invoke(script_uri, builtin_lib, "_hostFromHttpUri"); |
532 } | 532 } |
533 | 533 |
534 | 534 |
535 Dart_Handle DartUtils::PortFromUri(Dart_Handle script_uri, | 535 Dart_Handle DartUtils::PortFromUri(Dart_Handle script_uri, |
536 Dart_Handle builtin_lib) { | 536 Dart_Handle builtin_lib) { |
537 return SingleArgDart_Invoke(script_uri, builtin_lib, "_portFromHttpUri"); | 537 return SingleArgDart_Invoke(script_uri, builtin_lib, "_portFromHttpUri"); |
538 } | 538 } |
539 | 539 |
540 | 540 |
541 Dart_Handle DartUtils::ResolveUri(Dart_Handle library_url, | 541 Dart_Handle DartUtils::ResolveUri(Dart_Handle library_url, |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
706 if (Dart_IsError(source)) { | 706 if (Dart_IsError(source)) { |
707 return source; | 707 return source; |
708 } | 708 } |
709 return Dart_LoadScript(uri, source, 0, 0); | 709 return Dart_LoadScript(uri, source, 0, 0); |
710 } | 710 } |
711 } | 711 } |
712 | 712 |
713 | 713 |
714 Dart_Handle DartUtils::LoadScript(const char* script_uri, | 714 Dart_Handle DartUtils::LoadScript(const char* script_uri, |
715 Dart_Handle builtin_lib) { | 715 Dart_Handle builtin_lib) { |
716 if (DartUtils::IsHttpSchemeURL(script_uri)) { | |
717 return LoadScriptHttp(script_uri, builtin_lib); | |
718 } | |
719 Dart_Handle resolved_script_uri; | 716 Dart_Handle resolved_script_uri; |
717 // Always call ResolveScriptUri so that the base path is set. | |
siva
2013/05/31 20:36:29
From the comment it is not clear which base path i
Cutch
2013/05/31 22:37:19
Done.
| |
720 resolved_script_uri = ResolveScriptUri(NewString(script_uri), builtin_lib); | 718 resolved_script_uri = ResolveScriptUri(NewString(script_uri), builtin_lib); |
721 if (Dart_IsError(resolved_script_uri)) { | 719 if (Dart_IsError(resolved_script_uri)) { |
722 return resolved_script_uri; | 720 return resolved_script_uri; |
723 } | 721 } |
722 // Handle http: requests separately. | |
723 if (DartUtils::IsHttpSchemeURL(script_uri)) { | |
siva
2013/05/31 20:36:29
A NewString(script_uri) was done above and again i
Cutch
2013/05/31 22:37:19
Done.
| |
724 return LoadScriptHttp(script_uri, builtin_lib); | |
725 } | |
724 Dart_Handle script_path = DartUtils::FilePathFromUri(resolved_script_uri, | 726 Dart_Handle script_path = DartUtils::FilePathFromUri(resolved_script_uri, |
725 builtin_lib); | 727 builtin_lib); |
726 if (Dart_IsError(script_path)) { | 728 if (Dart_IsError(script_path)) { |
727 return script_path; | 729 return script_path; |
728 } | 730 } |
729 const char* script_path_cstr; | 731 const char* script_path_cstr; |
730 Dart_StringToCString(script_path, &script_path_cstr); | 732 Dart_StringToCString(script_path, &script_path_cstr); |
731 const char* error_msg = NULL; | 733 const char* error_msg = NULL; |
732 intptr_t len; | 734 intptr_t len; |
733 const uint8_t* text_buffer = ReadFileFully(script_path_cstr, | 735 const uint8_t* text_buffer = ReadFileFully(script_path_cstr, |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1103 new CObjectString(CObject::NewString(os_error->message())); | 1105 new CObjectString(CObject::NewString(os_error->message())); |
1104 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 1106 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
1105 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 1107 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
1106 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 1108 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
1107 result->SetAt(2, error_message); | 1109 result->SetAt(2, error_message); |
1108 return result; | 1110 return result; |
1109 } | 1111 } |
1110 | 1112 |
1111 } // namespace bin | 1113 } // namespace bin |
1112 } // namespace dart | 1114 } // namespace dart |
OLD | NEW |