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
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
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/
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
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
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
> 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
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
> >>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
Sorry, it was a figure of speech, an idiom.
/be
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
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
ok thank you for the details,
humm I really need to investigate more into XUL world.
zwetan