@mikrojs/quickjs 0.18.1 → 0.18.2
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.
- package/deps/quickjs/api-test.c +234 -0
- package/deps/quickjs/libregexp.c +18 -1
- package/deps/quickjs/libunicode-table.h +71 -84
- package/deps/quickjs/quickjs-libc.c +2 -2
- package/deps/quickjs/quickjs.c +103 -76
- package/deps/quickjs/quickjs.h +1 -1
- package/deps/quickjs/run-test262.c +22 -4
- package/deps/quickjs/unicode_gen.c +498 -2
- package/deps/quickjs/unicode_gen_def.h +16 -0
- package/package.json +1 -1
package/deps/quickjs/quickjs.c
CHANGED
|
@@ -4193,7 +4193,7 @@ bool JS_IsRegisteredClass(JSRuntime *rt, JSClassID class_id)
|
|
|
4193
4193
|
JSAtom JS_GetClassName(JSRuntime *rt, JSClassID class_id)
|
|
4194
4194
|
{
|
|
4195
4195
|
if (JS_IsRegisteredClass(rt, class_id)) {
|
|
4196
|
-
return JS_DupAtomRT(rt, rt->class_array[class_id].
|
|
4196
|
+
return JS_DupAtomRT(rt, rt->class_array[class_id].class_name);
|
|
4197
4197
|
} else {
|
|
4198
4198
|
return JS_ATOM_NULL;
|
|
4199
4199
|
}
|
|
@@ -6339,48 +6339,21 @@ JSValue JS_NewObjectProto(JSContext *ctx, JSValueConst proto)
|
|
|
6339
6339
|
JSValue JS_NewObjectFrom(JSContext *ctx, int count, const JSAtom *props,
|
|
6340
6340
|
const JSValue *values)
|
|
6341
6341
|
{
|
|
6342
|
-
JSShapeProperty *pr;
|
|
6343
|
-
uint32_t *hash;
|
|
6344
|
-
JSRuntime *rt;
|
|
6345
|
-
JSObject *p;
|
|
6346
|
-
JSShape *sh;
|
|
6347
6342
|
JSValue obj;
|
|
6348
|
-
JSAtom atom;
|
|
6349
|
-
intptr_t h;
|
|
6350
6343
|
int i;
|
|
6351
6344
|
|
|
6352
|
-
rt = ctx->rt;
|
|
6353
6345
|
obj = JS_NewObject(ctx);
|
|
6354
6346
|
if (JS_IsException(obj))
|
|
6355
6347
|
return JS_EXCEPTION;
|
|
6356
|
-
|
|
6357
|
-
|
|
6358
|
-
|
|
6359
|
-
assert(sh->is_hashed);
|
|
6360
|
-
assert(JS_REF_COUNT(sh) == 1);
|
|
6361
|
-
js_shape_hash_unlink(rt, sh);
|
|
6362
|
-
if (resize_properties(ctx, &sh, p, count)) {
|
|
6363
|
-
js_shape_hash_link(rt, sh);
|
|
6364
|
-
JS_FreeValue(ctx, obj);
|
|
6365
|
-
return JS_EXCEPTION;
|
|
6366
|
-
}
|
|
6367
|
-
p->shape = sh;
|
|
6368
|
-
for (i = 0; i < count; i++) {
|
|
6369
|
-
atom = props[i];
|
|
6370
|
-
pr = &get_shape_prop(sh)[i];
|
|
6371
|
-
sh->hash = shape_hash(shape_hash(sh->hash, atom), JS_PROP_C_W_E);
|
|
6372
|
-
h = atom & sh->prop_hash_mask;
|
|
6373
|
-
hash = &prop_hash_end(sh)[-h - 1];
|
|
6374
|
-
pr->hash_next = *hash;
|
|
6375
|
-
*hash = i + 1;
|
|
6376
|
-
pr->atom = JS_DupAtom(ctx, atom);
|
|
6377
|
-
pr->flags = JS_PROP_C_W_E;
|
|
6378
|
-
p->prop[i].u.value = values[i];
|
|
6379
|
-
}
|
|
6380
|
-
js_shape_hash_link(rt, sh);
|
|
6381
|
-
sh->prop_count = count;
|
|
6382
|
-
}
|
|
6348
|
+
for (i = 0; i < count; i++)
|
|
6349
|
+
if (JS_SetProperty(ctx, obj, props[i], values[i]) < 0)
|
|
6350
|
+
goto fail;
|
|
6383
6351
|
return obj;
|
|
6352
|
+
fail:
|
|
6353
|
+
for (/*empty*/; i < count; i++)
|
|
6354
|
+
JS_FreeValue(ctx, values[i]);
|
|
6355
|
+
JS_FreeValue(ctx, obj);
|
|
6356
|
+
return JS_EXCEPTION;
|
|
6384
6357
|
}
|
|
6385
6358
|
|
|
6386
6359
|
JSValue JS_NewObjectFromStr(JSContext *ctx, int count, const char **props,
|
|
@@ -22398,6 +22371,7 @@ typedef struct JSToken {
|
|
|
22398
22371
|
int line_num; /* line number of token start */
|
|
22399
22372
|
int col_num; /* column number of token start */
|
|
22400
22373
|
const uint8_t *ptr;
|
|
22374
|
+
const uint8_t *line_start; /* first character of the line of token start */
|
|
22401
22375
|
union {
|
|
22402
22376
|
struct {
|
|
22403
22377
|
JSValue str;
|
|
@@ -22431,6 +22405,7 @@ typedef struct JSParseState {
|
|
|
22431
22405
|
const uint8_t *buf_start;
|
|
22432
22406
|
const uint8_t *buf_ptr;
|
|
22433
22407
|
const uint8_t *buf_end;
|
|
22408
|
+
const uint8_t *line_start; /* first character of the current line */
|
|
22434
22409
|
const uint8_t *eol; // most recently seen end-of-line character
|
|
22435
22410
|
const uint8_t *mark; // first token character, invariant: eol < mark
|
|
22436
22411
|
|
|
@@ -22591,13 +22566,8 @@ int JS_PRINTF_FORMAT_ATTR(2, 3) js_parse_error(JSParseState *s, JS_PRINTF_FORMAT
|
|
|
22591
22566
|
/* s->col_num is not advanced during token scanning, so derive the column
|
|
22592
22567
|
as the 1-based offset of the token from the start of its line. */
|
|
22593
22568
|
int err_col_num = s->token.col_num;
|
|
22594
|
-
if (s->token.ptr && s->token.ptr >= s->
|
|
22595
|
-
|
|
22596
|
-
while (line_start > s->buf_start &&
|
|
22597
|
-
line_start[-1] != '\n' && line_start[-1] != '\r')
|
|
22598
|
-
line_start--;
|
|
22599
|
-
err_col_num = (int)(s->token.ptr - line_start) + 1;
|
|
22600
|
-
}
|
|
22569
|
+
if (s->token.ptr && s->token.ptr >= s->token.line_start)
|
|
22570
|
+
err_col_num = (int)(s->token.ptr - s->token.line_start) + 1;
|
|
22601
22571
|
build_backtrace(ctx, ctx->rt->current_exception, JS_UNDEFINED, s->filename,
|
|
22602
22572
|
s->token.line_num, err_col_num, backtrace_flags);
|
|
22603
22573
|
return -1;
|
|
@@ -22697,6 +22667,7 @@ static __exception int js_parse_template_part(JSParseState *s,
|
|
|
22697
22667
|
}
|
|
22698
22668
|
if (c == '\n') {
|
|
22699
22669
|
s->line_num++;
|
|
22670
|
+
s->line_start = p;
|
|
22700
22671
|
s->eol = &p[-1];
|
|
22701
22672
|
s->mark = p;
|
|
22702
22673
|
} else if (c >= 0x80) {
|
|
@@ -22790,6 +22761,7 @@ static __exception int js_parse_string(JSParseState *s, int sep,
|
|
|
22790
22761
|
p++;
|
|
22791
22762
|
if (sep != '`') {
|
|
22792
22763
|
s->line_num++;
|
|
22764
|
+
s->line_start = p;
|
|
22793
22765
|
s->eol = &p[-1];
|
|
22794
22766
|
s->mark = p;
|
|
22795
22767
|
}
|
|
@@ -23117,6 +23089,7 @@ static __exception int next_token(JSParseState *s)
|
|
|
23117
23089
|
s->token.line_num = s->line_num;
|
|
23118
23090
|
s->token.col_num = s->col_num;
|
|
23119
23091
|
s->token.ptr = p;
|
|
23092
|
+
s->token.line_start = s->line_start;
|
|
23120
23093
|
c = *p;
|
|
23121
23094
|
switch(c) {
|
|
23122
23095
|
case 0:
|
|
@@ -23144,6 +23117,7 @@ static __exception int next_token(JSParseState *s)
|
|
|
23144
23117
|
case '\n':
|
|
23145
23118
|
p++;
|
|
23146
23119
|
line_terminator:
|
|
23120
|
+
s->line_start = p;
|
|
23147
23121
|
s->eol = &p[-1];
|
|
23148
23122
|
s->mark = p;
|
|
23149
23123
|
s->got_lf = true;
|
|
@@ -23172,10 +23146,12 @@ static __exception int next_token(JSParseState *s)
|
|
|
23172
23146
|
s->line_num++;
|
|
23173
23147
|
s->got_lf = true; /* considered as LF for ASI */
|
|
23174
23148
|
s->eol = p++;
|
|
23149
|
+
s->line_start = p;
|
|
23175
23150
|
s->mark = p;
|
|
23176
23151
|
} else if (*p == '\r') {
|
|
23177
23152
|
s->got_lf = true; /* considered as LF for ASI */
|
|
23178
23153
|
p++;
|
|
23154
|
+
s->line_start = p;
|
|
23179
23155
|
} else if (*p >= 0x80) {
|
|
23180
23156
|
c = utf8_decode(p, &p);
|
|
23181
23157
|
/* ignore invalid UTF-8 in comments */
|
|
@@ -23763,6 +23739,7 @@ static __exception int json_next_token(JSParseState *s)
|
|
|
23763
23739
|
s->token.line_num = s->line_num;
|
|
23764
23740
|
s->token.col_num = s->col_num;
|
|
23765
23741
|
s->token.ptr = p;
|
|
23742
|
+
s->token.line_start = s->line_start;
|
|
23766
23743
|
c = *p;
|
|
23767
23744
|
switch(c) {
|
|
23768
23745
|
case 0:
|
|
@@ -23788,6 +23765,7 @@ static __exception int json_next_token(JSParseState *s)
|
|
|
23788
23765
|
case '\n':
|
|
23789
23766
|
s->line_num++;
|
|
23790
23767
|
s->eol = p++;
|
|
23768
|
+
s->line_start = p;
|
|
23791
23769
|
s->mark = p;
|
|
23792
23770
|
goto redo;
|
|
23793
23771
|
case '\f':
|
|
@@ -25020,6 +24998,7 @@ typedef struct JSParsePos {
|
|
|
25020
24998
|
int col_num;
|
|
25021
24999
|
bool got_lf;
|
|
25022
25000
|
const uint8_t *ptr;
|
|
25001
|
+
const uint8_t *line_start;
|
|
25023
25002
|
const uint8_t *eol;
|
|
25024
25003
|
const uint8_t *mark;
|
|
25025
25004
|
} JSParsePos;
|
|
@@ -25031,6 +25010,7 @@ static int js_parse_get_pos(JSParseState *s, JSParsePos *sp)
|
|
|
25031
25010
|
sp->line_num = s->token.line_num;
|
|
25032
25011
|
sp->col_num = s->token.col_num;
|
|
25033
25012
|
sp->ptr = s->token.ptr;
|
|
25013
|
+
sp->line_start = s->line_start;
|
|
25034
25014
|
sp->eol = s->eol;
|
|
25035
25015
|
sp->mark = s->mark;
|
|
25036
25016
|
sp->got_lf = s->got_lf;
|
|
@@ -25044,6 +25024,7 @@ static __exception int js_parse_seek_token(JSParseState *s, const JSParsePos *sp
|
|
|
25044
25024
|
s->line_num = sp->line_num;
|
|
25045
25025
|
s->col_num = sp->col_num;
|
|
25046
25026
|
s->buf_ptr = sp->ptr;
|
|
25027
|
+
s->line_start = sp->line_start;
|
|
25047
25028
|
s->eol = sp->eol;
|
|
25048
25029
|
s->mark = sp->mark;
|
|
25049
25030
|
s->got_lf = sp->got_lf;
|
|
@@ -27204,13 +27185,8 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags)
|
|
|
27204
27185
|
{
|
|
27205
27186
|
JSAtom name;
|
|
27206
27187
|
int identifier_line_num = s->token.line_num;
|
|
27207
|
-
const uint8_t *identifier_line_start = s->token.ptr;
|
|
27208
|
-
while (identifier_line_start > s->buf_start &&
|
|
27209
|
-
identifier_line_start[-1] != '\n' &&
|
|
27210
|
-
identifier_line_start[-1] != '\r')
|
|
27211
|
-
identifier_line_start--;
|
|
27212
27188
|
int identifier_col_num =
|
|
27213
|
-
(int)(s->token.ptr -
|
|
27189
|
+
(int)(s->token.ptr - s->line_start) + 1;
|
|
27214
27190
|
if (s->token.u.ident.is_reserved) {
|
|
27215
27191
|
return js_parse_error_reserved_identifier(s);
|
|
27216
27192
|
}
|
|
@@ -37170,8 +37146,8 @@ static JSValue js_create_function(JSContext *ctx, JSFunctionDef *fd)
|
|
|
37170
37146
|
goto fail;
|
|
37171
37147
|
|
|
37172
37148
|
function_size = sizeof(*b);
|
|
37173
|
-
cpool_offset = function_size;
|
|
37174
|
-
function_size
|
|
37149
|
+
cpool_offset = (function_size + 7) & ~7;
|
|
37150
|
+
function_size = cpool_offset + fd->cpool_count * sizeof(*fd->cpool);
|
|
37175
37151
|
vardefs_offset = function_size;
|
|
37176
37152
|
function_size += (fd->arg_count + fd->var_count) * sizeof(*b->vardefs);
|
|
37177
37153
|
closure_var_offset = function_size;
|
|
@@ -38216,6 +38192,7 @@ static void js_parse_init(JSContext *ctx, JSParseState *s,
|
|
|
38216
38192
|
s->col_num = 1;
|
|
38217
38193
|
s->buf_start = s->buf_ptr = (const uint8_t *)input;
|
|
38218
38194
|
s->buf_end = s->buf_ptr + input_len;
|
|
38195
|
+
s->line_start = s->buf_ptr;
|
|
38219
38196
|
s->mark = s->buf_ptr + min_int(1, input_len);
|
|
38220
38197
|
s->eol = s->buf_ptr;
|
|
38221
38198
|
s->token.val = ' ';
|
|
@@ -39871,8 +39848,8 @@ static JSValue JS_ReadFunctionTag(BCReaderState *s)
|
|
|
39871
39848
|
goto fail;
|
|
39872
39849
|
|
|
39873
39850
|
function_size = sizeof(*b);
|
|
39874
|
-
cpool_offset = function_size;
|
|
39875
|
-
function_size
|
|
39851
|
+
cpool_offset = (function_size + 7) & ~7;
|
|
39852
|
+
function_size = cpool_offset + bc.cpool_count * sizeof(*bc.cpool);
|
|
39876
39853
|
vardefs_offset = function_size;
|
|
39877
39854
|
function_size += local_count * sizeof(*bc.vardefs);
|
|
39878
39855
|
closure_var_offset = function_size;
|
|
@@ -41065,7 +41042,7 @@ static JSValue JS_NewCConstructor(JSContext *ctx, int class_id, const char *name
|
|
|
41065
41042
|
const JSCFunctionListEntry *proto_fields, int n_proto_fields,
|
|
41066
41043
|
int flags)
|
|
41067
41044
|
{
|
|
41068
|
-
JSValue ctor = JS_UNDEFINED, proto, parent_proto;
|
|
41045
|
+
JSValue ctor = JS_UNDEFINED, proto, parent_proto, *class_proto;
|
|
41069
41046
|
int proto_class_id, proto_flags, ctor_flags;
|
|
41070
41047
|
|
|
41071
41048
|
proto_flags = 0;
|
|
@@ -41096,8 +41073,12 @@ static JSValue JS_NewCConstructor(JSContext *ctx, int class_id, const char *name
|
|
|
41096
41073
|
n_proto_fields + 1);
|
|
41097
41074
|
if (JS_IsException(proto))
|
|
41098
41075
|
goto fail;
|
|
41099
|
-
if (class_id >= 0)
|
|
41100
|
-
ctx->class_proto[class_id]
|
|
41076
|
+
if (class_id >= 0) {
|
|
41077
|
+
class_proto = &ctx->class_proto[class_id];
|
|
41078
|
+
if (!JS_IsNull(*class_proto))
|
|
41079
|
+
JS_FreeValue(ctx, *class_proto);
|
|
41080
|
+
*class_proto = js_dup(proto);
|
|
41081
|
+
}
|
|
41101
41082
|
}
|
|
41102
41083
|
if (JS_SetPropertyFunctionList(ctx, proto, proto_fields, n_proto_fields))
|
|
41103
41084
|
goto fail;
|
|
@@ -41296,8 +41277,9 @@ static int js_obj_to_desc(JSContext *ctx, JSPropertyDescriptor *d,
|
|
|
41296
41277
|
if (present) {
|
|
41297
41278
|
flags |= JS_PROP_HAS_GET;
|
|
41298
41279
|
getter = JS_GetProperty(ctx, desc, JS_ATOM_get);
|
|
41299
|
-
if (JS_IsException(getter)
|
|
41300
|
-
|
|
41280
|
+
if (JS_IsException(getter))
|
|
41281
|
+
goto fail;
|
|
41282
|
+
if (!(JS_IsUndefined(getter) || JS_IsFunction(ctx, getter))) {
|
|
41301
41283
|
JS_ThrowTypeError(ctx, "Getter must be a function");
|
|
41302
41284
|
goto fail;
|
|
41303
41285
|
}
|
|
@@ -41308,8 +41290,9 @@ static int js_obj_to_desc(JSContext *ctx, JSPropertyDescriptor *d,
|
|
|
41308
41290
|
if (present) {
|
|
41309
41291
|
flags |= JS_PROP_HAS_SET;
|
|
41310
41292
|
setter = JS_GetProperty(ctx, desc, JS_ATOM_set);
|
|
41311
|
-
if (JS_IsException(setter)
|
|
41312
|
-
|
|
41293
|
+
if (JS_IsException(setter))
|
|
41294
|
+
goto fail;
|
|
41295
|
+
if (!(JS_IsUndefined(setter) || JS_IsFunction(ctx, setter))) {
|
|
41313
41296
|
JS_ThrowTypeError(ctx, "Setter must be a function");
|
|
41314
41297
|
goto fail;
|
|
41315
41298
|
}
|
|
@@ -43682,6 +43665,8 @@ static JSValue js_array_every(JSContext *ctx, JSValueConst this_val,
|
|
|
43682
43665
|
n = 0;
|
|
43683
43666
|
|
|
43684
43667
|
for(k = 0; k < len; k++) {
|
|
43668
|
+
if (js_poll_interrupts(ctx))
|
|
43669
|
+
goto exception;
|
|
43685
43670
|
if (special & special_TA) {
|
|
43686
43671
|
val = JS_GetPropertyInt64(ctx, obj, k);
|
|
43687
43672
|
if (JS_IsException(val))
|
|
@@ -43803,6 +43788,8 @@ static JSValue js_array_reduce(JSContext *ctx, JSValueConst this_val,
|
|
|
43803
43788
|
acc = js_dup(argv[1]);
|
|
43804
43789
|
} else {
|
|
43805
43790
|
for(;;) {
|
|
43791
|
+
if (js_poll_interrupts(ctx))
|
|
43792
|
+
goto exception;
|
|
43806
43793
|
if (k >= len) {
|
|
43807
43794
|
JS_ThrowTypeError(ctx, "empty array");
|
|
43808
43795
|
goto exception;
|
|
@@ -43824,6 +43811,8 @@ static JSValue js_array_reduce(JSContext *ctx, JSValueConst this_val,
|
|
|
43824
43811
|
}
|
|
43825
43812
|
}
|
|
43826
43813
|
for (; k < len; k++) {
|
|
43814
|
+
if (js_poll_interrupts(ctx))
|
|
43815
|
+
goto exception;
|
|
43827
43816
|
k1 = (special & special_reduceRight) ? len - k - 1 : k;
|
|
43828
43817
|
if (special & special_TA) {
|
|
43829
43818
|
val = JS_GetPropertyInt64(ctx, obj, k1);
|
|
@@ -43925,6 +43914,8 @@ static JSValue js_array_includes(JSContext *ctx, JSValueConst this_val,
|
|
|
43925
43914
|
}
|
|
43926
43915
|
}
|
|
43927
43916
|
for (; n < len; n++) {
|
|
43917
|
+
if (js_poll_interrupts(ctx))
|
|
43918
|
+
goto exception;
|
|
43928
43919
|
val = JS_GetPropertyInt64(ctx, obj, n);
|
|
43929
43920
|
if (JS_IsException(val))
|
|
43930
43921
|
goto exception;
|
|
@@ -43971,6 +43962,8 @@ static JSValue js_array_indexOf(JSContext *ctx, JSValueConst this_val,
|
|
|
43971
43962
|
}
|
|
43972
43963
|
}
|
|
43973
43964
|
for (; n < len; n++) {
|
|
43965
|
+
if (js_poll_interrupts(ctx))
|
|
43966
|
+
goto exception;
|
|
43974
43967
|
int present = JS_TryGetPropertyInt64(ctx, obj, n, &val);
|
|
43975
43968
|
if (present < 0)
|
|
43976
43969
|
goto exception;
|
|
@@ -44000,6 +43993,7 @@ static JSValue js_array_lastIndexOf(JSContext *ctx, JSValueConst this_val,
|
|
|
44000
43993
|
int64_t len, n;
|
|
44001
43994
|
JSValue *arrp;
|
|
44002
43995
|
uint32_t count;
|
|
43996
|
+
int present;
|
|
44003
43997
|
|
|
44004
43998
|
obj = JS_ToObject(ctx, this_val);
|
|
44005
43999
|
if (js_get_length64(ctx, &len, obj))
|
|
@@ -44020,7 +44014,9 @@ static JSValue js_array_lastIndexOf(JSContext *ctx, JSValueConst this_val,
|
|
|
44020
44014
|
}
|
|
44021
44015
|
}
|
|
44022
44016
|
for (; n >= 0; n--) {
|
|
44023
|
-
|
|
44017
|
+
if (js_poll_interrupts(ctx))
|
|
44018
|
+
goto exception;
|
|
44019
|
+
present = JS_TryGetPropertyInt64(ctx, obj, n, &val);
|
|
44024
44020
|
if (present < 0)
|
|
44025
44021
|
goto exception;
|
|
44026
44022
|
if (present) {
|
|
@@ -44083,6 +44079,8 @@ static JSValue js_array_find(JSContext *ctx, JSValueConst this_val,
|
|
|
44083
44079
|
|
|
44084
44080
|
// TODO(bnoordhuis) add fast path for fast arrays
|
|
44085
44081
|
for(; k != end; k += dir) {
|
|
44082
|
+
if (js_poll_interrupts(ctx))
|
|
44083
|
+
goto exception;
|
|
44086
44084
|
index_val = js_int64(k);
|
|
44087
44085
|
val = JS_GetPropertyValue(ctx, obj, index_val);
|
|
44088
44086
|
if (JS_IsException(val))
|
|
@@ -44791,11 +44789,6 @@ static int js_array_cmp_generic(const void *a, const void *b, void *opaque) {
|
|
|
44791
44789
|
return 0;
|
|
44792
44790
|
|
|
44793
44791
|
if (psc->has_method) {
|
|
44794
|
-
/* custom sort function is specified as returning 0 for identical
|
|
44795
|
-
* objects: avoid method call overhead.
|
|
44796
|
-
*/
|
|
44797
|
-
if (!memcmp(&ap->val, &bp->val, sizeof(ap->val)))
|
|
44798
|
-
goto cmp_same;
|
|
44799
44792
|
argv[0] = ap->val;
|
|
44800
44793
|
argv[1] = bp->val;
|
|
44801
44794
|
res = JS_Call(ctx, psc->method, JS_UNDEFINED, 2, argv);
|
|
@@ -44830,7 +44823,6 @@ static int js_array_cmp_generic(const void *a, const void *b, void *opaque) {
|
|
|
44830
44823
|
}
|
|
44831
44824
|
if (cmp != 0)
|
|
44832
44825
|
return cmp;
|
|
44833
|
-
cmp_same:
|
|
44834
44826
|
/* make sort stable: compare array offsets */
|
|
44835
44827
|
return (ap->pos > bp->pos) - (ap->pos < bp->pos);
|
|
44836
44828
|
|
|
@@ -52342,7 +52334,7 @@ static int js_proxy_has(JSContext *ctx, JSValueConst obj, JSAtom atom)
|
|
|
52342
52334
|
int res;
|
|
52343
52335
|
JSObject *p;
|
|
52344
52336
|
JSValueConst args[2];
|
|
52345
|
-
bool ret
|
|
52337
|
+
bool ret;
|
|
52346
52338
|
|
|
52347
52339
|
s = get_proxy_method(ctx, &method, obj, JS_ATOM_has);
|
|
52348
52340
|
if (!s)
|
|
@@ -52368,8 +52360,15 @@ static int js_proxy_has(JSContext *ctx, JSValueConst obj, JSAtom atom)
|
|
|
52368
52360
|
if (res < 0)
|
|
52369
52361
|
return -1;
|
|
52370
52362
|
if (res) {
|
|
52371
|
-
|
|
52372
|
-
|
|
52363
|
+
if (!(desc_flags & JS_PROP_CONFIGURABLE))
|
|
52364
|
+
goto inconsistent;
|
|
52365
|
+
/* must go through IsExtensible(): the target can be a proxy
|
|
52366
|
+
itself, whose isExtensible trap is observable */
|
|
52367
|
+
res = JS_IsExtensible(ctx, s->target);
|
|
52368
|
+
if (res < 0)
|
|
52369
|
+
return -1;
|
|
52370
|
+
if (!res) {
|
|
52371
|
+
inconsistent:
|
|
52373
52372
|
JS_ThrowTypeError(ctx, "proxy: inconsistent has");
|
|
52374
52373
|
return -1;
|
|
52375
52374
|
}
|
|
@@ -52565,7 +52564,14 @@ static int js_proxy_get_own_property(JSContext *ctx, JSPropertyDescriptor *pdesc
|
|
|
52565
52564
|
js_free_desc(ctx, &target_desc);
|
|
52566
52565
|
if (JS_IsUndefined(trap_result_obj)) {
|
|
52567
52566
|
if (target_desc_ret) {
|
|
52568
|
-
if (!(target_desc.flags & JS_PROP_CONFIGURABLE)
|
|
52567
|
+
if (!(target_desc.flags & JS_PROP_CONFIGURABLE))
|
|
52568
|
+
goto fail;
|
|
52569
|
+
/* must go through IsExtensible(): the target can be a proxy
|
|
52570
|
+
itself, whose isExtensible trap is observable */
|
|
52571
|
+
res = JS_IsExtensible(ctx, s->target);
|
|
52572
|
+
if (res < 0)
|
|
52573
|
+
return -1;
|
|
52574
|
+
if (!res)
|
|
52569
52575
|
goto fail;
|
|
52570
52576
|
}
|
|
52571
52577
|
ret = false;
|
|
@@ -52628,7 +52634,7 @@ static int js_proxy_define_own_property(JSContext *ctx, JSValueConst obj,
|
|
|
52628
52634
|
{
|
|
52629
52635
|
JSProxyData *s;
|
|
52630
52636
|
JSValue method, ret1, prop_val, desc_val;
|
|
52631
|
-
int res;
|
|
52637
|
+
int res, extensible_target;
|
|
52632
52638
|
JSObject *p;
|
|
52633
52639
|
JSValueConst args[3];
|
|
52634
52640
|
JSPropertyDescriptor desc;
|
|
@@ -52672,11 +52678,19 @@ static int js_proxy_define_own_property(JSContext *ctx, JSValueConst obj,
|
|
|
52672
52678
|
res = JS_GetOwnPropertyInternal(ctx, &desc, p, prop);
|
|
52673
52679
|
if (res < 0)
|
|
52674
52680
|
return -1;
|
|
52681
|
+
/* must go through IsExtensible(): the target can be a proxy itself, in
|
|
52682
|
+
which case its isExtensible trap is observable and may throw */
|
|
52683
|
+
extensible_target = JS_IsExtensible(ctx, s->target);
|
|
52684
|
+
if (extensible_target < 0) {
|
|
52685
|
+
if (res)
|
|
52686
|
+
js_free_desc(ctx, &desc);
|
|
52687
|
+
return -1;
|
|
52688
|
+
}
|
|
52675
52689
|
setting_not_configurable = ((flags & (JS_PROP_HAS_CONFIGURABLE |
|
|
52676
52690
|
JS_PROP_CONFIGURABLE)) ==
|
|
52677
52691
|
JS_PROP_HAS_CONFIGURABLE);
|
|
52678
52692
|
if (!res) {
|
|
52679
|
-
if (!
|
|
52693
|
+
if (!extensible_target || setting_not_configurable)
|
|
52680
52694
|
goto fail;
|
|
52681
52695
|
} else {
|
|
52682
52696
|
if (!check_define_prop_flags(desc.flags, flags) ||
|
|
@@ -52805,6 +52819,12 @@ static int js_proxy_get_own_property_names(JSContext *ctx,
|
|
|
52805
52819
|
prop_array = JS_CallFree(ctx, method, s->handler, 1, vc(&s->target));
|
|
52806
52820
|
if (JS_IsException(prop_array))
|
|
52807
52821
|
return -1;
|
|
52822
|
+
/* CreateListFromArrayLike() requires an object */
|
|
52823
|
+
if (JS_VALUE_GET_TAG(prop_array) != JS_TAG_OBJECT) {
|
|
52824
|
+
JS_FreeValue(ctx, prop_array);
|
|
52825
|
+
JS_ThrowTypeError(ctx, "proxy: ownKeys must return an object");
|
|
52826
|
+
return -1;
|
|
52827
|
+
}
|
|
52808
52828
|
tab = NULL;
|
|
52809
52829
|
len = 0;
|
|
52810
52830
|
tab_size = 0;
|
|
@@ -60220,10 +60240,13 @@ static JSValue js_typed_array_with(JSContext *ctx, JSValueConst this_val,
|
|
|
60220
60240
|
if (idx < 0)
|
|
60221
60241
|
idx = len + idx;
|
|
60222
60242
|
|
|
60223
|
-
|
|
60243
|
+
if (p->class_id == JS_CLASS_BIG_INT64_ARRAY || p->class_id == JS_CLASS_BIG_UINT64_ARRAY) {
|
|
60244
|
+
val = JS_ToBigInt(ctx, argv[1]);
|
|
60245
|
+
} else {
|
|
60246
|
+
val = JS_ToNumber(ctx, argv[1]);
|
|
60247
|
+
}
|
|
60224
60248
|
if (JS_IsException(val))
|
|
60225
60249
|
return JS_EXCEPTION;
|
|
60226
|
-
|
|
60227
60250
|
/* re-validate after user code (spec step 9: IsValidIntegerIndex) */
|
|
60228
60251
|
if (typed_array_is_oob(p)) {
|
|
60229
60252
|
JS_FreeValue(ctx, val);
|
|
@@ -63879,7 +63902,7 @@ int JS_AddIntrinsicDOMException(JSContext *ctx)
|
|
|
63879
63902
|
}
|
|
63880
63903
|
JS_DefinePropertyValue(ctx, ctx->global_obj, JS_ATOM_DOMException, ctor,
|
|
63881
63904
|
JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
|
|
63882
|
-
ctx->class_proto[JS_CLASS_DOM_EXCEPTION]
|
|
63905
|
+
set_value(ctx, &ctx->class_proto[JS_CLASS_DOM_EXCEPTION], proto);
|
|
63883
63906
|
return 0;
|
|
63884
63907
|
}
|
|
63885
63908
|
/* base64 */
|
|
@@ -64943,6 +64966,10 @@ uintptr_t js_std_cmd(int cmd, ...) {
|
|
|
64943
64966
|
if (JS_IsString(*pv))
|
|
64944
64967
|
rv = JS_VALUE_GET_STRING(*pv)->kind;
|
|
64945
64968
|
break;
|
|
64969
|
+
case 4: // GetShapeHashCount
|
|
64970
|
+
rt = va_arg(ap, JSRuntime *);
|
|
64971
|
+
rv = rt->shape_hash_count;
|
|
64972
|
+
break;
|
|
64946
64973
|
default:
|
|
64947
64974
|
rv = -1;
|
|
64948
64975
|
}
|
package/deps/quickjs/quickjs.h
CHANGED
|
@@ -1469,7 +1469,7 @@ JS_EXTERN int JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m,
|
|
|
1469
1469
|
|
|
1470
1470
|
#define QJS_VERSION_MAJOR 0
|
|
1471
1471
|
#define QJS_VERSION_MINOR 16
|
|
1472
|
-
#define QJS_VERSION_PATCH
|
|
1472
|
+
#define QJS_VERSION_PATCH 2
|
|
1473
1473
|
#define QJS_VERSION_SUFFIX ""
|
|
1474
1474
|
|
|
1475
1475
|
JS_EXTERN const char* JS_GetVersion(void);
|
|
@@ -1736,15 +1736,21 @@ JSContext *JS_NewCustomContext(JSRuntime *rt)
|
|
|
1736
1736
|
return ctx;
|
|
1737
1737
|
}
|
|
1738
1738
|
|
|
1739
|
+
static int interrupt_handler(JSRuntime *rt, void *opaque)
|
|
1740
|
+
{
|
|
1741
|
+
int *interrupt_countdown = opaque;
|
|
1742
|
+
return !--*interrupt_countdown;
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1739
1745
|
int run_test_buf(ThreadLocalStorage *tls, const char *filename, char *harness,
|
|
1740
1746
|
namelist_t *ip, char *buf, size_t buf_len,
|
|
1741
1747
|
const char* error_type, int eval_flags, bool is_negative,
|
|
1742
|
-
bool is_async, bool can_block, bool
|
|
1743
|
-
int *msec)
|
|
1748
|
+
bool is_async, bool can_block, bool set_interrupt_handler,
|
|
1749
|
+
bool track_promise_rejections, int *msec)
|
|
1744
1750
|
{
|
|
1751
|
+
int i, ret, interrupt_countdown;
|
|
1745
1752
|
JSRuntime *rt;
|
|
1746
1753
|
JSContext *ctx;
|
|
1747
|
-
int i, ret;
|
|
1748
1754
|
|
|
1749
1755
|
rt = JS_NewRuntime();
|
|
1750
1756
|
if (rt == NULL) {
|
|
@@ -1785,6 +1791,12 @@ int run_test_buf(ThreadLocalStorage *tls, const char *filename, char *harness,
|
|
|
1785
1791
|
}
|
|
1786
1792
|
}
|
|
1787
1793
|
|
|
1794
|
+
// must be big enough that the script isn't interrupted before it
|
|
1795
|
+
// gets to the meat but not so big that it takes ages to kick in
|
|
1796
|
+
interrupt_countdown = 150;
|
|
1797
|
+
if (set_interrupt_handler)
|
|
1798
|
+
JS_SetInterruptHandler(rt, interrupt_handler, &interrupt_countdown);
|
|
1799
|
+
|
|
1788
1800
|
ret = eval_buf(ctx, buf, buf_len, filename, true, is_negative,
|
|
1789
1801
|
error_type, eval_flags, is_async, msec);
|
|
1790
1802
|
ret = (ret != 0);
|
|
@@ -1814,6 +1826,7 @@ int run_test(ThreadLocalStorage *tls, const char *filename, int *msec)
|
|
|
1814
1826
|
int ret, eval_flags, use_strict, use_nostrict;
|
|
1815
1827
|
bool is_negative, is_nostrict, is_onlystrict, is_async, is_module, skip;
|
|
1816
1828
|
bool detect_module = true;
|
|
1829
|
+
bool set_interrupt_handler = false;
|
|
1817
1830
|
bool track_promise_rejections = false;
|
|
1818
1831
|
bool can_block;
|
|
1819
1832
|
namelist_t include_list = { 0 }, *ip = &include_list;
|
|
@@ -1873,6 +1886,9 @@ int run_test(ThreadLocalStorage *tls, const char *filename, int *msec)
|
|
|
1873
1886
|
else if (str_equal(option, "qjs:no-detect-module")) {
|
|
1874
1887
|
detect_module = false;
|
|
1875
1888
|
}
|
|
1889
|
+
else if (str_equal(option, "qjs:set-interrupt-handler")) {
|
|
1890
|
+
set_interrupt_handler = true;
|
|
1891
|
+
}
|
|
1876
1892
|
else if (str_equal(option, "qjs:track-promise-rejections")) {
|
|
1877
1893
|
track_promise_rejections = true;
|
|
1878
1894
|
}
|
|
@@ -1970,12 +1986,14 @@ int run_test(ThreadLocalStorage *tls, const char *filename, int *msec)
|
|
|
1970
1986
|
if (use_nostrict) {
|
|
1971
1987
|
ret = run_test_buf(tls, filename, harness, ip, buf, buf_len,
|
|
1972
1988
|
error_type, eval_flags, is_negative, is_async,
|
|
1973
|
-
can_block,
|
|
1989
|
+
can_block, set_interrupt_handler,
|
|
1990
|
+
track_promise_rejections, msec);
|
|
1974
1991
|
}
|
|
1975
1992
|
if (use_strict) {
|
|
1976
1993
|
ret |= run_test_buf(tls, filename, harness, ip, buf, buf_len,
|
|
1977
1994
|
error_type, eval_flags | JS_EVAL_FLAG_STRICT,
|
|
1978
1995
|
is_negative, is_async, can_block,
|
|
1996
|
+
set_interrupt_handler,
|
|
1979
1997
|
track_promise_rejections, msec);
|
|
1980
1998
|
}
|
|
1981
1999
|
}
|