Hi Luke,

A few comments on the proposed String functions:

1) String.prototype.reverse(), as proposed, corrupts supplementary characters. 
Clause 6 of Ecma-262 redefines the word "character" as "a 16-bit unsigned value 
used to represent a single 16-bit unit of text", that is, a UTF-16 code unit. 
In contrast, the phrase "Unicode character" is used for Unicode code points. 
For reverse(), this means that the proposed spec will reverse the sequence of 
the two UTF-16 code units representing a supplementary character, resulting in 
corruption. If this function is really needed (is it? for what?), it should 
preserve the order of surrogate pairs, as does java.lang.StringBuilder.reverse:
http://download.oracle.com/javase/7/docs/api/java/lang/StringBuilder.html#reverse()

2) String.prototype.toArray(), as proposed, breaks up the surrogate pairs 
representing supplementary characters and returns each UTF-16 code unit 
separately. This follows an unfortunate precedent set by 
String.prototype.split() and other functions. The function should be named to 
clearly indicate that it returns an array of UTF-16 code units. This also 
allows us to offer a parallel function that returns an array of code points.

3) String.prototype.toArray() was originally proposed as an equivalent of 
this.split(''), that is, returning an array of String values. The proposed 
specification fills the array with elements defined as "the character at 
position n in S", which according to clause 6 would mean 16-bit unsigned 
values. It seems there needs to be a conversion to the intended type of the 
elements.

Regards,
Norbert


On Nov 15, 2011, at 17:37 , Luke Hoban wrote:

> The Harmony proposals page contains several additions to the core String, 
> Number and Math libraries, adding some of the most commonly created and 
> requested helper operations to these libraries for ES6.  I've uploaded to the 
> wiki a first draft of candidate spec text for these library additions:
> * DOC: 
> http://wiki.ecmascript.org/lib/exe/fetch.php?media=harmony:es6libraryextensions.doc
> * PDF: 
> http://wiki.ecmascript.org/lib/exe/fetch.php?media=harmony:es6libraryextensions.pdf
> 
> There are a few remaining open issues, which I've listed in the corresponding 
> proposal pages:
> * Math Extras 
> http://wiki.ecmascript.org/doku.php?id=harmony:more_math_functions
> * String Extras http://wiki.ecmascript.org/doku.php?id=harmony:string_extras
> 
> Feedback welcome.
> 
> Luke

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to