quickjs 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/quickjsrb/quickjs/cutils.h +56 -0
- data/ext/quickjsrb/quickjs/libregexp-opcode.h +11 -1
- data/ext/quickjsrb/quickjs/libregexp.c +883 -132
- data/ext/quickjsrb/quickjs/libregexp.h +1 -0
- data/ext/quickjsrb/quickjs/libunicode-table.h +420 -1
- data/ext/quickjsrb/quickjs/libunicode.c +224 -11
- data/ext/quickjsrb/quickjs/libunicode.h +9 -5
- data/ext/quickjsrb/quickjs/qjs.c +1 -1
- data/ext/quickjsrb/quickjs/qjsc.c +81 -26
- data/ext/quickjsrb/quickjs/quickjs-atom.h +7 -0
- data/ext/quickjsrb/quickjs/quickjs-libc.c +254 -65
- data/ext/quickjsrb/quickjs/quickjs-libc.h +7 -1
- data/ext/quickjsrb/quickjs/quickjs-opcode.h +2 -2
- data/ext/quickjsrb/quickjs/quickjs.c +2021 -686
- data/ext/quickjsrb/quickjs/quickjs.h +52 -8
- data/ext/quickjsrb/quickjs/run-test262.c +109 -32
- data/ext/quickjsrb/quickjs/unicode_gen.c +541 -5
- data/ext/quickjsrb/quickjs/unicode_gen_def.h +15 -0
- data/ext/quickjsrb/quickjsrb.c +1 -1
- data/lib/quickjs/version.rb +1 -1
- metadata +2 -2
@@ -456,7 +456,11 @@ void JS_FreeAtom(JSContext *ctx, JSAtom v);
|
|
456
456
|
void JS_FreeAtomRT(JSRuntime *rt, JSAtom v);
|
457
457
|
JSValue JS_AtomToValue(JSContext *ctx, JSAtom atom);
|
458
458
|
JSValue JS_AtomToString(JSContext *ctx, JSAtom atom);
|
459
|
-
const char *
|
459
|
+
const char *JS_AtomToCStringLen(JSContext *ctx, size_t *plen, JSAtom atom);
|
460
|
+
static inline const char *JS_AtomToCString(JSContext *ctx, JSAtom atom)
|
461
|
+
{
|
462
|
+
return JS_AtomToCStringLen(ctx, NULL, atom);
|
463
|
+
}
|
460
464
|
JSAtom JS_ValueToAtom(JSContext *ctx, JSValueConst val);
|
461
465
|
|
462
466
|
/* object class support */
|
@@ -659,11 +663,10 @@ static inline JS_BOOL JS_IsObject(JSValueConst v)
|
|
659
663
|
}
|
660
664
|
|
661
665
|
JSValue JS_Throw(JSContext *ctx, JSValue obj);
|
666
|
+
void JS_SetUncatchableException(JSContext *ctx, JS_BOOL flag);
|
662
667
|
JSValue JS_GetException(JSContext *ctx);
|
663
668
|
JS_BOOL JS_HasException(JSContext *ctx);
|
664
669
|
JS_BOOL JS_IsError(JSContext *ctx, JSValueConst val);
|
665
|
-
void JS_SetUncatchableError(JSContext *ctx, JSValueConst val, JS_BOOL flag);
|
666
|
-
void JS_ResetUncatchableError(JSContext *ctx);
|
667
670
|
JSValue JS_NewError(JSContext *ctx);
|
668
671
|
JSValue __js_printf_like(2, 3) JS_ThrowSyntaxError(JSContext *ctx, const char *fmt, ...);
|
669
672
|
JSValue __js_printf_like(2, 3) JS_ThrowTypeError(JSContext *ctx, const char *fmt, ...);
|
@@ -806,6 +809,8 @@ JSValue JS_GetPrototype(JSContext *ctx, JSValueConst val);
|
|
806
809
|
|
807
810
|
int JS_GetOwnPropertyNames(JSContext *ctx, JSPropertyEnum **ptab,
|
808
811
|
uint32_t *plen, JSValueConst obj, int flags);
|
812
|
+
void JS_FreePropertyEnum(JSContext *ctx, JSPropertyEnum *tab,
|
813
|
+
uint32_t len);
|
809
814
|
int JS_GetOwnProperty(JSContext *ctx, JSPropertyDescriptor *desc,
|
810
815
|
JSValueConst obj, JSAtom prop);
|
811
816
|
|
@@ -872,6 +877,7 @@ typedef enum JSTypedArrayEnum {
|
|
872
877
|
JS_TYPED_ARRAY_UINT32,
|
873
878
|
JS_TYPED_ARRAY_BIG_INT64,
|
874
879
|
JS_TYPED_ARRAY_BIG_UINT64,
|
880
|
+
JS_TYPED_ARRAY_FLOAT16,
|
875
881
|
JS_TYPED_ARRAY_FLOAT32,
|
876
882
|
JS_TYPED_ARRAY_FLOAT64,
|
877
883
|
} JSTypedArrayEnum;
|
@@ -930,12 +936,25 @@ typedef char *JSModuleNormalizeFunc(JSContext *ctx,
|
|
930
936
|
const char *module_name, void *opaque);
|
931
937
|
typedef JSModuleDef *JSModuleLoaderFunc(JSContext *ctx,
|
932
938
|
const char *module_name, void *opaque);
|
933
|
-
|
939
|
+
typedef JSModuleDef *JSModuleLoaderFunc2(JSContext *ctx,
|
940
|
+
const char *module_name, void *opaque,
|
941
|
+
JSValueConst attributes);
|
942
|
+
/* return -1 if exception, 0 if OK */
|
943
|
+
typedef int JSModuleCheckSupportedImportAttributes(JSContext *ctx, void *opaque,
|
944
|
+
JSValueConst attributes);
|
945
|
+
|
934
946
|
/* module_normalize = NULL is allowed and invokes the default module
|
935
947
|
filename normalizer */
|
936
948
|
void JS_SetModuleLoaderFunc(JSRuntime *rt,
|
937
949
|
JSModuleNormalizeFunc *module_normalize,
|
938
950
|
JSModuleLoaderFunc *module_loader, void *opaque);
|
951
|
+
/* same as JS_SetModuleLoaderFunc but with attributes. if
|
952
|
+
module_check_attrs = NULL, no attribute checking is done. */
|
953
|
+
void JS_SetModuleLoaderFunc2(JSRuntime *rt,
|
954
|
+
JSModuleNormalizeFunc *module_normalize,
|
955
|
+
JSModuleLoaderFunc2 *module_loader,
|
956
|
+
JSModuleCheckSupportedImportAttributes *module_check_attrs,
|
957
|
+
void *opaque);
|
939
958
|
/* return the import.meta object of a module */
|
940
959
|
JSValue JS_GetImportMeta(JSContext *ctx, JSModuleDef *m);
|
941
960
|
JSAtom JS_GetModuleName(JSContext *ctx, JSModuleDef *m);
|
@@ -1030,7 +1049,9 @@ static inline JSValue JS_NewCFunctionMagic(JSContext *ctx, JSCFunctionMagic *fun
|
|
1030
1049
|
const char *name,
|
1031
1050
|
int length, JSCFunctionEnum cproto, int magic)
|
1032
1051
|
{
|
1033
|
-
|
1052
|
+
/* Used to squelch a -Wcast-function-type warning. */
|
1053
|
+
JSCFunctionType ft = { .generic_magic = func };
|
1054
|
+
return JS_NewCFunction2(ctx, ft.generic, name, length, cproto, magic);
|
1034
1055
|
}
|
1035
1056
|
void JS_SetConstructor(JSContext *ctx, JSValueConst func_obj,
|
1036
1057
|
JSValueConst proto);
|
@@ -1094,9 +1115,9 @@ typedef struct JSCFunctionListEntry {
|
|
1094
1115
|
#define JS_ALIAS_DEF(name, from) { name, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE, JS_DEF_ALIAS, 0, .u = { .alias = { from, -1 } } }
|
1095
1116
|
#define JS_ALIAS_BASE_DEF(name, from, base) { name, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE, JS_DEF_ALIAS, 0, .u = { .alias = { from, base } } }
|
1096
1117
|
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1118
|
+
int JS_SetPropertyFunctionList(JSContext *ctx, JSValueConst obj,
|
1119
|
+
const JSCFunctionListEntry *tab,
|
1120
|
+
int len);
|
1100
1121
|
|
1101
1122
|
/* C module definition */
|
1102
1123
|
|
@@ -1113,6 +1134,29 @@ int JS_SetModuleExport(JSContext *ctx, JSModuleDef *m, const char *export_name,
|
|
1113
1134
|
JSValue val);
|
1114
1135
|
int JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m,
|
1115
1136
|
const JSCFunctionListEntry *tab, int len);
|
1137
|
+
/* associate a JSValue to a C module */
|
1138
|
+
int JS_SetModulePrivateValue(JSContext *ctx, JSModuleDef *m, JSValue val);
|
1139
|
+
JSValue JS_GetModulePrivateValue(JSContext *ctx, JSModuleDef *m);
|
1140
|
+
|
1141
|
+
/* debug value output */
|
1142
|
+
|
1143
|
+
typedef struct {
|
1144
|
+
JS_BOOL show_hidden : 8; /* only show enumerable properties */
|
1145
|
+
JS_BOOL raw_dump : 8; /* avoid doing autoinit and avoid any malloc() call (for internal use) */
|
1146
|
+
uint32_t max_depth; /* recurse up to this depth, 0 = no limit */
|
1147
|
+
uint32_t max_string_length; /* print no more than this length for
|
1148
|
+
strings, 0 = no limit */
|
1149
|
+
uint32_t max_item_count; /* print no more than this count for
|
1150
|
+
arrays or objects, 0 = no limit */
|
1151
|
+
} JSPrintValueOptions;
|
1152
|
+
|
1153
|
+
typedef void JSPrintValueWrite(void *opaque, const char *buf, size_t len);
|
1154
|
+
|
1155
|
+
void JS_PrintValueSetDefaultOptions(JSPrintValueOptions *options);
|
1156
|
+
void JS_PrintValueRT(JSRuntime *rt, JSPrintValueWrite *write_func, void *write_opaque,
|
1157
|
+
JSValueConst val, const JSPrintValueOptions *options);
|
1158
|
+
void JS_PrintValue(JSContext *ctx, JSPrintValueWrite *write_func, void *write_opaque,
|
1159
|
+
JSValueConst val, const JSPrintValueOptions *options);
|
1116
1160
|
|
1117
1161
|
#undef js_unlikely
|
1118
1162
|
#undef js_force_inline
|
@@ -78,6 +78,7 @@ char *harness_dir;
|
|
78
78
|
char *harness_exclude;
|
79
79
|
char *harness_features;
|
80
80
|
char *harness_skip_features;
|
81
|
+
int *harness_skip_features_count;
|
81
82
|
char *error_filename;
|
82
83
|
char *error_file;
|
83
84
|
FILE *error_out;
|
@@ -372,26 +373,39 @@ static void enumerate_tests(const char *path)
|
|
372
373
|
namelist_cmp_indirect);
|
373
374
|
}
|
374
375
|
|
376
|
+
static void js_print_value_write(void *opaque, const char *buf, size_t len)
|
377
|
+
{
|
378
|
+
FILE *fo = opaque;
|
379
|
+
fwrite(buf, 1, len, fo);
|
380
|
+
}
|
381
|
+
|
375
382
|
static JSValue js_print(JSContext *ctx, JSValueConst this_val,
|
376
383
|
int argc, JSValueConst *argv)
|
377
384
|
{
|
378
385
|
int i;
|
379
|
-
|
380
|
-
|
386
|
+
JSValueConst v;
|
387
|
+
|
381
388
|
if (outfile) {
|
382
389
|
for (i = 0; i < argc; i++) {
|
383
390
|
if (i != 0)
|
384
391
|
fputc(' ', outfile);
|
385
|
-
|
386
|
-
if (
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
+
v = argv[i];
|
393
|
+
if (JS_IsString(v)) {
|
394
|
+
const char *str;
|
395
|
+
size_t len;
|
396
|
+
str = JS_ToCStringLen(ctx, &len, v);
|
397
|
+
if (!str)
|
398
|
+
return JS_EXCEPTION;
|
399
|
+
if (!strcmp(str, "Test262:AsyncTestComplete")) {
|
400
|
+
async_done++;
|
401
|
+
} else if (strstart(str, "Test262:AsyncTestFailure", NULL)) {
|
402
|
+
async_done = 2; /* force an error */
|
403
|
+
}
|
404
|
+
fwrite(str, 1, len, outfile);
|
405
|
+
JS_FreeCString(ctx, str);
|
406
|
+
} else {
|
407
|
+
JS_PrintValue(ctx, js_print_value_write, outfile, v, NULL);
|
392
408
|
}
|
393
|
-
fputs(str, outfile);
|
394
|
-
JS_FreeCString(ctx, str);
|
395
409
|
}
|
396
410
|
fputc('\n', outfile);
|
397
411
|
}
|
@@ -483,8 +497,7 @@ static void *agent_start(void *arg)
|
|
483
497
|
JS_FreeValue(ctx, ret_val);
|
484
498
|
|
485
499
|
for(;;) {
|
486
|
-
|
487
|
-
ret = JS_ExecutePendingJob(JS_GetRuntime(ctx), &ctx1);
|
500
|
+
ret = JS_ExecutePendingJob(JS_GetRuntime(ctx), NULL);
|
488
501
|
if (ret < 0) {
|
489
502
|
js_std_dump_error(ctx);
|
490
503
|
break;
|
@@ -823,13 +836,21 @@ static char *load_file(const char *filename, size_t *lenp)
|
|
823
836
|
return buf;
|
824
837
|
}
|
825
838
|
|
839
|
+
static int json_module_init_test(JSContext *ctx, JSModuleDef *m)
|
840
|
+
{
|
841
|
+
JSValue val;
|
842
|
+
val = JS_GetModulePrivateValue(ctx, m);
|
843
|
+
JS_SetModuleExport(ctx, m, "default", val);
|
844
|
+
return 0;
|
845
|
+
}
|
846
|
+
|
826
847
|
static JSModuleDef *js_module_loader_test(JSContext *ctx,
|
827
|
-
const char *module_name, void *opaque
|
848
|
+
const char *module_name, void *opaque,
|
849
|
+
JSValueConst attributes)
|
828
850
|
{
|
829
851
|
size_t buf_len;
|
830
852
|
uint8_t *buf;
|
831
853
|
JSModuleDef *m;
|
832
|
-
JSValue func_val;
|
833
854
|
char *filename, *slash, path[1024];
|
834
855
|
|
835
856
|
// interpret import("bar.js") from path/to/foo.js as
|
@@ -851,15 +872,33 @@ static JSModuleDef *js_module_loader_test(JSContext *ctx,
|
|
851
872
|
return NULL;
|
852
873
|
}
|
853
874
|
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
875
|
+
if (js_module_test_json(ctx, attributes) == 1) {
|
876
|
+
/* compile as JSON */
|
877
|
+
JSValue val;
|
878
|
+
val = JS_ParseJSON(ctx, (char *)buf, buf_len, module_name);
|
879
|
+
js_free(ctx, buf);
|
880
|
+
if (JS_IsException(val))
|
881
|
+
return NULL;
|
882
|
+
m = JS_NewCModule(ctx, module_name, json_module_init_test);
|
883
|
+
if (!m) {
|
884
|
+
JS_FreeValue(ctx, val);
|
885
|
+
return NULL;
|
886
|
+
}
|
887
|
+
/* only export the "default" symbol which will contain the JSON object */
|
888
|
+
JS_AddModuleExport(ctx, m, "default");
|
889
|
+
JS_SetModulePrivateValue(ctx, m, val);
|
890
|
+
} else {
|
891
|
+
JSValue func_val;
|
892
|
+
/* compile the module */
|
893
|
+
func_val = JS_Eval(ctx, (char *)buf, buf_len, module_name,
|
894
|
+
JS_EVAL_TYPE_MODULE | JS_EVAL_FLAG_COMPILE_ONLY);
|
895
|
+
js_free(ctx, buf);
|
896
|
+
if (JS_IsException(func_val))
|
897
|
+
return NULL;
|
898
|
+
/* the module is already referenced, so we must free it */
|
899
|
+
m = JS_VALUE_GET_PTR(func_val);
|
900
|
+
JS_FreeValue(ctx, func_val);
|
901
|
+
}
|
863
902
|
return m;
|
864
903
|
}
|
865
904
|
|
@@ -1231,8 +1270,7 @@ static int eval_buf(JSContext *ctx, const char *buf, size_t buf_len,
|
|
1231
1270
|
JS_FreeValue(ctx, res_val);
|
1232
1271
|
}
|
1233
1272
|
for(;;) {
|
1234
|
-
|
1235
|
-
ret = JS_ExecutePendingJob(JS_GetRuntime(ctx), &ctx1);
|
1273
|
+
ret = JS_ExecutePendingJob(JS_GetRuntime(ctx), NULL);
|
1236
1274
|
if (ret < 0) {
|
1237
1275
|
res_val = JS_EXCEPTION;
|
1238
1276
|
break;
|
@@ -1574,7 +1612,7 @@ int run_test_buf(const char *filename, const char *harness, namelist_t *ip,
|
|
1574
1612
|
JS_SetCanBlock(rt, can_block);
|
1575
1613
|
|
1576
1614
|
/* loader for ES6 modules */
|
1577
|
-
|
1615
|
+
JS_SetModuleLoaderFunc2(rt, NULL, js_module_loader_test, NULL, (void *)filename);
|
1578
1616
|
|
1579
1617
|
add_helpers(ctx);
|
1580
1618
|
|
@@ -1699,10 +1737,13 @@ int run_test(const char *filename, int index)
|
|
1699
1737
|
p = find_tag(desc, "features:", &state);
|
1700
1738
|
if (p) {
|
1701
1739
|
while ((option = get_option(&p, &state)) != NULL) {
|
1740
|
+
char *p1;
|
1702
1741
|
if (find_word(harness_features, option)) {
|
1703
1742
|
/* feature is enabled */
|
1704
|
-
} else if (find_word(harness_skip_features, option)) {
|
1743
|
+
} else if ((p1 = find_word(harness_skip_features, option)) != NULL) {
|
1705
1744
|
/* skip disabled feature */
|
1745
|
+
if (harness_skip_features_count)
|
1746
|
+
harness_skip_features_count[p1 - harness_skip_features]++;
|
1706
1747
|
skip |= 1;
|
1707
1748
|
} else {
|
1708
1749
|
/* feature is not listed: skip and warn */
|
@@ -1875,7 +1916,7 @@ int run_test262_harness_test(const char *filename, BOOL is_module)
|
|
1875
1916
|
JS_SetCanBlock(rt, can_block);
|
1876
1917
|
|
1877
1918
|
/* loader for ES6 modules */
|
1878
|
-
|
1919
|
+
JS_SetModuleLoaderFunc2(rt, NULL, js_module_loader_test, NULL, (void *)filename);
|
1879
1920
|
|
1880
1921
|
add_helpers(ctx);
|
1881
1922
|
|
@@ -1899,10 +1940,9 @@ int run_test262_harness_test(const char *filename, BOOL is_module)
|
|
1899
1940
|
JS_FreeValue(ctx, res_val);
|
1900
1941
|
}
|
1901
1942
|
for(;;) {
|
1902
|
-
|
1903
|
-
ret = JS_ExecutePendingJob(JS_GetRuntime(ctx), &ctx1);
|
1943
|
+
ret = JS_ExecutePendingJob(JS_GetRuntime(ctx), NULL);
|
1904
1944
|
if (ret < 0) {
|
1905
|
-
js_std_dump_error(
|
1945
|
+
js_std_dump_error(ctx);
|
1906
1946
|
ret_code = 1;
|
1907
1947
|
} else if (ret == 0) {
|
1908
1948
|
break;
|
@@ -2036,6 +2076,7 @@ int main(int argc, char **argv)
|
|
2036
2076
|
const char *ignore = "";
|
2037
2077
|
BOOL is_test262_harness = FALSE;
|
2038
2078
|
BOOL is_module = FALSE;
|
2079
|
+
BOOL count_skipped_features = FALSE;
|
2039
2080
|
clock_t clocks;
|
2040
2081
|
|
2041
2082
|
#if !defined(_WIN32)
|
@@ -2103,6 +2144,8 @@ int main(int argc, char **argv)
|
|
2103
2144
|
is_test262_harness = TRUE;
|
2104
2145
|
} else if (str_equal(arg, "--module")) {
|
2105
2146
|
is_module = TRUE;
|
2147
|
+
} else if (str_equal(arg, "--count_skipped_features")) {
|
2148
|
+
count_skipped_features = TRUE;
|
2106
2149
|
} else {
|
2107
2150
|
fatal(1, "unknown option: %s", arg);
|
2108
2151
|
break;
|
@@ -2137,6 +2180,14 @@ int main(int argc, char **argv)
|
|
2137
2180
|
|
2138
2181
|
clocks = clock();
|
2139
2182
|
|
2183
|
+
if (count_skipped_features) {
|
2184
|
+
/* not storage efficient but it is simple */
|
2185
|
+
size_t size;
|
2186
|
+
size = sizeof(harness_skip_features_count[0]) * strlen(harness_skip_features);
|
2187
|
+
harness_skip_features_count = malloc(size);
|
2188
|
+
memset(harness_skip_features_count, 0, size);
|
2189
|
+
}
|
2190
|
+
|
2140
2191
|
if (is_dir_list) {
|
2141
2192
|
if (optind < argc && !isdigit((unsigned char)argv[optind][0])) {
|
2142
2193
|
filename = argv[optind++];
|
@@ -2187,6 +2238,30 @@ int main(int argc, char **argv)
|
|
2187
2238
|
printf("\n");
|
2188
2239
|
}
|
2189
2240
|
|
2241
|
+
if (count_skipped_features) {
|
2242
|
+
size_t i, n, len = strlen(harness_skip_features);
|
2243
|
+
BOOL disp = FALSE;
|
2244
|
+
int c;
|
2245
|
+
for(i = 0; i < len; i++) {
|
2246
|
+
if (harness_skip_features_count[i] != 0) {
|
2247
|
+
if (!disp) {
|
2248
|
+
disp = TRUE;
|
2249
|
+
printf("%-30s %7s\n", "SKIPPED FEATURE", "COUNT");
|
2250
|
+
}
|
2251
|
+
for(n = 0; n < 30; n++) {
|
2252
|
+
c = harness_skip_features[i + n];
|
2253
|
+
if (is_word_sep(c))
|
2254
|
+
break;
|
2255
|
+
putchar(c);
|
2256
|
+
}
|
2257
|
+
for(; n < 30; n++)
|
2258
|
+
putchar(' ');
|
2259
|
+
printf(" %7d\n", harness_skip_features_count[i]);
|
2260
|
+
}
|
2261
|
+
}
|
2262
|
+
printf("\n");
|
2263
|
+
}
|
2264
|
+
|
2190
2265
|
if (is_dir_list) {
|
2191
2266
|
fprintf(stderr, "Result: %d/%d error%s",
|
2192
2267
|
test_failed, test_count, test_count != 1 ? "s" : "");
|
@@ -2216,6 +2291,8 @@ int main(int argc, char **argv)
|
|
2216
2291
|
namelist_free(&exclude_list);
|
2217
2292
|
namelist_free(&exclude_dir_list);
|
2218
2293
|
free(harness_dir);
|
2294
|
+
free(harness_skip_features);
|
2295
|
+
free(harness_skip_features_count);
|
2219
2296
|
free(harness_features);
|
2220
2297
|
free(harness_exclude);
|
2221
2298
|
free(error_file);
|