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 void FUNCTION_NAME(Platform_NumberOfProcessors)(Dart_NativeArguments args) { | 15 void FUNCTION_NAME(Platform_NumberOfProcessors)(Dart_NativeArguments args) { |
16 Dart_EnterScope(); | |
17 Dart_SetReturnValue(args, Dart_NewInteger(Platform::NumberOfProcessors())); | 16 Dart_SetReturnValue(args, Dart_NewInteger(Platform::NumberOfProcessors())); |
18 Dart_ExitScope(); | |
19 } | 17 } |
20 | 18 |
21 | 19 |
22 void FUNCTION_NAME(Platform_OperatingSystem)(Dart_NativeArguments args) { | 20 void FUNCTION_NAME(Platform_OperatingSystem)(Dart_NativeArguments args) { |
23 Dart_EnterScope(); | |
24 Dart_SetReturnValue(args, DartUtils::NewString(Platform::OperatingSystem())); | 21 Dart_SetReturnValue(args, DartUtils::NewString(Platform::OperatingSystem())); |
25 Dart_ExitScope(); | |
26 } | 22 } |
27 | 23 |
28 | 24 |
29 void FUNCTION_NAME(Platform_PathSeparator)(Dart_NativeArguments args) { | 25 void FUNCTION_NAME(Platform_PathSeparator)(Dart_NativeArguments args) { |
30 Dart_EnterScope(); | |
31 Dart_SetReturnValue(args, DartUtils::NewString(File::PathSeparator())); | 26 Dart_SetReturnValue(args, DartUtils::NewString(File::PathSeparator())); |
32 Dart_ExitScope(); | |
33 } | 27 } |
34 | 28 |
35 | 29 |
36 void FUNCTION_NAME(Platform_LocalHostname)(Dart_NativeArguments args) { | 30 void FUNCTION_NAME(Platform_LocalHostname)(Dart_NativeArguments args) { |
37 Dart_EnterScope(); | |
38 const intptr_t HOSTNAME_LENGTH = 256; | 31 const intptr_t HOSTNAME_LENGTH = 256; |
39 char hostname[HOSTNAME_LENGTH]; | 32 char hostname[HOSTNAME_LENGTH]; |
40 if (Platform::LocalHostname(hostname, HOSTNAME_LENGTH)) { | 33 if (Platform::LocalHostname(hostname, HOSTNAME_LENGTH)) { |
41 Dart_SetReturnValue(args, DartUtils::NewString(hostname)); | 34 Dart_SetReturnValue(args, DartUtils::NewString(hostname)); |
42 } else { | 35 } else { |
43 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 36 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
44 } | 37 } |
45 Dart_ExitScope(); | |
46 } | 38 } |
47 | 39 |
48 | 40 |
49 void FUNCTION_NAME(Platform_Environment)(Dart_NativeArguments args) { | 41 void FUNCTION_NAME(Platform_Environment)(Dart_NativeArguments args) { |
50 Dart_EnterScope(); | |
51 intptr_t count = 0; | 42 intptr_t count = 0; |
52 char** env = Platform::Environment(&count); | 43 char** env = Platform::Environment(&count); |
53 if (env == NULL) { | 44 if (env == NULL) { |
54 OSError error(-1, | 45 OSError error(-1, |
55 "Failed to retrieve environment variables.", | 46 "Failed to retrieve environment variables.", |
56 OSError::kUnknown); | 47 OSError::kUnknown); |
57 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&error)); | 48 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&error)); |
58 } else { | 49 } else { |
59 Dart_Handle result = Dart_NewList(count); | 50 Dart_Handle result = Dart_NewList(count); |
60 if (Dart_IsError(result)) { | 51 if (Dart_IsError(result)) { |
61 Platform::FreeEnvironment(env, count); | 52 Platform::FreeEnvironment(env, count); |
62 Dart_PropagateError(result); | 53 Dart_PropagateError(result); |
63 } | 54 } |
64 for (intptr_t i = 0; i < count; i++) { | 55 for (intptr_t i = 0; i < count; i++) { |
65 Dart_Handle str = DartUtils::NewString(env[i]); | 56 Dart_Handle str = DartUtils::NewString(env[i]); |
66 if (Dart_IsError(str)) { | 57 if (Dart_IsError(str)) { |
67 Platform::FreeEnvironment(env, count); | 58 Platform::FreeEnvironment(env, count); |
68 Dart_PropagateError(str); | 59 Dart_PropagateError(str); |
69 } | 60 } |
70 Dart_Handle error = Dart_ListSetAt(result, i, str); | 61 Dart_Handle error = Dart_ListSetAt(result, i, str); |
71 if (Dart_IsError(error)) { | 62 if (Dart_IsError(error)) { |
72 Platform::FreeEnvironment(env, count); | 63 Platform::FreeEnvironment(env, count); |
73 Dart_PropagateError(error); | 64 Dart_PropagateError(error); |
74 } | 65 } |
75 } | 66 } |
76 Platform::FreeEnvironment(env, count); | 67 Platform::FreeEnvironment(env, count); |
77 Dart_SetReturnValue(args, result); | 68 Dart_SetReturnValue(args, result); |
78 } | 69 } |
79 Dart_ExitScope(); | |
80 } | 70 } |
81 | 71 |
82 | 72 |
83 void FUNCTION_NAME(Platform_GetVersion)(Dart_NativeArguments args) { | 73 void FUNCTION_NAME(Platform_GetVersion)(Dart_NativeArguments args) { |
84 Dart_EnterScope(); | |
85 Dart_SetReturnValue(args, Dart_NewStringFromCString(Dart_VersionString())); | 74 Dart_SetReturnValue(args, Dart_NewStringFromCString(Dart_VersionString())); |
86 Dart_ExitScope(); | |
87 } | 75 } |
88 | 76 |
89 } // namespace bin | 77 } // namespace bin |
90 } // namespace dart | 78 } // namespace dart |
OLD | NEW |