Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Method added into Object.prototype: can't call directly inside XUL context.

3 views
Skip to first unread message

Lev Serebryakov

unread,
Oct 3, 2005, 1:24:01 PM10/3/05
to
This code works in JavaScript shell & JavaScript environment (provided
by Extension Developer Extension), but doesn't work in script, loaded
into XUL file (XUL file is in "chrome://" space) with "XXX.aha is not a
function" error:

Object.prototype.aha = function() { window.dump("aha\n"); }
function XXX() {};
XXX.aha();

This works everywhere:

Object.prototype.aha = function() { window.dump("aha\n"); }
function XXX() {};
XXX.prototype.aha.apply(XXX);

Why first variant doesn't work in XUL context? :( Second variant is too
ugly to use...

--
// Lev serebryakov

Brendan Eich

unread,
Oct 3, 2005, 4:06:22 AM10/3/05
to Lev Serebryakov, Boris Zbarsky, Johnny Stenback


What is XXX, exactly? I bet you are not using the same XXX in the js
shell, because XXX is a DOM or XPCOM object of some kind.

/be

Martin Honnen

unread,
Oct 3, 2005, 2:53:37 PM10/3/05
to

Lev Serebryakov wrote:

> This code works in JavaScript shell & JavaScript environment (provided
> by Extension Developer Extension), but doesn't work in script, loaded
> into XUL file (XUL file is in "chrome://" space) with "XXX.aha is not a
> function" error:
>
> Object.prototype.aha = function() { window.dump("aha\n"); }
> function XXX() {};
> XXX.aha();

Perhaps the same or at least related to
<https://bugzilla.mozilla.org/show_bug.cgi?id=300079>?

--

Martin Honnen
http://JavaScript.FAQTs.com/

Lev Serebryakov

unread,
Oct 3, 2005, 3:05:26 PM10/3/05
to

> What is XXX, exactly? I bet you are not using the same XXX in the js
> shell, because XXX is a DOM or XPCOM object of some kind.

This was cut'n'pasted!
It is minimal example of error. I found this strange behavior when
XXX was really big-and-scare object, but it is completely MY object.
Not a XPCOM object, nor DOM one.

I'm constructing some code, which implements inheritance by copying
functions, getters and setters from prototype of base to prototype of
child. It makes
more work, adds supports for `object.SUPER.method()' and some other
tricks.
It does it work in `Constructor.inherits( BaseConstructor );' call,
and 'inherits' is added to Object's prototype. This code works well in
JS Environment, but not in XUL window's scripts :(

I've start to experitment after this error and found minmal example
to demonstrate this behaviour. Posted code with `XXX' is this minimal
example, and it was cut'n'pasted from my code, where it works (in
Env/Shell) and doesn't work (in XUL).

But, I repeat, I call this code for custom objects, I don't try to
apply
it to any XPOCM or DOM object. And even all my `inheritance' code
works well if I call `inherits' method through
`prototype.inherits.apply'.

May be, it is because `function XXX()' becomes property of `window'
object when it is encountered in script, loaded into XUL?
--
// Lev Serebryakov

Lev Serebryakov

unread,
Oct 3, 2005, 3:11:26 PM10/3/05
to

Yes, it seems to be the same. And it was reproduced in build from
year 2002... Oh my...

--
// Lev Serebryakov

Lev Serebryakov

unread,
Oct 3, 2005, 3:23:27 PM10/3/05
to
But what induces this bug? "Function" is not XPConnect-wrapped object,
so XPCNativeWrapper should not hide it, am I right? Minimal code, which
illustrates, this bug, doesn't do anything about XPConnect.

The same JS engine gives different results in base behaviour in
different context... :(
It closes way for many legal tricks, which makes JavaScript good
programming language for big projects. Maybe, it was Ok when Mozilla
was only a browser, but now, when it pretends to be a platform :(.
I'll try to debug this tomorrow, but I almost sure, that only authors
of JS engine/XPConnect will able to fix this bug :(

--
// Lev Serebryakov

Brendan Eich

unread,
Oct 3, 2005, 7:00:40 AM10/3/05
to Lev Serebryakov
Lev Serebryakov wrote:
>>What is XXX, exactly? I bet you are not using the same XXX in the js
>>shell, because XXX is a DOM or XPCOM object of some kind.
>
>
> This was cut'n'pasted!

Sorry, this is the bug Martin Honnen points out:
https://bugzilla.mozilla.org/show_bug.cgi?id=300079

It's due to how XUL scripts are precompiled. It should be possible to
fix with some work. Let me write a comment in that bug.

/be

Lev Serebryakov

unread,
Oct 4, 2005, 4:45:17 AM10/4/05
to
On 10/3/05, Brendan Eich <bre...@meer.net> wrote:

> It's due to how XUL scripts are precompiled.

XUL library does something very special here? We used SpiderMonkey
engine in our previous project (as separate library, not XUL framework,
but only SpiderMonkey engine), we used precompiled scripts, and
everything works Ok. Even more, ability to do such tricks (like adding
new methods to base/host classes) was requirement for us and
SpiderMonkey was selected instad of MS JScript DLL (customer wanted MS
JScript), because it allows such tricks and they worked very well in
opposite to MS JScript DLL.
Now I'm programming in XUL environment and have bugs exactly as in MS
JScript! It is very sad :(

> It should be possible to fix with some work.

Is here anybody, who can do it?

> Let me write a comment in that bug.

How can I not to let you write comment in bugzilla? ;-)

--
// Lev Serebryakov

Brendan Eich

unread,
Oct 4, 2005, 5:00:34 AM10/4/05
to Lev Serebryakov
Lev Serebryakov wrote:
> On 10/3/05, Brendan Eich <bre...@meer.net> wrote:
>
>
>>It's due to how XUL scripts are precompiled.
>
> XUL library does something very special here? We used SpiderMonkey
> engine in our previous project (as separate library, not XUL framework,
> but only SpiderMonkey engine), we used precompiled scripts, and
> everything works Ok.

You must not have executed precompiled scripts against several different
global objects at the same time.


> Even more, ability to do such tricks (like adding
> new methods to base/host classes) was requirement for us and
> SpiderMonkey was selected instad of MS JScript DLL (customer wanted MS
> JScript), because it allows such tricks and they worked very well in
> opposite to MS JScript DLL.
> Now I'm programming in XUL environment and have bugs exactly as in MS
> JScript! It is very sad :(


Yes, it's sad, but the bug can be fixed. It has been around a long
time, only being noticed this year. I wonder why.


>>It should be possible to fix with some work.
>
> Is here anybody, who can do it?


Me?


>>Let me write a comment in that bug.
>
> How can I not to let you write comment in bugzilla? ;-)

Hey, I'm on your side. See
https://bugzilla.mozilla.org/show_bug.cgi?id=300079#c8.

/be

Lev Serebryakov

unread,
Oct 4, 2005, 5:13:47 AM10/4/05
to
> Yes, it's sad, but the bug can be fixed. It has been around a long
> time, only being noticed this year. I wonder why.
May be, because advanched JS tricks was "discovered" only now? They
were in language for long time, but even year ago almost everybody
thinks "Hey, it is silly JavaScript, it is not sophisticated
language". It is like gmail.com: all things, used by it was in
browsers for years, but rich DHTML-based interfaces are builded only
in last year or so.

> >>It should be possible to fix with some work.
> > Is here anybody, who can do it?
> Me?

It would be great :) Sorry, I don't know names of key persons in
Mozilla team yet :)

> >>Let me write a comment in that bug.
> > How can I not to let you write comment in bugzilla? ;-)
> Hey, I'm on your side.

Yes, surely. But may be my English is not so good (it is not native
language for me)? You've asked for mermisiion to write comment from me
:) I've answered, that I'm not a person,. who can "let" or "don't let"
to comment Mozilla's bugzilla in whole or this bug in particular :)

--
// Lev Serebryakov

Brendan Eich

unread,
Oct 4, 2005, 5:31:59 AM10/4/05
to Lev Serebryakov
Lev Serebryakov wrote:
>>
>>Hey, I'm on your side.
>
> Yes, surely. But may be my English is not so good (it is not native
> language for me)? You've asked for mermisiion to write comment from me
> :) I've answered, that I'm not a person,. who can "let" or "don't let"
> to comment Mozilla's bugzilla in whole or this bug in particular :)
>


Sorry, it was a figure of speech, an idiom.

/be

zwetan

unread,
Oct 11, 2005, 9:20:47 AM10/11/05
to
>
> Sorry, this is the bug Martin Honnen points out:
> https://bugzilla.mozilla.org/show_bug.cgi?id=300079
>
> It's due to how XUL scripts are precompiled. It should be possible to
> fix with some work. Let me write a comment in that bug.
>

is this behaviour only with Function.prototype members
or also with all the others core objects ?

ex: if I define something as
String.prototype.endsWith = function() {....}

I will be able to acces it in the HTML document but not in a XUL document,
am I right here ?

zwetan

Brendan Eich

unread,
Oct 11, 2005, 4:52:59 PM10/11/05
to zwetan
zwetan wrote:
>>Sorry, this is the bug Martin Honnen points out:
>>https://bugzilla.mozilla.org/show_bug.cgi?id=300079
>>
>>It's due to how XUL scripts are precompiled. It should be possible to
>>fix with some work. Let me write a comment in that bug.
>>
>
>
> is this behaviour only with Function.prototype members
> or also with all the others core objects ?


Function and RegExp.


> ex: if I define something as
> String.prototype.endsWith = function() {....}
>
> I will be able to acces it in the HTML document but not in a XUL document,
> am I right here ?


String and other classes are ok.

/be

zwetan

unread,
Oct 12, 2005, 7:07:27 AM10/12/05
to
> > is this behaviour only with Function.prototype members
> > or also with all the others core objects ?
>
> Function and RegExp.
>
[snip]

>
> String and other classes are ok.
>

ok thank you for the details,
humm I really need to investigate more into XUL world.

zwetan


0 new messages