2 question about JSEngine

0 views
Skip to first unread message

wenbin wang

unread,
Nov 16, 2009, 12:12:11 AM11/16/09
to google-gadgets-for-linux-user
In ScirptableView.cc Line 92
what does AssignFromNative() do for?

I just have known that the methods in c++ and js should be registered
in the global class info map,
but what should we have to register in javascript engine?

James Su

unread,
Nov 16, 2009, 12:41:23 AM11/16/09
to google-gadgets...@googlegroups.com
On Mon, Nov 16, 2009 at 1:12 PM, wenbin wang <wbwan...@gmail.com> wrote:
In ScirptableView.cc Line 92
what does  AssignFromNative() do for?
Have you read the comment of this method in script_context_interface.h? IMHO, the comment states the usage of this method clearly.
 

I just have known that the methods in c++ and js should be registered
in the global class info map,
but what should we have to register in javascript engine?
I don't understand this question at all :-(
 

--

You received this message because you are subscribed to the Google Groups "google-gadgets-for-linux-user" group.
To post to this group, send email to google-gadgets...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-gadgets-for-linux-user?hl=.



Xianzhu Wang

unread,
Nov 16, 2009, 1:00:52 AM11/16/09
to google-gadgets...@googlegroups.com
What to register depends on what API you want to expose to JavaScript code.

For gglinux, we provide Desktop Gadget API (http://code.google.com/intl/zh-CN/apis/desktop/docs/gadget_apiref.html) to JavaScript code, so we register the properties and methods according to the API.

2009/11/16 wenbin wang <wbwan...@gmail.com>
In ScirptableView.cc Line 92
what does  AssignFromNative() do for?

It assigns a native scriptable value to a JavaScrpit lvalue:
   some_js_lvalue = native_scriptable_value

For this particular line
"script_context_->AssignFromNative(NULL, "", "utils", Variant(&utils_);"
it creates a variable named "utils" in the global name space of the JavaScript context, with the value of the native scriptable object "utils_", so the script can use "utils.loadImage()" etc.

The "utils" API has been obsoleted, only for backward compatibility. Some very old gadgets use this API.

We use AssignFromNative() instead of registering "utils" as a property of the global object because we want the program can just safely ignore this obsoleted API and can freely use this the name "utils" as a normal JavaScript variable, for example, "utils = 10" or "utils = function() { ... }".

I just have known that the methods in c++ and js should be registered
in the global class info map,
but what should we have to register in javascript engine?
Reply all
Reply to author
Forward
0 new messages