Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 #library('child_process'); | |
| 6 #import('node.dart'); | |
| 7 #import('net.dart'); | |
| 8 | |
| 9 typedef void ChildProcessExitListener(int code, String signal); | |
| 10 | |
| 11 class ChildProcess implements EventEmitter native "ChildProcess" { | |
|
Jennifer Messerly
2012/01/21 01:00:31
Does this need to be marked "native"? It looks lik
| |
| 12 var _childprocess; | |
| 13 | |
| 14 ChildProcess(this._childprocess); | |
| 15 | |
| 16 // EventEmitter | |
| 17 void removeAllListeners(String event) | |
| 18 native "this._childprocess.removeAllListeners(event);"; | |
| 19 void setMaxListeners(num n) | |
| 20 native "this._childprocess.setMaxListeners(n);"; | |
| 21 var _listeners(String key) | |
| 22 native "return this._childprocess.listeners(key);"; | |
| 23 | |
| 24 // 'exit' event | |
| 25 void emitExit(int code, String signal) | |
| 26 native "this._childprocess.emit('exit', code, signal);"; | |
| 27 void addListenerExit(ChildProcessExitListener listener) | |
| 28 native "this._childprocess.addListener('exit', listener);"; | |
| 29 void onExit(ChildProcessExitListener listener) | |
| 30 native "this._childprocess.on('exit', listener);"; | |
| 31 void onceExit(ChildProcessExitListener listener) | |
| 32 native "this._childprocess.once('exit', listener);"; | |
| 33 void removeListenerExit(ChildProcessExitListener listener) | |
| 34 native "this._childprocess.removeListener('exit', listener);"; | |
| 35 List<ChildProcessExitListener> listenersExit() | |
| 36 => new _NativeListPrimitiveElement<ChildProcessExitListener>( | |
| 37 _listeners('exit')); | |
| 38 | |
| 39 Socket get stdin() | |
| 40 native "return this._childprocess.stdin;"; | |
| 41 Socket get stdout() | |
| 42 native "return this._childprocess.stdout;"; | |
| 43 Socket get stderr() | |
| 44 native "return this._childprocess.stderr;"; | |
| 45 int get pid() | |
| 46 native "return this._childprocess.pid;"; | |
| 47 } | |
| 48 | |
| 49 typedef void Child_processCallback(Error error, String stdout, String stderr); | |
| 50 | |
| 51 class Child_process native { | |
| 52 var _cp; | |
| 53 | |
| 54 Child_process() { | |
| 55 _cp = _child_process; | |
| 56 } | |
| 57 | |
| 58 // TODOO(jackpal): translate options into a Javascript dictionary | |
| 59 ChildProcess spawn(String command, [List<String> args, | |
| 60 Map<String, Object> options]){ | |
| 61 return new ChildProcess(_spawn(_cp, command, args, options)); | |
|
Jennifer Messerly
2012/01/21 01:00:31
_spawn doesn't take an options parameter -- does t
| |
| 62 } | |
| 63 | |
| 64 // TODOO(jackpal): translate options into a Javascript dictionary | |
| 65 ChildProcess exec(String command, Child_processCallback callback, | |
| 66 [Map<String, Object> options]) { | |
| 67 // Note the argument order to exec is different than to _exec, | |
| 68 // because Dart can't have optional arguments in the middle of | |
| 69 // an argument list. | |
| 70 return new ChildProcess(_exec(_cp, command, options, callback)); | |
| 71 } | |
| 72 | |
| 73 static var _spawn(var cp, String command, List<String> args) | |
|
Jennifer Messerly
2012/01/21 01:00:31
style nit: personally I wouldn't use "var" as an a
| |
| 74 native "return cp.spawn(command, args);"; | |
| 75 static var _exec(var cp, String command, Map<String, Object> options, | |
| 76 Child_processCallback callback) | |
| 77 native "return cp.exec(command, options, callback);"; | |
| 78 static var get _child_process() native "return require('child_process')"; | |
| 79 } | |
| 80 | |
| 81 var get child_process() { | |
|
Jennifer Messerly
2012/01/21 01:00:31
I wonder if this should lazy initialize?
| |
| 82 return new Child_process(); | |
| 83 } | |
| OLD | NEW |