diff --git a/Nodelike.xcodeproj/project.pbxproj b/Nodelike.xcodeproj/project.pbxproj index 13c92ee..03de9a4 100644 --- a/Nodelike.xcodeproj/project.pbxproj +++ b/Nodelike.xcodeproj/project.pbxproj @@ -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 */; }; @@ -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 */; }; @@ -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 = ""; }; + 418E78FB19478C5D0075FFEE /* NLAsync.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NLAsync.m; sourceTree = ""; }; B5061A381815A9B00083AB4B /* NLCares.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NLCares.h; sourceTree = ""; }; B5061A391815A9B00083AB4B /* NLCares.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NLCares.m; sourceTree = ""; }; B50A490218C3882700656FA3 /* NextTick_Tests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NextTick_Tests.m; sourceTree = ""; }; @@ -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 = ""; }; - B52B9B9218A01D0800492856 /* NLAsync.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NLAsync.m; sourceTree = ""; }; B53E6996184672F3004E4EF9 /* NLStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NLStream.h; sourceTree = ""; }; B53E6997184672F3004E4EF9 /* NLStream.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NLStream.m; sourceTree = ""; }; B541730F189415C000B6636B /* NLUDP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NLUDP.h; sourceTree = ""; }; @@ -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 */, @@ -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 */, @@ -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 */, @@ -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; @@ -2712,6 +2713,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 7.0; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; + VALID_ARCHS = "armv7 armv7s"; }; name = Debug; }; @@ -2719,6 +2721,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; @@ -2745,6 +2748,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 7.0; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; + VALID_ARCHS = "armv7 armv7s"; }; name = Release; }; @@ -2752,6 +2756,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; @@ -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; }; diff --git a/Nodelike/NLContext.m b/Nodelike/NLContext.m index 18a9132..c5f8a5c 100644 --- a/Nodelike/NLContext.m +++ b/Nodelike/NLContext.m @@ -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 diff --git a/Nodelike/NLContextify.m b/Nodelike/NLContextify.m index 8058e5c..2f470b5 100644 --- a/Nodelike/NLContextify.m +++ b/Nodelike/NLContextify.m @@ -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]; diff --git a/Nodelike/NLFS.h b/Nodelike/NLFS.h index 6652b3b..00fb49c 100644 --- a/Nodelike/NLFS.h +++ b/Nodelike/NLFS.h @@ -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); @@ -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 diff --git a/Nodelike/NLFS.m b/Nodelike/NLFS.m index da646f4..b3616a8 100644 --- a/Nodelike/NLFS.m +++ b/Nodelike/NLFS.m @@ -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); } @@ -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); @@ -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; }; diff --git a/lib/_http_client.js b/lib/_http_client.js index 69dd62e..b2f4ecd 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -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) { diff --git a/lib/console.js b/lib/console.js index 1c98167..0fb85b1 100644 --- a/lib/console.js +++ b/lib/console.js @@ -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'); }; diff --git a/lib/fs.js b/lib/fs.js index 70e9cf2..762e255 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -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), @@ -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; @@ -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; @@ -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); }; @@ -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); diff --git a/lib/module.js b/lib/module.js index 11b9f85..d35954c 100644 --- a/lib/module.js +++ b/lib/module.js @@ -233,6 +233,7 @@ Module._resolveLookupPaths = function(request, parent) { if (!parent.paths) parent.paths = []; paths = parent.paths.concat(paths); } + return [request, paths]; } @@ -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]; } @@ -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; @@ -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 + "'"); @@ -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')); diff --git a/lib/net.js b/lib/net.js index 3d0fe69..42dc42b 100644 --- a/lib/net.js +++ b/lib/net.js @@ -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; @@ -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 @@ -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); diff --git a/lib/node.js b/lib/node.js index 2c3372f..8882759 100644 --- a/lib/node.js +++ b/lib/node.js @@ -211,7 +211,7 @@ }; startup.globalConsole = function() { - global.__defineGetter__('console', function() { + global.__defineGetter__('gconsole', function() { return NativeModule.require('console'); }); }; diff --git a/lib/nodelike.js b/lib/nodelike.js index 20f72b0..d10e9e6 100644 --- a/lib/nodelike.js +++ b/lib/nodelike.js @@ -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; } diff --git a/lib/util.js b/lib/util.js index 500c1d1..40aeca6 100644 --- a/lib/util.js +++ b/lib/util.js @@ -108,6 +108,10 @@ exports.debuglog = function(set) { }; } else { debugs[set] = function() {}; +// debugs[set] = function() { +// var msg = exports.format.apply(exports, arguments); +// console.error('%s %d: %s', set, process.pid, msg); +// }; } } return debugs[set]; @@ -716,6 +720,7 @@ exports.pump = exports.deprecate(function(readStream, writeStream, callback) { }); readStream.addListener('end', function() { + writeStream.end(); });