Some previous discussion: [1] especiallly [2]

In general I think this is a reasonable thing, but it requires a decent bit 
more infrastructure to do things “safely”. For example, consider the definition 
[3]. It's generic in its arguments, which I think is nice (but does not fit 
with Web IDL---whatever). However, it's susceptible to author code overriding 
Array.prototype.join. Similarly, [4] relies upon the author-modifiable Math.max 
and Math.min, not to mention the author-modifiable Math binding.

I go into these issues in a bit more detail in [5], although that's from an 
implementation perspective. Regardless, it at least opens with another good 
example.

If we wanted to make this feasible---and I think that would be a good thing---I 
think at a minimum we'd need:

- "JS bindings" for all the ES abstract operations, so you could do e.g. 
max(...) or DefinePropertyOrThrow(...) instead of Math.max(...) and 
Object.defineProperty(...)
- Some way of expressing private state in ES. (Maybe WeakMaps are sufficient, 
semantically, but syntactically they are awkward.)
- Some kind of Record type, as well as some kind of List type, corresponding to 
those in the ES spec. Trying to use just objects or arrays will fail in the 
face of modifications to Object.prototype and Array.prototype. (Boris goes over 
this in [2])

It's a decent bit of work...

[1]: 
https://esdiscuss.org/topic/for-of-loops-iteratorclose-and-the-rest-of-the-iterations-in-the-spec
[2]: 
https://esdiscuss.org/topic/for-of-loops-iteratorclose-and-the-rest-of-the-iterations-in-the-spec#content-26
[3]: http://dev.w3.org/csswg/css-color/#dom-rgbcolor-stringifiers
[4]: http://dev.w3.org/csswg/css-color/#dom-hslcolor-hslcolorrgb
[5]: 
https://docs.google.com/document/d/1AT5-T0aHGp7Lt29vPWFr2-qG8r3l9CByyvKwEuA8Ec0/edit#heading=h.9yixony1a18r

Reply via email to