| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 Dart_Handle status_handle = Dart_GetNativeArgument(args, 9); | 67 Dart_Handle status_handle = Dart_GetNativeArgument(args, 9); |
| 68 Dart_Handle path_handle = Dart_GetNativeArgument(args, 1); | 68 Dart_Handle path_handle = Dart_GetNativeArgument(args, 1); |
| 69 // The Dart code verifies that the path implements the String | 69 // The Dart code verifies that the path implements the String |
| 70 // interface. However, only builtin Strings are handled by | 70 // interface. However, only builtin Strings are handled by |
| 71 // GetStringValue. | 71 // GetStringValue. |
| 72 if (!Dart_IsString(path_handle)) { | 72 if (!Dart_IsString(path_handle)) { |
| 73 DartUtils::SetIntegerField(status_handle, "_errorCode", 0); | 73 DartUtils::SetIntegerField(status_handle, "_errorCode", 0); |
| 74 DartUtils::SetStringField( | 74 DartUtils::SetStringField( |
| 75 status_handle, "_errorMessage", "Path must be a builtin string"); | 75 status_handle, "_errorMessage", "Path must be a builtin string"); |
| 76 Dart_SetReturnValue(args, Dart_NewBoolean(false)); | 76 Dart_SetReturnValue(args, Dart_NewBoolean(false)); |
| 77 Dart_ExitScope(); | |
| 78 return; | 77 return; |
| 79 } | 78 } |
| 80 const char* path = DartUtils::GetStringValue(path_handle); | 79 const char* path = DartUtils::GetStringValue(path_handle); |
| 81 Dart_Handle arguments = Dart_GetNativeArgument(args, 2); | 80 Dart_Handle arguments = Dart_GetNativeArgument(args, 2); |
| 82 intptr_t args_length = 0; | 81 intptr_t args_length = 0; |
| 83 char** string_args = | 82 char** string_args = |
| 84 ExtractCStringList(arguments, | 83 ExtractCStringList(arguments, |
| 85 status_handle, | 84 status_handle, |
| 86 "Arguments must be builtin strings", | 85 "Arguments must be builtin strings", |
| 87 &args_length); | 86 &args_length); |
| 88 if (string_args == NULL) { | 87 if (string_args == NULL) { |
| 89 Dart_SetReturnValue(args, Dart_NewBoolean(false)); | 88 Dart_SetReturnValue(args, Dart_NewBoolean(false)); |
| 90 Dart_ExitScope(); | |
| 91 return; | 89 return; |
| 92 } | 90 } |
| 93 Dart_Handle working_directory_handle = Dart_GetNativeArgument(args, 3); | 91 Dart_Handle working_directory_handle = Dart_GetNativeArgument(args, 3); |
| 94 // Defaults to the current working directoy. | 92 // Defaults to the current working directoy. |
| 95 const char* working_directory = NULL; | 93 const char* working_directory = NULL; |
| 96 if (Dart_IsString(working_directory_handle)) { | 94 if (Dart_IsString(working_directory_handle)) { |
| 97 working_directory = DartUtils::GetStringValue(working_directory_handle); | 95 working_directory = DartUtils::GetStringValue(working_directory_handle); |
| 98 } else if (!Dart_IsNull(working_directory_handle)) { | 96 } else if (!Dart_IsNull(working_directory_handle)) { |
| 99 delete[] string_args; | 97 delete[] string_args; |
| 100 DartUtils::SetIntegerField(status_handle, "_errorCode", 0); | 98 DartUtils::SetIntegerField(status_handle, "_errorCode", 0); |
| 101 DartUtils::SetStringField( | 99 DartUtils::SetStringField( |
| 102 status_handle, "_errorMessage", | 100 status_handle, "_errorMessage", |
| 103 "WorkingDirectory must be a builtin string"); | 101 "WorkingDirectory must be a builtin string"); |
| 104 Dart_SetReturnValue(args, Dart_NewBoolean(false)); | 102 Dart_SetReturnValue(args, Dart_NewBoolean(false)); |
| 105 Dart_ExitScope(); | |
| 106 return; | 103 return; |
| 107 } | 104 } |
| 108 Dart_Handle environment = Dart_GetNativeArgument(args, 4); | 105 Dart_Handle environment = Dart_GetNativeArgument(args, 4); |
| 109 intptr_t environment_length = 0; | 106 intptr_t environment_length = 0; |
| 110 char** string_environment = NULL; | 107 char** string_environment = NULL; |
| 111 if (!Dart_IsNull(environment)) { | 108 if (!Dart_IsNull(environment)) { |
| 112 string_environment = | 109 string_environment = |
| 113 ExtractCStringList(environment, | 110 ExtractCStringList(environment, |
| 114 status_handle, | 111 status_handle, |
| 115 "Environment values must be builtin strings", | 112 "Environment values must be builtin strings", |
| 116 &environment_length); | 113 &environment_length); |
| 117 if (string_environment == NULL) { | 114 if (string_environment == NULL) { |
| 118 delete[] string_args; | 115 delete[] string_args; |
| 119 Dart_SetReturnValue(args, Dart_NewBoolean(false)); | 116 Dart_SetReturnValue(args, Dart_NewBoolean(false)); |
| 120 Dart_ExitScope(); | |
| 121 return; | 117 return; |
| 122 } | 118 } |
| 123 } | 119 } |
| 124 Dart_Handle stdin_handle = Dart_GetNativeArgument(args, 5); | 120 Dart_Handle stdin_handle = Dart_GetNativeArgument(args, 5); |
| 125 Dart_Handle stdout_handle = Dart_GetNativeArgument(args, 6); | 121 Dart_Handle stdout_handle = Dart_GetNativeArgument(args, 6); |
| 126 Dart_Handle stderr_handle = Dart_GetNativeArgument(args, 7); | 122 Dart_Handle stderr_handle = Dart_GetNativeArgument(args, 7); |
| 127 Dart_Handle exit_handle = Dart_GetNativeArgument(args, 8); | 123 Dart_Handle exit_handle = Dart_GetNativeArgument(args, 8); |
| 128 intptr_t pid = -1; | 124 intptr_t pid = -1; |
| 129 char* os_error_message = NULL; | 125 char* os_error_message = NULL; |
| 130 | 126 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 int external_length = strlen(system_string); | 240 int external_length = strlen(system_string); |
| 245 uint8_t* buffer = NULL; | 241 uint8_t* buffer = NULL; |
| 246 Dart_Handle external_array = IOBuffer::Allocate(external_length, &buffer); | 242 Dart_Handle external_array = IOBuffer::Allocate(external_length, &buffer); |
| 247 memmove(buffer, system_string, external_length); | 243 memmove(buffer, system_string, external_length); |
| 248 if (utf8 != system_string) free(const_cast<char*>(system_string)); | 244 if (utf8 != system_string) free(const_cast<char*>(system_string)); |
| 249 Dart_SetReturnValue(args, external_array); | 245 Dart_SetReturnValue(args, external_array); |
| 250 } | 246 } |
| 251 | 247 |
| 252 } // namespace bin | 248 } // namespace bin |
| 253 } // namespace dart | 249 } // namespace dart |
| OLD | NEW |