JS GetFunctionDisplayId

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_GetFunctionDisplayId
  • Revision title: JS GetFunctionDisplayId
  • Revision id: 443595
  • Created:
  • Creator: kscarfone
  • Is current revision? Yes
  • Comment

Revision Content

 

Get a function's display name as a JSString.

Syntax

JSString * JS_GetFunctionDisplayId(JSFunction *fun);
Name Type Description
fun JSFunction * A JavaScript function.

Description

JS_GetFunctionDisplayId returns the name of a function, fun, as a JSString. This name is the same as returned by JS_GetFunctionId if the function explicitly has a name listed in the source, or if not it is an intelligently guessed name for the function based on its context in the source. If no smart name could be guessed for the function, then NULL is returned. The returned string is guaranteed to live as long as fun, so the application often does not need to root the string.

Some examples of named functions are:

function f() {}                     // f
var x = function() {};              // x

var a = { b: function() {} };       // a.b
a.c = function() {};                // a.c

a.d = (function() {                 // a.d<  -- the '<' loosely means "contributor to"
  return function() {};             // a.d
})();

var Foo = function() {              // Foo
  var bar = function() {};          // Foo/bar
};

setTimeout(function() {}, 100);     // no name, JS_GetFunctionDisplayId returns NULL

{{ LXRSearch("ident", "i", "JS_GetFunctionDisplayId") }}

Revision Source

<p> </p>
<p>Get a function's display name as a <code style="font-size: 14px;"><a href="/en/SpiderMonkey/JSAPI_Reference/JSString" title="en/JSString">JSString</a></code>.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="eval" style="font-size: 14px;"><a href="/en/SpiderMonkey/JSAPI_Reference/JSString" title="en/JSString">JSString</a> * <strong>JS_GetFunctionDisplayId</strong>(<a href="/en/JSFunction" title="en/JSFunction">JSFunction</a> *fun);
</pre>
<table class="fullwidth-table" style="font-size: 14px; width: 1145px;">
  <tbody>
    <tr>
      <th>Name</th>
      <th>Type</th>
      <th>Description</th>
    </tr>
    <tr>
      <td><code style="font-size: 14px;">fun</code></td>
      <td><code style="font-size: 14px;"><a href="/en/JSFunction" title="en/JSFunction">JSFunction</a> *</code></td>
      <td>A JavaScript function.</td>
    </tr>
  </tbody>
</table>
<h2 id="Description" name="Description">Description</h2>
<p><code style="font-size: 14px;">JS_GetFunctionDisplayId</code> returns the name of a function, <code style="font-size: 14px;">fun</code>, as a <code style="font-size: 14px;"><a href="/en/SpiderMonkey/JSAPI_Reference/JSString" title="en/JSString">JSString</a></code>. This name is the same as returned by <a href="/en-US/docs/SpiderMonkey/JSAPI_Reference/JS_GetFunctionId" title="/en-US/docs/SpiderMonkey/JSAPI_Reference/JS_GetFunctionId"><code>JS_GetFunctionId</code></a> if the function explicitly has a name listed in the source, or if not it is an intelligently guessed name for the function based on its context in the source. If no smart name could be guessed for the function, then <code style="font-size: 14px;">NULL</code> is returned. The returned string is guaranteed to live as long as <code style="font-size: 14px;">fun</code>, so the application often does not need to root the string.</p>
<p>Some examples of named functions are:</p>
<pre>function f() {}                     // f
var x = function() {};              // x

var a = { b: function() {} };       // a.b
a.c = function() {};                // a.c

a.d = (function() {                 // a.d&lt;  -- the '&lt;' loosely means "contributor to"
  return function() {};             // a.d
})();

var Foo = function() {              // Foo
  var bar = function() {};          // Foo/bar
};

setTimeout(function() {}, 100);     // no name, JS_GetFunctionDisplayId returns NULL</pre>
<p>{{ LXRSearch("ident", "i", "JS_GetFunctionDisplayId") }}</p>
Revert to this revision