mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
797c29b92e
--HG-- rename : browser/devtools/commandline/Commands.jsm => browser/devtools/commandline/GcliCommands.jsm rename : browser/devtools/commandline/CmdCookie.jsm => browser/devtools/commandline/GcliCookieCommands.jsm rename : browser/devtools/tilt/CmdTilt.jsm => browser/devtools/commandline/GcliTiltCommands.jsm rename : browser/devtools/commandline/commandline.css => browser/devtools/commandline/gcli.css rename : browser/devtools/commandline/commandlineoutput.xhtml => browser/devtools/commandline/gclioutput.xhtml rename : browser/devtools/commandline/commandlinetooltip.xhtml => browser/devtools/commandline/gclitooltip.xhtml rename : browser/devtools/commandline/test/browser_cmd_addon.js => browser/devtools/commandline/test/browser_gcli_addon.js rename : browser/devtools/commandline/test/browser_dbg_cmd_break.html => browser/devtools/commandline/test/browser_gcli_break.html rename : browser/devtools/commandline/test/browser_dbg_cmd_break.js => browser/devtools/commandline/test/browser_gcli_break.js rename : browser/devtools/commandline/test/browser_cmd_calllog.js => browser/devtools/commandline/test/browser_gcli_calllog.js rename : browser/devtools/commandline/test/browser_cmd_commands.js => browser/devtools/commandline/test/browser_gcli_commands.js rename : browser/devtools/commandline/test/browser_cmd_cookie.js => browser/devtools/commandline/test/browser_gcli_cookie.js rename : browser/devtools/commandline/test/browser_dbg_cmd.js => browser/devtools/commandline/test/browser_gcli_dbg.js rename : browser/devtools/styleeditor/test/browser_styleeditor_cmd_edit.js => browser/devtools/commandline/test/browser_gcli_edit.js rename : browser/devtools/commandline/test/browser_cmd_pagemod_export.html => browser/devtools/commandline/test/browser_gcli_inspect.html rename : browser/devtools/highlighter/test/browser_inspector_cmd_inspect.js => browser/devtools/commandline/test/browser_gcli_inspect.js rename : browser/devtools/commandline/test/browser_cmd_integrate.js => browser/devtools/commandline/test/browser_gcli_integrate.js rename : browser/devtools/commandline/test/browser_cmd_jsb.js => browser/devtools/commandline/test/browser_gcli_jsb.js rename : browser/devtools/commandline/test/browser_cmd_pagemod_export.js => browser/devtools/commandline/test/browser_gcli_pagemod_export.js rename : browser/devtools/commandline/test/browser_cmd_pref.js => browser/devtools/commandline/test/browser_gcli_pref.js rename : browser/devtools/responsivedesign/test/browser_responsive_cmd.js => browser/devtools/commandline/test/browser_gcli_responsivemode.js rename : browser/devtools/commandline/test/browser_cmd_restart.js => browser/devtools/commandline/test/browser_gcli_restart.js rename : browser/devtools/commandline/test/browser_cmd_settings.js => browser/devtools/commandline/test/browser_gcli_settings.js rename : browser/devtools/styleeditor/test/browser_styleeditor_cmd_edit.html => browser/devtools/commandline/test/resources.html rename : browser/devtools/commandline/test/browser_dbg_cmd.html => browser/devtools/commandline/test/resources_dbg.html rename : browser/devtools/styleeditor/test/resources_inpage.jsi => browser/devtools/commandline/test/resources_inpage.js rename : browser/devtools/styleeditor/test/resources_inpage1.css => browser/devtools/commandline/test/resources_inpage1.css rename : browser/devtools/styleeditor/test/resources_inpage2.css => browser/devtools/commandline/test/resources_inpage2.css rename : browser/devtools/commandline/test/browser_cmd_jsb_script.jsi => browser/devtools/commandline/test/resources_jsb_script.js rename : browser/themes/gnomestripe/devtools/commandline.css => browser/themes/gnomestripe/devtools/gcli.css rename : browser/themes/pinstripe/devtools/commandline.css => browser/themes/pinstripe/devtools/gcli.css rename : browser/themes/winstripe/devtools/commandline.css => browser/themes/winstripe/devtools/gcli.css
158 lines
3.4 KiB
JavaScript
158 lines
3.4 KiB
JavaScript
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
/**
|
|
* Memory leak hunter. Walks a tree of objects looking for DOM nodes.
|
|
* Usage:
|
|
* leakHunt({
|
|
* thing: thing,
|
|
* otherthing: otherthing
|
|
* });
|
|
*/
|
|
|
|
var noRecurse = [
|
|
/^string$/, /^number$/, /^boolean$/, /^null/, /^undefined/,
|
|
/^Window$/, /^Document$/,
|
|
/^XULDocument$/, /^XULElement$/,
|
|
/^DOMWindow$/, /^HTMLDocument$/, /^HTML.*Element$/
|
|
];
|
|
|
|
var hide = [ /^string$/, /^number$/, /^boolean$/, /^null/, /^undefined/ ];
|
|
|
|
function leakHunt(root, path, seen) {
|
|
path = path || [];
|
|
seen = seen || [];
|
|
|
|
try {
|
|
var output = leakHuntInner(root, path, seen);
|
|
output.forEach(function(line) {
|
|
dump(line + '\n');
|
|
});
|
|
}
|
|
catch (ex) {
|
|
dump(ex + '\n');
|
|
}
|
|
}
|
|
|
|
function leakHuntInner(root, path, seen) {
|
|
var prefix = new Array(path.length).join(' ');
|
|
|
|
var reply = [];
|
|
function log(msg) {
|
|
reply.push(msg);
|
|
}
|
|
|
|
var direct
|
|
try {
|
|
direct = Object.keys(root);
|
|
}
|
|
catch (ex) {
|
|
log(prefix + ' Error enumerating: ' + ex);
|
|
return reply;
|
|
}
|
|
|
|
for (var prop in root) {
|
|
var newPath = path.slice();
|
|
newPath.push(prop);
|
|
prefix = new Array(newPath.length).join(' ');
|
|
|
|
var data;
|
|
try {
|
|
data = root[prop];
|
|
}
|
|
catch (ex) {
|
|
log(prefix + prop + ' Error reading: ' + ex);
|
|
continue;
|
|
}
|
|
|
|
var recurse = true;
|
|
var message = getType(data);
|
|
|
|
if (matchesAnyPattern(message, hide)) {
|
|
continue;
|
|
}
|
|
|
|
if (message === 'function' && direct.indexOf(prop) == -1) {
|
|
continue;
|
|
}
|
|
|
|
if (message === 'string') {
|
|
var extra = data.length > 10 ? data.substring(0, 9) + '_' : data;
|
|
message += ' "' + extra.replace(/\n/g, "|") + '"';
|
|
recurse = false;
|
|
}
|
|
else if (matchesAnyPattern(message, noRecurse)) {
|
|
message += ' (no recurse)'
|
|
recurse = false;
|
|
}
|
|
else if (seen.indexOf(data) !== -1) {
|
|
message += ' (already seen)';
|
|
recurse = false;
|
|
}
|
|
|
|
if (recurse) {
|
|
seen.push(data);
|
|
var lines = leakHuntInner(data, newPath, seen);
|
|
if (lines.length == 0) {
|
|
if (message !== 'function') {
|
|
log(prefix + prop + ' = ' + message + ' { }');
|
|
}
|
|
}
|
|
else {
|
|
log(prefix + prop + ' = ' + message + ' {');
|
|
lines.forEach(function(line) {
|
|
reply.push(line);
|
|
});
|
|
log(prefix + '}');
|
|
}
|
|
}
|
|
else {
|
|
log(prefix + prop + ' = ' + message);
|
|
}
|
|
}
|
|
|
|
return reply;
|
|
}
|
|
|
|
function matchesAnyPattern(str, patterns) {
|
|
var match = false;
|
|
patterns.forEach(function(pattern) {
|
|
if (str.match(pattern)) {
|
|
match = true;
|
|
}
|
|
});
|
|
return match;
|
|
}
|
|
|
|
function getType(data) {
|
|
if (data === null) {
|
|
return 'null';
|
|
}
|
|
if (data === undefined) {
|
|
return 'undefined';
|
|
}
|
|
|
|
var type = typeof data;
|
|
if (type === 'object' || type === 'Object') {
|
|
type = getCtorName(data);
|
|
}
|
|
|
|
return type;
|
|
}
|
|
|
|
function getCtorName(aObj) {
|
|
try {
|
|
if (aObj.constructor && aObj.constructor.name) {
|
|
return aObj.constructor.name;
|
|
}
|
|
}
|
|
catch (ex) {
|
|
return 'UnknownObject';
|
|
}
|
|
|
|
// If that fails, use Objects toString which sometimes gives something
|
|
// better than 'Object', and at least defaults to Object if nothing better
|
|
return Object.prototype.toString.call(aObj).slice(8, -1);
|
|
}
|