| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/process.h" | 6 #include "bin/process.h" |
| 7 | 7 |
| 8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
| 9 | 9 |
| 10 void FUNCTION_NAME(Process_Start)(Dart_NativeArguments args) { | 10 void FUNCTION_NAME(Process_Start)(Dart_NativeArguments args) { |
| 11 Dart_EnterScope(); | 11 Dart_EnterScope(); |
| 12 Dart_Handle process = Dart_GetNativeArgument(args, 0); | 12 Dart_Handle process = Dart_GetNativeArgument(args, 0); |
| 13 intptr_t in; | 13 intptr_t in; |
| 14 intptr_t out; | 14 intptr_t out; |
| 15 intptr_t err; | 15 intptr_t err; |
| 16 intptr_t exit_event; | 16 intptr_t exit_event; |
| 17 const char* path = | 17 Dart_Handle status_handle = Dart_GetNativeArgument(args, 7); |
| 18 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1)); | 18 Dart_Handle path_handle = Dart_GetNativeArgument(args, 1); |
| 19 // The Dart code verifies that the path implements the String |
| 20 // interface. However, only builtin Strings are handled by |
| 21 // GetStringValue. |
| 22 if (!Dart_IsString(path_handle)) { |
| 23 DartUtils::SetIntegerInstanceField(status_handle, "_errorCode", 0); |
| 24 DartUtils::SetStringInstanceField( |
| 25 status_handle, "_errorMessage", "Path must be a builtin string"); |
| 26 Dart_SetReturnValue(args, Dart_NewBoolean(false)); |
| 27 Dart_ExitScope(); |
| 28 return; |
| 29 } |
| 30 const char* path = DartUtils::GetStringValue(path_handle); |
| 19 Dart_Handle arguments = Dart_GetNativeArgument(args, 2); | 31 Dart_Handle arguments = Dart_GetNativeArgument(args, 2); |
| 32 // The arguments are copied into a non-extensible array in the |
| 33 // dart code so this should not fail. |
| 20 ASSERT(Dart_IsArray(arguments)); | 34 ASSERT(Dart_IsArray(arguments)); |
| 21 Dart_Result result = Dart_GetLength(arguments); | 35 Dart_Result result = Dart_GetLength(arguments); |
| 22 ASSERT(Dart_IsValidResult(result)); | 36 ASSERT(Dart_IsValidResult(result)); |
| 23 intptr_t length = Dart_GetResultAsCIntptr(result); | 37 intptr_t length = Dart_GetResultAsCIntptr(result); |
| 24 char** string_args = new char*[length]; | 38 char** string_args = new char*[length]; |
| 25 for (int i = 0; i < length; i++) { | 39 for (int i = 0; i < length; i++) { |
| 26 result = Dart_ArrayGetAt(arguments, i); | 40 result = Dart_ArrayGetAt(arguments, i); |
| 27 ASSERT(Dart_IsValidResult(result)); | 41 ASSERT(Dart_IsValidResult(result)); |
| 28 Dart_Handle arg = Dart_GetResult(result); | 42 Dart_Handle arg = Dart_GetResult(result); |
| 43 // The Dart code verifies that the arguments implement the String |
| 44 // interface. However, only builtin Strings are handled by |
| 45 // GetStringValue. |
| 46 if (!Dart_IsString(arg)) { |
| 47 DartUtils::SetIntegerInstanceField(status_handle, "_errorCode", 0); |
| 48 DartUtils::SetStringInstanceField( |
| 49 status_handle, "_errorMessage", "Arguments must be builtin strings"); |
| 50 delete[] string_args; |
| 51 Dart_SetReturnValue(args, Dart_NewBoolean(false)); |
| 52 Dart_ExitScope(); |
| 53 return; |
| 54 } |
| 29 string_args[i] = const_cast<char *>(DartUtils::GetStringValue(arg)); | 55 string_args[i] = const_cast<char *>(DartUtils::GetStringValue(arg)); |
| 30 } | 56 } |
| 31 Dart_Handle in_handle = Dart_GetNativeArgument(args, 3); | 57 Dart_Handle in_handle = Dart_GetNativeArgument(args, 3); |
| 32 Dart_Handle out_handle = Dart_GetNativeArgument(args, 4); | 58 Dart_Handle out_handle = Dart_GetNativeArgument(args, 4); |
| 33 Dart_Handle err_handle = Dart_GetNativeArgument(args, 5); | 59 Dart_Handle err_handle = Dart_GetNativeArgument(args, 5); |
| 34 Dart_Handle exit_handle = Dart_GetNativeArgument(args, 6); | 60 Dart_Handle exit_handle = Dart_GetNativeArgument(args, 6); |
| 35 Dart_Handle status_handle = Dart_GetNativeArgument(args, 7); | |
| 36 intptr_t pid = -1; | 61 intptr_t pid = -1; |
| 37 static const int kMaxChildOsErrorMessageLength = 256; | 62 static const int kMaxChildOsErrorMessageLength = 256; |
| 38 char os_error_message[kMaxChildOsErrorMessageLength]; | 63 char os_error_message[kMaxChildOsErrorMessageLength]; |
| 39 | 64 |
| 40 int error_code = Process::Start( | 65 int error_code = Process::Start( |
| 41 path, string_args, length, | 66 path, string_args, length, |
| 42 &in, &out, &err, &pid, &exit_event, | 67 &in, &out, &err, &pid, &exit_event, |
| 43 os_error_message, kMaxChildOsErrorMessageLength); | 68 os_error_message, kMaxChildOsErrorMessageLength); |
| 44 if (error_code == 0) { | 69 if (error_code == 0) { |
| 45 DartUtils::SetIntegerInstanceField(in_handle, DartUtils::kIdFieldName, in); | 70 DartUtils::SetIntegerInstanceField(in_handle, DartUtils::kIdFieldName, in); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 70 Dart_ExitScope(); | 95 Dart_ExitScope(); |
| 71 } | 96 } |
| 72 | 97 |
| 73 | 98 |
| 74 void FUNCTION_NAME(Process_Exit)(Dart_NativeArguments args) { | 99 void FUNCTION_NAME(Process_Exit)(Dart_NativeArguments args) { |
| 75 Dart_EnterScope(); | 100 Dart_EnterScope(); |
| 76 intptr_t pid = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); | 101 intptr_t pid = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); |
| 77 Process::Exit(pid); | 102 Process::Exit(pid); |
| 78 Dart_ExitScope(); | 103 Dart_ExitScope(); |
| 79 } | 104 } |
| OLD | NEW |