Just discovered this: JSObjectCallAsFunction
: https://lists.webkit.org/pipermail/webkit-help/2011-January/001849.html
But I have bigger problems here now: can't do any JS/webkit/javascriptcore call from the bkg thread and I'm not sure how I could even send a message from the bkg thread to the main thread. Any ideas on that one?
JavaScriptCore is supposed to be thread-safe. So you should be able to call into it from any thread.
So, i can get a single JSValueMakeNumber to succeed, put it in an array and then try to create an object from that array with JSObjectMakeArray but it seg faults on the make array call
If it is doing that the first thing I’d do is uncomment the memory diagnostic sanitize address thing in the Makefile: https://github.com/mfikes/planck/blob/master/planck-c/Makefile#L7
Ok, trying that now
You may need to make clean and then make
yup, did that.
doh!
oh, found one stupid mistake. but after fixing that the previous (and serious one) still remains
looks like JSObjectMakeArray
causes a "SEGV on unknown address 0x0000000000e8"
Sounds like fun. 😞
the ctx passed into it is exactly the ctx that was passed to us in the main thread
perhaps either a) that ctx isn't as permanent as we thought or b) ctx's can't be shared between threads like that .
Well, if it helps narrow it down, I’ve never had it SEGV on me by calling from different threads.
i'm leaning more towards the former
Good thing is that it is pretty well documented by Apple
but then again it's the same ctx that was just used for creating a number
well, early day tomorrow for me. I'll look at it again tomorrow afternoon/evening.
Well, so the API itself, JavaScriptCore, is a thread safe API.
You can call into various JSContext and evaluate code and create values and that sort of thing on different threads and everything will work fine.
Good video on it, that’s from the transcript: http://asciiwwdc.com/2013/sessions/615
Yeah, it is late here as well (East Coast US)
@johanatan: a bit late to the party, but I’ve done this
basically, when I want to listen to a socket, I pass a callback, in the form of a String: https://github.com/slipset/planck/blob/sockets/planck/PLKClojureScriptEngine.m#L713-L732
and execute this callback in an iife like so:
https://github.com/slipset/planck/blob/sockets/planck/PLKSocketListener.m#L11-L33
@slipset: cool but are you doing that from a bkg thread?
Executing the callback isn't the problem right now-- it's the segfault lol
@mfikes: that's weird. I can't see anything else it could be. My JSContext looks legit and I was just previously able to create a JSNumber on it
And taking that number, packing it in an array and calling JSObjectMakeArray causes the segfault
Perhaps you can take a look if I push to my fork?
@johanatan: yeah, I may have some free time tonight to take a look
K, I'll do that in ~3-4 hours or so
@johanatan: no, it's running in the same thread, but I needed a way to get noticed when someone wrote on the socket, hence the callback.
@mfikes: pushed here: https://github.com/johanatan/planck/commit/4120be437b233c3f2b7a6a22893fa35b5f8b273e