Add exitCode getter counterpart to the existing setter in dart:io.

BUG=https://code.google.com/p/dart/issues/detail?id=16217
R=sgjesse@google.com

Review URL: https://codereview.chromium.org//200233002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@33737 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
ajohnsen@google.com
2014-03-17 10:40:19 +00:00
parent 37b30ab2ac
commit 09a4f24413
6 changed files with 38 additions and 7 deletions
+1
View File
@@ -48,6 +48,7 @@ namespace bin {
V(Process_Wait, 5) \
V(Process_Kill, 3) \
V(Process_SetExitCode, 1) \
V(Process_GetExitCode, 0) \
V(Process_Exit, 1) \
V(Process_Sleep, 1) \
V(Process_Pid, 1) \
+5
View File
@@ -221,6 +221,11 @@ void FUNCTION_NAME(Process_SetExitCode)(Dart_NativeArguments args) {
}
void FUNCTION_NAME(Process_GetExitCode)(Dart_NativeArguments args) {
Dart_SetReturnValue(args, Dart_NewInteger(Process::GlobalExitCode()));
}
void FUNCTION_NAME(Process_Sleep)(Dart_NativeArguments args) {
int64_t milliseconds = 0;
// Ignore result if passing invalid argument and just set exit code to 0.
+1
View File
@@ -125,6 +125,7 @@ patch class _ProcessUtils {
/* patch */ static void _exit(int status) native "Process_Exit";
/* patch */ static void _setExitCode(int status)
native "Process_SetExitCode";
/* patch */ static int _getExitCode() native "Process_GetExitCode";
/* patch */ static void _sleep(int millis) native "Process_Sleep";
/* patch */ static int _pid(Process process) native "Process_Pid";
/* patch */ static Stream<ProcessSignal> _watchSignal(ProcessSignal signal) {
+3
View File
@@ -179,6 +179,9 @@ patch class _ProcessUtils {
patch static void _setExitCode(int status) {
throw new UnsupportedError("ProcessUtils._setExitCode");
}
patch static int _getExitCode() {
throw new UnsupportedError("ProcessUtils._getExitCode");
}
patch static void _sleep(int millis) {
throw new UnsupportedError("ProcessUtils._sleep");
}
+22 -7
View File
@@ -9,6 +9,7 @@ part of dart.io;
class _ProcessUtils {
external static void _exit(int status);
external static void _setExitCode(int status);
external static int _getExitCode();
external static void _sleep(int millis);
external static int _pid(Process process);
external static Stream<ProcessSignal> _watchSignal(ProcessSignal signal);
@@ -49,7 +50,26 @@ void exit(int code) {
}
/**
* Global exit code for the Dart VM.
* Set the global exit code for the Dart VM.
*
* The exit code is global for the Dart VM and the last assignment to
* exitCode from any isolate determines the exit code of the Dart VM
* on normal termination.
*
* Default value is `0`.
*
* See [exit] for more information on how to chose a value for the
* exit code.
*/
void set exitCode(int code) {
if (code is !int) {
throw new ArgumentError("Integer value for exit code expected");
}
_ProcessUtils._setExitCode(code);
}
/*
* Get the global exit code for the Dart VM.
*
* The exit code is global for the Dart VM and the last assignment to
* exitCode from any isolate determines the exit code of the Dart VM
@@ -58,12 +78,7 @@ void exit(int code) {
* See [exit] for more information on how to chose a value for the
* exit code.
*/
set exitCode(int code) {
if (code is !int) {
throw new ArgumentError("Integer value for exit code expected");
}
_ProcessUtils._setExitCode(code);
}
int get exitCode => _ProcessUtils._getExitCode();
/**
* Sleep for the duration specified in [duration].
@@ -5,7 +5,13 @@
import "dart:io";
main() {
if (exitCode != 0) {
throw "Bad initial exit-code";
}
stdout.write("standard out");
stderr.write("standard error");
exitCode = 25;
if (exitCode != 25) {
throw "Exit-code not set correctly";
}
}