Showing with 19 additions and 11 deletions.
  1. +2 −3 lib/child_process.js
  2. +17 −8 src/spawn_sync.cc
@@ -1106,8 +1106,7 @@ function spawnSync(file, args, options) {
if (options.killSignal)
options.killSignal = lookupSignal(options.killSignal);

if (options.stdio === null || options.stdio === undefined ||
options.stdio === 'pipe')
if (options.stdio == null || options.stdio === 'pipe')
options.stdio = [
{ type: 'pipe', readable: true },
{ type: 'pipe', writable: true },
@@ -1172,7 +1171,7 @@ function spawnSync(file, args, options) {

if (Buffer.isBuffer(options.input))
stdin.input = options.input;
else
else if (options.input != null)
stdin.input = new Buffer(options.input, options.encoding);
}

@@ -31,17 +31,18 @@
namespace node {

using v8::Array;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::Handle;
using v8::HandleScope;
using v8::Integer;
using v8::Isolate;
using v8::Local;
using v8::Null;
using v8::Number;
using v8::Object;
using v8::String;
using v8::Value;
using v8::Isolate;


class SyncProcessOutputBuffer;
@@ -152,7 +153,9 @@ class SyncProcessRunner {
};

public:
static void Initialize(Handle<Object> target);
static void Initialize(Handle<Object> target,
Handle<Value> unused,
Handle<Context> context);
static void Spawn(const FunctionCallbackInfo<Value>& args);

private:
@@ -551,7 +554,10 @@ void SyncProcessStdioPipe::CloseCallback(uv_handle_t* handle) {
}


void SyncProcessRunner::Initialize(Handle<Object> target) {
void SyncProcessRunner::Initialize(Handle<Object> target,
Handle<Value> unused,
Handle<Context> context) {
Environment* env = Environment::GetCurrent(context);
NODE_SET_METHOD(target, "spawn", Spawn);
}

@@ -1030,12 +1036,15 @@ int SyncProcessRunner::ParseStdioOption(int child_fd,

if (readable) {
Local<Value> input = js_stdio_option->Get(env()->input_sym());
if (!Buffer::HasInstance(input))
// We can only deal with buffers for now.
assert(input->IsUndefined());
else
if (Buffer::HasInstance(input)) {
buf = uv_buf_init(Buffer::Data(input),
static_cast<unsigned int>(Buffer::Length(input)));
} else if (!input->IsUndefined() && !input->IsNull()) {
// Strings, numbers etc. are currently unsupported. It's not possible
// to create a buffer for them here because there is no way to free
// them afterwards.
return UV_EINVAL;
}
}

return AddStdioPipe(child_fd, readable, writable, buf);
@@ -1223,4 +1232,4 @@ void SyncProcessRunner::KillTimerCloseCallback(uv_handle_t* handle) {

} // namespace node

NODE_MODULE(node_spawn_sync, node::SyncProcessRunner::Initialize)
NODE_MODULE_CONTEXT_AWARE(node_spawn_sync, node::SyncProcessRunner::Initialize)