lucifer63
lucifer63

Reputation: 666

How to find a JS function declaration in browser sources?

How do I find a JS function declaration in the sources of FF ?

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: 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.

Upvotes: 1

Views: 169

Answers (1)

deamentiaemundi
deamentiaemundi

Reputation: 5525

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,
  };
});

The console.*functions get defined in ./dom/base/Console.cpp

Upvotes: 2

Related Questions