Re: [webkit-dev] KJS::JSObject question

2009-05-21 Thread Jack Wootton
Hello,

Having read through the following document Using JavaScript From Objective-C:

http://developer.apple.com/documentation/AppleApplications/Conceptual/SafariJSProgTopics/Tasks/ObjCFromJavaScript.html#//apple_ref/doc/uid/30001215-BBCBFJCD

It seems that the method:

WebView::windowScriptObject

would be useful to achieve what I wish to do (add a custom JavaScript
object).  However looking at the source code, it is not implemented on
windows:

http://trac.webkit.org/browser/trunk/WebKit/win/WebView.cpp#L2709



On Sun, May 17, 2009 at 6:30 PM, Darin Adler da...@apple.com wrote:
 On May 15, 2009, at 7:35 AM, Jack Wootton wrote:

 4. Create the context:

 JSGlobalContextRef context = JSGlobalContextCreate(globalObjectClass);

 You will only do this if you’re using JavaScript outside of a web page. If
 you want to do this in conjunction with WebKit you’ll need to get the
 context from WebKit APIs. On Mac OS X the relevant API is -[WebFrame
 globalContext].

 1. Who should share the context?  Is a single context used for a single
 webpage / frame?

 See my answer above.

 2. Where do I define the class that will actually handle the
 implementation of any methods on my new object?

 I don’t understand the “where” question. Do it wherever makes sense in your
 program, and call JSClassCreate. Then when it's time to make an object, pass
 the JSClassRef to JSObjectMake.

 3. The object has been made using JSObjectMake, but how is it added to
 WebKit?

 A common thing to do is to create an object and then put it in a property of
 the window object, which is the global object inside the web browser. That’s
 done on Mac OS X by implementing the webView:windowScriptObjectAvailable:
 method of the frame load delegate. The window script object is a
 WebScriptObject, and you can get the JSObject version of it by calling the
 JSObject method on it. Then you can set your object as a property of the
 window object with the JSObjectSetProperty function.

    -- Darin





-- 
Regards
Jack
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev


Re: [webkit-dev] KJS::JSObject question

2009-05-17 Thread Darin Adler

On May 15, 2009, at 7:35 AM, Jack Wootton wrote:


4. Create the context:

JSGlobalContextRef context = JSGlobalContextCreate(globalObjectClass);


You will only do this if you’re using JavaScript outside of a web  
page. If you want to do this in conjunction with WebKit you’ll need to  
get the context from WebKit APIs. On Mac OS X the relevant API is - 
[WebFrame globalContext].


1. Who should share the context?  Is a single context used for a  
single webpage / frame?


See my answer above.

2. Where do I define the class that will actually handle the  
implementation of any methods on my new object?


I don’t understand the “where” question. Do it wherever makes sense in  
your program, and call JSClassCreate. Then when it's time to make an  
object, pass the JSClassRef to JSObjectMake.


3. The object has been made using JSObjectMake, but how is it  
added to WebKit?


A common thing to do is to create an object and then put it in a  
property of the window object, which is the global object inside the  
web browser. That’s done on Mac OS X by implementing the  
webView:windowScriptObjectAvailable: method of the frame load  
delegate. The window script object is a WebScriptObject, and you can  
get the JSObject version of it by calling the JSObject method on it.  
Then you can set your object as a property of the window object with  
the JSObjectSetProperty function.


-- Darin

___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev


Re: [webkit-dev] KJS::JSObject question

2009-05-15 Thread Jack Wootton
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 da...@apple.com wrote:
 On May 14, 2009, at 8:03 AM, Jack Wootton wrote:

 My question:  I 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:

    a.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’s
 prototype, or the property can be “built 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
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev


Re: [webkit-dev] KJS::JSObject question

2009-05-15 Thread Jack Wootton
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 jackwoot...@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 browse...@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 jackwoot...@gmail.com
 To: Darin Adler da...@apple.com
 Cc: webkit-dev@lists.webkit.org webkit-dev@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 da...@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
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev


[webkit-dev] KJS::JSObject question

2009-05-14 Thread Jack Wootton
Hello all,

I'm looking at the JSObject class in the KJS namespace.  The file is
JavaScriptCore/kjs/object.h.  My understanding of this class is that
it must be subclassed when adding new JavaScript objects to suplement
the standard global objects such as document or window etc.  I
have a vague understanding of the functions involved when calling a
method or accessing an attribute of a JSObject, for example:

JSValue *get(ExecState *exec, const Identifier propertyName) const;
bool getPropertySlot(ExecState *, const Identifier, PropertySlot);
virtual bool getOwnPropertySlot(ExecState *, const Identifier, PropertySlot);

(Although I don't understand PropertySlots.  perhaps someone can offer
some guidance in that area?)

My question:  I do not understand how JSObject can be used to allow
for the JavaScript syntax of : myNewJSObject.someObject.hello().

So in the example above there are two objects before reaching the
function call.  Any advice on implementing this with WebKit would be
helpful.

-- 
Regards
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev


Re: [webkit-dev] KJS::JSObject question

2009-05-14 Thread Darin Adler

On May 14, 2009, at 8:03 AM, Jack Wootton wrote:

My question:  I 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:

a.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’s prototype, or the property can be “built 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

___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev