Exception when I pass @mozilla.org/js/xpc/Exception;1 object to alert() method

RESOLVED INACTIVE

Status

()

Core
XPConnect
RESOLVED INACTIVE
14 years ago
2 months ago

People

(Reporter: surkov, Unassigned)

Tracking

Trunk
x86
Windows 2000
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

14 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.0; rv:1.7.3) Gecko/20040913 Firefox/0.10.1
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7) Gecko/20040616

When I create @mozilla.org/js/xpc/Exception;1 object and query nsIException
interface then I get wrong javascript wrapper of created object, because it
throw exeption when I call toString() method or I try to pass it to alert() method.


Reproducible: Always
Steps to Reproduce:
1. alert(Components.classes["@mozilla.org/js/xpc/Exception;1"].
		createInstance(Components.interfaces.nsIException).toString());
or 

2. alert(Components.classes["@mozilla.org/js/xpc/Exception;1"].
		createInstance(Components.interfaces.nsIException));

Actual Results:  

Exception when I call toString() method:
Error: uncaught exception: [Exception... "Component returned failure code:
0xc1f30001 (NS_ERROR_NOT_INITIALIZED) [nsIXPCException.toString]"  nsresult:
"0xc1f30001 (NS_ERROR_NOT_INITIALIZED)"]

Exception when I pass object to alert() method:
Error: uncaught exception: [Exception... "Could not convert JavaScript argument
arg 0 [nsIDOMWindowInternal.alert]"  nsresult: "0x80570009
(NS_ERROR_XPC_BAD_CONVERT_JS)" ]

Expected Results:  
I expect to see something like this: xpconnect wrapped nsIException
The nsIException interface has a toString() method.  This method overrides the
"native" classinfo toString() that would return "xpconnect wrapped ....".

So the behavior looks correct to me.
Summary: Exception when I pass @mozilla.org/js/xpc/Exception;1 object to alert() method → Exception when I pass @mozilla.org/js/xpc/Exception;1 object to alert() method
(Reporter)

Comment 2

14 years ago
Any javascript object has to have toString() method to convert self to string. I
think if component replaces toString() method then component should think about
compatibility with javascript rules. I guess this bug is true and it's needed to
move it to XPCOM component.
The point is, the toString method can be anything.  There's no reason my JS
objects can't just throw when toString() is called on them...
(Reporter)

Comment 4

14 years ago
I agree there is no real reason. But I really don't think It's correct to throw
exception when I try to convert object to string. I think toString() method is
"native" method and it should work always and it shouldn't depend on state of
object. I am accustomed so much to the fact that I can "see" object at any time.
And when I get exception then I'm confused.

I think it's better to return string with error message.
> I think toString() method is "native" method

It's not, really... any object can override toString on itself any time it wants to.
(Reporter)

Comment 6

14 years ago
I seem javascript objects don't like to throw exceptions and exception throwing
isn't a method of javascript. Can you say me what native javascript object
throws exception?

Comment 7

14 years ago
i've had domwindows or something related to them throw exceptions when i
stringify them. and ie has some properties which throw exceptions when i
stringify them.
What do you mean by "native javascript objects"?  If you mean ECMA-262 objects,
the specification describes exceptions being thrown in a wide variety of
circumstances...

Comment 9

14 years ago
actually, sometimes i get exceptions from tostring (on instances of Array and
Object) just because my global object doesn't like me.
(Reporter)

Comment 10

14 years ago
When I use toString() method to "see" object then I don't know often type of
object. I should set try/catch instructions when I use toString(). I think it's
inconveniently.

Maybe I'm wrong and method toString() may throw exception in some cases.
Since any object may override its own toString any time it wishes, toString can
in fact do anything at all.
This is an automated message, with ID "auto-resolve01".

This bug has had no comments for a long time. Statistically, we have found that
bug reports that have not been confirmed by a second user after three months are
highly unlikely to be the source of a fix to the code.

While your input is very important to us, our resources are limited and so we
are asking for your help in focussing our efforts. If you can still reproduce
this problem in the latest version of the product (see below for how to obtain a
copy) or, for feature requests, if it's not present in the latest version and
you still believe we should implement it, please visit the URL of this bug
(given at the top of this mail) and add a comment to that effect, giving more
reproduction information if you have it.

If it is not a problem any longer, you need take no action. If this bug is not
changed in any way in the next two weeks, it will be automatically resolved.
Thank you for your help in this matter.

The latest beta releases can be obtained from:
Firefox:     http://www.mozilla.org/projects/firefox/
Thunderbird: http://www.mozilla.org/products/thunderbird/releases/1.5beta1.html
Seamonkey:   http://www.mozilla.org/projects/seamonkey/
(Reporter)

Comment 13

13 years ago
confrim Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.9a1) Gecko/20050909
SeaMonkey/1.1a

I still belive toString() shouldn't throw any exception
Brendan, shaver, is there any reason not to mark this bug invalid?  There's no
way an uninitialized exeption object can do sane toString, imo...
Assignee: dbradley → nobody
QA Contact: pschwartau → xpconnect

Comment 15

2 months ago
Per policy at https://wiki.mozilla.org/Bug_Triage/Projects/Bug_Handling/Bug_Husbandry#Inactive_Bugs. If this bug is not an enhancement request or a bug not present in a supported release of Firefox, then it may be reopened.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 2 months ago
Resolution: --- → INACTIVE
You need to log in before you can comment on or make changes to this bug.