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" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 intptr_t count = 0; | 95 intptr_t count = 0; |
96 char** env = Platform::Environment(&count); | 96 char** env = Platform::Environment(&count); |
97 if (env == NULL) { | 97 if (env == NULL) { |
98 OSError error(-1, | 98 OSError error(-1, |
99 "Failed to retrieve environment variables.", | 99 "Failed to retrieve environment variables.", |
100 OSError::kUnknown); | 100 OSError::kUnknown); |
101 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&error)); | 101 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&error)); |
102 } else { | 102 } else { |
103 Dart_Handle result = Dart_NewList(count); | 103 Dart_Handle result = Dart_NewList(count); |
104 if (Dart_IsError(result)) { | 104 if (Dart_IsError(result)) { |
105 Platform::FreeEnvironment(env, count); | |
106 Dart_PropagateError(result); | 105 Dart_PropagateError(result); |
107 } | 106 } |
108 for (intptr_t i = 0; i < count; i++) { | 107 for (intptr_t i = 0; i < count; i++) { |
109 Dart_Handle str = DartUtils::NewString(env[i]); | 108 Dart_Handle str = DartUtils::NewString(env[i]); |
110 if (Dart_IsError(str)) { | 109 if (Dart_IsError(str)) { |
111 Platform::FreeEnvironment(env, count); | |
112 Dart_PropagateError(str); | 110 Dart_PropagateError(str); |
113 } | 111 } |
114 Dart_Handle error = Dart_ListSetAt(result, i, str); | 112 Dart_Handle error = Dart_ListSetAt(result, i, str); |
115 if (Dart_IsError(error)) { | 113 if (Dart_IsError(error)) { |
116 Platform::FreeEnvironment(env, count); | |
117 Dart_PropagateError(error); | 114 Dart_PropagateError(error); |
118 } | 115 } |
119 } | 116 } |
120 Platform::FreeEnvironment(env, count); | |
121 Dart_SetReturnValue(args, result); | 117 Dart_SetReturnValue(args, result); |
122 } | 118 } |
123 } | 119 } |
124 | 120 |
125 | 121 |
126 void FUNCTION_NAME(Platform_GetVersion)(Dart_NativeArguments args) { | 122 void FUNCTION_NAME(Platform_GetVersion)(Dart_NativeArguments args) { |
127 Dart_SetReturnValue(args, Dart_NewStringFromCString(Dart_VersionString())); | 123 Dart_SetReturnValue(args, Dart_NewStringFromCString(Dart_VersionString())); |
128 } | 124 } |
129 | 125 |
130 } // namespace bin | 126 } // namespace bin |
131 } // namespace dart | 127 } // namespace dart |
OLD | NEW |