[webkit-dev] [JavaScriptCore] When to JSValueProtect?

Alexei Sholik alcosholik at gmail.com
Sat Dec 7 12:15:31 PST 2013

> The garbage collector scans the C stack.

Hm, let me make sure I understand this correctly.

Say, I created a context with JSGlobalContextCreate() and stored it in an
instance variable. Then I ran some JS code which stored a JS function in
some native C++ object (so the pointer to the JS function is stored
somewhere on the heap).

Then my application continues to run and at some point needs to call the
stored JS function. At this point there are no JSC API functions on the

void MyClass::callJsFunction(JSObjectRef arg0) {
   JSObjectRef arg1 = JSObjectMake(ctx_, ...);
   JSObjectRef arg2 = JSObjectMake(ctx_, ...);


   // ...

Will JSC scan the current stack which arg1 and arg2 are on? Will it scan
the stack even further back? Say

void MyClass::someOtherFunc() {
  JSObjectRef arg = JSObjectMake(ctx_, ...);  // does the GC sees this
"arg" pointer on the stack?

I'm asking because I've never previously dealt with a library that scans
the host application's stack. So it sounds pretty incredible to me.


On Sat, Dec 7, 2013 at 9:37 PM, Geoffrey Garen <ggaren at apple.com> wrote:

> > At this point, the code is not inside the JS stack, so is it possible
> for an object to be collected between the calls to JSObjectMake and
> JSObjectCallAsFunction?
> The garbage collector scans the C stack.
> Geoff

Best regards
Alexei Sholik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-dev/attachments/20131207/90859138/attachment.html>

More information about the webkit-dev mailing list