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

Side by Side Diff: runtime/bin/file_impl.dart

Issue 10989013: Change IllegalArgumentException to ArgumentError. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated co19 test expectations. Created 8 years, 2 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 class _FileInputStream extends _BaseDataInputStream implements InputStream { 5 class _FileInputStream extends _BaseDataInputStream implements InputStream {
6 _FileInputStream(String name) 6 _FileInputStream(String name)
7 : _data = const [], 7 : _data = const [],
8 _position = 0, 8 _position = 0,
9 _filePosition = 0 { 9 _filePosition = 0 {
10 var file = new File(name); 10 var file = new File(name);
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 static writeString(int id, String string) native "File_WriteString"; 386 static writeString(int id, String string) native "File_WriteString";
387 static position(int id) native "File_Position"; 387 static position(int id) native "File_Position";
388 static setPosition(int id, int position) native "File_SetPosition"; 388 static setPosition(int id, int position) native "File_SetPosition";
389 static truncate(int id, int length) native "File_Truncate"; 389 static truncate(int id, int length) native "File_Truncate";
390 static length(int id) native "File_Length"; 390 static length(int id) native "File_Length";
391 static flush(int id) native "File_Flush"; 391 static flush(int id) native "File_Flush";
392 static int openStdio(int fd) native "File_OpenStdio"; 392 static int openStdio(int fd) native "File_OpenStdio";
393 static SendPort newServicePort() native "File_NewServicePort"; 393 static SendPort newServicePort() native "File_NewServicePort";
394 394
395 static bool checkedExists(String name) { 395 static bool checkedExists(String name) {
396 if (name is !String) throw new IllegalArgumentException(); 396 if (name is !String) throw new ArgumentError();
397 var result = exists(name); 397 var result = exists(name);
398 throwIfError(result, "Cannot check existence of file '$name'"); 398 throwIfError(result, "Cannot check existence of file '$name'");
399 return result; 399 return result;
400 } 400 }
401 401
402 static int checkedOpen(String name, int mode) { 402 static int checkedOpen(String name, int mode) {
403 if (name is !String || mode is !int) throw new IllegalArgumentException(); 403 if (name is !String || mode is !int) throw new ArgumentError();
404 var result = open(name, mode); 404 var result = open(name, mode);
405 throwIfError(result, "Cannot open file '$name'"); 405 throwIfError(result, "Cannot open file '$name'");
406 return result; 406 return result;
407 } 407 }
408 408
409 static bool checkedCreate(String name) { 409 static bool checkedCreate(String name) {
410 if (name is !String) throw new IllegalArgumentException(); 410 if (name is !String) throw new ArgumentError();
411 var result = create(name); 411 var result = create(name);
412 throwIfError(result, "Cannot create file '$name'"); 412 throwIfError(result, "Cannot create file '$name'");
413 return true; 413 return true;
414 } 414 }
415 415
416 static bool checkedDelete(String name) { 416 static bool checkedDelete(String name) {
417 if (name is !String) throw new IllegalArgumentException(); 417 if (name is !String) throw new ArgumentError();
418 var result = delete(name); 418 var result = delete(name);
419 throwIfError(result, "Cannot delete file '$name'"); 419 throwIfError(result, "Cannot delete file '$name'");
420 return true; 420 return true;
421 } 421 }
422 422
423 static String checkedFullPath(String name) { 423 static String checkedFullPath(String name) {
424 if (name is !String) throw new IllegalArgumentException(); 424 if (name is !String) throw new ArgumentError();
425 var result = fullPath(name); 425 var result = fullPath(name);
426 throwIfError(result, "Cannot retrieve full path for file '$name'"); 426 throwIfError(result, "Cannot retrieve full path for file '$name'");
427 return result; 427 return result;
428 } 428 }
429 429
430 static String checkedDirectory(String name) { 430 static String checkedDirectory(String name) {
431 if (name is !String) throw new IllegalArgumentException(); 431 if (name is !String) throw new ArgumentError();
432 var result = directory(name); 432 var result = directory(name);
433 throwIfError(result, "Cannot retrieve directory for file '$name'"); 433 throwIfError(result, "Cannot retrieve directory for file '$name'");
434 return result; 434 return result;
435 } 435 }
436 436
437 static int checkedLengthFromName(String name) { 437 static int checkedLengthFromName(String name) {
438 if (name is !String) throw new IllegalArgumentException(); 438 if (name is !String) throw new ArgumentError();
439 var result = lengthFromName(name); 439 var result = lengthFromName(name);
440 throwIfError(result, "Cannot retrieve length of file '$name'"); 440 throwIfError(result, "Cannot retrieve length of file '$name'");
441 return result; 441 return result;
442 } 442 }
443 443
444 static int checkedLastModified(String name) { 444 static int checkedLastModified(String name) {
445 if (name is !String) throw new IllegalArgumentException(); 445 if (name is !String) throw new ArgumentError();
446 var result = lastModified(name); 446 var result = lastModified(name);
447 throwIfError(result, "Cannot retrieve modification time for file '$name'"); 447 throwIfError(result, "Cannot retrieve modification time for file '$name'");
448 return result; 448 return result;
449 } 449 }
450 450
451 static int checkReadWriteListArguments(int length, int offset, int bytes) { 451 static int checkReadWriteListArguments(int length, int offset, int bytes) {
452 if (offset < 0) return offset; 452 if (offset < 0) return offset;
453 if (bytes < 0) return bytes; 453 if (bytes < 0) return bytes;
454 if ((offset + bytes) > length) return offset + bytes; 454 if ((offset + bytes) > length) return offset + bytes;
455 return 0; 455 return 0;
456 } 456 }
457 457
458 static int checkedWriteString(int id, String string) { 458 static int checkedWriteString(int id, String string) {
459 if (string is !String) throw new IllegalArgumentException(); 459 if (string is !String) throw new ArgumentError();
460 return writeString(id, string); 460 return writeString(id, string);
461 } 461 }
462 462
463 static throwIfError(Object result, String msg) { 463 static throwIfError(Object result, String msg) {
464 if (result is OSError) { 464 if (result is OSError) {
465 throw new FileIOException(msg, result); 465 throw new FileIOException(msg, result);
466 } 466 }
467 } 467 }
468 } 468 }
469 469
470 // Base class for _File and _RandomAccessFile with shared functions. 470 // Base class for _File and _RandomAccessFile with shared functions.
471 class _FileBase { 471 class _FileBase {
472 bool _isErrorResponse(response) { 472 bool _isErrorResponse(response) {
473 return response is List && response[0] != _FileUtils.SUCCESS_RESPONSE; 473 return response is List && response[0] != _FileUtils.SUCCESS_RESPONSE;
474 } 474 }
475 475
476 Exception _exceptionFromResponse(response, String message) { 476 Exception _exceptionFromResponse(response, String message) {
477 assert(_isErrorResponse(response)); 477 assert(_isErrorResponse(response));
478 switch (response[_FileUtils.ERROR_RESPONSE_ERROR_TYPE]) { 478 switch (response[_FileUtils.ERROR_RESPONSE_ERROR_TYPE]) {
479 case _FileUtils.ILLEGAL_ARGUMENT_RESPONSE: 479 case _FileUtils.ILLEGAL_ARGUMENT_RESPONSE:
480 return new IllegalArgumentException(); 480 return new ArgumentError();
481 case _FileUtils.OSERROR_RESPONSE: 481 case _FileUtils.OSERROR_RESPONSE:
482 var err = new OSError(response[_FileUtils.OSERROR_RESPONSE_MESSAGE], 482 var err = new OSError(response[_FileUtils.OSERROR_RESPONSE_MESSAGE],
483 response[_FileUtils.OSERROR_RESPONSE_ERROR_CODE]); 483 response[_FileUtils.OSERROR_RESPONSE_ERROR_CODE]);
484 return new FileIOException(message, err); 484 return new FileIOException(message, err);
485 case _FileUtils.FILE_CLOSED_RESPONSE: 485 case _FileUtils.FILE_CLOSED_RESPONSE:
486 return new FileIOException("File closed"); 486 return new FileIOException("File closed");
487 default: 487 default:
488 return new Exception("Unknown error"); 488 return new Exception("Unknown error");
489 } 489 }
490 } 490 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 return new Directory(_FileUtils.directory(_name)); 572 return new Directory(_FileUtils.directory(_name));
573 } 573 }
574 574
575 Future<RandomAccessFile> open([FileMode mode = FileMode.READ]) { 575 Future<RandomAccessFile> open([FileMode mode = FileMode.READ]) {
576 _ensureFileService(); 576 _ensureFileService();
577 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); 577 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>();
578 if (mode != FileMode.READ && 578 if (mode != FileMode.READ &&
579 mode != FileMode.WRITE && 579 mode != FileMode.WRITE &&
580 mode != FileMode.APPEND) { 580 mode != FileMode.APPEND) {
581 new Timer(0, (t) { 581 new Timer(0, (t) {
582 completer.completeException(new IllegalArgumentException()); 582 completer.completeException(new ArgumentError());
583 }); 583 });
584 return completer.future; 584 return completer.future;
585 } 585 }
586 List request = new List(3); 586 List request = new List(3);
587 request[0] = _FileUtils.OPEN_REQUEST; 587 request[0] = _FileUtils.OPEN_REQUEST;
588 request[1] = _name; 588 request[1] = _name;
589 request[2] = mode._mode; // Direct int value for serialization. 589 request[2] = mode._mode; // Direct int value for serialization.
590 return _fileService.call(request).transform((response) { 590 return _fileService.call(request).transform((response) {
591 if (_isErrorResponse(response)) { 591 if (_isErrorResponse(response)) {
592 throw _exceptionFromResponse(response, "Cannot open file '$_name'"); 592 throw _exceptionFromResponse(response, "Cannot open file '$_name'");
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 new FileIOException("File closed '$_name'")); 1165 new FileIOException("File closed '$_name'"));
1166 }); 1166 });
1167 return completer.future; 1167 return completer.future;
1168 } 1168 }
1169 1169
1170 final String _name; 1170 final String _name;
1171 int _id; 1171 int _id;
1172 1172
1173 SendPort _fileService; 1173 SendPort _fileService;
1174 } 1174 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698