Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions Nodelike.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
418E78FC19478C5D0075FFEE /* NLAsync.m in Sources */ = {isa = PBXBuildFile; fileRef = 418E78FB19478C5D0075FFEE /* NLAsync.m */; };
B5061A3A1815A9B00083AB4B /* NLCares.m in Sources */ = {isa = PBXBuildFile; fileRef = B5061A391815A9B00083AB4B /* NLCares.m */; };
B50A48EB18C01CDF00656FA3 /* test-timers.js in Resources */ = {isa = PBXBuildFile; fileRef = B572E28418B94E32005E6403 /* test-timers.js */; };
B50A48EC18C01CF000656FA3 /* test-timers-zero-timeout.js in Resources */ = {isa = PBXBuildFile; fileRef = B572E28318B94E32005E6403 /* test-timers-zero-timeout.js */; };
Expand Down Expand Up @@ -97,7 +98,6 @@
B52B8164186075CD003B40D9 /* udp.c in Sources */ = {isa = PBXBuildFile; fileRef = B52B813E186075CD003B40D9 /* udp.c */; };
B52B8166186075CD003B40D9 /* uv-common.c in Sources */ = {isa = PBXBuildFile; fileRef = B52B8140186075CD003B40D9 /* uv-common.c */; };
B52B8167186075CD003B40D9 /* version.c in Sources */ = {isa = PBXBuildFile; fileRef = B52B8142186075CD003B40D9 /* version.c */; };
B52B9B9318A01D0800492856 /* NLAsync.m in Sources */ = {isa = PBXBuildFile; fileRef = B52B9B9218A01D0800492856 /* NLAsync.m */; };
B53E6998184672F3004E4EF9 /* NLStream.m in Sources */ = {isa = PBXBuildFile; fileRef = B53E6997184672F3004E4EF9 /* NLStream.m */; };
B5417311189415C000B6636B /* NLUDP.m in Sources */ = {isa = PBXBuildFile; fileRef = B5417310189415C000B6636B /* NLUDP.m */; };
B54173181894341600B6636B /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B54173171894341600B6636B /* XCTest.framework */; };
Expand Down Expand Up @@ -261,6 +261,8 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
418E78FA19478C5D0075FFEE /* NLAsync.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NLAsync.h; sourceTree = "<group>"; };
418E78FB19478C5D0075FFEE /* NLAsync.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NLAsync.m; sourceTree = "<group>"; };
B5061A381815A9B00083AB4B /* NLCares.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NLCares.h; sourceTree = "<group>"; };
B5061A391815A9B00083AB4B /* NLCares.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NLCares.m; sourceTree = "<group>"; };
B50A490218C3882700656FA3 /* NextTick_Tests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NextTick_Tests.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -353,8 +355,6 @@
B52B8140186075CD003B40D9 /* uv-common.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "uv-common.c"; path = "libuv/src/uv-common.c"; sourceTree = SOURCE_ROOT; };
B52B8141186075CD003B40D9 /* uv-common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "uv-common.h"; path = "libuv/src/uv-common.h"; sourceTree = SOURCE_ROOT; };
B52B8142186075CD003B40D9 /* version.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = version.c; path = libuv/src/version.c; sourceTree = SOURCE_ROOT; };
B52B9B9118A01D0800492856 /* NLAsync.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NLAsync.h; sourceTree = "<group>"; };
B52B9B9218A01D0800492856 /* NLAsync.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NLAsync.m; sourceTree = "<group>"; };
B53E6996184672F3004E4EF9 /* NLStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NLStream.h; sourceTree = "<group>"; };
B53E6997184672F3004E4EF9 /* NLStream.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NLStream.m; sourceTree = "<group>"; };
B541730F189415C000B6636B /* NLUDP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NLUDP.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2091,8 +2091,8 @@
DA49974618D899400078FCB1 /* NLTTY.h */,
B5A79B29189E4F9400CC04D6 /* NSObject+Nodelike.h */,
B5A79B2A189E4F9400CC04D6 /* NSObject+Nodelike.m */,
B52B9B9118A01D0800492856 /* NLAsync.h */,
B52B9B9218A01D0800492856 /* NLAsync.m */,
418E78FA19478C5D0075FFEE /* NLAsync.h */,
418E78FB19478C5D0075FFEE /* NLAsync.m */,
B5A79B2C189E501200CC04D6 /* NLContextify.h */,
B5A79B2D189E501200CC04D6 /* NLContextify.m */,
B59E5F98181F07270093A6FF /* NLContext.h */,
Expand Down Expand Up @@ -2542,7 +2542,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B52B9B9318A01D0800492856 /* NLAsync.m in Sources */,
B56DEFBE187DC18100FF1D8A /* NLHTTPParser.m in Sources */,
B5A79B2B189E4F9400CC04D6 /* NSObject+Nodelike.m in Sources */,
B599FF2C185A7ED000057DD6 /* NLTCP.m in Sources */,
Expand All @@ -2560,6 +2559,7 @@
B5A79B2E189E501300CC04D6 /* NLContextify.m in Sources */,
B59E5F94181F07090093A6FF /* NLFS.m in Sources */,
B59E5F9D181F07320093A6FF /* NLProcess.m in Sources */,
418E78FC19478C5D0075FFEE /* NLAsync.m in Sources */,
B59E5FA0181F073D0093A6FF /* NLBinding.m in Sources */,
B59E5FA61820EF530093A6FF /* NLTimer.m in Sources */,
B578842418944F2000EA1A81 /* NLBuffer.m in Sources */,
Expand Down Expand Up @@ -2681,6 +2681,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
Expand Down Expand Up @@ -2712,13 +2713,15 @@
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
VALID_ARCHS = "armv7 armv7s";
};
name = Debug;
};
B5B44670180AB78E009ADEF9 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
Expand All @@ -2745,13 +2748,15 @@
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
VALID_ARCHS = "armv7 armv7s";
};
name = Release;
};
B5C37E4518EB7E82008FA2D5 /* Testing */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
Expand Down Expand Up @@ -2784,8 +2789,9 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
ONLY_ACTIVE_ARCH = YES;
ONLY_ACTIVE_ARCH = NO;
SDKROOT = iphoneos;
VALID_ARCHS = "armv7 armv7s";
};
name = Testing;
};
Expand Down
8 changes: 7 additions & 1 deletion Nodelike/NLContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ + (void)attachToContext:(JSContext *)context {
JSValue __weak *weakProcess = process;

process[@"resourcePath"] = NLContext.resourcePath;
process[@"env"][@"NODE_PATH"] = [NLContext.resourcePath stringByAppendingString:@"/node_modules"];
//process[@"env"][@"NODE_PATH"] = [NLContext.resourcePath stringByAppendingString:@"/node_modules"];

NSString *allPaths = [NLContext.resourcePath stringByAppendingString:@"/client"];
allPaths = [allPaths stringByAppendingString:@":"]; //Adds a path delimeter
allPaths = [allPaths stringByAppendingString:[NLContext.resourcePath stringByAppendingString:@"/client/node_modules"]];
process[@"env"][@"NODE_PATH"] = allPaths;

// used in Hrtime() below
#define NANOS_PER_SEC 1000000000

Expand Down
2 changes: 1 addition & 1 deletion Nodelike/NLContextify.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ - (JSValue *)runInContext:(JSValue *)context options:(JSValue *)options {
if (!context.isObject)
return [context.context evaluateScript:@"throw TypeError('contextifiedSandbox argument must be an object.');"];

NSLog(@"run: %@ %@", context[@"_contextifyHidden"], self.code);
//NSLog(@"run: %@ %@", context[@"_contextifyHidden"], self.code);

JSContext *ctx = [context[@"_contextifyHidden"] toObjectOfClass:JSContext.class];

Expand Down
5 changes: 5 additions & 0 deletions Nodelike/NLFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ JSExportAs(close, - (JSValue *)close:(NSNumber *)file callback:(JSValue *)cb);

JSExportAs(read, - (JSValue *)read:(NSNumber *)file to:(JSValue *)target offset:(JSValue *)off length:(JSValue *)len pos:(JSValue *)pos callback:(JSValue *)cb);

JSExportAs(writeBuffer, - (JSValue *)writeBufferTo:(NSNumber *)file source:(JSValue *)source offset:(JSValue *)off length:(JSValue *)len pos:(JSValue *)pos callback:(JSValue *)cb );
JSExportAs(writeString, - (JSValue *)writeStringTo:(NSNumber *)file source:(NSString *)source offset:(JSValue *)off length:(JSValue *)len pos:(JSValue *)pos callback:(JSValue *)cb );

JSExportAs(readdir, - (JSValue *)readDir:(NSString *)path callback:(JSValue *)cb);

JSExportAs(fdatasync, - (JSValue *)fdatasync:(NSNumber *)file callback:(JSValue *)cb);
Expand Down Expand Up @@ -50,6 +53,8 @@ JSExportAs(stat, - (JSValue *)stat: (NSString *)path callback:(JSValue *)cb);
JSExportAs(lstat, - (JSValue *)lstat:(NSString *)path callback:(JSValue *)cb);
JSExportAs(fstat, - (JSValue *)fstat:(NSNumber *)file callback:(JSValue *)cb);

JSExportAs(utimes, - (JSValue *)utimes: (NSString *)path atime:(JSValue *)atime mtime:(JSValue *)mtime callback:(JSValue *)cb);

@end

@interface NLFS : NLBinding <NLFSExports>
Expand Down
35 changes: 34 additions & 1 deletion Nodelike/NLFS.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,35 @@ + (id)binding {
return fireReq(req, async); \
} while (0)


- (JSValue *)writeStringTo:(NSNumber *)file source:(NSString *)source offset:(JSValue *)off length:(JSValue *)len pos:(JSValue *)pos callback:(JSValue *)cb {

char * cString = malloc(sizeof(char)*(source.length + 1));
strcpy(cString, source.UTF8String);
cString[source.length] = '\0';

char const *buf = cString;

unsigned int buffer_length = [source length];
unsigned int length = [len isUndefined] ? buffer_length : [len toUInt32];
unsigned int position = [pos isUndefined] ? 0 : [pos toUInt32];

call(write, cb, nil, file.intValue, buf, length, position);

}

- (JSValue *)writeBufferTo:(NSNumber *)file source:(JSValue *)source offset:(JSValue *)off length:(JSValue *)len pos:(JSValue *)pos callback:(JSValue *)cb {

NSUInteger buffer_length = [NLBuffer getLength:source];

char const *buf = [NLBuffer getData:source ofSize:buffer_length];
unsigned int length = [len isUndefined] ? buffer_length : [len toUInt32];
unsigned int position = [pos isUndefined] ? 0 : [pos toUInt32];

call(write, cb, nil, file.intValue, buf, length, position);

}

- (JSValue *)open:(longlived NSString *)path flags:(NSNumber *)flags mode:(NSNumber *)mode callback:(JSValue *)cb {
call(open, cb, nil, path.UTF8String, flags.intValue, mode.intValue);
}
Expand All @@ -60,7 +89,7 @@ - (JSValue *)close:(NSNumber *)file callback:(JSValue *)cb {
- (JSValue *)read:(NSNumber *)file to:(JSValue *)target offset:(JSValue *)off length:(JSValue *)len pos:(JSValue *)pos callback:(JSValue *)cb {
unsigned int buffer_length = [target[@"length"] toUInt32];
unsigned int length = [len isUndefined] ? buffer_length : [len toUInt32];
unsigned int position = [pos isUndefined] ? 0 : [pos toUInt32];
unsigned int position = ( [pos isUndefined] || ([pos toInt32] < 0) ) ? 0 : [pos toUInt32];
call(read, cb, ^(uv_fs_t *req) {
[NLBuffer write:req->buf toBuffer:target atOffset:off withLength:len];
}, file.intValue, malloc(length), length, position);
Expand Down Expand Up @@ -167,6 +196,10 @@ - (JSValue *)fstat:(longlived NSNumber *)file callback:(JSValue *)cb {
call(fstat, cb, nil, file.intValue);
}

- (JSValue *)utimes:(longlived NSString *)path atime:(JSValue *)atime mtime:(JSValue *)mtime callback:(JSValue *)cb {
call(utime, cb, nil, path.UTF8String, (double)[atime toDouble]/1000, (double)[mtime toDouble]/1000);
}

struct data {
void *callback, *error, *value, *after;
};
Expand Down
10 changes: 7 additions & 3 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,13 @@ function tickOnSocket(req, socket) {
ClientRequest.prototype.onSocket = function(socket) {
var req = this;

process.nextTick(function() {
tickOnSocket(req, socket);
});
//(ESTEBAN EDIT:) For some reason, waiting for nextTick prevents subsequent calls from firing properly.
//a timeout properly executes our code:
setTimeout(tickOnSocket(req, socket),200);
// process.nextTick(function() {
// tickOnSocket(req, socket);
// });

};

ClientRequest.prototype._deferToConnect = function(method, arguments_, cb) {
Expand Down
4 changes: 2 additions & 2 deletions lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ function Console(stdout, stderr) {
}, this);
}

Console.prototype.log = function() {
this._stdout.write(util.format.apply(this, arguments) + '\n');
Console.prototype.log = function() {`
this._stdout.write('GLOBAL LOG: ' + util.format.apply(this, arguments) + '\n');
};


Expand Down
22 changes: 14 additions & 8 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ function modeNum(m, def) {
fs.open = function(path, flags, mode, callback) {
callback = makeCallback(arguments[arguments.length - 1]);
mode = modeNum(mode, 438 /*=0666*/);

//console.log('Opening File for path: ' + path);
if (!nullCheck(path, callback)) return;
binding.open(pathModule._makeLong(path),
stringToFlags(flags),
Expand Down Expand Up @@ -471,6 +471,7 @@ fs.readSync = function(fd, buffer, offset, length, position) {
// fs.write(fd, string[, position[, encoding]], callback);
fs.write = function(fd, buffer, offset, length, position, callback) {
if (util.isBuffer(buffer)) {

// if no position is passed then assume null
if (util.isFunction(position)) {
callback = position;
Expand All @@ -486,7 +487,9 @@ fs.write = function(fd, buffer, offset, length, position, callback) {

if (util.isString(buffer))
buffer += '';
if (!util.isFunction(position)) {
console.log('WRITING STRING');

if (!util.isFunction(position)) {
if (util.isFunction(offset)) {
position = offset;
offset = null;
Expand All @@ -495,11 +498,13 @@ fs.write = function(fd, buffer, offset, length, position, callback) {
}
length = 'utf8';
}
callback = maybeCallback(position);
position = function(err, written) {
// retain reference to string in case it's external
callback(err, written || 0, buffer);
};

callback = maybeCallback(position);
position = function(err, written) {
// retain reference to string in case it's external
callback(err, written || 0, buffer);
};

return binding.writeString(fd, buffer, offset, length, position);
};

Expand Down Expand Up @@ -933,7 +938,8 @@ fs.writeFile = function(path, data, options, callback) {
if (openErr) {
if (callback) callback(openErr);
} else {
var buffer = util.isBuffer(data) ? data : new Buffer('' + data,
//ESTEBAN Null character fix:
var buffer = util.isBuffer(data) ? data : new Buffer('' + data + '\0',
options.encoding || 'utf8');
var position = /a/.test(flag) ? null : 0;
writeAll(fd, buffer, 0, buffer.length, position, callback);
Expand Down
9 changes: 6 additions & 3 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ Module._resolveLookupPaths = function(request, parent) {
if (!parent.paths) parent.paths = [];
paths = parent.paths.concat(paths);
}

return [request, paths];
}

Expand All @@ -242,6 +243,7 @@ Module._resolveLookupPaths = function(request, parent) {
// from realpath(__filename) but with eval there is no filename
var mainPaths = ['.'].concat(modulePaths);
mainPaths = Module._nodeModulePaths('.').concat(mainPaths);

return [request, mainPaths];
}

Expand All @@ -266,12 +268,13 @@ Module._resolveLookupPaths = function(request, parent) {


Module._load = function(request, parent, isMain) {

if (parent) {
debug('Module._load REQUEST ' + (request) + ' parent: ' + parent.id);
}

var filename = Module._resolveFilename(request, parent);

var cachedModule = Module._cache[filename];
if (cachedModule) {
return cachedModule.exports;
Expand Down Expand Up @@ -325,7 +328,7 @@ Module._resolveFilename = function(request, parent) {
// look up the filename first, since that's the cache key.
debug('looking for ' + JSON.stringify(id) +
' in ' + JSON.stringify(paths));

var filename = Module._findPath(request, paths);
if (!filename) {
var err = new Error("Cannot find module '" + request + "'");
Expand Down Expand Up @@ -502,7 +505,7 @@ Module._initPaths = function() {
}

var paths = [path.resolve(process.execPath, '..', '..', 'lib', 'node')];

if (homeDir) {
paths.unshift(path.resolve(homeDir, '.node_libraries'));
paths.unshift(path.resolve(homeDir, '.node_modules'));
Expand Down
11 changes: 10 additions & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ function Socket(options) {
// shut down the socket when we're finished with it.
this.on('finish', onSocketFinish);
this.on('_socketEnd', onSocketEnd);

this.on('connect', onConnectFire);

initSocketHandle(this);

this._pendingData = null;
Expand All @@ -176,6 +177,11 @@ function Socket(options) {
}
util.inherits(Socket, stream.Duplex);


function onConnectFire() {
debug('firing the onConnectFire event');
}

// the user has called .end(), and all the bytes have been
// sent out to the other side.
// If allowHalfOpen is false, or if the readable side has
Expand Down Expand Up @@ -296,6 +302,9 @@ Socket.prototype.listen = function() {


Socket.prototype.setTimeout = function(msecs, callback) {
//ESTEBAN ADDED 3000 msecs;
//msecs = 3000;
//console.log('Setting timeout to: ' + msecs);
if (msecs > 0 && !isNaN(msecs) && isFinite(msecs)) {
timers.enroll(this, msecs);
timers._unrefActive(this);
Expand Down
2 changes: 1 addition & 1 deletion lib/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
};

startup.globalConsole = function() {
global.__defineGetter__('console', function() {
global.__defineGetter__('gconsole', function() {
return NativeModule.require('console');
});
};
Expand Down
2 changes: 1 addition & 1 deletion lib/nodelike.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
NativeModule._source = process.binding('natives');
NativeModule._cache = {};

NativeModule.require = function(id) {
NativeModule.require = function(id) {
if (id == 'native_module') {
return NativeModule;
}
Expand Down
Loading