Is there a test on obj that will detect of the for-in loop will fail?
jjb
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
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
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
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
_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