[webkit-dev] JavaScriptCore: Accessing things created in C from script

Cameron McCormack cam at mcc.id.au
Thu Dec 11 03:00:16 PST 2008


Hi Thomas.

Thomas Gutteridge:
> For example, I'm trying to use JSObjectMakeFunctionWithCallback to
> create a JavaScript function with a native implementation. Crucially,
> I'd like to then invoke this function from a script. However, the
> "name" parameter is apparently only "used when converting the function
> to string". The name I give is undefined if I use it in a script.

You’ll need to store that function in a property on the global object.
(When you define a function using ‘function f() …’ at the top level,
this creates a property on the global object named “f”.  When your code
calls functions, it looks up the function name as a property on objects
in the scope chain.  The scope chain starts off just having the global
object in it, but some other things can add objects on to the chain,
like ‘with’.)

-- 
Cameron McCormack ≝ http://mcc.id.au/


More information about the webkit-dev mailing list