njs_index_t is_point, njs_value_t *retval)
{
double num;
- u_char *p, *start, *end;
+ u_char *p, *start, *end, *last;
ssize_t len;
int32_t code;
uint32_t cp;
len = njs_utf16_encode(code, &start, end);
start = buf;
- cp = njs_utf16_decode(&ctx, (const u_char **) &start, start + len);
+ last = buf + len;
- if (cp > NJS_UNICODE_MAX_CODEPOINT) {
- if (cp == NJS_UNICODE_CONTINUE) {
- continue;
+ /* An unpaired leading surrogate leaves a unit to be reread. */
+
+ do {
+ cp = njs_utf16_decode(&ctx, (const u_char **) &start, last);
+
+ if (cp > NJS_UNICODE_MAX_CODEPOINT) {
+ if (cp == NJS_UNICODE_CONTINUE) {
+ break;
+ }
+
+ cp = NJS_UNICODE_REPLACEMENT;
}
- cp = NJS_UNICODE_REPLACEMENT;
- }
+ size += njs_utf8_size(cp);
+ length++;
- size += njs_utf8_size(cp);
- length++;
+ } while (start < last);
}
if (cp == NJS_UNICODE_CONTINUE) {
len = njs_utf16_encode(code, &start, end);
start = buf;
- cp = njs_utf16_decode(&ctx, (const u_char **) &start, start + len);
+ last = buf + len;
- if (cp > NJS_UNICODE_MAX_CODEPOINT) {
- if (cp == NJS_UNICODE_CONTINUE && i + 1 != nargs) {
- continue;
+ do {
+ cp = njs_utf16_decode(&ctx, (const u_char **) &start, last);
+
+ if (cp > NJS_UNICODE_MAX_CODEPOINT) {
+ if (cp == NJS_UNICODE_CONTINUE && i + 1 != nargs) {
+ break;
+ }
+
+ cp = NJS_UNICODE_REPLACEMENT;
}
- cp = NJS_UNICODE_REPLACEMENT;
- }
+ p = njs_utf8_encode(p, cp);
- p = njs_utf8_encode(p, cp);
+ } while (start < last);
}
return NJS_OK;
{ njs_str("String.fromCharCode(0xD83D) + String.fromCharCode(0xDCA9)"),
njs_str("��") },
+ { njs_str("String.fromCharCode(0xD83D, 0x41)"),
+ njs_str("�A") },
+
+ { njs_str("String.fromCharCode(0xD83D, 0x41, 0x42)"),
+ njs_str("�AB") },
+
+ { njs_str("String.fromCharCode(0xD83D, 0x41, 0x42).length"),
+ njs_str("3") },
+
+ { njs_str("String.fromCharCode(0xD83D, 0x41, 0xD83D)"),
+ njs_str("�A�") },
+
+ { njs_str("String.fromCharCode(0xD83D, 0xD83D)"),
+ njs_str("��") },
+
+ { njs_str("String.fromCharCode(0xD83D, 0xD83D, 0xDCA9)"),
+ njs_str("�💩") },
+
{ njs_str("String.fromCodePoint(65 + 65536)"),
njs_str("𐁁") },
{ njs_str("String.fromCodePoint(0xD83D).length"),
njs_str("1") },
+ { njs_str("String.fromCodePoint(0xD83D, 0x41, 0x42)"),
+ njs_str("�AB") },
+
+ { njs_str("String.fromCodePoint(0xD83D, 0x1F4A9)"),
+ njs_str("�💩") },
+
+ { njs_str("String.fromCodePoint(0xD83D, 0x1F4A9, 0x42)"),
+ njs_str("�💩B") },
+
+ { njs_str("String.fromCodePoint(0xD83D, 0x1F4A9, 0xD83D)"),
+ njs_str("�💩�") },
+
{ njs_str("String.fromCharCode(2**53 + 10)"),
njs_str("\n") },