Browse Source

Remove node.Process constructor from API

v0.7.4-release
Ryan 16 years ago
parent
commit
d56552dc66
  1. 1
      .gitignore
  2. 6
      src/node.js
  3. 24
      src/process.cc
  4. 1
      src/process.h
  5. 2
      test/mjsunit/test-process-buffering.js
  6. 2
      test/mjsunit/test-process-kill.js
  7. 2
      test/mjsunit/test-process-simple.js
  8. 2
      test/mjsunit/test-process-spawn-loop.js
  9. 5
      website/api.txt

1
.gitignore

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

6
src/node.js

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

24
src/process.cc

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

1
src/process.h

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

2
test/mjsunit/test-process-buffering.js

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

2
test/mjsunit/test-process-kill.js

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

2
test/mjsunit/test-process-simple.js

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

2
test/mjsunit/test-process-spawn-loop.js

@ -4,7 +4,7 @@ var N = 40;
var finished = false; var finished = false;
function spawn (i) { 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 = ""; var output = "";
p.addListener("output", function(chunk) { p.addListener("output", function(chunk) {

5
website/api.txt

@ -324,7 +324,6 @@ Node provides a tridirectional +popen(3)+ facility through the class
==== +node.Process+ ==== +node.Process+
.Events
[cols="1,2,10",options="header"] [cols="1,2,10",options="header"]
|========================================================= |=========================================================
|Event |Parameters |Notes |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: 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) { ls.addListener("output", function (data) {
puts(data); puts(data);
}); });

Loading…
Cancel
Save