Will `for (var a of null) {}` throw an error?

Allen Wirfs-Brock allen at wirfs-brock.com
Tue Dec 23 09:10:27 PST 2014


actually, in my working copy of the spec, CheckIterable has already been updated to look like:

	1.	If obj is undefined or null, then return undefined.
	2.	Return GetV(obj, @@iterator).

where GetV is similar to Get but it boxes non-object values before doing the property lookup

When you find issues like this, the best thing to do is to simply submit a bug ticket at: bugs.emcascript.org 

Allen

On Dec 22, 2014, at 4:32 PM, Gary Guo wrote:

> Actually I propose a change in texts in the specification.
> 
> >CheckIterable ( obj )
> >1. If obj is `undefined` or `null`, then return `undefined`.
> >2. If type(obj) is Object, then return Get(obj, @@iterator).
> >3. Let box be ToObject(obj).
> >4. ReturnIfAbrupt(box).
> >5. Return the result of calling the [[Get]] internal method of box passing @@iterator and obj as the arguments.
> 
> This is way more too complex. We know that there are three situation:
> 1. obj is `undefined` or `null`
> 2. obj is of a primitive type
> 3. obj is an object
> 
> In 1, we don't care if it returns undefined or throw a TypeError. In ES6 spec, there are two uses of the undefined returned. One of them passes it as F to Call, the other passes it to ToObject. Both of them will result in TypeError. So we can just let this step throw TypeError instead of return `undefined`.
> 
> I suggest we can a little bit combine these steps:
> 
> >CheckIterable (obj)
> >1. Let box be ToObject(obj).
> >2. ReturnIfAbrupt(box).
> >3. Return the result of calling the [[Get]] internal method of box passing @@iterator and obj as the arguments.
> 
> If obj is `undefined` or `null`, the first step will fail and throw TypeError. If obj is primitive, it's boxed. If obj is an object, it is no-op in ToObject.
> 
> 
> 
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20141223/4c613c58/attachment-0001.html>


More information about the es-discuss mailing list