eval on non-strings
allen at wirfs-brock.com
Tue Feb 28 14:18:01 PST 2012
On Feb 28, 2012, at 9:20 AM, Mark S. Miller wrote:
> On Tue, Feb 28, 2012 at 7:54 AM, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
> There is also a matter of maintaining internal insistency within a language. [...] JS generally converts primitive values to wrapper objects whenever one is used in a context that requires an object. [...]
> Some other violations of this rule that surprised me when I first came across them:
> > 3 instanceof Number
> > 'x' in 3
> TypeError: Cannot use 'in' operator to search for 'x' in 3
> I am not suggesting that we do anything to repair these -- it is likely too late. But depending on how many other such irregularities there are, it may not altogether be clear which direction the principle of least surprise should take us.
Both of these were added to the spec. in ES3. They are probably exactly the sort of thing I was warning against when I mentioned point in time or spec. writer introduced inconsistencies. Since exceptions were also spec'ed in ES3 I bet whoever spec'ed in and instanceof thought that throwing would be the "right thing" and perhaps didn't even think about maintaining consistency with the language's legacy. who knows...
Since, in and instanceof currently throw in the above situations we probably could get away with changing them to do ToObject. Not necessarily saying we should, but it probably wouldn't break anything. It would be a set towards maintaining internal consistency.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss