Output log more safely #1067

This commit is contained in:
Piro / YUKI Hiroshi 2016-02-15 23:45:58 +09:00
parent f5198c31aa
commit 1126c9f211
5 changed files with 72 additions and 12 deletions

View File

@ -302,7 +302,7 @@ var TreeStyleTabBookmarksService = inherit(TreeStyleTabConstants, {
let treeStructure = result.behavior & this.kGROUP_BOOKMARK_DONT_RESTORE_TREE_STRUCTURE ?
null :
this.getTreeStructureFromItems(aIDs) ;
log(' treeStructure => '+JSON.stringify(treeStructure));
log(' treeStructure => ', treeStructure);
if (treeStructure) {
let parentTabs = treeStructure.filter(function(aParent) {
return aParent < 0;
@ -340,7 +340,7 @@ var TreeStyleTabBookmarksService = inherit(TreeStyleTabConstants, {
title: aFolderTitle,
uri: uri
})
log(' updated treeStructure => '+JSON.stringify(treeStructure));
log(' updated treeStructure => ', treeStructure);
}
}
else if (!haveMultipleTrees) {
@ -428,7 +428,7 @@ PlacesUIUtils._openTabset = function(aItemsToOpen, aEvent, aWindow, ...aArgs) {
return this.__treestyletab__openTabset.apply(this, allArgs);
var result = BS.handleTabsOpenProcess(where, aEvent, w, ids, uris, aItemsToOpen, this.__treestyletab__folderName);
log(' result: '+JSON.stringify(result));
log(' result: ', result);
var tabs = TST.doAndGetNewTabs((function() {
this.__treestyletab__openTabset.apply(this, allArgs);

View File

@ -3436,7 +3436,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
var closeParentBehavior = this.getCloseParentBehaviorForTab(tab);
var backupAttributes = this._collectBackupAttributes(tab);
log('onTabClose: backupAttributes = '+JSON.stringify(backupAttributes));
log('onTabClose: backupAttributes = ', backupAttributes);
if (closeParentBehavior == this.kCLOSE_PARENT_BEHAVIOR_CLOSE_ALL_CHILDREN ||
this.isSubtreeCollapsed(tab))

View File

@ -97,7 +97,7 @@ FullscreenObserver.prototype = {
onSizeModeChange : function FullscreenObserver_onSizeModeChange()
{
log('onSizeModeChange: '+this.window.document.documentElement.getAttribute('sizemode'));
log('onSizeModeChange: ', this.window.document.documentElement.getAttribute('sizemode'));
this.updateToolboxPosition();
if (!this.window.gBrowser.treeStyleTab.notifyingRenderedEvent)
this.window.gBrowser.treeStyleTab.updateFloatingTabbar(TreeStyleTabConstants.kTABBAR_UPDATE_BY_WINDOW_RESIZE);

View File

@ -257,7 +257,7 @@ var TreeStyleTabUtils = {
if (!this.isDebugging(aModule))
return;
var logString = '[treestyletab:' + aModule+'] '+ aArgs.join(', ');
var logString = '[treestyletab:' + aModule+'] '+ aArgs.map(this.objectToLogString, this).join('');
Services.console.logStringMessage(logString);
dump(logString+'\n');
},
@ -266,6 +266,66 @@ var TreeStyleTabUtils = {
var stack = (new Error()).stack.replace(/^/gm, ' ');
return this.log.apply(this, [aModule].concat(aArgs).concat([stack]));
},
objectToLogString : function utils_objectToLogString(aObject)
{
if (!aObject)
return JSON.stringify(aObject);
if (/^(string|number|boolean)$/.test(typeof aObject))
return aObject;
return this.objectToString(aObject);
},
objectToString : function utils_objectToString(aObject)
{
try {
if (!aObject ||
/^(string|number|boolean)$/.test(typeof aObject))
return JSON.stringify(aObject);
if (Array.isArray(aObject))
return '['+aObject.map(this.objectToString, this).join(', ')+']';
var constructor = String(aObject.constructor).match(/^function ([^\(]+)/);
if (constructor) {
constructor = constructor[1];
switch (constructor)
{
case 'String':
case 'Number':
case 'Boolean':
return JSON.stringify(aObject);
case 'Object':
return '{' + Object.keys(aObject).map(function(aKey) {
return '"' + aKey + '":' + this.objectToString(aObject[aKey]);
}, this).join(', ') + '}';
default:
break;
}
if (/Element$/.test(constructor)) {
let id = '';
if (aObject.hasAttribute('id'))
id = '#' + aObject.getAttribute('id');
let classes = '';
if (aObject.className)
classes = '.' + aObject.className.replace(/\s+/g, '.');
return '<' + aObject.localName + id + classes + '>';
}
return '<object '+constructor+'>';
}
return String(aObject);
}
catch(e) {
return String(e);
}
},
/* string bundle */
get treeBundle () {

View File

@ -1385,7 +1385,7 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, {
if (!aTab)
return;
log('onBeforeOpenLinkWithTab '+[aTab, JSON.stringify(aParams), this.checkToOpenChildTab(aTab)]);
log('onBeforeOpenLinkWithTab: ', [aTab, aParams, this.checkToOpenChildTab(aTab)]);
if (!this.checkToOpenChildTab(aTab)) {
if (!aParams.fromChrome)
@ -1397,7 +1397,7 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, {
onBeforeOpenNewTabByThirdParty : function TSTWindow_onBeforeOpenNewTabByThirdParty(aOwner)
{
log('onBeforeOpenNewTabByThirdParty '+[aOwner, this.checkToOpenChildTab(aTab)]);
log('onBeforeOpenNewTabByThirdParty: ', [aOwner, this.checkToOpenChildTab(aTab)]);
if (!this.checkToOpenChildTab(aOwner)) {
this.handleNewTabFromCurrent(aOwner);
@ -1413,7 +1413,7 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, {
log('onBeforeBrowserAccessOpenURI: opener is DOMWindow');
opener = aOpener;
hasOwnerTab = this.getTabFromFrame(opener.top);
log(' opener =>'+[opener,hasOwnerTab]);
log(' opener =>', [opener, hasOwnerTab]);
}
else if (Ci.nsIOpenURIInFrameParams &&
aOpener instanceof Ci.nsIOpenURIInFrameParams) {
@ -1432,7 +1432,7 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, {
break;
}
}
log(' opener =>'+[opener,hasOwnerTab]);
log(' opener =>', [opener, hasOwnerTab]);
}
}
if (aOpener &&
@ -1462,7 +1462,7 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, {
{
var where = String(this.window.whereToOpenLink(aEvent, false, true));
log('onBeforeViewMedia '+[aEvent, aOwner, where]);
log('onBeforeViewMedia: ', [aEvent, aOwner, where]);
if (where.indexOf('tab') == 0)
this.handleNewTabFromCurrent(aOwner);
@ -1472,7 +1472,7 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, {
onBeforeBrowserSearch : function TSTWindow_onBeforeBrowserSearch(aTerm, aForceNewTab)
{
log('onBeforeBrowserSearch '+[aTerm, aForceNewTab, this.shouldOpenSearchResultAsChild(aTerm)]);
log('onBeforeBrowserSearch: ', [aTerm, aForceNewTab, this.shouldOpenSearchResultAsChild(aTerm)]);
if ((arguments.length == 1 || aForceNewTab) &&
this.shouldOpenSearchResultAsChild(aTerm))