Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: runtime/bin/process.cc

Issue 22303002: Auto create ApiLocalScope before calling native functions, this ensures that (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 status_handle, "_errorMessage", error_msg); 52 status_handle, "_errorMessage", error_msg);
53 delete[] string_args; 53 delete[] string_args;
54 return NULL; 54 return NULL;
55 } 55 }
56 string_args[i] = const_cast<char *>(DartUtils::GetStringValue(arg)); 56 string_args[i] = const_cast<char *>(DartUtils::GetStringValue(arg));
57 } 57 }
58 return string_args; 58 return string_args;
59 } 59 }
60 60
61 void FUNCTION_NAME(Process_Start)(Dart_NativeArguments args) { 61 void FUNCTION_NAME(Process_Start)(Dart_NativeArguments args) {
62 Dart_EnterScope();
63 Dart_Handle process = Dart_GetNativeArgument(args, 0); 62 Dart_Handle process = Dart_GetNativeArgument(args, 0);
64 intptr_t process_stdin; 63 intptr_t process_stdin;
65 intptr_t process_stdout; 64 intptr_t process_stdout;
66 intptr_t process_stderr; 65 intptr_t process_stderr;
67 intptr_t exit_event; 66 intptr_t exit_event;
68 Dart_Handle status_handle = Dart_GetNativeArgument(args, 9); 67 Dart_Handle status_handle = Dart_GetNativeArgument(args, 9);
69 Dart_Handle path_handle = Dart_GetNativeArgument(args, 1); 68 Dart_Handle path_handle = Dart_GetNativeArgument(args, 1);
70 // The Dart code verifies that the path implements the String 69 // The Dart code verifies that the path implements the String
71 // interface. However, only builtin Strings are handled by 70 // interface. However, only builtin Strings are handled by
72 // GetStringValue. 71 // GetStringValue.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 } else { 149 } else {
151 DartUtils::SetIntegerField( 150 DartUtils::SetIntegerField(
152 status_handle, "_errorCode", error_code); 151 status_handle, "_errorCode", error_code);
153 DartUtils::SetStringField( 152 DartUtils::SetStringField(
154 status_handle, "_errorMessage", os_error_message); 153 status_handle, "_errorMessage", os_error_message);
155 } 154 }
156 delete[] string_args; 155 delete[] string_args;
157 delete[] string_environment; 156 delete[] string_environment;
158 free(os_error_message); 157 free(os_error_message);
159 Dart_SetReturnValue(args, Dart_NewBoolean(error_code == 0)); 158 Dart_SetReturnValue(args, Dart_NewBoolean(error_code == 0));
160 Dart_ExitScope();
161 } 159 }
162 160
163 161
164 void FUNCTION_NAME(Process_Kill)(Dart_NativeArguments args) { 162 void FUNCTION_NAME(Process_Kill)(Dart_NativeArguments args) {
165 Dart_EnterScope();
166 Dart_Handle process = Dart_GetNativeArgument(args, 1); 163 Dart_Handle process = Dart_GetNativeArgument(args, 1);
167 intptr_t pid = -1; 164 intptr_t pid = -1;
168 Process::GetProcessIdNativeField(process, &pid); 165 Process::GetProcessIdNativeField(process, &pid);
169 int signal = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); 166 int signal = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2));
170 bool success = Process::Kill(pid, signal); 167 bool success = Process::Kill(pid, signal);
171 Dart_SetReturnValue(args, Dart_NewBoolean(success)); 168 Dart_SetReturnValue(args, Dart_NewBoolean(success));
172 Dart_ExitScope();
173 } 169 }
174 170
175 171
176 void FUNCTION_NAME(Process_Exit)(Dart_NativeArguments args) { 172 void FUNCTION_NAME(Process_Exit)(Dart_NativeArguments args) {
177 Dart_EnterScope();
178 int64_t status = 0; 173 int64_t status = 0;
179 // Ignore result if passing invalid argument and just exit 0. 174 // Ignore result if passing invalid argument and just exit 0.
180 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); 175 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status);
181 Dart_ExitScope();
182 exit(static_cast<int>(status)); 176 exit(static_cast<int>(status));
183 } 177 }
184 178
185 179
186 void FUNCTION_NAME(Process_SetExitCode)(Dart_NativeArguments args) { 180 void FUNCTION_NAME(Process_SetExitCode)(Dart_NativeArguments args) {
187 Dart_EnterScope();
188 int64_t status = 0; 181 int64_t status = 0;
189 // Ignore result if passing invalid argument and just set exit code to 0. 182 // Ignore result if passing invalid argument and just set exit code to 0.
190 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); 183 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status);
191 Process::SetGlobalExitCode(status); 184 Process::SetGlobalExitCode(status);
192 Dart_ExitScope();
193 } 185 }
194 186
195 187
196 void FUNCTION_NAME(Process_Sleep)(Dart_NativeArguments args) { 188 void FUNCTION_NAME(Process_Sleep)(Dart_NativeArguments args) {
197 Dart_EnterScope();
198 int64_t milliseconds = 0; 189 int64_t milliseconds = 0;
199 // Ignore result if passing invalid argument and just set exit code to 0. 190 // Ignore result if passing invalid argument and just set exit code to 0.
200 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &milliseconds); 191 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &milliseconds);
201 TimerUtils::Sleep(milliseconds); 192 TimerUtils::Sleep(milliseconds);
202 Dart_ExitScope();
203 } 193 }
204 194
205 195
206 void FUNCTION_NAME(Process_Pid)(Dart_NativeArguments args) { 196 void FUNCTION_NAME(Process_Pid)(Dart_NativeArguments args) {
207 Dart_EnterScope();
208 // Ignore result if passing invalid argument and just set exit code to 0. 197 // Ignore result if passing invalid argument and just set exit code to 0.
209 intptr_t pid = -1; 198 intptr_t pid = -1;
210 Dart_Handle process = Dart_GetNativeArgument(args, 0); 199 Dart_Handle process = Dart_GetNativeArgument(args, 0);
211 if (Dart_IsNull(process)) { 200 if (Dart_IsNull(process)) {
212 pid = Process::CurrentProcessId(); 201 pid = Process::CurrentProcessId();
213 } else { 202 } else {
214 Process::GetProcessIdNativeField(process, &pid); 203 Process::GetProcessIdNativeField(process, &pid);
215 } 204 }
216 Dart_SetReturnValue(args, Dart_NewInteger(pid)); 205 Dart_SetReturnValue(args, Dart_NewInteger(pid));
217 Dart_ExitScope();
218 } 206 }
219 207
220 208
221 Dart_Handle Process::GetProcessIdNativeField(Dart_Handle process, 209 Dart_Handle Process::GetProcessIdNativeField(Dart_Handle process,
222 intptr_t* pid) { 210 intptr_t* pid) {
223 return Dart_GetNativeInstanceField(process, kProcessIdNativeField, pid); 211 return Dart_GetNativeInstanceField(process, kProcessIdNativeField, pid);
224 } 212 }
225 213
226 214
227 Dart_Handle Process::SetProcessIdNativeField(Dart_Handle process, 215 Dart_Handle Process::SetProcessIdNativeField(Dart_Handle process,
228 intptr_t pid) { 216 intptr_t pid) {
229 return Dart_SetNativeInstanceField(process, kProcessIdNativeField, pid); 217 return Dart_SetNativeInstanceField(process, kProcessIdNativeField, pid);
230 } 218 }
231 219
232 220
233 void FUNCTION_NAME(SystemEncodingToString)(Dart_NativeArguments args) { 221 void FUNCTION_NAME(SystemEncodingToString)(Dart_NativeArguments args) {
234 Dart_EnterScope();
235 Dart_Handle bytes = Dart_GetNativeArgument(args, 0); 222 Dart_Handle bytes = Dart_GetNativeArgument(args, 0);
236 intptr_t bytes_length = 0; 223 intptr_t bytes_length = 0;
237 Dart_Handle result = Dart_ListLength(bytes, &bytes_length); 224 Dart_Handle result = Dart_ListLength(bytes, &bytes_length);
238 if (Dart_IsError(result)) Dart_PropagateError(result); 225 if (Dart_IsError(result)) Dart_PropagateError(result);
239 uint8_t* buffer = new uint8_t[bytes_length + 1]; 226 uint8_t* buffer = new uint8_t[bytes_length + 1];
240 result = Dart_ListGetAsBytes(bytes, 0, buffer, bytes_length); 227 result = Dart_ListGetAsBytes(bytes, 0, buffer, bytes_length);
241 buffer[bytes_length] = '\0'; 228 buffer[bytes_length] = '\0';
242 if (Dart_IsError(result)) { 229 if (Dart_IsError(result)) {
243 delete[] buffer; 230 delete[] buffer;
244 Dart_PropagateError(result); 231 Dart_PropagateError(result);
245 } 232 }
246 char* str = 233 char* str =
247 StringUtils::ConsoleStringToUtf8(reinterpret_cast<char*>(buffer)); 234 StringUtils::ConsoleStringToUtf8(reinterpret_cast<char*>(buffer));
248 Dart_SetReturnValue(args, DartUtils::NewString(str)); 235 Dart_SetReturnValue(args, DartUtils::NewString(str));
249 if (str != reinterpret_cast<char*>(buffer)) free(str); 236 if (str != reinterpret_cast<char*>(buffer)) free(str);
250 Dart_ExitScope();
251 } 237 }
252 238
253 239
254 void FUNCTION_NAME(StringToSystemEncoding)(Dart_NativeArguments args) { 240 void FUNCTION_NAME(StringToSystemEncoding)(Dart_NativeArguments args) {
255 Dart_EnterScope();
256 Dart_Handle str = Dart_GetNativeArgument(args, 0); 241 Dart_Handle str = Dart_GetNativeArgument(args, 0);
257 const char* utf8 = DartUtils::GetStringValue(str); 242 const char* utf8 = DartUtils::GetStringValue(str);
258 const char* system_string = StringUtils::Utf8ToConsoleString(utf8); 243 const char* system_string = StringUtils::Utf8ToConsoleString(utf8);
259 int external_length = strlen(system_string); 244 int external_length = strlen(system_string);
260 uint8_t* buffer = NULL; 245 uint8_t* buffer = NULL;
261 Dart_Handle external_array = IOBuffer::Allocate(external_length, &buffer); 246 Dart_Handle external_array = IOBuffer::Allocate(external_length, &buffer);
262 memmove(buffer, system_string, external_length); 247 memmove(buffer, system_string, external_length);
263 if (utf8 != system_string) free(const_cast<char*>(system_string)); 248 if (utf8 != system_string) free(const_cast<char*>(system_string));
264 Dart_SetReturnValue(args, external_array); 249 Dart_SetReturnValue(args, external_array);
265 Dart_ExitScope();
266 } 250 }
267 251
268 } // namespace bin 252 } // namespace bin
269 } // namespace dart 253 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/platform.cc ('k') | runtime/bin/secure_socket.cc » ('j') | runtime/vm/ast.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698