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

Side by Side Diff: runtime/bin/file.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
« no previous file with comments | « runtime/bin/eventhandler.cc ('k') | runtime/bin/filter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/file.h" 5 #include "bin/file.h"
6 6
7 #include "bin/builtin.h" 7 #include "bin/builtin.h"
8 #include "bin/dartutils.h" 8 #include "bin/dartutils.h"
9 #include "bin/io_buffer.h" 9 #include "bin/io_buffer.h"
10 #include "bin/thread.h" 10 #include "bin/thread.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 return File::kWriteTruncate; 70 return File::kWriteTruncate;
71 } 71 }
72 if (mode == File::kDartAppend) { 72 if (mode == File::kDartAppend) {
73 return File::kWrite; 73 return File::kWrite;
74 } 74 }
75 return File::kRead; 75 return File::kRead;
76 } 76 }
77 77
78 78
79 void FUNCTION_NAME(File_Open)(Dart_NativeArguments args) { 79 void FUNCTION_NAME(File_Open)(Dart_NativeArguments args) {
80 Dart_EnterScope();
81 const char* filename = 80 const char* filename =
82 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); 81 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
83 int64_t mode = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); 82 int64_t mode = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1));
84 File::DartFileOpenMode dart_file_mode = 83 File::DartFileOpenMode dart_file_mode =
85 static_cast<File::DartFileOpenMode>(mode); 84 static_cast<File::DartFileOpenMode>(mode);
86 File::FileOpenMode file_mode = File::DartModeToFileMode(dart_file_mode); 85 File::FileOpenMode file_mode = File::DartModeToFileMode(dart_file_mode);
87 // Check that the file exists before opening it only for 86 // Check that the file exists before opening it only for
88 // reading. This is to prevent the opening of directories as 87 // reading. This is to prevent the opening of directories as
89 // files. Directories can be opened for reading using the posix 88 // files. Directories can be opened for reading using the posix
90 // 'open' call. 89 // 'open' call.
91 File* file = NULL; 90 File* file = NULL;
92 file = File::Open(filename, file_mode); 91 file = File::Open(filename, file_mode);
93 if (file != NULL) { 92 if (file != NULL) {
94 Dart_SetReturnValue(args, 93 Dart_SetReturnValue(args,
95 Dart_NewInteger(reinterpret_cast<intptr_t>(file))); 94 Dart_NewInteger(reinterpret_cast<intptr_t>(file)));
96 } else { 95 } else {
97 Dart_Handle err = DartUtils::NewDartOSError(); 96 Dart_Handle err = DartUtils::NewDartOSError();
98 if (Dart_IsError(err)) Dart_PropagateError(err); 97 if (Dart_IsError(err)) Dart_PropagateError(err);
99 Dart_SetReturnValue(args, err); 98 Dart_SetReturnValue(args, err);
100 } 99 }
101 Dart_ExitScope();
102 } 100 }
103 101
104 102
105 void FUNCTION_NAME(File_Exists)(Dart_NativeArguments args) { 103 void FUNCTION_NAME(File_Exists)(Dart_NativeArguments args) {
106 Dart_EnterScope();
107 const char* filename = 104 const char* filename =
108 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); 105 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
109 bool exists = File::Exists(filename); 106 bool exists = File::Exists(filename);
110 Dart_SetReturnValue(args, Dart_NewBoolean(exists)); 107 Dart_SetReturnValue(args, Dart_NewBoolean(exists));
111 Dart_ExitScope();
112 } 108 }
113 109
114 110
115 void FUNCTION_NAME(File_Close)(Dart_NativeArguments args) { 111 void FUNCTION_NAME(File_Close)(Dart_NativeArguments args) {
116 Dart_EnterScope();
117 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0)); 112 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0));
118 ASSERT(file != NULL); 113 ASSERT(file != NULL);
119 delete file; 114 delete file;
120 Dart_SetReturnValue(args, Dart_NewInteger(0)); 115 Dart_SetReturnValue(args, Dart_NewInteger(0));
121 Dart_ExitScope();
122 } 116 }
123 117
124 118
125 void FUNCTION_NAME(File_ReadByte)(Dart_NativeArguments args) { 119 void FUNCTION_NAME(File_ReadByte)(Dart_NativeArguments args) {
126 Dart_EnterScope();
127 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0)); 120 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0));
128 ASSERT(file != NULL); 121 ASSERT(file != NULL);
129 uint8_t buffer; 122 uint8_t buffer;
130 int64_t bytes_read = file->Read(reinterpret_cast<void*>(&buffer), 1); 123 int64_t bytes_read = file->Read(reinterpret_cast<void*>(&buffer), 1);
131 if (bytes_read == 1) { 124 if (bytes_read == 1) {
132 Dart_SetReturnValue(args, Dart_NewInteger(buffer)); 125 Dart_SetReturnValue(args, Dart_NewInteger(buffer));
133 } else if (bytes_read == 0) { 126 } else if (bytes_read == 0) {
134 Dart_SetReturnValue(args, Dart_NewInteger(-1)); 127 Dart_SetReturnValue(args, Dart_NewInteger(-1));
135 } else { 128 } else {
136 Dart_Handle err = DartUtils::NewDartOSError(); 129 Dart_Handle err = DartUtils::NewDartOSError();
137 if (Dart_IsError(err)) Dart_PropagateError(err); 130 if (Dart_IsError(err)) Dart_PropagateError(err);
138 Dart_SetReturnValue(args, err); 131 Dart_SetReturnValue(args, err);
139 } 132 }
140 Dart_ExitScope();
141 } 133 }
142 134
143 135
144 void FUNCTION_NAME(File_WriteByte)(Dart_NativeArguments args) { 136 void FUNCTION_NAME(File_WriteByte)(Dart_NativeArguments args) {
145 Dart_EnterScope();
146 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0)); 137 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0));
147 ASSERT(file != NULL); 138 ASSERT(file != NULL);
148 int64_t byte = 0; 139 int64_t byte = 0;
149 if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &byte)) { 140 if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &byte)) {
150 uint8_t buffer = static_cast<uint8_t>(byte & 0xff); 141 uint8_t buffer = static_cast<uint8_t>(byte & 0xff);
151 int64_t bytes_written = file->Write(reinterpret_cast<void*>(&buffer), 1); 142 int64_t bytes_written = file->Write(reinterpret_cast<void*>(&buffer), 1);
152 if (bytes_written >= 0) { 143 if (bytes_written >= 0) {
153 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); 144 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written));
154 } else { 145 } else {
155 Dart_Handle err = DartUtils::NewDartOSError(); 146 Dart_Handle err = DartUtils::NewDartOSError();
156 if (Dart_IsError(err)) Dart_PropagateError(err); 147 if (Dart_IsError(err)) Dart_PropagateError(err);
157 Dart_SetReturnValue(args, err); 148 Dart_SetReturnValue(args, err);
158 } 149 }
159 } else { 150 } else {
160 OSError os_error(-1, "Invalid argument", OSError::kUnknown); 151 OSError os_error(-1, "Invalid argument", OSError::kUnknown);
161 Dart_Handle err = DartUtils::NewDartOSError(&os_error); 152 Dart_Handle err = DartUtils::NewDartOSError(&os_error);
162 if (Dart_IsError(err)) Dart_PropagateError(err); 153 if (Dart_IsError(err)) Dart_PropagateError(err);
163 Dart_SetReturnValue(args, err); 154 Dart_SetReturnValue(args, err);
164 } 155 }
165 Dart_ExitScope();
166 } 156 }
167 157
168 158
169 void FUNCTION_NAME(File_Read)(Dart_NativeArguments args) { 159 void FUNCTION_NAME(File_Read)(Dart_NativeArguments args) {
170 Dart_EnterScope();
171 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0)); 160 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0));
172 ASSERT(file != NULL); 161 ASSERT(file != NULL);
173 Dart_Handle length_object = Dart_GetNativeArgument(args, 1); 162 Dart_Handle length_object = Dart_GetNativeArgument(args, 1);
174 int64_t length = 0; 163 int64_t length = 0;
175 if (DartUtils::GetInt64Value(length_object, &length)) { 164 if (DartUtils::GetInt64Value(length_object, &length)) {
176 uint8_t* buffer = NULL; 165 uint8_t* buffer = NULL;
177 Dart_Handle external_array = IOBuffer::Allocate(length, &buffer); 166 Dart_Handle external_array = IOBuffer::Allocate(length, &buffer);
178 int64_t bytes_read = file->Read(reinterpret_cast<void*>(buffer), length); 167 int64_t bytes_read = file->Read(reinterpret_cast<void*>(buffer), length);
179 if (bytes_read < 0) { 168 if (bytes_read < 0) {
180 Dart_Handle err = DartUtils::NewDartOSError(); 169 Dart_Handle err = DartUtils::NewDartOSError();
(...skipping 20 matching lines...) Expand all
201 } else { 190 } else {
202 Dart_SetReturnValue(args, external_array); 191 Dart_SetReturnValue(args, external_array);
203 } 192 }
204 } 193 }
205 } else { 194 } else {
206 OSError os_error(-1, "Invalid argument", OSError::kUnknown); 195 OSError os_error(-1, "Invalid argument", OSError::kUnknown);
207 Dart_Handle err = DartUtils::NewDartOSError(&os_error); 196 Dart_Handle err = DartUtils::NewDartOSError(&os_error);
208 if (Dart_IsError(err)) Dart_PropagateError(err); 197 if (Dart_IsError(err)) Dart_PropagateError(err);
209 Dart_SetReturnValue(args, err); 198 Dart_SetReturnValue(args, err);
210 } 199 }
211 Dart_ExitScope();
212 } 200 }
213 201
214 202
215 void FUNCTION_NAME(File_ReadInto)(Dart_NativeArguments args) { 203 void FUNCTION_NAME(File_ReadInto)(Dart_NativeArguments args) {
216 Dart_EnterScope();
217 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0)); 204 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0));
218 ASSERT(file != NULL); 205 ASSERT(file != NULL);
219 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); 206 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1);
220 ASSERT(Dart_IsList(buffer_obj)); 207 ASSERT(Dart_IsList(buffer_obj));
221 // start and end arguments are checked in Dart code to be 208 // start and end arguments are checked in Dart code to be
222 // integers and have the property that end <= 209 // integers and have the property that end <=
223 // list.length. Therefore, it is safe to extract their value as 210 // list.length. Therefore, it is safe to extract their value as
224 // intptr_t. 211 // intptr_t.
225 intptr_t start = 212 intptr_t start =
226 DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2)); 213 DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2));
(...skipping 12 matching lines...) Expand all
239 delete[] buffer; 226 delete[] buffer;
240 Dart_PropagateError(result); 227 Dart_PropagateError(result);
241 } 228 }
242 Dart_SetReturnValue(args, Dart_NewInteger(bytes_read)); 229 Dart_SetReturnValue(args, Dart_NewInteger(bytes_read));
243 } else { 230 } else {
244 Dart_Handle err = DartUtils::NewDartOSError(); 231 Dart_Handle err = DartUtils::NewDartOSError();
245 if (Dart_IsError(err)) Dart_PropagateError(err); 232 if (Dart_IsError(err)) Dart_PropagateError(err);
246 Dart_SetReturnValue(args, err); 233 Dart_SetReturnValue(args, err);
247 } 234 }
248 delete[] buffer; 235 delete[] buffer;
249 Dart_ExitScope();
250 } 236 }
251 237
252 238
253 void FUNCTION_NAME(File_WriteFrom)(Dart_NativeArguments args) { 239 void FUNCTION_NAME(File_WriteFrom)(Dart_NativeArguments args) {
254 Dart_EnterScope();
255 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0)); 240 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0));
256 ASSERT(file != NULL); 241 ASSERT(file != NULL);
257 242
258 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); 243 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1);
259 244
260 // Offset and length arguments are checked in Dart code to be 245 // Offset and length arguments are checked in Dart code to be
261 // integers and have the property that (offset + length) <= 246 // integers and have the property that (offset + length) <=
262 // list.length. Therefore, it is safe to extract their value as 247 // list.length. Therefore, it is safe to extract their value as
263 // intptr_t. 248 // intptr_t.
264 intptr_t start = 249 intptr_t start =
(...skipping 20 matching lines...) Expand all
285 270
286 // Release the direct pointer acquired above. 271 // Release the direct pointer acquired above.
287 result = Dart_TypedDataReleaseData(buffer_obj); 272 result = Dart_TypedDataReleaseData(buffer_obj);
288 if (Dart_IsError(result)) Dart_PropagateError(result); 273 if (Dart_IsError(result)) Dart_PropagateError(result);
289 274
290 if (bytes_written != length) { 275 if (bytes_written != length) {
291 Dart_Handle err = DartUtils::NewDartOSError(); 276 Dart_Handle err = DartUtils::NewDartOSError();
292 if (Dart_IsError(err)) Dart_PropagateError(err); 277 if (Dart_IsError(err)) Dart_PropagateError(err);
293 Dart_SetReturnValue(args, err); 278 Dart_SetReturnValue(args, err);
294 } 279 }
295 Dart_ExitScope();
296 } 280 }
297 281
298 282
299 void FUNCTION_NAME(File_Position)(Dart_NativeArguments args) { 283 void FUNCTION_NAME(File_Position)(Dart_NativeArguments args) {
300 Dart_EnterScope();
301 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0)); 284 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0));
302 ASSERT(file != NULL); 285 ASSERT(file != NULL);
303 intptr_t return_value = file->Position(); 286 intptr_t return_value = file->Position();
304 if (return_value >= 0) { 287 if (return_value >= 0) {
305 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); 288 Dart_SetReturnValue(args, Dart_NewInteger(return_value));
306 } else { 289 } else {
307 Dart_Handle err = DartUtils::NewDartOSError(); 290 Dart_Handle err = DartUtils::NewDartOSError();
308 if (Dart_IsError(err)) Dart_PropagateError(err); 291 if (Dart_IsError(err)) Dart_PropagateError(err);
309 Dart_SetReturnValue(args, err); 292 Dart_SetReturnValue(args, err);
310 } 293 }
311 Dart_ExitScope();
312 } 294 }
313 295
314 296
315 void FUNCTION_NAME(File_SetPosition)(Dart_NativeArguments args) { 297 void FUNCTION_NAME(File_SetPosition)(Dart_NativeArguments args) {
316 Dart_EnterScope();
317 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0)); 298 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0));
318 ASSERT(file != NULL); 299 ASSERT(file != NULL);
319 int64_t position = 0; 300 int64_t position = 0;
320 if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &position)) { 301 if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &position)) {
321 if (file->SetPosition(position)) { 302 if (file->SetPosition(position)) {
322 Dart_SetReturnValue(args, Dart_True()); 303 Dart_SetReturnValue(args, Dart_True());
323 } else { 304 } else {
324 Dart_Handle err = DartUtils::NewDartOSError(); 305 Dart_Handle err = DartUtils::NewDartOSError();
325 if (Dart_IsError(err)) Dart_PropagateError(err); 306 if (Dart_IsError(err)) Dart_PropagateError(err);
326 Dart_SetReturnValue(args, err); 307 Dart_SetReturnValue(args, err);
327 } 308 }
328 } else { 309 } else {
329 OSError os_error(-1, "Invalid argument", OSError::kUnknown); 310 OSError os_error(-1, "Invalid argument", OSError::kUnknown);
330 Dart_Handle err = DartUtils::NewDartOSError(&os_error); 311 Dart_Handle err = DartUtils::NewDartOSError(&os_error);
331 if (Dart_IsError(err)) Dart_PropagateError(err); 312 if (Dart_IsError(err)) Dart_PropagateError(err);
332 Dart_SetReturnValue(args, err); 313 Dart_SetReturnValue(args, err);
333 } 314 }
334 Dart_ExitScope();
335 } 315 }
336 316
337 317
338 void FUNCTION_NAME(File_Truncate)(Dart_NativeArguments args) { 318 void FUNCTION_NAME(File_Truncate)(Dart_NativeArguments args) {
339 Dart_EnterScope();
340 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0)); 319 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0));
341 ASSERT(file != NULL); 320 ASSERT(file != NULL);
342 int64_t length = 0; 321 int64_t length = 0;
343 if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &length)) { 322 if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &length)) {
344 if (file->Truncate(length)) { 323 if (file->Truncate(length)) {
345 Dart_SetReturnValue(args, Dart_True()); 324 Dart_SetReturnValue(args, Dart_True());
346 } else { 325 } else {
347 Dart_Handle err = DartUtils::NewDartOSError(); 326 Dart_Handle err = DartUtils::NewDartOSError();
348 if (Dart_IsError(err)) Dart_PropagateError(err); 327 if (Dart_IsError(err)) Dart_PropagateError(err);
349 Dart_SetReturnValue(args, err); 328 Dart_SetReturnValue(args, err);
350 } 329 }
351 } else { 330 } else {
352 OSError os_error(-1, "Invalid argument", OSError::kUnknown); 331 OSError os_error(-1, "Invalid argument", OSError::kUnknown);
353 Dart_Handle err = DartUtils::NewDartOSError(&os_error); 332 Dart_Handle err = DartUtils::NewDartOSError(&os_error);
354 if (Dart_IsError(err)) Dart_PropagateError(err); 333 if (Dart_IsError(err)) Dart_PropagateError(err);
355 Dart_SetReturnValue(args, err); 334 Dart_SetReturnValue(args, err);
356 } 335 }
357 Dart_ExitScope();
358 } 336 }
359 337
360 338
361 void FUNCTION_NAME(File_Length)(Dart_NativeArguments args) { 339 void FUNCTION_NAME(File_Length)(Dart_NativeArguments args) {
362 Dart_EnterScope();
363 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0)); 340 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0));
364 ASSERT(file != NULL); 341 ASSERT(file != NULL);
365 intptr_t return_value = file->Length(); 342 intptr_t return_value = file->Length();
366 if (return_value >= 0) { 343 if (return_value >= 0) {
367 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); 344 Dart_SetReturnValue(args, Dart_NewInteger(return_value));
368 } else { 345 } else {
369 Dart_Handle err = DartUtils::NewDartOSError(); 346 Dart_Handle err = DartUtils::NewDartOSError();
370 if (Dart_IsError(err)) Dart_PropagateError(err); 347 if (Dart_IsError(err)) Dart_PropagateError(err);
371 Dart_SetReturnValue(args, err); 348 Dart_SetReturnValue(args, err);
372 } 349 }
373 Dart_ExitScope();
374 } 350 }
375 351
376 352
377 void FUNCTION_NAME(File_LengthFromPath)(Dart_NativeArguments args) { 353 void FUNCTION_NAME(File_LengthFromPath)(Dart_NativeArguments args) {
378 Dart_EnterScope();
379 const char* path = 354 const char* path =
380 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); 355 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
381 intptr_t return_value = File::LengthFromPath(path); 356 intptr_t return_value = File::LengthFromPath(path);
382 if (return_value >= 0) { 357 if (return_value >= 0) {
383 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); 358 Dart_SetReturnValue(args, Dart_NewInteger(return_value));
384 } else { 359 } else {
385 Dart_Handle err = DartUtils::NewDartOSError(); 360 Dart_Handle err = DartUtils::NewDartOSError();
386 if (Dart_IsError(err)) Dart_PropagateError(err); 361 if (Dart_IsError(err)) Dart_PropagateError(err);
387 Dart_SetReturnValue(args, err); 362 Dart_SetReturnValue(args, err);
388 } 363 }
389 Dart_ExitScope();
390 } 364 }
391 365
392 366
393 void FUNCTION_NAME(File_LastModified)(Dart_NativeArguments args) { 367 void FUNCTION_NAME(File_LastModified)(Dart_NativeArguments args) {
394 Dart_EnterScope();
395 const char* name = 368 const char* name =
396 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); 369 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
397 int64_t return_value = File::LastModified(name); 370 int64_t return_value = File::LastModified(name);
398 if (return_value >= 0) { 371 if (return_value >= 0) {
399 Dart_SetReturnValue(args, Dart_NewInteger(return_value * kMSPerSecond)); 372 Dart_SetReturnValue(args, Dart_NewInteger(return_value * kMSPerSecond));
400 } else { 373 } else {
401 Dart_Handle err = DartUtils::NewDartOSError(); 374 Dart_Handle err = DartUtils::NewDartOSError();
402 if (Dart_IsError(err)) Dart_PropagateError(err); 375 if (Dart_IsError(err)) Dart_PropagateError(err);
403 Dart_SetReturnValue(args, err); 376 Dart_SetReturnValue(args, err);
404 } 377 }
405 Dart_ExitScope();
406 } 378 }
407 379
408 380
409 void FUNCTION_NAME(File_Flush)(Dart_NativeArguments args) { 381 void FUNCTION_NAME(File_Flush)(Dart_NativeArguments args) {
410 Dart_EnterScope();
411 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0)); 382 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0));
412 ASSERT(file != NULL); 383 ASSERT(file != NULL);
413 if (file->Flush()) { 384 if (file->Flush()) {
414 Dart_SetReturnValue(args, Dart_True()); 385 Dart_SetReturnValue(args, Dart_True());
415 } else { 386 } else {
416 Dart_Handle err = DartUtils::NewDartOSError(); 387 Dart_Handle err = DartUtils::NewDartOSError();
417 if (Dart_IsError(err)) Dart_PropagateError(err); 388 if (Dart_IsError(err)) Dart_PropagateError(err);
418 Dart_SetReturnValue(args, err); 389 Dart_SetReturnValue(args, err);
419 } 390 }
420 Dart_ExitScope();
421 } 391 }
422 392
423 393
424 void FUNCTION_NAME(File_Create)(Dart_NativeArguments args) { 394 void FUNCTION_NAME(File_Create)(Dart_NativeArguments args) {
425 Dart_EnterScope();
426 const char* str = 395 const char* str =
427 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); 396 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
428 bool result = File::Create(str); 397 bool result = File::Create(str);
429 if (result) { 398 if (result) {
430 Dart_SetReturnValue(args, Dart_NewBoolean(result)); 399 Dart_SetReturnValue(args, Dart_NewBoolean(result));
431 } else { 400 } else {
432 Dart_Handle err = DartUtils::NewDartOSError(); 401 Dart_Handle err = DartUtils::NewDartOSError();
433 if (Dart_IsError(err)) Dart_PropagateError(err); 402 if (Dart_IsError(err)) Dart_PropagateError(err);
434 Dart_SetReturnValue(args, err); 403 Dart_SetReturnValue(args, err);
435 } 404 }
436 Dart_ExitScope();
437 } 405 }
438 406
439 407
440 void FUNCTION_NAME(File_CreateLink)(Dart_NativeArguments args) { 408 void FUNCTION_NAME(File_CreateLink)(Dart_NativeArguments args) {
441 Dart_EnterScope();
442 if (Dart_IsString(Dart_GetNativeArgument(args, 0)) && 409 if (Dart_IsString(Dart_GetNativeArgument(args, 0)) &&
443 Dart_IsString(Dart_GetNativeArgument(args, 1))) { 410 Dart_IsString(Dart_GetNativeArgument(args, 1))) {
444 const char* name = 411 const char* name =
445 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); 412 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
446 const char* target = 413 const char* target =
447 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1)); 414 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
448 if (!File::CreateLink(name, target)) { 415 if (!File::CreateLink(name, target)) {
449 Dart_Handle err = DartUtils::NewDartOSError(); 416 Dart_Handle err = DartUtils::NewDartOSError();
450 if (Dart_IsError(err)) Dart_PropagateError(err); 417 if (Dart_IsError(err)) Dart_PropagateError(err);
451 Dart_SetReturnValue(args, err); 418 Dart_SetReturnValue(args, err);
452 } 419 }
453 } else { 420 } else {
454 Dart_Handle err = DartUtils::NewDartArgumentError( 421 Dart_Handle err = DartUtils::NewDartArgumentError(
455 "Non-string argument to Link.create"); 422 "Non-string argument to Link.create");
456 if (Dart_IsError(err)) Dart_PropagateError(err); 423 if (Dart_IsError(err)) Dart_PropagateError(err);
457 Dart_SetReturnValue(args, err); 424 Dart_SetReturnValue(args, err);
458 } 425 }
459 Dart_ExitScope();
460 } 426 }
461 427
462 428
463 void FUNCTION_NAME(File_LinkTarget)(Dart_NativeArguments args) { 429 void FUNCTION_NAME(File_LinkTarget)(Dart_NativeArguments args) {
464 Dart_EnterScope();
465 if (Dart_IsString(Dart_GetNativeArgument(args, 0))) { 430 if (Dart_IsString(Dart_GetNativeArgument(args, 0))) {
466 const char* name = 431 const char* name =
467 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); 432 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
468 char* target = File::LinkTarget(name); 433 char* target = File::LinkTarget(name);
469 if (target == NULL) { 434 if (target == NULL) {
470 Dart_Handle err = DartUtils::NewDartOSError(); 435 Dart_Handle err = DartUtils::NewDartOSError();
471 if (Dart_IsError(err)) Dart_PropagateError(err); 436 if (Dart_IsError(err)) Dart_PropagateError(err);
472 Dart_SetReturnValue(args, err); 437 Dart_SetReturnValue(args, err);
473 } else { 438 } else {
474 Dart_SetReturnValue(args, DartUtils::NewString(target)); 439 Dart_SetReturnValue(args, DartUtils::NewString(target));
475 free(target); 440 free(target);
476 } 441 }
477 } else { 442 } else {
478 Dart_Handle err = DartUtils::NewDartArgumentError( 443 Dart_Handle err = DartUtils::NewDartArgumentError(
479 "Non-string argument to Link.target"); 444 "Non-string argument to Link.target");
480 if (Dart_IsError(err)) Dart_PropagateError(err); 445 if (Dart_IsError(err)) Dart_PropagateError(err);
481 Dart_SetReturnValue(args, err); 446 Dart_SetReturnValue(args, err);
482 } 447 }
483 Dart_ExitScope();
484 } 448 }
485 449
486 450
487 void FUNCTION_NAME(File_Delete)(Dart_NativeArguments args) { 451 void FUNCTION_NAME(File_Delete)(Dart_NativeArguments args) {
488 Dart_EnterScope();
489 const char* str = 452 const char* str =
490 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); 453 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
491 bool result = File::Delete(str); 454 bool result = File::Delete(str);
492 if (result) { 455 if (result) {
493 Dart_SetReturnValue(args, Dart_NewBoolean(result)); 456 Dart_SetReturnValue(args, Dart_NewBoolean(result));
494 } else { 457 } else {
495 Dart_Handle err = DartUtils::NewDartOSError(); 458 Dart_Handle err = DartUtils::NewDartOSError();
496 if (Dart_IsError(err)) Dart_PropagateError(err); 459 if (Dart_IsError(err)) Dart_PropagateError(err);
497 Dart_SetReturnValue(args, err); 460 Dart_SetReturnValue(args, err);
498 } 461 }
499 Dart_ExitScope();
500 } 462 }
501 463
502 464
503 void FUNCTION_NAME(File_DeleteLink)(Dart_NativeArguments args) { 465 void FUNCTION_NAME(File_DeleteLink)(Dart_NativeArguments args) {
504 Dart_EnterScope();
505 const char* str = 466 const char* str =
506 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); 467 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
507 bool result = File::DeleteLink(str); 468 bool result = File::DeleteLink(str);
508 if (result) { 469 if (result) {
509 Dart_SetReturnValue(args, Dart_NewBoolean(result)); 470 Dart_SetReturnValue(args, Dart_NewBoolean(result));
510 } else { 471 } else {
511 Dart_Handle err = DartUtils::NewDartOSError(); 472 Dart_Handle err = DartUtils::NewDartOSError();
512 if (Dart_IsError(err)) Dart_PropagateError(err); 473 if (Dart_IsError(err)) Dart_PropagateError(err);
513 Dart_SetReturnValue(args, err); 474 Dart_SetReturnValue(args, err);
514 } 475 }
515 Dart_ExitScope();
516 } 476 }
517 477
518 478
519 void FUNCTION_NAME(File_Rename)(Dart_NativeArguments args) { 479 void FUNCTION_NAME(File_Rename)(Dart_NativeArguments args) {
520 Dart_EnterScope();
521 const char* old_path = 480 const char* old_path =
522 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); 481 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
523 const char* new_path = 482 const char* new_path =
524 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1)); 483 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
525 bool result = File::Rename(old_path, new_path); 484 bool result = File::Rename(old_path, new_path);
526 if (result) { 485 if (result) {
527 Dart_SetReturnValue(args, Dart_NewBoolean(result)); 486 Dart_SetReturnValue(args, Dart_NewBoolean(result));
528 } else { 487 } else {
529 Dart_Handle err = DartUtils::NewDartOSError(); 488 Dart_Handle err = DartUtils::NewDartOSError();
530 if (Dart_IsError(err)) Dart_PropagateError(err); 489 if (Dart_IsError(err)) Dart_PropagateError(err);
531 Dart_SetReturnValue(args, err); 490 Dart_SetReturnValue(args, err);
532 } 491 }
533 Dart_ExitScope();
534 } 492 }
535 493
536 494
537 void FUNCTION_NAME(File_RenameLink)(Dart_NativeArguments args) { 495 void FUNCTION_NAME(File_RenameLink)(Dart_NativeArguments args) {
538 Dart_EnterScope();
539 const char* old_path = 496 const char* old_path =
540 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); 497 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
541 const char* new_path = 498 const char* new_path =
542 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1)); 499 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
543 bool result = File::RenameLink(old_path, new_path); 500 bool result = File::RenameLink(old_path, new_path);
544 if (result) { 501 if (result) {
545 Dart_SetReturnValue(args, Dart_NewBoolean(result)); 502 Dart_SetReturnValue(args, Dart_NewBoolean(result));
546 } else { 503 } else {
547 Dart_Handle err = DartUtils::NewDartOSError(); 504 Dart_Handle err = DartUtils::NewDartOSError();
548 if (Dart_IsError(err)) Dart_PropagateError(err); 505 if (Dart_IsError(err)) Dart_PropagateError(err);
549 Dart_SetReturnValue(args, err); 506 Dart_SetReturnValue(args, err);
550 } 507 }
551 Dart_ExitScope();
552 } 508 }
553 509
554 510
555 void FUNCTION_NAME(File_FullPath)(Dart_NativeArguments args) { 511 void FUNCTION_NAME(File_FullPath)(Dart_NativeArguments args) {
556 Dart_EnterScope();
557 const char* str = 512 const char* str =
558 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); 513 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
559 char* path = File::GetCanonicalPath(str); 514 char* path = File::GetCanonicalPath(str);
560 if (path != NULL) { 515 if (path != NULL) {
561 Dart_SetReturnValue(args, DartUtils::NewString(path)); 516 Dart_SetReturnValue(args, DartUtils::NewString(path));
562 free(path); 517 free(path);
563 } else { 518 } else {
564 Dart_Handle err = DartUtils::NewDartOSError(); 519 Dart_Handle err = DartUtils::NewDartOSError();
565 if (Dart_IsError(err)) Dart_PropagateError(err); 520 if (Dart_IsError(err)) Dart_PropagateError(err);
566 Dart_SetReturnValue(args, err); 521 Dart_SetReturnValue(args, err);
567 } 522 }
568 Dart_ExitScope();
569 } 523 }
570 524
571 525
572 void FUNCTION_NAME(File_OpenStdio)(Dart_NativeArguments args) { 526 void FUNCTION_NAME(File_OpenStdio)(Dart_NativeArguments args) {
573 Dart_EnterScope();
574 int64_t fd = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); 527 int64_t fd = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0));
575 ASSERT(fd == 0 || fd == 1 || fd == 2); 528 ASSERT(fd == 0 || fd == 1 || fd == 2);
576 File* file = File::OpenStdio(static_cast<int>(fd)); 529 File* file = File::OpenStdio(static_cast<int>(fd));
577 Dart_SetReturnValue(args, Dart_NewInteger(reinterpret_cast<intptr_t>(file))); 530 Dart_SetReturnValue(args, Dart_NewInteger(reinterpret_cast<intptr_t>(file)));
578 Dart_ExitScope();
579 } 531 }
580 532
581 533
582 void FUNCTION_NAME(File_GetStdioHandleType)(Dart_NativeArguments args) { 534 void FUNCTION_NAME(File_GetStdioHandleType)(Dart_NativeArguments args) {
583 Dart_EnterScope();
584 int64_t fd = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); 535 int64_t fd = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0));
585 ASSERT(fd == 0 || fd == 1 || fd == 2); 536 ASSERT(fd == 0 || fd == 1 || fd == 2);
586 File::StdioHandleType type = File::GetStdioHandleType(static_cast<int>(fd)); 537 File::StdioHandleType type = File::GetStdioHandleType(static_cast<int>(fd));
587 Dart_SetReturnValue(args, Dart_NewInteger(type)); 538 Dart_SetReturnValue(args, Dart_NewInteger(type));
588 Dart_ExitScope();
589 } 539 }
590 540
591 541
592 void FUNCTION_NAME(File_GetType)(Dart_NativeArguments args) { 542 void FUNCTION_NAME(File_GetType)(Dart_NativeArguments args) {
593 Dart_EnterScope();
594 if (Dart_IsString(Dart_GetNativeArgument(args, 0)) && 543 if (Dart_IsString(Dart_GetNativeArgument(args, 0)) &&
595 Dart_IsBoolean(Dart_GetNativeArgument(args, 1))) { 544 Dart_IsBoolean(Dart_GetNativeArgument(args, 1))) {
596 const char* str = 545 const char* str =
597 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); 546 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
598 bool follow_links = 547 bool follow_links =
599 DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 1)); 548 DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 1));
600 File::Type type = File::GetType(str, follow_links); 549 File::Type type = File::GetType(str, follow_links);
601 Dart_SetReturnValue(args, Dart_NewInteger(static_cast<int>(type))); 550 Dart_SetReturnValue(args, Dart_NewInteger(static_cast<int>(type)));
602 } else { 551 } else {
603 Dart_Handle err = DartUtils::NewDartArgumentError( 552 Dart_Handle err = DartUtils::NewDartArgumentError(
604 "Non-string argument to FileSystemEntity.type"); 553 "Non-string argument to FileSystemEntity.type");
605 if (Dart_IsError(err)) Dart_PropagateError(err); 554 if (Dart_IsError(err)) Dart_PropagateError(err);
606 Dart_SetReturnValue(args, err); 555 Dart_SetReturnValue(args, err);
607 } 556 }
608 Dart_ExitScope();
609 } 557 }
610 558
611 559
612 void FUNCTION_NAME(File_Stat)(Dart_NativeArguments args) { 560 void FUNCTION_NAME(File_Stat)(Dart_NativeArguments args) {
613 Dart_EnterScope();
614 if (Dart_IsString(Dart_GetNativeArgument(args, 0))) { 561 if (Dart_IsString(Dart_GetNativeArgument(args, 0))) {
615 const char* path = 562 const char* path =
616 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); 563 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
617 564
618 int64_t stat_data[File::kStatSize]; 565 int64_t stat_data[File::kStatSize];
619 File::Stat(path, stat_data); 566 File::Stat(path, stat_data);
620 if (stat_data[File::kType] == File::kDoesNotExist) { 567 if (stat_data[File::kType] == File::kDoesNotExist) {
621 Dart_Handle err = DartUtils::NewDartOSError(); 568 Dart_Handle err = DartUtils::NewDartOSError();
622 if (Dart_IsError(err)) Dart_PropagateError(err); 569 if (Dart_IsError(err)) Dart_PropagateError(err);
623 Dart_SetReturnValue(args, err); 570 Dart_SetReturnValue(args, err);
(...skipping 13 matching lines...) Expand all
637 status = Dart_TypedDataReleaseData(returned_data); 584 status = Dart_TypedDataReleaseData(returned_data);
638 if (Dart_IsError(status)) Dart_PropagateError(status); 585 if (Dart_IsError(status)) Dart_PropagateError(status);
639 Dart_SetReturnValue(args, returned_data); 586 Dart_SetReturnValue(args, returned_data);
640 } 587 }
641 } else { 588 } else {
642 Dart_Handle err = DartUtils::NewDartArgumentError( 589 Dart_Handle err = DartUtils::NewDartArgumentError(
643 "Non-string argument to FileSystemEntity.stat"); 590 "Non-string argument to FileSystemEntity.stat");
644 if (Dart_IsError(err)) Dart_PropagateError(err); 591 if (Dart_IsError(err)) Dart_PropagateError(err);
645 Dart_SetReturnValue(args, err); 592 Dart_SetReturnValue(args, err);
646 } 593 }
647 Dart_ExitScope();
648 } 594 }
649 595
650 596
651 void FUNCTION_NAME(File_AreIdentical)(Dart_NativeArguments args) { 597 void FUNCTION_NAME(File_AreIdentical)(Dart_NativeArguments args) {
652 Dart_EnterScope();
653 if (Dart_IsString(Dart_GetNativeArgument(args, 0)) && 598 if (Dart_IsString(Dart_GetNativeArgument(args, 0)) &&
654 Dart_IsString(Dart_GetNativeArgument(args, 1))) { 599 Dart_IsString(Dart_GetNativeArgument(args, 1))) {
655 const char* path_1 = 600 const char* path_1 =
656 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); 601 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
657 const char* path_2 = 602 const char* path_2 =
658 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1)); 603 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
659 File::Identical result = File::AreIdentical(path_1, path_2); 604 File::Identical result = File::AreIdentical(path_1, path_2);
660 if (result == File::kError) { 605 if (result == File::kError) {
661 Dart_Handle err = DartUtils::NewDartOSError(); 606 Dart_Handle err = DartUtils::NewDartOSError();
662 if (Dart_IsError(err)) Dart_PropagateError(err); 607 if (Dart_IsError(err)) Dart_PropagateError(err);
663 Dart_SetReturnValue(args, err); 608 Dart_SetReturnValue(args, err);
664 } else { 609 } else {
665 Dart_SetReturnValue(args, Dart_NewBoolean(result == File::kIdentical)); 610 Dart_SetReturnValue(args, Dart_NewBoolean(result == File::kIdentical));
666 } 611 }
667 } else { 612 } else {
668 Dart_Handle err = DartUtils::NewDartArgumentError( 613 Dart_Handle err = DartUtils::NewDartArgumentError(
669 "Non-string argument to FileSystemEntity.identical"); 614 "Non-string argument to FileSystemEntity.identical");
670 if (Dart_IsError(err)) Dart_PropagateError(err); 615 if (Dart_IsError(err)) Dart_PropagateError(err);
671 Dart_SetReturnValue(args, err); 616 Dart_SetReturnValue(args, err);
672 } 617 }
673 Dart_ExitScope();
674 } 618 }
675 619
676 620
677 static int64_t CObjectInt32OrInt64ToInt64(CObject* cobject) { 621 static int64_t CObjectInt32OrInt64ToInt64(CObject* cobject) {
678 ASSERT(cobject->IsInt32OrInt64()); 622 ASSERT(cobject->IsInt32OrInt64());
679 int64_t result; 623 int64_t result;
680 if (cobject->IsInt32()) { 624 if (cobject->IsInt32()) {
681 CObjectInt32 value(cobject); 625 CObjectInt32 value(cobject);
682 result = value.Value(); 626 result = value.Value();
683 } else { 627 } else {
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 Dart_PostCObject(reply_port_id, response->AsApiCObject()); 1261 Dart_PostCObject(reply_port_id, response->AsApiCObject());
1318 } 1262 }
1319 1263
1320 1264
1321 Dart_Port File::GetServicePort() { 1265 Dart_Port File::GetServicePort() {
1322 return file_service_.GetServicePort(); 1266 return file_service_.GetServicePort();
1323 } 1267 }
1324 1268
1325 1269
1326 void FUNCTION_NAME(File_NewServicePort)(Dart_NativeArguments args) { 1270 void FUNCTION_NAME(File_NewServicePort)(Dart_NativeArguments args) {
1327 Dart_EnterScope();
1328 Dart_SetReturnValue(args, Dart_Null()); 1271 Dart_SetReturnValue(args, Dart_Null());
1329 Dart_Port service_port = File::GetServicePort(); 1272 Dart_Port service_port = File::GetServicePort();
1330 if (service_port != ILLEGAL_PORT) { 1273 if (service_port != ILLEGAL_PORT) {
1331 // Return a send port for the service port. 1274 // Return a send port for the service port.
1332 Dart_Handle send_port = Dart_NewSendPort(service_port); 1275 Dart_Handle send_port = Dart_NewSendPort(service_port);
1333 Dart_SetReturnValue(args, send_port); 1276 Dart_SetReturnValue(args, send_port);
1334 } 1277 }
1335 Dart_ExitScope();
1336 } 1278 }
1337 1279
1338 } // namespace bin 1280 } // namespace bin
1339 } // namespace dart 1281 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/eventhandler.cc ('k') | runtime/bin/filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698