Showing with 1,407 additions and 1 deletion.
  1. +145 −0 lib/child_process.js
  2. +1 −0 node.gyp
  3. +25 −1 src/env.h
  4. +1 −0 src/node_extensions.h
  5. +1,235 −0 src/spawn_sync.cc
@@ -29,6 +29,7 @@ var util = require('util');
var Process = process.binding('process_wrap').Process;
var uv = process.binding('uv');

var spawn_sync; // Lazy-loaded process.binding('spawn_sync')
var constants; // Lazy-loaded process.binding('constants')

var errnoException = util._errnoException;
@@ -1096,3 +1097,147 @@ ChildProcess.prototype.ref = function() {
ChildProcess.prototype.unref = function() {
if (this._handle) this._handle.unref();
};


function lookupSignal(signal) {
if (typeof signal === 'number')
return signal;

if (!constants)
constants = process.binding('constants');

if (!(signal in constants))
throw new Error('Unknown signal: ' + signal);

return constants[signal];
}


function spawnSync(file, args, options) {
var i;

if (args)
args = [file].concat(args);
else
args = [file];

if (options)
options = util._extend({}, options);
else
options = {};

options.file = file;
options.args = args;

if (options.env) {
options.envPairs = [];
for (var key in options.env)
options.envPairs.push(key + '=' + options.env[key]);
}

if (options.killSignal)
options.killSignal = lookupSignal(options.killSignal);

if (options.stdio == null || options.stdio === 'pipe')
options.stdio = [
{ type: 'pipe', readable: true },
{ type: 'pipe', writable: true },
{ type: 'pipe', writable: true }
];
else if (options.stdio === 'inherit')
options.stdio = [
{ type: 'inherit', fd: 0 },
{ type: 'inherit', fd: 1 },
{ type: 'inherit', fd: 2 },
];
else if (options.stdio == null && options.customFds)
options.stdio = options.customFds.map(function(value, index) {
if (value === -1)
return {
type: 'pipe',
readable: index === 0,
writable: index !== 0
};
else if (~~value === value)
return {
type: 'inherit',
fd: value
};
else
throw new Error('Invalid customFd option: ' + value);
});
else if (options.stdio === 'ignore')
options.stdio = []
else if (Array.isArray(options.stdio))
options.stdio = options.stdio.map(function mapStdio(value, index) {
if (value === 'pipe')
return {
type: 'pipe',
readable: index === 0,
writable: index !== 0
};
else if (value === 'inherit')
return {
type: 'inherit',
fd: index
};
else if (value == null || value === 'ignore')
return {
type: 'ignore'
};
else if (typeof value === 'number')
return {
type: 'inherit',
fd: value
};
else if (typeof value === 'object')
return value;
else
throw new Error('Invalid stdio option: ' + value);
});
else
throw new Error('Invalid stdio option: ' + options.stdio);

if (options.input != null) {
var stdin = options.stdio[0] = util._extend({}, options.stdio[0]);

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

for (i = 0; i < options.stdio.length; i++) {
var input = options.stdio[i] && options.stdio[i].input;
if (input != null && !Buffer.isBuffer(input)) {
var pipe = options.stdio[i] = util._extend({}, options.stdio[i]);
pipe.input = new Buffer(input, options.encoding);
}
}

if (!spawn_sync)
spawn_sync = process.binding('spawn_sync');

var result = spawn_sync.spawn(options);

if (result.output && options.encoding) {
for (i = 0; i < result.output.length; i++) {
if (!result.output[i])
continue;
result.output[i] = result.output[i].toString(options.encoding);
}
}

result.stdout = result.output && result.output[1];
result.stderr = result.output && result.output[2];

if (result.error) {
var err = errnoException(result.error, 'spawnSync')
util._extend(err, result);
throw err;
}

return result;
};

exports.spawnSync = spawnSync;
@@ -106,6 +106,7 @@
'src/pipe_wrap.cc',
'src/signal_wrap.cc',
'src/smalloc.cc',
'src/spawn_sync.cc',
'src/string_bytes.cc',
'src/stream_wrap.cc',
'src/tcp_wrap.cc',
@@ -52,8 +52,9 @@ namespace node {
// for the sake of convenience.
#define PER_ISOLATE_STRING_PROPERTIES(V) \
V(address_string, "address") \
V(atime_string, "atime") \
V(args_sym, "args") \
V(async_queue_string, "_asyncQueue") \
V(atime_string, "atime") \
V(birthtime_string, "birthtime") \
V(blksize_string, "blksize") \
V(blocks_string, "blocks") \
@@ -64,27 +65,39 @@ namespace node {
V(close_string, "close") \
V(code_string, "code") \
V(ctime_string, "ctime") \
V(cwd_sym, "cwd") \
V(detached_sym, "detached") \
V(dev_string, "dev") \
V(disposed_string, "_disposed") \
V(enter_string, "enter") \
V(env_pairs_sym, "envPairs") \
V(errno_string, "errno") \
V(error_sym, "error") \
V(exit_string, "exit") \
V(exponent_string, "exponent") \
V(exports_string, "exports") \
V(ext_key_usage_string, "ext_key_usage") \
V(family_string, "family") \
V(fatal_exception_string, "_fatalException") \
V(fd_sym, "fd") \
V(file_sym, "file") \
V(fingerprint_string, "fingerprint") \
V(gid_string, "gid") \
V(gid_sym, "gid") \
V(handle_string, "handle") \
V(headers_string, "headers") \
V(heap_total_string, "heapTotal") \
V(heap_used_string, "heapUsed") \
V(ignore_sym, "ignore") \
V(immediate_callback_string, "_immediateCallback") \
V(inherit_sym, "inherit") \
V(ino_string, "ino") \
V(input_sym, "input") \
V(ipv4_string, "IPv4") \
V(ipv6_string, "IPv6") \
V(issuer_string, "issuer") \
V(kill_signal_sym, "killSignal") \
V(max_buffer_sym, "maxBuffer") \
V(method_string, "method") \
V(mode_string, "mode") \
V(modulus_string, "modulus") \
@@ -106,31 +119,42 @@ namespace node {
V(onselect_string, "onselect") \
V(onsignal_string, "onsignal") \
V(onstop_string, "onstop") \
V(output_sym, "output") \
V(path_string, "path") \
V(pipe_sym, "pipe") \
V(port_string, "port") \
V(rdev_string, "rdev") \
V(readable_sym, "readable") \
V(rename_string, "rename") \
V(rss_string, "rss") \
V(serial_number_string, "serialNumber") \
V(servername_string, "servername") \
V(session_id_string, "sessionId") \
V(should_keep_alive_string, "shouldKeepAlive") \
V(signal_sym, "signal") \
V(size_string, "size") \
V(smalloc_p_string, "_smalloc_p") \
V(status_sym, "status") \
V(stdio_sym, "stdio") \
V(sni_context_string, "sni_context") \
V(status_code_string, "statusCode") \
V(subject_string, "subject") \
V(subjectaltname_string, "subjectaltname") \
V(syscall_string, "syscall") \
V(timeout_sym, "timeout") \
V(tls_ticket_string, "tlsTicket") \
V(type_sym, "type") \
V(uid_string, "uid") \
V(uid_sym, "uid") \
V(upgrade_string, "upgrade") \
V(url_string, "url") \
V(valid_from_string, "valid_from") \
V(valid_to_string, "valid_to") \
V(version_major_string, "versionMajor") \
V(version_minor_string, "versionMinor") \
V(version_string, "version") \
V(windows_verbatim_arguments_sym, "windowsVerbatimArguments") \
V(writable_sym, "writable") \
V(write_queue_size_string, "writeQueueSize") \

#define ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V) \
@@ -39,6 +39,7 @@
ITEM(node_http_parser) \
ITEM(node_os) \
ITEM(node_smalloc) \
ITEM(node_spawn_sync) \
ITEM(node_zlib) \
\
ITEM(node_uv) \