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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 intptr_t len; | 376 intptr_t len; |
377 const uint8_t* text_buffer = ReadFileFully(filename, &len, &error_msg); | 377 const uint8_t* text_buffer = ReadFileFully(filename, &len, &error_msg); |
378 if (text_buffer == NULL) { | 378 if (text_buffer == NULL) { |
379 return Dart_Error(error_msg); | 379 return Dart_Error(error_msg); |
380 } | 380 } |
381 Dart_Handle str = Dart_NewStringFromUTF8(text_buffer, len); | 381 Dart_Handle str = Dart_NewStringFromUTF8(text_buffer, len); |
382 return str; | 382 return str; |
383 } | 383 } |
384 | 384 |
385 | 385 |
386 Dart_Handle DartUtils::SetWorkingDirectory(Dart_Handle builtin_lib) { | |
387 Dart_Handle directory = NewString(original_working_directory); | |
388 return SingleArgDart_Invoke(directory, builtin_lib, "_setWorkingDirectory"); | |
389 } | |
390 | |
391 | |
386 Dart_Handle DartUtils::ResolveScriptUri(Dart_Handle script_uri, | 392 Dart_Handle DartUtils::ResolveScriptUri(Dart_Handle script_uri, |
387 Dart_Handle builtin_lib) { | 393 Dart_Handle builtin_lib) { |
388 const int kNumArgs = 3; | 394 const int kNumArgs = 1; |
389 Dart_Handle dart_args[kNumArgs]; | 395 Dart_Handle dart_args[kNumArgs]; |
390 dart_args[0] = NewString(original_working_directory); | 396 dart_args[0] = script_uri; |
391 dart_args[1] = script_uri; | |
392 dart_args[2] = (IsWindowsHost() ? Dart_True() : Dart_False()); | |
393 return Dart_Invoke(builtin_lib, | 397 return Dart_Invoke(builtin_lib, |
394 NewString("_resolveScriptUri"), | 398 NewString("_resolveScriptUri"), |
395 kNumArgs, | 399 kNumArgs, |
396 dart_args); | 400 dart_args); |
siva
2013/06/06 01:13:17
I suppose this can also be:
return SingleArgDart_
Cutch
2013/06/12 19:34:26
Done.
| |
397 } | 401 } |
398 | 402 |
399 | 403 |
400 Dart_Handle DartUtils::FilePathFromUri(Dart_Handle script_uri, | 404 Dart_Handle DartUtils::FilePathFromUri(Dart_Handle script_uri, |
401 Dart_Handle builtin_lib) { | 405 Dart_Handle builtin_lib) { |
402 const int kNumArgs = 2; | 406 const int kNumArgs = 1; |
403 Dart_Handle dart_args[kNumArgs]; | 407 Dart_Handle dart_args[kNumArgs]; |
404 dart_args[0] = script_uri; | 408 dart_args[0] = script_uri; |
405 dart_args[1] = (IsWindowsHost() ? Dart_True() : Dart_False()); | |
406 return Dart_Invoke(builtin_lib, | 409 return Dart_Invoke(builtin_lib, |
407 NewString("_filePathFromUri"), | 410 NewString("_filePathFromUri"), |
408 kNumArgs, | 411 kNumArgs, |
409 dart_args); | 412 dart_args); |
siva
2013/06/06 01:13:17
I suppose this can also be:
return SingleArgDart_
Cutch
2013/06/12 19:34:26
Done.
| |
410 } | 413 } |
411 | 414 |
412 | 415 |
413 Dart_Handle DartUtils::ResolveUri(Dart_Handle library_url, | 416 Dart_Handle DartUtils::ResolveUri(Dart_Handle library_url, |
414 Dart_Handle url, | 417 Dart_Handle url, |
415 Dart_Handle builtin_lib) { | 418 Dart_Handle builtin_lib) { |
416 const int kNumArgs = 2; | 419 const int kNumArgs = 2; |
417 Dart_Handle dart_args[kNumArgs]; | 420 Dart_Handle dart_args[kNumArgs]; |
418 dart_args[0] = library_url; | 421 dart_args[0] = library_url; |
419 dart_args[1] = url; | 422 dart_args[1] = url; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
556 if (Dart_IsError(source)) { | 559 if (Dart_IsError(source)) { |
557 return source; | 560 return source; |
558 } | 561 } |
559 return Dart_LoadScript(uri, source, 0, 0); | 562 return Dart_LoadScript(uri, source, 0, 0); |
560 } | 563 } |
561 } | 564 } |
562 | 565 |
563 | 566 |
564 Dart_Handle DartUtils::LoadScript(const char* script_uri, | 567 Dart_Handle DartUtils::LoadScript(const char* script_uri, |
565 Dart_Handle builtin_lib) { | 568 Dart_Handle builtin_lib) { |
566 // Always call ResolveScriptUri because as a side effect it sets | |
567 // the script entry path which is used when automatically resolving | |
568 // package root. | |
569 Dart_Handle resolved_script_uri = | 569 Dart_Handle resolved_script_uri = |
570 ResolveScriptUri(NewString(script_uri), builtin_lib); | 570 ResolveScriptUri(NewString(script_uri), builtin_lib); |
571 if (Dart_IsError(resolved_script_uri)) { | 571 if (Dart_IsError(resolved_script_uri)) { |
572 return resolved_script_uri; | 572 return resolved_script_uri; |
573 } | 573 } |
574 // Handle http: requests separately. | 574 // Handle http: requests separately. |
575 if (DartUtils::IsHttpSchemeURL(script_uri)) { | 575 if (DartUtils::IsHttpSchemeURL(script_uri)) { |
576 return LoadScriptHttp(resolved_script_uri, builtin_lib); | 576 return LoadScriptHttp(resolved_script_uri, builtin_lib); |
577 } | 577 } |
578 Dart_Handle script_path = DartUtils::FilePathFromUri(resolved_script_uri, | 578 Dart_Handle script_path = DartUtils::FilePathFromUri(resolved_script_uri, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
658 Dart_Handle async_lib = Dart_LookupLibrary(url); | 658 Dart_Handle async_lib = Dart_LookupLibrary(url); |
659 DART_CHECK_VALID(async_lib); | 659 DART_CHECK_VALID(async_lib); |
660 Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); | 660 Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); |
661 Dart_Handle timer_closure = | 661 Dart_Handle timer_closure = |
662 Dart_Invoke(io_lib, NewString("_getTimerFactoryClosure"), 0, NULL); | 662 Dart_Invoke(io_lib, NewString("_getTimerFactoryClosure"), 0, NULL); |
663 Dart_Handle args[1]; | 663 Dart_Handle args[1]; |
664 args[0] = timer_closure; | 664 args[0] = timer_closure; |
665 DART_CHECK_VALID(Dart_Invoke( | 665 DART_CHECK_VALID(Dart_Invoke( |
666 async_lib, NewString("_setTimerFactoryClosure"), 1, args)); | 666 async_lib, NewString("_setTimerFactoryClosure"), 1, args)); |
667 | 667 |
668 | |
669 // Set running on Windows flag. | |
670 result = Dart_SetField(builtin_lib, NewString("_isWindows"), | |
671 (IsWindowsHost() ? Dart_True() : Dart_False())); | |
672 if (Dart_IsError(result)) { | |
673 return result; | |
674 } | |
675 // Set current working directory. | |
676 result = SetWorkingDirectory(builtin_lib); | |
677 if (Dart_IsError(result)) { | |
678 return result; | |
679 } | |
680 | |
668 // Set up package root if specified. | 681 // Set up package root if specified. |
669 if (package_root != NULL) { | 682 if (package_root != NULL) { |
670 result = NewString(package_root); | 683 result = NewString(package_root); |
671 if (!Dart_IsError(result)) { | 684 if (!Dart_IsError(result)) { |
672 const int kNumArgs = 1; | 685 const int kNumArgs = 1; |
673 Dart_Handle dart_args[kNumArgs]; | 686 Dart_Handle dart_args[kNumArgs]; |
674 dart_args[0] = result; | 687 dart_args[0] = result; |
675 return Dart_Invoke(builtin_lib, | 688 return Dart_Invoke(builtin_lib, |
676 NewString("_setPackageRoot"), | 689 NewString("_setPackageRoot"), |
677 kNumArgs, | 690 kNumArgs, |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
957 new CObjectString(CObject::NewString(os_error->message())); | 970 new CObjectString(CObject::NewString(os_error->message())); |
958 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 971 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
959 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 972 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
960 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 973 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
961 result->SetAt(2, error_message); | 974 result->SetAt(2, error_message); |
962 return result; | 975 return result; |
963 } | 976 } |
964 | 977 |
965 } // namespace bin | 978 } // namespace bin |
966 } // namespace dart | 979 } // namespace dart |
OLD | NEW |