<div dir="ltr">Thanks Saam,<div><br></div><div>I'll try and give as much information as I can. So basically I built a C++ API on top of the JSC C API surface that mimics the Objective-C API available with JavaScriptCore. So where objective-c has functionality to say [JSValue valueWithValueRef:valueRef] my API has similar C++ functionality</div><div>to say JSValue::valueWithJSValueRef(valueRef). You can imagine the most of the objective-C API then having C++ parallel in my API.</div><div><br></div><div>In using this API I have a JSContextRef manager that posts all access to context to a background thread. </div><div><br></div><div>Where the trouble is happening is on a lamda that is running on this background thread above I am basically making the C++ equivalent call to [jsValue invokeMethod:"method" withArguments:"arguments"] (Before doing this I've evaluated a javascript snippet on the context that has placed the required methods and functions in scope, I've also placed a setTimeout method in scope for the JavaScript code).</div><div>The JavaScript method that is called takes in a set of C++ callback functions. These functions are called back at different intervals during the JavaScript processing and are always called back on the same thread as the script was invoked on (With the exception of setTimeout which posts the timeout callback to a different thread).</div><div><br></div><div>In fact the script calls callback method A, then method B, and only when it attempts to call method A again does it hit the issue. In order to allow for JS to call my functions back I have a custom class type that sets a custom function call handler to call my callback functions (it wraps my callback functions in a JSObjectRef and stores the original callback function data in the Object references private data). The issue is that my function callback handler basically wraps the provided JSValueRef arguments in my C++ API JSValue (which again is equivalent to the Objective-C API for JSValue). When it does this wrapping it calls JSValueProtect on the JSValueRef arguments and eventually this is where the EXC_BAD_ACCESS gets hit in one of these calls to JSValueProtect which is calling <i style="color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif;font-size:15px"><code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);white-space:pre-wrap">JSLockHold<wbr>er::JSLockHolder(JSC::<wbr>ExecState*).</code></i> </div><div><br></div><div>Like I mentioned this happens the second time it tries to call callback method A, even though it was successful calling this callback first time and calling callback method B. </div><div><br></div><div>All of these calls and functionality are happening on the same thread, none of the off thread calls had been made yet at this point. Thats as best as I can think of right now. </div><div><br></div><div>If needed I could try and create a simple reproducible sample, unfortunately it's only now with all the peices and complex setup I have going that I'm starting to hit this issue, as most of the basic use cases I was working with before never ran into this.</div><div><br></div><div>Thanks</div><div>Avi Brenner</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 28, 2016 at 4:33 PM, Saam barati <span dir="ltr"><<a href="mailto:sbarati@apple.com" target="_blank">sbarati@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><span class=""><blockquote type="cite"><div>On Dec 28, 2016, at 10:13 AM, artcodex . <<a href="mailto:avi.brenner@gmail.com" target="_blank">avi.brenner@gmail.com</a>> wrote:</div><br class="m_2747928941680137556Apple-interchange-newline"><div><div dir="ltr">Hi,<div><br></div><div>I'm not sure if this is the right forum to ask this question, but I'm currently running into following issue</div><div>with using the JavaScriptCore API:</div></div></div></blockquote><div><br></div></span>This is an OK place for this conversation. IRC also works on #webkit. I’m saamyjoon on there.</div><div><span class=""><br><blockquote type="cite"><div><div dir="ltr"><div><br></div><div><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif"><i>I'm building an application that uses <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);white-space:pre-wrap">JavaScriptCore</code> on Android. So I'm building my own API which has generally worked well, but now that it's running on complex back and forward code that has callbacks between JS code and C++ I'm running into an issue where I'm hitting a <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);white-space:pre-wrap">EXC_BAD_ACCESS</code> in <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);white-space:pre-wrap">JSLockHold<wbr>er::JSLockHolder(JSC::<wbr>ExecState*)</code>.</i></p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif"><i>It seems fairly inconsistent in that when I put breakpoints randomly in my code while debugging sometimes I hit this, sometimes I don't. When running the app straight though I always seem to hit the issue at the same point.</i></p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif"><i>For me right now this is hitting during a call to <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);white-space:pre-wrap">JSValueProtect</code>, but if I were to remove that call it would just hit at the next call that uses <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);white-space:pre-wrap">JSLockHolder</code>.</i></p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif"><i>I have a test demo that hits this on a Mac build that uses the JavaScriptCore.framework as well (so it doesn't appear to be any issues with my Android jsc library build).</i></p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif">Thanks in advance.<i> </i><span style="font-family:arial,"helvetica neue",helvetica,sans-serif">Let me know if any more info could be provided for clarity.</span></p><div><br></div></div></div></div></blockquote></span>For anybody to be able to help you here, we need <i>much</i> more information on how you’re using JSC and what the code that’s hitting this problem is doing.</div><div><br></div><div>- Saam</div><div><br><blockquote type="cite"><div><div dir="ltr"><div><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif"><span style="font-family:arial,"helvetica neue",helvetica,sans-serif">Avi Brenner</span></p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif"><i><br></i></p></div></div>
______________________________<wbr>_________________<br>jsc-dev mailing list<br><a href="mailto:jsc-dev@lists.webkit.org" target="_blank">jsc-dev@lists.webkit.org</a><br><a href="https://lists.webkit.org/mailman/listinfo/jsc-dev" target="_blank">https://lists.webkit.org/<wbr>mailman/listinfo/jsc-dev</a><br></div></blockquote></div><br></div></blockquote></div><br></div>