title: Getting return value from Javascript in WebKit / JavaScriptCore
body: <p>I am using the JavaScriptCore API in order to obtain a global context to Javascript. I would like to be able to manipulate the value I get back from Javascript in C. Here is the code sample I have that is relevant:</p>
  
  <pre><code>JSGlobalContextRef jsContext = webkit_web_frame_get_global_context(webkit_web_view_get_main_frame(webView));
  
  JSStringRef script = JSStringCreateWithUTF8CString("ReturnOne()");
  
  JSValueRef val = JSEvaluateScript(jsContext, script, NULL, NULL, 0, NULL);
  
  return JSValueToNumber(jsContext, val, NULL);
  </code></pre>
  
  <p>ReturnOne() is a JavaScript function that looks like this:</p>
  
  <pre><code>function ReturnOne() {
    return 1;
  }
  </code></pre>
  
  <p>When I put an alert in the function, it displays, so I know the function is being called correctly. I am trying to simply print out the number 1 but I get a large negative value instead. Am I not interpreting JSValueToNumber correctly?</p>
  
  <p>Any advice would be appreciated. Thanks.</p>
  
  <p>EDIT: I have done some digging around and found this gem - <a href="https://lists.webkit.org/pipermail/webkit-help/2011-January/001849.html" rel="nofollow">https://lists.webkit.org/pipermail/webkit-help/2011-January/001849.html</a></p>
  
  <p>Unfortunately, I get the same result implementing my C code in this fashion. My function in Javascript is returning a primitive and I would like to convert that Javascript primitive into the value I'm expecting (in this case, 1).</p>
  
  <p>I would also be okay with an alternative in which an object is returned from Javascript, so long as I can get the numeric value I expect.</p>