Remove node.Process constructor from API

This commit is contained in:
Ryan
2009-06-30 13:40:00 +02:00
parent a3d77ee4e7
commit d56552dc66
9 changed files with 32 additions and 13 deletions

1
.gitignore vendored
View File

@@ -4,3 +4,4 @@ tags
.lock-wscript
Makefile
*.pyc
website/api.html

View File

@@ -5,6 +5,12 @@ node.tcp.createServer = function (on_connection, options) {
return server;
};
node.createProcess = function (command) {
var process = new node.Process();
process.spawn(command);
return process;
};
// Timers
function setTimeout (callback, after) {

View File

@@ -34,6 +34,7 @@ Process::Initialize (Handle<Object> target)
constructor_template->Inherit(EventEmitter::constructor_template);
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "spawn", Process::Spawn);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "write", Process::Write);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "close", Process::Close);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "kill", Process::Kill);
@@ -47,21 +48,32 @@ Process::Initialize (Handle<Object> target)
Handle<Value>
Process::New (const Arguments& args)
{
if (args.Length() == 0) return Undefined();
HandleScope scope;
String::Utf8Value command(args[0]->ToString());
Process *p = new Process(args.Holder());
ObjectWrap::InformV8ofAllocation(p);
int r = p->Spawn(*command);
return args.This();
}
Handle<Value>
Process::Spawn (const Arguments& args)
{
if (args.Length() == 0 || !args[0]->IsString()) {
return ThrowException(String::New("Bad argument."));
}
HandleScope scope;
Process *process = NODE_UNWRAP(Process, args.Holder());
String::Utf8Value command(args[0]->ToString());
int r = process->Spawn(*command);
if (r != 0) {
return ThrowException(String::New("Error spawning"));
}
return args.This();
return Undefined();
}
Handle<Value>

View File

@@ -17,6 +17,7 @@ class Process : EventEmitter {
protected:
static v8::Persistent<v8::FunctionTemplate> constructor_template;
static v8::Handle<v8::Value> New (const v8::Arguments& args);
static v8::Handle<v8::Value> Spawn (const v8::Arguments& args);
static v8::Handle<v8::Value> Write (const v8::Arguments& args);
static v8::Handle<v8::Value> Close (const v8::Arguments& args);
static v8::Handle<v8::Value> Kill (const v8::Arguments& args);

View File

@@ -4,7 +4,7 @@ var pwd_called = false;
function pwd (callback) {
var output = "";
var process = new node.Process("pwd");
var process = node.createProcess("pwd");
process.addListener("output", function (s) {
if (s) output += s;
});

View File

@@ -3,7 +3,7 @@ include("mjsunit.js");
var exit_status = -1;
function onLoad () {
var cat = new node.Process("cat");
var cat = node.createProcess("cat");
cat.addListener("output", function (chunk) { assertEquals(null, chunk); });
cat.addListener("error", function (chunk) { assertEquals(null, chunk); });

View File

@@ -1,6 +1,6 @@
include("mjsunit.js");
var cat = new node.Process("cat");
var cat = node.createProcess("cat");
var response = "";
var exit_status = -1;

View File

@@ -4,7 +4,7 @@ var N = 40;
var finished = false;
function spawn (i) {
var p = new node.Process('python -c "print 500 * 1024 * \'C\'"');
var p = node.createProcess('python -c "print 500 * 1024 * \'C\'"');
var output = "";
p.addListener("output", function(chunk) {

View File

@@ -324,7 +324,6 @@ Node provides a tridirectional +popen(3)+ facility through the class
==== +node.Process+
.Events
[cols="1,2,10",options="header"]
|=========================================================
|Event |Parameters |Notes
@@ -348,11 +347,11 @@ that the +"output"+ and +"error"+ callbacks will no longer be made.
|=========================================================
+new node.Process(command)+::
+node.createProcess(command)+::
Launches a new process with the given +command+. For example:
+
----------------------------------------
var ls = new node.Process("ls -lh /usr");
var ls = node.createProcess("ls -lh /usr");
ls.addListener("output", function (data) {
puts(data);
});