title: JavaScriptCore console.log
body: <p>I've put together a very simple program that uses JavaScriptCore to evaluate JS:</p>
  
  <pre><code>#import &lt;CoreFoundation/CoreFoundation.h&gt;
  #import &lt;JavaScriptCore/JavaScriptCore.h&gt;
  
  int main(int argc, const char * argv[])
  {
      JSGlobalContextRef ctx = JSGlobalContextCreate(NULL);
  
      FILE *f = fopen(argv[1],"r");
      char * buffer = malloc(10000000);
      fread(buffer,1,10000000,f);
  
      CFStringRef strs = CFStringCreateWithCString(NULL, buffer, kCFStringEncodingASCII);
  
      JSStringRef jsstr = JSStringCreateWithCFString(strs);
      JSValueRef result = JSEvaluateScript(ctx, jsstr, NULL, NULL, 0, NULL);
  
      double res  = JSValueToNumber(ctx, result, NULL);
      JSGlobalContextRelease(ctx);
  
      printf("%lf\n", res);
      return 0;
  }
  </code></pre>
  
  <p>The idea here is that the last value is expected to be a <code>Number</code>, and that value is printed.  This works for valid javascript code, such as</p>
  
  <pre><code>var square = function(x) { return x*x; }; square(4)
  </code></pre>
  
  <p>However, if the code tries to perform a <code>console.log</code>, the program segfaults.  Is there a log function available in JSC or do I have to roll my own?</p>