Subj : Re: Another JS question To : netscape.public.mozilla.jseng From : Sterling Bates Date : Tue May 04 2004 11:45 am Issac Goldstand wrote: >>Bug: JS_ValueToObject can return null in obj and true as its return >>value -- you need to check and defend, as null is not a valid object to >>pass to JS_IsArrayObject, etc. > > ??? > But I thought " JS_ValueToObject converts a specified JS value, v, to a JS > object. The converted object is stored in the object pointed to by objp. If > the conversion is successful, JS_ValueToObject returns JS_TRUE. Otherwise it > returns JS_FALSE. " I would think that null would be an unsuccessful > conversion http://lxr.mozilla.org/mozilla/source/js/src/jsobj.c#3613 The first case, NULL or VOID, is permitted. On the other hand, the ECMA 262-3 spec, page 53 (http://www.mozilla.org/js/language/E262-3.pdf): Input Type Result Undefined Throw a TypeError exception. Null Throw a TypeError exception. >>a is not an Array. You are not indexing -- using non-negative integer >>property ids. Why not use an Object instead? You could even use >>convenient object literal notation (a = {AB: [...], AR: [...], ...]). > > I'm not sure I understood that... In any case, I can't change the > javascript source as I'm having it passed to me - not generating it myself. Arrays are indexed using integers. Any javascript Object can be indexed using strings. The code you're being sent creates an array, then proceeds to use string indexes. >>Use an object. >> >>To enumerate it, use a for..in loop. >> > > Is there any way to identify an object that follows this "hash-like" > convention, so I can add a section in the conversion function to return a > native hash as the return value? I'm going to take a leap here and say "no". Whether you index an object using foo.bar or foo["bar"], javascript doesn't differentiate between the two. (At least, I haven't yet found anything in the spec to say otherwise.) Sterling .