| OLD | NEW |
| 1 // Copyright (c) 2013, 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" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 void FUNCTION_NAME(Process_Sleep)(Dart_NativeArguments args) { | 192 void FUNCTION_NAME(Process_Sleep)(Dart_NativeArguments args) { |
| 193 Dart_EnterScope(); | 193 Dart_EnterScope(); |
| 194 int64_t milliseconds = 0; | 194 int64_t milliseconds = 0; |
| 195 // Ignore result if passing invalid argument and just set exit code to 0. | 195 // Ignore result if passing invalid argument and just set exit code to 0. |
| 196 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &milliseconds); | 196 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &milliseconds); |
| 197 TimerUtils::Sleep(milliseconds); | 197 TimerUtils::Sleep(milliseconds); |
| 198 Dart_ExitScope(); | 198 Dart_ExitScope(); |
| 199 } | 199 } |
| 200 | 200 |
| 201 | 201 |
| 202 void FUNCTION_NAME(Process_Pid)(Dart_NativeArguments args) { |
| 203 Dart_EnterScope(); |
| 204 // Ignore result if passing invalid argument and just set exit code to 0. |
| 205 intptr_t pid = -1; |
| 206 Dart_Handle process = Dart_GetNativeArgument(args, 0); |
| 207 if (Dart_IsNull(process)) { |
| 208 pid = Process::CurrentProcessId(); |
| 209 } else { |
| 210 Process::GetProcessIdNativeField(process, &pid); |
| 211 } |
| 212 Dart_SetReturnValue(args, Dart_NewInteger(pid)); |
| 213 Dart_ExitScope(); |
| 214 } |
| 215 |
| 216 |
| 202 Dart_Handle Process::GetProcessIdNativeField(Dart_Handle process, | 217 Dart_Handle Process::GetProcessIdNativeField(Dart_Handle process, |
| 203 intptr_t* pid) { | 218 intptr_t* pid) { |
| 204 return Dart_GetNativeInstanceField(process, kProcessIdNativeField, pid); | 219 return Dart_GetNativeInstanceField(process, kProcessIdNativeField, pid); |
| 205 } | 220 } |
| 206 | 221 |
| 207 | 222 |
| 208 Dart_Handle Process::SetProcessIdNativeField(Dart_Handle process, | 223 Dart_Handle Process::SetProcessIdNativeField(Dart_Handle process, |
| 209 intptr_t pid) { | 224 intptr_t pid) { |
| 210 return Dart_SetNativeInstanceField(process, kProcessIdNativeField, pid); | 225 return Dart_SetNativeInstanceField(process, kProcessIdNativeField, pid); |
| 211 } | 226 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 238 const char* utf8 = DartUtils::GetStringValue(str); | 253 const char* utf8 = DartUtils::GetStringValue(str); |
| 239 const char* system_string = StringUtils::Utf8ToConsoleString(utf8); | 254 const char* system_string = StringUtils::Utf8ToConsoleString(utf8); |
| 240 int external_length = strlen(system_string); | 255 int external_length = strlen(system_string); |
| 241 uint8_t* buffer = NULL; | 256 uint8_t* buffer = NULL; |
| 242 Dart_Handle external_array = IOBuffer::Allocate(external_length, &buffer); | 257 Dart_Handle external_array = IOBuffer::Allocate(external_length, &buffer); |
| 243 memmove(buffer, system_string, external_length); | 258 memmove(buffer, system_string, external_length); |
| 244 if (utf8 != system_string) free(const_cast<char*>(system_string)); | 259 if (utf8 != system_string) free(const_cast<char*>(system_string)); |
| 245 Dart_SetReturnValue(args, external_array); | 260 Dart_SetReturnValue(args, external_array); |
| 246 Dart_ExitScope(); | 261 Dart_ExitScope(); |
| 247 } | 262 } |
| OLD | NEW |