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

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

Issue 2585443002: Error checking for Stdio calls (Closed)
Patch Set: Fix Windows Created 4 years 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
« no previous file with comments | « runtime/bin/stdio_macos.cc ('k') | runtime/bin/stdio_win.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 @patch class _StdIOUtils { 5 @patch class _StdIOUtils {
6 @patch static Stdin _getStdioInputStream() { 6 @patch static Stdin _getStdioInputStream() {
7 switch (_getStdioHandleType(0)) { 7 switch (_getStdioHandleType(0)) {
8 case _STDIO_HANDLE_TYPE_TERMINAL: 8 case _STDIO_HANDLE_TYPE_TERMINAL:
9 case _STDIO_HANDLE_TYPE_PIPE: 9 case _STDIO_HANDLE_TYPE_PIPE:
10 case _STDIO_HANDLE_TYPE_SOCKET: 10 case _STDIO_HANDLE_TYPE_SOCKET:
(...skipping 29 matching lines...) Expand all
40 throw new FileSystemException( 40 throw new FileSystemException(
41 "Error retrieving socket type", "", result); 41 "Error retrieving socket type", "", result);
42 } 42 }
43 return result; 43 return result;
44 } 44 }
45 45
46 @patch static _getStdioHandleType(int fd) native "File_GetStdioHandleType"; 46 @patch static _getStdioHandleType(int fd) native "File_GetStdioHandleType";
47 } 47 }
48 48
49 @patch class Stdin { 49 @patch class Stdin {
50 @patch int readByteSync() native "Stdin_ReadByte"; 50 @patch int readByteSync() {
51 var result = _readByte();
52 if (result is OSError) {
53 throw new StdinException("Error reading byte from stdin", result);
54 }
55 return result;
56 }
51 57
52 @patch bool get echoMode => _echoMode; 58 @patch bool get echoMode {
53 @patch void set echoMode(bool enabled) { _echoMode = enabled; } 59 var result = _echoMode();
60 if (result is OSError) {
61 throw new StdinException("Error getting terminal echo mode", result);
62 }
63 return result;
64 }
65 @patch void set echoMode(bool enabled) {
66 var result = _setEchoMode(enabled);
67 if (result is OSError) {
68 throw new StdinException("Error setting terminal echo mode", result);
69 }
70 }
54 71
55 @patch bool get lineMode => _lineMode; 72 @patch bool get lineMode {
56 @patch void set lineMode(bool enabled) { _lineMode = enabled; } 73 var result = _lineMode();
74 if (result is OSError) {
75 throw new StdinException("Error getting terminal line mode", result);
76 }
77 return result;
78 }
79 @patch void set lineMode(bool enabled) {
80 var result = _setLineMode(enabled);
81 if (result is OSError) {
82 throw new StdinException("Error setting terminal line mode", result);
83 }
84 }
57 85
58 static bool get _echoMode native "Stdin_GetEchoMode"; 86 static _echoMode() native "Stdin_GetEchoMode";
59 static void set _echoMode(bool enabled) native "Stdin_SetEchoMode"; 87 static _setEchoMode(bool enabled) native "Stdin_SetEchoMode";
60 static bool get _lineMode native "Stdin_GetLineMode"; 88 static _lineMode() native "Stdin_GetLineMode";
61 static void set _lineMode(bool enabled) native "Stdin_SetLineMode"; 89 static _setLineMode(bool enabled) native "Stdin_SetLineMode";
90 static _readByte() native "Stdin_ReadByte";
62 } 91 }
63 92
64 @patch class Stdout { 93 @patch class Stdout {
65 @patch bool _hasTerminal(int fd) { 94 @patch bool _hasTerminal(int fd) {
66 try { 95 try {
67 _terminalSize(fd); 96 _terminalSize(fd);
68 return true; 97 return true;
69 } catch (_) { 98 } catch (_) {
70 return false; 99 return false;
71 } 100 }
72 } 101 }
73 102
74 @patch int _terminalColumns(int fd) => _terminalSize(fd)[0]; 103 @patch int _terminalColumns(int fd) => _terminalSize(fd)[0];
75 @patch int _terminalLines(int fd) => _terminalSize(fd)[1]; 104 @patch int _terminalLines(int fd) => _terminalSize(fd)[1];
76 105
77 static List _terminalSize(int fd) { 106 static List _terminalSize(int fd) {
78 var size = _getTerminalSize(fd); 107 var size = _getTerminalSize(fd);
79 if (size is! List) { 108 if (size is! List) {
80 throw new StdoutException("Could not get terminal size", size); 109 throw new StdoutException("Could not get terminal size", size);
81 } 110 }
82 return size; 111 return size;
83 } 112 }
84 113
85 static _getTerminalSize(int fd) native "Stdout_GetTerminalSize"; 114 static _getTerminalSize(int fd) native "Stdout_GetTerminalSize";
86 } 115 }
87 116
88 117
89 _getStdioHandle(_NativeSocket socket, int num) native "Socket_GetStdioHandle"; 118 _getStdioHandle(_NativeSocket socket, int num) native "Socket_GetStdioHandle";
90 _getSocketType(_NativeSocket nativeSocket) native "Socket_GetType"; 119 _getSocketType(_NativeSocket nativeSocket) native "Socket_GetType";
OLDNEW
« no previous file with comments | « runtime/bin/stdio_macos.cc ('k') | runtime/bin/stdio_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698