Skip to content

Commit

Permalink
Clean up logging
Browse files Browse the repository at this point in the history
  • Loading branch information
sgtcoolguy committed May 24, 2016
1 parent e0bf4ac commit 77ce56f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 28 deletions.
18 changes: 2 additions & 16 deletions android/runtime/common/src/js/module.js
Expand Up @@ -240,11 +240,9 @@ Module.prototype.require = function (request, context) {
var start, // hack up the start of the string to check relative/absolute/"naked" module id
loaded; // variable to hold the possibly loaded module...

kroll.log(TAG, "require('" + request + "')");
// 1. If X is a core module,
loaded = this.loadCoreModule(request, context);
if (loaded) {
kroll.log(TAG, "Was core module, returning...");
// a. return the core module
// b. STOP
return loaded;
Expand Down Expand Up @@ -284,7 +282,7 @@ Module.prototype.require = function (request, context) {

// TODO Can we determine if the first path segment is a commonjs module id? If so, don't spit out this log!
// Fallback to old Titanium behavior of assuming it's actually an absolute path
kroll.log(TAG, "Naked module id, should be core or node_module. Falling back to old Ti behavior and assuming it's an absolute path");
kroll.log(TAG, "require called with un-prefixed module id, should be a core or CommonJS module. Falling back to old Ti behavior and assuming it's an absolute file");

loaded = this.loadAsFileOrDirectory('Resources/' + request, context);
if (loaded) {
Expand Down Expand Up @@ -346,14 +344,11 @@ Module.prototype.loadCoreModule = function (id, context) {
* @return {Object} The module's exports, if loaded. null if not.
*/
Module.prototype.loadAsFileOrDirectory = function (normalizedPath, context) {
var loaded;
kroll.log(TAG, "Attempting to load as file: " + normalizedPath);
// a. LOAD_AS_FILE(Y + X)
loaded = this.loadAsFile(normalizedPath, context);
var loaded = this.loadAsFile(normalizedPath, context);
if (loaded) {
return loaded;
}
kroll.log(TAG, "Attempting to load as directory: " + normalizedPath);
// b. LOAD_AS_DIRECTORY(Y + X)
loaded = this.loadAsDirectory(normalizedPath, context);
if (loaded) {
Expand Down Expand Up @@ -435,22 +430,18 @@ Module.prototype.loadAsFile = function (id, context) {
if (this.filenameExists(filename)) {
// If the file has a .json extension, load as JavascriptObject
if (filename.length > 5 && filename.slice(-4) === 'json') {
kroll.log(TAG, filename + ' exists, loading as JSON');
return this.loadJavascriptObject(filename, context);
}
kroll.log(TAG, filename + ' exists, loading as JS');
return this.loadJavascriptText(filename, context);
}
// 2. If X.js is a file, load X.js as JavaScript text. STOP
filename = id + '.js';
if (this.filenameExists(filename)) {
kroll.log(TAG, filename + ' exists, loading as JS');
return this.loadJavascriptText(filename, context);
}
// 3. If X.json is a file, parse X.json to a JavaScript Object. STOP
filename = id + '.json';
if (this.filenameExists(filename)) {
kroll.log(TAG, filename + ' exists, loading as JSON');
return this.loadJavascriptObject(filename, context);
}
// failed to load anything!
Expand All @@ -468,14 +459,11 @@ Module.prototype.loadAsDirectory = function (id, context) {
// 1. If X/package.json is a file,
var filename = path.resolve(id, 'package.json');
if (this.filenameExists(filename)) {
kroll.log(TAG, 'package.json exists, parsing...');
// a. Parse X/package.json, and look for "main" field.
var object = this.loadJavascriptObject(filename, context);
kroll.log(TAG, JSON.stringify(object));
if (object && object.main) {
// b. let M = X + (json main field)
var m = path.resolve(id, object.main);
kroll.log(TAG, 'Resolved to ' + m);
// c. LOAD_AS_FILE(M)
return this.loadAsFile(m, context);
}
Expand All @@ -484,13 +472,11 @@ Module.prototype.loadAsDirectory = function (id, context) {
// 2. If X/index.js is a file, load X/index.js as JavaScript text. STOP
filename = path.resolve(id, 'index.js');
if (this.filenameExists(filename)) {
kroll.log(TAG, filename + ' exists, loading as JS');
return this.loadJavascriptText(filename, context);
}
// 3. If X/index.json is a file, parse X/index.json to a JavaScript object. STOP
filename = path.resolve(id, 'index.json');
if (this.filenameExists(filename)) {
kroll.log(TAG, filename + ' exists, loading as JSON');
return this.loadJavascriptObject(filename, context);
}

Expand Down
14 changes: 2 additions & 12 deletions iphone/Classes/KrollBridge.m
Expand Up @@ -82,7 +82,7 @@ -(id)initWithContext:(KrollContext*)context_ host:(TiHost*)host_ context:(id<TiE
#if KROLLBRIDGE_MEMORY_DEBUG==1
-(id)retain
{
NSLog(@"[MEMRORY DEBUG] RETAIN: %@ (%d)",self,[self retainCount]+1);
NSLog(@"[MEMORY DEBUG] RETAIN: %@ (%d)",self,[self retainCount]+1);
return [super retain];
}
-(oneway void)release
Expand Down Expand Up @@ -955,7 +955,6 @@ - (TiModule *)loadJavascriptObject:(NSString *)data fromFile:(NSString *)filenam
// 5. close the JSON string and end the JSON.parse call
data = [data stringByAppendingString:@"');"];

NSLog(@"Modified JSON contents: %@", data);
return [self loadJavascriptText:data fromFile:filename withContext:kroll];
}

Expand Down Expand Up @@ -1012,14 +1011,12 @@ - (TiModule *)loadAsFile:(NSString *)path withContext:(KrollContext *)kroll
filename = [path stringByAppendingString:@".js"];
data = [self loadFile:filename];
if (data != nil) {
NSLog(@"%@ exists, loading as JS", filename);
return [self loadJavascriptText:data fromFile:filename withContext:context];
}
// 3. If X.json is a file, parse X.json to a JavaScript Object. STOP
filename = [path stringByAppendingString:@".json"];
data = [self loadFile:filename];
if (data != nil) {
NSLog(@"%@ exists, loading as JSON", filename);
return [self loadJavascriptObject:data fromFile:filename withContext:context];
}
// failed to load anything!
Expand All @@ -1032,7 +1029,6 @@ - (TiModule *)loadAsDirectory:(NSString *)path withContext:(KrollContext *)kroll
NSString *filename = [path stringByAppendingPathComponent:@"package.json"];
NSString *data = [self loadFile:filename];
if (data != nil) {
NSLog(@"package.json exists, parsing...");
// a. Parse X/package.json, and look for "main" field.
// Just cheat and use TiUtils.jsonParse here, rather than loading the package.json as a JS object...
NSDictionary *json = [TiUtils jsonParse:data];
Expand All @@ -1043,7 +1039,6 @@ - (TiModule *)loadAsDirectory:(NSString *)path withContext:(KrollContext *)kroll
mainString = (NSString *)main;
// b. let M = X + (json main field)
NSString *m = [[path stringByAppendingPathComponent:mainString] stringByStandardizingPath];
NSLog(@"Resolved to %@", m);
// c. LOAD_AS_FILE(M)
return [self loadAsFile:m withContext:context];
}
Expand All @@ -1054,14 +1049,12 @@ - (TiModule *)loadAsDirectory:(NSString *)path withContext:(KrollContext *)kroll
filename = [path stringByAppendingPathComponent:@"index.js"];
data = [self loadFile:filename];
if (data != nil) {
NSLog(@"%@ exists, loading as JS", filename);
return [self loadJavascriptText:data fromFile:filename withContext:context];
}
// 3. If X/index.json is a file, parse X/index.json to a JavaScript object. STOP
filename = [path stringByAppendingPathComponent:@"index.json"];
data = [self loadFile:filename];
if (data != nil) {
NSLog(@"%@ exists, loading as JSON", filename);
return [self loadJavascriptObject:data fromFile:filename withContext:context];
}

Expand All @@ -1071,13 +1064,11 @@ - (TiModule *)loadAsDirectory:(NSString *)path withContext:(KrollContext *)kroll
- (TiModule *)loadAsFileOrDirectory:(NSString *)path withContext:(KrollContext *)kroll
{
TiModule *module = nil;
NSLog(@"Attempting to load as file: %@", path);
// a. LOAD_AS_FILE(Y + X)
module = [self loadAsFile:path withContext:context];
if (module) {
return module;
}
NSLog(@"Attempting to load as directory: %@", path);
// b. LOAD_AS_DIRECTORY(Y + X)
module = [self loadAsDirectory:path withContext:context];
if (module) {
Expand All @@ -1094,7 +1085,6 @@ - (id)require:(KrollContext *)kroll path:(NSString *)path
// 1. If X is a core module,
TiModule *module = [self loadCoreModule:path withContext:kroll];
if (module) {
NSLog(@"Was core module, returning...");
// a. return the core module
// b. STOP
return module;
Expand Down Expand Up @@ -1136,7 +1126,7 @@ - (id)require:(KrollContext *)kroll path:(NSString *)path
}
// TODO Find a way to determine if the first path segment refers to a CommonJS module, and if so don't log
// TODO How can we make this spit this out to Ti.API.log?
NSLog(@"Non-prefixed module id, should be core or node_module. Falling back to old Ti behavior and assuming it's an absolute path");
NSLog(@"require called with un-prefixed module id, should be a core or CommonJS module. Falling back to old Ti behavior and assuming it's an absolute file");
module = [self loadAsFileOrDirectory:[path stringByStandardizingPath] withContext:context];
if (module) {
return module;
Expand Down

0 comments on commit 77ce56f

Please sign in to comment.