[webkit-dev] call function from c++ to js using JSObject
Filip Pizlo
fpizlo at apple.com
Mon Feb 3 09:17:42 PST 2014
On Feb 3, 2014, at 9:04 AM, Honey <honeysaini88 at gmail.com> wrote:
> I have exposed a function setObject() through webkit idl. Suppose i have a javascript class like
>
> function Player () { var speed = 5; var x = 50; var y = 50;}
I presume you meant:
function Player() { this.speed = 5; this.x = 50; this.y = 50; }
Since your original code means that the variables speed, x, and y are local and therefore dead at the point where you call setObject().
> var p = new Player();
> setObject(p);
>
> In webkit, i am getting the p as JSValue object. I want to retrieve the value of x through this JSValue object. how can i do that?
JSValue has this API:
JSValue::get(ExecState*, PropertyName)
So, jf you have "JSValue p" then you can do something like:
JSValue x = p.get(exec, Identifier(exec, "x"))
Where "exec" is an ExecState* or CallFrame* that you have lying around. If you're in the C++ code for your setObject(), then presumably someone is passing you one of those things, somehow.
-Filip
> any help would be appreciated..
>
>
> Sent from my iPad
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-dev/attachments/20140203/cf87dfd4/attachment.html>
More information about the webkit-dev
mailing list