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).
-Adam
_______________________________________________
webkit-help mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-help