[webkit-help] How do i retain a stack in JS callback function

Adam Roben aroben at apple.com
Wed Jul 27 05:01:16 PDT 2011

On Jul 27, 2011, at 3:19 AM, Sumedh wrote:

> Now instead of serving the request, i want to send a message to windows message loop (I am working on windows). Here, I need to save the stack of the argumets[] which is of type JSValueRef, const.
> Approach I:
> I tried to protect all elements from arguments array, by looping through, didn't work.
>             //Protect the each memeber of the JSValueRef array, Not working 
>             for(i = 0; i < argumentCount; i++){
>                 JSValueProtect(ctx, arguments[i]);
>             }
>             jsObject->arguments = (JSValueRef *) arguments;*/
> Approach II:
> I simply created a deep copy of the array using memcpy, which worked.
>             //Alternate Approach
>             //Copy the entire array here            
>             jsObject->arguments = (JSValueRef *)malloc(sizeof(JSValueRef)*argumentCount);
>             memcpy(jsObject->arguments, arguments, sizeof(JSValueRef)*argumentCount);
> NOTE: jsObject is object of my stack struct.
> Is it correct?  Is there any other approach to do this?

I think you need a combination of both approaches. You need to copy the array because there's no guarantee that the array passed to you will still be valid later. And you need to call JSValueProtect on each JSValueRef because otherwise they might be garbage-collected (or you need to store them somewhere on the stack, which JavaScriptCore's garbage collector scans automatically).


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-help/attachments/20110727/a8706737/attachment.html>

More information about the webkit-help mailing list