[webkit-dev] Adding Javascript object to Webkit

2008-05-06 Thread Habiba Boulefat
Hello *Lee Ka Yuk* ,

>I'm using the WebKit project for webpage rendering on Qtopia.
>I would like to add some Javascript objects that can be accessed in the
>webpage and implemented with C/C++.

I'm also using Webkit for developping an application that permit to
extract javascript links from the tree DOM

>I studied JavaScriptCore/kjs/math_object.* and successfully added a
>object in JavaScriptCore/kjs.

My problem is that I don't knew how beggining.
I don't knew what file can I use.
In brief, I need a help to begin.

Thanks in advence
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-dev


Re: [webkit-dev] Adding Javascript object to Webkit

2008-04-14 Thread Mark Rowe


On 10/04/2008, at 20:40, Lee Ka Yuk wrote:


Dear all,

I've tested with JSCore/API and JSCore/binding.
To my surprise, none of the test apps is working.

I don't have  in my platform
(Qtopia/Ubuntu) so I could not pass the build of
JSCore/API/JSStringRefCF.h.
How can I use JSCore/API then?


#include  to avoid the dependency on  
CoreFoundation.  It won't make testapi.c compile as that currently  
exercises the two CoreFoundation-specific convenience functions in the  
JavaScriptCore API.


- Mark





smime.p7s
Description: S/MIME cryptographic signature
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-dev


Re: [webkit-dev] Adding Javascript object to Webkit

2008-04-10 Thread Lee Ka Yuk
Dear all,

I've tested with JSCore/API and JSCore/binding.
To my surprise, none of the test apps is working.

I don't have  in my platform
(Qtopia/Ubuntu) so I could not pass the build of
JSCore/API/JSStringRefCF.h.
How can I use JSCore/API then?

Then I switched to JSCore/binding and found that testbindings.cpp and
testqtbindings.cpp are out of date.
(Interpreter class has changed its API.)
I see that the latest SVN trunk have JSCore/binding removed (I'm using
r28997).
So I think the only way to go is to get JSCore/API working.

And I still have some questions about JSCore.
What's the correspondence of the life cycle of the JS object to the C++
object?
More specifically, when will the C++ object be constructed? At the same
time a corresponding JSObject is created?
Will the C++ object be deleted when the JSObject is garbage collected?
If not, when should we free the C++ object?

Thanks,
LEE

~
This message (including any attachments) is for the named
addressee(s)'s use only. It may contain sensitive, confidential,
private proprietary or legally privileged information intended for a
specific individual and purpose, and is protected by law. If you are
not the intended recipient, please immediately delete it and all copies
of it from your system, destroy any hard copies of it
and notify the sender. Any use, disclosure, copying, or distribution of
this message and/or any attachments is strictly prohibited.


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


Re: [webkit-dev] Adding Javascript object to Webkit

2008-04-06 Thread Lee Ka Yuk
Thanks for the reply from Geoff, MichaelG and Shakti.

What's the dependency/architecture of the folders JSCore/API,
JSCore/binding in JSCore? They both seem to be able to do the same thing
(don't they?), what's the difference then? Geoff suggested JSCore/API
and Shakti suggested JSCore/binding, I'm a little bit confused by that.
WebCore/bindings/js is not needed?
What's the correspondence of the life cycle of the JS object to the C++
object?
I see a constructor for the class and callAsConstructor() member
function. Is the callAsConstructor() only used for "var a = new
Complex(a,b);" situation? When will the destructor be called?

> MichaelG
I refrain from using Qt binding in QT4.4. I don't want my app to bind to
Qt so tightly as my system reached its cap when running Qt and I may
work without Qt someday.

> Shakti
For complex JS object that support 
var a = new Complex(a,b);
I've skimmed the code of array_object and simple JS object like Math
will suffice for now.

~
This message (including any attachments) is for the named
addressee(s)'s use only. It may contain sensitive, confidential,
private proprietary or legally privileged information intended for a
specific individual and purpose, and is protected by law. If you are
not the intended recipient, please immediately delete it and all copies
of it from your system, destroy any hard copies of it
and notify the sender. Any use, disclosure, copying, or distribution of
this message and/or any attachments is strictly prohibited.


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


Re: [webkit-dev] Adding Javascript object to Webkit

2008-04-03 Thread Shakti Ashirvad
Hi Lee,

There are two ways we can bind C with JS. First implementation is to create
a runtime object which doesn't have a data type
(JavaScriptCore/bindings/testbindings.cpp). This means you can create an
object like "foo" with any number of properties and methods. and you can
directly access

foo.fooBar(); or foo.var

However you cannot create more than one object like:

var a = new Complex(a,b);
a.real
a.img

For this you need to understand the math_object.cpp.

Regards,
Shakti


On Thu, Apr 3, 2008 at 3:31 PM, Lee Ka Yuk <[EMAIL PROTECTED]> wrote:

>  Hi all,
>
> I'm using the WebKit project for webpage rendering on Qtopia.
> I would like to add some Javascript objects that can be accessed in the
> webpage and implemented with C/C++.
>
> I studied JavaScriptCore/kjs/math_object.* and successfully added a object
> in JavaScriptCore/kjs.
> But I doubt if this is the "correct" way of doing so.
> And this method is not at all useful if I would like to access the SAME
> C/C++ object in the main application.
> Say I added a foo object with member var, I would like to modify and
> retrieve foo.var in BOTH QtLauncher and Javascript (synchronization put
> aside first).
>
> There are some test apps in JavaScriptCore/bindings/ that seems to do what
> I wanted.
> But I'm again confused what are the different between C-binding in
> JavaScriptCore/bindings/c and those code in JavaScriptCore/bindings/.
> JavaScriptCore/bindings/NP_jsobject.h seems to be yet another API.
>
> Then I noticed WebCore also provide some binding in WebCore/bindings/js.
> How is it different from that in JavaScriptCore/bindings?
>
> Which binding should I use that would fit the architecture best?
> Must I understand JavaScriptCore/API in order to add the object? What is
> the life cycle of the Javascript objects?
>
> I can hardly find any information concering the implementation of
> JavaScriptCore, could someone giva me a pointer?
> (A "JavaScriptCore" search in the list yields too little info while
> "JavaScript" yeilds too much.)
>
> Thanks a lot,
> LEE
>
>
> --
>  This message (including any attachments) is for the named addressee(s)'s
> use only. It may contain sensitive, confidential, private proprietary or
> legally privileged information intended for a specific individual and
> purpose, and is protected by law. If you are not the intended recipient,
> please immediately delete it and all copies of it from your system, destroy
> any hard copies of it and notify the sender. Any use, disclosure, copying,
> or distribution of this message and/or any attachments is strictly
> prohibited.
> --
>
>
>
> ___
> webkit-dev mailing list
> webkit-dev@lists.webkit.org
> http://lists.webkit.org/mailman/listinfo/webkit-dev
>
>
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-dev


Re: [webkit-dev] Adding Javascript object to Webkit

2008-04-03 Thread Michael Goddard
Hello Lee,

On Thursday 03 April 2008 20:01, Lee Ka Yuk wrote:
> I'm using the WebKit project for webpage rendering on Qtopia.
> I would like to add some Javascript objects that can be accessed in the
> webpage and implemented with C/C++.

If you are using the latest Qt/4.4 snapshot, the "Qt" way to do it is to use 
the QWebFrame::addToJavaScriptWindowObject(const QString &name, QObject 
*object) function.

For example: (not compiled :) 

class MyObject : public QObject {
Q_OBJECT
public:
MyObject() : mVar(0) {}
int var() {return mFoo;}
void setVar(int foo) {mFoo = foo;}
   Q_PROPERTY(int var READ foo WRITE setFoo);

public slots:
   int doSomething(int seed)
   {
return seed * 2;
   }
private:
int mVar;
};

... later ...
   MyObject* foo = new MyObject();
   myFrame->addToJavaScriptWindowObject("foo", foo);

.. still later [C++] ...
   qDebug() << foo->var() << foo->property("var").toInt();
   qDebug() << foo->doSomething(21);

.. or [javascript] ...
  window.alert("foo.var is:" + foo.var);
  window.alert("foo.doSomething(21) is:" + foo.doSomething(21));

If you're using Qt/4.4 for WebKit, the JSCore functions are not exposed 
through the Qt library, so this is the only way to do what you'd like.

It's up to you to manage the lifetime of the C++ object - once it is deleted, 
if the JS object still exists, accessing member variables and functions will 
throw a JS exception.

Cheers,
MichaelG
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-dev


Re: [webkit-dev] Adding Javascript object to Webkit

2008-04-03 Thread Geoffrey Garen

Which binding should I use that would fit the architecture best?
Must I understand JavaScriptCore/API in order to add the object?  
What is the life cycle of the Javascript objects?


Yes, I think using the API in JavaScriptCore/API will give you the  
best results. It's also the easiest API to come up to speed on.  
There's some example usage of the API in JavaScriptCore/API/testapi.c.


You can also find example projects @ http://developer.apple.com/samplecode/JSPong/index.html 
 and http://developer.apple.com/samplecode/JSInterpreter/index.html.


Cheers,
Geoff___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-dev


[webkit-dev] Adding Javascript object to Webkit

2008-04-03 Thread Lee Ka Yuk
Hi all,
 
I'm using the WebKit project for webpage rendering on Qtopia.
I would like to add some Javascript objects that can be accessed in the
webpage and implemented with C/C++.
 
I studied JavaScriptCore/kjs/math_object.* and successfully added a
object in JavaScriptCore/kjs.
But I doubt if this is the "correct" way of doing so.
And this method is not at all useful if I would like to access the SAME
C/C++ object in the main application.
Say I added a foo object with member var, I would like to modify and
retrieve foo.var in BOTH QtLauncher and Javascript (synchronization put
aside first).
 
There are some test apps in JavaScriptCore/bindings/ that seems to do
what I wanted.
But I'm again confused what are the different between C-binding in
JavaScriptCore/bindings/c and those code in JavaScriptCore/bindings/.
JavaScriptCore/bindings/NP_jsobject.h seems to be yet another API.
 
Then I noticed WebCore also provide some binding in WebCore/bindings/js.
How is it different from that in JavaScriptCore/bindings?
 
Which binding should I use that would fit the architecture best?
Must I understand JavaScriptCore/API in order to add the object? What is
the life cycle of the Javascript objects?
 
I can hardly find any information concering the implementation of
JavaScriptCore, could someone giva me a pointer?
(A "JavaScriptCore" search in the list yields too little info while
"JavaScript" yeilds too much.)
 
Thanks a lot,
LEE


~
This message (including any attachments) is for the named
addressee(s)'s use only. It may contain sensitive, confidential,
private proprietary or legally privileged information intended for a
specific individual and purpose, and is protected by law. If you are
not the intended recipient, please immediately delete it and all copies
of it from your system, destroy any hard copies of it
and notify the sender. Any use, disclosure, copying, or distribution of
this message and/or any attachments is strictly prohibited.



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