OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 #include "bin/io_buffer.h" | 6 #include "bin/io_buffer.h" |
7 #include "bin/process.h" | 7 #include "bin/process.h" |
8 #include "bin/socket.h" | 8 #include "bin/socket.h" |
9 | 9 |
10 #include "include/dart_api.h" | 10 #include "include/dart_api.h" |
11 | 11 |
12 | |
13 static const int kProcessIdNativeField = 0; | 12 static const int kProcessIdNativeField = 0; |
14 | 13 |
15 int Process::global_exit_code_ = 0; | 14 int Process::global_exit_code_ = 0; |
16 dart::Mutex Process::global_exit_code_mutex_; | 15 dart::Mutex Process::global_exit_code_mutex_; |
17 | 16 |
18 // Extract an array of C strings from a list of Dart strings. | 17 // Extract an array of C strings from a list of Dart strings. |
19 static char** ExtractCStringList(Dart_Handle strings, | 18 static char** ExtractCStringList(Dart_Handle strings, |
20 Dart_Handle status_handle, | 19 Dart_Handle status_handle, |
21 const char* error_msg, | 20 const char* error_msg, |
22 intptr_t* length) { | 21 intptr_t* length) { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 void FUNCTION_NAME(Process_SetExitCode)(Dart_NativeArguments args) { | 182 void FUNCTION_NAME(Process_SetExitCode)(Dart_NativeArguments args) { |
184 Dart_EnterScope(); | 183 Dart_EnterScope(); |
185 int64_t status = 0; | 184 int64_t status = 0; |
186 // Ignore result if passing invalid argument and just set exit code to 0. | 185 // Ignore result if passing invalid argument and just set exit code to 0. |
187 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); | 186 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); |
188 Process::SetGlobalExitCode(status); | 187 Process::SetGlobalExitCode(status); |
189 Dart_ExitScope(); | 188 Dart_ExitScope(); |
190 } | 189 } |
191 | 190 |
192 | 191 |
| 192 void FUNCTION_NAME(Process_Sleep)(Dart_NativeArguments args) { |
| 193 Dart_EnterScope(); |
| 194 int64_t milliseconds = 0; |
| 195 // Ignore result if passing invalid argument and just set exit code to 0. |
| 196 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &milliseconds); |
| 197 TimerUtils::Sleep(milliseconds); |
| 198 Dart_ExitScope(); |
| 199 } |
| 200 |
| 201 |
193 Dart_Handle Process::GetProcessIdNativeField(Dart_Handle process, | 202 Dart_Handle Process::GetProcessIdNativeField(Dart_Handle process, |
194 intptr_t* pid) { | 203 intptr_t* pid) { |
195 return Dart_GetNativeInstanceField(process, kProcessIdNativeField, pid); | 204 return Dart_GetNativeInstanceField(process, kProcessIdNativeField, pid); |
196 } | 205 } |
197 | 206 |
198 | 207 |
199 Dart_Handle Process::SetProcessIdNativeField(Dart_Handle process, | 208 Dart_Handle Process::SetProcessIdNativeField(Dart_Handle process, |
200 intptr_t pid) { | 209 intptr_t pid) { |
201 return Dart_SetNativeInstanceField(process, kProcessIdNativeField, pid); | 210 return Dart_SetNativeInstanceField(process, kProcessIdNativeField, pid); |
202 } | 211 } |
(...skipping 26 matching lines...) Expand all Loading... |
229 const char* utf8 = DartUtils::GetStringValue(str); | 238 const char* utf8 = DartUtils::GetStringValue(str); |
230 const char* system_string = StringUtils::Utf8ToConsoleString(utf8); | 239 const char* system_string = StringUtils::Utf8ToConsoleString(utf8); |
231 int external_length = strlen(system_string); | 240 int external_length = strlen(system_string); |
232 uint8_t* buffer = NULL; | 241 uint8_t* buffer = NULL; |
233 Dart_Handle external_array = IOBuffer::Allocate(external_length, &buffer); | 242 Dart_Handle external_array = IOBuffer::Allocate(external_length, &buffer); |
234 memmove(buffer, system_string, external_length); | 243 memmove(buffer, system_string, external_length); |
235 if (utf8 != system_string) free(const_cast<char*>(system_string)); | 244 if (utf8 != system_string) free(const_cast<char*>(system_string)); |
236 Dart_SetReturnValue(args, external_array); | 245 Dart_SetReturnValue(args, external_array); |
237 Dart_ExitScope(); | 246 Dart_ExitScope(); |
238 } | 247 } |
OLD | NEW |