title: Calling callback function in SpiderMonkey JS Engine
body: <p>I'm using SpiderMonkey JS Engine 1.8.5 API.</p>
  
  <p>JS code looks like:</p>
  
  <pre><code>visitChildren(function() {
                               log("something");
                           });
  </code></pre>
  
  <p>VisitChildren is something like:</p>
  
  <pre><code>JSBool visit_children(JSContext* cx, uintN argc, jsval *vp) {
  
      JSFunction* function;
      if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "f", &amp;function))
          return JS_FALSE;
  
      jsval retVal;
      JS_CallFunction(cx, JS_GetGlobalObject(cx), function, 0, NULL, &amp;retVal);
  
      return JS_TRUE;
  }
  </code></pre>
  
  <p>I have intentionally simplified code to make question more clear. Definitely I'm doing something absolutely wrong, could someone suggest me why call to *JS_CallFunction* crashes application ?</p>
  
  <p><strong>UPD1:</strong></p>
  
  <p>Found some vague info here <a href="https://developer.mozilla.org/en-US/docs/SpiderMonkey/JSAPI_Reference/JSFunction" rel="nofollow">https://developer.mozilla.org/en-US/docs/SpiderMonkey/JSAPI_Reference/JSFunction</a> but still crashes:</p>
  
  <pre><code>jsval functionVal = OBJECT_TO_JSVAL(JS_GetFunctionObject(function));
  JS_CallFunctionValue(cx, JS_GetGlobalObject(cx), functionVal, 0, NULL, &amp;retVal);
  </code></pre>