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

"Component is not available" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" on for(var p in obj)

81 views
Skip to first unread message

John J. Barton

unread,
Nov 13, 2009, 1:28:55 PM11/13/09
to
On the line
for(var p in obj)
I get a lot of
"Component is not available" nsresult: "0x80040111
(NS_ERROR_NOT_AVAILABLE)"
exceptions.

Is there a test on obj that will detect of the for-in loop will fail?

jjb

Boris Zbarsky

unread,
Nov 13, 2009, 1:20:19 PM11/13/09
to
On 11/13/09 1:28 PM, John J. Barton wrote:
> Is there a test on obj that will detect of the for-in loop will fail?

In full generality, no: host objects can do whatever they please.

If you have specific objects that might be coming through here, then maybe.

-Boris

John J. Barton

unread,
Nov 13, 2009, 2:08:15 PM11/13/09
to
Boris Zbarsky wrote:
> On 11/13/09 1:28 PM, John J. Barton wrote:
>> Is there a test on obj that will detect of the for-in loop will fail?
>
> In full generality, no: host objects can do whatever they please.

What is a host object? How would such an object fail for-in? I guess
for-in compiles to a call to some function?

>
> If you have specific objects that might be coming through here, then maybe.

This is chromebug tracing code, so specifically any object that JS can
see in any window or component.

jjb

Boris Zbarsky

unread,
Nov 13, 2009, 2:19:26 PM11/13/09
to
On 11/13/09 2:08 PM, John J. Barton wrote:
> What is a host object?

Anything that's not actually defined as part of the ECMAScript language.
So any DOM object, for example. Any nsIFoo object exposed via
XPConnect. A Sandbox object.

Pretty much anything you didn't create with new String/Array/Object,
basically.

> How would such an object fail for-in? I guess
> for-in compiles to a call to some function?

It can; a host object can request notification when enumeration starts
(e.g. so that it can define lazy properties such that for..in will see
them). If that notification leads to an exception, then you might get
the situation you see here.

It seems that I shouldn't have limited this to host objects, though,
since even native objects can implement custom for..in behavior. Example:

var obj = { __iterator__: function() { return null; } };
var results = " -- ";
for (var i in obj) {
results += i + ": " + obj[i] + " -- ";
}

will throw because __iterator__ returns a primitive value. Or you could
have:

function myIter() {
yield "x";
yield "y";
throw new Error("z");
}
var obj = { __iterator__: myIter };
var results = " -- ";
for (var i in obj) {
results += i + ": " + obj[i] + " -- ";
}

which will throw for you. If you take out the throw it'll show " -- x:
undefined -- y: undefined -- " as expected.

-Boris

John J Barton

unread,
Nov 23, 2009, 7:35:51 PM11/23/09
to
Boris Zbarsky wrote:
> On 11/13/09 2:08 PM, John J. Barton wrote:
>> What is a host object?
>
> Anything that's not actually defined as part of the ECMAScript language.
> So any DOM object, for example. Any nsIFoo object exposed via
> XPConnect. A Sandbox object.
>
> Pretty much anything you didn't create with new String/Array/Object,
> basically.
>
>> How would such an object fail for-in? I guess
>> for-in compiles to a call to some function?
>
> It can; a host object can request notification when enumeration starts
> (e.g. so that it can define lazy properties such that for..in will see
> them). If that notification leads to an exception, then you might get
> the situation you see here.
>

In this case why don't I see the exception? I don't see the
jsd.onError() call, so this does not seem to be a case where xpconnect
is swallowing the exception.

The objects that fail for me a lot have .toString():
[object XPCNativeWrapper [object ChromeWindow]]
The value of obj.closed is false.

So I still don't understand why I am getting this message.
jjb

Boris Zbarsky

unread,
Nov 23, 2009, 10:18:29 PM11/23/09
to
On 11/23/09 7:35 PM, John J Barton wrote:
> In this case why don't I see the exception?

_That_ I can't tell you. Check in .js-engine?

> The objects that fail for me a lot have .toString():
> [object XPCNativeWrapper [object ChromeWindow]]
> The value of obj.closed is false.
>
> So I still don't understand why I am getting this message.

I don't either; I'd need a testcase and probably a debug build to tell
you more.

-Boris

0 new messages