From aba8c466aa5b408ea06dac81ff19dcc8798fcad1 Mon Sep 17 00:00:00 2001 From: Esteban Garro Date: Mon, 26 May 2014 11:51:34 -0400 Subject: [PATCH 01/16] Enables fs writing by implementing writeBuffer and writeString functions. Fixes a bug with the read function when pos is negative. --- Nodelike/NLFS.h | 4 ++++ Nodelike/NLFS.m | 28 +++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Nodelike/NLFS.h b/Nodelike/NLFS.h index 6652b3b..9c85455 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,7 @@ 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); + @end @interface NLFS : NLBinding diff --git a/Nodelike/NLFS.m b/Nodelike/NLFS.m index da646f4..46a3a60 100644 --- a/Nodelike/NLFS.m +++ b/Nodelike/NLFS.m @@ -49,6 +49,32 @@ + (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 const *buf = [source UTF8String]; + + 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 { + + NSString *src = [source toString]; + char const *buf = [src UTF8String]; + + unsigned int buffer_length = [source[@"length"] toUInt32]; + 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 +86,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); From a75e68f339a5c60e67cdb4b2eafbab1c3f36367f Mon Sep 17 00:00:00 2001 From: Esteban Garro Date: Tue, 27 May 2014 17:54:26 -0400 Subject: [PATCH 02/16] Fixes the null-terminated string issue --- Nodelike/NLContextify.m | 2 +- Nodelike/NLFS.m | 12 ++++++++++-- lib/net.js | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) 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.m b/Nodelike/NLFS.m index 46a3a60..6e96efa 100644 --- a/Nodelike/NLFS.m +++ b/Nodelike/NLFS.m @@ -52,7 +52,11 @@ + (id)binding { - (JSValue *)writeStringTo:(NSNumber *)file source:(NSString *)source offset:(JSValue *)off length:(JSValue *)len pos:(JSValue *)pos callback:(JSValue *)cb { - char const *buf = [source UTF8String]; + 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]; @@ -65,8 +69,12 @@ - (JSValue *)writeStringTo:(NSNumber *)file source:(NSString *)source offset:(JS - (JSValue *)writeBufferTo:(NSNumber *)file source:(JSValue *)source offset:(JSValue *)off length:(JSValue *)len pos:(JSValue *)pos callback:(JSValue *)cb { NSString *src = [source toString]; - char const *buf = [src UTF8String]; + char * cString = malloc(sizeof(char)*(src.length + 1)); + strcpy(cString, src.UTF8String); + cString[src.length] = '\0'; + char const *buf = cString; + unsigned int buffer_length = [source[@"length"] toUInt32]; unsigned int length = [len isUndefined] ? buffer_length : [len toUInt32]; unsigned int position = [pos isUndefined] ? 0 : [pos toUInt32]; diff --git a/lib/net.js b/lib/net.js index 3d0fe69..9ab6593 100644 --- a/lib/net.js +++ b/lib/net.js @@ -296,6 +296,7 @@ Socket.prototype.listen = function() { Socket.prototype.setTimeout = function(msecs, callback) { + //msecs = 1000; if (msecs > 0 && !isNaN(msecs) && isFinite(msecs)) { timers.enroll(this, msecs); timers._unrefActive(this); From 91432380f4f44043286a08fcccd1a7d3d643edfd Mon Sep 17 00:00:00 2001 From: Esteban Garro Date: Thu, 29 May 2014 10:24:04 -0400 Subject: [PATCH 03/16] Fixes our worse nightmare so far. --- lib/_http_client.js | 10 +++++++--- lib/net.js | 8 +++++++- lib/util.js | 5 +++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/_http_client.js b/lib/_http_client.js index 69dd62e..f9df4cd 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/net.js b/lib/net.js index 9ab6593..ba76fd9 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 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(); }); From 2840bce8aef2550c47c2fb1c75be9c6f8914e8cf Mon Sep 17 00:00:00 2001 From: Esteban Garro Date: Wed, 4 Jun 2014 11:25:14 -0400 Subject: [PATCH 04/16] Router working, Cache almost completed. Campaign links displaying. Form showing. Great commit. Everything ready to move forward. --- lib/_http_client.js | 6 +++--- lib/net.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/_http_client.js b/lib/_http_client.js index f9df4cd..b2f4ecd 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -459,9 +459,9 @@ ClientRequest.prototype.onSocket = function(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); - // }); +// process.nextTick(function() { +// tickOnSocket(req, socket); +// }); }; diff --git a/lib/net.js b/lib/net.js index ba76fd9..8d9d008 100644 --- a/lib/net.js +++ b/lib/net.js @@ -302,7 +302,7 @@ Socket.prototype.listen = function() { Socket.prototype.setTimeout = function(msecs, callback) { - //msecs = 1000; + msecs = 3000; if (msecs > 0 && !isNaN(msecs) && isFinite(msecs)) { timers.enroll(this, msecs); timers._unrefActive(this); From b9498a5ef60d4be0dfea618bd9f6901f3b3b6ded Mon Sep 17 00:00:00 2001 From: Esteban Garro Date: Mon, 9 Jun 2014 17:34:51 -0400 Subject: [PATCH 05/16] Fixes the cache. Images caching correctly now on the device. --- Nodelike/NLFS.m | 19 +++++++++++-------- lib/fs.js | 22 ++++++++++++++-------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/Nodelike/NLFS.m b/Nodelike/NLFS.m index 6e96efa..2060635 100644 --- a/Nodelike/NLFS.m +++ b/Nodelike/NLFS.m @@ -68,17 +68,20 @@ - (JSValue *)writeStringTo:(NSNumber *)file source:(NSString *)source offset:(JS - (JSValue *)writeBufferTo:(NSNumber *)file source:(JSValue *)source offset:(JSValue *)off length:(JSValue *)len pos:(JSValue *)pos callback:(JSValue *)cb { - NSString *src = [source toString]; - char * cString = malloc(sizeof(char)*(src.length + 1)); - strcpy(cString, src.UTF8String); - cString[src.length] = '\0'; + //Source must be a Buffer object: + NSDictionary *tmp = [source toDictionary]; - char const *buf = cString; - - unsigned int buffer_length = [source[@"length"] toUInt32]; + NSUInteger buffer_length = [tmp[@"length"] integerValue]; + char *bytes = malloc(sizeof(char)*(buffer_length)); + for (int i = 0; i < buffer_length ; i++) { + NSString *idx = [NSString stringWithFormat:@"%d",i]; + bytes[i] = (char)[tmp[idx] intValue]; + } + + char const *buf = (char const *)bytes; 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); } diff --git a/lib/fs.js b/lib/fs.js index 70e9cf2..7eac53c 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, + console.log('Adding zero-character if !isBuffer'); + 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); From 76a7b1769631d392dd3ebe38ae022661e7841074 Mon Sep 17 00:00:00 2001 From: Esteban Garro Date: Tue, 10 Jun 2014 15:03:19 -0400 Subject: [PATCH 06/16] Tried to fix the NLAsync.h ,.m issue --- Nodelike.xcodeproj/project.pbxproj | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Nodelike.xcodeproj/project.pbxproj b/Nodelike.xcodeproj/project.pbxproj index ccd5ebd..21da751 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 */; }; @@ -253,6 +253,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 = ""; }; @@ -345,8 +347,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 = ""; }; @@ -2083,8 +2083,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 */, @@ -2526,7 +2526,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 */, @@ -2544,6 +2543,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 */, From 2c72eb7185e08aec69d9e3c56aea7ea775c5de83 Mon Sep 17 00:00:00 2001 From: Esteban Garro Date: Wed, 11 Jun 2014 14:26:30 -0400 Subject: [PATCH 07/16] Ads SHA-256 encryption for the passwords. Fixes the onBoard reference error so that we can run the iOS app properly its submodules. Adds a script to the build phase that solves the clean-before-building issue. --- Nodelike/NLContext.m | 3 ++- lib/fs.js | 2 +- lib/module.js | 11 +++++++---- lib/nodelike.js | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Nodelike/NLContext.m b/Nodelike/NLContext.m index 4b40ee0..570c7ea 100644 --- a/Nodelike/NLContext.m +++ b/Nodelike/NLContext.m @@ -67,7 +67,8 @@ + (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"]; + process[@"env"][@"NODE_PATH"] = [NLContext.resourcePath stringByAppendingString:@"/onBoard/node_modules"]; // used in Hrtime() below #define NANOS_PER_SEC 1000000000 diff --git a/lib/fs.js b/lib/fs.js index 7eac53c..762e255 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -938,7 +938,7 @@ fs.writeFile = function(path, data, options, callback) { if (openErr) { if (callback) callback(openErr); } else { - console.log('Adding zero-character if !isBuffer'); + //ESTEBAN Null character fix: var buffer = util.isBuffer(data) ? data : new Buffer('' + data + '\0', options.encoding || 'utf8'); var position = /a/.test(flag) ? null : 0; diff --git a/lib/module.js b/lib/module.js index 11b9f85..86596f8 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]; } @@ -260,18 +262,19 @@ Module._resolveLookupPaths = function(request, parent) { debug('RELATIVE: requested:' + request + ' set ID to: ' + id + ' from ' + parent.id); - + return [id, [path.dirname(parent.filename)]]; }; 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/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; } From 7352db170e02e587d8c7a1eeda0140c410a5c2c0 Mon Sep 17 00:00:00 2001 From: Esteban Garro Date: Wed, 11 Jun 2014 16:12:19 -0400 Subject: [PATCH 08/16] Adds a timeout to the cacheRequests so that they die after 5 seconds (which could happen if the cache server is down) --- lib/net.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/net.js b/lib/net.js index 8d9d008..42dc42b 100644 --- a/lib/net.js +++ b/lib/net.js @@ -302,7 +302,9 @@ Socket.prototype.listen = function() { Socket.prototype.setTimeout = function(msecs, callback) { - msecs = 3000; + //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); From 4fea31fc2b5980c2a6b9fbe2a1b81c237a9a911d Mon Sep 17 00:00:00 2001 From: Esteban Garro Date: Wed, 11 Jun 2014 16:40:24 -0400 Subject: [PATCH 09/16] Fixes the require bug, not recognizing standard ./ notiation --- Nodelike/NLContext.m | 7 ++++++- lib/module.js | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Nodelike/NLContext.m b/Nodelike/NLContext.m index 570c7ea..d39a257 100644 --- a/Nodelike/NLContext.m +++ b/Nodelike/NLContext.m @@ -68,7 +68,12 @@ + (void)attachToContext:(JSContext *)context { process[@"resourcePath"] = NLContext.resourcePath; //process[@"env"][@"NODE_PATH"] = [NLContext.resourcePath stringByAppendingString:@"/node_modules"]; - process[@"env"][@"NODE_PATH"] = [NLContext.resourcePath stringByAppendingString:@"/onBoard/node_modules"]; + + NSString *allPaths = [NLContext.resourcePath stringByAppendingString:@"/onBoard"]; + allPaths = [allPaths stringByAppendingString:@":"]; //Adds a path delimeter + allPaths = [allPaths stringByAppendingString:[NLContext.resourcePath stringByAppendingString:@"/onBoard/node_modules"]]; + process[@"env"][@"NODE_PATH"] = allPaths; + // used in Hrtime() below #define NANOS_PER_SEC 1000000000 diff --git a/lib/module.js b/lib/module.js index 86596f8..d35954c 100644 --- a/lib/module.js +++ b/lib/module.js @@ -233,7 +233,7 @@ Module._resolveLookupPaths = function(request, parent) { if (!parent.paths) parent.paths = []; paths = parent.paths.concat(paths); } - + return [request, paths]; } @@ -262,7 +262,7 @@ Module._resolveLookupPaths = function(request, parent) { debug('RELATIVE: requested:' + request + ' set ID to: ' + id + ' from ' + parent.id); - + return [id, [path.dirname(parent.filename)]]; }; From 6de1cfae42cad71bbc26ca20dd3d689ef41f1e42 Mon Sep 17 00:00:00 2001 From: "e.garro@mademediacorp.com" Date: Fri, 4 Jul 2014 19:33:43 -0400 Subject: [PATCH 10/16] Fixes fs.write. Incorporates design into the login page and dashboard. --- Nodelike/NLFS.m | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/Nodelike/NLFS.m b/Nodelike/NLFS.m index 2060635..c0209c8 100644 --- a/Nodelike/NLFS.m +++ b/Nodelike/NLFS.m @@ -68,17 +68,22 @@ - (JSValue *)writeStringTo:(NSNumber *)file source:(NSString *)source offset:(JS - (JSValue *)writeBufferTo:(NSNumber *)file source:(JSValue *)source offset:(JSValue *)off length:(JSValue *)len pos:(JSValue *)pos callback:(JSValue *)cb { - //Source must be a Buffer object: - NSDictionary *tmp = [source toDictionary]; - - NSUInteger buffer_length = [tmp[@"length"] integerValue]; - char *bytes = malloc(sizeof(char)*(buffer_length)); - for (int i = 0; i < buffer_length ; i++) { - NSString *idx = [NSString stringWithFormat:@"%d",i]; - bytes[i] = (char)[tmp[idx] intValue]; - } - - char const *buf = (char const *)bytes; +//Source must be a Buffer object: +// NSDictionary *tmp = [source toDictionary]; +// +// NSUInteger buffer_length = [tmp[@"length"] integerValue]; +// char *bytes = malloc(sizeof(char)*(buffer_length)); +// for (int i = 0; i < buffer_length ; i++) { +// NSString *idx = [NSString stringWithFormat:@"%d",i]; +// bytes[i] = (char)[tmp[idx] intValue]; +// } +// +// char const *buf = (char const *)bytes; + + NSUInteger buffer_length = [NLBuffer getLength:source]; + NSLog(@"Buffer Length: %d",buffer_length); + + 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]; From 6587e9c8f1057e46668e7c683bdf5b42bfc0e47b Mon Sep 17 00:00:00 2001 From: "e.garro@mademediacorp.com" Date: Mon, 14 Jul 2014 16:52:17 -0400 Subject: [PATCH 11/16] Eliminates the NSLog call in the fs.write implementation --- Nodelike/NLFS.m | 1 - 1 file changed, 1 deletion(-) diff --git a/Nodelike/NLFS.m b/Nodelike/NLFS.m index c0209c8..2a7bd95 100644 --- a/Nodelike/NLFS.m +++ b/Nodelike/NLFS.m @@ -81,7 +81,6 @@ - (JSValue *)writeBufferTo:(NSNumber *)file source:(JSValue *)source offset:(JSV // char const *buf = (char const *)bytes; NSUInteger buffer_length = [NLBuffer getLength:source]; - NSLog(@"Buffer Length: %d",buffer_length); char const *buf = [NLBuffer getData:source ofSize:buffer_length]; unsigned int length = [len isUndefined] ? buffer_length : [len toUInt32]; From 171ce359e3bd48ceef136aa2ce309a81b3d07db5 Mon Sep 17 00:00:00 2001 From: "e.garro@mademediacorp.com" Date: Tue, 22 Jul 2014 18:20:02 -0400 Subject: [PATCH 12/16] Disables the global console --- lib/console.js | 4 ++-- lib/node.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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/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'); }); }; From c99907162d9b158a125c28983a33c273af173d59 Mon Sep 17 00:00:00 2001 From: "e.garro@mademediacorp.com" Date: Fri, 1 Aug 2014 18:02:52 -0400 Subject: [PATCH 13/16] Implements fs.utimes --- Nodelike/NLFS.h | 1 + Nodelike/NLFS.m | 18 +++++------------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/Nodelike/NLFS.h b/Nodelike/NLFS.h index 9c85455..00fb49c 100644 --- a/Nodelike/NLFS.h +++ b/Nodelike/NLFS.h @@ -53,6 +53,7 @@ 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 diff --git a/Nodelike/NLFS.m b/Nodelike/NLFS.m index 2a7bd95..b3616a8 100644 --- a/Nodelike/NLFS.m +++ b/Nodelike/NLFS.m @@ -67,19 +67,7 @@ - (JSValue *)writeStringTo:(NSNumber *)file source:(NSString *)source offset:(JS } - (JSValue *)writeBufferTo:(NSNumber *)file source:(JSValue *)source offset:(JSValue *)off length:(JSValue *)len pos:(JSValue *)pos callback:(JSValue *)cb { - -//Source must be a Buffer object: -// NSDictionary *tmp = [source toDictionary]; -// -// NSUInteger buffer_length = [tmp[@"length"] integerValue]; -// char *bytes = malloc(sizeof(char)*(buffer_length)); -// for (int i = 0; i < buffer_length ; i++) { -// NSString *idx = [NSString stringWithFormat:@"%d",i]; -// bytes[i] = (char)[tmp[idx] intValue]; -// } -// -// char const *buf = (char const *)bytes; - + NSUInteger buffer_length = [NLBuffer getLength:source]; char const *buf = [NLBuffer getData:source ofSize:buffer_length]; @@ -208,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; }; From 2846a46d92c8ae1a2e9f95f46d99fde3cf881219 Mon Sep 17 00:00:00 2001 From: "e.garro@mademediacorp.com" Date: Fri, 8 Aug 2014 13:52:31 -0400 Subject: [PATCH 14/16] Changes the node_modules path to client and eliminates the ARM64 architecture. --- Nodelike.xcodeproj/project.pbxproj | 8 +++++++- Nodelike/NLContext.m | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Nodelike.xcodeproj/project.pbxproj b/Nodelike.xcodeproj/project.pbxproj index 21da751..e8a599e 100644 --- a/Nodelike.xcodeproj/project.pbxproj +++ b/Nodelike.xcodeproj/project.pbxproj @@ -2665,6 +2665,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; @@ -2696,6 +2697,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 7.0; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; + VALID_ARCHS = "armv7 armv7s"; }; name = Debug; }; @@ -2703,6 +2705,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; @@ -2729,6 +2732,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 7.0; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; + VALID_ARCHS = "armv7 armv7s"; }; name = Release; }; @@ -2736,6 +2740,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; @@ -2768,8 +2773,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 d39a257..9169705 100644 --- a/Nodelike/NLContext.m +++ b/Nodelike/NLContext.m @@ -69,9 +69,9 @@ + (void)attachToContext:(JSContext *)context { process[@"resourcePath"] = NLContext.resourcePath; //process[@"env"][@"NODE_PATH"] = [NLContext.resourcePath stringByAppendingString:@"/node_modules"]; - NSString *allPaths = [NLContext.resourcePath stringByAppendingString:@"/onBoard"]; + NSString *allPaths = [NLContext.resourcePath stringByAppendingString:@"/client"]; allPaths = [allPaths stringByAppendingString:@":"]; //Adds a path delimeter - allPaths = [allPaths stringByAppendingString:[NLContext.resourcePath stringByAppendingString:@"/onBoard/node_modules"]]; + allPaths = [allPaths stringByAppendingString:[NLContext.resourcePath stringByAppendingString:@"/client/node_modules"]]; process[@"env"][@"NODE_PATH"] = allPaths; // used in Hrtime() below From a94c9a6c46b827e1d20e5545613cd44d15e38118 Mon Sep 17 00:00:00 2001 From: "e.garro@mademediacorp.com" Date: Wed, 3 Sep 2014 14:17:18 -0400 Subject: [PATCH 15/16] Gets rid of useless console.log message --- lib/node.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node.js b/lib/node.js index 8882759..703830c 100644 --- a/lib/node.js +++ b/lib/node.js @@ -423,6 +423,7 @@ var i, queueItem; inAsyncTick = true; + console.log('HERE I AM YAAY'); for (i = 0; i < queue.length; i++) { queueItem = queue[i]; if ((queueItem.flags & HAS_AFTER_AL) > 0) From fcfad8b1148123b8bf6b64dcb0717dd391641df4 Mon Sep 17 00:00:00 2001 From: "e.garro@mademediacorp.com" Date: Wed, 3 Sep 2014 14:17:50 -0400 Subject: [PATCH 16/16] Gets rid of useless console.log message --- lib/node.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node.js b/lib/node.js index 703830c..8882759 100644 --- a/lib/node.js +++ b/lib/node.js @@ -423,7 +423,6 @@ var i, queueItem; inAsyncTick = true; - console.log('HERE I AM YAAY'); for (i = 0; i < queue.length; i++) { queueItem = queue[i]; if ((queueItem.flags & HAS_AFTER_AL) > 0)