[webkit-dev] JSObjectMakeFunction question

Jack Wootton jackwootton at gmail.com
Mon Jun 1 08:29:51 PDT 2009


It seems some casting is required for this though?


JSValueRef JSObjectCallAsFunction(
    JSContextRef ctx,
    JSObjectRef object,
    JSObjectRef thisObject,
    size_t argumentCount,
    const JSValueRef arguments[],
    JSValueRef *exception);


The above function accepts a JSObjectRef object.


However

JSValueRef JSObjectGetProperty(
    JSContextRef ctx,
    JSObjectRef object,
    JSStringRef propertyName,
    JSValueRef *exception);

returns JSValueRef

Looking at the typedefs in APICast.h

typedef const struct OpaqueJSValue* JSValueRef;
typedef struct OpaqueJSValue* JSObjectRef;

If I didn't cast, then wouldn't I be attempting to pass a const value
into a function that accepts a non-const parameter?  It is however
reporting a compilation error because the types don't' match,


On Mon, Jun 1, 2009 at 2:53 PM, Kalle Vahlman <kalle.vahlman at gmail.com> wrote:
> 2009/6/1 Jack Wootton <jackwootton at gmail.com>:
>> Hi all,
>
> Hi!
>
>> I'm attempting to use the function JSObjectMakeFunction described here:
>>
>> http://gemma.apple.com/documentation/Carbon/Reference/WebKit_JavaScriptCore_Ref/JSObjectRef/index.html
>>
>> I would like to call a JavaScript function from C.  I assume the
>> following is required:
>>
>> 1. Create a function using JSObjectMakeFunction.
>> 2. Add it as a property of the Window JSObjectRef.
>> 3. Call it using JSObjectCallAsFunction.
>
> JSObjectMakeFunction creates a JavaScript function *from* C.
>
> To just call a JS function (not create one), all you need to do is get
> the function object (most likely JSObjectGetProperty() on the global
> object) and then call it with JSObjectCallAsFunction().
>
> --
> Kalle Vahlman, zuh at iki.fi
> Powered by http://movial.com
> Interesting stuff at http://sandbox.movial.com
> See also http://syslog.movial.fi
>



-- 
Regards
Jack


More information about the webkit-dev mailing list