Revert whitespace fixes to third_party (#501)

This commit is contained in:
Jared Miller 2022-07-22 00:46:07 -04:00 committed by GitHub
parent d4000bb8f7
commit 9de3d8f1e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
365 changed files with 39190 additions and 39211 deletions

View file

@ -1,5 +1,5 @@
QuickJS Javascript Engine
Copyright (c) 2017-2021 Fabrice Bellard
Copyright (c) 2017-2021 Charlie Gordon

View file

@ -669,8 +669,8 @@ static int js_binary_arith_bigdecimal(JSContext *ctx, OPCodeEnum op,
ret = bfdec_div(r, a, b, BF_PREC_INF, BF_RNDZ);
break;
case OP_math_mod:
/* Euclidean remainder */
ret = bfdec_rem(r, a, b, BF_PREC_INF, BF_RNDZ, BF_DIVREM_EUCLIDEAN);
/* Euclidian remainder */
ret = bfdec_rem(r, a, b, BF_PREC_INF, BF_RNDZ, BF_DIVREM_EUCLIDIAN);
break;
case OP_mod:
ret = bfdec_rem(r, a, b, BF_PREC_INF, BF_RNDZ, BF_RNDZ);
@ -696,7 +696,7 @@ static int js_binary_arith_bigdecimal(JSContext *ctx, OPCodeEnum op,
JS_FreeValue(ctx, op2);
return -1;
}
void JS_AddIntrinsicBigDecimal(JSContext *ctx)
{
JSRuntime *rt = ctx->rt;

View file

@ -403,11 +403,11 @@ static const JSCFunctionListEntry js_bigint_funcs[] = {
JS_CFUNC_MAGIC_DEF("tdiv", 2, js_bigint_div, BF_RNDZ ),
JS_CFUNC_MAGIC_DEF("fdiv", 2, js_bigint_div, BF_RNDD ),
JS_CFUNC_MAGIC_DEF("cdiv", 2, js_bigint_div, BF_RNDU ),
JS_CFUNC_MAGIC_DEF("ediv", 2, js_bigint_div, BF_DIVREM_EUCLIDEAN ),
JS_CFUNC_MAGIC_DEF("ediv", 2, js_bigint_div, BF_DIVREM_EUCLIDIAN ),
JS_CFUNC_MAGIC_DEF("tdivrem", 2, js_bigint_div, BF_RNDZ | 0x10 ),
JS_CFUNC_MAGIC_DEF("fdivrem", 2, js_bigint_div, BF_RNDD | 0x10 ),
JS_CFUNC_MAGIC_DEF("cdivrem", 2, js_bigint_div, BF_RNDU | 0x10 ),
JS_CFUNC_MAGIC_DEF("edivrem", 2, js_bigint_div, BF_DIVREM_EUCLIDEAN | 0x10 ),
JS_CFUNC_MAGIC_DEF("edivrem", 2, js_bigint_div, BF_DIVREM_EUCLIDIAN | 0x10 ),
JS_CFUNC_MAGIC_DEF("sqrt", 1, js_bigint_sqrt, 0 ),
JS_CFUNC_MAGIC_DEF("sqrtrem", 1, js_bigint_sqrt, 1 ),
JS_CFUNC_MAGIC_DEF("floorLog2", 1, js_bigint_op1, 0 ),
@ -584,9 +584,9 @@ static int js_binary_arith_bigint(JSContext *ctx, OPCodeEnum op,
}
break;
case OP_math_mod:
/* Euclidean remainder */
/* Euclidian remainder */
ret = bf_rem(r, a, b, BF_PREC_INF, BF_RNDZ,
BF_DIVREM_EUCLIDEAN) & BF_ST_INVALID_OP;
BF_DIVREM_EUCLIDIAN) & BF_ST_INVALID_OP;
break;
case OP_mod:
ret = bf_rem(r, a, b, BF_PREC_INF, BF_RNDZ,

View file

@ -1240,7 +1240,7 @@ static int js_op_define_class(JSContext *ctx, JSValue *sp,
if (JS_DefineObjectName(ctx, ctor, class_name, JS_PROP_CONFIGURABLE) < 0)
goto fail;
}
/* the constructor property must be first. It can be overridden by
/* the constructor property must be first. It can be overriden by
computed property names */
if (JS_DefinePropertyValue(ctx, proto, JS_ATOM_constructor,
JS_DupValue(ctx, ctor),

View file

@ -394,7 +394,7 @@ static inline void *med3(void *a, void *b, void *c, cmp_f cmp, void *opaque)
(cmp(b, c, opaque) > 0 ? b : (cmp(a, c, opaque) < 0 ? a : c ));
}
/* pointer based version with local stack and insertion sort threshold */
/* pointer based version with local stack and insertion sort threshhold */
void rqsort(void *base, size_t nmemb, size_t size, cmp_f cmp, void *opaque)
{
struct { uint8_t *base; size_t count; int depth; } stack[50], *sp = stack;

View file

@ -124,7 +124,7 @@ int dbuf_printf(DynBuf *s, const char *fmt, ...)
va_list ap;
char buf[128];
int len;
va_start(ap, fmt);
len = vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);

View file

@ -374,7 +374,7 @@ precision.
</li><li> Otherwise, the number is rounded to nearest with ties to even using
the global precision. It is then converted to string using the minimum
number of digits so that its conversion back to a floating point using
the global precision and round to nearest gives the same number.
the global precision and round to nearest gives the same number.
</li></ul>

View file

@ -289,7 +289,7 @@ precision.
Otherwise, the number is rounded to nearest with ties to even using
the global precision. It is then converted to string using the minimum
number of digits so that its conversion back to a floating point using
the global precision and round to nearest gives the same number.
the global precision and round to nearest gives the same number.
@end itemize

View file

@ -638,7 +638,7 @@ optional properties:
</p>
</dd>
<dt><code>full</code></dt>
<dd>
<dd>
<p>Boolean (default = false). If true, return the an object contains
the properties <code>response</code> (response content),
<code>responseHeaders</code> (headers separated by CRLF), <code>status</code>
@ -931,7 +931,7 @@ object containing optional parameters:
terminated. In this case, <code>exec</code> return the exit code if positive
or the negated signal number if the process was interrupted by a
signal. If false, do not block and return the process id of the child.
</p>
</p>
</dd>
<dt><code>usePath</code></dt>
<dd><p>Boolean (default = true). If true, the file is searched in the
@ -1031,7 +1031,7 @@ example is available in <samp>tests/test_worker.js</samp>.
</p>
<dl compact="compact">
<dt><code>postMessage(msg)</code></dt>
<dd>
<dd>
<p>Send a message to the corresponding worker. <code>msg</code> is cloned in
the destination worker using an algorithm similar to the <code>HTML</code>
structured clone algorithm. <code>SharedArrayBuffer</code> are shared
@ -1189,7 +1189,7 @@ callback can be used to implement an execution timeout.
representation such as a parse tree, hence it is very fast. Several
optimizations passes are done over the generated bytecode.
</p>
<p>A stack-based bytecode was chosen because it is simple and generates
<p>A stack-based bytecode was chosen because it is simple and generates
compact code.
</p>
<p>For each function, the maximum stack size is computed at compile time so that

View file

@ -155,7 +155,7 @@ Options are:
@table @code
@item -c
Only output bytecode in a C file. The default is to output an executable file.
@item -e
@item -e
Output @code{main()} and bytecode in a C file. The default is to output an
executable file.
@item -o output
@ -475,7 +475,7 @@ optional properties:
to be UTF-8 encoded.
@item full
Boolean (default = false). If true, return the an object contains
the properties @code{response} (response content),
@code{responseHeaders} (headers separated by CRLF), @code{status}
@ -582,7 +582,7 @@ Available exports:
Open a file. Return a handle or < 0 if error.
@item O_RDONLY
@item O_WRONLY
@item O_WRONLY
@item O_RDWR
@item O_APPEND
@item O_CREAT
@ -720,7 +720,7 @@ object containing optional parameters:
terminated. In this case, @code{exec} return the exit code if positive
or the negated signal number if the process was interrupted by a
signal. If false, do not block and return the process id of the child.
@item usePath
Boolean (default = true). If true, the file is searched in the
@code{PATH} environment variable.
@ -744,7 +744,7 @@ object containing optional parameters:
@item uid
Integer. If present, the process uid with @code{setuid}.
@item gid
@item gid
Integer. If present, the process gid with @code{setgid}.
@end table
@ -801,7 +801,7 @@ The worker instances have the following properties:
@table @code
@item postMessage(msg)
Send a message to the corresponding worker. @code{msg} is cloned in
the destination worker using an algorithm similar to the @code{HTML}
structured clone algorithm. @code{SharedArrayBuffer} are shared
@ -944,7 +944,7 @@ The compiler generates bytecode directly with no intermediate
representation such as a parse tree, hence it is very fast. Several
optimizations passes are done over the generated bytecode.
A stack-based bytecode was chosen because it is simple and generates
A stack-based bytecode was chosen because it is simple and generates
compact code.
For each function, the maximum stack size is computed at compile time so that

View file

@ -1,6 +1,6 @@
/*
* QuickJS: Example of C module
*
*
* Copyright (c) 2017-2018 Fabrice Bellard
*
* Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -11,7 +11,7 @@ function calc_pi(prec) {
const CHUD_C = 640320m;
const CHUD_C3 = 10939058860032000m; /* C^3/24 */
const CHUD_DIGITS_PER_TERM = 14.18164746272548; /* log10(C/12)*3 */
/* return [P, Q, G] */
function chud_bs(a, b, need_G) {
var c, P, Q, G, P1, Q1, G1, P2, Q2, G2, b1;

View file

@ -11,7 +11,7 @@ function calc_pi() {
const CHUD_C = 640320n;
const CHUD_C3 = 10939058860032000n; /* C^3/24 */
const CHUD_BITS_PER_TERM = 47.11041313821584202247; /* log2(C/12)*3 */
/* return [P, Q, G] */
function chud_bs(a, b, need_G) {
var c, P, Q, G, P1, Q1, G1, P2, Q2, G2;

View file

@ -54,7 +54,7 @@ function calc_pi(prec) {
const CHUD_C = 640320n;
const CHUD_C3 = 10939058860032000n; /* C^3/24 */
const CHUD_BITS_PER_TERM = 47.11041313821584202247; /* log2(C/12)*3 */
/* return [P, Q, G] */
function chud_bs(a, b, need_G) {
var c, P, Q, G, P1, Q1, G1, P2, Q2, G2;

View file

@ -1,6 +1,6 @@
/*
* QuickJS: Example of C module with a class
*
*
* Copyright (c) 2019 Fabrice Bellard
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@ -49,7 +49,7 @@ static JSValue js_point_ctor(JSContext *ctx,
JSPointData *s;
JSValue obj = JS_UNDEFINED;
JSValue proto;
s = js_mallocz(ctx, sizeof(*s));
if (!s)
return JS_EXCEPTION;
@ -112,7 +112,7 @@ static JSValue js_point_norm(JSContext *ctx, JSValueConst this_val,
static JSClassDef js_point_class = {
"Point",
.finalizer = js_point_finalizer,
};
};
static const JSCFunctionListEntry js_point_proto_funcs[] = {
JS_CGETSET_MAGIC_DEF("x", js_point_get_xy, js_point_set_xy, 0),
@ -123,19 +123,19 @@ static const JSCFunctionListEntry js_point_proto_funcs[] = {
static int js_point_init(JSContext *ctx, JSModuleDef *m)
{
JSValue point_proto, point_class;
/* create the Point class */
JS_NewClassID(&js_point_class_id);
JS_NewClass(JS_GetRuntime(ctx), js_point_class_id, &js_point_class);
point_proto = JS_NewObject(ctx);
JS_SetPropertyFunctionList(ctx, point_proto, js_point_proto_funcs, countof(js_point_proto_funcs));
point_class = JS_NewCFunction2(ctx, js_point_ctor, "Point", 2, JS_CFUNC_constructor, 0);
/* set proto.constructor and ctor.prototype */
JS_SetConstructor(ctx, point_class, point_proto);
JS_SetClassProto(ctx, js_point_class_id, point_proto);
JS_SetModuleExport(ctx, m, "Point", point_class);
return 0;
}

View file

@ -1000,9 +1000,9 @@ static int js_binary_arith_bigfloat(JSContext *ctx, OPCodeEnum op,
ret = bf_div(r, a, b, ctx->fp_env.prec, ctx->fp_env.flags);
break;
case OP_math_mod:
/* Euclidean remainder */
/* Euclidian remainder */
ret = bf_rem(r, a, b, ctx->fp_env.prec, ctx->fp_env.flags,
BF_DIVREM_EUCLIDEAN);
BF_DIVREM_EUCLIDIAN);
break;
case OP_mod:
ret = bf_rem(r, a, b, ctx->fp_env.prec, ctx->fp_env.flags,

View file

@ -397,7 +397,7 @@ void JS_RunGC(JSRuntime *rt)
/* decrement the reference of the children of each object. mark =
1 after this pass. */
gc_decref(rt);
/* keep the GC objects with a non zero refcount and their children */
/* keep the GC objects with a non zero refcount and their childs */
gc_scan(rt);
/* free the GC objects in a cycle */
gc_free_cycles(rt);

View file

@ -162,8 +162,8 @@ static JSValue js_generator_next(JSContext *ctx, JSValueConst this_val,
return ret;
}
JSValue js_generator_function_call(JSContext *ctx, JSValueConst func_obj,
JSValueConst this_obj, int argc,
JSValue js_generator_function_call(JSContext *ctx, JSValueConst func_obj,
JSValueConst this_obj, int argc,
JSValueConst *argv, int flags)
{
JSValue obj, func_ret;

View file

@ -1291,7 +1291,7 @@ typedef struct BlockEnv {
typedef struct JSGlobalVar {
int cpool_idx; /* if >= 0, index in the constant pool for hoisted
function definition*/
function defintion*/
uint8_t force_init : 1; /* force initialization to undefined */
uint8_t is_lexical : 1; /* global let/const definition */
uint8_t is_const : 1; /* const definition */
@ -1393,9 +1393,9 @@ typedef struct JSFunctionDef {
int func_var_idx; /* variable containing the current function (-1
if none, only used if is_func_expr is true) */
int eval_ret_idx; /* variable containing the return value of the eval, -1 if none */
int this_var_idx; /* variable containing the 'this' value, -1 if none */
int new_target_var_idx; /* variable containing the 'new.target' value, -1 if none */
int this_active_func_var_idx; /* variable containing the 'this.active_func' value, -1 if none */
int this_var_idx; /* variable containg the 'this' value, -1 if none */
int new_target_var_idx; /* variable containg the 'new.target' value, -1 if none */
int this_active_func_var_idx; /* variable containg the 'this.active_func' value, -1 if none */
int home_object_var_idx;
BOOL need_home_object;
int scope_level; /* index into fd->scopes if the current lexical scope */

View file

@ -1729,7 +1729,7 @@ static int __bf_div(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
/* division and remainder.
rnd_mode is the rounding mode for the quotient. The additional
rounding mode BF_RND_EUCLIDEAN is supported.
rounding mode BF_RND_EUCLIDIAN is supported.
'q' is an integer. 'r' is rounded with prec and flags (prec can be
BF_PREC_INF).
@ -1778,7 +1778,7 @@ int bf_divrem(bf_t *q, bf_t *r, const bf_t *a, const bf_t *b,
case BF_RNDA:
is_ceil = TRUE;
break;
case BF_DIVREM_EUCLIDEAN:
case BF_DIVREM_EUCLIDIAN:
is_ceil = a->sign;
break;
}
@ -4120,7 +4120,7 @@ static void bf_const_pi_internal(bf_t *Q, limb_t prec)
int64_t n, prec1;
bf_t P, G;
/* number of series terms */
/* number of serie terms */
n = prec / CHUD_BITS_PER_TERM + 1;
/* XXX: precision analysis */
prec1 = prec + 32;
@ -5188,7 +5188,7 @@ static int bf_atan2_internal(bf_t *r, const bf_t *y, limb_t prec, void *opaque)
return 0;
}
/* compute atan(y/x) assuming inf/inf = 1 and 0/0 = 0 */
/* compute atan(y/x) assumming inf/inf = 1 and 0/0 = 0 */
bf_init(s, T);
prec1 = prec + 32;
if (y->expn == BF_EXP_INF && x->expn == BF_EXP_INF) {
@ -5670,7 +5670,7 @@ limb_t mp_add_mul1_dec(limb_t *tabr, const limb_t *taba, mp_size_t n,
}
/* tabr[] -= taba[] * b. 0 <= b <= base - 1. Return the value to
subtract to the high word. */
substract to the high word. */
limb_t mp_sub_mul1_dec(limb_t *tabr, const limb_t *taba, mp_size_t n,
limb_t b)
{
@ -6934,7 +6934,7 @@ static void bfdec_tdivremu(bf_context_t *s, bfdec_t *q, bfdec_t *r,
/* division and remainder.
rnd_mode is the rounding mode for the quotient. The additional
rounding mode BF_RND_EUCLIDEAN is supported.
rounding mode BF_RND_EUCLIDIAN is supported.
'q' is an integer. 'r' is rounded with prec and flags (prec can be
BF_PREC_INF).
@ -6985,7 +6985,7 @@ int bfdec_divrem(bfdec_t *q, bfdec_t *r, const bfdec_t *a, const bfdec_t *b,
case BF_RNDA:
is_ceil = TRUE;
break;
case BF_DIVREM_EUCLIDEAN:
case BF_DIVREM_EUCLIDIAN:
is_ceil = a->sign;
break;
}

View file

@ -149,8 +149,8 @@ static inline bf_flags_t bf_set_exp_bits(int n)
#define BF_ST_OVERFLOW (1 << 2)
#define BF_ST_UNDERFLOW (1 << 3)
#define BF_ST_INEXACT (1 << 4)
/* indicate that a memory allocation error occurred. NaN is returned */
#define BF_ST_MEM_ERROR (1 << 5)
/* indicate that a memory allocation error occured. NaN is returned */
#define BF_ST_MEM_ERROR (1 << 5)
#define BF_RADIX_MAX 36 /* maximum radix for bf_atof() and bf_ftoa() */
@ -263,11 +263,11 @@ int bf_sub(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec, bf_flags_t flags)
int bf_add_si(bf_t *r, const bf_t *a, int64_t b1, limb_t prec, bf_flags_t flags);
int bf_mul(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec, bf_flags_t flags);
int bf_mul_ui(bf_t *r, const bf_t *a, uint64_t b1, limb_t prec, bf_flags_t flags);
int bf_mul_si(bf_t *r, const bf_t *a, int64_t b1, limb_t prec,
int bf_mul_si(bf_t *r, const bf_t *a, int64_t b1, limb_t prec,
bf_flags_t flags);
int bf_mul_2exp(bf_t *r, slimb_t e, limb_t prec, bf_flags_t flags);
int bf_div(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec, bf_flags_t flags);
#define BF_DIVREM_EUCLIDEAN BF_RNDF
#define BF_DIVREM_EUCLIDIAN BF_RNDF
int bf_divrem(bf_t *q, bf_t *r, const bf_t *a, const bf_t *b,
limb_t prec, bf_flags_t flags, int rnd_mode);
int bf_rem(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
@ -320,12 +320,12 @@ int bf_mul_pow_radix(bf_t *r, const bf_t *T, limb_t radix,
/* fractional format: prec digits after the decimal point rounded with
(flags & BF_RND_MASK) */
#define BF_FTOA_FORMAT_FRAC (1 << 16)
/* free format:
/* free format:
For binary radices with bf_ftoa() and for bfdec_ftoa(): use the minimum
number of digits to represent 'a'. The precision and the rounding
mode are ignored.
For the non binary radices with bf_ftoa(): use as many digits as
necessary so that bf_atof() return the same number when using
precision 'prec', rounding to nearest and the subnormal
@ -352,7 +352,7 @@ char *bf_ftoa(size_t *plen, const bf_t *a, int radix, limb_t prec,
bf_flags_t flags);
/* modulo 2^n instead of saturation. NaN and infinity return 0 */
#define BF_GET_INT_MOD (1 << 0)
#define BF_GET_INT_MOD (1 << 0)
int bf_get_int32(int *pres, const bf_t *a, int flags);
int bf_get_int64(int64_t *pres, const bf_t *a, int flags);
int bf_get_uint64(uint64_t *pres, const bf_t *a);
@ -366,10 +366,10 @@ int bf_normalize_and_round(bf_t *r, limb_t prec1, bf_flags_t flags);
int bf_can_round(const bf_t *a, slimb_t prec, bf_rnd_t rnd_mode, slimb_t k);
slimb_t bf_mul_log2_radix(slimb_t a1, unsigned int radix, int is_inv,
int is_ceil1);
int mp_mul(bf_context_t *s, limb_t *result,
const limb_t *op1, limb_t op1_size,
int mp_mul(bf_context_t *s, limb_t *result,
const limb_t *op1, limb_t op1_size,
const limb_t *op2, limb_t op2_size);
limb_t mp_add(limb_t *res, const limb_t *op1, const limb_t *op2,
limb_t mp_add(limb_t *res, const limb_t *op1, const limb_t *op2,
limb_t n, limb_t carry);
limb_t mp_add_ui(limb_t *tab, limb_t b, size_t n);
int mp_sqrtrem(bf_context_t *s, limb_t *tabs, limb_t *taba, limb_t n);

View file

@ -1635,7 +1635,7 @@ static int re_parse_term(REParseState *s, BOOL is_backward_dir)
put_u32(s->byte_code.buf + last_atom_start + 1,
len + 5 + add_zero_advance_check);
if (add_zero_advance_check) {
/* avoid infinite loop by stopping the
/* avoid infinite loop by stoping the
recursion if no advance was made in the
atom (only works if the atom has no
side effect) */

View file

@ -30,7 +30,7 @@ int lre_parse_escape(const uint8_t **pp, int allow_utf16);
LRE_BOOL lre_is_space(int c);
/* must be provided by the user */
LRE_BOOL lre_check_stack_overflow(void *opaque, size_t alloca_size);
LRE_BOOL lre_check_stack_overflow(void *opaque, size_t alloca_size);
void *lre_realloc(void *opaque, void *ptr, size_t size);
/* JS identifier test */

View file

@ -56,9 +56,9 @@ enum {
};
/* conv_type:
0 = to upper
0 = to upper
1 = to lower
2 = case folding (= to lower with modifications)
2 = case folding (= to lower with modifications)
*/
int lre_case_conv(uint32_t *res, uint32_t c, int conv_type)
{
@ -75,7 +75,7 @@ int lre_case_conv(uint32_t *res, uint32_t c, int conv_type)
} else {
uint32_t v, code, data, type, len, a, is_lower;
int idx, idx_min, idx_max;
is_lower = (conv_type != 0);
idx_min = 0;
idx_max = countof(case_conv_table1) - 1;
@ -215,7 +215,7 @@ static BOOL lre_is_in_table(uint32_t c, const uint8_t *table,
uint32_t code, b, bit;
int pos;
const uint8_t *p;
pos = get_index_pos(&code, c, index_table, index_table_len);
if (pos < 0)
return FALSE; /* outside the table */
@ -248,7 +248,7 @@ BOOL lre_is_cased(uint32_t c)
{
uint32_t v, code, len;
int idx, idx_min, idx_max;
idx_min = 0;
idx_max = countof(case_conv_table1) - 1;
while (idx_min <= idx_max) {
@ -307,7 +307,7 @@ int cr_realloc(CharRange *cr, int size)
{
int new_size;
uint32_t *new_buf;
if (size > cr->size) {
new_size = max_int(size, cr->size * 3 / 2);
new_buf = cr->realloc_func(cr->mem_opaque, cr->points,
@ -334,7 +334,7 @@ static void cr_compress(CharRange *cr)
{
int i, j, k, len;
uint32_t *pt;
pt = cr->points;
len = cr->len;
i = 0;
@ -364,7 +364,7 @@ int cr_op(CharRange *cr, const uint32_t *a_pt, int a_len,
{
int a_idx, b_idx, is_in;
uint32_t v;
a_idx = 0;
b_idx = 0;
for(;;) {
@ -665,7 +665,7 @@ static int unicode_decomp_char(uint32_t *res, uint32_t c, BOOL is_compat1)
{
uint32_t v, type, is_compat, code, len;
int idx_min, idx_max, idx;
idx_min = 0;
idx_max = countof(unicode_decomp_table1) - 1;
while (idx_min <= idx_max) {
@ -695,7 +695,7 @@ static int unicode_compose_pair(uint32_t c0, uint32_t c1)
uint32_t code, len, type, v, idx1, d_idx, d_offset, ch;
int idx_min, idx_max, idx, d;
uint32_t pair[2];
idx_min = 0;
idx_max = countof(unicode_comp_table) - 1;
while (idx_min <= idx_max) {
@ -731,7 +731,7 @@ static int unicode_get_cc(uint32_t c)
uint32_t code, n, type, cc, c1, b;
int pos;
const uint8_t *p;
pos = get_index_pos(&code, c,
unicode_cc_index, sizeof(unicode_cc_index) / 3);
if (pos < 0)
@ -780,7 +780,7 @@ static int unicode_get_cc(uint32_t c)
static void sort_cc(int *buf, int len)
{
int i, j, k, cc, cc1, start, ch1;
for(i = 0; i < len; i++) {
cc = unicode_get_cc(buf[i]);
if (cc != 0) {
@ -819,7 +819,7 @@ static void to_nfd_rec(DynBuf *dbuf,
uint32_t c, v;
int i, l;
uint32_t res[UNICODE_DECOMP_LEN_MAX];
for(i = 0; i < src_len; i++) {
c = src[i];
if (c >= 0xac00 && c < 0xd7a4) {
@ -864,7 +864,7 @@ int unicode_normalize(uint32_t **pdst, const uint32_t *src, int src_len,
int *buf, buf_len, i, p, starter_pos, cc, last_cc, out_len;
BOOL is_compat;
DynBuf dbuf_s, *dbuf = &dbuf_s;
is_compat = n_type >> 1;
dbuf_init2(dbuf, opaque, realloc_func);
@ -892,15 +892,15 @@ int unicode_normalize(uint32_t **pdst, const uint32_t *src, int src_len,
}
buf = (int *)dbuf->buf;
buf_len = dbuf->size / sizeof(int);
sort_cc(buf, buf_len);
if (buf_len <= 1 || (n_type & 1) != 0) {
/* NFD / NFKD */
*pdst = (uint32_t *)buf;
return buf_len;
}
i = 1;
out_len = 1;
while (i < buf_len) {
@ -937,7 +937,7 @@ static int unicode_find_name(const char *name_table, const char *name)
const char *p, *r;
int pos;
size_t name_len, len;
p = name_table;
pos = 0;
name_len = strlen(name);
@ -970,13 +970,13 @@ int unicode_script(CharRange *cr,
CharRange cr1_s, *cr1;
CharRange cr2_s, *cr2 = &cr2_s;
BOOL is_common;
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);
if (is_ext) {
@ -1243,7 +1243,7 @@ static int unicode_case1(CharRange *cr, int case_mask)
}
return 0;
}
typedef enum {
POP_GC,
POP_PROP,
@ -1263,7 +1263,7 @@ static int unicode_prop_ops(CharRange *cr, ...)
CharRange stack[POP_STACK_LEN_MAX];
int stack_len, op, ret, i;
uint32_t a;
va_start(ap, cr);
stack_len = 0;
for(;;) {
@ -1349,7 +1349,7 @@ int unicode_general_category(CharRange *cr, const char *gc_name)
{
int gc_idx;
uint32_t gc_mask;
gc_idx = unicode_find_name(unicode_gc_name_table, gc_name);
if (gc_idx < 0)
return -2;
@ -1367,7 +1367,7 @@ int unicode_general_category(CharRange *cr, const char *gc_name)
int unicode_prop(CharRange *cr, const char *prop_name)
{
int prop_idx, ret;
prop_idx = unicode_find_name(unicode_prop_name_table, prop_name);
if (prop_idx < 0)
return -2;

View file

@ -22,7 +22,7 @@ static inline void init_list_head(struct list_head *head)
}
/* insert 'el' between 'prev' and 'next' */
static inline void __list_add(struct list_head *el,
static inline void __list_add(struct list_head *el,
struct list_head *prev, struct list_head *next)
{
prev->next = el;

View file

@ -52,7 +52,7 @@ JSContext *JS_GetFunctionRealm(JSContext *ctx, JSValueConst func_obj)
{
JSObject *p;
JSContext *realm;
if (JS_VALUE_GET_TAG(func_obj) != JS_TAG_OBJECT)
return ctx;
p = JS_VALUE_GET_OBJ(func_obj);
@ -101,7 +101,7 @@ JSValue js_create_from_ctor(JSContext *ctx, JSValueConst ctor,
{
JSValue proto, obj;
JSContext *realm;
if (JS_IsUndefined(ctor)) {
proto = JS_DupValue(ctx, ctx->class_proto[class_id]);
} else {

View file

@ -1,6 +1,6 @@
/*
* QuickJS Javascript Calculator
*
*
* Copyright (c) 2017-2020 Fabrice Bellard
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@ -30,7 +30,7 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
global.Integer = global.BigInt;
global.Float = global.BigFloat;
global.algebraicMode = true;
/* add non enumerable properties */
function add_props(obj, props) {
var i, val, prop, tab, desc;
@ -85,9 +85,9 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
}
}
proto[Symbol.operatorSet] =
Operators.create.call(null, ...new_op_list);
Operators.create.call(null, ...new_op_list);
}
/* Integer */
function generic_pow(a, b) {
@ -121,7 +121,7 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
}
return r;
}
var small_primes = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499 ];
function miller_rabin_test(n, t) {
@ -184,7 +184,7 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
}
}
});
add_props(Integer, {
isInteger(a) {
/* integers are represented either as bigint or as number */
@ -305,7 +305,7 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
r.push(-1);
n = -n;
}
while ((n % 2) == 0) {
n >>= 1;
r.push(2);
@ -394,7 +394,7 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
a = Integer.tdiv(a, d);
b = Integer.tdiv(b, d);
}
/* the fractions are normalized with den > 0 */
if (b < 0) {
a = -a;
@ -476,7 +476,7 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
else
return a < b;
}
operators_set(Fraction.prototype,
{
"+": fraction_add,
@ -518,7 +518,7 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
"==": float_eq,
"<": float_lt,
});
add_props(Fraction, {
/* (internal use) simplify 'a' to an integer when possible */
toFraction(a, b) {
@ -602,11 +602,11 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
}
},
});
/* Float */
var const_tab = [];
/* we cache the constants for small precisions */
function get_const(n) {
var t, c, p;
@ -631,7 +631,7 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
return c;
}
}
add_props(Float, {
isFloat(a) {
return typeof a === "number" || typeof a === "bigfloat";
@ -700,9 +700,9 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
}
},
});
/* Complex */
Complex = function Complex(re, im)
{
var obj;
@ -719,7 +719,7 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
return obj;
}
function complex_add(a, b) {
a = Complex(a);
b = Complex(b);
@ -746,7 +746,7 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
b = Complex(b);
return a.re == b.re && a.im == b.im;
}
operators_set(Complex.prototype,
{
"+": complex_add,
@ -772,7 +772,7 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
"**": generic_pow,
"==": complex_eq,
});
add_props(Complex, {
/* simplify to real number when possible */
toComplex(re, im) {
@ -851,7 +851,7 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
obj.mod = m;
return obj;
};
function mod_add(a, b) {
if (!(a instanceof Mod)) {
return Mod(a + b.res, b.mod);
@ -947,7 +947,7 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
return true;
return false;
}
Polynomial = function Polynomial(a)
{
if (new.target)
@ -1017,7 +1017,7 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
/* trivial zero */
if (p[0] == 0)
return 0.0;
p1 = p.deriv();
p2 = p1.deriv();
el = 0.0;
@ -1041,7 +1041,7 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
}
el = e;
zl = z;
z1 = p1.apply(z);
z2 = p2.apply(z);
t0 = (d - 1) * z1;
@ -1052,7 +1052,7 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
d2 = z1 - t0;
if (norm2(d2) > norm2(d1))
d1 = d2;
if (d1 == 0)
if (d1 == 0)
return null;
z = z - d * z0 / d1;
}
@ -1274,7 +1274,7 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
"/": polynomial_div_scalar,
"**": generic_pow, /* XXX: only for integer */
});
add_props(Polynomial, {
divrem(a, b) {
var n1, n2, i, j, q, r, n, c;
@ -1437,7 +1437,7 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
});
/* Rational function */
RationalFunction = function RationalFunction(a, b)
{
var t, r, d, obj;
@ -1538,7 +1538,7 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
"/": ratfunc_div,
"**": generic_pow, /* should only be used with integers */
});
add_props(RationalFunction, {
/* This function always return a RationalFunction object even
if it could simplified to a polynomial, so it is not
@ -1555,7 +1555,7 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
}
},
});
/* Power series */
/* 'a' is an array */
@ -1574,11 +1574,11 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
return polynomial_is_scalar(a) ||
(a instanceof Polynomial);
}
/* n is the maximum number of terms if 'a' is not a serie */
Series = function Series(a, n) {
var emin, r, i;
if (a instanceof Series) {
return a;
} else if (series_is_scalar_or_polynomial(a)) {
@ -1897,7 +1897,7 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
return Series.zero(0, n);
},
});
/* Array (Matrix) */
Matrix = function Matrix(h, w) {
@ -2002,7 +2002,7 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
},
det(a) {
var n, i, j, k, s, src, v, c;
n = Matrix.check_square(a);
s = 1;
src = a.dup();
@ -2061,7 +2061,7 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
src[i][k] *= c;
dst[i][k] *= c;
}
for(j = 0; j < n; j++) {
if (j != i) {
c = src[j][i];
@ -2078,7 +2078,7 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
},
rank(a) {
var src, i, j, k, w, h, l, c;
if (!Array.isArray(a) ||
!Array.isArray(a[0]))
throw TypeError("matrix expected");
@ -2101,12 +2101,12 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
src[l][k] = v;
}
}
c = src[l][i].inverse();
for(k = 0; k < w; k++) {
src[l][k] *= c;
}
for(j = l + 1; j < h; j++) {
c = src[j][i];
for(k = i; k < w; k++) {
@ -2119,7 +2119,7 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
},
ker(a) {
var src, i, j, k, w, h, l, m, r, im_cols, ker_dim, c;
if (!Array.isArray(a) ||
!Array.isArray(a[0]))
throw TypeError("matrix expected");
@ -2145,12 +2145,12 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
src[l][k] = v;
}
}
c = src[l][i].inverse();
for(k = 0; k < w; k++) {
src[l][k] *= c;
}
for(j = 0; j < h; j++) {
if (j != l) {
c = src[j][i];

View file

@ -1,6 +1,6 @@
/*
* QuickJS atom definitions
*
*
* Copyright (c) 2017-2018 Fabrice Bellard
* Copyright (c) 2017-2018 Charlie Gordon
*
@ -202,7 +202,7 @@ DEF(RegExp, "RegExp")
DEF(ArrayBuffer, "ArrayBuffer")
DEF(SharedArrayBuffer, "SharedArrayBuffer")
/* must keep same order as class IDs for typed arrays */
DEF(Uint8ClampedArray, "Uint8ClampedArray")
DEF(Uint8ClampedArray, "Uint8ClampedArray")
DEF(Int8Array, "Int8Array")
DEF(Uint8Array, "Uint8Array")
DEF(Int16Array, "Int16Array")
@ -269,5 +269,5 @@ DEF(Symbol_asyncIterator, "Symbol.asyncIterator")
#ifdef CONFIG_BIGNUM
DEF(Symbol_operatorSet, "Symbol.operatorSet")
#endif
#endif /* DEF */

View file

@ -170,7 +170,7 @@ static JSValue js_printf_internal(JSContext *ctx,
break;
q = fmtbuf;
*q++ = *fmt++; /* copy '%' */
/* flags */
for(;;) {
c = *fmt;
@ -224,14 +224,14 @@ static JSValue js_printf_internal(JSContext *ctx,
if (*fmt == 'l') {
mod = *fmt++;
}
/* type */
c = *fmt++;
if (q >= fmtbuf + sizeof(fmtbuf) - 1)
goto invalid;
*q++ = c;
*q = '\0';
switch (c) {
case 'c':
if (i >= argc)
@ -253,7 +253,7 @@ static JSValue js_printf_internal(JSContext *ctx,
len = unicode_to_utf8(cbuf, int32_arg);
dbuf_put(&dbuf, cbuf, len);
break;
case 'd':
case 'i':
case 'o':
@ -298,7 +298,7 @@ static JSValue js_printf_internal(JSContext *ctx,
dbuf_printf_fun(&dbuf, fmtbuf, string_arg);
JS_FreeCString(ctx, string_arg);
break;
case 'e':
case 'f':
case 'g':
@ -313,11 +313,11 @@ static JSValue js_printf_internal(JSContext *ctx,
goto fail;
dbuf_printf_fun(&dbuf, fmtbuf, double_arg);
break;
case '%':
dbuf_putc(&dbuf, '%');
break;
default:
/* XXX: should support an extension mechanism */
invalid:
@ -354,7 +354,7 @@ uint8_t *js_load_file(JSContext *ctx, size_t *pbuf_len, const char *filename)
uint8_t *buf;
size_t buf_len;
long lret;
f = fopen(filename, "rb");
if (!f)
return NULL;
@ -401,7 +401,7 @@ static JSValue js_loadScript(JSContext *ctx, JSValueConst this_val,
const char *filename;
JSValue ret;
size_t buf_len;
filename = JS_ToCString(ctx, argv[0]);
if (!filename)
return JS_EXCEPTION;
@ -426,7 +426,7 @@ static JSValue js_std_loadFile(JSContext *ctx, JSValueConst this_val,
const char *filename;
JSValue ret;
size_t buf_len;
filename = JS_ToCString(ctx, argv[0]);
if (!filename)
return JS_EXCEPTION;
@ -458,7 +458,7 @@ static JSModuleDef *js_module_loader_so(JSContext *ctx,
void *hd;
JSInitModuleFunc *init;
char *filename;
if (!strchr(module_name, '/')) {
/* must add a '/' so that the DLL is not searched in the
system library paths */
@ -470,7 +470,7 @@ static JSModuleDef *js_module_loader_so(JSContext *ctx,
} else {
filename = (char *)module_name;
}
/* C module */
hd = dlopen(filename, RTLD_NOW | RTLD_LOCAL);
if (filename != module_name)
@ -509,7 +509,7 @@ int js_module_set_import_meta(JSContext *ctx, JSValueConst func_val,
JSValue meta_obj;
JSAtom module_name_atom;
const char *module_name;
assert(JS_VALUE_GET_TAG(func_val) == JS_TAG_MODULE);
m = JS_VALUE_GET_PTR(func_val);
@ -540,7 +540,7 @@ int js_module_set_import_meta(JSContext *ctx, JSValueConst func_val,
pstrcpy(buf, sizeof(buf), module_name);
}
JS_FreeCString(ctx, module_name);
meta_obj = JS_GetImportMeta(ctx, m);
if (JS_IsException(meta_obj))
return -1;
@ -565,14 +565,14 @@ JSModuleDef *js_module_loader(JSContext *ctx,
size_t buf_len;
uint8_t *buf;
JSValue func_val;
buf = js_load_file(ctx, &buf_len, module_name);
if (!buf) {
JS_ThrowReferenceError(ctx, "could not load module filename '%s'",
module_name);
return NULL;
}
/* compile the module */
func_val = JS_Eval(ctx, (char *)buf, buf_len, module_name,
JS_EVAL_TYPE_MODULE | JS_EVAL_FLAG_COMPILE_ONLY);
@ -738,7 +738,7 @@ static JSValue js_evalScript(JSContext *ctx, JSValueConst this_val,
JSValueConst options_obj;
BOOL backtrace_barrier = FALSE;
int flags;
if (argc >= 2) {
options_obj = argv[1];
if (get_bool_option(ctx, &backtrace_barrier, options_obj,
@ -753,7 +753,7 @@ static JSValue js_evalScript(JSContext *ctx, JSValueConst this_val,
/* install the interrupt handler */
JS_SetInterruptHandler(JS_GetRuntime(ctx), interrupt_handler, NULL);
}
flags = JS_EVAL_TYPE_GLOBAL;
flags = JS_EVAL_TYPE_GLOBAL;
if (backtrace_barrier)
flags |= JS_EVAL_FLAG_BACKTRACE_BARRIER;
ret = JS_Eval(ctx, str, len, "<evalScript>", flags);
@ -857,7 +857,7 @@ static JSValue js_std_open(JSContext *ctx, JSValueConst this_val,
const char *filename, *mode = NULL;
FILE *f;
int err;
filename = JS_ToCString(ctx, argv[0]);
if (!filename)
goto fail;
@ -893,7 +893,7 @@ static JSValue js_std_popen(JSContext *ctx, JSValueConst this_val,
const char *filename, *mode = NULL;
FILE *f;
int err;
filename = JS_ToCString(ctx, argv[0]);
if (!filename)
goto fail;
@ -1007,7 +1007,7 @@ static JSValue js_std_file_puts(JSContext *ctx, JSValueConst this_val,
if (!f)
return JS_EXCEPTION;
}
for(i = 0; i < argc; i++) {
str = JS_ToCStringLen(ctx, &len, argv[i]);
if (!str)
@ -1138,7 +1138,7 @@ static JSValue js_std_file_read_write(JSContext *ctx, JSValueConst this_val,
uint64_t pos, len;
size_t size, ret;
uint8_t *buf;
if (!f)
return JS_EXCEPTION;
if (JS_ToIndex(ctx, &pos, argv[1]))
@ -1165,7 +1165,7 @@ static JSValue js_std_file_getline(JSContext *ctx, JSValueConst this_val,
int c;
DynBuf dbuf;
JSValue obj;
if (!f)
return JS_EXCEPTION;
@ -1204,7 +1204,7 @@ static JSValue js_std_file_readAsString(JSContext *ctx, JSValueConst this_val,
uint64_t max_size64;
size_t max_size;
JSValueConst max_size_val;
if (!f)
return JS_EXCEPTION;
@ -1268,7 +1268,7 @@ static int http_get_header_line(FILE *f, char *buf, size_t buf_size,
{
int c;
char *p;
p = buf;
for(;;) {
c = fgetc(f);
@ -1304,21 +1304,21 @@ static JSValue js_std_urlGet(JSContext *ctx, JSValueConst this_val,
DynBuf cmd_buf;
DynBuf data_buf_s, *data_buf = &data_buf_s;
DynBuf header_buf_s, *header_buf = &header_buf_s;
char *buf;
char *buf;
size_t i, len;
int c, status;
JSValue response = JS_UNDEFINED, ret_obj;
JSValueConst options_obj;
FILE *f;
BOOL binary_flag, full_flag;
url = JS_ToCString(ctx, argv[0]);
if (!url)
return JS_EXCEPTION;
binary_flag = FALSE;
full_flag = FALSE;
if (argc >= 2) {
options_obj = argv[1];
@ -1331,7 +1331,7 @@ static JSValue js_std_urlGet(JSContext *ctx, JSValueConst this_val,
return JS_EXCEPTION;
}
}
js_std_dbuf_init(ctx, &cmd_buf);
dbuf_printf(&cmd_buf, "%s ''", URL_GET_PROGRAM);
len = strlen(url);
@ -1357,7 +1357,7 @@ static JSValue js_std_urlGet(JSContext *ctx, JSValueConst this_val,
js_std_dbuf_init(ctx, data_buf);
js_std_dbuf_init(ctx, header_buf);
buf = js_malloc(ctx, URL_GET_BUF_SIZE);
if (!buf)
goto fail;
@ -1371,7 +1371,7 @@ static JSValue js_std_urlGet(JSContext *ctx, JSValueConst this_val,
if (!full_flag && !(status >= 200 && status <= 299)) {
goto bad_header;
}
/* wait until there is an empty line */
for(;;) {
if (http_get_header_line(f, buf, URL_GET_BUF_SIZE, header_buf) < 0) {
@ -1447,7 +1447,7 @@ static JSValue js_std_urlGet(JSContext *ctx, JSValueConst this_val,
static JSClassDef js_std_file_class = {
"FILE",
.finalizer = js_std_file_finalizer,
};
};
static JSCFunctionListEntry js_std_error_props[11];
static textstartup void js_std_error_props_init() {
@ -1485,7 +1485,7 @@ static const JSCFunctionListEntry js_std_funcs[] = {
JS_CFUNC_DEF("loadFile", 1, js_std_loadFile ),
JS_CFUNC_DEF("strerror", 1, js_std_strerror ),
JS_CFUNC_DEF("parseExtJSON", 1, js_std_parseExtJSON ),
/* FILE I/O */
JS_CFUNC_DEF("open", 2, js_std_open ),
JS_CFUNC_DEF("popen", 2, js_std_popen ),
@ -1499,7 +1499,7 @@ static const JSCFunctionListEntry js_std_funcs[] = {
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),
};
static const JSCFunctionListEntry js_std_file_proto_funcs[] = {
JS_CFUNC_DEF("close", 0, js_std_file_close ),
JS_CFUNC_MAGIC_DEF("puts", 1, js_std_file_puts, 1 ),
@ -1524,7 +1524,7 @@ static const JSCFunctionListEntry js_std_file_proto_funcs[] = {
static int js_std_init(JSContext *ctx, JSModuleDef *m)
{
JSValue proto;
/* FILE class */
/* the class ID is created once */
JS_NewClassID(&js_std_file_class_id);
@ -1605,7 +1605,7 @@ static JSValue js_os_seek(JSContext *ctx, JSValueConst this_val,
int fd, whence;
int64_t pos, ret;
BOOL is_bigint;
if (JS_ToInt32(ctx, &fd, argv[0]))
return JS_EXCEPTION;
is_bigint = JS_IsBigInt(ctx, argv[1]);
@ -1630,7 +1630,7 @@ static JSValue js_os_read_write(JSContext *ctx, JSValueConst this_val,
size_t size;
ssize_t ret;
uint8_t *buf;
if (JS_ToInt32(ctx, &fd, argv[0]))
return JS_EXCEPTION;
if (JS_ToIndex(ctx, &pos, argv[2]))
@ -1670,7 +1670,7 @@ static JSValue js_os_ttyGetWinSize(JSContext *ctx, JSValueConst this_val,
if (JS_ToInt32(ctx, &fd, argv[0]))
return JS_EXCEPTION;
handle = (HANDLE)_get_osfhandle(fd);
if (!GetConsoleScreenBufferInfo(handle, &info))
return JS_NULL;
obj = JS_NewArray(ctx);
@ -1709,7 +1709,7 @@ static JSValue js_os_ttyGetWinSize(JSContext *ctx, JSValueConst this_val,
int fd;
struct winsize ws;
JSValue obj;
if (JS_ToInt32(ctx, &fd, argv[0]))
return JS_EXCEPTION;
if (ioctl(fd, TIOCGWINSZ, &ws) == 0 &&
@ -1738,7 +1738,7 @@ static JSValue js_os_ttySetRaw(JSContext *ctx, JSValueConst this_val,
{
struct termios tty;
int fd;
if (JS_ToInt32(ctx, &fd, argv[0]))
return JS_EXCEPTION;
bzero(&tty, sizeof(tty));
@ -1767,7 +1767,7 @@ static JSValue js_os_remove(JSContext *ctx, JSValueConst this_val,
{
const char *filename;
int ret;
filename = JS_ToCString(ctx, argv[0]);
if (!filename)
return JS_EXCEPTION;
@ -1793,7 +1793,7 @@ static JSValue js_os_rename(JSContext *ctx, JSValueConst this_val,
{
const char *oldpath, *newpath;
int ret;
oldpath = JS_ToCString(ctx, argv[0]);
if (!oldpath)
return JS_EXCEPTION;
@ -1845,7 +1845,7 @@ static JSValue js_os_setReadHandler(JSContext *ctx, JSValueConst this_val,
JSOSRWHandler *rh;
int fd;
JSValueConst func;
if (JS_ToInt32(ctx, &fd, argv[0]))
return JS_EXCEPTION;
func = argv[1];
@ -1919,7 +1919,7 @@ static JSValue js_os_signal(JSContext *ctx, JSValueConst this_val,
if (!is_main_thread(rt))
return JS_ThrowTypeError(ctx, "signal handler can only be set in the main thread");
if (JS_ToUint32(ctx, &sig_num, argv[0]))
return JS_EXCEPTION;
if (sig_num >= 64)
@ -2051,7 +2051,7 @@ static JSClassDef js_os_timer_class = {
"OSTimer",
.finalizer = js_os_timer_finalizer,
.gc_mark = js_os_timer_mark,
};
};
static void call_handler(JSContext *ctx, JSValueConst func)
{
@ -2081,12 +2081,12 @@ static int js_os_poll_nt(JSContext *ctx)
int64_t cur_time, delay;
JSOSRWHandler *rh;
struct list_head *el;
/* XXX: handle signals if useful */
if (list_empty(&ts->os_rw_handlers) && list_empty(&ts->os_timers))
return -1; /* no more events */
/* XXX: only timers and basic console input are supported */
if (!list_empty(&ts->os_timers)) {
cur_time = get_time_ms();
@ -2160,7 +2160,7 @@ static int handle_posted_message(JSRuntime *rt, JSContext *ctx,
struct list_head *el;
JSWorkerMessage *msg;
JSValue obj, data_obj, func, retval;
pthread_mutex_lock(&ps->mutex);
if (!list_empty(&ps->msg_queue)) {
el = ps->msg_queue.next;
@ -2187,7 +2187,7 @@ static int handle_posted_message(JSRuntime *rt, JSContext *ctx,
JS_READ_OBJ_SAB | JS_READ_OBJ_REFERENCE);
js_free_message(msg);
if (JS_IsException(data_obj))
goto fail;
obj = JS_NewObject(ctx);
@ -2242,7 +2242,7 @@ static int js_os_poll(JSContext *ctx)
if (!ts->recv_pipe && UNLIKELY(os_pending_signals != 0)) {
JSOSSignalHandler *sh;
uint64_t mask;
list_for_each(el, &ts->os_signal_handlers) {
sh = list_entry(el, JSOSSignalHandler, link);
mask = (uint64_t)1 << sh->sig_num;
@ -2257,7 +2257,7 @@ static int js_os_poll(JSContext *ctx)
if (list_empty(&ts->os_rw_handlers) && list_empty(&ts->os_timers) &&
list_empty(&ts->port_list))
return -1; /* no more events */
if (!list_empty(&ts->os_timers)) {
cur_time = get_time_ms();
min_delay = 10000;
@ -2285,7 +2285,7 @@ static int js_os_poll(JSContext *ctx)
} else {
tvp = NULL;
}
FD_ZERO(&rfds);
FD_ZERO(&wfds);
fd_max = -1;
@ -2371,7 +2371,7 @@ static JSValue js_os_getcwd(JSContext *ctx, JSValueConst this_val,
{
char buf[MAXPATH];
int err;
if (!getcwd(buf, sizeof(buf))) {
buf[0] = '\0';
err = errno;
@ -2400,7 +2400,7 @@ static JSValue js_os_mkdir(JSContext *ctx, JSValueConst this_val,
{
int mode, ret;
const char *path;
if (argc >= 2) {
if (JS_ToInt32(ctx, &mode, argv[1]))
return JS_EXCEPTION;
@ -2430,7 +2430,7 @@ static JSValue js_os_readdir(JSContext *ctx, JSValueConst this_val,
JSValue obj;
int err;
uint32_t len;
path = JS_ToCString(ctx, argv[0]);
if (!path)
return JS_EXCEPTION;
@ -2578,7 +2578,7 @@ static JSValue js_os_utimes(JSContext *ctx, JSValueConst this_val,
const char *path;
int64_t atime, mtime;
int ret;
if (JS_ToInt64(ctx, &atime, argv[1]))
return JS_EXCEPTION;
if (JS_ToInt64(ctx, &mtime, argv[2]))
@ -2611,7 +2611,7 @@ static JSValue js_os_sleep(JSContext *ctx, JSValueConst this_val,
{
int64_t delay;
int ret;
if (JS_ToInt64(ctx, &delay, argv[0]))
return JS_EXCEPTION;
if (delay < 0)
@ -2663,7 +2663,7 @@ static JSValue js_os_symlink(JSContext *ctx, JSValueConst this_val,
{
const char *target, *linkpath;
int err;
target = JS_ToCString(ctx, argv[0]);
if (!target)
return JS_EXCEPTION;
@ -2686,7 +2686,7 @@ static JSValue js_os_readlink(JSContext *ctx, JSValueConst this_val,
char buf[MAXPATH];
int err;
ssize_t res;
path = JS_ToCString(ctx, argv[0]);
if (!path)
return JS_EXCEPTION;
@ -2710,7 +2710,7 @@ static char **build_envp(JSContext *ctx, JSValueConst obj)
const char *key, *str;
JSValue val;
size_t key_len, str_len;
if (JS_GetOwnPropertyNames(ctx, &tab, &len, obj,
JS_GPN_STRING_MASK | JS_GPN_ENUM_ONLY) < 0)
return NULL;
@ -2775,7 +2775,7 @@ static JSValue js_os_exec(JSContext *ctx, JSValueConst this_val,
static const char *std_name[3] = { "stdin", "stdout", "stderr" };
int std_fds[3];
uint32_t uid = -1, gid = -1;
val = JS_GetPropertyStr(ctx, args, "length");
if (JS_IsException(val))
return JS_EXCEPTION;
@ -2804,7 +2804,7 @@ static JSValue js_os_exec(JSContext *ctx, JSValueConst this_val,
for(i = 0; i < 3; i++)
std_fds[i] = i;
/* get the options, if any */
if (argc >= 2) {
options = argv[1];
@ -2813,7 +2813,7 @@ static JSValue js_os_exec(JSContext *ctx, JSValueConst this_val,
goto exception;
if (get_bool_option(ctx, &use_path, options, "usePath"))
goto exception;
val = JS_GetPropertyStr(ctx, options, "file");
if (JS_IsException(val))
goto exception;
@ -2858,7 +2858,7 @@ static JSValue js_os_exec(JSContext *ctx, JSValueConst this_val,
if (!envp)
goto exception;
}
val = JS_GetPropertyStr(ctx, options, "uid");
if (JS_IsException(val))
goto exception;
@ -2965,7 +2965,7 @@ static JSValue js_os_waitpid(JSContext *ctx, JSValueConst this_val,
{
int pid, status, options, ret;
JSValue obj;
if (JS_ToInt32(ctx, &pid, argv[0]))
return JS_EXCEPTION;
if (JS_ToInt32(ctx, &options, argv[1]))
@ -2985,7 +2985,7 @@ static JSValue js_os_waitpid(JSContext *ctx, JSValueConst this_val,
JS_DefinePropertyValueUint32(ctx, obj, 1, JS_NewInt32(ctx, status),
JS_PROP_C_W_E);
return obj;
}
}
/* pipe() -> [read_fd, write_fd] or null if error */
static JSValue js_os_pipe(JSContext *ctx, JSValueConst this_val,
@ -2993,7 +2993,7 @@ static JSValue js_os_pipe(JSContext *ctx, JSValueConst this_val,
{
int pipe_fds[2], ret;
JSValue obj;
ret = pipe(pipe_fds);
if (ret < 0)
return JS_NULL;
@ -3012,7 +3012,7 @@ static JSValue js_os_kill(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv)
{
int pid, sig, ret;
if (JS_ToInt32(ctx, &pid, argv[0]))
return JS_EXCEPTION;
if (JS_ToInt32(ctx, &sig, argv[1]))
@ -3026,7 +3026,7 @@ static JSValue js_os_dup(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv)
{
int fd, ret;
if (JS_ToInt32(ctx, &fd, argv[0]))
return JS_EXCEPTION;
ret = js_get_errno(dup(fd));
@ -3038,7 +3038,7 @@ static JSValue js_os_dup2(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv)
{
int fd, fd2, ret;
if (JS_ToInt32(ctx, &fd, argv[0]))
return JS_EXCEPTION;
if (JS_ToInt32(ctx, &fd2, argv[1]))
@ -3112,7 +3112,7 @@ static JSWorkerMessagePipe *js_new_message_pipe(void)
{
JSWorkerMessagePipe *ps;
int pipe_fds[2];
if (pipe(pipe_fds) < 0)
return NULL;
@ -3153,10 +3153,10 @@ static void js_free_message_pipe(JSWorkerMessagePipe *ps)
struct list_head *el, *el1;
JSWorkerMessage *msg;
int ref_count;
if (!ps)
return;
ref_count = atomic_add_int(&ps->ref_count, -1);
assert(ref_count >= 0);
if (ref_count == 0) {
@ -3195,7 +3195,7 @@ static void js_worker_finalizer(JSRuntime *rt, JSValue val)
static JSClassDef js_worker_class = {
"Worker",
.finalizer = js_worker_finalizer,
};
};
static void *worker_func(void *opaque)
{
@ -3203,12 +3203,12 @@ static void *worker_func(void *opaque)
JSRuntime *rt;
JSThreadState *ts;
JSContext *ctx;
rt = JS_NewRuntime();
if (rt == NULL) {
fprintf(stderr, "JS_NewRuntime failure");
exit(1);
}
}
js_std_init_handlers(rt);
JS_SetModuleLoaderFunc(rt, NULL, js_module_loader, NULL);
@ -3217,7 +3217,7 @@ static void *worker_func(void *opaque)
ts = JS_GetRuntimeOpaque(rt);
ts->recv_pipe = args->recv_pipe;
ts->send_pipe = args->send_pipe;
/* function pointer to avoid linking the whole JS_NewContext() if
not needed */
ctx = js_worker_new_context_func(rt);
@ -3249,7 +3249,7 @@ static JSValue js_worker_ctor_internal(JSContext *ctx, JSValueConst new_target,
{
JSValue obj = JS_UNDEFINED, proto;
JSWorkerData *s;
/* create the object */
if (JS_IsUndefined(new_target)) {
proto = JS_GetClassProto(ctx, js_worker_class_id);
@ -3286,7 +3286,7 @@ static JSValue js_worker_ctor(JSContext *ctx, JSValueConst new_target,
int ret;
const char *filename = NULL, *basename;
JSAtom basename_atom;
/* XXX: in order to avoid problems with resource liberation, we
don't support creating workers inside workers */
if (!is_main_thread(rt))
@ -3302,7 +3302,7 @@ static JSValue js_worker_ctor(JSContext *ctx, JSValueConst new_target,
JS_FreeAtom(ctx, basename_atom);
if (!basename)
goto fail;
/* module name */
filename = JS_ToCString(ctx, argv[0]);
if (!filename)
@ -3327,7 +3327,7 @@ static JSValue js_worker_ctor(JSContext *ctx, JSValueConst new_target,
args->send_pipe, args->recv_pipe);
if (JS_IsException(obj))
goto fail;
pthread_attr_init(&attr);
/* no join at the end */
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
@ -3365,10 +3365,10 @@ static JSValue js_worker_postMessage(JSContext *ctx, JSValueConst this_val,
uint8_t *data;
JSWorkerMessage *msg;
uint8_t **sab_tab;
if (!worker)
return JS_EXCEPTION;
data = JS_WriteObject2(ctx, &data_len, argv[0],
JS_WRITE_OBJ_SAB | JS_WRITE_OBJ_REFERENCE,
&sab_tab, &sab_tab_len);
@ -3396,7 +3396,7 @@ static JSValue js_worker_postMessage(JSContext *ctx, JSValueConst this_val,
js_free(ctx, data);
js_free(ctx, sab_tab);
/* increment the SAB reference counts */
for(i = 0; i < msg->sab_tab_len; i++) {
js_sab_dup(NULL, msg->sab_tab[i]);
@ -3428,7 +3428,7 @@ static JSValue js_worker_postMessage(JSContext *ctx, JSValueConst this_val,
js_free(ctx, data);
js_free(ctx, sab_tab);
return JS_EXCEPTION;
}
static JSValue js_worker_set_onmessage(JSContext *ctx, JSValueConst this_val,
@ -3438,7 +3438,7 @@ static JSValue js_worker_set_onmessage(JSContext *ctx, JSValueConst this_val,
JSThreadState *ts = JS_GetRuntimeOpaque(rt);
JSWorkerData *worker = JS_GetOpaque2(ctx, this_val, js_worker_class_id);
JSWorkerMessageHandler *port;
if (!worker)
return JS_EXCEPTION;
@ -3597,7 +3597,7 @@ const void *const js_os_funcs_ctor[] initarray = {js_os_funcs_init};
static int js_os_init(JSContext *ctx, JSModuleDef *m)
{
os_poll_func = js_os_poll;
/* OSTimer class */
JS_NewClassID(&js_os_timer_class_id);
JS_NewClass(JS_GetRuntime(ctx), js_os_timer_class_id, &js_os_timer_class);
@ -3612,20 +3612,20 @@ static int js_os_init(JSContext *ctx, JSModuleDef *m)
JS_NewClass(JS_GetRuntime(ctx), js_worker_class_id, &js_worker_class);
proto = JS_NewObject(ctx);
JS_SetPropertyFunctionList(ctx, proto, js_worker_proto_funcs, countof(js_worker_proto_funcs));
obj = JS_NewCFunction2(ctx, js_worker_ctor, "Worker", 1,
JS_CFUNC_constructor, 0);
JS_SetConstructor(ctx, obj, proto);
JS_SetClassProto(ctx, js_worker_class_id, proto);
/* set 'Worker.parent' if necessary */
if (ts->recv_pipe && ts->send_pipe) {
JS_DefinePropertyValueStr(ctx, obj, "parent",
js_worker_ctor_internal(ctx, JS_UNDEFINED, ts->recv_pipe, ts->send_pipe),
JS_PROP_C_W_E);
}
JS_SetModuleExport(ctx, m, "Worker", obj);
}
#endif /* USE_WORKER */
@ -3690,12 +3690,12 @@ void js_std_add_helpers(JSContext *ctx, int argc, char **argv)
}
JS_SetPropertyStr(ctx, global_obj, "scriptArgs", args);
}
JS_SetPropertyStr(ctx, global_obj, "print",
JS_NewCFunction(ctx, js_print, "print", 1));
JS_SetPropertyStr(ctx, global_obj, "__loadScript",
JS_NewCFunction(ctx, js_loadScript, "__loadScript", 1));
JS_FreeValue(ctx, global_obj);
}
@ -3743,7 +3743,7 @@ void js_std_free_handlers(JSRuntime *rt)
JSOSSignalHandler *sh = list_entry(el, JSOSSignalHandler, link);
free_sh(rt, sh);
}
list_for_each_safe(el, el1, &ts->os_timers) {
JSOSTimer *th = list_entry(el, JSOSTimer, link);
unlink_timer(rt, th);
@ -3764,7 +3764,7 @@ void js_std_free_handlers(JSRuntime *rt)
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);
@ -3778,7 +3778,7 @@ 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) {
@ -3793,7 +3793,7 @@ static void js_std_dump_error1(JSContext *ctx, JSValueConst exception_val)
void js_std_dump_error(JSContext *ctx)
{
JSValue exception_val;
exception_val = JS_GetException(ctx);
js_std_dump_error1(ctx, exception_val);
JS_FreeValue(ctx, exception_val);

View file

@ -167,14 +167,14 @@ DEF( set_loc, 3, 1, 1, loc) /* must come after put_loc */
DEF( get_arg, 3, 0, 1, arg)
DEF( put_arg, 3, 1, 0, arg) /* must come after get_arg */
DEF( set_arg, 3, 1, 1, arg) /* must come after put_arg */
DEF( get_var_ref, 3, 0, 1, var_ref)
DEF( get_var_ref, 3, 0, 1, var_ref)
DEF( put_var_ref, 3, 1, 0, var_ref) /* must come after get_var_ref */
DEF( set_var_ref, 3, 1, 1, var_ref) /* must come after put_var_ref */
DEF(set_loc_uninitialized, 3, 0, 0, loc)
DEF( get_loc_check, 3, 0, 1, loc)
DEF( put_loc_check, 3, 1, 0, loc) /* must come after get_loc_check */
DEF( put_loc_check_init, 3, 1, 0, loc)
DEF(get_var_ref_check, 3, 0, 1, var_ref)
DEF(get_var_ref_check, 3, 0, 1, var_ref)
DEF(put_var_ref_check, 3, 1, 0, var_ref) /* must come after get_var_ref_check */
DEF(put_var_ref_check_init, 3, 1, 0, var_ref)
DEF( close_loc, 3, 0, 0, loc)
@ -263,7 +263,7 @@ DEF( mul_pow10, 1, 2, 1, none)
DEF( math_mod, 1, 2, 1, none)
#endif
/* must be the last non short and non temporary opcode */
DEF( nop, 1, 0, 0, none)
DEF( nop, 1, 0, 0, none)
/* temporary opcodes: never emitted in the final bytecode */
@ -284,7 +284,7 @@ def(scope_get_private_field2, 7, 1, 2, atom_u16) /* obj -> obj value, emitted in
def(scope_put_private_field, 7, 1, 1, atom_u16) /* obj value ->, emitted in phase 1, removed in phase 2 */
def( set_class_name, 5, 1, 1, u32) /* emitted in phase 1, removed in phase 2 */
def( line_num, 5, 0, 0, u32) /* emitted in phase 1, removed in phase 3 */
#if SHORT_OPCODES

View file

@ -10513,7 +10513,7 @@ static int find_private_class_field_all(JSContext *ctx, JSFunctionDef *fd,
static void get_loc_or_ref(DynBuf *bc, BOOL is_ref, int idx)
{
/* if the field is not initialized, the error is caught when
/* if the field is not initialized, the error is catched when
accessing it */
if (is_ref)
dbuf_putc(bc, OP_get_var_ref);
@ -12667,7 +12667,7 @@ static __exception int ss_check(JSContext *ctx, StackSizeState *s,
if (s->stack_level_tab[pos] != 0xffff) {
/* already explored: check that the stack size is consistent */
if (s->stack_level_tab[pos] != stack_len) {
JS_ThrowInternalError(ctx, "inconsistent stack size: %d %d (pc=%d)",
JS_ThrowInternalError(ctx, "unconsistent stack size: %d %d (pc=%d)",
s->stack_level_tab[pos], stack_len, pos);
return -1;
} else {

View file

@ -95,7 +95,7 @@ static inline JS_BOOL JS_VALUE_IS_NAN(JSValue v)
{
return 0;
}
#elif defined(JS_NAN_BOXING)
typedef uint64_t JSValue;
@ -160,7 +160,7 @@ static inline JS_BOOL JS_VALUE_IS_NAN(JSValue v)
tag = JS_VALUE_GET_TAG(v);
return tag == (JS_NAN >> 32);
}
#else /* !JS_NAN_BOXING */
typedef union JSValueUnion {
@ -926,7 +926,7 @@ static inline JSValue JS_NewCFunctionMagic(JSContext *ctx, JSCFunctionMagic *fun
{
return JS_NewCFunction2(ctx, (JSCFunction *)func, name, length, cproto, magic);
}
void JS_SetConstructor(JSContext *ctx, JSValueConst func_obj,
void JS_SetConstructor(JSContext *ctx, JSValueConst func_obj,
JSValueConst proto);
/* C property definition */

View file

@ -1,6 +1,6 @@
/*
* QuickJS Read Eval Print Loop
*
*
* Copyright (c) 2017-2020 Fabrice Bellard
* Copyright (c) 2017-2020 Charlie Gordon
*
@ -31,7 +31,7 @@ import * as os from "os";
/* add 'os' and 'std' bindings */
g.os = os;
g.std = std;
/* close global objects */
var Object = g.Object;
var String = g.String;
@ -45,7 +45,7 @@ import * as os from "os";
var config_numcalc = (typeof os.open === "undefined");
var has_jscalc = (typeof Fraction === "function");
var has_bignum = (typeof BigFloat === "function");
var colors = {
none: "\x1b[0m",
black: "\x1b[30m",
@ -105,7 +105,7 @@ import * as os from "os";
var prec;
var expBits;
var log2_10;
var pstate = "";
var prompt = "";
var plen = 0;
@ -119,7 +119,7 @@ import * as os from "os";
var show_time = false;
var show_colors = true;
var eval_time = 0;
var mexpr = "";
var level = 0;
var cmd = "";
@ -137,12 +137,12 @@ import * as os from "os";
var term_read_buf;
var term_width;
/* current X position of the cursor in the terminal */
var term_cursor_x = 0;
var term_cursor_x = 0;
function termInit() {
var tab;
term_fd = std.in.fileno();
/* get the terminal size */
term_width = 80;
if (os.isatty(term_fd)) {
@ -169,14 +169,14 @@ import * as os from "os";
/* send Ctrl-C to readline */
handle_byte(3);
}
function term_read_handler() {
var l, i;
l = os.read(term_fd, term_read_buf.buffer, 0, term_read_buf.length);
for(i = 0; i < l; i++)
handle_byte(term_read_buf[i]);
}
function handle_byte(c) {
if (!utf8) {
handle_char(c);
@ -194,12 +194,12 @@ import * as os from "os";
handle_char(c);
}
}
function is_alpha(c) {
return typeof c === "string" &&
((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'));
}
function is_digit(c) {
return typeof c === "string" && (c >= '0' && c <= '9');
}
@ -231,7 +231,7 @@ import * as os from "os";
d = c.codePointAt(0); /* can be NaN if empty string */
return d >= 0xdc00 && d < 0xe000;
}
function is_balanced(a, b) {
switch (a + b) {
case "()":
@ -270,7 +270,7 @@ import * as os from "os";
} else {
l = Math.min(term_width - 1 - term_cursor_x, delta);
print_csi(l, "C"); /* right */
delta -= l;
delta -= l;
term_cursor_x += l;
}
}
@ -398,7 +398,7 @@ import * as os from "os";
function backward_word() {
cursor_pos = skip_word_backward(cursor_pos);
}
}
function accept_line() {
std.puts("\n");
@ -581,7 +581,7 @@ import * as os from "os";
readline_print_prompt();
}
}
function reset() {
cmd = "";
cursor_pos = 0;
@ -735,7 +735,7 @@ import * as os from "os";
readline_print_prompt();
}
}
var commands = { /* command table */
"\x01": beginning_of_line, /* ^A - bol */
"\x02": backward_char, /* ^B - backward-char */
@ -813,9 +813,9 @@ import * as os from "os";
cursor_pos = cmd.length;
history_index = history.length;
readline_cb = cb;
prompt = pstate;
if (mexpr) {
prompt += dupstr(" ", plen - prompt.length);
prompt += ps2;
@ -902,7 +902,7 @@ import * as os from "os";
} else {
alert(); /* beep! */
}
cursor_pos = (cursor_pos < 0) ? 0 :
(cursor_pos > cmd.length) ? cmd.length : cursor_pos;
update();
@ -1000,13 +1000,13 @@ import * as os from "os";
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) {
@ -1080,7 +1080,7 @@ import * as os from "os";
}
print_rec(a);
}
function extract_directive(a) {
var pos;
if (a[0] !== '\\')
@ -1095,7 +1095,7 @@ import * as os from "os";
/* return true if the string after cmd can be evaluted as JS */
function handle_directive(cmd, expr) {
var param, prec1, expBits1;
if (cmd === "h" || cmd === "?" || cmd == "help") {
help();
} else if (cmd === "load") {
@ -1205,7 +1205,7 @@ import * as os from "os";
}
}
}
function help() {
function sel(n) {
return n ? "*": " ";
@ -1233,7 +1233,7 @@ import * as os from "os";
function eval_and_print(expr) {
var result;
try {
if (eval_mode === "math")
expr = '"use math"; void 0;' + expr;
@ -1286,7 +1286,7 @@ import * as os from "os";
function cmd_readline_start() {
readline_start(dupstr(" ", level), readline_handle_cmd);
}
function readline_handle_cmd(expr) {
handle_cmd(expr);
cmd_readline_start();
@ -1294,7 +1294,7 @@ import * as os from "os";
function handle_cmd(expr) {
var colorstate, cmd;
if (expr === null) {
expr = "";
return;
@ -1311,7 +1311,7 @@ import * as os from "os";
}
if (expr === "")
return;
if (mexpr)
expr = mexpr + '\n' + expr;
colorstate = colorize_js(expr);
@ -1322,7 +1322,7 @@ import * as os from "os";
return;
}
mexpr = "";
if (has_bignum) {
BigFloatEnv.setPrec(eval_and_print.bind(null, expr),
prec, expBits);
@ -1330,7 +1330,7 @@ import * as os from "os";
eval_and_print(expr);
}
level = 0;
/* run the garbage collector after each command */
std.gc();
}
@ -1567,7 +1567,7 @@ import * as os from "os";
}
termInit();
cmd_start();
})(globalThis);

View file

@ -325,7 +325,7 @@ void namelist_load(namelist_t *lp, const char *filename)
char *p = str_strip(buf);
if (*p == '#' || *p == ';' || *p == '\0')
continue; /* line comment */
namelist_add(lp, base_name, p);
}
free(base_name);
@ -467,11 +467,11 @@ static void *agent_start(void *arg)
JSContext *ctx;
JSValue ret_val;
int ret;
rt = JS_NewRuntime();
if (rt == NULL) {
fatal(1, "JS_NewRuntime failure");
}
}
ctx = JS_NewContext(rt);
if (ctx == NULL) {
JS_FreeRuntime(rt);
@ -480,7 +480,7 @@ static void *agent_start(void *arg)
JS_SetContextOpaque(ctx, agent);
JS_SetRuntimeInfo(rt, "agent");
JS_SetCanBlock(rt, TRUE);
add_helpers(ctx);
ret_val = JS_Eval(ctx, agent->script, strlen(agent->script),
"<evalScript>", JS_EVAL_TYPE_GLOBAL);
@ -489,7 +489,7 @@ static void *agent_start(void *arg)
if (JS_IsException(ret_val))
js_std_dump_error(ctx);
JS_FreeValue(ctx, ret_val);
for(;;) {
JSContext *ctx1;
ret = JS_ExecutePendingJob(JS_GetRuntime(ctx), &ctx1);
@ -501,12 +501,12 @@ static void *agent_start(void *arg)
break;
} else {
JSValue args[2];
pthread_mutex_lock(&agent_mutex);
while (!agent->broadcast_pending) {
pthread_cond_wait(&agent_cond, &agent_mutex);
}
agent->broadcast_pending = FALSE;
pthread_cond_signal(&agent_cond);
@ -543,7 +543,7 @@ static JSValue js_agent_start(JSContext *ctx, JSValue this_val,
if (JS_GetContextOpaque(ctx) != NULL)
return JS_ThrowTypeError(ctx, "cannot be called inside an agent");
script = JS_ToCString(ctx, argv[0]);
if (!script)
return JS_EXCEPTION;
@ -562,7 +562,7 @@ static void js_agent_free(JSContext *ctx)
{
struct list_head *el, *el1;
Test262Agent *agent;
list_for_each_safe(el, el1, &agent_list) {
agent = list_entry(el, Test262Agent, link);
pthread_join(agent->tid, NULL);
@ -571,7 +571,7 @@ static void js_agent_free(JSContext *ctx)
free(agent);
}
}
static JSValue js_agent_leaving(JSContext *ctx, JSValue this_val,
int argc, JSValue *argv)
{
@ -603,16 +603,16 @@ static JSValue js_agent_broadcast(JSContext *ctx, JSValue this_val,
uint8_t *buf;
size_t buf_size;
int32_t val;
if (JS_GetContextOpaque(ctx) != NULL)
return JS_ThrowTypeError(ctx, "cannot be called inside an agent");
buf = JS_GetArrayBuffer(ctx, &buf_size, sab);
if (!buf)
return JS_EXCEPTION;
if (JS_ToInt32(ctx, &val, argv[1]))
return JS_EXCEPTION;
/* broadcast the values and wait until all agents have started
calling their callbacks */
pthread_mutex_lock(&agent_mutex);
@ -700,7 +700,7 @@ static JSValue js_agent_report(JSContext *ctx, JSValue this_val,
rep = malloc(sizeof(*rep));
rep->str = strdup(str);
JS_FreeCString(ctx, str);
pthread_mutex_lock(&report_mutex);
list_add_tail(&rep->link, &report_list);
pthread_mutex_unlock(&report_mutex);
@ -720,7 +720,7 @@ static const JSCFunctionListEntry js_agent_funcs[] = {
JS_CFUNC_DEF("sleep", 1, js_agent_sleep ),
JS_CFUNC_DEF("monotonicNow", 0, js_agent_monotonicNow ),
};
static JSValue js_new_agent(JSContext *ctx)
{
JSValue agent;
@ -736,7 +736,7 @@ static JSValue js_createRealm(JSContext *ctx, JSValue this_val,
{
JSContext *ctx1;
JSValue ret;
ctx1 = JS_NewContext(JS_GetRuntime(ctx));
if (!ctx1)
return JS_ThrowOutOfMemory(ctx);
@ -756,7 +756,7 @@ static JSValue add_helpers1(JSContext *ctx)
{
JSValue global_obj;
JSValue obj262, obj;
global_obj = JS_GetGlobalObject(ctx);
JS_SetPropertyStr(ctx, global_obj, "print",
@ -787,7 +787,7 @@ static JSValue add_helpers1(JSContext *ctx)
JS_SetPropertyStr(ctx, obj262, "IsHTMLDDA", obj);
JS_SetPropertyStr(ctx, global_obj, "$262", JS_DupValue(ctx, obj262));
JS_FreeValue(ctx, global_obj);
return obj262;
}
@ -816,14 +816,14 @@ static JSModuleDef *js_module_loader_test(JSContext *ctx,
uint8_t *buf;
JSModuleDef *m;
JSValue func_val;
buf = js_load_file(ctx, &buf_len, module_name);
if (!buf) {
JS_ThrowReferenceError(ctx, "could not load module filename '%s'",
module_name);
return NULL;
}
/* compile the module */
func_val = JS_Eval(ctx, (char *)buf, buf_len, module_name,
JS_EVAL_TYPE_MODULE | JS_EVAL_FLAG_COMPILE_ONLY);
@ -933,14 +933,14 @@ void load_config(const char *filename)
}
/* base_name = get_basename(filename); */
base_name = strdup("");
while (fgets(buf, sizeof(buf), f) != NULL) {
char *p, *q;
lineno++;
p = str_strip(buf);
if (*p == '#' || *p == ';' || *p == '\0')
continue; /* line comment */
if (*p == "[]"[0]) {
/* new section */
p++;
@ -1006,7 +1006,7 @@ void load_config(const char *filename)
test_mode = TEST_STRICT;
else if (str_equal(q, "all") || str_equal(q, "both"))
test_mode = TEST_ALL;
else
else
fatal(2, "unknown test mode: %s", q);
continue;
}
@ -1147,7 +1147,7 @@ int longest_match(const char *str, const char *find, int pos, int *ppos, int lin
int len, maxlen;
maxlen = 0;
if (*find) {
const char *p;
for (p = str + pos; *p; p++) {
@ -1180,7 +1180,7 @@ static int eval_buf(JSContext *ctx, const char *buf, size_t buf_len,
int ret, error_line, pos, pos_line;
BOOL is_error, has_error_line;
const char *error_name;
pos = skip_comments(buf, 1, &pos_line);
error_line = pos_line;
has_error_line = FALSE;
@ -1224,7 +1224,7 @@ static int eval_buf(JSContext *ctx, const char *buf, size_t buf_len,
if (is_error) {
JSValue name, stack;
const char *stack_str;
name = JS_GetPropertyStr(ctx, exception_val, "name");
error_name = JS_ToCString(ctx, name);
stack = JS_GetPropertyStr(ctx, exception_val, "stack");
@ -1233,10 +1233,10 @@ static int eval_buf(JSContext *ctx, const char *buf, size_t buf_len,
if (stack_str) {
const char *p;
int len;
if (outfile)
fprintf(outfile, "%s", stack_str);
len = strlen(filename);
p = strstr(stack_str, filename);
if (p != NULL && p[len] == ':') {
@ -1254,7 +1254,7 @@ static int eval_buf(JSContext *ctx, const char *buf, size_t buf_len,
if (error_type) {
char *error_class;
const char *msg;
msg = JS_ToCString(ctx, exception_val);
error_class = strdup_len(msg, strcspn(msg, ":"));
if (!str_equal(error_class, error_type))
@ -1378,7 +1378,7 @@ char *extract_desc(const char *buf, char style)
const char *p, *desc_start;
char *desc;
int len;
p = buf;
while (*p != '\0') {
if (p[0] == '/' && p[1] == '*' && p[2] == style && p[3] != '/') {
@ -1510,11 +1510,11 @@ int run_test_buf(const char *filename, char *harness, namelist_t *ip,
JSRuntime *rt;
JSContext *ctx;
int i, ret;
rt = JS_NewRuntime();
if (rt == NULL) {
fatal(1, "JS_NewRuntime failure");
}
}
ctx = JS_NewContext(rt);
if (ctx == NULL) {
JS_FreeRuntime(rt);
@ -1523,10 +1523,10 @@ int run_test_buf(const char *filename, char *harness, namelist_t *ip,
JS_SetRuntimeInfo(rt, filename);
JS_SetCanBlock(rt, can_block);
/* loader for ES6 modules */
JS_SetModuleLoaderFunc(rt, NULL, js_module_loader_test, NULL);
add_helpers(ctx);
for (i = 0; i < ip->count; i++) {
@ -1539,7 +1539,7 @@ int run_test_buf(const char *filename, char *harness, namelist_t *ip,
ret = eval_buf(ctx, buf, buf_len, filename, TRUE, is_negative,
error_type, outfile, eval_flags, is_async);
ret = (ret != 0);
if (dump_memory) {
update_stats(rt, filename);
}
@ -1572,7 +1572,7 @@ int run_test(const char *filename, int index)
BOOL is_negative, is_nostrict, is_onlystrict, is_async, is_module, skip;
BOOL can_block;
namelist_t include_list = { 0 }, *ip = &include_list;
is_nostrict = is_onlystrict = is_negative = is_async = is_module = skip = FALSE;
can_block = TRUE;
error_type = NULL;
@ -1806,13 +1806,13 @@ int run_test262_harness_test(const char *filename, BOOL is_module)
int eval_flags, ret_code, ret;
JSValue res_val;
BOOL can_block;
outfile = stdout; /* for js_print */
rt = JS_NewRuntime();
if (rt == NULL) {
fatal(1, "JS_NewRuntime failure");
}
}
ctx = JS_NewContext(rt);
if (ctx == NULL) {
JS_FreeRuntime(rt);
@ -1822,10 +1822,10 @@ int run_test262_harness_test(const char *filename, BOOL is_module)
can_block = TRUE;
JS_SetCanBlock(rt, can_block);
/* loader for ES6 modules */
JS_SetModuleLoaderFunc(rt, NULL, js_module_loader_test, NULL);
add_helpers(ctx);
buf = load_file(filename, &buf_len);
@ -2005,14 +2005,14 @@ int main(int argc, char **argv)
break;
}
}
if (optind >= argc && !test_list.count)
help();
if (is_test262_harness) {
return run_test262_harness_test(argv[optind], is_module);
}
error_out = stdout;
if (error_filename) {
error_file = load_file(error_filename, NULL);

View file

@ -15,7 +15,7 @@ mode=default
# handle tests flagged as [async]: yes, no, skip
# for these, load 'harness/doneprintHandle.js' prior to test
# and expect `print('Test262:AsyncTestComplete')` to be called for
# and expect `print('Test262:AsyncTestComplete')` to be called for
# successful termination
async=yes

View file

@ -1,6 +1,6 @@
/*
* QuickJS: binary JSON module (test only)
*
*
* Copyright (c) 2017-2019 Fabrice Bellard
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@ -32,7 +32,7 @@ static JSValue js_bjson_read(JSContext *ctx, JSValueConst this_val,
JSValue obj;
size_t size;
int flags;
if (JS_ToIndex(ctx, &pos, argv[1]))
return JS_EXCEPTION;
if (JS_ToIndex(ctx, &len, argv[2]))
@ -56,7 +56,7 @@ static JSValue js_bjson_write(JSContext *ctx, JSValueConst this_val,
uint8_t *buf;
JSValue array;
int flags;
flags = 0;
if (JS_ToBool(ctx, argv[1]))
flags |= JS_WRITE_OBJ_REFERENCE;

View file

@ -60,7 +60,7 @@ function toPrec(n, prec) {
s = s.substring(0, i) + "." + s.substring(i);
return s;
}
var ref_data;
var log_data;
@ -995,7 +995,7 @@ function main(argc, argv, g)
];
var tests = [];
var i, j, n, f, name;
if (typeof BigInt == "function") {
/* BigInt test */
test_list.push(bigint64_arith);
@ -1005,7 +1005,7 @@ function main(argc, argv, g)
/* BigFloat test */
test_list.push(float256_arith);
}
for (i = 1; i < argc;) {
name = argv[i++];
if (name == "-a") {
@ -1055,7 +1055,7 @@ function main(argc, argv, g)
log_line("total", "", total[2], total[3], total_score * 100 / total_scale);
else
log_line("total", "", total[2]);
if (tests == test_list)
save_result("microbench-new.txt", log_data);
}

View file

@ -19,7 +19,7 @@ index 9c1217351e..3c24755558 100644
+ long: 100,
+ huge: 1000,
};
/**
diff --git a/harness/regExpUtils.js b/harness/regExpUtils.js
index be7039fda0..7b38abf8df 100644
@ -28,7 +28,7 @@ index be7039fda0..7b38abf8df 100644
@@ -6,24 +6,27 @@ description: |
defines: [buildString, testPropertyEscapes, matchValidator]
---*/
+if ($262 && typeof $262.codePointRange === "function") {
+ /* use C function to build the codePointRange (much faster with
+ slow JS engines) */
@ -67,5 +67,5 @@ index be7039fda0..7b38abf8df 100644
- return result;
+ return result;
}
function testPropertyEscapes(regex, string, expression) {

View file

@ -94,7 +94,7 @@ function test_bigint1()
r = 1n << 31n;
assert(r, 2147483648n, "1 << 31n === 2147483648n");
r = 1n << 32n;
assert(r, 4294967296n, "1 << 32n === 4294967296n");
}
@ -150,7 +150,7 @@ function test_bigint_ext()
function test_bigfloat()
{
var e, a, b, sqrt2;
assert(typeof 1n === "bigint");
assert(typeof 1l === "bigfloat");
assert(1 == 1.0l);
@ -164,7 +164,7 @@ function test_bigfloat()
test_less(2.1, 3l);
test_eq(Math.sqrt(9), 3l);
test_less(2n, 3l);
test_eq(3n, 3l);
@ -174,7 +174,7 @@ function test_bigfloat()
assert(a === BigFloat.parseFloat("0x1.6a09e667f3bcc908b2fb1366ea957d3e", 0, e));
assert(e.inexact === true);
assert(BigFloat.fpRound(a) == 0x1.6a09e667f3bcc908b2fb1366ea95l);
b = BigFloatEnv.setPrec(BigFloat.sqrt.bind(null, 2), 128);
assert(a === b);
@ -188,7 +188,7 @@ function test_bigfloat()
assert(BigFloat.exp(0.2l) === 1.2214027581601698339210719946396742l);
assert(BigFloat.log(3l) === 1.0986122886681096913952452369225256l);
assert(BigFloat.pow(2.1l, 1.6l) === 3.277561666451861947162828744873745l);
assert(BigFloat.sin(-1l) === -0.841470984807896506652502321630299l);
assert(BigFloat.cos(1l) === 0.5403023058681397174009366074429766l);
assert(BigFloat.tan(0.1l) === 0.10033467208545054505808004578111154l);
@ -241,16 +241,16 @@ function test_bigdecimal()
assert(1m !== 2m);
test_less(1m, 2m);
test_eq(2m, 2m);
test_less(1, 2m);
test_eq(2, 2m);
test_less(1.1, 2m);
test_eq(Math.sqrt(4), 2m);
test_less(2n, 3m);
test_eq(3n, 3m);
assert(BigDecimal("1234.1") === 1234.1m);
assert(BigDecimal(" 1234.1") === 1234.1m);
assert(BigDecimal(" 1234.1 ") === 1234.1m);
@ -272,7 +272,7 @@ function test_bigdecimal()
assert(1234.5m ** 3m === 1881365963.625m);
assertThrows(RangeError, () => { 2m ** 3.1m } );
assertThrows(RangeError, () => { 2m ** -3m } );
assert(BigDecimal.sqrt(2m,
{ roundingMode: "half-even",
maximumSignificantDigits: 4 }) === 1.414m);
@ -282,7 +282,7 @@ function test_bigdecimal()
assert(BigDecimal.sqrt(0.002m,
{ roundingMode: "half-even",
maximumFractionDigits: 3 }) === 0.045m);
assert(BigDecimal.round(3.14159m,
{ roundingMode: "half-even",
maximumFractionDigits: 3 }) === 3.142m);

View file

@ -34,7 +34,7 @@ function toHex(a)
function isArrayLike(a)
{
return Array.isArray(a) ||
return Array.isArray(a) ||
(a instanceof Uint8ClampedArray) ||
(a instanceof Uint8Array) ||
(a instanceof Uint16Array) ||
@ -147,7 +147,7 @@ function bjson_test_reference()
function bjson_test_all()
{
var obj;
bjson_test({x:1, y:2, if:3});
bjson_test([1, 2, 3]);
bjson_test([1.0, "aa", true, false, undefined, null, NaN, -Infinity, -0.0]);
@ -174,7 +174,7 @@ function bjson_test_all()
bjson_test(new Int32Array([123123, 222111, -32222]));
bjson_test(new Float64Array([123123, 222111.5]));
/* tested with a circular reference */
obj = {};
obj.x = obj;

View file

@ -57,7 +57,7 @@ function test_function()
}
var r, g;
r = my_func.call(null, 1, 2);
assert(r, 3, "call");
@ -70,10 +70,10 @@ function test_function()
assert_throws(TypeError, (function() {
Reflect.apply((function () { return 1; }), null, undefined);
}));
r = new Function("a", "b", "return a + b;");
assert(r(2,3), 5, "function");
g = f.bind(1, 2);
assert(g.length, 1);
assert(g.name, "bound f");
@ -103,7 +103,7 @@ function test()
assert(a.z, 4, "get");
a.z = 5;
assert(a.z_val, 5, "set");
a = { get z() { return 4; }, set z(val) { this.z_val = val; } };
assert(a.z, 4, "get");
a.z = 5;
@ -207,7 +207,7 @@ function test_string()
assert(a.charAt(1), "b");
assert(a.charAt(-1), "");
assert(a.charAt(3), "");
a = "abcd";
assert(a.substring(1, 3), "bc", "substring");
a = String.fromCharCode(0x20ac);
@ -216,7 +216,7 @@ function test_string()
assert(a, "\u20ac", "unicode");
assert(a, "\u{20ac}", "unicode");
assert("a", "\x61", "unicode");
a = "\u{10ffff}";
assert(a.length, 2, "unicode");
assert(a, "\u{dbff}\u{dfff}", "unicode");
@ -379,7 +379,7 @@ function test_eval()
assert(eval("if (0) 2; else 3;"), 3);
assert(f.call(1, "this"), 1);
a = 2;
assert(eval("a"), 2);
@ -424,7 +424,7 @@ function test_typed_array()
a[2] = 0.5;
a[3] = 1233.5;
assert(a.toString(), "0,2,0,255");
buffer = new ArrayBuffer(16);
assert(buffer.byteLength, 16);
a = new Uint32Array(buffer, 12, 1);
@ -436,7 +436,7 @@ function test_typed_array()
a = new Float32Array(buffer, 8, 1);
a[0] = 1;
a = new Uint8Array(buffer);
str = a.toString();
@ -525,7 +525,7 @@ function test_regexp()
a = /(\.(?!com|org)|\/)/.exec("ah.com");
assert(a, null);
a = /(?=(a+))/.exec("baaabac");
assert(a.index === 1 && a[0] === "" && a[1] === "aaa");
@ -592,7 +592,7 @@ function test_map()
}
i = 0;
a.forEach(function (v, o) {
a.forEach(function (v, o) {
assert(o, tab[i++][0]);
assert(a.has(o));
assert(a.delete(o));
@ -615,7 +615,7 @@ function test_weak_map()
a.set(o, v);
}
o = null;
n2 = n >> 1;
for(i = 0; i < n2; i++) {
a.delete(tab[i][0]);

View file

@ -54,7 +54,7 @@ function test_closure1()
function f2()
{
var val = 1;
function set(a) {
val = a;
}
@ -63,7 +63,7 @@ function test_closure1()
}
return { "set": set, "get": get };
}
var obj = f2();
obj.set(10);
var r;

View file

@ -68,10 +68,10 @@ function test_op1()
r = 1 << 31;
assert(r, -2147483648, "1 << 31 === -2147483648");
r = 1 << 32;
assert(r, 1, "1 << 32 === 1");
r = (1 << 31) < 0;
assert(r, true, "(1 << 31) < 0 === true");
@ -113,7 +113,7 @@ function test_cvt()
assert(("12345" | 0) === 12345);
assert(("0x12345" | 0) === 0x12345);
assert(((4294967296 * 3 - 4) | 0) === -4);
assert(("12345" >>> 0) === 12345);
assert(("0x12345" >>> 0) === 0x12345);
assert((NaN >>> 0) === 0);
@ -140,7 +140,7 @@ function test_eq()
function test_inc_dec()
{
var a, r;
a = 1;
r = a++;
assert(r === 1 && a === 2, true, "++");
@ -168,19 +168,19 @@ function test_inc_dec()
a = [true];
a[0]++;
assert(a[0], 2, "++");
a = {x:true};
r = a.x++;
assert(r === 1 && a.x === 2, true, "++");
a = {x:true};
r = a.x--;
assert(r === 1 && a.x === 0, true, "--");
a = [true];
r = a[0]++;
assert(r === 1 && a[0] === 2, true, "++");
a = [true];
r = a[0]--;
assert(r === 1 && a[0] === 0, true, "--");
@ -212,7 +212,7 @@ function test_op2()
assert((typeof Object), "function", "typeof");
assert((typeof null), "object", "typeof");
assert((typeof unknown_var), "undefined", "typeof");
a = {x: 1, if: 2, async: 3};
assert(a.if === 2);
assert(a.async === 3);
@ -225,7 +225,7 @@ function test_delete()
a = {x: 1, y: 1};
assert((delete a.x), true, "delete");
assert(("x" in a), false, "delete");
/* the following are not tested by test262 */
assert(delete "abc"[100], true);
@ -310,7 +310,7 @@ function test_class()
o = new C();
assert(o.f() === 1);
assert(o.x === 10);
assert(D.F() === -1);
assert(D.G() === -2);
assert(D.H() === -1);
@ -364,7 +364,7 @@ function test_regexp_skip()
var a, b;
[a, b = /abc\(/] = [1];
assert(a === 1);
[a, b =/abc\(/] = [2];
assert(a === 2);
}
@ -409,7 +409,7 @@ function test_argument_scope()
{
var f;
var c = "global";
f = function(a = eval("var arguments")) {};
assert_throws(SyntaxError, f);
@ -480,7 +480,7 @@ function test_function_expr_name()
/* non strict mode test : assignment to the function name silently
fails */
f = function myfunc() {
myfunc = 1;
return myfunc;
@ -501,7 +501,7 @@ function test_function_expr_name()
return myfunc;
};
assert(f(), f);
/* strict mode test : assignment to the function name raises a
TypeError exception */

View file

@ -333,7 +333,7 @@ function test_try_catch7()
function test_try_catch8()
{
var i, s;
s = "";
for(var i in {x:1, y:2}) {
try {

View file

@ -35,7 +35,7 @@ function test_operators_create() {
return "Vec2(" + this.x + "," + this.y + ")";
}
}
Vec2.prototype[Symbol.operatorSet] = Operators.create(
{
"+"(p1, p2) {
@ -172,7 +172,7 @@ function test_operators()
return "Vec2(" + this.x + "," + this.y + ")";
}
}
var a = new Vec2(1, 2);
var b = new Vec2(3, 4);
var r;

View file

@ -60,10 +60,10 @@ function test_integer()
r = 1 << 31;
assert(r, 2147483648, "1 << 31 === 2147483648");
r = 1 << 32;
assert(r, 4294967296, "1 << 32 === 4294967296");
r = (1 << 31) < 0;
assert(r, false, "(1 << 31) < 0 === false");
@ -115,7 +115,7 @@ function test_fraction()
function test_mod()
{
var a, b, p;
a = Mod(3, 101);
b = Mod(-1, 101);
assert((a + b) == Mod(2, 101));
@ -131,7 +131,7 @@ function test_polynomial()
var a, b, q, r, t, i;
a = (1 + X) ^ 4;
assert(a == X^4+4*X^3+6*X^2+4*X+1);
r = (1 + X);
q = (1+X+X^2);
b = (1 - X^2);

View file

@ -45,7 +45,7 @@ function test_file1()
f.seek(0, std.SEEK_SET);
str1 = f.readAsString();
assert(str1 === str);
f.seek(0, std.SEEK_END);
size = f.tell();
assert(size === str.length);
@ -80,7 +80,7 @@ function test_file2()
function test_getline()
{
var f, line, line_count, lines, i;
lines = ["hello world", "line 1", "line 2" ];
f = std.tmpfile();
for(i = 0; i < lines.length; i++) {
@ -102,7 +102,7 @@ function test_getline()
f.close();
}
function test_popen()
{
var str, f, fname = "tmp_file.txt";
@ -114,7 +114,7 @@ function test_popen()
/* test loadFile */
assert(std.loadFile(fname), content);
/* execute the 'cat' shell command */
f = std.popen("cat " + fname, "r");
str = f.readAsString();
@ -149,17 +149,17 @@ function test_os()
fname = "tmp_file.txt";
fpath = fdir + "/" + fname;
link_path = fdir + "/test_link";
os.remove(link_path);
os.remove(fpath);
os.remove(fdir);
err = os.mkdir(fdir, 0o755);
assert(err === 0);
fd = os.open(fpath, os.O_RDWR | os.O_CREAT | os.O_TRUNC);
assert(fd >= 0);
buf = new Uint8Array(10);
for(i = 0; i < buf.length; i++)
buf[i] = i;
@ -168,16 +168,16 @@ function test_os()
assert(os.seek(fd, 0, std.SEEK_SET) === 0);
buf2 = new Uint8Array(buf.length);
assert(os.read(fd, buf2.buffer, 0, buf2.length) === buf2.length);
for(i = 0; i < buf.length; i++)
assert(buf[i] == buf2[i]);
if (typeof BigInt !== "undefined") {
assert(os.seek(fd, BigInt(6), std.SEEK_SET), BigInt(6));
assert(os.read(fd, buf2.buffer, 0, 1) === 1);
assert(buf[6] == buf2[0]);
}
assert(os.close(fd) === 0);
[files, err] = os.readdir(fdir);
@ -188,7 +188,7 @@ function test_os()
err = os.utimes(fpath, fdate, fdate);
assert(err, 0);
[st, err] = os.stat(fpath);
assert(err, 0);
assert(st.mode & os.S_IFMT, os.S_IFREG);
@ -196,7 +196,7 @@ function test_os()
err = os.symlink(fname, link_path);
assert(err === 0);
[st, err] = os.lstat(link_path);
assert(err, 0);
assert(st.mode & os.S_IFMT, os.S_IFLNK);
@ -204,7 +204,7 @@ function test_os()
[buf, err] = os.readlink(link_path);
assert(err, 0);
assert(buf, fname);
assert(os.remove(link_path) === 0);
[buf, err] = os.getcwd();
@ -214,7 +214,7 @@ function test_os()
assert(err, 0);
assert(buf, buf2);
assert(os.remove(fpath) === 0);
fd = os.open(fpath, os.O_RDONLY);
@ -232,7 +232,7 @@ function test_os_exec()
ret = os.exec(["/bin/sh", "-c", "exit 1"], { usePath: false });
assert(ret, 1);
fds = os.pipe();
pid = os.exec(["sh", "-c", "echo $FOO"], {
stdout: fds[1],

View file

@ -21,10 +21,10 @@ function handle_msg(e) {
function worker_main() {
var i;
parent.onmessage = handle_msg;
for(i = 0; i < 10; i++) {
parent.postMessage({ type: "num", num: i });
parent.postMessage({ type: "num", num: i });
}
}

View file

@ -15,5 +15,5 @@ mkdir -p unicode
# g="${url}/${f}"
# wget $g -O unicode/$f
#done
wget $emoji_url -O unicode/emoji-data.txt

View file

@ -297,7 +297,7 @@ void parse_unicode_data(const char *filename)
const char *p;
int code, lc, uc, last_code;
CCInfo *ci, *tab = unicode_db;
f = fopen(filename, "rb");
if (!f) {
perror(filename);
@ -320,7 +320,7 @@ void parse_unicode_data(const char *filename)
code = strtoul(p, NULL, 16);
lc = 0;
uc = 0;
p = get_field(line, 12);
if (p && *p != ';') {
uc = strtoul(p, NULL, 16);
@ -356,7 +356,7 @@ void parse_unicode_data(const char *filename)
}
ci->general_category = i;
}
p = get_field(line, 3);
if (p && *p != ';' && *p != '\0') {
int cc;
@ -408,7 +408,7 @@ void parse_unicode_data(const char *filename)
if (p && *p == 'Y') {
set_prop(code, PROP_Bidi_Mirrored, 1);
}
/* handle ranges */
get_field_buf(buf1, sizeof(buf1), line, 1);
if (strstr(buf1, " Last>")) {
@ -422,7 +422,7 @@ void parse_unicode_data(const char *filename)
}
last_code = code;
}
fclose(f);
}
@ -433,7 +433,7 @@ void parse_special_casing(CCInfo *tab, const char *filename)
const char *p;
int code;
CCInfo *ci;
f = fopen(filename, "rb");
if (!f) {
perror(filename);
@ -464,8 +464,8 @@ void parse_special_casing(CCInfo *tab, const char *filename)
if (*p != '#' && *p != '\0')
continue;
}
p = get_field(line, 1);
if (p && *p != ';') {
ci->l_len = 0;
@ -498,7 +498,7 @@ void parse_special_casing(CCInfo *tab, const char *filename)
ci->u_len = 0;
}
}
fclose(f);
}
@ -509,7 +509,7 @@ void parse_case_folding(CCInfo *tab, const char *filename)
const char *p;
int code;
CCInfo *ci;
f = fopen(filename, "rb");
if (!f) {
perror(filename);
@ -540,14 +540,14 @@ void parse_case_folding(CCInfo *tab, const char *filename)
p++;
if (*p != 'C' && *p != 'S')
continue;
p = get_field(line, 2);
assert(p != 0);
assert(ci->f_code == 0);
ci->f_code = strtoul(p, NULL, 16);
assert(ci->f_code != 0 && ci->f_code != code);
}
fclose(f);
}
@ -556,7 +556,7 @@ void parse_composition_exclusions(const char *filename)
FILE *f;
char line[4096], *p;
uint32_t c0;
f = fopen(filename, "rb");
if (!f) {
perror(filename);
@ -584,7 +584,7 @@ void parse_derived_core_properties(const char *filename)
char line[4096], *p, buf[256], *q;
uint32_t c0, c1, c;
int i;
f = fopen(filename, "rb");
if (!f) {
perror(filename);
@ -640,7 +640,7 @@ void parse_derived_norm_properties(const char *filename)
FILE *f;
char line[4096], *p, buf[256], *q;
uint32_t c0, c1, c;
f = fopen(filename, "rb");
if (!f) {
perror(filename);
@ -690,7 +690,7 @@ void parse_prop_list(const char *filename)
char line[4096], *p, buf[256], *q;
uint32_t c0, c1, c;
int i;
f = fopen(filename, "rb");
if (!f) {
perror(filename);
@ -744,7 +744,7 @@ void parse_scripts(const char *filename)
char line[4096], *p, buf[256], *q;
uint32_t c0, c1, c;
int i;
f = fopen(filename, "rb");
if (!f) {
perror(filename);
@ -799,7 +799,7 @@ void parse_script_extensions(const char *filename)
int i;
uint8_t script_ext[255];
int script_ext_len;
f = fopen(filename, "rb");
if (!f) {
perror(filename);
@ -955,7 +955,7 @@ void find_run_type(TableEntry *te, CCInfo *tab, int code)
ci1 = &tab[code + 1];
ci2 = &tab[code + 2];
te->code = code;
if (ci->l_len == 1 && ci->l_data[0] == code + 2 &&
ci->f_code == ci->l_data[0] &&
ci->u_len == 0 &&
@ -1111,7 +1111,7 @@ void find_run_type(TableEntry *te, CCInfo *tab, int code)
te->data = 0;
return;
}
ci = &tab[code];
is_lower = ci->l_len > 0;
len = 1;
@ -1192,7 +1192,7 @@ void build_conv_table(CCInfo *tab)
int code, i, j;
CCInfo *ci;
TableEntry *te;
te = conv_table;
for(code = 0; code <= CHARCODE_MAX; code++) {
ci = &tab[code];
@ -1216,7 +1216,7 @@ void build_conv_table(CCInfo *tab)
for(i = 0; i < conv_table_len; i++) {
int data_index;
te = &conv_table[i];
switch(te->type) {
case RUN_TYPE_U:
case RUN_TYPE_L:
@ -1413,7 +1413,7 @@ void build_prop_table(FILE *f, int prop_index, BOOL add_index)
const uint32_t *buf;
int buf_len, block_end_pos, bit;
char cname[128];
dbuf_init(dbuf1);
for(i = 0; i <= CHARCODE_MAX;) {
@ -1429,15 +1429,15 @@ void build_prop_table(FILE *f, int prop_index, BOOL add_index)
dbuf_put_u32(dbuf1, n - 1);
i += n;
}
dbuf_init(dbuf);
dbuf_init(dbuf2);
buf = (uint32_t *)dbuf1->buf;
buf_len = dbuf1->size / sizeof(buf[0]);
/* the first value is assumed to be 0 */
assert(get_prop(0, prop_index) == 0);
block_end_pos = PROP_BLOCK_LEN;
i = 0;
code = 0;
@ -1498,7 +1498,7 @@ void build_prop_table(FILE *f, int prop_index, BOOL add_index)
snprintf(cname, sizeof(cname), "unicode_prop_%s_index", unicode_prop_name[prop_index]);
dump_byte_table(f, cname, dbuf2->buf, dbuf2->size);
}
dbuf_free(dbuf);
dbuf_free(dbuf1);
dbuf_free(dbuf2);
@ -1613,7 +1613,7 @@ void build_general_category_table(FILE *f)
printf(" %d", cw_len_count[i]);
printf(" ], length=%d bytes\n", (int)dbuf->size);
#endif
dump_byte_table(f, "unicode_gc_table", dbuf->buf, dbuf->size);
dbuf_free(dbuf);
@ -1683,7 +1683,7 @@ void build_script_table(FILE *f)
printf(" %d", cw_len_count[i]);
printf(" ], length=%d bytes\n", (int)dbuf->size);
#endif
dump_byte_table(f, "unicode_script_table", dbuf->buf, dbuf->size);
dbuf_free(dbuf);
@ -1733,7 +1733,7 @@ void build_script_ext_table(FILE *f)
cw_count);
printf(", length=%d bytes\n", (int)dbuf->size);
#endif
dump_byte_table(f, "unicode_script_ext_table", dbuf->buf, dbuf->size);
dbuf_free(dbuf);
@ -1745,7 +1745,7 @@ void build_script_ext_table(FILE *f)
void build_prop_list_table(FILE *f)
{
int i;
for(i = 0; i < PROP_TABLE_COUNT; i++) {
if (i == PROP_ID_Start ||
i == PROP_Case_Ignorable ||
@ -1755,7 +1755,7 @@ void build_prop_list_table(FILE *f)
build_prop_table(f, i, FALSE);
}
}
fprintf(f, "typedef enum {\n");
for(i = 0; i < PROP_COUNT; i++)
fprintf(f, " UNICODE_PROP_%s,\n", unicode_prop_name[i]);
@ -1793,7 +1793,7 @@ void check_case_conv(void)
int l, error;
CCInfo ci_s, *ci1, *ci = &ci_s;
int code;
for(code = 0; code <= CHARCODE_MAX; code++) {
ci1 = &tab[code];
*ci = *ci1;
@ -1907,7 +1907,7 @@ void build_cc_table(FILE *f)
DynBuf dbuf1_s, *dbuf1 = &dbuf1_s;
int cw_len_tab[3], cw_start, block_end_pos;
uint32_t v;
dbuf_init(dbuf);
dbuf_init(dbuf1);
cc_table_len = 0;
@ -1979,7 +1979,7 @@ void build_cc_table(FILE *f)
dbuf_putc(dbuf1, v);
dbuf_putc(dbuf1, v >> 8);
dbuf_putc(dbuf1, v >> 16);
dump_byte_table(f, "unicode_cc_table", dbuf->buf, dbuf->size);
dump_byte_table(f, "unicode_cc_index", dbuf1->buf, dbuf1->size);
@ -2084,7 +2084,7 @@ const int decomp_incr_tab[4][4] = {
/*
entry size:
type bits
code 18
code 18
len 7
compat 1
type 5
@ -2193,7 +2193,7 @@ void find_decomp_run(DecompEntry *tab_de, int i)
DecompEntry de_s, *de = &de_s;
CCInfo *ci, *ci1, *ci2;
int l, j, n, len_max;
ci = &unicode_db[i];
l = ci->decomp_len;
if (l == 0) {
@ -2204,12 +2204,12 @@ void find_decomp_run(DecompEntry *tab_de, int i)
/* the offset for the compose table has only 6 bits, so we must
limit if it can be used by the compose table */
if (!ci->is_compat && !ci->is_excluded && l == 2)
len_max = 64;
len_max = 64;
else
len_max = 127;
tab_de[i].cost = 0x7fffffff;
if (!is_16bit(ci->decomp_data, l)) {
assert(l <= 2);
@ -2252,7 +2252,7 @@ void find_decomp_run(DecompEntry *tab_de, int i)
if (de->cost < tab_de[i].cost) {
tab_de[i] = *de;
}
if (!((i + n) <= CHARCODE_MAX && n < len_max))
break;
ci1 = &unicode_db[i + n];
@ -2265,7 +2265,7 @@ void find_decomp_run(DecompEntry *tab_de, int i)
n++;
}
}
if (l <= 8 || l == 18) {
int c_min, c_max, c;
c_min = c_max = -1;
@ -2336,7 +2336,7 @@ void find_decomp_run(DecompEntry *tab_de, int i)
/* check if a single char is increasing */
if (l <= 4) {
int idx1, idx;
for(idx1 = 1; (idx = decomp_incr_tab[l - 1][idx1]) >= 0; idx1++) {
n = 1;
for(;;) {
@ -2420,7 +2420,7 @@ void find_decomp_run(DecompEntry *tab_de, int i)
if (l == 2) {
BOOL is_16bit;
n = 0;
is_16bit = FALSE;
for(;;) {
@ -2465,7 +2465,7 @@ void add_decomp_data(uint8_t *data_buf, int *pidx, DecompEntry *de)
{
int i, j, idx, c;
CCInfo *ci;
idx = *pidx;
de->data_index = idx;
if (de->type <= DECOMP_TYPE_C1) {
@ -2616,9 +2616,9 @@ void build_decompose_table(FILE *f)
int i, array_len, code_max, data_len, count;
DecompEntry *tab_de, de_s, *de = &de_s;
uint8_t *data_buf;
code_max = CHARCODE_MAX;
tab_de = mallocz((code_max + 2) * sizeof(*tab_de));
for(i = code_max; i >= 0; i--) {
@ -2642,7 +2642,7 @@ void build_decompose_table(FILE *f)
/* dump */
{
int size, size1;
printf("START LEN TYPE L C SIZE\n");
size = 0;
for(i = 0; i <= code_max; i++) {
@ -2656,7 +2656,7 @@ void build_decompose_table(FILE *f)
size += size1;
}
}
printf("array_len=%d estimated size=%d bytes actual=%d bytes\n",
array_len, size, array_len * 6 + data_len);
}
@ -2694,7 +2694,7 @@ void build_decompose_table(FILE *f)
}
}
fprintf(f, "\n};\n\n");
fprintf(f, "static const uint8_t unicode_decomp_data[%u] = {",
data_len);
for(i = 0; i < data_len; i++) {
@ -2707,7 +2707,7 @@ void build_decompose_table(FILE *f)
build_compose_table(f, tab_de);
free(data_buf);
free(tab_de);
}
@ -2738,7 +2738,7 @@ static int get_decomp_pos(const DecompEntry *tab_de, int c)
{
int i, v, k;
const DecompEntry *de;
k = 0;
for(i = 0; i <= CHARCODE_MAX; i++) {
de = &tab_de[i];
@ -2761,14 +2761,14 @@ void build_compose_table(FILE *f, const DecompEntry *tab_de)
{
int i, v, tab_ce_len;
ComposeEntry *ce, *tab_ce;
tab_ce = malloc(sizeof(*tab_ce) * COMPOSE_LEN_MAX);
tab_ce_len = 0;
for(i = 0; i <= CHARCODE_MAX; i++) {
CCInfo *ci = &unicode_db[i];
if (ci->decomp_len == 2 && !ci->is_compat &&
!ci->is_excluded) {
assert(tab_ce_len < COMPOSE_LEN_MAX);
assert(tab_ce_len < COMPOSE_LEN_MAX);
ce = &tab_ce[tab_ce_len++];
ce->c[0] = ci->decomp_data[0];
ce->c[1] = ci->decomp_data[1];
@ -2786,7 +2786,7 @@ void build_compose_table(FILE *f, const DecompEntry *tab_de)
}
}
#endif
fprintf(f, "static const uint16_t unicode_comp_table[%u] = {",
tab_ce_len);
for(i = 0; i < tab_ce_len; i++) {
@ -2801,7 +2801,7 @@ void build_compose_table(FILE *f, const DecompEntry *tab_de)
fprintf(f, " 0x%04x,", v);
}
fprintf(f, "\n};\n\n");
free(tab_ce);
}
@ -2850,7 +2850,7 @@ void check_compose_table(void)
}
}
}
}
@ -2890,7 +2890,7 @@ void check_cc_table(void)
#ifdef PROFILE
{
int64_t ti, count;
ti = get_time_ns();
count = 0;
/* only do it on meaningful chars */
@ -2913,7 +2913,7 @@ void normalization_test(const char *filename)
int *in_str, *nfc_str, *nfd_str, *nfkc_str, *nfkd_str;
int in_len, nfc_len, nfd_len, nfkc_len, nfkd_len;
int *buf, buf_len, pos;
f = fopen(filename, "rb");
if (!f) {
perror(filename);
@ -2944,7 +2944,7 @@ void normalization_test(const char *filename)
buf_len = unicode_normalize((uint32_t **)&buf, (uint32_t *)in_str, in_len, UNICODE_NFKD, NULL, NULL);
check_str("nfkd", pos, in_str, in_len, buf, buf_len, nfkd_str, nfkd_len);
free(buf);
buf_len = unicode_normalize((uint32_t **)&buf, (uint32_t *)in_str, in_len, UNICODE_NFC, NULL, NULL);
check_str("nfc", pos, in_str, in_len, buf, buf_len, nfc_str, nfc_len);
free(buf);
@ -2967,7 +2967,7 @@ int main(int argc, char **argv)
{
const char *unicode_db_path, *outfilename;
char filename[1024];
if (argc < 2) {
printf("usage: %s unicode_db_path [output_file]\n"
"\n"
@ -2988,13 +2988,13 @@ int main(int argc, char **argv)
snprintf(filename, sizeof(filename), "%s/SpecialCasing.txt", unicode_db_path);
parse_special_casing(unicode_db, filename);
snprintf(filename, sizeof(filename), "%s/CaseFolding.txt", unicode_db_path);
parse_case_folding(unicode_db, filename);
snprintf(filename, sizeof(filename), "%s/CompositionExclusions.txt", unicode_db_path);
parse_composition_exclusions(filename);
snprintf(filename, sizeof(filename), "%s/DerivedCoreProperties.txt", unicode_db_path);
parse_derived_core_properties(filename);
@ -3010,7 +3010,7 @@ int main(int argc, char **argv)
snprintf(filename, sizeof(filename), "%s/ScriptExtensions.txt",
unicode_db_path);
parse_script_extensions(filename);
snprintf(filename, sizeof(filename), "%s/emoji-data.txt",
unicode_db_path);
parse_prop_list(filename);
@ -3018,7 +3018,7 @@ int main(int argc, char **argv)
// dump_data(unicode_db);
build_conv_table(unicode_db);
// dump_table();
if (!outfilename) {
@ -3037,7 +3037,7 @@ int main(int argc, char **argv)
} else
{
FILE *fo = fopen(outfilename, "wb");
if (!fo) {
perror(outfilename);
exit(1);