About the variables not defined in js file

2 views
Skip to first unread message

wenbin wang

unread,
Nov 17, 2009, 11:17:35 PM11/17/09
to google-gadgets-for-linux-user
For instance analog_clock, in main.js


options.putDefaultValue(OPTION_SECONDHAND, SECOND_QUARTZ);

view.caption = strings.PLUGIN_TITLE;

HourHand.rotation = Minutes / 2;


options, view, HourHand are not defined in this js file.
How the javascript Engine can compile these variables without errors?


Thanks very much!!!

Xianzhu Wang

unread,
Nov 17, 2009, 11:30:39 PM11/17/09
to google-gadgets...@googlegroups.com
Please read the Gadget API document: http://code.google.com/intl/zh-CN/apis/desktop/docs/gadget_apiref.html

2009/11/18 wenbin wang <wbwan...@gmail.com>

--

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=.



wenbin wang

unread,
Nov 18, 2009, 1:11:18 AM11/18/09
to google-gadgets-for-linux-user
I have analysed and run code line by line in InitFormXML() in
scriptable_view.cc.
When the attr tag is "name", nothing has been done but insert an
element.
I still don't know how Let JavascriptEngine know Variables like
HourHand, MiniteHand, Options and so on.
If you can tell me more details, for example, which code do this work,
I will be very grateful of you.

On 11月18日, 下午12时30分, Xianzhu Wang <phnix...@gmail.com> wrote:
> Please read the Gadget API document:http://code.google.com/intl/zh-CN/apis/desktop/docs/gadget_apiref.html
>
> 2009/11/18 wenbin wang <wbwang1...@gmail.com>
>
>
>
> > For instance analog_clock, in main.js
>
> > options.putDefaultValue(OPTION_SECONDHAND, SECOND_QUARTZ);
>
> > view.caption = strings.PLUGIN_TITLE;
>
> > HourHand.rotation = Minutes / 2;
>
> > options, view, HourHand are not defined in this js file.
> > How the javascript Engine can compile these variables without errors?
>
> > Thanks very much!!!
>
> > --
>
> > 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=.- 隐藏被引用文字 -
>
> - 显示引用的文字 -

James Su

unread,
Nov 18, 2009, 1:29:56 AM11/18/09
to google-gadgets...@googlegroups.com
If you want to know how does javascript access an element by its name, you can have a look at:
scriptable_view.cc:125 (DoRegister() method)
view.cc:1433 (GetElementByName() method).
view.cc:1438 (OnElementAdd() method).
elements.cc:95 (InsertElementInternal() method).
xml_utils.cc:217 (InsertElementFromDOM() function).
and
scriptable_view.cc:188 (InitFromXML() method).

And if you want to know the underlying mechanism of the javascript-c++ binding, you should spend some time to read the source code of a script runtime implementation, such as extensions/smjs_script_runtime or webkit_script_runtime. And of course scriptable_helper.{h,cc}.

Regards
James Su

wenbin wang

unread,
Nov 18, 2009, 4:29:31 AM11/18/09
to google-gadgets-for-linux-user
I have reviewed the code you told me again, but I still have my
problem.

<img name="HourHand" src="hourhand.png" x="52" y="52" pinX="3"
pinY="27" />
I hope you can tell me how "HourHand" be known by the JSEngine, so the
HourHand in main.js can be compiled without error.

For src, x, y, pinX, and pinY, some info have been registered to the
all_class_info_ in scriptable_helper.cc,
but for name, a new element named "HourHand" is inserted into children
of view, without work that let JSengine know the exist of "HourHand".

I am confused. Thanks for your time.
> > > >http://groups.google.com/group/google-gadgets-for-linux-user?hl=.-隐藏被引用文字 -

James Su

unread,
Nov 18, 2009, 4:38:45 AM11/18/09
to google-gadgets...@googlegroups.com
Have you read all code I listed below carefully?

Things like HourHand is resolved through the dynamic property handler, see ScriptableHelper's SetDynamicPropertyHandler() method.
When accessing HourHand from javascript, View's GetElementByName() method will eventually be called with name "HourHand", if it finds an element with that name, then the element will be returned to javascript, otherwise null will be returned.

Regards
James Su

2009/11/18 wenbin wang <wbwan...@gmail.com>

wenbin wang

unread,
Nov 18, 2009, 4:47:47 AM11/18/09
to google-gadgets-for-linux-user
I saw
global_object_.SetDynamicPropertyHandler(
NewSlot(this, &Impl::GetElementByNameVariant), NULL);

class GlobalObject : public ScriptableHelperNativeOwnedDefault {
public:
DEFINE_CLASS_ID(0x23840d38ed164ab2, ScriptableInterface);
virtual bool IsStrict() const { return false; }
};

GetElementByNameVariant is registerd in global_object_ of
ScriptableView, but how javascript have this dynamic property handler?
Thanks very much.

On 11月18日, 下午5时38分, James Su <james...@gmail.com> wrote:
> Have you read all code I listed below carefully?
>
> Things like HourHand is resolved through the dynamic property handler, see
> ScriptableHelper's SetDynamicPropertyHandler() method.
> When accessing HourHand from javascript, View's GetElementByName() method
> will eventually be called with name "HourHand", if it finds an element with
> that name, then the element will be returned to javascript, otherwise null
> will be returned.
>
> Regards
> James Su
>
> 2009/11/18 wenbin wang <wbwang1...@gmail.com>
> >http://groups.google.com/group/google-gadgets-for-linux-user?hl=.-隐藏被引用文字<http://groups.google.com/group/google-gadgets-for-linux-user?hl=.-%E9...>-

Xianzhu Wang

unread,
Nov 18, 2009, 5:05:08 AM11/18/09
to google-gadgets...@googlegroups.com
I suggest you to use gdb to debug the program and set a break point in GetElementByNameVariant(), then you can know how this function is called from the JavaScript Engine.

2009/11/18 wenbin wang <wbwan...@gmail.com>

wenbin wang

unread,
Nov 18, 2009, 7:06:09 AM11/18/09
to google-gadgets-for-linux-user
I have debugged as you guide, I know GetElementByNameVariant() is
called in execute js file.
But
global_object_.SetDynamicPropertyHandler(
NewSlot(this, &Impl::GetElementByNameVariant), NULL);
GetElementByNameVariant() is set as a callback slot of global_object_,
but not JSEngine,
is there some relation between global_object_ and JSEngine?

On 11月18日, 下午6时05分, Xianzhu Wang <phnix...@gmail.com> wrote:
> I suggest you to use gdb to debug the program and set a break point in
> GetElementByNameVariant(), then you can know how this function is called
> from the JavaScript Engine.
>
> 2009/11/18 wenbin wang <wbwang1...@gmail.com>
> > <http://groups.google.com/group/google-gadgets-for-linux-user?hl=.-%E9..

James Su

unread,
Nov 18, 2009, 7:09:58 AM11/18/09
to google-gadgets...@googlegroups.com
Did you use gdb command 'bt' to print out the backtrace?

2009/11/18 wenbin wang <wbwan...@gmail.com>

I have debugged as you guide, I know GetElementByNameVariant() is
called in execute js file.
But
global_object_.SetDynamicPropertyHandler(
       NewSlot(this, &Impl::GetElementByNameVariant), NULL);
GetElementByNameVariant() is set as a callback slot of global_object_,
but not JSEngine,
is there some relation between global_object_ and JSEngine?
global_object_ is set as the global object of the javascript context. You may search on google to learn what is the global object of a javascript context.
 
Reply all
Reply to author
Forward
0 new messages