|
@ -1,13 +1,13 @@ |
|
|
node.tcp.createServer = function () { |
|
|
process.tcp.createServer = function () { |
|
|
throw new Error("node.tcp.createServer() has moved. Use require('/tcp.js') to access it."); |
|
|
throw new Error("process.tcp.createServer() has moved. Use require('/tcp.js') to access it."); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
node.createProcess = function () { |
|
|
process.createProcess = function () { |
|
|
throw "node.createProcess() has been changed to node.createChildProcess() update your code"; |
|
|
throw "process.createProcess() has been changed to process.createChildProcess() update your code"; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
node.createChildProcess = function (file, args, env) { |
|
|
process.createChildProcess = function (file, args, env) { |
|
|
var child = new node.ChildProcess(); |
|
|
var child = new process.ChildProcess(); |
|
|
args = args || []; |
|
|
args = args || []; |
|
|
env = env || process.ENV; |
|
|
env = env || process.ENV; |
|
|
var envPairs = []; |
|
|
var envPairs = []; |
|
@ -23,24 +23,24 @@ node.createChildProcess = function (file, args, env) { |
|
|
return child; |
|
|
return child; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
node.exec = function () { |
|
|
process.exec = function () { |
|
|
throw new Error("node.exec() has moved. Use require('/sys.js') to bring it back."); |
|
|
throw new Error("process.exec() has moved. Use require('/sys.js') to bring it back."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
node.http.createServer = function () { |
|
|
process.http.createServer = function () { |
|
|
throw new Error("node.http.createServer() has moved. Use require('/http.js') to access it."); |
|
|
throw new Error("process.http.createServer() has moved. Use require('/http.js') to access it."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
node.http.createClient = function () { |
|
|
process.http.createClient = function () { |
|
|
throw new Error("node.http.createClient() has moved. Use require('/http.js') to access it."); |
|
|
throw new Error("process.http.createClient() has moved. Use require('/http.js') to access it."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
node.tcp.createConnection = function (port, host) { |
|
|
process.tcp.createConnection = function (port, host) { |
|
|
throw new Error("node.tcp.createConnection() has moved. Use require('/tcp.js') to access it."); |
|
|
throw new Error("process.tcp.createConnection() has moved. Use require('/tcp.js') to access it."); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
include = function () { |
|
|
include = function () { |
|
|
throw new Error("include() has been removed. Use node.mixin(process, require(file)) to get the same effect."); |
|
|
throw new Error("include() has been removed. Use process.mixin(process, require(file)) to get the same effect."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* From jQuery.extend in the jQuery JavaScript Library v1.3.2 |
|
|
/* From jQuery.extend in the jQuery JavaScript Library v1.3.2 |
|
@ -48,7 +48,7 @@ include = function () { |
|
|
* Dual licensed under the MIT and GPL licenses. |
|
|
* Dual licensed under the MIT and GPL licenses. |
|
|
* http://docs.jquery.com/License
|
|
|
* http://docs.jquery.com/License
|
|
|
*/ |
|
|
*/ |
|
|
node.mixin = function() { |
|
|
process.mixin = function() { |
|
|
// copy reference to target object
|
|
|
// copy reference to target object
|
|
|
var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options; |
|
|
var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options; |
|
|
|
|
|
|
|
@ -61,12 +61,12 @@ node.mixin = function() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Handle case when target is a string or something (possible in deep copy)
|
|
|
// Handle case when target is a string or something (possible in deep copy)
|
|
|
if ( typeof target !== "object" && !node.isFunction(target) ) |
|
|
if ( typeof target !== "object" && !process.isFunction(target) ) |
|
|
target = {}; |
|
|
target = {}; |
|
|
|
|
|
|
|
|
// mixin process itself if only one argument is passed
|
|
|
// mixin process itself if only one argument is passed
|
|
|
if ( length == i ) { |
|
|
if ( length == i ) { |
|
|
target = process; |
|
|
target = GLOBAL; |
|
|
--i; |
|
|
--i; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -83,7 +83,7 @@ node.mixin = function() { |
|
|
|
|
|
|
|
|
// Recurse if we're merging object values
|
|
|
// Recurse if we're merging object values
|
|
|
if ( deep && copy && typeof copy === "object" && !copy.nodeType ) |
|
|
if ( deep && copy && typeof copy === "object" && !copy.nodeType ) |
|
|
target[ name ] = node.mixin( deep, |
|
|
target[ name ] = process.mixin( deep, |
|
|
// Never move original objects, clone them
|
|
|
// Never move original objects, clone them
|
|
|
src || ( copy.length != null ? [ ] : { } ) |
|
|
src || ( copy.length != null ? [ ] : { } ) |
|
|
, copy ); |
|
|
, copy ); |
|
@ -103,12 +103,12 @@ node.mixin = function() { |
|
|
(function () { // anonymous namespace
|
|
|
(function () { // anonymous namespace
|
|
|
|
|
|
|
|
|
function isSignal (event) { |
|
|
function isSignal (event) { |
|
|
return event.slice(0, 3) === 'SIG' && node.hasOwnProperty(event); |
|
|
return event.slice(0, 3) === 'SIG' && process.hasOwnProperty(event); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
process.addListener("newListener", function (event) { |
|
|
process.addListener("newListener", function (event) { |
|
|
if (isSignal(event) && process.listeners(event).length === 0) { |
|
|
if (isSignal(event) && process.listeners(event).length === 0) { |
|
|
var handler = new node.SignalHandler(node[event]); |
|
|
var handler = new process.SignalHandler(process[event]); |
|
|
handler.addListener("signal", function () { |
|
|
handler.addListener("signal", function () { |
|
|
process.emit(event); |
|
|
process.emit(event); |
|
|
}); |
|
|
}); |
|
@ -120,14 +120,14 @@ node.mixin = function() { |
|
|
// Timers
|
|
|
// Timers
|
|
|
|
|
|
|
|
|
function setTimeout (callback, after) { |
|
|
function setTimeout (callback, after) { |
|
|
var timer = new node.Timer(); |
|
|
var timer = new process.Timer(); |
|
|
timer.addListener("timeout", callback); |
|
|
timer.addListener("timeout", callback); |
|
|
timer.start(after, 0); |
|
|
timer.start(after, 0); |
|
|
return timer; |
|
|
return timer; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function setInterval (callback, repeat) { |
|
|
function setInterval (callback, repeat) { |
|
|
var timer = new node.Timer(); |
|
|
var timer = new process.Timer(); |
|
|
timer.addListener("timeout", callback); |
|
|
timer.addListener("timeout", callback); |
|
|
timer.start(repeat, repeat); |
|
|
timer.start(repeat, repeat); |
|
|
return timer; |
|
|
return timer; |
|
@ -141,18 +141,18 @@ clearInterval = clearTimeout; |
|
|
|
|
|
|
|
|
// Module
|
|
|
// Module
|
|
|
|
|
|
|
|
|
node.libraryPaths = [ node.path.join(ENV["HOME"], ".node_libraries") |
|
|
process.libraryPaths = [ process.path.join(process.ENV["HOME"], ".node_libraries") |
|
|
, node.path.join(node.installPrefix, "lib/node/libraries") |
|
|
, process.path.join(process.installPrefix, "lib/node/libraries") |
|
|
, "/" |
|
|
, "/" |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
if (ENV["NODE_LIBRARY_PATHS"]) { |
|
|
if (process.ENV["NODE_LIBRARY_PATHS"]) { |
|
|
node.libraryPaths = |
|
|
process.libraryPaths = |
|
|
ENV["NODE_LIBRARY_PATHS"].split(":").concat(node.libraryPaths); |
|
|
process.ENV["NODE_LIBRARY_PATHS"].split(":").concat(process.libraryPaths); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
node.Module = function (filename, parent) { |
|
|
process.Module = function (filename, parent) { |
|
|
node.assert(filename.charAt(0) == "/"); |
|
|
process.assert(filename.charAt(0) == "/"); |
|
|
this.filename = filename; |
|
|
this.filename = filename; |
|
|
this.exports = {}; |
|
|
this.exports = {}; |
|
|
this.parent = parent; |
|
|
this.parent = parent; |
|
@ -163,26 +163,26 @@ node.Module = function (filename, parent) { |
|
|
this.children = []; |
|
|
this.children = []; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
node.Module.cache = {}; |
|
|
process.Module.cache = {}; |
|
|
|
|
|
|
|
|
(function () { |
|
|
(function () { |
|
|
function retrieveFromCache (loadPromise, fullPath, parent) { |
|
|
function retrieveFromCache (loadPromise, fullPath, parent) { |
|
|
var module; |
|
|
var module; |
|
|
if (fullPath in node.Module.cache) { |
|
|
if (fullPath in process.Module.cache) { |
|
|
module = node.Module.cache[fullPath]; |
|
|
module = process.Module.cache[fullPath]; |
|
|
setTimeout(function () { |
|
|
setTimeout(function () { |
|
|
loadPromise.emitSuccess(module.exports); |
|
|
loadPromise.emitSuccess(module.exports); |
|
|
}, 0); |
|
|
}, 0); |
|
|
} else { |
|
|
} else { |
|
|
module = new node.Module(fullPath, parent); |
|
|
module = new process.Module(fullPath, parent); |
|
|
node.Module.cache[fullPath] = module; |
|
|
process.Module.cache[fullPath] = module; |
|
|
module.load(loadPromise); |
|
|
module.load(loadPromise); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function findPath (path, dirs, callback) { |
|
|
function findPath (path, dirs, callback) { |
|
|
node.assert(path.charAt(0) == "/"); |
|
|
process.assert(path.charAt(0) == "/"); |
|
|
node.assert(dirs.constructor == Array); |
|
|
process.assert(dirs.constructor == Array); |
|
|
|
|
|
|
|
|
if (dirs.length == 0) { |
|
|
if (dirs.length == 0) { |
|
|
callback(); |
|
|
callback(); |
|
@ -190,8 +190,8 @@ node.Module.cache = {}; |
|
|
var dir = dirs[0]; |
|
|
var dir = dirs[0]; |
|
|
var rest = dirs.slice(1, dirs.length); |
|
|
var rest = dirs.slice(1, dirs.length); |
|
|
|
|
|
|
|
|
var fullPath = node.path.join(dir, path); |
|
|
var fullPath = process.path.join(dir, path); |
|
|
node.fs.exists(fullPath, function (doesExist) { |
|
|
process.fs.exists(fullPath, function (doesExist) { |
|
|
if (doesExist) { |
|
|
if (doesExist) { |
|
|
callback(fullPath); |
|
|
callback(fullPath); |
|
|
} else { |
|
|
} else { |
|
@ -201,8 +201,8 @@ node.Module.cache = {}; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
node.loadModule = function (requestedPath, exports, parent) { |
|
|
process.loadModule = function (requestedPath, exports, parent) { |
|
|
var loadPromise = new node.Promise(); |
|
|
var loadPromise = new process.Promise(); |
|
|
|
|
|
|
|
|
// On success copy the loaded properties into the exports
|
|
|
// On success copy the loaded properties into the exports
|
|
|
loadPromise.addCallback(function (t) { |
|
|
loadPromise.addCallback(function (t) { |
|
@ -212,19 +212,19 @@ node.Module.cache = {}; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
loadPromise.addErrback(function (e) { |
|
|
loadPromise.addErrback(function (e) { |
|
|
node.stdio.writeError(e.message + "\n"); |
|
|
process.stdio.writeError(e.message + "\n"); |
|
|
process.exit(1); |
|
|
process.exit(1); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
if (!parent) { |
|
|
if (!parent) { |
|
|
// root module
|
|
|
// root module
|
|
|
node.assert(requestedPath.charAt(0) == "/"); |
|
|
process.assert(requestedPath.charAt(0) == "/"); |
|
|
retrieveFromCache(loadPromise, requestedPath); |
|
|
retrieveFromCache(loadPromise, requestedPath); |
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
if (requestedPath.charAt(0) == "/") { |
|
|
if (requestedPath.charAt(0) == "/") { |
|
|
// Need to find the module in node.libraryPaths
|
|
|
// Need to find the module in process.libraryPaths
|
|
|
findPath(requestedPath, node.libraryPaths, function (fullPath) { |
|
|
findPath(requestedPath, process.libraryPaths, function (fullPath) { |
|
|
if (fullPath) { |
|
|
if (fullPath) { |
|
|
retrieveFromCache(loadPromise, fullPath, parent); |
|
|
retrieveFromCache(loadPromise, fullPath, parent); |
|
|
} else { |
|
|
} else { |
|
@ -234,7 +234,7 @@ node.Module.cache = {}; |
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
// Relative file load
|
|
|
// Relative file load
|
|
|
var fullPath = node.path.join(node.path.dirname(parent.filename), |
|
|
var fullPath = process.path.join(process.path.dirname(parent.filename), |
|
|
requestedPath); |
|
|
requestedPath); |
|
|
retrieveFromCache(loadPromise, fullPath, parent); |
|
|
retrieveFromCache(loadPromise, fullPath, parent); |
|
|
} |
|
|
} |
|
@ -244,12 +244,12 @@ node.Module.cache = {}; |
|
|
}; |
|
|
}; |
|
|
}()); |
|
|
}()); |
|
|
|
|
|
|
|
|
node.Module.prototype.load = function (loadPromise) { |
|
|
process.Module.prototype.load = function (loadPromise) { |
|
|
if (this.loaded) { |
|
|
if (this.loaded) { |
|
|
loadPromise.emitError(new Error("Module '" + self.filename + "' is already loaded.")); |
|
|
loadPromise.emitError(new Error("Module '" + self.filename + "' is already loaded.")); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
node.assert(!node.loadPromise); |
|
|
process.assert(!process.loadPromise); |
|
|
this.loadPromise = loadPromise; |
|
|
this.loadPromise = loadPromise; |
|
|
|
|
|
|
|
|
if (this.filename.match(/\.node$/)) { |
|
|
if (this.filename.match(/\.node$/)) { |
|
@ -259,14 +259,14 @@ node.Module.prototype.load = function (loadPromise) { |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
node.Module.prototype.loadObject = function (loadPromise) { |
|
|
process.Module.prototype.loadObject = function (loadPromise) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
// XXX Not yet supporting loading from HTTP. would need to download the
|
|
|
// XXX Not yet supporting loading from HTTP. would need to download the
|
|
|
// file, store it to tmp then run dlopen on it.
|
|
|
// file, store it to tmp then run dlopen on it.
|
|
|
node.fs.exists(self.filename, function (does_exist) { |
|
|
process.fs.exists(self.filename, function (does_exist) { |
|
|
if (does_exist) { |
|
|
if (does_exist) { |
|
|
self.loaded = true; |
|
|
self.loaded = true; |
|
|
node.dlopen(self.filename, self.exports); // FIXME synchronus
|
|
|
process.dlopen(self.filename, self.exports); // FIXME synchronus
|
|
|
loadPromise.emitSuccess(self.exports); |
|
|
loadPromise.emitSuccess(self.exports); |
|
|
} else { |
|
|
} else { |
|
|
loadPromise.emitError(new Error("Error reading " + self.filename)); |
|
|
loadPromise.emitError(new Error("Error reading " + self.filename)); |
|
@ -274,9 +274,9 @@ node.Module.prototype.loadObject = function (loadPromise) { |
|
|
}); |
|
|
}); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
node.Module.prototype.loadScript = function (loadPromise) { |
|
|
process.Module.prototype.loadScript = function (loadPromise) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
var catPromise = node.cat(self.filename); |
|
|
var catPromise = process.cat(self.filename); |
|
|
|
|
|
|
|
|
catPromise.addErrback(function () { |
|
|
catPromise.addErrback(function () { |
|
|
loadPromise.emitError(new Error("Error reading " + self.filename)); |
|
|
loadPromise.emitError(new Error("Error reading " + self.filename)); |
|
@ -294,14 +294,14 @@ node.Module.prototype.loadScript = function (loadPromise) { |
|
|
return requireAsync(url).wait(); |
|
|
return requireAsync(url).wait(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
require.paths = node.libraryPaths; |
|
|
require.paths = process.libraryPaths; |
|
|
require.async = requireAsync; |
|
|
require.async = requireAsync; |
|
|
|
|
|
|
|
|
// create wrapper function
|
|
|
// create wrapper function
|
|
|
var wrapper = "var __wrap__ = function (__module, __filename, exports, require) { " |
|
|
var wrapper = "var __wrap__ = function (__module, __filename, exports, require) { " |
|
|
+ content |
|
|
+ content |
|
|
+ "\n}; __wrap__;"; |
|
|
+ "\n}; __wrap__;"; |
|
|
var compiled_wrapper = node.compile(wrapper, self.filename); |
|
|
var compiled_wrapper = process.compile(wrapper, self.filename); |
|
|
|
|
|
|
|
|
compiled_wrapper.apply(self.exports, [self, self.filename, self.exports, require]); |
|
|
compiled_wrapper.apply(self.exports, [self, self.filename, self.exports, require]); |
|
|
|
|
|
|
|
@ -312,11 +312,11 @@ node.Module.prototype.loadScript = function (loadPromise) { |
|
|
}); |
|
|
}); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
node.Module.prototype.newChild = function (path) { |
|
|
process.Module.prototype.newChild = function (path) { |
|
|
return node.loadModule(path, {}, this); |
|
|
return process.loadModule(path, {}, this); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
node.Module.prototype.waitChildrenLoad = function (callback) { |
|
|
process.Module.prototype.waitChildrenLoad = function (callback) { |
|
|
var nloaded = 0; |
|
|
var nloaded = 0; |
|
|
var children = this.children; |
|
|
var children = this.children; |
|
|
for (var i = 0; i < children.length; i++) { |
|
|
for (var i = 0; i < children.length; i++) { |
|
@ -336,25 +336,21 @@ node.Module.prototype.waitChildrenLoad = function (callback) { |
|
|
|
|
|
|
|
|
process.exit = function (code) { |
|
|
process.exit = function (code) { |
|
|
process.emit("exit"); |
|
|
process.emit("exit"); |
|
|
node.reallyExit(code); |
|
|
process.reallyExit(code); |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
node.exit = function (code) { |
|
|
|
|
|
throw new Error("node.exit() has been renamed to process.exit()."); |
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
(function () { |
|
|
(function () { |
|
|
var cwd = node.cwd(); |
|
|
var cwd = process.cwd(); |
|
|
|
|
|
|
|
|
// Make ARGV[0] and ARGV[1] into full paths.
|
|
|
// Make process.ARGV[0] and process.ARGV[1] into full paths.
|
|
|
if (ARGV[0].charAt(0) != "/") { |
|
|
if (process.ARGV[0].charAt(0) != "/") { |
|
|
ARGV[0] = node.path.join(cwd, ARGV[0]); |
|
|
process.ARGV[0] = process.path.join(cwd, process.ARGV[0]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (ARGV[1].charAt(0) != "/") { |
|
|
if (process.ARGV[1].charAt(0) != "/") { |
|
|
ARGV[1] = node.path.join(cwd, ARGV[1]); |
|
|
process.ARGV[1] = process.path.join(cwd, process.ARGV[1]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Load the root module--the command line argument.
|
|
|
// Load the root module--the command line argument.
|
|
|
node.loadModule(ARGV[1], process); |
|
|
process.loadModule(process.ARGV[1], process); |
|
|
}()); |
|
|
}()); |
|
|