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

Unified Diff: frog/lib/node/child_process.dart

Issue 9034014: Add support for the node net module. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: frog/lib/node/child_process.dart
===================================================================
--- frog/lib/node/child_process.dart (revision 0)
+++ frog/lib/node/child_process.dart (revision 0)
@@ -0,0 +1,83 @@
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#library('child_process');
+#import('node.dart');
+#import('net.dart');
+
+typedef void ChildProcessExitListener(int code, String signal);
+
+class ChildProcess implements EventEmitter native "ChildProcess" {
Jennifer Messerly 2012/01/21 01:00:31 Does this need to be marked "native"? It looks lik
+ var _childprocess;
+
+ ChildProcess(this._childprocess);
+
+ // EventEmitter
+ void removeAllListeners(String event)
+ native "this._childprocess.removeAllListeners(event);";
+ void setMaxListeners(num n)
+ native "this._childprocess.setMaxListeners(n);";
+ var _listeners(String key)
+ native "return this._childprocess.listeners(key);";
+
+ // 'exit' event
+ void emitExit(int code, String signal)
+ native "this._childprocess.emit('exit', code, signal);";
+ void addListenerExit(ChildProcessExitListener listener)
+ native "this._childprocess.addListener('exit', listener);";
+ void onExit(ChildProcessExitListener listener)
+ native "this._childprocess.on('exit', listener);";
+ void onceExit(ChildProcessExitListener listener)
+ native "this._childprocess.once('exit', listener);";
+ void removeListenerExit(ChildProcessExitListener listener)
+ native "this._childprocess.removeListener('exit', listener);";
+ List<ChildProcessExitListener> listenersExit()
+ => new _NativeListPrimitiveElement<ChildProcessExitListener>(
+ _listeners('exit'));
+
+ Socket get stdin()
+ native "return this._childprocess.stdin;";
+ Socket get stdout()
+ native "return this._childprocess.stdout;";
+ Socket get stderr()
+ native "return this._childprocess.stderr;";
+ int get pid()
+ native "return this._childprocess.pid;";
+}
+
+typedef void Child_processCallback(Error error, String stdout, String stderr);
+
+class Child_process native {
+ var _cp;
+
+ Child_process() {
+ _cp = _child_process;
+ }
+
+ // TODOO(jackpal): translate options into a Javascript dictionary
+ ChildProcess spawn(String command, [List<String> args,
+ Map<String, Object> options]){
+ 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
+ }
+
+ // TODOO(jackpal): translate options into a Javascript dictionary
+ ChildProcess exec(String command, Child_processCallback callback,
+ [Map<String, Object> options]) {
+ // Note the argument order to exec is different than to _exec,
+ // because Dart can't have optional arguments in the middle of
+ // an argument list.
+ return new ChildProcess(_exec(_cp, command, options, callback));
+ }
+
+ 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
+ native "return cp.spawn(command, args);";
+ static var _exec(var cp, String command, Map<String, Object> options,
+ Child_processCallback callback)
+ native "return cp.exec(command, options, callback);";
+ static var get _child_process() native "return require('child_process')";
+}
+
+var get child_process() {
Jennifer Messerly 2012/01/21 01:00:31 I wonder if this should lazy initialize?
+ return new Child_process();
+}

Powered by Google App Engine
This is Rietveld 408576698