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

Error: can't convert this.obj[p] to primitive type

1 view
Skip to first unread message

John J. Barton

unread,
Nov 6, 2009, 12:20:15 PM11/6/09
to
I get the error message
Error: can't convert this.obj[p] to primitive type
from this line:
var value = "" + this.obj[p];

How do I stop this message?

Note that
https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Object/toString
claims:
"Every object has a toString method ..."

(No I do not know what this.obj is, that's the point printing the
properties).

jjb

Mike Shaver

unread,
Nov 6, 2009, 12:27:47 PM11/6/09
to John J. Barton, dev-pl...@lists.mozilla.org
On Fri, Nov 6, 2009 at 12:20 PM, John J. Barton
<johnj...@johnjbarton.com> wrote:
> I get the error message
> Error: can't convert this.obj[p] to primitive type
> from this line:
>   var value = "" + this.obj[p];
>
> How do I stop this message?
>
> Note that
> https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Object/toString
> claims:
> "Every object has a toString method ..."

Yes, but if that object's toString method throws, or returns a
non-primitive, then you get the above error.

> (No I do not know what this.obj is, that's the point printing the
> properties).

What does this.obj convert to string as? Can you get this.obj[p]'s
toString function and see what it decompiles as?
this.obj[p].__proto__ would be good to discover as well. (If it's
null, you won't have a toString to be found, f.e..)

Mike

John J. Barton

unread,
Nov 6, 2009, 1:11:32 PM11/6/09
to
Mike Shaver wrote:
> On Fri, Nov 6, 2009 at 12:20 PM, John J. Barton
> <johnj...@johnjbarton.com> wrote:
>> I get the error message
>> Error: can't convert this.obj[p] to primitive type
>> from this line:
>> var value = "" + this.obj[p];
>>
>> How do I stop this message?
>>
>> Note that
>> https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Object/toString
>> claims:
>> "Every object has a toString method ..."
>
> Yes, but if that object's toString method throws, or returns a
> non-primitive, then you get the above error.

But I would have hoped that in either case I would also get an exception
so that I can figure out what is wrong. Since the code does not enter my
catch block, I can't distinguish this case from the hundreds that work.

Any way, I remembered that I've been this way before and now use our
toString:
http://code.google.com/p/fbug/source/browse/branches/firebug1.5/content/firebug/lib.js#204

jjb

Mike Shaver

unread,
Nov 6, 2009, 2:35:06 PM11/6/09
to John J. Barton, dev-pl...@lists.mozilla.org
On Fri, Nov 6, 2009 at 1:11 PM, John J. Barton
<johnj...@johnjbarton.com> wrote:
> But I would have hoped that in either case I would also get an exception so
> that I can figure out what is wrong. Since the code does not enter my catch
> block, I can't distinguish this case from the hundreds that work.

You mean that this case doesn't throw an exception, but rather just
aborts the script? In that case I would _very_ much like to find out
more about the object (see my previous questions), so that we can
isolate the case and fix the JS engine bug that is indicated.

Mike

0 new messages