如何在浏览器源代码中找到JS函数声明? [英] How to find a JS function declaration in browser sources?
问题描述
如何在FF的源代码中找到JS函数声明?
How do I find a JS function declaration in the sources of FF ?
首先,我想查找函数"copy"的声明.我打开控制台,键入并执行"copy.toSource()",输出显示它是本机代码.我查看了此问题页面,然后点击了链接,下载了源代码,并认为我只会搜索"copy"一词,但搜索结果非常庞大,大约有17,000条条目,我无法在此处找到"copy"声明)
First I wanted to find declaration of function "copy". I opened console, typed and executed 'copy.toSource()', the output said it is the native code. I looked this question page, followed link, downloaded sources and I thought I'll just search for word 'copy' but search results were colossal, there were about 17k entries, there's no way I can find 'copy' declaration here)
有什么想法如何在要搜索的目录中找到复制"声明?
Any ideas how to find 'copy' declaration, in which directory to search?
PS:还要看看所有其他功能,例如'console.log',也会很有趣.如果您知道如何找到它的声明,那就太棒了.
PS: it would be interesting to look at all other functions too, for example 'console.log'. If you know how to find it's declaration, it will be awesome.
推荐答案
copy
的来源(假设您的意思是复制到剪贴板")在./toolkit/devtools/webconsole/utils.js
中.它很小,所以在这里:
The source of copy
(assuming you mean "copy to clipboard") is in ./toolkit/devtools/webconsole/utils.js
. It is small, so here it is:
WebConsoleCommands._registerOriginal("copy", function JSTH_copy(aOwner, aValue)
{
let payload;
try {
if (aValue instanceof Ci.nsIDOMElement) {
payload = aValue.outerHTML;
} else if (typeof aValue == "string") {
payload = aValue;
} else {
payload = JSON.stringify(aValue, null, " ");
}
} catch (ex) {
payload = "/* " + ex + " */";
}
aOwner.helperResult = {
type: "copyValueToClipboard",
value: payload,
};
});
console.*
函数在./dom/base/Console.cpp
这篇关于如何在浏览器源代码中找到JS函数声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!