| 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/platform.h" | 5 #include "bin/platform.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 | 8 |
| 9 #include "bin/file.h" | 9 #include "bin/file.h" |
| 10 #include "bin/utils.h" | 10 #include "bin/utils.h" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 namespace bin { | 13 namespace bin { |
| 14 | 14 |
| 15 const char* Platform::executable_name_ = NULL; | 15 const char* Platform::executable_name_ = NULL; |
| 16 const char* Platform::package_root_ = NULL; |
| 17 int Platform::script_index_ = 1; |
| 18 char** Platform::argv_ = NULL; |
| 16 | 19 |
| 17 void FUNCTION_NAME(Platform_NumberOfProcessors)(Dart_NativeArguments args) { | 20 void FUNCTION_NAME(Platform_NumberOfProcessors)(Dart_NativeArguments args) { |
| 18 Dart_SetReturnValue(args, Dart_NewInteger(Platform::NumberOfProcessors())); | 21 Dart_SetReturnValue(args, Dart_NewInteger(Platform::NumberOfProcessors())); |
| 19 } | 22 } |
| 20 | 23 |
| 21 | 24 |
| 22 void FUNCTION_NAME(Platform_OperatingSystem)(Dart_NativeArguments args) { | 25 void FUNCTION_NAME(Platform_OperatingSystem)(Dart_NativeArguments args) { |
| 23 Dart_SetReturnValue(args, DartUtils::NewString(Platform::OperatingSystem())); | 26 Dart_SetReturnValue(args, DartUtils::NewString(Platform::OperatingSystem())); |
| 24 } | 27 } |
| 25 | 28 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 39 } | 42 } |
| 40 } | 43 } |
| 41 | 44 |
| 42 | 45 |
| 43 void FUNCTION_NAME(Platform_ExecutableName)(Dart_NativeArguments args) { | 46 void FUNCTION_NAME(Platform_ExecutableName)(Dart_NativeArguments args) { |
| 44 ASSERT(Platform::GetExecutableName() != NULL); | 47 ASSERT(Platform::GetExecutableName() != NULL); |
| 45 Dart_SetReturnValue( | 48 Dart_SetReturnValue( |
| 46 args, Dart_NewStringFromCString(Platform::GetExecutableName())); | 49 args, Dart_NewStringFromCString(Platform::GetExecutableName())); |
| 47 } | 50 } |
| 48 | 51 |
| 52 |
| 53 void FUNCTION_NAME(Platform_ExecutableArguments)(Dart_NativeArguments args) { |
| 54 int end = Platform::GetScriptIndex(); |
| 55 char** argv = Platform::GetArgv(); |
| 56 Dart_Handle result = Dart_NewList(end - 1); |
| 57 for (intptr_t i = 1; i < end; i++) { |
| 58 Dart_Handle str = DartUtils::NewString(argv[i]); |
| 59 Dart_Handle error = Dart_ListSetAt(result, i - 1, str); |
| 60 if (Dart_IsError(error)) { |
| 61 Dart_PropagateError(error); |
| 62 } |
| 63 } |
| 64 Dart_SetReturnValue(args, result); |
| 65 } |
| 66 |
| 67 |
| 68 void FUNCTION_NAME(Platform_PackageRoot)(Dart_NativeArguments args) { |
| 69 const char* package_root = Platform::GetPackageRoot(); |
| 70 if (package_root == NULL) { |
| 71 package_root = ""; |
| 72 } |
| 73 Dart_SetReturnValue(args, Dart_NewStringFromCString(package_root)); |
| 74 } |
| 75 |
| 76 |
| 49 void FUNCTION_NAME(Platform_Environment)(Dart_NativeArguments args) { | 77 void FUNCTION_NAME(Platform_Environment)(Dart_NativeArguments args) { |
| 50 intptr_t count = 0; | 78 intptr_t count = 0; |
| 51 char** env = Platform::Environment(&count); | 79 char** env = Platform::Environment(&count); |
| 52 if (env == NULL) { | 80 if (env == NULL) { |
| 53 OSError error(-1, | 81 OSError error(-1, |
| 54 "Failed to retrieve environment variables.", | 82 "Failed to retrieve environment variables.", |
| 55 OSError::kUnknown); | 83 OSError::kUnknown); |
| 56 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&error)); | 84 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&error)); |
| 57 } else { | 85 } else { |
| 58 Dart_Handle result = Dart_NewList(count); | 86 Dart_Handle result = Dart_NewList(count); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 77 } | 105 } |
| 78 } | 106 } |
| 79 | 107 |
| 80 | 108 |
| 81 void FUNCTION_NAME(Platform_GetVersion)(Dart_NativeArguments args) { | 109 void FUNCTION_NAME(Platform_GetVersion)(Dart_NativeArguments args) { |
| 82 Dart_SetReturnValue(args, Dart_NewStringFromCString(Dart_VersionString())); | 110 Dart_SetReturnValue(args, Dart_NewStringFromCString(Dart_VersionString())); |
| 83 } | 111 } |
| 84 | 112 |
| 85 } // namespace bin | 113 } // namespace bin |
| 86 } // namespace dart | 114 } // namespace dart |
| OLD | NEW |