Chromium Code Reviews| 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 Dart_Handle status_handle = Dart_GetNativeArgument(args, 7); | 17 Dart_Handle status_handle = Dart_GetNativeArgument(args, 8); |
| 18 Dart_Handle path_handle = Dart_GetNativeArgument(args, 1); | 18 Dart_Handle path_handle = Dart_GetNativeArgument(args, 1); |
| 19 // The Dart code verifies that the path implements the String | 19 // The Dart code verifies that the path implements the String |
| 20 // interface. However, only builtin Strings are handled by | 20 // interface. However, only builtin Strings are handled by |
| 21 // GetStringValue. | 21 // GetStringValue. |
| 22 if (!Dart_IsString(path_handle)) { | 22 if (!Dart_IsString(path_handle)) { |
| 23 DartUtils::SetIntegerInstanceField(status_handle, "_errorCode", 0); | 23 DartUtils::SetIntegerInstanceField(status_handle, "_errorCode", 0); |
| 24 DartUtils::SetStringInstanceField( | 24 DartUtils::SetStringInstanceField( |
| 25 status_handle, "_errorMessage", "Path must be a builtin string"); | 25 status_handle, "_errorMessage", "Path must be a builtin string"); |
| 26 Dart_SetReturnValue(args, Dart_NewBoolean(false)); | 26 Dart_SetReturnValue(args, Dart_NewBoolean(false)); |
| 27 Dart_ExitScope(); | 27 Dart_ExitScope(); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 46 DartUtils::SetIntegerInstanceField(status_handle, "_errorCode", 0); | 46 DartUtils::SetIntegerInstanceField(status_handle, "_errorCode", 0); |
| 47 DartUtils::SetStringInstanceField( | 47 DartUtils::SetStringInstanceField( |
| 48 status_handle, "_errorMessage", "Arguments must be builtin strings"); | 48 status_handle, "_errorMessage", "Arguments must be builtin strings"); |
| 49 delete[] string_args; | 49 delete[] string_args; |
| 50 Dart_SetReturnValue(args, Dart_NewBoolean(false)); | 50 Dart_SetReturnValue(args, Dart_NewBoolean(false)); |
| 51 Dart_ExitScope(); | 51 Dart_ExitScope(); |
| 52 return; | 52 return; |
| 53 } | 53 } |
| 54 string_args[i] = const_cast<char *>(DartUtils::GetStringValue(arg)); | 54 string_args[i] = const_cast<char *>(DartUtils::GetStringValue(arg)); |
| 55 } | 55 } |
| 56 Dart_Handle in_handle = Dart_GetNativeArgument(args, 3); | 56 Dart_Handle working_directory_handle = Dart_GetNativeArgument(args, 3); |
| 57 Dart_Handle out_handle = Dart_GetNativeArgument(args, 4); | 57 // Default to the current working directoy. |
|
Søren Gjesse
2012/01/05 09:30:47
Default => Defaults
Anders Johnsen
2012/01/05 09:50:49
Done.
| |
| 58 Dart_Handle err_handle = Dart_GetNativeArgument(args, 5); | 58 const char* working_directory = NULL; |
| 59 Dart_Handle exit_handle = Dart_GetNativeArgument(args, 6); | 59 if (Dart_IsString(working_directory_handle)) { |
| 60 working_directory = DartUtils::GetStringValue(working_directory_handle); | |
| 61 } else if (!Dart_IsNull(working_directory_handle)) { | |
| 62 delete[] string_args; | |
| 63 DartUtils::SetIntegerInstanceField(status_handle, "_errorCode", 0); | |
| 64 DartUtils::SetStringInstanceField( | |
| 65 status_handle, "_errorMessage", | |
| 66 "WorkingDirectory must be a builtin string"); | |
| 67 Dart_SetReturnValue(args, Dart_NewBoolean(false)); | |
| 68 Dart_ExitScope(); | |
| 69 return; | |
| 70 } | |
| 71 Dart_Handle in_handle = Dart_GetNativeArgument(args, 4); | |
| 72 Dart_Handle out_handle = Dart_GetNativeArgument(args, 5); | |
| 73 Dart_Handle err_handle = Dart_GetNativeArgument(args, 6); | |
| 74 Dart_Handle exit_handle = Dart_GetNativeArgument(args, 7); | |
| 60 intptr_t pid = -1; | 75 intptr_t pid = -1; |
| 61 static const int kMaxChildOsErrorMessageLength = 256; | 76 static const int kMaxChildOsErrorMessageLength = 256; |
| 62 char os_error_message[kMaxChildOsErrorMessageLength]; | 77 char os_error_message[kMaxChildOsErrorMessageLength]; |
| 63 | 78 |
| 64 int error_code = Process::Start( | 79 int error_code = Process::Start( |
| 65 path, string_args, length, | 80 path, string_args, length, working_directory, |
| 66 &in, &out, &err, &pid, &exit_event, | 81 &in, &out, &err, &pid, &exit_event, |
| 67 os_error_message, kMaxChildOsErrorMessageLength); | 82 os_error_message, kMaxChildOsErrorMessageLength); |
| 68 if (error_code == 0) { | 83 if (error_code == 0) { |
| 69 DartUtils::SetIntegerInstanceField(in_handle, DartUtils::kIdFieldName, in); | 84 DartUtils::SetIntegerInstanceField(in_handle, DartUtils::kIdFieldName, in); |
| 70 DartUtils::SetIntegerInstanceField( | 85 DartUtils::SetIntegerInstanceField( |
| 71 out_handle, DartUtils::kIdFieldName, out); | 86 out_handle, DartUtils::kIdFieldName, out); |
| 72 DartUtils::SetIntegerInstanceField( | 87 DartUtils::SetIntegerInstanceField( |
| 73 err_handle, DartUtils::kIdFieldName, err); | 88 err_handle, DartUtils::kIdFieldName, err); |
| 74 DartUtils::SetIntegerInstanceField( | 89 DartUtils::SetIntegerInstanceField( |
| 75 exit_handle, DartUtils::kIdFieldName, exit_event); | 90 exit_handle, DartUtils::kIdFieldName, exit_event); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 94 Dart_ExitScope(); | 109 Dart_ExitScope(); |
| 95 } | 110 } |
| 96 | 111 |
| 97 | 112 |
| 98 void FUNCTION_NAME(Process_Exit)(Dart_NativeArguments args) { | 113 void FUNCTION_NAME(Process_Exit)(Dart_NativeArguments args) { |
| 99 Dart_EnterScope(); | 114 Dart_EnterScope(); |
| 100 intptr_t pid = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); | 115 intptr_t pid = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); |
| 101 Process::Exit(pid); | 116 Process::Exit(pid); |
| 102 Dart_ExitScope(); | 117 Dart_ExitScope(); |
| 103 } | 118 } |
| OLD | NEW |