Bug 785200 - Conditioned logging in osfiles with exports.OS.Shared.DEBUG. r=yoric

--HG--
extra : rebase_source : e6e9de813d8ec5f82f32522d32e0cedb0ec07f2c
This commit is contained in:
Abhishek Potnis 2012-08-29 14:12:23 +05:30
parent 14b3b51372
commit ef0432f69a
3 changed files with 31 additions and 9 deletions

View File

@ -46,6 +46,10 @@
}); });
}; };
/**
* A variable controlling whether we should printout logs.
*/
exports.OS.Shared.DEBUG = false;
let LOG; let LOG;
if (typeof console != "undefined" && console.log) { if (typeof console != "undefined" && console.log) {
LOG = console.log.bind(console, "OS"); LOG = console.log.bind(console, "OS");
@ -329,8 +333,10 @@
}; };
function projector(type, signed) { function projector(type, signed) {
LOG("Determining best projection for", type, if (exports.OS.Shared.DEBUG) {
LOG("Determining best projection for", type,
"(size: ", type.size, ")", signed?"signed":"unsigned"); "(size: ", type.size, ")", signed?"signed":"unsigned");
}
if (type instanceof Type) { if (type instanceof Type) {
type = type.implementation; type = type.implementation;
} }
@ -348,14 +354,20 @@
|| type == ctypes.uintptr_t || type == ctypes.uintptr_t
|| type == ctypes.off_t){ || type == ctypes.off_t){
if (signed) { if (signed) {
LOG("Projected as a large signed integer"); if (exports.OS.Shared.DEBUG) {
LOG("Projected as a large signed integer");
}
return projectLargeInt; return projectLargeInt;
} else { } else {
LOG("Projected as a large unsigned integer"); if (exports.OS.Shared.DEBUG) {
LOG("Projected as a large unsigned integer");
}
return projectLargeUInt; return projectLargeUInt;
} }
} }
LOG("Projected as a regular number"); if (exports.OS.Shared.DEBUG) {
LOG("Projected as a regular number");
}
return projectValue; return projectValue;
}; };
exports.OS.Shared.projectValue = projectValue; exports.OS.Shared.projectValue = projectValue;
@ -758,7 +770,9 @@
// thread // thread
let declareFFI = function declareFFI(lib, symbol, abi, let declareFFI = function declareFFI(lib, symbol, abi,
returnType /*, argTypes ...*/) { returnType /*, argTypes ...*/) {
LOG("Attempting to declare FFI ", symbol); if (exports.OS.Shared.DEBUG) {
LOG("Attempting to declare FFI ", symbol);
}
// We guard agressively, to avoid any late surprise // We guard agressively, to avoid any late surprise
if (typeof symbol != "string") { if (typeof symbol != "string") {
throw new TypeError("declareFFI expects as first argument a string"); throw new TypeError("declareFFI expects as first argument a string");
@ -796,12 +810,16 @@
if (exports.OS.Shared.DEBUG) { if (exports.OS.Shared.DEBUG) {
result.fun = fun; // Also return the raw FFI function. result.fun = fun; // Also return the raw FFI function.
} }
LOG("Function", symbol, "declared"); if (exports.OS.Shared.DEBUG) {
LOG("Function", symbol, "declared");
}
return result; return result;
} catch (x) { } catch (x) {
// Note: Not being able to declare a function is normal. // Note: Not being able to declare a function is normal.
// Some functions are OS (or OS version)-specific. // Some functions are OS (or OS version)-specific.
LOG("Could not declare function " + symbol, x); if (exports.OS.Shared.DEBUG) {
LOG("Could not declare function " + symbol, x);
}
return null; return null;
} }
}; };

View File

@ -50,7 +50,9 @@ if (typeof Components != "undefined") {
libc = ctypes.open(libc_candidates[i]); libc = ctypes.open(libc_candidates[i]);
break; break;
} catch (x) { } catch (x) {
LOG("Could not open libc "+libc_candidates[i]); if (exports.OS.Shared.DEBUG) {
LOG("Could not open libc "+libc_candidates[i]);
}
} }
} }
if (!libc) { if (!libc) {

View File

@ -112,7 +112,9 @@ if (typeof Components != "undefined") {
stack.push(v); stack.push(v);
} }
}); });
exports.OS.Shared.LOG("normalize", "stack", stack.toSource()); if (exports.OS.Shared.DEBUG) {
exports.OS.Shared.LOG("normalize", "stack", stack.toSource());
}
let string = stack.join("/"); let string = stack.join("/");
return absolute ? "/" + string : string; return absolute ? "/" + string : string;
}, },