| 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/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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 return NULL; | 51 return NULL; |
| 52 } | 52 } |
| 53 string_args[i] = const_cast<char *>(DartUtils::GetStringValue(arg)); | 53 string_args[i] = const_cast<char *>(DartUtils::GetStringValue(arg)); |
| 54 } | 54 } |
| 55 return string_args; | 55 return string_args; |
| 56 } | 56 } |
| 57 | 57 |
| 58 void FUNCTION_NAME(Process_Start)(Dart_NativeArguments args) { | 58 void FUNCTION_NAME(Process_Start)(Dart_NativeArguments args) { |
| 59 Dart_EnterScope(); | 59 Dart_EnterScope(); |
| 60 Dart_Handle process = Dart_GetNativeArgument(args, 0); | 60 Dart_Handle process = Dart_GetNativeArgument(args, 0); |
| 61 intptr_t in; | 61 intptr_t process_stdin; |
| 62 intptr_t out; | 62 intptr_t process_stdout; |
| 63 intptr_t err; | 63 intptr_t process_stderr; |
| 64 intptr_t exit_event; | 64 intptr_t exit_event; |
| 65 Dart_Handle status_handle = Dart_GetNativeArgument(args, 9); | 65 Dart_Handle status_handle = Dart_GetNativeArgument(args, 9); |
| 66 Dart_Handle path_handle = Dart_GetNativeArgument(args, 1); | 66 Dart_Handle path_handle = Dart_GetNativeArgument(args, 1); |
| 67 // The Dart code verifies that the path implements the String | 67 // The Dart code verifies that the path implements the String |
| 68 // interface. However, only builtin Strings are handled by | 68 // interface. However, only builtin Strings are handled by |
| 69 // GetStringValue. | 69 // GetStringValue. |
| 70 if (!Dart_IsString(path_handle)) { | 70 if (!Dart_IsString(path_handle)) { |
| 71 DartUtils::SetIntegerField(status_handle, "_errorCode", 0); | 71 DartUtils::SetIntegerField(status_handle, "_errorCode", 0); |
| 72 DartUtils::SetStringField( | 72 DartUtils::SetStringField( |
| 73 status_handle, "_errorMessage", "Path must be a builtin string"); | 73 status_handle, "_errorMessage", "Path must be a builtin string"); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 status_handle, | 112 status_handle, |
| 113 "Environment values must be builtin strings", | 113 "Environment values must be builtin strings", |
| 114 &environment_length); | 114 &environment_length); |
| 115 if (string_environment == NULL) { | 115 if (string_environment == NULL) { |
| 116 delete[] string_args; | 116 delete[] string_args; |
| 117 Dart_SetReturnValue(args, Dart_NewBoolean(false)); | 117 Dart_SetReturnValue(args, Dart_NewBoolean(false)); |
| 118 Dart_ExitScope(); | 118 Dart_ExitScope(); |
| 119 return; | 119 return; |
| 120 } | 120 } |
| 121 } | 121 } |
| 122 Dart_Handle in_handle = Dart_GetNativeArgument(args, 5); | 122 Dart_Handle stdin_handle = Dart_GetNativeArgument(args, 5); |
| 123 Dart_Handle out_handle = Dart_GetNativeArgument(args, 6); | 123 Dart_Handle stdout_handle = Dart_GetNativeArgument(args, 6); |
| 124 Dart_Handle err_handle = Dart_GetNativeArgument(args, 7); | 124 Dart_Handle stderr_handle = Dart_GetNativeArgument(args, 7); |
| 125 Dart_Handle exit_handle = Dart_GetNativeArgument(args, 8); | 125 Dart_Handle exit_handle = Dart_GetNativeArgument(args, 8); |
| 126 intptr_t pid = -1; | 126 intptr_t pid = -1; |
| 127 char* os_error_message = NULL; | 127 char* os_error_message = NULL; |
| 128 | 128 |
| 129 int error_code = Process::Start(path, | 129 int error_code = Process::Start(path, |
| 130 string_args, | 130 string_args, |
| 131 args_length, | 131 args_length, |
| 132 working_directory, | 132 working_directory, |
| 133 string_environment, | 133 string_environment, |
| 134 environment_length, | 134 environment_length, |
| 135 &in, | 135 &process_stdout, |
| 136 &out, | 136 &process_stdin, |
| 137 &err, | 137 &process_stderr, |
| 138 &pid, | 138 &pid, |
| 139 &exit_event, | 139 &exit_event, |
| 140 &os_error_message); | 140 &os_error_message); |
| 141 if (error_code == 0) { | 141 if (error_code == 0) { |
| 142 Socket::SetSocketIdNativeField(in_handle, in); | 142 Socket::SetSocketIdNativeField(stdin_handle, process_stdin); |
| 143 Socket::SetSocketIdNativeField(out_handle, out); | 143 Socket::SetSocketIdNativeField(stdout_handle, process_stdout); |
| 144 Socket::SetSocketIdNativeField(err_handle, err); | 144 Socket::SetSocketIdNativeField(stderr_handle, process_stderr); |
| 145 Socket::SetSocketIdNativeField(exit_handle, exit_event); | 145 Socket::SetSocketIdNativeField(exit_handle, exit_event); |
| 146 Process::SetProcessIdNativeField(process, pid); | 146 Process::SetProcessIdNativeField(process, pid); |
| 147 } else { | 147 } else { |
| 148 DartUtils::SetIntegerField( | 148 DartUtils::SetIntegerField( |
| 149 status_handle, "_errorCode", error_code); | 149 status_handle, "_errorCode", error_code); |
| 150 DartUtils::SetStringField( | 150 DartUtils::SetStringField( |
| 151 status_handle, "_errorMessage", os_error_message); | 151 status_handle, "_errorMessage", os_error_message); |
| 152 } | 152 } |
| 153 delete[] string_args; | 153 delete[] string_args; |
| 154 delete[] string_environment; | 154 delete[] string_environment; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 const char* utf8 = DartUtils::GetStringValue(str); | 229 const char* utf8 = DartUtils::GetStringValue(str); |
| 230 const char* system_string = StringUtils::Utf8ToConsoleString(utf8); | 230 const char* system_string = StringUtils::Utf8ToConsoleString(utf8); |
| 231 int external_length = strlen(system_string); | 231 int external_length = strlen(system_string); |
| 232 uint8_t* buffer = NULL; | 232 uint8_t* buffer = NULL; |
| 233 Dart_Handle external_array = IOBuffer::Allocate(external_length, &buffer); | 233 Dart_Handle external_array = IOBuffer::Allocate(external_length, &buffer); |
| 234 memmove(buffer, system_string, external_length); | 234 memmove(buffer, system_string, external_length); |
| 235 if (utf8 != system_string) free(const_cast<char*>(system_string)); | 235 if (utf8 != system_string) free(const_cast<char*>(system_string)); |
| 236 Dart_SetReturnValue(args, external_array); | 236 Dart_SetReturnValue(args, external_array); |
| 237 Dart_ExitScope(); | 237 Dart_ExitScope(); |
| 238 } | 238 } |
| OLD | NEW |