Support 4-byte UTF-8 sequences.

The following functions are no longer restricted to 16-bit integer values:

	String.fromCharCode()
	String.prototype.charCodeAt()

repr() will not escape SMP characters, as doing so would require conversion to
surrogate pairs, but will encode these characters as UTF-8. Unicode characters
in the BMP will still be escaped with \uXXXX as before.

JSON.stringify() only escapes control characters, so will represent all non-ASCII
characters as UTF-8.

We do no automatic conversions to/from surrogate pairs. Code that worked with
surrogate pairs should not be affected by these changes.
This commit is contained in:
Tor Andersson
2020-02-19 10:11:31 +01:00
parent 0261579d78
commit 832e069049
6 changed files with 87 additions and 27 deletions

View File

@@ -310,7 +310,7 @@ static void S_fromCharCode(js_State *J)
}
for (i = 1; i < top; ++i) {
c = js_touint16(J, i);
c = js_touint32(J, i);
p += runetochar(p, &c);
}
*p = 0;