[webkit-dev] KJS::JSObject question

Jack Wootton jackwootton at gmail.com
Fri May 15 08:06:25 PDT 2009


Sorry,some corrections:

I am using kJSClassDefinitionEmpty to help create the JSClassDefinition.

Also, myObjectDef.myObjectName; should be myObjectDef.className = myObjectName;

On Fri, May 15, 2009 at 3:35 PM, Jack Wootton <jackwootton at gmail.com> wrote:
> I have had a look at the JavaScriptCore Framework Reference
> (http://developer.apple.com/documentation/Carbon/Reference/WebKit_JavaScriptCore_Ref/index.html#//apple_ref/doc/framework/javascriptcore_fw).
>  My understanding now is that to add a custo object, the following
> steps would need to be taken:
>
> 1. Create a name for the new object, for example:
>
> JSStringRef myObjectName = JSStringCreateWithUTF8CString("foo");
>
> 2. Create the class definition structure;
>
> JSClassDefinition myObjectDef;
> myObjectDef.version = 1;
> myObjectDef.myObjectName;
>
> 3. Create the class.
>
> JSClassRef globalObjectClass = JSClassCreate(&myObjectDef);
>
> 4. Create the context:
>
> JSGlobalContextRef context = JSGlobalContextCreate(globalObjectClass);
>
> 5. Make the object:
>
> JSObjectRef JSObjectMake(context, globalObjectClass, NULL)
>
>
> However I have the following questions.
>
> 1. Who should share the context?  Is a single context used for a
> single webpage / frame?
> 2. Where do I define the class that will actually handle the
> implementation of any methods on my new object?
> 3. The object has been made using "JSObjectMake", but how is it added to WebKit?
>
> Many thanks,
> Jack
>
> 2009/5/15 browserwk <browserwk at gmail.com>:
>> Maybe you need check out the JavaScriptCore/API directory.
>>
>> Following file is need carefully.
>>
>> JavaScriptCore/API/tests/testapi.c
>>
>> Thanks.
>>
>> -Xiong
>>
>> -------- Original Message  --------
>> Subject: Re: [webkit-dev] KJS::JSObject question
>> From: Jack Wootton <jackwootton at gmail.com>
>> To: Darin Adler <darin at apple.com>
>> Cc: "webkit-dev at lists.webkit.org" <webkit-dev at lists.webkit.org>
>> Date: 2009年05月15日 星期五 17时40分40秒
>>
>>> OK.  It seems I was on completely the wrong track.  I was under the
>>> impression WebKit didn't have public and non public APIs as such, at
>>> least I haven't read anything to this effect.  Where can I read what
>>> the published Vs non published APIs are?  Or which ones I should use
>>> and which ones I shouldn't?
>>>
>>> On Thu, May 14, 2009 at 6:02 PM, Darin Adler <darin at apple.com> wrote:
>>>> On May 14, 2009, at 8:03 AM, Jack Wootton wrote:
>>>>
>>>>> My question: 營 do not understand how JSObject can be used to allow for
>>>>> the JavaScript syntax of : myNewJSObject.someObject.hello().
>>>> My first comment is that you should not be using JSObject directly. The
>>>> right way to do this is to use the C-based public API of JavaScriptCore,
>>>> which includes types like JSObjectRef. The JSObject internal interface is
>>>> constantly being changed and not suitable for use outside the WebKit
>>>> project.
>>>>
>>>> In JavaScript, if you want:
>>>>
>>>>   燼.b.c()
>>>>
>>>> to work, then the object "a" need a property "b" with a property "c" that is
>>>> callable as a function. At each level, the object can just be a general
>>>> purpose object with a property attached, which can be set up with functions
>>>> like JSObjectSetProperty, or the property can come from the object抯
>>>> prototype, or the property can be 揵uilt in� to the object, which can by
>>>> done with JSClassCreate supplying a JSObjectGetPropertyCallback function.
>>>>
>>>> When it comes to the value of the property named "c", to make something
>>>> callable as a function, you can either use an actual compiled JavaScript
>>>> function, one of the built in JavaScript functions such as
>>>> String.prototype.toLowerCase or you can make an object that acts like a
>>>> function using JSClassCreate supplying a JSObjectCallAsFunctionCallback
>>>> function.
>>>>
>>>>    -- Darin
>>>>
>>>>
>>>
>>>
>>>
>>
>
>
>
> --
> Regards
> Jack
>



-- 
Regards
Jack


More information about the webkit-dev mailing list