[webkit-dev] JSClassCreate & JSObjectSetProperty question

Darin Adler darin at apple.com
Wed May 27 13:23:53 PDT 2009


On May 27, 2009, at 8:34 AM, Jack Wootton wrote:

> I'm using JSObjectSetProperty.
>
>     [...]
>
> I successfully have the execution context to use, the window
> JSObjectRef, property name, attributes and use NULL for exception (all
> these parameters make sense to me).  However I'm unsure about the
> purpose of the parameter 'JSValueRef value'.

This function is used to set the property of a particular JavaScript  
object. To do this in JavaScript the syntax is:

     object.propertyName = value;

The value is the new value to be stored in the JavaScript property.

> (note I was
> unable to use kJSClassDefinitionEmpty because of compile errors about
> a missing symbol '_kJSClassDefinitionEmpty')

What platform? Did you file a bug about this?

> JSClassDefinition globalObjectClassDefinition = { 0, 0, 0, 0, 0, 0, 0,
> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
> globalObjectClassDefinition.version = 1;
> char myword[] = {'f', 'o', 'o', '\0' };
> globalObjectClassDefinition.className = myword;
>
> Question 1.  What is the class name?  The documentation describes it
> as "A null-terminated UTF8 string containing the class's name.".
> However it does not mention what it's for, or what it represents
> within the program.  Is anyone able to elaborate please?  Does it
> represent a C class I've al;ready created, that I must describe by
> using the JSClassDefinition?

The class name is used for debugging purposes and for the default  
behavior of the toString function. If your name is "foo" then toString  
will yield "[object foo]".

> Question 2. I am unclear as to the purpose of the JSClassDefinition.
> Does it represent a C class or a JavaScript class?  Are the callbacks
> to C / C++ functions?

JSClassDefinition can be used to make a JSClassRef. A JSClassRef can  
be used to construct JavaScript objects with behavior that is  
implemented with C functions.

     -- Darin



More information about the webkit-dev mailing list