quickjs 0.9.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.c +2 -0
- data/ext/quickjsrb/quickjs/cutils.h +56 -0
- data/ext/quickjsrb/quickjs/dtoa.c +5 -11
- 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 +2211 -1619
- data/ext/quickjsrb/quickjs/libunicode.c +224 -11
- data/ext/quickjsrb/quickjs/libunicode.h +9 -5
- data/ext/quickjsrb/quickjs/qjs.c +48 -9
- data/ext/quickjsrb/quickjs/qjsc.c +216 -73
- data/ext/quickjsrb/quickjs/quickjs-atom.h +14 -0
- data/ext/quickjsrb/quickjs/quickjs-libc.c +460 -174
- data/ext/quickjsrb/quickjs/quickjs-libc.h +7 -1
- data/ext/quickjsrb/quickjs/quickjs-opcode.h +5 -4
- data/ext/quickjsrb/quickjs/quickjs.c +4503 -1614
- data/ext/quickjsrb/quickjs/quickjs.h +82 -15
- data/ext/quickjsrb/quickjs/run-test262.c +119 -33
- data/ext/quickjsrb/quickjs/unicode_gen.c +560 -6
- data/ext/quickjsrb/quickjs/unicode_gen_def.h +27 -0
- data/ext/quickjsrb/quickjsrb.c +1 -1
- data/lib/quickjs/version.rb +1 -1
- metadata +2 -2
@@ -27,6 +27,7 @@
|
|
27
27
|
|
28
28
|
#include <stdio.h>
|
29
29
|
#include <stdint.h>
|
30
|
+
#include <string.h>
|
30
31
|
|
31
32
|
#ifdef __cplusplus
|
32
33
|
extern "C" {
|
@@ -48,7 +49,6 @@ extern "C" {
|
|
48
49
|
|
49
50
|
typedef struct JSRuntime JSRuntime;
|
50
51
|
typedef struct JSContext JSContext;
|
51
|
-
typedef struct JSObject JSObject;
|
52
52
|
typedef struct JSClass JSClass;
|
53
53
|
typedef uint32_t JSClassID;
|
54
54
|
typedef uint32_t JSAtom;
|
@@ -78,6 +78,7 @@ enum {
|
|
78
78
|
JS_TAG_BIG_INT = -9,
|
79
79
|
JS_TAG_SYMBOL = -8,
|
80
80
|
JS_TAG_STRING = -7,
|
81
|
+
JS_TAG_STRING_ROPE = -6,
|
81
82
|
JS_TAG_MODULE = -3, /* used internally */
|
82
83
|
JS_TAG_FUNCTION_BYTECODE = -2, /* used internally */
|
83
84
|
JS_TAG_OBJECT = -1,
|
@@ -280,8 +281,6 @@ static inline JSValue __JS_NewShortBigInt(JSContext *ctx, int64_t d)
|
|
280
281
|
#define JS_VALUE_IS_BOTH_INT(v1, v2) ((JS_VALUE_GET_TAG(v1) | JS_VALUE_GET_TAG(v2)) == 0)
|
281
282
|
#define JS_VALUE_IS_BOTH_FLOAT(v1, v2) (JS_TAG_IS_FLOAT64(JS_VALUE_GET_TAG(v1)) && JS_TAG_IS_FLOAT64(JS_VALUE_GET_TAG(v2)))
|
282
283
|
|
283
|
-
#define JS_VALUE_GET_OBJ(v) ((JSObject *)JS_VALUE_GET_PTR(v))
|
284
|
-
#define JS_VALUE_GET_STRING(v) ((JSString *)JS_VALUE_GET_PTR(v))
|
285
284
|
#define JS_VALUE_HAS_REF_COUNT(v) ((unsigned)JS_VALUE_GET_TAG(v) >= (unsigned)JS_TAG_FIRST)
|
286
285
|
|
287
286
|
/* special values */
|
@@ -323,7 +322,9 @@ static inline JSValue __JS_NewShortBigInt(JSContext *ctx, int64_t d)
|
|
323
322
|
#define JS_PROP_NO_ADD (1 << 16) /* internal use */
|
324
323
|
#define JS_PROP_NO_EXOTIC (1 << 17) /* internal use */
|
325
324
|
|
326
|
-
#
|
325
|
+
#ifndef JS_DEFAULT_STACK_SIZE
|
326
|
+
#define JS_DEFAULT_STACK_SIZE (1024 * 1024)
|
327
|
+
#endif
|
327
328
|
|
328
329
|
/* JS_Eval() flags */
|
329
330
|
#define JS_EVAL_TYPE_GLOBAL (0 << 0) /* global code (default) */
|
@@ -333,7 +334,6 @@ static inline JSValue __JS_NewShortBigInt(JSContext *ctx, int64_t d)
|
|
333
334
|
#define JS_EVAL_TYPE_MASK (3 << 0)
|
334
335
|
|
335
336
|
#define JS_EVAL_FLAG_STRICT (1 << 3) /* force 'strict' mode */
|
336
|
-
#define JS_EVAL_FLAG_STRIP (1 << 4) /* force 'strip' mode */
|
337
337
|
/* compile but do not run. The result is an object with a
|
338
338
|
JS_TAG_FUNCTION_BYTECODE or JS_TAG_MODULE tag. It can be executed
|
339
339
|
with JS_EvalFunction(). */
|
@@ -406,6 +406,7 @@ void JS_AddIntrinsicProxy(JSContext *ctx);
|
|
406
406
|
void JS_AddIntrinsicMapSet(JSContext *ctx);
|
407
407
|
void JS_AddIntrinsicTypedArrays(JSContext *ctx);
|
408
408
|
void JS_AddIntrinsicPromise(JSContext *ctx);
|
409
|
+
void JS_AddIntrinsicWeakRef(JSContext *ctx);
|
409
410
|
|
410
411
|
JSValue js_string_codePointRange(JSContext *ctx, JSValueConst this_val,
|
411
412
|
int argc, JSValueConst *argv);
|
@@ -455,7 +456,11 @@ void JS_FreeAtom(JSContext *ctx, JSAtom v);
|
|
455
456
|
void JS_FreeAtomRT(JSRuntime *rt, JSAtom v);
|
456
457
|
JSValue JS_AtomToValue(JSContext *ctx, JSAtom atom);
|
457
458
|
JSValue JS_AtomToString(JSContext *ctx, JSAtom atom);
|
458
|
-
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
|
+
}
|
459
464
|
JSAtom JS_ValueToAtom(JSContext *ctx, JSValueConst val);
|
460
465
|
|
461
466
|
/* object class support */
|
@@ -500,6 +505,17 @@ typedef struct JSClassExoticMethods {
|
|
500
505
|
/* return < 0 if exception or TRUE/FALSE */
|
501
506
|
int (*set_property)(JSContext *ctx, JSValueConst obj, JSAtom atom,
|
502
507
|
JSValueConst value, JSValueConst receiver, int flags);
|
508
|
+
|
509
|
+
/* To get a consistent object behavior when get_prototype != NULL,
|
510
|
+
get_property, set_property and set_prototype must be != NULL
|
511
|
+
and the object must be created with a JS_NULL prototype. */
|
512
|
+
JSValue (*get_prototype)(JSContext *ctx, JSValueConst obj);
|
513
|
+
/* return < 0 if exception or TRUE/FALSE */
|
514
|
+
int (*set_prototype)(JSContext *ctx, JSValueConst obj, JSValueConst proto_val);
|
515
|
+
/* return < 0 if exception or TRUE/FALSE */
|
516
|
+
int (*is_extensible)(JSContext *ctx, JSValueConst obj);
|
517
|
+
/* return < 0 if exception or TRUE/FALSE */
|
518
|
+
int (*prevent_extensions)(JSContext *ctx, JSValueConst obj);
|
503
519
|
} JSClassExoticMethods;
|
504
520
|
|
505
521
|
typedef void JSClassFinalizer(JSRuntime *rt, JSValue val);
|
@@ -632,7 +648,8 @@ static inline JS_BOOL JS_IsUninitialized(JSValueConst v)
|
|
632
648
|
|
633
649
|
static inline JS_BOOL JS_IsString(JSValueConst v)
|
634
650
|
{
|
635
|
-
return JS_VALUE_GET_TAG(v) == JS_TAG_STRING
|
651
|
+
return JS_VALUE_GET_TAG(v) == JS_TAG_STRING ||
|
652
|
+
JS_VALUE_GET_TAG(v) == JS_TAG_STRING_ROPE;
|
636
653
|
}
|
637
654
|
|
638
655
|
static inline JS_BOOL JS_IsSymbol(JSValueConst v)
|
@@ -646,11 +663,10 @@ static inline JS_BOOL JS_IsObject(JSValueConst v)
|
|
646
663
|
}
|
647
664
|
|
648
665
|
JSValue JS_Throw(JSContext *ctx, JSValue obj);
|
666
|
+
void JS_SetUncatchableException(JSContext *ctx, JS_BOOL flag);
|
649
667
|
JSValue JS_GetException(JSContext *ctx);
|
650
668
|
JS_BOOL JS_HasException(JSContext *ctx);
|
651
669
|
JS_BOOL JS_IsError(JSContext *ctx, JSValueConst val);
|
652
|
-
void JS_SetUncatchableError(JSContext *ctx, JSValueConst val, JS_BOOL flag);
|
653
|
-
void JS_ResetUncatchableError(JSContext *ctx);
|
654
670
|
JSValue JS_NewError(JSContext *ctx);
|
655
671
|
JSValue __js_printf_like(2, 3) JS_ThrowSyntaxError(JSContext *ctx, const char *fmt, ...);
|
656
672
|
JSValue __js_printf_like(2, 3) JS_ThrowTypeError(JSContext *ctx, const char *fmt, ...);
|
@@ -717,7 +733,10 @@ int JS_ToBigInt64(JSContext *ctx, int64_t *pres, JSValueConst val);
|
|
717
733
|
int JS_ToInt64Ext(JSContext *ctx, int64_t *pres, JSValueConst val);
|
718
734
|
|
719
735
|
JSValue JS_NewStringLen(JSContext *ctx, const char *str1, size_t len1);
|
720
|
-
JSValue JS_NewString(JSContext *ctx, const char *str)
|
736
|
+
static inline JSValue JS_NewString(JSContext *ctx, const char *str)
|
737
|
+
{
|
738
|
+
return JS_NewStringLen(ctx, str, strlen(str));
|
739
|
+
}
|
721
740
|
JSValue JS_NewAtomString(JSContext *ctx, const char *str);
|
722
741
|
JSValue JS_ToString(JSContext *ctx, JSValueConst val);
|
723
742
|
JSValue JS_ToPropertyKey(JSContext *ctx, JSValueConst val);
|
@@ -790,6 +809,8 @@ JSValue JS_GetPrototype(JSContext *ctx, JSValueConst val);
|
|
790
809
|
|
791
810
|
int JS_GetOwnPropertyNames(JSContext *ctx, JSPropertyEnum **ptab,
|
792
811
|
uint32_t *plen, JSValueConst obj, int flags);
|
812
|
+
void JS_FreePropertyEnum(JSContext *ctx, JSPropertyEnum *tab,
|
813
|
+
uint32_t len);
|
793
814
|
int JS_GetOwnProperty(JSContext *ctx, JSPropertyDescriptor *desc,
|
794
815
|
JSValueConst obj, JSAtom prop);
|
795
816
|
|
@@ -827,6 +848,7 @@ int JS_DefinePropertyGetSet(JSContext *ctx, JSValueConst this_obj,
|
|
827
848
|
void JS_SetOpaque(JSValue obj, void *opaque);
|
828
849
|
void *JS_GetOpaque(JSValueConst obj, JSClassID class_id);
|
829
850
|
void *JS_GetOpaque2(JSContext *ctx, JSValueConst obj, JSClassID class_id);
|
851
|
+
void *JS_GetAnyOpaque(JSValueConst obj, JSClassID *class_id);
|
830
852
|
|
831
853
|
/* 'buf' must be zero terminated i.e. buf[buf_len] = '\0'. */
|
832
854
|
JSValue JS_ParseJSON(JSContext *ctx, const char *buf, size_t buf_len,
|
@@ -855,6 +877,7 @@ typedef enum JSTypedArrayEnum {
|
|
855
877
|
JS_TYPED_ARRAY_UINT32,
|
856
878
|
JS_TYPED_ARRAY_BIG_INT64,
|
857
879
|
JS_TYPED_ARRAY_BIG_UINT64,
|
880
|
+
JS_TYPED_ARRAY_FLOAT16,
|
858
881
|
JS_TYPED_ARRAY_FLOAT32,
|
859
882
|
JS_TYPED_ARRAY_FLOAT64,
|
860
883
|
} JSTypedArrayEnum;
|
@@ -895,6 +918,12 @@ typedef int JSInterruptHandler(JSRuntime *rt, void *opaque);
|
|
895
918
|
void JS_SetInterruptHandler(JSRuntime *rt, JSInterruptHandler *cb, void *opaque);
|
896
919
|
/* if can_block is TRUE, Atomics.wait() can be used */
|
897
920
|
void JS_SetCanBlock(JSRuntime *rt, JS_BOOL can_block);
|
921
|
+
/* select which debug info is stripped from the compiled code */
|
922
|
+
#define JS_STRIP_SOURCE (1 << 0) /* strip source code */
|
923
|
+
#define JS_STRIP_DEBUG (1 << 1) /* strip all debug info including source code */
|
924
|
+
void JS_SetStripInfo(JSRuntime *rt, int flags);
|
925
|
+
int JS_GetStripInfo(JSRuntime *rt);
|
926
|
+
|
898
927
|
/* set the [IsHTMLDDA] internal slot */
|
899
928
|
void JS_SetIsHTMLDDA(JSContext *ctx, JSValueConst obj);
|
900
929
|
|
@@ -907,12 +936,25 @@ typedef char *JSModuleNormalizeFunc(JSContext *ctx,
|
|
907
936
|
const char *module_name, void *opaque);
|
908
937
|
typedef JSModuleDef *JSModuleLoaderFunc(JSContext *ctx,
|
909
938
|
const char *module_name, void *opaque);
|
910
|
-
|
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
|
+
|
911
946
|
/* module_normalize = NULL is allowed and invokes the default module
|
912
947
|
filename normalizer */
|
913
948
|
void JS_SetModuleLoaderFunc(JSRuntime *rt,
|
914
949
|
JSModuleNormalizeFunc *module_normalize,
|
915
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);
|
916
958
|
/* return the import.meta object of a module */
|
917
959
|
JSValue JS_GetImportMeta(JSContext *ctx, JSModuleDef *m);
|
918
960
|
JSAtom JS_GetModuleName(JSContext *ctx, JSModuleDef *m);
|
@@ -1007,7 +1049,9 @@ static inline JSValue JS_NewCFunctionMagic(JSContext *ctx, JSCFunctionMagic *fun
|
|
1007
1049
|
const char *name,
|
1008
1050
|
int length, JSCFunctionEnum cproto, int magic)
|
1009
1051
|
{
|
1010
|
-
|
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);
|
1011
1055
|
}
|
1012
1056
|
void JS_SetConstructor(JSContext *ctx, JSValueConst func_obj,
|
1013
1057
|
JSValueConst proto);
|
@@ -1071,9 +1115,9 @@ typedef struct JSCFunctionListEntry {
|
|
1071
1115
|
#define JS_ALIAS_DEF(name, from) { name, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE, JS_DEF_ALIAS, 0, .u = { .alias = { from, -1 } } }
|
1072
1116
|
#define JS_ALIAS_BASE_DEF(name, from, base) { name, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE, JS_DEF_ALIAS, 0, .u = { .alias = { from, base } } }
|
1073
1117
|
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1118
|
+
int JS_SetPropertyFunctionList(JSContext *ctx, JSValueConst obj,
|
1119
|
+
const JSCFunctionListEntry *tab,
|
1120
|
+
int len);
|
1077
1121
|
|
1078
1122
|
/* C module definition */
|
1079
1123
|
|
@@ -1090,6 +1134,29 @@ int JS_SetModuleExport(JSContext *ctx, JSModuleDef *m, const char *export_name,
|
|
1090
1134
|
JSValue val);
|
1091
1135
|
int JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m,
|
1092
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);
|
1093
1160
|
|
1094
1161
|
#undef js_unlikely
|
1095
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;
|
@@ -757,6 +770,13 @@ static JSValue js_IsHTMLDDA(JSContext *ctx, JSValue this_val,
|
|
757
770
|
return JS_NULL;
|
758
771
|
}
|
759
772
|
|
773
|
+
static JSValue js_gc(JSContext *ctx, JSValueConst this_val,
|
774
|
+
int argc, JSValueConst *argv)
|
775
|
+
{
|
776
|
+
JS_RunGC(JS_GetRuntime(ctx));
|
777
|
+
return JS_UNDEFINED;
|
778
|
+
}
|
779
|
+
|
760
780
|
static JSValue add_helpers1(JSContext *ctx)
|
761
781
|
{
|
762
782
|
JSValue global_obj;
|
@@ -790,6 +810,8 @@ static JSValue add_helpers1(JSContext *ctx)
|
|
790
810
|
obj = JS_NewCFunction(ctx, js_IsHTMLDDA, "IsHTMLDDA", 0);
|
791
811
|
JS_SetIsHTMLDDA(ctx, obj);
|
792
812
|
JS_SetPropertyStr(ctx, obj262, "IsHTMLDDA", obj);
|
813
|
+
JS_SetPropertyStr(ctx, obj262, "gc",
|
814
|
+
JS_NewCFunction(ctx, js_gc, "gc", 0));
|
793
815
|
|
794
816
|
JS_SetPropertyStr(ctx, global_obj, "$262", JS_DupValue(ctx, obj262));
|
795
817
|
|
@@ -814,13 +836,21 @@ static char *load_file(const char *filename, size_t *lenp)
|
|
814
836
|
return buf;
|
815
837
|
}
|
816
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
|
+
|
817
847
|
static JSModuleDef *js_module_loader_test(JSContext *ctx,
|
818
|
-
const char *module_name, void *opaque
|
848
|
+
const char *module_name, void *opaque,
|
849
|
+
JSValueConst attributes)
|
819
850
|
{
|
820
851
|
size_t buf_len;
|
821
852
|
uint8_t *buf;
|
822
853
|
JSModuleDef *m;
|
823
|
-
JSValue func_val;
|
824
854
|
char *filename, *slash, path[1024];
|
825
855
|
|
826
856
|
// interpret import("bar.js") from path/to/foo.js as
|
@@ -842,15 +872,33 @@ static JSModuleDef *js_module_loader_test(JSContext *ctx,
|
|
842
872
|
return NULL;
|
843
873
|
}
|
844
874
|
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
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
|
+
}
|
854
902
|
return m;
|
855
903
|
}
|
856
904
|
|
@@ -1222,8 +1270,7 @@ static int eval_buf(JSContext *ctx, const char *buf, size_t buf_len,
|
|
1222
1270
|
JS_FreeValue(ctx, res_val);
|
1223
1271
|
}
|
1224
1272
|
for(;;) {
|
1225
|
-
|
1226
|
-
ret = JS_ExecutePendingJob(JS_GetRuntime(ctx), &ctx1);
|
1273
|
+
ret = JS_ExecutePendingJob(JS_GetRuntime(ctx), NULL);
|
1227
1274
|
if (ret < 0) {
|
1228
1275
|
res_val = JS_EXCEPTION;
|
1229
1276
|
break;
|
@@ -1565,13 +1612,13 @@ int run_test_buf(const char *filename, const char *harness, namelist_t *ip,
|
|
1565
1612
|
JS_SetCanBlock(rt, can_block);
|
1566
1613
|
|
1567
1614
|
/* loader for ES6 modules */
|
1568
|
-
|
1615
|
+
JS_SetModuleLoaderFunc2(rt, NULL, js_module_loader_test, NULL, (void *)filename);
|
1569
1616
|
|
1570
1617
|
add_helpers(ctx);
|
1571
1618
|
|
1572
1619
|
for (i = 0; i < ip->count; i++) {
|
1573
1620
|
if (eval_file(ctx, harness, ip->array[i],
|
1574
|
-
JS_EVAL_TYPE_GLOBAL
|
1621
|
+
JS_EVAL_TYPE_GLOBAL)) {
|
1575
1622
|
fatal(1, "error including %s for %s", ip->array[i], filename);
|
1576
1623
|
}
|
1577
1624
|
}
|
@@ -1690,10 +1737,13 @@ int run_test(const char *filename, int index)
|
|
1690
1737
|
p = find_tag(desc, "features:", &state);
|
1691
1738
|
if (p) {
|
1692
1739
|
while ((option = get_option(&p, &state)) != NULL) {
|
1740
|
+
char *p1;
|
1693
1741
|
if (find_word(harness_features, option)) {
|
1694
1742
|
/* feature is enabled */
|
1695
|
-
} else if (find_word(harness_skip_features, option)) {
|
1743
|
+
} else if ((p1 = find_word(harness_skip_features, option)) != NULL) {
|
1696
1744
|
/* skip disabled feature */
|
1745
|
+
if (harness_skip_features_count)
|
1746
|
+
harness_skip_features_count[p1 - harness_skip_features]++;
|
1697
1747
|
skip |= 1;
|
1698
1748
|
} else {
|
1699
1749
|
/* feature is not listed: skip and warn */
|
@@ -1866,7 +1916,7 @@ int run_test262_harness_test(const char *filename, BOOL is_module)
|
|
1866
1916
|
JS_SetCanBlock(rt, can_block);
|
1867
1917
|
|
1868
1918
|
/* loader for ES6 modules */
|
1869
|
-
|
1919
|
+
JS_SetModuleLoaderFunc2(rt, NULL, js_module_loader_test, NULL, (void *)filename);
|
1870
1920
|
|
1871
1921
|
add_helpers(ctx);
|
1872
1922
|
|
@@ -1890,10 +1940,9 @@ int run_test262_harness_test(const char *filename, BOOL is_module)
|
|
1890
1940
|
JS_FreeValue(ctx, res_val);
|
1891
1941
|
}
|
1892
1942
|
for(;;) {
|
1893
|
-
|
1894
|
-
ret = JS_ExecutePendingJob(JS_GetRuntime(ctx), &ctx1);
|
1943
|
+
ret = JS_ExecutePendingJob(JS_GetRuntime(ctx), NULL);
|
1895
1944
|
if (ret < 0) {
|
1896
|
-
js_std_dump_error(
|
1945
|
+
js_std_dump_error(ctx);
|
1897
1946
|
ret_code = 1;
|
1898
1947
|
} else if (ret == 0) {
|
1899
1948
|
break;
|
@@ -2027,6 +2076,7 @@ int main(int argc, char **argv)
|
|
2027
2076
|
const char *ignore = "";
|
2028
2077
|
BOOL is_test262_harness = FALSE;
|
2029
2078
|
BOOL is_module = FALSE;
|
2079
|
+
BOOL count_skipped_features = FALSE;
|
2030
2080
|
clock_t clocks;
|
2031
2081
|
|
2032
2082
|
#if !defined(_WIN32)
|
@@ -2094,6 +2144,8 @@ int main(int argc, char **argv)
|
|
2094
2144
|
is_test262_harness = TRUE;
|
2095
2145
|
} else if (str_equal(arg, "--module")) {
|
2096
2146
|
is_module = TRUE;
|
2147
|
+
} else if (str_equal(arg, "--count_skipped_features")) {
|
2148
|
+
count_skipped_features = TRUE;
|
2097
2149
|
} else {
|
2098
2150
|
fatal(1, "unknown option: %s", arg);
|
2099
2151
|
break;
|
@@ -2128,6 +2180,14 @@ int main(int argc, char **argv)
|
|
2128
2180
|
|
2129
2181
|
clocks = clock();
|
2130
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
|
+
|
2131
2191
|
if (is_dir_list) {
|
2132
2192
|
if (optind < argc && !isdigit((unsigned char)argv[optind][0])) {
|
2133
2193
|
filename = argv[optind++];
|
@@ -2178,6 +2238,30 @@ int main(int argc, char **argv)
|
|
2178
2238
|
printf("\n");
|
2179
2239
|
}
|
2180
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
|
+
|
2181
2265
|
if (is_dir_list) {
|
2182
2266
|
fprintf(stderr, "Result: %d/%d error%s",
|
2183
2267
|
test_failed, test_count, test_count != 1 ? "s" : "");
|
@@ -2207,6 +2291,8 @@ int main(int argc, char **argv)
|
|
2207
2291
|
namelist_free(&exclude_list);
|
2208
2292
|
namelist_free(&exclude_dir_list);
|
2209
2293
|
free(harness_dir);
|
2294
|
+
free(harness_skip_features);
|
2295
|
+
free(harness_skip_features_count);
|
2210
2296
|
free(harness_features);
|
2211
2297
|
free(harness_exclude);
|
2212
2298
|
free(error_file);
|