Merge commit 'de4d392' into upgrade-quickjs-2025-09-13

This commit is contained in:
Nicolas Duteil 2025-09-22 14:53:57 +02:00
commit b71f081e92
36 changed files with 4992 additions and 1278 deletions

View File

@ -214,6 +214,7 @@ jobs:
submodules: true
- name: Install MinGW and Wine
run: |
sudo apt update
sudo apt install -y wine mingw-w64
cp /usr/x86_64-w64-mingw32/lib/libwinpthread-1.dll .
- name: Setup Wine

View File

@ -1,3 +1,21 @@
2025-09-13:
- added JSON modules and import attributes
- added JS_PrintValue() API
- qjs: pretty print objects in print() and console.log()
- qjs: better promise rejection tracker heuristics
- added RegExp v flag
- added RegExp modifiers
- added RegExp.escape
- added Float16Array
- added Promise.try
- improved JSON parser spec conformance
- qjs: improved compatibility of std.parseExtJSON() with JSON5 and
accept JSON5 modules
- added JS_FreePropertyEnum() and JS_AtomToCStringLen() API
- added Error.isError()
- misc bug fixes
2025-04-26:
- removed the bignum extensions and qjscalc

5
TODO
View File

@ -62,6 +62,5 @@ Optimization ideas:
Test262o: 0/11262 errors, 463 excluded
Test262o commit: 7da91bceb9ce7613f87db47ddd1292a2dda58b42 (es5-tests branch)
Result: 70/78178 errors, 1610 excluded, 7236 skipped
Test262 commit: 56e77d6325067a545ea7e8ff5be5d9284334e33c
Result: 54/79414 errors, 1637 excluded, 6821 skipped
Test262 commit: e7e136756cd67c1ffcf7c09d03aeb8ad5a6cec0c

View File

@ -1 +1 @@
2025-04-26
2025-09-13

View File

@ -364,4 +364,60 @@ static inline double uint64_as_float64(uint64_t u64)
return u.d;
}
static inline double fromfp16(uint16_t v)
{
double d;
uint32_t v1;
v1 = v & 0x7fff;
if (unlikely(v1 >= 0x7c00))
v1 += 0x1f8000; /* NaN or infinity */
d = uint64_as_float64(((uint64_t)(v >> 15) << 63) | ((uint64_t)v1 << (52 - 10)));
return d * 0x1p1008;
}
static inline uint16_t tofp16(double d)
{
uint64_t a, addend;
uint32_t v, sgn;
int shift;
a = float64_as_uint64(d);
sgn = a >> 63;
a = a & 0x7fffffffffffffff;
if (unlikely(a > 0x7ff0000000000000)) {
/* nan */
v = 0x7c01;
} else if (a < 0x3f10000000000000) { /* 0x1p-14 */
/* subnormal f16 number or zero */
if (a <= 0x3e60000000000000) { /* 0x1p-25 */
v = 0x0000; /* zero */
} else {
shift = 1051 - (a >> 52);
a = ((uint64_t)1 << 52) | (a & (((uint64_t)1 << 52) - 1));
addend = ((a >> shift) & 1) + (((uint64_t)1 << (shift - 1)) - 1);
v = (a + addend) >> shift;
}
} else {
/* normal number or infinity */
a -= 0x3f00000000000000; /* adjust the exponent */
/* round */
addend = ((a >> (52 - 10)) & 1) + (((uint64_t)1 << (52 - 11)) - 1);
v = (a + addend) >> (52 - 10);
/* overflow ? */
if (unlikely(v > 0x7c00))
v = 0x7c00;
}
return v | (sgn << 15);
}
static inline int isfp16nan(uint16_t v)
{
return (v & 0x7FFF) > 0x7C00;
}
static inline int isfp16zero(uint16_t v)
{
return (v & 0x7FFF) == 0;
}
#endif /* CUTILS_H */

View File

@ -449,17 +449,20 @@ optional properties:
@item parseExtJSON(str)
Parse @code{str} using a superset of @code{JSON.parse}. The
following extensions are accepted:
Parse @code{str} using a superset of @code{JSON.parse}. The superset
is very close to the JSON5 specification. The following extensions
are accepted:
@itemize
@item Single line and multiline comments
@item unquoted properties (ASCII-only Javascript identifiers)
@item trailing comma in array and object definitions
@item single quoted strings
@item @code{\v} escape and multi-line strings with trailing @code{\}
@item @code{\f} and @code{\v} are accepted as space characters
@item leading plus in numbers
@item octal (@code{0o} prefix) and hexadecimal (@code{0x} prefix) numbers
@item leading plus or decimal point in numbers
@item hexadecimal (@code{0x} prefix), octal (@code{0o} prefix) and binary (@code{0b} prefix) integers
@item @code{NaN} and @code{Infinity} are accepted as numbers
@end itemize
@end table

View File

@ -1,6 +1,8 @@
/* example of JS module */
/* example of JS and JSON modules */
import { fib } from "./fib_module.js";
import msg from "./message.json";
console.log("Hello World");
console.log("fib(10)=", fib(10));
console.log("msg=", msg);

2
examples/message.json Normal file
View File

@ -0,0 +1,2 @@
{ "x" : 1, "tab": [ 1, 2, 3 ] }

View File

@ -26,11 +26,15 @@
DEF(invalid, 1) /* never used */
DEF(char, 3)
DEF(char_i, 3)
DEF(char32, 5)
DEF(char32_i, 5)
DEF(dot, 1)
DEF(any, 1) /* same as dot but match any character including line terminator */
DEF(line_start, 1)
DEF(line_start_m, 1)
DEF(line_end, 1)
DEF(line_end_m, 1)
DEF(goto, 5)
DEF(split_goto_first, 5)
DEF(split_next_first, 5)
@ -42,11 +46,17 @@ DEF(loop, 5) /* decrement the top the stack and goto if != 0 */
DEF(push_i32, 5) /* push integer on the stack */
DEF(drop, 1)
DEF(word_boundary, 1)
DEF(word_boundary_i, 1)
DEF(not_word_boundary, 1)
DEF(not_word_boundary_i, 1)
DEF(back_reference, 2)
DEF(backward_back_reference, 2) /* must come after back_reference */
DEF(back_reference_i, 2) /* must come after */
DEF(backward_back_reference, 2) /* must come after */
DEF(backward_back_reference_i, 2) /* must come after */
DEF(range, 3) /* variable length */
DEF(range_i, 3) /* variable length */
DEF(range32, 3) /* variable length */
DEF(range32_i, 3) /* variable length */
DEF(lookahead, 5)
DEF(negative_lookahead, 5)
DEF(push_char_pos, 1) /* push the character position on the stack */

File diff suppressed because it is too large Load Diff

View File

@ -35,6 +35,7 @@
#define LRE_FLAG_STICKY (1 << 5)
#define LRE_FLAG_INDICES (1 << 6) /* Unused by libregexp, just recorded. */
#define LRE_FLAG_NAMED_GROUPS (1 << 7) /* named groups are present in the regexp */
#define LRE_FLAG_UNICODE_SETS (1 << 8)
#define LRE_RET_MEMORY_ERROR (-1)
#define LRE_RET_TIMEOUT (-2)

View File

@ -3130,6 +3130,7 @@ typedef enum {
} UnicodeScriptEnum;
static const char unicode_script_name_table[] =
"Unknown,Zzzz" "\0"
"Adlam,Adlm" "\0"
"Ahom,Ahom" "\0"
"Anatolian_Hieroglyphs,Hluw" "\0"
@ -4054,6 +4055,89 @@ static const uint8_t unicode_prop_Changes_When_NFKC_Casefolded1_table[450] = {
0x4f, 0xff,
};
static const uint8_t unicode_prop_Basic_Emoji1_table[143] = {
0x60, 0x23, 0x19, 0x81, 0x40, 0xcc, 0x1a, 0x01,
0x80, 0x42, 0x08, 0x81, 0x94, 0x81, 0xb1, 0x8b,
0xaa, 0x80, 0x92, 0x80, 0x8c, 0x07, 0x81, 0x90,
0x0c, 0x0f, 0x04, 0x80, 0x94, 0x06, 0x08, 0x03,
0x01, 0x06, 0x03, 0x81, 0x9b, 0x80, 0xa2, 0x00,
0x03, 0x10, 0x80, 0xbc, 0x82, 0x97, 0x80, 0x8d,
0x80, 0x43, 0x5a, 0x81, 0xb2, 0x03, 0x80, 0x61,
0xc4, 0xad, 0x80, 0x40, 0xc9, 0x80, 0x40, 0xbd,
0x01, 0x89, 0xe5, 0x80, 0x97, 0x80, 0x93, 0x01,
0x20, 0x82, 0x94, 0x81, 0x40, 0xad, 0xa0, 0x8b,
0x88, 0x80, 0xc5, 0x80, 0x95, 0x8b, 0xaa, 0x1c,
0x8b, 0x90, 0x10, 0x82, 0xc6, 0x00, 0x80, 0x40,
0xba, 0x81, 0xbe, 0x8c, 0x18, 0x97, 0x91, 0x80,
0x99, 0x81, 0x8c, 0x80, 0xd5, 0xd4, 0xaf, 0xc5,
0x28, 0x12, 0x0a, 0x1b, 0x8a, 0x0e, 0x88, 0x40,
0xe2, 0x8b, 0x18, 0x41, 0x1a, 0xae, 0x80, 0x89,
0x80, 0x40, 0xb8, 0xef, 0x8c, 0x82, 0x89, 0x84,
0xb7, 0x86, 0x8e, 0x81, 0x8a, 0x85, 0x88,
};
static const uint8_t unicode_prop_Basic_Emoji2_table[183] = {
0x40, 0xa8, 0x03, 0x80, 0x5f, 0x8c, 0x80, 0x8b,
0x80, 0x40, 0xd7, 0x80, 0x95, 0x80, 0xd9, 0x85,
0x8e, 0x81, 0x41, 0x7c, 0x80, 0x40, 0xa5, 0x80,
0x9c, 0x10, 0x0c, 0x82, 0x40, 0xc6, 0x80, 0x40,
0xe6, 0x81, 0x89, 0x80, 0x88, 0x80, 0xb9, 0x0a,
0x84, 0x88, 0x01, 0x05, 0x03, 0x01, 0x00, 0x09,
0x02, 0x02, 0x0f, 0x14, 0x00, 0x80, 0x9b, 0x09,
0x00, 0x08, 0x80, 0x91, 0x01, 0x80, 0x92, 0x00,
0x18, 0x00, 0x0a, 0x05, 0x07, 0x81, 0x95, 0x05,
0x00, 0x00, 0x80, 0x94, 0x05, 0x09, 0x01, 0x17,
0x04, 0x09, 0x08, 0x01, 0x00, 0x00, 0x05, 0x02,
0x80, 0x90, 0x81, 0x8e, 0x01, 0x80, 0x9a, 0x81,
0xbb, 0x80, 0x41, 0x91, 0x81, 0x41, 0xce, 0x82,
0x45, 0x27, 0x80, 0x8b, 0x80, 0x42, 0x58, 0x00,
0x80, 0x61, 0xbe, 0xd5, 0x81, 0x8b, 0x81, 0x40,
0x81, 0x80, 0xb3, 0x80, 0x40, 0xe8, 0x01, 0x88,
0x88, 0x80, 0xc5, 0x80, 0x97, 0x08, 0x11, 0x81,
0xaa, 0x1c, 0x8b, 0x92, 0x00, 0x00, 0x80, 0xc6,
0x00, 0x80, 0x40, 0xba, 0x80, 0xca, 0x81, 0xa3,
0x09, 0x86, 0x8c, 0x01, 0x19, 0x80, 0x93, 0x01,
0x07, 0x81, 0x88, 0x04, 0x82, 0x8b, 0x17, 0x11,
0x00, 0x03, 0x05, 0x02, 0x05, 0x80, 0x40, 0xcf,
0x00, 0x82, 0x8f, 0x2a, 0x05, 0x01, 0x80,
};
static const uint8_t unicode_prop_RGI_Emoji_Modifier_Sequence_table[73] = {
0x60, 0x26, 0x1c, 0x80, 0x40, 0xda, 0x80, 0x8f,
0x83, 0x61, 0xcc, 0x76, 0x80, 0xbb, 0x11, 0x01,
0x82, 0xf4, 0x09, 0x8a, 0x94, 0x18, 0x18, 0x88,
0x10, 0x1a, 0x02, 0x30, 0x00, 0x97, 0x80, 0x40,
0xc8, 0x0b, 0x80, 0x94, 0x03, 0x81, 0x40, 0xad,
0x12, 0x84, 0xd2, 0x80, 0x8f, 0x82, 0x88, 0x80,
0x8a, 0x80, 0x42, 0x3e, 0x01, 0x07, 0x3d, 0x80,
0x88, 0x89, 0x11, 0xb7, 0x80, 0xbc, 0x08, 0x08,
0x80, 0x90, 0x10, 0x8c, 0x40, 0xe4, 0x82, 0xa9,
0x88,
};
static const uint8_t unicode_prop_RGI_Emoji_Flag_Sequence_table[128] = {
0x0c, 0x00, 0x09, 0x00, 0x04, 0x01, 0x02, 0x06,
0x03, 0x03, 0x01, 0x02, 0x01, 0x03, 0x07, 0x0d,
0x18, 0x00, 0x09, 0x00, 0x00, 0x89, 0x08, 0x00,
0x00, 0x81, 0x88, 0x83, 0x8c, 0x10, 0x00, 0x01,
0x07, 0x08, 0x29, 0x10, 0x28, 0x00, 0x80, 0x8a,
0x00, 0x0a, 0x00, 0x0e, 0x15, 0x18, 0x83, 0x89,
0x06, 0x00, 0x81, 0x8d, 0x00, 0x12, 0x08, 0x00,
0x03, 0x00, 0x24, 0x00, 0x05, 0x21, 0x00, 0x00,
0x29, 0x90, 0x00, 0x02, 0x00, 0x08, 0x09, 0x00,
0x08, 0x18, 0x8b, 0x80, 0x8c, 0x02, 0x19, 0x1a,
0x11, 0x00, 0x00, 0x80, 0x9c, 0x80, 0x88, 0x02,
0x00, 0x00, 0x02, 0x20, 0x88, 0x0a, 0x00, 0x03,
0x01, 0x02, 0x05, 0x08, 0x00, 0x01, 0x09, 0x20,
0x21, 0x18, 0x22, 0x00, 0x00, 0x00, 0x00, 0x18,
0x28, 0x89, 0x80, 0x8b, 0x80, 0x90, 0x80, 0x92,
0x80, 0x8d, 0x05, 0x80, 0x8a, 0x80, 0x88, 0x80,
};
static const uint8_t unicode_prop_Emoji_Keycap_Sequence_table[4] = {
0xa2, 0x05, 0x04, 0x89,
};
static const uint8_t unicode_prop_ASCII_Hex_Digit_table[5] = {
0xaf, 0x89, 0x35, 0x99, 0x85,
};
@ -4493,6 +4577,11 @@ typedef enum {
UNICODE_PROP_Changes_When_Titlecased1,
UNICODE_PROP_Changes_When_Casefolded1,
UNICODE_PROP_Changes_When_NFKC_Casefolded1,
UNICODE_PROP_Basic_Emoji1,
UNICODE_PROP_Basic_Emoji2,
UNICODE_PROP_RGI_Emoji_Modifier_Sequence,
UNICODE_PROP_RGI_Emoji_Flag_Sequence,
UNICODE_PROP_Emoji_Keycap_Sequence,
UNICODE_PROP_ASCII_Hex_Digit,
UNICODE_PROP_Bidi_Control,
UNICODE_PROP_Dash,
@ -4633,6 +4722,11 @@ static const uint8_t * const unicode_prop_table[] = {
unicode_prop_Changes_When_Titlecased1_table,
unicode_prop_Changes_When_Casefolded1_table,
unicode_prop_Changes_When_NFKC_Casefolded1_table,
unicode_prop_Basic_Emoji1_table,
unicode_prop_Basic_Emoji2_table,
unicode_prop_RGI_Emoji_Modifier_Sequence_table,
unicode_prop_RGI_Emoji_Flag_Sequence_table,
unicode_prop_Emoji_Keycap_Sequence_table,
unicode_prop_ASCII_Hex_Digit_table,
unicode_prop_Bidi_Control_table,
unicode_prop_Dash_table,
@ -4688,6 +4782,11 @@ static const uint16_t unicode_prop_len_table[] = {
countof(unicode_prop_Changes_When_Titlecased1_table),
countof(unicode_prop_Changes_When_Casefolded1_table),
countof(unicode_prop_Changes_When_NFKC_Casefolded1_table),
countof(unicode_prop_Basic_Emoji1_table),
countof(unicode_prop_Basic_Emoji2_table),
countof(unicode_prop_RGI_Emoji_Modifier_Sequence_table),
countof(unicode_prop_RGI_Emoji_Flag_Sequence_table),
countof(unicode_prop_Emoji_Keycap_Sequence_table),
countof(unicode_prop_ASCII_Hex_Digit_table),
countof(unicode_prop_Bidi_Control_table),
countof(unicode_prop_Dash_table),
@ -4726,5 +4825,325 @@ static const uint16_t unicode_prop_len_table[] = {
countof(unicode_prop_Case_Ignorable_table),
};
typedef enum {
UNICODE_SEQUENCE_PROP_Basic_Emoji,
UNICODE_SEQUENCE_PROP_Emoji_Keycap_Sequence,
UNICODE_SEQUENCE_PROP_RGI_Emoji_Modifier_Sequence,
UNICODE_SEQUENCE_PROP_RGI_Emoji_Flag_Sequence,
UNICODE_SEQUENCE_PROP_RGI_Emoji_Tag_Sequence,
UNICODE_SEQUENCE_PROP_RGI_Emoji_ZWJ_Sequence,
UNICODE_SEQUENCE_PROP_RGI_Emoji,
UNICODE_SEQUENCE_PROP_COUNT,
} UnicodeSequencePropertyEnum;
static const char unicode_sequence_prop_name_table[] =
"Basic_Emoji" "\0"
"Emoji_Keycap_Sequence" "\0"
"RGI_Emoji_Modifier_Sequence" "\0"
"RGI_Emoji_Flag_Sequence" "\0"
"RGI_Emoji_Tag_Sequence" "\0"
"RGI_Emoji_ZWJ_Sequence" "\0"
"RGI_Emoji" "\0"
;
static const uint8_t unicode_rgi_emoji_tag_sequence[18] = {
0x67, 0x62, 0x65, 0x6e, 0x67, 0x00, 0x67, 0x62,
0x73, 0x63, 0x74, 0x00, 0x67, 0x62, 0x77, 0x6c,
0x73, 0x00,
};
static const uint8_t unicode_rgi_emoji_zwj_sequence[2320] = {
0x02, 0xb8, 0x19, 0x40, 0x86, 0x02, 0xd1, 0x39,
0xb0, 0x19, 0x02, 0x26, 0x39, 0x42, 0x86, 0x02,
0xb4, 0x36, 0x42, 0x86, 0x03, 0x68, 0x54, 0x64,
0x87, 0x68, 0x54, 0x02, 0xdc, 0x39, 0x42, 0x86,
0x02, 0xd1, 0x39, 0x73, 0x13, 0x02, 0x39, 0x39,
0x40, 0x86, 0x02, 0x69, 0x34, 0xbd, 0x19, 0x03,
0xb6, 0x36, 0x40, 0x86, 0xa1, 0x87, 0x03, 0x68,
0x74, 0x1d, 0x19, 0x68, 0x74, 0x03, 0x68, 0x34,
0xbd, 0x19, 0xa1, 0x87, 0x02, 0xf1, 0x7a, 0xf2,
0x7a, 0x02, 0xca, 0x33, 0x42, 0x86, 0x02, 0x69,
0x34, 0xb0, 0x19, 0x04, 0x68, 0x14, 0x68, 0x14,
0x67, 0x14, 0x66, 0x14, 0x02, 0xf9, 0x26, 0x42,
0x86, 0x03, 0x69, 0x74, 0x1d, 0x19, 0x69, 0x74,
0x03, 0xd1, 0x19, 0xbc, 0x19, 0xa1, 0x87, 0x02,
0x3c, 0x19, 0x40, 0x86, 0x02, 0x68, 0x34, 0xeb,
0x13, 0x02, 0xc3, 0x33, 0xa1, 0x87, 0x02, 0x70,
0x34, 0x40, 0x86, 0x02, 0xd4, 0x39, 0x42, 0x86,
0x02, 0xcf, 0x39, 0x42, 0x86, 0x02, 0x47, 0x36,
0x40, 0x86, 0x02, 0x39, 0x39, 0x42, 0x86, 0x04,
0xd1, 0x79, 0x64, 0x87, 0x8b, 0x14, 0xd1, 0x79,
0x02, 0xd1, 0x39, 0x95, 0x86, 0x02, 0x68, 0x34,
0x93, 0x13, 0x02, 0x69, 0x34, 0xed, 0x13, 0x02,
0xda, 0x39, 0x40, 0x86, 0x03, 0x69, 0x34, 0xaf,
0x19, 0xa1, 0x87, 0x02, 0xd1, 0x39, 0x93, 0x13,
0x03, 0xce, 0x39, 0x42, 0x86, 0xa1, 0x87, 0x03,
0xd1, 0x79, 0x64, 0x87, 0xd1, 0x79, 0x03, 0xc3,
0x33, 0x42, 0x86, 0xa1, 0x87, 0x03, 0x69, 0x74,
0x1d, 0x19, 0x68, 0x74, 0x02, 0x69, 0x34, 0x92,
0x16, 0x02, 0xd1, 0x39, 0x96, 0x86, 0x04, 0x69,
0x14, 0x64, 0x87, 0x8b, 0x14, 0x68, 0x14, 0x02,
0x68, 0x34, 0x7c, 0x13, 0x02, 0x47, 0x36, 0x42,
0x86, 0x02, 0x86, 0x34, 0x42, 0x86, 0x02, 0xd1,
0x39, 0x7c, 0x13, 0x02, 0x69, 0x14, 0xa4, 0x13,
0x02, 0xda, 0x39, 0x42, 0x86, 0x02, 0x37, 0x39,
0x40, 0x86, 0x02, 0xd1, 0x39, 0x08, 0x87, 0x04,
0x68, 0x54, 0x64, 0x87, 0x8b, 0x14, 0x68, 0x54,
0x02, 0x4d, 0x36, 0x40, 0x86, 0x02, 0x68, 0x34,
0x2c, 0x15, 0x02, 0x69, 0x34, 0xaf, 0x19, 0x02,
0x6e, 0x34, 0x40, 0x86, 0x02, 0xcd, 0x39, 0x42,
0x86, 0x02, 0xd1, 0x39, 0x2c, 0x15, 0x02, 0x6f,
0x14, 0x40, 0x86, 0x03, 0xd1, 0x39, 0xbc, 0x19,
0xa1, 0x87, 0x02, 0x68, 0x34, 0xa8, 0x13, 0x02,
0x69, 0x34, 0x73, 0x13, 0x04, 0x69, 0x54, 0x64,
0x87, 0x8b, 0x14, 0x68, 0x54, 0x02, 0x71, 0x34,
0x42, 0x86, 0x02, 0xd1, 0x39, 0xa8, 0x13, 0x02,
0x45, 0x36, 0x40, 0x86, 0x03, 0x69, 0x54, 0x64,
0x87, 0x68, 0x54, 0x03, 0x69, 0x54, 0x64, 0x87,
0x69, 0x54, 0x03, 0xce, 0x39, 0x40, 0x86, 0xa1,
0x87, 0x02, 0xd8, 0x39, 0x40, 0x86, 0x03, 0xc3,
0x33, 0x40, 0x86, 0xa1, 0x87, 0x02, 0x4d, 0x36,
0x42, 0x86, 0x02, 0xd1, 0x19, 0x92, 0x16, 0x02,
0xd1, 0x39, 0xeb, 0x13, 0x02, 0x68, 0x34, 0xbc,
0x14, 0x02, 0xd1, 0x39, 0xbc, 0x14, 0x02, 0x3d,
0x39, 0x40, 0x86, 0x02, 0xb8, 0x39, 0x42, 0x86,
0x02, 0xa3, 0x36, 0x40, 0x86, 0x02, 0x75, 0x35,
0x40, 0x86, 0x02, 0xd8, 0x39, 0x42, 0x86, 0x02,
0x69, 0x34, 0x93, 0x13, 0x02, 0x35, 0x39, 0x40,
0x86, 0x02, 0x4b, 0x36, 0x40, 0x86, 0x02, 0x3d,
0x39, 0x42, 0x86, 0x02, 0x38, 0x39, 0x42, 0x86,
0x02, 0xa3, 0x36, 0x42, 0x86, 0x03, 0x69, 0x14,
0x67, 0x14, 0x67, 0x14, 0x02, 0xb6, 0x36, 0x40,
0x86, 0x02, 0x69, 0x34, 0x7c, 0x13, 0x02, 0x75,
0x35, 0x42, 0x86, 0x02, 0xcc, 0x93, 0x40, 0x86,
0x02, 0xcc, 0x33, 0x40, 0x86, 0x03, 0xd1, 0x39,
0xbd, 0x19, 0xa1, 0x87, 0x02, 0x82, 0x34, 0x40,
0x86, 0x02, 0x87, 0x34, 0x40, 0x86, 0x02, 0x69,
0x14, 0x3e, 0x13, 0x02, 0xd6, 0x39, 0x40, 0x86,
0x02, 0x68, 0x14, 0xbd, 0x19, 0x02, 0x46, 0x36,
0x42, 0x86, 0x02, 0x4b, 0x36, 0x42, 0x86, 0x02,
0x69, 0x34, 0x2c, 0x15, 0x03, 0xb6, 0x36, 0x42,
0x86, 0xa1, 0x87, 0x02, 0xc4, 0x33, 0x40, 0x86,
0x02, 0x26, 0x19, 0x40, 0x86, 0x02, 0x69, 0x14,
0xb0, 0x19, 0x02, 0xde, 0x19, 0x42, 0x86, 0x02,
0x69, 0x34, 0xa8, 0x13, 0x02, 0xcc, 0x33, 0x42,
0x86, 0x02, 0x82, 0x34, 0x42, 0x86, 0x02, 0xd1,
0x19, 0x93, 0x13, 0x02, 0x81, 0x14, 0x42, 0x86,
0x02, 0x69, 0x34, 0x95, 0x86, 0x02, 0x68, 0x34,
0xbb, 0x14, 0x02, 0xd1, 0x39, 0xbb, 0x14, 0x02,
0x69, 0x34, 0xeb, 0x13, 0x02, 0xd1, 0x39, 0x84,
0x13, 0x02, 0x69, 0x34, 0xbc, 0x14, 0x04, 0x69,
0x54, 0x64, 0x87, 0x8b, 0x14, 0x69, 0x54, 0x02,
0x26, 0x39, 0x40, 0x86, 0x02, 0xb4, 0x36, 0x40,
0x86, 0x02, 0x47, 0x16, 0x42, 0x86, 0x02, 0xdc,
0x39, 0x40, 0x86, 0x02, 0xca, 0x33, 0x40, 0x86,
0x02, 0xf9, 0x26, 0x40, 0x86, 0x02, 0x69, 0x34,
0x08, 0x87, 0x03, 0x69, 0x14, 0x69, 0x14, 0x66,
0x14, 0x03, 0xd1, 0x59, 0x1d, 0x19, 0xd1, 0x59,
0x02, 0xd4, 0x39, 0x40, 0x86, 0x02, 0xcf, 0x39,
0x40, 0x86, 0x02, 0x68, 0x34, 0xa4, 0x13, 0x02,
0xd1, 0x39, 0xa4, 0x13, 0x02, 0xd1, 0x19, 0xa8,
0x13, 0x02, 0xd7, 0x39, 0x42, 0x86, 0x03, 0x69,
0x34, 0xbc, 0x19, 0xa1, 0x87, 0x02, 0x68, 0x14,
0xb0, 0x19, 0x02, 0x68, 0x14, 0x73, 0x13, 0x04,
0x69, 0x14, 0x69, 0x14, 0x66, 0x14, 0x66, 0x14,
0x03, 0x68, 0x34, 0xaf, 0x19, 0xa1, 0x87, 0x02,
0x68, 0x34, 0x80, 0x16, 0x02, 0x73, 0x34, 0x42,
0x86, 0x02, 0xd1, 0x39, 0x80, 0x16, 0x02, 0x68,
0x34, 0xb0, 0x19, 0x02, 0x86, 0x34, 0x40, 0x86,
0x02, 0x38, 0x19, 0x42, 0x86, 0x02, 0x69, 0x34,
0xbb, 0x14, 0x02, 0xb5, 0x36, 0x42, 0x86, 0x02,
0xcd, 0x39, 0x40, 0x86, 0x02, 0x68, 0x34, 0x95,
0x86, 0x02, 0x68, 0x34, 0x27, 0x15, 0x03, 0x68,
0x14, 0x68, 0x14, 0x66, 0x14, 0x02, 0x71, 0x34,
0x40, 0x86, 0x02, 0xd1, 0x39, 0x27, 0x15, 0x02,
0x2e, 0x16, 0xa8, 0x14, 0x02, 0xc3, 0x33, 0x42,
0x86, 0x02, 0x69, 0x14, 0x66, 0x14, 0x02, 0x68,
0x34, 0x96, 0x86, 0x02, 0x69, 0x34, 0xa4, 0x13,
0x03, 0x69, 0x14, 0x64, 0x87, 0x68, 0x14, 0x02,
0xb8, 0x39, 0x40, 0x86, 0x02, 0x68, 0x34, 0x3e,
0x13, 0x03, 0xd1, 0x19, 0xaf, 0x19, 0xa1, 0x87,
0x02, 0xd1, 0x39, 0x3e, 0x13, 0x02, 0x68, 0x34,
0xbd, 0x19, 0x02, 0xd1, 0x19, 0xbb, 0x14, 0x02,
0xd1, 0x19, 0x95, 0x86, 0x02, 0xdb, 0x39, 0x42,
0x86, 0x02, 0x38, 0x39, 0x40, 0x86, 0x02, 0x69,
0x34, 0x80, 0x16, 0x02, 0x69, 0x14, 0xeb, 0x13,
0x04, 0x68, 0x14, 0x69, 0x14, 0x67, 0x14, 0x67,
0x14, 0x02, 0x77, 0x34, 0x42, 0x86, 0x02, 0x46,
0x36, 0x40, 0x86, 0x02, 0x68, 0x34, 0x92, 0x16,
0x02, 0x4e, 0x36, 0x42, 0x86, 0x03, 0x69, 0x14,
0xbd, 0x19, 0xa1, 0x87, 0x02, 0xde, 0x19, 0x40,
0x86, 0x02, 0x69, 0x34, 0x27, 0x15, 0x03, 0xc3,
0x13, 0x40, 0x86, 0xa1, 0x87, 0x02, 0x81, 0x14,
0x40, 0x86, 0x03, 0xd1, 0x39, 0xaf, 0x19, 0xa1,
0x87, 0x02, 0x68, 0x34, 0xbc, 0x19, 0x02, 0xd1,
0x19, 0x80, 0x16, 0x02, 0xd9, 0x39, 0x42, 0x86,
0x02, 0xd1, 0x39, 0xbc, 0x19, 0x02, 0xdc, 0x19,
0x42, 0x86, 0x02, 0x68, 0x34, 0x73, 0x13, 0x02,
0x69, 0x34, 0x3e, 0x13, 0x02, 0x47, 0x16, 0x40,
0x86, 0x02, 0xd1, 0x39, 0xbd, 0x19, 0x02, 0x3e,
0x39, 0x42, 0x86, 0x02, 0x69, 0x14, 0x95, 0x86,
0x02, 0x68, 0x14, 0x96, 0x86, 0x03, 0x69, 0x34,
0xbd, 0x19, 0xa1, 0x87, 0x02, 0xd7, 0x39, 0x40,
0x86, 0x02, 0x45, 0x16, 0x42, 0x86, 0x02, 0x68,
0x34, 0xed, 0x13, 0x03, 0x68, 0x34, 0xbc, 0x19,
0xa1, 0x87, 0x02, 0xd1, 0x39, 0xed, 0x13, 0x02,
0xd1, 0x39, 0x92, 0x16, 0x02, 0x73, 0x34, 0x40,
0x86, 0x02, 0x38, 0x19, 0x40, 0x86, 0x02, 0xb5,
0x36, 0x40, 0x86, 0x02, 0x68, 0x34, 0xaf, 0x19,
0x02, 0xd1, 0x39, 0xaf, 0x19, 0x02, 0x69, 0x34,
0xbc, 0x19, 0x02, 0xb6, 0x16, 0x42, 0x86, 0x02,
0x26, 0x14, 0x25, 0x15, 0x02, 0xc3, 0x33, 0x40,
0x86, 0x02, 0xdd, 0x39, 0x42, 0x86, 0x02, 0xcb,
0x93, 0x42, 0x86, 0x02, 0xcb, 0x33, 0x42, 0x86,
0x02, 0x81, 0x34, 0x42, 0x86, 0x02, 0xce, 0x39,
0xa1, 0x87, 0x02, 0xdb, 0x39, 0x40, 0x86, 0x02,
0x68, 0x34, 0x08, 0x87, 0x02, 0xd1, 0x19, 0xb0,
0x19, 0x02, 0x77, 0x34, 0x40, 0x86, 0x02, 0x4e,
0x36, 0x40, 0x86, 0x02, 0xce, 0x39, 0x42, 0x86,
0x02, 0x4e, 0x16, 0x42, 0x86, 0x02, 0xd9, 0x39,
0x40, 0x86, 0x02, 0xdc, 0x19, 0x40, 0x86, 0x02,
0x3e, 0x39, 0x40, 0x86, 0x02, 0xb9, 0x39, 0x42,
0x86, 0x02, 0xda, 0x19, 0x42, 0x86, 0x02, 0x42,
0x16, 0x94, 0x81, 0x02, 0x45, 0x16, 0x40, 0x86,
0x02, 0x69, 0x14, 0xbd, 0x19, 0x02, 0x70, 0x34,
0x42, 0x86, 0x02, 0xce, 0x19, 0xa1, 0x87, 0x02,
0xc3, 0x13, 0x42, 0x86, 0x02, 0x68, 0x14, 0x08,
0x87, 0x02, 0xd1, 0x19, 0x7c, 0x13, 0x02, 0x68,
0x14, 0x92, 0x16, 0x02, 0xb6, 0x16, 0x40, 0x86,
0x02, 0x37, 0x39, 0x42, 0x86, 0x03, 0xce, 0x19,
0x42, 0x86, 0xa1, 0x87, 0x03, 0x68, 0x14, 0x67,
0x14, 0x67, 0x14, 0x02, 0xdd, 0x39, 0x40, 0x86,
0x02, 0xcf, 0x19, 0x42, 0x86, 0x02, 0xd1, 0x19,
0x2c, 0x15, 0x02, 0x4b, 0x13, 0xe9, 0x17, 0x02,
0x68, 0x14, 0x67, 0x14, 0x02, 0xcb, 0x93, 0x40,
0x86, 0x02, 0x6e, 0x34, 0x42, 0x86, 0x02, 0xcb,
0x33, 0x40, 0x86, 0x02, 0x81, 0x34, 0x40, 0x86,
0x02, 0xb6, 0x36, 0xa1, 0x87, 0x02, 0x45, 0x36,
0x42, 0x86, 0x02, 0xb4, 0x16, 0x42, 0x86, 0x02,
0x69, 0x14, 0x73, 0x13, 0x04, 0x69, 0x14, 0x69,
0x14, 0x67, 0x14, 0x66, 0x14, 0x02, 0x35, 0x39,
0x42, 0x86, 0x02, 0x68, 0x14, 0x93, 0x13, 0x02,
0xb6, 0x36, 0x42, 0x86, 0x03, 0x68, 0x14, 0x69,
0x14, 0x66, 0x14, 0x02, 0xce, 0x39, 0x40, 0x86,
0x02, 0x4e, 0x16, 0x40, 0x86, 0x02, 0x87, 0x34,
0x42, 0x86, 0x02, 0x86, 0x14, 0x42, 0x86, 0x02,
0xd6, 0x39, 0x42, 0x86, 0x02, 0xc4, 0x33, 0x42,
0x86, 0x02, 0x69, 0x34, 0x96, 0x86, 0x02, 0xb9,
0x39, 0x40, 0x86, 0x02, 0x68, 0x14, 0xa8, 0x13,
0x02, 0xd1, 0x19, 0x84, 0x13, 0x02, 0xda, 0x19,
0x40, 0x86, 0x02, 0xd8, 0x19, 0x42, 0x86, 0x02,
0xc3, 0x13, 0x40, 0x86, 0x02, 0xb9, 0x19, 0x42,
0x86, 0x02, 0x3d, 0x19, 0x42, 0x86, 0x02, 0xcf,
0x19, 0x40, 0x86, 0x04, 0x68, 0x14, 0x68, 0x14,
0x67, 0x14, 0x67, 0x14, 0x03, 0xd1, 0x19, 0xd1,
0x19, 0xd2, 0x19, 0x02, 0x68, 0x14, 0xbb, 0x14,
0x02, 0x3b, 0x14, 0x44, 0x87, 0x02, 0xd1, 0x19,
0x27, 0x15, 0x02, 0xb4, 0x16, 0x40, 0x86, 0x02,
0xcd, 0x19, 0x42, 0x86, 0x02, 0xd3, 0x86, 0xa5,
0x14, 0x02, 0x70, 0x14, 0x42, 0x86, 0x03, 0xb6,
0x16, 0x42, 0x86, 0xa1, 0x87, 0x04, 0x69, 0x14,
0x64, 0x87, 0x8b, 0x14, 0x69, 0x14, 0x02, 0x36,
0x16, 0x2b, 0x93, 0x02, 0x68, 0x14, 0x80, 0x16,
0x02, 0x86, 0x14, 0x40, 0x86, 0x02, 0x08, 0x14,
0x1b, 0x0b, 0x02, 0xd1, 0x19, 0xbc, 0x19, 0x02,
0xca, 0x13, 0x42, 0x86, 0x02, 0x41, 0x94, 0xe8,
0x95, 0x02, 0xd8, 0x19, 0x40, 0x86, 0x02, 0xb9,
0x19, 0x40, 0x86, 0x02, 0xd1, 0x19, 0xed, 0x13,
0x02, 0xf9, 0x86, 0x42, 0x86, 0x03, 0xd1, 0x19,
0xbd, 0x19, 0xa1, 0x87, 0x02, 0x3d, 0x19, 0x40,
0x86, 0x02, 0xd6, 0x19, 0x42, 0x86, 0x03, 0x69,
0x14, 0x66, 0x14, 0x66, 0x14, 0x02, 0xd1, 0x19,
0xaf, 0x19, 0x03, 0x69, 0x14, 0x69, 0x14, 0x67,
0x14, 0x02, 0xcd, 0x19, 0x40, 0x86, 0x02, 0x70,
0x14, 0x40, 0x86, 0x03, 0x68, 0x14, 0xbc, 0x19,
0xa1, 0x87, 0x02, 0x6e, 0x14, 0x42, 0x86, 0x02,
0x69, 0x14, 0x92, 0x16, 0x03, 0x68, 0x14, 0x68,
0x14, 0x67, 0x14, 0x02, 0x69, 0x14, 0x67, 0x14,
0x02, 0x75, 0x95, 0x42, 0x86, 0x03, 0x69, 0x14,
0x64, 0x87, 0x69, 0x14, 0x02, 0xd1, 0x19, 0xbc,
0x14, 0x02, 0xdf, 0x19, 0x42, 0x86, 0x02, 0xca,
0x13, 0x40, 0x86, 0x02, 0x82, 0x14, 0x42, 0x86,
0x02, 0x69, 0x14, 0x93, 0x13, 0x02, 0x68, 0x14,
0x7c, 0x13, 0x02, 0xf9, 0x86, 0x40, 0x86, 0x02,
0xd6, 0x19, 0x40, 0x86, 0x02, 0x68, 0x14, 0x2c,
0x15, 0x02, 0x69, 0x14, 0xa8, 0x13, 0x02, 0xd4,
0x19, 0x42, 0x86, 0x04, 0x68, 0x14, 0x69, 0x14,
0x66, 0x14, 0x66, 0x14, 0x02, 0x77, 0x14, 0x42,
0x86, 0x02, 0x39, 0x19, 0x42, 0x86, 0x02, 0xd1,
0x19, 0xa4, 0x13, 0x02, 0x6e, 0x14, 0x40, 0x86,
0x03, 0xd1, 0x19, 0xd2, 0x19, 0xd2, 0x19, 0x02,
0x69, 0x14, 0xbb, 0x14, 0x02, 0xd1, 0x19, 0x96,
0x86, 0x02, 0x75, 0x95, 0x40, 0x86, 0x04, 0x68,
0x14, 0x64, 0x87, 0x8b, 0x14, 0x68, 0x14, 0x02,
0xd1, 0x19, 0x3e, 0x13, 0x02, 0xdf, 0x19, 0x40,
0x86, 0x02, 0x82, 0x14, 0x40, 0x86, 0x02, 0x44,
0x13, 0xeb, 0x17, 0x02, 0xdd, 0x19, 0x42, 0x86,
0x02, 0x69, 0x14, 0x80, 0x16, 0x03, 0x68, 0x14,
0xaf, 0x19, 0xa1, 0x87, 0x02, 0xa3, 0x16, 0x42,
0x86, 0x02, 0x69, 0x14, 0x96, 0x86, 0x02, 0x46,
0x16, 0x42, 0x86, 0x02, 0xb6, 0x16, 0xa1, 0x87,
0x02, 0x68, 0x14, 0x27, 0x15, 0x02, 0x26, 0x14,
0x1b, 0x0b, 0x02, 0xd4, 0x19, 0x40, 0x86, 0x02,
0x77, 0x14, 0x40, 0x86, 0x02, 0x39, 0x19, 0x40,
0x86, 0x02, 0x37, 0x19, 0x42, 0x86, 0x03, 0x69,
0x14, 0x67, 0x14, 0x66, 0x14, 0x03, 0xc3, 0x13,
0x42, 0x86, 0xa1, 0x87, 0x02, 0x68, 0x14, 0xbc,
0x19, 0x02, 0xd1, 0x19, 0xeb, 0x13, 0x04, 0x69,
0x14, 0x69, 0x14, 0x67, 0x14, 0x67, 0x14, 0x02,
0xd1, 0x19, 0x08, 0x87, 0x02, 0x68, 0x14, 0xed,
0x13, 0x03, 0x69, 0x14, 0xbc, 0x19, 0xa1, 0x87,
0x02, 0xdd, 0x19, 0x40, 0x86, 0x02, 0xc3, 0x13,
0xa1, 0x87, 0x03, 0x68, 0x14, 0x66, 0x14, 0x66,
0x14, 0x03, 0x68, 0x14, 0x69, 0x14, 0x67, 0x14,
0x02, 0xa3, 0x16, 0x40, 0x86, 0x02, 0xdb, 0x19,
0x42, 0x86, 0x02, 0x68, 0x14, 0xaf, 0x19, 0x02,
0x46, 0x16, 0x40, 0x86, 0x02, 0x35, 0x16, 0xab,
0x14, 0x02, 0x68, 0x14, 0x95, 0x86, 0x02, 0x42,
0x16, 0x95, 0x81, 0x02, 0xc4, 0x13, 0x42, 0x86,
0x02, 0x15, 0x14, 0xba, 0x19, 0x02, 0x69, 0x14,
0x08, 0x87, 0x03, 0xd1, 0x19, 0x1d, 0x19, 0xd1,
0x19, 0x02, 0x69, 0x14, 0x7c, 0x13, 0x02, 0x37,
0x19, 0x40, 0x86, 0x02, 0x73, 0x14, 0x42, 0x86,
0x02, 0x69, 0x14, 0x2c, 0x15, 0x02, 0xb5, 0x16,
0x42, 0x86, 0x02, 0x35, 0x19, 0x42, 0x86, 0x04,
0x68, 0x14, 0x69, 0x14, 0x67, 0x14, 0x66, 0x14,
0x02, 0x64, 0x87, 0x25, 0x15, 0x02, 0x64, 0x87,
0x79, 0x1a, 0x02, 0x68, 0x14, 0xbc, 0x14, 0x03,
0xce, 0x19, 0x40, 0x86, 0xa1, 0x87, 0x02, 0x87,
0x14, 0x42, 0x86, 0x02, 0x4d, 0x16, 0x42, 0x86,
0x04, 0x68, 0x14, 0x68, 0x14, 0x66, 0x14, 0x66,
0x14, 0x02, 0xdb, 0x19, 0x40, 0x86, 0x02, 0xd9,
0x19, 0x42, 0x86, 0x02, 0xc4, 0x13, 0x40, 0x86,
0x02, 0xd1, 0x19, 0xbd, 0x19, 0x02, 0x68, 0x14,
0xa4, 0x13, 0x02, 0x3e, 0x19, 0x42, 0x86, 0x02,
0xf3, 0x93, 0xa7, 0x86, 0x03, 0x69, 0x14, 0xaf,
0x19, 0xa1, 0x87, 0x02, 0xf3, 0x93, 0x08, 0x13,
0x02, 0xd1, 0x19, 0xd2, 0x19, 0x02, 0x73, 0x14,
0x40, 0x86, 0x02, 0xb5, 0x16, 0x40, 0x86, 0x02,
0x35, 0x19, 0x40, 0x86, 0x02, 0x69, 0x14, 0x27,
0x15, 0x02, 0xce, 0x19, 0x42, 0x86, 0x02, 0x71,
0x14, 0x42, 0x86, 0x02, 0xd1, 0x19, 0x73, 0x13,
0x02, 0x68, 0x14, 0x3e, 0x13, 0x02, 0xf4, 0x13,
0x20, 0x86, 0x02, 0x87, 0x14, 0x40, 0x86, 0x03,
0xb6, 0x16, 0x40, 0x86, 0xa1, 0x87, 0x02, 0x4d,
0x16, 0x40, 0x86, 0x02, 0x69, 0x14, 0xbc, 0x19,
0x02, 0x4b, 0x16, 0x42, 0x86, 0x02, 0xd9, 0x19,
0x40, 0x86, 0x02, 0x3e, 0x19, 0x40, 0x86, 0x02,
0x69, 0x14, 0xed, 0x13, 0x02, 0xd7, 0x19, 0x42,
0x86, 0x02, 0xb8, 0x19, 0x42, 0x86, 0x03, 0x68,
0x14, 0x67, 0x14, 0x66, 0x14, 0x02, 0x3c, 0x19,
0x42, 0x86, 0x02, 0x68, 0x14, 0x66, 0x14, 0x03,
0x68, 0x14, 0x64, 0x87, 0x68, 0x14, 0x02, 0x69,
0x14, 0xaf, 0x19, 0x02, 0xce, 0x19, 0x40, 0x86,
0x02, 0x71, 0x14, 0x40, 0x86, 0x02, 0x68, 0x14,
0xeb, 0x13, 0x03, 0x68, 0x14, 0xbd, 0x19, 0xa1,
0x87, 0x02, 0x6f, 0x14, 0x42, 0x86, 0x04, 0xd1,
0x19, 0xd1, 0x19, 0xd2, 0x19, 0xd2, 0x19, 0x02,
0x69, 0x14, 0xbc, 0x14, 0x02, 0xcc, 0x93, 0x42,
0x86, 0x02, 0x4b, 0x16, 0x40, 0x86, 0x02, 0x26,
0x19, 0x42, 0x86, 0x02, 0xd7, 0x19, 0x40, 0x86,
};
#endif /* CONFIG_ALL_UNICODE */
/* 64 tables / 33442 bytes, 5 index / 351 bytes */
/* 71 tables / 36311 bytes, 5 index / 351 bytes */

View File

@ -499,6 +499,9 @@ int cr_op(CharRange *cr, const uint32_t *a_pt, int a_len,
case CR_OP_XOR:
is_in = (a_idx & 1) ^ (b_idx & 1);
break;
case CR_OP_SUB:
is_in = (a_idx & 1) & ((b_idx & 1) ^ 1);
break;
default:
abort();
}
@ -511,14 +514,14 @@ int cr_op(CharRange *cr, const uint32_t *a_pt, int a_len,
return 0;
}
int cr_union1(CharRange *cr, const uint32_t *b_pt, int b_len)
int cr_op1(CharRange *cr, const uint32_t *b_pt, int b_len, int op)
{
CharRange a = *cr;
int ret;
cr->len = 0;
cr->size = 0;
cr->points = NULL;
ret = cr_op(cr, a.points, a.len, b_pt, b_len, CR_OP_UNION);
ret = cr_op(cr, a.points, a.len, b_pt, b_len, op);
cr_free(&a);
return ret;
}
@ -1282,8 +1285,6 @@ int unicode_script(CharRange *cr,
script_idx = unicode_find_name(unicode_script_name_table, script_name);
if (script_idx < 0)
return -2;
/* Note: we remove the "Unknown" Script */
script_idx += UNICODE_SCRIPT_Unknown + 1;
is_common = (script_idx == UNICODE_SCRIPT_Common ||
script_idx == UNICODE_SCRIPT_Inherited);
@ -1313,17 +1314,21 @@ int unicode_script(CharRange *cr,
n |= *p++;
n += 96 + (1 << 12);
}
if (type == 0)
v = 0;
else
v = *p++;
c1 = c + n + 1;
if (v == script_idx) {
if (type != 0) {
v = *p++;
if (v == script_idx || script_idx == UNICODE_SCRIPT_Unknown) {
if (cr_add_interval(cr1, c, c1))
goto fail;
}
}
c = c1;
}
if (script_idx == UNICODE_SCRIPT_Unknown) {
/* Unknown is all the characters outside scripts */
if (cr_invert(cr1))
goto fail;
}
if (is_ext) {
/* add the script extensions */
@ -1554,6 +1559,7 @@ static int unicode_prop_ops(CharRange *cr, ...)
cr2 = &stack[stack_len - 1];
cr3 = &stack[stack_len++];
cr_init(cr3, cr->mem_opaque, cr->realloc_func);
/* CR_OP_XOR may be used here */
if (cr_op(cr3, cr1->points, cr1->len,
cr2->points, cr2->len, op - POP_UNION + CR_OP_UNION))
goto fail;
@ -1908,3 +1914,210 @@ BOOL lre_is_space_non_ascii(uint32_t c)
}
return FALSE;
}
#define SEQ_MAX_LEN 16
static int unicode_sequence_prop1(int seq_prop_idx, UnicodeSequencePropCB *cb, void *opaque,
CharRange *cr)
{
int i, c, j;
uint32_t seq[SEQ_MAX_LEN];
switch(seq_prop_idx) {
case UNICODE_SEQUENCE_PROP_Basic_Emoji:
if (unicode_prop1(cr, UNICODE_PROP_Basic_Emoji1) < 0)
return -1;
for(i = 0; i < cr->len; i += 2) {
for(c = cr->points[i]; c < cr->points[i + 1]; c++) {
seq[0] = c;
cb(opaque, seq, 1);
}
}
cr->len = 0;
if (unicode_prop1(cr, UNICODE_PROP_Basic_Emoji2) < 0)
return -1;
for(i = 0; i < cr->len; i += 2) {
for(c = cr->points[i]; c < cr->points[i + 1]; c++) {
seq[0] = c;
seq[1] = 0xfe0f;
cb(opaque, seq, 2);
}
}
break;
case UNICODE_SEQUENCE_PROP_RGI_Emoji_Modifier_Sequence:
if (unicode_prop1(cr, UNICODE_PROP_Emoji_Modifier_Base) < 0)
return -1;
for(i = 0; i < cr->len; i += 2) {
for(c = cr->points[i]; c < cr->points[i + 1]; c++) {
for(j = 0; j < 5; j++) {
seq[0] = c;
seq[1] = 0x1f3fb + j;
cb(opaque, seq, 2);
}
}
}
break;
case UNICODE_SEQUENCE_PROP_RGI_Emoji_Flag_Sequence:
if (unicode_prop1(cr, UNICODE_PROP_RGI_Emoji_Flag_Sequence) < 0)
return -1;
for(i = 0; i < cr->len; i += 2) {
for(c = cr->points[i]; c < cr->points[i + 1]; c++) {
int c0, c1;
c0 = c / 26;
c1 = c % 26;
seq[0] = 0x1F1E6 + c0;
seq[1] = 0x1F1E6 + c1;
cb(opaque, seq, 2);
}
}
break;
case UNICODE_SEQUENCE_PROP_RGI_Emoji_ZWJ_Sequence:
{
int len, code, pres, k, mod, mod_count, mod_pos[2], hc_pos, n_mod, n_hc, mod1;
int mod_idx, hc_idx, i0, i1;
const uint8_t *tab = unicode_rgi_emoji_zwj_sequence;
for(i = 0; i < countof(unicode_rgi_emoji_zwj_sequence);) {
len = tab[i++];
k = 0;
mod = 0;
mod_count = 0;
hc_pos = -1;
for(j = 0; j < len; j++) {
code = tab[i++];
code |= tab[i++] << 8;
pres = code >> 15;
mod1 = (code >> 13) & 3;
code &= 0x1fff;
if (code < 0x1000) {
c = code + 0x2000;
} else {
c = 0x1f000 + (code - 0x1000);
}
if (c == 0x1f9b0)
hc_pos = k;
seq[k++] = c;
if (mod1 != 0) {
assert(mod_count < 2);
mod = mod1;
mod_pos[mod_count++] = k;
seq[k++] = 0; /* will be filled later */
}
if (pres) {
seq[k++] = 0xfe0f;
}
if (j < len - 1) {
seq[k++] = 0x200d;
}
}
/* genrate all the variants */
switch(mod) {
case 1:
n_mod = 5;
break;
case 2:
n_mod = 25;
break;
case 3:
n_mod = 20;
break;
default:
n_mod = 1;
break;
}
if (hc_pos >= 0)
n_hc = 4;
else
n_hc = 1;
for(hc_idx = 0; hc_idx < n_hc; hc_idx++) {
for(mod_idx = 0; mod_idx < n_mod; mod_idx++) {
if (hc_pos >= 0)
seq[hc_pos] = 0x1f9b0 + hc_idx;
switch(mod) {
case 1:
seq[mod_pos[0]] = 0x1f3fb + mod_idx;
break;
case 2:
case 3:
i0 = mod_idx / 5;
i1 = mod_idx % 5;
/* avoid identical values */
if (mod == 3 && i0 >= i1)
i0++;
seq[mod_pos[0]] = 0x1f3fb + i0;
seq[mod_pos[1]] = 0x1f3fb + i1;
break;
default:
break;
}
#if 0
for(j = 0; j < k; j++)
printf(" %04x", seq[j]);
printf("\n");
#endif
cb(opaque, seq, k);
}
}
}
}
break;
case UNICODE_SEQUENCE_PROP_RGI_Emoji_Tag_Sequence:
{
for(i = 0; i < countof(unicode_rgi_emoji_tag_sequence);) {
j = 0;
seq[j++] = 0x1F3F4;
for(;;) {
c = unicode_rgi_emoji_tag_sequence[i++];
if (c == 0x00)
break;
seq[j++] = 0xe0000 + c;
}
seq[j++] = 0xe007f;
cb(opaque, seq, j);
}
}
break;
case UNICODE_SEQUENCE_PROP_Emoji_Keycap_Sequence:
if (unicode_prop1(cr, UNICODE_PROP_Emoji_Keycap_Sequence) < 0)
return -1;
for(i = 0; i < cr->len; i += 2) {
for(c = cr->points[i]; c < cr->points[i + 1]; c++) {
seq[0] = c;
seq[1] = 0xfe0f;
seq[2] = 0x20e3;
cb(opaque, seq, 3);
}
}
break;
case UNICODE_SEQUENCE_PROP_RGI_Emoji:
/* all prevous sequences */
for(i = UNICODE_SEQUENCE_PROP_Basic_Emoji; i <= UNICODE_SEQUENCE_PROP_RGI_Emoji_ZWJ_Sequence; i++) {
int ret;
ret = unicode_sequence_prop1(i, cb, opaque, cr);
if (ret < 0)
return ret;
cr->len = 0;
}
break;
default:
return -2;
}
return 0;
}
/* build a unicode sequence property */
/* return -2 if not found, -1 if other error. 'cr' is used as temporary memory. */
int unicode_sequence_prop(const char *prop_name, UnicodeSequencePropCB *cb, void *opaque,
CharRange *cr)
{
int seq_prop_idx;
seq_prop_idx = unicode_find_name(unicode_sequence_prop_name_table, prop_name);
if (seq_prop_idx < 0)
return -2;
return unicode_sequence_prop1(seq_prop_idx, cb, opaque, cr);
}

View File

@ -45,6 +45,7 @@ typedef enum {
CR_OP_UNION,
CR_OP_INTER,
CR_OP_XOR,
CR_OP_SUB,
} CharRangeOpEnum;
void cr_init(CharRange *cr, void *mem_opaque, void *(*realloc_func)(void *opaque, void *ptr, size_t size));
@ -73,19 +74,18 @@ static inline int cr_add_interval(CharRange *cr, uint32_t c1, uint32_t c2)
return 0;
}
int cr_union1(CharRange *cr, const uint32_t *b_pt, int b_len);
int cr_op(CharRange *cr, const uint32_t *a_pt, int a_len,
const uint32_t *b_pt, int b_len, int op);
int cr_op1(CharRange *cr, const uint32_t *b_pt, int b_len, int op);
static inline int cr_union_interval(CharRange *cr, uint32_t c1, uint32_t c2)
{
uint32_t b_pt[2];
b_pt[0] = c1;
b_pt[1] = c2 + 1;
return cr_union1(cr, b_pt, 2);
return cr_op1(cr, b_pt, 2, CR_OP_UNION);
}
int cr_op(CharRange *cr, const uint32_t *a_pt, int a_len,
const uint32_t *b_pt, int b_len, int op);
int cr_invert(CharRange *cr);
int cr_regexp_canonicalize(CharRange *cr, int is_unicode);
@ -107,6 +107,10 @@ int unicode_script(CharRange *cr, const char *script_name, int is_ext);
int unicode_general_category(CharRange *cr, const char *gc_name);
int unicode_prop(CharRange *cr, const char *prop_name);
typedef void UnicodeSequencePropCB(void *opaque, const uint32_t *buf, int len);
int unicode_sequence_prop(const char *prop_name, UnicodeSequencePropCB *cb, void *opaque,
CharRange *cr);
int lre_case_conv(uint32_t *res, uint32_t c, int conv_type);
int lre_canonicalize(uint32_t c, int is_unicode);

2
qjs.c
View File

@ -465,7 +465,7 @@ int main(int argc, char **argv)
}
/* loader for ES6 modules */
JS_SetModuleLoaderFunc(rt, NULL, js_module_loader, NULL);
JS_SetModuleLoaderFunc2(rt, NULL, js_module_loader, js_module_check_attributes, NULL);
if (dump_unhandled_promise_rejection) {
JS_SetHostPromiseRejectionTracker(rt, js_std_promise_rejection_tracker,

77
qjsc.c
View File

@ -170,13 +170,23 @@ static void dump_hex(FILE *f, const uint8_t *buf, size_t len)
fprintf(f, "\n");
}
typedef enum {
CNAME_TYPE_SCRIPT,
CNAME_TYPE_MODULE,
CNAME_TYPE_JSON_MODULE,
} CNameTypeEnum;
static void output_object_code(JSContext *ctx,
FILE *fo, JSValueConst obj, const char *c_name,
BOOL load_only)
CNameTypeEnum c_name_type)
{
uint8_t *out_buf;
size_t out_buf_len;
int flags;
if (c_name_type == CNAME_TYPE_JSON_MODULE)
flags = 0;
else
flags = JS_WRITE_OBJ_BYTECODE;
if (byte_swap)
flags |= JS_WRITE_OBJ_BSWAP;
@ -186,7 +196,7 @@ static void output_object_code(JSContext *ctx,
exit(1);
}
namelist_add(&cname_list, c_name, NULL, load_only);
namelist_add(&cname_list, c_name, NULL, c_name_type);
fprintf(fo, "const uint32_t %s_size = %u;\n\n",
c_name, (unsigned int)out_buf_len);
@ -227,7 +237,8 @@ static void find_unique_cname(char *cname, size_t cname_size)
}
JSModuleDef *jsc_module_loader(JSContext *ctx,
const char *module_name, void *opaque)
const char *module_name, void *opaque,
JSValueConst attributes)
{
JSModuleDef *m;
namelist_entry_t *e;
@ -249,8 +260,8 @@ JSModuleDef *jsc_module_loader(JSContext *ctx,
} else {
size_t buf_len;
uint8_t *buf;
JSValue func_val;
char cname[1024];
int res;
buf = js_load_file(ctx, &buf_len, module_name);
if (!buf) {
@ -259,6 +270,43 @@ JSModuleDef *jsc_module_loader(JSContext *ctx,
return NULL;
}
res = js_module_test_json(ctx, attributes);
if (has_suffix(module_name, ".json") || res > 0) {
/* compile as JSON or JSON5 depending on "type" */
JSValue val;
int flags;
if (res == 2)
flags = JS_PARSE_JSON_EXT;
else
flags = 0;
val = JS_ParseJSON2(ctx, (char *)buf, buf_len, module_name, flags);
js_free(ctx, buf);
if (JS_IsException(val))
return NULL;
/* create a dummy module */
m = JS_NewCModule(ctx, module_name, js_module_dummy_init);
if (!m) {
JS_FreeValue(ctx, val);
return NULL;
}
get_c_name(cname, sizeof(cname), module_name);
if (namelist_find(&cname_list, cname)) {
find_unique_cname(cname, sizeof(cname));
}
/* output the module name */
fprintf(outfile, "static const uint8_t %s_module_name[] = {\n",
cname);
dump_hex(outfile, (const uint8_t *)module_name, strlen(module_name) + 1);
fprintf(outfile, "};\n\n");
output_object_code(ctx, outfile, val, cname, CNAME_TYPE_JSON_MODULE);
JS_FreeValue(ctx, val);
} else {
JSValue func_val;
/* compile the module */
func_val = JS_Eval(ctx, (char *)buf, buf_len, module_name,
JS_EVAL_TYPE_MODULE | JS_EVAL_FLAG_COMPILE_ONLY);
@ -269,12 +317,13 @@ JSModuleDef *jsc_module_loader(JSContext *ctx,
if (namelist_find(&cname_list, cname)) {
find_unique_cname(cname, sizeof(cname));
}
output_object_code(ctx, outfile, func_val, cname, TRUE);
output_object_code(ctx, outfile, func_val, cname, CNAME_TYPE_MODULE);
/* the module is already referenced, so we must free it */
m = JS_VALUE_GET_PTR(func_val);
JS_FreeValue(ctx, func_val);
}
}
return m;
}
@ -313,8 +362,11 @@ static void compile_file(JSContext *ctx, FILE *fo,
pstrcpy(c_name, sizeof(c_name), c_name1);
} else {
get_c_name(c_name, sizeof(c_name), filename);
if (namelist_find(&cname_list, c_name)) {
find_unique_cname(c_name, sizeof(c_name));
}
output_object_code(ctx, fo, obj, c_name, FALSE);
}
output_object_code(ctx, fo, obj, c_name, CNAME_TYPE_SCRIPT);
JS_FreeValue(ctx, obj);
}
@ -709,7 +761,7 @@ int main(int argc, char **argv)
JS_SetStripInfo(rt, strip_flags);
/* loader for ES6 modules */
JS_SetModuleLoaderFunc(rt, NULL, jsc_module_loader, NULL);
JS_SetModuleLoaderFunc2(rt, NULL, jsc_module_loader, NULL, NULL);
fprintf(fo, "/* File generated automatically by the QuickJS compiler. */\n"
"\n"
@ -732,7 +784,7 @@ int main(int argc, char **argv)
}
for(i = 0; i < dynamic_module_list.count; i++) {
if (!jsc_module_loader(ctx, dynamic_module_list.array[i].name, NULL)) {
if (!jsc_module_loader(ctx, dynamic_module_list.array[i].name, NULL, JS_UNDEFINED)) {
fprintf(stderr, "Could not load dynamic module '%s'\n",
dynamic_module_list.array[i].name);
exit(1);
@ -770,9 +822,12 @@ int main(int argc, char **argv)
}
for(i = 0; i < cname_list.count; i++) {
namelist_entry_t *e = &cname_list.array[i];
if (e->flags) {
if (e->flags == CNAME_TYPE_MODULE) {
fprintf(fo, " js_std_eval_binary(ctx, %s, %s_size, 1);\n",
e->name, e->name);
} else if (e->flags == CNAME_TYPE_JSON_MODULE) {
fprintf(fo, " js_std_eval_binary_json_module(ctx, %s, %s_size, (const char *)%s_module_name);\n",
e->name, e->name, e->name);
}
}
fprintf(fo,
@ -788,7 +843,7 @@ int main(int argc, char **argv)
/* add the module loader if necessary */
if (feature_bitmap & (1 << FE_MODULE_LOADER)) {
fprintf(fo, " JS_SetModuleLoaderFunc(rt, NULL, js_module_loader, NULL);\n");
fprintf(fo, " JS_SetModuleLoaderFunc2(rt, NULL, js_module_loader, js_module_check_attributes, NULL);\n");
}
fprintf(fo,
@ -797,7 +852,7 @@ int main(int argc, char **argv)
for(i = 0; i < cname_list.count; i++) {
namelist_entry_t *e = &cname_list.array[i];
if (!e->flags) {
if (e->flags == CNAME_TYPE_SCRIPT) {
fprintf(fo, " js_std_eval_binary(ctx, %s, %s_size, 0);\n",
e->name, e->name);
}

View File

@ -177,6 +177,12 @@ DEF(minus_zero, "-0")
DEF(Infinity, "Infinity")
DEF(minus_Infinity, "-Infinity")
DEF(NaN, "NaN")
DEF(hasIndices, "hasIndices")
DEF(ignoreCase, "ignoreCase")
DEF(multiline, "multiline")
DEF(dotAll, "dotAll")
DEF(sticky, "sticky")
DEF(unicodeSets, "unicodeSets")
/* the following 3 atoms are only used with CONFIG_ATOMICS */
DEF(not_equal, "not-equal")
DEF(timed_out, "timed-out")
@ -211,6 +217,7 @@ DEF(Int32Array, "Int32Array")
DEF(Uint32Array, "Uint32Array")
DEF(BigInt64Array, "BigInt64Array")
DEF(BigUint64Array, "BigUint64Array")
DEF(Float16Array, "Float16Array")
DEF(Float32Array, "Float32Array")
DEF(Float64Array, "Float64Array")
DEF(DataView, "DataView")

View File

@ -136,11 +136,18 @@ typedef struct {
JSValue on_message_func;
} JSWorkerMessageHandler;
typedef struct {
struct list_head link;
JSValue promise;
JSValue reason;
} JSRejectedPromiseEntry;
typedef struct JSThreadState {
struct list_head os_rw_handlers; /* list of JSOSRWHandler.link */
struct list_head os_signal_handlers; /* list JSOSSignalHandler.link */
struct list_head os_timers; /* list of JSOSTimer.link */
struct list_head port_list; /* list of JSWorkerMessageHandler.link */
struct list_head rejected_promise_list; /* list of JSRejectedPromiseEntry.link */
int eval_script_recurse; /* only used in the main thread */
int next_timer_id; /* for setTimeout() */
/* not used in the main thread */
@ -160,6 +167,7 @@ static BOOL my_isdigit(int c)
return (c >= '0' && c <= '9');
}
/* XXX: use 'o' and 'O' for object using JS_PrintValue() ? */
static JSValue js_printf_internal(JSContext *ctx,
int argc, JSValueConst *argv, FILE *fp)
{
@ -583,17 +591,101 @@ int js_module_set_import_meta(JSContext *ctx, JSValueConst func_val,
return 0;
}
JSModuleDef *js_module_loader(JSContext *ctx,
const char *module_name, void *opaque)
static int json_module_init(JSContext *ctx, JSModuleDef *m)
{
JSValue val;
val = JS_GetModulePrivateValue(ctx, m);
JS_SetModuleExport(ctx, m, "default", val);
return 0;
}
static JSModuleDef *create_json_module(JSContext *ctx, const char *module_name, JSValue val)
{
JSModuleDef *m;
m = JS_NewCModule(ctx, module_name, json_module_init);
if (!m) {
JS_FreeValue(ctx, val);
return NULL;
}
/* only export the "default" symbol which will contain the JSON object */
JS_AddModuleExport(ctx, m, "default");
JS_SetModulePrivateValue(ctx, m, val);
return m;
}
/* in order to conform with the specification, only the keys should be
tested and not the associated values. */
int js_module_check_attributes(JSContext *ctx, void *opaque,
JSValueConst attributes)
{
JSPropertyEnum *tab;
uint32_t i, len;
int ret;
const char *cstr;
size_t cstr_len;
if (JS_GetOwnPropertyNames(ctx, &tab, &len, attributes, JS_GPN_ENUM_ONLY | JS_GPN_STRING_MASK))
return -1;
ret = 0;
for(i = 0; i < len; i++) {
cstr = JS_AtomToCStringLen(ctx, &cstr_len, tab[i].atom);
if (!cstr) {
ret = -1;
break;
}
if (!(cstr_len == 4 && !memcmp(cstr, "type", cstr_len))) {
JS_ThrowTypeError(ctx, "import attribute '%s' is not supported", cstr);
ret = -1;
}
JS_FreeCString(ctx, cstr);
if (ret)
break;
}
JS_FreePropertyEnum(ctx, tab, len);
return ret;
}
/* return > 0 if the attributes indicate a JSON module */
int js_module_test_json(JSContext *ctx, JSValueConst attributes)
{
JSValue str;
const char *cstr;
size_t len;
BOOL res;
if (JS_IsUndefined(attributes))
return FALSE;
str = JS_GetPropertyStr(ctx, attributes, "type");
if (!JS_IsString(str))
return FALSE;
cstr = JS_ToCStringLen(ctx, &len, str);
JS_FreeValue(ctx, str);
if (!cstr)
return FALSE;
/* XXX: raise an error if unknown type ? */
if (len == 4 && !memcmp(cstr, "json", len)) {
res = 1;
} else if (len == 5 && !memcmp(cstr, "json5", len)) {
res = 2;
} else {
res = 0;
}
JS_FreeCString(ctx, cstr);
return res;
}
JSModuleDef *js_module_loader(JSContext *ctx,
const char *module_name, void *opaque,
JSValueConst attributes)
{
JSModuleDef *m;
int res;
if (has_suffix(module_name, ".so")) {
m = js_module_loader_so(ctx, module_name);
} else {
size_t buf_len;
uint8_t *buf;
JSValue func_val;
buf = js_load_file(ctx, &buf_len, module_name);
if (!buf) {
@ -601,7 +693,24 @@ JSModuleDef *js_module_loader(JSContext *ctx,
module_name);
return NULL;
}
res = js_module_test_json(ctx, attributes);
if (has_suffix(module_name, ".json") || res > 0) {
/* compile as JSON or JSON5 depending on "type" */
JSValue val;
int flags;
if (res == 2)
flags = JS_PARSE_JSON_EXT;
else
flags = 0;
val = JS_ParseJSON2(ctx, (char *)buf, buf_len, module_name, flags);
js_free(ctx, buf);
if (JS_IsException(val))
return NULL;
m = create_json_module(ctx, module_name, val);
if (!m)
return NULL;
} else {
JSValue func_val;
/* compile the module */
func_val = JS_Eval(ctx, (char *)buf, buf_len, module_name,
JS_EVAL_TYPE_MODULE | JS_EVAL_FLAG_COMPILE_ONLY);
@ -614,6 +723,7 @@ JSModuleDef *js_module_loader(JSContext *ctx,
m = JS_VALUE_GET_PTR(func_val);
JS_FreeValue(ctx, func_val);
}
}
return m;
}
@ -804,7 +914,7 @@ static JSValue js_evalScript(JSContext *ctx, JSValueConst this_val,
/* convert the uncatchable "interrupted" error into a normal error
so that it can be caught by the REPL */
if (JS_IsException(ret))
JS_ResetUncatchableError(ctx);
JS_SetUncatchableException(ctx, FALSE);
}
return ret;
}
@ -1083,6 +1193,19 @@ static JSValue js_std_file_printf(JSContext *ctx, JSValueConst this_val,
return js_printf_internal(ctx, argc, argv, f);
}
static void js_print_value_write(void *opaque, const char *buf, size_t len)
{
FILE *fo = opaque;
fwrite(buf, 1, len, fo);
}
static JSValue js_std_file_printObject(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv)
{
JS_PrintValue(ctx, js_print_value_write, stdout, argv[0], NULL);
return JS_UNDEFINED;
}
static JSValue js_std_file_flush(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv)
{
@ -1540,6 +1663,7 @@ static const JSCFunctionListEntry js_std_funcs[] = {
JS_PROP_INT32_DEF("SEEK_CUR", SEEK_CUR, JS_PROP_CONFIGURABLE ),
JS_PROP_INT32_DEF("SEEK_END", SEEK_END, JS_PROP_CONFIGURABLE ),
JS_OBJECT_DEF("Error", js_std_error_props, countof(js_std_error_props), JS_PROP_CONFIGURABLE),
JS_CFUNC_DEF("__printObject", 1, js_std_file_printObject ),
};
static const JSCFunctionListEntry js_std_file_proto_funcs[] = {
@ -2916,9 +3040,7 @@ static char **build_envp(JSContext *ctx, JSValueConst obj)
JS_FreeCString(ctx, str);
}
done:
for(i = 0; i < len; i++)
JS_FreeAtom(ctx, tab[i].atom);
js_free(ctx, tab);
JS_FreePropertyEnum(ctx, tab, len);
return envp;
fail:
if (envp) {
@ -3470,7 +3592,7 @@ static void *worker_func(void *opaque)
JS_SetStripInfo(rt, args->strip_flags);
js_std_init_handlers(rt);
JS_SetModuleLoaderFunc(rt, NULL, js_module_loader, NULL);
JS_SetModuleLoaderFunc2(rt, NULL, js_module_loader, js_module_check_attributes, NULL);
/* set the pipe to communicate with the parent */
ts = JS_GetRuntimeOpaque(rt);
@ -3903,17 +4025,23 @@ static JSValue js_print(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv)
{
int i;
const char *str;
size_t len;
JSValueConst v;
for(i = 0; i < argc; i++) {
if (i != 0)
putchar(' ');
str = JS_ToCStringLen(ctx, &len, argv[i]);
v = argv[i];
if (JS_IsString(v)) {
const char *str;
size_t len;
str = JS_ToCStringLen(ctx, &len, v);
if (!str)
return JS_EXCEPTION;
fwrite(str, 1, len, stdout);
JS_FreeCString(ctx, str);
} else {
JS_PrintValue(ctx, js_print_value_write, stdout, v, NULL);
}
}
putchar('\n');
return JS_UNDEFINED;
@ -3977,6 +4105,7 @@ void js_std_init_handlers(JSRuntime *rt)
init_list_head(&ts->os_signal_handlers);
init_list_head(&ts->os_timers);
init_list_head(&ts->port_list);
init_list_head(&ts->rejected_promise_list);
ts->next_timer_id = 1;
JS_SetRuntimeOpaque(rt, ts);
@ -4014,6 +4143,13 @@ void js_std_free_handlers(JSRuntime *rt)
free_timer(rt, th);
}
list_for_each_safe(el, el1, &ts->rejected_promise_list) {
JSRejectedPromiseEntry *rp = list_entry(el, JSRejectedPromiseEntry, link);
JS_FreeValueRT(rt, rp->promise);
JS_FreeValueRT(rt, rp->reason);
free(rp);
}
#ifdef USE_WORKER
/* XXX: free port_list ? */
js_free_message_pipe(ts->recv_pipe);
@ -4024,33 +4160,10 @@ void js_std_free_handlers(JSRuntime *rt)
JS_SetRuntimeOpaque(rt, NULL); /* fail safe */
}
static void js_dump_obj(JSContext *ctx, FILE *f, JSValueConst val)
{
const char *str;
str = JS_ToCString(ctx, val);
if (str) {
fprintf(f, "%s\n", str);
JS_FreeCString(ctx, str);
} else {
fprintf(f, "[exception]\n");
}
}
static void js_std_dump_error1(JSContext *ctx, JSValueConst exception_val)
{
JSValue val;
BOOL is_error;
is_error = JS_IsError(ctx, exception_val);
js_dump_obj(ctx, stderr, exception_val);
if (is_error) {
val = JS_GetPropertyStr(ctx, exception_val, "stack");
if (!JS_IsUndefined(val)) {
js_dump_obj(ctx, stderr, val);
}
JS_FreeValue(ctx, val);
}
JS_PrintValue(ctx, js_print_value_write, stderr, exception_val, NULL);
fputc('\n', stderr);
}
void js_std_dump_error(JSContext *ctx)
@ -4062,13 +4175,66 @@ void js_std_dump_error(JSContext *ctx)
JS_FreeValue(ctx, exception_val);
}
static JSRejectedPromiseEntry *find_rejected_promise(JSContext *ctx, JSThreadState *ts,
JSValueConst promise)
{
struct list_head *el;
list_for_each(el, &ts->rejected_promise_list) {
JSRejectedPromiseEntry *rp = list_entry(el, JSRejectedPromiseEntry, link);
if (JS_SameValue(ctx, rp->promise, promise))
return rp;
}
return NULL;
}
void js_std_promise_rejection_tracker(JSContext *ctx, JSValueConst promise,
JSValueConst reason,
BOOL is_handled, void *opaque)
{
JSRuntime *rt = JS_GetRuntime(ctx);
JSThreadState *ts = JS_GetRuntimeOpaque(rt);
JSRejectedPromiseEntry *rp;
if (!is_handled) {
/* add a new entry if needed */
rp = find_rejected_promise(ctx, ts, promise);
if (!rp) {
rp = malloc(sizeof(*rp));
if (rp) {
rp->promise = JS_DupValue(ctx, promise);
rp->reason = JS_DupValue(ctx, reason);
list_add_tail(&rp->link, &ts->rejected_promise_list);
}
}
} else {
/* the rejection is handled, so the entry can be removed if present */
rp = find_rejected_promise(ctx, ts, promise);
if (rp) {
JS_FreeValue(ctx, rp->promise);
JS_FreeValue(ctx, rp->reason);
list_del(&rp->link);
free(rp);
}
}
}
/* check if there are pending promise rejections. It must be done
asynchrously in case a rejected promise is handled later. Currently
we do it once the application is about to sleep. It could be done
more often if needed. */
static void js_std_promise_rejection_check(JSContext *ctx)
{
JSRuntime *rt = JS_GetRuntime(ctx);
JSThreadState *ts = JS_GetRuntimeOpaque(rt);
struct list_head *el;
if (unlikely(!list_empty(&ts->rejected_promise_list))) {
list_for_each(el, &ts->rejected_promise_list) {
JSRejectedPromiseEntry *rp = list_entry(el, JSRejectedPromiseEntry, link);
fprintf(stderr, "Possibly unhandled promise rejection: ");
js_std_dump_error1(ctx, reason);
js_std_dump_error1(ctx, rp->reason);
}
exit(1);
}
}
@ -4076,21 +4242,21 @@ void js_std_promise_rejection_tracker(JSContext *ctx, JSValueConst promise,
/* main loop which calls the user JS callbacks */
void js_std_loop(JSContext *ctx)
{
JSContext *ctx1;
int err;
for(;;) {
/* execute the pending jobs */
for(;;) {
err = JS_ExecutePendingJob(JS_GetRuntime(ctx), &ctx1);
err = JS_ExecutePendingJob(JS_GetRuntime(ctx), NULL);
if (err <= 0) {
if (err < 0) {
js_std_dump_error(ctx1);
}
if (err < 0)
js_std_dump_error(ctx);
break;
}
}
js_std_promise_rejection_check(ctx);
if (!os_poll_func || os_poll_func(ctx))
break;
}
@ -4115,13 +4281,14 @@ JSValue js_std_await(JSContext *ctx, JSValue obj)
JS_FreeValue(ctx, obj);
break;
} else if (state == JS_PROMISE_PENDING) {
JSContext *ctx1;
int err;
err = JS_ExecutePendingJob(JS_GetRuntime(ctx), &ctx1);
err = JS_ExecutePendingJob(JS_GetRuntime(ctx), NULL);
if (err < 0) {
js_std_dump_error(ctx1);
js_std_dump_error(ctx);
}
if (err == 0) {
js_std_promise_rejection_check(ctx);
if (os_poll_func)
os_poll_func(ctx);
}
@ -4145,6 +4312,7 @@ void js_std_eval_binary(JSContext *ctx, const uint8_t *buf, size_t buf_len,
if (JS_VALUE_GET_TAG(obj) == JS_TAG_MODULE) {
js_module_set_import_meta(ctx, obj, FALSE, FALSE);
}
JS_FreeValue(ctx, obj);
} else {
if (JS_VALUE_GET_TAG(obj) == JS_TAG_MODULE) {
if (JS_ResolveModule(ctx, obj) < 0) {
@ -4165,3 +4333,22 @@ void js_std_eval_binary(JSContext *ctx, const uint8_t *buf, size_t buf_len,
JS_FreeValue(ctx, val);
}
}
void js_std_eval_binary_json_module(JSContext *ctx,
const uint8_t *buf, size_t buf_len,
const char *module_name)
{
JSValue obj;
JSModuleDef *m;
obj = JS_ReadObject(ctx, buf, buf_len, 0);
if (JS_IsException(obj))
goto exception;
m = create_json_module(ctx, module_name, obj);
if (!m) {
exception:
js_std_dump_error(ctx);
exit(1);
}
}

View File

@ -44,10 +44,16 @@ void js_std_dump_error(JSContext *ctx);
uint8_t *js_load_file(JSContext *ctx, size_t *pbuf_len, const char *filename);
int js_module_set_import_meta(JSContext *ctx, JSValueConst func_val,
JS_BOOL use_realpath, JS_BOOL is_main);
int js_module_test_json(JSContext *ctx, JSValueConst attributes);
int js_module_check_attributes(JSContext *ctx, void *opaque, JSValueConst attributes);
JSModuleDef *js_module_loader(JSContext *ctx,
const char *module_name, void *opaque);
const char *module_name, void *opaque,
JSValueConst attributes);
void js_std_eval_binary(JSContext *ctx, const uint8_t *buf, size_t buf_len,
int flags);
void js_std_eval_binary_json_module(JSContext *ctx,
const uint8_t *buf, size_t buf_len,
const char *module_name);
void js_std_promise_rejection_tracker(JSContext *ctx, JSValueConst promise,
JSValueConst reason,
JS_BOOL is_handled, void *opaque);

View File

@ -121,7 +121,7 @@ DEF( apply_eval, 3, 2, 1, u16) /* func array -> ret_eval */
DEF( regexp, 1, 2, 1, none) /* create a RegExp object from the pattern and a
bytecode string */
DEF( get_super, 1, 1, 1, none)
DEF( import, 1, 1, 1, none) /* dynamic module import */
DEF( import, 1, 2, 1, none) /* dynamic module import */
DEF( check_var, 5, 0, 1, atom) /* check if a variable exists */
DEF( get_var_undef, 5, 0, 1, atom) /* push undefined if the variable does not exist */
@ -144,6 +144,7 @@ DEF( put_private_field, 1, 3, 0, none) /* obj value prop -> */
DEF(define_private_field, 1, 3, 1, none) /* obj prop value -> obj */
DEF( get_array_el, 1, 2, 1, none)
DEF( get_array_el2, 1, 2, 2, none) /* obj prop -> obj value */
DEF( get_array_el3, 1, 2, 3, none) /* obj prop -> obj prop1 value */
DEF( put_array_el, 1, 3, 0, none)
DEF(get_super_value, 1, 3, 1, none) /* this obj prop -> value */
DEF(put_super_value, 1, 4, 0, none) /* this obj prop value -> */
@ -189,7 +190,6 @@ DEF( nip_catch, 1, 2, 1, none) /* catch ... a -> a */
DEF( to_object, 1, 1, 1, none)
//DEF( to_string, 1, 1, 1, none)
DEF( to_propkey, 1, 1, 1, none)
DEF( to_propkey2, 1, 2, 2, none)
DEF( with_get_var, 10, 1, 0, atom_label_u8) /* must be in the same order as scope_xxx */
DEF( with_put_var, 10, 2, 1, atom_label_u8) /* must be in the same order as scope_xxx */

2761
quickjs.c

File diff suppressed because it is too large Load Diff

View File

@ -456,7 +456,11 @@ void JS_FreeAtom(JSContext *ctx, JSAtom v);
void JS_FreeAtomRT(JSRuntime *rt, JSAtom v);
JSValue JS_AtomToValue(JSContext *ctx, JSAtom atom);
JSValue JS_AtomToString(JSContext *ctx, JSAtom atom);
const char *JS_AtomToCString(JSContext *ctx, JSAtom atom);
const char *JS_AtomToCStringLen(JSContext *ctx, size_t *plen, JSAtom atom);
static inline const char *JS_AtomToCString(JSContext *ctx, JSAtom atom)
{
return JS_AtomToCStringLen(ctx, NULL, atom);
}
JSAtom JS_ValueToAtom(JSContext *ctx, JSValueConst val);
/* object class support */
@ -659,11 +663,10 @@ static inline JS_BOOL JS_IsObject(JSValueConst v)
}
JSValue JS_Throw(JSContext *ctx, JSValue obj);
void JS_SetUncatchableException(JSContext *ctx, JS_BOOL flag);
JSValue JS_GetException(JSContext *ctx);
JS_BOOL JS_HasException(JSContext *ctx);
JS_BOOL JS_IsError(JSContext *ctx, JSValueConst val);
void JS_SetUncatchableError(JSContext *ctx, JSValueConst val, JS_BOOL flag);
void JS_ResetUncatchableError(JSContext *ctx);
JSValue JS_NewError(JSContext *ctx);
JSValue __js_printf_like(2, 3) JS_ThrowSyntaxError(JSContext *ctx, const char *fmt, ...);
JSValue __js_printf_like(2, 3) JS_ThrowTypeError(JSContext *ctx, const char *fmt, ...);
@ -806,6 +809,8 @@ JSValue JS_GetPrototype(JSContext *ctx, JSValueConst val);
int JS_GetOwnPropertyNames(JSContext *ctx, JSPropertyEnum **ptab,
uint32_t *plen, JSValueConst obj, int flags);
void JS_FreePropertyEnum(JSContext *ctx, JSPropertyEnum *tab,
uint32_t len);
int JS_GetOwnProperty(JSContext *ctx, JSPropertyDescriptor *desc,
JSValueConst obj, JSAtom prop);
@ -872,6 +877,7 @@ typedef enum JSTypedArrayEnum {
JS_TYPED_ARRAY_UINT32,
JS_TYPED_ARRAY_BIG_INT64,
JS_TYPED_ARRAY_BIG_UINT64,
JS_TYPED_ARRAY_FLOAT16,
JS_TYPED_ARRAY_FLOAT32,
JS_TYPED_ARRAY_FLOAT64,
} JSTypedArrayEnum;
@ -930,12 +936,25 @@ typedef char *JSModuleNormalizeFunc(JSContext *ctx,
const char *module_name, void *opaque);
typedef JSModuleDef *JSModuleLoaderFunc(JSContext *ctx,
const char *module_name, void *opaque);
typedef JSModuleDef *JSModuleLoaderFunc2(JSContext *ctx,
const char *module_name, void *opaque,
JSValueConst attributes);
/* return -1 if exception, 0 if OK */
typedef int JSModuleCheckSupportedImportAttributes(JSContext *ctx, void *opaque,
JSValueConst attributes);
/* module_normalize = NULL is allowed and invokes the default module
filename normalizer */
void JS_SetModuleLoaderFunc(JSRuntime *rt,
JSModuleNormalizeFunc *module_normalize,
JSModuleLoaderFunc *module_loader, void *opaque);
/* same as JS_SetModuleLoaderFunc but with attributes. if
module_check_attrs = NULL, no attribute checking is done. */
void JS_SetModuleLoaderFunc2(JSRuntime *rt,
JSModuleNormalizeFunc *module_normalize,
JSModuleLoaderFunc2 *module_loader,
JSModuleCheckSupportedImportAttributes *module_check_attrs,
void *opaque);
/* return the import.meta object of a module */
JSValue JS_GetImportMeta(JSContext *ctx, JSModuleDef *m);
JSAtom JS_GetModuleName(JSContext *ctx, JSModuleDef *m);
@ -1030,7 +1049,9 @@ static inline JSValue JS_NewCFunctionMagic(JSContext *ctx, JSCFunctionMagic *fun
const char *name,
int length, JSCFunctionEnum cproto, int magic)
{
return JS_NewCFunction2(ctx, (JSCFunction *)func, name, length, cproto, magic);
/* Used to squelch a -Wcast-function-type warning. */
JSCFunctionType ft = { .generic_magic = func };
return JS_NewCFunction2(ctx, ft.generic, name, length, cproto, magic);
}
void JS_SetConstructor(JSContext *ctx, JSValueConst func_obj,
JSValueConst proto);
@ -1094,7 +1115,7 @@ typedef struct JSCFunctionListEntry {
#define JS_ALIAS_DEF(name, from) { name, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE, JS_DEF_ALIAS, 0, .u = { .alias = { from, -1 } } }
#define JS_ALIAS_BASE_DEF(name, from, base) { name, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE, JS_DEF_ALIAS, 0, .u = { .alias = { from, base } } }
void JS_SetPropertyFunctionList(JSContext *ctx, JSValueConst obj,
int JS_SetPropertyFunctionList(JSContext *ctx, JSValueConst obj,
const JSCFunctionListEntry *tab,
int len);
@ -1113,6 +1134,29 @@ int JS_SetModuleExport(JSContext *ctx, JSModuleDef *m, const char *export_name,
JSValue val);
int JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m,
const JSCFunctionListEntry *tab, int len);
/* associate a JSValue to a C module */
int JS_SetModulePrivateValue(JSContext *ctx, JSModuleDef *m, JSValue val);
JSValue JS_GetModulePrivateValue(JSContext *ctx, JSModuleDef *m);
/* debug value output */
typedef struct {
JS_BOOL show_hidden : 8; /* only show enumerable properties */
JS_BOOL raw_dump : 8; /* avoid doing autoinit and avoid any malloc() call (for internal use) */
uint32_t max_depth; /* recurse up to this depth, 0 = no limit */
uint32_t max_string_length; /* print no more than this length for
strings, 0 = no limit */
uint32_t max_item_count; /* print no more than this count for
arrays or objects, 0 = no limit */
} JSPrintValueOptions;
typedef void JSPrintValueWrite(void *opaque, const char *buf, size_t len);
void JS_PrintValueSetDefaultOptions(JSPrintValueOptions *options);
void JS_PrintValueRT(JSRuntime *rt, JSPrintValueWrite *write_func, void *write_opaque,
JSValueConst val, const JSPrintValueOptions *options);
void JS_PrintValue(JSContext *ctx, JSPrintValueWrite *write_func, void *write_opaque,
JSValueConst val, const JSPrintValueOptions *options);
#undef js_unlikely
#undef js_force_inline

View File

@ -174,7 +174,7 @@ cp Makefile VERSION TODO Changelog readme.txt LICENSE \
cp tests/*.js tests/*.patch tests/bjson.c $outdir/tests
cp examples/*.js examples/*.c $outdir/examples
cp examples/*.js examples/*.c examples/*.json $outdir/examples
cp doc/quickjs.texi doc/quickjs.pdf doc/quickjs.html \
$outdir/doc

137
repl.js
View File

@ -875,21 +875,8 @@ import * as os from "os";
}
var hex_mode = false;
var eval_mode = "std";
function number_to_string(a, radix) {
var s;
if (!isFinite(a)) {
/* NaN, Infinite */
return a.toString();
} else {
if (a == 0) {
if (1 / a < 0)
s = "-0";
else
s = "0";
} else {
if (radix == 16 && a === Math.floor(a)) {
function number_to_string_hex(a) {
var s;
if (a < 0) {
a = -a;
@ -898,102 +885,8 @@ import * as os from "os";
s = "";
}
s += "0x" + a.toString(16);
} else {
s = a.toString();
}
}
return s;
}
}
function bigint_to_string(a, radix) {
var s;
if (radix == 16) {
var s;
if (a < 0) {
a = -a;
s = "-";
} else {
s = "";
}
s += "0x" + a.toString(16);
} else {
s = a.toString();
}
if (eval_mode === "std")
s += "n";
return s;
}
function print(a) {
var stack = [];
function print_rec(a) {
var n, i, keys, key, type, s;
type = typeof(a);
if (type === "object") {
if (a === null) {
std.puts(a);
} else if (stack.indexOf(a) >= 0) {
std.puts("[circular]");
} else if (a instanceof Date) {
std.puts("Date " + a.toGMTString().__quote());
} else {
stack.push(a);
if (Array.isArray(a)) {
n = a.length;
std.puts("[ ");
for(i = 0; i < n; i++) {
if (i !== 0)
std.puts(", ");
if (i in a) {
print_rec(a[i]);
} else {
std.puts("<empty>");
}
if (i > 20) {
std.puts("...");
break;
}
}
std.puts(" ]");
} else if (Object.__getClass(a) === "RegExp") {
std.puts(a.toString());
} else {
keys = Object.keys(a);
n = keys.length;
std.puts("{ ");
for(i = 0; i < n; i++) {
if (i !== 0)
std.puts(", ");
key = keys[i];
std.puts(key, ": ");
print_rec(a[key]);
}
std.puts(" }");
}
stack.pop(a);
}
} else if (type === "string") {
s = a.__quote();
if (s.length > 79)
s = s.substring(0, 75) + "...\"";
std.puts(s);
} else if (type === "number") {
std.puts(number_to_string(a, hex_mode ? 16 : 10));
} else if (type === "bigint") {
std.puts(bigint_to_string(a, hex_mode ? 16 : 10));
} else if (type === "symbol") {
std.puts(String(a));
} else if (type === "function") {
std.puts("function " + a.name + "()");
} else {
std.puts(a);
}
}
print_rec(a);
}
function extract_directive(a) {
var pos;
@ -1116,10 +1009,25 @@ import * as os from "os";
}
function print_eval_result(result) {
var default_print = true;
result = result.value;
eval_time = os.now() - eval_start_time;
std.puts(colors[styles.result]);
print(result);
if (hex_mode) {
if (typeof result == "number" &&
result === Math.floor(result)) {
std.puts(number_to_string_hex(result));
default_print = false;
} else if (typeof result == "bigint") {
std.puts(number_to_string_hex(result));
std.puts("n");
default_print = false;
}
}
if (default_print) {
std.__printObject(result);
}
std.puts("\n");
std.puts(colors.none);
/* set the last result */
@ -1130,15 +1038,10 @@ import * as os from "os";
function print_eval_error(error) {
std.puts(colors[styles.error_msg]);
if (error instanceof Error) {
console.log(error);
if (error.stack) {
std.puts(error.stack);
}
} else {
if (!(error instanceof Error))
std.puts("Throw: ");
console.log(error);
}
std.__printObject(error);
std.puts("\n");
std.puts(colors.none);
handle_cmd_end();

View File

@ -78,6 +78,7 @@ char *harness_dir;
char *harness_exclude;
char *harness_features;
char *harness_skip_features;
int *harness_skip_features_count;
char *error_filename;
char *error_file;
FILE *error_out;
@ -372,17 +373,27 @@ static void enumerate_tests(const char *path)
namelist_cmp_indirect);
}
static void js_print_value_write(void *opaque, const char *buf, size_t len)
{
FILE *fo = opaque;
fwrite(buf, 1, len, fo);
}
static JSValue js_print(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv)
{
int i;
const char *str;
JSValueConst v;
if (outfile) {
for (i = 0; i < argc; i++) {
if (i != 0)
fputc(' ', outfile);
str = JS_ToCString(ctx, argv[i]);
v = argv[i];
if (JS_IsString(v)) {
const char *str;
size_t len;
str = JS_ToCStringLen(ctx, &len, v);
if (!str)
return JS_EXCEPTION;
if (!strcmp(str, "Test262:AsyncTestComplete")) {
@ -390,8 +401,11 @@ static JSValue js_print(JSContext *ctx, JSValueConst this_val,
} else if (strstart(str, "Test262:AsyncTestFailure", NULL)) {
async_done = 2; /* force an error */
}
fputs(str, outfile);
fwrite(str, 1, len, outfile);
JS_FreeCString(ctx, str);
} else {
JS_PrintValue(ctx, js_print_value_write, outfile, v, NULL);
}
}
fputc('\n', outfile);
}
@ -483,8 +497,7 @@ static void *agent_start(void *arg)
JS_FreeValue(ctx, ret_val);
for(;;) {
JSContext *ctx1;
ret = JS_ExecutePendingJob(JS_GetRuntime(ctx), &ctx1);
ret = JS_ExecutePendingJob(JS_GetRuntime(ctx), NULL);
if (ret < 0) {
js_std_dump_error(ctx);
break;
@ -823,13 +836,21 @@ static char *load_file(const char *filename, size_t *lenp)
return buf;
}
static int json_module_init_test(JSContext *ctx, JSModuleDef *m)
{
JSValue val;
val = JS_GetModulePrivateValue(ctx, m);
JS_SetModuleExport(ctx, m, "default", val);
return 0;
}
static JSModuleDef *js_module_loader_test(JSContext *ctx,
const char *module_name, void *opaque)
const char *module_name, void *opaque,
JSValueConst attributes)
{
size_t buf_len;
uint8_t *buf;
JSModuleDef *m;
JSValue func_val;
char *filename, *slash, path[1024];
// interpret import("bar.js") from path/to/foo.js as
@ -851,6 +872,23 @@ static JSModuleDef *js_module_loader_test(JSContext *ctx,
return NULL;
}
if (js_module_test_json(ctx, attributes) == 1) {
/* compile as JSON */
JSValue val;
val = JS_ParseJSON(ctx, (char *)buf, buf_len, module_name);
js_free(ctx, buf);
if (JS_IsException(val))
return NULL;
m = JS_NewCModule(ctx, module_name, json_module_init_test);
if (!m) {
JS_FreeValue(ctx, val);
return NULL;
}
/* only export the "default" symbol which will contain the JSON object */
JS_AddModuleExport(ctx, m, "default");
JS_SetModulePrivateValue(ctx, m, val);
} else {
JSValue func_val;
/* compile the module */
func_val = JS_Eval(ctx, (char *)buf, buf_len, module_name,
JS_EVAL_TYPE_MODULE | JS_EVAL_FLAG_COMPILE_ONLY);
@ -860,6 +898,7 @@ static JSModuleDef *js_module_loader_test(JSContext *ctx,
/* the module is already referenced, so we must free it */
m = JS_VALUE_GET_PTR(func_val);
JS_FreeValue(ctx, func_val);
}
return m;
}
@ -1231,8 +1270,7 @@ static int eval_buf(JSContext *ctx, const char *buf, size_t buf_len,
JS_FreeValue(ctx, res_val);
}
for(;;) {
JSContext *ctx1;
ret = JS_ExecutePendingJob(JS_GetRuntime(ctx), &ctx1);
ret = JS_ExecutePendingJob(JS_GetRuntime(ctx), NULL);
if (ret < 0) {
res_val = JS_EXCEPTION;
break;
@ -1574,7 +1612,7 @@ int run_test_buf(const char *filename, const char *harness, namelist_t *ip,
JS_SetCanBlock(rt, can_block);
/* loader for ES6 modules */
JS_SetModuleLoaderFunc(rt, NULL, js_module_loader_test, (void *)filename);
JS_SetModuleLoaderFunc2(rt, NULL, js_module_loader_test, NULL, (void *)filename);
add_helpers(ctx);
@ -1699,10 +1737,13 @@ int run_test(const char *filename, int index)
p = find_tag(desc, "features:", &state);
if (p) {
while ((option = get_option(&p, &state)) != NULL) {
char *p1;
if (find_word(harness_features, option)) {
/* feature is enabled */
} else if (find_word(harness_skip_features, option)) {
} else if ((p1 = find_word(harness_skip_features, option)) != NULL) {
/* skip disabled feature */
if (harness_skip_features_count)
harness_skip_features_count[p1 - harness_skip_features]++;
skip |= 1;
} else {
/* feature is not listed: skip and warn */
@ -1875,7 +1916,7 @@ int run_test262_harness_test(const char *filename, BOOL is_module)
JS_SetCanBlock(rt, can_block);
/* loader for ES6 modules */
JS_SetModuleLoaderFunc(rt, NULL, js_module_loader_test, (void *)filename);
JS_SetModuleLoaderFunc2(rt, NULL, js_module_loader_test, NULL, (void *)filename);
add_helpers(ctx);
@ -1899,10 +1940,9 @@ int run_test262_harness_test(const char *filename, BOOL is_module)
JS_FreeValue(ctx, res_val);
}
for(;;) {
JSContext *ctx1;
ret = JS_ExecutePendingJob(JS_GetRuntime(ctx), &ctx1);
ret = JS_ExecutePendingJob(JS_GetRuntime(ctx), NULL);
if (ret < 0) {
js_std_dump_error(ctx1);
js_std_dump_error(ctx);
ret_code = 1;
} else if (ret == 0) {
break;
@ -2036,6 +2076,7 @@ int main(int argc, char **argv)
const char *ignore = "";
BOOL is_test262_harness = FALSE;
BOOL is_module = FALSE;
BOOL count_skipped_features = FALSE;
clock_t clocks;
#if !defined(_WIN32)
@ -2103,6 +2144,8 @@ int main(int argc, char **argv)
is_test262_harness = TRUE;
} else if (str_equal(arg, "--module")) {
is_module = TRUE;
} else if (str_equal(arg, "--count_skipped_features")) {
count_skipped_features = TRUE;
} else {
fatal(1, "unknown option: %s", arg);
break;
@ -2137,6 +2180,14 @@ int main(int argc, char **argv)
clocks = clock();
if (count_skipped_features) {
/* not storage efficient but it is simple */
size_t size;
size = sizeof(harness_skip_features_count[0]) * strlen(harness_skip_features);
harness_skip_features_count = malloc(size);
memset(harness_skip_features_count, 0, size);
}
if (is_dir_list) {
if (optind < argc && !isdigit((unsigned char)argv[optind][0])) {
filename = argv[optind++];
@ -2187,6 +2238,30 @@ int main(int argc, char **argv)
printf("\n");
}
if (count_skipped_features) {
size_t i, n, len = strlen(harness_skip_features);
BOOL disp = FALSE;
int c;
for(i = 0; i < len; i++) {
if (harness_skip_features_count[i] != 0) {
if (!disp) {
disp = TRUE;
printf("%-30s %7s\n", "SKIPPED FEATURE", "COUNT");
}
for(n = 0; n < 30; n++) {
c = harness_skip_features[i + n];
if (is_word_sep(c))
break;
putchar(c);
}
for(; n < 30; n++)
putchar(' ');
printf(" %7d\n", harness_skip_features_count[i]);
}
}
printf("\n");
}
if (is_dir_list) {
fprintf(stderr, "Result: %d/%d error%s",
test_failed, test_count, test_count != 1 ? "s" : "");
@ -2216,6 +2291,8 @@ int main(int argc, char **argv)
namelist_free(&exclude_list);
namelist_free(&exclude_dir_list);
free(harness_dir);
free(harness_skip_features);
free(harness_skip_features_count);
free(harness_features);
free(harness_exclude);
free(error_file);

View File

@ -103,12 +103,12 @@ destructuring-assignment
destructuring-binding
dynamic-import
error-cause
Error.isError=skip
Error.isError
explicit-resource-management=skip
exponentiation
export-star-as-namespace-from-module
FinalizationRegistry
Float16Array=skip
Float16Array
Float32Array
Float64Array
for-in-order
@ -116,9 +116,7 @@ for-of
generators
globalThis
hashbang
host-gc-required=skip
import-assertions=skip
import-attributes=skip
import-attributes
import-defer=skip
import.meta
Int16Array
@ -144,7 +142,7 @@ Intl.Segmenter=skip
IsHTMLDDA
iterator-helpers=skip
iterator-sequencing=skip
json-modules=skip
json-modules
json-parse-with-source=skip
json-superset
legacy-regexp=skip
@ -162,7 +160,7 @@ Object.is
optional-catch-binding
optional-chaining
Promise
promise-try=skip
promise-try
promise-with-resolvers
Promise.allSettled
Promise.any
@ -177,11 +175,11 @@ regexp-dotall
regexp-duplicate-named-groups=skip
regexp-lookbehind
regexp-match-indices
regexp-modifiers=skip
regexp-modifiers
regexp-named-groups
regexp-unicode-property-escapes
regexp-v-flag=skip
RegExp.escape=skip
regexp-v-flag
RegExp.escape
resizable-arraybuffer=skip
rest-parameters
Set
@ -230,6 +228,7 @@ Uint32Array
Uint8Array
uint8array-base64=skip
Uint8ClampedArray
upsert=skip
WeakMap
WeakRef
WeakSet
@ -250,32 +249,6 @@ test262/test/built-ins/ThrowTypeError/unique-per-realm-function-proto.js
#test262/test/built-ins/RegExp/CharacterClassEscapes/
#test262/test/built-ins/RegExp/property-escapes/
# feature regexp-v-flag is missing in the tests
test262/test/built-ins/RegExp/CharacterClassEscapes/character-class-digit-class-escape-negative-cases.js
test262/test/built-ins/RegExp/CharacterClassEscapes/character-class-digit-class-escape-negative-cases.js
test262/test/built-ins/RegExp/CharacterClassEscapes/character-class-digit-class-escape-positive-cases.js
test262/test/built-ins/RegExp/CharacterClassEscapes/character-class-digit-class-escape-positive-cases.js
test262/test/built-ins/RegExp/CharacterClassEscapes/character-class-non-digit-class-escape-negative-cases.js
test262/test/built-ins/RegExp/CharacterClassEscapes/character-class-non-digit-class-escape-negative-cases.js
test262/test/built-ins/RegExp/CharacterClassEscapes/character-class-non-digit-class-escape-positive-cases.js
test262/test/built-ins/RegExp/CharacterClassEscapes/character-class-non-digit-class-escape-positive-cases.js
test262/test/built-ins/RegExp/CharacterClassEscapes/character-class-non-whitespace-class-escape-negative-cases.js
test262/test/built-ins/RegExp/CharacterClassEscapes/character-class-non-whitespace-class-escape-negative-cases.js
test262/test/built-ins/RegExp/CharacterClassEscapes/character-class-non-whitespace-class-escape-positive-cases.js
test262/test/built-ins/RegExp/CharacterClassEscapes/character-class-non-whitespace-class-escape-positive-cases.js
test262/test/built-ins/RegExp/CharacterClassEscapes/character-class-non-word-class-escape-negative-cases.js
test262/test/built-ins/RegExp/CharacterClassEscapes/character-class-non-word-class-escape-negative-cases.js
test262/test/built-ins/RegExp/CharacterClassEscapes/character-class-non-word-class-escape-positive-cases.js
test262/test/built-ins/RegExp/CharacterClassEscapes/character-class-non-word-class-escape-positive-cases.js
test262/test/built-ins/RegExp/CharacterClassEscapes/character-class-whitespace-class-escape-negative-cases.js
test262/test/built-ins/RegExp/CharacterClassEscapes/character-class-whitespace-class-escape-negative-cases.js
test262/test/built-ins/RegExp/CharacterClassEscapes/character-class-whitespace-class-escape-positive-cases.js
test262/test/built-ins/RegExp/CharacterClassEscapes/character-class-whitespace-class-escape-positive-cases.js
test262/test/built-ins/RegExp/CharacterClassEscapes/character-class-word-class-escape-negative-cases.js
test262/test/built-ins/RegExp/CharacterClassEscapes/character-class-word-class-escape-negative-cases.js
test262/test/built-ins/RegExp/CharacterClassEscapes/character-class-word-class-escape-positive-cases.js
test262/test/built-ins/RegExp/CharacterClassEscapes/character-class-word-class-escape-positive-cases.js
# not yet in official specification
test262/test/built-ins/String/prototype/match/cstm-matcher-on-bigint-primitive.js
test262/test/built-ins/String/prototype/match/cstm-matcher-on-bigint-primitive.js
@ -341,14 +314,6 @@ test262/test/staging/sm/Set/symmetric-difference.js
test262/test/staging/sm/Set/union.js
test262/test/staging/sm/extensions/censor-strict-caller.js
test262/test/staging/sm/JSON/parse-with-source.js
test262/test/staging/sm/RegExp/flags.js
test262/test/staging/sm/RegExp/prototype.js
# no f16
test262/test/staging/sm/Math/f16round.js
test262/test/staging/sm/TypedArray/sort_small.js
test262/test/staging/sm/extensions/dataview.js
test262/test/staging/sm/TypedArray/toString.js
# not standard
test262/test/staging/sm/Function/builtin-no-construct.js
@ -357,9 +322,23 @@ test262/test/staging/sm/Function/function-toString-builtin-name.js
test262/test/staging/sm/extensions/arguments-property-access-in-function.js
test262/test/staging/sm/extensions/function-caller-skips-eval-frames.js
test262/test/staging/sm/extensions/function-properties.js
test262/test/staging/sm/regress/regress-577648-1.js
test262/test/staging/sm/regress/regress-577648-2.js
test262/test/staging/sm/regress/regress-584355.js
test262/test/staging/sm/regress/regress-586482-1.js
test262/test/staging/sm/regress/regress-586482-2.js
test262/test/staging/sm/regress/regress-586482-3.js
test262/test/staging/sm/regress/regress-586482-4.js
test262/test/staging/sm/regress/regress-699682.js
# RegExp toSource not fully compliant
test262/test/staging/sm/RegExp/toString.js
test262/test/staging/sm/RegExp/source.js
test262/test/staging/sm/RegExp/escape.js
# source directives are not standard yet
test262/test/staging/sm/syntax/syntax-parsed-arrow-then-directive.js
# returning "bound fn" as initialName for a function is permitted by the spec
test262/test/staging/sm/Function/function-toString-builtin.js
[tests]
# list test files or use config.testdir

View File

@ -1,72 +1,54 @@
test262/test/language/module-code/top-level-await/module-graphs-does-not-hang.js:10: TypeError: $DONE() not called
test262/test/annexB/language/expressions/assignmenttargettype/callexpression-as-for-in-lhs.js:27: SyntaxError: invalid for in/of left hand-side
test262/test/annexB/language/expressions/assignmenttargettype/callexpression-as-for-of-lhs.js:27: SyntaxError: invalid for in/of left hand-side
test262/test/annexB/language/expressions/assignmenttargettype/callexpression-in-compound-assignment.js:33: SyntaxError: invalid assignment left-hand side
test262/test/annexB/language/expressions/assignmenttargettype/callexpression-in-postfix-update.js:27: SyntaxError: invalid increment/decrement operand
test262/test/annexB/language/expressions/assignmenttargettype/callexpression-in-prefix-update.js:27: SyntaxError: invalid increment/decrement operand
test262/test/annexB/language/expressions/assignmenttargettype/callexpression.js:33: SyntaxError: invalid assignment left-hand side
test262/test/annexB/language/expressions/assignmenttargettype/cover-callexpression-and-asyncarrowhead.js:20: SyntaxError: invalid assignment left-hand side
test262/test/built-ins/Atomics/notify/retrieve-length-before-index-coercion-non-shared-detached.js:34: TypeError: ArrayBuffer is detached
test262/test/built-ins/Atomics/notify/retrieve-length-before-index-coercion-non-shared-detached.js:34: strict mode: TypeError: ArrayBuffer is detached
test262/test/staging/sm/Date/UTC-convert-all-arguments.js:75: Test262Error: index 1: expected 42, got Error: didn't throw Expected SameValue(«Error: didn't throw», «42») to be true
test262/test/staging/sm/Date/constructor-convert-all-arguments.js:75: Test262Error: index undefined: expected 42, got Error: didn't throw Expected SameValue(«Error: didn't throw», «42») to be true
test262/test/staging/sm/Date/non-iso.js:76: Test262Error: Expected SameValue(«NaN», «-40071559730000») to be true
test262/test/staging/sm/Date/two-digit-years.js:76: Test262Error: Expected SameValue(«915177600000», «NaN») to be true
test262/test/staging/sm/Function/arguments-parameter-shadowing.js:15: Test262Error: Expected SameValue(«true», «false») to be true
test262/test/staging/sm/Function/constructor-binding.js:12: Test262Error: Expected SameValue(«"function"», «"undefined"») to be true
test262/test/staging/sm/Function/function-bind.js:14: Test262Error: Expected SameValue(«false», «true») to be true
test262/test/staging/sm/Function/function-bind.js:14: Test262Error: Conforms to NativeFunction Syntax: "function bound unbound() {\n [native code]\n}"
test262/test/staging/sm/Function/function-name-for.js:12: Test262Error: Expected SameValue(«""», «"forInHead"») to be true
test262/test/staging/sm/Function/function-toString-builtin.js:14: Test262Error: Expected match to '/^\s*function\s*(get|set)?\s*(\w+|(?:'[^']*')|(?:"[^"]*")|\d+|(?:\[[^\]]+\]))?\s*\(\s*\)\s*\{\s*\[native code\]\s*\}\s*$/', Actual value 'function bound fn() {
[native code]
}' Expected SameValue(«null», «null») to be false
test262/test/staging/sm/Function/implicit-this-in-parameter-expression.js:13: Test262Error: Expected SameValue(«[object Object]», «undefined») to be true
test262/test/staging/sm/Function/invalid-parameter-list.js:35: Error: Assertion failed: expected exception SyntaxError, no exception thrown
test262/test/staging/sm/JSON/parse-number-syntax.js:39: Test262Error: parsing string <1.> threw a non-SyntaxError exception: Test262Error: string <1.> shouldn't have parsed as JSON Expected SameValue(«false», «true») to be true Expected SameValue(«true», «false») to be true
test262/test/staging/sm/JSON/parse-syntax-errors-02.js:51: Test262Error: parsing string <["Illegal backslash escape: \x15"]> threw a non-SyntaxError exception: Test262Error: string <["Illegal backslash escape: \x15"]> shouldn't have parsed as JSON Expected SameValue(«false», «true») to be true Expected SameValue(«true», «false») to be true
test262/test/staging/sm/Math/cbrt-approx.js:26: Error: got 1.39561242508609, expected a number near 1.3956124250860895 (relative error: 2)
test262/test/staging/sm/RegExp/constructor-ordering-2.js:15: Test262Error: Expected SameValue(«false», «true») to be true
test262/test/staging/sm/RegExp/escape.js:13: Test262Error: Expected SameValue(«"\\\n"», «"\\n"») to be true
test262/test/staging/sm/RegExp/match-trace.js:13: Test262Error: Expected SameValue(«"get:flags,get:unicode,set:lastIndex,get:exec,call:exec,get:result[0],get:exec,call:exec,get:result[0],get:exec,call:exec,"», «"get:flags,set:lastIndex,get:exec,call:exec,get:result[0],get:exec,call:exec,get:result[0],get:exec,call:exec,"») to be true
test262/test/staging/sm/RegExp/regress-613820-1.js:13: Test262Error: Expected SameValue(«"aaa"», «"aa"») to be true
test262/test/staging/sm/RegExp/regress-613820-2.js:13: Test262Error: Expected SameValue(«"f"», «undefined») to be true
test262/test/staging/sm/RegExp/regress-613820-3.js:13: Test262Error: Expected SameValue(«"aab"», «"aa"») to be true
test262/test/staging/sm/RegExp/replace-trace.js:13: Test262Error: Expected SameValue(«"get:flags,get:unicode,set:lastIndex,get:exec,call:exec,get:result[0],get:exec,call:exec,get:result[length],get:result[0],get:result[index],get:result[groups],"», «"get:flags,set:lastIndex,get:exec,call:exec,get:result[0],get:exec,call:exec,get:result[length],get:result[0],get:result[index],get:result[groups],"») to be true
test262/test/staging/sm/RegExp/unicode-ignoreCase-escape.js:22: Test262Error: Actual argument shouldn't be nullish.
test262/test/staging/sm/RegExp/unicode-ignoreCase-word-boundary.js:13: Test262Error: Expected SameValue(«false», «true») to be true
test262/test/staging/sm/String/match-defines-match-elements.js:52: Test262Error: Expected SameValue(«true», «false») to be true
test262/test/staging/sm/RegExp/regress-613820-1.js:12: Test262Error: Actual [aaa, aa, a] and expected [aa, a, a] should have the same contents.
test262/test/staging/sm/RegExp/regress-613820-1.js:12: strict mode: Test262Error: Actual [aaa, aa, a] and expected [aa, a, a] should have the same contents.
test262/test/staging/sm/RegExp/regress-613820-2.js:12: Test262Error: Actual [foobar, f, o, o, b, a, r] and expected [foobar, undefined, undefined, undefined, b, a, r] should have the same contents.
test262/test/staging/sm/RegExp/regress-613820-2.js:12: strict mode: Test262Error: Actual [foobar, f, o, o, b, a, r] and expected [foobar, undefined, undefined, undefined, b, a, r] should have the same contents.
test262/test/staging/sm/RegExp/regress-613820-3.js:12: Test262Error: Actual [aab, a, undefined, ab] and expected [aa, undefined, a, undefined] should have the same contents.
test262/test/staging/sm/RegExp/regress-613820-3.js:12: strict mode: Test262Error: Actual [aab, a, undefined, ab] and expected [aa, undefined, a, undefined] should have the same contents.
test262/test/staging/sm/TypedArray/constructor-buffer-sequence.js:73: Error: Assertion failed: expected exception ExpectedError, got Error: Poisoned Value
test262/test/staging/sm/TypedArray/prototype-constructor-identity.js:17: Test262Error: Expected SameValue(«2», «6») to be true
test262/test/staging/sm/TypedArray/set-detached-bigint.js:27: Error: Assertion failed: expected exception SyntaxError, got RangeError: invalid array length
test262/test/staging/sm/TypedArray/set-detached.js:112: RangeError: invalid array length
test262/test/staging/sm/TypedArray/sort-negative-nan.js:102: TypeError: cannot read property 'name' of undefined
test262/test/staging/sm/TypedArray/sort_modifications.js:12: Test262Error: Int8Array at index 0 for size 4 Expected SameValue(«0», «1») to be true
test262/test/staging/sm/TypedArray/subarray.js:15: Test262Error: Expected SameValue(«0», «1») to be true
test262/test/staging/sm/async-functions/async-contains-unicode-escape.js:45: Error: Assertion failed: expected exception SyntaxError, no exception thrown
test262/test/staging/sm/async-functions/await-error.js:12: Test262Error: Expected SameValue(«false», «true») to be true
test262/test/staging/sm/async-functions/await-in-arrow-parameters.js:33: Error: Assertion failed: expected exception SyntaxError, no exception thrown - AsyncFunction:(a = (b = await/r/g) => {}) => {}
test262/test/staging/sm/class/boundFunctionSubclassing.js:12: Test262Error: Expected SameValue(«false», «true») to be true
test262/test/staging/sm/class/compPropNames.js:26: Error: Expected syntax error: ({[1, 2]: 3})
test262/test/staging/sm/class/methDefn.js:26: Error: Expected syntax error: b = {a() => 0}
test262/test/staging/sm/class/strictExecution.js:32: Error: Assertion failed: expected exception TypeError, no exception thrown
test262/test/staging/sm/class/superPropOrdering.js:83: Error: Assertion failed: expected exception TypeError, no exception thrown
test262/test/staging/sm/expressions/optional-chain.js:25: Error: Assertion failed: expected exception SyntaxError, no exception thrown
test262/test/staging/sm/expressions/short-circuit-compound-assignment-const.js:97: TypeError: 'a' is read-only
test262/test/staging/sm/expressions/short-circuit-compound-assignment-tdz.js:23: Error: Assertion failed: expected exception ReferenceError, got TypeError: 'a' is read-only
test262/test/staging/sm/extensions/TypedArray-set-object-funky-length-detaches.js:55: RangeError: invalid array length
test262/test/staging/sm/extensions/regress-469625-01.js:16: Test262Error: TM: Array prototype and expression closures Expected SameValue(«"TypeError: [].__proto__ is not a function"», «"TypeError: not a function"») to be true
test262/test/staging/sm/generators/syntax.js:30: Error: Assertion failed: expected SyntaxError, but no exception thrown - function* g() { (function* yield() {}); }
test262/test/staging/sm/lexical-environment/block-scoped-functions-annex-b-arguments.js:14: Test262Error: Expected SameValue(«"object"», «"function"») to be true
test262/test/staging/sm/lexical-environment/block-scoped-functions-annex-b-eval.js:12: Test262Error: Expected SameValue(«"outer-gouter-geval-gtruefalseq"», «"outer-geval-gwith-gtruefalseq"») to be true
test262/test/staging/sm/lexical-environment/block-scoped-functions-annex-b-if.js:20: TypeError: not a function
test262/test/staging/sm/lexical-environment/block-scoped-functions-annex-b-notapplicable.js:15: Test262Error: Expected SameValue(«function x() {2}», «function x() {1}») to be true
test262/test/staging/sm/lexical-environment/block-scoped-functions-deprecated-redecl.js:23: Test262Error: Expected SameValue(«3», «4») to be true
test262/test/staging/sm/lexical-environment/unscopables-proto.js:15: Test262Error: Expected SameValue(«true», «false») to be true
test262/test/staging/sm/lexical-environment/var-in-catch-body-annex-b-eval.js:17: Test262Error: Expected SameValue(«"g"», «"global-x"») to be true
test262/test/staging/sm/module/module-export-name-star.js:15: SyntaxError: identifier expected
test262/test/staging/sm/object/defineProperties-order.js:14: Test262Error: Expected SameValue(«"ownKeys,getOwnPropertyDescriptor,getOwnPropertyDescriptor,get,get"», «"ownKeys,getOwnPropertyDescriptor,get,getOwnPropertyDescriptor,get"») to be true
test262/test/staging/sm/object/defineProperty-proxy.js:32: Test262Error: Expected ["has configurable", "get configurable", "has writable", "get writable", "has enumerable", "get enumerable", "has value", "get value", "has get", "has set"] to be structurally equal to ["has enumerable", "get enumerable", "has configurable", "get configurable", "has value", "get value", "has writable", "get writable", "has get", "has set"].
test262/test/staging/sm/regress/regress-577648-1.js:21: Test262Error: 1 Expected SameValue(«true», «false») to be true
test262/test/staging/sm/regress/regress-577648-2.js:14: Test262Error: Expected SameValue(«true», «false») to be true
test262/test/staging/sm/regress/regress-584355.js:12: Test262Error: Expected SameValue(«"function f () { ff (); }"», «"undefined"») to be true
test262/test/staging/sm/regress/regress-586482-1.js:19: Test262Error: ok Expected SameValue(«true», «false») to be true
test262/test/staging/sm/regress/regress-586482-2.js:19: Test262Error: ok Expected SameValue(«true», «false») to be true
test262/test/staging/sm/regress/regress-586482-3.js:18: Test262Error: ok Expected SameValue(«true», «false») to be true
test262/test/staging/sm/regress/regress-586482-4.js:14: Test262Error: ok Expected SameValue(«function() { this.f(); }», «undefined») to be true
test262/test/staging/sm/regress/regress-602621.js:14: Test262Error: function sub-statement must override arguments Expected SameValue(«"function"», «"object"») to be true
test262/test/staging/sm/regress/regress-699682.js:15: Test262Error: Expected SameValue(«false», «true») to be true
test262/test/staging/sm/regress/regress-1383630.js:30: Error: Assertion failed: expected exception TypeError, no exception thrown
test262/test/staging/sm/statements/arrow-function-in-for-statement-head.js:15: Test262Error: expected syntax error, got Error: didn't throw Expected SameValue(«false», «true») to be true
test262/test/staging/sm/statements/regress-642975.js:14: Test262Error: Expected SameValue(«undefined», «"y"») to be true
test262/test/staging/sm/statements/try-completion.js:17: Test262Error: Expected SameValue(«"try"», «undefined») to be true
test262/test/staging/sm/syntax/syntax-parsed-arrow-then-directive.js:77: Test262Error: stack should contain 'http://example.com/foo.js': block, semi Expected SameValue(«false», «true») to be true

View File

@ -3,14 +3,8 @@ export function assert(actual, expected, message) {
expected = true;
if (typeof actual === typeof expected) {
if (actual === expected) {
if (actual !== 0 || (1 / actual) === (1 / expected))
if (Object.is(actual, expected))
return;
}
if (typeof actual === 'number') {
if (isNaN(actual) && isNaN(expected))
return;
}
if (typeof actual === 'object') {
if (actual !== null && expected !== null
&& actual.constructor === expected.constructor

View File

@ -71,10 +71,10 @@ index b397be0..c197ddc 100644
return result;
}
diff --git a/harness/sm/non262.js b/harness/sm/non262.js
index c1829e3..3a3ee27 100644
index 89df923..79ded15 100644
--- a/harness/sm/non262.js
+++ b/harness/sm/non262.js
@@ -41,8 +41,6 @@ globalThis.createNewGlobal = function() {
@@ -34,8 +34,6 @@ globalThis.createNewGlobal = function() {
return $262.createRealm().global
}
@ -83,13 +83,43 @@ index c1829e3..3a3ee27 100644
function assertEq(...args) {
assert.sameValue(...args)
}
@@ -71,4 +69,4 @@ if (globalThis.createExternalArrayBuffer === undefined) {
if (globalThis.enableGeckoProfilingWithSlowAssertions === undefined) {
globalThis.enableGeckoProfilingWithSlowAssertions = globalThis.enableGeckoProfiling =
globalThis.disableGeckoProfiling = () => {}
-}
\ No newline at end of file
+}
diff --git a/test/staging/sm/extensions/regress-469625-01.js b/test/staging/sm/extensions/regress-469625-01.js
index 81f84fc..4652002 100644
--- a/test/staging/sm/extensions/regress-469625-01.js
+++ b/test/staging/sm/extensions/regress-469625-01.js
@@ -14,8 +14,7 @@ esid: pending
//-----------------------------------------------------------------------------
var BUGNUMBER = 469625;
var summary = 'TM: Array prototype and expression closures';
-var actual = '';
-var expect = '';
+var actual = null;
//-----------------------------------------------------------------------------
@@ -24,9 +23,6 @@ test();
function test()
{
- expect = 'TypeError: [].__proto__ is not a function';
-
-
Array.prototype.__proto__ = function () { return 3; };
try
@@ -35,8 +31,10 @@ function test()
}
catch(ex)
{
- print(actual = ex + '');
+ print(ex + '');
+ actual = ex;
}
- assert.sameValue(expect, actual, summary);
+ assert.sameValue(actual instanceof TypeError, true);
+ assert.sameValue(actual.message.includes("not a function"), true);
}
diff --git a/test/staging/sm/misc/new-with-non-constructor.js b/test/staging/sm/misc/new-with-non-constructor.js
index 18c2f0c..f9aa209 100644
--- a/test/staging/sm/misc/new-with-non-constructor.js

View File

@ -42,6 +42,7 @@ function isArrayLike(a)
(a instanceof Int8Array) ||
(a instanceof Int16Array) ||
(a instanceof Int32Array) ||
(a instanceof Float16Array) ||
(a instanceof Float32Array) ||
(a instanceof Float64Array);
}
@ -85,7 +86,7 @@ function toStr(a)
case "undefined":
return "undefined";
case "string":
return a.__quote();
return JSON.stringify(a);
case "number":
if (a == 0 && 1 / a < 0)
return "-0";
@ -157,6 +158,7 @@ function bjson_test_all()
bjson_test([new Date(1234), new String("abc"), new Number(-12.1), new Boolean(true)]);
bjson_test(new Int32Array([123123, 222111, -32222]));
bjson_test(new Float16Array([1024, 1024.5]));
bjson_test(new Float64Array([123123, 222111.5]));
/* tested with a circular reference */

View File

@ -489,6 +489,9 @@ function test_typed_array()
a = new Uint16Array(buffer, 2);
a[0] = -1;
a = new Float16Array(buffer, 8, 1);
a[0] = 1;
a = new Float32Array(buffer, 8, 1);
a[0] = 1;
@ -593,7 +596,7 @@ function test_json()
]
]`);
assert_json_error('\n" @\\x"');
assert_json_error('\n" \\@x"');
assert_json_error('\n{ "a": @x }"');
}
@ -748,6 +751,51 @@ function test_regexp()
assert(a, ["123a23", "3"]);
a = /()*?a/.exec(",");
assert(a, null);
/* test \b escape */
assert(/[\q{a\b}]/.test("a\b"), true);
assert(/[\b]/.test("\b"), true);
/* test case insensitive matching (test262 hardly tests it) */
assert("aAbBcC#4".replace(/\p{Lower}/gu,"X"), "XAXBXC#4");
assert("aAbBcC#4".replace(/\p{Lower}/gui,"X"), "XXXXXX#4");
assert("aAbBcC#4".replace(/\p{Upper}/gui,"X"), "XXXXXX#4");
assert("aAbBcC#4".replace(/\P{Lower}/gui,"X"), "XXXXXXXX");
assert("aAbBcC#4".replace(/\P{Upper}/gui,"X"), "XXXXXXXX");
assert("aAbBcC".replace(/[^b]/gui, "X"), "XXbBXX");
assert("aAbBcC".replace(/[^A-B]/gui, "X"), "aAbBXX");
assert("aAbBcC#4".replace(/\p{Lower}/gvi,"X"), "XXXXXX#4");
assert("aAbBcC#4".replace(/\P{Lower}/gvi,"X"), "aAbBcCXX");
assert("aAbBcC#4".replace(/[^\P{Lower}]/gvi,"X"), "XXXXXX#4");
assert("aAbBcC#4".replace(/\P{Upper}/gvi,"X"), "aAbBcCXX");
assert("aAbBcC".replace(/[^b]/gvi, "X"), "XXbBXX");
assert("aAbBcC".replace(/[^A-B]/gvi, "X"), "aAbBXX");
assert("aAbBcC".replace(/[[a-c]&&B]/gvi, "X"), "aAXXcC");
assert("aAbBcC".replace(/[[a-c]--B]/gvi, "X"), "XXbBXX");
assert("abcAbC".replace(/[\q{AbC}]/gvi,"X"), "XX");
/* Note: SpiderMonkey and v8 may not be correct */
assert("abcAbC".replace(/[\q{BC|A}]/gvi,"X"), "XXXX");
assert("abcAbC".replace(/[\q{BC|A}--a]/gvi,"X"), "aXAX");
/* case where lastIndex points to the second element of a
surrogate pair */
a = /(?:)/gu;
a.lastIndex = 1;
a.exec("🐱");
assert(a.lastIndex, 0);
a.lastIndex = 1;
a.exec("a\udc00");
assert(a.lastIndex, 1);
a = /\u{10000}/vgd;
a.lastIndex = 1;
a = a.exec("\u{10000}_\u{10000}");
assert(a.indices[0][0], 0);
assert(a.indices[0][1], 2);
}
function test_symbol()

View File

@ -2,7 +2,7 @@ function assert(actual, expected, message) {
if (arguments.length == 1)
expected = true;
if (actual === expected)
if (Object.is(actual, expected))
return;
if (actual !== null && expected !== null

View File

@ -6,7 +6,7 @@ function assert(actual, expected, message) {
if (arguments.length == 1)
expected = true;
if (actual === expected)
if (Object.is(actual, expected))
return;
if (actual !== null && expected !== null
@ -129,15 +129,27 @@ function test_popen()
function test_ext_json()
{
var expected, input, obj;
expected = '{"x":false,"y":true,"z2":null,"a":[1,8,160],"s":"str"}';
expected = '{"x":false,"y":true,"z2":null,"a":[1,8,160],"b":"abc\\u000bd","s":"str"}';
input = `{ "x":false, /*comments are allowed */
"y":true, // also a comment
z2:null, // unquoted property names
"a":[+1,0o10,0xa0,], // plus prefix, octal, hexadecimal
"s":"str",} // trailing comma in objects and arrays
"b": "ab\
c\\vd", // multi-line strings, '\v' escape
"s":'str',} // trailing comma in objects and arrays, single quoted string
`;
obj = std.parseExtJSON(input);
assert(JSON.stringify(obj), expected);
obj = std.parseExtJSON('[Infinity, +Infinity, -Infinity, NaN, +NaN, -NaN, .1, -.2]');
assert(obj[0], Infinity);
assert(obj[1], Infinity);
assert(obj[2], -Infinity);
assert(obj[3], NaN);
assert(obj[4], NaN);
assert(obj[5], NaN);
assert(obj[6], 0.1);
assert(obj[7], -0.2);
}
function test_os()
@ -294,6 +306,22 @@ function test_async_gc()
})();
}
/* check that the promise async rejection handler is not invoked when
the rejection is handled not too late after the promise
rejection. */
function test_async_promise_rejection()
{
var counter = 0;
var p1, p2, p3;
p1 = Promise.reject();
p2 = Promise.reject();
p3 = Promise.resolve();
p1.catch(() => counter++);
p2.catch(() => counter++);
p3.then(() => counter++)
os.setTimeout(() => { assert(counter, 3) }, 10);
}
test_printf();
test_file1();
test_file2();
@ -304,4 +332,5 @@ test_os_exec();
test_timer();
test_ext_json();
test_async_gc();
test_async_promise_rejection();

View File

@ -1,8 +1,9 @@
#!/bin/sh
set -e
url="ftp://ftp.unicode.org/Public/16.0.0/ucd"
emoji_url="${url}/emoji/emoji-data.txt"
version="16.0.0"
emoji_version="16.0"
url="ftp://ftp.unicode.org/Public"
files="CaseFolding.txt DerivedNormalizationProps.txt PropList.txt \
SpecialCasing.txt CompositionExclusions.txt ScriptExtensions.txt \
@ -12,8 +13,11 @@ PropertyValueAliases.txt"
mkdir -p unicode
for f in $files; do
g="${url}/${f}"
g="${url}/${version}/ucd/${f}"
wget $g -O unicode/$f
done
wget $emoji_url -O unicode/emoji-data.txt
wget "${url}/${version}/ucd/emoji/emoji-data.txt" -O unicode/emoji-data.txt
wget "${url}/emoji/${emoji_version}/emoji-sequences.txt" -O unicode/emoji-sequences.txt
wget "${url}/emoji/${emoji_version}/emoji-zwj-sequences.txt" -O unicode/emoji-zwj-sequences.txt

View File

@ -156,6 +156,153 @@ char *get_line(char *buf, int buf_size, FILE *f)
return buf;
}
typedef struct REString {
struct REString *next;
uint32_t hash;
uint32_t len;
uint32_t flags;
uint32_t buf[];
} REString;
typedef struct {
uint32_t n_strings;
uint32_t hash_size;
int hash_bits;
REString **hash_table;
} REStringList;
static uint32_t re_string_hash(int len, const uint32_t *buf)
{
int i;
uint32_t h;
h = 1;
for(i = 0; i < len; i++)
h = h * 263 + buf[i];
return h * 0x61C88647;
}
static void re_string_list_init(REStringList *s)
{
s->n_strings = 0;
s->hash_size = 0;
s->hash_bits = 0;
s->hash_table = NULL;
}
static __maybe_unused void re_string_list_free(REStringList *s)
{
REString *p, *p_next;
int i;
for(i = 0; i < s->hash_size; i++) {
for(p = s->hash_table[i]; p != NULL; p = p_next) {
p_next = p->next;
free(p);
}
}
free(s->hash_table);
}
static void lre_print_char(int c, BOOL is_range)
{
if (c == '\'' || c == '\\' ||
(is_range && (c == '-' || c == ']'))) {
printf("\\%c", c);
} else if (c >= ' ' && c <= 126) {
printf("%c", c);
} else {
printf("\\u{%04x}", c);
}
}
static __maybe_unused void re_string_list_dump(const char *str, const REStringList *s)
{
REString *p;
int i, j, k;
printf("%s:\n", str);
j = 0;
for(i = 0; i < s->hash_size; i++) {
for(p = s->hash_table[i]; p != NULL; p = p->next) {
printf(" %d/%d: '", j, s->n_strings);
for(k = 0; k < p->len; k++) {
lre_print_char(p->buf[k], FALSE);
}
printf("'\n");
j++;
}
}
}
static REString *re_string_find2(REStringList *s, int len, const uint32_t *buf,
uint32_t h0, BOOL add_flag)
{
uint32_t h = 0; /* avoid warning */
REString *p;
if (s->n_strings != 0) {
h = h0 >> (32 - s->hash_bits);
for(p = s->hash_table[h]; p != NULL; p = p->next) {
if (p->hash == h0 && p->len == len &&
!memcmp(p->buf, buf, len * sizeof(buf[0]))) {
return p;
}
}
}
/* not found */
if (!add_flag)
return NULL;
/* increase the size of the hash table if needed */
if (unlikely((s->n_strings + 1) > s->hash_size)) {
REString **new_hash_table, *p_next;
int new_hash_bits, i;
uint32_t new_hash_size;
new_hash_bits = max_int(s->hash_bits + 1, 4);
new_hash_size = 1 << new_hash_bits;
new_hash_table = malloc(sizeof(new_hash_table[0]) * new_hash_size);
if (!new_hash_table)
return NULL;
memset(new_hash_table, 0, sizeof(new_hash_table[0]) * new_hash_size);
for(i = 0; i < s->hash_size; i++) {
for(p = s->hash_table[i]; p != NULL; p = p_next) {
p_next = p->next;
h = p->hash >> (32 - new_hash_bits);
p->next = new_hash_table[h];
new_hash_table[h] = p;
}
}
free(s->hash_table);
s->hash_bits = new_hash_bits;
s->hash_size = new_hash_size;
s->hash_table = new_hash_table;
h = h0 >> (32 - s->hash_bits);
}
p = malloc(sizeof(REString) + len * sizeof(buf[0]));
if (!p)
return NULL;
p->next = s->hash_table[h];
s->hash_table[h] = p;
s->n_strings++;
p->hash = h0;
p->len = len;
p->flags = 0;
memcpy(p->buf, buf, sizeof(buf[0]) * len);
return p;
}
static REString *re_string_find(REStringList *s, int len, const uint32_t *buf,
BOOL add_flag)
{
uint32_t h0;
h0 = re_string_hash(len, buf);
return re_string_find2(s, len, buf, h0, add_flag);
}
static void re_string_add(REStringList *s, int len, const uint32_t *buf)
{
re_string_find(s, len, buf, TRUE);
}
#define UNICODE_GENERAL_CATEGORY
typedef enum {
@ -225,6 +372,23 @@ static const char *unicode_prop_short_name[] = {
#undef UNICODE_PROP_LIST
#define UNICODE_SEQUENCE_PROP_LIST
typedef enum {
#define DEF(id) SEQUENCE_PROP_ ## id,
#include "unicode_gen_def.h"
#undef DEF
SEQUENCE_PROP_COUNT,
} UnicodeSequencePropEnum1;
static const char *unicode_sequence_prop_name[] = {
#define DEF(id) #id,
#include "unicode_gen_def.h"
#undef DEF
};
#undef UNICODE_SEQUENCE_PROP_LIST
typedef struct {
/* case conv */
uint8_t u_len;
@ -247,7 +411,15 @@ typedef struct {
int *decomp_data;
} CCInfo;
typedef struct {
int count;
int size;
int *tab;
} UnicodeSequenceProperties;
CCInfo *unicode_db;
REStringList rgi_emoji_zwj_sequence;
DynBuf rgi_emoji_tag_sequence;
int find_name(const char **tab, int tab_len, const char *name)
{
@ -751,6 +923,147 @@ void parse_prop_list(const char *filename)
fclose(f);
}
#define SEQ_MAX_LEN 16
static BOOL is_emoji_modifier(uint32_t c)
{
return (c >= 0x1f3fb && c <= 0x1f3ff);
}
static void add_sequence_prop(int idx, int seq_len, int *seq)
{
int i;
assert(idx < SEQUENCE_PROP_COUNT);
switch(idx) {
case SEQUENCE_PROP_Basic_Emoji:
/* convert to 2 properties lists */
if (seq_len == 1) {
set_prop(seq[0], PROP_Basic_Emoji1, 1);
} else if (seq_len == 2 && seq[1] == 0xfe0f) {
set_prop(seq[0], PROP_Basic_Emoji2, 1);
} else {
abort();
}
break;
case SEQUENCE_PROP_RGI_Emoji_Modifier_Sequence:
assert(seq_len == 2);
assert(is_emoji_modifier(seq[1]));
assert(get_prop(seq[0], PROP_Emoji_Modifier_Base));
set_prop(seq[0], PROP_RGI_Emoji_Modifier_Sequence, 1);
break;
case SEQUENCE_PROP_RGI_Emoji_Flag_Sequence:
{
int code;
assert(seq_len == 2);
assert(seq[0] >= 0x1F1E6 && seq[0] <= 0x1F1FF);
assert(seq[1] >= 0x1F1E6 && seq[1] <= 0x1F1FF);
code = (seq[0] - 0x1F1E6) * 26 + (seq[1] - 0x1F1E6);
/* XXX: would be more compact with a simple bitmap -> 676 bits */
set_prop(code, PROP_RGI_Emoji_Flag_Sequence, 1);
}
break;
case SEQUENCE_PROP_RGI_Emoji_ZWJ_Sequence:
re_string_add(&rgi_emoji_zwj_sequence, seq_len, (uint32_t *)seq);
break;
case SEQUENCE_PROP_RGI_Emoji_Tag_Sequence:
{
assert(seq_len >= 3);
assert(seq[0] == 0x1F3F4);
assert(seq[seq_len - 1] == 0xE007F);
for(i = 1; i < seq_len - 1; i++) {
assert(seq[i] >= 0xe0001 && seq[i] <= 0xe007e);
dbuf_putc(&rgi_emoji_tag_sequence, seq[i] - 0xe0000);
}
dbuf_putc(&rgi_emoji_tag_sequence, 0);
}
break;
case SEQUENCE_PROP_Emoji_Keycap_Sequence:
assert(seq_len == 3);
assert(seq[1] == 0xfe0f);
assert(seq[2] == 0x20e3);
set_prop(seq[0], PROP_Emoji_Keycap_Sequence, 1);
break;
default:
assert(0);
}
}
void parse_sequence_prop_list(const char *filename)
{
FILE *f;
char line[4096], *p, buf[256], *q, *p_start;
uint32_t c0, c1, c;
int idx, seq_len;
int seq[SEQ_MAX_LEN];
f = fopen(filename, "rb");
if (!f) {
perror(filename);
exit(1);
}
for(;;) {
if (!get_line(line, sizeof(line), f))
break;
p = line;
while (isspace(*p))
p++;
if (*p == '#' || *p == '@' || *p == '\0')
continue;
p_start = p;
/* find the sequence property name */
p = strchr(p, ';');
if (!p)
continue;
p++;
p += strspn(p, " \t");
q = buf;
while (*p != '\0' && *p != ' ' && *p != '#' && *p != '\t' && *p != ';') {
if ((q - buf) < sizeof(buf) - 1)
*q++ = *p;
p++;
}
*q = '\0';
idx = find_name(unicode_sequence_prop_name,
countof(unicode_sequence_prop_name), buf);
if (idx < 0) {
fprintf(stderr, "Property not found: %s\n", buf);
exit(1);
}
p = p_start;
c0 = strtoul(p, (char **)&p, 16);
assert(c0 <= CHARCODE_MAX);
if (*p == '.' && p[1] == '.') {
p += 2;
c1 = strtoul(p, (char **)&p, 16);
assert(c1 <= CHARCODE_MAX);
for(c = c0; c <= c1; c++) {
seq[0] = c;
add_sequence_prop(idx, 1, seq);
}
} else {
seq_len = 0;
seq[seq_len++] = c0;
for(;;) {
while (isspace(*p))
p++;
if (*p == ';' || *p == '\0')
break;
c0 = strtoul(p, (char **)&p, 16);
assert(c0 <= CHARCODE_MAX);
assert(seq_len < countof(seq));
seq[seq_len++] = c0;
}
add_sequence_prop(idx, seq_len, seq);
}
}
fclose(f);
}
void parse_scripts(const char *filename)
{
FILE *f;
@ -1654,7 +1967,7 @@ void dump_name_table(FILE *f, const char *cname, const char **tab_name, int len,
maxw = 0;
for(i = 0; i < len; i++) {
w = strlen(tab_name[i]);
if (tab_short_name[i][0] != '\0') {
if (tab_short_name && tab_short_name[i][0] != '\0') {
w += 1 + strlen(tab_short_name[i]);
}
if (maxw < w)
@ -1666,7 +1979,7 @@ void dump_name_table(FILE *f, const char *cname, const char **tab_name, int len,
for(i = 0; i < len; i++) {
fprintf(f, " \"");
w = fprintf(f, "%s", tab_name[i]);
if (tab_short_name[i][0] != '\0') {
if (tab_short_name && tab_short_name[i][0] != '\0') {
w += fprintf(f, ",%s", tab_short_name[i]);
}
fprintf(f, "\"%*s\"\\0\"\n", 1 + maxw - w, "");
@ -1774,10 +2087,9 @@ void build_script_table(FILE *f)
fprintf(f, " UNICODE_SCRIPT_COUNT,\n");
fprintf(f, "} UnicodeScriptEnum;\n\n");
i = 1;
dump_name_table(f, "unicode_script_name_table",
unicode_script_name + i, SCRIPT_COUNT - i,
unicode_script_short_name + i);
unicode_script_name, SCRIPT_COUNT,
unicode_script_short_name);
dbuf_init(dbuf);
#ifdef DUMP_TABLE_SIZE
@ -1930,6 +2242,218 @@ void build_prop_list_table(FILE *f)
fprintf(f, "};\n\n");
}
static BOOL is_emoji_hair_color(uint32_t c)
{
return (c >= 0x1F9B0 && c <= 0x1F9B3);
}
#define EMOJI_MOD_NONE 0
#define EMOJI_MOD_TYPE1 1
#define EMOJI_MOD_TYPE2 2
#define EMOJI_MOD_TYPE2D 3
static BOOL mark_zwj_string(REStringList *sl, uint32_t *buf, int len, int mod_type, int *mod_pos,
int hc_pos, BOOL mark_flag)
{
REString *p;
int i, n_mod, i0, i1, hc_count, j;
#if 0
if (mark_flag)
printf("mod_type=%d\n", mod_type);
#endif
switch(mod_type) {
case EMOJI_MOD_NONE:
n_mod = 1;
break;
case EMOJI_MOD_TYPE1:
n_mod = 5;
break;
case EMOJI_MOD_TYPE2:
n_mod = 25;
break;
case EMOJI_MOD_TYPE2D:
n_mod = 20;
break;
default:
assert(0);
}
if (hc_pos >= 0)
hc_count = 4;
else
hc_count = 1;
/* check that all the related strings are present */
for(j = 0; j < hc_count; j++) {
for(i = 0; i < n_mod; i++) {
switch(mod_type) {
case EMOJI_MOD_NONE:
break;
case EMOJI_MOD_TYPE1:
buf[mod_pos[0]] = 0x1f3fb + i;
break;
case EMOJI_MOD_TYPE2:
case EMOJI_MOD_TYPE2D:
i0 = i / 5;
i1 = i % 5;
/* avoid identical values */
if (mod_type == EMOJI_MOD_TYPE2D && i0 >= i1)
i0++;
buf[mod_pos[0]] = 0x1f3fb + i0;
buf[mod_pos[1]] = 0x1f3fb + i1;
break;
default:
assert(0);
}
if (hc_pos >= 0)
buf[hc_pos] = 0x1F9B0 + j;
p = re_string_find(sl, len, buf, FALSE);
if (!p)
return FALSE;
if (mark_flag)
p->flags |= 1;
}
}
return TRUE;
}
static void zwj_encode_string(DynBuf *dbuf, const uint32_t *buf, int len, int mod_type, int *mod_pos,
int hc_pos)
{
int i, j;
int c, code;
uint32_t buf1[SEQ_MAX_LEN];
j = 0;
for(i = 0; i < len;) {
c = buf[i++];
if (c >= 0x2000 && c <= 0x2fff) {
code = c - 0x2000;
} else if (c >= 0x1f000 && c <= 0x1ffff) {
code = c - 0x1f000 + 0x1000;
} else {
assert(0);
}
if (i < len && is_emoji_modifier(buf[i])) {
/* modifier */
code |= (mod_type << 13);
i++;
}
if (i < len && buf[i] == 0xfe0f) {
/* presentation selector present */
code |= 0x8000;
i++;
}
if (i < len) {
/* zero width join */
assert(buf[i] == 0x200d);
i++;
}
buf1[j++] = code;
}
dbuf_putc(dbuf, j);
for(i = 0; i < j; i++) {
dbuf_putc(dbuf, buf1[i]);
dbuf_putc(dbuf, buf1[i] >> 8);
}
}
static void build_rgi_emoji_zwj_sequence(FILE *f, REStringList *sl)
{
int mod_pos[2], mod_count, hair_color_pos, j, h;
REString *p;
uint32_t buf[SEQ_MAX_LEN];
DynBuf dbuf;
#if 0
{
for(h = 0; h < sl->hash_size; h++) {
for(p = sl->hash_table[h]; p != NULL; p = p->next) {
for(j = 0; j < p->len; j++)
printf(" %04x", p->buf[j]);
printf("\n");
}
}
exit(0);
}
#endif
// printf("rgi_emoji_zwj_sequence: n=%d\n", sl->n_strings);
dbuf_init(&dbuf);
/* avoid duplicating strings with emoji modifiers or hair colors */
for(h = 0; h < sl->hash_size; h++) {
for(p = sl->hash_table[h]; p != NULL; p = p->next) {
if (p->flags) /* already examined */
continue;
mod_count = 0;
hair_color_pos = -1;
for(j = 0; j < p->len; j++) {
if (is_emoji_modifier(p->buf[j])) {
assert(mod_count < 2);
mod_pos[mod_count++] = j;
} else if (is_emoji_hair_color(p->buf[j])) {
hair_color_pos = j;
}
buf[j] = p->buf[j];
}
if (mod_count != 0 || hair_color_pos >= 0) {
int mod_type;
if (mod_count == 0)
mod_type = EMOJI_MOD_NONE;
else if (mod_count == 1)
mod_type = EMOJI_MOD_TYPE1;
else
mod_type = EMOJI_MOD_TYPE2;
if (mark_zwj_string(sl, buf, p->len, mod_type, mod_pos, hair_color_pos, FALSE)) {
mark_zwj_string(sl, buf, p->len, mod_type, mod_pos, hair_color_pos, TRUE);
} else if (mod_type == EMOJI_MOD_TYPE2) {
mod_type = EMOJI_MOD_TYPE2D;
if (mark_zwj_string(sl, buf, p->len, mod_type, mod_pos, hair_color_pos, FALSE)) {
mark_zwj_string(sl, buf, p->len, mod_type, mod_pos, hair_color_pos, TRUE);
} else {
dump_str("not_found", (int *)p->buf, p->len);
goto keep;
}
}
if (hair_color_pos >= 0)
buf[hair_color_pos] = 0x1f9b0;
/* encode the string */
zwj_encode_string(&dbuf, buf, p->len, mod_type, mod_pos, hair_color_pos);
} else {
keep:
zwj_encode_string(&dbuf, buf, p->len, EMOJI_MOD_NONE, NULL, -1);
}
}
}
/* Encode */
dump_byte_table(f, "unicode_rgi_emoji_zwj_sequence", dbuf.buf, dbuf.size);
dbuf_free(&dbuf);
}
void build_sequence_prop_list_table(FILE *f)
{
int i;
fprintf(f, "typedef enum {\n");
for(i = 0; i < SEQUENCE_PROP_COUNT; i++)
fprintf(f, " UNICODE_SEQUENCE_PROP_%s,\n", unicode_sequence_prop_name[i]);
fprintf(f, " UNICODE_SEQUENCE_PROP_COUNT,\n");
fprintf(f, "} UnicodeSequencePropertyEnum;\n\n");
dump_name_table(f, "unicode_sequence_prop_name_table",
unicode_sequence_prop_name, SEQUENCE_PROP_COUNT, NULL);
dump_byte_table(f, "unicode_rgi_emoji_tag_sequence", rgi_emoji_tag_sequence.buf, rgi_emoji_tag_sequence.size);
build_rgi_emoji_zwj_sequence(f, &rgi_emoji_zwj_sequence);
}
#ifdef USE_TEST
int check_conv(uint32_t *res, uint32_t c, int conv_type)
{
@ -3156,6 +3680,8 @@ int main(int argc, char *argv[])
outfilename = argv[arg++];
unicode_db = mallocz(sizeof(unicode_db[0]) * (CHARCODE_MAX + 1));
re_string_list_init(&rgi_emoji_zwj_sequence);
dbuf_init(&rgi_emoji_tag_sequence);
snprintf(filename, sizeof(filename), "%s/UnicodeData.txt", unicode_db_path);
@ -3190,6 +3716,14 @@ int main(int argc, char *argv[])
unicode_db_path);
parse_prop_list(filename);
snprintf(filename, sizeof(filename), "%s/emoji-sequences.txt",
unicode_db_path);
parse_sequence_prop_list(filename);
snprintf(filename, sizeof(filename), "%s/emoji-zwj-sequences.txt",
unicode_db_path);
parse_sequence_prop_list(filename);
// dump_unicode_data(unicode_db);
build_conv_table(unicode_db);
@ -3234,10 +3768,12 @@ int main(int argc, char *argv[])
build_script_table(fo);
build_script_ext_table(fo);
build_prop_list_table(fo);
build_sequence_prop_list_table(fo);
fprintf(fo, "#endif /* CONFIG_ALL_UNICODE */\n");
fprintf(fo, "/* %u tables / %u bytes, %u index / %u bytes */\n",
total_tables, total_table_bytes, total_index, total_index_bytes);
fclose(fo);
}
re_string_list_free(&rgi_emoji_zwj_sequence);
return 0;
}

View File

@ -234,6 +234,11 @@ DEF(XID_Continue1, "")
DEF(Changes_When_Titlecased1, "")
DEF(Changes_When_Casefolded1, "")
DEF(Changes_When_NFKC_Casefolded1, "")
DEF(Basic_Emoji1, "")
DEF(Basic_Emoji2, "")
DEF(RGI_Emoji_Modifier_Sequence, "")
DEF(RGI_Emoji_Flag_Sequence, "")
DEF(Emoji_Keycap_Sequence, "")
/* Prop list exported to JS */
DEF(ASCII_Hex_Digit, "AHex")
@ -301,3 +306,13 @@ DEF(XID_Start, "XIDS")
DEF(Cased1, "")
#endif
#ifdef UNICODE_SEQUENCE_PROP_LIST
DEF(Basic_Emoji)
DEF(Emoji_Keycap_Sequence)
DEF(RGI_Emoji_Modifier_Sequence)
DEF(RGI_Emoji_Flag_Sequence)
DEF(RGI_Emoji_Tag_Sequence)
DEF(RGI_Emoji_ZWJ_Sequence)
DEF(RGI_Emoji)
#endif