aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2025-03-11 23:06:42 +0100
committerbptato <nincsnevem662@gmail.com>2025-03-11 23:10:01 +0100
commit9424b6910b3944731857d9b014ac37aec392b9d5 (patch)
tree4ffa88524ee14b996ed2a8ae8ddf534d2f01de45 /lib
parentbd0a5eed0d0c67d5f9e6b0cda4985f8a09b1cc73 (diff)
downloadchawan-9424b6910b3944731857d9b014ac37aec392b9d5.tar.gz
Update QuickJS-NG to 0.9.0
Diffstat (limited to 'lib')
-rw-r--r--lib/monoucha0/monoucha/qjs/LICENSE8
-rw-r--r--lib/monoucha0/monoucha/qjs/cutils.c17
-rw-r--r--lib/monoucha0/monoucha/qjs/cutils.h64
-rw-r--r--lib/monoucha0/monoucha/qjs/libbf.c124
-rw-r--r--lib/monoucha0/monoucha/qjs/libregexp.c122
-rw-r--r--lib/monoucha0/monoucha/qjs/libregexp.h11
-rw-r--r--lib/monoucha0/monoucha/qjs/libunicode.c36
-rw-r--r--lib/monoucha0/monoucha/qjs/libunicode.h21
-rw-r--r--lib/monoucha0/monoucha/qjs/quickjs-opcode.h6
-rw-r--r--lib/monoucha0/monoucha/qjs/quickjs.c6858
-rw-r--r--lib/monoucha0/monoucha/qjs/quickjs.h524
-rw-r--r--lib/monoucha0/monoucha/quickjs.nim10
12 files changed, 3906 insertions, 3895 deletions
diff --git a/lib/monoucha0/monoucha/qjs/LICENSE b/lib/monoucha0/monoucha/qjs/LICENSE
index 7d87e3ca..3c78b692 100644
--- a/lib/monoucha0/monoucha/qjs/LICENSE
+++ b/lib/monoucha0/monoucha/qjs/LICENSE
@@ -1,9 +1,9 @@
The MIT License (MIT)
-Copyright (c) 2017-2021 Fabrice Bellard
-Copyright (c) 2017-2021 Charlie Gordon
-Copyright (c) 2023 Ben Noordhuis
-Copyright (c) 2023 Saúl Ibarra Corretgé
+Copyright (c) 2017-2024 Fabrice Bellard
+Copyright (c) 2017-2024 Charlie Gordon
+Copyright (c) 2023-2025 Ben Noordhuis
+Copyright (c) 2023-2025 Saúl Ibarra Corretgé
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/lib/monoucha0/monoucha/qjs/cutils.c b/lib/monoucha0/monoucha/qjs/cutils.c
index 0a8ff459..a7b80502 100644
--- a/lib/monoucha0/monoucha/qjs/cutils.c
+++ b/lib/monoucha0/monoucha/qjs/cutils.c
@@ -125,7 +125,7 @@ int dbuf_realloc(DynBuf *s, size_t new_size)
new_size = size;
new_buf = s->realloc_func(s->opaque, s->buf, new_size);
if (!new_buf) {
- s->error = TRUE;
+ s->error = true;
return -1;
}
s->buf = new_buf;
@@ -180,8 +180,7 @@ int dbuf_putstr(DynBuf *s, const char *str)
return dbuf_put(s, (const uint8_t *)str, strlen(str));
}
-int __attribute__((format(printf, 2, 3))) dbuf_printf(DynBuf *s,
- const char *fmt, ...)
+int JS_PRINTF_FORMAT_ATTR(2, 3) dbuf_printf(DynBuf *s, JS_PRINTF_FORMAT const char *fmt, ...)
{
va_list ap;
char buf[128];
@@ -590,7 +589,13 @@ overflow:
*/
/* 2 <= base <= 36 */
-char const digits36[36] = "0123456789abcdefghijklmnopqrstuvwxyz";
+char const digits36[36] = {
+ '0','1','2','3','4','5','6','7','8','9',
+ 'a','b','c','d','e','f','g','h','i','j',
+ 'k','l','m','n','o','p','q','r','s','t',
+ 'u','v','w','x','y','z'
+};
+
#define USE_SPECIAL_RADIX_10 1 // special case base 10 radix conversions
#define USE_SINGLE_CASE_FAST 1 // special case single digit numbers
@@ -1203,12 +1208,12 @@ typedef struct {
js__once_cb callback;
} js__once_data_t;
-static BOOL WINAPI js__once_inner(INIT_ONCE *once, void *param, void **context) {
+static int WINAPI js__once_inner(INIT_ONCE *once, void *param, void **context) {
js__once_data_t *data = param;
data->callback();
- return TRUE;
+ return 1;
}
void js_once(js_once_t *guard, js__once_cb callback) {
diff --git a/lib/monoucha0/monoucha/qjs/cutils.h b/lib/monoucha0/monoucha/qjs/cutils.h
index 907bd559..c0537e68 100644
--- a/lib/monoucha0/monoucha/qjs/cutils.h
+++ b/lib/monoucha0/monoucha/qjs/cutils.h
@@ -25,6 +25,7 @@
#ifndef CUTILS_H
#define CUTILS_H
+#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
@@ -54,14 +55,6 @@ extern "C" {
#include <pthread.h>
#endif
-#if defined(__SANITIZE_ADDRESS__)
-# define __ASAN__ 1
-#elif defined(__has_feature)
-# if __has_feature(address_sanitizer)
-# define __ASAN__ 1
-# endif
-#endif
-
#if defined(_MSC_VER) && !defined(__clang__)
# define likely(x) (x)
# define unlikely(x) (x)
@@ -70,10 +63,6 @@ extern "C" {
# define __maybe_unused
# define __attribute__(x)
# define __attribute(x)
-# include <intrin.h>
-static void *__builtin_frame_address(unsigned int level) {
- return (void *)((char*)_AddressOfReturnAddress() - sizeof(int *) - level * sizeof(int *));
-}
#else
# define likely(x) __builtin_expect(!!(x), 1)
# define unlikely(x) __builtin_expect(!!(x), 0)
@@ -82,19 +71,6 @@ static void *__builtin_frame_address(unsigned int level) {
# define __maybe_unused __attribute__((unused))
#endif
-// https://stackoverflow.com/a/6849629
-#undef FORMAT_STRING
-#if _MSC_VER >= 1400
-# include <sal.h>
-# if _MSC_VER > 1400
-# define FORMAT_STRING(p) _Printf_format_string_ p
-# else
-# define FORMAT_STRING(p) __format_string p
-# endif /* FORMAT_STRING */
-#else
-# define FORMAT_STRING(p) p
-#endif /* _MSC_VER */
-
#if defined(_MSC_VER) && !defined(__clang__)
#include <math.h>
#define INF INFINITY
@@ -124,13 +100,22 @@ static void *__builtin_frame_address(unsigned int level) {
#define minimum_length(n) static n
#endif
-typedef int BOOL;
-
-#ifndef FALSE
-enum {
- FALSE = 0,
- TRUE = 1,
-};
+/* Borrowed from Folly */
+#ifndef JS_PRINTF_FORMAT
+#ifdef _MSC_VER
+#include <sal.h>
+#define JS_PRINTF_FORMAT _Printf_format_string_
+#define JS_PRINTF_FORMAT_ATTR(format_param, dots_param)
+#else
+#define JS_PRINTF_FORMAT
+#if !defined(__clang__) && defined(__GNUC__)
+#define JS_PRINTF_FORMAT_ATTR(format_param, dots_param) \
+ __attribute__((format(gnu_printf, format_param, dots_param)))
+#else
+#define JS_PRINTF_FORMAT_ATTR(format_param, dots_param) \
+ __attribute__((format(printf, format_param, dots_param)))
+#endif
+#endif
#endif
void js__pstrcpy(char *buf, int buf_size, const char *str);
@@ -440,7 +425,7 @@ typedef struct DynBuf {
uint8_t *buf;
size_t size;
size_t allocated_size;
- BOOL error; /* true if a memory allocation error occurred */
+ bool error; /* true if a memory allocation error occurred */
DynBufReallocFunc *realloc_func;
void *opaque; /* for realloc_func */
} DynBuf;
@@ -465,15 +450,14 @@ static inline int dbuf_put_u64(DynBuf *s, uint64_t val)
{
return dbuf_put(s, (uint8_t *)&val, 8);
}
-int __attribute__((format(printf, 2, 3))) dbuf_printf(DynBuf *s,
- FORMAT_STRING(const char *fmt), ...);
+int JS_PRINTF_FORMAT_ATTR(2, 3) dbuf_printf(DynBuf *s, JS_PRINTF_FORMAT const char *fmt, ...);
void dbuf_free(DynBuf *s);
-static inline BOOL dbuf_error(DynBuf *s) {
+static inline bool dbuf_error(DynBuf *s) {
return s->error;
}
static inline void dbuf_set_error(DynBuf *s)
{
- s->error = TRUE;
+ s->error = true;
}
/*---- UTF-8 and UTF-16 handling ----*/
@@ -497,17 +481,17 @@ size_t utf8_decode_buf16(uint16_t *dest, size_t dest_len, const char *src, size_
size_t utf8_encode_buf8(char *dest, size_t dest_len, const uint8_t *src, size_t src_len);
size_t utf8_encode_buf16(char *dest, size_t dest_len, const uint16_t *src, size_t src_len);
-static inline BOOL is_surrogate(uint32_t c)
+static inline bool is_surrogate(uint32_t c)
{
return (c >> 11) == (0xD800 >> 11); // 0xD800-0xDFFF
}
-static inline BOOL is_hi_surrogate(uint32_t c)
+static inline bool is_hi_surrogate(uint32_t c)
{
return (c >> 10) == (0xD800 >> 10); // 0xD800-0xDBFF
}
-static inline BOOL is_lo_surrogate(uint32_t c)
+static inline bool is_lo_surrogate(uint32_t c)
{
return (c >> 10) == (0xDC00 >> 10); // 0xDC00-0xDFFF
}
diff --git a/lib/monoucha0/monoucha/qjs/libbf.c b/lib/monoucha0/monoucha/qjs/libbf.c
index 6293f4ea..26872c6d 100644
--- a/lib/monoucha0/monoucha/qjs/libbf.c
+++ b/lib/monoucha0/monoucha/qjs/libbf.c
@@ -646,20 +646,20 @@ int bf_normalize_and_round(bf_t *r, limb_t prec1, bf_flags_t flags)
rounding */
int bf_can_round(const bf_t *a, slimb_t prec, bf_rnd_t rnd_mode, slimb_t k)
{
- BOOL is_rndn;
+ bool is_rndn;
slimb_t bit_pos, n;
limb_t bit;
if (a->expn == BF_EXP_INF || a->expn == BF_EXP_NAN)
- return FALSE;
+ return false;
if (rnd_mode == BF_RNDF) {
return (k >= (prec + 1));
}
if (a->expn == BF_EXP_ZERO)
- return FALSE;
+ return false;
is_rndn = (rnd_mode == BF_RNDN || rnd_mode == BF_RNDNA);
if (k < (prec + 2))
- return FALSE;
+ return false;
bit_pos = a->len * LIMB_BITS - 1 - prec;
n = k - prec;
/* bit pattern for RNDN or RNDNA: 0111.. or 1000...
@@ -672,11 +672,11 @@ int bf_can_round(const bf_t *a, slimb_t prec, bf_rnd_t rnd_mode, slimb_t k)
/* XXX: slow, but a few iterations on average */
while (n != 0) {
if (get_bit(a->tab, a->len, bit_pos) != bit)
- return TRUE;
+ return true;
bit_pos--;
n--;
}
- return FALSE;
+ return false;
}
/* Cannot fail with BF_ST_MEM_ERROR. */
@@ -955,20 +955,20 @@ static int bf_add_internal(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
i = r_len - tot_len;
while (i < 0) {
slimb_t ap, bp;
- BOOL inflag;
+ bool inflag;
ap = a_offset + i;
bp = b_bit_offset + i * LIMB_BITS;
- inflag = FALSE;
+ inflag = false;
if (ap >= 0 && ap < a->len) {
v1 = a->tab[ap];
- inflag = TRUE;
+ inflag = true;
} else {
v1 = 0;
}
if (bp + LIMB_BITS > 0 && bp < (slimb_t)(b->len * LIMB_BITS)) {
v2 = get_bits(b->tab, b->len, bp);
- inflag = TRUE;
+ inflag = true;
} else {
v2 = 0;
}
@@ -1758,7 +1758,7 @@ int bf_divrem(bf_t *q, bf_t *r, const bf_t *a, const bf_t *b,
bf_t a1_s, *a1 = &a1_s;
bf_t b1_s, *b1 = &b1_s;
int q_sign, ret;
- BOOL is_ceil, is_rndn;
+ bool is_ceil, is_rndn;
assert(q != a && q != b);
assert(r != a && r != b);
@@ -1785,7 +1785,7 @@ int bf_divrem(bf_t *q, bf_t *r, const bf_t *a, const bf_t *b,
case BF_RNDZ:
case BF_RNDN:
case BF_RNDNA:
- is_ceil = FALSE;
+ is_ceil = false;
break;
case BF_RNDD:
is_ceil = q_sign;
@@ -1794,7 +1794,7 @@ int bf_divrem(bf_t *q, bf_t *r, const bf_t *a, const bf_t *b,
is_ceil = q_sign ^ 1;
break;
case BF_RNDA:
- is_ceil = TRUE;
+ is_ceil = true;
break;
case BF_DIVREM_EUCLIDIAN:
is_ceil = a->sign;
@@ -2900,13 +2900,13 @@ static int strcasestart(const char *str, const char *val, const char **ptr)
static int bf_atof_internal(bf_t *r, slimb_t *pexponent,
const char *str, const char **pnext, int radix,
- limb_t prec, bf_flags_t flags, BOOL is_dec)
+ limb_t prec, bf_flags_t flags, bool is_dec)
{
const char *p, *p_start;
int is_neg, radix_bits, exp_is_neg, ret, digits_per_limb, shift;
limb_t cur_limb;
slimb_t pos, expn, int_len, digit_count;
- BOOL has_decpt, is_bin_exp;
+ bool has_decpt, is_bin_exp;
bf_t a_s, *a;
*pexponent = 0;
@@ -2991,14 +2991,14 @@ static int bf_atof_internal(bf_t *r, slimb_t *pexponent,
cur_limb = 0;
bf_resize(a, 1);
pos = 0;
- has_decpt = FALSE;
+ has_decpt = false;
int_len = digit_count = 0;
for(;;) {
limb_t c;
if (*p == '.' && (p > p_start || bf_to_digit(p[1]) < radix)) {
if (has_decpt)
break;
- has_decpt = TRUE;
+ has_decpt = true;
int_len = digit_count;
p++;
}
@@ -3067,7 +3067,7 @@ static int bf_atof_internal(bf_t *r, slimb_t *pexponent,
/* parse the exponent, if any */
expn = 0;
- is_bin_exp = FALSE;
+ is_bin_exp = false;
if (((radix == 10 && (*p == 'e' || *p == 'E')) ||
(radix != 10 && (*p == '@' ||
(radix_bits && (*p == 'p' || *p == 'P'))))) &&
@@ -3162,14 +3162,14 @@ int bf_atof2(bf_t *r, slimb_t *pexponent,
limb_t prec, bf_flags_t flags)
{
return bf_atof_internal(r, pexponent, str, pnext, radix, prec, flags,
- FALSE);
+ false);
}
int bf_atof(bf_t *r, const char *str, const char **pnext, int radix,
limb_t prec, bf_flags_t flags)
{
slimb_t dummy_exp;
- return bf_atof_internal(r, &dummy_exp, str, pnext, radix, prec, flags, FALSE);
+ return bf_atof_internal(r, &dummy_exp, str, pnext, radix, prec, flags, false);
}
/* base conversion to radix */
@@ -3340,7 +3340,7 @@ slimb_t bf_mul_log2_radix(slimb_t a1, unsigned int radix, int is_inv,
{
int is_neg;
limb_t a;
- BOOL is_ceil;
+ bool is_ceil;
is_ceil = is_ceil1;
a = a1;
@@ -3510,7 +3510,7 @@ static int bf_integer_to_radix(bf_t *r, const bf_t *a, limb_t radixl)
static int bf_convert_to_radix(bf_t *r, slimb_t *pE,
const bf_t *a, int radix,
limb_t P, bf_rnd_t rnd_mode,
- BOOL is_fixed_exponent)
+ bool is_fixed_exponent)
{
slimb_t E, e, prec, extra_bits, ziv_extra_bits, prec0;
bf_t B_s, *B = &B_s;
@@ -3526,7 +3526,7 @@ static int bf_convert_to_radix(bf_t *r, slimb_t *pE,
E = *pE;
} else {
/* compute the new exponent */
- E = 1 + bf_mul_log2_radix(a->expn - 1, radix, TRUE, FALSE);
+ E = 1 + bf_mul_log2_radix(a->expn - 1, radix, true, false);
}
// bf_print_str("a", a);
// printf("E=%ld P=%ld radix=%d\n", E, P, radix);
@@ -3539,7 +3539,7 @@ static int bf_convert_to_radix(bf_t *r, slimb_t *pE,
e_sign = 1;
}
/* Note: precision for log2(radix) is not critical here */
- prec0 = bf_mul_log2_radix(P, radix, FALSE, TRUE);
+ prec0 = bf_mul_log2_radix(P, radix, false, true);
ziv_extra_bits = 16;
for(;;) {
prec = prec0 + ziv_extra_bits;
@@ -3632,12 +3632,12 @@ static void limb_to_a2(char *buf, limb_t n, unsigned int radix_bits, int len)
}
}
-/* 'a' must be an integer if the is_dec = FALSE or if the radix is not
+/* 'a' must be an integer if the is_dec = false or if the radix is not
a power of two. A dot is added before the 'dot_pos' digit. dot_pos
= n_digits does not display the dot. 0 <= dot_pos <=
n_digits. n_digits >= 1. */
static void output_digits(DynBuf *s, const bf_t *a1, int radix, limb_t n_digits,
- limb_t dot_pos, BOOL is_dec)
+ limb_t dot_pos, bool is_dec)
{
limb_t i, v, l;
slimb_t pos, pos_incr;
@@ -3721,7 +3721,7 @@ static void *bf_dbuf_realloc(void *opaque, void *ptr, size_t size)
/* return the length in bytes. A trailing '\0' is added */
static char *bf_ftoa_internal(size_t *plen, const bf_t *a2, int radix,
- limb_t prec, bf_flags_t flags, BOOL is_dec)
+ limb_t prec, bf_flags_t flags, bool is_dec)
{
bf_context_t *ctx = a2->ctx;
DynBuf s_s, *s = &s_s;
@@ -3810,11 +3810,11 @@ static char *bf_ftoa_internal(size_t *plen, const bf_t *a2, int radix,
a->sign = 0;
/* one more digit for the rounding */
- n = 1 + bf_mul_log2_radix(bf_max(a->expn, 0), radix, TRUE, TRUE);
+ n = 1 + bf_mul_log2_radix(bf_max(a->expn, 0), radix, true, true);
n_digits = n + prec;
n1 = n;
if (bf_convert_to_radix(a1, &n1, a, radix, n_digits,
- flags & BF_RND_MASK, TRUE))
+ flags & BF_RND_MASK, true))
goto fail1;
start = s->size;
output_digits(s, a1, radix, n_digits, n, is_dec);
@@ -3897,7 +3897,7 @@ static char *bf_ftoa_internal(size_t *plen, const bf_t *a2, int radix,
slimb_t n_digits_max, n_digits_min;
assert(prec != BF_PREC_INF);
- n_digits = 1 + bf_mul_log2_radix(prec, radix, TRUE, TRUE);
+ n_digits = 1 + bf_mul_log2_radix(prec, radix, true, true);
/* max number of digits for non exponential
notation. The rational is to have the same rule
as JS i.e. n_max = 21 for 64 bit float in base 10. */
@@ -3914,7 +3914,7 @@ static char *bf_ftoa_internal(size_t *plen, const bf_t *a2, int radix,
while (n_digits_min < n_digits_max) {
n_digits = (n_digits_min + n_digits_max) / 2;
if (bf_convert_to_radix(a1, &n, a, radix, n_digits,
- flags & BF_RND_MASK, FALSE)) {
+ flags & BF_RND_MASK, false)) {
bf_delete(b);
goto fail1;
}
@@ -3938,7 +3938,7 @@ static char *bf_ftoa_internal(size_t *plen, const bf_t *a2, int radix,
}
}
if (bf_convert_to_radix(a1, &n, a, radix, n_digits,
- flags & BF_RND_MASK, FALSE)) {
+ flags & BF_RND_MASK, false)) {
fail1:
bf_delete(a1);
goto fail;
@@ -3962,22 +3962,20 @@ static char *bf_ftoa_internal(size_t *plen, const bf_t *a2, int radix,
n = 1;
if ((flags & BF_FTOA_FORCE_EXP) ||
n <= -6 || n > n_max) {
- const char *fmt;
/* exponential notation */
output_digits(s, a1, radix, n_digits, 1, is_dec);
if (radix_bits != 0 && radix <= 16) {
+ slimb_t exp_n = (n - 1) * radix_bits;
if (flags & BF_FTOA_JS_QUIRKS)
- fmt = "p%+" PRId_LIMB;
+ dbuf_printf(s, "p%+" PRId_LIMB, exp_n);
else
- fmt = "p%" PRId_LIMB;
- dbuf_printf(s, fmt, (n - 1) * radix_bits);
+ dbuf_printf(s, "p%" PRId_LIMB, exp_n);
} else {
+ const char c = radix <= 10 ? 'e' : '@';
if (flags & BF_FTOA_JS_QUIRKS)
- fmt = "%c%+" PRId_LIMB;
+ dbuf_printf(s, "%c%+" PRId_LIMB, c, n - 1);
else
- fmt = "%c%" PRId_LIMB;
- dbuf_printf(s, fmt,
- radix <= 10 ? 'e' : '@', n - 1);
+ dbuf_printf(s, "%c%" PRId_LIMB, c, n - 1);
}
} else if (n <= 0) {
/* 0.x */
@@ -4017,7 +4015,7 @@ static char *bf_ftoa_internal(size_t *plen, const bf_t *a2, int radix,
char *bf_ftoa(size_t *plen, const bf_t *a, int radix, limb_t prec,
bf_flags_t flags)
{
- return bf_ftoa_internal(plen, a, radix, prec, flags, FALSE);
+ return bf_ftoa_internal(plen, a, radix, prec, flags, false);
}
/***************************************************************/
@@ -4025,7 +4023,7 @@ char *bf_ftoa(size_t *plen, const bf_t *a, int radix, limb_t prec,
/* Note: the algorithm is from MPFR */
static void bf_const_log2_rec(bf_t *T, bf_t *P, bf_t *Q, limb_t n1,
- limb_t n2, BOOL need_P)
+ limb_t n2, bool need_P)
{
bf_context_t *s = T->ctx;
if ((n2 - n1) == 1) {
@@ -4045,7 +4043,7 @@ static void bf_const_log2_rec(bf_t *T, bf_t *P, bf_t *Q, limb_t n1,
bf_t Q1_s, *Q1 = &Q1_s;
m = n1 + ((n2 - n1) >> 1);
- bf_const_log2_rec(T, P, Q, n1, m, TRUE);
+ bf_const_log2_rec(T, P, Q, n1, m, true);
bf_init(s, T1);
bf_init(s, P1);
bf_init(s, Q1);
@@ -4073,7 +4071,7 @@ static void bf_const_log2_internal(bf_t *T, limb_t prec)
N = w / 3 + 1;
bf_init(T->ctx, P);
bf_init(T->ctx, Q);
- bf_const_log2_rec(T, P, Q, 0, N, FALSE);
+ bf_const_log2_rec(T, P, Q, 0, N, false);
bf_div(T, T, Q, prec, BF_RNDN);
bf_delete(P);
bf_delete(Q);
@@ -4635,10 +4633,10 @@ static int bf_pow_int(bf_t *r, const bf_t *x, limb_t prec, void *opaque)
return ret;
}
-/* x must be a finite non zero float. Return TRUE if there is a
+/* x must be a finite non zero float. Return true if there is a
floating point number r such as x=r^(2^n) and return this floating
- point number 'r'. Otherwise return FALSE and r is undefined. */
-static BOOL check_exact_power2n(bf_t *r, const bf_t *x, slimb_t n)
+ point number 'r'. Otherwise return false and r is undefined. */
+static bool check_exact_power2n(bf_t *r, const bf_t *x, slimb_t n)
{
bf_context_t *s = r->ctx;
bf_t T_s, *T = &T_s;
@@ -4650,17 +4648,17 @@ static BOOL check_exact_power2n(bf_t *r, const bf_t *x, slimb_t n)
/* fast check on the exponent */
if (n > (LIMB_BITS - 1)) {
if (e != 0)
- return FALSE;
+ return false;
er = 0;
} else {
if ((e & (((limb_t)1 << n) - 1)) != 0)
- return FALSE;
+ return false;
er = e >> n;
}
/* every perfect odd square = 1 modulo 8 */
v = get_bits(x->tab, x->len, x->len * LIMB_BITS - x->expn + e);
if ((v & 7) != 1)
- return FALSE;
+ return false;
bf_init(s, T);
bf_set(T, x);
@@ -4669,10 +4667,10 @@ static BOOL check_exact_power2n(bf_t *r, const bf_t *x, slimb_t n)
if (i != 0)
bf_set(T, r);
if (bf_sqrtrem(r, NULL, T) != 0)
- return FALSE;
+ return false;
}
r->expn += er;
- return TRUE;
+ return true;
}
/* prec = BF_PREC_INF is accepted for x and y integers and y >= 0 */
@@ -4681,7 +4679,7 @@ int bf_pow(bf_t *r, const bf_t *x, const bf_t *y, limb_t prec, bf_flags_t flags)
bf_context_t *s = r->ctx;
bf_t T_s, *T = &T_s;
bf_t ytmp_s;
- BOOL y_is_int, y_is_odd;
+ bool y_is_int, y_is_odd;
int r_sign, ret, rnd_mode;
slimb_t y_emin;
@@ -5072,7 +5070,7 @@ static int bf_atan_internal(bf_t *r, const bf_t *a, limb_t prec,
void *opaque)
{
bf_context_t *s = r->ctx;
- BOOL add_pi2 = (BOOL)(intptr_t)opaque;
+ bool add_pi2 = (bool)(intptr_t)opaque;
bf_t T_s, *T = &T_s;
bf_t U_s, *U = &U_s;
bf_t V_s, *V = &V_s;
@@ -5197,7 +5195,7 @@ int bf_atan(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)
}
}
- return bf_ziv_rounding(r, a, prec, flags, bf_atan_internal, (void *)FALSE);
+ return bf_ziv_rounding(r, a, prec, flags, bf_atan_internal, (void *)false);
}
static int bf_atan2_internal(bf_t *r, const bf_t *y, limb_t prec, void *opaque)
@@ -5247,7 +5245,7 @@ int bf_atan2(bf_t *r, const bf_t *y, const bf_t *x,
static int bf_asin_internal(bf_t *r, const bf_t *a, limb_t prec, void *opaque)
{
bf_context_t *s = r->ctx;
- BOOL is_acos = (BOOL)(intptr_t)opaque;
+ bool is_acos = (bool)(intptr_t)opaque;
bf_t T_s, *T = &T_s;
limb_t prec1, prec2;
@@ -5313,7 +5311,7 @@ int bf_asin(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)
}
}
- return bf_ziv_rounding(r, a, prec, flags, bf_asin_internal, (void *)FALSE);
+ return bf_ziv_rounding(r, a, prec, flags, bf_asin_internal, (void *)false);
}
int bf_acos(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)
@@ -5347,7 +5345,7 @@ int bf_acos(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)
return 0;
}
- return bf_ziv_rounding(r, a, prec, flags, bf_asin_internal, (void *)TRUE);
+ return bf_ziv_rounding(r, a, prec, flags, bf_asin_internal, (void *)true);
}
/***************************************************************/
@@ -6930,7 +6928,7 @@ int bfdec_divrem(bfdec_t *q, bfdec_t *r, const bfdec_t *a, const bfdec_t *b,
bfdec_t b1_s, *b1 = &b1_s;
bfdec_t r1_s, *r1 = &r1_s;
int q_sign, res;
- BOOL is_ceil, is_rndn;
+ bool is_ceil, is_rndn;
assert(q != a && q != b);
assert(r != a && r != b);
@@ -6957,7 +6955,7 @@ int bfdec_divrem(bfdec_t *q, bfdec_t *r, const bfdec_t *a, const bfdec_t *b,
case BF_RNDZ:
case BF_RNDN:
case BF_RNDNA:
- is_ceil = FALSE;
+ is_ceil = false;
break;
case BF_RNDD:
is_ceil = q_sign;
@@ -6966,7 +6964,7 @@ int bfdec_divrem(bfdec_t *q, bfdec_t *r, const bfdec_t *a, const bfdec_t *b,
is_ceil = q_sign ^ 1;
break;
case BF_RNDA:
- is_ceil = TRUE;
+ is_ceil = true;
break;
case BF_DIVREM_EUCLIDIAN:
is_ceil = a->sign;
@@ -7196,7 +7194,7 @@ int bfdec_pow_ui(bfdec_t *r, const bfdec_t *a, limb_t b)
char *bfdec_ftoa(size_t *plen, const bfdec_t *a, limb_t prec, bf_flags_t flags)
{
- return bf_ftoa_internal(plen, (const bf_t *)a, 10, prec, flags, TRUE);
+ return bf_ftoa_internal(plen, (const bf_t *)a, 10, prec, flags, true);
}
int bfdec_atof(bfdec_t *r, const char *str, const char **pnext,
@@ -7204,7 +7202,7 @@ int bfdec_atof(bfdec_t *r, const char *str, const char **pnext,
{
slimb_t dummy_exp;
return bf_atof_internal((bf_t *)r, &dummy_exp, str, pnext, 10, prec,
- flags, TRUE);
+ flags, true);
}
#endif /* USE_BF_DEC */
diff --git a/lib/monoucha0/monoucha/qjs/libregexp.c b/lib/monoucha0/monoucha/qjs/libregexp.c
index 603c2795..693acbbf 100644
--- a/lib/monoucha0/monoucha/qjs/libregexp.c
+++ b/lib/monoucha0/monoucha/qjs/libregexp.c
@@ -67,10 +67,10 @@ typedef struct {
const uint8_t *buf_end;
const uint8_t *buf_start;
int re_flags;
- BOOL is_unicode;
- BOOL unicode_sets;
- BOOL ignore_case;
- BOOL dotall;
+ bool is_unicode;
+ bool unicode_sets;
+ bool ignore_case;
+ bool dotall;
int capture_count;
int total_capture_count; /* -1 = not computed yet */
int has_named_captures; /* -1 = don't know, 0 = no, 1 = yes */
@@ -143,19 +143,19 @@ static const uint16_t char_range_s[] = {
0xFEFF, 0xFEFF + 1,
};
-BOOL lre_is_space(int c)
+bool lre_is_space(int c)
{
int i, n, low, high;
n = (countof(char_range_s) - 1) / 2;
for(i = 0; i < n; i++) {
low = char_range_s[2 * i + 1];
if (c < low)
- return FALSE;
+ return false;
high = char_range_s[2 * i + 2];
if (c < high)
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
uint32_t const lre_id_start_table_ascii[4] = {
@@ -196,7 +196,7 @@ static const uint16_t *char_range_table[] = {
static int cr_init_char_range(REParseState *s, CharRange *cr, uint32_t c)
{
- BOOL invert;
+ bool invert;
const uint16_t *c_pt;
int len, i;
@@ -374,7 +374,7 @@ static void re_emit_op_u16(REParseState *s, int op, uint32_t val)
dbuf_put_u16(&s->byte_code, val);
}
-static int __attribute__((format(printf, 2, 3))) re_parse_error(REParseState *s, const char *fmt, ...)
+static int JS_PRINTF_FORMAT_ATTR(2, 3) re_parse_error(REParseState *s, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
@@ -390,7 +390,7 @@ static int re_parse_out_of_memory(REParseState *s)
/* If allow_overflow is false, return -1 in case of
overflow. Otherwise return INT32_MAX. */
-static int parse_digits(const uint8_t **pp, BOOL allow_overflow)
+static int parse_digits(const uint8_t **pp, bool allow_overflow)
{
const uint8_t *p;
uint64_t v;
@@ -548,7 +548,7 @@ int lre_parse_escape(const uint8_t **pp, int allow_utf16)
}
/* XXX: we use the same chars for name and value */
-static BOOL is_unicode_char(int c)
+static bool is_unicode_char(int c)
{
return ((c >= '0' && c <= '9') ||
(c >= 'A' && c <= 'Z') ||
@@ -557,12 +557,12 @@ static BOOL is_unicode_char(int c)
}
static int parse_unicode_property(REParseState *s, CharRange *cr,
- const uint8_t **pp, BOOL is_inv)
+ const uint8_t **pp, bool is_inv)
{
const uint8_t *p;
char name[64], value[64];
char *q;
- BOOL script_ext;
+ bool script_ext;
int ret;
p = *pp;
@@ -592,10 +592,10 @@ static int parse_unicode_property(REParseState *s, CharRange *cr,
// printf("name=%s value=%s\n", name, value);
if (!strcmp(name, "Script") || !strcmp(name, "sc")) {
- script_ext = FALSE;
+ script_ext = false;
goto do_script;
} else if (!strcmp(name, "Script_Extensions") || !strcmp(name, "scx")) {
- script_ext = TRUE;
+ script_ext = true;
do_script:
cr_init(cr, s->opaque, lre_realloc);
ret = unicode_script(cr, value, script_ext);
@@ -654,7 +654,7 @@ static int parse_unicode_property(REParseState *s, CharRange *cr,
(CLASS_RANGE_BASE). In case of class range, 'cr' is
initialized. Otherwise, it is ignored. */
static int get_class_atom(REParseState *s, CharRange *cr,
- const uint8_t **pp, BOOL inclass)
+ const uint8_t **pp, bool inclass)
{
const uint8_t *p, *p_next;
uint32_t c;
@@ -813,7 +813,7 @@ static int re_parse_char_class(REParseState *s, const uint8_t **pp)
uint32_t c1, c2;
CharRange cr_s, *cr = &cr_s;
CharRange cr1_s, *cr1 = &cr1_s;
- BOOL invert;
+ bool invert;
cr_init(cr, s->opaque, lre_realloc);
p = *pp;
@@ -838,16 +838,16 @@ static int re_parse_char_class(REParseState *s, const uint8_t **pp)
} while (n < 4);
}
- invert = FALSE;
+ invert = false;
if (*p == '^') {
p++;
- invert = TRUE;
+ invert = true;
}
for(;;) {
if (*p == ']')
break;
- c1 = get_class_atom(s, cr1, &p, TRUE);
+ c1 = get_class_atom(s, cr1, &p, true);
if ((int)c1 < 0)
goto fail;
if (*p == '-' && p[1] == ']' && s->unicode_sets) {
@@ -865,7 +865,7 @@ static int re_parse_char_class(REParseState *s, const uint8_t **pp)
/* Annex B: match '-' character */
goto class_atom;
}
- c2 = get_class_atom(s, cr1, &p0, TRUE);
+ c2 = get_class_atom(s, cr1, &p0, true);
if ((int)c2 < 0)
goto fail;
if (c2 >= CLASS_RANGE_BASE) {
@@ -923,13 +923,13 @@ static int re_parse_char_class(REParseState *s, const uint8_t **pp)
- true if the opcodes may not advance the char pointer
- false if the opcodes always advance the char pointer
*/
-static BOOL re_need_check_advance(const uint8_t *bc_buf, int bc_buf_len)
+static bool re_need_check_advance(const uint8_t *bc_buf, int bc_buf_len)
{
int pos, opcode, len;
uint32_t val;
- BOOL ret;
+ bool ret;
- ret = TRUE;
+ ret = true;
pos = 0;
while (pos < bc_buf_len) {
@@ -950,7 +950,7 @@ static BOOL re_need_check_advance(const uint8_t *bc_buf, int bc_buf_len)
case REOP_dot:
case REOP_any:
simple_char:
- ret = FALSE;
+ ret = false;
break;
case REOP_line_start:
case REOP_line_end:
@@ -970,7 +970,7 @@ static BOOL re_need_check_advance(const uint8_t *bc_buf, int bc_buf_len)
break;
default:
/* safe behvior: we cannot predict the outcome */
- return TRUE;
+ return true;
}
pos += len;
}
@@ -1136,7 +1136,7 @@ static int re_count_captures(REParseState *s)
return s->total_capture_count;
}
-static BOOL re_has_named_captures(REParseState *s)
+static bool re_has_named_captures(REParseState *s)
{
if (s->has_named_captures < 0)
re_count_captures(s);
@@ -1164,13 +1164,13 @@ static int find_group_name(REParseState *s, const char *name)
return -1;
}
-static int re_parse_disjunction(REParseState *s, BOOL is_backward_dir);
+static int re_parse_disjunction(REParseState *s, bool is_backward_dir);
-static int re_parse_term(REParseState *s, BOOL is_backward_dir)
+static int re_parse_term(REParseState *s, bool is_backward_dir)
{
const uint8_t *p;
int c, last_atom_start, quant_min, quant_max, last_capture_count;
- BOOL greedy, add_zero_advance_check, is_neg, is_backward_lookahead;
+ bool greedy, add_zero_advance_check, is_neg, is_backward_lookahead;
CharRange cr_s, *cr = &cr_s;
last_atom_start = -1;
@@ -1206,11 +1206,11 @@ static int re_parse_term(REParseState *s, BOOL is_backward_dir)
} else {
const uint8_t *p1 = p + 1;
/* Annex B: error if it is like a repetition count */
- parse_digits(&p1, TRUE);
+ parse_digits(&p1, true);
if (*p1 == ',') {
p1++;
if (lre_is_digit(*p1)) {
- parse_digits(&p1, TRUE);
+ parse_digits(&p1, true);
}
}
if (*p1 != '}') {
@@ -1236,14 +1236,14 @@ static int re_parse_term(REParseState *s, BOOL is_backward_dir)
return -1;
} else if ((p[2] == '=' || p[2] == '!')) {
is_neg = (p[2] == '!');
- is_backward_lookahead = FALSE;
+ is_backward_lookahead = false;
p += 3;
goto lookahead;
} else if (p[2] == '<' &&
(p[3] == '=' || p[3] == '!')) {
int pos;
is_neg = (p[3] == '!');
- is_backward_lookahead = TRUE;
+ is_backward_lookahead = true;
p += 4;
/* lookahead */
lookahead:
@@ -1376,7 +1376,7 @@ static int re_parse_term(REParseState *s, BOOL is_backward_dir)
{
const uint8_t *q = ++p;
- c = parse_digits(&p, FALSE);
+ c = parse_digits(&p, false);
if (c < 0 || (c >= s->capture_count && c >= re_count_captures(s))) {
if (!s->is_unicode) {
/* Annex B.1.4: accept legacy octal */
@@ -1425,7 +1425,7 @@ static int re_parse_term(REParseState *s, BOOL is_backward_dir)
goto parse_class_atom;
default:
parse_class_atom:
- c = get_class_atom(s, cr, &p, FALSE);
+ c = get_class_atom(s, cr, &p, false);
if ((int)c < 0)
return -1;
normal_char:
@@ -1485,12 +1485,12 @@ static int re_parse_term(REParseState *s, BOOL is_backward_dir)
break;
}
p++;
- quant_min = parse_digits(&p, TRUE);
+ quant_min = parse_digits(&p, true);
quant_max = quant_min;
if (*p == ',') {
p++;
if (lre_is_digit(*p)) {
- quant_max = parse_digits(&p, TRUE);
+ quant_max = parse_digits(&p, true);
if (quant_max < quant_min) {
invalid_quant_count:
return re_parse_error(s, "invalid repetition count");
@@ -1508,10 +1508,10 @@ static int re_parse_term(REParseState *s, BOOL is_backward_dir)
return -1;
}
quantifier:
- greedy = TRUE;
+ greedy = true;
if (*p == '?') {
p++;
- greedy = FALSE;
+ greedy = false;
}
if (last_atom_start < 0) {
return re_parse_error(s, "nothing to repeat");
@@ -1571,7 +1571,7 @@ static int re_parse_term(REParseState *s, BOOL is_backward_dir)
if (quant_max == 0) {
s->byte_code.size = last_atom_start;
} else if (quant_max == 1 || quant_max == INT32_MAX) {
- BOOL has_goto = (quant_max == INT32_MAX);
+ bool has_goto = (quant_max == INT32_MAX);
if (dbuf_insert(&s->byte_code, last_atom_start, 5 + add_zero_advance_check))
goto out_of_memory;
s->byte_code.buf[last_atom_start] = REOP_split_goto_first +
@@ -1596,7 +1596,7 @@ static int re_parse_term(REParseState *s, BOOL is_backward_dir)
pos += 4;
if (add_zero_advance_check) {
s->byte_code.buf[pos++] = REOP_push_char_pos;
- re_emit_op(s, REOP_check_advance);
+ re_emit_op(s, REOP_check_advance);
}
re_emit_goto(s, REOP_loop, last_atom_start + 5);
re_emit_op(s, REOP_drop);
@@ -1658,7 +1658,7 @@ static int re_parse_term(REParseState *s, BOOL is_backward_dir)
return re_parse_out_of_memory(s);
}
-static int re_parse_alternative(REParseState *s, BOOL is_backward_dir)
+static int re_parse_alternative(REParseState *s, bool is_backward_dir)
{
const uint8_t *p;
int ret;
@@ -1692,7 +1692,7 @@ static int re_parse_alternative(REParseState *s, BOOL is_backward_dir)
return 0;
}
-static int re_parse_disjunction(REParseState *s, BOOL is_backward_dir)
+static int re_parse_disjunction(REParseState *s, bool is_backward_dir)
{
int start, len, pos;
@@ -1781,7 +1781,7 @@ uint8_t *lre_compile(int *plen, char *error_msg, int error_msg_size,
{
REParseState s_s, *s = &s_s;
int stack_size;
- BOOL is_sticky;
+ bool is_sticky;
memset(s, 0, sizeof(*s));
s->opaque = opaque;
@@ -1817,7 +1817,7 @@ uint8_t *lre_compile(int *plen, char *error_msg, int error_msg_size,
}
re_emit_op_u8(s, REOP_save_start, 0);
- if (re_parse_disjunction(s, FALSE)) {
+ if (re_parse_disjunction(s, false)) {
error:
dbuf_free(&s->byte_code);
dbuf_free(&s->group_names);
@@ -1868,12 +1868,12 @@ uint8_t *lre_compile(int *plen, char *error_msg, int error_msg_size,
return s->byte_code.buf;
}
-static BOOL is_line_terminator(uint32_t c)
+static bool is_line_terminator(uint32_t c)
{
return (c == '\n' || c == '\r' || c == CP_LS || c == CP_PS);
}
-static BOOL is_word_char(uint32_t c)
+static bool is_word_char(uint32_t c)
{
return ((c >= '0' && c <= '9') ||
(c >= 'a' && c <= 'z') ||
@@ -2009,9 +2009,9 @@ typedef struct {
int cbuf_type;
int capture_count;
int stack_size_max;
- BOOL multi_line;
- BOOL ignore_case;
- BOOL is_unicode;
+ bool multi_line;
+ bool ignore_case;
+ bool is_unicode;
void *opaque; /* used for stack overflow check */
size_t state_size;
@@ -2062,7 +2062,7 @@ static int push_state(REExecContext *s,
static intptr_t lre_exec_backtrack(REExecContext *s, uint8_t **capture,
StackInt *stack, int stack_len,
const uint8_t *pc, const uint8_t *cptr,
- BOOL no_recurse)
+ bool no_recurse)
{
int opcode, ret;
int cbuf_type;
@@ -2276,17 +2276,17 @@ static intptr_t lre_exec_backtrack(REExecContext *s, uint8_t **capture,
case REOP_word_boundary:
case REOP_not_word_boundary:
{
- BOOL v1, v2;
+ bool v1, v2;
/* char before */
if (cptr == s->cbuf) {
- v1 = FALSE;
+ v1 = false;
} else {
PEEK_PREV_CHAR(c, cptr, s->cbuf, cbuf_type);
v1 = is_word_char(c);
}
/* current char */
if (cptr >= cbuf_end) {
- v2 = FALSE;
+ v2 = false;
} else {
PEEK_CHAR(c, cptr, cbuf_end, cbuf_type);
v2 = is_word_char(c);
@@ -2439,7 +2439,7 @@ static intptr_t lre_exec_backtrack(REExecContext *s, uint8_t **capture,
q = 0;
for(;;) {
res = lre_exec_backtrack(s, capture, stack, stack_len,
- pc1, cptr, TRUE);
+ pc1, cptr, true);
if (res == -1)
return res;
if (!res)
@@ -2506,7 +2506,7 @@ int lre_exec(uint8_t **capture,
alloca_size = s->stack_size_max * sizeof(stack_buf[0]);
stack_buf = alloca(alloca_size);
ret = lre_exec_backtrack(s, capture, stack_buf, 0, bc_buf + RE_HEADER_LEN,
- cbuf + (cindex << cbuf_width), FALSE);
+ cbuf + (cindex << cbuf_width), false);
lre_realloc(s->opaque, s->state_stack, 0);
return ret;
}
@@ -2532,7 +2532,7 @@ const char *lre_get_groupnames(const uint8_t *bc_buf)
return (const char *)(bc_buf + RE_HEADER_LEN + re_bytecode_len);
}
-void lre_byte_swap(uint8_t *buf, size_t len, BOOL is_byte_swapped)
+void lre_byte_swap(uint8_t *buf, size_t len, bool is_byte_swapped)
{
uint8_t *p, *pe;
uint32_t n, r, nw;
@@ -2608,9 +2608,9 @@ void lre_byte_swap(uint8_t *buf, size_t len, BOOL is_byte_swapped)
#ifdef TEST
-BOOL lre_check_stack_overflow(void *opaque, size_t alloca_size)
+bool lre_check_stack_overflow(void *opaque, size_t alloca_size)
{
- return FALSE;
+ return false;
}
void *lre_realloc(void *opaque, void *ptr, size_t size)
diff --git a/lib/monoucha0/monoucha/qjs/libregexp.h b/lib/monoucha0/monoucha/qjs/libregexp.h
index c2e664a2..0b8fec52 100644
--- a/lib/monoucha0/monoucha/qjs/libregexp.h
+++ b/lib/monoucha0/monoucha/qjs/libregexp.h
@@ -24,6 +24,7 @@
#ifndef LIBREGEXP_H
#define LIBREGEXP_H
+#include <stdbool.h>
#include <stddef.h>
#include "libunicode.h"
@@ -32,8 +33,6 @@
extern "C" {
#endif
-#define LRE_BOOL int /* for documentation purposes */
-
#define LRE_FLAG_GLOBAL (1 << 0)
#define LRE_FLAG_IGNORECASE (1 << 1)
#define LRE_FLAG_MULTILINE (1 << 2)
@@ -55,12 +54,12 @@ int lre_exec(uint8_t **capture,
int cbuf_type, void *opaque);
int lre_parse_escape(const uint8_t **pp, int allow_utf16);
-LRE_BOOL lre_is_space(int c);
+bool lre_is_space(int c);
-void lre_byte_swap(uint8_t *buf, size_t len, LRE_BOOL is_byte_swapped);
+void lre_byte_swap(uint8_t *buf, size_t len, bool is_byte_swapped);
/* must be provided by the user */
-LRE_BOOL lre_check_stack_overflow(void *opaque, size_t alloca_size);
+bool lre_check_stack_overflow(void *opaque, size_t alloca_size);
void *lre_realloc(void *opaque, void *ptr, size_t size);
/* JS identifier test */
@@ -86,8 +85,6 @@ static inline int lre_js_is_ident_next(int c)
}
}
-#undef LRE_BOOL
-
#ifdef __cplusplus
} /* extern "C" { */
#endif
diff --git a/lib/monoucha0/monoucha/qjs/libunicode.c b/lib/monoucha0/monoucha/qjs/libunicode.c
index e68b0cad..a621c523 100644
--- a/lib/monoucha0/monoucha/qjs/libunicode.c
+++ b/lib/monoucha0/monoucha/qjs/libunicode.c
@@ -190,7 +190,7 @@ int lre_case_conv(uint32_t *res, uint32_t c, int conv_type)
return 1;
}
-static int lre_case_folding_entry(uint32_t c, uint32_t idx, uint32_t v, BOOL is_unicode)
+static int lre_case_folding_entry(uint32_t c, uint32_t idx, uint32_t v, bool is_unicode)
{
uint32_t res[LRE_CC_RES_LEN_MAX];
int len;
@@ -216,7 +216,7 @@ static int lre_case_folding_entry(uint32_t c, uint32_t idx, uint32_t v, BOOL is_
c = c - 'a' + 'A';
} else {
/* legacy regexp: to upper case if single char >= 128 */
- len = lre_case_conv_entry(res, c, FALSE, idx, v);
+ len = lre_case_conv_entry(res, c, false, idx, v);
if (len == 1 && res[0] >= 128)
c = res[0];
}
@@ -225,7 +225,7 @@ static int lre_case_folding_entry(uint32_t c, uint32_t idx, uint32_t v, BOOL is_
}
/* JS regexp specific rules for case folding */
-int lre_canonicalize(uint32_t c, BOOL is_unicode)
+int lre_canonicalize(uint32_t c, bool is_unicode)
{
if (c < 128) {
/* fast case */
@@ -241,7 +241,7 @@ int lre_canonicalize(uint32_t c, BOOL is_unicode)
} else {
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) {
@@ -302,7 +302,7 @@ static int get_index_pos(uint32_t *pcode, uint32_t c,
return (idx_min + 1) * UNICODE_INDEX_BLOCK_LEN + (v >> 21);
}
-static BOOL lre_is_in_table(uint32_t c, const uint8_t *table,
+static bool lre_is_in_table(uint32_t c, const uint8_t *table,
const uint8_t *index_table, int index_table_len)
{
uint32_t code, b, bit;
@@ -311,7 +311,7 @@ static BOOL lre_is_in_table(uint32_t c, const uint8_t *table,
pos = get_index_pos(&code, c, index_table, index_table_len);
if (pos < 0)
- return FALSE; /* outside the table */
+ return false; /* outside the table */
p = table + pos;
bit = 0;
for(;;) {
@@ -337,7 +337,7 @@ static BOOL lre_is_in_table(uint32_t c, const uint8_t *table,
}
}
-BOOL lre_is_cased(uint32_t c)
+bool lre_is_cased(uint32_t c)
{
uint32_t v, code, len;
int idx, idx_min, idx_max;
@@ -354,7 +354,7 @@ BOOL lre_is_cased(uint32_t c)
} else if (c >= code + len) {
idx_min = idx + 1;
} else {
- return TRUE;
+ return true;
}
}
return lre_is_in_table(c, unicode_prop_Cased1_table,
@@ -362,7 +362,7 @@ BOOL lre_is_cased(uint32_t c)
sizeof(unicode_prop_Cased1_index) / 3);
}
-BOOL lre_is_case_ignorable(uint32_t c)
+bool lre_is_case_ignorable(uint32_t c)
{
return lre_is_in_table(c, unicode_prop_Case_Ignorable_table,
unicode_prop_Case_Ignorable_index,
@@ -530,14 +530,14 @@ int cr_invert(CharRange *cr)
return 0;
}
-BOOL lre_is_id_start(uint32_t c)
+bool lre_is_id_start(uint32_t c)
{
return lre_is_in_table(c, unicode_prop_ID_Start_table,
unicode_prop_ID_Start_index,
sizeof(unicode_prop_ID_Start_index) / 3);
}
-BOOL lre_is_id_continue(uint32_t c)
+bool lre_is_id_continue(uint32_t c)
{
return lre_is_id_start(c) ||
lre_is_in_table(c, unicode_prop_ID_Continue1_table,
@@ -545,7 +545,7 @@ BOOL lre_is_id_continue(uint32_t c)
sizeof(unicode_prop_ID_Continue1_index) / 3);
}
-BOOL lre_is_white_space(uint32_t c)
+bool lre_is_white_space(uint32_t c)
{
return lre_is_in_table(c, unicode_prop_White_Space_table,
unicode_prop_White_Space_index,
@@ -759,7 +759,7 @@ static int unicode_decomp_entry(uint32_t *res, uint32_t c,
/* return the length of the decomposition (length <=
UNICODE_DECOMP_LEN_MAX) or 0 if no decomposition */
-static int unicode_decomp_char(uint32_t *res, uint32_t c, BOOL is_compat1)
+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;
@@ -953,7 +953,7 @@ int unicode_normalize(uint32_t **pdst, const uint32_t *src, int src_len,
void *opaque, DynBufReallocFunc *realloc_func)
{
int *buf, buf_len, i, p, starter_pos, cc, last_cc, out_len;
- BOOL is_compat;
+ bool is_compat;
DynBuf dbuf_s, *dbuf = &dbuf_s;
is_compat = n_type >> 1;
@@ -1053,14 +1053,14 @@ static int unicode_find_name(const char *name_table, const char *name)
/* 'cr' must be initialized and empty. Return 0 if OK, -1 if error, -2
if not found */
int unicode_script(CharRange *cr,
- const char *script_name, BOOL is_ext)
+ const char *script_name, bool is_ext)
{
int script_idx;
const uint8_t *p, *p_end;
uint32_t c, c1, b, n, v, v_len, i, type;
CharRange cr1_s = { 0 }, *cr1 = NULL;
CharRange cr2_s = { 0 }, *cr2 = &cr2_s;
- BOOL is_common;
+ bool is_common;
script_idx = unicode_find_name(unicode_script_name_table, script_name);
if (script_idx < 0)
@@ -1380,7 +1380,7 @@ static void cr_sort_and_remove_overlap(CharRange *cr)
/* canonicalize a character set using the JS regex case folding rules
(see lre_canonicalize()) */
-int cr_regexp_canonicalize(CharRange *cr, BOOL is_unicode)
+int cr_regexp_canonicalize(CharRange *cr, bool is_unicode)
{
CharRange cr_inter, cr_mask, cr_result, cr_sub;
uint32_t v, code, len, i, idx, start, end, c, d_start, d_end, d;
@@ -1542,11 +1542,13 @@ static int unicode_prop_ops(CharRange *cr, ...)
}
}
done:
+ va_end(ap);
assert(stack_len == 1);
ret = cr_copy(cr, &stack[0]);
cr_free(&stack[0]);
return ret;
fail:
+ va_end(ap);
for(i = 0; i < stack_len; i++)
cr_free(&stack[i]);
return -1;
diff --git a/lib/monoucha0/monoucha/qjs/libunicode.h b/lib/monoucha0/monoucha/qjs/libunicode.h
index 00400ffa..8e6f2a01 100644
--- a/lib/monoucha0/monoucha/qjs/libunicode.h
+++ b/lib/monoucha0/monoucha/qjs/libunicode.h
@@ -24,6 +24,7 @@
#ifndef LIBUNICODE_H
#define LIBUNICODE_H
+#include <stdbool.h>
#include <stddef.h>
#include <inttypes.h>
@@ -31,8 +32,6 @@
extern "C" {
#endif
-#define LRE_BOOL int /* for documentation purposes */
-
#define LRE_CC_RES_LEN_MAX 3
typedef enum {
@@ -43,9 +42,9 @@ typedef enum {
} UnicodeNormalizationEnum;
int lre_case_conv(uint32_t *res, uint32_t c, int conv_type);
-int lre_canonicalize(uint32_t c, LRE_BOOL is_unicode);
-LRE_BOOL lre_is_cased(uint32_t c);
-LRE_BOOL lre_is_case_ignorable(uint32_t c);
+int lre_canonicalize(uint32_t c, bool is_unicode);
+bool lre_is_cased(uint32_t c);
+bool lre_is_case_ignorable(uint32_t c);
/* char ranges */
@@ -103,11 +102,11 @@ int cr_op(CharRange *cr, const uint32_t *a_pt, int a_len,
const uint32_t *b_pt, int b_len, int op);
int cr_invert(CharRange *cr);
-int cr_regexp_canonicalize(CharRange *cr, LRE_BOOL is_unicode);
+int cr_regexp_canonicalize(CharRange *cr, bool is_unicode);
-LRE_BOOL lre_is_id_start(uint32_t c);
-LRE_BOOL lre_is_id_continue(uint32_t c);
-LRE_BOOL lre_is_white_space(uint32_t c);
+bool lre_is_id_start(uint32_t c);
+bool lre_is_id_continue(uint32_t c);
+bool lre_is_white_space(uint32_t c);
int unicode_normalize(uint32_t **pdst, const uint32_t *src, int src_len,
UnicodeNormalizationEnum n_type,
@@ -116,12 +115,10 @@ int unicode_normalize(uint32_t **pdst, const uint32_t *src, int src_len,
/* Unicode character range functions */
int unicode_script(CharRange *cr,
- const char *script_name, LRE_BOOL is_ext);
+ const char *script_name, bool is_ext);
int unicode_general_category(CharRange *cr, const char *gc_name);
int unicode_prop(CharRange *cr, const char *prop_name);
-#undef LRE_BOOL
-
#ifdef __cplusplus
} /* extern "C" { */
#endif
diff --git a/lib/monoucha0/monoucha/qjs/quickjs-opcode.h b/lib/monoucha0/monoucha/qjs/quickjs-opcode.h
index 09dacb3e..42c3faee 100644
--- a/lib/monoucha0/monoucha/qjs/quickjs-opcode.h
+++ b/lib/monoucha0/monoucha/qjs/quickjs-opcode.h
@@ -111,6 +111,7 @@ DEF( return, 1, 1, 0, none)
DEF( return_undef, 1, 0, 0, none)
DEF(check_ctor_return, 1, 1, 2, none)
DEF( check_ctor, 1, 0, 0, none)
+DEF( init_ctor, 1, 0, 1, none)
DEF( check_brand, 1, 2, 2, none) /* this_obj func -> this_obj func */
DEF( add_brand, 1, 2, 0, none) /* this_obj home_obj -> */
DEF( return_async, 1, 1, 0, none)
@@ -364,11 +365,6 @@ DEF( is_null, 1, 1, 1, none)
DEF(typeof_is_undefined, 1, 1, 1, none)
DEF( typeof_is_function, 1, 1, 1, none)
-// order matters, see non-IC counterparts
-DEF( get_field_ic, 5, 1, 1, none)
-DEF( get_field2_ic, 5, 1, 2, none)
-DEF( put_field_ic, 5, 2, 0, none)
-
#undef DEF
#undef def
#endif /* DEF */
diff --git a/lib/monoucha0/monoucha/qjs/quickjs.c b/lib/monoucha0/monoucha/qjs/quickjs.c
index e8a5f6fc..a7dcb2c2 100644
--- a/lib/monoucha0/monoucha/qjs/quickjs.c
+++ b/lib/monoucha0/monoucha/qjs/quickjs.c
@@ -1,10 +1,10 @@
/*
* QuickJS Javascript Engine
*
- * Copyright (c) 2017-2021 Fabrice Bellard
- * Copyright (c) 2017-2021 Charlie Gordon
- * Copyright (c) 2023 Ben Noordhuis
- * Copyright (c) 2023 Saúl Ibarra Corretgé
+ * Copyright (c) 2017-2024 Fabrice Bellard
+ * Copyright (c) 2017-2024 Charlie Gordon
+ * Copyright (c) 2023-2025 Ben Noordhuis
+ * Copyright (c) 2023-2025 Saúl Ibarra Corretgé
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -36,6 +36,9 @@
#include <timezoneapi.h>
#endif
#endif
+#if defined(_WIN32)
+#include <intrin.h>
+#endif
#include <time.h>
#include <fenv.h>
#include <math.h>
@@ -74,29 +77,8 @@
#define __extension__
#endif
-// Debug trace system: the debug output will be produced to the dump stream (currently
-// stdout) if qjs is invoked with -D<bitmask> with the corresponding bit set.
-
#ifndef NDEBUG
-#define DUMP_BYTECODE_FINAL 0x01 /* dump pass 3 final byte code */
-#define DUMP_BYTECODE_PASS2 0x02 /* dump pass 2 code */
-#define DUMP_BYTECODE_PASS1 0x04 /* dump pass 1 code */
-#define DUMP_BYTECODE_HEX 0x10 /* dump bytecode in hex */
-#define DUMP_BYTECODE_PC2LINE 0x20 /* dump line number table */
-#define DUMP_BYTECODE_STACK 0x40 /* dump compute_stack_size */
-#define DUMP_BYTECODE_STEP 0x80 /* dump executed bytecode */
-#define DUMP_READ_OBJECT 0x100 /* dump the marshalled objects at load time */
-#define DUMP_FREE 0x200 /* dump every object free */
-#define DUMP_GC 0x400 /* dump the occurrence of the automatic GC */
-#define DUMP_GC_FREE 0x800 /* dump objects freed by the GC */
-#define DUMP_MODULE_RESOLVE 0x1000 /* dump module resolution steps */
-#define DUMP_PROMISE 0x2000 /* dump promise steps */
-#define DUMP_LEAKS 0x4000 /* dump leaked objects and strings in JS_FreeRuntime */
-#define DUMP_ATOM_LEAKS 0x8000 /* dump leaked atoms in JS_FreeRuntime */
-#define DUMP_MEM 0x10000 /* dump memory usage in JS_FreeRuntime */
-#define DUMP_OBJECTS 0x20000 /* dump objects in JS_FreeRuntime */
-#define DUMP_ATOMS 0x40000 /* dump atoms in JS_FreeRuntime */
-#define DUMP_SHAPES 0x80000 /* dump shapes in JS_FreeRuntime */
+#define ENABLE_DUMPS
#endif
//#define FORCE_GC_AT_MALLOC /* test the GC by forcing it before each object allocation */
@@ -116,6 +98,29 @@ const char* JS_GetVersion(void) {
#undef STRINFIGY_
#undef STRINGIFY
+static inline JSValueConst *vc(JSValue *vals)
+{
+ return (JSValueConst *)vals;
+}
+
+static inline JSValue unsafe_unconst(JSValueConst v)
+{
+#ifdef JS_CHECK_JSVALUE
+ return (JSValue)v;
+#else
+ return v;
+#endif
+}
+
+static inline JSValueConst safe_const(JSValue v)
+{
+#ifdef JS_CHECK_JSVALUE
+ return (JSValueConst)v;
+#else
+ return v;
+#endif
+}
+
enum {
/* classid tag */ /* union usage | properties */
JS_CLASS_OBJECT = 1, /* must be first */
@@ -260,7 +265,7 @@ struct JSRuntime {
struct list_head tmp_hook_obj_list;
JSGCPhaseEnum gc_phase : 8;
size_t malloc_gc_threshold;
-#ifdef DUMP_LEAKS
+#ifdef ENABLE_DUMPS // JS_DUMP_LEAKS
struct list_head string_list; /* list of JSString.link */
#endif
/* stack limitation */
@@ -270,11 +275,11 @@ struct JSRuntime {
JSValue current_exception;
/* true if inside an out of memory error, to avoid recursing */
- BOOL in_out_of_memory : 8;
- /* and likewise if inside Error.prepareStackTrace() */
- BOOL in_prepare_stack_trace : 8;
+ bool in_out_of_memory;
+ /* true if inside build_backtrace, to avoid recursing */
+ bool in_build_stack_trace;
/* true if inside JS_FreeRuntime */
- BOOL in_free : 8;
+ bool in_free;
struct JSStackFrame *current_stack_frame;
@@ -295,7 +300,7 @@ struct JSRuntime {
/* used to allocate, free and clone SharedArrayBuffers */
JSSharedArrayBufferFunctions sab_funcs;
- BOOL can_block : 8; /* TRUE if Atomics.wait can block */
+ bool can_block; /* true if Atomics.wait can block */
uint32_t dump_flags : 24;
/* Shape hash table */
@@ -419,8 +424,9 @@ struct JSContext {
JSValue promise_ctor;
JSValue native_error_proto[JS_NATIVE_ERROR_COUNT];
JSValue error_ctor;
+ JSValue error_back_trace;
JSValue error_prepare_stack;
- int error_stack_trace_limit;
+ JSValue error_stack_trace_limit;
JSValue iterator_ctor;
JSValue iterator_proto;
JSValue async_iterator_proto;
@@ -441,12 +447,12 @@ struct JSContext {
struct list_head loaded_modules; /* list of JSModuleDef.link */
/* if NULL, RegExp compilation is not supported */
- JSValue (*compile_regexp)(JSContext *ctx, JSValue pattern,
- JSValue flags);
+ JSValue (*compile_regexp)(JSContext *ctx, JSValueConst pattern,
+ JSValueConst flags);
/* if NULL, eval is not supported */
- JSValue (*eval_internal)(JSContext *ctx, JSValue this_obj,
+ JSValue (*eval_internal)(JSContext *ctx, JSValueConst this_obj,
const char *input, size_t input_len,
- const char *filename, int flags, int scope_idx);
+ const char *filename, int line, int flags, int scope_idx);
void *user_opaque;
};
@@ -503,15 +509,21 @@ struct JSString {
uint8_t atom_type : 2; /* != 0 if atom, JS_ATOM_TYPE_x */
uint32_t hash_next; /* atom_index for JS_ATOM_TYPE_SYMBOL */
JSWeakRefRecord *first_weak_ref;
-#ifdef DUMP_LEAKS
+#ifdef ENABLE_DUMPS // JS_DUMP_LEAKS
struct list_head link; /* string list */
#endif
- union {
- __extension__ uint8_t str8[0]; /* 8 bit strings will get an extra null terminator */
- __extension__ uint16_t str16[0];
- } u;
};
+static inline uint8_t *str8(JSString *p)
+{
+ return (void *)(p + 1);
+}
+
+static inline uint16_t *str16(JSString *p)
+{
+ return (void *)(p + 1);
+}
+
typedef struct JSClosureVar {
uint8_t is_local : 1;
uint8_t is_arg : 1;
@@ -519,7 +531,7 @@ typedef struct JSClosureVar {
uint8_t is_lexical : 1;
uint8_t var_kind : 4; /* see JSVarKindEnum */
/* 8 bits available */
- uint16_t var_idx; /* is_local = TRUE: index to a normal variable of the
+ uint16_t var_idx; /* is_local = true: index to a normal variable of the
parent function. otherwise: index to a closure
variable of the parent function */
JSAtom var_name;
@@ -591,79 +603,6 @@ typedef enum JSFunctionKindEnum {
JS_FUNC_ASYNC_GENERATOR = (JS_FUNC_GENERATOR | JS_FUNC_ASYNC),
} JSFunctionKindEnum;
-#define IC_CACHE_ITEM_CAPACITY 4
-
-typedef struct JSInlineCacheRingSlot {
- /* SoA for space optimization: 56 bytes */
- JSShape* shape[IC_CACHE_ITEM_CAPACITY];
- uint32_t prop_offset[IC_CACHE_ITEM_CAPACITY];
- JSAtom atom;
- uint8_t index;
-} JSInlineCacheRingSlot;
-
-typedef struct JSInlineCacheHashSlot {
- JSAtom atom;
- uint32_t index;
- struct JSInlineCacheHashSlot *next;
-} JSInlineCacheHashSlot;
-
-typedef struct JSInlineCache {
- uint32_t count;
- uint32_t capacity;
- uint32_t hash_bits;
- JSInlineCacheHashSlot **hash;
- JSInlineCacheRingSlot *cache;
-} JSInlineCache;
-
-#define INLINE_CACHE_MISS ((uint32_t)-1) // sentinel
-
-// This is a struct so we don't tie up two argument registers in calls to
-// JS_GetPropertyInternal2 and JS_SetPropertyInternal2 in the common case
-// where there is no IC and therefore no offset to update.
-typedef struct JSInlineCacheUpdate {
- JSInlineCache *ic;
- uint32_t offset;
-} JSInlineCacheUpdate;
-
-static JSInlineCache *init_ic(JSContext *ctx);
-static int rebuild_ic(JSContext *ctx, JSInlineCache *ic);
-static int resize_ic_hash(JSContext *ctx, JSInlineCache *ic);
-static int free_ic(JSRuntime *rt, JSInlineCache *ic);
-static void add_ic_slot(JSContext *ctx, JSInlineCacheUpdate *icu,
- JSAtom atom, JSObject *object, uint32_t prop_offset);
-
-static uint32_t get_ic_prop_offset(const JSInlineCacheUpdate *icu,
- JSShape *shape)
-{
- uint32_t i, cache_offset = icu->offset;
- JSInlineCache *ic = icu->ic;
- JSInlineCacheRingSlot *cr;
- JSShape *shape_slot;
- assert(cache_offset < ic->capacity);
- cr = ic->cache + cache_offset;
- i = cr->index;
- for (;;) {
- shape_slot = *(cr->shape + i);
- if (likely(shape_slot == shape)) {
- cr->index = i;
- return cr->prop_offset[i];
- }
-
- i = (i + 1) % countof(cr->shape);
- if (unlikely(i == cr->index)) {
- break;
- }
- }
-
- return INLINE_CACHE_MISS;
-}
-
-static force_inline JSAtom get_ic_atom(JSInlineCache *ic, uint32_t cache_offset)
-{
- assert(cache_offset < ic->capacity);
- return ic->cache[cache_offset].atom;
-}
-
typedef struct JSFunctionBytecode {
JSGCObjectHeader header; /* must come first */
uint8_t is_strict_mode : 1;
@@ -692,7 +631,6 @@ typedef struct JSFunctionBytecode {
JSValue *cpool; /* constant pool (self pointer) */
int cpool_count;
int closure_var_count;
- JSInlineCache *ic;
JSAtom filename;
int line_num;
int col_num;
@@ -729,7 +667,7 @@ typedef enum JSIteratorHelperKindEnum {
typedef struct JSForInIterator {
JSValue obj;
- BOOL is_array;
+ bool is_array;
uint32_t array_length;
uint32_t idx;
} JSForInIterator;
@@ -763,13 +701,13 @@ typedef struct JSTypedArray {
JSObject *buffer; /* based array buffer */
uint32_t offset; /* byte offset in the array buffer */
uint32_t length; /* byte length in the array buffer */
- BOOL track_rab; /* auto-track length of backing array buffer */
+ bool track_rab; /* auto-track length of backing array buffer */
} JSTypedArray;
typedef struct JSAsyncFunctionState {
JSValue this_val; /* 'this' generator argument */
int argc; /* number of function arguments */
- BOOL throw_flag; /* used to throw an exception in JS_CallInternal() */
+ bool throw_flag; /* used to throw an exception in JS_CallInternal() */
JSStackFrame frame;
} JSAsyncFunctionState;
@@ -778,7 +716,7 @@ typedef struct JSAsyncFunctionState {
typedef struct JSAsyncFunctionData {
JSGCObjectHeader header; /* must come first */
JSValue resolving_funcs[2];
- BOOL is_active; /* true if the async function state is valid */
+ bool is_active; /* true if the async function state is valid */
JSAsyncFunctionState func_state;
} JSAsyncFunctionData;
@@ -849,9 +787,9 @@ struct JSModuleDef {
JSValue module_ns;
JSValue func_obj; /* only used for JS modules */
JSModuleInitFunc *init_func; /* only used for C modules */
- BOOL has_tla : 8; /* true if func_obj contains await */
- BOOL resolved : 8;
- BOOL func_created : 8;
+ bool has_tla; /* true if func_obj contains await */
+ bool resolved;
+ bool func_created;
JSModuleStatus status : 8;
/* temp use during js_module_link() & js_module_evaluate() */
int dfs_index, dfs_ancestor_index;
@@ -861,14 +799,14 @@ struct JSModuleDef {
int async_parent_modules_count;
int async_parent_modules_size;
int pending_async_dependencies;
- BOOL async_evaluation;
+ bool async_evaluation;
int64_t async_evaluation_timestamp;
JSModuleDef *cycle_root;
JSValue promise; /* corresponds to spec field: capability */
JSValue resolving_funcs[2]; /* corresponds to spec field: capability */
/* true if evaluation yielded an exception. It is saved in
eval_exception */
- BOOL eval_has_exception : 8;
+ bool eval_has_exception;
JSValue eval_exception;
JSValue meta_obj; /* for import.meta */
};
@@ -939,10 +877,10 @@ struct JSObject {
uint8_t extensible : 1;
uint8_t free_mark : 1; /* only used when freeing objects with cycles */
- uint8_t is_exotic : 1; /* TRUE if object has exotic property handlers */
- uint8_t fast_array : 1; /* TRUE if u.array is used for get/put (for JS_CLASS_ARRAY, JS_CLASS_ARGUMENTS and typed arrays) */
- uint8_t is_constructor : 1; /* TRUE if object is a constructor function */
- uint8_t is_uncatchable_error : 1; /* if TRUE, error is not catchable */
+ uint8_t is_exotic : 1; /* true if object has exotic property handlers */
+ uint8_t fast_array : 1; /* true if u.array is used for get/put (for JS_CLASS_ARRAY, JS_CLASS_ARGUMENTS and typed arrays) */
+ uint8_t is_constructor : 1; /* true if object is a constructor function */
+ uint8_t is_uncatchable_error : 1; /* if true, error is not catchable */
uint8_t tmp_mark : 1; /* used in JS_WriteObjectRec() */
uint8_t is_HTMLDDA : 1; /* specific annex B IsHtmlDDA behavior */
uint16_t class_id; /* see JS_CLASS_x */
@@ -1020,7 +958,7 @@ typedef struct JSCallSiteData {
JSValue filename;
JSValue func;
JSValue func_name;
- BOOL native;
+ bool native;
int line_num;
int col_num;
} JSCallSiteData;
@@ -1076,91 +1014,92 @@ static JSAtom __JS_NewAtomInit(JSRuntime *rt, const char *str, int len,
int atom_type);
static void JS_FreeAtomStruct(JSRuntime *rt, JSAtomStruct *p);
static void free_function_bytecode(JSRuntime *rt, JSFunctionBytecode *b);
-static JSValue js_call_c_function(JSContext *ctx, JSValue func_obj,
- JSValue this_obj,
- int argc, JSValue *argv, int flags);
-static JSValue js_call_bound_function(JSContext *ctx, JSValue func_obj,
- JSValue this_obj,
- int argc, JSValue *argv, int flags);
-static JSValue JS_CallInternal(JSContext *ctx, JSValue func_obj,
- JSValue this_obj, JSValue new_target,
- int argc, JSValue *argv, int flags);
+static JSValue js_call_c_function(JSContext *ctx, JSValueConst func_obj,
+ JSValueConst this_obj,
+ int argc, JSValueConst *argv, int flags);
+static JSValue js_call_bound_function(JSContext *ctx, JSValueConst func_obj,
+ JSValueConst this_obj,
+ int argc, JSValueConst *argv, int flags);
+static JSValue JS_CallInternal(JSContext *ctx, JSValueConst func_obj,
+ JSValueConst this_obj, JSValueConst new_target,
+ int argc, JSValueConst *argv, int flags);
static JSValue JS_CallConstructorInternal(JSContext *ctx,
- JSValue func_obj,
- JSValue new_target,
- int argc, JSValue *argv, int flags);
-static JSValue JS_CallFree(JSContext *ctx, JSValue func_obj, JSValue this_obj,
- int argc, JSValue *argv);
+ JSValueConst func_obj,
+ JSValueConst new_target,
+ int argc, JSValueConst *argv, int flags);
+static JSValue JS_CallFree(JSContext *ctx, JSValue func_obj, JSValueConst this_obj,
+ int argc, JSValueConst *argv);
static JSValue JS_InvokeFree(JSContext *ctx, JSValue this_val, JSAtom atom,
- int argc, JSValue *argv);
+ int argc, JSValueConst *argv);
static __exception int JS_ToArrayLengthFree(JSContext *ctx, uint32_t *plen,
- JSValue val, BOOL is_array_ctor);
-static JSValue JS_EvalObject(JSContext *ctx, JSValue this_obj,
- JSValue val, int flags, int scope_idx);
-JSValue __attribute__((format(printf, 2, 3))) JS_ThrowInternalError(JSContext *ctx, const char *fmt, ...);
+ JSValue val, bool is_array_ctor);
+static JSValue JS_EvalObject(JSContext *ctx, JSValueConst this_obj,
+ JSValueConst val, int flags, int scope_idx);
+JSValue JS_PRINTF_FORMAT_ATTR(2, 3) JS_ThrowInternalError(JSContext *ctx, JS_PRINTF_FORMAT const char *fmt, ...);
-static __maybe_unused void JS_DumpString(JSRuntime *rt, const JSString *p);
+static __maybe_unused void JS_DumpString(JSRuntime *rt, JSString *p);
static __maybe_unused void JS_DumpObjectHeader(JSRuntime *rt);
static __maybe_unused void JS_DumpObject(JSRuntime *rt, JSObject *p);
static __maybe_unused void JS_DumpGCObject(JSRuntime *rt, JSGCObjectHeader *p);
-static __maybe_unused void JS_DumpValue(JSRuntime *rt, JSValue val);
+static __maybe_unused void JS_DumpValue(JSRuntime *rt, JSValueConst val);
static __maybe_unused void JS_DumpAtoms(JSRuntime *rt);
static __maybe_unused void JS_DumpShapes(JSRuntime *rt);
-static JSValue js_function_apply(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic);
-static void js_array_finalizer(JSRuntime *rt, JSValue val);
-static void js_array_mark(JSRuntime *rt, JSValue val,
+static JSValue js_function_apply(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic);
+static void js_array_finalizer(JSRuntime *rt, JSValueConst val);
+static void js_array_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func);
-static void js_object_data_finalizer(JSRuntime *rt, JSValue val);
-static void js_object_data_mark(JSRuntime *rt, JSValue val,
+static void js_object_data_finalizer(JSRuntime *rt, JSValueConst val);
+static void js_object_data_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func);
-static void js_c_function_finalizer(JSRuntime *rt, JSValue val);
-static void js_c_function_mark(JSRuntime *rt, JSValue val,
+static void js_c_function_finalizer(JSRuntime *rt, JSValueConst val);
+static void js_c_function_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func);
-static void js_bytecode_function_finalizer(JSRuntime *rt, JSValue val);
-static void js_bytecode_function_mark(JSRuntime *rt, JSValue val,
+static void js_bytecode_function_finalizer(JSRuntime *rt, JSValueConst val);
+static void js_bytecode_function_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func);
-static void js_bound_function_finalizer(JSRuntime *rt, JSValue val);
-static void js_bound_function_mark(JSRuntime *rt, JSValue val,
+static void js_bound_function_finalizer(JSRuntime *rt, JSValueConst val);
+static void js_bound_function_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func);
-static void js_for_in_iterator_finalizer(JSRuntime *rt, JSValue val);
-static void js_for_in_iterator_mark(JSRuntime *rt, JSValue val,
+static void js_for_in_iterator_finalizer(JSRuntime *rt, JSValueConst val);
+static void js_for_in_iterator_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func);
-static void js_regexp_finalizer(JSRuntime *rt, JSValue val);
-static void js_array_buffer_finalizer(JSRuntime *rt, JSValue val);
-static void js_typed_array_finalizer(JSRuntime *rt, JSValue val);
-static void js_typed_array_mark(JSRuntime *rt, JSValue val,
+static void js_regexp_finalizer(JSRuntime *rt, JSValueConst val);
+static void js_array_buffer_finalizer(JSRuntime *rt, JSValueConst val);
+static void js_typed_array_finalizer(JSRuntime *rt, JSValueConst val);
+static void js_typed_array_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func);
-static void js_proxy_finalizer(JSRuntime *rt, JSValue val);
-static void js_proxy_mark(JSRuntime *rt, JSValue val,
+static void js_proxy_finalizer(JSRuntime *rt, JSValueConst val);
+static void js_proxy_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func);
-static void js_map_finalizer(JSRuntime *rt, JSValue val);
-static void js_map_mark(JSRuntime *rt, JSValue val,
+static void js_map_finalizer(JSRuntime *rt, JSValueConst val);
+static void js_map_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func);
-static void js_map_iterator_finalizer(JSRuntime *rt, JSValue val);
-static void js_map_iterator_mark(JSRuntime *rt, JSValue val,
+static void js_map_iterator_finalizer(JSRuntime *rt, JSValueConst val);
+static void js_map_iterator_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func);
-static void js_array_iterator_finalizer(JSRuntime *rt, JSValue val);
-static void js_array_iterator_mark(JSRuntime *rt, JSValue val,
+static void js_array_iterator_finalizer(JSRuntime *rt, JSValueConst val);
+static void js_array_iterator_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func);
-static void js_iterator_helper_finalizer(JSRuntime *rt, JSValue val);
-static void js_iterator_helper_mark(JSRuntime *rt, JSValue val,
+static void js_iterator_helper_finalizer(JSRuntime *rt, JSValueConst val);
+static void js_iterator_helper_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func);
-static void js_iterator_wrap_finalizer(JSRuntime *rt, JSValue val);
-static void js_iterator_wrap_mark(JSRuntime *rt, JSValue val,
+static void js_iterator_wrap_finalizer(JSRuntime *rt, JSValueConst val);
+static void js_iterator_wrap_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func);
-static void js_regexp_string_iterator_finalizer(JSRuntime *rt, JSValue val);
-static void js_regexp_string_iterator_mark(JSRuntime *rt, JSValue val,
+static void js_regexp_string_iterator_finalizer(JSRuntime *rt,
+ JSValueConst val);
+static void js_regexp_string_iterator_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func);
-static void js_generator_finalizer(JSRuntime *rt, JSValue obj);
-static void js_generator_mark(JSRuntime *rt, JSValue val,
+static void js_generator_finalizer(JSRuntime *rt, JSValueConst val);
+static void js_generator_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func);
-static void js_promise_finalizer(JSRuntime *rt, JSValue val);
-static void js_promise_mark(JSRuntime *rt, JSValue val,
+static void js_promise_finalizer(JSRuntime *rt, JSValueConst val);
+static void js_promise_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func);
-static void js_promise_resolve_function_finalizer(JSRuntime *rt, JSValue val);
-static void js_promise_resolve_function_mark(JSRuntime *rt, JSValue val,
+static void js_promise_resolve_function_finalizer(JSRuntime *rt, JSValueConst val);
+static void js_promise_resolve_function_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func);
#define HINT_STRING 0
@@ -1174,9 +1113,9 @@ static int JS_ToInt32Free(JSContext *ctx, int32_t *pres, JSValue val);
static int JS_ToFloat64Free(JSContext *ctx, double *pres, JSValue val);
static int JS_ToUint8ClampFree(JSContext *ctx, int32_t *pres, JSValue val);
static JSValue js_new_string8_len(JSContext *ctx, const char *buf, int len);
-static JSValue js_compile_regexp(JSContext *ctx, JSValue pattern,
- JSValue flags);
-static JSValue js_regexp_constructor_internal(JSContext *ctx, JSValue ctor,
+static JSValue js_compile_regexp(JSContext *ctx, JSValueConst pattern,
+ JSValueConst flags);
+static JSValue js_regexp_constructor_internal(JSContext *ctx, JSValueConst ctor,
JSValue pattern, JSValue bc);
static void gc_decref(JSRuntime *rt);
static int JS_NewClass1(JSRuntime *rt, JSClassID class_id,
@@ -1190,17 +1129,16 @@ typedef enum JSStrictEqModeEnum {
JS_EQ_SAME_VALUE_ZERO,
} JSStrictEqModeEnum;
-static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2,
+static bool js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2,
JSStrictEqModeEnum eq_mode);
-static BOOL js_strict_eq(JSContext *ctx, JSValue op1, JSValue op2);
-static BOOL js_same_value(JSContext *ctx, JSValue op1, JSValue op2);
-static BOOL js_same_value_zero(JSContext *ctx, JSValue op1, JSValue op2);
-static JSValue JS_ToObject(JSContext *ctx, JSValue val);
+static bool js_strict_eq(JSContext *ctx, JSValue op1, JSValue op2);
+static bool js_same_value(JSContext *ctx, JSValueConst op1, JSValueConst op2);
+static bool js_same_value_zero(JSContext *ctx, JSValueConst op1, JSValueConst op2);
static JSValue JS_ToObjectFree(JSContext *ctx, JSValue val);
static JSProperty *add_property(JSContext *ctx,
JSObject *p, JSAtom prop, int prop_flags);
static JSValue JS_NewBigInt(JSContext *ctx);
-static inline bf_t *JS_GetBigInt(JSValue val)
+static inline bf_t *JS_GetBigInt(JSValueConst val)
{
JSBigInt *p = JS_VALUE_GET_PTR(val);
return &p->num;
@@ -1208,83 +1146,85 @@ static inline bf_t *JS_GetBigInt(JSValue val)
static JSValue JS_CompactBigInt1(JSContext *ctx, JSValue val);
static JSValue JS_CompactBigInt(JSContext *ctx, JSValue val);
static int JS_ToBigInt64Free(JSContext *ctx, int64_t *pres, JSValue val);
-static bf_t *JS_ToBigInt(JSContext *ctx, bf_t *buf, JSValue val);
-static bf_t *JS_ToBigInt1(JSContext *ctx, bf_t *buf, JSValue val);
+static bf_t *JS_ToBigInt(JSContext *ctx, bf_t *buf, JSValueConst val);
+static bf_t *JS_ToBigInt1(JSContext *ctx, bf_t *buf, JSValueConst val);
static void JS_FreeBigInt(JSContext *ctx, bf_t *a, bf_t *buf);
JSValue JS_ThrowOutOfMemory(JSContext *ctx);
static JSValue JS_ThrowTypeErrorRevokedProxy(JSContext *ctx);
-static JSValue js_proxy_getPrototypeOf(JSContext *ctx, JSValue obj);
-static int js_proxy_setPrototypeOf(JSContext *ctx, JSValue obj,
- JSValue proto_val, BOOL throw_flag);
-static int js_proxy_isExtensible(JSContext *ctx, JSValue obj);
-static int js_proxy_preventExtensions(JSContext *ctx, JSValue obj);
-static int js_proxy_isArray(JSContext *ctx, JSValue obj);
+static JSValue js_proxy_getPrototypeOf(JSContext *ctx, JSValueConst obj);
+static int js_proxy_setPrototypeOf(JSContext *ctx, JSValueConst obj,
+ JSValueConst proto_val, bool throw_flag);
+static int js_proxy_isExtensible(JSContext *ctx, JSValueConst obj);
+static int js_proxy_preventExtensions(JSContext *ctx, JSValueConst obj);
+static int js_proxy_isArray(JSContext *ctx, JSValueConst obj);
static int JS_CreateProperty(JSContext *ctx, JSObject *p,
- JSAtom prop, JSValue val,
- JSValue getter, JSValue setter,
+ JSAtom prop, JSValueConst val,
+ JSValueConst getter, JSValueConst setter,
int flags);
-static int js_string_memcmp(const JSString *p1, const JSString *p2, int len);
+static int js_string_memcmp(JSString *p1, JSString *p2, int len);
static void reset_weak_ref(JSRuntime *rt, JSWeakRefRecord **first_weak_ref);
-static BOOL is_valid_weakref_target(JSValue val);
-static void insert_weakref_record(JSValue target, struct JSWeakRefRecord *wr);
+static bool is_valid_weakref_target(JSValueConst val);
+static void insert_weakref_record(JSValueConst target,
+ struct JSWeakRefRecord *wr);
static JSValue js_array_buffer_constructor3(JSContext *ctx,
- JSValue new_target,
+ JSValueConst new_target,
uint64_t len, uint64_t *max_len,
JSClassID class_id,
uint8_t *buf,
JSFreeArrayBufferDataFunc *free_func,
- void *opaque, BOOL alloc_flag);
+ void *opaque, bool alloc_flag);
static void js_array_buffer_free(JSRuntime *rt, void *opaque, void *ptr);
-static JSArrayBuffer *js_get_array_buffer(JSContext *ctx, JSValue obj);
-static BOOL array_buffer_is_resizable(const JSArrayBuffer *abuf);
+static JSArrayBuffer *js_get_array_buffer(JSContext *ctx, JSValueConst obj);
+static bool array_buffer_is_resizable(const JSArrayBuffer *abuf);
static JSValue js_typed_array_constructor(JSContext *ctx,
- JSValue this_val,
- int argc, JSValue *argv,
+ JSValueConst this_val,
+ int argc, JSValueConst *argv,
int classid);
static JSValue js_typed_array_constructor_ta(JSContext *ctx,
- JSValue new_target,
- JSValue src_obj,
+ JSValueConst new_target,
+ JSValueConst src_obj,
int classid, uint32_t len);
-static BOOL typed_array_is_oob(JSObject *p);
+static bool is_typed_array(JSClassID class_id);
+static bool typed_array_is_oob(JSObject *p);
static uint32_t typed_array_get_length(JSContext *ctx, JSObject *p);
static JSValue JS_ThrowTypeErrorDetachedArrayBuffer(JSContext *ctx);
static JSValue JS_ThrowTypeErrorArrayBufferOOB(JSContext *ctx);
static JSVarRef *get_var_ref(JSContext *ctx, JSStackFrame *sf, int var_idx,
- BOOL is_arg);
-static JSValue js_generator_function_call(JSContext *ctx, JSValue func_obj,
- JSValue this_obj,
- int argc, JSValue *argv,
+ bool is_arg);
+static JSValue js_generator_function_call(JSContext *ctx, JSValueConst func_obj,
+ JSValueConst this_obj,
+ int argc, JSValueConst *argv,
int flags);
-static void js_async_function_resolve_finalizer(JSRuntime *rt, JSValue val);
-static void js_async_function_resolve_mark(JSRuntime *rt, JSValue val,
+static void js_async_function_resolve_finalizer(JSRuntime *rt,
+ JSValueConst val);
+static void js_async_function_resolve_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func);
-static JSValue JS_EvalInternal(JSContext *ctx, JSValue this_obj,
+static JSValue JS_EvalInternal(JSContext *ctx, JSValueConst this_obj,
const char *input, size_t input_len,
- const char *filename, int flags, int scope_idx);
+ const char *filename, int line, int flags, int scope_idx);
static void js_free_module_def(JSContext *ctx, JSModuleDef *m);
static void js_mark_module_def(JSRuntime *rt, JSModuleDef *m,
JS_MarkFunc *mark_func);
static JSValue js_import_meta(JSContext *ctx);
-static JSValue js_dynamic_import(JSContext *ctx, JSValue specifier);
+static JSValue js_dynamic_import(JSContext *ctx, JSValueConst specifier);
static void free_var_ref(JSRuntime *rt, JSVarRef *var_ref);
static JSValue js_new_promise_capability(JSContext *ctx,
JSValue *resolving_funcs,
- JSValue ctor);
+ JSValueConst ctor);
static __exception int perform_promise_then(JSContext *ctx,
- JSValue promise,
- JSValue *resolve_reject,
- JSValue *cap_resolving_funcs);
-static JSValue js_promise_resolve(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic);
+ JSValueConst promise,
+ JSValueConst *resolve_reject,
+ JSValueConst *cap_resolving_funcs);
+static JSValue js_promise_resolve(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic);
static JSValue js_promise_then(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv);
-static int js_string_compare(JSContext *ctx,
- const JSString *p1, const JSString *p2);
-static JSValue JS_ToNumber(JSContext *ctx, JSValue val);
-static int JS_SetPropertyValue(JSContext *ctx, JSValue this_obj,
+static bool js_string_eq(JSString *p1, JSString *p2);
+static int js_string_compare(JSString *p1, JSString *p2);
+static int JS_SetPropertyValue(JSContext *ctx, JSValueConst this_obj,
JSValue prop, JSValue val, int flags);
-static int JS_NumberIsInteger(JSContext *ctx, JSValue val);
-static BOOL JS_NumberIsNegativeOrMinusZero(JSContext *ctx, JSValue val);
+static int JS_NumberIsInteger(JSContext *ctx, JSValueConst val);
+static bool JS_NumberIsNegativeOrMinusZero(JSContext *ctx, JSValueConst val);
static JSValue JS_ToNumberFree(JSContext *ctx, JSValue val);
static int JS_GetOwnPropertyInternal(JSContext *ctx, JSPropertyDescriptor *desc,
JSObject *p, JSAtom prop);
@@ -1298,25 +1238,27 @@ static int js_shape_prepare_update(JSContext *ctx, JSObject *p,
JSShapeProperty **pprs);
static int init_shape_hash(JSRuntime *rt);
static __exception int js_get_length32(JSContext *ctx, uint32_t *pres,
- JSValue obj);
+ JSValueConst obj);
static __exception int js_get_length64(JSContext *ctx, int64_t *pres,
- JSValue obj);
-static __exception int js_set_length64(JSContext *ctx, JSValue obj,
+ JSValueConst obj);
+static __exception int js_set_length64(JSContext *ctx, JSValueConst obj,
int64_t len);
static void free_arg_list(JSContext *ctx, JSValue *tab, uint32_t len);
static JSValue *build_arg_list(JSContext *ctx, uint32_t *plen,
- JSValue array_arg);
-static BOOL js_get_fast_array(JSContext *ctx, JSValue obj,
+ JSValueConst array_arg);
+static JSValue js_create_array(JSContext *ctx, int len, JSValueConst *tab);
+static bool js_get_fast_array(JSContext *ctx, JSValue obj,
JSValue **arrpp, uint32_t *countp);
+static int expand_fast_array(JSContext *ctx, JSObject *p, uint32_t new_len);
static JSValue JS_CreateAsyncFromSyncIterator(JSContext *ctx,
JSValue sync_iter);
-static void js_c_function_data_finalizer(JSRuntime *rt, JSValue val);
-static void js_c_function_data_mark(JSRuntime *rt, JSValue val,
+static void js_c_function_data_finalizer(JSRuntime *rt, JSValueConst val);
+static void js_c_function_data_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func);
-static JSValue js_c_function_data_call(JSContext *ctx, JSValue func_obj,
- JSValue this_val,
- int argc, JSValue *argv, int flags);
-static JSAtom js_symbol_to_atom(JSContext *ctx, JSValue val);
+static JSValue js_c_function_data_call(JSContext *ctx, JSValueConst func_obj,
+ JSValueConst this_val,
+ int argc, JSValueConst *argv, int flags);
+static JSAtom js_symbol_to_atom(JSContext *ctx, JSValueConst val);
static void add_gc_object(JSRuntime *rt, JSGCObjectHeader *h,
JSGCObjectTypeEnum type);
static void remove_gc_object(JSGCObjectHeader *h);
@@ -1326,21 +1268,23 @@ static JSValue js_module_ns_autoinit(JSContext *ctx, JSObject *p, JSAtom atom,
void *opaque);
static JSValue JS_InstantiateFunctionListItem2(JSContext *ctx, JSObject *p,
JSAtom atom, void *opaque);
-void JS_SetUncatchableError(JSContext *ctx, JSValue val, BOOL flag);
+
+static void js_set_uncatchable_error(JSContext *ctx, JSValueConst val,
+ bool flag);
static JSValue js_new_callsite(JSContext *ctx, JSCallSiteData *csd);
static void js_new_callsite_data(JSContext *ctx, JSCallSiteData *csd, JSStackFrame *sf);
static void js_new_callsite_data2(JSContext *ctx, JSCallSiteData *csd, const char *filename, int line_num, int col_num);
static void _JS_AddIntrinsicCallSite(JSContext *ctx);
-static void JS_SetOpaqueInternal(JSValue obj, void *opaque);
+static void JS_SetOpaqueInternal(JSValueConst obj, void *opaque);
static const JSClassExoticMethods js_arguments_exotic_methods;
static const JSClassExoticMethods js_string_exotic_methods;
static const JSClassExoticMethods js_proxy_exotic_methods;
static const JSClassExoticMethods js_module_ns_exotic_methods;
-static inline BOOL double_is_int32(double d)
+static inline bool double_is_int32(double d)
{
uint64_t u, e;
JSFloat64Union t;
@@ -1405,44 +1349,43 @@ JSValue JS_NewNumber(JSContext *ctx, double d)
return js_number(d);
}
-static JSValue js_bool(JS_BOOL v)
+static JSValue js_bool(bool v)
{
return JS_MKVAL(JS_TAG_BOOL, (v != 0));
}
-static JSValue js_dup(JSValue v)
+static JSValue js_dup(JSValueConst v)
{
if (JS_VALUE_HAS_REF_COUNT(v)) {
JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
p->ref_count++;
}
- return v;
+ return unsafe_unconst(v);
}
-JSValue JS_DupValue(JSContext *ctx, JSValue v)
+JSValue JS_DupValue(JSContext *ctx, JSValueConst v)
{
return js_dup(v);
}
-JSValue JS_DupValueRT(JSRuntime *rt, JSValue v)
+JSValue JS_DupValueRT(JSRuntime *rt, JSValueConst v)
{
return js_dup(v);
}
static void js_trigger_gc(JSRuntime *rt, size_t size)
{
- BOOL force_gc;
+ bool force_gc;
#ifdef FORCE_GC_AT_MALLOC
- force_gc = TRUE;
+ force_gc = true;
#else
force_gc = ((rt->malloc_state.malloc_size + size) >
rt->malloc_gc_threshold);
#endif
if (force_gc) {
-#ifdef DUMP_GC
- if (check_dump_flag(rt, DUMP_GC)) {
- printf("GC: size=%" PRIu64 "\n",
- (uint64_t)rt->malloc_state.malloc_size);
+#ifdef ENABLE_DUMPS // JS_DUMP_GC
+ if (check_dump_flag(rt, JS_DUMP_GC)) {
+ printf("GC: size=%zd\n", rt->malloc_state.malloc_size);
}
#endif
JS_RunGC(rt);
@@ -1545,12 +1488,6 @@ void *js_realloc_rt(JSRuntime *rt, void *ptr, size_t size)
return ptr;
}
-static void *js_dbuf_realloc(void *opaque, void *ptr, size_t size)
-{
- JSRuntime *rt = opaque;
- return js_realloc_rt(rt, ptr, size);
-}
-
size_t js_malloc_usable_size_rt(JSRuntime *rt, const void *ptr)
{
return rt->mf.js_malloc_usable_size(ptr);
@@ -1693,17 +1630,22 @@ static inline int js_resize_array(JSContext *ctx, void **parray, int elem_size,
return 0;
}
+static void *js_dbuf_realloc(void *ctx, void *ptr, size_t size)
+{
+ return js_realloc(ctx, ptr, size);
+}
+
static inline void js_dbuf_init(JSContext *ctx, DynBuf *s)
{
- dbuf_init2(s, ctx->rt, js_dbuf_realloc);
+ dbuf_init2(s, ctx, js_dbuf_realloc);
}
static inline int is_digit(int c) {
return c >= '0' && c <= '9';
}
-static inline int string_get(const JSString *p, int idx) {
- return p->is_wide_char ? p->u.str16[idx] : p->u.str8[idx];
+static inline int string_get(JSString *p, int idx) {
+ return p->is_wide_char ? str16(p)[idx] : str8(p)[idx];
}
typedef struct JSClassShortDef {
@@ -1779,13 +1721,26 @@ static int init_class_range(JSRuntime *rt, JSClassShortDef const *tab,
return 0;
}
-/* Note: OS and CPU dependent */
+/* Uses code from LLVM project. */
static inline uintptr_t js_get_stack_pointer(void)
{
+#if defined(__clang__) || defined(__GNUC__)
return (uintptr_t)__builtin_frame_address(0);
+#elif defined(_MSC_VER)
+ return (uintptr_t)_AddressOfReturnAddress();
+#else
+ char CharOnStack = 0;
+ // The volatile store here is intended to escape the local variable, to
+ // prevent the compiler from optimizing CharOnStack into anything other
+ // than a char on the stack.
+ //
+ // Tested on: MSVC 2015 - 2019, GCC 4.9 - 9, Clang 3.2 - 9, ICC 13 - 19.
+ char *volatile Ptr = &CharOnStack;
+ return (uintptr_t) Ptr;
+#endif
}
-static inline BOOL js_check_stack_overflow(JSRuntime *rt, size_t alloca_size)
+static inline bool js_check_stack_overflow(JSRuntime *rt, size_t alloca_size)
{
uintptr_t sp;
sp = js_get_stack_pointer() - alloca_size;
@@ -1822,7 +1777,7 @@ JSRuntime *JS_NewRuntime2(const JSMallocFunctions *mf, void *opaque)
init_list_head(&rt->gc_zero_ref_count_list);
rt->gc_phase = JS_GC_PHASE_NONE;
-#ifdef DUMP_LEAKS
+#ifdef ENABLE_DUMPS // JS_DUMP_LEAKS
init_list_head(&rt->string_list);
#endif
init_list_head(&rt->job_list);
@@ -1930,7 +1885,18 @@ void JS_SetMemoryLimit(JSRuntime *rt, size_t limit)
void JS_SetDumpFlags(JSRuntime *rt, uint64_t flags)
{
+#ifdef ENABLE_DUMPS
rt->dump_flags = flags;
+#endif
+}
+
+uint64_t JS_GetDumpFlags(JSRuntime *rt)
+{
+#ifdef ENABLE_DUMPS
+ return rt->dump_flags;
+#else
+ return 0;
+#endif
}
size_t JS_GetGCThreshold(JSRuntime *rt) {
@@ -1953,7 +1919,7 @@ void JS_SetInterruptHandler(JSRuntime *rt, JSInterruptHandler *cb, void *opaque)
rt->interrupt_opaque = opaque;
}
-void JS_SetCanBlock(JSRuntime *rt, BOOL can_block)
+void JS_SetCanBlock(JSRuntime *rt, bool can_block)
{
rt->can_block = can_block;
}
@@ -1966,7 +1932,7 @@ void JS_SetSharedArrayBufferFunctions(JSRuntime *rt,
/* return 0 if OK, < 0 if exception */
int JS_EnqueueJob(JSContext *ctx, JSJobFunc *job_func,
- int argc, JSValue *argv)
+ int argc, JSValueConst *argv)
{
JSRuntime *rt = ctx->rt;
JSJobEntry *e;
@@ -1987,7 +1953,7 @@ int JS_EnqueueJob(JSContext *ctx, JSJobFunc *job_func,
return 0;
}
-BOOL JS_IsJobPending(JSRuntime *rt)
+bool JS_IsJobPending(JSRuntime *rt)
{
return !list_empty(&rt->job_list);
}
@@ -2010,7 +1976,7 @@ int JS_ExecutePendingJob(JSRuntime *rt, JSContext **pctx)
e = list_entry(rt->job_list.next, JSJobEntry, link);
list_del(&e->link);
ctx = e->ctx;
- res = e->job_func(e->ctx, e->argc, e->argv);
+ res = e->job_func(e->ctx, e->argc, vc(e->argv));
for(i = 0; i < e->argc; i++)
JS_FreeValue(ctx, e->argv[i]);
if (JS_IsException(res))
@@ -2028,7 +1994,7 @@ static inline uint32_t atom_get_free(const JSAtomStruct *p)
return (uintptr_t)p >> 1;
}
-static inline BOOL atom_is_free(const JSAtomStruct *p)
+static inline bool atom_is_free(const JSAtomStruct *p)
{
return (uintptr_t)p & 1;
}
@@ -2051,7 +2017,7 @@ static JSString *js_alloc_string_rt(JSRuntime *rt, int max_len, int is_wide_char
str->atom_type = 0;
str->hash = 0; /* optional but costless */
str->hash_next = 0; /* optional */
-#ifdef DUMP_LEAKS
+#ifdef ENABLE_DUMPS // JS_DUMP_LEAKS
list_add_tail(&str->link, &rt->string_list);
#endif
return str;
@@ -2075,7 +2041,7 @@ static inline void js_free_string(JSRuntime *rt, JSString *str)
if (str->atom_type) {
JS_FreeAtomStruct(rt, str);
} else {
-#ifdef DUMP_LEAKS
+#ifdef ENABLE_DUMPS // JS_DUMP_LEAKS
list_del(&str->link);
#endif
js_free_rt(rt, str);
@@ -2094,7 +2060,7 @@ void JS_FreeRuntime(JSRuntime *rt)
struct list_head *el, *el1;
int i;
- rt->in_free = TRUE;
+ rt->in_free = true;
JS_FreeValueRT(rt, rt->current_exception);
list_for_each_safe(el, el1, &rt->job_list) {
@@ -2110,10 +2076,10 @@ void JS_FreeRuntime(JSRuntime *rt)
JS_RunGC(rt);
-#ifdef DUMP_LEAKS
+#ifdef ENABLE_DUMPS // JS_DUMP_LEAKS
/* leaking objects */
- if (check_dump_flag(rt, DUMP_LEAKS)) {
- BOOL header_done;
+ if (check_dump_flag(rt, JS_DUMP_LEAKS)) {
+ bool header_done;
JSGCObjectHeader *p;
int count;
@@ -2125,14 +2091,14 @@ void JS_FreeRuntime(JSRuntime *rt)
}
gc_decref(rt);
- header_done = FALSE;
+ header_done = false;
list_for_each(el, &rt->gc_obj_list) {
p = list_entry(el, JSGCObjectHeader, link);
if (p->ref_count != 0) {
if (!header_done) {
printf("Object leaks:\n");
JS_DumpObjectHeader(rt);
- header_done = TRUE;
+ header_done = true;
}
JS_DumpGCObject(rt, p);
}
@@ -2163,17 +2129,17 @@ void JS_FreeRuntime(JSRuntime *rt)
bf_context_end(&rt->bf_ctx);
-#ifdef DUMP_ATOM_LEAKS
+#ifdef ENABLE_DUMPS // JS_DUMP_ATOM_LEAKS
/* only the atoms defined in JS_InitAtoms() should be left */
- if (check_dump_flag(rt, DUMP_ATOM_LEAKS)) {
- BOOL header_done = FALSE;
+ if (check_dump_flag(rt, JS_DUMP_ATOM_LEAKS)) {
+ bool header_done = false;
for(i = 0; i < rt->atom_size; i++) {
JSAtomStruct *p = rt->atom_array[i];
if (!atom_is_free(p) /* && p->str*/) {
if (i >= JS_ATOM_END || p->header.ref_count != 1) {
if (!header_done) {
- header_done = TRUE;
+ header_done = true;
if (rt->rt_info) {
printf("%s:1: atom leakage:", rt->rt_info);
} else {
@@ -2225,7 +2191,7 @@ void JS_FreeRuntime(JSRuntime *rt)
for(i = 0; i < rt->atom_size; i++) {
JSAtomStruct *p = rt->atom_array[i];
if (!atom_is_free(p)) {
-#ifdef DUMP_LEAKS
+#ifdef ENABLE_DUMPS // JS_DUMP_LEAKS
list_del(&p->link);
#endif
js_free_rt(rt, p);
@@ -2234,8 +2200,8 @@ void JS_FreeRuntime(JSRuntime *rt)
js_free_rt(rt, rt->atom_array);
js_free_rt(rt, rt->atom_hash);
js_free_rt(rt, rt->shape_hash);
-#ifdef DUMP_LEAKS
- if (check_dump_flag(rt, DUMP_LEAKS) && !list_empty(&rt->string_list)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_LEAKS
+ if (check_dump_flag(rt, JS_DUMP_LEAKS) && !list_empty(&rt->string_list)) {
if (rt->rt_info) {
printf("%s:1: string leakage:", rt->rt_info);
} else {
@@ -2271,15 +2237,15 @@ void JS_FreeRuntime(JSRuntime *rt)
js_free_rt(rt, fs);
}
-#ifdef DUMP_LEAKS
- if (check_dump_flag(rt, DUMP_LEAKS)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_LEAKS
+ if (check_dump_flag(rt, JS_DUMP_LEAKS)) {
JSMallocState *s = &rt->malloc_state;
if (s->malloc_count > 1) {
if (rt->rt_info)
printf("%s:1: ", rt->rt_info);
- printf("Memory leak: %"PRIu64" bytes lost in %"PRIu64" block%s\n",
- (uint64_t)(s->malloc_size - sizeof(JSRuntime)),
- (uint64_t)(s->malloc_count - 1), &"s"[s->malloc_count == 2]);
+ printf("Memory leak: %zd bytes lost in %zd block%s\n",
+ s->malloc_size - sizeof(JSRuntime),
+ s->malloc_count - 1, &"s"[s->malloc_count == 2]);
}
}
#endif
@@ -2317,8 +2283,9 @@ JSContext *JS_NewContextRaw(JSRuntime *rt)
ctx->regexp_ctor = JS_NULL;
ctx->promise_ctor = JS_NULL;
ctx->error_ctor = JS_NULL;
+ ctx->error_back_trace = JS_UNDEFINED;
ctx->error_prepare_stack = JS_UNDEFINED;
- ctx->error_stack_trace_limit = 10;
+ ctx->error_stack_trace_limit = js_int32(10);
init_list_head(&ctx->loaded_modules);
JS_AddIntrinsicBasicObjects(ctx);
@@ -2436,7 +2403,9 @@ static void JS_MarkContext(JSRuntime *rt, JSContext *ctx,
JS_MarkValue(rt, ctx->native_error_proto[i], mark_func);
}
JS_MarkValue(rt, ctx->error_ctor, mark_func);
+ JS_MarkValue(rt, ctx->error_back_trace, mark_func);
JS_MarkValue(rt, ctx->error_prepare_stack, mark_func);
+ JS_MarkValue(rt, ctx->error_stack_trace_limit, mark_func);
for(i = 0; i < rt->class_count; i++) {
JS_MarkValue(rt, ctx->class_proto[i], mark_func);
}
@@ -2461,16 +2430,16 @@ void JS_FreeContext(JSContext *ctx)
return;
assert(ctx->header.ref_count == 0);
-#ifdef DUMP_ATOMS
- if (check_dump_flag(rt, DUMP_ATOMS))
+#ifdef ENABLE_DUMPS // JS_DUMP_ATOMS
+ if (check_dump_flag(rt, JS_DUMP_ATOMS))
JS_DumpAtoms(ctx->rt);
#endif
-#ifdef DUMP_SHAPES
- if (check_dump_flag(rt, DUMP_SHAPES))
+#ifdef ENABLE_DUMPS // JS_DUMP_SHAPES
+ if (check_dump_flag(rt, JS_DUMP_SHAPES))
JS_DumpShapes(ctx->rt);
#endif
-#ifdef DUMP_OBJECTS
- if (check_dump_flag(rt, DUMP_OBJECTS)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_OBJECTS
+ if (check_dump_flag(rt, JS_DUMP_OBJECTS)) {
struct list_head *el;
JSGCObjectHeader *p;
printf("JSObjects: {\n");
@@ -2482,8 +2451,8 @@ void JS_FreeContext(JSContext *ctx)
printf("}\n");
}
#endif
-#ifdef DUMP_MEM
- if (check_dump_flag(rt, DUMP_MEM)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_MEM
+ if (check_dump_flag(rt, JS_DUMP_MEM)) {
JSMemoryUsage stats;
JS_ComputeMemoryUsage(rt, &stats);
JS_DumpMemoryUsage(stdout, &stats, rt);
@@ -2503,7 +2472,9 @@ void JS_FreeContext(JSContext *ctx)
JS_FreeValue(ctx, ctx->native_error_proto[i]);
}
JS_FreeValue(ctx, ctx->error_ctor);
+ JS_FreeValue(ctx, ctx->error_back_trace);
JS_FreeValue(ctx, ctx->error_prepare_stack);
+ JS_FreeValue(ctx, ctx->error_stack_trace_limit);
for(i = 0; i < rt->class_count; i++) {
JS_FreeValue(ctx, ctx->class_proto[i]);
}
@@ -2530,7 +2501,7 @@ JSRuntime *JS_GetRuntime(JSContext *ctx)
static void update_stack_limit(JSRuntime *rt)
{
-#if defined(__wasi__) || (defined(__ASAN__) && !defined(NDEBUG))
+#if defined(__wasi__)
rt->stack_limit = 0; /* no limit */
#else
if (rt->stack_size == 0) {
@@ -2553,7 +2524,7 @@ void JS_UpdateStackTop(JSRuntime *rt)
update_stack_limit(rt);
}
-static inline BOOL is_strict_mode(JSContext *ctx)
+static inline bool is_strict_mode(JSContext *ctx)
{
JSStackFrame *sf = ctx->rt->current_stack_frame;
return sf && sf->is_strict_mode;
@@ -2568,12 +2539,12 @@ static inline BOOL is_strict_mode(JSContext *ctx)
/* return the max count from the hash size */
#define JS_ATOM_COUNT_RESIZE(n) ((n) * 2)
-static inline BOOL __JS_AtomIsConst(JSAtom v)
+static inline bool __JS_AtomIsConst(JSAtom v)
{
return (int32_t)v < JS_ATOM_END;
}
-static inline BOOL __JS_AtomIsTaggedInt(JSAtom v)
+static inline bool __JS_AtomIsTaggedInt(JSAtom v)
{
return (v & JS_ATOM_TAG_INT) != 0;
}
@@ -2593,8 +2564,8 @@ static inline int is_num(int c)
return c >= '0' && c <= '9';
}
-/* return TRUE if the string is a number n with 0 <= n <= 2^32-1 */
-static inline BOOL is_num_string(uint32_t *pval, const JSString *p)
+/* return true if the string is a number n with 0 <= n <= 2^32-1 */
+static inline bool is_num_string(uint32_t *pval, JSString *p)
{
uint32_t n;
uint64_t n64;
@@ -2602,29 +2573,29 @@ static inline BOOL is_num_string(uint32_t *pval, const JSString *p)
len = p->len;
if (len == 0 || len > 10)
- return FALSE;
+ return false;
c = string_get(p, 0);
if (is_num(c)) {
if (c == '0') {
if (len != 1)
- return FALSE;
+ return false;
n = 0;
} else {
n = c - '0';
for(i = 1; i < len; i++) {
c = string_get(p, i);
if (!is_num(c))
- return FALSE;
+ return false;
n64 = (uint64_t)n * 10 + (c - '0');
if ((n64 >> 32) != 0)
- return FALSE;
+ return false;
n = n64;
}
}
*pval = n;
- return TRUE;
+ return true;
} else {
- return FALSE;
+ return false;
}
}
@@ -2648,17 +2619,16 @@ static inline uint32_t hash_string16(const uint16_t *str,
return h;
}
-static uint32_t hash_string(const JSString *str, uint32_t h)
+static uint32_t hash_string(JSString *str, uint32_t h)
{
if (str->is_wide_char)
- h = hash_string16(str->u.str16, str->len, h);
+ h = hash_string16(str16(str), str->len, h);
else
- h = hash_string8(str->u.str8, str->len, h);
+ h = hash_string8(str8(str), str->len, h);
return h;
}
-static __maybe_unused void JS_DumpString(JSRuntime *rt,
- const JSString *p)
+static __maybe_unused void JS_DumpString(JSRuntime *rt, JSString *p)
{
int i, c, sep;
@@ -2926,7 +2896,7 @@ static JSAtom __JS_NewAtom(JSRuntime *rt, JSString *str, int atom_type)
}
p->header.ref_count = 1; /* not refcounted */
p->atom_type = JS_ATOM_TYPE_SYMBOL;
-#ifdef DUMP_LEAKS
+#ifdef ENABLE_DUMPS // JS_DUMP_LEAKS
list_add_tail(&p->link, &rt->string_list);
#endif
new_array[0] = p;
@@ -2959,10 +2929,10 @@ static JSAtom __JS_NewAtom(JSRuntime *rt, JSString *str, int atom_type)
p->header.ref_count = 1;
p->is_wide_char = str->is_wide_char;
p->len = str->len;
-#ifdef DUMP_LEAKS
+#ifdef ENABLE_DUMPS // JS_DUMP_LEAKS
list_add_tail(&p->link, &rt->string_list);
#endif
- memcpy(p->u.str8, str->u.str8, (str->len << str->is_wide_char) +
+ memcpy(str8(p), str8(str), (str->len << str->is_wide_char) +
1 - str->is_wide_char);
js_free_string(rt, str);
}
@@ -2973,7 +2943,7 @@ static JSAtom __JS_NewAtom(JSRuntime *rt, JSString *str, int atom_type)
p->header.ref_count = 1;
p->is_wide_char = 1; /* Hack to represent NULL as a JSString */
p->len = 0;
-#ifdef DUMP_LEAKS
+#ifdef ENABLE_DUMPS // JS_DUMP_LEAKS
list_add_tail(&p->link, &rt->string_list);
#endif
}
@@ -3017,8 +2987,8 @@ static JSAtom __JS_NewAtomInit(JSRuntime *rt, const char *str, int len,
p = js_alloc_string_rt(rt, len, 0);
if (!p)
return JS_ATOM_NULL;
- memcpy(p->u.str8, str, len);
- p->u.str8[len] = '\0';
+ memcpy(str8(p), str, len);
+ str8(p)[len] = '\0';
return __JS_NewAtom(rt, p, atom_type);
}
@@ -3039,7 +3009,7 @@ static JSAtom __JS_FindAtom(JSRuntime *rt, const char *str, size_t len,
p->atom_type == JS_ATOM_TYPE_STRING &&
p->len == len &&
p->is_wide_char == 0 &&
- memcmp(p->u.str8, str, len) == 0) {
+ memcmp(str8(p), str, len) == 0) {
if (!__JS_AtomIsConst(i))
p->header.ref_count++;
return i;
@@ -3081,7 +3051,7 @@ static void JS_FreeAtomStruct(JSRuntime *rt, JSAtomStruct *p)
reset_weak_ref(rt, &p->first_weak_ref);
}
/* free the string structure */
-#ifdef DUMP_LEAKS
+#ifdef ENABLE_DUMPS // JS_DUMP_LEAKS
list_del(&p->link);
#endif
js_free_rt(rt, p);
@@ -3194,7 +3164,7 @@ static JSValue JS_NewSymbolFromAtom(JSContext *ctx, JSAtom descr,
}
/* `description` may be pure ASCII or UTF-8 encoded */
-JSValue JS_NewSymbol(JSContext *ctx, const char *description, JS_BOOL is_global)
+JSValue JS_NewSymbol(JSContext *ctx, const char *description, bool is_global)
{
JSAtom atom = JS_NewAtom(ctx, description);
if (atom == JS_ATOM_NULL)
@@ -3204,7 +3174,6 @@ JSValue JS_NewSymbol(JSContext *ctx, const char *description, JS_BOOL is_global)
#define ATOM_GET_STR_BUF_SIZE 64
-/* Should only be used for debug. */
static const char *JS_AtomGetStrRT(JSRuntime *rt, char *buf, int buf_size,
JSAtom atom)
{
@@ -3225,16 +3194,9 @@ static const char *JS_AtomGetStrRT(JSRuntime *rt, char *buf, int buf_size,
JSString *str = p;
if (str->is_wide_char) {
/* encode surrogates correctly */
- utf8_encode_buf16(buf, buf_size, str->u.str16, str->len);
+ utf8_encode_buf16(buf, buf_size, str16(str), str->len);
} else {
- /* special case ASCII strings */
- int i, c = 0;
- for(i = 0; i < str->len; i++) {
- c |= str->u.str8[i];
- }
- if (c < 0x80)
- return (const char *)str->u.str8;
- utf8_encode_buf8(buf, buf_size, str->u.str8, str->len);
+ utf8_encode_buf8(buf, buf_size, str8(str), str->len);
}
}
}
@@ -3246,7 +3208,7 @@ static const char *JS_AtomGetStr(JSContext *ctx, char *buf, int buf_size, JSAtom
return JS_AtomGetStrRT(ctx->rt, buf, buf_size, atom);
}
-static JSValue __JS_AtomToValue(JSContext *ctx, JSAtom atom, BOOL force_string)
+static JSValue __JS_AtomToValue(JSContext *ctx, JSAtom atom, bool force_string)
{
char buf[ATOM_GET_STR_BUF_SIZE];
@@ -3275,21 +3237,21 @@ static JSValue __JS_AtomToValue(JSContext *ctx, JSAtom atom, BOOL force_string)
JSValue JS_AtomToValue(JSContext *ctx, JSAtom atom)
{
- return __JS_AtomToValue(ctx, atom, FALSE);
+ return __JS_AtomToValue(ctx, atom, false);
}
JSValue JS_AtomToString(JSContext *ctx, JSAtom atom)
{
- return __JS_AtomToValue(ctx, atom, TRUE);
+ return __JS_AtomToValue(ctx, atom, true);
}
-/* return TRUE if the atom is an array index (i.e. 0 <= index <=
+/* return true if the atom is an array index (i.e. 0 <= index <=
2^32-2 and return its value */
-static BOOL JS_AtomIsArrayIndex(JSContext *ctx, uint32_t *pval, JSAtom atom)
+static bool JS_AtomIsArrayIndex(JSContext *ctx, uint32_t *pval, JSAtom atom)
{
if (__JS_AtomIsTaggedInt(atom)) {
*pval = __JS_AtomToUInt32(atom);
- return TRUE;
+ return true;
} else {
JSRuntime *rt = ctx->rt;
JSAtomStruct *p;
@@ -3300,10 +3262,10 @@ static BOOL JS_AtomIsArrayIndex(JSContext *ctx, uint32_t *pval, JSAtom atom)
if (p->atom_type == JS_ATOM_TYPE_STRING &&
is_num_string(&val, p) && val != -1) {
*pval = val;
- return TRUE;
+ return true;
} else {
*pval = 0;
- return FALSE;
+ return false;
}
}
}
@@ -3328,7 +3290,7 @@ static JSValue JS_AtomIsNumericIndex1(JSContext *ctx, JSAtom atom)
p = p1;
len = p->len;
if (p->is_wide_char) {
- const uint16_t *r = p->u.str16, *r_end = p->u.str16 + len;
+ const uint16_t *r = str16(p), *r_end = str16(p) + len;
if (r >= r_end)
return JS_UNDEFINED;
c = *r;
@@ -3350,7 +3312,7 @@ static JSValue JS_AtomIsNumericIndex1(JSContext *ctx, JSAtom atom)
return JS_UNDEFINED;
}
} else {
- const uint8_t *r = p->u.str8, *r_end = p->u.str8 + len;
+ const uint8_t *r = str8(p), *r_end = str8(p) + len;
if (r >= r_end)
return JS_UNDEFINED;
c = *r;
@@ -3380,9 +3342,9 @@ static JSValue JS_AtomIsNumericIndex1(JSContext *ctx, JSAtom atom)
JS_FreeValue(ctx, num);
return str;
}
- ret = js_string_compare(ctx, p, JS_VALUE_GET_STRING(str));
+ ret = js_string_eq(p, JS_VALUE_GET_STRING(str));
JS_FreeValue(ctx, str);
- if (ret == 0) {
+ if (ret) {
return num;
} else {
JS_FreeValue(ctx, num);
@@ -3390,17 +3352,17 @@ static JSValue JS_AtomIsNumericIndex1(JSContext *ctx, JSAtom atom)
}
}
-/* return -1 if exception or TRUE/FALSE */
+/* return -1 if exception or true/false */
static int JS_AtomIsNumericIndex(JSContext *ctx, JSAtom atom)
{
JSValue num;
num = JS_AtomIsNumericIndex1(ctx, atom);
if (likely(JS_IsUndefined(num)))
- return FALSE;
+ return false;
if (JS_IsException(num))
return -1;
JS_FreeValue(ctx, num);
- return TRUE;
+ return true;
}
void JS_FreeAtom(JSContext *ctx, JSAtom v)
@@ -3415,15 +3377,15 @@ void JS_FreeAtomRT(JSRuntime *rt, JSAtom v)
__JS_FreeAtom(rt, v);
}
-/* return TRUE if 'v' is a symbol with a string description */
-static BOOL JS_AtomSymbolHasDescription(JSContext *ctx, JSAtom v)
+/* return true if 'v' is a symbol with a string description */
+static bool JS_AtomSymbolHasDescription(JSContext *ctx, JSAtom v)
{
JSRuntime *rt;
JSAtomStruct *p;
rt = ctx->rt;
if (__JS_AtomIsTaggedInt(v))
- return FALSE;
+ return false;
p = rt->atom_array[v];
return (((p->atom_type == JS_ATOM_TYPE_SYMBOL &&
p->hash == JS_ATOM_HASH_SYMBOL) ||
@@ -3525,14 +3487,14 @@ static JSAtom js_atom_concat_num(JSContext *ctx, JSAtom name, uint32_t n)
return js_atom_concat_str(ctx, name, buf);
}
-static inline BOOL JS_IsEmptyString(JSValue v)
+static inline bool JS_IsEmptyString(JSValueConst v)
{
return JS_VALUE_GET_TAG(v) == JS_TAG_STRING && JS_VALUE_GET_STRING(v)->len == 0;
}
/* JSClass support */
-/* a new class ID is allocated if *pclass_id != 0 */
+/* a new class ID is allocated if *pclass_id == 0, otherwise *pclass_id is left unchanged */
JSClassID JS_NewClassID(JSRuntime *rt, JSClassID *pclass_id)
{
JSClassID class_id = *pclass_id;
@@ -3543,7 +3505,7 @@ JSClassID JS_NewClassID(JSRuntime *rt, JSClassID *pclass_id)
return class_id;
}
-JSClassID JS_GetClassID(JSValue v)
+JSClassID JS_GetClassID(JSValueConst v)
{
JSObject *p;
if (JS_VALUE_GET_TAG(v) != JS_TAG_OBJECT)
@@ -3552,7 +3514,7 @@ JSClassID JS_GetClassID(JSValue v)
return p->class_id;
}
-BOOL JS_IsRegisteredClass(JSRuntime *rt, JSClassID class_id)
+bool JS_IsRegisteredClass(JSRuntime *rt, JSClassID class_id)
{
return (class_id < rt->class_count &&
rt->class_array[class_id].class_id != 0);
@@ -3636,8 +3598,8 @@ static JSValue js_new_string8_len(JSContext *ctx, const char *buf, int len)
str = js_alloc_string(ctx, len, 0);
if (!str)
return JS_EXCEPTION;
- memcpy(str->u.str8, buf, len);
- str->u.str8[len] = '\0';
+ memcpy(str8(str), buf, len);
+ str8(str)[len] = '\0';
return JS_MKPTR(JS_TAG_STRING, str);
}
@@ -3654,7 +3616,7 @@ static JSValue js_new_string16_len(JSContext *ctx, const uint16_t *buf, int len)
str = js_alloc_string(ctx, len, 1);
if (!str)
return JS_EXCEPTION;
- memcpy(str->u.str16, buf, len * 2);
+ memcpy(str16(str), buf, len * 2);
return JS_MKPTR(JS_TAG_STRING, str);
}
@@ -3683,21 +3645,21 @@ static JSValue js_sub_string(JSContext *ctx, JSString *p, int start, int end)
int i;
uint16_t c = 0;
for (i = start; i < end; i++) {
- c |= p->u.str16[i];
+ c |= str16(p)[i];
}
if (c > 0xFF)
- return js_new_string16_len(ctx, p->u.str16 + start, len);
+ return js_new_string16_len(ctx, str16(p) + start, len);
str = js_alloc_string(ctx, len, 0);
if (!str)
return JS_EXCEPTION;
for (i = 0; i < len; i++) {
- str->u.str8[i] = p->u.str16[start + i];
+ str8(str)[i] = str16(p)[start + i];
}
- str->u.str8[len] = '\0';
+ str8(str)[len] = '\0';
return JS_MKPTR(JS_TAG_STRING, str);
} else {
- return js_new_string8_len(ctx, (const char *)(p->u.str8 + start), len);
+ return js_new_string8_len(ctx, (const char *)(str8(p) + start), len);
}
}
@@ -3727,7 +3689,7 @@ static int string_buffer_init2(JSContext *ctx, StringBuffer *s, int size,
s->size = 0;
return s->error_status = -1;
}
-#ifdef DUMP_LEAKS
+#ifdef ENABLE_DUMPS // JS_DUMP_LEAKS
/* the StringBuffer may reallocate the JSString, only link it at the end */
list_del(&s->str->link);
#endif
@@ -3768,7 +3730,7 @@ static no_inline int string_buffer_widen(StringBuffer *s, int size)
return string_buffer_set_error(s);
size += slack >> 1;
for(i = s->len; i-- > 0;) {
- str->u.str16[i] = str->u.str8[i];
+ str16(str)[i] = str8(str)[i];
}
s->is_wide_char = 1;
s->size = size;
@@ -3810,13 +3772,13 @@ static no_inline int string_buffer_putc_slow(StringBuffer *s, uint32_t c)
return -1;
}
if (s->is_wide_char) {
- s->str->u.str16[s->len++] = c;
+ str16(s->str)[s->len++] = c;
} else if (c < 0x100) {
- s->str->u.str8[s->len++] = c;
+ str8(s->str)[s->len++] = c;
} else {
if (string_buffer_widen(s, s->size))
return -1;
- s->str->u.str16[s->len++] = c;
+ str16(s->str)[s->len++] = c;
}
return 0;
}
@@ -3829,9 +3791,9 @@ static int string_buffer_putc8(StringBuffer *s, uint32_t c)
return -1;
}
if (s->is_wide_char) {
- s->str->u.str16[s->len++] = c;
+ str16(s->str)[s->len++] = c;
} else {
- s->str->u.str8[s->len++] = c;
+ str8(s->str)[s->len++] = c;
}
return 0;
}
@@ -3841,10 +3803,10 @@ static int string_buffer_putc16(StringBuffer *s, uint32_t c)
{
if (likely(s->len < s->size)) {
if (s->is_wide_char) {
- s->str->u.str16[s->len++] = c;
+ str16(s->str)[s->len++] = c;
return 0;
} else if (c < 0x100) {
- s->str->u.str8[s->len++] = c;
+ str8(s->str)[s->len++] = c;
return 0;
}
}
@@ -3863,21 +3825,21 @@ static int string_buffer_putc(StringBuffer *s, uint32_t c)
return string_buffer_putc16(s, c);
}
-static int string_getc(const JSString *p, int *pidx)
+static int string_getc(JSString *p, int *pidx)
{
int idx, c, c1;
idx = *pidx;
if (p->is_wide_char) {
- c = p->u.str16[idx++];
+ c = str16(p)[idx++];
if (is_hi_surrogate(c) && idx < p->len) {
- c1 = p->u.str16[idx];
+ c1 = str16(p)[idx];
if (is_lo_surrogate(c1)) {
c = from_surrogate(c, c1);
idx++;
}
}
} else {
- c = p->u.str8[idx++];
+ c = str8(p)[idx++];
}
*pidx = idx;
return c;
@@ -3893,11 +3855,11 @@ static int string_buffer_write8(StringBuffer *s, const uint8_t *p, int len)
}
if (s->is_wide_char) {
for (i = 0; i < len; i++) {
- s->str->u.str16[s->len + i] = p[i];
+ str16(s->str)[s->len + i] = p[i];
}
s->len += len;
} else {
- memcpy(&s->str->u.str8[s->len], p, len);
+ memcpy(&str8(s->str)[s->len], p, len);
s->len += len;
}
return 0;
@@ -3918,11 +3880,11 @@ static int string_buffer_write16(StringBuffer *s, const uint16_t *p, int len)
return -1;
}
if (s->is_wide_char) {
- memcpy(&s->str->u.str16[s->len], p, len << 1);
+ memcpy(&str16(s->str)[s->len], p, len << 1);
s->len += len;
} else {
for (i = 0; i < len; i++) {
- s->str->u.str8[s->len + i] = p[i];
+ str8(s->str)[s->len + i] = p[i];
}
s->len += len;
}
@@ -3935,18 +3897,18 @@ static int string_buffer_puts8(StringBuffer *s, const char *str)
return string_buffer_write8(s, (const uint8_t *)str, strlen(str));
}
-static int string_buffer_concat(StringBuffer *s, const JSString *p,
+static int string_buffer_concat(StringBuffer *s, JSString *p,
uint32_t from, uint32_t to)
{
if (to <= from)
return 0;
if (p->is_wide_char)
- return string_buffer_write16(s, p->u.str16 + from, to - from);
+ return string_buffer_write16(s, str16(p) + from, to - from);
else
- return string_buffer_write8(s, p->u.str8 + from, to - from);
+ return string_buffer_write8(s, str8(p) + from, to - from);
}
-static int string_buffer_concat_value(StringBuffer *s, JSValue v)
+static int string_buffer_concat_value(StringBuffer *s, JSValueConst v)
{
JSString *p;
JSValue v1;
@@ -4026,8 +3988,8 @@ static JSValue string_buffer_end(StringBuffer *s)
s->str = str;
}
if (!s->is_wide_char)
- str->u.str8[s->len] = 0;
-#ifdef DUMP_LEAKS
+ str8(str)[s->len] = 0;
+#ifdef ENABLE_DUMPS // JS_DUMP_LEAKS
list_add_tail(&str->link, &s->ctx->rt->string_list);
#endif
str->is_wide_char = s->is_wide_char;
@@ -4056,15 +4018,15 @@ JSValue JS_NewStringLen(JSContext *ctx, const char *buf, size_t buf_len)
str = js_alloc_string(ctx, len, 0);
if (!str)
return JS_EXCEPTION;
- memcpy(str->u.str8, buf, len);
- str->u.str8[len] = '\0';
+ memcpy(str8(str), buf, len);
+ str8(str)[len] = '\0';
break;
case UTF8_NON_ASCII:
/* buf contains non-ASCII code-points, but limited to 8-bit values */
str = js_alloc_string(ctx, len, 0);
if (!str)
return JS_EXCEPTION;
- utf8_decode_buf8(str->u.str8, len + 1, buf, buf_len);
+ utf8_decode_buf8(str8(str), len + 1, buf, buf_len);
break;
default:
// This causes a potential problem in JS_ThrowError if message is invalid
@@ -4073,7 +4035,7 @@ JSValue JS_NewStringLen(JSContext *ctx, const char *buf, size_t buf_len)
str = js_alloc_string(ctx, len, 1);
if (!str)
return JS_EXCEPTION;
- utf8_decode_buf16(str->u.str16, len, buf, buf_len);
+ utf8_decode_buf16(str16(str), len, buf, buf_len);
break;
}
return JS_MKPTR(JS_TAG_STRING, str);
@@ -4124,7 +4086,8 @@ JSValue JS_NewAtomString(JSContext *ctx, const char *str)
/* return (NULL, 0) if exception. */
/* return pointer into a JSString with a live ref_count */
/* cesu8 determines if non-BMP1 codepoints are encoded as 1 or 2 utf-8 sequences */
-const char *JS_ToCStringLen2(JSContext *ctx, size_t *plen, JSValue val1, BOOL cesu8)
+const char *JS_ToCStringLen2(JSContext *ctx, size_t *plen, JSValueConst val1,
+ bool cesu8)
{
JSValue val;
JSString *str, *str_new;
@@ -4162,7 +4125,7 @@ go:
str = JS_VALUE_GET_STRING(val);
len = str->len;
if (!str->is_wide_char) {
- const uint8_t *src = str->u.str8;
+ const uint8_t *src = str8(str);
int count;
/* count the number of non-ASCII characters */
@@ -4183,7 +4146,7 @@ go:
str_new = js_alloc_string(ctx, len + count, 0);
if (!str_new)
goto fail;
- q = str_new->u.str8;
+ q = str8(str_new);
for (pos = 0; pos < len; pos++) {
c = src[pos];
if (c < 0x80) {
@@ -4194,14 +4157,14 @@ go:
}
}
} else {
- const uint16_t *src = str->u.str16;
+ const uint16_t *src = str16(str);
/* Allocate 3 bytes per 16 bit code point. Surrogate pairs may
produce 4 bytes but use 2 code points.
*/
str_new = js_alloc_string(ctx, len * 3, 0);
if (!str_new)
goto fail;
- q = str_new->u.str8;
+ q = str8(str_new);
pos = 0;
while (pos < len) {
c = src[pos++];
@@ -4229,11 +4192,11 @@ go:
}
*q = '\0';
- str_new->len = q - str_new->u.str8;
+ str_new->len = q - str8(str_new);
JS_FreeValue(ctx, val);
if (plen)
*plen = str_new->len;
- return (const char *)str_new->u.str8;
+ return (const char *)str8(str_new);
fail:
if (plen)
*plen = 0;
@@ -4242,12 +4205,10 @@ go:
void JS_FreeCString(JSContext *ctx, const char *ptr)
{
- JSString *p;
if (!ptr)
return;
/* purposely removing constness */
- p = container_of(ptr, JSString, u);
- JS_FreeValue(ctx, JS_MKPTR(JS_TAG_STRING, p));
+ JS_FreeValue(ctx, JS_MKPTR(JS_TAG_STRING, (JSString *)ptr - 1));
}
/* create a string from a narrow Unicode (latin-1) buffer */
@@ -4258,21 +4219,21 @@ JSValue JS_NewNarrowStringLen(JSContext *ctx, const char *buf, size_t buf_len)
return js_new_string8_len(ctx, buf, buf_len);
}
-JS_BOOL JS_IsStringWideChar(JSValue value)
+bool JS_IsStringWideChar(JSValueConst value)
{
if (unlikely(JS_VALUE_GET_TAG(value) != JS_TAG_STRING))
- return FALSE;
+ return false;
return JS_VALUE_GET_STRING(value)->is_wide_char;
}
-uint8_t *JS_GetNarrowStringBuffer(JSValue value)
+uint8_t *JS_GetNarrowStringBuffer(JSValueConst value)
{
if (unlikely(JS_VALUE_GET_TAG(value) != JS_TAG_STRING))
return NULL;
- return JS_VALUE_GET_STRING(value)->u.str8;
+ return str8(JS_VALUE_GET_STRING(value));
}
-uint32_t JS_GetStringLength(JSValue value)
+uint32_t JS_GetStringLength(JSValueConst value)
{
if (unlikely(JS_VALUE_GET_TAG(value) != JS_TAG_STRING))
return 0;
@@ -4301,27 +4262,32 @@ static int memcmp16(const uint16_t *src1, const uint16_t *src2, int len)
return 0;
}
-static int js_string_memcmp(const JSString *p1, const JSString *p2, int len)
+static int js_string_memcmp(JSString *p1, JSString *p2, int len)
{
int res;
if (likely(!p1->is_wide_char)) {
if (likely(!p2->is_wide_char))
- res = memcmp(p1->u.str8, p2->u.str8, len);
+ res = memcmp(str8(p1), str8(p2), len);
else
- res = -memcmp16_8(p2->u.str16, p1->u.str8, len);
+ res = -memcmp16_8(str16(p2), str8(p1), len);
} else {
if (!p2->is_wide_char)
- res = memcmp16_8(p1->u.str16, p2->u.str8, len);
+ res = memcmp16_8(str16(p1), str8(p2), len);
else
- res = memcmp16(p1->u.str16, p2->u.str16, len);
+ res = memcmp16(str16(p1), str16(p2), len);
}
return res;
}
+static bool js_string_eq(JSString *p1, JSString *p2) {
+ if (p1->len != p2->len)
+ return false;
+ return js_string_memcmp(p1, p2, p1->len) == 0;
+}
+
/* return < 0, 0 or > 0 */
-static int js_string_compare(JSContext *ctx,
- const JSString *p1, const JSString *p2)
+static int js_string_compare(JSString *p1, JSString *p2)
{
int res, len;
len = min_int(p1->len, p2->len);
@@ -4331,12 +4297,12 @@ static int js_string_compare(JSContext *ctx,
return res;
}
-static void copy_str16(uint16_t *dst, const JSString *p, int offset, int len)
+static void copy_str16(uint16_t *dst, JSString *p, int offset, int len)
{
if (p->is_wide_char) {
- memcpy(dst, p->u.str16 + offset, len * 2);
+ memcpy(dst, str16(p) + offset, len * 2);
} else {
- const uint8_t *src1 = p->u.str8 + offset;
+ const uint8_t *src1 = str8(p) + offset;
int i;
for(i = 0; i < len; i++)
@@ -4344,8 +4310,7 @@ static void copy_str16(uint16_t *dst, const JSString *p, int offset, int len)
}
}
-static JSValue JS_ConcatString1(JSContext *ctx,
- const JSString *p1, const JSString *p2)
+static JSValue JS_ConcatString1(JSContext *ctx, JSString *p1, JSString *p2)
{
JSString *p;
uint32_t len;
@@ -4359,12 +4324,12 @@ static JSValue JS_ConcatString1(JSContext *ctx,
if (!p)
return JS_EXCEPTION;
if (!is_wide_char) {
- memcpy(p->u.str8, p1->u.str8, p1->len);
- memcpy(p->u.str8 + p1->len, p2->u.str8, p2->len);
- p->u.str8[len] = '\0';
+ memcpy(str8(p), str8(p1), p1->len);
+ memcpy(str8(p) + p1->len, str8(p2), p2->len);
+ str8(p)[len] = '\0';
} else {
- copy_str16(p->u.str16, p1, 0, p1->len);
- copy_str16(p->u.str16 + p1->len, p2, 0, p2->len);
+ copy_str16(str16(p), p1, 0, p1->len);
+ copy_str16(str16(p) + p1->len, p2, 0, p2->len);
}
return JS_MKPTR(JS_TAG_STRING, p);
}
@@ -4401,12 +4366,12 @@ static JSValue JS_ConcatString(JSContext *ctx, JSValue op1, JSValue op2)
&& js_malloc_usable_size(ctx, p1) >= sizeof(*p1) + ((p1->len + p2->len) << p2->is_wide_char) + 1 - p1->is_wide_char) {
/* Concatenate in place in available space at the end of p1 */
if (p1->is_wide_char) {
- memcpy(p1->u.str16 + p1->len, p2->u.str16, p2->len << 1);
+ memcpy(str16(p1) + p1->len, str16(p2), p2->len << 1);
p1->len += p2->len;
} else {
- memcpy(p1->u.str8 + p1->len, p2->u.str8, p2->len);
+ memcpy(str8(p1) + p1->len, str8(p2), p2->len);
p1->len += p2->len;
- p1->u.str8[p1->len] = '\0';
+ str8(p1)[p1->len] = '\0';
}
ret_op1:
JS_FreeValue(ctx, op2);
@@ -4558,8 +4523,8 @@ static no_inline JSShape *js_new_shape2(JSContext *ctx, JSObject *proto,
/* insert in the hash table */
sh->hash = shape_initial_hash(proto);
- sh->is_hashed = TRUE;
- sh->has_small_array_index = FALSE;
+ sh->is_hashed = true;
+ sh->has_small_array_index = false;
js_shape_hash_link(ctx->rt, sh);
return sh;
}
@@ -4590,7 +4555,7 @@ static JSShape *js_clone_shape(JSContext *ctx, JSShape *sh1)
sh = get_shape_from_alloc(sh_alloc, hash_size);
sh->header.ref_count = 1;
add_gc_object(ctx->rt, &sh->header, JS_GC_OBJ_TYPE_SHAPE);
- sh->is_hashed = FALSE;
+ sh->is_hashed = false;
if (sh->proto) {
js_dup(JS_MKPTR(JS_TAG_OBJECT, sh->proto));
}
@@ -4924,7 +4889,7 @@ static JSValue JS_NewObjectFromShape(JSContext *ctx, JSShape *sh, JSClassID clas
if (unlikely(!p))
goto fail;
p->class_id = class_id;
- p->extensible = TRUE;
+ p->extensible = true;
p->free_mark = 0;
p->is_exotic = 0;
p->fast_array = 0;
@@ -5015,7 +4980,7 @@ static JSValue JS_NewObjectFromShape(JSContext *ctx, JSShape *sh, JSClassID clas
return JS_MKPTR(JS_TAG_OBJECT, p);
}
-static JSObject *get_proto_obj(JSValue proto_val)
+static JSObject *get_proto_obj(JSValueConst proto_val)
{
if (JS_VALUE_GET_TAG(proto_val) != JS_TAG_OBJECT)
return NULL;
@@ -5024,7 +4989,7 @@ static JSObject *get_proto_obj(JSValue proto_val)
}
/* WARNING: proto must be an object or JS_NULL */
-JSValue JS_NewObjectProtoClass(JSContext *ctx, JSValue proto_val,
+JSValue JS_NewObjectProtoClass(JSContext *ctx, JSValueConst proto_val,
JSClassID class_id)
{
JSShape *sh;
@@ -5042,7 +5007,7 @@ JSValue JS_NewObjectProtoClass(JSContext *ctx, JSValue proto_val,
return JS_NewObjectFromShape(ctx, sh, class_id);
}
-static int JS_SetObjectData(JSContext *ctx, JSValue obj, JSValue val)
+static int JS_SetObjectData(JSContext *ctx, JSValueConst obj, JSValue val)
{
JSObject *p;
@@ -5071,17 +5036,117 @@ JSValue JS_NewObjectClass(JSContext *ctx, int class_id)
return JS_NewObjectProtoClass(ctx, ctx->class_proto[class_id], class_id);
}
-JSValue JS_NewObjectProto(JSContext *ctx, JSValue proto)
+JSValue JS_NewObjectProto(JSContext *ctx, JSValueConst proto)
{
return JS_NewObjectProtoClass(ctx, proto, JS_CLASS_OBJECT);
}
+JSValue JS_NewObjectFrom(JSContext *ctx, int count, const JSAtom *props,
+ const JSValue *values)
+{
+ JSShapeProperty *pr;
+ uint32_t *hash;
+ JSRuntime *rt;
+ JSObject *p;
+ JSShape *sh;
+ JSValue obj;
+ JSAtom atom;
+ intptr_t h;
+ int i;
+
+ rt = ctx->rt;
+ obj = JS_NewObject(ctx);
+ if (JS_IsException(obj))
+ return JS_EXCEPTION;
+ if (count > 0) {
+ p = JS_VALUE_GET_OBJ(obj);
+ sh = p->shape;
+ assert(sh->is_hashed);
+ assert(sh->header.ref_count == 1);
+ js_shape_hash_unlink(rt, sh);
+ if (resize_properties(ctx, &sh, p, count)) {
+ js_shape_hash_link(rt, sh);
+ JS_FreeValue(ctx, obj);
+ return JS_EXCEPTION;
+ }
+ p->shape = sh;
+ for (i = 0; i < count; i++) {
+ atom = props[i];
+ pr = &sh->prop[i];
+ sh->hash = shape_hash(shape_hash(sh->hash, atom), JS_PROP_C_W_E);
+ sh->has_small_array_index |= __JS_AtomIsTaggedInt(atom);
+ h = atom & sh->prop_hash_mask;
+ hash = &prop_hash_end(sh)[-h - 1];
+ pr->hash_next = *hash;
+ *hash = i + 1;
+ pr->atom = JS_DupAtom(ctx, atom);
+ pr->flags = JS_PROP_C_W_E;
+ p->prop[i].u.value = values[i];
+ }
+ js_shape_hash_link(rt, sh);
+ sh->prop_count = count;
+ }
+ return obj;
+}
+
+JSValue JS_NewObjectFromStr(JSContext *ctx, int count, const char **props,
+ const JSValue *values)
+{
+ JSAtom atoms_s[16], *atoms = atoms_s;
+ JSValue ret;
+ int i;
+
+ i = 0;
+ ret = JS_EXCEPTION;
+ if (count < 1)
+ goto out;
+ if (count > (int)countof(atoms_s)) {
+ atoms = js_malloc(ctx, count * sizeof(*atoms));
+ if (!atoms)
+ return JS_EXCEPTION;
+ }
+ for (i = 0; i < count; i++) {
+ atoms[i] = JS_NewAtom(ctx, props[i]);
+ if (atoms[i] == JS_ATOM_NULL)
+ goto out;
+ }
+ ret = JS_NewObjectFrom(ctx, count, atoms, values);
+out:
+ while (i-- > 0)
+ JS_FreeAtom(ctx, atoms[i]);
+ if (atoms != atoms_s)
+ js_free(ctx, atoms);
+ return ret;
+}
+
JSValue JS_NewArray(JSContext *ctx)
{
return JS_NewObjectFromShape(ctx, js_dup_shape(ctx->array_shape),
JS_CLASS_ARRAY);
}
+// note: takes ownership of |values|, unlike js_create_array
+JSValue JS_NewArrayFrom(JSContext *ctx, int count, const JSValue *values)
+{
+ JSObject *p;
+ JSValue obj;
+
+ obj = JS_NewArray(ctx);
+ if (JS_IsException(obj))
+ return JS_EXCEPTION;
+ if (count > 0) {
+ p = JS_VALUE_GET_OBJ(obj);
+ if (expand_fast_array(ctx, p, count)) {
+ JS_FreeValue(ctx, obj);
+ return JS_EXCEPTION;
+ }
+ p->u.array.count = count;
+ p->prop[0].u.value = js_int32(count);
+ memcpy(p->u.array.u.values, values, count * sizeof(*values));
+ }
+ return obj;
+}
+
JSValue JS_NewObject(JSContext *ctx)
{
/* inline JS_NewObjectClass(ctx, JS_CLASS_OBJECT); */
@@ -5098,7 +5163,7 @@ static void js_function_set_properties(JSContext *ctx, JSValue func_obj,
JS_AtomToString(ctx, name), JS_PROP_CONFIGURABLE);
}
-static BOOL js_class_has_bytecode(JSClassID class_id)
+static bool js_class_has_bytecode(JSClassID class_id)
{
return (class_id == JS_CLASS_BYTECODE_FUNCTION ||
class_id == JS_CLASS_GENERATOR_FUNCTION ||
@@ -5107,7 +5172,7 @@ static BOOL js_class_has_bytecode(JSClassID class_id)
}
/* return NULL without exception if not a function or no bytecode */
-static JSFunctionBytecode *JS_GetFunctionBytecode(JSValue val)
+static JSFunctionBytecode *JS_GetFunctionBytecode(JSValueConst val)
{
JSObject *p;
if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT)
@@ -5180,7 +5245,8 @@ static int js_method_set_properties(JSContext *ctx, JSValue func_obj,
/* Note: at least 'length' arguments will be readable in 'argv' */
/* `name` may be NULL, pure ASCII or UTF-8 encoded */
-JSValue JS_NewCFunction3(JSContext *ctx, JSCFunction *func, const char *name,
+JSValue JS_NewCFunction3(JSContext *ctx, JSCFunction *func,
+ const char *name,
int length, JSCFunctionEnum cproto, int magic,
JSValue proto_val)
{
@@ -5226,7 +5292,7 @@ typedef struct JSCFunctionDataRecord {
JSValue data[];
} JSCFunctionDataRecord;
-static void js_c_function_data_finalizer(JSRuntime *rt, JSValue val)
+static void js_c_function_data_finalizer(JSRuntime *rt, JSValueConst val)
{
JSCFunctionDataRecord *s = JS_GetOpaque(val, JS_CLASS_C_FUNCTION_DATA);
int i;
@@ -5239,7 +5305,7 @@ static void js_c_function_data_finalizer(JSRuntime *rt, JSValue val)
}
}
-static void js_c_function_data_mark(JSRuntime *rt, JSValue val,
+static void js_c_function_data_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func)
{
JSCFunctionDataRecord *s = JS_GetOpaque(val, JS_CLASS_C_FUNCTION_DATA);
@@ -5252,12 +5318,12 @@ static void js_c_function_data_mark(JSRuntime *rt, JSValue val,
}
}
-static JSValue js_c_function_data_call(JSContext *ctx, JSValue func_obj,
- JSValue this_val,
- int argc, JSValue *argv, int flags)
+static JSValue js_c_function_data_call(JSContext *ctx, JSValueConst func_obj,
+ JSValueConst this_val,
+ int argc, JSValueConst *argv, int flags)
{
JSCFunctionDataRecord *s = JS_GetOpaque(func_obj, JS_CLASS_C_FUNCTION_DATA);
- JSValue *arg_buf;
+ JSValueConst *arg_buf;
int i;
/* XXX: could add the function on the stack for debug */
@@ -5271,12 +5337,12 @@ static JSValue js_c_function_data_call(JSContext *ctx, JSValue func_obj,
arg_buf = argv;
}
- return s->func(ctx, this_val, argc, arg_buf, s->magic, s->data);
+ return s->func(ctx, this_val, argc, arg_buf, s->magic, vc(s->data));
}
JSValue JS_NewCFunctionData(JSContext *ctx, JSCFunctionData *func,
int length, int magic, int data_len,
- JSValue *data)
+ JSValueConst *data)
{
JSCFunctionDataRecord *s;
JSValue func_obj;
@@ -5386,33 +5452,8 @@ static force_inline JSShapeProperty *find_own_property(JSProperty **ppr,
return NULL;
}
-static force_inline JSShapeProperty* find_own_property_ic(JSProperty** ppr, JSObject* p,
- JSAtom atom, uint32_t* offset)
-{
- JSShape* sh;
- JSShapeProperty *pr, *prop;
- intptr_t h, i;
- sh = p->shape;
- h = (uintptr_t)atom & sh->prop_hash_mask;
- h = prop_hash_end(sh)[-h - 1];
- prop = get_shape_prop(sh);
- while (h) {
- i = h - 1;
- pr = &prop[i];
- if (likely(pr->atom == atom)) {
- *ppr = &p->prop[i];
- *offset = i;
- /* the compiler should be able to assume that pr != NULL here */
- return pr;
- }
- h = pr->hash_next;
- }
- *ppr = NULL;
- return NULL;
-}
-
/* indicate that the object may be part of a function prototype cycle */
-static void set_cycle_flag(JSContext *ctx, JSValue obj)
+static void set_cycle_flag(JSContext *ctx, JSValueConst obj)
{
}
@@ -5432,7 +5473,7 @@ static void free_var_ref(JSRuntime *rt, JSVarRef *var_ref)
}
}
-static void js_array_finalizer(JSRuntime *rt, JSValue val)
+static void js_array_finalizer(JSRuntime *rt, JSValueConst val)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
int i;
@@ -5443,7 +5484,7 @@ static void js_array_finalizer(JSRuntime *rt, JSValue val)
js_free_rt(rt, p->u.array.u.values);
}
-static void js_array_mark(JSRuntime *rt, JSValue val,
+static void js_array_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
@@ -5454,21 +5495,21 @@ static void js_array_mark(JSRuntime *rt, JSValue val,
}
}
-static void js_object_data_finalizer(JSRuntime *rt, JSValue val)
+static void js_object_data_finalizer(JSRuntime *rt, JSValueConst val)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
JS_FreeValueRT(rt, p->u.object_data);
p->u.object_data = JS_UNDEFINED;
}
-static void js_object_data_mark(JSRuntime *rt, JSValue val,
+static void js_object_data_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
JS_MarkValue(rt, p->u.object_data, mark_func);
}
-static void js_c_function_finalizer(JSRuntime *rt, JSValue val)
+static void js_c_function_finalizer(JSRuntime *rt, JSValueConst val)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
@@ -5476,7 +5517,7 @@ static void js_c_function_finalizer(JSRuntime *rt, JSValue val)
JS_FreeContext(p->u.cfunc.realm);
}
-static void js_c_function_mark(JSRuntime *rt, JSValue val,
+static void js_c_function_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
@@ -5485,7 +5526,7 @@ static void js_c_function_mark(JSRuntime *rt, JSValue val,
mark_func(rt, &p->u.cfunc.realm->header);
}
-static void js_bytecode_function_finalizer(JSRuntime *rt, JSValue val)
+static void js_bytecode_function_finalizer(JSRuntime *rt, JSValueConst val)
{
JSObject *p1, *p = JS_VALUE_GET_OBJ(val);
JSFunctionBytecode *b;
@@ -5508,7 +5549,7 @@ static void js_bytecode_function_finalizer(JSRuntime *rt, JSValue val)
}
}
-static void js_bytecode_function_mark(JSRuntime *rt, JSValue val,
+static void js_bytecode_function_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
@@ -5535,7 +5576,7 @@ static void js_bytecode_function_mark(JSRuntime *rt, JSValue val,
}
}
-static void js_bound_function_finalizer(JSRuntime *rt, JSValue val)
+static void js_bound_function_finalizer(JSRuntime *rt, JSValueConst val)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
JSBoundFunction *bf = p->u.bound_function;
@@ -5549,7 +5590,7 @@ static void js_bound_function_finalizer(JSRuntime *rt, JSValue val)
js_free_rt(rt, bf);
}
-static void js_bound_function_mark(JSRuntime *rt, JSValue val,
+static void js_bound_function_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
@@ -5562,7 +5603,7 @@ static void js_bound_function_mark(JSRuntime *rt, JSValue val,
JS_MarkValue(rt, bf->argv[i], mark_func);
}
-static void js_for_in_iterator_finalizer(JSRuntime *rt, JSValue val)
+static void js_for_in_iterator_finalizer(JSRuntime *rt, JSValueConst val)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
JSForInIterator *it = p->u.for_in_iterator;
@@ -5570,7 +5611,7 @@ static void js_for_in_iterator_finalizer(JSRuntime *rt, JSValue val)
js_free_rt(rt, it);
}
-static void js_for_in_iterator_mark(JSRuntime *rt, JSValue val,
+static void js_for_in_iterator_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
@@ -5685,8 +5726,8 @@ static void js_free_value_rt(JSRuntime *rt, JSValue v)
{
uint32_t tag = JS_VALUE_GET_TAG(v);
-#ifdef DUMP_FREE
- if (check_dump_flag(rt, DUMP_FREE)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_FREE
+ if (check_dump_flag(rt, JS_DUMP_FREE)) {
/* Prevent invalid object access during GC */
if ((rt->gc_phase != JS_GC_PHASE_REMOVE_CYCLES)
|| (tag != JS_TAG_OBJECT && tag != JS_TAG_FUNCTION_BYTECODE)) {
@@ -5708,7 +5749,7 @@ static void js_free_value_rt(JSRuntime *rt, JSValue v)
if (p->atom_type) {
JS_FreeAtomStruct(rt, p);
} else {
-#ifdef DUMP_LEAKS
+#ifdef ENABLE_DUMPS // JS_DUMP_LEAKS
list_del(&p->link);
#endif
js_free_rt(rt, p);
@@ -5784,7 +5825,7 @@ static void remove_gc_object(JSGCObjectHeader *h)
list_del(&h->link);
}
-void JS_MarkValue(JSRuntime *rt, JSValue val, JS_MarkFunc *mark_func)
+void JS_MarkValue(JSRuntime *rt, JSValueConst val, JS_MarkFunc *mark_func)
{
if (JS_VALUE_HAS_REF_COUNT(val)) {
switch(JS_VALUE_GET_TAG(val)) {
@@ -5848,7 +5889,6 @@ static void mark_children(JSRuntime *rt, JSGCObjectHeader *gp,
case JS_GC_OBJ_TYPE_FUNCTION_BYTECODE:
/* the template objects can be part of a cycle */
{
- JSShape **shape, *(*shapes)[IC_CACHE_ITEM_CAPACITY];
JSFunctionBytecode *b = (JSFunctionBytecode *)gp;
int i;
for(i = 0; i < b->cpool_count; i++) {
@@ -5856,14 +5896,6 @@ static void mark_children(JSRuntime *rt, JSGCObjectHeader *gp,
}
if (b->realm)
mark_func(rt, &b->realm->header);
- if (b->ic) {
- for (i = 0; i < b->ic->count; i++) {
- shapes = &b->ic->cache[i].shape;
- for (shape = *shapes; shape != endof(*shapes); shape++)
- if (*shape)
- mark_func(rt, &(*shape)->header);
- }
- }
}
break;
case JS_GC_OBJ_TYPE_VAR_REF:
@@ -6015,8 +6047,8 @@ static void gc_free_cycles(JSRuntime *rt)
{
struct list_head *el, *el1;
JSGCObjectHeader *p;
-#ifdef DUMP_GC_FREE
- BOOL header_done = FALSE;
+#ifdef ENABLE_DUMPS // JS_DUMP_GC_FREE
+ bool header_done = false;
#endif
rt->gc_phase = JS_GC_PHASE_REMOVE_CYCLES;
@@ -6032,12 +6064,12 @@ static void gc_free_cycles(JSRuntime *rt)
switch(p->gc_obj_type) {
case JS_GC_OBJ_TYPE_JS_OBJECT:
case JS_GC_OBJ_TYPE_FUNCTION_BYTECODE:
-#ifdef DUMP_GC_FREE
- if (check_dump_flag(rt, DUMP_GC_FREE)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_GC_FREE
+ if (check_dump_flag(rt, JS_DUMP_GC_FREE)) {
if (!header_done) {
printf("Freeing cycles:\n");
JS_DumpObjectHeader(rt);
- header_done = TRUE;
+ header_done = true;
}
JS_DumpGCObject(rt, p);
}
@@ -6078,11 +6110,11 @@ void JS_RunGC(JSRuntime *rt)
/* Return false if not an object or if the object has already been
freed (zombie objects are visible in finalizers when freeing
cycles). */
-BOOL JS_IsLiveObject(JSRuntime *rt, JSValue obj)
+bool JS_IsLiveObject(JSRuntime *rt, JSValueConst obj)
{
JSObject *p;
if (!JS_IsObject(obj))
- return FALSE;
+ return false;
p = JS_VALUE_GET_OBJ(obj);
return !p->free_mark;
}
@@ -6587,7 +6619,7 @@ JSValue JS_GetException(JSContext *ctx)
return val;
}
-JS_BOOL JS_HasException(JSContext *ctx)
+bool JS_HasException(JSContext *ctx)
{
return !JS_IsUninitialized(ctx->rt->current_exception);
}
@@ -6701,7 +6733,7 @@ fail:
/* in order to avoid executing arbitrary code during the stack trace
generation, we only look at simple 'name' properties containing a
string. */
-static const char *get_func_name(JSContext *ctx, JSValue func)
+static const char *get_func_name(JSContext *ctx, JSValueConst func)
{
JSProperty *pr;
JSShapeProperty *prs;
@@ -6720,6 +6752,20 @@ static const char *get_func_name(JSContext *ctx, JSValue func)
return JS_ToCString(ctx, val);
}
+/* Note: it is important that no exception is returned by this function */
+static bool can_add_backtrace(JSValueConst obj)
+{
+ JSObject *p;
+ if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)
+ return false;
+ p = JS_VALUE_GET_OBJ(obj);
+ if (p->class_id != JS_CLASS_ERROR)
+ return false;
+ if (find_own_property1(p, JS_ATOM_stack))
+ return false;
+ return true;
+}
+
#define JS_BACKTRACE_FLAG_SKIP_FIRST_LEVEL (1 << 0)
/* only taken into account if filename is provided */
#define JS_BACKTRACE_FLAG_SINGLE_LEVEL (1 << 1)
@@ -6727,9 +6773,9 @@ static const char *get_func_name(JSContext *ctx, JSValue func)
/* if filename != NULL, an additional level is added with the filename
and line number information (used for parse error). */
-static void build_backtrace(JSContext *ctx, JSValue error_obj, JSValue filter_func,
- const char *filename, int line_num, int col_num,
- int backtrace_flags)
+static void build_backtrace(JSContext *ctx, JSValueConst error_val,
+ JSValueConst filter_func, const char *filename,
+ int line_num, int col_num, int backtrace_flags)
{
JSStackFrame *sf, *sf_start;
JSValue stack, prepare, saved_exception;
@@ -6738,28 +6784,49 @@ static void build_backtrace(JSContext *ctx, JSValue error_obj, JSValue filter_fu
const char *str1;
JSObject *p;
JSFunctionBytecode *b;
- BOOL backtrace_barrier, has_prepare;
+ bool backtrace_barrier, has_prepare, has_filter_func;
JSRuntime *rt;
JSCallSiteData csd[64];
uint32_t i;
+ double d;
int stack_trace_limit;
- stack_trace_limit = ctx->error_stack_trace_limit;
+ rt = ctx->rt;
+ if (rt->in_build_stack_trace)
+ return;
+ rt->in_build_stack_trace = true;
+
+ // Save exception because conversion to double may fail.
+ saved_exception = JS_GetException(ctx);
+
+ // Extract stack trace limit.
+ // Ignore error since it sets d to NAN anyway.
+ // coverity[check_return]
+ JS_ToFloat64(ctx, &d, ctx->error_stack_trace_limit);
+ if (isnan(d) || d < 0.0)
+ stack_trace_limit = 0;
+ else if (d > INT32_MAX)
+ stack_trace_limit = INT32_MAX;
+ else
+ stack_trace_limit = fabs(d);
+
+ // Restore current exception.
+ JS_Throw(ctx, saved_exception);
+ saved_exception = JS_UNINITIALIZED;
+
stack_trace_limit = min_int(stack_trace_limit, countof(csd));
stack_trace_limit = max_int(stack_trace_limit, 0);
- rt = ctx->rt;
- has_prepare = FALSE;
+ has_prepare = false;
+ has_filter_func = backtrace_flags & JS_BACKTRACE_FLAG_FILTER_FUNC;
i = 0;
- if (!rt->in_prepare_stack_trace && !JS_IsNull(ctx->error_ctor)) {
+ if (!JS_IsNull(ctx->error_ctor)) {
prepare = js_dup(ctx->error_prepare_stack);
has_prepare = JS_IsFunction(ctx, prepare);
- rt->in_prepare_stack_trace = TRUE;
}
if (has_prepare) {
- saved_exception = rt->current_exception;
- rt->current_exception = JS_NULL;
+ saved_exception = JS_GetException(ctx);
if (stack_trace_limit == 0)
goto done;
if (filename)
@@ -6784,7 +6851,7 @@ static void build_backtrace(JSContext *ctx, JSValue error_obj, JSValue filter_fu
/* Find the frame we want to start from. Note that when a filter is used the filter
function will be the first, but we also specify we want to skip the first one. */
- if (backtrace_flags & JS_BACKTRACE_FLAG_FILTER_FUNC) {
+ if (has_filter_func) {
for (sf = sf_start; sf != NULL && i < stack_trace_limit; sf = sf->prev_frame) {
if (js_same_value(ctx, sf->cur_func, filter_func)) {
sf_start = sf;
@@ -6801,7 +6868,7 @@ static void build_backtrace(JSContext *ctx, JSValue error_obj, JSValue filter_fu
p = JS_VALUE_GET_OBJ(sf->cur_func);
b = NULL;
- backtrace_barrier = FALSE;
+ backtrace_barrier = false;
if (js_class_has_bytecode(p->class_id)) {
b = p->u.func.function_bytecode;
@@ -6820,23 +6887,24 @@ static void build_backtrace(JSContext *ctx, JSValue error_obj, JSValue filter_fu
dbuf_printf(&dbuf, " at %s", str1);
JS_FreeCString(ctx, func_name_str);
- if (b) {
+ if (b && sf->cur_pc) {
const char *atom_str;
int line_num1, col_num1;
+ uint32_t pc;
- /* Bytecode functions must have cur_pc set in the stack frame. */
- if (sf->cur_pc == NULL)
- abort();
-
- line_num1 = find_line_num(ctx, b,
- sf->cur_pc - b->byte_code_buf - 1,
- &col_num1);
+ pc = sf->cur_pc - b->byte_code_buf - 1;
+ line_num1 = find_line_num(ctx, b, pc, &col_num1);
atom_str = b->filename ? JS_AtomToCString(ctx, b->filename) : NULL;
dbuf_printf(&dbuf, " (%s", atom_str ? atom_str : "<null>");
JS_FreeCString(ctx, atom_str);
if (line_num1 != -1)
dbuf_printf(&dbuf, ":%d:%d", line_num1, col_num1);
dbuf_putc(&dbuf, ')');
+ } else if (b) {
+ // FIXME(bnoordhuis) Missing `sf->cur_pc = pc` in bytecode
+ // handler in JS_CallInternal. Almost never user observable
+ // except with intercepting JS proxies that throw exceptions.
+ dbuf_printf(&dbuf, " (missing)");
} else {
dbuf_printf(&dbuf, " (native)");
}
@@ -6871,8 +6939,8 @@ static void build_backtrace(JSContext *ctx, JSValue error_obj, JSValue filter_fu
JS_FreeValue(ctx, csd[k].func);
JS_FreeValue(ctx, csd[k].func_name);
}
- JSValue args[] = {
- error_obj,
+ JSValueConst args[] = {
+ error_val,
stack,
};
JSValue stack2 = JS_Call(ctx, prepare, ctx->error_ctor, countof(args), args);
@@ -6882,8 +6950,7 @@ static void build_backtrace(JSContext *ctx, JSValue error_obj, JSValue filter_fu
else
stack = stack2;
JS_FreeValue(ctx, prepare);
- JS_FreeValue(ctx, rt->current_exception);
- rt->current_exception = saved_exception;
+ JS_Throw(ctx, saved_exception);
} else {
if (dbuf_error(&dbuf))
stack = JS_NULL;
@@ -6892,36 +6959,34 @@ static void build_backtrace(JSContext *ctx, JSValue error_obj, JSValue filter_fu
dbuf_free(&dbuf);
}
- rt->in_prepare_stack_trace = FALSE;
- JS_DefinePropertyValue(ctx, error_obj, JS_ATOM_stack, stack, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
-}
+ if (JS_IsUndefined(ctx->error_back_trace))
+ ctx->error_back_trace = js_dup(stack);
+ if (has_filter_func || can_add_backtrace(error_val)) {
+ JS_DefinePropertyValue(ctx, error_val, JS_ATOM_stack, stack,
+ JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
+ } else {
+ JS_FreeValue(ctx, stack);
+ }
-/* Note: it is important that no exception is returned by this function */
-static BOOL is_backtrace_needed(JSContext *ctx, JSValue obj)
-{
- JSObject *p;
- if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)
- return FALSE;
- p = JS_VALUE_GET_OBJ(obj);
- if (p->class_id != JS_CLASS_ERROR)
- return FALSE;
- if (find_own_property1(p, JS_ATOM_stack))
- return FALSE;
- return TRUE;
+ rt->in_build_stack_trace = false;
}
JSValue JS_NewError(JSContext *ctx)
{
- return JS_NewObjectClass(ctx, JS_CLASS_ERROR);
+ JSValue obj = JS_NewObjectClass(ctx, JS_CLASS_ERROR);
+ if (JS_IsException(obj))
+ return JS_EXCEPTION;
+ build_backtrace(ctx, obj, JS_UNDEFINED, NULL, 0, 0, 0);
+ return obj;
}
static JSValue JS_MakeError(JSContext *ctx, JSErrorEnum error_num,
- const char *message, BOOL add_backtrace)
+ const char *message, bool add_backtrace)
{
JSValue obj, msg;
if (error_num == JS_PLAIN_ERROR) {
- obj = JS_NewError(ctx);
+ obj = JS_NewObjectClass(ctx, JS_CLASS_ERROR);
} else {
obj = JS_NewObjectProtoClass(ctx, ctx->native_error_proto[error_num],
JS_CLASS_ERROR);
@@ -6941,8 +7006,9 @@ static JSValue JS_MakeError(JSContext *ctx, JSErrorEnum error_num,
}
/* fmt and arguments may be pure ASCII or UTF-8 encoded contents */
-static JSValue JS_ThrowError2(JSContext *ctx, JSErrorEnum error_num,
- const char *fmt, va_list ap, BOOL add_backtrace)
+static JSValue JS_PRINTF_FORMAT_ATTR(4, 0)
+JS_ThrowError2(JSContext *ctx, JSErrorEnum error_num,
+ bool add_backtrace, JS_PRINTF_FORMAT const char *fmt, va_list ap)
{
char buf[256];
JSValue obj;
@@ -6956,21 +7022,22 @@ static JSValue JS_ThrowError2(JSContext *ctx, JSErrorEnum error_num,
return JS_Throw(ctx, obj);
}
-static JSValue JS_ThrowError(JSContext *ctx, JSErrorEnum error_num,
- const char *fmt, va_list ap)
+static JSValue JS_PRINTF_FORMAT_ATTR(3, 0)
+JS_ThrowError(JSContext *ctx, JSErrorEnum error_num,
+ JS_PRINTF_FORMAT const char *fmt, va_list ap)
{
JSRuntime *rt = ctx->rt;
JSStackFrame *sf;
- BOOL add_backtrace;
+ bool add_backtrace;
/* the backtrace is added later if called from a bytecode function */
sf = rt->current_stack_frame;
add_backtrace = !rt->in_out_of_memory &&
(!sf || (JS_GetFunctionBytecode(sf->cur_func) == NULL));
- return JS_ThrowError2(ctx, error_num, fmt, ap, add_backtrace);
+ return JS_ThrowError2(ctx, error_num, add_backtrace, fmt, ap);
}
-JSValue __attribute__((format(printf, 2, 3))) JS_ThrowPlainError(JSContext *ctx, const char *fmt, ...)
+JSValue JS_PRINTF_FORMAT_ATTR(2, 3) JS_ThrowPlainError(JSContext *ctx, JS_PRINTF_FORMAT const char *fmt, ...)
{
JSValue val;
va_list ap;
@@ -6981,7 +7048,7 @@ JSValue __attribute__((format(printf, 2, 3))) JS_ThrowPlainError(JSContext *ctx,
return val;
}
-JSValue __attribute__((format(printf, 2, 3))) JS_ThrowSyntaxError(JSContext *ctx, const char *fmt, ...)
+JSValue JS_PRINTF_FORMAT_ATTR(2, 3) JS_ThrowSyntaxError(JSContext *ctx, JS_PRINTF_FORMAT const char *fmt, ...)
{
JSValue val;
va_list ap;
@@ -6992,7 +7059,7 @@ JSValue __attribute__((format(printf, 2, 3))) JS_ThrowSyntaxError(JSContext *ctx
return val;
}
-JSValue __attribute__((format(printf, 2, 3))) JS_ThrowTypeError(JSContext *ctx, const char *fmt, ...)
+JSValue JS_PRINTF_FORMAT_ATTR(2, 3) JS_ThrowTypeError(JSContext *ctx, JS_PRINTF_FORMAT const char *fmt, ...)
{
JSValue val;
va_list ap;
@@ -7003,7 +7070,7 @@ JSValue __attribute__((format(printf, 2, 3))) JS_ThrowTypeError(JSContext *ctx,
return val;
}
-static int __attribute__((format(printf, 3, 4))) JS_ThrowTypeErrorOrFalse(JSContext *ctx, int flags, const char *fmt, ...)
+static int JS_PRINTF_FORMAT_ATTR(3, 4) JS_ThrowTypeErrorOrFalse(JSContext *ctx, int flags, JS_PRINTF_FORMAT const char *fmt, ...)
{
va_list ap;
@@ -7014,30 +7081,30 @@ static int __attribute__((format(printf, 3, 4))) JS_ThrowTypeErrorOrFalse(JSCont
va_end(ap);
return -1;
} else {
- return FALSE;
+ return false;
}
}
-/* never use it directly */
-static JSValue __attribute__((format(printf, 3, 4))) __JS_ThrowTypeErrorAtom(JSContext *ctx, JSAtom atom, const char *fmt, ...)
+#ifdef __GNUC__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+#endif // __GNUC__
+static JSValue JS_ThrowTypeErrorAtom(JSContext *ctx, const char *fmt, JSAtom atom)
{
char buf[ATOM_GET_STR_BUF_SIZE];
- return JS_ThrowTypeError(ctx, fmt,
- JS_AtomGetStr(ctx, buf, sizeof(buf), atom));
+ JS_AtomGetStr(ctx, buf, sizeof(buf), atom);
+ return JS_ThrowTypeError(ctx, fmt, buf);
}
-/* never use it directly */
-static JSValue __attribute__((format(printf, 3, 4))) __JS_ThrowSyntaxErrorAtom(JSContext *ctx, JSAtom atom, const char *fmt, ...)
+static JSValue JS_ThrowSyntaxErrorAtom(JSContext *ctx, const char *fmt, JSAtom atom)
{
char buf[ATOM_GET_STR_BUF_SIZE];
- return JS_ThrowSyntaxError(ctx, fmt,
- JS_AtomGetStr(ctx, buf, sizeof(buf), atom));
+ JS_AtomGetStr(ctx, buf, sizeof(buf), atom);
+ return JS_ThrowSyntaxError(ctx, fmt, buf);
}
-
-/* %s is replaced by 'atom'. The macro is used so that gcc can check
- the format string. */
-#define JS_ThrowTypeErrorAtom(ctx, fmt, atom) __JS_ThrowTypeErrorAtom(ctx, atom, fmt, "")
-#define JS_ThrowSyntaxErrorAtom(ctx, fmt, atom) __JS_ThrowSyntaxErrorAtom(ctx, atom, fmt, "")
+#ifdef __GNUC__
+#pragma GCC diagnostic pop // ignored "-Wformat-nonliteral"
+#endif // __GNUC__
static int JS_ThrowTypeErrorReadOnly(JSContext *ctx, int flags, JSAtom atom)
{
@@ -7046,11 +7113,11 @@ static int JS_ThrowTypeErrorReadOnly(JSContext *ctx, int flags, JSAtom atom)
JS_ThrowTypeErrorAtom(ctx, "'%s' is read-only", atom);
return -1;
} else {
- return FALSE;
+ return false;
}
}
-JSValue __attribute__((format(printf, 2, 3))) JS_ThrowReferenceError(JSContext *ctx, const char *fmt, ...)
+JSValue JS_PRINTF_FORMAT_ATTR(2, 3) JS_ThrowReferenceError(JSContext *ctx, JS_PRINTF_FORMAT const char *fmt, ...)
{
JSValue val;
va_list ap;
@@ -7061,7 +7128,7 @@ JSValue __attribute__((format(printf, 2, 3))) JS_ThrowReferenceError(JSContext *
return val;
}
-JSValue __attribute__((format(printf, 2, 3))) JS_ThrowRangeError(JSContext *ctx, const char *fmt, ...)
+JSValue JS_PRINTF_FORMAT_ATTR(2, 3) JS_ThrowRangeError(JSContext *ctx, JS_PRINTF_FORMAT const char *fmt, ...)
{
JSValue val;
va_list ap;
@@ -7072,7 +7139,7 @@ JSValue __attribute__((format(printf, 2, 3))) JS_ThrowRangeError(JSContext *ctx,
return val;
}
-JSValue __attribute__((format(printf, 2, 3))) JS_ThrowInternalError(JSContext *ctx, const char *fmt, ...)
+JSValue JS_PRINTF_FORMAT_ATTR(2, 3) JS_ThrowInternalError(JSContext *ctx, JS_PRINTF_FORMAT const char *fmt, ...)
{
JSValue val;
va_list ap;
@@ -7087,9 +7154,9 @@ JSValue JS_ThrowOutOfMemory(JSContext *ctx)
{
JSRuntime *rt = ctx->rt;
if (!rt->in_out_of_memory) {
- rt->in_out_of_memory = TRUE;
+ rt->in_out_of_memory = true;
JS_ThrowInternalError(ctx, "out of memory");
- rt->in_out_of_memory = FALSE;
+ rt->in_out_of_memory = false;
}
return JS_EXCEPTION;
}
@@ -7099,6 +7166,11 @@ static JSValue JS_ThrowStackOverflow(JSContext *ctx)
return JS_ThrowRangeError(ctx, "Maximum call stack size exceeded");
}
+static JSValue JS_ThrowTypeErrorNotAFunction(JSContext *ctx)
+{
+ return JS_ThrowTypeError(ctx, "not a function");
+}
+
static JSValue JS_ThrowTypeErrorNotAnObject(JSContext *ctx)
{
return JS_ThrowTypeError(ctx, "not an object");
@@ -7126,7 +7198,7 @@ static JSValue JS_ThrowReferenceErrorUninitialized(JSContext *ctx, JSAtom name)
static JSValue JS_ThrowReferenceErrorUninitialized2(JSContext *ctx,
JSFunctionBytecode *b,
- int idx, BOOL is_ref)
+ int idx, bool is_ref)
{
JSAtom atom = JS_ATOM_NULL;
if (is_ref) {
@@ -7155,7 +7227,7 @@ static no_inline __exception int __js_poll_interrupts(JSContext *ctx)
if (rt->interrupt_handler(rt, rt->interrupt_opaque)) {
/* XXX: should set a specific flag to avoid catching */
JS_ThrowInternalError(ctx, "interrupted");
- JS_SetUncatchableError(ctx, ctx->rt->current_exception, TRUE);
+ js_set_uncatchable_error(ctx, ctx->rt->current_exception, true);
return -1;
}
}
@@ -7171,10 +7243,9 @@ static inline __exception int js_poll_interrupts(JSContext *ctx)
}
}
-/* return -1 (exception) or TRUE/FALSE */
-static int JS_SetPrototypeInternal(JSContext *ctx, JSValue obj,
- JSValue proto_val,
- BOOL throw_flag)
+/* return -1 (exception) or true/false */
+static int JS_SetPrototypeInternal(JSContext *ctx, JSValueConst obj,
+ JSValueConst proto_val, bool throw_flag)
{
JSObject *proto, *p, *p1;
JSShape *sh;
@@ -7200,26 +7271,26 @@ static int JS_SetPrototypeInternal(JSContext *ctx, JSValue obj,
}
if (throw_flag && JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)
- return TRUE;
+ return true;
if (unlikely(p->class_id == JS_CLASS_PROXY))
return js_proxy_setPrototypeOf(ctx, obj, proto_val, throw_flag);
sh = p->shape;
if (sh->proto == proto)
- return TRUE;
+ return true;
if (p == JS_VALUE_GET_OBJ(ctx->class_proto[JS_CLASS_OBJECT])) {
if (throw_flag) {
JS_ThrowTypeError(ctx, "'Immutable prototype object \'Object.prototype\' cannot have their prototype set'");
return -1;
}
- return FALSE;
+ return false;
}
if (!p->extensible) {
if (throw_flag) {
JS_ThrowTypeError(ctx, "object is not extensible");
return -1;
} else {
- return FALSE;
+ return false;
}
}
if (proto) {
@@ -7231,7 +7302,7 @@ static int JS_SetPrototypeInternal(JSContext *ctx, JSValue obj,
JS_ThrowTypeError(ctx, "circular prototype chain");
return -1;
} else {
- return FALSE;
+ return false;
}
}
/* Note: for Proxy objects, proto is NULL */
@@ -7246,47 +7317,48 @@ static int JS_SetPrototypeInternal(JSContext *ctx, JSValue obj,
if (sh->proto)
JS_FreeValue(ctx, JS_MKPTR(JS_TAG_OBJECT, sh->proto));
sh->proto = proto;
- return TRUE;
+ return true;
}
-/* return -1 (exception) or TRUE/FALSE */
-int JS_SetPrototype(JSContext *ctx, JSValue obj, JSValue proto_val)
+/* return -1 (exception) or true/false */
+int JS_SetPrototype(JSContext *ctx, JSValueConst obj, JSValue proto_val)
{
- return JS_SetPrototypeInternal(ctx, obj, proto_val, TRUE);
+ return JS_SetPrototypeInternal(ctx, obj, proto_val, true);
}
/* Only works for primitive types, otherwise return JS_NULL. */
-static JSValue JS_GetPrototypePrimitive(JSContext *ctx, JSValue val)
+static JSValueConst JS_GetPrototypePrimitive(JSContext *ctx, JSValueConst val)
{
+ JSValue ret;
switch(JS_VALUE_GET_NORM_TAG(val)) {
case JS_TAG_BIG_INT:
- val = ctx->class_proto[JS_CLASS_BIG_INT];
+ ret = ctx->class_proto[JS_CLASS_BIG_INT];
break;
case JS_TAG_INT:
case JS_TAG_FLOAT64:
- val = ctx->class_proto[JS_CLASS_NUMBER];
+ ret = ctx->class_proto[JS_CLASS_NUMBER];
break;
case JS_TAG_BOOL:
- val = ctx->class_proto[JS_CLASS_BOOLEAN];
+ ret = ctx->class_proto[JS_CLASS_BOOLEAN];
break;
case JS_TAG_STRING:
- val = ctx->class_proto[JS_CLASS_STRING];
+ ret = ctx->class_proto[JS_CLASS_STRING];
break;
case JS_TAG_SYMBOL:
- val = ctx->class_proto[JS_CLASS_SYMBOL];
+ ret = ctx->class_proto[JS_CLASS_SYMBOL];
break;
case JS_TAG_OBJECT:
case JS_TAG_NULL:
case JS_TAG_UNDEFINED:
default:
- val = JS_NULL;
+ ret = JS_NULL;
break;
}
- return val;
+ return ret;
}
/* Return an Object, JS_NULL or JS_EXCEPTION in case of Proxy object. */
-JSValue JS_GetPrototype(JSContext *ctx, JSValue obj)
+JSValue JS_GetPrototype(JSContext *ctx, JSValueConst obj)
{
JSValue val;
if (JS_VALUE_GET_TAG(obj) == JS_TAG_OBJECT) {
@@ -7315,25 +7387,25 @@ static JSValue JS_GetPrototypeFree(JSContext *ctx, JSValue obj)
return obj1;
}
-int JS_GetLength(JSContext *ctx, JSValue obj, int64_t *pres) {
+int JS_GetLength(JSContext *ctx, JSValueConst obj, int64_t *pres) {
return js_get_length64(ctx, pres, obj);
}
-int JS_SetLength(JSContext *ctx, JSValue obj, int64_t len) {
+int JS_SetLength(JSContext *ctx, JSValueConst obj, int64_t len) {
return js_set_length64(ctx, obj, len);
}
-/* return TRUE, FALSE or (-1) in case of exception */
-static int JS_OrdinaryIsInstanceOf(JSContext *ctx, JSValue val,
- JSValue obj)
+/* return true, false or (-1) in case of exception */
+static int JS_OrdinaryIsInstanceOf(JSContext *ctx, JSValueConst val,
+ JSValueConst obj)
{
JSValue obj_proto;
JSObject *proto;
const JSObject *p, *proto1;
- BOOL ret;
+ int ret;
if (!JS_IsFunction(ctx, obj))
- return FALSE;
+ return false;
p = JS_VALUE_GET_OBJ(obj);
if (p->class_id == JS_CLASS_BOUND_FUNCTION) {
JSBoundFunction *s = p->u.bound_function;
@@ -7342,7 +7414,7 @@ static int JS_OrdinaryIsInstanceOf(JSContext *ctx, JSValue val,
/* Only explicitly boxed values are instances of constructors */
if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT)
- return FALSE;
+ return false;
obj_proto = JS_GetProperty(ctx, obj, JS_ATOM_prototype);
if (JS_VALUE_GET_TAG(obj_proto) != JS_TAG_OBJECT) {
if (!JS_IsException(obj_proto))
@@ -7366,12 +7438,12 @@ static int JS_OrdinaryIsInstanceOf(JSContext *ctx, JSValue val,
break;
}
if (JS_IsNull(obj1)) {
- ret = FALSE;
+ ret = false;
break;
}
if (proto == JS_VALUE_GET_OBJ(obj1)) {
JS_FreeValue(ctx, obj1);
- ret = TRUE;
+ ret = true;
break;
}
/* must check for timeout to avoid infinite loop */
@@ -7382,13 +7454,13 @@ static int JS_OrdinaryIsInstanceOf(JSContext *ctx, JSValue val,
}
}
} else {
- ret = FALSE;
+ ret = false;
}
break;
}
p = proto1;
if (proto == p) {
- ret = TRUE;
+ ret = true;
break;
}
}
@@ -7397,8 +7469,8 @@ done:
return ret;
}
-/* return TRUE, FALSE or (-1) in case of exception */
-int JS_IsInstanceOf(JSContext *ctx, JSValue val, JSValue obj)
+/* return true, false or (-1) in case of exception */
+int JS_IsInstanceOf(JSContext *ctx, JSValueConst val, JSValueConst obj)
{
JSValue method;
@@ -7455,17 +7527,16 @@ static int JS_AutoInitProperty(JSContext *ctx, JSObject *p, JSAtom prop,
return 0;
}
-static JSValue JS_GetPropertyInternal2(JSContext *ctx, JSValue obj,
- JSAtom prop, JSValue this_obj,
- JSInlineCacheUpdate *icu,
- BOOL throw_ref_error)
+static JSValue JS_GetPropertyInternal(JSContext *ctx, JSValueConst obj,
+ JSAtom prop, JSValueConst this_obj,
+ bool throw_ref_error)
{
JSObject *p;
JSProperty *pr;
JSShapeProperty *prs;
- uint32_t tag, offset, proto_depth;
+ uint32_t tag, proto_depth;
- offset = proto_depth = 0;
+ proto_depth = 0;
tag = JS_VALUE_GET_TAG(obj);
if (unlikely(tag != JS_TAG_OBJECT)) {
switch(tag) {
@@ -7502,7 +7573,7 @@ static JSValue JS_GetPropertyInternal2(JSContext *ctx, JSValue obj,
}
for(;;) {
- prs = find_own_property_ic(&pr, p, prop, &offset);
+ prs = find_own_property(&pr, p, prop);
if (prs) {
/* found */
if (unlikely(prs->flags & JS_PROP_TMASK)) {
@@ -7527,8 +7598,6 @@ static JSValue JS_GetPropertyInternal2(JSContext *ctx, JSValue obj,
continue;
}
} else {
- if (proto_depth == 0)
- add_ic_slot(ctx, icu, prop, p, offset);
return js_dup(pr->u.value);
}
}
@@ -7540,12 +7609,10 @@ static JSValue JS_GetPropertyInternal2(JSContext *ctx, JSValue obj,
if (idx < p->u.array.count) {
/* we avoid duplicating the code */
return JS_GetPropertyUint32(ctx, JS_MKPTR(JS_TAG_OBJECT, p), idx);
- } else if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&
- p->class_id <= JS_CLASS_FLOAT64_ARRAY) {
+ } else if (is_typed_array(p->class_id)) {
return JS_UNDEFINED;
}
- } else if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&
- p->class_id <= JS_CLASS_FLOAT64_ARRAY) {
+ } else if (is_typed_array(p->class_id)) {
int ret;
ret = JS_AtomIsNumericIndex(ctx, prop);
if (ret != 0) {
@@ -7603,34 +7670,9 @@ static JSValue JS_GetPropertyInternal2(JSContext *ctx, JSValue obj,
}
}
-static JSValue JS_GetPropertyInternal(JSContext *ctx, JSValue obj,
- JSAtom prop, JSValue this_obj,
- BOOL throw_ref_error)
-{
- return JS_GetPropertyInternal2(ctx, obj, prop, this_obj, NULL, throw_ref_error);
-}
-
-JSValue JS_GetProperty(JSContext *ctx, JSValue this_obj, JSAtom prop)
-{
- return JS_GetPropertyInternal2(ctx, this_obj, prop, this_obj, NULL, FALSE);
-}
-
-static JSValue JS_GetPropertyInternalWithIC(JSContext *ctx, JSValue obj,
- JSAtom prop, JSValue this_obj,
- JSInlineCacheUpdate *icu,
- BOOL throw_ref_error)
+JSValue JS_GetProperty(JSContext *ctx, JSValueConst this_obj, JSAtom prop)
{
- uint32_t tag, offset;
- JSObject *p;
- tag = JS_VALUE_GET_TAG(obj);
- if (unlikely(tag != JS_TAG_OBJECT))
- goto slow_path;
- p = JS_VALUE_GET_OBJ(obj);
- offset = get_ic_prop_offset(icu, p->shape);
- if (likely(offset != INLINE_CACHE_MISS))
- return js_dup(p->prop[offset].u.value);
-slow_path:
- return JS_GetPropertyInternal2(ctx, obj, prop, this_obj, icu, throw_ref_error);
+ return JS_GetPropertyInternal(ctx, this_obj, prop, this_obj, false);
}
static JSValue JS_ThrowTypeErrorPrivateNotFound(JSContext *ctx, JSAtom atom)
@@ -7641,7 +7683,7 @@ static JSValue JS_ThrowTypeErrorPrivateNotFound(JSContext *ctx, JSAtom atom)
/* Private fields can be added even on non extensible objects or
Proxies */
-static int JS_DefinePrivateField(JSContext *ctx, JSValue obj,
+static int JS_DefinePrivateField(JSContext *ctx, JSValueConst obj,
JSValue name, JSValue val)
{
JSObject *p;
@@ -7676,8 +7718,8 @@ static int JS_DefinePrivateField(JSContext *ctx, JSValue obj,
return 0;
}
-static JSValue JS_GetPrivateField(JSContext *ctx, JSValue obj,
- JSValue name)
+static JSValue JS_GetPrivateField(JSContext *ctx, JSValueConst obj,
+ JSValueConst name)
{
JSObject *p;
JSShapeProperty *prs;
@@ -7699,8 +7741,8 @@ static JSValue JS_GetPrivateField(JSContext *ctx, JSValue obj,
return js_dup(pr->u.value);
}
-static int JS_SetPrivateField(JSContext *ctx, JSValue obj,
- JSValue name, JSValue val)
+static int JS_SetPrivateField(JSContext *ctx, JSValueConst obj,
+ JSValueConst name, JSValue val)
{
JSObject *p;
JSShapeProperty *prs;
@@ -7731,7 +7773,7 @@ static int JS_SetPrivateField(JSContext *ctx, JSValue obj,
/* add a private brand field to 'home_obj' if not already present and
if obj is != null add a private brand to it */
-static int JS_AddBrand(JSContext *ctx, JSValue obj, JSValue home_obj)
+static int JS_AddBrand(JSContext *ctx, JSValueConst obj, JSValueConst home_obj)
{
JSObject *p, *p1;
JSShapeProperty *prs;
@@ -7820,8 +7862,7 @@ static int JS_CheckBrand(JSContext *ctx, JSValue obj, JSValue func)
return (prs != NULL);
}
-static uint32_t js_string_obj_get_length(JSContext *ctx,
- JSValue obj)
+static uint32_t js_string_obj_get_length(JSContext *ctx, JSValueConst obj)
{
JSObject *p;
JSString *p1;
@@ -7842,7 +7883,7 @@ static int num_keys_cmp(const void *p1, const void *p2, void *opaque)
JSAtom atom1 = ((const JSPropertyEnum *)p1)->atom;
JSAtom atom2 = ((const JSPropertyEnum *)p2)->atom;
uint32_t v1, v2;
- BOOL atom1_is_integer, atom2_is_integer;
+ bool atom1_is_integer, atom2_is_integer;
atom1_is_integer = JS_AtomIsArrayIndex(ctx, &v1, atom1);
atom2_is_integer = JS_AtomIsArrayIndex(ctx, &v2, atom2);
@@ -7879,7 +7920,7 @@ static int __exception JS_GetOwnPropertyNamesInternal(JSContext *ctx,
JSAtom atom;
uint32_t num_keys_count, str_keys_count, sym_keys_count, atom_count;
uint32_t num_index, str_index, sym_index, exotic_count, exotic_keys_count;
- BOOL is_enumerable, num_sorted;
+ bool is_enumerable, num_sorted;
uint32_t num_key;
JSAtomKindEnum kind;
@@ -7942,7 +7983,7 @@ static int __exception JS_GetOwnPropertyNamesInternal(JSContext *ctx,
atom = tab_exotic[i].atom;
kind = JS_AtomGetKind(ctx, atom);
if (((flags >> kind) & 1) != 0) {
- is_enumerable = FALSE;
+ is_enumerable = false;
if (flags & (JS_GPN_SET_ENUM | JS_GPN_ENUM_ONLY)) {
JSPropertyDescriptor desc;
int res;
@@ -7982,7 +8023,7 @@ static int __exception JS_GetOwnPropertyNamesInternal(JSContext *ctx,
str_index = num_keys_count;
sym_index = str_index + str_keys_count;
- num_sorted = TRUE;
+ num_sorted = true;
sh = p->shape;
for(i = 0, prs = get_shape_prop(sh); i < sh->prop_count; i++, prs++) {
atom = prs->atom;
@@ -7993,7 +8034,7 @@ static int __exception JS_GetOwnPropertyNamesInternal(JSContext *ctx,
((flags >> kind) & 1) != 0) {
if (JS_AtomIsArrayIndex(ctx, &num_key, atom)) {
j = num_index++;
- num_sorted = FALSE;
+ num_sorted = false;
} else if (kind == JS_ATOM_KIND_STRING) {
j = str_index++;
} else {
@@ -8022,7 +8063,7 @@ static int __exception JS_GetOwnPropertyNamesInternal(JSContext *ctx,
js_free_prop_enum(ctx, tab_atom, num_index);
return -1;
}
- tab_atom[num_index].is_enumerable = TRUE;
+ tab_atom[num_index].is_enumerable = true;
num_index++;
}
}
@@ -8059,7 +8100,7 @@ static int __exception JS_GetOwnPropertyNamesInternal(JSContext *ctx,
}
int JS_GetOwnPropertyNames(JSContext *ctx, JSPropertyEnum **ptab,
- uint32_t *plen, JSValue obj, int flags)
+ uint32_t *plen, JSValueConst obj, int flags)
{
if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT) {
JS_ThrowTypeErrorNotAnObject(ctx);
@@ -8070,7 +8111,7 @@ int JS_GetOwnPropertyNames(JSContext *ctx, JSPropertyEnum **ptab,
}
/* Return -1 if exception,
- FALSE if the property does not exist, TRUE if it exists. If TRUE is
+ false if the property does not exist, true if it exists. If true is
returned, the property descriptor 'desc' is filled present. */
static int JS_GetOwnPropertyInternal(JSContext *ctx, JSPropertyDescriptor *desc,
JSObject *p, JSAtom prop)
@@ -8120,7 +8161,7 @@ retry:
/* nothing to do: delay instantiation until actual value and/or attributes are read */
}
}
- return TRUE;
+ return true;
}
if (p->is_exotic) {
if (p->fast_array) {
@@ -8136,7 +8177,7 @@ retry:
desc->setter = JS_UNDEFINED;
desc->value = JS_GetPropertyUint32(ctx, JS_MKPTR(JS_TAG_OBJECT, p), idx);
}
- return TRUE;
+ return true;
}
}
} else {
@@ -8147,11 +8188,11 @@ retry:
}
}
}
- return FALSE;
+ return false;
}
int JS_GetOwnProperty(JSContext *ctx, JSPropertyDescriptor *desc,
- JSValue obj, JSAtom prop)
+ JSValueConst obj, JSAtom prop)
{
if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT) {
JS_ThrowTypeErrorNotAnObject(ctx);
@@ -8166,13 +8207,13 @@ void JS_FreePropertyEnum(JSContext *ctx, JSPropertyEnum *tab,
js_free_prop_enum(ctx, tab, len);
}
-/* return -1 if exception (Proxy object only) or TRUE/FALSE */
-int JS_IsExtensible(JSContext *ctx, JSValue obj)
+/* return -1 if exception (Proxy object only) or true/false */
+int JS_IsExtensible(JSContext *ctx, JSValueConst obj)
{
JSObject *p;
if (unlikely(JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT))
- return FALSE;
+ return false;
p = JS_VALUE_GET_OBJ(obj);
if (unlikely(p->class_id == JS_CLASS_PROXY))
return js_proxy_isExtensible(ctx, obj);
@@ -8180,29 +8221,29 @@ int JS_IsExtensible(JSContext *ctx, JSValue obj)
return p->extensible;
}
-/* return -1 if exception (Proxy object only) or TRUE/FALSE */
-int JS_PreventExtensions(JSContext *ctx, JSValue obj)
+/* return -1 if exception (Proxy object only) or true/false */
+int JS_PreventExtensions(JSContext *ctx, JSValueConst obj)
{
JSObject *p;
if (unlikely(JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT))
- return FALSE;
+ return false;
p = JS_VALUE_GET_OBJ(obj);
if (unlikely(p->class_id == JS_CLASS_PROXY))
return js_proxy_preventExtensions(ctx, obj);
- p->extensible = FALSE;
- return TRUE;
+ p->extensible = false;
+ return true;
}
-/* return -1 if exception otherwise TRUE or FALSE */
-int JS_HasProperty(JSContext *ctx, JSValue obj, JSAtom prop)
+/* return -1 if exception otherwise true or false */
+int JS_HasProperty(JSContext *ctx, JSValueConst obj, JSAtom prop)
{
JSObject *p;
int ret;
JSValue obj1;
if (unlikely(JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT))
- return FALSE;
+ return false;
p = JS_VALUE_GET_OBJ(obj);
for(;;) {
if (p->is_exotic) {
@@ -8221,31 +8262,30 @@ int JS_HasProperty(JSContext *ctx, JSValue obj, JSAtom prop)
JS_FreeValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p));
if (ret != 0)
return ret;
- if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&
- p->class_id <= JS_CLASS_FLOAT64_ARRAY) {
+ if (is_typed_array(p->class_id)) {
ret = JS_AtomIsNumericIndex(ctx, prop);
if (ret != 0) {
if (ret < 0)
return -1;
- return FALSE;
+ return false;
}
}
p = p->shape->proto;
if (!p)
break;
}
- return FALSE;
+ return false;
}
/* val must be a symbol */
-static JSAtom js_symbol_to_atom(JSContext *ctx, JSValue val)
+static JSAtom js_symbol_to_atom(JSContext *ctx, JSValueConst val)
{
JSAtomStruct *p = JS_VALUE_GET_PTR(val);
return js_get_atom_index(ctx->rt, p);
}
/* return JS_ATOM_NULL in case of exception */
-JSAtom JS_ValueToAtom(JSContext *ctx, JSValue val)
+JSAtom JS_ValueToAtom(JSContext *ctx, JSValueConst val)
{
JSAtom atom;
uint32_t tag;
@@ -8271,66 +8311,66 @@ JSAtom JS_ValueToAtom(JSContext *ctx, JSValue val)
return atom;
}
-static BOOL js_get_fast_array_element(JSContext *ctx, JSObject *p,
+static bool js_get_fast_array_element(JSContext *ctx, JSObject *p,
uint32_t idx, JSValue *pval)
{
switch(p->class_id) {
case JS_CLASS_ARRAY:
case JS_CLASS_ARGUMENTS:
- if (unlikely(idx >= p->u.array.count)) return FALSE;
+ if (unlikely(idx >= p->u.array.count)) return false;
*pval = js_dup(p->u.array.u.values[idx]);
- return TRUE;
+ return true;
case JS_CLASS_INT8_ARRAY:
- if (unlikely(idx >= p->u.array.count)) return FALSE;
+ if (unlikely(idx >= p->u.array.count)) return false;
*pval = js_int32(p->u.array.u.int8_ptr[idx]);
- return TRUE;
+ return true;
case JS_CLASS_UINT8C_ARRAY:
case JS_CLASS_UINT8_ARRAY:
- if (unlikely(idx >= p->u.array.count)) return FALSE;
+ if (unlikely(idx >= p->u.array.count)) return false;
*pval = js_int32(p->u.array.u.uint8_ptr[idx]);
- return TRUE;
+ return true;
case JS_CLASS_INT16_ARRAY:
- if (unlikely(idx >= p->u.array.count)) return FALSE;
+ if (unlikely(idx >= p->u.array.count)) return false;
*pval = js_int32(p->u.array.u.int16_ptr[idx]);
- return TRUE;
+ return true;
case JS_CLASS_UINT16_ARRAY:
- if (unlikely(idx >= p->u.array.count)) return FALSE;
+ if (unlikely(idx >= p->u.array.count)) return false;
*pval = js_int32(p->u.array.u.uint16_ptr[idx]);
- return TRUE;
+ return true;
case JS_CLASS_INT32_ARRAY:
- if (unlikely(idx >= p->u.array.count)) return FALSE;
+ if (unlikely(idx >= p->u.array.count)) return false;
*pval = js_int32(p->u.array.u.int32_ptr[idx]);
- return TRUE;
+ return true;
case JS_CLASS_UINT32_ARRAY:
- if (unlikely(idx >= p->u.array.count)) return FALSE;
+ if (unlikely(idx >= p->u.array.count)) return false;
*pval = js_uint32(p->u.array.u.uint32_ptr[idx]);
- return TRUE;
+ return true;
case JS_CLASS_BIG_INT64_ARRAY:
- if (unlikely(idx >= p->u.array.count)) return FALSE;
+ if (unlikely(idx >= p->u.array.count)) return false;
*pval = JS_NewBigInt64(ctx, p->u.array.u.int64_ptr[idx]);
- return TRUE;
+ return true;
case JS_CLASS_BIG_UINT64_ARRAY:
- if (unlikely(idx >= p->u.array.count)) return FALSE;
+ if (unlikely(idx >= p->u.array.count)) return false;
*pval = JS_NewBigUint64(ctx, p->u.array.u.uint64_ptr[idx]);
- return TRUE;
+ return true;
case JS_CLASS_FLOAT16_ARRAY:
- if (unlikely(idx >= p->u.array.count)) return FALSE;
+ if (unlikely(idx >= p->u.array.count)) return false;
*pval = js_float64(fromfp16(p->u.array.u.fp16_ptr[idx]));
- return TRUE;
+ return true;
case JS_CLASS_FLOAT32_ARRAY:
- if (unlikely(idx >= p->u.array.count)) return FALSE;
+ if (unlikely(idx >= p->u.array.count)) return false;
*pval = js_float64(p->u.array.u.float_ptr[idx]);
- return TRUE;
+ return true;
case JS_CLASS_FLOAT64_ARRAY:
- if (unlikely(idx >= p->u.array.count)) return FALSE;
+ if (unlikely(idx >= p->u.array.count)) return false;
*pval = js_float64(p->u.array.u.double_ptr[idx]);
- return TRUE;
+ return true;
default:
- return FALSE;
+ return false;
}
}
-static JSValue JS_GetPropertyValue(JSContext *ctx, JSValue this_obj,
+static JSValue JS_GetPropertyValue(JSContext *ctx, JSValueConst this_obj,
JSValue prop)
{
JSAtom atom;
@@ -8366,7 +8406,7 @@ static JSValue JS_GetPropertyValue(JSContext *ctx, JSValue this_obj,
return ret;
}
-JSValue JS_GetPropertyUint32(JSContext *ctx, JSValue this_obj,
+JSValue JS_GetPropertyUint32(JSContext *ctx, JSValueConst this_obj,
uint32_t idx)
{
return JS_GetPropertyInt64(ctx, this_obj, idx);
@@ -8374,10 +8414,10 @@ JSValue JS_GetPropertyUint32(JSContext *ctx, JSValue this_obj,
/* Check if an object has a generalized numeric property. Return value:
-1 for exception, *pval set to JS_EXCEPTION
- TRUE if property exists, stored into *pval,
- FALSE if property does not exist. *pval set to JS_UNDEFINED.
+ true if property exists, stored into *pval,
+ false if property does not exist. *pval set to JS_UNDEFINED.
*/
-static int JS_TryGetPropertyInt64(JSContext *ctx, JSValue obj, int64_t idx, JSValue *pval)
+static int JS_TryGetPropertyInt64(JSContext *ctx, JSValueConst obj, int64_t idx, JSValue *pval)
{
JSValue val;
JSAtom prop;
@@ -8388,7 +8428,7 @@ static int JS_TryGetPropertyInt64(JSContext *ctx, JSValue obj, int64_t idx, JSVa
/* fast path for array and typed array access */
JSObject *p = JS_VALUE_GET_OBJ(obj);
if (js_get_fast_array_element(ctx, p, idx, pval))
- return TRUE;
+ return true;
}
val = JS_EXCEPTION;
present = -1;
@@ -8399,7 +8439,7 @@ static int JS_TryGetPropertyInt64(JSContext *ctx, JSValue obj, int64_t idx, JSVa
val = JS_GetProperty(ctx, obj, prop);
if (unlikely(JS_IsException(val)))
present = -1;
- } else if (present == FALSE) {
+ } else if (present == false) {
val = JS_UNDEFINED;
}
JS_FreeAtom(ctx, prop);
@@ -8408,7 +8448,7 @@ static int JS_TryGetPropertyInt64(JSContext *ctx, JSValue obj, int64_t idx, JSVa
return present;
}
-JSValue JS_GetPropertyInt64(JSContext *ctx, JSValue obj, int64_t idx)
+JSValue JS_GetPropertyInt64(JSContext *ctx, JSValueConst obj, int64_t idx)
{
JSAtom prop;
JSValue val;
@@ -8430,7 +8470,7 @@ JSValue JS_GetPropertyInt64(JSContext *ctx, JSValue obj, int64_t idx)
}
/* `prop` may be pure ASCII or UTF-8 encoded */
-JSValue JS_GetPropertyStr(JSContext *ctx, JSValue this_obj,
+JSValue JS_GetPropertyStr(JSContext *ctx, JSValueConst this_obj,
const char *prop)
{
JSAtom atom;
@@ -8472,7 +8512,7 @@ static JSProperty *add_property(JSContext *ctx,
if (!new_sh)
return NULL;
/* hash the cloned shape */
- new_sh->is_hashed = TRUE;
+ new_sh->is_hashed = true;
js_shape_hash_link(ctx->rt, new_sh);
js_free_shape(ctx->rt, p->shape);
p->shape = new_sh;
@@ -8540,7 +8580,7 @@ static int delete_property(JSContext *ctx, JSObject *p, JSAtom atom)
if (likely(pr->atom == atom)) {
/* found ! */
if (!(pr->flags & JS_PROP_CONFIGURABLE))
- return FALSE;
+ return false;
/* realloc the shape if needed */
if (lpr)
lpr_idx = lpr - get_shape_prop(sh);
@@ -8569,7 +8609,7 @@ static int delete_property(JSContext *ctx, JSObject *p, JSAtom atom)
sh->deleted_prop_count >= ((unsigned)sh->prop_count / 2)) {
compact_properties(ctx, p);
}
- return TRUE;
+ return true;
}
lpr = pr;
h = pr->hash_next;
@@ -8586,13 +8626,13 @@ static int delete_property(JSContext *ctx, JSObject *p, JSAtom atom)
if (idx == p->u.array.count - 1) {
JS_FreeValue(ctx, p->u.array.u.values[idx]);
p->u.array.count = idx;
- return TRUE;
+ return true;
}
if (convert_fast_array_to_array(ctx, p))
return -1;
goto redo;
} else {
- return FALSE;
+ return false;
}
}
} else {
@@ -8603,23 +8643,23 @@ static int delete_property(JSContext *ctx, JSObject *p, JSAtom atom)
}
}
/* not found */
- return TRUE;
+ return true;
}
static int call_setter(JSContext *ctx, JSObject *setter,
- JSValue this_obj, JSValue val, int flags)
+ JSValueConst this_obj, JSValue val, int flags)
{
JSValue ret, func;
if (likely(setter)) {
func = JS_MKPTR(JS_TAG_OBJECT, setter);
/* Note: the field could be removed in the setter */
func = js_dup(func);
- ret = JS_CallFree(ctx, func, this_obj, 1, &val);
+ ret = JS_CallFree(ctx, func, this_obj, 1, vc(&val));
JS_FreeValue(ctx, val);
if (JS_IsException(ret))
return -1;
JS_FreeValue(ctx, ret);
- return TRUE;
+ return true;
} else {
JS_FreeValue(ctx, val);
if ((flags & JS_PROP_THROW) ||
@@ -8627,7 +8667,7 @@ static int call_setter(JSContext *ctx, JSObject *setter,
JS_ThrowTypeError(ctx, "no setter for property");
return -1;
}
- return FALSE;
+ return false;
}
}
@@ -8639,7 +8679,7 @@ static int set_array_length(JSContext *ctx, JSObject *p, JSValue val,
int i, ret;
/* Note: this call can reallocate the properties of 'p' */
- ret = JS_ToArrayLengthFree(ctx, &len, val, FALSE);
+ ret = JS_ToArrayLengthFree(ctx, &len, val, false);
if (ret)
return -1;
/* JS_ToArrayLengthFree() must be done before the read-only test */
@@ -8719,7 +8759,7 @@ static int set_array_length(JSContext *ctx, JSObject *p, JSValue val,
return JS_ThrowTypeErrorOrFalse(ctx, flags, "not configurable");
}
}
- return TRUE;
+ return true;
}
/* return -1 if exception */
@@ -8740,7 +8780,7 @@ static int expand_fast_array(JSContext *ctx, JSObject *p, uint32_t new_len)
}
/* Preconditions: 'p' must be of class JS_CLASS_ARRAY, p->fast_array =
- TRUE and p->extensible = TRUE */
+ true and p->extensible = true */
static int add_fast_array_element(JSContext *ctx, JSObject *p,
JSValue val, int flags)
{
@@ -8768,7 +8808,7 @@ static int add_fast_array_element(JSContext *ctx, JSObject *p,
}
p->u.array.u.values[new_len - 1] = val;
p->u.array.count = new_len;
- return TRUE;
+ return true;
}
static void js_free_desc(JSContext *ctx, JSPropertyDescriptor *desc)
@@ -8778,22 +8818,20 @@ static void js_free_desc(JSContext *ctx, JSPropertyDescriptor *desc)
JS_FreeValue(ctx, desc->value);
}
-/* return -1 in case of exception or TRUE or FALSE. Warning: 'val' is
+/* return -1 in case of exception or true or false. Warning: 'val' is
freed by the function. 'flags' is a bitmask of JS_PROP_NO_ADD,
JS_PROP_THROW or JS_PROP_THROW_STRICT. If JS_PROP_NO_ADD is set,
the new property is not added and an error is raised.
'obj' must be an object when obj != this_obj.
*/
-static int JS_SetPropertyInternal2(JSContext *ctx, JSValue obj, JSAtom prop,
- JSValue val, JSValue this_obj, int flags,
- JSInlineCacheUpdate *icu)
+static int JS_SetPropertyInternal2(JSContext *ctx, JSValueConst obj, JSAtom prop,
+ JSValue val, JSValueConst this_obj, int flags)
{
JSObject *p, *p1;
JSShapeProperty *prs;
JSProperty *pr;
JSPropertyDescriptor desc;
int ret;
- uint32_t offset = 0;
switch(JS_VALUE_GET_TAG(this_obj)) {
case JS_TAG_NULL:
@@ -8817,14 +8855,13 @@ static int JS_SetPropertyInternal2(JSContext *ctx, JSValue obj, JSAtom prop,
}
retry:
- prs = find_own_property_ic(&pr, p1, prop, &offset);
+ prs = find_own_property(&pr, p1, prop);
if (prs) {
if (likely((prs->flags & (JS_PROP_TMASK | JS_PROP_WRITABLE |
JS_PROP_LENGTH)) == JS_PROP_WRITABLE)) {
/* fast case */
- add_ic_slot(ctx, icu, prop, p, offset);
set_value(ctx, &pr->u.value, val);
- return TRUE;
+ return true;
} else if (prs->flags & JS_PROP_LENGTH) {
assert(p->class_id == JS_CLASS_ARRAY);
assert(prop == JS_ATOM_length);
@@ -8838,7 +8875,7 @@ retry:
if (p->class_id == JS_CLASS_MODULE_NS)
goto read_only_prop;
set_value(ctx, pr->u.var_ref->pvalue, val);
- return TRUE;
+ return true;
} else if ((prs->flags & JS_PROP_TMASK) == JS_PROP_AUTOINIT) {
/* Instantiate property and retry (potentially useless) */
if (JS_AutoInitProperty(ctx, p, prop, pr, prs))
@@ -8859,12 +8896,10 @@ retry:
return JS_SetPropertyValue(ctx, this_obj, js_int32(idx), val, flags);
else
break;
- } else if (p1->class_id >= JS_CLASS_UINT8C_ARRAY &&
- p1->class_id <= JS_CLASS_FLOAT64_ARRAY) {
+ } else if (is_typed_array(p1->class_id)) {
goto typed_array_oob;
}
- } else if (p1->class_id >= JS_CLASS_UINT8C_ARRAY &&
- p1->class_id <= JS_CLASS_FLOAT64_ARRAY) {
+ } else if (is_typed_array(p1->class_id)) {
ret = JS_AtomIsNumericIndex(ctx, prop);
if (ret != 0) {
if (ret < 0)
@@ -8882,7 +8917,7 @@ retry:
if (JS_IsException(val))
return -1;
}
- return TRUE;
+ return true;
}
}
} else {
@@ -8988,7 +9023,7 @@ retry:
if (!pr)
goto fail;
pr->u.value = val;
- return TRUE;
+ return true;
}
}
@@ -9034,40 +9069,19 @@ fail:
return -1;
}
-static int JS_SetPropertyInternal(JSContext *ctx, JSValue this_obj,
- JSAtom prop, JSValue val, int flags)
+static int JS_SetPropertyInternal(JSContext *ctx, JSValueConst obj, JSAtom prop,
+ JSValue val, int flags)
{
- return JS_SetPropertyInternal2(ctx, this_obj, prop, val, this_obj,
- flags, NULL);
+ return JS_SetPropertyInternal2(ctx, obj, prop, val, obj, flags);
}
-int JS_SetProperty(JSContext *ctx, JSValue this_obj, JSAtom prop, JSValue val)
+int JS_SetProperty(JSContext *ctx, JSValueConst this_obj, JSAtom prop, JSValue val)
{
- return JS_SetPropertyInternal2(ctx, this_obj, prop, val, this_obj, JS_PROP_THROW, NULL);
-}
-
-// XXX(bnoordhuis) only used by OP_put_field_ic, maybe inline at call site
-static int JS_SetPropertyInternalWithIC(JSContext *ctx, JSValue this_obj,
- JSAtom prop, JSValue val, int flags,
- JSInlineCacheUpdate *icu) {
- uint32_t tag, offset;
- JSObject *p;
- tag = JS_VALUE_GET_TAG(this_obj);
- if (unlikely(tag != JS_TAG_OBJECT))
- goto slow_path;
- p = JS_VALUE_GET_OBJ(this_obj);
- offset = get_ic_prop_offset(icu, p->shape);
- if (likely(offset != INLINE_CACHE_MISS)) {
- set_value(ctx, &p->prop[offset].u.value, val);
- return TRUE;
- }
-slow_path:
- return JS_SetPropertyInternal2(ctx, this_obj, prop, val, this_obj,
- flags, icu);
+ return JS_SetPropertyInternal(ctx, this_obj, prop, val, JS_PROP_THROW);
}
/* flags can be JS_PROP_THROW or JS_PROP_THROW_STRICT */
-static int JS_SetPropertyValue(JSContext *ctx, JSValue this_obj,
+static int JS_SetPropertyValue(JSContext *ctx, JSValueConst this_obj,
JSValue prop, JSValue val, int flags)
{
if (likely(JS_VALUE_GET_TAG(this_obj) == JS_TAG_OBJECT &&
@@ -9179,7 +9193,7 @@ static int JS_SetPropertyValue(JSContext *ctx, JSValue this_obj,
ta_cvt_fail:
if (flags & JS_PROP_REFLECT_DEFINE_PROPERTY) {
JS_FreeValue(ctx, JS_GetException(ctx));
- return FALSE;
+ return false;
}
return -1;
}
@@ -9188,14 +9202,14 @@ static int JS_SetPropertyValue(JSContext *ctx, JSValue this_obj,
if (typed_array_is_oob(p))
if (flags & JS_PROP_DEFINE_PROPERTY)
return JS_ThrowTypeErrorOrFalse(ctx, flags, "out-of-bound numeric index");
- return TRUE; // per spec: no OOB exception
+ return true; // per spec: no OOB exception
}
p->u.array.u.double_ptr[idx] = d;
break;
default:
goto slow_path;
}
- return TRUE;
+ return true;
} else {
JSAtom atom;
int ret;
@@ -9212,14 +9226,14 @@ static int JS_SetPropertyValue(JSContext *ctx, JSValue this_obj,
}
}
-int JS_SetPropertyUint32(JSContext *ctx, JSValue this_obj,
+int JS_SetPropertyUint32(JSContext *ctx, JSValueConst this_obj,
uint32_t idx, JSValue val)
{
return JS_SetPropertyValue(ctx, this_obj, js_uint32(idx), val,
JS_PROP_THROW);
}
-int JS_SetPropertyInt64(JSContext *ctx, JSValue this_obj,
+int JS_SetPropertyInt64(JSContext *ctx, JSValueConst this_obj,
int64_t idx, JSValue val)
{
JSAtom prop;
@@ -9241,7 +9255,7 @@ int JS_SetPropertyInt64(JSContext *ctx, JSValue this_obj,
}
/* `prop` may be pure ASCII or UTF-8 encoded */
-int JS_SetPropertyStr(JSContext *ctx, JSValue this_obj,
+int JS_SetPropertyStr(JSContext *ctx, JSValueConst this_obj,
const char *prop, JSValue val)
{
JSAtom atom;
@@ -9264,8 +9278,8 @@ static int get_prop_flags(int flags, int def_flags)
}
static int JS_CreateProperty(JSContext *ctx, JSObject *p,
- JSAtom prop, JSValue val,
- JSValue getter, JSValue setter,
+ JSAtom prop, JSValueConst val,
+ JSValueConst getter, JSValueConst setter,
int flags)
{
JSProperty *pr;
@@ -9316,8 +9330,7 @@ static int JS_CreateProperty(JSContext *ctx, JSObject *p,
set_value(ctx, &plen->u.value, js_uint32(len));
}
}
- } else if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&
- p->class_id <= JS_CLASS_FLOAT64_ARRAY) {
+ } else if (is_typed_array(p->class_id)) {
ret = JS_AtomIsNumericIndex(ctx, prop);
if (ret != 0) {
if (ret < 0)
@@ -9372,22 +9385,22 @@ static int JS_CreateProperty(JSContext *ctx, JSObject *p,
pr->u.value = JS_UNDEFINED;
}
}
- return TRUE;
+ return true;
}
-/* return FALSE if not OK */
-static BOOL check_define_prop_flags(int prop_flags, int flags)
+/* return false if not OK */
+static bool check_define_prop_flags(int prop_flags, int flags)
{
- BOOL has_accessor, is_getset;
+ bool has_accessor, is_getset;
if (!(prop_flags & JS_PROP_CONFIGURABLE)) {
if ((flags & (JS_PROP_HAS_CONFIGURABLE | JS_PROP_CONFIGURABLE)) ==
(JS_PROP_HAS_CONFIGURABLE | JS_PROP_CONFIGURABLE)) {
- return FALSE;
+ return false;
}
if ((flags & JS_PROP_HAS_ENUMERABLE) &&
(flags & JS_PROP_ENUMERABLE) != (prop_flags & JS_PROP_ENUMERABLE))
- return FALSE;
+ return false;
}
if (flags & (JS_PROP_HAS_VALUE | JS_PROP_HAS_WRITABLE |
JS_PROP_HAS_GET | JS_PROP_HAS_SET)) {
@@ -9395,16 +9408,16 @@ static BOOL check_define_prop_flags(int prop_flags, int flags)
has_accessor = ((flags & (JS_PROP_HAS_GET | JS_PROP_HAS_SET)) != 0);
is_getset = ((prop_flags & JS_PROP_TMASK) == JS_PROP_GETSET);
if (has_accessor != is_getset)
- return FALSE;
+ return false;
if (!has_accessor && !is_getset && !(prop_flags & JS_PROP_WRITABLE)) {
/* not writable: cannot set the writable bit */
if ((flags & (JS_PROP_HAS_WRITABLE | JS_PROP_WRITABLE)) ==
(JS_PROP_HAS_WRITABLE | JS_PROP_WRITABLE))
- return FALSE;
+ return false;
}
}
}
- return TRUE;
+ return true;
}
/* ensure that the shape can be safely modified */
@@ -9429,7 +9442,7 @@ static int js_shape_prepare_update(JSContext *ctx, JSObject *p,
*pprs = get_shape_prop(sh) + idx;
} else {
js_shape_hash_unlink(ctx->rt, sh);
- sh->is_hashed = FALSE;
+ sh->is_hashed = false;
}
}
return 0;
@@ -9451,14 +9464,14 @@ static int js_update_property_flags(JSContext *ctx, JSObject *p,
JS_PROP_HAS_GET, JS_PROP_HAS_SET, JS_PROP_HAS_VALUE,
JS_PROP_HAS_CONFIGURABLE, JS_PROP_HAS_WRITABLE, JS_PROP_HAS_ENUMERABLE,
JS_PROP_THROW, JS_PROP_NO_EXOTIC.
- If JS_PROP_THROW is set, return an exception instead of FALSE.
+ If JS_PROP_THROW is set, return an exception instead of false.
if JS_PROP_NO_EXOTIC is set, do not call the exotic
define_own_property callback.
- return -1 (exception), FALSE or TRUE.
+ return -1 (exception), false or true.
*/
-int JS_DefineProperty(JSContext *ctx, JSValue this_obj,
- JSAtom prop, JSValue val,
- JSValue getter, JSValue setter, int flags)
+int JS_DefineProperty(JSContext *ctx, JSValueConst this_obj,
+ JSAtom prop, JSValueConst val,
+ JSValueConst getter, JSValueConst setter, int flags)
{
JSObject *p;
JSShapeProperty *prs;
@@ -9478,7 +9491,7 @@ int JS_DefineProperty(JSContext *ctx, JSValue this_obj,
if ((prs->flags & JS_PROP_LENGTH) && (flags & JS_PROP_HAS_VALUE)) {
uint32_t array_length;
if (JS_ToArrayLengthFree(ctx, &array_length,
- js_dup(val), FALSE)) {
+ js_dup(val), false)) {
return -1;
}
/* this code relies on the fact that Uint32 are never allocated */
@@ -9575,7 +9588,7 @@ int JS_DefineProperty(JSContext *ctx, JSValue this_obj,
if (!js_same_value(ctx, val, pr->u.value)) {
goto not_configurable;
} else {
- return TRUE;
+ return true;
}
}
}
@@ -9589,8 +9602,7 @@ int JS_DefineProperty(JSContext *ctx, JSValue this_obj,
goto not_configurable;
}
/* update the reference */
- set_value(ctx, pr->u.var_ref->pvalue,
- js_dup(val));
+ set_value(ctx, pr->u.var_ref->pvalue, js_dup(val));
}
/* if writable is set to false, no longer a
reference (for mapped arguments) */
@@ -9607,10 +9619,9 @@ int JS_DefineProperty(JSContext *ctx, JSValue this_obj,
if (flags & JS_PROP_HAS_VALUE) {
/* Note: no JS code is executable because
'val' is guaranted to be a Uint32 */
- res = set_array_length(ctx, p, js_dup(val),
- flags);
+ res = set_array_length(ctx, p, js_dup(val), flags);
} else {
- res = TRUE;
+ res = true;
}
/* still need to reset the writable flag if
needed. The JS_PROP_LENGTH is kept because the
@@ -9646,7 +9657,7 @@ int JS_DefineProperty(JSContext *ctx, JSValue this_obj,
if (js_update_property_flags(ctx, p, &prs,
(prs->flags & ~mask) | (flags & mask)))
return -1;
- return TRUE;
+ return true;
}
/* handle modification of fast array elements */
@@ -9670,11 +9681,10 @@ int JS_DefineProperty(JSContext *ctx, JSValue this_obj,
if (flags & JS_PROP_HAS_VALUE) {
set_value(ctx, &p->u.array.u.values[idx], js_dup(val));
}
- return TRUE;
+ return true;
}
}
- } else if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&
- p->class_id <= JS_CLASS_FLOAT64_ARRAY) {
+ } else if (is_typed_array(p->class_id)) {
JSValue num;
int ret;
@@ -9716,7 +9726,7 @@ int JS_DefineProperty(JSContext *ctx, JSValue this_obj,
if (flags & JS_PROP_HAS_VALUE) {
return JS_SetPropertyValue(ctx, this_obj, js_int32(idx), js_dup(val), flags);
}
- return TRUE;
+ return true;
typed_array_done: ;
}
}
@@ -9724,7 +9734,7 @@ int JS_DefineProperty(JSContext *ctx, JSValue this_obj,
return JS_CreateProperty(ctx, p, prop, val, getter, setter, flags);
}
-static int JS_DefineAutoInitProperty(JSContext *ctx, JSValue this_obj,
+static int JS_DefineAutoInitProperty(JSContext *ctx, JSValueConst this_obj,
JSAtom prop, JSAutoInitIDEnum id,
void *opaque, int flags)
{
@@ -9732,14 +9742,14 @@ static int JS_DefineAutoInitProperty(JSContext *ctx, JSValue this_obj,
JSProperty *pr;
if (JS_VALUE_GET_TAG(this_obj) != JS_TAG_OBJECT)
- return FALSE;
+ return false;
p = JS_VALUE_GET_OBJ(this_obj);
if (find_own_property(&pr, p, prop)) {
/* property already exists */
abort();
- return FALSE;
+ return false;
}
/* Specialized CreateProperty */
@@ -9751,11 +9761,11 @@ static int JS_DefineAutoInitProperty(JSContext *ctx, JSValue this_obj,
assert(id <= 3);
pr->u.init.realm_and_id |= id;
pr->u.init.opaque = opaque;
- return TRUE;
+ return true;
}
/* shortcut to add or redefine a new property value */
-int JS_DefinePropertyValue(JSContext *ctx, JSValue this_obj,
+int JS_DefinePropertyValue(JSContext *ctx, JSValueConst this_obj,
JSAtom prop, JSValue val, int flags)
{
int ret;
@@ -9765,7 +9775,7 @@ int JS_DefinePropertyValue(JSContext *ctx, JSValue this_obj,
return ret;
}
-int JS_DefinePropertyValueValue(JSContext *ctx, JSValue this_obj,
+int JS_DefinePropertyValueValue(JSContext *ctx, JSValueConst this_obj,
JSValue prop, JSValue val, int flags)
{
JSAtom atom;
@@ -9781,14 +9791,14 @@ int JS_DefinePropertyValueValue(JSContext *ctx, JSValue this_obj,
return ret;
}
-int JS_DefinePropertyValueUint32(JSContext *ctx, JSValue this_obj,
+int JS_DefinePropertyValueUint32(JSContext *ctx, JSValueConst this_obj,
uint32_t idx, JSValue val, int flags)
{
return JS_DefinePropertyValueValue(ctx, this_obj, js_uint32(idx),
val, flags);
}
-int JS_DefinePropertyValueInt64(JSContext *ctx, JSValue this_obj,
+int JS_DefinePropertyValueInt64(JSContext *ctx, JSValueConst this_obj,
int64_t idx, JSValue val, int flags)
{
return JS_DefinePropertyValueValue(ctx, this_obj, js_int64(idx),
@@ -9796,7 +9806,7 @@ int JS_DefinePropertyValueInt64(JSContext *ctx, JSValue this_obj,
}
/* `prop` may be pure ASCII or UTF-8 encoded */
-int JS_DefinePropertyValueStr(JSContext *ctx, JSValue this_obj,
+int JS_DefinePropertyValueStr(JSContext *ctx, JSValueConst this_obj,
const char *prop, JSValue val, int flags)
{
JSAtom atom;
@@ -9808,7 +9818,7 @@ int JS_DefinePropertyValueStr(JSContext *ctx, JSValue this_obj,
}
/* shortcut to add getter & setter */
-int JS_DefinePropertyGetSet(JSContext *ctx, JSValue this_obj,
+int JS_DefinePropertyGetSet(JSContext *ctx, JSValueConst this_obj,
JSAtom prop, JSValue getter, JSValue setter,
int flags)
{
@@ -9821,7 +9831,7 @@ int JS_DefinePropertyGetSet(JSContext *ctx, JSValue this_obj,
return ret;
}
-static int JS_CreateDataPropertyUint32(JSContext *ctx, JSValue this_obj,
+static int JS_CreateDataPropertyUint32(JSContext *ctx, JSValueConst this_obj,
int64_t idx, JSValue val, int flags)
{
return JS_DefinePropertyValueValue(ctx, this_obj, js_int64(idx),
@@ -9830,8 +9840,8 @@ static int JS_CreateDataPropertyUint32(JSContext *ctx, JSValue this_obj,
}
-/* return TRUE if 'obj' has a non empty 'name' string */
-static BOOL js_object_has_name(JSContext *ctx, JSValue obj)
+/* return true if 'obj' has a non empty 'name' string */
+static bool js_object_has_name(JSContext *ctx, JSValue obj)
{
JSProperty *pr;
JSShapeProperty *prs;
@@ -9840,12 +9850,12 @@ static BOOL js_object_has_name(JSContext *ctx, JSValue obj)
prs = find_own_property(&pr, JS_VALUE_GET_OBJ(obj), JS_ATOM_name);
if (!prs)
- return FALSE;
+ return false;
if ((prs->flags & JS_PROP_TMASK) != JS_PROP_NORMAL)
- return TRUE;
+ return true;
val = pr->u.value;
if (JS_VALUE_GET_TAG(val) != JS_TAG_STRING)
- return TRUE;
+ return true;
p = JS_VALUE_GET_STRING(val);
return (p->len != 0);
}
@@ -9989,7 +9999,7 @@ static int JS_DefineGlobalFunction(JSContext *ctx, JSAtom prop,
}
static JSValue JS_GetGlobalVar(JSContext *ctx, JSAtom prop,
- BOOL throw_ref_error)
+ bool throw_ref_error)
{
JSObject *p;
JSShapeProperty *prs;
@@ -10056,7 +10066,7 @@ static int JS_CheckGlobalVar(JSContext *ctx, JSAtom prop)
p = JS_VALUE_GET_OBJ(ctx->global_var_obj);
prs = find_own_property1(p, prop);
if (prs) {
- ret = TRUE;
+ ret = true;
} else {
ret = JS_HasProperty(ctx, ctx->global_obj, prop);
if (ret < 0)
@@ -10102,10 +10112,10 @@ static int JS_SetGlobalVar(JSContext *ctx, JSAtom prop, JSValue val,
return JS_SetPropertyInternal(ctx, ctx->global_obj, prop, val, flags);
}
-/* return -1, FALSE or TRUE. return FALSE if not configurable or
+/* return -1, false or true. return false if not configurable or
invalid object. return -1 in case of exception.
flags can be 0, JS_PROP_THROW or JS_PROP_THROW_STRICT */
-int JS_DeleteProperty(JSContext *ctx, JSValue obj, JSAtom prop, int flags)
+int JS_DeleteProperty(JSContext *ctx, JSValueConst obj, JSAtom prop, int flags)
{
JSValue obj1;
JSObject *p;
@@ -10117,17 +10127,17 @@ int JS_DeleteProperty(JSContext *ctx, JSValue obj, JSAtom prop, int flags)
p = JS_VALUE_GET_OBJ(obj1);
res = delete_property(ctx, p, prop);
JS_FreeValue(ctx, obj1);
- if (res != FALSE)
+ if (res != false)
return res;
if ((flags & JS_PROP_THROW) ||
((flags & JS_PROP_THROW_STRICT) && is_strict_mode(ctx))) {
JS_ThrowTypeError(ctx, "could not delete property");
return -1;
}
- return FALSE;
+ return false;
}
-int JS_DeletePropertyInt64(JSContext *ctx, JSValue obj, int64_t idx, int flags)
+int JS_DeletePropertyInt64(JSContext *ctx, JSValueConst obj, int64_t idx, int flags)
{
JSAtom prop;
int res;
@@ -10144,15 +10154,15 @@ int JS_DeletePropertyInt64(JSContext *ctx, JSValue obj, int64_t idx, int flags)
return res;
}
-BOOL JS_IsFunction(JSContext *ctx, JSValue val)
+bool JS_IsFunction(JSContext *ctx, JSValueConst val)
{
JSObject *p;
if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT)
- return FALSE;
+ return false;
p = JS_VALUE_GET_OBJ(val);
switch(p->class_id) {
case JS_CLASS_BYTECODE_FUNCTION:
- return TRUE;
+ return true;
case JS_CLASS_PROXY:
return p->u.proxy_data->is_func;
default:
@@ -10160,57 +10170,72 @@ BOOL JS_IsFunction(JSContext *ctx, JSValue val)
}
}
-BOOL JS_IsCFunction(JSContext *ctx, JSValue val, JSCFunction *func, int magic)
+static bool JS_IsCFunction(JSContext *ctx, JSValueConst val, JSCFunction *func,
+ int magic)
{
JSObject *p;
if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT)
- return FALSE;
+ return false;
p = JS_VALUE_GET_OBJ(val);
if (p->class_id == JS_CLASS_C_FUNCTION)
return (p->u.cfunc.c_function.generic == func && p->u.cfunc.magic == magic);
else
- return FALSE;
+ return false;
}
-BOOL JS_IsConstructor(JSContext *ctx, JSValue val)
+bool JS_IsConstructor(JSContext *ctx, JSValueConst val)
{
JSObject *p;
if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT)
- return FALSE;
+ return false;
p = JS_VALUE_GET_OBJ(val);
return p->is_constructor;
}
-BOOL JS_SetConstructorBit(JSContext *ctx, JSValue func_obj, BOOL val)
+bool JS_SetConstructorBit(JSContext *ctx, JSValueConst func_obj, bool val)
{
JSObject *p;
if (JS_VALUE_GET_TAG(func_obj) != JS_TAG_OBJECT)
- return FALSE;
+ return false;
p = JS_VALUE_GET_OBJ(func_obj);
p->is_constructor = val;
- return TRUE;
+ return true;
+}
+
+bool JS_IsRegExp(JSValueConst val)
+{
+ if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT)
+ return false;
+ return JS_VALUE_GET_OBJ(val)->class_id == JS_CLASS_REGEXP;
}
-BOOL JS_IsError(JSContext *ctx, JSValue val)
+bool JS_IsMap(JSValueConst val)
+{
+ if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT)
+ return false;
+ return JS_VALUE_GET_OBJ(val)->class_id == JS_CLASS_MAP;
+}
+
+bool JS_IsError(JSContext *ctx, JSValueConst val)
{
JSObject *p;
if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT)
- return FALSE;
+ return false;
p = JS_VALUE_GET_OBJ(val);
return (p->class_id == JS_CLASS_ERROR);
}
/* used to avoid catching interrupt exceptions */
-BOOL JS_IsUncatchableError(JSContext *ctx, JSValue val)
+bool JS_IsUncatchableError(JSContext *ctx, JSValueConst val)
{
JSObject *p;
if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT)
- return FALSE;
+ return false;
p = JS_VALUE_GET_OBJ(val);
return p->class_id == JS_CLASS_ERROR && p->is_uncatchable_error;
}
-void JS_SetUncatchableError(JSContext *ctx, JSValue val, BOOL flag)
+static void js_set_uncatchable_error(JSContext *ctx, JSValueConst val, bool flag)
{
JSObject *p;
if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT)
@@ -10220,12 +10245,22 @@ void JS_SetUncatchableError(JSContext *ctx, JSValue val, BOOL flag)
p->is_uncatchable_error = flag;
}
+void JS_SetUncatchableError(JSContext *ctx, JSValueConst val)
+{
+ js_set_uncatchable_error(ctx, val, true);
+}
+
+void JS_ClearUncatchableError(JSContext *ctx, JSValueConst val)
+{
+ js_set_uncatchable_error(ctx, val, false);
+}
+
void JS_ResetUncatchableError(JSContext *ctx)
{
- JS_SetUncatchableError(ctx, ctx->rt->current_exception, FALSE);
+ js_set_uncatchable_error(ctx, ctx->rt->current_exception, false);
}
-int JS_SetOpaque(JSValue obj, void *opaque)
+int JS_SetOpaque(JSValueConst obj, void *opaque)
{
JSObject *p;
if (JS_VALUE_GET_TAG(obj) == JS_TAG_OBJECT) {
@@ -10250,7 +10285,7 @@ int JS_SetOpaque(JSValue obj, void *opaque)
}
/* |obj| must be a JSObject of an internal class. */
-static void JS_SetOpaqueInternal(JSValue obj, void *opaque)
+static void JS_SetOpaqueInternal(JSValueConst obj, void *opaque)
{
JSObject *p;
assert(JS_VALUE_GET_TAG(obj) == JS_TAG_OBJECT);
@@ -10260,7 +10295,7 @@ static void JS_SetOpaqueInternal(JSValue obj, void *opaque)
}
/* return NULL if not an object of class class_id */
-void *JS_GetOpaque(JSValue obj, JSClassID class_id)
+void *JS_GetOpaque(JSValueConst obj, JSClassID class_id)
{
JSObject *p;
if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)
@@ -10271,7 +10306,7 @@ void *JS_GetOpaque(JSValue obj, JSClassID class_id)
return p->u.opaque;
}
-void *JS_GetOpaque2(JSContext *ctx, JSValue obj, JSClassID class_id)
+void *JS_GetOpaque2(JSContext *ctx, JSValueConst obj, JSClassID class_id)
{
void *p = JS_GetOpaque(obj, class_id);
if (unlikely(!p)) {
@@ -10280,7 +10315,7 @@ void *JS_GetOpaque2(JSContext *ctx, JSValue obj, JSClassID class_id)
return p;
}
-void *JS_GetAnyOpaque(JSValue obj, JSClassID *class_id)
+void *JS_GetAnyOpaque(JSValueConst obj, JSClassID *class_id)
{
JSObject *p;
if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT) {
@@ -10295,7 +10330,7 @@ void *JS_GetAnyOpaque(JSValue obj, JSClassID *class_id)
static JSValue JS_ToPrimitiveFree(JSContext *ctx, JSValue val, int hint)
{
int i;
- BOOL force_ordinary;
+ bool force_ordinary;
JSAtom method_name;
JSValue method, ret;
@@ -10325,7 +10360,7 @@ static JSValue JS_ToPrimitiveFree(JSContext *ctx, JSValue val, int hint)
break;
}
arg = JS_AtomToString(ctx, atom);
- ret = JS_CallFree(ctx, method, val, 1, &arg);
+ ret = JS_CallFree(ctx, method, val, 1, vc(&arg));
JS_FreeValue(ctx, arg);
if (JS_IsException(ret))
goto exception;
@@ -10366,25 +10401,25 @@ exception:
return JS_EXCEPTION;
}
-static JSValue JS_ToPrimitive(JSContext *ctx, JSValue val, int hint)
+static JSValue JS_ToPrimitive(JSContext *ctx, JSValueConst val, int hint)
{
return JS_ToPrimitiveFree(ctx, js_dup(val), hint);
}
-void JS_SetIsHTMLDDA(JSContext *ctx, JSValue obj)
+void JS_SetIsHTMLDDA(JSContext *ctx, JSValueConst obj)
{
JSObject *p;
if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)
return;
p = JS_VALUE_GET_OBJ(obj);
- p->is_HTMLDDA = TRUE;
+ p->is_HTMLDDA = true;
}
-static inline BOOL JS_IsHTMLDDA(JSContext *ctx, JSValue obj)
+static inline bool JS_IsHTMLDDA(JSContext *ctx, JSValueConst obj)
{
JSObject *p;
if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)
- return FALSE;
+ return false;
p = JS_VALUE_GET_OBJ(obj);
return p->is_HTMLDDA;
}
@@ -10403,14 +10438,14 @@ static int JS_ToBoolFree(JSContext *ctx, JSValue val)
return -1;
case JS_TAG_STRING:
{
- BOOL ret = JS_VALUE_GET_STRING(val)->len != 0;
+ bool ret = JS_VALUE_GET_STRING(val)->len != 0;
JS_FreeValue(ctx, val);
return ret;
}
case JS_TAG_BIG_INT:
{
JSBigInt *p = JS_VALUE_GET_PTR(val);
- BOOL ret;
+ bool ret;
ret = p->num.expn != BF_EXP_ZERO && p->num.expn != BF_EXP_NAN;
JS_FreeValue(ctx, val);
return ret;
@@ -10418,8 +10453,7 @@ static int JS_ToBoolFree(JSContext *ctx, JSValue val)
case JS_TAG_OBJECT:
{
JSObject *p = JS_VALUE_GET_OBJ(val);
- BOOL ret;
- ret = !p->is_HTMLDDA;
+ bool ret = !p->is_HTMLDDA;
JS_FreeValue(ctx, val);
return ret;
}
@@ -10430,12 +10464,12 @@ static int JS_ToBoolFree(JSContext *ctx, JSValue val)
return !isnan(d) && d != 0;
} else {
JS_FreeValue(ctx, val);
- return TRUE;
+ return true;
}
}
}
-int JS_ToBool(JSContext *ctx, JSValue val)
+int JS_ToBool(JSContext *ctx, JSValueConst val)
{
return JS_ToBoolFree(ctx, js_dup(val));
}
@@ -10476,7 +10510,7 @@ static inline int to_digit(int c)
}
/* XXX: remove */
-static double js_strtod(const char *str, int radix, BOOL is_float)
+static double js_strtod(const char *str, int radix, bool is_float)
{
double d;
int c;
@@ -10574,7 +10608,7 @@ static JSValue js_atof(JSContext *ctx, const char *p, size_t len,
const char *p_start;
const char *end = p + len;
int sep;
- BOOL is_float;
+ bool is_float;
char buf1[64], *buf = buf1;
size_t i, j;
JSValue val = JS_NAN;
@@ -10625,7 +10659,7 @@ static JSValue js_atof(JSContext *ctx, const char *p, size_t len,
goto done;
}
}
- is_float = FALSE;
+ is_float = false;
p_start = p;
while (to_digit(*p) < radix) {
p++;
@@ -10634,7 +10668,7 @@ static JSValue js_atof(JSContext *ctx, const char *p, size_t len,
}
if ((flags & ATOD_ACCEPT_FLOAT) && radix == 10) {
if (*p == '.' && (p > p_start || to_digit(p[1]) < radix)) {
- is_float = TRUE;
+ is_float = true;
p++;
while (to_digit(*p) < radix) {
p++;
@@ -10648,7 +10682,7 @@ static JSValue js_atof(JSContext *ctx, const char *p, size_t len,
i++;
}
if (is_digit(p[i])) {
- is_float = TRUE;
+ is_float = true;
p += i + 1;
while (is_digit(*p) || (*p == sep && is_digit(p[1])))
p++;
@@ -10783,7 +10817,7 @@ static JSValue JS_ToNumericFree(JSContext *ctx, JSValue val)
return JS_ToNumberHintFree(ctx, val, TON_FLAG_NUMERIC);
}
-static JSValue JS_ToNumeric(JSContext *ctx, JSValue val)
+static JSValue JS_ToNumeric(JSContext *ctx, JSValueConst val)
{
return JS_ToNumericFree(ctx, js_dup(val));
}
@@ -10796,7 +10830,7 @@ static __exception int __JS_ToFloat64Free(JSContext *ctx, double *pres,
val = JS_ToNumberFree(ctx, val);
if (JS_IsException(val)) {
- *pres = JS_FLOAT64_NAN;
+ *pres = NAN;
return -1;
}
tag = JS_VALUE_GET_NORM_TAG(val);
@@ -10840,12 +10874,12 @@ static inline int JS_ToFloat64Free(JSContext *ctx, double *pres, JSValue val)
}
}
-int JS_ToFloat64(JSContext *ctx, double *pres, JSValue val)
+int JS_ToFloat64(JSContext *ctx, double *pres, JSValueConst val)
{
return JS_ToFloat64Free(ctx, pres, js_dup(val));
}
-static JSValue JS_ToNumber(JSContext *ctx, JSValue val)
+JSValue JS_ToNumber(JSContext *ctx, JSValueConst val)
{
return JS_ToNumberFree(ctx, js_dup(val));
}
@@ -10931,13 +10965,13 @@ static int JS_ToInt32SatFree(JSContext *ctx, int *pres, JSValue val)
return 0;
}
-int JS_ToInt32Sat(JSContext *ctx, int *pres, JSValue val)
+static int JS_ToInt32Sat(JSContext *ctx, int *pres, JSValueConst val)
{
return JS_ToInt32SatFree(ctx, pres, js_dup(val));
}
-int JS_ToInt32Clamp(JSContext *ctx, int *pres, JSValue val,
- int min, int max, int min_offset)
+static int JS_ToInt32Clamp(JSContext *ctx, int *pres, JSValueConst val,
+ int min, int max, int min_offset)
{
int res = JS_ToInt32SatFree(ctx, pres, js_dup(val));
if (res == 0) {
@@ -10994,12 +11028,12 @@ static int JS_ToInt64SatFree(JSContext *ctx, int64_t *pres, JSValue val)
}
}
-int JS_ToInt64Sat(JSContext *ctx, int64_t *pres, JSValue val)
+int JS_ToInt64Sat(JSContext *ctx, int64_t *pres, JSValueConst val)
{
return JS_ToInt64SatFree(ctx, pres, js_dup(val));
}
-int JS_ToInt64Clamp(JSContext *ctx, int64_t *pres, JSValue val,
+int JS_ToInt64Clamp(JSContext *ctx, int64_t *pres, JSValueConst val,
int64_t min, int64_t max, int64_t neg_offset)
{
int res = JS_ToInt64SatFree(ctx, pres, js_dup(val));
@@ -11068,12 +11102,12 @@ static int JS_ToInt64Free(JSContext *ctx, int64_t *pres, JSValue val)
return 0;
}
-int JS_ToInt64(JSContext *ctx, int64_t *pres, JSValue val)
+int JS_ToInt64(JSContext *ctx, int64_t *pres, JSValueConst val)
{
return JS_ToInt64Free(ctx, pres, js_dup(val));
}
-int JS_ToInt64Ext(JSContext *ctx, int64_t *pres, JSValue val)
+int JS_ToInt64Ext(JSContext *ctx, int64_t *pres, JSValueConst val)
{
if (JS_IsBigInt(ctx, val))
return JS_ToBigInt64(ctx, pres, val);
@@ -11135,7 +11169,7 @@ static int JS_ToInt32Free(JSContext *ctx, int32_t *pres, JSValue val)
return 0;
}
-int JS_ToInt32(JSContext *ctx, int32_t *pres, JSValue val)
+int JS_ToInt32(JSContext *ctx, int32_t *pres, JSValueConst val)
{
return JS_ToInt32Free(ctx, pres, js_dup(val));
}
@@ -11188,7 +11222,7 @@ static int JS_ToUint8ClampFree(JSContext *ctx, int32_t *pres, JSValue val)
}
static __exception int JS_ToArrayLengthFree(JSContext *ctx, uint32_t *plen,
- JSValue val, BOOL is_array_ctor)
+ JSValue val, bool is_array_ctor)
{
uint32_t tag, len;
@@ -11209,7 +11243,7 @@ static __exception int JS_ToArrayLengthFree(JSContext *ctx, uint32_t *plen,
{
JSBigInt *p = JS_VALUE_GET_PTR(val);
bf_t a;
- BOOL res;
+ bool res;
bf_get_int32((int32_t *)&len, &p->num, BF_GET_INT_MOD);
bf_init(ctx->bf_ctx, &a);
bf_set_ui(&a, len);
@@ -11237,7 +11271,7 @@ static __exception int JS_ToArrayLengthFree(JSContext *ctx, uint32_t *plen,
if (JS_IsException(val))
return -1;
/* cannot recurse because val is a number */
- if (JS_ToArrayLengthFree(ctx, &len, val, TRUE))
+ if (JS_ToArrayLengthFree(ctx, &len, val, true))
return -1;
} else {
/* legacy behavior: must do the conversion twice and compare */
@@ -11249,7 +11283,7 @@ static __exception int JS_ToArrayLengthFree(JSContext *ctx, uint32_t *plen,
if (JS_IsException(val))
return -1;
/* cannot recurse because val is a number */
- if (JS_ToArrayLengthFree(ctx, &len1, val, FALSE))
+ if (JS_ToArrayLengthFree(ctx, &len1, val, false))
return -1;
if (len1 != len) {
fail:
@@ -11266,13 +11300,13 @@ static __exception int JS_ToArrayLengthFree(JSContext *ctx, uint32_t *plen,
#define MAX_SAFE_INTEGER (((int64_t)1 << 53) - 1)
-static BOOL is_safe_integer(double d)
+static bool is_safe_integer(double d)
{
return isfinite(d) && floor(d) == d &&
fabs(d) <= (double)MAX_SAFE_INTEGER;
}
-int JS_ToIndex(JSContext *ctx, uint64_t *plen, JSValue val)
+int JS_ToIndex(JSContext *ctx, uint64_t *plen, JSValueConst val)
{
int64_t v;
if (JS_ToInt64Sat(ctx, &v, val))
@@ -11297,17 +11331,17 @@ static __exception int JS_ToLengthFree(JSContext *ctx, int64_t *plen,
}
/* Note: can return an exception */
-static int JS_NumberIsInteger(JSContext *ctx, JSValue val)
+static int JS_NumberIsInteger(JSContext *ctx, JSValueConst val)
{
double d;
if (!JS_IsNumber(val))
- return FALSE;
+ return false;
if (unlikely(JS_ToFloat64(ctx, &d, val)))
return -1;
return isfinite(d) && floor(d) == d;
}
-static BOOL JS_NumberIsNegativeOrMinusZero(JSContext *ctx, JSValue val)
+static bool JS_NumberIsNegativeOrMinusZero(JSContext *ctx, JSValueConst val)
{
uint32_t tag;
@@ -11332,11 +11366,11 @@ static BOOL JS_NumberIsNegativeOrMinusZero(JSContext *ctx, JSValue val)
return p->num.sign && !bf_is_zero(&p->num);
}
default:
- return FALSE;
+ return false;
}
}
-static JSValue js_bigint_to_string1(JSContext *ctx, JSValue val, int radix)
+static JSValue js_bigint_to_string1(JSContext *ctx, JSValueConst val, int radix)
{
JSValue ret;
bf_t a_s, *a;
@@ -11361,7 +11395,7 @@ static JSValue js_bigint_to_string1(JSContext *ctx, JSValue val, int radix)
return ret;
}
-static JSValue js_bigint_to_string(JSContext *ctx, JSValue val)
+static JSValue js_bigint_to_string(JSContext *ctx, JSValueConst val)
{
return js_bigint_to_string1(ctx, val, 10);
}
@@ -11789,7 +11823,8 @@ done:
return js_new_string8_len(ctx, ptr, ptr2 - ptr);
}
-JSValue JS_ToStringInternal(JSContext *ctx, JSValue val, BOOL is_ToPropertyKey)
+JSValue JS_ToStringInternal(JSContext *ctx, JSValueConst val,
+ bool is_ToPropertyKey)
{
uint32_t tag;
char buf[32];
@@ -11841,9 +11876,9 @@ JSValue JS_ToStringInternal(JSContext *ctx, JSValue val, BOOL is_ToPropertyKey)
}
}
-JSValue JS_ToString(JSContext *ctx, JSValue val)
+JSValue JS_ToString(JSContext *ctx, JSValueConst val)
{
- return JS_ToStringInternal(ctx, val, FALSE);
+ return JS_ToStringInternal(ctx, val, false);
}
static JSValue JS_ToStringFree(JSContext *ctx, JSValue val)
@@ -11861,12 +11896,12 @@ static JSValue JS_ToLocaleStringFree(JSContext *ctx, JSValue val)
return JS_InvokeFree(ctx, val, JS_ATOM_toLocaleString, 0, NULL);
}
-JSValue JS_ToPropertyKey(JSContext *ctx, JSValue val)
+JSValue JS_ToPropertyKey(JSContext *ctx, JSValueConst val)
{
- return JS_ToStringInternal(ctx, val, TRUE);
+ return JS_ToStringInternal(ctx, val, true);
}
-static JSValue JS_ToStringCheckObject(JSContext *ctx, JSValue val)
+static JSValue JS_ToStringCheckObject(JSContext *ctx, JSValueConst val)
{
uint32_t tag = JS_VALUE_GET_TAG(val);
if (tag == JS_TAG_NULL || tag == JS_TAG_UNDEFINED)
@@ -11874,7 +11909,7 @@ static JSValue JS_ToStringCheckObject(JSContext *ctx, JSValue val)
return JS_ToString(ctx, val);
}
-static JSValue JS_ToQuotedString(JSContext *ctx, JSValue val1)
+static JSValue JS_ToQuotedString(JSContext *ctx, JSValueConst val1)
{
JSValue val;
JSString *p;
@@ -11955,7 +11990,7 @@ static __maybe_unused void JS_DumpObject(JSRuntime *rt, JSObject *p)
JSShape *sh;
JSShapeProperty *prs;
JSProperty *pr;
- BOOL is_first = TRUE;
+ bool is_first = true;
/* XXX: should encode atoms with special characters */
sh = p->shape; /* the shape can be NULL while freeing an object */
@@ -12028,7 +12063,7 @@ static __maybe_unused void JS_DumpObject(JSRuntime *rt, JSObject *p)
} else {
JS_DumpValue(rt, pr->u.value);
}
- is_first = FALSE;
+ is_first = false;
}
}
printf(" }");
@@ -12085,7 +12120,7 @@ static __maybe_unused void JS_DumpGCObject(JSRuntime *rt, JSGCObjectHeader *p)
}
}
-static __maybe_unused void JS_DumpValue(JSRuntime *rt, JSValue val)
+static __maybe_unused void JS_DumpValue(JSRuntime *rt, JSValueConst val)
{
uint32_t tag = JS_VALUE_GET_NORM_TAG(val);
const char *str;
@@ -12171,8 +12206,17 @@ static __maybe_unused void JS_DumpValue(JSRuntime *rt, JSValue val)
}
}
-/* return -1 if exception (proxy case) or TRUE/FALSE */
-int JS_IsArray(JSContext *ctx, JSValue val)
+bool JS_IsArray(JSValueConst val)
+{
+ if (JS_VALUE_GET_TAG(val) == JS_TAG_OBJECT) {
+ JSObject *p = JS_VALUE_GET_OBJ(val);
+ return p->class_id == JS_CLASS_ARRAY;
+ }
+ return false;
+}
+
+/* return -1 if exception (proxy case) or true/false */
+static int js_is_array(JSContext *ctx, JSValueConst val)
{
JSObject *p;
if (JS_VALUE_GET_TAG(val) == JS_TAG_OBJECT) {
@@ -12182,7 +12226,7 @@ int JS_IsArray(JSContext *ctx, JSValue val)
else
return p->class_id == JS_CLASS_ARRAY;
} else {
- return FALSE;
+ return false;
}
}
@@ -12190,7 +12234,7 @@ static double js_math_pow(double a, double b)
{
if (unlikely(!isfinite(b)) && fabs(a) == 1) {
/* not compatible with IEEE 754 */
- return JS_FLOAT64_NAN;
+ return NAN;
} else {
return pow(a, b);
}
@@ -12231,7 +12275,7 @@ JSValue JS_NewBigUint64(JSContext *ctx, uint64_t v)
'buf'. Otherwise it is a pointer to the bigint in 'val'. Return
NULL in case of error. */
// TODO(bnoordhuis) Merge with JS_ToBigInt()
-static bf_t *JS_ToBigInt1(JSContext *ctx, bf_t *buf, JSValue val)
+static bf_t *JS_ToBigInt1(JSContext *ctx, bf_t *buf, JSValueConst val)
{
uint32_t tag;
bf_t *r;
@@ -12342,7 +12386,7 @@ static bf_t *JS_ToBigIntFree(JSContext *ctx, bf_t *buf, JSValue val)
return r;
}
-static bf_t *JS_ToBigInt(JSContext *ctx, bf_t *buf, JSValue val)
+static bf_t *JS_ToBigInt(JSContext *ctx, bf_t *buf, JSValueConst val)
{
return JS_ToBigIntFree(ctx, buf, js_dup(val));
}
@@ -12401,12 +12445,12 @@ static int JS_ToBigInt64Free(JSContext *ctx, int64_t *pres, JSValue val)
return 0;
}
-int JS_ToBigInt64(JSContext *ctx, int64_t *pres, JSValue val)
+int JS_ToBigInt64(JSContext *ctx, int64_t *pres, JSValueConst val)
{
return JS_ToBigInt64Free(ctx, pres, js_dup(val));
}
-int JS_ToBigUint64(JSContext *ctx, uint64_t *pres, JSValue val)
+int JS_ToBigUint64(JSContext *ctx, uint64_t *pres, JSValueConst val)
{
return JS_ToBigInt64Free(ctx, (int64_t *)pres, js_dup(val));
}
@@ -13058,7 +13102,7 @@ static no_inline int js_relational_slow(JSContext *ctx, JSValue *sp,
JSString *p1, *p2;
p1 = JS_VALUE_GET_STRING(op1);
p2 = JS_VALUE_GET_STRING(op2);
- res = js_string_compare(ctx, p1, p2);
+ res = js_string_compare(p1, p2);
switch(op) {
case OP_lt:
res = (res < 0);
@@ -13094,7 +13138,7 @@ static no_inline int js_relational_slow(JSContext *ctx, JSValue *sp,
invalid_bigint_string:
JS_FreeValue(ctx, op1);
JS_FreeValue(ctx, op2);
- res = FALSE;
+ res = false;
goto done;
}
}
@@ -13159,14 +13203,14 @@ static no_inline int js_relational_slow(JSContext *ctx, JSValue *sp,
return -1;
}
-static BOOL tag_is_number(uint32_t tag)
+static bool tag_is_number(uint32_t tag)
{
return (tag == JS_TAG_INT || tag == JS_TAG_BIG_INT ||
tag == JS_TAG_FLOAT64);
}
static no_inline __exception int js_eq_slow(JSContext *ctx, JSValue *sp,
- BOOL is_neq)
+ bool is_neq)
{
JSValue op1, op2;
int res;
@@ -13205,7 +13249,7 @@ static no_inline __exception int js_eq_slow(JSContext *ctx, JSValue *sp,
res = js_strict_eq2(ctx, op1, op2, JS_EQ_STRICT);
} else if ((tag1 == JS_TAG_NULL && tag2 == JS_TAG_UNDEFINED) ||
(tag2 == JS_TAG_NULL && tag1 == JS_TAG_UNDEFINED)) {
- res = TRUE;
+ res = true;
} else if ((tag1 == JS_TAG_STRING && tag_is_number(tag2)) ||
(tag2 == JS_TAG_STRING && tag_is_number(tag1))) {
@@ -13221,7 +13265,7 @@ static no_inline __exception int js_eq_slow(JSContext *ctx, JSValue *sp,
invalid_bigint_string:
JS_FreeValue(ctx, op1);
JS_FreeValue(ctx, op2);
- res = FALSE;
+ res = false;
goto done;
}
}
@@ -13265,9 +13309,9 @@ static no_inline __exception int js_eq_slow(JSContext *ctx, JSValue *sp,
(tag2 == JS_TAG_NULL || tag2 == JS_TAG_UNDEFINED)) ||
(JS_IsHTMLDDA(ctx, op2) &&
(tag1 == JS_TAG_NULL || tag1 == JS_TAG_UNDEFINED))) {
- res = TRUE;
+ res = true;
} else {
- res = FALSE;
+ res = false;
}
JS_FreeValue(ctx, op1);
JS_FreeValue(ctx, op2);
@@ -13318,11 +13362,10 @@ static no_inline int js_shr_slow(JSContext *ctx, JSValue *sp)
return -1;
}
-/* XXX: Should take JSValue arguments */
-static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2,
+static bool js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2,
JSStrictEqModeEnum eq_mode)
{
- BOOL res;
+ bool res;
int tag1, tag2;
double d1, d2;
@@ -13331,7 +13374,7 @@ static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2,
switch(tag1) {
case JS_TAG_BOOL:
if (tag1 != tag2) {
- res = FALSE;
+ res = false;
} else {
res = JS_VALUE_GET_INT(op1) == JS_VALUE_GET_INT(op2);
goto done_no_free;
@@ -13345,11 +13388,11 @@ static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2,
{
JSString *p1, *p2;
if (tag1 != tag2) {
- res = FALSE;
+ res = false;
} else {
p1 = JS_VALUE_GET_STRING(op1);
p2 = JS_VALUE_GET_STRING(op2);
- res = (js_string_compare(ctx, p1, p2) == 0);
+ res = js_string_eq(p1, p2);
}
}
break;
@@ -13357,7 +13400,7 @@ static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2,
{
JSAtomStruct *p1, *p2;
if (tag1 != tag2) {
- res = FALSE;
+ res = false;
} else {
p1 = JS_VALUE_GET_PTR(op1);
p2 = JS_VALUE_GET_PTR(op2);
@@ -13367,7 +13410,7 @@ static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2,
break;
case JS_TAG_OBJECT:
if (tag1 != tag2)
- res = FALSE;
+ res = false;
else
res = JS_VALUE_GET_OBJ(op1) == JS_VALUE_GET_OBJ(op2);
break;
@@ -13380,7 +13423,7 @@ static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2,
d2 = JS_VALUE_GET_FLOAT64(op2);
goto number_test;
} else {
- res = FALSE;
+ res = false;
}
break;
case JS_TAG_FLOAT64:
@@ -13390,7 +13433,7 @@ static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2,
} else if (tag2 == JS_TAG_INT) {
d2 = JS_VALUE_GET_INT(op2);
} else {
- res = FALSE;
+ res = false;
break;
}
number_test:
@@ -13414,7 +13457,7 @@ static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2,
{
bf_t a_s, *a, b_s, *b;
if (tag1 != tag2) {
- res = FALSE;
+ res = false;
break;
}
a = JS_ToBigInt1(ctx, &a_s, op1);
@@ -13427,7 +13470,7 @@ static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2,
}
break;
default:
- res = FALSE;
+ res = false;
break;
}
JS_FreeValue(ctx, op1);
@@ -13436,25 +13479,25 @@ static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2,
return res;
}
-static BOOL js_strict_eq(JSContext *ctx, JSValue op1, JSValue op2)
+static bool js_strict_eq(JSContext *ctx, JSValue op1, JSValue op2)
{
return js_strict_eq2(ctx, op1, op2, JS_EQ_STRICT);
}
-static BOOL js_same_value(JSContext *ctx, JSValue op1, JSValue op2)
+static bool js_same_value(JSContext *ctx, JSValueConst op1, JSValueConst op2)
{
return js_strict_eq2(ctx, js_dup(op1), js_dup(op2), JS_EQ_SAME_VALUE);
}
-static BOOL js_same_value_zero(JSContext *ctx, JSValue op1, JSValue op2)
+static bool js_same_value_zero(JSContext *ctx, JSValueConst op1, JSValueConst op2)
{
return js_strict_eq2(ctx, js_dup(op1), js_dup(op2), JS_EQ_SAME_VALUE_ZERO);
}
static no_inline int js_strict_eq_slow(JSContext *ctx, JSValue *sp,
- BOOL is_neq)
+ bool is_neq)
{
- BOOL res;
+ bool res;
res = js_strict_eq(ctx, sp[-2], sp[-1]);
sp[-2] = js_bool(res ^ is_neq);
return 0;
@@ -13542,7 +13585,7 @@ static __exception int js_has_unscopable(JSContext *ctx, JSValue obj,
static __exception int js_operator_instanceof(JSContext *ctx, JSValue *sp)
{
JSValue op1, op2;
- BOOL ret;
+ int ret;
op1 = sp[-2];
op2 = sp[-1];
@@ -13625,8 +13668,8 @@ static __exception int js_operator_delete(JSContext *ctx, JSValue *sp)
return 0;
}
-static JSValue js_throw_type_error(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_throw_type_error(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
return JS_ThrowTypeError(ctx, "invalid property access");
}
@@ -13634,8 +13677,8 @@ static JSValue js_throw_type_error(JSContext *ctx, JSValue this_val,
/* XXX: not 100% compatible, but mozilla seems to use a similar
implementation to ensure that caller in non strict mode does not
throw (ES5 compatibility) */
-static JSValue js_function_proto_caller(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_function_proto_caller(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSFunctionBytecode *b = JS_GetFunctionBytecode(this_val);
if (!b || b->is_strict_mode || !b->has_prototype) {
@@ -13645,7 +13688,7 @@ static JSValue js_function_proto_caller(JSContext *ctx, JSValue this_val,
}
static JSValue js_function_proto_fileName(JSContext *ctx,
- JSValue this_val)
+ JSValueConst this_val)
{
JSFunctionBytecode *b = JS_GetFunctionBytecode(this_val);
if (b) {
@@ -13655,7 +13698,7 @@ static JSValue js_function_proto_fileName(JSContext *ctx,
}
static JSValue js_function_proto_int32(JSContext *ctx,
- JSValue this_val,
+ JSValueConst this_val,
int magic)
{
JSFunctionBytecode *b = JS_GetFunctionBytecode(this_val);
@@ -13667,9 +13710,10 @@ static JSValue js_function_proto_int32(JSContext *ctx,
}
static int js_arguments_define_own_property(JSContext *ctx,
- JSValue this_obj,
- JSAtom prop, JSValue val,
- JSValue getter, JSValue setter, int flags)
+ JSValueConst this_obj,
+ JSAtom prop, JSValueConst val,
+ JSValueConst getter,
+ JSValueConst setter, int flags)
{
JSObject *p;
uint32_t idx;
@@ -13689,7 +13733,7 @@ static const JSClassExoticMethods js_arguments_exotic_methods = {
.define_own_property = js_arguments_define_own_property,
};
-static JSValue js_build_arguments(JSContext *ctx, int argc, JSValue *argv)
+static JSValue js_build_arguments(JSContext *ctx, int argc, JSValueConst *argv)
{
JSValue val, *tab;
JSProperty *pr;
@@ -13741,7 +13785,7 @@ static JSValue js_build_arguments(JSContext *ctx, int argc, JSValue *argv)
/* legacy arguments object: add references to the function arguments */
static JSValue js_build_mapped_arguments(JSContext *ctx, int argc,
- JSValue *argv,
+ JSValueConst *argv,
JSStackFrame *sf, int arg_count)
{
JSValue val;
@@ -13764,7 +13808,7 @@ static JSValue js_build_mapped_arguments(JSContext *ctx, int argc,
for(i = 0; i < arg_count; i++) {
JSVarRef *var_ref;
- var_ref = get_var_ref(ctx, sf, i, TRUE);
+ var_ref = get_var_ref(ctx, sf, i, true);
if (!var_ref)
goto fail;
pr = add_property(ctx, p, __JS_AtomFromUInt32(i), JS_PROP_C_W_E | JS_PROP_VARREF);
@@ -13797,26 +13841,6 @@ static JSValue js_build_mapped_arguments(JSContext *ctx, int argc,
return JS_EXCEPTION;
}
-static JSValue js_build_rest(JSContext *ctx, int first, int argc, JSValue *argv)
-{
- JSValue val;
- int i, ret;
-
- val = JS_NewArray(ctx);
- if (JS_IsException(val))
- return val;
- for (i = first; i < argc; i++) {
- ret = JS_DefinePropertyValueUint32(ctx, val, i - first,
- js_dup(argv[i]),
- JS_PROP_C_W_E);
- if (ret < 0) {
- JS_FreeValue(ctx, val);
- return JS_EXCEPTION;
- }
- }
- return val;
-}
-
static JSValue build_for_in_iterator(JSContext *ctx, JSValue obj)
{
JSObject *p;
@@ -13842,7 +13866,7 @@ static JSValue build_for_in_iterator(JSContext *ctx, JSValue obj)
JS_FreeValue(ctx, obj);
return JS_EXCEPTION;
}
- it->is_array = FALSE;
+ it->is_array = false;
it->obj = obj;
it->idx = 0;
p = JS_VALUE_GET_OBJ(enum_obj);
@@ -13889,7 +13913,7 @@ static JSValue build_for_in_iterator(JSContext *ctx, JSValue obj)
goto normal_case;
}
/* for fast arrays, we only store the number of elements */
- it->is_array = TRUE;
+ it->is_array = true;
it->array_length = p->u.array.count;
} else {
normal_case:
@@ -14006,8 +14030,8 @@ static __exception int js_for_in_next(JSContext *ctx, JSValue *sp)
return 0;
}
-static JSValue JS_GetIterator2(JSContext *ctx, JSValue obj,
- JSValue method)
+static JSValue JS_GetIterator2(JSContext *ctx, JSValueConst obj,
+ JSValueConst method)
{
JSValue enum_obj;
@@ -14021,7 +14045,7 @@ static JSValue JS_GetIterator2(JSContext *ctx, JSValue obj,
return enum_obj;
}
-static JSValue JS_GetIterator(JSContext *ctx, JSValue obj, BOOL is_async)
+static JSValue JS_GetIterator(JSContext *ctx, JSValueConst obj, bool is_async)
{
JSValue method, ret, sync_iter;
@@ -14056,9 +14080,9 @@ static JSValue JS_GetIterator(JSContext *ctx, JSValue obj, BOOL is_async)
}
/* return *pdone = 2 if the iterator object is not parsed */
-static JSValue JS_IteratorNext2(JSContext *ctx, JSValue enum_obj,
- JSValue method,
- int argc, JSValue *argv, int *pdone)
+static JSValue JS_IteratorNext2(JSContext *ctx, JSValueConst enum_obj,
+ JSValueConst method,
+ int argc, JSValueConst *argv, int *pdone)
{
JSValue obj;
@@ -14069,7 +14093,7 @@ static JSValue JS_IteratorNext2(JSContext *ctx, JSValue enum_obj,
if (p->class_id == JS_CLASS_C_FUNCTION &&
p->u.cfunc.cproto == JS_CFUNC_iterator_next) {
JSCFunctionType func;
- JSValue args[1];
+ JSValueConst args[1];
/* in case the function expects one argument */
if (argc == 0) {
@@ -14092,13 +14116,13 @@ static JSValue JS_IteratorNext2(JSContext *ctx, JSValue enum_obj,
*pdone = 2;
return obj;
fail:
- *pdone = FALSE;
+ *pdone = false;
return JS_EXCEPTION;
}
-static JSValue JS_IteratorNext(JSContext *ctx, JSValue enum_obj,
- JSValue method,
- int argc, JSValue *argv, BOOL *pdone)
+static JSValue JS_IteratorNext(JSContext *ctx, JSValueConst enum_obj,
+ JSValueConst method,
+ int argc, JSValueConst *argv, int *pdone)
{
JSValue obj, value, done_val;
int done;
@@ -14123,13 +14147,13 @@ static JSValue JS_IteratorNext(JSContext *ctx, JSValue enum_obj,
}
fail:
JS_FreeValue(ctx, obj);
- *pdone = FALSE;
+ *pdone = false;
return JS_EXCEPTION;
}
/* return < 0 in case of exception */
-static int JS_IteratorClose(JSContext *ctx, JSValue enum_obj,
- BOOL is_exception_pending)
+static int JS_IteratorClose(JSContext *ctx, JSValueConst enum_obj,
+ bool is_exception_pending)
{
JSValue method, ret, ex_obj;
int res;
@@ -14169,7 +14193,7 @@ static int JS_IteratorClose(JSContext *ctx, JSValue enum_obj,
/* obj -> enum_rec (3 slots) */
static __exception int js_for_of_start(JSContext *ctx, JSValue *sp,
- BOOL is_async)
+ bool is_async)
{
JSValue op1, obj, method;
op1 = sp[-1];
@@ -14217,10 +14241,10 @@ static __exception int js_for_of_next(JSContext *ctx, JSValue *sp, int offset)
}
static JSValue JS_IteratorGetCompleteValue(JSContext *ctx, JSValue obj,
- BOOL *pdone)
+ int *pdone)
{
JSValue done_val, value;
- BOOL done;
+ int done;
done_val = JS_GetProperty(ctx, obj, JS_ATOM_done);
if (JS_IsException(done_val))
goto fail;
@@ -14231,14 +14255,14 @@ static JSValue JS_IteratorGetCompleteValue(JSContext *ctx, JSValue obj,
*pdone = done;
return value;
fail:
- *pdone = FALSE;
+ *pdone = false;
return JS_EXCEPTION;
}
static __exception int js_iterator_get_value_done(JSContext *ctx, JSValue *sp)
{
JSValue obj, value;
- BOOL done;
+ int done;
obj = sp[-1];
if (!JS_IsObject(obj)) {
JS_ThrowTypeError(ctx, "iterator must return an object");
@@ -14255,7 +14279,7 @@ static __exception int js_iterator_get_value_done(JSContext *ctx, JSValue *sp)
static JSValue js_create_iterator_result(JSContext *ctx,
JSValue val,
- BOOL done)
+ bool done)
{
JSValue obj;
obj = JS_NewObject(ctx);
@@ -14276,27 +14300,27 @@ static JSValue js_create_iterator_result(JSContext *ctx,
return obj;
}
-static JSValue js_array_iterator_next(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv,
- BOOL *pdone, int magic);
+static JSValue js_array_iterator_next(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv,
+ int *pdone, int magic);
-static JSValue js_create_array_iterator(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic);
+static JSValue js_create_array_iterator(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic);
-static BOOL js_is_fast_array(JSContext *ctx, JSValue obj)
+static bool js_is_fast_array(JSContext *ctx, JSValue obj)
{
/* Try and handle fast arrays explicitly */
if (JS_VALUE_GET_TAG(obj) == JS_TAG_OBJECT) {
JSObject *p = JS_VALUE_GET_OBJ(obj);
if (p->class_id == JS_CLASS_ARRAY && p->fast_array) {
- return TRUE;
+ return true;
}
}
- return FALSE;
+ return false;
}
/* Access an Array's internal JSValue array if available */
-static BOOL js_get_fast_array(JSContext *ctx, JSValue obj,
+static bool js_get_fast_array(JSContext *ctx, JSValue obj,
JSValue **arrpp, uint32_t *countp)
{
/* Try and handle fast arrays explicitly */
@@ -14305,10 +14329,10 @@ static BOOL js_get_fast_array(JSContext *ctx, JSValue obj,
if (p->class_id == JS_CLASS_ARRAY && p->fast_array) {
*countp = p->u.array.count;
*arrpp = p->u.array.u.values;
- return TRUE;
+ return true;
}
}
- return FALSE;
+ return false;
}
static __exception int js_append_enumerate(JSContext *ctx, JSValue *sp)
@@ -14341,7 +14365,7 @@ static __exception int js_append_enumerate(JSContext *ctx, JSValue *sp)
JS_ITERATOR_KIND_VALUE);
JS_FreeValue(ctx, iterator);
- enumobj = JS_GetIterator(ctx, sp[-1], FALSE);
+ enumobj = JS_GetIterator(ctx, sp[-1], false);
if (JS_IsException(enumobj))
return -1;
method = JS_GetProperty(ctx, enumobj, JS_ATOM_next);
@@ -14370,7 +14394,7 @@ static __exception int js_append_enumerate(JSContext *ctx, JSValue *sp)
} else {
general_case:
for (;;) {
- BOOL done;
+ int done;
value = JS_IteratorNext(ctx, enumobj, method, 0, NULL, &done);
if (JS_IsException(value))
goto exception;
@@ -14389,7 +14413,7 @@ static __exception int js_append_enumerate(JSContext *ctx, JSValue *sp)
return 0;
exception:
- JS_IteratorClose(ctx, enumobj, TRUE);
+ JS_IteratorClose(ctx, enumobj, true);
JS_FreeValue(ctx, enumobj);
JS_FreeValue(ctx, method);
return -1;
@@ -14399,7 +14423,7 @@ static __exception int JS_CopyDataProperties(JSContext *ctx,
JSValue target,
JSValue source,
JSValue excluded,
- BOOL setprop)
+ bool setprop)
{
JSPropertyEnum *tab_atom;
JSValue val;
@@ -14408,7 +14432,7 @@ static __exception int JS_CopyDataProperties(JSContext *ctx,
JSObject *pexcl = NULL;
int ret, gpn_flags;
JSPropertyDescriptor desc;
- BOOL is_enumerable;
+ bool is_enumerable;
if (JS_VALUE_GET_TAG(source) != JS_TAG_OBJECT)
return 0;
@@ -14471,13 +14495,13 @@ static __exception int JS_CopyDataProperties(JSContext *ctx,
}
/* only valid inside C functions */
-static JSValue JS_GetActiveFunction(JSContext *ctx)
+static JSValueConst JS_GetActiveFunction(JSContext *ctx)
{
return ctx->rt->current_stack_frame->cur_func;
}
static JSVarRef *get_var_ref(JSContext *ctx, JSStackFrame *sf,
- int var_idx, BOOL is_arg)
+ int var_idx, bool is_arg)
{
JSVarRef *var_ref;
struct list_head *el;
@@ -14494,7 +14518,7 @@ static JSVarRef *get_var_ref(JSContext *ctx, JSStackFrame *sf,
if (!var_ref)
return NULL;
var_ref->header.ref_count = 1;
- var_ref->is_detached = FALSE;
+ var_ref->is_detached = false;
var_ref->is_arg = is_arg;
var_ref->var_idx = var_idx;
list_add_tail(&var_ref->header.link, &sf->var_ref_list);
@@ -14617,7 +14641,7 @@ static JSValue js_closure(JSContext *ctx, JSValue bfunc,
/* add the 'prototype' property: delay instantiation to avoid
creating cycles for every javascript function. The prototype
object is created on the fly when first accessed */
- JS_SetConstructorBit(ctx, func_obj, TRUE);
+ JS_SetConstructorBit(ctx, func_obj, true);
JS_DefineAutoInitProperty(ctx, func_obj, JS_ATOM_prototype,
JS_AUTOINIT_ID_PROTOTYPE, NULL,
JS_PROP_WRITABLE);
@@ -14634,7 +14658,7 @@ static JSValue js_closure(JSContext *ctx, JSValue bfunc,
static int js_op_define_class(JSContext *ctx, JSValue *sp,
JSAtom class_name, int class_flags,
JSVarRef **cur_var_refs,
- JSStackFrame *sf, BOOL is_computed_name)
+ JSStackFrame *sf, bool is_computed_name)
{
JSValue bfunc, parent_class, proto = JS_UNDEFINED;
JSValue ctor = JS_UNDEFINED, parent_proto = JS_UNDEFINED;
@@ -14680,7 +14704,7 @@ static int js_op_define_class(JSContext *ctx, JSValue *sp,
if (JS_IsException(ctor))
goto fail;
js_method_set_home_object(ctx, ctor, proto);
- JS_SetConstructorBit(ctx, ctor, TRUE);
+ JS_SetConstructorBit(ctx, ctor, true);
JS_DefinePropertyValue(ctx, ctor, JS_ATOM_length,
js_int32(b->defined_arg_count),
@@ -14741,7 +14765,7 @@ static void close_var_refs(JSRuntime *rt, JSStackFrame *sf)
var_ref->value = js_dup(sf->var_buf[var_idx]);
var_ref->pvalue = &var_ref->value;
/* the reference is no longer to a local variable */
- var_ref->is_detached = TRUE;
+ var_ref->is_detached = true;
add_gc_object(rt, &var_ref->header, JS_GC_OBJ_TYPE_VAR_REF);
}
}
@@ -14758,7 +14782,7 @@ static void close_lexical_var(JSContext *ctx, JSStackFrame *sf, int var_idx)
var_ref->pvalue = &var_ref->value;
list_del(&var_ref->header.link);
/* the reference is no longer to a local variable */
- var_ref->is_detached = TRUE;
+ var_ref->is_detached = true;
add_gc_object(ctx->rt, &var_ref->header, JS_GC_OBJ_TYPE_VAR_REF);
}
}
@@ -14767,16 +14791,16 @@ static void close_lexical_var(JSContext *ctx, JSStackFrame *sf, int var_idx)
#define JS_CALL_FLAG_COPY_ARGV (1 << 1)
#define JS_CALL_FLAG_GENERATOR (1 << 2)
-static JSValue js_call_c_function(JSContext *ctx, JSValue func_obj,
- JSValue this_obj,
- int argc, JSValue *argv, int flags)
+static JSValue js_call_c_function(JSContext *ctx, JSValueConst func_obj,
+ JSValueConst this_obj,
+ int argc, JSValueConst *argv, int flags)
{
JSRuntime *rt = ctx->rt;
JSCFunctionType func;
JSObject *p;
JSStackFrame sf_s, *sf = &sf_s, *prev_sf;
JSValue ret_val;
- JSValue *arg_buf;
+ JSValueConst *arg_buf;
int arg_count, i;
JSCFunctionEnum cproto;
@@ -14793,8 +14817,8 @@ static JSValue js_call_c_function(JSContext *ctx, JSValue func_obj,
rt->current_stack_frame = sf;
ctx = p->u.cfunc.realm; /* change the current realm */
- sf->is_strict_mode = FALSE;
- sf->cur_func = func_obj;
+ sf->is_strict_mode = false;
+ sf->cur_func = unsafe_unconst(func_obj);
sf->arg_count = argc;
arg_buf = argv;
@@ -14807,7 +14831,7 @@ static JSValue js_call_c_function(JSContext *ctx, JSValue func_obj,
arg_buf[i] = JS_UNDEFINED;
sf->arg_count = arg_count;
}
- sf->arg_buf = arg_buf;
+ sf->arg_buf = (JSValue *)arg_buf;
func = p->u.cfunc.c_function;
switch(cproto) {
@@ -14897,13 +14921,13 @@ static JSValue js_call_c_function(JSContext *ctx, JSValue func_obj,
return ret_val;
}
-static JSValue js_call_bound_function(JSContext *ctx, JSValue func_obj,
- JSValue this_obj,
- int argc, JSValue *argv, int flags)
+static JSValue js_call_bound_function(JSContext *ctx, JSValueConst func_obj,
+ JSValueConst this_obj,
+ int argc, JSValueConst *argv, int flags)
{
JSObject *p;
JSBoundFunction *bf;
- JSValue *arg_buf, new_target;
+ JSValueConst *arg_buf, new_target;
int arg_count, i;
p = JS_VALUE_GET_OBJ(func_obj);
@@ -14945,25 +14969,28 @@ typedef enum {
#define FUNC_RET_YIELD 1
#define FUNC_RET_YIELD_STAR 2
-#if defined(DUMP_BYTECODE_FINAL) || \
- defined(DUMP_BYTECODE_PASS2) || \
- defined(DUMP_BYTECODE_PASS1) || \
- defined(DUMP_BYTECODE_STACK) || \
- defined(DUMP_BYTECODE_STEP) || \
- defined(DUMP_READ_OBJECT)
-#define DUMP_BYTECODE
-#endif
-
-#ifdef DUMP_BYTECODE
+#ifdef ENABLE_DUMPS // JS_DUMP_BYTECODE_*
static void dump_single_byte_code(JSContext *ctx, const uint8_t *pc,
JSFunctionBytecode *b, int start_pos);
static void print_func_name(JSFunctionBytecode *b);
#endif
+static bool needs_backtrace(JSValue exc)
+{
+ JSObject *p;
+
+ if (JS_VALUE_GET_TAG(exc) != JS_TAG_OBJECT)
+ return false;
+ p = JS_VALUE_GET_OBJ(exc);
+ if (p->class_id != JS_CLASS_ERROR)
+ return false;
+ return !find_own_property1(p, JS_ATOM_stack);
+}
+
/* argv[] is modified if (flags & JS_CALL_FLAG_COPY_ARGV) = 0. */
-static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
- JSValue this_obj, JSValue new_target,
- int argc, JSValue *argv, int flags)
+static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
+ JSValueConst this_obj, JSValueConst new_target,
+ int argc, JSValueConst *argv, int flags)
{
JSRuntime *rt = caller_ctx->rt;
JSContext *ctx;
@@ -14975,11 +15002,10 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
JSValue *local_buf, *stack_buf, *var_buf, *arg_buf, *sp, ret_val, *pval;
JSVarRef **var_refs;
size_t alloca_size;
- JSInlineCache *ic;
-#ifdef DUMP_BYTECODE_STEP
+#ifdef ENABLE_DUMPS // JS_DUMP_BYTECODE_STEP
#define DUMP_BYTECODE_OR_DONT(pc) \
- if (check_dump_flag(ctx->rt, DUMP_BYTECODE_STEP)) dump_single_byte_code(ctx, pc, b, 0);
+ if (check_dump_flag(ctx->rt, JS_DUMP_BYTECODE_STEP)) dump_single_byte_code(ctx, pc, b, 0);
#else
#define DUMP_BYTECODE_OR_DONT(pc)
#endif
@@ -15022,7 +15048,6 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
pc = sf->cur_pc;
sf->prev_frame = rt->current_stack_frame;
rt->current_stack_frame = sf;
- ic = b->ic;
if (s->throw_flag)
goto exception;
else
@@ -15037,7 +15062,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
call_func = rt->class_array[p->class_id].call;
if (!call_func) {
not_a_function:
- return JS_ThrowTypeError(caller_ctx, "not a function");
+ return JS_ThrowTypeErrorNotAFunction(caller_ctx);
}
return call_func(caller_ctx, func_obj, this_obj, argc,
argv, flags);
@@ -15056,9 +15081,9 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
return JS_ThrowStackOverflow(caller_ctx);
sf->is_strict_mode = b->is_strict_mode;
- arg_buf = argv;
+ arg_buf = (JSValue *)argv;
sf->arg_count = argc;
- sf->cur_func = func_obj;
+ sf->cur_func = unsafe_unconst(func_obj);
init_list_head(&sf->var_ref_list);
var_refs = p->u.func.var_refs;
@@ -15067,7 +15092,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
int n = min_int(argc, b->arg_count);
arg_buf = local_buf;
for(i = 0; i < n; i++)
- arg_buf[i] = JS_DupValue(caller_ctx, argv[i]);
+ arg_buf[i] = js_dup(argv[i]);
for(; i < b->arg_count; i++)
arg_buf[i] = JS_UNDEFINED;
sf->arg_count = b->arg_count;
@@ -15087,10 +15112,9 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
sf->prev_frame = rt->current_stack_frame;
rt->current_stack_frame = sf;
ctx = b->realm; /* set the current realm */
- ic = b->ic;
-#ifdef DUMP_BYTECODE_STEP
- if (check_dump_flag(ctx->rt, DUMP_BYTECODE_STEP))
+#ifdef ENABLE_DUMPS // JS_DUMP_BYTECODE_STEP
+ if (check_dump_flag(ctx->rt, JS_DUMP_BYTECODE_STEP))
print_func_name(b);
#endif
@@ -15241,9 +15265,11 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
BREAK;
CASE(OP_rest):
{
- int first = get_u16(pc);
+ int i, n, first = get_u16(pc);
pc += 2;
- *sp++ = js_build_rest(ctx, first, argc, argv);
+ i = min_int(first, argc);
+ n = argc - i;
+ *sp++ = js_create_array(ctx, n, &argv[i]);
if (unlikely(JS_IsException(sp[-1])))
goto exception;
}
@@ -15416,7 +15442,8 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
call_argv = sp - call_argc;
sf->cur_pc = pc;
ret_val = JS_CallInternal(ctx, call_argv[-1], JS_UNDEFINED,
- JS_UNDEFINED, call_argc, call_argv, 0);
+ JS_UNDEFINED, call_argc,
+ vc(call_argv), 0);
if (unlikely(JS_IsException(ret_val)))
goto exception;
if (opcode == OP_tail_call)
@@ -15434,8 +15461,8 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
call_argv = sp - call_argc;
sf->cur_pc = pc;
ret_val = JS_CallConstructorInternal(ctx, call_argv[-2],
- call_argv[-1],
- call_argc, call_argv, 0);
+ call_argv[-1], call_argc,
+ vc(call_argv), 0);
if (unlikely(JS_IsException(ret_val)))
goto exception;
for(i = -2; i < call_argc; i++)
@@ -15452,7 +15479,8 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
call_argv = sp - call_argc;
sf->cur_pc = pc;
ret_val = JS_CallInternal(ctx, call_argv[-1], call_argv[-2],
- JS_UNDEFINED, call_argc, call_argv, 0);
+ JS_UNDEFINED, call_argc,
+ vc(call_argv), 0);
if (unlikely(JS_IsException(ret_val)))
goto exception;
if (opcode == OP_tail_call_method)
@@ -15465,23 +15493,12 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
BREAK;
CASE(OP_array_from):
{
- int i, ret;
-
call_argc = get_u16(pc);
pc += 2;
- ret_val = JS_NewArray(ctx);
+ call_argv = sp - call_argc;
+ ret_val = JS_NewArrayFrom(ctx, call_argc, call_argv);
if (unlikely(JS_IsException(ret_val)))
goto exception;
- call_argv = sp - call_argc;
- for(i = 0; i < call_argc; i++) {
- ret = JS_DefinePropertyValue(ctx, ret_val, __JS_AtomFromUInt32(i), call_argv[i],
- JS_PROP_C_W_E | JS_PROP_THROW);
- call_argv[i] = JS_UNDEFINED;
- if (ret < 0) {
- JS_FreeValue(ctx, ret_val);
- goto exception;
- }
- }
sp -= call_argc;
*sp++ = ret_val;
}
@@ -15494,7 +15511,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
pc += 2;
sf->cur_pc = pc;
- ret_val = js_function_apply(ctx, sp[-3], 2, &sp[-2], magic);
+ ret_val = js_function_apply(ctx, sp[-3], 2, vc(&sp[-2]), magic);
if (unlikely(JS_IsException(ret_val)))
goto exception;
JS_FreeValue(ctx, sp[-3]);
@@ -15512,7 +15529,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
goto done;
CASE(OP_check_ctor_return):
- /* return TRUE if 'this' should be returned */
+ /* return true if 'this' should be returned */
if (!JS_IsObject(sp[-1])) {
if (!JS_IsUndefined(sp[-1])) {
JS_ThrowTypeError(caller_ctx, "derived class constructor must return an object or undefined");
@@ -15526,10 +15543,27 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
BREAK;
CASE(OP_check_ctor):
if (JS_IsUndefined(new_target)) {
+ non_ctor_call:
JS_ThrowTypeError(ctx, "class constructors must be invoked with 'new'");
goto exception;
}
BREAK;
+ CASE(OP_init_ctor):
+ {
+ JSValue super, ret;
+ sf->cur_pc = pc;
+ if (JS_IsUndefined(new_target))
+ goto non_ctor_call;
+ super = JS_GetPrototype(ctx, func_obj);
+ if (JS_IsException(super))
+ goto exception;
+ ret = JS_CallConstructor2(ctx, super, new_target, argc, argv);
+ JS_FreeValue(ctx, super);
+ if (JS_IsException(ret))
+ goto exception;
+ *sp++ = ret;
+ }
+ BREAK;
CASE(OP_check_brand):
{
int ret = JS_CheckBrand(ctx, sp[-2], sp[-1]);
@@ -15602,7 +15636,8 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
JS_EVAL_TYPE_DIRECT, scope_idx);
} else {
ret_val = JS_CallInternal(ctx, call_argv[-1], JS_UNDEFINED,
- JS_UNDEFINED, call_argc, call_argv, 0);
+ JS_UNDEFINED, call_argc,
+ vc(call_argv), 0);
}
if (unlikely(JS_IsException(ret_val)))
goto exception;
@@ -15634,8 +15669,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
ret_val = JS_EvalObject(ctx, JS_UNDEFINED, obj,
JS_EVAL_TYPE_DIRECT, scope_idx);
} else {
- ret_val = JS_Call(ctx, sp[-2], JS_UNDEFINED, len,
- tab);
+ ret_val = JS_Call(ctx, sp[-2], JS_UNDEFINED, len, vc(tab));
}
free_arg_list(ctx, tab, len);
if (unlikely(JS_IsException(ret_val)))
@@ -15918,7 +15952,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
pc += 2;
val = *var_refs[idx]->pvalue;
if (unlikely(JS_IsUninitialized(val))) {
- JS_ThrowReferenceErrorUninitialized2(ctx, b, idx, TRUE);
+ JS_ThrowReferenceErrorUninitialized2(ctx, b, idx, true);
goto exception;
}
sp[0] = js_dup(val);
@@ -15931,7 +15965,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
idx = get_u16(pc);
pc += 2;
if (unlikely(JS_IsUninitialized(*var_refs[idx]->pvalue))) {
- JS_ThrowReferenceErrorUninitialized2(ctx, b, idx, TRUE);
+ JS_ThrowReferenceErrorUninitialized2(ctx, b, idx, true);
goto exception;
}
set_value(ctx, var_refs[idx]->pvalue, sp[-1]);
@@ -15944,7 +15978,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
idx = get_u16(pc);
pc += 2;
if (unlikely(!JS_IsUninitialized(*var_refs[idx]->pvalue))) {
- JS_ThrowReferenceErrorUninitialized2(ctx, b, idx, TRUE);
+ JS_ThrowReferenceErrorUninitialized2(ctx, b, idx, true);
goto exception;
}
set_value(ctx, var_refs[idx]->pvalue, sp[-1]);
@@ -15966,7 +16000,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
pc += 2;
if (unlikely(JS_IsUninitialized(var_buf[idx]))) {
JS_ThrowReferenceErrorUninitialized2(caller_ctx, b, idx,
- FALSE);
+ false);
goto exception;
}
sp[0] = js_dup(var_buf[idx]);
@@ -15980,7 +16014,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
pc += 2;
if (unlikely(JS_IsUninitialized(var_buf[idx]))) {
JS_ThrowReferenceErrorUninitialized2(caller_ctx, b, idx,
- FALSE);
+ false);
goto exception;
}
set_value(ctx, &var_buf[idx], sp[-1]);
@@ -16199,7 +16233,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
BREAK;
CASE(OP_for_of_start):
sf->cur_pc = pc;
- if (js_for_of_start(ctx, sp, FALSE))
+ if (js_for_of_start(ctx, sp, false))
goto exception;
sp += 1;
*sp++ = JS_NewCatchOffset(ctx, 0);
@@ -16216,7 +16250,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
BREAK;
CASE(OP_for_await_of_start):
sf->cur_pc = pc;
- if (js_for_of_start(ctx, sp, TRUE))
+ if (js_for_of_start(ctx, sp, true))
goto exception;
sp += 1;
*sp++ = JS_NewCatchOffset(ctx, 0);
@@ -16241,7 +16275,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
sp--;
if (!JS_IsUndefined(sp[-1])) {
sf->cur_pc = pc;
- if (JS_IteratorClose(ctx, sp[-1], FALSE))
+ if (JS_IteratorClose(ctx, sp[-1], false))
goto exception;
JS_FreeValue(ctx, sp[-1]);
}
@@ -16270,7 +16304,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
{
JSValue ret;
sf->cur_pc = pc;
- ret = JS_Call(ctx, sp[-3], sp[-4], 1, (sp - 1));
+ ret = JS_Call(ctx, sp[-3], sp[-4], 1, vc(sp - 1));
if (JS_IsException(ret))
goto exception;
JS_FreeValue(ctx, sp[-1]);
@@ -16282,7 +16316,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
/* stack: iter_obj next catch_offset val */
{
JSValue method, ret;
- BOOL ret_flag;
+ bool ret_flag;
int flags;
flags = *pc++;
sf->cur_pc = pc;
@@ -16291,7 +16325,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
if (JS_IsException(method))
goto exception;
if (JS_IsUndefined(method) || JS_IsNull(method)) {
- ret_flag = TRUE;
+ ret_flag = true;
} else {
if (flags & 2) {
/* no argument */
@@ -16299,13 +16333,13 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
0, NULL);
} else {
ret = JS_CallFree(ctx, method, sp[-4],
- 1, (sp - 1));
+ 1, vc(sp - 1));
}
if (JS_IsException(ret))
goto exception;
JS_FreeValue(ctx, sp[-1]);
sp[-1] = ret;
- ret_flag = FALSE;
+ ret_flag = false;
}
sp[0] = js_bool(ret_flag);
sp += 1;
@@ -16331,39 +16365,12 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
{
JSValue val;
JSAtom atom;
- JSInlineCacheUpdate icu;
atom = get_u32(pc);
pc += 4;
sf->cur_pc = pc;
- icu = (JSInlineCacheUpdate){ic, INLINE_CACHE_MISS};
- val = JS_GetPropertyInternal2(ctx, sp[-1], atom, sp[-1], &icu, FALSE);
- if (unlikely(JS_IsException(val)))
- goto exception;
- if (icu.offset != INLINE_CACHE_MISS) {
- put_u8(pc - 5, OP_get_field_ic);
- put_u32(pc - 4, icu.offset);
- JS_FreeAtom(ctx, atom);
- }
- JS_FreeValue(ctx, sp[-1]);
- sp[-1] = val;
- }
- BREAK;
-
- CASE(OP_get_field_ic):
- {
- JSValue val;
- JSAtom atom;
- uint32_t ic_offset;
- JSInlineCacheUpdate icu;
- ic_offset = get_u32(pc);
- atom = get_ic_atom(ic, ic_offset);
- pc += 4;
- sf->cur_pc = pc;
- icu = (JSInlineCacheUpdate){ic, ic_offset};
- val = JS_GetPropertyInternalWithIC(ctx, sp[-1], atom, sp[-1], &icu, FALSE);
+ val = JS_GetPropertyInternal(ctx, sp[-1], atom, sp[-1], false);
if (unlikely(JS_IsException(val)))
goto exception;
- assert(icu.offset == ic_offset);
JS_FreeValue(ctx, sp[-1]);
sp[-1] = val;
}
@@ -16373,85 +16380,31 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
{
JSValue val;
JSAtom atom;
- JSInlineCacheUpdate icu;
atom = get_u32(pc);
pc += 4;
sf->cur_pc = pc;
- icu = (JSInlineCacheUpdate){ic, INLINE_CACHE_MISS};
- val = JS_GetPropertyInternal2(ctx, sp[-1], atom, sp[-1], &icu, FALSE);
+ val = JS_GetPropertyInternal(ctx, sp[-1], atom, sp[-1], false);
if (unlikely(JS_IsException(val)))
goto exception;
- if (icu.offset != INLINE_CACHE_MISS) {
- put_u8(pc - 5, OP_get_field2_ic);
- put_u32(pc - 4, icu.offset);
- JS_FreeAtom(ctx, atom);
- }
*sp++ = val;
}
BREAK;
- CASE(OP_get_field2_ic):
- {
- JSValue val;
- JSAtom atom;
- uint32_t ic_offset;
- JSInlineCacheUpdate icu;
- ic_offset = get_u32(pc);
- atom = get_ic_atom(ic, ic_offset);
- pc += 4;
- sf->cur_pc = pc;
- icu = (JSInlineCacheUpdate){ic, ic_offset};
- val = JS_GetPropertyInternalWithIC(ctx, sp[-1], atom, sp[-1], &icu, FALSE);
- if (unlikely(JS_IsException(val)))
- goto exception;
- assert(icu.offset == ic_offset);
- *sp++ = val;
- }
- BREAK;
-
CASE(OP_put_field):
{
int ret;
JSAtom atom;
- JSInlineCacheUpdate icu;
atom = get_u32(pc);
pc += 4;
sf->cur_pc = pc;
- icu = (JSInlineCacheUpdate){ic, INLINE_CACHE_MISS};
ret = JS_SetPropertyInternal2(ctx,
sp[-2], atom,
sp[-1], sp[-2],
- JS_PROP_THROW_STRICT, &icu);
+ JS_PROP_THROW_STRICT);
JS_FreeValue(ctx, sp[-2]);
sp -= 2;
if (unlikely(ret < 0))
goto exception;
- if (icu.offset != INLINE_CACHE_MISS) {
- put_u8(pc - 5, OP_put_field_ic);
- put_u32(pc - 4, icu.offset);
- JS_FreeAtom(ctx, atom);
- }
- }
- BREAK;
-
- CASE(OP_put_field_ic):
- {
- int ret;
- JSAtom atom;
- uint32_t ic_offset;
- JSInlineCacheUpdate icu;
- ic_offset = get_u32(pc);
- atom = get_ic_atom(ic, ic_offset);
- pc += 4;
- sf->cur_pc = pc;
- icu = (JSInlineCacheUpdate){ic, ic_offset};
- ret = JS_SetPropertyInternalWithIC(ctx, sp[-2], atom, sp[-1],
- JS_PROP_THROW_STRICT, &icu);
- JS_FreeValue(ctx, sp[-2]);
- sp -= 2;
- if (unlikely(ret < 0))
- goto exception;
- assert(icu.offset == ic_offset);
}
BREAK;
@@ -16547,7 +16500,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
JSValue proto;
proto = sp[-1];
if (JS_IsObject(proto) || JS_IsNull(proto)) {
- if (JS_SetPrototypeInternal(ctx, sp[-2], proto, TRUE) < 0)
+ if (JS_SetPrototypeInternal(ctx, sp[-2], proto, true) < 0)
goto exception;
}
JS_FreeValue(ctx, proto);
@@ -16564,7 +16517,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
JSValue obj;
JSAtom atom;
int flags, ret, op_flags;
- BOOL is_computed;
+ bool is_computed;
#define OP_DEFINE_METHOD_METHOD 0
#define OP_DEFINE_METHOD_GETTER 1
#define OP_DEFINE_METHOD_SETTER 2
@@ -16688,7 +16641,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
atom = JS_ValueToAtom(ctx, sp[-1]);
if (unlikely(atom == JS_ATOM_NULL))
goto exception;
- val = JS_GetPropertyInternal2(ctx, sp[-2], atom, sp[-3], NULL, FALSE);
+ val = JS_GetPropertyInternal(ctx, sp[-2], atom, sp[-3], false);
JS_FreeAtom(ctx, atom);
if (unlikely(JS_IsException(val)))
goto exception;
@@ -16755,7 +16708,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
ret = JS_SetPropertyInternal2(ctx,
sp[-3], atom,
sp[-1], sp[-4],
- JS_PROP_THROW_STRICT, NULL);
+ JS_PROP_THROW_STRICT);
JS_FreeAtom(ctx, atom);
JS_FreeValue(ctx, sp[-4]);
JS_FreeValue(ctx, sp[-3]);
@@ -17509,12 +17462,11 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
}
}
exception:
- if (is_backtrace_needed(ctx, rt->current_exception)) {
- /* add the backtrace information now (it is not done
- before if the exception happens in a bytecode
- operation */
+ if (needs_backtrace(rt->current_exception)
+ || JS_IsUndefined(ctx->error_back_trace)) {
sf->cur_pc = pc;
- build_backtrace(ctx, rt->current_exception, JS_UNDEFINED, NULL, 0, 0, 0);
+ build_backtrace(ctx, rt->current_exception, JS_UNDEFINED,
+ NULL, 0, 0, 0);
}
if (!JS_IsUncatchableError(ctx, rt->current_exception)) {
while (sp > stack_buf) {
@@ -17526,10 +17478,12 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
/* enumerator: close it with a throw */
JS_FreeValue(ctx, sp[-1]); /* drop the next method */
sp--;
- JS_IteratorClose(ctx, sp[-1], TRUE);
+ JS_IteratorClose(ctx, sp[-1], true);
} else {
*sp++ = rt->current_exception;
rt->current_exception = JS_UNINITIALIZED;
+ JS_FreeValueRT(rt, ctx->error_back_trace);
+ ctx->error_back_trace = JS_UNDEFINED;
pc = b->byte_code_buf + pos;
goto restart;
}
@@ -17559,15 +17513,15 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
return ret_val;
}
-JSValue JS_Call(JSContext *ctx, JSValue func_obj, JSValue this_obj,
- int argc, JSValue *argv)
+JSValue JS_Call(JSContext *ctx, JSValueConst func_obj, JSValueConst this_obj,
+ int argc, JSValueConst *argv)
{
return JS_CallInternal(ctx, func_obj, this_obj, JS_UNDEFINED,
argc, argv, JS_CALL_FLAG_COPY_ARGV);
}
-static JSValue JS_CallFree(JSContext *ctx, JSValue func_obj, JSValue this_obj,
- int argc, JSValue *argv)
+static JSValue JS_CallFree(JSContext *ctx, JSValue func_obj, JSValueConst this_obj,
+ int argc, JSValueConst *argv)
{
JSValue res = JS_CallInternal(ctx, func_obj, this_obj, JS_UNDEFINED,
argc, argv, JS_CALL_FLAG_COPY_ARGV);
@@ -17577,7 +17531,7 @@ static JSValue JS_CallFree(JSContext *ctx, JSValue func_obj, JSValue this_obj,
/* warning: the refcount of the context is not incremented. Return
NULL in case of exception (case of revoked proxy only) */
-static JSContext *JS_GetFunctionRealm(JSContext *ctx, JSValue func_obj)
+static JSContext *JS_GetFunctionRealm(JSContext *ctx, JSValueConst func_obj)
{
JSObject *p;
JSContext *realm;
@@ -17625,7 +17579,7 @@ static JSContext *JS_GetFunctionRealm(JSContext *ctx, JSValue func_obj)
return realm;
}
-static JSValue js_create_from_ctor(JSContext *ctx, JSValue ctor,
+static JSValue js_create_from_ctor(JSContext *ctx, JSValueConst ctor,
int class_id)
{
JSValue proto, obj;
@@ -17658,9 +17612,10 @@ JSValue JS_NewObjectFromCtor(JSContext *ctx, JSValueConst ctor,
/* argv[] is modified if (flags & JS_CALL_FLAG_COPY_ARGV) = 0. */
static JSValue JS_CallConstructorInternal(JSContext *ctx,
- JSValue func_obj,
- JSValue new_target,
- int argc, JSValue *argv, int flags)
+ JSValueConst func_obj,
+ JSValueConst new_target,
+ int argc, JSValueConst *argv,
+ int flags)
{
JSObject *p;
JSFunctionBytecode *b;
@@ -17678,7 +17633,7 @@ static JSValue JS_CallConstructorInternal(JSContext *ctx,
call_func = ctx->rt->class_array[p->class_id].call;
if (!call_func) {
not_a_function:
- return JS_ThrowTypeError(ctx, "not a function");
+ return JS_ThrowTypeErrorNotAFunction(ctx);
}
return call_func(ctx, func_obj, new_target, argc,
argv, flags);
@@ -17705,25 +17660,25 @@ static JSValue JS_CallConstructorInternal(JSContext *ctx,
}
}
-JSValue JS_CallConstructor2(JSContext *ctx, JSValue func_obj,
- JSValue new_target,
- int argc, JSValue *argv)
+JSValue JS_CallConstructor2(JSContext *ctx, JSValueConst func_obj,
+ JSValueConst new_target,
+ int argc, JSValueConst *argv)
{
return JS_CallConstructorInternal(ctx, func_obj, new_target,
argc, argv,
JS_CALL_FLAG_COPY_ARGV);
}
-JSValue JS_CallConstructor(JSContext *ctx, JSValue func_obj,
- int argc, JSValue *argv)
+JSValue JS_CallConstructor(JSContext *ctx, JSValueConst func_obj,
+ int argc, JSValueConst *argv)
{
return JS_CallConstructorInternal(ctx, func_obj, func_obj,
argc, argv,
JS_CALL_FLAG_COPY_ARGV);
}
-JSValue JS_Invoke(JSContext *ctx, JSValue this_val, JSAtom atom,
- int argc, JSValue *argv)
+JSValue JS_Invoke(JSContext *ctx, JSValueConst this_val, JSAtom atom,
+ int argc, JSValueConst *argv)
{
JSValue func_obj;
func_obj = JS_GetProperty(ctx, this_val, atom);
@@ -17733,7 +17688,7 @@ JSValue JS_Invoke(JSContext *ctx, JSValue this_val, JSAtom atom,
}
static JSValue JS_InvokeFree(JSContext *ctx, JSValue this_val, JSAtom atom,
- int argc, JSValue *argv)
+ int argc, JSValueConst *argv)
{
JSValue res = JS_Invoke(ctx, this_val, atom, argc, argv);
JS_FreeValue(ctx, this_val);
@@ -17742,8 +17697,9 @@ static JSValue JS_InvokeFree(JSContext *ctx, JSValue this_val, JSAtom atom,
/* JSAsyncFunctionState (used by generator and async functions) */
static __exception int async_func_init(JSContext *ctx, JSAsyncFunctionState *s,
- JSValue func_obj, JSValue this_obj,
- int argc, JSValue *argv)
+ JSValueConst func_obj,
+ JSValueConst this_obj,
+ int argc, JSValueConst *argv)
{
JSObject *p;
JSFunctionBytecode *b;
@@ -17826,7 +17782,8 @@ static JSValue async_func_resume(JSContext *ctx, JSAsyncFunctionState *s)
/* the tag does not matter provided it is not an object */
func_obj = JS_MKPTR(JS_TAG_INT, s);
return JS_CallInternal(ctx, func_obj, s->this_val, JS_UNDEFINED,
- s->argc, s->frame.arg_buf, JS_CALL_FLAG_GENERATOR);
+ s->argc, vc(s->frame.arg_buf),
+ JS_CALL_FLAG_GENERATOR);
}
@@ -17853,7 +17810,7 @@ static void free_generator_stack_rt(JSRuntime *rt, JSGeneratorData *s)
s->state = JS_GENERATOR_STATE_COMPLETED;
}
-static void js_generator_finalizer(JSRuntime *rt, JSValue obj)
+static void js_generator_finalizer(JSRuntime *rt, JSValueConst obj)
{
JSGeneratorData *s = JS_GetOpaque(obj, JS_CLASS_GENERATOR);
@@ -17868,7 +17825,7 @@ static void free_generator_stack(JSContext *ctx, JSGeneratorData *s)
free_generator_stack_rt(ctx->rt, s);
}
-static void js_generator_mark(JSRuntime *rt, JSValue val,
+static void js_generator_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
@@ -17884,15 +17841,15 @@ static void js_generator_mark(JSRuntime *rt, JSValue val,
#define GEN_MAGIC_RETURN 1
#define GEN_MAGIC_THROW 2
-static JSValue js_generator_next(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv,
- BOOL *pdone, int magic)
+static JSValue js_generator_next(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv,
+ int *pdone, int magic)
{
JSGeneratorData *s = JS_GetOpaque(this_val, JS_CLASS_GENERATOR);
JSStackFrame *sf;
JSValue ret, func_ret;
- *pdone = TRUE;
+ *pdone = true;
if (!s)
return JS_ThrowTypeError(ctx, "not a generator");
sf = &s->func_state.frame;
@@ -17913,13 +17870,13 @@ static JSValue js_generator_next(JSContext *ctx, JSValue this_val,
if (magic == GEN_MAGIC_THROW &&
s->state == JS_GENERATOR_STATE_SUSPENDED_YIELD) {
JS_Throw(ctx, ret);
- s->func_state.throw_flag = TRUE;
+ s->func_state.throw_flag = true;
} else {
sf->cur_sp[-1] = ret;
sf->cur_sp[0] = js_int32(magic);
sf->cur_sp++;
exec_no_arg:
- s->func_state.throw_flag = FALSE;
+ s->func_state.throw_flag = false;
}
s->state = JS_GENERATOR_STATE_EXECUTING;
func_ret = async_func_resume(ctx, &s->func_state);
@@ -17938,7 +17895,7 @@ static JSValue js_generator_next(JSContext *ctx, JSValue this_val,
/* return (value, done) object */
*pdone = 2;
} else {
- *pdone = FALSE;
+ *pdone = false;
}
} else {
/* end of iterator */
@@ -17971,9 +17928,9 @@ static JSValue js_generator_next(JSContext *ctx, JSValue this_val,
return ret;
}
-static JSValue js_generator_function_call(JSContext *ctx, JSValue func_obj,
- JSValue this_obj,
- int argc, JSValue *argv,
+static JSValue js_generator_function_call(JSContext *ctx, JSValueConst func_obj,
+ JSValueConst this_obj,
+ int argc, JSValueConst *argv,
int flags)
{
JSValue obj, func_ret;
@@ -18011,7 +17968,7 @@ static void js_async_function_terminate(JSRuntime *rt, JSAsyncFunctionData *s)
{
if (s->is_active) {
async_func_free(rt, &s->func_state);
- s->is_active = FALSE;
+ s->is_active = false;
}
}
@@ -18031,7 +17988,8 @@ static void js_async_function_free(JSRuntime *rt, JSAsyncFunctionData *s)
}
}
-static void js_async_function_resolve_finalizer(JSRuntime *rt, JSValue val)
+static void js_async_function_resolve_finalizer(JSRuntime *rt,
+ JSValueConst val)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
JSAsyncFunctionData *s = p->u.async_function_data;
@@ -18040,7 +17998,7 @@ static void js_async_function_resolve_finalizer(JSRuntime *rt, JSValue val)
}
}
-static void js_async_function_resolve_mark(JSRuntime *rt, JSValue val,
+static void js_async_function_resolve_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
@@ -18073,20 +18031,32 @@ static int js_async_function_resolve_create(JSContext *ctx,
return 0;
}
-static void js_async_function_resume(JSContext *ctx, JSAsyncFunctionData *s)
+static bool js_async_function_resume(JSContext *ctx, JSAsyncFunctionData *s)
{
+ bool is_success = true;
JSValue func_ret, ret2;
func_ret = async_func_resume(ctx, &s->func_state);
if (JS_IsException(func_ret)) {
- JSValue error;
fail:
- error = JS_GetException(ctx);
- ret2 = JS_Call(ctx, s->resolving_funcs[1], JS_UNDEFINED,
- 1, &error);
- JS_FreeValue(ctx, error);
+ if (unlikely(JS_IsUncatchableError(ctx, ctx->rt->current_exception))) {
+ is_success = false;
+ } else {
+ JSValue error = JS_GetException(ctx);
+ ret2 = JS_Call(ctx, s->resolving_funcs[1], JS_UNDEFINED,
+ 1, vc(&error));
+ JS_FreeValue(ctx, error);
+ resolved:
+ if (unlikely(JS_IsException(ret2))) {
+ if (JS_IsUncatchableError(ctx, ctx->rt->current_exception)) {
+ is_success = false;
+ } else {
+ abort(); /* BUG */
+ }
+ }
+ JS_FreeValue(ctx, ret2);
+ }
js_async_function_terminate(ctx->rt, s);
- JS_FreeValue(ctx, ret2); /* XXX: what to do if exception ? */
} else {
JSValue value;
value = s->func_state.frame.cur_sp[-1];
@@ -18094,10 +18064,9 @@ static void js_async_function_resume(JSContext *ctx, JSAsyncFunctionData *s)
if (JS_IsUndefined(func_ret)) {
/* function returned */
ret2 = JS_Call(ctx, s->resolving_funcs[0], JS_UNDEFINED,
- 1, &value);
- JS_FreeValue(ctx, ret2); /* XXX: what to do if exception ? */
+ 1, vc(&value));
JS_FreeValue(ctx, value);
- js_async_function_terminate(ctx->rt, s);
+ goto resolved;
} else {
JSValue promise, resolving_funcs[2], resolving_funcs1[2];
int i, res;
@@ -18105,7 +18074,7 @@ static void js_async_function_resume(JSContext *ctx, JSAsyncFunctionData *s)
/* await */
JS_FreeValue(ctx, func_ret); /* not used */
promise = js_promise_resolve(ctx, ctx->promise_ctor,
- 1, &value, 0);
+ 1, vc(&value), 0);
JS_FreeValue(ctx, value);
if (JS_IsException(promise))
goto fail;
@@ -18119,8 +18088,8 @@ static void js_async_function_resume(JSContext *ctx, JSAsyncFunctionData *s)
for(i = 0; i < 2; i++)
resolving_funcs1[i] = JS_UNDEFINED;
res = perform_promise_then(ctx, promise,
- resolving_funcs,
- resolving_funcs1);
+ vc(resolving_funcs),
+ vc(resolving_funcs1));
JS_FreeValue(ctx, promise);
for(i = 0; i < 2; i++)
JS_FreeValue(ctx, resolving_funcs[i]);
@@ -18128,18 +18097,19 @@ static void js_async_function_resume(JSContext *ctx, JSAsyncFunctionData *s)
goto fail;
}
}
+ return is_success;
}
static JSValue js_async_function_resolve_call(JSContext *ctx,
- JSValue func_obj,
- JSValue this_obj,
- int argc, JSValue *argv,
+ JSValueConst func_obj,
+ JSValueConst this_obj,
+ int argc, JSValueConst *argv,
int flags)
{
JSObject *p = JS_VALUE_GET_OBJ(func_obj);
JSAsyncFunctionData *s = p->u.async_function_data;
- BOOL is_reject = p->class_id - JS_CLASS_ASYNC_FUNCTION_RESOLVE;
- JSValue arg;
+ bool is_reject = p->class_id - JS_CLASS_ASYNC_FUNCTION_RESOLVE;
+ JSValueConst arg;
if (argc > 0)
arg = argv[0];
@@ -18152,13 +18122,14 @@ static JSValue js_async_function_resolve_call(JSContext *ctx,
/* return value of await */
s->func_state.frame.cur_sp[-1] = js_dup(arg);
}
- js_async_function_resume(ctx, s);
+ if (!js_async_function_resume(ctx, s))
+ return JS_EXCEPTION;
return JS_UNDEFINED;
}
-static JSValue js_async_function_call(JSContext *ctx, JSValue func_obj,
- JSValue this_obj,
- int argc, JSValue *argv, int flags)
+static JSValue js_async_function_call(JSContext *ctx, JSValueConst func_obj,
+ JSValueConst this_obj,
+ int argc, JSValueConst *argv, int flags)
{
JSValue promise;
JSAsyncFunctionData *s;
@@ -18168,7 +18139,7 @@ static JSValue js_async_function_call(JSContext *ctx, JSValue func_obj,
return JS_EXCEPTION;
s->header.ref_count = 1;
add_gc_object(ctx->rt, &s->header, JS_GC_OBJ_TYPE_ASYNC_FUNCTION);
- s->is_active = FALSE;
+ s->is_active = false;
s->resolving_funcs[0] = JS_UNDEFINED;
s->resolving_funcs[1] = JS_UNDEFINED;
@@ -18182,9 +18153,10 @@ static JSValue js_async_function_call(JSContext *ctx, JSValue func_obj,
js_async_function_free(ctx->rt, s);
return JS_EXCEPTION;
}
- s->is_active = TRUE;
+ s->is_active = true;
- js_async_function_resume(ctx, s);
+ if (!js_async_function_resume(ctx, s))
+ goto fail;
js_async_function_free(ctx->rt, s);
@@ -18240,7 +18212,7 @@ static void js_async_generator_free(JSRuntime *rt,
js_free_rt(rt, s);
}
-static void js_async_generator_finalizer(JSRuntime *rt, JSValue obj)
+static void js_async_generator_finalizer(JSRuntime *rt, JSValueConst obj)
{
JSAsyncGeneratorData *s = JS_GetOpaque(obj, JS_CLASS_ASYNC_GENERATOR);
@@ -18249,7 +18221,7 @@ static void js_async_generator_finalizer(JSRuntime *rt, JSValue obj)
}
}
-static void js_async_generator_mark(JSRuntime *rt, JSValue val,
+static void js_async_generator_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func)
{
JSAsyncGeneratorData *s = JS_GetOpaque(val, JS_CLASS_ASYNC_GENERATOR);
@@ -18271,21 +18243,21 @@ static void js_async_generator_mark(JSRuntime *rt, JSValue val,
}
static JSValue js_async_generator_resolve_function(JSContext *ctx,
- JSValue this_obj,
- int argc, JSValue *argv,
- int magic, JSValue *func_data);
+ JSValueConst this_obj,
+ int argc, JSValueConst *argv,
+ int magic, JSValueConst *func_data);
static int js_async_generator_resolve_function_create(JSContext *ctx,
JSValue generator,
JSValue *resolving_funcs,
- BOOL is_resume_next)
+ bool is_resume_next)
{
int i;
JSValue func;
for(i = 0; i < 2; i++) {
func = JS_NewCFunctionData(ctx, js_async_generator_resolve_function, 1,
- i + is_resume_next * 2, 1, &generator);
+ i + is_resume_next * 2, 1, vc(&generator));
if (JS_IsException(func)) {
if (i == 1)
JS_FreeValue(ctx, resolving_funcs[0]);
@@ -18304,12 +18276,12 @@ static int js_async_generator_await(JSContext *ctx,
int i, res;
promise = js_promise_resolve(ctx, ctx->promise_ctor,
- 1, &value, 0);
+ 1, vc(&value), 0);
if (JS_IsException(promise))
goto fail;
if (js_async_generator_resolve_function_create(ctx, JS_MKPTR(JS_TAG_OBJECT, s->generator),
- resolving_funcs, FALSE)) {
+ resolving_funcs, false)) {
JS_FreeValue(ctx, promise);
goto fail;
}
@@ -18319,8 +18291,8 @@ static int js_async_generator_await(JSContext *ctx,
for(i = 0; i < 2; i++)
resolving_funcs1[i] = JS_UNDEFINED;
res = perform_promise_then(ctx, promise,
- resolving_funcs,
- resolving_funcs1);
+ vc(resolving_funcs),
+ vc(resolving_funcs1));
JS_FreeValue(ctx, promise);
for(i = 0; i < 2; i++)
JS_FreeValue(ctx, resolving_funcs[i]);
@@ -18333,7 +18305,7 @@ static int js_async_generator_await(JSContext *ctx,
static void js_async_generator_resolve_or_reject(JSContext *ctx,
JSAsyncGeneratorData *s,
- JSValue result,
+ JSValueConst result,
int is_reject)
{
JSAsyncGeneratorRequest *next;
@@ -18353,8 +18325,8 @@ static void js_async_generator_resolve_or_reject(JSContext *ctx,
static void js_async_generator_resolve(JSContext *ctx,
JSAsyncGeneratorData *s,
- JSValue value,
- BOOL done)
+ JSValueConst value,
+ bool done)
{
JSValue result;
result = js_create_iterator_result(ctx, js_dup(value), done);
@@ -18365,7 +18337,7 @@ static void js_async_generator_resolve(JSContext *ctx,
static void js_async_generator_reject(JSContext *ctx,
JSAsyncGeneratorData *s,
- JSValue exception)
+ JSValueConst exception)
{
js_async_generator_resolve_or_reject(ctx, s, exception, 1);
}
@@ -18387,13 +18359,13 @@ static int js_async_generator_completed_return(JSContext *ctx,
int res;
// Can fail looking up JS_ATOM_constructor when is_reject==0.
- promise = js_promise_resolve(ctx, ctx->promise_ctor, 1, &value,
+ promise = js_promise_resolve(ctx, ctx->promise_ctor, 1, vc(&value),
/*is_reject*/0);
// A poisoned .constructor property is observable and the resulting
// exception should be delivered to the catch handler.
if (JS_IsException(promise)) {
JSValue err = JS_GetException(ctx);
- promise = js_promise_resolve(ctx, ctx->promise_ctor, 1, &err,
+ promise = js_promise_resolve(ctx, ctx->promise_ctor, 1, vc(&err),
/*is_reject*/1);
JS_FreeValue(ctx, err);
if (JS_IsException(promise))
@@ -18402,15 +18374,15 @@ static int js_async_generator_completed_return(JSContext *ctx,
if (js_async_generator_resolve_function_create(ctx,
JS_MKPTR(JS_TAG_OBJECT, s->generator),
resolving_funcs1,
- TRUE)) {
+ true)) {
JS_FreeValue(ctx, promise);
return -1;
}
resolving_funcs[0] = JS_UNDEFINED;
resolving_funcs[1] = JS_UNDEFINED;
res = perform_promise_then(ctx, promise,
- resolving_funcs1,
- resolving_funcs);
+ vc(resolving_funcs1),
+ vc(resolving_funcs));
JS_FreeValue(ctx, resolving_funcs1[0]);
JS_FreeValue(ctx, resolving_funcs1[1]);
JS_FreeValue(ctx, promise);
@@ -18442,7 +18414,7 @@ static void js_async_generator_resume_next(JSContext *ctx,
break;
case JS_ASYNC_GENERATOR_STATE_COMPLETED:
if (next->completion_type == GEN_MAGIC_NEXT) {
- js_async_generator_resolve(ctx, s, JS_UNDEFINED, TRUE);
+ js_async_generator_resolve(ctx, s, JS_UNDEFINED, true);
} else if (next->completion_type == GEN_MAGIC_RETURN) {
s->state = JS_ASYNC_GENERATOR_STATE_AWAITING_RETURN;
js_async_generator_completed_return(ctx, s, next->result);
@@ -18456,7 +18428,7 @@ static void js_async_generator_resume_next(JSContext *ctx,
if (next->completion_type == GEN_MAGIC_THROW &&
s->state == JS_ASYNC_GENERATOR_STATE_SUSPENDED_YIELD) {
JS_Throw(ctx, value);
- s->func_state.throw_flag = TRUE;
+ s->func_state.throw_flag = true;
} else {
/* 'yield' returns a value. 'yield *' also returns a value
in case the 'throw' method is called */
@@ -18465,7 +18437,7 @@ static void js_async_generator_resume_next(JSContext *ctx,
js_int32(next->completion_type);
s->func_state.frame.cur_sp++;
exec_no_arg:
- s->func_state.throw_flag = FALSE;
+ s->func_state.throw_flag = false;
}
s->state = JS_ASYNC_GENERATOR_STATE_EXECUTING;
resume_exec:
@@ -18487,7 +18459,7 @@ static void js_async_generator_resume_next(JSContext *ctx,
s->state = JS_ASYNC_GENERATOR_STATE_SUSPENDED_YIELD_STAR;
else
s->state = JS_ASYNC_GENERATOR_STATE_SUSPENDED_YIELD;
- js_async_generator_resolve(ctx, s, value, FALSE);
+ js_async_generator_resolve(ctx, s, value, false);
JS_FreeValue(ctx, value);
break;
case FUNC_RET_AWAIT:
@@ -18495,7 +18467,7 @@ static void js_async_generator_resume_next(JSContext *ctx,
JS_FreeValue(ctx, value);
if (ret < 0) {
/* exception: throw it */
- s->func_state.throw_flag = TRUE;
+ s->func_state.throw_flag = true;
goto resume_exec;
}
goto done;
@@ -18508,7 +18480,7 @@ static void js_async_generator_resume_next(JSContext *ctx,
value = s->func_state.frame.cur_sp[-1];
s->func_state.frame.cur_sp[-1] = JS_UNDEFINED;
js_async_generator_complete(ctx, s);
- js_async_generator_resolve(ctx, s, value, TRUE);
+ js_async_generator_resolve(ctx, s, value, true);
JS_FreeValue(ctx, value);
}
break;
@@ -18520,13 +18492,13 @@ static void js_async_generator_resume_next(JSContext *ctx,
}
static JSValue js_async_generator_resolve_function(JSContext *ctx,
- JSValue this_obj,
- int argc, JSValue *argv,
- int magic, JSValue *func_data)
+ JSValueConst this_obj,
+ int argc, JSValueConst *argv,
+ int magic, JSValueConst *func_data)
{
- BOOL is_reject = magic & 1;
+ bool is_reject = magic & 1;
JSAsyncGeneratorData *s = JS_GetOpaque(func_data[0], JS_CLASS_ASYNC_GENERATOR);
- JSValue arg = argv[0];
+ JSValueConst arg = argv[0];
/* XXX: what if s == NULL */
@@ -18538,7 +18510,7 @@ static JSValue js_async_generator_resolve_function(JSContext *ctx,
if (is_reject) {
js_async_generator_reject(ctx, s, arg);
} else {
- js_async_generator_resolve(ctx, s, arg, TRUE);
+ js_async_generator_resolve(ctx, s, arg, true);
}
} else {
/* restart function execution after await() */
@@ -18556,8 +18528,8 @@ static JSValue js_async_generator_resolve_function(JSContext *ctx,
}
/* magic = GEN_MAGIC_x */
-static JSValue js_async_generator_next(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv,
+static JSValue js_async_generator_next(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv,
int magic)
{
JSAsyncGeneratorData *s = JS_GetOpaque(this_val, JS_CLASS_ASYNC_GENERATOR);
@@ -18572,7 +18544,7 @@ static JSValue js_async_generator_next(JSContext *ctx, JSValue this_val,
JS_ThrowTypeError(ctx, "not an AsyncGenerator object");
err = JS_GetException(ctx);
res2 = JS_Call(ctx, resolving_funcs[1], JS_UNDEFINED,
- 1, &err);
+ 1, vc(&err));
JS_FreeValue(ctx, err);
JS_FreeValue(ctx, res2);
JS_FreeValue(ctx, resolving_funcs[0]);
@@ -18599,9 +18571,10 @@ static JSValue js_async_generator_next(JSContext *ctx, JSValue this_val,
return JS_EXCEPTION;
}
-static JSValue js_async_generator_function_call(JSContext *ctx, JSValue func_obj,
- JSValue this_obj,
- int argc, JSValue *argv,
+static JSValue js_async_generator_function_call(JSContext *ctx,
+ JSValueConst func_obj,
+ JSValueConst this_obj,
+ int argc, JSValueConst *argv,
int flags)
{
JSValue obj, func_ret;
@@ -18821,29 +18794,29 @@ typedef struct JSFunctionDef {
struct list_head child_list; /* list of JSFunctionDef.link */
struct list_head link;
- BOOL is_eval; /* TRUE if eval code */
- int eval_type; /* only valid if is_eval = TRUE */
- BOOL is_global_var; /* TRUE if variables are not defined locally:
+ bool is_eval; /* true if eval code */
+ int eval_type; /* only valid if is_eval = true */
+ bool is_global_var; /* true if variables are not defined locally:
eval global, eval module or non strict eval */
- BOOL is_func_expr; /* TRUE if function expression */
- BOOL has_home_object; /* TRUE if the home object is available */
- BOOL has_prototype; /* true if a prototype field is necessary */
- BOOL has_simple_parameter_list;
- BOOL has_parameter_expressions; /* if true, an argument scope is created */
- BOOL has_use_strict; /* to reject directive in special cases */
- BOOL has_eval_call; /* true if the function contains a call to eval() */
- BOOL has_arguments_binding; /* true if the 'arguments' binding is
+ bool is_func_expr; /* true if function expression */
+ bool has_home_object; /* true if the home object is available */
+ bool has_prototype; /* true if a prototype field is necessary */
+ bool has_simple_parameter_list;
+ bool has_parameter_expressions; /* if true, an argument scope is created */
+ bool has_use_strict; /* to reject directive in special cases */
+ bool has_eval_call; /* true if the function contains a call to eval() */
+ bool has_arguments_binding; /* true if the 'arguments' binding is
available in the function */
- BOOL has_this_binding; /* true if the 'this' and new.target binding are
+ bool has_this_binding; /* true if the 'this' and new.target binding are
available in the function */
- BOOL new_target_allowed; /* true if the 'new.target' does not
+ bool new_target_allowed; /* true if the 'new.target' does not
throw a syntax error */
- BOOL super_call_allowed; /* true if super() is allowed */
- BOOL super_allowed; /* true if super. or super[] is allowed */
- BOOL arguments_allowed; /* true if the 'arguments' identifier is allowed */
- BOOL is_derived_class_constructor;
- BOOL in_function_body;
- BOOL backtrace_barrier;
+ bool super_call_allowed; /* true if super() is allowed */
+ bool super_allowed; /* true if super. or super[] is allowed */
+ bool arguments_allowed; /* true if the 'arguments' identifier is allowed */
+ bool is_derived_class_constructor;
+ bool in_function_body;
+ bool backtrace_barrier;
JSFunctionKindEnum func_kind : 8;
JSParseFunctionEnum func_type : 7;
uint8_t is_strict_mode : 1;
@@ -18869,7 +18842,7 @@ typedef struct JSFunctionDef {
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;
+ bool need_home_object;
int scope_level; /* index into fd->scopes if the current lexical scope */
int scope_first; /* index into vd->vars of first lexically scoped variable */
@@ -18885,7 +18858,7 @@ typedef struct JSFunctionDef {
DynBuf byte_code;
int last_opcode_pos; /* -1 if no last opcode */
- BOOL use_short_opcodes; /* true if short opcodes are used in byte_code */
+ bool use_short_opcodes; /* true if short opcodes are used in byte_code */
LabelSlot *label_slots;
int label_size; /* allocated size for label_slots[] */
@@ -18923,8 +18896,7 @@ typedef struct JSFunctionDef {
int source_len;
JSModuleDef *module; /* != NULL when parsing a module */
- BOOL has_await; /* TRUE if await is used (used in module eval) */
- JSInlineCache *ic; /* inline cache for field op */
+ bool has_await; /* true if await is used (used in module eval) */
} JSFunctionDef;
typedef struct JSToken {
@@ -18942,8 +18914,8 @@ typedef struct JSToken {
} num;
struct {
JSAtom atom;
- BOOL has_escape;
- BOOL is_reserved;
+ bool has_escape;
+ bool is_reserved;
} ident;
struct {
JSValue body;
@@ -18960,7 +18932,7 @@ typedef struct JSParseState {
int col_num; /* column number of current offset */
const char *filename;
JSToken token;
- BOOL got_lf; /* true if got line feed before the current token */
+ bool got_lf; /* true if got line feed before the current token */
const uint8_t *last_ptr;
const uint8_t *buf_start;
const uint8_t *buf_ptr;
@@ -18970,12 +18942,12 @@ typedef struct JSParseState {
/* current function code */
JSFunctionDef *cur_func;
- BOOL is_module; /* parsing a module */
- BOOL allow_html_comments;
+ bool is_module; /* parsing a module */
+ bool allow_html_comments;
} JSParseState;
typedef struct JSOpCode {
-#ifdef DUMP_BYTECODE
+#ifdef ENABLE_DUMPS // JS_DUMP_BYTECODE_*
const char *name;
#endif
uint8_t size; /* in bytes */
@@ -18988,7 +18960,7 @@ typedef struct JSOpCode {
static const JSOpCode opcode_info[OP_COUNT + (OP_TEMP_END - OP_TEMP_START)] = {
#define FMT(f)
-#ifdef DUMP_BYTECODE
+#ifdef ENABLE_DUMPS // JS_DUMP_BYTECODE_*
#define DEF(id, size, n_pop, n_push, f) { #id, size, n_pop, n_push, OP_FMT_ ## f },
#else
#define DEF(id, size, n_pop, n_push, f) { size, n_pop, n_push, OP_FMT_ ## f },
@@ -19097,14 +19069,14 @@ static void __attribute((unused)) dump_token(JSParseState *s,
}
}
-int __attribute__((format(printf, 2, 3))) js_parse_error(JSParseState *s, const char *fmt, ...)
+int JS_PRINTF_FORMAT_ATTR(2, 3) js_parse_error(JSParseState *s, JS_PRINTF_FORMAT const char *fmt, ...)
{
JSContext *ctx = s->ctx;
va_list ap;
int backtrace_flags;
va_start(ap, fmt);
- JS_ThrowError2(ctx, JS_SYNTAX_ERROR, fmt, ap, FALSE);
+ JS_ThrowError2(ctx, JS_SYNTAX_ERROR, false, fmt, ap);
va_end(ap);
backtrace_flags = 0;
if (s->cur_func && s->cur_func->backtrace_barrier)
@@ -19230,7 +19202,7 @@ static __exception int js_parse_template_part(JSParseState *s,
}
static __exception int js_parse_string(JSParseState *s, int sep,
- BOOL do_throw, const uint8_t *p,
+ bool do_throw, const uint8_t *p,
JSToken *token, const uint8_t **pp)
{
const uint8_t *p_next;
@@ -19320,7 +19292,7 @@ static __exception int js_parse_string(JSParseState *s, int sep,
if (c == CP_LS || c == CP_PS)
continue;
} else {
- ret = lre_parse_escape(&p, TRUE);
+ ret = lre_parse_escape(&p, true);
if (ret == -1) {
if (do_throw) {
js_parse_error(s, "Invalid %s escape sequence",
@@ -19363,7 +19335,7 @@ static __exception int js_parse_string(JSParseState *s, int sep,
return -1;
}
-static inline BOOL token_is_pseudo_keyword(JSParseState *s, JSAtom atom) {
+static inline bool token_is_pseudo_keyword(JSParseState *s, JSAtom atom) {
return s->token.val == TOK_IDENT && s->token.u.ident.atom == atom &&
!s->token.u.ident.has_escape;
}
@@ -19371,14 +19343,14 @@ static inline BOOL token_is_pseudo_keyword(JSParseState *s, JSAtom atom) {
static __exception int js_parse_regexp(JSParseState *s)
{
const uint8_t *p, *p_next;
- BOOL in_class;
+ bool in_class;
StringBuffer b_s, *b = &b_s;
StringBuffer b2_s, *b2 = &b2_s;
uint32_t c;
p = s->buf_ptr;
p++;
- in_class = FALSE;
+ in_class = false;
if (string_buffer_init(s->ctx, b, 32))
return -1;
if (string_buffer_init(s->ctx, b2, 1))
@@ -19396,10 +19368,10 @@ static __exception int js_parse_regexp(JSParseState *s)
if (!in_class)
break;
} else if (c == '[') {
- in_class = TRUE;
+ in_class = true;
} else if (c == ']') {
/* XXX: incorrect as the first character in a class */
- in_class = FALSE;
+ in_class = false;
} else if (c == '\\') {
if (string_buffer_putc8(b, c))
goto fail;
@@ -19505,7 +19477,7 @@ static void update_token_ident(JSParseState *s)
((s->cur_func->parent->func_kind & JS_FUNC_ASYNC) ||
s->cur_func->parent->func_type == JS_PARSE_FUNC_CLASS_STATIC_INIT))))) {
if (s->token.u.ident.has_escape) {
- s->token.u.ident.is_reserved = TRUE;
+ s->token.u.ident.is_reserved = true;
s->token.val = TOK_IDENT;
} else {
/* The keywords atoms are pre allocated */
@@ -19522,14 +19494,14 @@ static void reparse_ident_token(JSParseState *s)
(s->token.val >= TOK_FIRST_KEYWORD &&
s->token.val <= TOK_LAST_KEYWORD)) {
s->token.val = TOK_IDENT;
- s->token.u.ident.is_reserved = FALSE;
+ s->token.u.ident.is_reserved = false;
update_token_ident(s);
}
}
/* 'c' is the first character. Return JS_ATOM_NULL in case of error */
static JSAtom parse_ident(JSParseState *s, const uint8_t **pp,
- BOOL *pident_has_escape, int c, BOOL is_private)
+ bool *pident_has_escape, int c, bool is_private)
{
const uint8_t *p, *p_next;
char ident_buf[128], *buf;
@@ -19551,8 +19523,8 @@ static JSAtom parse_ident(JSParseState *s, const uint8_t **pp,
c = *p;
p_next = p + 1;
if (c == '\\' && *p_next == 'u') {
- c = lre_parse_escape(&p_next, TRUE);
- *pident_has_escape = TRUE;
+ c = lre_parse_escape(&p_next, true);
+ *pident_has_escape = true;
} else if (c >= 0x80) {
c = utf8_decode(p, &p_next);
/* no need to test for invalid UTF-8, 0xFFFD is not ident_next */
@@ -19579,7 +19551,7 @@ static __exception int next_token(JSParseState *s)
{
const uint8_t *p, *p_next;
int c;
- BOOL ident_has_escape;
+ bool ident_has_escape;
JSAtom atom;
int flags, radix;
@@ -19591,7 +19563,7 @@ static __exception int next_token(JSParseState *s)
free_token(s, &s->token);
p = s->last_ptr = s->buf_ptr;
- s->got_lf = FALSE;
+ s->got_lf = false;
s->last_line_num = s->token.line_num;
s->last_col_num = s->token.col_num;
redo:
@@ -19614,7 +19586,7 @@ static __exception int next_token(JSParseState *s)
break;
case '\'':
case '\"':
- if (js_parse_string(s, c, TRUE, p + 1, &s->token, &p))
+ if (js_parse_string(s, c, true, p + 1, &s->token, &p))
goto fail;
break;
case '\r': /* accept DOS and MAC newline sequences */
@@ -19627,7 +19599,7 @@ static __exception int next_token(JSParseState *s)
line_terminator:
s->eol = &p[-1];
s->mark = p;
- s->got_lf = TRUE;
+ s->got_lf = true;
s->line_num++;
goto redo;
case '\f':
@@ -19651,17 +19623,17 @@ static __exception int next_token(JSParseState *s)
}
if (*p == '\n') {
s->line_num++;
- s->got_lf = TRUE; /* considered as LF for ASI */
+ s->got_lf = true; /* considered as LF for ASI */
s->eol = p++;
s->mark = p;
} else if (*p == '\r') {
- s->got_lf = TRUE; /* considered as LF for ASI */
+ s->got_lf = true; /* considered as LF for ASI */
p++;
} else if (*p >= 0x80) {
c = utf8_decode(p, &p);
/* ignore invalid UTF-8 in comments */
if (c == CP_LS || c == CP_PS) {
- s->got_lf = TRUE; /* considered as LF for ASI */
+ s->got_lf = true; /* considered as LF for ASI */
}
} else {
p++;
@@ -19702,11 +19674,11 @@ static __exception int next_token(JSParseState *s)
case '\\':
if (p[1] == 'u') {
const uint8_t *p1 = p + 1;
- int c1 = lre_parse_escape(&p1, TRUE);
+ int c1 = lre_parse_escape(&p1, true);
if (c1 >= 0 && lre_js_is_ident_first(c1)) {
c = c1;
p = p1;
- ident_has_escape = TRUE;
+ ident_has_escape = true;
goto has_ident;
} else {
/* XXX: syntax error? */
@@ -19732,14 +19704,14 @@ static __exception int next_token(JSParseState *s)
/* identifier */
s->mark = p;
p++;
- ident_has_escape = FALSE;
+ ident_has_escape = false;
has_ident:
- atom = parse_ident(s, &p, &ident_has_escape, c, FALSE);
+ atom = parse_ident(s, &p, &ident_has_escape, c, false);
if (atom == JS_ATOM_NULL)
goto fail;
s->token.u.ident.atom = atom;
s->token.u.ident.has_escape = ident_has_escape;
- s->token.u.ident.is_reserved = FALSE;
+ s->token.u.ident.is_reserved = false;
s->token.val = TOK_IDENT;
update_token_ident(s);
break;
@@ -19750,7 +19722,7 @@ static __exception int next_token(JSParseState *s)
c = *p;
p_next = p + 1;
if (c == '\\' && *p_next == 'u') {
- c = lre_parse_escape(&p_next, TRUE);
+ c = lre_parse_escape(&p_next, true);
} else if (c >= 0x80) {
c = utf8_decode(p, &p_next);
if (p_next == p + 1)
@@ -19761,8 +19733,8 @@ static __exception int next_token(JSParseState *s)
goto fail;
}
p = p_next;
- ident_has_escape = FALSE; /* not used */
- atom = parse_ident(s, &p, &ident_has_escape, c, TRUE);
+ ident_has_escape = false; /* not used */
+ atom = parse_ident(s, &p, &ident_has_escape, c, true);
if (atom == JS_ATOM_NULL)
goto fail;
s->token.u.ident.atom = atom;
@@ -20033,7 +20005,7 @@ static __exception int next_token(JSParseState *s)
s->mark = p;
goto redo;
} else if (lre_js_is_ident_first(c)) {
- ident_has_escape = FALSE;
+ ident_has_escape = false;
goto has_ident;
} else {
js_parse_error(s, "unexpected character");
@@ -20306,8 +20278,8 @@ static __exception int json_next_token(JSParseState *s)
if (atom == JS_ATOM_NULL)
goto fail;
s->token.u.ident.atom = atom;
- s->token.u.ident.has_escape = FALSE;
- s->token.u.ident.is_reserved = FALSE;
+ s->token.u.ident.has_escape = false;
+ s->token.u.ident.is_reserved = false;
s->token.val = TOK_IDENT;
break;
case '-':
@@ -20362,7 +20334,7 @@ static __exception int json_next_token(JSParseState *s)
/* only used for ':' and '=>', 'let' or 'function' look-ahead. *pp is
only set if TOK_IMPORT is returned */
/* XXX: handle all unicode cases */
-static int simple_next_token(const uint8_t **pp, BOOL no_line_terminator)
+static int simple_next_token(const uint8_t **pp, bool no_line_terminator)
{
const uint8_t *p;
uint32_t c;
@@ -20441,7 +20413,7 @@ static int simple_next_token(const uint8_t **pp, BOOL no_line_terminator)
}
}
-static int peek_token(JSParseState *s, BOOL no_line_terminator)
+static int peek_token(JSParseState *s, bool no_line_terminator)
{
const uint8_t *p = s->buf_ptr;
return simple_next_token(&p, no_line_terminator);
@@ -20477,7 +20449,7 @@ static inline int get_prev_opcode(JSFunctionDef *fd) {
return fd->byte_code.buf[fd->last_opcode_pos];
}
-static BOOL js_is_live_code(JSParseState *s) {
+static bool js_is_live_code(JSParseState *s) {
switch (get_prev_opcode(s->cur_func)) {
case OP_tail_call:
case OP_tail_call_method:
@@ -20490,9 +20462,9 @@ static BOOL js_is_live_code(JSParseState *s) {
case OP_goto8:
case OP_goto16:
case OP_ret:
- return FALSE;
+ return false;
default:
- return TRUE;
+ return true;
}
}
@@ -20517,8 +20489,8 @@ static void emit_source_loc(JSParseState *s)
DynBuf *bc = &fd->byte_code;
dbuf_putc(bc, OP_source_loc);
- dbuf_put_u32(bc, s->last_line_num);
- dbuf_put_u32(bc, s->last_col_num);
+ dbuf_put_u32(bc, s->token.line_num);
+ dbuf_put_u32(bc, s->token.col_num);
}
static void emit_op(JSParseState *s, uint8_t val)
@@ -20535,36 +20507,6 @@ static void emit_atom(JSParseState *s, JSAtom name)
emit_u32(s, JS_DupAtom(s->ctx, name));
}
-static force_inline uint32_t get_index_hash(JSAtom atom, int hash_bits)
-{
- return (atom * 0x9e370001) >> (32 - hash_bits);
-}
-
-static void emit_ic(JSParseState *s, JSAtom atom)
-{
- uint32_t h;
- JSContext *ctx;
- JSInlineCache *ic;
- JSInlineCacheHashSlot *ch;
-
- ic = s->cur_func->ic;
- ctx = s->ctx;
- if (ic->count + 1 >= ic->capacity && resize_ic_hash(ctx, ic))
- return;
- h = get_index_hash(atom, ic->hash_bits);
- for (ch = ic->hash[h]; ch != NULL; ch = ch->next)
- if (ch->atom == atom)
- return;
- ch = js_malloc(ctx, sizeof(*ch));
- if (unlikely(!ch))
- return;
- ch->atom = JS_DupAtom(ctx, atom);
- ch->index = 0;
- ch->next = ic->hash[h];
- ic->hash[h] = ch;
- ic->count += 1;
-}
-
static int update_label(JSFunctionDef *s, int label, int delta)
{
LabelSlot *ls;
@@ -20649,14 +20591,14 @@ static int cpool_add(JSParseState *s, JSValue val)
}
static __exception int emit_push_const(JSParseState *s, JSValue val,
- BOOL as_atom)
+ bool as_atom)
{
int idx;
if (JS_VALUE_GET_TAG(val) == JS_TAG_STRING && as_atom) {
JSAtom atom;
/* warning: JS_NewAtomStr frees the string value */
- JS_DupValue(s->ctx, val);
+ js_dup(val);
atom = JS_NewAtomStr(s->ctx, JS_VALUE_GET_STRING(val));
if (atom != JS_ATOM_NULL && !__JS_AtomIsTaggedInt(atom)) {
emit_op(s, OP_push_atom_value);
@@ -20665,7 +20607,7 @@ static __exception int emit_push_const(JSParseState *s, JSValue val,
}
}
- idx = cpool_add(s, JS_DupValue(s->ctx, val));
+ idx = cpool_add(s, js_dup(val));
if (idx < 0)
return -1;
emit_op(s, OP_push_const);
@@ -20805,15 +20747,15 @@ static int find_var_in_scope(JSContext *ctx, JSFunctionDef *fd,
/* return true if scope == parent_scope or if scope is a child of
parent_scope */
-static BOOL is_child_scope(JSContext *ctx, JSFunctionDef *fd,
+static bool is_child_scope(JSContext *ctx, JSFunctionDef *fd,
int scope, int parent_scope)
{
while (scope >= 0) {
if (scope == parent_scope)
- return TRUE;
+ return true;
scope = fd->scopes[scope].parent;
}
- return FALSE;
+ return false;
}
/* find a 'var' declaration in the same scope or a child scope */
@@ -20855,7 +20797,7 @@ static JSGlobalVar *find_lexical_global_var(JSFunctionDef *fd, JSAtom name)
}
static int find_lexical_decl(JSContext *ctx, JSFunctionDef *fd, JSAtom name,
- int scope_idx, BOOL check_catch_var)
+ int scope_idx, bool check_catch_var)
{
while (scope_idx >= 0) {
JSVarDef *vd = &fd->vars[scope_idx];
@@ -20986,7 +20928,7 @@ static int add_func_var(JSContext *ctx, JSFunctionDef *fd, JSAtom name)
fd->func_var_idx = idx;
fd->vars[idx].var_kind = JS_VAR_FUNCTION_NAME;
if (fd->is_strict_mode)
- fd->vars[idx].is_const = TRUE;
+ fd->vars[idx].is_const = true;
}
return idx;
}
@@ -21017,7 +20959,7 @@ static int add_arguments_arg(JSContext *ctx, JSFunctionDef *fd)
fd->vars[idx].scope_next = fd->scopes[ARG_SCOPE_INDEX].first;
fd->scopes[ARG_SCOPE_INDEX].first = idx;
fd->vars[idx].scope_level = ARG_SCOPE_INDEX;
- fd->vars[idx].is_lexical = TRUE;
+ fd->vars[idx].is_lexical = true;
fd->arguments_arg_idx = idx;
}
@@ -21058,9 +21000,9 @@ static JSGlobalVar *add_global_var(JSContext *ctx, JSFunctionDef *s,
return NULL;
hf = &s->global_vars[s->global_var_count++];
hf->cpool_idx = -1;
- hf->force_init = FALSE;
- hf->is_lexical = FALSE;
- hf->is_const = FALSE;
+ hf->force_init = false;
+ hf->is_lexical = false;
+ hf->is_const = false;
hf->scope_level = s->scope_level;
hf->var_name = JS_DupAtom(ctx, name);
return hf;
@@ -21092,7 +21034,7 @@ static int define_var(JSParseState *s, JSFunctionDef *fd, JSAtom name,
case JS_VAR_DEF_CONST:
case JS_VAR_DEF_FUNCTION_DECL:
case JS_VAR_DEF_NEW_FUNCTION_DECL:
- idx = find_lexical_decl(ctx, fd, name, fd->scope_first, TRUE);
+ idx = find_lexical_decl(ctx, fd, name, fd->scope_first, true);
if (idx >= 0) {
if (idx < GLOBAL_VAR_OFFSET) {
if (fd->vars[idx].scope_level == fd->scope_level) {
@@ -21143,7 +21085,7 @@ static int define_var(JSParseState *s, JSFunctionDef *fd, JSAtom name,
hf = add_global_var(s->ctx, fd, name);
if (!hf)
return -1;
- hf->is_lexical = TRUE;
+ hf->is_lexical = true;
hf->is_const = (var_def_type == JS_VAR_DEF_CONST);
idx = GLOBAL_VAR_OFFSET;
} else {
@@ -21169,7 +21111,7 @@ static int define_var(JSParseState *s, JSFunctionDef *fd, JSAtom name,
case JS_VAR_DEF_VAR:
if (find_lexical_decl(ctx, fd, name, fd->scope_first,
- FALSE) >= 0) {
+ false) >= 0) {
invalid_lexical_redefinition:
/* error to redefine a var that inside a lexical scope */
return js_parse_error(s, "invalid redefinition of lexical identifier");
@@ -21206,7 +21148,7 @@ static int define_var(JSParseState *s, JSFunctionDef *fd, JSAtom name,
/* add a private field variable in the current scope */
static int add_private_class_field(JSParseState *s, JSFunctionDef *fd,
- JSAtom name, JSVarKindEnum var_kind, BOOL is_static)
+ JSAtom name, JSVarKindEnum var_kind, bool is_static)
{
JSContext *ctx = s->ctx;
JSVarDef *vd;
@@ -21263,7 +21205,7 @@ static int seal_template_obj(JSContext *ctx, JSValue obj)
prs->flags & ~(JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE)))
return -1;
}
- p->extensible = FALSE;
+ p->extensible = false;
return 0;
}
@@ -21309,7 +21251,7 @@ static __exception int js_parse_template(JSParseState *s, int call, int *argc)
/* re-parse the string with escape sequences but do not throw a
syntax error if it contains invalid sequences
*/
- if (js_parse_string(s, '`', FALSE, p, &cooked, &p)) {
+ if (js_parse_string(s, '`', false, p, &cooked, &p)) {
cooked.u.str.str = JS_UNDEFINED;
}
if (JS_DefinePropertyValueUint32(ctx, template_object, depth,
@@ -21324,7 +21266,7 @@ static __exception int js_parse_template(JSParseState *s, int call, int *argc)
*/
JS_FreeValue(ctx, s->token.u.str.str);
s->token.u.str.str = JS_UNDEFINED;
- if (js_parse_string(s, '`', TRUE, p, &cooked, &p))
+ if (js_parse_string(s, '`', true, p, &cooked, &p))
return -1;
str = JS_VALUE_GET_STRING(cooked.u.str.str);
if (str->len != 0 || depth == 0) {
@@ -21337,7 +21279,6 @@ static __exception int js_parse_template(JSParseState *s, int call, int *argc)
goto done1;
emit_op(s, OP_get_field2);
emit_atom(s, JS_ATOM_concat);
- emit_ic(s, JS_ATOM_concat);
}
depth++;
} else {
@@ -21358,7 +21299,7 @@ static __exception int js_parse_template(JSParseState *s, int call, int *argc)
free_token(s, &s->token);
/* Resume TOK_TEMPLATE parsing (s->token.line_num and
* s->token.ptr are OK) */
- s->got_lf = FALSE;
+ s->got_lf = false;
s->last_line_num = s->token.line_num;
s->last_col_num = s->token.col_num;
if (js_parse_template_part(s, s->buf_ptr))
@@ -21391,7 +21332,7 @@ static __exception int js_parse_template(JSParseState *s, int call, int *argc)
#define PROP_TYPE_PRIVATE (1 << 4)
-static BOOL token_is_ident(int tok)
+static bool token_is_ident(int tok)
{
/* Accept keywords and reserved words as property names */
return (tok == TOK_IDENT ||
@@ -21402,11 +21343,11 @@ static BOOL token_is_ident(int tok)
/* if the property is an expression, name = JS_ATOM_NULL */
static int __exception js_parse_property_name(JSParseState *s,
JSAtom *pname,
- BOOL allow_method, BOOL allow_var,
- BOOL allow_private)
+ bool allow_method, bool allow_var,
+ bool allow_private)
{
int is_private = 0;
- BOOL is_non_reserved_ident;
+ bool is_non_reserved_ident;
JSAtom name;
int prop_type;
@@ -21421,7 +21362,7 @@ static int __exception js_parse_property_name(JSParseState *s,
if (s->token.val == ':' || s->token.val == ',' ||
s->token.val == '}' || s->token.val == '(' ||
s->token.val == '=' || s->token.val == ';') {
- is_non_reserved_ident = TRUE;
+ is_non_reserved_ident = true;
goto ident_found;
}
prop_type = PROP_TYPE_GET + (name == JS_ATOM_set);
@@ -21431,14 +21372,14 @@ static int __exception js_parse_property_name(JSParseState *s,
goto fail;
prop_type = PROP_TYPE_STAR;
} else if (token_is_pseudo_keyword(s, JS_ATOM_async) &&
- peek_token(s, TRUE) != '\n') {
+ peek_token(s, true) != '\n') {
name = JS_DupAtom(s->ctx, s->token.u.ident.atom);
if (next_token(s))
goto fail1;
if (s->token.val == ':' || s->token.val == ',' ||
s->token.val == '}' || s->token.val == '(' ||
s->token.val == '=' || s->token.val == ';') {
- is_non_reserved_ident = TRUE;
+ is_non_reserved_ident = true;
goto ident_found;
}
JS_FreeAtom(s->ctx, name);
@@ -21519,7 +21460,7 @@ typedef struct JSParsePos {
int last_col_num;
int line_num;
int col_num;
- BOOL got_lf;
+ bool got_lf;
const uint8_t *ptr;
const uint8_t *eol;
const uint8_t *mark;
@@ -21551,8 +21492,8 @@ static __exception int js_parse_seek_token(JSParseState *s, const JSParsePos *sp
return next_token(s);
}
-/* return TRUE if a regexp literal is allowed after this token */
-static BOOL is_regexp_allowed(int tok)
+/* return true if a regexp literal is allowed after this token */
+static bool is_regexp_allowed(int tok)
{
switch (tok) {
case TOK_NUMBER:
@@ -21568,9 +21509,9 @@ static BOOL is_regexp_allowed(int tok)
case ']':
case '}': /* XXX: regexp may occur after */
case TOK_IDENT:
- return FALSE;
+ return false;
default:
- return TRUE;
+ return true;
}
}
@@ -21581,7 +21522,7 @@ static BOOL is_regexp_allowed(int tok)
/* XXX: improve speed with early bailout */
/* XXX: no longer works if regexps are present. Could use previous
regexp parsing heuristics to handle most cases */
-static int js_parse_skip_parens_token(JSParseState *s, int *pbits, BOOL no_line_terminator)
+static int js_parse_skip_parens_token(JSParseState *s, int *pbits, bool no_line_terminator)
{
char state[256];
size_t level = 0;
@@ -21618,7 +21559,7 @@ static int js_parse_skip_parens_token(JSParseState *s, int *pbits, BOOL no_line_
free_token(s, &s->token);
/* Resume TOK_TEMPLATE parsing (s->token.line_num and
* s->token.ptr are OK) */
- s->got_lf = FALSE;
+ s->got_lf = false;
s->last_line_num = s->token.line_num;
s->last_col_num = s->token.col_num;
if (js_parse_template_part(s, s->buf_ptr))
@@ -21753,13 +21694,13 @@ static __exception int js_parse_object_literal(JSParseState *s)
JSAtom name = JS_ATOM_NULL;
const uint8_t *start_ptr;
int start_line, start_col, prop_type;
- BOOL has_proto;
+ bool has_proto;
if (next_token(s))
goto fail;
/* XXX: add an initial length that will be patched back */
emit_op(s, OP_object);
- has_proto = FALSE;
+ has_proto = false;
while (s->token.val != '}') {
/* specific case for getter/setter */
start_ptr = s->token.ptr;
@@ -21779,7 +21720,7 @@ static __exception int js_parse_object_literal(JSParseState *s)
goto next;
}
- prop_type = js_parse_property_name(s, &name, TRUE, TRUE, FALSE);
+ prop_type = js_parse_property_name(s, &name, true, true, false);
if (prop_type < 0)
goto fail;
@@ -21791,7 +21732,7 @@ static __exception int js_parse_object_literal(JSParseState *s)
emit_op(s, OP_define_field);
emit_atom(s, name);
} else if (s->token.val == '(') {
- BOOL is_getset = (prop_type == PROP_TYPE_GET ||
+ bool is_getset = (prop_type == PROP_TYPE_GET ||
prop_type == PROP_TYPE_SET);
JSParseFunctionEnum func_type;
JSFunctionKindEnum func_kind;
@@ -21840,7 +21781,7 @@ static __exception int js_parse_object_literal(JSParseState *s)
goto fail;
}
emit_op(s, OP_set_proto);
- has_proto = TRUE;
+ has_proto = true;
} else {
set_object_name(s, name);
emit_op(s, OP_define_field);
@@ -21932,9 +21873,9 @@ static JSAtom get_private_setter_name(JSContext *ctx, JSAtom name)
typedef struct {
JSFunctionDef *fields_init_fd;
int computed_fields_count;
- BOOL need_brand;
+ bool need_brand;
int brand_push_pos;
- BOOL is_static;
+ bool is_static;
} ClassFieldsDef;
static __exception int emit_class_init_start(JSParseState *s,
@@ -21987,88 +21928,59 @@ static void emit_class_init_end(JSParseState *s, ClassFieldsDef *cf)
emit_op(s, OP_set_home_object);
}
-static void emit_return(JSParseState *s, BOOL hasval);
+static void emit_return(JSParseState *s, bool hasval);
static JSFunctionDef *js_new_function_def(JSContext *ctx,
JSFunctionDef *parent,
- BOOL is_eval,
- BOOL is_func_expr,
+ bool is_eval,
+ bool is_func_expr,
const char *filename,
int line_num,
int col_num);
static __exception int js_parse_class_default_ctor(JSParseState *s,
- BOOL has_super,
+ bool has_super,
JSFunctionDef **pfd)
{
JSParseFunctionEnum func_type;
JSFunctionDef *fd = s->cur_func;
- fd = js_new_function_def(s->ctx, fd, FALSE, FALSE, s->filename,
+ fd = js_new_function_def(s->ctx, fd, false, false, s->filename,
s->token.line_num, s->token.col_num);
if (!fd)
return -1;
s->cur_func = fd;
- fd->has_home_object = TRUE;
- fd->super_allowed = TRUE;
- fd->has_prototype = FALSE;
- fd->has_this_binding = TRUE;
- fd->new_target_allowed = TRUE;
-
- /* error if not invoked as a constructor */
- emit_op(s, OP_check_ctor);
+ fd->has_home_object = true;
+ fd->super_allowed = true;
+ fd->has_prototype = false;
+ fd->has_this_binding = true;
+ fd->new_target_allowed = true;
push_scope(s); /* enter body scope */
fd->body_scope = fd->scope_level;
if (has_super) {
- fd->is_derived_class_constructor = TRUE;
- fd->super_call_allowed = TRUE;
- fd->arguments_allowed = TRUE;
- fd->has_arguments_binding = TRUE;
-
+ fd->is_derived_class_constructor = true;
+ fd->super_call_allowed = true;
+ fd->arguments_allowed = true;
+ fd->has_arguments_binding = true;
func_type = JS_PARSE_FUNC_DERIVED_CLASS_CONSTRUCTOR;
- /* super */
- emit_op(s, OP_scope_get_var);
- emit_atom(s, JS_ATOM_this_active_func);
- emit_u16(s, 0);
-
- emit_op(s, OP_get_super);
-
- emit_op(s, OP_scope_get_var);
- emit_atom(s, JS_ATOM_new_target);
- emit_u16(s, 0);
-
- emit_op(s, OP_array_from);
- emit_u16(s, 0);
- emit_op(s, OP_push_i32);
- emit_u32(s, 0);
-
- /* arguments */
- emit_op(s, OP_scope_get_var);
- emit_atom(s, JS_ATOM_arguments);
- emit_u16(s, 0);
-
- emit_op(s, OP_append);
- /* drop the index */
- emit_op(s, OP_drop);
-
- emit_op(s, OP_apply);
- emit_u16(s, 1);
- /* set the 'this' value */
- emit_op(s, OP_dup);
+ emit_op(s, OP_init_ctor);
+ // TODO(bnoordhuis) roll into OP_init_ctor
emit_op(s, OP_scope_put_var_init);
emit_atom(s, JS_ATOM_this);
emit_u16(s, 0);
emit_class_field_init(s);
} else {
func_type = JS_PARSE_FUNC_CLASS_CONSTRUCTOR;
+ /* error if not invoked as a constructor */
+ emit_op(s, OP_check_ctor);
emit_class_field_init(s);
}
fd->func_kind = JS_FUNC_NORMAL;
fd->func_type = func_type;
- emit_return(s, FALSE);
+ emit_return(s, false);
s->cur_func = fd->parent;
if (pfd)
@@ -22083,7 +21995,7 @@ static __exception int js_parse_class_default_ctor(JSParseState *s,
}
-static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
+static __exception int js_parse_class(JSParseState *s, bool is_class_expr,
JSParseExportEnum export_flag)
{
JSContext *ctx = s->ctx;
@@ -22093,14 +22005,14 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
JSFunctionDef *method_fd, *ctor_fd;
int class_name_var_idx, prop_type, ctor_cpool_offset;
int class_flags = 0, i, define_class_offset;
- BOOL is_static, is_private, is_strict_mode;
+ bool is_static, is_private, is_strict_mode;
const uint8_t *class_start_ptr = s->token.ptr;
const uint8_t *start_ptr;
ClassFieldsDef class_fields[2];
/* classes are parsed and executed in strict mode */
is_strict_mode = fd->is_strict_mode;
- fd->is_strict_mode = TRUE;
+ fd->is_strict_mode = true;
if (next_token(s))
goto fail;
if (s->token.val == TOK_IDENT) {
@@ -22170,7 +22082,7 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
ClassFieldsDef *cf = &class_fields[i];
cf->fields_init_fd = NULL;
cf->computed_fields_count = 0;
- cf->need_brand = FALSE;
+ cf->need_brand = false;
cf->is_static = i;
}
@@ -22181,11 +22093,11 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
goto fail;
continue;
}
- is_static = FALSE;
+ is_static = false;
if (s->token.val == TOK_STATIC) {
- int next = peek_token(s, TRUE);
+ int next = peek_token(s, true);
if (!(next == ';' || next == '}' || next == '(' || next == '='))
- is_static = TRUE;
+ is_static = true;
}
prop_type = -1;
if (is_static) {
@@ -22233,7 +22145,7 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
}
/* allow "static" field name */
if (s->token.val == ';' || s->token.val == '=') {
- is_static = FALSE;
+ is_static = false;
name = JS_DupAtom(ctx, JS_ATOM_static);
prop_type = PROP_TYPE_IDENT;
}
@@ -22242,7 +22154,7 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
emit_op(s, OP_swap);
start_ptr = s->token.ptr;
if (prop_type < 0) {
- prop_type = js_parse_property_name(s, &name, TRUE, FALSE, TRUE);
+ prop_type = js_parse_property_name(s, &name, true, false, true);
if (prop_type < 0)
goto fail;
}
@@ -22257,7 +22169,7 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
goto fail;
}
if (prop_type == PROP_TYPE_GET || prop_type == PROP_TYPE_SET) {
- BOOL is_set = prop_type - PROP_TYPE_GET;
+ bool is_set = prop_type - PROP_TYPE_GET;
JSFunctionDef *method_fd;
if (is_private) {
@@ -22280,7 +22192,7 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
JS_VAR_PRIVATE_GETTER + is_set, is_static) < 0)
goto fail;
}
- class_fields[is_static].need_brand = TRUE;
+ class_fields[is_static].need_brand = true;
}
if (js_parse_function_decl2(s, JS_PARSE_FUNC_GETTER + is_set,
@@ -22291,7 +22203,7 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
JS_PARSE_EXPORT_NONE, &method_fd))
goto fail;
if (is_private) {
- method_fd->need_home_object = TRUE; /* needed for brand check */
+ method_fd->need_home_object = true; /* needed for brand check */
emit_op(s, OP_set_home_object);
/* XXX: missing function name */
emit_op(s, OP_scope_put_var_init);
@@ -22437,7 +22349,7 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
func_type = JS_PARSE_FUNC_CLASS_CONSTRUCTOR;
}
if (is_private) {
- class_fields[is_static].need_brand = TRUE;
+ class_fields[is_static].need_brand = true;
}
if (js_parse_function_decl2(s, func_type, func_kind, JS_ATOM_NULL,
start_ptr,
@@ -22449,7 +22361,7 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
func_type == JS_PARSE_FUNC_CLASS_CONSTRUCTOR) {
ctor_fd = method_fd;
} else if (is_private) {
- method_fd->need_home_object = TRUE; /* needed for brand check */
+ method_fd->need_home_object = true; /* needed for brand check */
if (find_private_class_field(ctx, fd, name,
fd->scope_level) >= 0) {
private_field_already_defined:
@@ -22613,7 +22525,7 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
static __exception int js_parse_array_literal(JSParseState *s)
{
uint32_t idx;
- BOOL need_length;
+ bool need_length;
if (next_token(s))
return -1;
@@ -22637,17 +22549,17 @@ static __exception int js_parse_array_literal(JSParseState *s)
emit_u16(s, idx);
/* larger arrays and holes are handled with explicit indices */
- need_length = FALSE;
+ need_length = false;
while (s->token.val != ']' && idx < 0x7fffffff) {
if (s->token.val == TOK_ELLIPSIS)
break;
- need_length = TRUE;
+ need_length = true;
if (s->token.val != ',') {
if (js_parse_assign_expr(s))
return -1;
emit_op(s, OP_define_field);
emit_u32(s, __JS_AtomFromUInt32(idx));
- need_length = FALSE;
+ need_length = false;
}
idx++;
/* accept trailing comma */
@@ -22665,7 +22577,6 @@ static __exception int js_parse_array_literal(JSParseState *s)
emit_u32(s, idx);
emit_op(s, OP_put_field);
emit_atom(s, JS_ATOM_length);
- emit_ic(s, JS_ATOM_length);
}
goto done;
}
@@ -22683,13 +22594,13 @@ static __exception int js_parse_array_literal(JSParseState *s)
return -1;
emit_op(s, OP_append);
} else {
- need_length = TRUE;
+ need_length = true;
if (s->token.val != ',') {
if (js_parse_assign_expr(s))
return -1;
/* a idx val */
emit_op(s, OP_define_array_el);
- need_length = FALSE;
+ need_length = false;
}
emit_op(s, OP_inc);
}
@@ -22704,7 +22615,6 @@ static __exception int js_parse_array_literal(JSParseState *s)
emit_op(s, OP_dup1); /* array length - array array length */
emit_op(s, OP_put_field);
emit_atom(s, JS_ATOM_length);
- emit_ic(s, JS_ATOM_length);
} else {
emit_op(s, OP_drop); /* array length - array */
}
@@ -22713,7 +22623,7 @@ done:
}
/* XXX: remove */
-static BOOL has_with_scope(JSFunctionDef *s, int scope_level)
+static bool has_with_scope(JSFunctionDef *s, int scope_level)
{
/* check if scope chain contains a with statement */
while (s) {
@@ -22722,18 +22632,18 @@ static BOOL has_with_scope(JSFunctionDef *s, int scope_level)
JSVarDef *vd = &s->vars[scope_idx];
if (vd->var_name == JS_ATOM__with_)
- return TRUE;
+ return true;
scope_idx = vd->scope_next;
}
/* check parent scopes */
scope_level = s->parent_scope_level;
s = s->parent;
}
- return FALSE;
+ return false;
}
static __exception int get_lvalue(JSParseState *s, int *popcode, int *pscope,
- JSAtom *pname, int *plabel, int *pdepth, BOOL keep,
+ JSAtom *pname, int *plabel, int *pdepth, bool keep,
int tok)
{
JSFunctionDef *fd;
@@ -22805,7 +22715,6 @@ static __exception int get_lvalue(JSParseState *s, int *popcode, int *pscope,
case OP_get_field:
emit_op(s, OP_get_field2);
emit_atom(s, name);
- emit_ic(s, name);
break;
case OP_scope_get_private_field:
emit_op(s, OP_scope_get_private_field2);
@@ -22870,7 +22779,7 @@ typedef enum {
OP_scope_get_var which is never generated by get_lvalue(). */
static void put_lvalue(JSParseState *s, int opcode, int scope,
JSAtom name, int label, PutLValueEnum special,
- BOOL is_let)
+ bool is_let)
{
switch(opcode) {
case OP_get_field:
@@ -22953,7 +22862,6 @@ static void put_lvalue(JSParseState *s, int opcode, int scope,
case OP_get_field:
emit_op(s, OP_put_field);
emit_u32(s, name); /* name has refcount */
- emit_ic(s, name);
break;
case OP_scope_get_private_field:
emit_op(s, OP_scope_put_private_field);
@@ -23082,7 +22990,7 @@ duplicate:
return js_parse_error(s, "Duplicate parameter name not allowed in this context");
}
-static JSAtom js_parse_destructuring_var(JSParseState *s, int tok, int is_arg)
+static JSAtom js_parse_destructuring_var(JSParseState *s, int tok, bool is_arg)
{
JSAtom name;
@@ -23106,21 +23014,23 @@ fail:
/* Return -1 if error, 0 if no initializer, 1 if an initializer is
present at the top level. */
-static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg,
- int hasval, int has_ellipsis,
- BOOL allow_initializer)
+static int js_parse_destructuring_element(JSParseState *s, int tok,
+ bool is_arg, bool hasval,
+ int has_ellipsis, // tri-state
+ bool allow_initializer,
+ bool export_flag)
{
int label_parse, label_assign, label_done, label_lvalue, depth_lvalue;
int start_addr, assign_addr;
JSAtom prop_name, var_name;
int opcode, scope, tok1, skip_bits;
- BOOL has_initializer;
+ bool has_initializer;
label_lvalue = -1;
if (has_ellipsis < 0) {
/* pre-parse destructuration target for spread detection */
- js_parse_skip_parens_token(s, &skip_bits, FALSE);
+ js_parse_skip_parens_token(s, &skip_bits, false);
has_ellipsis = skip_bits & SKIP_HAS_ELLIPSIS;
}
@@ -23174,7 +23084,7 @@ static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg,
return -1;
if (get_lvalue(s, &opcode, &scope, &var_name,
- &label_lvalue, &depth_lvalue, FALSE, '{'))
+ &label_lvalue, &depth_lvalue, false, '{'))
return -1;
}
if (s->token.val != '}') {
@@ -23186,7 +23096,7 @@ static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg,
emit_u8(s, 0 | ((depth_lvalue + 1) << 2) | ((depth_lvalue + 2) << 5));
goto set_val;
}
- prop_type = js_parse_property_name(s, &prop_name, FALSE, TRUE, FALSE);
+ prop_type = js_parse_property_name(s, &prop_name, false, true, false);
if (prop_type < 0)
return -1;
var_name = JS_ATOM_NULL;
@@ -23198,7 +23108,7 @@ static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg,
if (next_token(s))
goto prop_error;
if ((s->token.val == '[' || s->token.val == '{')
- && ((tok1 = js_parse_skip_parens_token(s, &skip_bits, FALSE)) == ',' ||
+ && ((tok1 = js_parse_skip_parens_token(s, &skip_bits, false)) == ',' ||
tok1 == '=' || tok1 == '}')) {
if (prop_name == JS_ATOM_NULL) {
/* computed property name on stack */
@@ -23225,9 +23135,8 @@ static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg,
/* get the named property from the source object */
emit_op(s, OP_get_field2);
emit_u32(s, prop_name);
- emit_ic(s, prop_name);
}
- if (js_parse_destructuring_element(s, tok, is_arg, TRUE, -1, TRUE) < 0)
+ if (js_parse_destructuring_element(s, tok, is_arg, true, -1, true, export_flag) < 0)
return -1;
if (s->token.val == '}')
break;
@@ -23268,7 +23177,7 @@ static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg,
goto prop_error;
lvalue:
if (get_lvalue(s, &opcode, &scope, &var_name,
- &label_lvalue, &depth_lvalue, FALSE, '{'))
+ &label_lvalue, &depth_lvalue, false, '{'))
goto prop_error;
/* swap ref and lvalue object if any */
if (prop_name == JS_ATOM_NULL) {
@@ -23315,7 +23224,6 @@ static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg,
/* source -- val */
emit_op(s, OP_get_field);
emit_u32(s, prop_name);
- emit_ic(s, prop_name);
}
} else {
/* prop_type = PROP_TYPE_VAR, cannot be a computed property */
@@ -23347,12 +23255,16 @@ static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg,
/* source -- source val */
emit_op(s, OP_get_field2);
emit_u32(s, prop_name);
- emit_ic(s, prop_name);
}
set_val:
if (tok) {
if (js_define_var(s, var_name, tok))
goto var_error;
+ if (export_flag) {
+ if (!add_export_entry(s, s->cur_func->module, var_name, var_name,
+ JS_EXPORT_TYPE_LOCAL))
+ goto var_error;
+ }
scope = s->cur_func->scope_level;
}
if (s->token.val == '=') { /* handle optional default value */
@@ -23388,7 +23300,7 @@ static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg,
if (next_token(s))
return -1;
} else if (s->token.val == '[') {
- BOOL has_spread;
+ bool has_spread;
int enum_depth;
BlockEnv block_env;
@@ -23398,9 +23310,9 @@ static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg,
'yield' triggers a 'return' */
push_break_entry(s->cur_func, &block_env,
JS_ATOM_NULL, -1, -1, 2);
- block_env.has_iterator = TRUE;
+ block_env.has_iterator = true;
emit_op(s, OP_for_of_start);
- has_spread = FALSE;
+ has_spread = false;
while (s->token.val != ']') {
/* get the next value */
if (s->token.val == TOK_ELLIPSIS) {
@@ -23408,7 +23320,7 @@ static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg,
return -1;
if (s->token.val == ',' || s->token.val == ']')
return js_parse_error(s, "missing binding pattern...");
- has_spread = TRUE;
+ has_spread = true;
}
if (s->token.val == ',') {
/* do nothing, skip the value, has_spread is false */
@@ -23417,7 +23329,7 @@ static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg,
emit_op(s, OP_drop);
emit_op(s, OP_drop);
} else if ((s->token.val == '[' || s->token.val == '{')
- && ((tok1 = js_parse_skip_parens_token(s, &skip_bits, FALSE)) == ',' ||
+ && ((tok1 = js_parse_skip_parens_token(s, &skip_bits, false)) == ',' ||
tok1 == '=' || tok1 == ']')) {
if (has_spread) {
if (tok1 == '=')
@@ -23428,7 +23340,7 @@ static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg,
emit_u8(s, 0);
emit_op(s, OP_drop);
}
- if (js_parse_destructuring_element(s, tok, is_arg, TRUE, skip_bits & SKIP_HAS_ELLIPSIS, TRUE) < 0)
+ if (js_parse_destructuring_element(s, tok, is_arg, true, skip_bits & SKIP_HAS_ELLIPSIS, true, export_flag) < 0)
return -1;
} else {
var_name = JS_ATOM_NULL;
@@ -23445,7 +23357,7 @@ static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg,
if (js_parse_left_hand_side_expr(s))
return -1;
if (get_lvalue(s, &opcode, &scope, &var_name,
- &label_lvalue, &enum_depth, FALSE, '[')) {
+ &label_lvalue, &enum_depth, false, '[')) {
return -1;
}
}
@@ -23505,7 +23417,7 @@ static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg,
return -1;
emit_goto(s, OP_goto, label_assign);
emit_label(s, label_done);
- has_initializer = TRUE;
+ has_initializer = true;
} else {
/* normally hasval is true except if
js_parse_skip_parens_token() was wrong in the parsing */
@@ -23518,7 +23430,7 @@ static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg,
memset(s->cur_func->byte_code.buf + start_addr, OP_nop,
assign_addr - start_addr);
s->cur_func->label_slots[label_parse].ref_count--;
- has_initializer = FALSE;
+ has_initializer = false;
}
return has_initializer;
@@ -23558,7 +23470,7 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags)
{
FuncCallType call_type;
int optional_chaining_label;
- BOOL accept_lparen = (parse_flags & PF_POSTFIX_CALL) != 0;
+ bool accept_lparen = (parse_flags & PF_POSTFIX_CALL) != 0;
call_type = FUNC_CALL_NORMAL;
switch(s->token.val) {
@@ -23643,7 +23555,7 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags)
return -1;
break;
case TOK_CLASS:
- if (js_parse_class(s, TRUE, JS_PARSE_EXPORT_NONE))
+ if (js_parse_class(s, true, JS_PARSE_EXPORT_NONE))
return -1;
break;
case TOK_NULL:
@@ -23675,7 +23587,7 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags)
return js_parse_error_reserved_identifier(s);
}
if (token_is_pseudo_keyword(s, JS_ATOM_async) &&
- peek_token(s, TRUE) != '\n') {
+ peek_token(s, true) != '\n') {
const uint8_t *source_ptr;
int source_line_num;
int source_col_num;
@@ -23718,8 +23630,8 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags)
case '[':
{
int skip_bits;
- if (js_parse_skip_parens_token(s, &skip_bits, FALSE) == '=') {
- if (js_parse_destructuring_element(s, 0, 0, FALSE, skip_bits & SKIP_HAS_ELLIPSIS, TRUE) < 0)
+ if (js_parse_skip_parens_token(s, &skip_bits, false) == '=') {
+ if (js_parse_destructuring_element(s, 0, false, false, skip_bits & SKIP_HAS_ELLIPSIS, true, false) < 0)
return -1;
} else {
if (s->token.val == '{') {
@@ -23751,7 +23663,7 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags)
emit_source_loc(s);
if (js_parse_postfix_expr(s, 0))
return -1;
- accept_lparen = TRUE;
+ accept_lparen = true;
if (s->token.val != '(') {
/* new operator on an object */
emit_op(s, OP_dup);
@@ -23817,13 +23729,13 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags)
optional_chaining_label = -1;
for(;;) {
JSFunctionDef *fd = s->cur_func;
- BOOL has_optional_chain = FALSE;
+ bool has_optional_chain = false;
if (s->token.val == TOK_QUESTION_MARK_DOT) {
/* optional chaining */
if (next_token(s))
return -1;
- has_optional_chain = TRUE;
+ has_optional_chain = true;
if (s->token.val == '(' && accept_lparen) {
goto parse_func_call;
} else if (s->token.val == '[') {
@@ -24031,7 +23943,7 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags)
case OP_eval:
emit_op(s, OP_apply_eval);
emit_u16(s, fd->scope_level);
- fd->has_eval_call = TRUE;
+ fd->has_eval_call = true;
break;
default:
if (call_type == FUNC_CALL_SUPER_CTOR) {
@@ -24074,7 +23986,7 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags)
emit_op(s, OP_eval);
emit_u16(s, arg_count);
emit_u16(s, fd->scope_level);
- fd->has_eval_call = TRUE;
+ fd->has_eval_call = true;
break;
default:
if (call_type == FUNC_CALL_SUPER_CTOR) {
@@ -24133,7 +24045,6 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags)
}
emit_op(s, OP_get_field);
emit_atom(s, s->token.u.ident.atom);
- emit_ic(s, s->token.u.ident.atom);
}
}
if (next_token(s))
@@ -24321,11 +24232,11 @@ static __exception int js_parse_unary(JSParseState *s, int parse_flags)
return -1;
if (js_parse_unary(s, 0))
return -1;
- if (get_lvalue(s, &opcode, &scope, &name, &label, NULL, TRUE, op))
+ if (get_lvalue(s, &opcode, &scope, &name, &label, NULL, true, op))
return -1;
emit_op(s, OP_dec + op - TOK_DEC);
put_lvalue(s, opcode, scope, name, label, PUT_LVALUE_KEEP_TOP,
- FALSE);
+ false);
}
break;
case TOK_TYPEOF:
@@ -24359,7 +24270,7 @@ static __exception int js_parse_unary(JSParseState *s, int parse_flags)
return -1;
if (js_parse_unary(s, PF_POW_FORBIDDEN))
return -1;
- s->cur_func->has_await = TRUE;
+ s->cur_func->has_await = true;
emit_op(s, OP_await);
parse_flags = 0;
break;
@@ -24371,11 +24282,11 @@ static __exception int js_parse_unary(JSParseState *s, int parse_flags)
int opcode, op, scope, label;
JSAtom name;
op = s->token.val;
- if (get_lvalue(s, &opcode, &scope, &name, &label, NULL, TRUE, op))
+ if (get_lvalue(s, &opcode, &scope, &name, &label, NULL, true, op))
return -1;
emit_op(s, OP_post_dec + op - TOK_DEC);
put_lvalue(s, opcode, scope, name, label, PUT_LVALUE_KEEP_SECOND,
- FALSE);
+ false);
if (next_token(s))
return -1;
}
@@ -24410,7 +24321,7 @@ static __exception int js_parse_expr_binary(JSParseState *s, int level,
return js_parse_unary(s, PF_POW_ALLOWED);
} else if (s->token.val == TOK_PRIVATE_NAME &&
(parse_flags & PF_IN_ACCEPTED) && level == 4 &&
- peek_token(s, FALSE) == TOK_IN) {
+ peek_token(s, false) == TOK_IN) {
JSAtom atom;
atom = JS_DupAtom(s->ctx, s->token.u.ident.atom);
if (next_token(s))
@@ -24556,6 +24467,7 @@ static __exception int js_parse_expr_binary(JSParseState *s, int level,
}
if (next_token(s))
return -1;
+ emit_source_loc(s);
if (js_parse_expr_binary(s, level - 1, parse_flags))
return -1;
emit_op(s, opcode);
@@ -24669,7 +24581,7 @@ static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags)
JSAtom name;
if (s->token.val == TOK_YIELD) {
- BOOL is_star = FALSE, is_async;
+ bool is_star = false, is_async;
if (!(s->cur_func->func_kind & JS_FUNC_GENERATOR))
return js_parse_error(s, "unexpected 'yield' keyword");
@@ -24683,7 +24595,7 @@ static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags)
s->token.val != ']' && s->token.val != '}' &&
s->token.val != ',' && s->token.val != ':' && !s->got_lf) {
if (s->token.val == '*') {
- is_star = TRUE;
+ is_star = true;
if (next_token(s))
return -1;
}
@@ -24718,14 +24630,12 @@ static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags)
emit_op(s, OP_iterator_check_object);
emit_op(s, OP_get_field2);
emit_atom(s, JS_ATOM_done);
- emit_ic(s, JS_ATOM_done);
label_next = emit_goto(s, OP_if_true, -1); /* end of loop */
emit_label(s, label_yield);
if (is_async) {
/* OP_async_yield_star takes the value as parameter */
emit_op(s, OP_get_field);
emit_atom(s, JS_ATOM_value);
- emit_ic(s, JS_ATOM_value);
emit_op(s, OP_async_yield_star);
} else {
/* OP_yield_star takes (value, done) as parameter */
@@ -24753,18 +24663,16 @@ static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags)
emit_op(s, OP_iterator_check_object);
emit_op(s, OP_get_field2);
emit_atom(s, JS_ATOM_done);
- emit_ic(s, JS_ATOM_done);
emit_goto(s, OP_if_false, label_yield);
emit_op(s, OP_get_field);
emit_atom(s, JS_ATOM_value);
- emit_ic(s, JS_ATOM_value);
emit_label(s, label_return1);
emit_op(s, OP_nip);
emit_op(s, OP_nip);
emit_op(s, OP_nip);
- emit_return(s, TRUE);
+ emit_return(s, true);
/* throw handling */
emit_label(s, label_throw);
@@ -24776,7 +24684,6 @@ static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags)
emit_op(s, OP_iterator_check_object);
emit_op(s, OP_get_field2);
emit_atom(s, JS_ATOM_done);
- emit_ic(s, JS_ATOM_done);
emit_goto(s, OP_if_false, label_yield);
emit_goto(s, OP_goto, label_next);
/* close the iterator and throw a type error exception */
@@ -24795,7 +24702,6 @@ static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags)
emit_label(s, label_next);
emit_op(s, OP_get_field);
emit_atom(s, JS_ATOM_value);
- emit_ic(s, JS_ATOM_value);
emit_op(s, OP_nip); /* keep the value associated with
done = true */
emit_op(s, OP_nip);
@@ -24807,12 +24713,12 @@ static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags)
emit_op(s, OP_await);
emit_op(s, OP_yield);
label_next = emit_goto(s, OP_if_false, -1);
- emit_return(s, TRUE);
+ emit_return(s, true);
emit_label(s, label_next);
}
return 0;
} else if (s->token.val == '(' &&
- js_parse_skip_parens_token(s, NULL, TRUE) == TOK_ARROW) {
+ js_parse_skip_parens_token(s, NULL, true) == TOK_ARROW) {
return js_parse_function_decl(s, JS_PARSE_FUNC_ARROW,
JS_FUNC_NORMAL, JS_ATOM_NULL,
s->token.ptr, s->token.line_num,
@@ -24823,7 +24729,7 @@ static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags)
JSParsePos pos;
/* fast test */
- tok = peek_token(s, TRUE);
+ tok = peek_token(s, true);
if (tok == TOK_FUNCTION || tok == '\n')
goto next;
@@ -24834,9 +24740,9 @@ static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags)
if (next_token(s))
return -1;
if ((s->token.val == '(' &&
- js_parse_skip_parens_token(s, NULL, TRUE) == TOK_ARROW) ||
+ js_parse_skip_parens_token(s, NULL, true) == TOK_ARROW) ||
(s->token.val == TOK_IDENT && !s->token.u.ident.is_reserved &&
- peek_token(s, TRUE) == TOK_ARROW)) {
+ peek_token(s, true) == TOK_ARROW)) {
return js_parse_function_decl(s, JS_PARSE_FUNC_ARROW,
JS_FUNC_ASYNC, JS_ATOM_NULL,
source_ptr, source_line_num,
@@ -24847,7 +24753,7 @@ static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags)
return -1;
}
} else if (s->token.val == TOK_IDENT &&
- peek_token(s, TRUE) == TOK_ARROW) {
+ peek_token(s, true) == TOK_ARROW) {
return js_parse_function_decl(s, JS_PARSE_FUNC_ARROW,
JS_FUNC_NORMAL, JS_ATOM_NULL,
s->token.ptr, s->token.line_num,
@@ -24910,14 +24816,14 @@ static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags)
} else {
emit_op(s, op - TOK_MUL_ASSIGN + OP_mul);
}
- put_lvalue(s, opcode, scope, name, label, PUT_LVALUE_KEEP_TOP, FALSE);
+ put_lvalue(s, opcode, scope, name, label, PUT_LVALUE_KEEP_TOP, false);
} else if (op >= TOK_LAND_ASSIGN && op <= TOK_DOUBLE_QUESTION_MARK_ASSIGN) {
int label, label1, depth_lvalue, label2;
if (next_token(s))
return -1;
if (get_lvalue(s, &opcode, &scope, &name, &label,
- &depth_lvalue, TRUE, op) < 0)
+ &depth_lvalue, true, op) < 0)
return -1;
emit_op(s, OP_dup);
@@ -24953,7 +24859,7 @@ static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags)
/* XXX: we disable the OP_put_ref_value optimization by not
using put_lvalue() otherwise depth_lvalue is not correct */
put_lvalue(s, opcode, scope, name, label, PUT_LVALUE_NOKEEP_DEPTH,
- FALSE);
+ false);
label2 = emit_goto(s, OP_goto, -1);
emit_label(s, label1);
@@ -24977,7 +24883,7 @@ static __exception int js_parse_assign_expr(JSParseState *s)
/* allowed parse_flags: PF_IN_ACCEPTED */
static __exception int js_parse_expr2(JSParseState *s, int parse_flags)
{
- BOOL comma = FALSE;
+ bool comma = false;
for(;;) {
if (js_parse_assign_expr2(s, parse_flags))
return -1;
@@ -24991,7 +24897,7 @@ static __exception int js_parse_expr2(JSParseState *s, int parse_flags)
}
if (s->token.val != ',')
break;
- comma = TRUE;
+ comma = true;
if (next_token(s))
return -1;
emit_op(s, OP_drop);
@@ -25017,8 +24923,8 @@ static void push_break_entry(JSFunctionDef *fd, BlockEnv *be,
be->drop_count = drop_count;
be->label_finally = -1;
be->scope_level = fd->scope_level;
- be->has_iterator = FALSE;
- be->is_regular_stmt = FALSE;
+ be->has_iterator = false;
+ be->is_regular_stmt = false;
}
static void pop_break_entry(JSFunctionDef *fd)
@@ -25078,7 +24984,7 @@ static __exception int emit_break(JSParseState *s, JSAtom name, int is_cont)
}
/* execute the finally blocks before return */
-static void emit_return(JSParseState *s, BOOL hasval)
+static void emit_return(JSParseState *s, bool hasval)
{
BlockEnv *top;
@@ -25086,7 +24992,7 @@ static void emit_return(JSParseState *s, BOOL hasval)
if (!hasval) {
/* no value: direct return in case of async generator */
emit_op(s, OP_undefined);
- hasval = TRUE;
+ hasval = true;
} else if (s->cur_func->func_kind == JS_FUNC_ASYNC_GENERATOR) {
/* the await must be done before handling the "finally" in
case it raises an exception */
@@ -25099,7 +25005,7 @@ static void emit_return(JSParseState *s, BOOL hasval)
if (top->has_iterator || top->label_finally != -1) {
if (!hasval) {
emit_op(s, OP_undefined);
- hasval = TRUE;
+ hasval = true;
}
/* Remove the stack elements up to and including the catch
offset. When 'yield' is used in an expression we have
@@ -25114,7 +25020,6 @@ static void emit_return(JSParseState *s, BOOL hasval)
emit_op(s, OP_swap);
emit_op(s, OP_get_field2);
emit_atom(s, JS_ATOM_return);
- emit_ic(s, JS_ATOM_return);
/* stack: iter_obj return_func */
emit_op(s, OP_dup);
emit_op(s, OP_is_undefined_or_null);
@@ -25203,7 +25108,7 @@ static __exception int js_parse_block(JSParseState *s)
/* allowed parse_flags: PF_IN_ACCEPTED */
static __exception int js_parse_var(JSParseState *s, int parse_flags, int tok,
- BOOL export_flag)
+ bool export_flag)
{
JSContext *ctx = s->ctx;
JSFunctionDef *fd = s->cur_func;
@@ -25240,7 +25145,7 @@ static __exception int js_parse_var(JSParseState *s, int parse_flags, int tok,
emit_op(s, OP_scope_get_var);
emit_atom(s, name);
emit_u16(s, fd->scope_level);
- if (get_lvalue(s, &opcode, &scope, &name1, &label, NULL, FALSE, '=') < 0)
+ if (get_lvalue(s, &opcode, &scope, &name1, &label, NULL, false, '=') < 0)
goto var_error;
if (js_parse_assign_expr2(s, parse_flags)) {
JS_FreeAtom(ctx, name1);
@@ -25248,7 +25153,7 @@ static __exception int js_parse_var(JSParseState *s, int parse_flags, int tok,
}
set_object_name(s, name);
put_lvalue(s, opcode, scope, name1, label,
- PUT_LVALUE_NOKEEP, FALSE);
+ PUT_LVALUE_NOKEEP, false);
} else {
if (js_parse_assign_expr2(s, parse_flags))
goto var_error;
@@ -25275,9 +25180,9 @@ static __exception int js_parse_var(JSParseState *s, int parse_flags, int tok,
} else {
int skip_bits;
if ((s->token.val == '[' || s->token.val == '{')
- && js_parse_skip_parens_token(s, &skip_bits, FALSE) == '=') {
+ && js_parse_skip_parens_token(s, &skip_bits, false) == '=') {
emit_op(s, OP_undefined);
- if (js_parse_destructuring_element(s, tok, 0, TRUE, skip_bits & SKIP_HAS_ELLIPSIS, TRUE) < 0)
+ if (js_parse_destructuring_element(s, tok, false, true, skip_bits & SKIP_HAS_ELLIPSIS, true, export_flag) < 0)
return -1;
} else {
return js_parse_error(s, "variable name expected");
@@ -25296,16 +25201,16 @@ static __exception int js_parse_var(JSParseState *s, int parse_flags, int tok,
}
/* test if the current token is a label. Use simplistic look-ahead scanner */
-static BOOL is_label(JSParseState *s)
+static bool is_label(JSParseState *s)
{
return (s->token.val == TOK_IDENT && !s->token.u.ident.is_reserved &&
- peek_token(s, FALSE) == ':');
+ peek_token(s, false) == ':');
}
/* test if the current token is a let keyword. Use simplistic look-ahead scanner */
static int is_let(JSParseState *s, int decl_mask)
{
- int res = FALSE;
+ int res = false;
if (token_is_pseudo_keyword(s, JS_ATOM_let)) {
JSParsePos pos;
@@ -25318,7 +25223,7 @@ static int is_let(JSParseState *s, int decl_mask)
if (s->token.val == '[') {
/* let [ is a syntax restriction:
it never introduces an ExpressionStatement */
- res = TRUE;
+ res = true;
break;
}
if (s->token.val == '{' ||
@@ -25330,7 +25235,7 @@ static int is_let(JSParseState *s, int decl_mask)
/* XXX: should also check that `{` introduces a BindingPattern,
but Firefox does not and rejects eval("let=1;let\n{if(1)2;}") */
if (s->last_line_num == s->token.line_num || (decl_mask & DECL_MASK_OTHER)) {
- res = TRUE;
+ res = true;
break;
}
break;
@@ -25347,20 +25252,20 @@ static int is_let(JSParseState *s, int decl_mask)
/* XXX: handle IteratorClose when exiting the loop before the
enumeration is done */
static __exception int js_parse_for_in_of(JSParseState *s, int label_name,
- BOOL is_async)
+ bool is_async)
{
JSContext *ctx = s->ctx;
JSFunctionDef *fd = s->cur_func;
JSAtom var_name;
- BOOL has_initializer, is_for_of, has_destructuring;
+ bool has_initializer, is_for_of, has_destructuring;
int tok, tok1, opcode, scope, block_scope_level;
int label_next, label_expr, label_cont, label_body, label_break;
int pos_next, pos_expr;
BlockEnv break_entry;
- has_initializer = FALSE;
- has_destructuring = FALSE;
- is_for_of = FALSE;
+ has_initializer = false;
+ has_destructuring = false;
+ is_for_of = false;
block_scope_level = fd->scope_level;
label_cont = new_label(s);
label_body = new_label(s);
@@ -25385,10 +25290,10 @@ static __exception int js_parse_for_in_of(JSParseState *s, int label_name,
tok = s->token.val;
switch (is_let(s, DECL_MASK_OTHER)) {
- case TRUE:
+ case true:
tok = TOK_LET;
break;
- case FALSE:
+ case false:
break;
default:
return -1;
@@ -25399,9 +25304,9 @@ static __exception int js_parse_for_in_of(JSParseState *s, int label_name,
if (!(s->token.val == TOK_IDENT && !s->token.u.ident.is_reserved)) {
if (s->token.val == '[' || s->token.val == '{') {
- if (js_parse_destructuring_element(s, tok, 0, TRUE, -1, FALSE) < 0)
+ if (js_parse_destructuring_element(s, tok, false, true, -1, false, false) < 0)
return -1;
- has_destructuring = TRUE;
+ has_destructuring = true;
} else {
return js_parse_error(s, "variable name expected");
}
@@ -25421,23 +25326,23 @@ static __exception int js_parse_for_in_of(JSParseState *s, int label_name,
emit_atom(s, var_name);
emit_u16(s, fd->scope_level);
}
- } else if (!is_async && token_is_pseudo_keyword(s, JS_ATOM_async) && peek_token(s, FALSE) == TOK_OF) {
+ } else if (!is_async && token_is_pseudo_keyword(s, JS_ATOM_async) && peek_token(s, false) == TOK_OF) {
return js_parse_error(s, "'for of' expression cannot start with 'async'");
} else {
int skip_bits;
if ((s->token.val == '[' || s->token.val == '{')
- && ((tok1 = js_parse_skip_parens_token(s, &skip_bits, FALSE)) == TOK_IN || tok1 == TOK_OF)) {
- if (js_parse_destructuring_element(s, 0, 0, TRUE, skip_bits & SKIP_HAS_ELLIPSIS, TRUE) < 0)
+ && ((tok1 = js_parse_skip_parens_token(s, &skip_bits, false)) == TOK_IN || tok1 == TOK_OF)) {
+ if (js_parse_destructuring_element(s, 0, false, true, skip_bits & SKIP_HAS_ELLIPSIS, true, false) < 0)
return -1;
} else {
int lvalue_label;
if (js_parse_left_hand_side_expr(s))
return -1;
if (get_lvalue(s, &opcode, &scope, &var_name, &lvalue_label,
- NULL, FALSE, TOK_FOR))
+ NULL, false, TOK_FOR))
return -1;
put_lvalue(s, opcode, scope, var_name, lvalue_label,
- PUT_LVALUE_NOKEEP_BOTTOM, FALSE);
+ PUT_LVALUE_NOKEEP_BOTTOM, false);
}
var_name = JS_ATOM_NULL;
}
@@ -25447,7 +25352,7 @@ static __exception int js_parse_for_in_of(JSParseState *s, int label_name,
emit_label(s, label_expr);
if (s->token.val == '=') {
/* XXX: potential scoping issue if inside `with` statement */
- has_initializer = TRUE;
+ has_initializer = true;
/* parse and evaluate initializer prior to evaluating the
object (only used with "for in" with a non lexical variable
in non strict mode */
@@ -25464,8 +25369,8 @@ static __exception int js_parse_for_in_of(JSParseState *s, int label_name,
JS_FreeAtom(ctx, var_name);
if (token_is_pseudo_keyword(s, JS_ATOM_of)) {
- is_for_of = TRUE;
- break_entry.has_iterator = TRUE;
+ is_for_of = true;
+ break_entry.has_iterator = true;
break_entry.drop_count += 2;
if (has_initializer)
goto initializer_error;
@@ -25649,9 +25554,9 @@ static __exception int js_parse_statement_or_decl(JSParseState *s,
if (s->token.val != ';' && s->token.val != '}' && !s->got_lf) {
if (js_parse_expr(s))
goto fail;
- emit_return(s, TRUE);
+ emit_return(s, true);
} else {
- emit_return(s, FALSE);
+ emit_return(s, false);
}
if (js_parse_expect_semi(s))
goto fail;
@@ -25663,6 +25568,7 @@ static __exception int js_parse_statement_or_decl(JSParseState *s,
js_parse_error(s, "line terminator not allowed after throw");
goto fail;
}
+ emit_source_loc(s);
if (js_parse_expr(s))
goto fail;
emit_op(s, OP_throw);
@@ -25680,7 +25586,7 @@ static __exception int js_parse_statement_or_decl(JSParseState *s,
case TOK_VAR:
if (next_token(s))
goto fail;
- if (js_parse_var(s, TRUE, tok, FALSE))
+ if (js_parse_var(s, PF_IN_ACCEPTED, tok, /*export_flag*/false))
goto fail;
if (js_parse_expect_semi(s))
goto fail;
@@ -25794,25 +25700,25 @@ static __exception int js_parse_statement_or_decl(JSParseState *s,
int pos_cont, pos_body, block_scope_level;
BlockEnv break_entry;
int tok, bits;
- BOOL is_async;
+ bool is_async;
if (next_token(s))
goto fail;
set_eval_ret_undefined(s);
bits = 0;
- is_async = FALSE;
+ is_async = false;
if (s->token.val == '(') {
- js_parse_skip_parens_token(s, &bits, FALSE);
+ js_parse_skip_parens_token(s, &bits, false);
} else if (s->token.val == TOK_AWAIT) {
if (!(s->cur_func->func_kind & JS_FUNC_ASYNC)) {
js_parse_error(s, "for await is only valid in asynchronous functions");
goto fail;
}
- is_async = TRUE;
+ is_async = true;
if (next_token(s))
goto fail;
- s->cur_func->has_await = TRUE;
+ s->cur_func->has_await = true;
}
if (js_parse_expect(s, '('))
goto fail;
@@ -25832,10 +25738,10 @@ static __exception int js_parse_statement_or_decl(JSParseState *s,
tok = s->token.val;
if (tok != ';') {
switch (is_let(s, DECL_MASK_OTHER)) {
- case TRUE:
+ case true:
tok = TOK_LET;
break;
- case FALSE:
+ case false:
break;
default:
goto fail;
@@ -25843,10 +25749,10 @@ static __exception int js_parse_statement_or_decl(JSParseState *s,
if (tok == TOK_VAR || tok == TOK_LET || tok == TOK_CONST) {
if (next_token(s))
goto fail;
- if (js_parse_var(s, FALSE, tok, FALSE))
+ if (js_parse_var(s, 0, tok, /*export_flag*/false))
goto fail;
} else {
- if (js_parse_expr2(s, FALSE))
+ if (js_parse_expr2(s, false))
goto fail;
emit_op(s, OP_drop);
}
@@ -26105,7 +26011,7 @@ static __exception int js_parse_statement_or_decl(JSParseState *s,
if (!(s->token.val == TOK_IDENT && !s->token.u.ident.is_reserved)) {
if (s->token.val == '[' || s->token.val == '{') {
/* XXX: TOK_LET is not completely correct */
- if (js_parse_destructuring_element(s, TOK_LET, 0, TRUE, -1, TRUE) < 0)
+ if (js_parse_destructuring_element(s, TOK_LET, false, true, -1, true, false) < 0)
goto fail;
} else {
js_parse_error(s, "identifier expected");
@@ -26247,7 +26153,7 @@ static __exception int js_parse_statement_or_decl(JSParseState *s,
/* ES6 Annex B.3.2 and B.3.3 semantics */
if (!(decl_mask & DECL_MASK_FUNC))
goto func_decl_error;
- if (!(decl_mask & DECL_MASK_OTHER) && peek_token(s, FALSE) == '*')
+ if (!(decl_mask & DECL_MASK_OTHER) && peek_token(s, false) == '*')
goto func_decl_error;
goto parse_func_var;
case TOK_IDENT:
@@ -26257,16 +26163,16 @@ static __exception int js_parse_statement_or_decl(JSParseState *s,
}
/* Determine if `let` introduces a Declaration or an ExpressionStatement */
switch (is_let(s, decl_mask)) {
- case TRUE:
+ case true:
tok = TOK_LET;
goto haslet;
- case FALSE:
+ case false:
break;
default:
goto fail;
}
if (token_is_pseudo_keyword(s, JS_ATOM_async) &&
- peek_token(s, TRUE) == TOK_FUNCTION) {
+ peek_token(s, true) == TOK_FUNCTION) {
if (!(decl_mask & DECL_MASK_OTHER)) {
func_decl_error:
js_parse_error(s, "function declarations can't appear in single-statement context");
@@ -26288,7 +26194,7 @@ static __exception int js_parse_statement_or_decl(JSParseState *s,
js_parse_error(s, "class declarations can't appear in single-statement context");
goto fail;
}
- if (js_parse_class(s, FALSE, JS_PARSE_EXPORT_NONE))
+ if (js_parse_class(s, false, JS_PARSE_EXPORT_NONE))
return -1;
break;
@@ -26927,7 +26833,7 @@ static int find_exported_name(GetExportNamesState *s, JSAtom name)
static __exception int get_exported_names(JSContext *ctx,
GetExportNamesState *s,
- JSModuleDef *m, BOOL from_star)
+ JSModuleDef *m, bool from_star)
{
ExportedNameEntry *en;
int i, j;
@@ -26968,14 +26874,14 @@ static __exception int get_exported_names(JSContext *ctx,
JSStarExportEntry *se = &m->star_export_entries[i];
JSModuleDef *m1;
m1 = m->req_module_entries[se->req_module_idx].module;
- if (get_exported_names(ctx, s, m1, TRUE))
+ if (get_exported_names(ctx, s, m1, true))
return -1;
}
return 0;
}
/* Unfortunately, the spec gives a different behavior from GetOwnProperty ! */
-static int js_module_ns_has(JSContext *ctx, JSValue obj, JSAtom atom)
+static int js_module_ns_has(JSContext *ctx, JSValueConst obj, JSAtom atom)
{
return (find_own_property1(JS_VALUE_GET_OBJ(obj), atom) != NULL);
}
@@ -26999,7 +26905,7 @@ static int exported_names_cmp(const void *p1, const void *p2, void *opaque)
/* XXX: raise an error ? */
ret = 0;
} else {
- ret = js_string_compare(ctx, JS_VALUE_GET_STRING(str1),
+ ret = js_string_compare(JS_VALUE_GET_STRING(str1),
JS_VALUE_GET_STRING(str2));
}
JS_FreeValue(ctx, str1);
@@ -27028,7 +26934,7 @@ static JSValue js_build_module_ns(JSContext *ctx, JSModuleDef *m)
p = JS_VALUE_GET_OBJ(obj);
memset(s, 0, sizeof(*s));
- ret = get_exported_names(ctx, s, m, FALSE);
+ ret = get_exported_names(ctx, s, m, false);
js_free(ctx, s->modules);
if (ret)
goto fail;
@@ -27114,7 +27020,7 @@ static JSValue js_build_module_ns(JSContext *ctx, JSModuleDef *m)
JS_AtomToString(ctx, JS_ATOM_Module),
0);
- p->extensible = FALSE;
+ p->extensible = false;
return obj;
fail:
js_free(ctx, s->exported_names);
@@ -27134,10 +27040,10 @@ JSValue JS_GetModuleNamespace(JSContext *ctx, JSModuleDef *m)
return js_dup(m->module_ns);
}
-#ifdef DUMP_MODULE_RESOLVE
+#ifdef ENABLE_DUMPS // JS_DUMP_MODULE_RESOLVE
#define module_trace(ctx, ...) \
do { \
- if (check_dump_flag(ctx->rt, DUMP_MODULE_RESOLVE)) \
+ if (check_dump_flag(ctx->rt, JS_DUMP_MODULE_RESOLVE)) \
printf(__VA_ARGS__); \
} while (0)
#else
@@ -27152,13 +27058,13 @@ static int js_resolve_module(JSContext *ctx, JSModuleDef *m)
if (m->resolved)
return 0;
-#ifdef DUMP_MODULE_RESOLVE
- if (check_dump_flag(ctx->rt, DUMP_MODULE_RESOLVE)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_MODULE_RESOLVE
+ if (check_dump_flag(ctx->rt, JS_DUMP_MODULE_RESOLVE)) {
char buf1[ATOM_GET_STR_BUF_SIZE];
printf("resolving module '%s':\n", JS_AtomGetStr(ctx, buf1, sizeof(buf1), m->module_name));
}
#endif
- m->resolved = TRUE;
+ m->resolved = true;
/* resolve each requested module */
for(i = 0; i < m->req_module_entries_count; i++) {
JSReqModuleEntry *rme = &m->req_module_entries[i];
@@ -27175,7 +27081,7 @@ static int js_resolve_module(JSContext *ctx, JSModuleDef *m)
return 0;
}
-static JSVarRef *js_create_module_var(JSContext *ctx, BOOL is_lexical)
+static JSVarRef *js_create_module_var(JSContext *ctx, bool is_lexical)
{
JSVarRef *var_ref;
var_ref = js_malloc(ctx, sizeof(JSVarRef));
@@ -27187,7 +27093,7 @@ static JSVarRef *js_create_module_var(JSContext *ctx, BOOL is_lexical)
else
var_ref->value = JS_UNDEFINED;
var_ref->pvalue = &var_ref->value;
- var_ref->is_detached = TRUE;
+ var_ref->is_detached = true;
add_gc_object(ctx->rt, &var_ref->header, JS_GC_OBJ_TYPE_VAR_REF);
return var_ref;
}
@@ -27230,7 +27136,7 @@ static int js_create_module_bytecode_function(JSContext *ctx, JSModuleDef *m)
if (!var_ref)
goto fail;
- module_trace(ctx, "local %d: %p\n", i, var_ref);
+ module_trace(ctx, "local %d: %p\n", i, (void *)var_ref);
var_refs[i] = var_ref;
}
@@ -27247,7 +27153,7 @@ static int js_create_module_bytecode_function(JSContext *ctx, JSModuleDef *m)
/* must be done before js_link_module() because of cyclic references */
static int js_create_module_function(JSContext *ctx, JSModuleDef *m)
{
- BOOL is_c_module;
+ bool is_c_module;
int i;
JSVarRef *var_ref;
@@ -27261,7 +27167,7 @@ static int js_create_module_function(JSContext *ctx, JSModuleDef *m)
for(i = 0; i < m->export_entries_count; i++) {
JSExportEntry *me = &m->export_entries[i];
if (me->export_type == JS_EXPORT_TYPE_LOCAL) {
- var_ref = js_create_module_var(ctx, FALSE);
+ var_ref = js_create_module_var(ctx, false);
if (!var_ref)
return -1;
me->u.local.var_ref = var_ref;
@@ -27271,7 +27177,7 @@ static int js_create_module_function(JSContext *ctx, JSModuleDef *m)
if (js_create_module_bytecode_function(ctx, m))
return -1;
}
- m->func_created = TRUE;
+ m->func_created = true;
/* do it on the dependencies */
@@ -27295,7 +27201,7 @@ static int js_inner_module_linking(JSContext *ctx, JSModuleDef *m,
JSModuleDef *m1;
JSVarRef **var_refs, *var_ref;
JSObject *p;
- BOOL is_c_module;
+ bool is_c_module;
JSValue ret_val;
if (js_check_stack_overflow(ctx->rt, 0)) {
@@ -27303,8 +27209,8 @@ static int js_inner_module_linking(JSContext *ctx, JSModuleDef *m,
return -1;
}
-#ifdef DUMP_MODULE_RESOLVE
- if (check_dump_flag(ctx->rt, DUMP_MODULE_RESOLVE)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_MODULE_RESOLVE
+ if (check_dump_flag(ctx->rt, JS_DUMP_MODULE_RESOLVE)) {
char buf1[ATOM_GET_STR_BUF_SIZE];
printf("js_inner_module_linking '%s':\n", JS_AtomGetStr(ctx, buf1, sizeof(buf1), m->module_name));
}
@@ -27341,8 +27247,8 @@ static int js_inner_module_linking(JSContext *ctx, JSModuleDef *m,
}
}
-#ifdef DUMP_MODULE_RESOLVE
- if (check_dump_flag(ctx->rt, DUMP_MODULE_RESOLVE)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_MODULE_RESOLVE
+ if (check_dump_flag(ctx->rt, JS_DUMP_MODULE_RESOLVE)) {
char buf1[ATOM_GET_STR_BUF_SIZE];
printf("instantiating module '%s':\n", JS_AtomGetStr(ctx, buf1, sizeof(buf1), m->module_name));
}
@@ -27364,8 +27270,8 @@ static int js_inner_module_linking(JSContext *ctx, JSModuleDef *m,
}
}
-#ifdef DUMP_MODULE_RESOLVE
- if (check_dump_flag(ctx->rt, DUMP_MODULE_RESOLVE)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_MODULE_RESOLVE
+ if (check_dump_flag(ctx->rt, JS_DUMP_MODULE_RESOLVE)) {
printf("exported bindings:\n");
for(i = 0; i < m->export_entries_count; i++) {
JSExportEntry *me = &m->export_entries[i];
@@ -27384,8 +27290,8 @@ static int js_inner_module_linking(JSContext *ctx, JSModuleDef *m,
for(i = 0; i < m->import_entries_count; i++) {
mi = &m->import_entries[i];
-#ifdef DUMP_MODULE_RESOLVE
- if (check_dump_flag(ctx->rt, DUMP_MODULE_RESOLVE)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_MODULE_RESOLVE
+ if (check_dump_flag(ctx->rt, JS_DUMP_MODULE_RESOLVE)) {
printf("import var_idx=%d name=", mi->var_idx);
print_atom(ctx, mi->import_name);
printf(": ");
@@ -27422,7 +27328,7 @@ static int js_inner_module_linking(JSContext *ctx, JSModuleDef *m,
val = JS_GetModuleNamespace(ctx, m2);
if (JS_IsException(val))
goto fail;
- var_ref = js_create_module_var(ctx, TRUE);
+ var_ref = js_create_module_var(ctx, true);
if (!var_ref) {
JS_FreeValue(ctx, val);
goto fail;
@@ -27441,7 +27347,7 @@ static int js_inner_module_linking(JSContext *ctx, JSModuleDef *m,
var_ref->header.ref_count++;
var_refs[mi->var_idx] = var_ref;
- module_trace(ctx, "local export (var_ref=%p)\n", var_ref);
+ module_trace(ctx, "local export (var_ref=%p)\n", (void *)var_ref);
}
}
}
@@ -27477,8 +27383,8 @@ static int js_inner_module_linking(JSContext *ctx, JSModuleDef *m,
}
}
-#ifdef DUMP_MODULE_RESOLVE
- if (check_dump_flag(ctx->rt, DUMP_MODULE_RESOLVE)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_MODULE_RESOLVE
+ if (check_dump_flag(ctx->rt, JS_DUMP_MODULE_RESOLVE)) {
printf("js_inner_module_linking done\n");
}
#endif
@@ -27493,8 +27399,8 @@ static int js_link_module(JSContext *ctx, JSModuleDef *m)
{
JSModuleDef *stack_top, *m1;
-#ifdef DUMP_MODULE_RESOLVE
- if (check_dump_flag(ctx->rt, DUMP_MODULE_RESOLVE)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_MODULE_RESOLVE
+ if (check_dump_flag(ctx->rt, JS_DUMP_MODULE_RESOLVE)) {
char buf1[ATOM_GET_STR_BUF_SIZE];
printf("js_link_module '%s':\n", JS_AtomGetStr(ctx, buf1, sizeof(buf1), m->module_name));
}
@@ -27589,13 +27495,14 @@ static JSValue js_import_meta(JSContext *ctx)
static JSValue JS_NewModuleValue(JSContext *ctx, JSModuleDef *m)
{
- return JS_DupValue(ctx, JS_MKPTR(JS_TAG_MODULE, m));
+ return js_dup(JS_MKPTR(JS_TAG_MODULE, m));
}
static JSValue js_load_module_rejected(JSContext *ctx, JSValueConst this_val,
- int argc, JSValueConst *argv, int magic, JSValue *func_data)
+ int argc, JSValueConst *argv, int magic,
+ JSValueConst *func_data)
{
- JSValueConst *resolving_funcs = (JSValueConst *)func_data;
+ JSValueConst *resolving_funcs = func_data;
JSValueConst error;
JSValue ret;
@@ -27604,16 +27511,16 @@ static JSValue js_load_module_rejected(JSContext *ctx, JSValueConst this_val,
error = argv[0];
else
error = JS_UNDEFINED;
- ret = JS_Call(ctx, resolving_funcs[1], JS_UNDEFINED,
- 1, &error);
+ ret = JS_Call(ctx, resolving_funcs[1], JS_UNDEFINED, 1, &error);
JS_FreeValue(ctx, ret);
return JS_UNDEFINED;
}
static JSValue js_load_module_fulfilled(JSContext *ctx, JSValueConst this_val,
- int argc, JSValueConst *argv, int magic, JSValue *func_data)
+ int argc, JSValueConst *argv, int magic,
+ JSValueConst *func_data)
{
- JSValueConst *resolving_funcs = (JSValueConst *)func_data;
+ JSValueConst *resolving_funcs = func_data;
JSModuleDef *m = JS_VALUE_GET_PTR(func_data[2]);
JSValue ret, ns;
@@ -27621,11 +27528,10 @@ static JSValue js_load_module_fulfilled(JSContext *ctx, JSValueConst this_val,
ns = JS_GetModuleNamespace(ctx, m);
if (JS_IsException(ns)) {
JSValue err = JS_GetException(ctx);
- js_load_module_rejected(ctx, JS_UNDEFINED, 1, (JSValueConst *)&err, 0, func_data);
+ js_load_module_rejected(ctx, JS_UNDEFINED, 1, vc(&err), 0, func_data);
return JS_UNDEFINED;
}
- ret = JS_Call(ctx, resolving_funcs[0], JS_UNDEFINED,
- 1, (JSValueConst *)&ns);
+ ret = JS_Call(ctx, resolving_funcs[0], JS_UNDEFINED, 1, vc(&ns));
JS_FreeValue(ctx, ret);
JS_FreeValue(ctx, ns);
return JS_UNDEFINED;
@@ -27655,8 +27561,7 @@ static void JS_LoadModuleInternal(JSContext *ctx, const char *basename,
if (JS_IsException(evaluate_promise)) {
fail:
err = JS_GetException(ctx);
- ret = JS_Call(ctx, resolving_funcs[1], JS_UNDEFINED,
- 1, (JSValueConst *)&err);
+ ret = JS_Call(ctx, resolving_funcs[1], JS_UNDEFINED, 1, vc(&err));
JS_FreeValue(ctx, ret); /* XXX: what to do if exception ? */
JS_FreeValue(ctx, err);
return;
@@ -27669,7 +27574,7 @@ static void JS_LoadModuleInternal(JSContext *ctx, const char *basename,
evaluate_resolving_funcs[0] = JS_NewCFunctionData(ctx, js_load_module_fulfilled, 0, 0, 3, func_data);
evaluate_resolving_funcs[1] = JS_NewCFunctionData(ctx, js_load_module_rejected, 0, 0, 3, func_data);
JS_FreeValue(ctx, func_obj);
- ret = js_promise_then(ctx, evaluate_promise, 2, (JSValueConst *)evaluate_resolving_funcs);
+ ret = js_promise_then(ctx, evaluate_promise, 2, vc(evaluate_resolving_funcs));
JS_FreeValue(ctx, ret);
JS_FreeValue(ctx, evaluate_resolving_funcs[0]);
JS_FreeValue(ctx, evaluate_resolving_funcs[1]);
@@ -27686,19 +27591,18 @@ JSValue JS_LoadModule(JSContext *ctx, const char *basename,
promise = JS_NewPromiseCapability(ctx, resolving_funcs);
if (JS_IsException(promise))
return JS_EXCEPTION;
- JS_LoadModuleInternal(ctx, basename, filename,
- (JSValueConst *)resolving_funcs);
+ JS_LoadModuleInternal(ctx, basename, filename, vc(resolving_funcs));
JS_FreeValue(ctx, resolving_funcs[0]);
JS_FreeValue(ctx, resolving_funcs[1]);
return promise;
}
static JSValue js_dynamic_import_job(JSContext *ctx,
- int argc, JSValue *argv)
+ int argc, JSValueConst *argv)
{
- JSValue *resolving_funcs = argv;
- JSValue basename_val = argv[2];
- JSValue specifier = argv[3];
+ JSValueConst *resolving_funcs = argv;
+ JSValueConst basename_val = argv[2];
+ JSValueConst specifier = argv[3];
const char *basename = NULL, *filename;
JSValue ret, err;
@@ -27721,15 +27625,14 @@ static JSValue js_dynamic_import_job(JSContext *ctx,
return JS_UNDEFINED;
exception:
err = JS_GetException(ctx);
- ret = JS_Call(ctx, resolving_funcs[1], JS_UNDEFINED,
- 1, &err);
+ ret = JS_Call(ctx, resolving_funcs[1], JS_UNDEFINED, 1, vc(&err));
JS_FreeValue(ctx, ret); /* XXX: what to do if exception ? */
JS_FreeValue(ctx, err);
JS_FreeCString(ctx, basename);
return JS_UNDEFINED;
}
-static JSValue js_dynamic_import(JSContext *ctx, JSValue specifier)
+static JSValue js_dynamic_import(JSContext *ctx, JSValueConst specifier)
{
JSAtom basename;
JSValue promise, resolving_funcs[2], basename_val;
@@ -27753,11 +27656,11 @@ static JSValue js_dynamic_import(JSContext *ctx, JSValue specifier)
args[0] = resolving_funcs[0];
args[1] = resolving_funcs[1];
args[2] = basename_val;
- args[3] = specifier;
+ args[3] = unsafe_unconst(specifier);
/* cannot run JS_LoadModuleInternal synchronously because it would
cause an unexpected recursion in js_evaluate_module() */
- JS_EnqueueJob(ctx, js_dynamic_import_job, 4, args);
+ JS_EnqueueJob(ctx, js_dynamic_import_job, 4, vc(args));
JS_FreeValue(ctx, basename_val);
JS_FreeValue(ctx, resolving_funcs[0]);
@@ -27769,11 +27672,10 @@ static void js_set_module_evaluated(JSContext *ctx, JSModuleDef *m)
{
m->status = JS_MODULE_STATUS_EVALUATED;
if (!JS_IsUndefined(m->promise)) {
- JSValue value, ret_val;
+ JSValue ret_val;
assert(m->cycle_root == m);
- value = JS_UNDEFINED;
- ret_val = JS_Call(ctx, m->resolving_funcs[0], JS_UNDEFINED,
- 1, (JSValueConst *)&value);
+ JSValueConst value = JS_UNDEFINED;
+ ret_val = JS_Call(ctx, m->resolving_funcs[0], JS_UNDEFINED, 1, &value);
JS_FreeValue(ctx, ret_val);
}
}
@@ -27785,14 +27687,14 @@ typedef struct {
} ExecModuleList;
/* XXX: slow. Could use a linked list instead of ExecModuleList */
-static BOOL find_in_exec_module_list(ExecModuleList *exec_list, JSModuleDef *m)
+static bool find_in_exec_module_list(ExecModuleList *exec_list, JSModuleDef *m)
{
int i;
for(i = 0; i < exec_list->count; i++) {
if (exec_list->tab[i] == m)
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
static int gather_available_ancestors(JSContext *ctx, JSModuleDef *module,
@@ -27841,7 +27743,8 @@ static int js_execute_sync_module(JSContext *ctx, JSModuleDef *m,
JSValue *pvalue);
static JSValue js_async_module_execution_rejected(JSContext *ctx, JSValueConst this_val,
- int argc, JSValueConst *argv, int magic, JSValue *func_data)
+ int argc, JSValueConst *argv, int magic,
+ JSValueConst *func_data)
{
JSModuleDef *module = JS_VALUE_GET_PTR(func_data[0]);
JSValueConst error = argv[0];
@@ -27859,15 +27762,15 @@ static JSValue js_async_module_execution_rejected(JSContext *ctx, JSValueConst t
assert(!module->eval_has_exception);
assert(module->async_evaluation);
- module->eval_has_exception = TRUE;
- module->eval_exception = JS_DupValue(ctx, error);
+ module->eval_has_exception = true;
+ module->eval_exception = js_dup(error);
module->status = JS_MODULE_STATUS_EVALUATED;
for(i = 0; i < module->async_parent_modules_count; i++) {
JSModuleDef *m = module->async_parent_modules[i];
JSValue m_obj = JS_NewModuleValue(ctx, m);
js_async_module_execution_rejected(ctx, JS_UNDEFINED, 1, &error, 0,
- &m_obj);
+ vc(&m_obj));
JS_FreeValue(ctx, m_obj);
}
@@ -27882,7 +27785,8 @@ static JSValue js_async_module_execution_rejected(JSContext *ctx, JSValueConst t
}
static JSValue js_async_module_execution_fulfilled(JSContext *ctx, JSValueConst this_val,
- int argc, JSValueConst *argv, int magic, JSValue *func_data)
+ int argc, JSValueConst *argv, int magic,
+ JSValueConst *func_data)
{
JSModuleDef *module = JS_VALUE_GET_PTR(func_data[0]);
ExecModuleList exec_list_s, *exec_list = &exec_list_s;
@@ -27895,7 +27799,7 @@ static JSValue js_async_module_execution_fulfilled(JSContext *ctx, JSValueConst
assert(module->status == JS_MODULE_STATUS_EVALUATING_ASYNC);
assert(!module->eval_has_exception);
assert(module->async_evaluation);
- module->async_evaluation = FALSE;
+ module->async_evaluation = false;
js_set_module_evaluated(ctx, module);
exec_list->tab = NULL;
@@ -27922,8 +27826,8 @@ static JSValue js_async_module_execution_fulfilled(JSContext *ctx, JSValueConst
if (js_execute_sync_module(ctx, m, &error) < 0) {
JSValue m_obj = JS_NewModuleValue(ctx, m);
js_async_module_execution_rejected(ctx, JS_UNDEFINED,
- 1, (JSValueConst *)&error, 0,
- &m_obj);
+ 1, vc(&error),
+ 0, vc(&m_obj));
JS_FreeValue(ctx, m_obj);
JS_FreeValue(ctx, error);
} else {
@@ -27943,9 +27847,9 @@ static int js_execute_async_module(JSContext *ctx, JSModuleDef *m)
if (JS_IsException(promise))
return -1;
m_obj = JS_NewModuleValue(ctx, m);
- resolve_funcs[0] = JS_NewCFunctionData(ctx, js_async_module_execution_fulfilled, 0, 0, 1, (JSValueConst *)&m_obj);
- resolve_funcs[1] = JS_NewCFunctionData(ctx, js_async_module_execution_rejected, 0, 0, 1, (JSValueConst *)&m_obj);
- ret_val = js_promise_then(ctx, promise, 2, (JSValueConst *)resolve_funcs);
+ resolve_funcs[0] = JS_NewCFunctionData(ctx, js_async_module_execution_fulfilled, 0, 0, 1, vc(&m_obj));
+ resolve_funcs[1] = JS_NewCFunctionData(ctx, js_async_module_execution_rejected, 0, 0, 1, vc(&m_obj));
+ ret_val = js_promise_then(ctx, promise, 2, vc(resolve_funcs));
JS_FreeValue(ctx, ret_val);
JS_FreeValue(ctx, m_obj);
JS_FreeValue(ctx, resolve_funcs[0]);
@@ -28003,8 +27907,8 @@ static int js_inner_module_evaluation(JSContext *ctx, JSModuleDef *m,
return -1;
}
-#ifdef DUMP_MODULE_RESOLVE
- if (check_dump_flag(ctx->rt, DUMP_MODULE_RESOLVE)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_MODULE_RESOLVE
+ if (check_dump_flag(ctx->rt, JS_DUMP_MODULE_RESOLVE)) {
char buf1[ATOM_GET_STR_BUF_SIZE];
printf("js_inner_module_evaluation '%s':\n", JS_AtomGetStr(ctx, buf1, sizeof(buf1), m->module_name));
}
@@ -28013,7 +27917,7 @@ static int js_inner_module_evaluation(JSContext *ctx, JSModuleDef *m,
if (m->status == JS_MODULE_STATUS_EVALUATING_ASYNC ||
m->status == JS_MODULE_STATUS_EVALUATED) {
if (m->eval_has_exception) {
- *pvalue = JS_DupValue(ctx, m->eval_exception);
+ *pvalue = js_dup(m->eval_exception);
return -1;
} else {
*pvalue = JS_UNDEFINED;
@@ -28052,7 +27956,7 @@ static int js_inner_module_evaluation(JSContext *ctx, JSModuleDef *m,
assert(m1->status == JS_MODULE_STATUS_EVALUATING_ASYNC ||
m1->status == JS_MODULE_STATUS_EVALUATED);
if (m1->eval_has_exception) {
- *pvalue = JS_DupValue(ctx, m1->eval_exception);
+ *pvalue = js_dup(m1->eval_exception);
return -1;
}
}
@@ -28068,12 +27972,12 @@ static int js_inner_module_evaluation(JSContext *ctx, JSModuleDef *m,
if (m->pending_async_dependencies > 0) {
assert(!m->async_evaluation);
- m->async_evaluation = TRUE;
+ m->async_evaluation = true;
m->async_evaluation_timestamp =
ctx->rt->module_async_evaluation_next_timestamp++;
} else if (m->has_tla) {
assert(!m->async_evaluation);
- m->async_evaluation = TRUE;
+ m->async_evaluation = true;
m->async_evaluation_timestamp =
ctx->rt->module_async_evaluation_next_timestamp++;
js_execute_async_module(ctx, m);
@@ -28119,7 +28023,7 @@ static JSValue js_evaluate_module(JSContext *ctx, JSModuleDef *m)
}
/* a promise may be created only on the cycle_root of a cycle */
if (!JS_IsUndefined(m->promise))
- return JS_DupValue(ctx, m->promise);
+ return js_dup(m->promise);
m->promise = JS_NewPromiseCapability(ctx, m->resolving_funcs);
if (JS_IsException(m->promise))
return JS_EXCEPTION;
@@ -28130,8 +28034,8 @@ static JSValue js_evaluate_module(JSContext *ctx, JSModuleDef *m)
m1 = stack_top;
assert(m1->status == JS_MODULE_STATUS_EVALUATING);
m1->status = JS_MODULE_STATUS_EVALUATED;
- m1->eval_has_exception = TRUE;
- m1->eval_exception = JS_DupValue(ctx, result);
+ m1->eval_has_exception = true;
+ m1->eval_exception = js_dup(result);
m1->cycle_root = m; /* spec bug: should be present */
stack_top = m1->stack_prev;
}
@@ -28139,23 +28043,22 @@ static JSValue js_evaluate_module(JSContext *ctx, JSModuleDef *m)
assert(m->status == JS_MODULE_STATUS_EVALUATED);
assert(m->eval_has_exception);
ret_val = JS_Call(ctx, m->resolving_funcs[1], JS_UNDEFINED,
- 1, (JSValueConst *)&m->eval_exception);
+ 1, vc(&m->eval_exception));
JS_FreeValue(ctx, ret_val);
} else {
assert(m->status == JS_MODULE_STATUS_EVALUATING_ASYNC ||
m->status == JS_MODULE_STATUS_EVALUATED);
assert(!m->eval_has_exception);
if (!m->async_evaluation) {
- JSValue value;
assert(m->status == JS_MODULE_STATUS_EVALUATED);
- value = JS_UNDEFINED;
+ JSValueConst value = JS_UNDEFINED;
ret_val = JS_Call(ctx, m->resolving_funcs[0], JS_UNDEFINED,
- 1, (JSValueConst *)&value);
+ 1, &value);
JS_FreeValue(ctx, ret_val);
}
assert(stack_top == NULL);
}
- return JS_DupValue(ctx, m->promise);
+ return js_dup(m->promise);
}
static __exception JSAtom js_parse_from_clause(JSParseState *s)
@@ -28195,10 +28098,10 @@ static __exception int js_parse_export(JSParseState *s)
tok = s->token.val;
if (tok == TOK_CLASS) {
- return js_parse_class(s, FALSE, JS_PARSE_EXPORT_NAMED);
+ return js_parse_class(s, false, JS_PARSE_EXPORT_NAMED);
} else if (tok == TOK_FUNCTION ||
(token_is_pseudo_keyword(s, JS_ATOM_async) &&
- peek_token(s, TRUE) == TOK_FUNCTION)) {
+ peek_token(s, true) == TOK_FUNCTION)) {
return js_parse_function_decl2(s, JS_PARSE_FUNC_STATEMENT,
JS_FUNC_NORMAL, JS_ATOM_NULL,
s->token.ptr,
@@ -28307,10 +28210,10 @@ static __exception int js_parse_export(JSParseState *s)
break;
case TOK_DEFAULT:
if (s->token.val == TOK_CLASS) {
- return js_parse_class(s, FALSE, JS_PARSE_EXPORT_DEFAULT);
+ return js_parse_class(s, false, JS_PARSE_EXPORT_DEFAULT);
} else if (s->token.val == TOK_FUNCTION ||
(token_is_pseudo_keyword(s, JS_ATOM_async) &&
- peek_token(s, TRUE) == TOK_FUNCTION)) {
+ peek_token(s, true) == TOK_FUNCTION)) {
return js_parse_function_decl2(s, JS_PARSE_FUNC_STATEMENT,
JS_FUNC_NORMAL, JS_ATOM_NULL,
s->token.ptr,
@@ -28340,7 +28243,7 @@ static __exception int js_parse_export(JSParseState *s)
case TOK_VAR:
case TOK_LET:
case TOK_CONST:
- return js_parse_var(s, TRUE, tok, TRUE);
+ return js_parse_var(s, PF_IN_ACCEPTED, tok, /*export_flag*/true);
default:
return js_parse_error(s, "invalid export syntax");
}
@@ -28348,9 +28251,9 @@ static __exception int js_parse_export(JSParseState *s)
}
static int add_closure_var(JSContext *ctx, JSFunctionDef *s,
- BOOL is_local, BOOL is_arg,
+ bool is_local, bool is_arg,
int var_idx, JSAtom var_name,
- BOOL is_const, BOOL is_lexical,
+ bool is_const, bool is_lexical,
JSVarKindEnum var_kind);
static int add_import(JSParseState *s, JSModuleDef *m,
@@ -28359,7 +28262,7 @@ static int add_import(JSParseState *s, JSModuleDef *m,
JSContext *ctx = s->ctx;
int i, var_idx;
JSImportEntry *mi;
- BOOL is_local;
+ bool is_local;
if (local_name == JS_ATOM_arguments || local_name == JS_ATOM_eval)
return js_parse_error(s, "invalid import binding");
@@ -28372,9 +28275,9 @@ static int add_import(JSParseState *s, JSModuleDef *m,
}
is_local = (import_name == JS_ATOM__star_);
- var_idx = add_closure_var(ctx, s->cur_func, is_local, FALSE,
+ var_idx = add_closure_var(ctx, s->cur_func, is_local, false,
m->import_entries_count,
- local_name, TRUE, TRUE, JS_VAR_NORMAL);
+ local_name, true, true, JS_VAR_NORMAL);
if (var_idx < 0)
return -1;
if (js_resize_array(ctx, (void **)&m->import_entries,
@@ -28510,7 +28413,7 @@ static __exception int js_parse_source_element(JSParseState *s)
if (s->token.val == TOK_FUNCTION ||
(token_is_pseudo_keyword(s, JS_ATOM_async) &&
- peek_token(s, TRUE) == TOK_FUNCTION)) {
+ peek_token(s, true) == TOK_FUNCTION)) {
if (js_parse_function_decl(s, JS_PARSE_FUNC_STATEMENT,
JS_FUNC_NORMAL, JS_ATOM_NULL,
s->token.ptr,
@@ -28521,7 +28424,7 @@ static __exception int js_parse_source_element(JSParseState *s)
if (js_parse_export(s))
return -1;
} else if (s->token.val == TOK_IMPORT && fd->module &&
- ((tok = peek_token(s, FALSE)) != '(' && tok != '.')) {
+ ((tok = peek_token(s, false)) != '(' && tok != '.')) {
/* the peek_token is needed to avoid confusion with ImportCall
(dynamic import) or import.meta */
if (js_parse_import(s))
@@ -28536,8 +28439,8 @@ static __exception int js_parse_source_element(JSParseState *s)
/* `filename` may be pure ASCII or UTF-8 encoded */
static JSFunctionDef *js_new_function_def(JSContext *ctx,
JSFunctionDef *parent,
- BOOL is_eval,
- BOOL is_func_expr,
+ bool is_eval,
+ bool is_func_expr,
const char *filename,
int line_num,
int col_num)
@@ -28594,13 +28497,12 @@ static JSFunctionDef *js_new_function_def(JSContext *ctx,
//fd->pc2line_last_line_num = line_num;
//fd->pc2line_last_pc = 0;
- fd->ic = init_ic(ctx);
return fd;
}
static void free_bytecode_atoms(JSRuntime *rt,
const uint8_t *bc_buf, int bc_len,
- BOOL use_short_opcodes)
+ bool use_short_opcodes)
{
int pos, len, op;
JSAtom atom;
@@ -28650,10 +28552,6 @@ static void js_free_function_def(JSContext *ctx, JSFunctionDef *fd)
js_free(ctx, fd->label_slots);
js_free(ctx, fd->source_loc_slots);
- /* free ic */
- if (fd->ic)
- free_ic(ctx->rt, fd->ic);
-
for(i = 0; i < fd->cpool_count; i++) {
JS_FreeValue(ctx, fd->cpool[i]);
}
@@ -28697,7 +28595,7 @@ static void js_free_function_def(JSContext *ctx, JSFunctionDef *fd)
js_free(ctx, fd);
}
-#ifdef DUMP_BYTECODE
+#ifdef ENABLE_DUMPS // JS_DUMP_BYTECODE_*
static const char *skip_lines(const char *p, int n) {
while (p && n-- > 0 && *p) {
while (*p && *p++ != '\n')
@@ -28735,7 +28633,7 @@ static void dump_byte_code(JSContext *ctx, int pass,
const JSOpCode *oi;
int pos, pos_next, op, size, idx, addr, line, line1, in_source;
uint8_t *bits = js_mallocz(ctx, len * sizeof(*bits));
- BOOL use_short_opcodes = (b != NULL);
+ bool use_short_opcodes = (b != NULL);
if (start_pos != 0 || bits == NULL)
goto no_labels;
@@ -28824,8 +28722,8 @@ static void dump_byte_code(JSContext *ctx, int pass,
printf("truncated opcode (0x%02x)\n", op);
break;
}
-#ifdef DUMP_BYTECODE_HEX
- if (check_dump_flag(ctx->rt, DUMP_BYTECODE_HEX)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_BYTECODE_HEX
+ if (check_dump_flag(ctx->rt, JS_DUMP_BYTECODE_HEX)) {
int i, x, x0;
x = x0 = printf("%5d ", pos);
for (i = 0; i < size; i++) {
@@ -29087,6 +28985,7 @@ static __maybe_unused void js_dump_function_bytecode(JSContext *ctx, JSFunctionB
int i;
char atom_buf[ATOM_GET_STR_BUF_SIZE];
const char *str;
+ const uint8_t *op;
if (b->filename != JS_ATOM_NULL) {
str = JS_AtomGetStr(ctx, atom_buf, sizeof(atom_buf), b->filename);
@@ -29133,15 +29032,19 @@ static __maybe_unused void js_dump_function_bytecode(JSContext *ctx, JSFunctionB
}
}
printf(" stack_size: %d\n", b->stack_size);
- printf(" opcodes:\n");
+ printf(" byte_code_len: %d\n", b->byte_code_len);
+ op = b->byte_code_buf;
+ for (i = 0; op < &b->byte_code_buf[b->byte_code_len]; i++)
+ op += short_opcode_info(*op).size;
+ printf(" opcodes: %d\n", i);
dump_byte_code(ctx, 3, b->byte_code_buf, b->byte_code_len,
b->vardefs, b->arg_count,
b->vardefs ? b->vardefs + b->arg_count : NULL, b->var_count,
b->closure_var, b->closure_var_count,
b->cpool, b->cpool_count,
b->source, b->line_num, NULL, b, 0);
-#ifdef DUMP_BYTECODE_PC2LINE
- if (check_dump_flag(ctx->rt, DUMP_BYTECODE_PC2LINE))
+#ifdef ENABLE_DUMPS // JS_DUMP_BYTECODE_PC2LINE
+ if (check_dump_flag(ctx->rt, JS_DUMP_BYTECODE_PC2LINE))
dump_pc2line(ctx, b->pc2line_buf, b->pc2line_len, b->line_num, b->col_num);
#endif
printf("\n");
@@ -29149,9 +29052,9 @@ static __maybe_unused void js_dump_function_bytecode(JSContext *ctx, JSFunctionB
#endif
static int add_closure_var(JSContext *ctx, JSFunctionDef *s,
- BOOL is_local, BOOL is_arg,
+ bool is_local, bool is_arg,
int var_idx, JSAtom var_name,
- BOOL is_const, BOOL is_lexical,
+ bool is_const, bool is_lexical,
JSVarKindEnum var_kind)
{
JSClosureVar *cv;
@@ -29192,12 +29095,12 @@ static int find_closure_var(JSContext *ctx, JSFunctionDef *s,
}
/* 'fd' must be a parent of 's'. Create in 's' a closure referencing a
- local variable (is_local = TRUE) or a closure (is_local = FALSE) in
+ local variable (is_local = true) or a closure (is_local = false) in
'fd' */
static int get_closure_var2(JSContext *ctx, JSFunctionDef *s,
- JSFunctionDef *fd, BOOL is_local,
- BOOL is_arg, int var_idx, JSAtom var_name,
- BOOL is_const, BOOL is_lexical,
+ JSFunctionDef *fd, bool is_local,
+ bool is_arg, int var_idx, JSAtom var_name,
+ bool is_const, bool is_lexical,
JSVarKindEnum var_kind)
{
int i;
@@ -29208,7 +29111,7 @@ static int get_closure_var2(JSContext *ctx, JSFunctionDef *s,
is_const, is_lexical, var_kind);
if (var_idx < 0)
return -1;
- is_local = FALSE;
+ is_local = false;
}
for(i = 0; i < s->closure_var_count; i++) {
JSClosureVar *cv = &s->closure_var[i];
@@ -29221,12 +29124,12 @@ static int get_closure_var2(JSContext *ctx, JSFunctionDef *s,
}
static int get_closure_var(JSContext *ctx, JSFunctionDef *s,
- JSFunctionDef *fd, BOOL is_arg,
+ JSFunctionDef *fd, bool is_arg,
int var_idx, JSAtom var_name,
- BOOL is_const, BOOL is_lexical,
+ bool is_const, bool is_lexical,
JSVarKindEnum var_kind)
{
- return get_closure_var2(ctx, s, fd, TRUE, is_arg,
+ return get_closure_var2(ctx, s, fd, true, is_arg,
var_idx, var_name, is_const, is_lexical,
var_kind);
}
@@ -29239,7 +29142,7 @@ static int get_with_scope_opcode(int op)
return OP_with_get_var + (op - OP_scope_get_var);
}
-static BOOL can_opt_put_ref_value(const uint8_t *bc_buf, int pos)
+static bool can_opt_put_ref_value(const uint8_t *bc_buf, int pos)
{
int opcode = bc_buf[pos];
return (bc_buf[pos + 1] == OP_put_ref_value &&
@@ -29249,7 +29152,7 @@ static BOOL can_opt_put_ref_value(const uint8_t *bc_buf, int pos)
opcode == OP_rot3l));
}
-static BOOL can_opt_put_global_ref_value(const uint8_t *bc_buf, int pos)
+static bool can_opt_put_global_ref_value(const uint8_t *bc_buf, int pos)
{
int opcode = bc_buf[pos];
return (bc_buf[pos + 1] == OP_put_ref_value &&
@@ -29309,7 +29212,7 @@ static int optimize_scope_make_global_ref(JSContext *ctx, JSFunctionDef *s,
JSAtom var_name)
{
int label_pos, end_pos, pos, op;
- BOOL is_strict_mode = s->is_strict_mode;
+ bool is_strict_mode = s->is_strict_mode;
/* replace the reference get/put with normal variable
accesses */
@@ -29427,7 +29330,7 @@ static int resolve_pseudo_var(JSContext *ctx, JSFunctionDef *s,
the case, handle it and jump to 'label_done' */
static void var_object_test(JSContext *ctx, JSFunctionDef *s,
JSAtom var_name, int op, DynBuf *bc,
- int *plabel_done, BOOL is_with)
+ int *plabel_done, bool is_with)
{
dbuf_putc(bc, get_with_scope_opcode(op));
dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));
@@ -29448,7 +29351,7 @@ static int resolve_scope_var(JSContext *ctx, JSFunctionDef *s,
int label_done;
JSFunctionDef *fd;
JSVarDef *vd;
- BOOL is_pseudo_var, is_arg_scope;
+ bool is_pseudo_var, is_arg_scope;
label_done = -1;
@@ -29631,7 +29534,7 @@ static int resolve_scope_var(JSContext *ctx, JSFunctionDef *s,
break;
} else if (vd->var_name == JS_ATOM__with_ && !is_pseudo_var) {
vd->is_captured = 1;
- idx = get_closure_var(ctx, s, fd, FALSE, idx, vd->var_name, FALSE, FALSE, JS_VAR_NORMAL);
+ idx = get_closure_var(ctx, s, fd, false, idx, vd->var_name, false, false, JS_VAR_NORMAL);
if (idx >= 0) {
dbuf_putc(bc, OP_get_var_ref);
dbuf_put_u16(bc, idx);
@@ -29668,9 +29571,9 @@ static int resolve_scope_var(JSContext *ctx, JSFunctionDef *s,
if (!is_arg_scope && fd->var_object_idx >= 0 && !is_pseudo_var) {
vd = &fd->vars[fd->var_object_idx];
vd->is_captured = 1;
- idx = get_closure_var(ctx, s, fd, FALSE,
+ idx = get_closure_var(ctx, s, fd, false,
fd->var_object_idx, vd->var_name,
- FALSE, FALSE, JS_VAR_NORMAL);
+ false, false, JS_VAR_NORMAL);
dbuf_putc(bc, OP_get_var_ref);
dbuf_put_u16(bc, idx);
var_object_test(ctx, s, var_name, op, bc, &label_done, 0);
@@ -29680,9 +29583,9 @@ static int resolve_scope_var(JSContext *ctx, JSFunctionDef *s,
if (fd->arg_var_object_idx >= 0 && !is_pseudo_var) {
vd = &fd->vars[fd->arg_var_object_idx];
vd->is_captured = 1;
- idx = get_closure_var(ctx, s, fd, FALSE,
+ idx = get_closure_var(ctx, s, fd, false,
fd->arg_var_object_idx, vd->var_name,
- FALSE, FALSE, JS_VAR_NORMAL);
+ false, false, JS_VAR_NORMAL);
dbuf_putc(bc, OP_get_var_ref);
dbuf_put_u16(bc, idx);
var_object_test(ctx, s, var_name, op, bc, &label_done, 0);
@@ -29703,7 +29606,7 @@ static int resolve_scope_var(JSContext *ctx, JSFunctionDef *s,
if (var_name == cv->var_name) {
if (fd != s) {
idx = get_closure_var2(ctx, s, fd,
- FALSE,
+ false,
cv->is_arg, idx1,
cv->var_name, cv->is_const,
cv->is_lexical, cv->var_kind);
@@ -29717,9 +29620,9 @@ static int resolve_scope_var(JSContext *ctx, JSFunctionDef *s,
int is_with = (cv->var_name == JS_ATOM__with_);
if (fd != s) {
idx = get_closure_var2(ctx, s, fd,
- FALSE,
+ false,
cv->is_arg, idx1,
- cv->var_name, FALSE, FALSE,
+ cv->var_name, false, false,
JS_VAR_NORMAL);
} else {
idx = idx1;
@@ -29736,12 +29639,12 @@ static int resolve_scope_var(JSContext *ctx, JSFunctionDef *s,
if (var_idx & ARGUMENT_VAR_OFFSET) {
fd->args[var_idx - ARGUMENT_VAR_OFFSET].is_captured = 1;
idx = get_closure_var(ctx, s, fd,
- TRUE, var_idx - ARGUMENT_VAR_OFFSET,
- var_name, FALSE, FALSE, JS_VAR_NORMAL);
+ true, var_idx - ARGUMENT_VAR_OFFSET,
+ var_name, false, false, JS_VAR_NORMAL);
} else {
fd->vars[var_idx].is_captured = 1;
idx = get_closure_var(ctx, s, fd,
- FALSE, var_idx,
+ false, var_idx,
var_name,
fd->vars[var_idx].is_const,
fd->vars[var_idx].is_lexical,
@@ -29886,7 +29789,7 @@ static int find_private_class_field_all(JSContext *ctx, JSFunctionDef *fd,
return -1;
}
-static void get_loc_or_ref(DynBuf *bc, BOOL is_ref, int idx)
+static void get_loc_or_ref(DynBuf *bc, bool is_ref, int idx)
{
/* if the field is not initialized, the error is catched when
accessing it */
@@ -29898,23 +29801,23 @@ static void get_loc_or_ref(DynBuf *bc, BOOL is_ref, int idx)
}
static int resolve_scope_private_field1(JSContext *ctx,
- BOOL *pis_ref, int *pvar_kind,
+ bool *pis_ref, int *pvar_kind,
JSFunctionDef *s,
JSAtom var_name, int scope_level)
{
int idx, var_kind;
JSFunctionDef *fd;
- BOOL is_ref;
+ bool is_ref;
fd = s;
- is_ref = FALSE;
+ is_ref = false;
for(;;) {
idx = find_private_class_field_all(ctx, fd, var_name, scope_level);
if (idx >= 0) {
var_kind = fd->vars[idx].var_kind;
if (is_ref) {
- idx = get_closure_var(ctx, s, fd, FALSE, idx, var_name,
- TRUE, TRUE, JS_VAR_NORMAL);
+ idx = get_closure_var(ctx, s, fd, false, idx, var_name,
+ true, true, JS_VAR_NORMAL);
if (idx < 0)
return -1;
}
@@ -29928,10 +29831,10 @@ static int resolve_scope_private_field1(JSContext *ctx,
JSClosureVar *cv = &fd->closure_var[idx];
if (cv->var_name == var_name) {
var_kind = cv->var_kind;
- is_ref = TRUE;
+ is_ref = true;
if (fd != s) {
idx = get_closure_var2(ctx, s, fd,
- FALSE,
+ false,
cv->is_arg, idx,
cv->var_name, cv->is_const,
cv->is_lexical,
@@ -29951,7 +29854,7 @@ static int resolve_scope_private_field1(JSContext *ctx,
} else {
fd = fd->parent;
}
- is_ref = TRUE;
+ is_ref = true;
}
done:
*pis_ref = is_ref;
@@ -29965,7 +29868,7 @@ static int resolve_scope_private_field(JSContext *ctx, JSFunctionDef *s,
DynBuf *bc)
{
int idx, var_kind;
- BOOL is_ref;
+ bool is_ref;
idx = resolve_scope_private_field1(ctx, &is_ref, &var_kind, s,
var_name, scope_level);
@@ -30074,7 +29977,7 @@ static void mark_eval_captured_variables(JSContext *ctx, JSFunctionDef *s,
}
/* XXX: should handle the argument scope generically */
-static BOOL is_var_in_arg_scope(const JSVarDef *vd)
+static bool is_var_in_arg_scope(const JSVarDef *vd)
{
return (vd->var_name == JS_ATOM_home_object ||
vd->var_name == JS_ATOM_this_active_func ||
@@ -30089,7 +29992,7 @@ static void add_eval_variables(JSContext *ctx, JSFunctionDef *s)
JSFunctionDef *fd;
JSVarDef *vd;
int i, scope_level, scope_idx;
- BOOL has_arguments_binding, has_this_binding, is_arg_scope;
+ bool has_arguments_binding, has_this_binding, is_arg_scope;
/* in non strict mode, variables are created in the caller's
environment object */
@@ -30149,12 +30052,12 @@ static void add_eval_variables(JSContext *ctx, JSFunctionDef *s)
fd->this_active_func_var_idx = add_var(ctx, fd, JS_ATOM_this_active_func);
if (fd->has_home_object && fd->home_object_var_idx < 0)
fd->home_object_var_idx = add_var(ctx, fd, JS_ATOM_home_object);
- has_this_binding = TRUE;
+ has_this_binding = true;
}
/* add 'arguments' if it was not previously added */
if (!has_arguments_binding && fd->has_arguments_binding) {
add_arguments_var(ctx, fd);
- has_arguments_binding = TRUE;
+ has_arguments_binding = true;
}
/* add function name */
if (fd->is_func_expr && fd->func_name != JS_ATOM_NULL)
@@ -30165,7 +30068,7 @@ static void add_eval_variables(JSContext *ctx, JSFunctionDef *s)
while (scope_idx >= 0) {
vd = &fd->vars[scope_idx];
vd->is_captured = 1;
- get_closure_var(ctx, s, fd, FALSE, scope_idx,
+ get_closure_var(ctx, s, fd, false, scope_idx,
vd->var_name, vd->is_const, vd->is_lexical, vd->var_kind);
scope_idx = vd->scope_next;
}
@@ -30177,7 +30080,7 @@ static void add_eval_variables(JSContext *ctx, JSFunctionDef *s)
vd = &fd->args[i];
if (vd->var_name != JS_ATOM_NULL) {
get_closure_var(ctx, s, fd,
- TRUE, i, vd->var_name, FALSE,
+ true, i, vd->var_name, false,
vd->is_lexical, JS_VAR_NORMAL);
}
}
@@ -30188,7 +30091,7 @@ static void add_eval_variables(JSContext *ctx, JSFunctionDef *s)
vd->var_name != JS_ATOM__ret_ &&
vd->var_name != JS_ATOM_NULL) {
get_closure_var(ctx, s, fd,
- FALSE, i, vd->var_name, FALSE,
+ false, i, vd->var_name, false,
vd->is_lexical, JS_VAR_NORMAL);
}
}
@@ -30198,7 +30101,7 @@ static void add_eval_variables(JSContext *ctx, JSFunctionDef *s)
/* do not close top level last result */
if (vd->scope_level == 0 && is_var_in_arg_scope(vd)) {
get_closure_var(ctx, s, fd,
- FALSE, i, vd->var_name, FALSE,
+ false, i, vd->var_name, false,
vd->is_lexical, JS_VAR_NORMAL);
}
}
@@ -30210,7 +30113,7 @@ static void add_eval_variables(JSContext *ctx, JSFunctionDef *s)
for (idx = 0; idx < fd->closure_var_count; idx++) {
JSClosureVar *cv = &fd->closure_var[idx];
get_closure_var2(ctx, s, fd,
- FALSE, cv->is_arg,
+ false, cv->is_arg,
idx, cv->var_name, cv->is_const,
cv->is_lexical, cv->var_kind);
}
@@ -30221,8 +30124,8 @@ static void add_eval_variables(JSContext *ctx, JSFunctionDef *s)
static void set_closure_from_var(JSContext *ctx, JSClosureVar *cv,
JSVarDef *vd, int var_idx)
{
- cv->is_local = TRUE;
- cv->is_arg = FALSE;
+ cv->is_local = true;
+ cv->is_arg = false;
cv->is_const = vd->is_const;
cv->is_lexical = vd->is_lexical;
cv->var_kind = vd->var_kind;
@@ -30237,7 +30140,7 @@ static __exception int add_closure_variables(JSContext *ctx, JSFunctionDef *s,
{
int i, count;
JSVarDef *vd;
- BOOL is_arg_scope;
+ bool is_arg_scope;
count = b->arg_count + b->var_count + b->closure_var_count;
s->closure_var = NULL;
@@ -30263,10 +30166,10 @@ static __exception int add_closure_variables(JSContext *ctx, JSFunctionDef *s,
for(i = 0; i < b->arg_count; i++) {
JSClosureVar *cv = &s->closure_var[s->closure_var_count++];
vd = &b->vardefs[i];
- cv->is_local = TRUE;
- cv->is_arg = TRUE;
- cv->is_const = FALSE;
- cv->is_lexical = FALSE;
+ cv->is_local = true;
+ cv->is_arg = true;
+ cv->is_const = false;
+ cv->is_lexical = false;
cv->var_kind = JS_VAR_NORMAL;
cv->var_idx = i;
cv->var_name = JS_DupAtom(ctx, vd->var_name);
@@ -30292,7 +30195,7 @@ static __exception int add_closure_variables(JSContext *ctx, JSFunctionDef *s,
for(i = 0; i < b->closure_var_count; i++) {
JSClosureVar *cv0 = &b->closure_var[i];
JSClosureVar *cv = &s->closure_var[s->closure_var_count++];
- cv->is_local = FALSE;
+ cv->is_local = false;
cv->is_arg = cv0->is_arg;
cv->is_const = cv0->is_const;
cv->is_lexical = cv0->is_lexical;
@@ -30320,12 +30223,12 @@ typedef struct CodeContext {
#define M3(op1, op2, op3) ((uint32_t)(op1) | ((uint32_t)(op2) << 8) | ((uint32_t)(op3) << 16))
#define M4(op1, op2, op3, op4) ((uint32_t)(op1) | ((uint32_t)(op2) << 8) | ((uint32_t)(op3) << 16) | ((uint32_t)(op4) << 24))
-static BOOL code_match(CodeContext *s, int pos, ...)
+static bool code_match(CodeContext *s, int pos, ...)
{
const uint8_t *tab = s->bc_buf;
int op, len, op1, line_num, col_num, pos_next;
va_list ap;
- BOOL ret = FALSE;
+ bool ret = false;
line_num = -1;
col_num = -1;
@@ -30337,7 +30240,7 @@ static BOOL code_match(CodeContext *s, int pos, ...)
s->pos = pos;
s->line_num = line_num;
s->col_num = col_num;
- ret = TRUE;
+ ret = true;
break;
}
for (;;) {
@@ -30490,7 +30393,7 @@ static void instantiate_hoisted_definitions(JSContext *ctx, JSFunctionDef *s, Dy
for(i = 0; i < s->global_var_count; i++) {
JSGlobalVar *hf = &s->global_vars[i];
int has_closure = 0;
- BOOL force_init = hf->force_init;
+ bool force_init = hf->force_init;
/* we are in an eval, so the closure contains all the
enclosing variables */
/* If the outer function has a variable environment,
@@ -30499,7 +30402,7 @@ static void instantiate_hoisted_definitions(JSContext *ctx, JSFunctionDef *s, Dy
JSClosureVar *cv = &s->closure_var[idx];
if (cv->var_name == hf->var_name) {
has_closure = 2;
- force_init = FALSE;
+ force_init = false;
break;
}
if (cv->var_name == JS_ATOM__var_ ||
@@ -30507,7 +30410,7 @@ static void instantiate_hoisted_definitions(JSContext *ctx, JSFunctionDef *s, Dy
dbuf_putc(bc, OP_get_var_ref);
dbuf_put_u16(bc, idx);
has_closure = 1;
- force_init = TRUE;
+ force_init = true;
break;
}
}
@@ -31085,7 +30988,7 @@ static RelocEntry *add_reloc(JSContext *ctx, LabelSlot *ls, uint32_t addr, int s
return re;
}
-static BOOL code_has_label(CodeContext *s, int pos, int label)
+static bool code_has_label(CodeContext *s, int pos, int label)
{
while (pos < s->bc_len) {
int op = s->bc_buf[pos];
@@ -31096,18 +30999,18 @@ static BOOL code_has_label(CodeContext *s, int pos, int label)
if (op == OP_label) {
int lab = get_u32(s->bc_buf + pos + 1);
if (lab == label)
- return TRUE;
+ return true;
pos += 5;
continue;
}
if (op == OP_goto) {
int lab = get_u32(s->bc_buf + pos + 1);
if (lab == label)
- return TRUE;
+ return true;
}
break;
}
- return FALSE;
+ return false;
}
/* return the target label, following the OP_goto jumps
@@ -32094,7 +31997,7 @@ static __exception int resolve_labels(JSContext *ctx, JSFunctionDef *s)
/* set the new byte code */
dbuf_free(&s->byte_code);
s->byte_code = bc_out;
- s->use_short_opcodes = TRUE;
+ s->use_short_opcodes = true;
if (dbuf_error(&s->byte_code)) {
JS_ThrowOutOfMemory(ctx);
return -1;
@@ -32201,8 +32104,8 @@ static __exception int compute_stack_size(JSContext *ctx,
goto fail;
}
oi = &short_opcode_info(op);
-#ifdef DUMP_BYTECODE_STACK
- if (check_dump_flag(ctx->rt, DUMP_BYTECODE_STACK))
+#ifdef ENABLE_DUMPS // JS_DUMP_BYTECODE_STACK
+ if (check_dump_flag(ctx->rt, JS_DUMP_BYTECODE_STACK))
printf("%5d: %10s %5d %5d\n", pos, oi->name, stack_len, catch_pos);
#endif
pos_next = pos + oi->size;
@@ -32369,7 +32272,7 @@ static int add_module_variables(JSContext *ctx, JSFunctionDef *fd)
for(i = 0; i < fd->global_var_count; i++) {
hf = &fd->global_vars[i];
- if (add_closure_var(ctx, fd, TRUE, FALSE, i, hf->var_name, hf->is_const,
+ if (add_closure_var(ctx, fd, true, false, i, hf->var_name, hf->is_const,
hf->is_lexical, JS_VAR_NORMAL) < 0)
return -1;
}
@@ -32457,8 +32360,8 @@ static JSValue js_create_function(JSContext *ctx, JSFunctionDef *fd)
fd->cpool[cpool_idx] = func_obj;
}
-#ifdef DUMP_BYTECODE_PASS1
- if (check_dump_flag(ctx->rt, DUMP_BYTECODE_PASS1)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_BYTECODE_PASS1
+ if (check_dump_flag(ctx->rt, JS_DUMP_BYTECODE_PASS1)) {
printf("pass 1\n");
dump_byte_code(ctx, 1, fd->byte_code.buf, fd->byte_code.size,
fd->args, fd->arg_count, fd->vars, fd->var_count,
@@ -32472,8 +32375,8 @@ static JSValue js_create_function(JSContext *ctx, JSFunctionDef *fd)
if (resolve_variables(ctx, fd))
goto fail;
-#ifdef DUMP_BYTECODE_PASS2
- if (check_dump_flag(ctx->rt, DUMP_BYTECODE_PASS2)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_BYTECODE_PASS2
+ if (check_dump_flag(ctx->rt, JS_DUMP_BYTECODE_PASS2)) {
printf("pass 2\n");
dump_byte_code(ctx, 2, fd->byte_code.buf, fd->byte_code.size,
fd->args, fd->arg_count, fd->vars, fd->var_count,
@@ -32573,18 +32476,11 @@ static JSValue js_create_function(JSContext *ctx, JSFunctionDef *fd)
b->arguments_allowed = fd->arguments_allowed;
b->backtrace_barrier = fd->backtrace_barrier;
b->realm = JS_DupContext(ctx);
- b->ic = fd->ic;
- fd->ic = NULL;
- rebuild_ic(ctx, b->ic);
- if (b->ic->count == 0) {
- free_ic(ctx->rt, b->ic);
- b->ic = NULL;
- }
add_gc_object(ctx->rt, &b->header, JS_GC_OBJ_TYPE_FUNCTION_BYTECODE);
-#ifdef DUMP_BYTECODE_FINAL
- if (check_dump_flag(ctx->rt, DUMP_BYTECODE_FINAL))
+#ifdef ENABLE_DUMPS // JS_DUMP_BYTECODE_FINAL
+ if (check_dump_flag(ctx->rt, JS_DUMP_BYTECODE_FINAL))
js_dump_function_bytecode(ctx, b);
#endif
@@ -32604,10 +32500,7 @@ static void free_function_bytecode(JSRuntime *rt, JSFunctionBytecode *b)
{
int i;
- free_bytecode_atoms(rt, b->byte_code_buf, b->byte_code_len, TRUE);
-
- if (b->ic)
- free_ic(rt, b->ic);
+ free_bytecode_atoms(rt, b->byte_code_buf, b->byte_code_len, true);
if (b->vardefs) {
for(i = 0; i < b->arg_count + b->var_count; i++) {
@@ -32641,7 +32534,7 @@ static __exception int js_parse_directives(JSParseState *s)
{
char str[20];
JSParsePos pos;
- BOOL has_semi;
+ bool has_semi;
if (s->token.val != TOK_STRING)
return 0;
@@ -32656,16 +32549,16 @@ static __exception int js_parse_directives(JSParseState *s)
if (next_token(s))
return -1;
- has_semi = FALSE;
+ has_semi = false;
switch (s->token.val) {
case ';':
if (next_token(s))
return -1;
- has_semi = TRUE;
+ has_semi = true;
break;
case '}':
case TOK_EOF:
- has_semi = TRUE;
+ has_semi = true;
break;
case TOK_NUMBER:
case TOK_STRING:
@@ -32708,7 +32601,7 @@ static __exception int js_parse_directives(JSParseState *s)
case TOK_STATIC:
/* automatic insertion of ';' */
if (s->got_lf)
- has_semi = TRUE;
+ has_semi = true;
break;
default:
break;
@@ -32716,14 +32609,14 @@ static __exception int js_parse_directives(JSParseState *s)
if (!has_semi)
break;
if (!strcmp(str, "use strict")) {
- s->cur_func->has_use_strict = TRUE;
- s->cur_func->is_strict_mode = TRUE;
+ s->cur_func->has_use_strict = true;
+ s->cur_func->is_strict_mode = true;
}
}
return js_parse_seek_token(s, &pos);
}
-static BOOL js_invalid_strict_name(JSAtom name) {
+static bool js_invalid_strict_name(JSAtom name) {
switch (name) {
case JS_ATOM_eval:
case JS_ATOM_arguments:
@@ -32736,9 +32629,9 @@ static BOOL js_invalid_strict_name(JSAtom name) {
case JS_ATOM_public:
case JS_ATOM_static:
case JS_ATOM_yield:
- return TRUE;
+ return true;
default:
- return FALSE;
+ return false;
}
}
@@ -32796,21 +32689,21 @@ static JSFunctionDef *js_parse_function_class_fields_init(JSParseState *s)
{
JSFunctionDef *fd;
- fd = js_new_function_def(s->ctx, s->cur_func, FALSE, FALSE,
+ fd = js_new_function_def(s->ctx, s->cur_func, false, false,
s->filename, 0, 0);
if (!fd)
return NULL;
fd->func_name = JS_ATOM_NULL;
- fd->has_prototype = FALSE;
- fd->has_home_object = TRUE;
-
- fd->has_arguments_binding = FALSE;
- fd->has_this_binding = TRUE;
- fd->is_derived_class_constructor = FALSE;
- fd->new_target_allowed = TRUE;
- fd->super_call_allowed = FALSE;
+ fd->has_prototype = false;
+ fd->has_home_object = true;
+
+ fd->has_arguments_binding = false;
+ fd->has_this_binding = true;
+ fd->is_derived_class_constructor = false;
+ fd->new_target_allowed = true;
+ fd->super_call_allowed = false;
fd->super_allowed = fd->has_home_object;
- fd->arguments_allowed = FALSE;
+ fd->arguments_allowed = false;
fd->func_kind = JS_FUNC_NORMAL;
fd->func_type = JS_PARSE_FUNC_METHOD;
@@ -32831,10 +32724,10 @@ static __exception int js_parse_function_decl2(JSParseState *s,
{
JSContext *ctx = s->ctx;
JSFunctionDef *fd = s->cur_func;
- BOOL is_expr;
+ bool is_expr;
int func_idx, lexical_func_idx = -1;
- BOOL has_opt_arg;
- BOOL create_func_var = FALSE;
+ bool has_opt_arg;
+ bool create_func_var = false;
is_expr = (func_type != JS_PARSE_FUNC_STATEMENT &&
func_type != JS_PARSE_FUNC_VAR);
@@ -32844,7 +32737,7 @@ static __exception int js_parse_function_decl2(JSParseState *s,
func_type == JS_PARSE_FUNC_EXPR) {
if (func_kind == JS_FUNC_NORMAL &&
token_is_pseudo_keyword(s, JS_ATOM_async) &&
- peek_token(s, TRUE) != '\n') {
+ peek_token(s, true) != '\n') {
if (next_token(s))
return -1;
func_kind = JS_FUNC_ASYNC;
@@ -32903,10 +32796,10 @@ static __exception int js_parse_function_decl2(JSParseState *s,
if (func_type == JS_PARSE_FUNC_VAR) {
if (!fd->is_strict_mode
&& func_kind == JS_FUNC_NORMAL
- && find_lexical_decl(ctx, fd, func_name, fd->scope_first, FALSE) < 0
+ && find_lexical_decl(ctx, fd, func_name, fd->scope_first, false) < 0
&& !((func_idx = find_var(ctx, fd, func_name)) >= 0 && (func_idx & ARGUMENT_VAR_OFFSET))
&& !(func_name == JS_ATOM_arguments && fd->has_arguments_binding)) {
- create_func_var = TRUE;
+ create_func_var = true;
}
/* Create the lexical name here so that the function closure
contains it */
@@ -32939,7 +32832,7 @@ static __exception int js_parse_function_decl2(JSParseState *s,
}
}
- fd = js_new_function_def(ctx, fd, FALSE, is_expr, s->filename,
+ fd = js_new_function_def(ctx, fd, false, is_expr, s->filename,
function_line_num, function_col_num);
if (!fd) {
JS_FreeAtom(ctx, func_name);
@@ -32969,18 +32862,18 @@ static __exception int js_parse_function_decl2(JSParseState *s,
fd->super_allowed = fd->parent->super_allowed;
fd->arguments_allowed = fd->parent->arguments_allowed;
} else if (func_type == JS_PARSE_FUNC_CLASS_STATIC_INIT) {
- fd->new_target_allowed = TRUE; // although new.target === undefined
- fd->super_call_allowed = FALSE;
- fd->super_allowed = TRUE;
- fd->arguments_allowed = FALSE;
+ fd->new_target_allowed = true; // although new.target === undefined
+ fd->super_call_allowed = false;
+ fd->super_allowed = true;
+ fd->arguments_allowed = false;
} else {
- fd->new_target_allowed = TRUE;
+ fd->new_target_allowed = true;
fd->super_call_allowed = fd->is_derived_class_constructor;
fd->super_allowed = fd->has_home_object;
- fd->arguments_allowed = TRUE;
+ fd->arguments_allowed = true;
}
- /* fd->in_function_body == FALSE prevents yield/await during the parsing
+ /* fd->in_function_body == false prevents yield/await during the parsing
of the arguments in generator/async functions. They are parsed as
regular identifiers for other function kinds. */
fd->func_kind = func_kind;
@@ -32997,9 +32890,9 @@ static __exception int js_parse_function_decl2(JSParseState *s,
}
/* parse arguments */
- fd->has_simple_parameter_list = TRUE;
- fd->has_parameter_expressions = FALSE;
- has_opt_arg = FALSE;
+ fd->has_simple_parameter_list = true;
+ fd->has_parameter_expressions = false;
+ has_opt_arg = false;
if (func_type == JS_PARSE_FUNC_ARROW && s->token.val == TOK_IDENT) {
JSAtom name;
if (s->token.u.ident.is_reserved) {
@@ -33015,9 +32908,9 @@ static __exception int js_parse_function_decl2(JSParseState *s,
int skip_bits;
/* if there is an '=' inside the parameter list, we
consider there is a parameter expression inside */
- js_parse_skip_parens_token(s, &skip_bits, FALSE);
+ js_parse_skip_parens_token(s, &skip_bits, false);
if (skip_bits & SKIP_HAS_ASSIGNMENT)
- fd->has_parameter_expressions = TRUE;
+ fd->has_parameter_expressions = true;
if (next_token(s))
goto fail;
} else {
@@ -33033,17 +32926,17 @@ static __exception int js_parse_function_decl2(JSParseState *s,
while (s->token.val != ')') {
JSAtom name;
- BOOL rest = FALSE;
+ bool rest = false;
int idx, has_initializer;
if (s->token.val == TOK_ELLIPSIS) {
- fd->has_simple_parameter_list = FALSE;
- rest = TRUE;
+ fd->has_simple_parameter_list = false;
+ rest = true;
if (next_token(s))
goto fail;
}
if (s->token.val == '[' || s->token.val == '{') {
- fd->has_simple_parameter_list = FALSE;
+ fd->has_simple_parameter_list = false;
if (rest) {
emit_op(s, OP_rest);
emit_u16(s, fd->arg_count);
@@ -33053,11 +32946,11 @@ static __exception int js_parse_function_decl2(JSParseState *s,
emit_op(s, OP_get_arg);
emit_u16(s, idx);
}
- has_initializer = js_parse_destructuring_element(s, fd->has_parameter_expressions ? TOK_LET : TOK_VAR, 1, TRUE, -1, TRUE);
+ has_initializer = js_parse_destructuring_element(s, fd->has_parameter_expressions ? TOK_LET : TOK_VAR, true, true, -1, true, false);
if (has_initializer < 0)
goto fail;
if (has_initializer)
- has_opt_arg = TRUE;
+ has_opt_arg = true;
if (!has_opt_arg)
fd->defined_arg_count++;
} else if (s->token.val == TOK_IDENT) {
@@ -33093,13 +32986,13 @@ static __exception int js_parse_function_decl2(JSParseState *s,
}
emit_op(s, OP_put_arg);
emit_u16(s, idx);
- fd->has_simple_parameter_list = FALSE;
- has_opt_arg = TRUE;
+ fd->has_simple_parameter_list = false;
+ has_opt_arg = true;
} else if (s->token.val == '=') {
int label;
- fd->has_simple_parameter_list = FALSE;
- has_opt_arg = TRUE;
+ fd->has_simple_parameter_list = false;
+ has_opt_arg = true;
if (next_token(s))
goto fail;
@@ -33200,7 +33093,7 @@ static __exception int js_parse_function_decl2(JSParseState *s,
/* in generators, yield expression is forbidden during the parsing
of the arguments */
- fd->in_function_body = TRUE;
+ fd->in_function_body = true;
push_scope(s); /* enter body scope */
fd->body_scope = fd->scope_level;
@@ -33262,7 +33155,7 @@ static __exception int js_parse_function_decl2(JSParseState *s,
/* in case there is no return, add one */
if (js_is_live_code(s)) {
- emit_return(s, FALSE);
+ emit_return(s, false);
}
done:
s->cur_func = fd->parent;
@@ -33440,9 +33333,9 @@ static __exception int js_parse_program(JSParseState *s)
emit_op(s, OP_get_loc);
emit_u16(s, fd->eval_ret_idx);
}
- emit_return(s, TRUE);
+ emit_return(s, true);
} else {
- emit_return(s, FALSE);
+ emit_return(s, false);
}
return 0;
@@ -33450,12 +33343,12 @@ static __exception int js_parse_program(JSParseState *s)
static void js_parse_init(JSContext *ctx, JSParseState *s,
const char *input, size_t input_len,
- const char *filename)
+ const char *filename, int line)
{
memset(s, 0, sizeof(*s));
s->ctx = ctx;
s->filename = filename;
- s->line_num = 1;
+ s->line_num = line;
s->col_num = 1;
s->buf_start = s->buf_ptr = (const uint8_t *)input;
s->buf_end = s->buf_ptr + input_len;
@@ -33467,7 +33360,7 @@ static void js_parse_init(JSContext *ctx, JSParseState *s,
}
static JSValue JS_EvalFunctionInternal(JSContext *ctx, JSValue fun_obj,
- JSValue this_obj,
+ JSValueConst this_obj,
JSVarRef **var_refs, JSStackFrame *sf)
{
JSValue ret_val;
@@ -33505,9 +33398,9 @@ JSValue JS_EvalFunction(JSContext *ctx, JSValue fun_obj)
/* 'input' must be zero terminated i.e. input[input_len] = '\0'. */
/* `export_name` and `input` may be pure ASCII or UTF-8 encoded */
-static JSValue __JS_EvalInternal(JSContext *ctx, JSValue this_obj,
+static JSValue __JS_EvalInternal(JSContext *ctx, JSValueConst this_obj,
const char *input, size_t input_len,
- const char *filename, int flags, int scope_idx)
+ const char *filename, int line, int flags, int scope_idx)
{
JSParseState s1, *s = &s1;
int err, eval_type;
@@ -33517,9 +33410,9 @@ static JSValue __JS_EvalInternal(JSContext *ctx, JSValue this_obj,
JSFunctionBytecode *b;
JSFunctionDef *fd;
JSModuleDef *m;
- BOOL is_strict_mode;
+ bool is_strict_mode;
- js_parse_init(ctx, s, input, input_len, filename);
+ js_parse_init(ctx, s, input, input_len, filename, line);
skip_shebang(&s->buf_ptr, s->buf_end);
eval_type = flags & JS_EVAL_TYPE_MASK;
@@ -33546,10 +33439,10 @@ static JSValue __JS_EvalInternal(JSContext *ctx, JSValue this_obj,
m = js_new_module_def(ctx, module_name);
if (!m)
return JS_EXCEPTION;
- is_strict_mode = TRUE;
+ is_strict_mode = true;
}
}
- fd = js_new_function_def(ctx, NULL, TRUE, FALSE, filename, 1, 1);
+ fd = js_new_function_def(ctx, NULL, true, false, filename, line, 1);
if (!fd)
goto fail1;
s->cur_func = fd;
@@ -33562,10 +33455,10 @@ static JSValue __JS_EvalInternal(JSContext *ctx, JSValue this_obj,
fd->super_allowed = b->super_allowed;
fd->arguments_allowed = b->arguments_allowed;
} else {
- fd->new_target_allowed = FALSE;
- fd->super_call_allowed = FALSE;
- fd->super_allowed = FALSE;
- fd->arguments_allowed = TRUE;
+ fd->new_target_allowed = false;
+ fd->super_call_allowed = false;
+ fd->super_allowed = false;
+ fd->arguments_allowed = true;
}
fd->is_strict_mode = is_strict_mode;
fd->func_name = JS_DupAtom(ctx, JS_ATOM__eval_);
@@ -33575,7 +33468,7 @@ static JSValue __JS_EvalInternal(JSContext *ctx, JSValue this_obj,
}
fd->module = m;
if (m != NULL || (flags & JS_EVAL_FLAG_ASYNC)) {
- fd->in_function_body = TRUE;
+ fd->in_function_body = true;
fd->func_kind = JS_FUNC_ASYNC;
}
s->is_module = (m != NULL);
@@ -33620,19 +33513,25 @@ static JSValue __JS_EvalInternal(JSContext *ctx, JSValue this_obj,
}
/* the indirection is needed to make 'eval' optional */
-static JSValue JS_EvalInternal(JSContext *ctx, JSValue this_obj,
+static JSValue JS_EvalInternal(JSContext *ctx, JSValueConst this_obj,
const char *input, size_t input_len,
- const char *filename, int flags, int scope_idx)
+ const char *filename, int line, int flags, int scope_idx)
{
+ JSRuntime *rt = ctx->rt;
+
if (unlikely(!ctx->eval_internal)) {
return JS_ThrowTypeError(ctx, "eval is not supported");
}
- return ctx->eval_internal(ctx, this_obj, input, input_len, filename,
+ if (!rt->current_stack_frame) {
+ JS_FreeValueRT(rt, ctx->error_back_trace);
+ ctx->error_back_trace = JS_UNDEFINED;
+ }
+ return ctx->eval_internal(ctx, this_obj, input, input_len, filename, line,
flags, scope_idx);
}
-static JSValue JS_EvalObject(JSContext *ctx, JSValue this_obj,
- JSValue val, int flags, int scope_idx)
+static JSValue JS_EvalObject(JSContext *ctx, JSValueConst this_obj,
+ JSValueConst val, int flags, int scope_idx)
{
JSValue ret;
const char *str;
@@ -33643,21 +33542,46 @@ static JSValue JS_EvalObject(JSContext *ctx, JSValue this_obj,
str = JS_ToCStringLen(ctx, &len, val);
if (!str)
return JS_EXCEPTION;
- ret = JS_EvalInternal(ctx, this_obj, str, len, "<input>", flags, scope_idx);
+ ret = JS_EvalInternal(ctx, this_obj, str, len, "<input>", 1, flags, scope_idx);
JS_FreeCString(ctx, str);
return ret;
}
-JSValue JS_EvalThis(JSContext *ctx, JSValue this_obj,
+JSValue JS_EvalThis(JSContext *ctx, JSValueConst this_obj,
const char *input, size_t input_len,
const char *filename, int eval_flags)
{
+ JSEvalOptions options = {
+ .version = JS_EVAL_OPTIONS_VERSION,
+ .filename = filename,
+ .line_num = 1,
+ .eval_flags = eval_flags
+ };
+ return JS_EvalThis2(ctx, this_obj, input, input_len, &options);
+}
+
+JSValue JS_EvalThis2(JSContext *ctx, JSValueConst this_obj,
+ const char *input, size_t input_len,
+ JSEvalOptions *options)
+{
+ const char *filename = "<unnamed>";
+ int line = 1;
+ int eval_flags = 0;
+ if (options) {
+ if (options->version != JS_EVAL_OPTIONS_VERSION)
+ return JS_ThrowInternalError(ctx, "bad JSEvalOptions version");
+ if (options->filename)
+ filename = options->filename;
+ if (options->line_num != 0)
+ line = options->line_num;
+ eval_flags = options->eval_flags;
+ }
JSValue ret;
assert((eval_flags & JS_EVAL_TYPE_MASK) == JS_EVAL_TYPE_GLOBAL ||
(eval_flags & JS_EVAL_TYPE_MASK) == JS_EVAL_TYPE_MODULE);
- ret = JS_EvalInternal(ctx, this_obj, input, input_len, filename,
+ ret = JS_EvalInternal(ctx, this_obj, input, input_len, filename, line,
eval_flags, -1);
return ret;
}
@@ -33665,11 +33589,21 @@ JSValue JS_EvalThis(JSContext *ctx, JSValue this_obj,
JSValue JS_Eval(JSContext *ctx, const char *input, size_t input_len,
const char *filename, int eval_flags)
{
- return JS_EvalThis(ctx, ctx->global_obj, input, input_len, filename,
- eval_flags);
+ JSEvalOptions options = {
+ .version = JS_EVAL_OPTIONS_VERSION,
+ .filename = filename,
+ .line_num = 1,
+ .eval_flags = eval_flags
+ };
+ return JS_EvalThis2(ctx, ctx->global_obj, input, input_len, &options);
}
-int JS_ResolveModule(JSContext *ctx, JSValue obj)
+JSValue JS_Eval2(JSContext *ctx, const char *input, size_t input_len, JSEvalOptions *options)
+{
+ return JS_EvalThis2(ctx, ctx->global_obj, input, input_len, options);
+}
+
+int JS_ResolveModule(JSContext *ctx, JSValueConst obj)
{
if (JS_VALUE_GET_TAG(obj) == JS_TAG_MODULE) {
JSModuleDef *m = JS_VALUE_GET_PTR(obj);
@@ -33819,11 +33753,11 @@ typedef enum BCTagEnum {
typedef struct BCWriterState {
JSContext *ctx;
DynBuf dbuf;
- BOOL allow_bytecode : 8;
- BOOL allow_sab : 8;
- BOOL allow_reference : 8;
- BOOL allow_source : 1;
- BOOL allow_debug : 1;
+ bool allow_bytecode;
+ bool allow_sab;
+ bool allow_reference;
+ bool allow_source;
+ bool allow_debug;
uint32_t first_atom;
uint32_t *atom_to_idx;
int atom_to_idx_size;
@@ -33833,11 +33767,11 @@ typedef struct BCWriterState {
uint8_t **sab_tab;
int sab_tab_len;
int sab_tab_size;
- /* list of referenced objects (used if allow_reference = TRUE) */
+ /* list of referenced objects (used if allow_reference = true) */
JSObjectList object_list;
} BCWriterState;
-#ifdef DUMP_READ_OBJECT
+#ifdef ENABLE_DUMPS // JS_DUMP_READ_OBJECT
static const char * const bc_tag_str[] = {
"invalid",
"null",
@@ -34023,11 +33957,6 @@ static void bc_byte_swap(uint8_t *bc_buf, int bc_len)
}
}
-static BOOL is_ic_op(uint8_t op)
-{
- return op >= OP_get_field_ic && op <= OP_put_field_ic;
-}
-
static int JS_WriteFunctionBytecode(BCWriterState *s,
const JSFunctionBytecode *b)
{
@@ -34058,16 +33987,6 @@ static int JS_WriteFunctionBytecode(BCWriterState *s,
put_u32(bc_buf + pos + 1, val);
break;
default:
- // IC (inline cache) opcodes should not end up in the serialized
- // bytecode; translate them to their non-IC counterparts here
- if (is_ic_op(op)) {
- val = get_u32(bc_buf + pos + 1);
- atom = get_ic_atom(b->ic, val);
- if (bc_atom_to_idx(s, &val, atom))
- goto fail;
- put_u32(bc_buf + pos + 1, val);
- bc_buf[pos] -= (OP_get_field_ic - OP_get_field);
- }
break;
}
pos += len;
@@ -34091,13 +34010,13 @@ static void JS_WriteString(BCWriterState *s, JSString *p)
bc_put_leb128(s, ((uint32_t)p->len << 1) | p->is_wide_char);
if (p->is_wide_char) {
for(i = 0; i < p->len; i++)
- bc_put_u16(s, p->u.str16[i]);
+ bc_put_u16(s, str16(p)[i]);
} else {
- dbuf_put(&s->dbuf, p->u.str8, p->len);
+ dbuf_put(&s->dbuf, str8(p), p->len);
}
}
-static int JS_WriteBigInt(BCWriterState *s, JSValue obj)
+static int JS_WriteBigInt(BCWriterState *s, JSValueConst obj)
{
uint32_t tag, tag1;
int64_t e;
@@ -34169,9 +34088,9 @@ static int JS_WriteBigInt(BCWriterState *s, JSValue obj)
return 0;
}
-static int JS_WriteObjectRec(BCWriterState *s, JSValue obj);
+static int JS_WriteObjectRec(BCWriterState *s, JSValueConst obj);
-static int JS_WriteFunctionTag(BCWriterState *s, JSValue obj)
+static int JS_WriteFunctionTag(BCWriterState *s, JSValueConst obj)
{
JSFunctionBytecode *b = JS_VALUE_GET_PTR(obj);
uint32_t flags;
@@ -34264,7 +34183,7 @@ static int JS_WriteFunctionTag(BCWriterState *s, JSValue obj)
return -1;
}
-static int JS_WriteModule(BCWriterState *s, JSValue obj)
+static int JS_WriteModule(BCWriterState *s, JSValueConst obj)
{
JSModuleDef *m = JS_VALUE_GET_PTR(obj);
int i;
@@ -34314,22 +34233,22 @@ static int JS_WriteModule(BCWriterState *s, JSValue obj)
return -1;
}
-static int JS_WriteArray(BCWriterState *s, JSValue obj)
+static int JS_WriteArray(BCWriterState *s, JSValueConst obj)
{
JSObject *p = JS_VALUE_GET_OBJ(obj);
uint32_t i, len;
JSValue val;
int ret;
- BOOL is_template;
+ bool is_template;
if (s->allow_bytecode && !p->extensible) {
/* not extensible array: we consider it is a
template when we are saving bytecode */
bc_put_u8(s, BC_TAG_TEMPLATE_OBJECT);
- is_template = TRUE;
+ is_template = true;
} else {
bc_put_u8(s, BC_TAG_ARRAY);
- is_template = FALSE;
+ is_template = false;
}
if (js_get_length32(s->ctx, &len, obj))
goto fail1;
@@ -34357,7 +34276,7 @@ static int JS_WriteArray(BCWriterState *s, JSValue obj)
return -1;
}
-static int JS_WriteObjectTag(BCWriterState *s, JSValue obj)
+static int JS_WriteObjectTag(BCWriterState *s, JSValueConst obj)
{
JSObject *p = JS_VALUE_GET_OBJ(obj);
uint32_t i, prop_count;
@@ -34394,7 +34313,7 @@ static int JS_WriteObjectTag(BCWriterState *s, JSValue obj)
return -1;
}
-static int JS_WriteTypedArray(BCWriterState *s, JSValue obj)
+static int JS_WriteTypedArray(BCWriterState *s, JSValueConst obj)
{
JSObject *p = JS_VALUE_GET_OBJ(obj);
JSTypedArray *ta = p->u.typed_array;
@@ -34408,7 +34327,7 @@ static int JS_WriteTypedArray(BCWriterState *s, JSValue obj)
return 0;
}
-static int JS_WriteArrayBuffer(BCWriterState *s, JSValue obj)
+static int JS_WriteArrayBuffer(BCWriterState *s, JSValueConst obj)
{
JSObject *p = JS_VALUE_GET_OBJ(obj);
JSArrayBuffer *abuf = p->u.array_buffer;
@@ -34423,7 +34342,7 @@ static int JS_WriteArrayBuffer(BCWriterState *s, JSValue obj)
return 0;
}
-static int JS_WriteSharedArrayBuffer(BCWriterState *s, JSValue obj)
+static int JS_WriteSharedArrayBuffer(BCWriterState *s, JSValueConst obj)
{
JSObject *p = JS_VALUE_GET_OBJ(obj);
JSArrayBuffer *abuf = p->u.array_buffer;
@@ -34448,12 +34367,12 @@ static int JS_WriteRegExp(BCWriterState *s, JSRegExp regexp)
JS_WriteString(s, regexp.pattern);
if (is_be())
- lre_byte_swap(bc->u.str8, bc->len, /*is_byte_swapped*/FALSE);
+ lre_byte_swap(str8(bc), bc->len, /*is_byte_swapped*/false);
JS_WriteString(s, bc);
if (is_be())
- lre_byte_swap(bc->u.str8, bc->len, /*is_byte_swapped*/TRUE);
+ lre_byte_swap(str8(bc), bc->len, /*is_byte_swapped*/true);
return 0;
}
@@ -34461,7 +34380,7 @@ static int JS_WriteRegExp(BCWriterState *s, JSRegExp regexp)
static int JS_WriteMap(BCWriterState *s, struct JSMapState *map_state);
static int JS_WriteSet(BCWriterState *s, struct JSMapState *map_state);
-static int JS_WriteObjectRec(BCWriterState *s, JSValue obj)
+static int JS_WriteObjectRec(BCWriterState *s, JSValueConst obj)
{
uint32_t tag;
@@ -34573,8 +34492,7 @@ static int JS_WriteObjectRec(BCWriterState *s, JSValue obj)
ret = JS_WriteSet(s, p->u.map_state);
break;
default:
- if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&
- p->class_id <= JS_CLASS_FLOAT64_ARRAY) {
+ if (is_typed_array(p->class_id)) {
ret = JS_WriteTypedArray(s, obj);
} else {
JS_ThrowTypeError(s->ctx, "unsupported object class");
@@ -34660,7 +34578,7 @@ static int JS_WriteObjectAtoms(BCWriterState *s)
return -1;
}
-uint8_t *JS_WriteObject2(JSContext *ctx, size_t *psize, JSValue obj,
+uint8_t *JS_WriteObject2(JSContext *ctx, size_t *psize, JSValueConst obj,
int flags, JSSABTab *psab_tab)
{
BCWriterState ss, *s = &ss;
@@ -34708,7 +34626,7 @@ uint8_t *JS_WriteObject2(JSContext *ctx, size_t *psize, JSValue obj,
return NULL;
}
-uint8_t *JS_WriteObject(JSContext *ctx, size_t *psize, JSValue obj,
+uint8_t *JS_WriteObject(JSContext *ctx, size_t *psize, JSValueConst obj,
int flags)
{
return JS_WriteObject2(ctx, psize, obj, flags, NULL);
@@ -34721,9 +34639,9 @@ typedef struct BCReaderState {
uint32_t idx_to_atom_count;
JSAtom *idx_to_atom;
int error_state;
- BOOL allow_sab : 8;
- BOOL allow_bytecode : 8;
- BOOL allow_reference : 8;
+ bool allow_sab;
+ bool allow_bytecode;
+ bool allow_reference;
/* object references */
JSObject **objects;
int objects_count;
@@ -34732,17 +34650,17 @@ typedef struct BCReaderState {
uint8_t **sab_tab;
int sab_tab_len;
int sab_tab_size;
- /* used for DUMP_READ_OBJECT */
+ /* used for JS_DUMP_READ_OBJECT */
const uint8_t *ptr_last;
int level;
} BCReaderState;
-#ifdef DUMP_READ_OBJECT
-static void __attribute__((format(printf, 2, 3))) bc_read_trace(BCReaderState *s, const char *fmt, ...) {
+#ifdef ENABLE_DUMPS // JS_DUMP_READ_OBJECT
+static void JS_PRINTF_FORMAT_ATTR(2, 3) bc_read_trace(BCReaderState *s, JS_PRINTF_FORMAT const char *fmt, ...) {
va_list ap;
int i, n, n0;
- if (!check_dump_flag(s->ctx->rt, DUMP_READ_OBJECT))
+ if (!check_dump_flag(s->ctx->rt, JS_DUMP_READ_OBJECT))
return;
if (!s->ptr_last)
@@ -34925,7 +34843,7 @@ static JSString *JS_ReadString(BCReaderState *s)
{
uint32_t len;
size_t size;
- BOOL is_wide_char;
+ bool is_wide_char;
JSString *p;
if (bc_get_leb128(s, &len))
@@ -34943,19 +34861,19 @@ static JSString *JS_ReadString(BCReaderState *s)
js_free_string(s->ctx->rt, p);
return NULL;
}
- memcpy(p->u.str8, s->ptr, size);
+ memcpy(str8(p), s->ptr, size);
s->ptr += size;
if (is_wide_char) {
if (is_be()) {
uint32_t i;
for (i = 0; i < len; i++)
- p->u.str16[i] = bswap16(p->u.str16[i]);
+ str16(p)[i] = bswap16(str16(p)[i]);
}
} else {
- p->u.str8[size] = '\0'; /* add the trailing zero for 8 bit strings */
+ str8(p)[size] = '\0'; /* add the trailing zero for 8 bit strings */
}
-#ifdef DUMP_READ_OBJECT
- if (check_dump_flag(s->ctx->rt, DUMP_READ_OBJECT)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_READ_OBJECT
+ if (check_dump_flag(s->ctx->rt, JS_DUMP_READ_OBJECT)) {
bc_read_trace(s, "%s", ""); // hex dump and indentation
JS_DumpString(s->ctx->rt, p);
printf("\n");
@@ -35008,11 +34926,10 @@ static int JS_ReadFunctionBytecode(BCReaderState *s, JSFunctionBytecode *b,
put_u32(bc_buf + pos + 1, atom);
break;
default:
- assert(!is_ic_op(op)); // should not end up in serialized bytecode
break;
}
-#ifdef DUMP_READ_OBJECT
- if (check_dump_flag(s->ctx->rt, DUMP_READ_OBJECT)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_READ_OBJECT
+ if (check_dump_flag(s->ctx->rt, JS_DUMP_READ_OBJECT)) {
const uint8_t *save_ptr = s->ptr;
s->ptr = s->ptr_last + len;
s->level -= 4;
@@ -35207,8 +35124,8 @@ static JSValue JS_ReadFunctionTag(BCReaderState *s)
obj = JS_MKPTR(JS_TAG_FUNCTION_BYTECODE, b);
-#ifdef DUMP_READ_OBJECT
- if (check_dump_flag(s->ctx->rt, DUMP_READ_OBJECT)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_READ_OBJECT
+ if (check_dump_flag(s->ctx->rt, JS_DUMP_READ_OBJECT)) {
if (b->func_name) {
bc_read_trace(s, "name: ");
print_atom(s->ctx, b->func_name);
@@ -35241,8 +35158,8 @@ static JSValue JS_ReadFunctionTag(BCReaderState *s)
vd->is_const = bc_get_flags(v8, &idx, 1);
vd->is_lexical = bc_get_flags(v8, &idx, 1);
vd->is_captured = bc_get_flags(v8, &idx, 1);
-#ifdef DUMP_READ_OBJECT
- if (check_dump_flag(s->ctx->rt, DUMP_READ_OBJECT)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_READ_OBJECT
+ if (check_dump_flag(s->ctx->rt, JS_DUMP_READ_OBJECT)) {
bc_read_trace(s, "%3d %d%c%c%c %4d ",
i, vd->var_kind,
vd->is_const ? 'C' : '.',
@@ -35275,8 +35192,8 @@ static JSValue JS_ReadFunctionTag(BCReaderState *s)
cv->is_const = bc_get_flags(v8, &idx, 1);
cv->is_lexical = bc_get_flags(v8, &idx, 1);
cv->var_kind = bc_get_flags(v8, &idx, 4);
-#ifdef DUMP_READ_OBJECT
- if (check_dump_flag(s->ctx->rt, DUMP_READ_OBJECT)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_READ_OBJECT
+ if (check_dump_flag(s->ctx->rt, JS_DUMP_READ_OBJECT)) {
bc_read_trace(s, "%3d %d%c%c%c%c %3d ",
i, cv->var_kind,
cv->is_local ? 'L' : '.',
@@ -35319,8 +35236,8 @@ static JSValue JS_ReadFunctionTag(BCReaderState *s)
goto fail;
if (bc_get_leb128_int(s, &b->col_num))
goto fail;
-#ifdef DUMP_READ_OBJECT
- if (check_dump_flag(s->ctx->rt, DUMP_READ_OBJECT)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_READ_OBJECT
+ if (check_dump_flag(s->ctx->rt, JS_DUMP_READ_OBJECT)) {
bc_read_trace(s, "filename: ");
print_atom(s->ctx, b->filename);
printf(", line: %d, column: %d\n", b->line_num, b->col_num);
@@ -35372,8 +35289,8 @@ static JSValue JS_ReadModule(BCReaderState *s)
if (bc_get_atom(s, &module_name))
goto fail;
-#ifdef DUMP_READ_OBJECT
- if (check_dump_flag(s->ctx->rt, DUMP_READ_OBJECT)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_READ_OBJECT
+ if (check_dump_flag(s->ctx->rt, JS_DUMP_READ_OBJECT)) {
bc_read_trace(s, "name: ");
print_atom(s->ctx, module_name);
printf("\n");
@@ -35393,8 +35310,21 @@ static JSValue JS_ReadModule(BCReaderState *s)
goto fail;
for(i = 0; i < m->req_module_entries_count; i++) {
JSReqModuleEntry *rme = &m->req_module_entries[i];
+ JSModuleDef **pm = &rme->module;
if (bc_get_atom(s, &rme->module_name))
goto fail;
+ // Resolves a module either from the cache or by requesting
+ // it from the module loader. From cache is not ideal because
+ // the module may not be the one it was a time of serialization
+ // but directly petitioning the module loader is not correct
+ // either because then the same module can get loaded twice.
+ // JS_WriteModule() does not serialize modules transitively
+ // because that doesn't work for C modules and is also prone
+ // to loading the same JS module twice.
+ *pm = js_host_resolve_imported_module_atom(s->ctx, m->module_name,
+ rme->module_name);
+ if (!*pm)
+ goto fail;
}
}
@@ -35488,8 +35418,8 @@ static JSValue JS_ReadObjectTag(BCReaderState *s)
for(i = 0; i < prop_count; i++) {
if (bc_get_atom(s, &atom))
goto fail;
-#ifdef DUMP_READ_OBJECT
- if (check_dump_flag(s->ctx->rt, DUMP_READ_OBJECT)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_READ_OBJECT
+ if (check_dump_flag(s->ctx->rt, JS_DUMP_READ_OBJECT)) {
bc_read_trace(s, "propname: ");
print_atom(s->ctx, atom);
printf("\n");
@@ -35518,7 +35448,7 @@ static JSValue JS_ReadArray(BCReaderState *s, int tag)
uint32_t len, i;
JSValue val;
int ret, prop_flags;
- BOOL is_template;
+ bool is_template;
obj = JS_NewArray(ctx);
if (BC_add_object_ref(s, obj))
@@ -35561,7 +35491,7 @@ static JSValue JS_ReadTypedArray(BCReaderState *s)
JSContext *ctx = s->ctx;
JSValue obj = JS_UNDEFINED, array_buffer = JS_UNDEFINED;
uint8_t array_tag;
- JSValue args[3];
+ JSValueConst args[3];
uint32_t offset, len, idx;
if (bc_get_u8(s, &array_tag))
@@ -35630,7 +35560,7 @@ static JSValue JS_ReadArrayBuffer(BCReaderState *s)
JS_CLASS_ARRAY_BUFFER,
(uint8_t*)s->ptr,
js_array_buffer_free, NULL,
- /*alloc_flag*/TRUE);
+ /*alloc_flag*/true);
if (JS_IsException(obj))
goto fail;
if (BC_add_object_ref(s, obj))
@@ -35674,7 +35604,7 @@ static JSValue JS_ReadSharedArrayBuffer(BCReaderState *s)
byte_length, pmax_byte_length,
JS_CLASS_SHARED_ARRAY_BUFFER,
data_ptr,
- NULL, NULL, FALSE);
+ NULL, NULL, false);
if (JS_IsException(obj))
goto fail;
if (BC_add_object_ref(s, obj))
@@ -35708,7 +35638,7 @@ static JSValue JS_ReadRegExp(BCReaderState *s)
}
if (is_be())
- lre_byte_swap(bc->u.str8, bc->len, /*is_byte_swapped*/TRUE);
+ lre_byte_swap(str8(bc), bc->len, /*is_byte_swapped*/true);
return js_regexp_constructor_internal(ctx, JS_UNDEFINED,
JS_MKPTR(JS_TAG_STRING, pattern),
@@ -36018,18 +35948,18 @@ JSValue JS_ReadObject(JSContext *ctx, const uint8_t *buf, size_t buf_len,
/*******************************************************************/
/* runtime functions & objects */
-static JSValue js_string_constructor(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv);
-static JSValue js_boolean_constructor(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv);
-static JSValue js_number_constructor(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv);
+static JSValue js_string_constructor(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv);
+static JSValue js_boolean_constructor(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv);
+static JSValue js_number_constructor(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv);
-static int check_function(JSContext *ctx, JSValue obj)
+static int check_function(JSContext *ctx, JSValueConst obj)
{
if (likely(JS_IsFunction(ctx, obj)))
return 0;
- JS_ThrowTypeError(ctx, "not a function");
+ JS_ThrowTypeErrorNotAFunction(ctx);
return -1;
}
@@ -36053,7 +35983,7 @@ static JSAtom find_atom(JSContext *ctx, const char *name)
for(atom = JS_ATOM_Symbol_toPrimitive; atom < JS_ATOM_END; atom++) {
JSAtomStruct *p = ctx->rt->atom_array[atom];
JSString *str = p;
- if (str->len == len && !memcmp(str->u.str8, name, len))
+ if (str->len == len && !memcmp(str8(str), name, len))
return JS_DupAtom(ctx, atom);
}
abort();
@@ -36245,8 +36175,8 @@ int JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m,
/* Note: 'func_obj' is not necessarily a constructor */
static void JS_SetConstructor2(JSContext *ctx,
- JSValue func_obj,
- JSValue proto,
+ JSValueConst func_obj,
+ JSValueConst proto,
int proto_flags, int ctor_flags)
{
JS_DefinePropertyValue(ctx, func_obj, JS_ATOM_prototype,
@@ -36257,8 +36187,8 @@ static void JS_SetConstructor2(JSContext *ctx,
set_cycle_flag(ctx, proto);
}
-void JS_SetConstructor(JSContext *ctx, JSValue func_obj,
- JSValue proto)
+void JS_SetConstructor(JSContext *ctx, JSValueConst func_obj,
+ JSValueConst proto)
{
JS_SetConstructor2(ctx, func_obj, proto,
0, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
@@ -36267,18 +36197,18 @@ void JS_SetConstructor(JSContext *ctx, JSValue func_obj,
static void JS_NewGlobalCConstructor2(JSContext *ctx,
JSValue func_obj,
const char *name,
- JSValue proto)
+ JSValueConst proto)
{
JS_DefinePropertyValueStr(ctx, ctx->global_obj, name,
- js_dup(func_obj),
- JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
+ js_dup(func_obj),
+ JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
JS_SetConstructor(ctx, func_obj, proto);
JS_FreeValue(ctx, func_obj);
}
static JSValue JS_NewGlobalCConstructor(JSContext *ctx, const char *name,
- JSCFunction *func, int length,
- JSValue proto)
+ JSCFunction *func, int length,
+ JSValueConst proto)
{
JSValue func_obj;
func_obj = JS_NewCFunction2(ctx, func, name, length, JS_CFUNC_constructor_or_func, 0);
@@ -36287,8 +36217,8 @@ static JSValue JS_NewGlobalCConstructor(JSContext *ctx, const char *name,
}
static JSValue JS_NewGlobalCConstructorOnly(JSContext *ctx, const char *name,
- JSCFunction *func, int length,
- JSValue proto)
+ JSCFunction *func, int length,
+ JSValue proto)
{
JSValue func_obj;
func_obj = JS_NewCFunction2(ctx, func, name, length, JS_CFUNC_constructor, 0);
@@ -36296,14 +36226,14 @@ static JSValue JS_NewGlobalCConstructorOnly(JSContext *ctx, const char *name,
return func_obj;
}
-static JSValue js_global_eval(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_global_eval(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
return JS_EvalObject(ctx, ctx->global_obj, argv[0], JS_EVAL_TYPE_INDIRECT, -1);
}
-static JSValue js_global_isNaN(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_global_isNaN(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
double d;
@@ -36312,10 +36242,10 @@ static JSValue js_global_isNaN(JSContext *ctx, JSValue this_val,
return js_bool(isnan(d));
}
-static JSValue js_global_isFinite(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_global_isFinite(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
- BOOL res;
+ bool res;
double d;
if (unlikely(JS_ToFloat64(ctx, &d, argv[0])))
return JS_EXCEPTION;
@@ -36324,13 +36254,13 @@ static JSValue js_global_isFinite(JSContext *ctx, JSValue this_val,
}
static JSValue js_microtask_job(JSContext *ctx,
- int argc, JSValue *argv)
+ int argc, JSValueConst *argv)
{
return JS_Call(ctx, argv[0], ctx->global_obj, 0, NULL);
}
-static JSValue js_global_queueMicrotask(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_global_queueMicrotask(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
if (check_function(ctx, argv[0]))
return JS_EXCEPTION;
@@ -36341,7 +36271,7 @@ static JSValue js_global_queueMicrotask(JSContext *ctx, JSValue this_val,
/* Object class */
-static JSValue JS_ToObject(JSContext *ctx, JSValue val)
+JSValue JS_ToObject(JSContext *ctx, JSValueConst val)
{
int tag = JS_VALUE_GET_NORM_TAG(val);
JSValue obj;
@@ -36389,7 +36319,7 @@ static JSValue JS_ToObjectFree(JSContext *ctx, JSValue val)
}
static int js_obj_to_desc(JSContext *ctx, JSPropertyDescriptor *d,
- JSValue desc)
+ JSValueConst desc)
{
JSValue val, getter, setter;
int present;
@@ -36486,8 +36416,8 @@ static int js_obj_to_desc(JSContext *ctx, JSPropertyDescriptor *d,
return -1;
}
-static __exception int JS_DefinePropertyDesc(JSContext *ctx, JSValue obj,
- JSAtom prop, JSValue desc,
+static __exception int JS_DefinePropertyDesc(JSContext *ctx, JSValueConst obj,
+ JSAtom prop, JSValueConst desc,
int flags)
{
JSPropertyDescriptor d;
@@ -36503,8 +36433,8 @@ static __exception int JS_DefinePropertyDesc(JSContext *ctx, JSValue obj,
}
static __exception int JS_ObjectDefineProperties(JSContext *ctx,
- JSValue obj,
- JSValue properties)
+ JSValueConst obj,
+ JSValueConst properties)
{
JSValue props, desc;
JSObject *p;
@@ -36544,8 +36474,8 @@ exception:
return ret;
}
-static JSValue js_object_constructor(JSContext *ctx, JSValue new_target,
- int argc, JSValue *argv)
+static JSValue js_object_constructor(JSContext *ctx, JSValueConst new_target,
+ int argc, JSValueConst *argv)
{
JSValue ret;
if (!JS_IsUndefined(new_target) &&
@@ -36567,10 +36497,10 @@ static JSValue js_object_constructor(JSContext *ctx, JSValue new_target,
return ret;
}
-static JSValue js_object_create(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_object_create(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
- JSValue proto, props;
+ JSValueConst proto, props;
JSValue obj;
proto = argv[0];
@@ -36589,12 +36519,10 @@ static JSValue js_object_create(JSContext *ctx, JSValue this_val,
return obj;
}
-static JSValue js_object_getPrototypeOf(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue js_object_getPrototypeOf(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
- JSValue val;
-
- val = argv[0];
+ JSValueConst val = argv[0];
if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT) {
/* ES6 feature non compatible with ES5.1: primitive types are
accepted */
@@ -36605,21 +36533,20 @@ static JSValue js_object_getPrototypeOf(JSContext *ctx, JSValue this_val,
return JS_GetPrototype(ctx, val);
}
-static JSValue js_object_setPrototypeOf(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_object_setPrototypeOf(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
- JSValue obj;
- obj = argv[0];
- if (JS_SetPrototypeInternal(ctx, obj, argv[1], TRUE) < 0)
+ JSValueConst obj = argv[0];
+ if (JS_SetPrototypeInternal(ctx, obj, argv[1], true) < 0)
return JS_EXCEPTION;
return js_dup(obj);
}
/* magic = 1 if called as Reflect.defineProperty */
-static JSValue js_object_defineProperty(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue js_object_defineProperty(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
- JSValue obj, prop, desc;
+ JSValueConst obj, prop, desc;
int ret, flags;
JSAtom atom;
@@ -36646,24 +36573,22 @@ static JSValue js_object_defineProperty(JSContext *ctx, JSValue this_val,
}
}
-static JSValue js_object_defineProperties(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_object_defineProperties(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
// defineProperties(obj, properties)
- JSValue obj = argv[0];
-
+ JSValueConst obj = argv[0];
if (JS_ObjectDefineProperties(ctx, obj, argv[1]))
return JS_EXCEPTION;
- else
- return js_dup(obj);
+ return js_dup(obj);
}
/* magic = 1 if called as __defineSetter__ */
-static JSValue js_object___defineGetter__(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue js_object___defineGetter__(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
JSValue obj;
- JSValue prop, value, get, set;
+ JSValueConst prop, value, get, set;
int ret, flags;
JSAtom atom;
@@ -36705,10 +36630,10 @@ static JSValue js_object___defineGetter__(JSContext *ctx, JSValue this_val,
}
}
-static JSValue js_object_getOwnPropertyDescriptor(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue js_object_getOwnPropertyDescriptor(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
- JSValue prop;
+ JSValueConst prop;
JSAtom atom;
JSValue ret, obj;
JSPropertyDescriptor desc;
@@ -36772,8 +36697,8 @@ exception:
return JS_EXCEPTION;
}
-static JSValue js_object_getOwnPropertyDescriptors(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_object_getOwnPropertyDescriptors(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
//getOwnPropertyDescriptors(obj)
JSValue obj, r;
@@ -36795,7 +36720,7 @@ static JSValue js_object_getOwnPropertyDescriptors(JSContext *ctx, JSValue this_
goto exception;
for(i = 0; i < len; i++) {
JSValue atomValue, desc;
- JSValue args[2];
+ JSValueConst args[2];
atomValue = JS_AtomToValue(ctx, props[i].atom);
if (JS_IsException(atomValue))
@@ -36823,7 +36748,7 @@ exception:
return JS_EXCEPTION;
}
-static JSValue JS_GetOwnPropertyNames2(JSContext *ctx, JSValue obj1,
+static JSValue JS_GetOwnPropertyNames2(JSContext *ctx, JSValueConst obj1,
int flags, int kind)
{
JSValue obj, r, val, key, value;
@@ -36902,27 +36827,27 @@ done:
return r;
}
-static JSValue js_object_getOwnPropertyNames(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_object_getOwnPropertyNames(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
return JS_GetOwnPropertyNames2(ctx, argv[0],
JS_GPN_STRING_MASK, JS_ITERATOR_KIND_KEY);
}
-static JSValue js_object_getOwnPropertySymbols(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_object_getOwnPropertySymbols(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
return JS_GetOwnPropertyNames2(ctx, argv[0],
JS_GPN_SYMBOL_MASK, JS_ITERATOR_KIND_KEY);
}
-static JSValue js_object_groupBy(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_object_groupBy(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
- JSValue cb, res, iter, next, groups, k, v, prop;
- JSValue args[2];
+ JSValue res, iter, next, groups, k, v, prop;
+ JSValueConst cb, args[2];
int64_t idx;
- BOOL done;
+ int done;
// "is function?" check must be observed before argv[0] is accessed
cb = argv[1];
@@ -36932,7 +36857,7 @@ static JSValue js_object_groupBy(JSContext *ctx, JSValue this_val,
// TODO(bnoordhuis) add fast path for arrays but as groupBy() is
// defined in terms of iterators, the fast path must check that
// this[Symbol.iterator] is the built-in array iterator
- iter = JS_GetIterator(ctx, argv[0], /*is_async*/FALSE);
+ iter = JS_GetIterator(ctx, argv[0], /*is_async*/false);
if (JS_IsException(iter))
return JS_EXCEPTION;
@@ -36979,7 +36904,7 @@ static JSValue js_object_groupBy(JSContext *ctx, JSValue this_val,
}
}
- res = js_array_push(ctx, prop, 1, &v, /*unshift*/0);
+ res = js_array_push(ctx, prop, 1, vc(&v), /*unshift*/0);
if (JS_IsException(res))
goto exception;
// res is an int64
@@ -37006,17 +36931,17 @@ exception:
return JS_EXCEPTION;
}
-static JSValue js_object_keys(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int kind)
+static JSValue js_object_keys(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int kind)
{
return JS_GetOwnPropertyNames2(ctx, argv[0],
JS_GPN_ENUM_ONLY | JS_GPN_STRING_MASK, kind);
}
-static JSValue js_object_isExtensible(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int reflect)
+static JSValue js_object_isExtensible(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int reflect)
{
- JSValue obj;
+ JSValueConst obj;
int ret;
obj = argv[0];
@@ -37033,10 +36958,10 @@ static JSValue js_object_isExtensible(JSContext *ctx, JSValue this_val,
return js_bool(ret);
}
-static JSValue js_object_preventExtensions(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int reflect)
+static JSValue js_object_preventExtensions(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int reflect)
{
- JSValue obj;
+ JSValueConst obj;
int ret;
obj = argv[0];
@@ -37058,13 +36983,13 @@ static JSValue js_object_preventExtensions(JSContext *ctx, JSValue this_val,
}
}
-static JSValue js_object_hasOwnProperty(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_object_hasOwnProperty(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue obj;
JSAtom atom;
JSObject *p;
- BOOL ret;
+ int ret;
atom = JS_ValueToAtom(ctx, argv[0]); /* must be done first */
if (unlikely(atom == JS_ATOM_NULL))
@@ -37084,13 +37009,13 @@ static JSValue js_object_hasOwnProperty(JSContext *ctx, JSValue this_val,
return js_bool(ret);
}
-static JSValue js_object_hasOwn(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_object_hasOwn(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue obj;
JSAtom atom;
JSObject *p;
- BOOL ret;
+ int ret;
obj = JS_ToObject(ctx, argv[0]);
if (JS_IsException(obj))
@@ -37110,14 +37035,14 @@ static JSValue js_object_hasOwn(JSContext *ctx, JSValue this_val,
return js_bool(ret);
}
-static JSValue js_object_valueOf(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_object_valueOf(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
return JS_ToObject(ctx, this_val);
}
-static JSValue js_object_toString(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_object_toString(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue obj, tag;
int is_array;
@@ -37132,7 +37057,7 @@ static JSValue js_object_toString(JSContext *ctx, JSValue this_val,
obj = JS_ToObject(ctx, this_val);
if (JS_IsException(obj))
return obj;
- is_array = JS_IsArray(ctx, obj);
+ is_array = js_is_array(ctx, obj);
if (is_array < 0) {
JS_FreeValue(ctx, obj);
return JS_EXCEPTION;
@@ -37171,14 +37096,19 @@ static JSValue js_object_toString(JSContext *ctx, JSValue this_val,
return JS_ConcatString3(ctx, "[object ", tag, "]");
}
-static JSValue js_object_toLocaleString(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+JSValue JS_ToObjectString(JSContext *ctx, JSValueConst val)
+{
+ return js_object_toString(ctx, val, 0, NULL);
+}
+
+static JSValue js_object_toLocaleString(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
return JS_Invoke(ctx, this_val, JS_ATOM_toString, 0, NULL);
}
-static JSValue js_object_assign(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_object_assign(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
// Object.assign(obj, source1)
JSValue obj, s;
@@ -37193,7 +37123,7 @@ static JSValue js_object_assign(JSContext *ctx, JSValue this_val,
s = JS_ToObject(ctx, argv[i]);
if (JS_IsException(s))
goto exception;
- if (JS_CopyDataProperties(ctx, obj, s, JS_UNDEFINED, TRUE))
+ if (JS_CopyDataProperties(ctx, obj, s, JS_UNDEFINED, true))
goto exception;
JS_FreeValue(ctx, s);
}
@@ -37205,11 +37135,13 @@ exception:
return JS_EXCEPTION;
}
-static JSValue js_object_seal(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int freeze_flag)
+static JSValue js_object_seal(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int freeze_flag)
{
- JSValue obj = argv[0];
+ JSValueConst obj = argv[0];
JSObject *p;
+ JSTypedArray *ta;
+ JSArrayBuffer *abuf;
JSPropertyEnum *props;
uint32_t len, i;
int flags, desc_flags, res;
@@ -37230,6 +37162,13 @@ static JSValue js_object_seal(JSContext *ctx, JSValue this_val,
return JS_ThrowTypeError(ctx, "proxy preventExtensions handler returned false");
}
+ if (freeze_flag && is_typed_array(p->class_id)) {
+ ta = p->u.typed_array;
+ abuf = ta->buffer->u.array_buffer;
+ if (array_buffer_is_resizable(abuf) || typed_array_is_oob(p))
+ return JS_ThrowTypeError(ctx, "cannot freeze resizable typed array");
+ }
+
flags = JS_GPN_STRING_MASK | JS_GPN_SYMBOL_MASK;
if (JS_GetOwnPropertyNamesInternal(ctx, &props, &len, p, flags))
return JS_EXCEPTION;
@@ -37261,10 +37200,10 @@ static JSValue js_object_seal(JSContext *ctx, JSValue this_val,
return JS_EXCEPTION;
}
-static JSValue js_object_isSealed(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int is_frozen)
+static JSValue js_object_isSealed(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int is_frozen)
{
- JSValue obj = argv[0];
+ JSValueConst obj = argv[0];
JSObject *p;
JSPropertyEnum *props;
uint32_t len, i;
@@ -37289,7 +37228,7 @@ static JSValue js_object_isSealed(JSContext *ctx, JSValue this_val,
js_free_desc(ctx, &desc);
if ((desc.flags & JS_PROP_CONFIGURABLE)
|| (is_frozen && (desc.flags & JS_PROP_WRITABLE))) {
- res = FALSE;
+ res = false;
goto done;
}
}
@@ -37307,12 +37246,28 @@ exception:
return JS_EXCEPTION;
}
-static JSValue js_object_fromEntries(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+int JS_SealObject(JSContext *ctx, JSValueConst obj)
+{
+ JSValue value = js_object_seal(ctx, JS_UNDEFINED, 1, &obj, 0);
+ int result = JS_IsException(value) ? -1 : true;
+ JS_FreeValue(ctx, value);
+ return result;
+}
+
+int JS_FreezeObject(JSContext *ctx, JSValueConst obj)
+{
+ JSValue value = js_object_seal(ctx, JS_UNDEFINED, 1, &obj, 1);
+ int result = JS_IsException(value) ? -1 : true;
+ JS_FreeValue(ctx, value);
+ return result;
+}
+
+static JSValue js_object_fromEntries(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue obj, iter, next_method = JS_UNDEFINED;
- JSValue iterable;
- BOOL done;
+ JSValueConst iterable;
+ int done;
/* RequireObjectCoercible() not necessary because it is tested in
JS_GetIterator() by JS_GetProperty() */
@@ -37322,7 +37277,7 @@ static JSValue js_object_fromEntries(JSContext *ctx, JSValue this_val,
if (JS_IsException(obj))
return obj;
- iter = JS_GetIterator(ctx, iterable, FALSE);
+ iter = JS_GetIterator(ctx, iterable, false);
if (JS_IsException(iter))
goto fail;
next_method = JS_GetProperty(ctx, iter, JS_ATOM_next);
@@ -37367,7 +37322,7 @@ static JSValue js_object_fromEntries(JSContext *ctx, JSValue this_val,
fail:
if (JS_IsObject(iter)) {
/* close the iterator object, preserving pending exception */
- JS_IteratorClose(ctx, iter, TRUE);
+ JS_IteratorClose(ctx, iter, true);
}
JS_FreeValue(ctx, next_method);
JS_FreeValue(ctx, iter);
@@ -37375,14 +37330,14 @@ static JSValue js_object_fromEntries(JSContext *ctx, JSValue this_val,
return JS_EXCEPTION;
}
-static JSValue js_object_is(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_object_is(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
return js_bool(js_same_value(ctx, argv[0], argv[1]));
}
-static JSValue JS_SpeciesConstructor(JSContext *ctx, JSValue obj,
- JSValue defaultConstructor)
+static JSValue JS_SpeciesConstructor(JSContext *ctx, JSValueConst obj,
+ JSValueConst defaultConstructor)
{
JSValue ctor, species;
@@ -37410,7 +37365,7 @@ static JSValue JS_SpeciesConstructor(JSContext *ctx, JSValue obj,
return species;
}
-static JSValue js_object_get___proto__(JSContext *ctx, JSValue this_val)
+static JSValue js_object_get___proto__(JSContext *ctx, JSValueConst this_val)
{
JSValue val, ret;
@@ -37422,24 +37377,24 @@ static JSValue js_object_get___proto__(JSContext *ctx, JSValue this_val)
return ret;
}
-static JSValue js_object_set___proto__(JSContext *ctx, JSValue this_val,
- JSValue proto)
+static JSValue js_object_set___proto__(JSContext *ctx, JSValueConst this_val,
+ JSValueConst proto)
{
if (JS_IsUndefined(this_val) || JS_IsNull(this_val))
return JS_ThrowTypeErrorNotAnObject(ctx);
if (!JS_IsObject(proto) && !JS_IsNull(proto))
return JS_UNDEFINED;
- if (JS_SetPrototypeInternal(ctx, this_val, proto, TRUE) < 0)
+ if (JS_SetPrototypeInternal(ctx, this_val, proto, true) < 0)
return JS_EXCEPTION;
else
return JS_UNDEFINED;
}
-static JSValue js_object_isPrototypeOf(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_object_isPrototypeOf(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue obj, v1;
- JSValue v;
+ JSValueConst v;
int res;
v = argv[0];
@@ -37454,11 +37409,11 @@ static JSValue js_object_isPrototypeOf(JSContext *ctx, JSValue this_val,
if (JS_IsException(v1))
goto exception;
if (JS_IsNull(v1)) {
- res = FALSE;
+ res = false;
break;
}
if (JS_VALUE_GET_OBJ(obj) == JS_VALUE_GET_OBJ(v1)) {
- res = TRUE;
+ res = true;
break;
}
/* avoid infinite loop (possible with proxies) */
@@ -37475,8 +37430,8 @@ exception:
return JS_EXCEPTION;
}
-static JSValue js_object_propertyIsEnumerable(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_object_propertyIsEnumerable(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue obj, res = JS_EXCEPTION;
JSAtom prop = JS_ATOM_NULL;
@@ -37506,8 +37461,8 @@ exception:
return res;
}
-static JSValue js_object___lookupGetter__(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int setter)
+static JSValue js_object___lookupGetter__(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int setter)
{
JSValue obj, res = JS_EXCEPTION;
JSAtom prop = JS_ATOM_NULL;
@@ -37593,15 +37548,15 @@ static const JSCFunctionListEntry js_object_proto_funcs[] = {
/* Function class */
-static JSValue js_function_proto(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_function_proto(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
return JS_UNDEFINED;
}
/* XXX: add a specific eval mode so that Function("}), ({") is rejected */
-static JSValue js_function_constructor(JSContext *ctx, JSValue new_target,
- int argc, JSValue *argv, int magic)
+static JSValue js_function_constructor(JSContext *ctx, JSValueConst new_target,
+ int argc, JSValueConst *argv, int magic)
{
JSFunctionKindEnum func_kind = magic;
int i, n, ret;
@@ -37656,7 +37611,7 @@ static JSValue js_function_constructor(JSContext *ctx, JSValue new_target,
goto fail1;
proto = js_dup(realm->class_proto[func_kind_to_class_id[func_kind]]);
}
- ret = JS_SetPrototypeInternal(ctx, obj, proto, TRUE);
+ ret = JS_SetPrototypeInternal(ctx, obj, proto, true);
JS_FreeValue(ctx, proto);
if (ret < 0)
goto fail1;
@@ -37671,7 +37626,7 @@ static JSValue js_function_constructor(JSContext *ctx, JSValue new_target,
}
static __exception int js_get_length32(JSContext *ctx, uint32_t *pres,
- JSValue obj)
+ JSValueConst obj)
{
JSValue len_val;
len_val = JS_GetProperty(ctx, obj, JS_ATOM_length);
@@ -37683,7 +37638,7 @@ static __exception int js_get_length32(JSContext *ctx, uint32_t *pres,
}
static __exception int js_get_length64(JSContext *ctx, int64_t *pres,
- JSValue obj)
+ JSValueConst obj)
{
JSValue len_val;
len_val = JS_GetProperty(ctx, obj, JS_ATOM_length);
@@ -37694,7 +37649,8 @@ static __exception int js_get_length64(JSContext *ctx, int64_t *pres,
return JS_ToLengthFree(ctx, pres, len_val);
}
-static __exception int js_set_length64(JSContext *ctx, JSValue obj, int64_t len)
+static __exception int js_set_length64(JSContext *ctx, JSValueConst obj,
+ int64_t len)
{
return JS_SetProperty(ctx, obj, JS_ATOM_length, js_int64(len));
}
@@ -37710,7 +37666,7 @@ static void free_arg_list(JSContext *ctx, JSValue *tab, uint32_t len)
/* XXX: should use ValueArray */
static JSValue *build_arg_list(JSContext *ctx, uint32_t *plen,
- JSValue array_arg)
+ JSValueConst array_arg)
{
uint32_t len, i;
JSValue *tab, ret;
@@ -37755,10 +37711,10 @@ static JSValue *build_arg_list(JSContext *ctx, uint32_t *plen,
/* magic value: 0 = normal apply, 1 = apply for constructor, 2 =
Reflect.apply */
-static JSValue js_function_apply(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue js_function_apply(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
- JSValue this_arg, array_arg;
+ JSValueConst this_arg, array_arg;
uint32_t len;
JSValue *tab, ret;
@@ -37774,16 +37730,16 @@ static JSValue js_function_apply(JSContext *ctx, JSValue this_val,
if (!tab)
return JS_EXCEPTION;
if (magic & 1) {
- ret = JS_CallConstructor2(ctx, this_val, this_arg, len, tab);
+ ret = JS_CallConstructor2(ctx, this_val, this_arg, len, vc(tab));
} else {
- ret = JS_Call(ctx, this_val, this_arg, len, tab);
+ ret = JS_Call(ctx, this_val, this_arg, len, vc(tab));
}
free_arg_list(ctx, tab, len);
return ret;
}
-static JSValue js_function_call(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_function_call(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
if (argc <= 0) {
return JS_Call(ctx, this_val, JS_UNDEFINED, 0, NULL);
@@ -37792,8 +37748,8 @@ static JSValue js_function_call(JSContext *ctx, JSValue this_val,
}
}
-static JSValue js_function_bind(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_function_bind(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSBoundFunction *bf;
JSValue func_obj, name1, len_val;
@@ -37877,8 +37833,8 @@ static JSValue js_function_bind(JSContext *ctx, JSValue this_val,
return JS_EXCEPTION;
}
-static JSValue js_function_toString(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_function_toString(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSObject *p;
JSFunctionKindEnum func_kind = JS_FUNC_NORMAL;
@@ -37920,8 +37876,8 @@ static JSValue js_function_toString(JSContext *ctx, JSValue this_val,
}
}
-static JSValue js_function_hasInstance(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_function_hasInstance(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
int ret;
ret = JS_OrdinaryIsInstanceOf(ctx, argv[0], this_val);
@@ -37946,14 +37902,14 @@ static const JSCFunctionListEntry js_function_proto_funcs[] = {
/* Error class */
-static JSValue iterator_to_array(JSContext *ctx, JSValue items)
+static JSValue iterator_to_array(JSContext *ctx, JSValueConst items)
{
JSValue iter, next_method = JS_UNDEFINED;
JSValue v, r = JS_UNDEFINED;
int64_t k;
- BOOL done;
+ int done;
- iter = JS_GetIterator(ctx, items, FALSE);
+ iter = JS_GetIterator(ctx, items, false);
if (JS_IsException(iter))
goto exception;
next_method = JS_GetProperty(ctx, iter, JS_ATOM_next);
@@ -37977,20 +37933,19 @@ static JSValue iterator_to_array(JSContext *ctx, JSValue items)
JS_FreeValue(ctx, iter);
return r;
exception_close:
- JS_IteratorClose(ctx, iter, TRUE);
+ JS_IteratorClose(ctx, iter, true);
exception:
JS_FreeValue(ctx, r);
r = JS_EXCEPTION;
goto done;
}
-static JSValue js_error_constructor(JSContext *ctx, JSValue new_target,
- int argc, JSValue *argv, int magic)
+static JSValue js_error_constructor(JSContext *ctx, JSValueConst new_target,
+ int argc, JSValueConst *argv, int magic)
{
JSValue obj, msg, proto, cause;
- JSValue message;
- int opts;
- BOOL present;
+ JSValueConst message;
+ int present, opts;
if (JS_IsUndefined(new_target))
new_target = JS_GetActiveFunction(ctx);
@@ -38061,8 +38016,8 @@ static JSValue js_error_constructor(JSContext *ctx, JSValue new_target,
return JS_EXCEPTION;
}
-static JSValue js_error_toString(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_error_toString(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue name, msg;
@@ -38096,13 +38051,13 @@ static const JSCFunctionListEntry js_error_proto_funcs[] = {
JS_PROP_STRING_DEF("message", "", JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE ),
};
-static JSValue js_error_isError(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_error_isError(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
return js_bool(JS_IsError(ctx, argv[0]));
}
-static JSValue js_error_get_stackTraceLimit(JSContext *ctx, JSValue this_val)
+static JSValue js_error_get_stackTraceLimit(JSContext *ctx, JSValueConst this_val)
{
JSValue val;
@@ -38110,21 +38065,18 @@ static JSValue js_error_get_stackTraceLimit(JSContext *ctx, JSValue this_val)
if (JS_IsException(val))
return val;
JS_FreeValue(ctx, val);
- return js_int32(ctx->error_stack_trace_limit);
+ return js_dup(ctx->error_stack_trace_limit);
}
-static JSValue js_error_set_stackTraceLimit(JSContext *ctx, JSValue this_val, JSValue value)
+static JSValue js_error_set_stackTraceLimit(JSContext *ctx, JSValueConst this_val, JSValueConst value)
{
if (JS_IsUndefined(this_val) || JS_IsNull(this_val))
return JS_ThrowTypeErrorNotAnObject(ctx);
- int limit;
- if (JS_ToInt32(ctx, &limit, value) < 0)
- return JS_EXCEPTION;
- ctx->error_stack_trace_limit = limit;
+ ctx->error_stack_trace_limit = js_dup(value);
return JS_UNDEFINED;
}
-static JSValue js_error_get_prepareStackTrace(JSContext *ctx, JSValue this_val)
+static JSValue js_error_get_prepareStackTrace(JSContext *ctx, JSValueConst this_val)
{
JSValue val;
@@ -38135,7 +38087,7 @@ static JSValue js_error_get_prepareStackTrace(JSContext *ctx, JSValue this_val)
return js_dup(ctx->error_prepare_stack);
}
-static JSValue js_error_set_prepareStackTrace(JSContext *ctx, JSValue this_val, JSValue value)
+static JSValue js_error_set_prepareStackTrace(JSContext *ctx, JSValueConst this_val, JSValueConst value)
{
if (JS_IsUndefined(this_val) || JS_IsNull(this_val))
return JS_ThrowTypeErrorNotAnObject(ctx);
@@ -38144,10 +38096,10 @@ static JSValue js_error_set_prepareStackTrace(JSContext *ctx, JSValue this_val,
return JS_UNDEFINED;
}
-static JSValue js_error_capture_stack_trace(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_error_capture_stack_trace(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
- JSValue v = argv[0];
+ JSValueConst v = argv[0];
if (JS_VALUE_GET_TAG(v) != JS_TAG_OBJECT)
return JS_ThrowTypeErrorNotAnObject(ctx);
build_backtrace(ctx, v, argv[1], NULL, 0, 0, JS_BACKTRACE_FLAG_SKIP_FIRST_LEVEL|JS_BACKTRACE_FLAG_FILTER_FUNC);
@@ -38165,7 +38117,7 @@ static const JSCFunctionListEntry js_error_funcs[] = {
/* used by C code. */
static JSValue js_aggregate_error_constructor(JSContext *ctx,
- JSValue errors)
+ JSValueConst errors)
{
JSValue obj;
@@ -38251,8 +38203,8 @@ static int JS_CopySubArray(JSContext *ctx,
return -1;
}
-static JSValue js_array_constructor(JSContext *ctx, JSValue new_target,
- int argc, JSValue *argv)
+static JSValue js_array_constructor(JSContext *ctx, JSValueConst new_target,
+ int argc, JSValueConst *argv)
{
JSValue obj;
int i;
@@ -38262,7 +38214,7 @@ static JSValue js_array_constructor(JSContext *ctx, JSValue new_target,
return obj;
if (argc == 1 && JS_IsNumber(argv[0])) {
uint32_t len;
- if (JS_ToArrayLengthFree(ctx, &len, js_dup(argv[0]), TRUE))
+ if (JS_ToArrayLengthFree(ctx, &len, js_dup(argv[0]), true))
goto fail;
if (JS_SetProperty(ctx, obj, JS_ATOM_length, js_uint32(len)) < 0)
goto fail;
@@ -38278,18 +38230,18 @@ fail:
return JS_EXCEPTION;
}
-static JSValue js_array_from(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_array_from(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
// from(items, mapfn = void 0, this_arg = void 0)
- JSValue items = argv[0], mapfn, this_arg;
- JSValue args[2];
+ JSValueConst items = argv[0], mapfn, this_arg;
+ JSValueConst args[2];
JSValue stack[2];
JSValue iter, r, v, v2, arrayLike;
int64_t k, len;
int done, mapping;
- mapping = FALSE;
+ mapping = false;
mapfn = JS_UNDEFINED;
this_arg = JS_UNDEFINED;
r = JS_UNDEFINED;
@@ -38319,7 +38271,7 @@ static JSValue js_array_from(JSContext *ctx, JSValue this_val,
if (JS_IsException(r))
goto exception;
stack[0] = js_dup(items);
- if (js_for_of_start(ctx, &stack[1], FALSE))
+ if (js_for_of_start(ctx, &stack[1], false))
goto exception;
for (k = 0;; k++) {
v = JS_IteratorNext(ctx, stack[0], stack[1], 0, NULL, &done);
@@ -38380,7 +38332,7 @@ static JSValue js_array_from(JSContext *ctx, JSValue this_val,
exception_close:
if (!JS_IsUndefined(stack[0]))
- JS_IteratorClose(ctx, stack[0], TRUE);
+ JS_IteratorClose(ctx, stack[0], true);
exception:
JS_FreeValue(ctx, r);
r = JS_EXCEPTION;
@@ -38391,15 +38343,15 @@ static JSValue js_array_from(JSContext *ctx, JSValue this_val,
return r;
}
-static JSValue js_array_of(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_array_of(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
- JSValue obj, args[1];
+ JSValue n, obj;
int i;
if (JS_IsConstructor(ctx, this_val)) {
- args[0] = js_int32(argc);
- obj = JS_CallConstructor(ctx, this_val, 1, args);
+ n = js_int32(argc);
+ obj = JS_CallConstructor(ctx, this_val, 1, vc(&n));
} else {
obj = JS_NewArray(ctx);
}
@@ -38419,31 +38371,30 @@ static JSValue js_array_of(JSContext *ctx, JSValue this_val,
return obj;
}
-static JSValue js_array_isArray(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_array_isArray(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
int ret;
- ret = JS_IsArray(ctx, argv[0]);
+ ret = js_is_array(ctx, argv[0]);
if (ret < 0)
return JS_EXCEPTION;
else
return js_bool(ret);
}
-static JSValue js_get_this(JSContext *ctx,
- JSValue this_val)
+static JSValue js_get_this(JSContext *ctx, JSValueConst this_val)
{
return js_dup(this_val);
}
-static JSValue JS_ArraySpeciesCreate(JSContext *ctx, JSValue obj,
- JSValue len_val)
+static JSValue JS_ArraySpeciesCreate(JSContext *ctx, JSValueConst obj,
+ JSValueConst len_val)
{
JSValue ctor, ret, species;
int res;
JSContext *realm;
- res = JS_IsArray(ctx, obj);
+ res = js_is_array(ctx, obj);
if (res < 0)
return JS_EXCEPTION;
if (!res)
@@ -38489,22 +38440,22 @@ static const JSCFunctionListEntry js_array_funcs[] = {
JS_CGETSET_DEF("[Symbol.species]", js_get_this, NULL ),
};
-static int JS_isConcatSpreadable(JSContext *ctx, JSValue obj)
+static int JS_isConcatSpreadable(JSContext *ctx, JSValueConst obj)
{
JSValue val;
if (!JS_IsObject(obj))
- return FALSE;
+ return false;
val = JS_GetProperty(ctx, obj, JS_ATOM_Symbol_isConcatSpreadable);
if (JS_IsException(val))
return -1;
if (!JS_IsUndefined(val))
return JS_ToBoolFree(ctx, val);
- return JS_IsArray(ctx, obj);
+ return js_is_array(ctx, obj);
}
-static JSValue js_array_at(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_array_at(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue obj, ret;
int64_t len, idx;
@@ -38531,8 +38482,8 @@ static JSValue js_array_at(JSContext *ctx, JSValue this_val,
return ret;
}
-static JSValue js_array_with(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_array_with(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue arr, obj, ret, *arrp, *pval;
JSObject *p;
@@ -38605,11 +38556,11 @@ exception:
return ret;
}
-static JSValue js_array_concat(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_array_concat(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue obj, arr, val;
- JSValue e;
+ JSValueConst e;
int64_t len, k, n;
int i, res;
@@ -38678,14 +38629,13 @@ exception:
#define special_filter 4
#define special_TA 8
-static JSObject *get_typed_array(JSContext *ctx, JSValue this_val)
+static JSObject *get_typed_array(JSContext *ctx, JSValueConst this_val)
{
JSObject *p;
if (JS_VALUE_GET_TAG(this_val) != JS_TAG_OBJECT)
goto fail;
p = JS_VALUE_GET_OBJ(this_val);
- if (!(p->class_id >= JS_CLASS_UINT8C_ARRAY &&
- p->class_id <= JS_CLASS_FLOAT64_ARRAY)) {
+ if (!is_typed_array(p->class_id)) {
fail:
JS_ThrowTypeError(ctx, "not a TypedArray");
return NULL;
@@ -38701,7 +38651,7 @@ static JSObject *get_typed_array(JSContext *ctx, JSValue this_val)
// Exclusively reading or writing elements with JS_GetProperty,
// JS_GetPropertyInt64, JS_SetProperty, etc. is safe because they
// perform bounds checks, as does js_get_fast_array_element.
-static int js_typed_array_get_length_unsafe(JSContext *ctx, JSValue obj)
+static int js_typed_array_get_length_unsafe(JSContext *ctx, JSValueConst obj)
{
JSObject *p;
p = get_typed_array(ctx, obj);
@@ -38715,15 +38665,15 @@ static int js_typed_array_get_length_unsafe(JSContext *ctx, JSValue obj)
}
static JSValue js_typed_array___speciesCreate(JSContext *ctx,
- JSValue this_val,
- int argc, JSValue *argv);
+ JSValueConst this_val,
+ int argc, JSValueConst *argv);
-static JSValue js_array_every(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int special)
+static JSValue js_array_every(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int special)
{
JSValue obj, val, index_val, res, ret;
- JSValue args[3];
- JSValue func, this_arg;
+ JSValueConst args[3];
+ JSValueConst func, this_arg;
int64_t len, k, n;
int present;
@@ -38787,7 +38737,7 @@ static JSValue js_array_every(JSContext *ctx, JSValue this_val,
val = JS_GetPropertyInt64(ctx, obj, k);
if (JS_IsException(val))
goto exception;
- present = TRUE;
+ present = true;
} else {
present = JS_TryGetPropertyInt64(ctx, obj, k, &val);
if (present < 0)
@@ -38871,12 +38821,12 @@ exception:
#define special_reduce 0
#define special_reduceRight 1
-static JSValue js_array_reduce(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int special)
+static JSValue js_array_reduce(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int special)
{
JSValue obj, val, index_val, acc, acc1;
- JSValue args[4];
- JSValue func;
+ JSValueConst args[4];
+ JSValueConst func;
int64_t len, k, k1;
int present;
@@ -38928,7 +38878,7 @@ static JSValue js_array_reduce(JSContext *ctx, JSValue this_val,
val = JS_GetPropertyInt64(ctx, obj, k1);
if (JS_IsException(val))
goto exception;
- present = TRUE;
+ present = true;
} else {
present = JS_TryGetPropertyInt64(ctx, obj, k1, &val);
if (present < 0)
@@ -38960,8 +38910,8 @@ exception:
return JS_EXCEPTION;
}
-static JSValue js_array_fill(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_array_fill(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue obj;
int64_t len, start, end;
@@ -38995,8 +38945,8 @@ static JSValue js_array_fill(JSContext *ctx, JSValue this_val,
return JS_EXCEPTION;
}
-static JSValue js_array_includes(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_array_includes(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue obj, val;
int64_t len, n;
@@ -39008,7 +38958,7 @@ static JSValue js_array_includes(JSContext *ctx, JSValue this_val,
if (js_get_length64(ctx, &len, obj))
goto exception;
- res = TRUE;
+ res = true;
if (len > 0) {
n = 0;
if (argc > 1) {
@@ -39033,7 +38983,7 @@ static JSValue js_array_includes(JSContext *ctx, JSValue this_val,
}
}
}
- res = FALSE;
+ res = false;
done:
JS_FreeValue(ctx, obj);
return js_bool(res);
@@ -39043,8 +38993,8 @@ static JSValue js_array_includes(JSContext *ctx, JSValue this_val,
return JS_EXCEPTION;
}
-static JSValue js_array_indexOf(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_array_indexOf(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue obj, val;
int64_t len, n;
@@ -39090,8 +39040,8 @@ static JSValue js_array_indexOf(JSContext *ctx, JSValue this_val,
return JS_EXCEPTION;
}
-static JSValue js_array_lastIndexOf(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_array_lastIndexOf(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue obj, val;
int64_t len, n;
@@ -39144,11 +39094,11 @@ enum {
ArrayFindLastIndex,
};
-static JSValue js_array_find(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int mode)
+static JSValue js_array_find(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int mode)
{
- JSValue func, this_arg;
- JSValue args[3];
+ JSValueConst func, this_arg;
+ JSValueConst args[3];
JSValue obj, val, index_val, res;
int64_t len, k, end;
int dir;
@@ -39215,8 +39165,8 @@ exception:
return JS_EXCEPTION;
}
-static JSValue js_array_toString(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_array_toString(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue obj, method, ret;
@@ -39238,8 +39188,8 @@ static JSValue js_array_toString(JSContext *ctx, JSValue this_val,
return ret;
}
-static JSValue js_array_join(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int toLocaleString)
+static JSValue js_array_join(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int toLocaleString)
{
JSValue obj, sep = JS_UNDEFINED, el;
StringBuffer b_s, *b = &b_s;
@@ -39258,7 +39208,7 @@ static JSValue js_array_join(JSContext *ctx, JSValue this_val,
goto exception;
p = JS_VALUE_GET_STRING(sep);
if (p->len == 1 && !p->is_wide_char)
- c = p->u.str8[0];
+ c = str8(p)[0];
else
c = -1;
}
@@ -39295,8 +39245,8 @@ exception:
return JS_EXCEPTION;
}
-static JSValue js_array_pop(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int shift)
+static JSValue js_array_pop(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int shift)
{
JSValue obj, res = JS_UNDEFINED;
int64_t len, newLen;
@@ -39348,8 +39298,8 @@ static JSValue js_array_pop(JSContext *ctx, JSValue this_val,
return JS_EXCEPTION;
}
-static JSValue js_array_push(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int unshift)
+static JSValue js_array_push(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int unshift)
{
JSValue obj;
int i;
@@ -39384,8 +39334,8 @@ static JSValue js_array_push(JSContext *ctx, JSValue this_val,
return JS_EXCEPTION;
}
-static JSValue js_array_reverse(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_array_reverse(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue obj, lval, hval;
JSValue *arrp;
@@ -39457,8 +39407,8 @@ static JSValue js_array_reverse(JSContext *ctx, JSValue this_val,
// leaves holes in sparse arrays intact whereas a.toReversed() replaces them
// with undefined, thus in effect creating a dense array.
// Does not use Array[@@species], always returns a base Array.
-static JSValue js_array_toReversed(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_array_toReversed(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue arr, obj, ret, *arrp, *pval;
JSObject *p;
@@ -39516,8 +39466,8 @@ exception:
return ret;
}
-static JSValue js_array_slice(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int splice)
+static JSValue js_array_slice(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int splice)
{
JSValue obj, arr, val, len_val;
int64_t len, start, k, final, n, count, del_count, new_len;
@@ -39622,8 +39572,8 @@ static JSValue js_array_slice(JSContext *ctx, JSValue this_val,
return JS_EXCEPTION;
}
-static JSValue js_array_toSpliced(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_array_toSpliced(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue arr, obj, ret, *arrp, *pval, *last;
JSObject *p;
@@ -39717,8 +39667,8 @@ exception:
return ret;
}
-static JSValue js_array_copyWithin(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_array_copyWithin(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue obj;
int64_t len, from, to, final, count;
@@ -39752,11 +39702,11 @@ static JSValue js_array_copyWithin(JSContext *ctx, JSValue this_val,
return JS_EXCEPTION;
}
-static int64_t JS_FlattenIntoArray(JSContext *ctx, JSValue target,
- JSValue source, int64_t sourceLen,
+static int64_t JS_FlattenIntoArray(JSContext *ctx, JSValueConst target,
+ JSValueConst source, int64_t sourceLen,
int64_t targetIndex, int depth,
- JSValue mapperFunction,
- JSValue thisArg)
+ JSValueConst mapperFunction,
+ JSValueConst thisArg)
{
JSValue element;
int64_t sourceIndex, elementLen;
@@ -39774,15 +39724,17 @@ static int64_t JS_FlattenIntoArray(JSContext *ctx, JSValue target,
if (!present)
continue;
if (!JS_IsUndefined(mapperFunction)) {
- JSValue args[3] = { element, js_int64(sourceIndex), source };
- element = JS_Call(ctx, mapperFunction, thisArg, 3, args);
- JS_FreeValue(ctx, args[0]);
- JS_FreeValue(ctx, args[1]);
- if (JS_IsException(element))
+ JSValue index = js_int64(sourceIndex);
+ JSValueConst args[3] = { element, index, source };
+ JSValue ret = JS_Call(ctx, mapperFunction, thisArg, 3, args);
+ JS_FreeValue(ctx, element);
+ JS_FreeValue(ctx, index);
+ if (JS_IsException(ret))
return -1;
+ element = ret;
}
if (depth > 0) {
- is_array = JS_IsArray(ctx, element);
+ is_array = js_is_array(ctx, element);
if (is_array < 0)
goto fail;
if (is_array) {
@@ -39814,11 +39766,11 @@ fail:
return -1;
}
-static JSValue js_array_flatten(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int map)
+static JSValue js_array_flatten(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int map)
{
JSValue obj, arr;
- JSValue mapperFunction, thisArg;
+ JSValueConst mapperFunction, thisArg;
int64_t sourceLen;
int depthNum;
@@ -39870,13 +39822,13 @@ struct array_sort_context {
JSContext *ctx;
int exception;
int has_method;
- JSValue method;
+ JSValueConst method;
};
static int js_array_cmp_generic(const void *a, const void *b, void *opaque) {
struct array_sort_context *psc = opaque;
JSContext *ctx = psc->ctx;
- JSValue argv[2];
+ JSValueConst argv[2];
JSValue res;
ValueSlot *ap = (ValueSlot *)(void *)a;
ValueSlot *bp = (ValueSlot *)(void *)b;
@@ -39921,7 +39873,7 @@ static int js_array_cmp_generic(const void *a, const void *b, void *opaque) {
goto exception;
bp->str = JS_VALUE_GET_STRING(str);
}
- cmp = js_string_compare(ctx, ap->str, bp->str);
+ cmp = js_string_compare(ap->str, bp->str);
}
if (cmp != 0)
return cmp;
@@ -39934,8 +39886,8 @@ exception:
return 0;
}
-static JSValue js_array_sort(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_array_sort(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
struct array_sort_context asc = { ctx, 0, 0, argv[0] };
JSValue obj = JS_UNDEFINED;
@@ -40024,8 +39976,8 @@ fail:
// leaves holes in sparse arrays intact whereas a.toSorted() replaces them
// with undefined, thus in effect creating a dense array.
// Does not use Array[@@species], always returns a base Array.
-static JSValue js_array_toSorted(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_array_toSorted(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue arr, obj, ret, *arrp, *pval;
JSObject *p;
@@ -40035,7 +39987,7 @@ static JSValue js_array_toSorted(JSContext *ctx, JSValue this_val,
ok = JS_IsUndefined(argv[0]) || JS_IsFunction(ctx, argv[0]);
if (!ok)
- return JS_ThrowTypeError(ctx, "not a function");
+ return JS_ThrowTypeErrorNotAFunction(ctx);
ret = JS_EXCEPTION;
arr = JS_UNDEFINED;
@@ -40097,7 +40049,7 @@ typedef struct JSArrayIteratorData {
uint32_t idx;
} JSArrayIteratorData;
-static void js_array_iterator_finalizer(JSRuntime *rt, JSValue val)
+static void js_array_iterator_finalizer(JSRuntime *rt, JSValueConst val)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
JSArrayIteratorData *it = p->u.array_iterator_data;
@@ -40107,7 +40059,7 @@ static void js_array_iterator_finalizer(JSRuntime *rt, JSValue val)
}
}
-static void js_array_iterator_mark(JSRuntime *rt, JSValue val,
+static void js_array_iterator_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
@@ -40117,7 +40069,7 @@ static void js_array_iterator_mark(JSRuntime *rt, JSValue val,
}
}
-static JSValue js_create_array(JSContext *ctx, int len, JSValue *tab)
+static JSValue js_create_array(JSContext *ctx, int len, JSValueConst *tab)
{
JSValue obj;
int i;
@@ -40134,8 +40086,8 @@ static JSValue js_create_array(JSContext *ctx, int len, JSValue *tab)
return obj;
}
-static JSValue js_create_array_iterator(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue js_create_array_iterator(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
JSValue enum_obj, arr;
JSArrayIteratorData *it;
@@ -40171,9 +40123,9 @@ static JSValue js_create_array_iterator(JSContext *ctx, JSValue this_val,
return JS_EXCEPTION;
}
-static JSValue js_array_iterator_next(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv,
- BOOL *pdone, int magic)
+static JSValue js_array_iterator_next(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv,
+ int *pdone, int magic)
{
JSArrayIteratorData *it;
uint32_t len, idx;
@@ -40186,8 +40138,7 @@ static JSValue js_array_iterator_next(JSContext *ctx, JSValue this_val,
if (JS_IsUndefined(it->obj))
goto done;
p = JS_VALUE_GET_OBJ(it->obj);
- if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&
- p->class_id <= JS_CLASS_FLOAT64_ARRAY) {
+ if (is_typed_array(p->class_id)) {
if (typed_array_is_oob(p)) {
JS_ThrowTypeErrorArrayBufferOOB(ctx);
goto fail1;
@@ -40196,7 +40147,7 @@ static JSValue js_array_iterator_next(JSContext *ctx, JSValue this_val,
} else {
if (js_get_length32(ctx, &len, it->obj)) {
fail1:
- *pdone = FALSE;
+ *pdone = false;
return JS_EXCEPTION;
}
}
@@ -40205,11 +40156,11 @@ static JSValue js_array_iterator_next(JSContext *ctx, JSValue this_val,
JS_FreeValue(ctx, it->obj);
it->obj = JS_UNDEFINED;
done:
- *pdone = TRUE;
+ *pdone = true;
return JS_UNDEFINED;
}
it->idx = idx + 1;
- *pdone = FALSE;
+ *pdone = false;
if (it->kind == JS_ITERATOR_KIND_KEY) {
return js_uint32(idx);
} else {
@@ -40219,7 +40170,7 @@ static JSValue js_array_iterator_next(JSContext *ctx, JSValue this_val,
if (it->kind == JS_ITERATOR_KIND_VALUE) {
return val;
} else {
- JSValue args[2];
+ JSValueConst args[2];
JSValue num;
num = js_uint32(idx);
args[0] = num;
@@ -40237,7 +40188,7 @@ typedef struct JSIteratorWrapData {
JSValue wrapped_next;
} JSIteratorWrapData;
-static void js_iterator_wrap_finalizer(JSRuntime *rt, JSValue val)
+static void js_iterator_wrap_finalizer(JSRuntime *rt, JSValueConst val)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
JSIteratorWrapData *it = p->u.iterator_wrap_data;
@@ -40248,7 +40199,7 @@ static void js_iterator_wrap_finalizer(JSRuntime *rt, JSValue val)
}
}
-static void js_iterator_wrap_mark(JSRuntime *rt, JSValue val,
+static void js_iterator_wrap_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
@@ -40259,9 +40210,9 @@ static void js_iterator_wrap_mark(JSRuntime *rt, JSValue val,
}
}
-static JSValue js_iterator_wrap_next(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv,
- BOOL *pdone, int magic)
+static JSValue js_iterator_wrap_next(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv,
+ int *pdone, int magic)
{
JSIteratorWrapData *it;
JSValue method, ret;
@@ -40274,7 +40225,7 @@ static JSValue js_iterator_wrap_next(JSContext *ctx, JSValue this_val,
if (JS_IsException(method))
return JS_EXCEPTION;
if (JS_IsNull(method) || JS_IsUndefined(method)) {
- *pdone = TRUE;
+ *pdone = true;
return JS_UNDEFINED;
}
ret = JS_IteratorNext2(ctx, it->wrapped_iter, method, argc, argv, pdone);
@@ -40287,8 +40238,8 @@ static const JSCFunctionListEntry js_iterator_wrap_proto_funcs[] = {
JS_ITERATOR_NEXT_DEF("return", 0, js_iterator_wrap_next, GEN_MAGIC_RETURN ),
};
-static JSValue js_iterator_constructor(JSContext *ctx, JSValue new_target,
- int argc, JSValue *argv)
+static JSValue js_iterator_constructor(JSContext *ctx, JSValueConst new_target,
+ int argc, JSValueConst *argv)
{
JSObject *p;
@@ -40301,14 +40252,14 @@ static JSValue js_iterator_constructor(JSContext *ctx, JSValue new_target,
return js_create_from_ctor(ctx, new_target, JS_CLASS_ITERATOR);
}
-static JSValue js_iterator_from(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_iterator_from(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
- JSValue obj, method, iter;
+ JSValue method, iter;
JSIteratorWrapData *it;
int ret;
- obj = argv[0];
+ JSValueConst obj = argv[0];
if (JS_IsString(obj)) {
method = JS_GetProperty(ctx, obj, JS_ATOM_Symbol_iterator);
if (JS_IsException(method))
@@ -40351,7 +40302,7 @@ fail:
return JS_EXCEPTION;
}
-static int check_iterator(JSContext *ctx, JSValue obj)
+static int check_iterator(JSContext *ctx, JSValueConst obj)
{
if (!JS_IsObject(obj)) {
JS_ThrowTypeErrorNotAnObject(ctx);
@@ -40371,10 +40322,11 @@ typedef struct JSIteratorHelperData {
uint8_t done : 1;
} JSIteratorHelperData;
-static JSValue js_create_iterator_helper(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue js_create_iterator_helper(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
- JSValue func, obj, method;
+ JSValueConst func;
+ JSValue obj, method;
int64_t count;
JSIteratorHelperData *it;
@@ -40460,13 +40412,13 @@ static JSValue js_create_iterator_helper(JSContext *ctx, JSValue this_val,
return obj;
}
-static JSValue js_iterator_proto_func(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue js_iterator_proto_func(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
JSValue item, method, ret, func, index_val, r;
- JSValue args[2];
+ JSValueConst args[2];
int64_t idx;
- BOOL done;
+ int done;
if (check_iterator(ctx, this_val) < 0)
return JS_EXCEPTION;
@@ -40498,7 +40450,7 @@ static JSValue js_iterator_proto_func(JSContext *ctx, JSValue this_val,
if (JS_IsException(ret))
goto fail;
if (!JS_ToBoolFree(ctx, ret)) {
- if (JS_IteratorClose(ctx, this_val, FALSE) < 0)
+ if (JS_IteratorClose(ctx, this_val, false) < 0)
r = JS_EXCEPTION;
else
r = JS_FALSE;
@@ -40528,7 +40480,7 @@ static JSValue js_iterator_proto_func(JSContext *ctx, JSValue this_val,
goto fail;
}
if (JS_ToBoolFree(ctx, ret)) {
- if (JS_IteratorClose(ctx, this_val, FALSE) < 0) {
+ if (JS_IteratorClose(ctx, this_val, false) < 0) {
JS_FreeValue(ctx, item);
r = JS_EXCEPTION;
} else {
@@ -40583,7 +40535,7 @@ static JSValue js_iterator_proto_func(JSContext *ctx, JSValue this_val,
if (JS_IsException(ret))
goto fail;
if (JS_ToBoolFree(ctx, ret)) {
- if (JS_IteratorClose(ctx, this_val, FALSE) < 0)
+ if (JS_IteratorClose(ctx, this_val, false) < 0)
r = JS_EXCEPTION;
else
r = JS_TRUE;
@@ -40604,19 +40556,19 @@ static JSValue js_iterator_proto_func(JSContext *ctx, JSValue this_val,
JS_FreeValue(ctx, method);
return r;
fail:
- JS_IteratorClose(ctx, this_val, TRUE);
+ JS_IteratorClose(ctx, this_val, true);
JS_FreeValue(ctx, func);
JS_FreeValue(ctx, method);
return JS_EXCEPTION;
}
-static JSValue js_iterator_proto_reduce(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_iterator_proto_reduce(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue item, method, ret, func, index_val, acc;
- JSValue args[3];
+ JSValueConst args[3];
int64_t idx;
- BOOL done;
+ int done;
if (check_iterator(ctx, this_val) < 0)
return JS_EXCEPTION;
@@ -40665,19 +40617,19 @@ static JSValue js_iterator_proto_reduce(JSContext *ctx, JSValue this_val,
JS_FreeValue(ctx, method);
return acc;
exception:
- JS_IteratorClose(ctx, this_val, TRUE);
+ JS_IteratorClose(ctx, this_val, true);
JS_FreeValue(ctx, acc);
JS_FreeValue(ctx, func);
JS_FreeValue(ctx, method);
return JS_EXCEPTION;
}
-static JSValue js_iterator_proto_toArray(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_iterator_proto_toArray(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue item, method, result;
int64_t idx;
- BOOL done;
+ int done;
result = JS_UNDEFINED;
if (check_iterator(ctx, this_val) < 0)
@@ -40708,18 +40660,18 @@ exception:
return JS_EXCEPTION;
}
-static JSValue js_iterator_proto_iterator(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_iterator_proto_iterator(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
return js_dup(this_val);
}
-static JSValue js_iterator_proto_get_toStringTag(JSContext *ctx, JSValue this_val)
+static JSValue js_iterator_proto_get_toStringTag(JSContext *ctx, JSValueConst this_val)
{
return JS_AtomToString(ctx, JS_ATOM_Iterator);
}
-static JSValue js_iterator_proto_set_toStringTag(JSContext *ctx, JSValue this_val, JSValue val)
+static JSValue js_iterator_proto_set_toStringTag(JSContext *ctx, JSValueConst this_val, JSValueConst val)
{
int res;
@@ -40740,7 +40692,7 @@ static JSValue js_iterator_proto_set_toStringTag(JSContext *ctx, JSValue this_va
return JS_UNDEFINED;
}
-static void js_iterator_helper_finalizer(JSRuntime *rt, JSValue val)
+static void js_iterator_helper_finalizer(JSRuntime *rt, JSValueConst val)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
JSIteratorHelperData *it = p->u.iterator_helper_data;
@@ -40753,7 +40705,7 @@ static void js_iterator_helper_finalizer(JSRuntime *rt, JSValue val)
}
}
-static void js_iterator_helper_mark(JSRuntime *rt, JSValue val,
+static void js_iterator_helper_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
@@ -40766,14 +40718,14 @@ static void js_iterator_helper_mark(JSRuntime *rt, JSValue val,
}
}
-static JSValue js_iterator_helper_next(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv,
- BOOL *pdone, int magic)
+static JSValue js_iterator_helper_next(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv,
+ int *pdone, int magic)
{
JSIteratorHelperData *it;
JSValue ret;
- *pdone = FALSE;
+ *pdone = false;
it = JS_GetOpaque2(ctx, this_val, JS_CLASS_ITERATOR_HELPER);
if (!it)
@@ -40781,7 +40733,7 @@ static JSValue js_iterator_helper_next(JSContext *ctx, JSValue this_val,
if (it->executing)
return JS_ThrowTypeError(ctx, "cannot invoke a running iterator");
if (it->done) {
- *pdone = TRUE;
+ *pdone = true;
return JS_UNDEFINED;
}
@@ -40807,7 +40759,7 @@ static JSValue js_iterator_helper_next(JSContext *ctx, JSValue this_val,
}
JS_FreeValue(ctx, item);
if (magic == GEN_MAGIC_RETURN)
- *pdone = TRUE;
+ *pdone = true;
if (*pdone) {
JS_FreeValue(ctx, method);
ret = JS_UNDEFINED;
@@ -40825,7 +40777,8 @@ static JSValue js_iterator_helper_next(JSContext *ctx, JSValue this_val,
break;
case JS_ITERATOR_HELPER_KIND_FILTER:
{
- JSValue item, method, selected, index_val, args[2];
+ JSValue item, method, selected, index_val;
+ JSValueConst args[2];
if (magic == GEN_MAGIC_NEXT) {
method = js_dup(it->next);
} else {
@@ -40863,7 +40816,8 @@ static JSValue js_iterator_helper_next(JSContext *ctx, JSValue this_val,
break;
case JS_ITERATOR_HELPER_KIND_FLAT_MAP:
{
- JSValue item, method, index_val, args[2], iter;
+ JSValue item, method, index_val, iter;
+ JSValueConst args[2];
flat_map_again:
if (JS_IsUndefined(it->inner)) {
if (magic == GEN_MAGIC_NEXT) {
@@ -40919,7 +40873,7 @@ static JSValue js_iterator_helper_next(JSContext *ctx, JSValue this_val,
method = JS_GetProperty(ctx, it->inner, JS_ATOM_return);
if (JS_IsException(method)) {
inner_fail:
- JS_IteratorClose(ctx, it->inner, FALSE);
+ JS_IteratorClose(ctx, it->inner, false);
JS_FreeValue(ctx, it->inner);
it->inner = JS_UNDEFINED;
goto fail;
@@ -40934,8 +40888,8 @@ static JSValue js_iterator_helper_next(JSContext *ctx, JSValue this_val,
}
if (*pdone) {
inner_end:
- *pdone = FALSE; // The outer iterator must continue.
- JS_IteratorClose(ctx, it->inner, FALSE);
+ *pdone = false; // The outer iterator must continue.
+ JS_IteratorClose(ctx, it->inner, false);
JS_FreeValue(ctx, it->inner);
it->inner = JS_UNDEFINED;
goto flat_map_again;
@@ -40946,7 +40900,8 @@ static JSValue js_iterator_helper_next(JSContext *ctx, JSValue this_val,
break;
case JS_ITERATOR_HELPER_KIND_MAP:
{
- JSValue item, method, index_val, args[2];
+ JSValue item, method, index_val;
+ JSValueConst args[2];
if (magic == GEN_MAGIC_NEXT) {
method = js_dup(it->next);
} else {
@@ -40992,8 +40947,8 @@ static JSValue js_iterator_helper_next(JSContext *ctx, JSValue this_val,
goto done;
}
- *pdone = TRUE;
- if (JS_IteratorClose(ctx, it->obj, FALSE))
+ *pdone = true;
+ if (JS_IteratorClose(ctx, it->obj, false))
ret = JS_EXCEPTION;
else
ret = JS_UNDEFINED;
@@ -41010,7 +40965,7 @@ done:
return ret;
fail:
/* close the iterator object, preserving pending exception */
- JS_IteratorClose(ctx, it->obj, TRUE);
+ JS_IteratorClose(ctx, it->obj, true);
ret = JS_EXCEPTION;
goto done;
}
@@ -41090,8 +41045,8 @@ static const JSCFunctionListEntry js_array_iterator_proto_funcs[] = {
/* Number */
-static JSValue js_number_constructor(JSContext *ctx, JSValue new_target,
- int argc, JSValue *argv)
+static JSValue js_number_constructor(JSContext *ctx, JSValueConst new_target,
+ int argc, JSValueConst *argv)
{
JSValue val, obj;
if (argc == 0) {
@@ -41124,24 +41079,24 @@ static JSValue js_number_constructor(JSContext *ctx, JSValue new_target,
}
}
-static JSValue js_number_isNaN(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_number_isNaN(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
if (!JS_IsNumber(argv[0]))
return JS_FALSE;
return js_global_isNaN(ctx, this_val, argc, argv);
}
-static JSValue js_number_isFinite(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_number_isFinite(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
if (!JS_IsNumber(argv[0]))
return JS_FALSE;
return js_global_isFinite(ctx, this_val, argc, argv);
}
-static JSValue js_number_isInteger(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_number_isInteger(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
int ret;
ret = JS_NumberIsInteger(ctx, argv[0]);
@@ -41151,8 +41106,8 @@ static JSValue js_number_isInteger(JSContext *ctx, JSValue this_val,
return js_bool(ret);
}
-static JSValue js_number_isSafeInteger(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_number_isSafeInteger(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
double d;
if (!JS_IsNumber(argv[0]))
@@ -41180,7 +41135,7 @@ static const JSCFunctionListEntry js_number_funcs[] = {
JS_PROP_DOUBLE_DEF("MIN_SAFE_INTEGER", -9007199254740991.0, 0 ), /* ES6 */
};
-static JSValue js_thisNumberValue(JSContext *ctx, JSValue this_val)
+static JSValue js_thisNumberValue(JSContext *ctx, JSValueConst this_val)
{
if (JS_IsNumber(this_val))
return js_dup(this_val);
@@ -41195,13 +41150,13 @@ static JSValue js_thisNumberValue(JSContext *ctx, JSValue this_val)
return JS_ThrowTypeError(ctx, "not a number");
}
-static JSValue js_number_valueOf(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_number_valueOf(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
return js_thisNumberValue(ctx, this_val);
}
-static int js_get_radix(JSContext *ctx, JSValue val)
+static int js_get_radix(JSContext *ctx, JSValueConst val)
{
int radix;
if (JS_ToInt32Sat(ctx, &radix, val))
@@ -41213,8 +41168,8 @@ static int js_get_radix(JSContext *ctx, JSValue val)
return radix;
}
-static JSValue js_number_toString(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue js_number_toString(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
char buf[72];
JSValue val;
@@ -41249,8 +41204,8 @@ static JSValue js_number_toString(JSContext *ctx, JSValue this_val,
return js_dtoa(ctx, d, 0, JS_DTOA_TOSTRING);
}
-static JSValue js_number_toFixed(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_number_toFixed(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue val;
int f;
@@ -41274,8 +41229,8 @@ static JSValue js_number_toFixed(JSContext *ctx, JSValue this_val,
}
}
-static JSValue js_number_toExponential(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_number_toExponential(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue val;
double d;
@@ -41299,8 +41254,8 @@ static JSValue js_number_toExponential(JSContext *ctx, JSValue this_val,
return js_dtoa(ctx, d, f, JS_DTOA_EXPONENTIAL);
}
-static JSValue js_number_toPrecision(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_number_toPrecision(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue val;
int p;
@@ -41332,8 +41287,8 @@ static const JSCFunctionListEntry js_number_proto_funcs[] = {
JS_CFUNC_DEF("valueOf", 0, js_number_valueOf ),
};
-static JSValue js_parseInt(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_parseInt(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
const char *str;
int radix, flags;
@@ -41357,8 +41312,8 @@ static JSValue js_parseInt(JSContext *ctx, JSValue this_val,
return ret;
}
-static JSValue js_parseFloat(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_parseFloat(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
const char *str;
JSValue ret;
@@ -41375,8 +41330,8 @@ static JSValue js_parseFloat(JSContext *ctx, JSValue this_val,
}
/* Boolean */
-static JSValue js_boolean_constructor(JSContext *ctx, JSValue new_target,
- int argc, JSValue *argv)
+static JSValue js_boolean_constructor(JSContext *ctx, JSValueConst new_target,
+ int argc, JSValueConst *argv)
{
JSValue val, obj;
val = js_bool(JS_ToBool(ctx, argv[0]));
@@ -41390,7 +41345,7 @@ static JSValue js_boolean_constructor(JSContext *ctx, JSValue new_target,
}
}
-static JSValue js_thisBooleanValue(JSContext *ctx, JSValue this_val)
+static JSValue js_thisBooleanValue(JSContext *ctx, JSValueConst this_val)
{
if (JS_VALUE_GET_TAG(this_val) == JS_TAG_BOOL)
return js_dup(this_val);
@@ -41405,8 +41360,8 @@ static JSValue js_thisBooleanValue(JSContext *ctx, JSValue this_val)
return JS_ThrowTypeError(ctx, "not a boolean");
}
-static JSValue js_boolean_toString(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_boolean_toString(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue val = js_thisBooleanValue(ctx, this_val);
if (JS_IsException(val))
@@ -41415,8 +41370,8 @@ static JSValue js_boolean_toString(JSContext *ctx, JSValue this_val,
JS_ATOM_true : JS_ATOM_false);
}
-static JSValue js_boolean_valueOf(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_boolean_valueOf(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
return js_thisBooleanValue(ctx, this_val);
}
@@ -41430,7 +41385,7 @@ static const JSCFunctionListEntry js_boolean_proto_funcs[] = {
static int js_string_get_own_property(JSContext *ctx,
JSPropertyDescriptor *desc,
- JSValue obj, JSAtom prop)
+ JSValueConst obj, JSAtom prop)
{
JSObject *p;
JSString *p1;
@@ -41450,18 +41405,18 @@ static int js_string_get_own_property(JSContext *ctx,
desc->getter = JS_UNDEFINED;
desc->setter = JS_UNDEFINED;
}
- return TRUE;
+ return true;
}
}
}
- return FALSE;
+ return false;
}
static int js_string_define_own_property(JSContext *ctx,
- JSValue this_obj,
- JSAtom prop, JSValue val,
- JSValue getter,
- JSValue setter, int flags)
+ JSValueConst this_obj,
+ JSAtom prop, JSValueConst val,
+ JSValueConst getter,
+ JSValueConst setter, int flags)
{
uint32_t idx;
JSObject *p;
@@ -41489,7 +41444,7 @@ static int js_string_define_own_property(JSContext *ctx,
return JS_ThrowTypeErrorOrFalse(ctx, flags, "property is not configurable");
}
}
- return TRUE;
+ return true;
} else {
def:
return JS_DefineProperty(ctx, this_obj, prop, val, getter, setter,
@@ -41498,17 +41453,17 @@ static int js_string_define_own_property(JSContext *ctx,
}
static int js_string_delete_property(JSContext *ctx,
- JSValue obj, JSAtom prop)
+ JSValueConst obj, JSAtom prop)
{
uint32_t idx;
if (__JS_AtomIsTaggedInt(prop)) {
idx = __JS_AtomToUInt32(prop);
if (idx < js_string_obj_get_length(ctx, obj)) {
- return FALSE;
+ return false;
}
}
- return TRUE;
+ return true;
}
static const JSClassExoticMethods js_string_exotic_methods = {
@@ -41517,8 +41472,8 @@ static const JSClassExoticMethods js_string_exotic_methods = {
.delete_property = js_string_delete_property,
};
-static JSValue js_string_constructor(JSContext *ctx, JSValue new_target,
- int argc, JSValue *argv)
+static JSValue js_string_constructor(JSContext *ctx, JSValueConst new_target,
+ int argc, JSValueConst *argv)
{
JSValue val, obj;
if (argc == 0) {
@@ -41547,7 +41502,7 @@ static JSValue js_string_constructor(JSContext *ctx, JSValue new_target,
}
}
-static JSValue js_thisStringValue(JSContext *ctx, JSValue this_val)
+static JSValue js_thisStringValue(JSContext *ctx, JSValueConst this_val)
{
if (JS_VALUE_GET_TAG(this_val) == JS_TAG_STRING)
return js_dup(this_val);
@@ -41562,8 +41517,8 @@ static JSValue js_thisStringValue(JSContext *ctx, JSValue this_val)
return JS_ThrowTypeError(ctx, "not a string");
}
-static JSValue js_string_fromCharCode(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_string_fromCharCode(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
int i;
StringBuffer b_s, *b = &b_s;
@@ -41586,8 +41541,8 @@ static JSValue js_string_fromCharCode(JSContext *ctx, JSValue this_val,
return string_buffer_end(b);
}
-static JSValue js_string_fromCodePoint(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_string_fromCodePoint(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
double d;
int i, c;
@@ -41635,8 +41590,8 @@ static JSValue js_string_fromCodePoint(JSContext *ctx, JSValue this_val,
return JS_EXCEPTION;
}
-static JSValue js_string_raw(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_string_raw(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
// raw(temp,...a)
JSValue cooked, val, raw;
@@ -41676,8 +41631,8 @@ exception:
}
/* only used in test262 */
-JSValue js_string_codePointRange(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+JSValue js_string_codePointRange(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
uint32_t start, end, i, n;
StringBuffer b_s, *b = &b_s;
@@ -41702,8 +41657,8 @@ JSValue js_string_codePointRange(JSContext *ctx, JSValue this_val,
return string_buffer_end(b);
}
-static JSValue js_string_at(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_string_at(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue val, ret;
JSString *p;
@@ -41729,8 +41684,8 @@ static JSValue js_string_at(JSContext *ctx, JSValue this_val,
return ret;
}
-static JSValue js_string_charCodeAt(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_string_charCodeAt(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue val, ret;
JSString *p;
@@ -41754,8 +41709,8 @@ static JSValue js_string_charCodeAt(JSContext *ctx, JSValue this_val,
return ret;
}
-static JSValue js_string_charAt(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_string_charAt(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue val, ret;
JSString *p;
@@ -41779,8 +41734,8 @@ static JSValue js_string_charAt(JSContext *ctx, JSValue this_val,
return ret;
}
-static JSValue js_string_codePointAt(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_string_codePointAt(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue val, ret;
JSString *p;
@@ -41804,8 +41759,8 @@ static JSValue js_string_codePointAt(JSContext *ctx, JSValue this_val,
return ret;
}
-static JSValue js_string_concat(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_string_concat(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue r;
int i;
@@ -41838,13 +41793,13 @@ static int string_indexof_char(JSString *p, int c, int from)
int i, len = p->len;
if (p->is_wide_char) {
for (i = from; i < len; i++) {
- if (p->u.str16[i] == c)
+ if (str16(p)[i] == c)
return i;
}
} else {
if ((c & ~0xff) == 0) {
for (i = from; i < len; i++) {
- if (p->u.str8[i] == (uint8_t)c)
+ if (str8(p)[i] == (uint8_t)c)
return i;
}
}
@@ -41868,7 +41823,7 @@ static int string_indexof(JSString *p1, JSString *p2, int from)
return -1;
}
-static int64_t string_advance_index(JSString *p, int64_t index, BOOL unicode)
+static int64_t string_advance_index(JSString *p, int64_t index, bool unicode)
{
if (!unicode || index >= p->len || !p->is_wide_char) {
index++;
@@ -41880,8 +41835,8 @@ static int64_t string_advance_index(JSString *p, int64_t index, BOOL unicode)
return index;
}
-static JSValue js_string_isWellFormed(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_string_isWellFormed(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue str;
JSValue ret;
@@ -41898,12 +41853,12 @@ static JSValue js_string_isWellFormed(JSContext *ctx, JSValue this_val,
goto done; // by definition well-formed
for (i = 0, n = p->len; i < n; i++) {
- c = p->u.str16[i];
+ c = str16(p)[i];
if (!is_surrogate(c))
continue;
if (is_lo_surrogate(c) || i + 1 == n)
break;
- c = p->u.str16[++i];
+ c = str16(p)[++i];
if (!is_lo_surrogate(c))
break;
}
@@ -41916,8 +41871,8 @@ done:
return ret;
}
-static JSValue js_string_toWellFormed(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_string_toWellFormed(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue str;
JSValue ret;
@@ -41933,30 +41888,30 @@ static JSValue js_string_toWellFormed(JSContext *ctx, JSValue this_val,
return str; // by definition well-formed
// TODO(bnoordhuis) don't clone when input is well-formed
- ret = js_new_string16_len(ctx, p->u.str16, p->len);
+ ret = js_new_string16_len(ctx, str16(p), p->len);
JS_FreeValue(ctx, str);
if (JS_IsException(ret))
return JS_EXCEPTION;
p = JS_VALUE_GET_STRING(ret);
for (i = 0, n = p->len; i < n; i++) {
- c = p->u.str16[i];
+ c = str16(p)[i];
if (!is_surrogate(c))
continue;
if (is_lo_surrogate(c) || i + 1 == n) {
- p->u.str16[i] = 0xFFFD;
+ str16(p)[i] = 0xFFFD;
continue;
}
- c = p->u.str16[++i];
+ c = str16(p)[++i];
if (!is_lo_surrogate(c))
- p->u.str16[--i] = 0xFFFD;
+ str16(p)[--i] = 0xFFFD;
}
return ret;
}
-static JSValue js_string_indexOf(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int lastIndexOf)
+static JSValue js_string_indexOf(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int lastIndexOf)
{
JSValue str, v;
int i, len, v_len, pos, start, stop, ret, inc;
@@ -42020,11 +41975,11 @@ fail:
return JS_EXCEPTION;
}
-/* return < 0 if exception or TRUE/FALSE */
-static int js_is_regexp(JSContext *ctx, JSValue obj);
+/* return < 0 if exception or true/false */
+static int js_is_regexp(JSContext *ctx, JSValueConst obj);
-static JSValue js_string_includes(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue js_string_includes(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
JSValue str, v = JS_UNDEFINED;
int i, len, v_len, pos, start, stop, ret;
@@ -42087,7 +42042,7 @@ fail:
return JS_EXCEPTION;
}
-static int check_regexp_g_flag(JSContext *ctx, JSValue regexp)
+static int check_regexp_g_flag(JSContext *ctx, JSValueConst regexp)
{
int ret;
JSValue flags;
@@ -42116,12 +42071,12 @@ static int check_regexp_g_flag(JSContext *ctx, JSValue regexp)
return 0;
}
-static JSValue js_string_match(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int atom)
+static JSValue js_string_match(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int atom)
{
// match(rx), search(rx), matchAll(rx)
// atom is JS_ATOM_Symbol_match, JS_ATOM_Symbol_search, or JS_ATOM_Symbol_matchAll
- JSValue O = this_val, regexp = argv[0], args[2];
+ JSValueConst O = this_val, regexp = argv[0], args[2];
JSValue matcher, S, rx, result, str;
int args_len;
@@ -42161,16 +42116,16 @@ static JSValue js_string_match(JSContext *ctx, JSValue this_val,
JS_FreeValue(ctx, S);
return JS_EXCEPTION;
}
- result = JS_InvokeFree(ctx, rx, atom, 1, &S);
+ result = JS_InvokeFree(ctx, rx, atom, 1, vc(&S));
JS_FreeValue(ctx, S);
return result;
}
-static JSValue js_string___GetSubstitution(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_string___GetSubstitution(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
// GetSubstitution(matched, str, position, captures, namedCaptures, rep)
- JSValue matched, str, captures, namedCaptures, rep;
+ JSValueConst matched, str, captures, namedCaptures, rep;
JSValue capture, name, s;
uint32_t position, len, matched_len, captures_len;
int i, j, j0, k, k1;
@@ -42274,18 +42229,18 @@ exception:
return JS_EXCEPTION;
}
-static JSValue js_string_replace(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv,
+static JSValue js_string_replace(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv,
int is_replaceAll)
{
// replace(rx, rep)
- JSValue O = this_val, searchValue = argv[0], replaceValue = argv[1];
- JSValue args[6];
+ JSValueConst O = this_val, searchValue = argv[0], replaceValue = argv[1];
+ JSValueConst args[6];
JSValue str, search_str, replaceValue_str, repl_str;
JSString *sp, *searchp;
StringBuffer b_s, *b = &b_s;
int pos, functionalReplace, endOfLastMatch;
- BOOL is_first;
+ bool is_first;
if (JS_IsUndefined(O) || JS_IsNull(O))
return JS_ThrowTypeError(ctx, "cannot convert to object");
@@ -42327,7 +42282,7 @@ static JSValue js_string_replace(JSContext *ctx, JSValue this_val,
sp = JS_VALUE_GET_STRING(str);
searchp = JS_VALUE_GET_STRING(search_str);
endOfLastMatch = 0;
- is_first = TRUE;
+ is_first = true;
for(;;) {
if (unlikely(searchp->len == 0)) {
if (is_first)
@@ -42369,7 +42324,7 @@ static JSValue js_string_replace(JSContext *ctx, JSValue this_val,
string_buffer_concat(b, sp, endOfLastMatch, pos);
string_buffer_concat_value_free(b, repl_str);
endOfLastMatch = pos + searchp->len;
- is_first = FALSE;
+ is_first = false;
if (!is_replaceAll)
break;
}
@@ -42387,12 +42342,12 @@ exception:
return JS_EXCEPTION;
}
-static JSValue js_string_split(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_string_split(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
// split(sep, limit)
- JSValue O = this_val, separator = argv[0], limit = argv[1];
- JSValue args[2];
+ JSValueConst O = this_val, separator = argv[0], limit = argv[1];
+ JSValueConst args[2];
JSValue S, A, R, T;
uint32_t lim, lengthA;
int64_t p, q, s, r, e;
@@ -42477,8 +42432,8 @@ exception:
return JS_EXCEPTION;
}
-static JSValue js_string_substring(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_string_substring(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue str, ret;
int a, b, start, end;
@@ -42511,8 +42466,8 @@ static JSValue js_string_substring(JSContext *ctx, JSValue this_val,
return ret;
}
-static JSValue js_string_substr(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_string_substr(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue str, ret;
int a, len, n;
@@ -42539,8 +42494,8 @@ static JSValue js_string_substr(JSContext *ctx, JSValue this_val,
return ret;
}
-static JSValue js_string_slice(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_string_slice(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue str, ret;
int len, start, end;
@@ -42567,8 +42522,8 @@ static JSValue js_string_slice(JSContext *ctx, JSValue this_val,
return ret;
}
-static JSValue js_string_pad(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int padEnd)
+static JSValue js_string_pad(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int padEnd)
{
JSValue str, v = JS_UNDEFINED;
StringBuffer b_s, *b = &b_s;
@@ -42638,8 +42593,8 @@ fail1:
return JS_EXCEPTION;
}
-static JSValue js_string_repeat(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_string_repeat(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue str;
StringBuffer b_s, *b = &b_s;
@@ -42682,8 +42637,8 @@ fail:
return JS_EXCEPTION;
}
-static JSValue js_string_trim(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue js_string_trim(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
JSValue str, ret;
int a, b, len;
@@ -42718,22 +42673,22 @@ static int string_prevc(JSString *p, int *pidx)
return 0;
idx--;
if (p->is_wide_char) {
- c = p->u.str16[idx];
+ c = str16(p)[idx];
if (is_lo_surrogate(c) && idx > 0) {
- c1 = p->u.str16[idx - 1];
+ c1 = str16(p)[idx - 1];
if (is_hi_surrogate(c1)) {
c = from_surrogate(c1, c);
idx--;
}
}
} else {
- c = p->u.str8[idx];
+ c = str8(p)[idx];
}
*pidx = idx;
return c;
}
-static BOOL test_final_sigma(JSString *p, int sigma_pos)
+static bool test_final_sigma(JSString *p, int sigma_pos)
{
int k, c1;
@@ -42746,14 +42701,14 @@ static BOOL test_final_sigma(JSString *p, int sigma_pos)
break;
}
if (!lre_is_cased(c1))
- return FALSE;
+ return false;
/* after C: skip case ignorable chars and check there is
no cased letter */
k = sigma_pos + 1;
for(;;) {
if (k >= p->len)
- return TRUE;
+ return true;
c1 = string_getc(p, &k);
if (!lre_is_case_ignorable(c1))
break;
@@ -42776,8 +42731,8 @@ static int to_utf32_buf(JSContext *ctx, JSString *p, uint32_t **pbuf)
return j;
}
-static JSValue js_string_localeCompare(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_string_localeCompare(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
int i, n, an, bn, cmp;
uint32_t *as, *bs, *ts;
@@ -42837,8 +42792,8 @@ exception:
return ret;
}
-static JSValue js_string_toLowerCase(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int to_lower)
+static JSValue js_string_toLowerCase(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int to_lower)
{
JSValue val;
StringBuffer b_s, *b = &b_s;
@@ -42905,8 +42860,8 @@ static JSValue JS_NewUTF32String(JSContext *ctx, const uint32_t *buf, int len)
return JS_EXCEPTION;
}
-static JSValue js_string_normalize(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_string_normalize(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
const char *form, *p;
size_t form_len;
@@ -42918,6 +42873,7 @@ static JSValue js_string_normalize(JSContext *ctx, JSValue this_val,
val = JS_ToStringCheckObject(ctx, this_val);
if (JS_IsException(val))
return val;
+ buf = NULL; // appease bogus -Wmaybe-uninitialized warning
buf_len = JS_ToUTF32String(ctx, &buf, val);
JS_FreeValue(ctx, val);
if (buf_len < 0)
@@ -42933,9 +42889,9 @@ static JSValue js_string_normalize(JSContext *ctx, JSValue this_val,
if (p[0] != 'N' || p[1] != 'F')
goto bad_form;
p += 2;
- is_compat = FALSE;
+ is_compat = false;
if (*p == 'K') {
- is_compat = TRUE;
+ is_compat = true;
p++;
}
if (*p == 'C' || *p == 'D') {
@@ -42964,17 +42920,17 @@ static JSValue js_string_normalize(JSContext *ctx, JSValue this_val,
}
/* also used for String.prototype.valueOf */
-static JSValue js_string_toString(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_string_toString(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
return js_thisStringValue(ctx, this_val);
}
/* String Iterator */
-static JSValue js_string_iterator_next(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv,
- BOOL *pdone, int magic)
+static JSValue js_string_iterator_next(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv,
+ int *pdone, int magic)
{
JSArrayIteratorData *it;
uint32_t idx, c, start;
@@ -42982,7 +42938,7 @@ static JSValue js_string_iterator_next(JSContext *ctx, JSValue this_val,
it = JS_GetOpaque2(ctx, this_val, JS_CLASS_STRING_ITERATOR);
if (!it) {
- *pdone = FALSE;
+ *pdone = false;
return JS_EXCEPTION;
}
if (JS_IsUndefined(it->obj))
@@ -42993,18 +42949,18 @@ static JSValue js_string_iterator_next(JSContext *ctx, JSValue this_val,
JS_FreeValue(ctx, it->obj);
it->obj = JS_UNDEFINED;
done:
- *pdone = TRUE;
+ *pdone = true;
return JS_UNDEFINED;
}
start = idx;
c = string_getc(p, (int *)&idx);
it->idx = idx;
- *pdone = FALSE;
+ *pdone = false;
if (c <= 0xffff) {
return js_new_string_char(ctx, c);
} else {
- return js_new_string16_len(ctx, p->u.str16 + start, 2);
+ return js_new_string16_len(ctx, str16(p) + start, 2);
}
}
@@ -43025,11 +42981,11 @@ enum {
magic_string_sup,
};
-static JSValue js_string_CreateHTML(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue js_string_CreateHTML(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
JSValue str;
- const JSString *p;
+ JSString *p;
StringBuffer b_s, *b = &b_s;
static struct { const char *tag, *attr; } const defs[] = {
{ "a", "name" }, { "big", NULL }, { "blink", NULL }, { "b", NULL },
@@ -43177,10 +43133,10 @@ static double js_fmax(double a, double b)
}
}
-static JSValue js_math_min_max(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue js_math_min_max(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
- BOOL is_max = magic;
+ bool is_max = magic;
double r, a;
int i;
uint32_t tag;
@@ -43268,8 +43224,8 @@ static double js_math_round(double a)
return u.d;
}
-static JSValue js_math_hypot(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_math_hypot(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
double r, a;
int i;
@@ -43302,8 +43258,8 @@ static double js_math_fround(double a)
return (float)a;
}
-static JSValue js_math_imul(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_math_imul(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
uint32_t a, b, c;
int32_t d;
@@ -43317,8 +43273,8 @@ static JSValue js_math_imul(JSContext *ctx, JSValue this_val,
return js_int32(d);
}
-static JSValue js_math_clz32(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_math_clz32(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
uint32_t a, r;
@@ -43331,16 +43287,16 @@ static JSValue js_math_clz32(JSContext *ctx, JSValue this_val,
return js_int32(r);
}
-static JSValue js_math_sumPrecise(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_math_sumPrecise(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue iter, next, item, ret;
bf_t a, b;
- BOOL done;
+ int done;
double d;
int r;
- iter = JS_GetIterator(ctx, argv[0], /*async*/FALSE);
+ iter = JS_GetIterator(ctx, argv[0], /*async*/false);
if (JS_IsException(iter))
return JS_EXCEPTION;
bf_init(ctx->bf_ctx, &a);
@@ -43349,7 +43305,7 @@ static JSValue js_math_sumPrecise(JSContext *ctx, JSValue this_val,
next = JS_GetProperty(ctx, iter, JS_ATOM_next);
if (JS_IsException(next))
goto fail;
- bf_set_zero(&a, /*is_neg*/TRUE);
+ bf_set_zero(&a, /*is_neg*/true);
for (;;) {
item = JS_IteratorNext(ctx, iter, next, 0, NULL, &done);
if (JS_IsException(item))
@@ -43409,8 +43365,8 @@ static void js_random_init(JSContext *ctx)
ctx->random_state = 1;
}
-static JSValue js_math_random(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_math_random(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSFloat64Union u;
uint64_t v;
@@ -43567,7 +43523,7 @@ static int getTimezoneOffset(int64_t time) {
/* RegExp */
-static void js_regexp_finalizer(JSRuntime *rt, JSValue val)
+static void js_regexp_finalizer(JSRuntime *rt, JSValueConst val)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
JSRegExp *re = &p->u.regexp;
@@ -43576,8 +43532,8 @@ static void js_regexp_finalizer(JSRuntime *rt, JSValue val)
}
/* create a string containing the RegExp bytecode */
-static JSValue js_compile_regexp(JSContext *ctx, JSValue pattern,
- JSValue flags)
+static JSValue js_compile_regexp(JSContext *ctx, JSValueConst pattern,
+ JSValueConst flags)
{
const char *str;
int re_flags, mask;
@@ -43654,7 +43610,7 @@ static JSValue js_compile_regexp(JSContext *ctx, JSValue pattern,
/* create a RegExp object from a string containing the RegExp bytecode
and the source pattern */
-static JSValue js_regexp_constructor_internal(JSContext *ctx, JSValue ctor,
+static JSValue js_regexp_constructor_internal(JSContext *ctx, JSValueConst ctor,
JSValue pattern, JSValue bc)
{
JSValue obj;
@@ -43683,7 +43639,8 @@ static JSValue js_regexp_constructor_internal(JSContext *ctx, JSValue ctor,
return obj;
}
-static JSRegExp *js_get_regexp(JSContext *ctx, JSValue obj, BOOL throw_error)
+static JSRegExp *js_get_regexp(JSContext *ctx, JSValueConst obj,
+ bool throw_error)
{
if (JS_VALUE_GET_TAG(obj) == JS_TAG_OBJECT) {
JSObject *p = JS_VALUE_GET_OBJ(obj);
@@ -43696,26 +43653,26 @@ static JSRegExp *js_get_regexp(JSContext *ctx, JSValue obj, BOOL throw_error)
return NULL;
}
-/* return < 0 if exception or TRUE/FALSE */
-static int js_is_regexp(JSContext *ctx, JSValue obj)
+/* return < 0 if exception or true/false */
+static int js_is_regexp(JSContext *ctx, JSValueConst obj)
{
JSValue m;
if (!JS_IsObject(obj))
- return FALSE;
+ return false;
m = JS_GetProperty(ctx, obj, JS_ATOM_Symbol_match);
if (JS_IsException(m))
return -1;
if (!JS_IsUndefined(m))
return JS_ToBoolFree(ctx, m);
- return js_get_regexp(ctx, obj, FALSE) != NULL;
+ return js_get_regexp(ctx, obj, false) != NULL;
}
-static JSValue js_regexp_constructor(JSContext *ctx, JSValue new_target,
- int argc, JSValue *argv)
+static JSValue js_regexp_constructor(JSContext *ctx, JSValueConst new_target,
+ int argc, JSValueConst *argv)
{
JSValue pattern, flags, bc, val;
- JSValue pat, flags1;
+ JSValueConst pat, flags1;
JSRegExp *re;
int pat_is_regexp;
@@ -43729,7 +43686,7 @@ static JSValue js_regexp_constructor(JSContext *ctx, JSValue new_target,
new_target = JS_GetActiveFunction(ctx);
if (pat_is_regexp && JS_IsUndefined(flags1)) {
JSValue ctor;
- BOOL res;
+ bool res;
ctor = JS_GetProperty(ctx, pat, JS_ATOM_constructor);
if (JS_IsException(ctor))
return ctor;
@@ -43739,7 +43696,7 @@ static JSValue js_regexp_constructor(JSContext *ctx, JSValue new_target,
return js_dup(pat);
}
}
- re = js_get_regexp(ctx, pat, FALSE);
+ re = js_get_regexp(ctx, pat, false);
if (re) {
pattern = js_dup(JS_MKPTR(JS_TAG_STRING, re->pattern));
if (JS_IsUndefined(flags1)) {
@@ -43789,19 +43746,19 @@ static JSValue js_regexp_constructor(JSContext *ctx, JSValue new_target,
return JS_EXCEPTION;
}
-static JSValue js_regexp_compile(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_regexp_compile(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSRegExp *re1, *re;
- JSValue pattern1, flags1;
+ JSValueConst pattern1, flags1;
JSValue bc, pattern;
- re = js_get_regexp(ctx, this_val, TRUE);
+ re = js_get_regexp(ctx, this_val, true);
if (!re)
return JS_EXCEPTION;
pattern1 = argv[0];
flags1 = argv[1];
- re1 = js_get_regexp(ctx, pattern1, FALSE);
+ re1 = js_get_regexp(ctx, pattern1, false);
if (re1) {
if (!JS_IsUndefined(flags1))
return JS_ThrowTypeError(ctx, "flags must be undefined");
@@ -43833,7 +43790,7 @@ static JSValue js_regexp_compile(JSContext *ctx, JSValue this_val,
return JS_EXCEPTION;
}
-static JSValue js_regexp_get_source(JSContext *ctx, JSValue this_val)
+static JSValue js_regexp_get_source(JSContext *ctx, JSValueConst this_val)
{
JSRegExp *re;
JSString *p;
@@ -43846,7 +43803,7 @@ static JSValue js_regexp_get_source(JSContext *ctx, JSValue this_val)
if (js_same_value(ctx, this_val, ctx->class_proto[JS_CLASS_REGEXP]))
goto empty_regex;
- re = js_get_regexp(ctx, this_val, TRUE);
+ re = js_get_regexp(ctx, this_val, true);
if (!re)
return JS_EXCEPTION;
@@ -43899,7 +43856,7 @@ static JSValue js_regexp_get_source(JSContext *ctx, JSValue this_val)
return string_buffer_end(b);
}
-static JSValue js_regexp_get_flag(JSContext *ctx, JSValue this_val, int mask)
+static JSValue js_regexp_get_flag(JSContext *ctx, JSValueConst this_val, int mask)
{
JSRegExp *re;
int flags;
@@ -43907,7 +43864,7 @@ static JSValue js_regexp_get_flag(JSContext *ctx, JSValue this_val, int mask)
if (JS_VALUE_GET_TAG(this_val) != JS_TAG_OBJECT)
return JS_ThrowTypeErrorNotAnObject(ctx);
- re = js_get_regexp(ctx, this_val, FALSE);
+ re = js_get_regexp(ctx, this_val, false);
if (!re) {
if (js_same_value(ctx, this_val, ctx->class_proto[JS_CLASS_REGEXP]))
return JS_UNDEFINED;
@@ -43915,11 +43872,11 @@ static JSValue js_regexp_get_flag(JSContext *ctx, JSValue this_val, int mask)
return JS_ThrowTypeErrorInvalidClass(ctx, JS_CLASS_REGEXP);
}
- flags = lre_get_flags(re->bytecode->u.str8);
+ flags = lre_get_flags(str8(re->bytecode));
return js_bool(flags & mask);
}
-static JSValue js_regexp_get_flags(JSContext *ctx, JSValue this_val)
+static JSValue js_regexp_get_flags(JSContext *ctx, JSValueConst this_val)
{
char str[8], *p = str;
int res;
@@ -43975,8 +43932,8 @@ exception:
return JS_EXCEPTION;
}
-static JSValue js_regexp_toString(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_regexp_toString(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue pattern, flags;
StringBuffer b_s, *b = &b_s;
@@ -44000,7 +43957,7 @@ fail:
return JS_EXCEPTION;
}
-BOOL lre_check_stack_overflow(void *opaque, size_t alloca_size)
+bool lre_check_stack_overflow(void *opaque, size_t alloca_size)
{
if (!opaque)
return 0;
@@ -44017,8 +43974,8 @@ void *lre_realloc(void *opaque, void *ptr, size_t size)
}
#endif
-static JSValue js_regexp_escape(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_regexp_escape(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
StringBuffer b_s, *b = &b_s;
JSString *p;
@@ -44030,7 +43987,7 @@ static JSValue js_regexp_escape(JSContext *ctx, JSValue this_val,
p = JS_VALUE_GET_STRING(argv[0]);
string_buffer_init2(ctx, b, 0, p->is_wide_char);
for (i = 0; i < p->len; i++) {
- c = p->is_wide_char ? (uint32_t)p->u.str16[i] : (uint32_t)p->u.str8[i];
+ c = p->is_wide_char ? (uint32_t)str16(p)[i] : (uint32_t)str8(p)[i];
if (c < 33) {
if (c >= 9 && c <= 13) {
string_buffer_putc8(b, '\\');
@@ -44064,10 +44021,10 @@ static JSValue js_regexp_escape(JSContext *ctx, JSValue this_val,
return string_buffer_end(b);
}
-static JSValue js_regexp_exec(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_regexp_exec(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
- JSRegExp *re = js_get_regexp(ctx, this_val, TRUE);
+ JSRegExp *re = js_get_regexp(ctx, this_val, true);
JSString *str;
JSValue t, ret, str_val, obj, val, groups;
JSValue indices, indices_groups;
@@ -44095,7 +44052,7 @@ static JSValue js_regexp_exec(JSContext *ctx, JSValue this_val,
if (JS_IsException(val) || JS_ToLengthFree(ctx, &last_index, val))
goto fail;
- re_bytecode = re->bytecode->u.str8;
+ re_bytecode = str8(re->bytecode);
re_flags = lre_get_flags(re_bytecode);
if ((re_flags & (LRE_FLAG_GLOBAL | LRE_FLAG_STICKY)) == 0) {
last_index = 0;
@@ -44108,7 +44065,7 @@ static JSValue js_regexp_exec(JSContext *ctx, JSValue this_val,
goto fail;
}
shift = str->is_wide_char;
- str_buf = str->u.str8;
+ str_buf = str8(str);
if (last_index > str->len) {
rc = 2;
} else {
@@ -44264,9 +44221,9 @@ fail:
}
/* delete portions of a string that match a given regex */
-static JSValue JS_RegExpDelete(JSContext *ctx, JSValue this_val, JSValue arg)
+static JSValue JS_RegExpDelete(JSContext *ctx, JSValueConst this_val, JSValue arg)
{
- JSRegExp *re = js_get_regexp(ctx, this_val, TRUE);
+ JSRegExp *re = js_get_regexp(ctx, this_val, true);
JSString *str;
JSValue str_val, val;
uint8_t *re_bytecode;
@@ -44287,7 +44244,7 @@ static JSValue JS_RegExpDelete(JSContext *ctx, JSValue this_val, JSValue arg)
if (JS_IsException(str_val))
goto fail;
str = JS_VALUE_GET_STRING(str_val);
- re_bytecode = re->bytecode->u.str8;
+ re_bytecode = str8(re->bytecode);
re_flags = lre_get_flags(re_bytecode);
if ((re_flags & (LRE_FLAG_GLOBAL | LRE_FLAG_STICKY)) == 0) {
last_index = 0;
@@ -44303,7 +44260,7 @@ static JSValue JS_RegExpDelete(JSContext *ctx, JSValue this_val, JSValue arg)
goto fail;
}
shift = str->is_wide_char;
- str_buf = str->u.str8;
+ str_buf = str8(str);
next_src_pos = 0;
for (;;) {
if (last_index > str->len)
@@ -44359,7 +44316,7 @@ fail:
return JS_EXCEPTION;
}
-static JSValue JS_RegExpExec(JSContext *ctx, JSValue r, JSValue s)
+static JSValue JS_RegExpExec(JSContext *ctx, JSValueConst r, JSValueConst s)
{
JSValue method, ret;
@@ -44380,11 +44337,11 @@ static JSValue JS_RegExpExec(JSContext *ctx, JSValue r, JSValue s)
return js_regexp_exec(ctx, r, 1, &s);
}
-static JSValue js_regexp_test(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_regexp_test(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue val;
- BOOL ret;
+ bool ret;
val = JS_RegExpExec(ctx, this_val, argv[0]);
if (JS_IsException(val))
@@ -44394,11 +44351,11 @@ static JSValue js_regexp_test(JSContext *ctx, JSValue this_val,
return js_bool(ret);
}
-static JSValue js_regexp_Symbol_match(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_regexp_Symbol_match(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
// [Symbol.match](str)
- JSValue rx = this_val;
+ JSValueConst rx = this_val;
JSValue A, S, flags, result, matchStr;
int global, n, fullUnicode, isEmpty;
JSString *p;
@@ -44482,12 +44439,13 @@ exception:
typedef struct JSRegExpStringIteratorData {
JSValue iterating_regexp;
JSValue iterated_string;
- BOOL global;
- BOOL unicode;
- BOOL done;
+ bool global;
+ bool unicode;
+ int done;
} JSRegExpStringIteratorData;
-static void js_regexp_string_iterator_finalizer(JSRuntime *rt, JSValue val)
+static void js_regexp_string_iterator_finalizer(JSRuntime *rt,
+ JSValueConst val)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
JSRegExpStringIteratorData *it = p->u.regexp_string_iterator_data;
@@ -44498,7 +44456,7 @@ static void js_regexp_string_iterator_finalizer(JSRuntime *rt, JSValue val)
}
}
-static void js_regexp_string_iterator_mark(JSRuntime *rt, JSValue val,
+static void js_regexp_string_iterator_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
@@ -44510,9 +44468,9 @@ static void js_regexp_string_iterator_mark(JSRuntime *rt, JSValue val,
}
static JSValue js_regexp_string_iterator_next(JSContext *ctx,
- JSValue this_val,
- int argc, JSValue *argv,
- BOOL *pdone, int magic)
+ JSValueConst this_val,
+ int argc, JSValueConst *argv,
+ int *pdone, int magic)
{
JSRegExpStringIteratorData *it;
JSValue R, S;
@@ -44523,7 +44481,7 @@ static JSValue js_regexp_string_iterator_next(JSContext *ctx,
if (!it)
goto exception;
if (it->done) {
- *pdone = TRUE;
+ *pdone = true;
return JS_UNDEFINED;
}
R = it->iterating_regexp;
@@ -44532,8 +44490,8 @@ static JSValue js_regexp_string_iterator_next(JSContext *ctx,
if (JS_IsException(match))
goto exception;
if (JS_IsNull(match)) {
- it->done = TRUE;
- *pdone = TRUE;
+ it->done = true;
+ *pdone = true;
return JS_UNDEFINED;
} else if (it->global) {
matchStr = JS_ToStringFree(ctx, JS_GetPropertyInt64(ctx, match, 0));
@@ -44551,24 +44509,24 @@ static JSValue js_regexp_string_iterator_next(JSContext *ctx,
}
JS_FreeValue(ctx, matchStr);
} else {
- it->done = TRUE;
+ it->done = true;
}
- *pdone = FALSE;
+ *pdone = false;
return match;
exception:
JS_FreeValue(ctx, match);
JS_FreeValue(ctx, matchStr);
- *pdone = FALSE;
+ *pdone = false;
return JS_EXCEPTION;
}
-static JSValue js_regexp_Symbol_matchAll(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_regexp_Symbol_matchAll(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
// [Symbol.matchAll](str)
- JSValue R = this_val;
+ JSValueConst R = this_val;
JSValue S, C, flags, matcher, iter;
- JSValue args[2];
+ JSValueConst args[2];
JSString *strp;
int64_t lastIndex;
JSRegExpStringIteratorData *it;
@@ -44612,7 +44570,7 @@ static JSValue js_regexp_Symbol_matchAll(JSContext *ctx, JSValue this_val,
strp = JS_VALUE_GET_STRING(flags);
it->global = string_indexof_char(strp, 'g', 0) >= 0;
it->unicode = string_indexof_char(strp, 'u', 0) >= 0;
- it->done = FALSE;
+ it->done = false;
JS_SetOpaqueInternal(iter, it);
JS_FreeValue(ctx, C);
@@ -44687,7 +44645,7 @@ static int value_buffer_append(ValueBuffer *b, JSValue val)
return 0;
}
-static int js_is_standard_regexp(JSContext *ctx, JSValue rx)
+static int js_is_standard_regexp(JSContext *ctx, JSValueConst rx)
{
JSValue val;
int res;
@@ -44709,12 +44667,12 @@ static int js_is_standard_regexp(JSContext *ctx, JSValue rx)
return res;
}
-static JSValue js_regexp_Symbol_replace(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_regexp_Symbol_replace(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
// [Symbol.replace](str, rep)
- JSValue rx = this_val, rep = argv[1];
- JSValue args[6];
+ JSValueConst rx = this_val, rep = argv[1];
+ JSValueConst args[6];
JSValue flags, str, rep_val, matched, tab, rep_str, namedCaptures, res;
JSString *p, *sp, *rp;
StringBuffer b_s, *b = &b_s;
@@ -44902,10 +44860,10 @@ done1:
return res;
}
-static JSValue js_regexp_Symbol_search(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_regexp_Symbol_search(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
- JSValue rx = this_val;
+ JSValueConst rx = this_val;
JSValue str, previousLastIndex, currentLastIndex, result, index;
if (!JS_IsObject(rx))
@@ -44960,12 +44918,12 @@ exception:
return JS_EXCEPTION;
}
-static JSValue js_regexp_Symbol_split(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_regexp_Symbol_split(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
// [Symbol.split](str, limit)
- JSValue rx = this_val;
- JSValue args[2];
+ JSValueConst rx = this_val;
+ JSValueConst args[2];
JSValue str, ctor, splitter, A, flags, z, sub;
JSString *strp;
uint32_t lim, size, p, q;
@@ -45288,7 +45246,7 @@ JSValue JS_ParseJSON(JSContext *ctx, const char *buf, size_t buf_len, const char
JSParseState s1, *s = &s1;
JSValue val = JS_UNDEFINED;
- js_parse_init(ctx, s, buf, buf_len, filename);
+ js_parse_init(ctx, s, buf, buf_len, filename, 1);
if (json_next_token(s))
goto fail;
val = json_parse_value(s);
@@ -45305,11 +45263,11 @@ JSValue JS_ParseJSON(JSContext *ctx, const char *buf, size_t buf_len, const char
return JS_EXCEPTION;
}
-static JSValue internalize_json_property(JSContext *ctx, JSValue holder,
- JSAtom name, JSValue reviver)
+static JSValue internalize_json_property(JSContext *ctx, JSValueConst holder,
+ JSAtom name, JSValueConst reviver)
{
JSValue val, new_el, name_val, res;
- JSValue args[2];
+ JSValueConst args[2];
int ret, is_array;
uint32_t i, len = 0;
JSAtom prop;
@@ -45323,7 +45281,7 @@ static JSValue internalize_json_property(JSContext *ctx, JSValue holder,
if (JS_IsException(val))
return val;
if (JS_IsObject(val)) {
- is_array = JS_IsArray(ctx, val);
+ is_array = js_is_array(ctx, val);
if (is_array < 0)
goto fail;
if (is_array) {
@@ -45374,11 +45332,11 @@ static JSValue internalize_json_property(JSContext *ctx, JSValue holder,
return JS_EXCEPTION;
}
-static JSValue js_json_parse(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_json_parse(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue obj, root;
- JSValue reviver;
+ JSValueConst reviver;
const char *str;
size_t len;
@@ -45409,7 +45367,7 @@ static JSValue js_json_parse(JSContext *ctx, JSValue this_val,
}
typedef struct JSONStringifyContext {
- JSValue replacer_func;
+ JSValueConst replacer_func;
JSValue stack;
JSValue property_list;
JSValue gap;
@@ -45424,10 +45382,11 @@ static JSValue JS_ToQuotedStringFree(JSContext *ctx, JSValue val) {
}
static JSValue js_json_check(JSContext *ctx, JSONStringifyContext *jsc,
- JSValue holder, JSValue val, JSValue key)
+ JSValueConst holder, JSValue val,
+ JSValueConst key)
{
JSValue v;
- JSValue args[2];
+ JSValueConst args[2];
if (JS_IsObject(val) || JS_IsBigInt(ctx, val)) {
JSValue f = JS_GetProperty(ctx, val, JS_ATOM_toJSON);
@@ -45478,14 +45437,14 @@ exception:
}
static int js_json_to_str(JSContext *ctx, JSONStringifyContext *jsc,
- JSValue holder, JSValue val,
- JSValue indent)
+ JSValueConst holder, JSValue val,
+ JSValueConst indent)
{
JSValue indent1, sep, sep1, tab, v, prop;
JSObject *p;
int64_t i, len;
int cl, ret;
- BOOL has_content;
+ bool has_content;
indent1 = JS_UNDEFINED;
sep = JS_UNDEFINED;
@@ -45510,7 +45469,7 @@ static int js_json_to_str(JSContext *ctx, JSONStringifyContext *jsc,
set_value(ctx, &val, js_dup(p->u.object_data));
goto concat_primitive;
}
- v = js_array_includes(ctx, jsc->stack, 1, &val);
+ v = js_array_includes(ctx, jsc->stack, 1, vc(&val));
if (JS_IsException(v))
goto exception;
if (JS_ToBoolFree(ctx, v)) {
@@ -45531,10 +45490,10 @@ static int js_json_to_str(JSContext *ctx, JSONStringifyContext *jsc,
sep = js_dup(jsc->empty);
sep1 = js_dup(jsc->empty);
}
- v = js_array_push(ctx, jsc->stack, 1, &val, 0);
+ v = js_array_push(ctx, jsc->stack, 1, vc(&val), 0);
if (check_exception_free(ctx, v))
goto exception;
- ret = JS_IsArray(ctx, val);
+ ret = js_is_array(ctx, val);
if (ret < 0)
goto exception;
if (ret) {
@@ -45571,13 +45530,14 @@ static int js_json_to_str(JSContext *ctx, JSONStringifyContext *jsc,
if (!JS_IsUndefined(jsc->property_list))
tab = js_dup(jsc->property_list);
else
- tab = js_object_keys(ctx, JS_UNDEFINED, 1, &val, JS_ITERATOR_KIND_KEY);
+ tab = js_object_keys(ctx, JS_UNDEFINED, 1, vc(&val),
+ JS_ITERATOR_KIND_KEY);
if (JS_IsException(tab))
goto exception;
if (js_get_length64(ctx, &len, tab))
goto exception;
string_buffer_putc8(jsc->b, '{');
- has_content = FALSE;
+ has_content = false;
for(i = 0; i < len; i++) {
JS_FreeValue(ctx, prop);
prop = JS_GetPropertyInt64(ctx, tab, i);
@@ -45603,7 +45563,7 @@ static int js_json_to_str(JSContext *ctx, JSONStringifyContext *jsc,
string_buffer_concat_value(jsc->b, sep1);
if (js_json_to_str(ctx, jsc, val, v, indent1))
goto exception;
- has_content = TRUE;
+ has_content = true;
}
}
if (has_content && JS_VALUE_GET_STRING(jsc->gap)->len != 0) {
@@ -45657,8 +45617,8 @@ exception:
return -1;
}
-JSValue JS_JSONStringify(JSContext *ctx, JSValue obj,
- JSValue replacer, JSValue space0)
+JSValue JS_JSONStringify(JSContext *ctx, JSValueConst obj,
+ JSValueConst replacer, JSValueConst space0)
{
StringBuffer b_s;
JSONStringifyContext jsc_s, *jsc = &jsc_s;
@@ -45682,7 +45642,7 @@ JSValue JS_JSONStringify(JSContext *ctx, JSValue obj,
if (JS_IsFunction(ctx, replacer)) {
jsc->replacer_func = replacer;
} else {
- res = JS_IsArray(ctx, replacer);
+ res = js_is_array(ctx, replacer);
if (res < 0)
goto exception;
if (res) {
@@ -45717,7 +45677,7 @@ JSValue JS_JSONStringify(JSContext *ctx, JSValue obj,
continue;
}
present = js_array_includes(ctx, jsc->property_list,
- 1, &v);
+ 1, vc(&v));
if (JS_IsException(present)) {
JS_FreeValue(ctx, v);
goto exception;
@@ -45791,8 +45751,8 @@ done:
return ret;
}
-static JSValue js_json_stringify(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_json_stringify(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
// stringify(val, replacer, space)
return JS_JSONStringify(ctx, argv[0], argv[1], argv[2]);
@@ -45816,16 +45776,16 @@ void JS_AddIntrinsicJSON(JSContext *ctx)
/* Reflect */
-static JSValue js_reflect_apply(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_reflect_apply(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
return js_function_apply(ctx, argv[0], max_int(0, argc - 1), argv + 1, 2);
}
-static JSValue js_reflect_construct(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_reflect_construct(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
- JSValue func, array_arg, new_target;
+ JSValueConst func, array_arg, new_target;
JSValue *tab, ret;
uint32_t len;
@@ -45841,15 +45801,15 @@ static JSValue js_reflect_construct(JSContext *ctx, JSValue this_val,
tab = build_arg_list(ctx, &len, array_arg);
if (!tab)
return JS_EXCEPTION;
- ret = JS_CallConstructor2(ctx, func, new_target, len, tab);
+ ret = JS_CallConstructor2(ctx, func, new_target, len, vc(tab));
free_arg_list(ctx, tab, len);
return ret;
}
-static JSValue js_reflect_deleteProperty(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_reflect_deleteProperty(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
- JSValue obj;
+ JSValueConst obj;
JSAtom atom;
int ret;
@@ -45867,10 +45827,10 @@ static JSValue js_reflect_deleteProperty(JSContext *ctx, JSValue this_val,
return js_bool(ret);
}
-static JSValue js_reflect_get(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_reflect_get(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
- JSValue obj, prop, receiver;
+ JSValueConst obj, prop, receiver;
JSAtom atom;
JSValue ret;
@@ -45885,15 +45845,15 @@ static JSValue js_reflect_get(JSContext *ctx, JSValue this_val,
atom = JS_ValueToAtom(ctx, prop);
if (unlikely(atom == JS_ATOM_NULL))
return JS_EXCEPTION;
- ret = JS_GetPropertyInternal(ctx, obj, atom, receiver, FALSE);
+ ret = JS_GetPropertyInternal(ctx, obj, atom, receiver, false);
JS_FreeAtom(ctx, atom);
return ret;
}
-static JSValue js_reflect_has(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_reflect_has(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
- JSValue obj, prop;
+ JSValueConst obj, prop;
JSAtom atom;
int ret;
@@ -45912,10 +45872,10 @@ static JSValue js_reflect_has(JSContext *ctx, JSValue this_val,
return js_bool(ret);
}
-static JSValue js_reflect_set(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_reflect_set(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
- JSValue obj, prop, val, receiver;
+ JSValueConst obj, prop, val, receiver;
int ret;
JSAtom atom;
@@ -45931,8 +45891,7 @@ static JSValue js_reflect_set(JSContext *ctx, JSValue this_val,
atom = JS_ValueToAtom(ctx, prop);
if (unlikely(atom == JS_ATOM_NULL))
return JS_EXCEPTION;
- ret = JS_SetPropertyInternal2(ctx, obj, atom, js_dup(val), receiver,
- 0, NULL);
+ ret = JS_SetPropertyInternal2(ctx, obj, atom, js_dup(val), receiver, 0);
JS_FreeAtom(ctx, atom);
if (ret < 0)
return JS_EXCEPTION;
@@ -45940,19 +45899,19 @@ static JSValue js_reflect_set(JSContext *ctx, JSValue this_val,
return js_bool(ret);
}
-static JSValue js_reflect_setPrototypeOf(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_reflect_setPrototypeOf(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
int ret;
- ret = JS_SetPrototypeInternal(ctx, argv[0], argv[1], FALSE);
+ ret = JS_SetPrototypeInternal(ctx, argv[0], argv[1], false);
if (ret < 0)
return JS_EXCEPTION;
else
return js_bool(ret);
}
-static JSValue js_reflect_ownKeys(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_reflect_ownKeys(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
if (JS_VALUE_GET_TAG(argv[0]) != JS_TAG_OBJECT)
return JS_ThrowTypeErrorNotAnObject(ctx);
@@ -45984,7 +45943,7 @@ static const JSCFunctionListEntry js_reflect_obj[] = {
/* Proxy */
-static void js_proxy_finalizer(JSRuntime *rt, JSValue val)
+static void js_proxy_finalizer(JSRuntime *rt, JSValueConst val)
{
JSProxyData *s = JS_GetOpaque(val, JS_CLASS_PROXY);
if (s) {
@@ -45994,7 +45953,7 @@ static void js_proxy_finalizer(JSRuntime *rt, JSValue val)
}
}
-static void js_proxy_mark(JSRuntime *rt, JSValue val,
+static void js_proxy_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func)
{
JSProxyData *s = JS_GetOpaque(val, JS_CLASS_PROXY);
@@ -46010,7 +45969,7 @@ static JSValue JS_ThrowTypeErrorRevokedProxy(JSContext *ctx)
}
static JSProxyData *get_proxy_method(JSContext *ctx, JSValue *pmethod,
- JSValue obj, JSAtom name)
+ JSValueConst obj, JSAtom name)
{
JSProxyData *s = JS_GetOpaque(obj, JS_CLASS_PROXY);
JSValue method;
@@ -46035,7 +45994,7 @@ static JSProxyData *get_proxy_method(JSContext *ctx, JSValue *pmethod,
return s;
}
-static JSValue js_proxy_getPrototypeOf(JSContext *ctx, JSValue obj)
+static JSValue js_proxy_getPrototypeOf(JSContext *ctx, JSValueConst obj)
{
JSProxyData *s;
JSValue method, ret, proto1;
@@ -46046,7 +46005,7 @@ static JSValue js_proxy_getPrototypeOf(JSContext *ctx, JSValue obj)
return JS_EXCEPTION;
if (JS_IsUndefined(method))
return JS_GetPrototype(ctx, s->target);
- ret = JS_CallFree(ctx, method, s->handler, 1, &s->target);
+ ret = JS_CallFree(ctx, method, s->handler, 1, vc(&s->target));
if (JS_IsException(ret))
return ret;
if (JS_VALUE_GET_TAG(ret) != JS_TAG_NULL &&
@@ -46076,13 +46035,13 @@ static JSValue js_proxy_getPrototypeOf(JSContext *ctx, JSValue obj)
return ret;
}
-static int js_proxy_setPrototypeOf(JSContext *ctx, JSValue obj,
- JSValue proto_val, BOOL throw_flag)
+static int js_proxy_setPrototypeOf(JSContext *ctx, JSValueConst obj,
+ JSValueConst proto_val, bool throw_flag)
{
JSProxyData *s;
JSValue method, ret, proto1;
- JSValue args[2];
- BOOL res;
+ JSValueConst args[2];
+ bool res;
int res2;
s = get_proxy_method(ctx, &method, obj, JS_ATOM_setPrototypeOf);
@@ -46101,7 +46060,7 @@ static int js_proxy_setPrototypeOf(JSContext *ctx, JSValue obj,
JS_ThrowTypeError(ctx, "proxy: bad prototype");
return -1;
} else {
- return FALSE;
+ return false;
}
}
res2 = JS_IsExtensible(ctx, s->target);
@@ -46118,14 +46077,14 @@ static int js_proxy_setPrototypeOf(JSContext *ctx, JSValue obj,
}
JS_FreeValue(ctx, proto1);
}
- return TRUE;
+ return true;
}
-static int js_proxy_isExtensible(JSContext *ctx, JSValue obj)
+static int js_proxy_isExtensible(JSContext *ctx, JSValueConst obj)
{
JSProxyData *s;
JSValue method, ret;
- BOOL res;
+ bool res;
int res2;
s = get_proxy_method(ctx, &method, obj, JS_ATOM_isExtensible);
@@ -46133,7 +46092,7 @@ static int js_proxy_isExtensible(JSContext *ctx, JSValue obj)
return -1;
if (JS_IsUndefined(method))
return JS_IsExtensible(ctx, s->target);
- ret = JS_CallFree(ctx, method, s->handler, 1, &s->target);
+ ret = JS_CallFree(ctx, method, s->handler, 1, vc(&s->target));
if (JS_IsException(ret))
return -1;
res = JS_ToBoolFree(ctx, ret);
@@ -46147,11 +46106,11 @@ static int js_proxy_isExtensible(JSContext *ctx, JSValue obj)
return res;
}
-static int js_proxy_preventExtensions(JSContext *ctx, JSValue obj)
+static int js_proxy_preventExtensions(JSContext *ctx, JSValueConst obj)
{
JSProxyData *s;
JSValue method, ret;
- BOOL res;
+ bool res;
int res2;
s = get_proxy_method(ctx, &method, obj, JS_ATOM_preventExtensions);
@@ -46159,7 +46118,7 @@ static int js_proxy_preventExtensions(JSContext *ctx, JSValue obj)
return -1;
if (JS_IsUndefined(method))
return JS_PreventExtensions(ctx, s->target);
- ret = JS_CallFree(ctx, method, s->handler, 1, &s->target);
+ ret = JS_CallFree(ctx, method, s->handler, 1, vc(&s->target));
if (JS_IsException(ret))
return -1;
res = JS_ToBoolFree(ctx, ret);
@@ -46175,14 +46134,14 @@ static int js_proxy_preventExtensions(JSContext *ctx, JSValue obj)
return res;
}
-static int js_proxy_has(JSContext *ctx, JSValue obj, JSAtom atom)
+static int js_proxy_has(JSContext *ctx, JSValueConst obj, JSAtom atom)
{
JSProxyData *s;
JSValue method, ret1, atom_val;
- int ret, res;
+ int res;
JSObject *p;
- JSValue args[2];
- BOOL res2;
+ JSValueConst args[2];
+ bool ret, res2;
s = get_proxy_method(ctx, &method, obj, JS_ATOM_has);
if (!s)
@@ -46219,13 +46178,13 @@ static int js_proxy_has(JSContext *ctx, JSValue obj, JSAtom atom)
return ret;
}
-static JSValue js_proxy_get(JSContext *ctx, JSValue obj, JSAtom atom,
- JSValue receiver)
+static JSValue js_proxy_get(JSContext *ctx, JSValueConst obj, JSAtom atom,
+ JSValueConst receiver)
{
JSProxyData *s;
JSValue method, ret, atom_val;
int res;
- JSValue args[3];
+ JSValueConst args[3];
JSPropertyDescriptor desc;
s = get_proxy_method(ctx, &method, obj, JS_ATOM_get);
@@ -46233,7 +46192,7 @@ static JSValue js_proxy_get(JSContext *ctx, JSValue obj, JSAtom atom,
return JS_EXCEPTION;
/* Note: recursion is possible thru the prototype of s->target */
if (JS_IsUndefined(method))
- return JS_GetPropertyInternal(ctx, s->target, atom, receiver, FALSE);
+ return JS_GetPropertyInternal(ctx, s->target, atom, receiver, false);
atom_val = JS_AtomToValue(ctx, atom);
if (JS_IsException(atom_val)) {
JS_FreeValue(ctx, method);
@@ -46269,21 +46228,21 @@ static JSValue js_proxy_get(JSContext *ctx, JSValue obj, JSAtom atom,
return ret;
}
-static int js_proxy_set(JSContext *ctx, JSValue obj, JSAtom atom,
- JSValue value, JSValue receiver, int flags)
+static int js_proxy_set(JSContext *ctx, JSValueConst obj, JSAtom atom,
+ JSValueConst value, JSValueConst receiver, int flags)
{
JSProxyData *s;
JSValue method, ret1, atom_val;
- int ret, res;
- JSValue args[4];
+ bool ret;
+ int res;
+ JSValueConst args[4];
s = get_proxy_method(ctx, &method, obj, JS_ATOM_set);
if (!s)
return -1;
if (JS_IsUndefined(method)) {
return JS_SetPropertyInternal2(ctx, s->target, atom,
- js_dup(value), receiver,
- flags, NULL);
+ js_dup(value), receiver, flags);
}
atom_val = JS_AtomToValue(ctx, atom);
if (JS_IsException(atom_val)) {
@@ -46327,8 +46286,8 @@ static int js_proxy_set(JSContext *ctx, JSValue obj, JSAtom atom,
return ret;
}
-static JSValue js_create_desc(JSContext *ctx, JSValue val,
- JSValue getter, JSValue setter,
+static JSValue js_create_desc(JSContext *ctx, JSValueConst val,
+ JSValueConst getter, JSValueConst setter,
int flags)
{
JSValue ret;
@@ -46366,13 +46325,13 @@ static JSValue js_create_desc(JSContext *ctx, JSValue val,
}
static int js_proxy_get_own_property(JSContext *ctx, JSPropertyDescriptor *pdesc,
- JSValue obj, JSAtom prop)
+ JSValueConst obj, JSAtom prop)
{
JSProxyData *s;
JSValue method, trap_result_obj, prop_val;
int res, target_desc_ret, ret;
JSObject *p;
- JSValue args[2];
+ JSValueConst args[2];
JSPropertyDescriptor result_desc, target_desc;
s = get_proxy_method(ctx, &method, obj, JS_ATOM_getOwnPropertyDescriptor);
@@ -46409,7 +46368,7 @@ static int js_proxy_get_own_property(JSContext *ctx, JSPropertyDescriptor *pdesc
if (!(target_desc.flags & JS_PROP_CONFIGURABLE) || !p->extensible)
goto fail;
}
- ret = FALSE;
+ ret = false;
} else {
int flags1, extensible_target;
extensible_target = JS_IsExtensible(ctx, s->target);
@@ -46452,7 +46411,7 @@ static int js_proxy_get_own_property(JSContext *ctx, JSPropertyDescriptor *pdesc
return -1;
}
}
- ret = TRUE;
+ ret = true;
if (pdesc) {
*pdesc = result_desc;
} else {
@@ -46462,18 +46421,18 @@ static int js_proxy_get_own_property(JSContext *ctx, JSPropertyDescriptor *pdesc
return ret;
}
-static int js_proxy_define_own_property(JSContext *ctx, JSValue obj,
- JSAtom prop, JSValue val,
- JSValue getter, JSValue setter,
- int flags)
+static int js_proxy_define_own_property(JSContext *ctx, JSValueConst obj,
+ JSAtom prop, JSValueConst val,
+ JSValueConst getter,
+ JSValueConst setter, int flags)
{
JSProxyData *s;
JSValue method, ret1, prop_val, desc_val;
- int res, ret;
+ int res;
JSObject *p;
- JSValue args[3];
+ JSValueConst args[3];
JSPropertyDescriptor desc;
- BOOL setting_not_configurable;
+ bool ret, setting_not_configurable;
s = get_proxy_method(ctx, &method, obj, JS_ATOM_defineProperty);
if (!s)
@@ -46562,13 +46521,14 @@ static int js_proxy_define_own_property(JSContext *ctx, JSValue obj,
return 1;
}
-static int js_proxy_delete_property(JSContext *ctx, JSValue obj,
+static int js_proxy_delete_property(JSContext *ctx, JSValueConst obj,
JSAtom atom)
{
JSProxyData *s;
JSValue method, ret, atom_val;
- int res, res2, is_extensible;
- JSValue args[2];
+ int res2, is_extensible;
+ bool res;
+ JSValueConst args[2];
s = get_proxy_method(ctx, &method, obj, JS_ATOM_deleteProperty);
if (!s)
@@ -46627,7 +46587,7 @@ static int find_prop_key(const JSPropertyEnum *tab, int n, JSAtom atom)
static int js_proxy_get_own_property_names(JSContext *ctx,
JSPropertyEnum **ptab,
uint32_t *plen,
- JSValue obj)
+ JSValueConst obj)
{
JSProxyData *s;
JSValue method, prop_array, val;
@@ -46645,7 +46605,7 @@ static int js_proxy_get_own_property_names(JSContext *ctx,
JS_VALUE_GET_OBJ(s->target),
JS_GPN_STRING_MASK | JS_GPN_SYMBOL_MASK);
}
- prop_array = JS_CallFree(ctx, method, s->handler, 1, &s->target);
+ prop_array = JS_CallFree(ctx, method, s->handler, 1, vc(&s->target));
if (JS_IsException(prop_array))
return -1;
tab = NULL;
@@ -46673,7 +46633,7 @@ static int js_proxy_get_own_property_names(JSContext *ctx,
if (atom == JS_ATOM_NULL)
goto fail;
tab[i].atom = atom;
- tab[i].is_enumerable = FALSE; /* XXX: redundant? */
+ tab[i].is_enumerable = false; /* XXX: redundant? */
}
/* check duplicate properties (XXX: inefficient, could store the
@@ -46716,7 +46676,7 @@ static int js_proxy_get_own_property_names(JSContext *ctx,
}
/* mark the property as found */
if (!is_extensible)
- tab[idx].is_enumerable = TRUE;
+ tab[idx].is_enumerable = true;
}
}
}
@@ -46742,13 +46702,13 @@ static int js_proxy_get_own_property_names(JSContext *ctx,
return -1;
}
-static JSValue js_proxy_call_constructor(JSContext *ctx, JSValue func_obj,
- JSValue new_target,
- int argc, JSValue *argv)
+static JSValue js_proxy_call_constructor(JSContext *ctx, JSValueConst func_obj,
+ JSValueConst new_target,
+ int argc, JSValueConst *argv)
{
JSProxyData *s;
JSValue method, arg_array, ret;
- JSValue args[3];
+ JSValueConst args[3];
s = get_proxy_method(ctx, &method, func_obj, JS_ATOM_construct);
if (!s)
@@ -46776,13 +46736,13 @@ static JSValue js_proxy_call_constructor(JSContext *ctx, JSValue func_obj,
return ret;
}
-static JSValue js_proxy_call(JSContext *ctx, JSValue func_obj,
- JSValue this_obj,
- int argc, JSValue *argv, int flags)
+static JSValue js_proxy_call(JSContext *ctx, JSValueConst func_obj,
+ JSValueConst this_obj,
+ int argc, JSValueConst *argv, int flags)
{
JSProxyData *s;
JSValue method, arg_array, ret;
- JSValue args[3];
+ JSValueConst args[3];
if (flags & JS_CALL_FLAG_CONSTRUCTOR)
return js_proxy_call_constructor(ctx, func_obj, this_obj, argc, argv);
@@ -46792,7 +46752,7 @@ static JSValue js_proxy_call(JSContext *ctx, JSValue func_obj,
return JS_EXCEPTION;
if (!s->is_func) {
JS_FreeValue(ctx, method);
- return JS_ThrowTypeError(ctx, "not a function");
+ return JS_ThrowTypeErrorNotAFunction(ctx);
}
if (JS_IsUndefined(method))
return JS_Call(ctx, s->target, this_obj, argc, argv);
@@ -46811,11 +46771,11 @@ static JSValue js_proxy_call(JSContext *ctx, JSValue func_obj,
return ret;
}
-static int js_proxy_isArray(JSContext *ctx, JSValue obj)
+static int js_proxy_isArray(JSContext *ctx, JSValueConst obj)
{
JSProxyData *s = JS_GetOpaque(obj, JS_CLASS_PROXY);
if (!s)
- return FALSE;
+ return false;
if (js_check_stack_overflow(ctx->rt, 0)) {
JS_ThrowStackOverflow(ctx);
@@ -46826,7 +46786,7 @@ static int js_proxy_isArray(JSContext *ctx, JSValue obj)
JS_ThrowTypeErrorRevokedProxy(ctx);
return -1;
}
- return JS_IsArray(ctx, s->target);
+ return js_is_array(ctx, s->target);
}
static const JSClassExoticMethods js_proxy_exotic_methods = {
@@ -46839,10 +46799,10 @@ static const JSClassExoticMethods js_proxy_exotic_methods = {
.set_property = js_proxy_set,
};
-static JSValue js_proxy_constructor(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_proxy_constructor(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
- JSValue target, handler;
+ JSValueConst target, handler;
JSValue obj;
JSProxyData *s;
@@ -46863,35 +46823,35 @@ static JSValue js_proxy_constructor(JSContext *ctx, JSValue this_val,
s->target = js_dup(target);
s->handler = js_dup(handler);
s->is_func = JS_IsFunction(ctx, target);
- s->is_revoked = FALSE;
+ s->is_revoked = false;
JS_SetOpaqueInternal(obj, s);
JS_SetConstructorBit(ctx, obj, JS_IsConstructor(ctx, target));
return obj;
}
-static JSValue js_proxy_revoke(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic,
- JSValue *func_data)
+static JSValue js_proxy_revoke(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic,
+ JSValueConst *func_data)
{
JSProxyData *s = JS_GetOpaque(func_data[0], JS_CLASS_PROXY);
if (s) {
/* We do not free the handler and target in case they are
referenced as constants in the C call stack */
- s->is_revoked = TRUE;
- JS_FreeValue(ctx, func_data[0]);
+ s->is_revoked = true;
+ JS_FreeValue(ctx, unsafe_unconst(func_data[0]));
func_data[0] = JS_NULL;
}
return JS_UNDEFINED;
}
static JSValue js_proxy_revoke_constructor(JSContext *ctx,
- JSValue proxy_obj)
+ JSValueConst proxy_obj)
{
return JS_NewCFunctionData(ctx, js_proxy_revoke, 0, 0, 1, &proxy_obj);
}
-static JSValue js_proxy_revocable(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_proxy_revocable(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue proxy_obj, revoke_obj = JS_UNDEFINED, obj;
@@ -46936,17 +46896,51 @@ void JS_AddIntrinsicProxy(JSContext *ctx)
obj1 = JS_NewCFunction2(ctx, js_proxy_constructor, "Proxy", 2,
JS_CFUNC_constructor, 0);
- JS_SetConstructorBit(ctx, obj1, TRUE);
+ JS_SetConstructorBit(ctx, obj1, true);
JS_SetPropertyFunctionList(ctx, obj1, js_proxy_funcs,
countof(js_proxy_funcs));
JS_DefinePropertyValueStr(ctx, ctx->global_obj, "Proxy",
obj1, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
}
+bool JS_IsProxy(JSValueConst val)
+{
+ if (JS_VALUE_GET_TAG(val) == JS_TAG_OBJECT) {
+ JSObject *p = JS_VALUE_GET_OBJ(val);
+ return p->class_id == JS_CLASS_PROXY;
+ }
+ return false;
+}
+
+static JSValue js_get_proxy_field(JSContext *ctx, JSValueConst proxy,
+ int offset)
+{
+ if (JS_VALUE_GET_TAG(proxy) == JS_TAG_OBJECT) {
+ JSObject *p = JS_VALUE_GET_OBJ(proxy);
+ if (p->class_id == JS_CLASS_PROXY) {
+ JSProxyData *s = JS_GetOpaque(proxy, JS_CLASS_PROXY);
+ if (s->is_revoked)
+ return JS_ThrowTypeErrorRevokedProxy(ctx);
+ return js_dup(*(JSValue *)((char *)s + offset));
+ }
+ }
+ return JS_ThrowTypeError(ctx, "not a proxy");
+}
+
+JSValue JS_GetProxyTarget(JSContext *ctx, JSValueConst proxy)
+{
+ return js_get_proxy_field(ctx, proxy, offsetof(JSProxyData, target));
+}
+
+JSValue JS_GetProxyHandler(JSContext *ctx, JSValueConst proxy)
+{
+ return js_get_proxy_field(ctx, proxy, offsetof(JSProxyData, handler));
+}
+
/* Symbol */
-static JSValue js_symbol_constructor(JSContext *ctx, JSValue new_target,
- int argc, JSValue *argv)
+static JSValue js_symbol_constructor(JSContext *ctx, JSValueConst new_target,
+ int argc, JSValueConst *argv)
{
JSValue str;
JSString *p;
@@ -46964,7 +46958,7 @@ static JSValue js_symbol_constructor(JSContext *ctx, JSValue new_target,
return JS_NewSymbolInternal(ctx, p, JS_ATOM_TYPE_SYMBOL);
}
-static JSValue js_thisSymbolValue(JSContext *ctx, JSValue this_val)
+static JSValue js_thisSymbolValue(JSContext *ctx, JSValueConst this_val)
{
if (JS_VALUE_GET_TAG(this_val) == JS_TAG_SYMBOL)
return js_dup(this_val);
@@ -46979,26 +46973,26 @@ static JSValue js_thisSymbolValue(JSContext *ctx, JSValue this_val)
return JS_ThrowTypeError(ctx, "not a symbol");
}
-static JSValue js_symbol_toString(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_symbol_toString(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue val, ret;
val = js_thisSymbolValue(ctx, this_val);
if (JS_IsException(val))
return val;
/* XXX: use JS_ToStringInternal() with a flags */
- ret = js_string_constructor(ctx, JS_UNDEFINED, 1, &val);
+ ret = js_string_constructor(ctx, JS_UNDEFINED, 1, vc(&val));
JS_FreeValue(ctx, val);
return ret;
}
-static JSValue js_symbol_valueOf(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_symbol_valueOf(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
return js_thisSymbolValue(ctx, this_val);
}
-static JSValue js_symbol_get_description(JSContext *ctx, JSValue this_val)
+static JSValue js_symbol_get_description(JSContext *ctx, JSValueConst this_val)
{
JSValue val, ret;
JSAtomStruct *p;
@@ -47025,8 +47019,8 @@ static const JSCFunctionListEntry js_symbol_proto_funcs[] = {
JS_CGETSET_DEF("description", js_symbol_get_description, NULL ),
};
-static JSValue js_symbol_for(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_symbol_for(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue str;
@@ -47036,8 +47030,8 @@ static JSValue js_symbol_for(JSContext *ctx, JSValue this_val,
return JS_NewSymbolInternal(ctx, JS_VALUE_GET_STRING(str), JS_ATOM_TYPE_GLOBAL_SYMBOL);
}
-static JSValue js_symbol_keyFor(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_symbol_keyFor(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSAtomStruct *p;
@@ -47058,7 +47052,7 @@ static const JSCFunctionListEntry js_symbol_funcs[] = {
typedef struct JSMapRecord {
int ref_count; /* used during enumeration to avoid freeing the record */
- BOOL empty; /* TRUE if the record is deleted */
+ bool empty; /* true if the record is deleted */
struct JSMapState *map;
struct list_head link;
struct list_head hash_link;
@@ -47067,7 +47061,7 @@ typedef struct JSMapRecord {
} JSMapRecord;
typedef struct JSMapState {
- BOOL is_weak; /* TRUE if WeakSet/WeakMap */
+ bool is_weak; /* true if WeakSet/WeakMap */
struct list_head records; /* list of JSMapRecord.link */
uint32_t record_count;
struct list_head *hash_table;
@@ -47079,13 +47073,13 @@ typedef struct JSMapState {
#define MAGIC_SET (1 << 0)
#define MAGIC_WEAK (1 << 1)
-static JSValue js_map_constructor(JSContext *ctx, JSValue new_target,
- int argc, JSValue *argv, int magic)
+static JSValue js_map_constructor(JSContext *ctx, JSValueConst new_target,
+ int argc, JSValueConst *argv, int magic)
{
JSMapState *s;
JSValue obj, adder = JS_UNDEFINED, iter = JS_UNDEFINED, next_method = JS_UNDEFINED;
- JSValue arr;
- BOOL is_set, is_weak;
+ JSValueConst arr;
+ bool is_set, is_weak;
is_set = magic & MAGIC_SET;
is_weak = ((magic & MAGIC_WEAK) != 0);
@@ -47110,7 +47104,7 @@ static JSValue js_map_constructor(JSContext *ctx, JSValue new_target,
arr = argv[0];
if (!JS_IsUndefined(arr) && !JS_IsNull(arr)) {
JSValue item, ret;
- BOOL done;
+ int done;
adder = JS_GetProperty(ctx, obj, is_set ? JS_ATOM_add : JS_ATOM_set);
if (JS_IsException(adder))
@@ -47120,7 +47114,7 @@ static JSValue js_map_constructor(JSContext *ctx, JSValue new_target,
goto fail;
}
- iter = JS_GetIterator(ctx, arr, FALSE);
+ iter = JS_GetIterator(ctx, arr, false);
if (JS_IsException(iter))
goto fail;
next_method = JS_GetProperty(ctx, iter, JS_ATOM_next);
@@ -47136,14 +47130,14 @@ static JSValue js_map_constructor(JSContext *ctx, JSValue new_target,
break;
}
if (is_set) {
- ret = JS_Call(ctx, adder, obj, 1, &item);
+ ret = JS_Call(ctx, adder, obj, 1, vc(&item));
if (JS_IsException(ret)) {
JS_FreeValue(ctx, item);
goto fail;
}
} else {
JSValue key, value;
- JSValue args[2];
+ JSValueConst args[2];
key = JS_UNDEFINED;
value = JS_UNDEFINED;
if (!JS_IsObject(item)) {
@@ -47180,7 +47174,7 @@ static JSValue js_map_constructor(JSContext *ctx, JSValue new_target,
fail:
if (JS_IsObject(iter)) {
/* close the iterator object, preserving pending exception */
- JS_IteratorClose(ctx, iter, TRUE);
+ JS_IteratorClose(ctx, iter, true);
}
JS_FreeValue(ctx, next_method);
JS_FreeValue(ctx, iter);
@@ -47193,15 +47187,20 @@ static JSValue js_map_constructor(JSContext *ctx, JSValue new_target,
static JSValue map_normalize_key(JSContext *ctx, JSValue key)
{
uint32_t tag = JS_VALUE_GET_TAG(key);
- /* convert -0.0 to +0.0 */
- if (JS_TAG_IS_FLOAT64(tag) && JS_VALUE_GET_FLOAT64(key) == 0.0) {
- key = js_int32(0);
- }
+ // convert -0.0 to +0.0
+ // not a leak; |key| and return value are not heap-allocated
+ if (JS_TAG_IS_FLOAT64(tag) && JS_VALUE_GET_FLOAT64(key) == 0.0)
+ return js_int32(0);
return key;
}
+static JSValueConst map_normalize_key_const(JSContext *ctx, JSValueConst key)
+{
+ return safe_const(map_normalize_key(ctx, unsafe_unconst(key)));
+}
+
/* XXX: better hash ? */
-static uint32_t map_hash_key(JSContext *ctx, JSValue key)
+static uint32_t map_hash_key(JSContext *ctx, JSValueConst key)
{
uint32_t tag = JS_VALUE_GET_NORM_TAG(key);
uint32_t h;
@@ -47231,7 +47230,7 @@ static uint32_t map_hash_key(JSContext *ctx, JSValue key)
d = JS_VALUE_GET_FLOAT64(key);
/* normalize the NaN */
if (isnan(d))
- d = JS_FLOAT64_NAN;
+ d = NAN;
hash_float64:
u.d = d;
h = (u.u32[0] ^ u.u32[1]) * 3163;
@@ -47245,7 +47244,7 @@ static uint32_t map_hash_key(JSContext *ctx, JSValue key)
}
static JSMapRecord *map_find_record(JSContext *ctx, JSMapState *s,
- JSValue key)
+ JSValueConst key)
{
struct list_head *el;
JSMapRecord *mr;
@@ -47292,7 +47291,7 @@ static void map_hash_resize(JSContext *ctx, JSMapState *s)
s->record_count_threshold = new_hash_size * 2;
}
-static JSWeakRefRecord **get_first_weak_ref(JSValue key)
+static JSWeakRefRecord **get_first_weak_ref(JSValueConst key)
{
switch (JS_VALUE_GET_TAG(key)) {
case JS_TAG_OBJECT:
@@ -47314,7 +47313,7 @@ static JSWeakRefRecord **get_first_weak_ref(JSValue key)
}
static JSMapRecord *map_add_record(JSContext *ctx, JSMapState *s,
- JSValue key)
+ JSValueConst key)
{
uint32_t h;
JSMapRecord *mr;
@@ -47324,7 +47323,7 @@ static JSMapRecord *map_add_record(JSContext *ctx, JSMapState *s,
return NULL;
mr->ref_count = 1;
mr->map = s;
- mr->empty = FALSE;
+ mr->empty = false;
if (s->is_weak) {
JSWeakRefRecord *wr = js_malloc(ctx, sizeof(*wr));
if (!wr) {
@@ -47334,10 +47333,10 @@ static JSMapRecord *map_add_record(JSContext *ctx, JSMapState *s,
wr->kind = JS_WEAK_REF_KIND_MAP;
wr->u.map_record = mr;
insert_weakref_record(key, wr);
+ mr->key = unsafe_unconst(key);
} else {
- js_dup(key);
+ mr->key = js_dup(key);
}
- mr->key = key;
h = map_hash_key(ctx, key) & (s->hash_size - 1);
list_add_tail(&mr->hash_link, &s->hash_table[h]);
list_add_tail(&mr->link, &s->records);
@@ -47384,7 +47383,7 @@ static void map_delete_record(JSRuntime *rt, JSMapState *s, JSMapRecord *mr)
js_free_rt(rt, mr);
} else {
/* keep a zombie record for iterators */
- mr->empty = TRUE;
+ mr->empty = true;
mr->key = JS_UNDEFINED;
mr->value = JS_UNDEFINED;
}
@@ -47401,18 +47400,18 @@ static void map_decref_record(JSRuntime *rt, JSMapRecord *mr)
}
}
-static JSValue js_map_set(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue js_map_set(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
JSMapState *s = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic);
JSMapRecord *mr;
- JSValue key, value;
+ JSValueConst key, value;
int is_set;
if (!s)
return JS_EXCEPTION;
is_set = (magic & MAGIC_SET);
- key = map_normalize_key(ctx, argv[0]);
+ key = map_normalize_key_const(ctx, argv[0]);
if (s->is_weak && !is_valid_weakref_target(key))
return JS_ThrowTypeError(ctx, "invalid value used as %s key", is_set ? "WeakSet" : "WeakMap");
if (is_set)
@@ -47431,16 +47430,16 @@ static JSValue js_map_set(JSContext *ctx, JSValue this_val,
return js_dup(this_val);
}
-static JSValue js_map_get(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue js_map_get(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
JSMapState *s = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic);
JSMapRecord *mr;
- JSValue key;
+ JSValueConst key;
if (!s)
return JS_EXCEPTION;
- key = map_normalize_key(ctx, argv[0]);
+ key = map_normalize_key_const(ctx, argv[0]);
mr = map_find_record(ctx, s, key);
if (!mr)
return JS_UNDEFINED;
@@ -47448,30 +47447,30 @@ static JSValue js_map_get(JSContext *ctx, JSValue this_val,
return js_dup(mr->value);
}
-static JSValue js_map_has(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue js_map_has(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
JSMapState *s = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic);
JSMapRecord *mr;
- JSValue key;
+ JSValueConst key;
if (!s)
return JS_EXCEPTION;
- key = map_normalize_key(ctx, argv[0]);
+ key = map_normalize_key_const(ctx, argv[0]);
mr = map_find_record(ctx, s, key);
return js_bool(mr != NULL);
}
-static JSValue js_map_delete(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue js_map_delete(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
JSMapState *s = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic);
JSMapRecord *mr;
- JSValue key;
+ JSValueConst key;
if (!s)
return JS_EXCEPTION;
- key = map_normalize_key(ctx, argv[0]);
+ key = map_normalize_key_const(ctx, argv[0]);
mr = map_find_record(ctx, s, key);
if (!mr)
return JS_FALSE;
@@ -47479,8 +47478,8 @@ static JSValue js_map_delete(JSContext *ctx, JSValue this_val,
return JS_TRUE;
}
-static JSValue js_map_clear(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue js_map_clear(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
JSMapState *s = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic);
struct list_head *el, *el1;
@@ -47495,7 +47494,7 @@ static JSValue js_map_clear(JSContext *ctx, JSValue this_val,
return JS_UNDEFINED;
}
-static JSValue js_map_get_size(JSContext *ctx, JSValue this_val, int magic)
+static JSValue js_map_get_size(JSContext *ctx, JSValueConst this_val, int magic)
{
JSMapState *s = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic);
if (!s)
@@ -47503,11 +47502,11 @@ static JSValue js_map_get_size(JSContext *ctx, JSValue this_val, int magic)
return js_uint32(s->record_count);
}
-static JSValue js_map_forEach(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue js_map_forEach(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
JSMapState *s = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic);
- JSValue func, this_arg;
+ JSValueConst func, this_arg;
JSValue ret, args[3];
struct list_head *el;
JSMapRecord *mr;
@@ -47534,8 +47533,8 @@ static JSValue js_map_forEach(JSContext *ctx, JSValue this_val,
args[0] = args[1];
else
args[0] = js_dup(mr->value);
- args[2] = this_val;
- ret = JS_Call(ctx, func, this_arg, 3, args);
+ args[2] = unsafe_unconst(this_val);
+ ret = JS_Call(ctx, func, this_arg, 3, vc(args));
JS_FreeValue(ctx, args[0]);
if (!magic)
JS_FreeValue(ctx, args[1]);
@@ -47551,20 +47550,20 @@ static JSValue js_map_forEach(JSContext *ctx, JSValue this_val,
return JS_UNDEFINED;
}
-static JSValue js_map_groupBy(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_map_groupBy(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
- JSValue cb, res, iter, next, groups, k, v, prop;
- JSValue args[2];
+ JSValue res, iter, next, groups, k, v, prop;
+ JSValueConst cb, args[2];
int64_t idx;
- BOOL done;
+ int done;
// "is function?" check must be observed before argv[0] is accessed
cb = argv[1];
if (check_function(ctx, cb))
return JS_EXCEPTION;
- iter = JS_GetIterator(ctx, argv[0], /*is_async*/FALSE);
+ iter = JS_GetIterator(ctx, argv[0], /*is_async*/false);
if (JS_IsException(iter))
return JS_EXCEPTION;
@@ -47594,7 +47593,7 @@ static JSValue js_map_groupBy(JSContext *ctx, JSValue this_val,
if (JS_IsException(k))
goto exception;
- prop = js_map_get(ctx, groups, 1, &k, 0);
+ prop = js_map_get(ctx, groups, 1, vc(&k), 0);
if (JS_IsException(prop))
goto exception;
@@ -47610,7 +47609,7 @@ static JSValue js_map_groupBy(JSContext *ctx, JSValue this_val,
JS_FreeValue(ctx, res);
}
- res = js_array_push(ctx, prop, 1, &v, /*unshift*/0);
+ res = js_array_push(ctx, prop, 1, vc(&v), /*unshift*/0);
if (JS_IsException(res))
goto exception;
// res is an int64
@@ -47637,7 +47636,7 @@ exception:
return JS_EXCEPTION;
}
-static void js_map_finalizer(JSRuntime *rt, JSValue val)
+static void js_map_finalizer(JSRuntime *rt, JSValueConst val)
{
JSObject *p;
JSMapState *s;
@@ -47665,7 +47664,8 @@ static void js_map_finalizer(JSRuntime *rt, JSValue val)
}
}
-static void js_map_mark(JSRuntime *rt, JSValue val, JS_MarkFunc *mark_func)
+static void js_map_mark(JSRuntime *rt, JSValueConst val,
+ JS_MarkFunc *mark_func)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
JSMapState *s;
@@ -47691,7 +47691,7 @@ typedef struct JSMapIteratorData {
JSMapRecord *cur_record;
} JSMapIteratorData;
-static void js_map_iterator_finalizer(JSRuntime *rt, JSValue val)
+static void js_map_iterator_finalizer(JSRuntime *rt, JSValueConst val)
{
JSObject *p;
JSMapIteratorData *it;
@@ -47709,7 +47709,7 @@ static void js_map_iterator_finalizer(JSRuntime *rt, JSValue val)
}
}
-static void js_map_iterator_mark(JSRuntime *rt, JSValue val,
+static void js_map_iterator_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
@@ -47721,8 +47721,8 @@ static void js_map_iterator_mark(JSRuntime *rt, JSValue val,
}
}
-static JSValue js_create_map_iterator(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue js_create_map_iterator(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
JSIteratorKindEnum kind;
JSMapState *s;
@@ -47751,9 +47751,9 @@ static JSValue js_create_map_iterator(JSContext *ctx, JSValue this_val,
return JS_EXCEPTION;
}
-static JSValue js_map_iterator_next(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv,
- BOOL *pdone, int magic)
+static JSValue js_map_iterator_next(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv,
+ int *pdone, int magic)
{
JSMapIteratorData *it;
JSMapState *s;
@@ -47762,7 +47762,7 @@ static JSValue js_map_iterator_next(JSContext *ctx, JSValue this_val,
it = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP_ITERATOR + magic);
if (!it) {
- *pdone = FALSE;
+ *pdone = false;
return JS_EXCEPTION;
}
if (JS_IsUndefined(it->obj))
@@ -47784,7 +47784,7 @@ static JSValue js_map_iterator_next(JSContext *ctx, JSValue this_val,
it->obj = JS_UNDEFINED;
done:
/* end of enumeration */
- *pdone = TRUE;
+ *pdone = true;
return JS_UNDEFINED;
}
mr = list_entry(el, JSMapRecord, link);
@@ -47797,12 +47797,12 @@ static JSValue js_map_iterator_next(JSContext *ctx, JSValue this_val,
/* lock the record so that it won't be freed */
mr->ref_count++;
it->cur_record = mr;
- *pdone = FALSE;
+ *pdone = false;
if (it->kind == JS_ITERATOR_KIND_KEY) {
return js_dup(mr->key);
} else {
- JSValue args[2];
+ JSValueConst args[2];
args[0] = mr->key;
if (magic)
args[1] = mr->key;
@@ -47840,7 +47840,7 @@ static JSValue js_map_read(BCReaderState *s, int magic)
if (JS_IsException(argv[1]))
goto fail;
}
- rv = js_map_set(ctx, obj, countof(argv), argv, magic);
+ rv = js_map_set(ctx, obj, countof(argv), vc(argv), magic);
if (JS_IsException(rv))
goto fail;
JS_FreeValue(ctx, rv);
@@ -47899,7 +47899,8 @@ static int JS_WriteSet(BCWriterState *s, struct JSMapState *map_state)
return js_map_write(s, map_state, MAGIC_SET);
}
-static int js_setlike_get_size(JSContext *ctx, JSValue setlike, int64_t *pout)
+static int js_setlike_get_size(JSContext *ctx, JSValueConst setlike,
+ int64_t *pout)
{
JSMapState *s;
JSValue v;
@@ -47927,7 +47928,8 @@ static int js_setlike_get_size(JSContext *ctx, JSValue setlike, int64_t *pout)
return 0;
}
-static int js_setlike_get_has(JSContext *ctx, JSValue setlike, JSValue *pout)
+static int js_setlike_get_has(JSContext *ctx, JSValueConst setlike,
+ JSValue *pout)
{
JSValue v;
@@ -47947,7 +47949,8 @@ static int js_setlike_get_has(JSContext *ctx, JSValue setlike, JSValue *pout)
return 0;
}
-static int js_setlike_get_keys(JSContext *ctx, JSValue setlike, JSValue *pout)
+static int js_setlike_get_keys(JSContext *ctx, JSValueConst setlike,
+ JSValue *pout)
{
JSValue v;
@@ -47967,11 +47970,12 @@ static int js_setlike_get_keys(JSContext *ctx, JSValue setlike, JSValue *pout)
return 0;
}
-static JSValue js_set_isDisjointFrom(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_set_isDisjointFrom(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue item, iter, keys, has, next, rv, rval;
- BOOL done, found;
+ int done;
+ bool found;
JSMapState *s;
int64_t size;
int ok;
@@ -47998,7 +48002,7 @@ static JSValue js_set_isDisjointFrom(JSContext *ctx, JSValue this_val,
next = JS_GetProperty(ctx, iter, JS_ATOM_next);
if (JS_IsException(next))
goto exception;
- found = FALSE;
+ found = false;
do {
item = JS_IteratorNext(ctx, iter, next, 0, NULL, &done);
if (JS_IsException(item))
@@ -48013,14 +48017,14 @@ static JSValue js_set_isDisjointFrom(JSContext *ctx, JSValue this_val,
iter = js_create_map_iterator(ctx, this_val, 0, NULL, MAGIC_SET);
if (JS_IsException(iter))
goto exception;
- found = FALSE;
+ found = false;
do {
item = js_map_iterator_next(ctx, iter, 0, NULL, &done, MAGIC_SET);
if (JS_IsException(item))
goto exception;
if (done) // item is JS_UNDEFINED
break;
- rv = JS_Call(ctx, has, argv[0], 1, &item);
+ rv = JS_Call(ctx, has, argv[0], 1, vc(&item));
JS_FreeValue(ctx, item);
ok = JS_ToBoolFree(ctx, rv); // returns -1 if rv is JS_EXCEPTION
if (ok < 0)
@@ -48037,14 +48041,14 @@ exception:
return rval;
}
-static JSValue js_set_isSubsetOf(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_set_isSubsetOf(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue item, iter, keys, has, next, rv, rval;
- BOOL done, found;
+ bool found;
JSMapState *s;
int64_t size;
- int ok;
+ int done, ok;
has = JS_UNDEFINED;
iter = JS_UNDEFINED;
@@ -48061,20 +48065,20 @@ static JSValue js_set_isSubsetOf(JSContext *ctx, JSValue this_val,
goto exception;
if (js_setlike_get_keys(ctx, argv[0], &keys) < 0)
goto exception;
- found = FALSE;
+ found = false;
if (s->record_count > size)
goto fini;
iter = js_create_map_iterator(ctx, this_val, 0, NULL, MAGIC_SET);
if (JS_IsException(iter))
goto exception;
- found = TRUE;
+ found = true;
do {
item = js_map_iterator_next(ctx, iter, 0, NULL, &done, MAGIC_SET);
if (JS_IsException(item))
goto exception;
if (done) // item is JS_UNDEFINED
break;
- rv = JS_Call(ctx, has, argv[0], 1, &item);
+ rv = JS_Call(ctx, has, argv[0], 1, vc(&item));
JS_FreeValue(ctx, item);
ok = JS_ToBoolFree(ctx, rv); // returns -1 if rv is JS_EXCEPTION
if (ok < 0)
@@ -48091,11 +48095,12 @@ exception:
return rval;
}
-static JSValue js_set_isSupersetOf(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_set_isSupersetOf(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue item, iter, keys, has, next, rval;
- BOOL done, found;
+ int done;
+ bool found;
JSMapState *s;
int64_t size;
@@ -48114,7 +48119,7 @@ static JSValue js_set_isSupersetOf(JSContext *ctx, JSValue this_val,
goto exception;
if (js_setlike_get_keys(ctx, argv[0], &keys) < 0)
goto exception;
- found = FALSE;
+ found = false;
if (s->record_count < size)
goto fini;
iter = JS_Call(ctx, keys, argv[0], 0, NULL);
@@ -48123,7 +48128,7 @@ static JSValue js_set_isSupersetOf(JSContext *ctx, JSValue this_val,
next = JS_GetProperty(ctx, iter, JS_ATOM_next);
if (JS_IsException(next))
goto exception;
- found = TRUE;
+ found = true;
do {
item = JS_IteratorNext(ctx, iter, next, 0, NULL, &done);
if (JS_IsException(item))
@@ -48144,15 +48149,14 @@ exception:
return rval;
}
-static JSValue js_set_intersection(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_set_intersection(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue newset, item, iter, keys, has, next, rv;
JSMapState *s, *t;
JSMapRecord *mr;
int64_t size;
- BOOL done;
- int ok;
+ int done, ok;
has = JS_UNDEFINED;
iter = JS_UNDEFINED;
@@ -48212,7 +48216,7 @@ static JSValue js_set_intersection(JSContext *ctx, JSValue this_val,
goto exception;
if (done) // item is JS_UNDEFINED
break;
- rv = JS_Call(ctx, has, argv[0], 1, &item);
+ rv = JS_Call(ctx, has, argv[0], 1, vc(&item));
ok = JS_ToBoolFree(ctx, rv); // returns -1 if rv is JS_EXCEPTION
if (ok > 0) {
item = map_normalize_key(ctx, item);
@@ -48243,14 +48247,14 @@ fini:
return newset;
}
-static JSValue js_set_difference(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_set_difference(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue newset, item, iter, keys, has, next, rv;
JSMapState *s, *t;
JSMapRecord *mr;
int64_t size;
- BOOL done;
+ int done;
int ok;
has = JS_UNDEFINED;
@@ -48305,7 +48309,7 @@ static JSValue js_set_difference(JSContext *ctx, JSValue this_val,
goto exception;
if (done) // item is JS_UNDEFINED
break;
- rv = JS_Call(ctx, has, argv[0], 1, &item);
+ rv = JS_Call(ctx, has, argv[0], 1, vc(&item));
ok = JS_ToBoolFree(ctx, rv); // returns -1 if rv is JS_EXCEPTION
if (ok == 0) {
item = map_normalize_key(ctx, item);
@@ -48336,15 +48340,16 @@ fini:
return newset;
}
-static JSValue js_set_symmetricDifference(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_set_symmetricDifference(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue newset, item, iter, next, rv;
struct list_head *el;
JSMapState *s, *t;
JSMapRecord *mr;
int64_t size;
- BOOL done, present;
+ int done;
+ bool present;
s = JS_GetOpaque2(ctx, this_val, JS_CLASS_SET);
if (!s)
@@ -48423,15 +48428,15 @@ fini:
return newset;
}
-static JSValue js_set_union(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_set_union(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue newset, item, iter, next, rv;
struct list_head *el;
JSMapState *s, *t;
JSMapRecord *mr;
int64_t size;
- BOOL done;
+ int done;
s = JS_GetOpaque2(ctx, this_val, JS_CLASS_SET);
if (!s)
@@ -48472,7 +48477,7 @@ static JSValue js_set_union(JSContext *ctx, JSValue this_val,
goto exception;
if (done) // item is JS_UNDEFINED
break;
- rv = js_map_set(ctx, newset, 1, &item, MAGIC_SET);
+ rv = js_map_set(ctx, newset, 1, vc(&item), MAGIC_SET);
JS_FreeValue(ctx, item);
if (JS_IsException(rv))
goto exception;
@@ -48627,13 +48632,13 @@ typedef struct JSPromiseData {
JSPromiseStateEnum promise_state;
/* 0=fulfill, 1=reject, list of JSPromiseReactionData.link */
struct list_head promise_reactions[2];
- BOOL is_handled; /* Note: only useful to debug */
+ bool is_handled; /* Note: only useful to debug */
JSValue promise_result;
} JSPromiseData;
typedef struct JSPromiseFunctionDataResolved {
int ref_count;
- BOOL already_resolved;
+ bool already_resolved;
} JSPromiseFunctionDataResolved;
typedef struct JSPromiseFunctionData {
@@ -48647,7 +48652,7 @@ typedef struct JSPromiseReactionData {
JSValue handler;
} JSPromiseReactionData;
- JSPromiseStateEnum JS_PromiseState(JSContext *ctx, JSValue promise)
+JSPromiseStateEnum JS_PromiseState(JSContext *ctx, JSValueConst promise)
{
JSPromiseData *s = JS_GetOpaque(promise, JS_CLASS_PROMISE);
if (!s)
@@ -48655,16 +48660,23 @@ typedef struct JSPromiseReactionData {
return s->promise_state;
}
-JSValue JS_PromiseResult(JSContext *ctx, JSValue promise)
+JSValue JS_PromiseResult(JSContext *ctx, JSValueConst promise)
{
JSPromiseData *s = JS_GetOpaque(promise, JS_CLASS_PROMISE);
if (!s)
return JS_UNDEFINED;
- return JS_DupValue(ctx, s->promise_result);
+ return js_dup(s->promise_result);
+}
+
+bool JS_IsPromise(JSValueConst val)
+{
+ if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT)
+ return false;
+ return JS_VALUE_GET_OBJ(val)->class_id == JS_CLASS_PROMISE;
}
static int js_create_resolving_functions(JSContext *ctx, JSValue *args,
- JSValue promise);
+ JSValueConst promise);
static void promise_reaction_data_free(JSRuntime *rt,
JSPromiseReactionData *rd)
@@ -48675,10 +48687,10 @@ static void promise_reaction_data_free(JSRuntime *rt,
js_free_rt(rt, rd);
}
-#ifdef DUMP_PROMISE
+#ifdef ENABLE_DUMPS // JS_DUMP_PROMISE
#define promise_trace(ctx, ...) \
do { \
- if (check_dump_flag(ctx->rt, DUMP_PROMISE)) \
+ if (check_dump_flag(ctx->rt, JS_DUMP_PROMISE)) \
printf(__VA_ARGS__); \
} while (0)
#else
@@ -48686,11 +48698,12 @@ static void promise_reaction_data_free(JSRuntime *rt,
#endif
static JSValue promise_reaction_job(JSContext *ctx, int argc,
- JSValue *argv)
+ JSValueConst *argv)
{
- JSValue handler, arg, func;
+ JSValueConst handler, func;
JSValue res, res2;
- BOOL is_reject;
+ JSValueConst arg;
+ bool is_reject;
assert(argc == 5);
handler = argv[2];
@@ -48709,15 +48722,17 @@ static JSValue promise_reaction_job(JSContext *ctx, int argc,
res = JS_Call(ctx, handler, JS_UNDEFINED, 1, &arg);
}
is_reject = JS_IsException(res);
- if (is_reject)
+ if (is_reject) {
+ if (unlikely(JS_IsUncatchableError(ctx, ctx->rt->current_exception)))
+ return JS_EXCEPTION;
res = JS_GetException(ctx);
+ }
func = argv[is_reject];
/* as an extension, we support undefined as value to avoid
creating a dummy promise in the 'await' implementation of async
functions */
if (!JS_IsUndefined(func)) {
- res2 = JS_Call(ctx, func, JS_UNDEFINED,
- 1, &res);
+ res2 = JS_Call(ctx, func, JS_UNDEFINED, 1, vc(&res));
} else {
res2 = JS_UNDEFINED;
}
@@ -48734,13 +48749,13 @@ void JS_SetHostPromiseRejectionTracker(JSRuntime *rt,
rt->host_promise_rejection_tracker_opaque = opaque;
}
-static void fulfill_or_reject_promise(JSContext *ctx, JSValue promise,
- JSValue value, BOOL is_reject)
+static void fulfill_or_reject_promise(JSContext *ctx, JSValueConst promise,
+ JSValueConst value, bool is_reject)
{
JSPromiseData *s = JS_GetOpaque(promise, JS_CLASS_PROMISE);
struct list_head *el, *el1;
JSPromiseReactionData *rd;
- JSValue args[5];
+ JSValueConst args[5];
if (!s || s->promise_state != JS_PROMISE_PENDING)
return; /* should never happen */
@@ -48752,7 +48767,7 @@ static void fulfill_or_reject_promise(JSContext *ctx, JSValue promise,
if (s->promise_state == JS_PROMISE_REJECTED && !s->is_handled) {
JSRuntime *rt = ctx->rt;
if (rt->host_promise_rejection_tracker) {
- rt->host_promise_rejection_tracker(ctx, promise, value, FALSE,
+ rt->host_promise_rejection_tracker(ctx, promise, value, false,
rt->host_promise_rejection_tracker_opaque);
}
}
@@ -48776,16 +48791,16 @@ static void fulfill_or_reject_promise(JSContext *ctx, JSValue promise,
}
}
-static void reject_promise(JSContext *ctx, JSValue promise,
- JSValue value)
+static void reject_promise(JSContext *ctx, JSValueConst promise,
+ JSValueConst value)
{
- fulfill_or_reject_promise(ctx, promise, value, TRUE);
+ fulfill_or_reject_promise(ctx, promise, value, true);
}
static JSValue js_promise_resolve_thenable_job(JSContext *ctx,
- int argc, JSValue *argv)
+ int argc, JSValueConst *argv)
{
- JSValue promise, thenable, then;
+ JSValueConst promise, thenable, then;
JSValue args[2], res;
promise_trace(ctx, "js_promise_resolve_thenable_job\n");
@@ -48796,10 +48811,10 @@ static JSValue js_promise_resolve_thenable_job(JSContext *ctx,
then = argv[2];
if (js_create_resolving_functions(ctx, args, promise) < 0)
return JS_EXCEPTION;
- res = JS_Call(ctx, then, thenable, 2, args);
+ res = JS_Call(ctx, then, thenable, 2, vc(args));
if (JS_IsException(res)) {
JSValue error = JS_GetException(ctx);
- res = JS_Call(ctx, args[1], JS_UNDEFINED, 1, &error);
+ res = JS_Call(ctx, args[1], JS_UNDEFINED, 1, vc(&error));
JS_FreeValue(ctx, error);
}
JS_FreeValue(ctx, args[0]);
@@ -48817,7 +48832,7 @@ static void js_promise_resolve_function_free_resolved(JSRuntime *rt,
static int js_create_resolving_functions(JSContext *ctx,
JSValue *resolving_funcs,
- JSValue promise)
+ JSValueConst promise)
{
JSValue obj;
@@ -48829,7 +48844,7 @@ static int js_create_resolving_functions(JSContext *ctx,
if (!sr)
return -1;
sr->ref_count = 1;
- sr->already_resolved = FALSE; /* must be shared between the two functions */
+ sr->already_resolved = false; /* must be shared between the two functions */
ret = 0;
for(i = 0; i < 2; i++) {
obj = JS_NewObjectProtoClass(ctx, ctx->function_proto,
@@ -48857,7 +48872,8 @@ static int js_create_resolving_functions(JSContext *ctx,
return ret;
}
-static void js_promise_resolve_function_finalizer(JSRuntime *rt, JSValue val)
+static void js_promise_resolve_function_finalizer(JSRuntime *rt,
+ JSValueConst val)
{
JSPromiseFunctionData *s = JS_VALUE_GET_OBJ(val)->u.promise_function_data;
if (s) {
@@ -48867,7 +48883,7 @@ static void js_promise_resolve_function_finalizer(JSRuntime *rt, JSValue val)
}
}
-static void js_promise_resolve_function_mark(JSRuntime *rt, JSValue val,
+static void js_promise_resolve_function_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func)
{
JSPromiseFunctionData *s = JS_VALUE_GET_OBJ(val)->u.promise_function_data;
@@ -48877,28 +48893,29 @@ static void js_promise_resolve_function_mark(JSRuntime *rt, JSValue val,
}
static JSValue js_promise_resolve_function_call(JSContext *ctx,
- JSValue func_obj,
- JSValue this_val,
- int argc, JSValue *argv,
+ JSValueConst func_obj,
+ JSValueConst this_val,
+ int argc, JSValueConst *argv,
int flags)
{
JSObject *p = JS_VALUE_GET_OBJ(func_obj);
JSPromiseFunctionData *s;
- JSValue resolution, args[3];
+ JSValueConst args[3];
+ JSValueConst resolution;
JSValue then;
- BOOL is_reject;
+ bool is_reject;
s = p->u.promise_function_data;
if (!s || s->presolved->already_resolved)
return JS_UNDEFINED;
- s->presolved->already_resolved = TRUE;
+ s->presolved->already_resolved = true;
is_reject = p->class_id - JS_CLASS_PROMISE_RESOLVE_FUNCTION;
if (argc > 0)
resolution = argv[0];
else
resolution = JS_UNDEFINED;
-#ifdef DUMP_PROMISE
- if (check_dump_flag(ctx->rt, DUMP_PROMISE)) {
+#ifdef ENABLE_DUMPS // JS_DUMP_PROMISE
+ if (check_dump_flag(ctx->rt, JS_DUMP_PROMISE)) {
printf("js_promise_resolving_function_call: is_reject=%d resolution=", is_reject);
JS_DumpValue(ctx->rt, resolution);
printf("\n");
@@ -48931,7 +48948,7 @@ static JSValue js_promise_resolve_function_call(JSContext *ctx,
return JS_UNDEFINED;
}
-static void js_promise_finalizer(JSRuntime *rt, JSValue val)
+static void js_promise_finalizer(JSRuntime *rt, JSValueConst val)
{
JSPromiseData *s = JS_GetOpaque(val, JS_CLASS_PROMISE);
struct list_head *el, *el1;
@@ -48950,7 +48967,7 @@ static void js_promise_finalizer(JSRuntime *rt, JSValue val)
js_free_rt(rt, s);
}
-static void js_promise_mark(JSRuntime *rt, JSValue val,
+static void js_promise_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func)
{
JSPromiseData *s = JS_GetOpaque(val, JS_CLASS_PROMISE);
@@ -48971,10 +48988,10 @@ static void js_promise_mark(JSRuntime *rt, JSValue val,
JS_MarkValue(rt, s->promise_result, mark_func);
}
-static JSValue js_promise_constructor(JSContext *ctx, JSValue new_target,
- int argc, JSValue *argv)
+static JSValue js_promise_constructor(JSContext *ctx, JSValueConst new_target,
+ int argc, JSValueConst *argv)
{
- JSValue executor;
+ JSValueConst executor;
JSValue obj;
JSPromiseData *s;
JSValue args[2], ret;
@@ -48990,18 +49007,18 @@ static JSValue js_promise_constructor(JSContext *ctx, JSValue new_target,
if (!s)
goto fail;
s->promise_state = JS_PROMISE_PENDING;
- s->is_handled = FALSE;
+ s->is_handled = false;
for(i = 0; i < 2; i++)
init_list_head(&s->promise_reactions[i]);
s->promise_result = JS_UNDEFINED;
JS_SetOpaqueInternal(obj, s);
if (js_create_resolving_functions(ctx, args, obj))
goto fail;
- ret = JS_Call(ctx, executor, JS_UNDEFINED, 2, args);
+ ret = JS_Call(ctx, executor, JS_UNDEFINED, 2, vc(args));
if (JS_IsException(ret)) {
JSValue ret2, error;
error = JS_GetException(ctx);
- ret2 = JS_Call(ctx, args[1], JS_UNDEFINED, 1, &error);
+ ret2 = JS_Call(ctx, args[1], JS_UNDEFINED, 1, vc(&error));
JS_FreeValue(ctx, error);
if (JS_IsException(ret2))
goto fail1;
@@ -49020,9 +49037,9 @@ static JSValue js_promise_constructor(JSContext *ctx, JSValue new_target,
}
static JSValue js_promise_executor(JSContext *ctx,
- JSValue this_val,
- int argc, JSValue *argv,
- int magic, JSValue *func_data)
+ JSValueConst this_val,
+ int argc, JSValueConst *argv,
+ int magic, JSValueConst *func_data)
{
int i;
@@ -49036,7 +49053,7 @@ static JSValue js_promise_executor(JSContext *ctx,
static JSValue js_promise_executor_new(JSContext *ctx)
{
- JSValue func_data[2];
+ JSValueConst func_data[2];
func_data[0] = JS_UNDEFINED;
func_data[1] = JS_UNDEFINED;
@@ -49046,7 +49063,7 @@ static JSValue js_promise_executor_new(JSContext *ctx)
static JSValue js_new_promise_capability(JSContext *ctx,
JSValue *resolving_funcs,
- JSValue ctor)
+ JSValueConst ctor)
{
JSValue executor, result_promise;
JSCFunctionDataRecord *s;
@@ -49057,11 +49074,9 @@ static JSValue js_new_promise_capability(JSContext *ctx,
return executor;
if (JS_IsUndefined(ctor)) {
- result_promise = js_promise_constructor(ctx, ctor, 1,
- &executor);
+ result_promise = js_promise_constructor(ctx, ctor, 1, vc(&executor));
} else {
- result_promise = JS_CallConstructor(ctx, ctor, 1,
- &executor);
+ result_promise = JS_CallConstructor(ctx, ctor, 1, vc(&executor));
}
if (JS_IsException(result_promise))
goto fail;
@@ -49085,17 +49100,17 @@ JSValue JS_NewPromiseCapability(JSContext *ctx, JSValue *resolving_funcs)
return js_new_promise_capability(ctx, resolving_funcs, JS_UNDEFINED);
}
-static JSValue js_promise_resolve(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue js_promise_resolve(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
JSValue result_promise, resolving_funcs[2], ret;
- BOOL is_reject = magic;
+ bool is_reject = magic;
if (!JS_IsObject(this_val))
return JS_ThrowTypeErrorNotAnObject(ctx);
if (!is_reject && JS_GetOpaque(argv[0], JS_CLASS_PROMISE)) {
JSValue ctor;
- BOOL is_same;
+ bool is_same;
ctor = JS_GetProperty(ctx, argv[0], JS_ATOM_constructor);
if (JS_IsException(ctor))
return ctor;
@@ -49118,8 +49133,8 @@ static JSValue js_promise_resolve(JSContext *ctx, JSValue this_val,
return result_promise;
}
-static JSValue js_promise_withResolvers(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_promise_withResolvers(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue result_promise, resolving_funcs[2], obj;
if (!JS_IsObject(this_val))
@@ -49140,11 +49155,11 @@ static JSValue js_promise_withResolvers(JSContext *ctx, JSValue this_val,
return obj;
}
-static JSValue js_promise_try(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_promise_try(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue result_promise, resolving_funcs[2], ret, ret2;
- BOOL is_reject = 0;
+ bool is_reject = 0;
if (!JS_IsObject(this_val))
return JS_ThrowTypeErrorNotAnObject(ctx);
@@ -49156,7 +49171,7 @@ static JSValue js_promise_try(JSContext *ctx, JSValue this_val,
is_reject = 1;
ret = JS_GetException(ctx);
}
- ret2 = JS_Call(ctx, resolving_funcs[is_reject], JS_UNDEFINED, 1, &ret);
+ ret2 = JS_Call(ctx, resolving_funcs[is_reject], JS_UNDEFINED, 1, vc(&ret));
JS_FreeValue(ctx, resolving_funcs[0]);
JS_FreeValue(ctx, resolving_funcs[1]);
JS_FreeValue(ctx, ret);
@@ -49169,7 +49184,7 @@ static JSValue js_promise_try(JSContext *ctx, JSValue this_val,
}
static __exception int remainingElementsCount_add(JSContext *ctx,
- JSValue resolve_element_env,
+ JSValueConst resolve_element_env,
int addend)
{
JSValue val;
@@ -49192,17 +49207,17 @@ static __exception int remainingElementsCount_add(JSContext *ctx,
#define PROMISE_MAGIC_any 2
static JSValue js_promise_all_resolve_element(JSContext *ctx,
- JSValue this_val,
- int argc, JSValue *argv,
+ JSValueConst this_val,
+ int argc, JSValueConst *argv,
int magic,
- JSValue *func_data)
+ JSValueConst *func_data)
{
int resolve_type = magic & 3;
int is_reject = magic & 4;
- BOOL alreadyCalled = JS_ToBool(ctx, func_data[0]);
- JSValue values = func_data[2];
- JSValue resolve = func_data[3];
- JSValue resolve_element_env = func_data[4];
+ bool alreadyCalled = JS_ToBool(ctx, func_data[0]);
+ JSValueConst values = func_data[2];
+ JSValueConst resolve = func_data[3];
+ JSValueConst resolve_element_env = func_data[4];
JSValue ret, obj;
int is_zero, index;
@@ -49210,7 +49225,7 @@ static JSValue js_promise_all_resolve_element(JSContext *ctx,
return JS_EXCEPTION;
if (alreadyCalled)
return JS_UNDEFINED;
- func_data[0] = js_bool(TRUE);
+ func_data[0] = JS_TRUE;
if (resolve_type == PROMISE_MAGIC_allSettled) {
JSValue str;
@@ -49249,7 +49264,7 @@ static JSValue js_promise_all_resolve_element(JSContext *ctx,
error = js_aggregate_error_constructor(ctx, values);
if (JS_IsException(error))
return JS_EXCEPTION;
- ret = JS_Call(ctx, resolve, JS_UNDEFINED, 1, &error);
+ ret = JS_Call(ctx, resolve, JS_UNDEFINED, 1, vc(&error));
JS_FreeValue(ctx, error);
} else {
ret = JS_Call(ctx, resolve, JS_UNDEFINED, 1, &values);
@@ -49262,16 +49277,15 @@ static JSValue js_promise_all_resolve_element(JSContext *ctx,
}
/* magic = 0: Promise.all 1: Promise.allSettled */
-static JSValue js_promise_all(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue js_promise_all(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
JSValue result_promise, resolving_funcs[2], item, next_promise, ret;
JSValue next_method = JS_UNDEFINED, values = JS_UNDEFINED;
JSValue resolve_element_env = JS_UNDEFINED, resolve_element, reject_element;
JSValue promise_resolve = JS_UNDEFINED, iter = JS_UNDEFINED;
- JSValue then_args[2], resolve_element_data[5];
- BOOL done;
- int index, is_zero, is_promise_any = (magic == PROMISE_MAGIC_any);
+ JSValueConst then_args[2], resolve_element_data[5];
+ int done, index, is_zero, is_promise_any = (magic == PROMISE_MAGIC_any);
if (!JS_IsObject(this_val))
return JS_ThrowTypeErrorNotAnObject(ctx);
@@ -49282,13 +49296,12 @@ static JSValue js_promise_all(JSContext *ctx, JSValue this_val,
if (JS_IsException(promise_resolve) ||
check_function(ctx, promise_resolve))
goto fail_reject;
- iter = JS_GetIterator(ctx, argv[0], FALSE);
+ iter = JS_GetIterator(ctx, argv[0], false);
if (JS_IsException(iter)) {
JSValue error;
fail_reject:
error = JS_GetException(ctx);
- ret = JS_Call(ctx, resolving_funcs[1], JS_UNDEFINED, 1,
- &error);
+ ret = JS_Call(ctx, resolving_funcs[1], JS_UNDEFINED, 1, vc(&error));
JS_FreeValue(ctx, error);
if (JS_IsException(ret))
goto fail;
@@ -49319,14 +49332,14 @@ static JSValue js_promise_all(JSContext *ctx, JSValue this_val,
if (done)
break;
next_promise = JS_Call(ctx, promise_resolve,
- this_val, 1, &item);
+ this_val, 1, vc(&item));
JS_FreeValue(ctx, item);
if (JS_IsException(next_promise)) {
fail_reject1:
- JS_IteratorClose(ctx, iter, TRUE);
+ JS_IteratorClose(ctx, iter, true);
goto fail_reject;
}
- resolve_element_data[0] = js_bool(FALSE);
+ resolve_element_data[0] = JS_FALSE;
resolve_element_data[1] = js_int32(index);
resolve_element_data[2] = values;
resolve_element_data[3] = resolving_funcs[is_promise_any];
@@ -49387,7 +49400,7 @@ static JSValue js_promise_all(JSContext *ctx, JSValue this_val,
values = error;
}
ret = JS_Call(ctx, resolving_funcs[is_promise_any], JS_UNDEFINED,
- 1, &values);
+ 1, vc(&values));
if (check_exception_free(ctx, ret))
goto fail_reject;
}
@@ -49407,13 +49420,13 @@ static JSValue js_promise_all(JSContext *ctx, JSValue this_val,
goto done;
}
-static JSValue js_promise_race(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_promise_race(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue result_promise, resolving_funcs[2], item, next_promise, ret;
JSValue next_method = JS_UNDEFINED, iter = JS_UNDEFINED;
JSValue promise_resolve = JS_UNDEFINED;
- BOOL done;
+ int done;
if (!JS_IsObject(this_val))
return JS_ThrowTypeErrorNotAnObject(ctx);
@@ -49424,13 +49437,12 @@ static JSValue js_promise_race(JSContext *ctx, JSValue this_val,
if (JS_IsException(promise_resolve) ||
check_function(ctx, promise_resolve))
goto fail_reject;
- iter = JS_GetIterator(ctx, argv[0], FALSE);
+ iter = JS_GetIterator(ctx, argv[0], false);
if (JS_IsException(iter)) {
JSValue error;
fail_reject:
error = JS_GetException(ctx);
- ret = JS_Call(ctx, resolving_funcs[1], JS_UNDEFINED, 1,
- &error);
+ ret = JS_Call(ctx, resolving_funcs[1], JS_UNDEFINED, 1, vc(&error));
JS_FreeValue(ctx, error);
if (JS_IsException(ret))
goto fail;
@@ -49449,15 +49461,15 @@ static JSValue js_promise_race(JSContext *ctx, JSValue this_val,
if (done)
break;
next_promise = JS_Call(ctx, promise_resolve,
- this_val, 1, &item);
+ this_val, 1, vc(&item));
JS_FreeValue(ctx, item);
if (JS_IsException(next_promise)) {
fail_reject1:
- JS_IteratorClose(ctx, iter, TRUE);
+ JS_IteratorClose(ctx, iter, true);
goto fail_reject;
}
ret = JS_InvokeFree(ctx, next_promise, JS_ATOM_then, 2,
- resolving_funcs);
+ vc(resolving_funcs));
if (check_exception_free(ctx, ret))
goto fail_reject1;
}
@@ -49477,9 +49489,9 @@ static JSValue js_promise_race(JSContext *ctx, JSValue this_val,
}
static __exception int perform_promise_then(JSContext *ctx,
- JSValue promise,
- JSValue *resolve_reject,
- JSValue *cap_resolving_funcs)
+ JSValueConst promise,
+ JSValueConst *resolve_reject,
+ JSValueConst *cap_resolving_funcs)
{
JSPromiseData *s = JS_GetOpaque(promise, JS_CLASS_PROMISE);
JSPromiseReactionData *rd_array[2], *rd;
@@ -49488,7 +49500,7 @@ static __exception int perform_promise_then(JSContext *ctx,
rd_array[0] = NULL;
rd_array[1] = NULL;
for(i = 0; i < 2; i++) {
- JSValue handler;
+ JSValueConst handler;
rd = js_mallocz(ctx, sizeof(*rd));
if (!rd) {
if (i == 1)
@@ -49508,12 +49520,12 @@ static __exception int perform_promise_then(JSContext *ctx,
for(i = 0; i < 2; i++)
list_add_tail(&rd_array[i]->link, &s->promise_reactions[i]);
} else {
- JSValue args[5];
+ JSValueConst args[5];
if (s->promise_state == JS_PROMISE_REJECTED && !s->is_handled) {
JSRuntime *rt = ctx->rt;
if (rt->host_promise_rejection_tracker) {
rt->host_promise_rejection_tracker(ctx, promise, s->promise_result,
- TRUE, rt->host_promise_rejection_tracker_opaque);
+ true, rt->host_promise_rejection_tracker_opaque);
}
}
i = s->promise_state - JS_PROMISE_FULFILLED;
@@ -49527,12 +49539,12 @@ static __exception int perform_promise_then(JSContext *ctx,
for(i = 0; i < 2; i++)
promise_reaction_data_free(ctx->rt, rd_array[i]);
}
- s->is_handled = TRUE;
+ s->is_handled = true;
return 0;
}
-static JSValue js_promise_then(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_promise_then(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue ctor, result_promise, resolving_funcs[2];
JSPromiseData *s;
@@ -49549,8 +49561,7 @@ static JSValue js_promise_then(JSContext *ctx, JSValue this_val,
JS_FreeValue(ctx, ctor);
if (JS_IsException(result_promise))
return result_promise;
- ret = perform_promise_then(ctx, this_val, argv,
- resolving_funcs);
+ ret = perform_promise_then(ctx, this_val, argv, vc(resolving_funcs));
for(i = 0; i < 2; i++)
JS_FreeValue(ctx, resolving_funcs[i]);
if (ret) {
@@ -49560,41 +49571,41 @@ static JSValue js_promise_then(JSContext *ctx, JSValue this_val,
return result_promise;
}
-static JSValue js_promise_catch(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_promise_catch(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
- JSValue args[2];
+ JSValueConst args[2];
args[0] = JS_UNDEFINED;
args[1] = argv[0];
return JS_Invoke(ctx, this_val, JS_ATOM_then, 2, args);
}
-static JSValue js_promise_finally_value_thunk(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv,
- int magic, JSValue *func_data)
+static JSValue js_promise_finally_value_thunk(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv,
+ int magic, JSValueConst *func_data)
{
return js_dup(func_data[0]);
}
-static JSValue js_promise_finally_thrower(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv,
- int magic, JSValue *func_data)
+static JSValue js_promise_finally_thrower(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv,
+ int magic, JSValueConst *func_data)
{
return JS_Throw(ctx, js_dup(func_data[0]));
}
-static JSValue js_promise_then_finally_func(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv,
- int magic, JSValue *func_data)
+static JSValue js_promise_then_finally_func(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv,
+ int magic, JSValueConst *func_data)
{
- JSValue ctor = func_data[0];
- JSValue onFinally = func_data[1];
+ JSValueConst ctor = func_data[0];
+ JSValueConst onFinally = func_data[1];
JSValue res, promise, ret, then_func;
res = JS_Call(ctx, onFinally, JS_UNDEFINED, 0, NULL);
if (JS_IsException(res))
return res;
- promise = js_promise_resolve(ctx, ctor, 1, &res, 0);
+ promise = js_promise_resolve(ctx, ctor, 1, vc(&res), 0);
JS_FreeValue(ctx, res);
if (JS_IsException(promise))
return promise;
@@ -49609,18 +49620,18 @@ static JSValue js_promise_then_finally_func(JSContext *ctx, JSValue this_val,
JS_FreeValue(ctx, promise);
return then_func;
}
- ret = JS_InvokeFree(ctx, promise, JS_ATOM_then, 1, &then_func);
+ ret = JS_InvokeFree(ctx, promise, JS_ATOM_then, 1, vc(&then_func));
JS_FreeValue(ctx, then_func);
return ret;
}
-static JSValue js_promise_finally(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_promise_finally(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
- JSValue onFinally = argv[0];
+ JSValueConst onFinally = argv[0];
JSValue ctor, ret;
JSValue then_funcs[2];
- JSValue func_data[2];
+ JSValueConst func_data[2];
int i;
ctor = JS_SpeciesConstructor(ctx, this_val, JS_UNDEFINED);
@@ -49643,7 +49654,7 @@ static JSValue js_promise_finally(JSContext *ctx, JSValue this_val,
}
}
JS_FreeValue(ctx, ctor);
- ret = JS_Invoke(ctx, this_val, JS_ATOM_then, 2, then_funcs);
+ ret = JS_Invoke(ctx, this_val, JS_ATOM_then, 2, vc(then_funcs));
JS_FreeValue(ctx, then_funcs[0]);
JS_FreeValue(ctx, then_funcs[1]);
return ret;
@@ -49674,18 +49685,18 @@ static const JSCFunctionListEntry js_async_function_proto_funcs[] = {
};
static JSValue js_async_from_sync_iterator_unwrap(JSContext *ctx,
- JSValue this_val,
- int argc, JSValue *argv,
- int magic, JSValue *func_data)
+ JSValueConst this_val,
+ int argc, JSValueConst *argv,
+ int magic, JSValueConst *func_data)
{
return js_create_iterator_result(ctx, js_dup(argv[0]),
JS_ToBool(ctx, func_data[0]));
}
static JSValue js_async_from_sync_iterator_unwrap_func_create(JSContext *ctx,
- BOOL done)
+ bool done)
{
- JSValue func_data[1];
+ JSValueConst func_data[1];
func_data[0] = js_bool(done);
return JS_NewCFunctionData(ctx, js_async_from_sync_iterator_unwrap,
@@ -49705,7 +49716,8 @@ typedef struct JSAsyncFromSyncIteratorData {
JSValue next_method;
} JSAsyncFromSyncIteratorData;
-static void js_async_from_sync_iterator_finalizer(JSRuntime *rt, JSValue val)
+static void js_async_from_sync_iterator_finalizer(JSRuntime *rt,
+ JSValueConst val)
{
JSAsyncFromSyncIteratorData *s =
JS_GetOpaque(val, JS_CLASS_ASYNC_FROM_SYNC_ITERATOR);
@@ -49716,7 +49728,7 @@ static void js_async_from_sync_iterator_finalizer(JSRuntime *rt, JSValue val)
}
}
-static void js_async_from_sync_iterator_mark(JSRuntime *rt, JSValue val,
+static void js_async_from_sync_iterator_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func)
{
JSAsyncFromSyncIteratorData *s =
@@ -49753,8 +49765,8 @@ static JSValue JS_CreateAsyncFromSyncIterator(JSContext *ctx,
return async_iter;
}
-static JSValue js_async_from_sync_iterator_next(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv,
+static JSValue js_async_from_sync_iterator_next(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv,
int magic)
{
JSValue promise, resolving_funcs[2], value, err, method;
@@ -49781,11 +49793,11 @@ static JSValue js_async_from_sync_iterator_next(JSContext *ctx, JSValue this_val
goto reject;
if (JS_IsUndefined(method) || JS_IsNull(method)) {
if (magic == GEN_MAGIC_RETURN) {
- err = js_create_iterator_result(ctx, js_dup(argv[0]), TRUE);
+ err = js_create_iterator_result(ctx, js_dup(argv[0]), true);
is_reject = 0;
} else {
err = JS_MakeError(ctx, JS_TYPE_ERROR, "throw is not a method",
- TRUE);
+ true);
is_reject = 1;
}
goto done_resolve;
@@ -49811,7 +49823,7 @@ static JSValue js_async_from_sync_iterator_next(JSContext *ctx, JSValue this_val
is_reject = 1;
done_resolve:
res2 = JS_Call(ctx, resolving_funcs[is_reject], JS_UNDEFINED,
- 1, &err);
+ 1, vc(&err));
JS_FreeValue(ctx, err);
JS_FreeValue(ctx, res2);
JS_FreeValue(ctx, resolving_funcs[0]);
@@ -49823,7 +49835,7 @@ static JSValue js_async_from_sync_iterator_next(JSContext *ctx, JSValue this_val
int res;
value_wrapper_promise = js_promise_resolve(ctx, ctx->promise_ctor,
- 1, &value, 0);
+ 1, vc(&value), 0);
if (JS_IsException(value_wrapper_promise)) {
JS_FreeValue(ctx, value);
goto reject;
@@ -49839,8 +49851,8 @@ static JSValue js_async_from_sync_iterator_next(JSContext *ctx, JSValue this_val
resolve_reject[1] = JS_UNDEFINED;
res = perform_promise_then(ctx, value_wrapper_promise,
- resolve_reject,
- resolving_funcs);
+ vc(resolve_reject),
+ vc(resolving_funcs));
JS_FreeValue(ctx, resolve_reject[0]);
JS_FreeValue(ctx, value_wrapper_promise);
JS_FreeValue(ctx, resolving_funcs[0]);
@@ -49998,7 +50010,7 @@ static int isURIReserved(int c) {
return c < 0x100 && memchr(";/?:@&=+$,#", c, sizeof(";/?:@&=+$,#") - 1) != NULL;
}
-static int __attribute__((format(printf, 2, 3))) js_throw_URIError(JSContext *ctx, const char *fmt, ...)
+static int JS_PRINTF_FORMAT_ATTR(2, 3) js_throw_URIError(JSContext *ctx, JS_PRINTF_FORMAT const char *fmt, ...)
{
va_list ap;
@@ -50019,8 +50031,8 @@ static int hex_decode(JSContext *ctx, JSString *p, int k) {
return c;
}
-static JSValue js_global_decodeURI(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int isComponent)
+static JSValue js_global_decodeURI(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int isComponent)
{
JSValue str;
StringBuffer b_s, *b = &b_s;
@@ -50130,8 +50142,8 @@ static int encodeURI_hex(StringBuffer *b, int c) {
return string_buffer_write8(b, buf, n);
}
-static JSValue js_global_encodeURI(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv,
+static JSValue js_global_encodeURI(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv,
int isComponent)
{
JSValue str;
@@ -50195,8 +50207,8 @@ fail:
return JS_EXCEPTION;
}
-static JSValue js_global_escape(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_global_escape(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue str;
StringBuffer b_s, *b = &b_s;
@@ -50221,8 +50233,8 @@ static JSValue js_global_escape(JSContext *ctx, JSValue this_val,
return string_buffer_end(b);
}
-static JSValue js_global_unescape(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_global_unescape(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue str;
StringBuffer b_s, *b = &b_s;
@@ -50291,10 +50303,11 @@ static int64_t floor_div_int64(int64_t a, int64_t b) {
return (a - (m + (m < 0) * b)) / b;
}
-static JSValue js_Date_parse(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv);
+static JSValue js_Date_parse(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv);
-static __exception int JS_ThisTimeValue(JSContext *ctx, double *valp, JSValue this_val)
+static __exception int JS_ThisTimeValue(JSContext *ctx, double *valp,
+ JSValueConst this_val)
{
if (JS_VALUE_GET_TAG(this_val) == JS_TAG_OBJECT) {
JSObject *p = JS_VALUE_GET_OBJ(this_val);
@@ -50305,7 +50318,7 @@ static __exception int JS_ThisTimeValue(JSContext *ctx, double *valp, JSValue th
return -1;
}
-static JSValue JS_SetThisTimeValue(JSContext *ctx, JSValue this_val, double v)
+static JSValue JS_SetThisTimeValue(JSContext *ctx, JSValueConst this_val, double v)
{
if (JS_VALUE_GET_TAG(this_val) == JS_TAG_OBJECT) {
JSObject *p = JS_VALUE_GET_OBJ(this_val);
@@ -50354,7 +50367,7 @@ static int const month_days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
static char const month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
static char const day_names[] = "SunMonTueWedThuFriSat";
-static __exception int get_date_fields(JSContext *ctx, JSValue obj,
+static __exception int get_date_fields(JSContext *ctx, JSValueConst obj,
double fields[minimum_length(9)],
int is_local, int force)
{
@@ -50366,7 +50379,7 @@ static __exception int get_date_fields(JSContext *ctx, JSValue obj,
if (isnan(dval)) {
if (!force)
- return FALSE; /* NaN */
+ return false; /* NaN */
d = 0; /* initialize all fields to 0 */
} else {
d = dval; /* assuming -8.64e15 <= dval <= -8.64e15 */
@@ -50405,7 +50418,7 @@ static __exception int get_date_fields(JSContext *ctx, JSValue obj,
fields[6] = ms;
fields[7] = wd;
fields[8] = tz;
- return TRUE;
+ return true;
}
static double time_clip(double t) {
@@ -50474,8 +50487,8 @@ static double set_date_fields(double fields[minimum_length(7)], int is_local) {
return time_clip(tv);
}
-static JSValue get_date_field(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue get_date_field(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
// get_date_field(obj, n, is_local)
double fields[9];
@@ -50495,8 +50508,8 @@ static JSValue get_date_field(JSContext *ctx, JSValue this_val,
return js_number(fields[n]);
}
-static JSValue set_date_field(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue set_date_field(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
// _field(obj, first_field, end_field, args, is_local)
double fields[9];
@@ -50518,7 +50531,7 @@ static JSValue set_date_field(JSContext *ctx, JSValue this_val,
if (JS_ToFloat64(ctx, &a, argv[i]))
return JS_EXCEPTION;
if (!isfinite(a))
- res = FALSE;
+ res = false;
fields[first_field + i] = trunc(a);
}
@@ -50539,8 +50552,8 @@ static JSValue set_date_field(JSContext *ctx, JSValue this_val,
part: 1=date, 2=time 3=all
XXX: should use a variant of strftime().
*/
-static JSValue get_date_string(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue get_date_string(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
// _string(obj, fmt, part)
char buf[64];
@@ -50654,8 +50667,8 @@ static int64_t date_now(void) {
return js__gettimeofday_us() / 1000;
}
-static JSValue js_date_constructor(JSContext *ctx, JSValue new_target,
- int argc, JSValue *argv)
+static JSValue js_date_constructor(JSContext *ctx, JSValueConst new_target,
+ int argc, JSValueConst *argv)
{
// Date(y, mon, d, h, m, s, ms)
JSValue rv;
@@ -50682,7 +50695,7 @@ static JSValue js_date_constructor(JSContext *ctx, JSValue new_target,
}
v = JS_ToPrimitive(ctx, argv[0], HINT_NONE);
if (JS_IsString(v)) {
- dv = js_Date_parse(ctx, JS_UNDEFINED, 1, &v);
+ dv = js_Date_parse(ctx, JS_UNDEFINED, 1, vc(&v));
JS_FreeValue(ctx, v);
if (JS_IsException(dv))
return JS_EXCEPTION;
@@ -50722,8 +50735,8 @@ has_val:
return rv;
}
-static JSValue js_Date_UTC(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_Date_UTC(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
// UTC(y, mon, d, h, m, s, ms)
double fields[] = { 0, 0, 1, 0, 0, 0, 0 };
@@ -50749,12 +50762,12 @@ static JSValue js_Date_UTC(JSContext *ctx, JSValue this_val,
/* Date string parsing */
-static BOOL string_skip_char(const uint8_t *sp, int *pp, int c) {
+static bool string_skip_char(const uint8_t *sp, int *pp, int c) {
if (sp[*pp] == c) {
*pp += 1;
- return TRUE;
+ return true;
} else {
- return FALSE;
+ return false;
}
}
@@ -50783,7 +50796,7 @@ static int string_skip_until(const uint8_t *sp, int *pp, const char *stoplist) {
}
/* parse a numeric field (max_digits = 0 -> no maximum) */
-static BOOL string_get_digits(const uint8_t *sp, int *pp, int *pval,
+static bool string_get_digits(const uint8_t *sp, int *pp, int *pval,
int min_digits, int max_digits)
{
int v = 0;
@@ -50797,13 +50810,13 @@ static BOOL string_get_digits(const uint8_t *sp, int *pp, int *pval,
break;
}
if (p - p_start < min_digits)
- return FALSE;
+ return false;
*pval = v;
*pp = p;
- return TRUE;
+ return true;
}
-static BOOL string_get_milliseconds(const uint8_t *sp, int *pp, int *pval) {
+static bool string_get_milliseconds(const uint8_t *sp, int *pp, int *pval) {
/* parse optional fractional part as milliseconds and truncate. */
/* spec does not indicate which rounding should be used */
int mul = 100, ms = 0, c, p_start, p = *pp;
@@ -50825,20 +50838,20 @@ static BOOL string_get_milliseconds(const uint8_t *sp, int *pp, int *pval) {
*pp = p;
}
}
- return TRUE;
+ return true;
}
-static BOOL string_get_tzoffset(const uint8_t *sp, int *pp, int *tzp, BOOL strict) {
+static bool string_get_tzoffset(const uint8_t *sp, int *pp, int *tzp, bool strict) {
int tz = 0, sgn, hh, mm, p = *pp;
sgn = sp[p++];
if (sgn == '+' || sgn == '-') {
int n = p;
if (!string_get_digits(sp, &p, &hh, 1, 9))
- return FALSE;
+ return false;
n = p - n;
if (strict && n != 2 && n != 4)
- return FALSE;
+ return false;
while (n > 4) {
n -= 2;
hh /= 100;
@@ -50850,31 +50863,31 @@ static BOOL string_get_tzoffset(const uint8_t *sp, int *pp, int *tzp, BOOL stric
mm = 0;
if (string_skip_char(sp, &p, ':') /* optional separator */
&& !string_get_digits(sp, &p, &mm, 2, 2))
- return FALSE;
+ return false;
}
if (hh > 23 || mm > 59)
- return FALSE;
+ return false;
tz = hh * 60 + mm;
if (sgn != '+')
tz = -tz;
} else
if (sgn != 'Z') {
- return FALSE;
+ return false;
}
*pp = p;
*tzp = tz;
- return TRUE;
+ return true;
}
-static BOOL string_match(const uint8_t *sp, int *pp, const char *s) {
+static bool string_match(const uint8_t *sp, int *pp, const char *s) {
int p = *pp;
while (*s != '\0') {
if (to_upper_ascii(sp[p]) != to_upper_ascii(*s++))
- return FALSE;
+ return false;
p++;
}
*pp = p;
- return TRUE;
+ return true;
}
static int find_abbrev(const uint8_t *sp, int p, const char *list, int count) {
@@ -50891,75 +50904,75 @@ static int find_abbrev(const uint8_t *sp, int p, const char *list, int count) {
return -1;
}
-static BOOL string_get_month(const uint8_t *sp, int *pp, int *pval) {
+static bool string_get_month(const uint8_t *sp, int *pp, int *pval) {
int n;
n = find_abbrev(sp, *pp, month_names, 12);
if (n < 0)
- return FALSE;
+ return false;
*pval = n + 1;
*pp += 3;
- return TRUE;
+ return true;
}
/* parse toISOString format */
-static BOOL js_date_parse_isostring(const uint8_t *sp, int fields[9], BOOL *is_local) {
+static bool js_date_parse_isostring(const uint8_t *sp, int fields[9], bool *is_local) {
int sgn, i, p = 0;
/* initialize fields to the beginning of the Epoch */
for (i = 0; i < 9; i++) {
fields[i] = (i == 2);
}
- *is_local = FALSE;
+ *is_local = false;
/* year is either yyyy digits or [+-]yyyyyy */
sgn = sp[p];
if (sgn == '-' || sgn == '+') {
p++;
if (!string_get_digits(sp, &p, &fields[0], 6, 6))
- return FALSE;
+ return false;
if (sgn == '-') {
if (fields[0] == 0)
- return FALSE; // reject -000000
+ return false; // reject -000000
fields[0] = -fields[0];
}
} else {
if (!string_get_digits(sp, &p, &fields[0], 4, 4))
- return FALSE;
+ return false;
}
if (string_skip_char(sp, &p, '-')) {
if (!string_get_digits(sp, &p, &fields[1], 2, 2)) /* month */
- return FALSE;
+ return false;
if (fields[1] < 1)
- return FALSE;
+ return false;
fields[1] -= 1;
if (string_skip_char(sp, &p, '-')) {
if (!string_get_digits(sp, &p, &fields[2], 2, 2)) /* day */
- return FALSE;
+ return false;
if (fields[2] < 1)
- return FALSE;
+ return false;
}
}
if (string_skip_char(sp, &p, 'T')) {
- *is_local = TRUE;
+ *is_local = true;
if (!string_get_digits(sp, &p, &fields[3], 2, 2) /* hour */
|| !string_skip_char(sp, &p, ':')
|| !string_get_digits(sp, &p, &fields[4], 2, 2)) { /* minute */
fields[3] = 100; // reject unconditionally
- return TRUE;
+ return true;
}
if (string_skip_char(sp, &p, ':')) {
if (!string_get_digits(sp, &p, &fields[5], 2, 2)) /* second */
- return FALSE;
+ return false;
string_get_milliseconds(sp, &p, &fields[6]);
}
}
/* parse the time zone offset if present: [+-]HH:mm or [+-]HHmm */
if (sp[p]) {
- *is_local = FALSE;
- if (!string_get_tzoffset(sp, &p, &fields[8], TRUE))
- return FALSE;
+ *is_local = false;
+ if (!string_get_tzoffset(sp, &p, &fields[8], true))
+ return false;
}
/* error if extraneous characters */
return sp[p] == '\0';
@@ -50989,27 +51002,27 @@ static struct {
{ "EEST", +3 * 60 }, // Eastern European Summer Time
};
-static BOOL string_get_tzabbr(const uint8_t *sp, int *pp, int *offset) {
+static bool string_get_tzabbr(const uint8_t *sp, int *pp, int *offset) {
size_t i;
for (i = 0; i < countof(js_tzabbr); i++) {
if (string_match(sp, pp, js_tzabbr[i].name)) {
*offset = js_tzabbr[i].offset;
- return TRUE;
+ return true;
}
}
- return FALSE;
+ return false;
}
/* parse toString, toUTCString and other formats */
-static BOOL js_date_parse_otherstring(const uint8_t *sp,
+static bool js_date_parse_otherstring(const uint8_t *sp,
int fields[minimum_length(9)],
- BOOL *is_local) {
+ bool *is_local) {
int c, i, val, p = 0, p_start;
int num[3];
- BOOL has_year = FALSE;
- BOOL has_mon = FALSE;
- BOOL has_time = FALSE;
+ bool has_year = false;
+ bool has_mon = false;
+ bool has_time = false;
int num_index = 0;
/* initialize fields to the beginning of 2001-01-01 */
@@ -51019,23 +51032,23 @@ static BOOL js_date_parse_otherstring(const uint8_t *sp,
for (i = 3; i < 9; i++) {
fields[i] = 0;
}
- *is_local = TRUE;
+ *is_local = true;
while (string_skip_spaces(sp, &p)) {
p_start = p;
if ((c = sp[p]) == '+' || c == '-') {
- if (has_time && string_get_tzoffset(sp, &p, &fields[8], FALSE)) {
- *is_local = FALSE;
+ if (has_time && string_get_tzoffset(sp, &p, &fields[8], false)) {
+ *is_local = false;
} else {
p++;
if (string_get_digits(sp, &p, &val, 1, 9)) {
if (c == '-') {
if (val == 0)
- return FALSE;
+ return false;
val = -val;
}
fields[0] = val;
- has_year = TRUE;
+ has_year = true;
}
}
} else
@@ -51044,32 +51057,32 @@ static BOOL js_date_parse_otherstring(const uint8_t *sp,
/* time part */
fields[3] = val;
if (!string_get_digits(sp, &p, &fields[4], 1, 2))
- return FALSE;
+ return false;
if (string_skip_char(sp, &p, ':')) {
if (!string_get_digits(sp, &p, &fields[5], 1, 2))
- return FALSE;
+ return false;
string_get_milliseconds(sp, &p, &fields[6]);
} else
if (sp[p] != '\0' && sp[p] != ' ')
- return FALSE;
- has_time = TRUE;
+ return false;
+ has_time = true;
} else {
if (p - p_start > 2) {
fields[0] = val;
- has_year = TRUE;
+ has_year = true;
} else
if (val < 1 || val > 31) {
fields[0] = val + (val < 100) * 1900 + (val < 50) * 100;
- has_year = TRUE;
+ has_year = true;
} else {
if (num_index == 3)
- return FALSE;
+ return false;
num[num_index++] = val;
}
}
} else
if (string_get_month(sp, &p, &fields[1])) {
- has_mon = TRUE;
+ has_mon = true;
string_skip_until(sp, &p, "0123456789 -/(");
} else
if (has_time && string_match(sp, &p, "PM")) {
@@ -51083,13 +51096,13 @@ static BOOL js_date_parse_otherstring(const uint8_t *sp,
if (has_time && string_match(sp, &p, "AM")) {
/* 00:00 AM will be silently accepted */
if (fields[3] > 12)
- return FALSE;
+ return false;
if (fields[3] == 12)
fields[3] -= 12;
continue;
} else
if (string_get_tzabbr(sp, &p, &fields[8])) {
- *is_local = FALSE;
+ *is_local = false;
continue;
} else
if (c == '(') { /* skip parenthesized phrase */
@@ -51102,25 +51115,25 @@ static BOOL js_date_parse_otherstring(const uint8_t *sp,
break;
}
if (level > 0)
- return FALSE;
+ return false;
} else
if (c == ')') {
- return FALSE;
+ return false;
} else {
if (has_year + has_mon + has_time + num_index)
- return FALSE;
+ return false;
/* skip a word */
string_skip_until(sp, &p, " -/(");
}
string_skip_separators(sp, &p);
}
if (num_index + has_year + has_mon > 3)
- return FALSE;
+ return false;
switch (num_index) {
case 0:
if (!has_year)
- return FALSE;
+ return false;
break;
case 1:
if (has_mon)
@@ -51147,16 +51160,16 @@ static BOOL js_date_parse_otherstring(const uint8_t *sp,
fields[2] = num[1];
break;
default:
- return FALSE;
+ return false;
}
if (fields[1] < 1 || fields[2] < 1)
- return FALSE;
+ return false;
fields[1] -= 1;
- return TRUE;
+ return true;
}
-static JSValue js_Date_parse(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_Date_parse(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue s, rv;
int fields[9];
@@ -51165,7 +51178,7 @@ static JSValue js_Date_parse(JSContext *ctx, JSValue this_val,
int i, c;
JSString *sp;
uint8_t buf[128];
- BOOL is_local;
+ bool is_local;
rv = JS_NAN;
@@ -51185,15 +51198,15 @@ static JSValue js_Date_parse(JSContext *ctx, JSValue this_val,
if (js_date_parse_isostring(buf, fields, &is_local)
|| js_date_parse_otherstring(buf, fields, &is_local)) {
static int const field_max[6] = { 0, 11, 31, 24, 59, 59 };
- BOOL valid = TRUE;
+ bool valid = true;
/* check field maximum values */
for (i = 1; i < 6; i++) {
if (fields[i] > field_max[i])
- valid = FALSE;
+ valid = false;
}
/* special case 24:00:00.000 */
if (fields[3] == 24 && (fields[4] | fields[5] | fields[6]))
- valid = FALSE;
+ valid = false;
if (valid) {
for(i = 0; i < 7; i++)
fields1[i] = fields[i];
@@ -51205,18 +51218,18 @@ static JSValue js_Date_parse(JSContext *ctx, JSValue this_val,
return rv;
}
-static JSValue js_Date_now(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_Date_now(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
// now()
return js_int64(date_now());
}
-static JSValue js_date_Symbol_toPrimitive(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_date_Symbol_toPrimitive(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
// Symbol_toPrimitive(hint)
- JSValue obj = this_val;
+ JSValueConst obj = this_val;
JSAtom hint = JS_ATOM_NULL;
int hint_num;
@@ -51244,8 +51257,8 @@ static JSValue js_date_Symbol_toPrimitive(JSContext *ctx, JSValue this_val,
return JS_ToPrimitive(ctx, obj, hint_num | HINT_FORCE_ORDINARY);
}
-static JSValue js_date_getTimezoneOffset(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_date_getTimezoneOffset(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
// getTimezoneOffset()
double v;
@@ -51259,8 +51272,8 @@ static JSValue js_date_getTimezoneOffset(JSContext *ctx, JSValue this_val,
return js_int64(getTimezoneOffset((int64_t)trunc(v)));
}
-static JSValue js_date_getTime(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_date_getTime(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
// getTime()
double v;
@@ -51270,8 +51283,8 @@ static JSValue js_date_getTime(JSContext *ctx, JSValue this_val,
return js_float64(v);
}
-static JSValue js_date_setTime(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_date_setTime(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
// setTime(v)
double v;
@@ -51281,12 +51294,12 @@ static JSValue js_date_setTime(JSContext *ctx, JSValue this_val,
return JS_SetThisTimeValue(ctx, this_val, time_clip(v));
}
-static JSValue js_date_setYear(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_date_setYear(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
// setYear(y)
double y;
- JSValue args[1];
+ JSValue d, ret;
if (JS_ThisTimeValue(ctx, &y, this_val) || JS_ToFloat64(ctx, &y, argv[0]))
return JS_EXCEPTION;
@@ -51298,12 +51311,14 @@ static JSValue js_date_setYear(JSContext *ctx, JSValue this_val,
if (y >= 0 && y < 100)
y += 1900;
}
- args[0] = js_float64(y);
- return set_date_field(ctx, this_val, 1, args, 0x011);
+ d = js_float64(y);
+ ret = set_date_field(ctx, this_val, 1, vc(&d), 0x011);
+ JS_FreeValue(ctx, d);
+ return ret;
}
-static JSValue js_date_toJSON(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_date_toJSON(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
// toJSON(key)
JSValue obj, tv, method, rv;
@@ -51405,6 +51420,13 @@ JSValue JS_NewDate(JSContext *ctx, double epoch_ms)
return obj;
}
+bool JS_IsDate(JSValueConst v)
+{
+ if (JS_VALUE_GET_TAG(v) != JS_TAG_OBJECT)
+ return false;
+ return JS_VALUE_GET_OBJ(v)->class_id == JS_CLASS_DATE;
+}
+
void JS_AddIntrinsicDate(JSContext *ctx)
{
JSValue obj;
@@ -51492,15 +51514,15 @@ static JSValue JS_ToBigIntCtorFree(JSContext *ctx, JSValue val)
}
static JSValue js_bigint_constructor(JSContext *ctx,
- JSValue new_target,
- int argc, JSValue *argv)
+ JSValueConst new_target,
+ int argc, JSValueConst *argv)
{
if (!JS_IsUndefined(new_target))
return JS_ThrowTypeError(ctx, "not a constructor");
return JS_ToBigIntCtorFree(ctx, js_dup(argv[0]));
}
-static JSValue js_thisBigIntValue(JSContext *ctx, JSValue this_val)
+static JSValue js_thisBigIntValue(JSContext *ctx, JSValueConst this_val)
{
if (JS_IsBigInt(ctx, this_val))
return js_dup(this_val);
@@ -51515,8 +51537,8 @@ static JSValue js_thisBigIntValue(JSContext *ctx, JSValue this_val)
return JS_ThrowTypeError(ctx, "not a BigInt");
}
-static JSValue js_bigint_toString(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_bigint_toString(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue val;
int base;
@@ -51540,15 +51562,15 @@ static JSValue js_bigint_toString(JSContext *ctx, JSValue this_val,
return JS_EXCEPTION;
}
-static JSValue js_bigint_valueOf(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_bigint_valueOf(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
return js_thisBigIntValue(ctx, this_val);
}
static JSValue js_bigint_asUintN(JSContext *ctx,
- JSValue this_val,
- int argc, JSValue *argv, int asIntN)
+ JSValueConst this_val,
+ int argc, JSValueConst *argv, int asIntN)
{
uint64_t bits;
bf_t a_s, *a = &a_s, *r, mask_s, *mask = &mask_s;
@@ -51624,6 +51646,8 @@ static void JS_AddIntrinsicBasicObjects(JSContext *ctx)
int i;
ctx->class_proto[JS_CLASS_OBJECT] = JS_NewObjectProto(ctx, JS_NULL);
+ ctx->global_obj = JS_NewObject(ctx);
+ ctx->global_var_obj = JS_NewObjectProto(ctx, JS_NULL);
ctx->function_proto = JS_NewCFunction3(ctx, js_function_proto, "", 0,
JS_CFUNC_generic, 0,
ctx->class_proto[JS_CLASS_OBJECT]);
@@ -51681,10 +51705,7 @@ void JS_AddIntrinsicBaseObjects(JSContext *ctx)
JS_PROP_HAS_GET | JS_PROP_HAS_SET |
JS_PROP_HAS_CONFIGURABLE | JS_PROP_CONFIGURABLE);
JS_FreeValue(ctx, obj1);
- JS_FreeValue(ctx, js_object_seal(ctx, JS_UNDEFINED, 1, &ctx->throw_type_error, 1));
-
- ctx->global_obj = JS_NewObject(ctx);
- ctx->global_var_obj = JS_NewObjectProto(ctx, JS_NULL);
+ JS_FreeValue(ctx, js_object_seal(ctx, JS_UNDEFINED, 1, vc(&ctx->throw_type_error), 1));
/* Object */
obj = JS_NewGlobalCConstructor(ctx, "Object", js_object_constructor, 1,
@@ -51816,7 +51837,7 @@ void JS_AddIntrinsicBaseObjects(JSContext *ctx)
/* Boolean */
ctx->class_proto[JS_CLASS_BOOLEAN] = JS_NewObjectProtoClass(ctx, ctx->class_proto[JS_CLASS_OBJECT],
JS_CLASS_BOOLEAN);
- JS_SetObjectData(ctx, ctx->class_proto[JS_CLASS_BOOLEAN], js_bool(FALSE));
+ JS_SetObjectData(ctx, ctx->class_proto[JS_CLASS_BOOLEAN], JS_FALSE);
JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_BOOLEAN], js_boolean_proto_funcs,
countof(js_boolean_proto_funcs));
JS_NewGlobalCConstructor(ctx, "Boolean", js_boolean_constructor, 1,
@@ -51905,12 +51926,12 @@ static uint8_t const typed_array_size_log2[JS_TYPED_ARRAY_COUNT] = {
};
static JSValue js_array_buffer_constructor3(JSContext *ctx,
- JSValue new_target,
+ JSValueConst new_target,
uint64_t len, uint64_t *max_len,
JSClassID class_id,
uint8_t *buf,
JSFreeArrayBufferDataFunc *free_func,
- void *opaque, BOOL alloc_flag)
+ void *opaque, bool alloc_flag)
{
JSRuntime *rt = ctx->rt;
JSValue obj;
@@ -51966,7 +51987,7 @@ static JSValue js_array_buffer_constructor3(JSContext *ctx,
abuf->data = buf;
}
init_list_head(&abuf->array_list);
- abuf->detached = FALSE;
+ abuf->detached = false;
abuf->shared = (class_id == JS_CLASS_SHARED_ARRAY_BUFFER);
abuf->opaque = opaque;
abuf->free_func = free_func;
@@ -51986,17 +52007,17 @@ static void js_array_buffer_free(JSRuntime *rt, void *opaque, void *ptr)
}
static JSValue js_array_buffer_constructor2(JSContext *ctx,
- JSValue new_target,
+ JSValueConst new_target,
uint64_t len, uint64_t *max_len,
JSClassID class_id)
{
return js_array_buffer_constructor3(ctx, new_target, len, max_len,
class_id, NULL, js_array_buffer_free,
- NULL, TRUE);
+ NULL, true);
}
static JSValue js_array_buffer_constructor1(JSContext *ctx,
- JSValue new_target,
+ JSValueConst new_target,
uint64_t len, uint64_t *max_len)
{
return js_array_buffer_constructor2(ctx, new_target, len, max_len,
@@ -52005,15 +52026,15 @@ static JSValue js_array_buffer_constructor1(JSContext *ctx,
JSValue JS_NewArrayBuffer(JSContext *ctx, uint8_t *buf, size_t len,
JSFreeArrayBufferDataFunc *free_func, void *opaque,
- BOOL is_shared)
+ bool is_shared)
{
JSClassID class_id =
is_shared ? JS_CLASS_SHARED_ARRAY_BUFFER : JS_CLASS_ARRAY_BUFFER;
return js_array_buffer_constructor3(ctx, JS_UNDEFINED, len, NULL, class_id,
- buf, free_func, opaque, FALSE);
+ buf, free_func, opaque, false);
}
-JS_BOOL JS_IsArrayBuffer(JSValue obj) {
+bool JS_IsArrayBuffer(JSValueConst obj) {
return JS_GetClassID(obj) == JS_CLASS_ARRAY_BUFFER;
}
@@ -52024,11 +52045,11 @@ JSValue JS_NewArrayBufferCopy(JSContext *ctx, const uint8_t *buf, size_t len)
JS_CLASS_ARRAY_BUFFER,
(uint8_t *)buf,
js_array_buffer_free, NULL,
- TRUE);
+ true);
}
-static JSValue js_array_buffer_constructor0(JSContext *ctx, JSValue new_target,
- int argc, JSValue *argv,
+static JSValue js_array_buffer_constructor0(JSContext *ctx, JSValueConst new_target,
+ int argc, JSValueConst *argv,
JSClassID class_id)
{
uint64_t len, max_len, *pmax_len = NULL;
@@ -52062,23 +52083,23 @@ next:
class_id);
}
-static JSValue js_array_buffer_constructor(JSContext *ctx, JSValue new_target,
- int argc, JSValue *argv)
+static JSValue js_array_buffer_constructor(JSContext *ctx, JSValueConst new_target,
+ int argc, JSValueConst *argv)
{
return js_array_buffer_constructor0(ctx, new_target, argc, argv,
JS_CLASS_ARRAY_BUFFER);
}
static JSValue js_shared_array_buffer_constructor(JSContext *ctx,
- JSValue new_target,
- int argc, JSValue *argv)
+ JSValueConst new_target,
+ int argc, JSValueConst *argv)
{
return js_array_buffer_constructor0(ctx, new_target, argc, argv,
JS_CLASS_SHARED_ARRAY_BUFFER);
}
/* also used for SharedArrayBuffer */
-static void js_array_buffer_finalizer(JSRuntime *rt, JSValue val)
+static void js_array_buffer_finalizer(JSRuntime *rt, JSValueConst val)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
JSArrayBuffer *abuf = p->u.array_buffer;
@@ -52113,20 +52134,17 @@ static void js_array_buffer_finalizer(JSRuntime *rt, JSValue val)
}
static JSValue js_array_buffer_isView(JSContext *ctx,
- JSValue this_val,
- int argc, JSValue *argv)
+ JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSObject *p;
- BOOL res;
- res = FALSE;
+
if (JS_VALUE_GET_TAG(argv[0]) == JS_TAG_OBJECT) {
p = JS_VALUE_GET_OBJ(argv[0]);
- if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&
- p->class_id <= JS_CLASS_DATAVIEW) {
- res = TRUE;
- }
+ return js_bool(is_typed_array(p->class_id) ||
+ p->class_id == JS_CLASS_DATAVIEW);
}
- return js_bool(res);
+ return JS_FALSE;
}
static const JSCFunctionListEntry js_array_buffer_funcs[] = {
@@ -52146,7 +52164,7 @@ static JSValue JS_ThrowTypeErrorArrayBufferOOB(JSContext *ctx)
// #sec-get-arraybuffer.prototype.detached
static JSValue js_array_buffer_get_detached(JSContext *ctx,
- JSValue this_val)
+ JSValueConst this_val)
{
JSArrayBuffer *abuf = JS_GetOpaque2(ctx, this_val, JS_CLASS_ARRAY_BUFFER);
if (!abuf)
@@ -52157,7 +52175,7 @@ static JSValue js_array_buffer_get_detached(JSContext *ctx,
}
static JSValue js_array_buffer_get_byteLength(JSContext *ctx,
- JSValue this_val,
+ JSValueConst this_val,
int class_id)
{
JSArrayBuffer *abuf = JS_GetOpaque2(ctx, this_val, class_id);
@@ -52168,7 +52186,7 @@ static JSValue js_array_buffer_get_byteLength(JSContext *ctx,
}
static JSValue js_array_buffer_get_maxByteLength(JSContext *ctx,
- JSValue this_val,
+ JSValueConst this_val,
int class_id)
{
JSArrayBuffer *abuf = JS_GetOpaque2(ctx, this_val, class_id);
@@ -52179,7 +52197,8 @@ static JSValue js_array_buffer_get_maxByteLength(JSContext *ctx,
return js_uint32(abuf->byte_length);
}
-static JSValue js_array_buffer_get_resizable(JSContext *ctx, JSValue this_val,
+static JSValue js_array_buffer_get_resizable(JSContext *ctx,
+ JSValueConst this_val,
int class_id)
{
JSArrayBuffer *abuf = JS_GetOpaque2(ctx, this_val, class_id);
@@ -52188,7 +52207,7 @@ static JSValue js_array_buffer_get_resizable(JSContext *ctx, JSValue this_val,
return js_bool(array_buffer_is_resizable(abuf));
}
-void JS_DetachArrayBuffer(JSContext *ctx, JSValue obj)
+void JS_DetachArrayBuffer(JSContext *ctx, JSValueConst obj)
{
JSArrayBuffer *abuf = JS_GetOpaque(obj, JS_CLASS_ARRAY_BUFFER);
struct list_head *el;
@@ -52199,7 +52218,7 @@ void JS_DetachArrayBuffer(JSContext *ctx, JSValue obj)
abuf->free_func(ctx->rt, abuf->opaque, abuf->data);
abuf->data = NULL;
abuf->byte_length = 0;
- abuf->detached = TRUE;
+ abuf->detached = true;
list_for_each(el, &abuf->array_list) {
JSTypedArray *ta;
@@ -52216,7 +52235,7 @@ void JS_DetachArrayBuffer(JSContext *ctx, JSValue obj)
}
/* get an ArrayBuffer or SharedArrayBuffer */
-static JSArrayBuffer *js_get_array_buffer(JSContext *ctx, JSValue obj)
+static JSArrayBuffer *js_get_array_buffer(JSContext *ctx, JSValueConst obj)
{
JSObject *p;
if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)
@@ -52233,7 +52252,7 @@ static JSArrayBuffer *js_get_array_buffer(JSContext *ctx, JSValue obj)
/* return NULL if exception. WARNING: any JS call can detach the
buffer and render the returned pointer invalid */
-uint8_t *JS_GetArrayBuffer(JSContext *ctx, size_t *psize, JSValue obj)
+uint8_t *JS_GetArrayBuffer(JSContext *ctx, size_t *psize, JSValueConst obj)
{
JSArrayBuffer *abuf = js_get_array_buffer(ctx, obj);
if (!abuf)
@@ -52249,16 +52268,16 @@ uint8_t *JS_GetArrayBuffer(JSContext *ctx, size_t *psize, JSValue obj)
return NULL;
}
-static BOOL array_buffer_is_resizable(const JSArrayBuffer *abuf)
+static bool array_buffer_is_resizable(const JSArrayBuffer *abuf)
{
return abuf->max_byte_length >= 0;
}
// ES #sec-arraybuffer.prototype.transfer
-static JSValue js_array_buffer_transfer(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue js_array_buffer_transfer(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
- BOOL transfer_to_fixed_length = magic & 1;
+ bool transfer_to_fixed_length = magic & 1;
JSArrayBuffer *abuf;
uint64_t new_len, old_len, max_len, *pmax_len;
uint8_t *bs, *new_bs;
@@ -52305,15 +52324,15 @@ static JSValue js_array_buffer_transfer(JSContext *ctx, JSValue this_val,
/* neuter the backing buffer */
abuf->data = NULL;
abuf->byte_length = 0;
- abuf->detached = TRUE;
+ abuf->detached = true;
return js_array_buffer_constructor3(ctx, JS_UNDEFINED, new_len, pmax_len,
JS_CLASS_ARRAY_BUFFER,
bs, abuf->free_func,
- NULL, FALSE);
+ NULL, false);
}
-static JSValue js_array_buffer_resize(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int class_id)
+static JSValue js_array_buffer_resize(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int class_id)
{
uint32_t size_log2, size_elem;
struct list_head *el;
@@ -52389,8 +52408,8 @@ static JSValue js_array_buffer_resize(JSContext *ctx, JSValue this_val,
}
static JSValue js_array_buffer_slice(JSContext *ctx,
- JSValue this_val,
- int argc, JSValue *argv, int class_id)
+ JSValueConst this_val,
+ int argc, JSValueConst *argv, int class_id)
{
JSArrayBuffer *abuf, *new_abuf;
int64_t len, start, end, new_len;
@@ -52421,7 +52440,7 @@ static JSValue js_array_buffer_slice(JSContext *ctx,
} else {
JSValue args[1];
args[0] = js_int64(new_len);
- new_obj = JS_CallConstructor(ctx, ctor, 1, args);
+ new_obj = JS_CallConstructor(ctx, ctor, 1, vc(args));
JS_FreeValue(ctx, ctor);
JS_FreeValue(ctx, args[0]);
}
@@ -52481,29 +52500,33 @@ static const JSCFunctionListEntry js_shared_array_buffer_proto_funcs[] = {
JS_PROP_STRING_DEF("[Symbol.toStringTag]", "SharedArrayBuffer", JS_PROP_CONFIGURABLE ),
};
+static bool is_typed_array(JSClassID class_id)
+{
+ return class_id >= JS_CLASS_UINT8C_ARRAY && class_id <= JS_CLASS_FLOAT64_ARRAY;
+}
+
// is the typed array detached or out of bounds relative to its RAB?
// |p| must be a typed array, *not* a DataView
-static BOOL typed_array_is_oob(JSObject *p)
+static bool typed_array_is_oob(JSObject *p)
{
JSArrayBuffer *abuf;
JSTypedArray *ta;
int len, size_elem;
int64_t end;
- assert(p->class_id >= JS_CLASS_UINT8C_ARRAY);
- assert(p->class_id <= JS_CLASS_FLOAT64_ARRAY);
+ assert(is_typed_array(p->class_id));
ta = p->u.typed_array;
abuf = ta->buffer->u.array_buffer;
if (abuf->detached)
- return TRUE;
+ return true;
len = abuf->byte_length;
if (ta->offset > len)
- return TRUE;
+ return true;
if (ta->track_rab)
- return FALSE;
+ return false;
if (len < (int64_t)ta->offset + ta->length)
- return TRUE;
+ return true;
size_elem = 1 << typed_array_size_log2(p->class_id);
end = (int64_t)ta->offset + (int64_t)p->u.array.count * size_elem;
return end > len;
@@ -52518,7 +52541,7 @@ static uint32_t typed_array_get_length(JSContext *ctx, JSObject *p)
return ta->length >> size_log2;
}
-static int validate_typed_array(JSContext *ctx, JSValue this_val)
+static int validate_typed_array(JSContext *ctx, JSValueConst this_val)
{
JSObject *p;
p = get_typed_array(ctx, this_val);
@@ -52531,7 +52554,7 @@ static int validate_typed_array(JSContext *ctx, JSValue this_val)
return 0;
}
-static JSValue js_typed_array_get_length(JSContext *ctx, JSValue this_val)
+static JSValue js_typed_array_get_length(JSContext *ctx, JSValueConst this_val)
{
JSObject *p;
p = get_typed_array(ctx, this_val);
@@ -52540,7 +52563,7 @@ static JSValue js_typed_array_get_length(JSContext *ctx, JSValue this_val)
return js_int32(p->u.array.count);
}
-static JSValue js_typed_array_get_buffer(JSContext *ctx, JSValue this_val)
+static JSValue js_typed_array_get_buffer(JSContext *ctx, JSValueConst this_val)
{
JSObject *p;
JSTypedArray *ta;
@@ -52551,7 +52574,7 @@ static JSValue js_typed_array_get_buffer(JSContext *ctx, JSValue this_val)
return js_dup(JS_MKPTR(JS_TAG_OBJECT, ta->buffer));
}
-static JSValue js_typed_array_get_byteLength(JSContext *ctx, JSValue this_val)
+static JSValue js_typed_array_get_byteLength(JSContext *ctx, JSValueConst this_val)
{
uint32_t size_log2;
JSTypedArray *ta;
@@ -52569,7 +52592,7 @@ static JSValue js_typed_array_get_byteLength(JSContext *ctx, JSValue this_val)
return js_int64((int64_t)p->u.array.count << size_log2);
}
-static JSValue js_typed_array_get_byteOffset(JSContext *ctx, JSValue this_val)
+static JSValue js_typed_array_get_byteOffset(JSContext *ctx, JSValueConst this_val)
{
JSObject *p;
JSTypedArray *ta;
@@ -52582,7 +52605,7 @@ static JSValue js_typed_array_get_byteOffset(JSContext *ctx, JSValue this_val)
return js_uint32(ta->offset);
}
-JSValue JS_NewTypedArray(JSContext *ctx, int argc, JSValue *argv,
+JSValue JS_NewTypedArray(JSContext *ctx, int argc, JSValueConst *argv,
JSTypedArrayEnum type)
{
if (type < JS_TYPED_ARRAY_UINT8C || type > JS_TYPED_ARRAY_FLOAT64)
@@ -52595,7 +52618,7 @@ JSValue JS_NewTypedArray(JSContext *ctx, int argc, JSValue *argv,
/* Return the buffer associated to the typed array or an exception if
it is not a typed array or if the buffer is detached. pbyte_offset,
pbyte_length or pbytes_per_element can be NULL. */
-JSValue JS_GetTypedArrayBuffer(JSContext *ctx, JSValue obj,
+JSValue JS_GetTypedArrayBuffer(JSContext *ctx, JSValueConst obj,
size_t *pbyte_offset,
size_t *pbyte_length,
size_t *pbytes_per_element)
@@ -52620,7 +52643,7 @@ JSValue JS_GetTypedArrayBuffer(JSContext *ctx, JSValue obj,
/* return NULL if exception. WARNING: any JS call can detach the
buffer and render the returned pointer invalid */
-uint8_t *JS_GetUint8Array(JSContext *ctx, size_t *psize, JSValue obj)
+uint8_t *JS_GetUint8Array(JSContext *ctx, size_t *psize, JSValueConst obj)
{
JSObject *p;
JSTypedArray *ta;
@@ -52647,22 +52670,21 @@ uint8_t *JS_GetUint8Array(JSContext *ctx, size_t *psize, JSValue obj)
}
static JSValue js_typed_array_get_toStringTag(JSContext *ctx,
- JSValue this_val)
+ JSValueConst this_val)
{
JSObject *p;
if (JS_VALUE_GET_TAG(this_val) != JS_TAG_OBJECT)
return JS_UNDEFINED;
p = JS_VALUE_GET_OBJ(this_val);
- if (!(p->class_id >= JS_CLASS_UINT8C_ARRAY &&
- p->class_id <= JS_CLASS_FLOAT64_ARRAY))
+ if (!is_typed_array(p->class_id))
return JS_UNDEFINED;
return JS_AtomToString(ctx, ctx->rt->class_array[p->class_id].class_name);
}
static JSValue js_typed_array_set_internal(JSContext *ctx,
- JSValue dst,
- JSValue src,
- JSValue off)
+ JSValueConst dst,
+ JSValueConst src,
+ JSValueConst off)
{
JSObject *p;
JSObject *src_p;
@@ -52687,8 +52709,7 @@ static JSValue js_typed_array_set_internal(JSContext *ctx,
if (JS_IsException(src_obj))
goto fail;
src_p = JS_VALUE_GET_OBJ(src_obj);
- if (src_p->class_id >= JS_CLASS_UINT8C_ARRAY &&
- src_p->class_id <= JS_CLASS_FLOAT64_ARRAY) {
+ if (is_typed_array(src_p->class_id)) {
JSTypedArray *dest_ta = p->u.typed_array;
JSArrayBuffer *dest_abuf = dest_ta->buffer->u.array_buffer;
JSTypedArray *src_ta = src_p->u.typed_array;
@@ -52746,8 +52767,8 @@ fail:
return JS_EXCEPTION;
}
-static JSValue js_typed_array_at(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_typed_array_at(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSObject *p;
int64_t idx, len;
@@ -52799,8 +52820,8 @@ static JSValue js_typed_array_at(JSContext *ctx, JSValue this_val,
return JS_UNDEFINED;
}
-static JSValue js_typed_array_with(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_typed_array_with(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue arr, val;
JSObject *p;
@@ -52842,26 +52863,26 @@ static JSValue js_typed_array_with(JSContext *ctx, JSValue this_val,
}
static JSValue js_typed_array_set(JSContext *ctx,
- JSValue this_val,
- int argc, JSValue *argv)
+ JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
- JSValue offset = JS_UNDEFINED;
+ JSValueConst offset = JS_UNDEFINED;
if (argc > 1) {
offset = argv[1];
}
return js_typed_array_set_internal(ctx, this_val, argv[0], offset);
}
-static JSValue js_create_typed_array_iterator(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int magic)
+static JSValue js_create_typed_array_iterator(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int magic)
{
if (validate_typed_array(ctx, this_val))
return JS_EXCEPTION;
return js_create_array_iterator(ctx, this_val, argc, argv, magic);
}
-static JSValue js_typed_array_create(JSContext *ctx, JSValue ctor,
- int argc, JSValue *argv)
+static JSValue js_typed_array_create(JSContext *ctx, JSValueConst ctor,
+ int argc, JSValueConst *argv)
{
JSValue ret;
int new_len;
@@ -52889,10 +52910,10 @@ static JSValue js_typed_array_create(JSContext *ctx, JSValue ctor,
}
static JSValue js_typed_array___speciesCreate(JSContext *ctx,
- JSValue this_val,
- int argc, JSValue *argv)
+ JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
- JSValue obj;
+ JSValueConst obj;
JSObject *p;
JSValue ctor, ret;
int argc1;
@@ -52915,18 +52936,18 @@ static JSValue js_typed_array___speciesCreate(JSContext *ctx,
return ret;
}
-static JSValue js_typed_array_from(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_typed_array_from(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
// from(items, mapfn = void 0, this_arg = void 0)
- JSValue items = argv[0], mapfn, this_arg;
- JSValue args[2];
+ JSValueConst items = argv[0], mapfn, this_arg;
+ JSValueConst args[2];
JSValue stack[2];
JSValue iter, arr, r, v, v2;
int64_t k, len;
int done, mapping;
- mapping = FALSE;
+ mapping = false;
mapfn = JS_UNDEFINED;
this_arg = JS_UNDEFINED;
r = JS_UNDEFINED;
@@ -52953,7 +52974,7 @@ static JSValue js_typed_array_from(JSContext *ctx, JSValue this_val,
if (JS_IsException(arr))
goto exception;
stack[0] = js_dup(items);
- if (js_for_of_start(ctx, &stack[1], FALSE))
+ if (js_for_of_start(ctx, &stack[1], false))
goto exception;
for (k = 0;; k++) {
v = JS_IteratorNext(ctx, stack[0], stack[1], 0, NULL, &done);
@@ -52972,8 +52993,7 @@ static JSValue js_typed_array_from(JSContext *ctx, JSValue this_val,
if (js_get_length64(ctx, &len, arr) < 0)
goto exception;
v = js_int64(len);
- args[0] = v;
- r = js_typed_array_create(ctx, this_val, 1, args);
+ r = js_typed_array_create(ctx, this_val, 1, vc(&v));
JS_FreeValue(ctx, v);
if (JS_IsException(r))
goto exception;
@@ -52997,7 +53017,7 @@ static JSValue js_typed_array_from(JSContext *ctx, JSValue this_val,
exception_close:
if (!JS_IsUndefined(stack[0]))
- JS_IteratorClose(ctx, stack[0], TRUE);
+ JS_IteratorClose(ctx, stack[0], true);
exception:
JS_FreeValue(ctx, r);
r = JS_EXCEPTION;
@@ -53008,15 +53028,14 @@ static JSValue js_typed_array_from(JSContext *ctx, JSValue this_val,
return r;
}
-static JSValue js_typed_array_of(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_typed_array_of(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
- JSValue obj;
- JSValue args[1];
+ JSValue v, obj;
int i;
- args[0] = js_int32(argc);
- obj = js_typed_array_create(ctx, this_val, 1, args);
+ v = js_int32(argc);
+ obj = js_typed_array_create(ctx, this_val, 1, vc(&v));
if (JS_IsException(obj))
return obj;
@@ -53029,8 +53048,8 @@ static JSValue js_typed_array_of(JSContext *ctx, JSValue this_val,
return obj;
}
-static JSValue js_typed_array_copyWithin(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_typed_array_copyWithin(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSObject *p;
int len, to, from, final, count, shift, space;
@@ -53070,8 +53089,8 @@ static JSValue js_typed_array_copyWithin(JSContext *ctx, JSValue this_val,
return js_dup(this_val);
}
-static JSValue js_typed_array_fill(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_typed_array_fill(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSObject *p;
int len, k, final, shift;
@@ -53163,11 +53182,10 @@ static JSValue js_typed_array_fill(JSContext *ctx, JSValue this_val,
return js_dup(this_val);
}
-static JSValue js_typed_array_find(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int mode)
+static JSValue js_typed_array_find(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int mode)
{
- JSValue func, this_arg;
- JSValue args[3];
+ JSValueConst func, this_arg, args[3];
JSValue val, index_val, res;
int len, k, end;
int dir;
@@ -53229,8 +53247,8 @@ exception:
#define special_lastIndexOf 1
#define special_includes -1
-static JSValue js_typed_array_indexOf(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int special)
+static JSValue js_typed_array_indexOf(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int special)
{
JSObject *p;
int len, tag, is_int, is_bigint, k, stop, inc, res = -1;
@@ -53238,7 +53256,7 @@ static JSValue js_typed_array_indexOf(JSContext *ctx, JSValue this_val,
double d;
float f;
uint16_t hf;
- BOOL oob;
+ bool oob;
p = get_typed_array(ctx, this_val);
if (!p)
@@ -53250,7 +53268,7 @@ static JSValue js_typed_array_indexOf(JSContext *ctx, JSValue this_val,
if (len == 0)
goto done;
- oob = FALSE;
+ oob = false;
if (special == special_lastIndexOf) {
k = len - 1;
if (argc > 1) {
@@ -53284,7 +53302,7 @@ static JSValue js_typed_array_indexOf(JSContext *ctx, JSValue this_val,
k = 0;
} else if (k > len) {
k = len;
- oob = TRUE;
+ oob = true;
}
}
stop = len;
@@ -53521,8 +53539,8 @@ exception:
return JS_EXCEPTION;
}
-static JSValue js_typed_array_join(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int toLocaleString)
+static JSValue js_typed_array_join(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int toLocaleString)
{
JSValue sep = JS_UNDEFINED, el;
StringBuffer b_s, *b = &b_s;
@@ -53545,7 +53563,7 @@ static JSValue js_typed_array_join(JSContext *ctx, JSValue this_val,
goto exception;
s = JS_VALUE_GET_STRING(sep);
if (s->len == 1 && !s->is_wide_char)
- c = s->u.str8[0];
+ c = str8(s)[0];
else
c = -1;
// ToString(sep) can detach or resize the arraybuffer as a side effect
@@ -53600,8 +53618,8 @@ exception:
return JS_EXCEPTION;
}
-static JSValue js_typed_array_reverse(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_typed_array_reverse(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSObject *p;
int len;
@@ -53663,8 +53681,8 @@ static JSValue js_typed_array_reverse(JSContext *ctx, JSValue this_val,
return js_dup(this_val);
}
-static JSValue js_typed_array_toReversed(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_typed_array_toReversed(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue arr, ret;
JSObject *p;
@@ -53681,10 +53699,10 @@ static JSValue js_typed_array_toReversed(JSContext *ctx, JSValue this_val,
return ret;
}
-static JSValue js_typed_array_slice(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_typed_array_slice(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
- JSValue args[2];
+ JSValueConst args[2];
JSValue arr, val;
JSObject *p, *p1;
int n, len, start, final, count, shift, space;
@@ -53749,12 +53767,12 @@ static JSValue js_typed_array_slice(JSContext *ctx, JSValue this_val,
return JS_EXCEPTION;
}
-static JSValue js_typed_array_subarray(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_typed_array_subarray(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSArrayBuffer *abuf;
JSTypedArray *ta;
- JSValue args[4];
+ JSValueConst args[4];
JSValue arr, byteOffset, ta_buffer;
JSObject *p;
int len, start, final, count, shift, offset;
@@ -53790,9 +53808,9 @@ static JSValue js_typed_array_subarray(JSContext *ctx, JSValue this_val,
if (JS_IsException(ta_buffer))
goto exception;
args[0] = this_val;
- args[1] = ta_buffer;
- args[2] = js_int32(offset);
- args[3] = js_int32(count);
+ args[1] = safe_const(ta_buffer);
+ args[2] = safe_const(js_int32(offset));
+ args[3] = safe_const(js_int32(count));
// result is length-tracking if source TA is and no explicit count is given
if (ta->track_rab && JS_IsUndefined(argv[1]))
args[3] = JS_UNDEFINED;
@@ -53916,8 +53934,8 @@ static JSValue js_TA_get_float64(JSContext *ctx, const void *a) {
struct TA_sort_context {
JSContext *ctx;
int exception;
- JSValue arr;
- JSValue cmp;
+ JSValueConst arr;
+ JSValueConst cmp;
JSValue (*getfun)(JSContext *ctx, const void *a);
int elt_size;
};
@@ -53945,7 +53963,7 @@ static int js_TA_cmp_generic(const void *a, const void *b, void *opaque) {
a_idx * (size_t)psc->elt_size);
argv[1] = psc->getfun(ctx, (char *)p->u.array.u.ptr +
b_idx * (size_t)(psc->elt_size));
- res = JS_Call(ctx, psc->cmp, JS_UNDEFINED, 2, argv);
+ res = JS_Call(ctx, psc->cmp, JS_UNDEFINED, 2, vc(argv));
if (JS_IsException(res)) {
psc->exception = 1;
goto done;
@@ -53973,8 +53991,8 @@ static int js_TA_cmp_generic(const void *a, const void *b, void *opaque) {
return cmp;
}
-static JSValue js_typed_array_sort(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_typed_array_sort(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSObject *p;
int len;
@@ -54117,8 +54135,8 @@ static JSValue js_typed_array_sort(JSContext *ctx, JSValue this_val,
return js_dup(this_val);
}
-static JSValue js_typed_array_toSorted(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv)
+static JSValue js_typed_array_toSorted(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSValue arr, ret;
JSObject *p;
@@ -54182,15 +54200,15 @@ static const JSCFunctionListEntry js_typed_array_base_proto_funcs[] = {
};
static JSValue js_typed_array_base_constructor(JSContext *ctx,
- JSValue this_val,
- int argc, JSValue *argv)
+ JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
return JS_ThrowTypeError(ctx, "cannot be called");
}
/* 'obj' must be an allocated typed array object */
static int typed_array_init(JSContext *ctx, JSValue obj, JSValue buffer,
- uint64_t offset, uint64_t len, BOOL track_rab)
+ uint64_t offset, uint64_t len, bool track_rab)
{
JSTypedArray *ta;
JSObject *p, *pbuffer;
@@ -54220,10 +54238,10 @@ static int typed_array_init(JSContext *ctx, JSValue obj, JSValue buffer,
static JSValue js_array_from_iterator(JSContext *ctx, uint32_t *plen,
- JSValue obj, JSValue method)
+ JSValueConst obj, JSValueConst method)
{
JSValue arr, iter, next_method = JS_UNDEFINED, val;
- BOOL done;
+ int done;
uint32_t k;
*plen = 0;
@@ -54261,8 +54279,8 @@ static JSValue js_array_from_iterator(JSContext *ctx, uint32_t *plen,
}
static JSValue js_typed_array_constructor_obj(JSContext *ctx,
- JSValue new_target,
- JSValue obj,
+ JSValueConst new_target,
+ JSValueConst obj,
int classid)
{
JSValue iter, ret, arr = JS_UNDEFINED, val, buffer;
@@ -54296,7 +54314,7 @@ static JSValue js_typed_array_constructor_obj(JSContext *ctx,
NULL);
if (JS_IsException(buffer))
goto fail;
- if (typed_array_init(ctx, ret, buffer, 0, len, /*track_rab*/FALSE))
+ if (typed_array_init(ctx, ret, buffer, 0, len, /*track_rab*/false))
goto fail;
for(i = 0; i < len; i++) {
@@ -54315,8 +54333,8 @@ static JSValue js_typed_array_constructor_obj(JSContext *ctx,
}
static JSValue js_typed_array_constructor_ta(JSContext *ctx,
- JSValue new_target,
- JSValue src_obj,
+ JSValueConst new_target,
+ JSValueConst src_obj,
int classid, uint32_t len)
{
JSObject *p, *src_buffer;
@@ -54350,7 +54368,7 @@ static JSValue js_typed_array_constructor_ta(JSContext *ctx,
goto fail;
}
abuf = JS_GetOpaque(buffer, JS_CLASS_ARRAY_BUFFER);
- if (typed_array_init(ctx, obj, buffer, 0, len, /*track_rab*/FALSE))
+ if (typed_array_init(ctx, obj, buffer, 0, len, /*track_rab*/false))
goto fail;
if (p->class_id == classid) {
/* same type: copy the content */
@@ -54372,11 +54390,11 @@ static JSValue js_typed_array_constructor_ta(JSContext *ctx,
}
static JSValue js_typed_array_constructor(JSContext *ctx,
- JSValue new_target,
- int argc, JSValue *argv,
+ JSValueConst new_target,
+ int argc, JSValueConst *argv,
int classid)
{
- BOOL track_rab = FALSE;
+ bool track_rab = false;
JSValue buffer, obj;
JSArrayBuffer *abuf;
int size_log2;
@@ -54422,8 +54440,7 @@ static JSValue js_typed_array_constructor(JSContext *ctx,
}
buffer = js_dup(argv[0]);
} else {
- if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&
- p->class_id <= JS_CLASS_FLOAT64_ARRAY) {
+ if (is_typed_array(p->class_id)) {
return js_typed_array_constructor_ta(ctx, new_target, argv[0],
classid, p->u.array.count);
} else {
@@ -54444,7 +54461,7 @@ static JSValue js_typed_array_constructor(JSContext *ctx,
return obj;
}
-static void js_typed_array_finalizer(JSRuntime *rt, JSValue val)
+static void js_typed_array_finalizer(JSRuntime *rt, JSValueConst val)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
JSTypedArray *ta = p->u.typed_array;
@@ -54459,7 +54476,7 @@ static void js_typed_array_finalizer(JSRuntime *rt, JSValue val)
}
}
-static void js_typed_array_mark(JSRuntime *rt, JSValue val,
+static void js_typed_array_mark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func)
{
JSObject *p = JS_VALUE_GET_OBJ(val);
@@ -54470,15 +54487,15 @@ static void js_typed_array_mark(JSRuntime *rt, JSValue val,
}
static JSValue js_dataview_constructor(JSContext *ctx,
- JSValue new_target,
- int argc, JSValue *argv)
+ JSValueConst new_target,
+ int argc, JSValueConst *argv)
{
- BOOL recompute_len = FALSE;
- BOOL track_rab = FALSE;
+ bool recompute_len = false;
+ bool track_rab = false;
JSArrayBuffer *abuf;
uint64_t offset;
uint32_t len;
- JSValue buffer;
+ JSValueConst buffer;
JSValue obj;
JSTypedArray *ta;
JSObject *p;
@@ -54505,7 +54522,7 @@ static JSValue js_dataview_constructor(JSContext *ctx,
return JS_ThrowRangeError(ctx, "invalid byteLength");
len = l;
} else {
- recompute_len = TRUE;
+ recompute_len = true;
track_rab = array_buffer_is_resizable(abuf);
}
@@ -54545,7 +54562,7 @@ static JSValue js_dataview_constructor(JSContext *ctx,
}
// is the DataView out of bounds relative to its parent arraybuffer?
-static BOOL dataview_is_oob(JSObject *p)
+static bool dataview_is_oob(JSObject *p)
{
JSArrayBuffer *abuf;
JSTypedArray *ta;
@@ -54554,15 +54571,15 @@ static BOOL dataview_is_oob(JSObject *p)
ta = p->u.typed_array;
abuf = ta->buffer->u.array_buffer;
if (abuf->detached)
- return TRUE;
+ return true;
if (ta->offset > abuf->byte_length)
- return TRUE;
+ return true;
if (ta->track_rab)
- return FALSE;
+ return false;
return (int64_t)ta->offset + ta->length > abuf->byte_length;
}
-static JSObject *get_dataview(JSContext *ctx, JSValue this_val)
+static JSObject *get_dataview(JSContext *ctx, JSValueConst this_val)
{
JSObject *p;
if (JS_VALUE_GET_TAG(this_val) != JS_TAG_OBJECT)
@@ -54576,7 +54593,7 @@ static JSObject *get_dataview(JSContext *ctx, JSValue this_val)
return p;
}
-static JSValue js_dataview_get_buffer(JSContext *ctx, JSValue this_val)
+static JSValue js_dataview_get_buffer(JSContext *ctx, JSValueConst this_val)
{
JSObject *p;
JSTypedArray *ta;
@@ -54587,7 +54604,7 @@ static JSValue js_dataview_get_buffer(JSContext *ctx, JSValue this_val)
return js_dup(JS_MKPTR(JS_TAG_OBJECT, ta->buffer));
}
-static JSValue js_dataview_get_byteLength(JSContext *ctx, JSValue this_val)
+static JSValue js_dataview_get_byteLength(JSContext *ctx, JSValueConst this_val)
{
JSArrayBuffer *abuf;
JSTypedArray *ta;
@@ -54606,7 +54623,7 @@ static JSValue js_dataview_get_byteLength(JSContext *ctx, JSValue this_val)
return js_uint32(ta->length);
}
-static JSValue js_dataview_get_byteOffset(JSContext *ctx, JSValue this_val)
+static JSValue js_dataview_get_byteOffset(JSContext *ctx, JSValueConst this_val)
{
JSTypedArray *ta;
JSObject *p;
@@ -54621,12 +54638,12 @@ static JSValue js_dataview_get_byteOffset(JSContext *ctx, JSValue this_val)
}
static JSValue js_dataview_getValue(JSContext *ctx,
- JSValue this_obj,
- int argc, JSValue *argv, int class_id)
+ JSValueConst this_obj,
+ int argc, JSValueConst *argv, int class_id)
{
JSTypedArray *ta;
JSArrayBuffer *abuf;
- BOOL littleEndian, is_swap;
+ bool littleEndian, is_swap;
int size;
uint8_t *ptr;
uint32_t v;
@@ -54734,18 +54751,18 @@ static JSValue js_dataview_getValue(JSContext *ctx,
}
static JSValue js_dataview_setValue(JSContext *ctx,
- JSValue this_obj,
- int argc, JSValue *argv, int class_id)
+ JSValueConst this_obj,
+ int argc, JSValueConst *argv, int class_id)
{
JSTypedArray *ta;
JSArrayBuffer *abuf;
- BOOL littleEndian, is_swap;
+ bool littleEndian, is_swap;
int size;
uint8_t *ptr;
uint64_t v64;
uint32_t v;
uint64_t pos;
- JSValue val;
+ JSValueConst val;
ta = JS_GetOpaque2(ctx, this_obj, JS_CLASS_DATAVIEW);
if (!ta)
@@ -54869,7 +54886,7 @@ static JSValue js_new_uint8array(JSContext *ctx, JSValue buffer)
}
JSArrayBuffer *abuf = js_get_array_buffer(ctx, buffer);
assert(abuf != NULL);
- if (typed_array_init(ctx, obj, buffer, 0, abuf->byte_length, /*track_rab*/FALSE)) {
+ if (typed_array_init(ctx, obj, buffer, 0, abuf->byte_length, /*track_rab*/false)) {
// 'buffer' is freed on error above.
JS_FreeValue(ctx, obj);
return JS_EXCEPTION;
@@ -54879,13 +54896,13 @@ static JSValue js_new_uint8array(JSContext *ctx, JSValue buffer)
JSValue JS_NewUint8Array(JSContext *ctx, uint8_t *buf, size_t len,
JSFreeArrayBufferDataFunc *free_func, void *opaque,
- JS_BOOL is_shared)
+ bool is_shared)
{
JSClassID class_id =
is_shared ? JS_CLASS_SHARED_ARRAY_BUFFER : JS_CLASS_ARRAY_BUFFER;
JSValue buffer = js_array_buffer_constructor3(ctx, JS_UNDEFINED, len, NULL,
class_id, buf, free_func,
- opaque, FALSE);
+ opaque, false);
return js_new_uint8array(ctx, buffer);
}
@@ -54895,14 +54912,14 @@ JSValue JS_NewUint8ArrayCopy(JSContext *ctx, const uint8_t *buf, size_t len)
JS_CLASS_ARRAY_BUFFER,
(uint8_t *)buf,
js_array_buffer_free, NULL,
- TRUE);
+ true);
return js_new_uint8array(ctx, buffer);
}
-int JS_GetTypedArrayType(JSValue obj)
+int JS_GetTypedArrayType(JSValueConst obj)
{
JSClassID class_id = JS_GetClassID(obj);
- if (class_id >= JS_CLASS_UINT8C_ARRAY && class_id <= JS_CLASS_FLOAT64_ARRAY)
+ if (is_typed_array(class_id))
return class_id - JS_CLASS_UINT8C_ARRAY;
else
return -1;
@@ -54925,7 +54942,7 @@ typedef enum AtomicsOpEnum {
static void *js_atomics_get_ptr(JSContext *ctx,
JSArrayBuffer **pabuf,
int *psize_log2, JSClassID *pclass_id,
- JSValue obj, JSValue idx_val,
+ JSValueConst obj, JSValueConst idx_val,
int is_waitable)
{
JSObject *p;
@@ -54933,7 +54950,7 @@ static void *js_atomics_get_ptr(JSContext *ctx,
JSArrayBuffer *abuf;
void *ptr;
uint64_t idx;
- BOOL err;
+ bool err;
int size_log2;
if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)
@@ -54982,8 +54999,8 @@ static void *js_atomics_get_ptr(JSContext *ctx,
}
static JSValue js_atomics_op(JSContext *ctx,
- JSValue this_obj,
- int argc, JSValue *argv, int op)
+ JSValueConst this_obj,
+ int argc, JSValueConst *argv, int op)
{
int size_log2;
uint64_t v, a, rep_val;
@@ -55125,8 +55142,8 @@ static JSValue js_atomics_op(JSContext *ctx,
}
static JSValue js_atomics_store(JSContext *ctx,
- JSValue this_obj,
- int argc, JSValue *argv)
+ JSValueConst this_obj,
+ int argc, JSValueConst *argv)
{
int size_log2;
void *ptr;
@@ -55179,8 +55196,8 @@ static JSValue js_atomics_store(JSContext *ctx,
}
static JSValue js_atomics_isLockFree(JSContext *ctx,
- JSValue this_obj,
- int argc, JSValue *argv)
+ JSValueConst this_obj,
+ int argc, JSValueConst *argv)
{
int v, ret;
if (JS_ToInt32Sat(ctx, &v, argv[0]))
@@ -55191,7 +55208,7 @@ static JSValue js_atomics_isLockFree(JSContext *ctx,
typedef struct JSAtomicsWaiter {
struct list_head link;
- BOOL linked;
+ bool linked;
js_cond_t cond;
int32_t *ptr;
} JSAtomicsWaiter;
@@ -55204,8 +55221,8 @@ static struct list_head js_atomics_waiter_list =
// no-op: Atomics.pause() is not allowed to block or yield to another
// thread, only to hint the CPU that it should back off for a bit;
// the amount of work we do here is a good enough substitute
-static JSValue js_atomics_pause(JSContext *ctx, JSValue this_obj,
- int argc, JSValue *argv)
+static JSValue js_atomics_pause(JSContext *ctx, JSValueConst this_obj,
+ int argc, JSValueConst *argv)
{
double d;
@@ -55228,8 +55245,8 @@ static JSValue js_atomics_pause(JSContext *ctx, JSValue this_obj,
}
static JSValue js_atomics_wait(JSContext *ctx,
- JSValue this_obj,
- int argc, JSValue *argv)
+ JSValueConst this_obj,
+ int argc, JSValueConst *argv)
{
int64_t v;
int32_t v32;
@@ -55278,7 +55295,7 @@ static JSValue js_atomics_wait(JSContext *ctx,
waiter = &waiter_s;
waiter->ptr = ptr;
js_cond_init(&waiter->cond);
- waiter->linked = TRUE;
+ waiter->linked = true;
list_add_tail(&waiter->link, &js_atomics_waiter_list);
if (timeout == INT64_MAX) {
@@ -55299,8 +55316,8 @@ static JSValue js_atomics_wait(JSContext *ctx,
}
static JSValue js_atomics_notify(JSContext *ctx,
- JSValue this_obj,
- int argc, JSValue *argv)
+ JSValueConst this_obj,
+ int argc, JSValueConst *argv)
{
struct list_head *el, *el1, waiter_list;
int32_t count, n;
@@ -55329,7 +55346,7 @@ static JSValue js_atomics_notify(JSContext *ctx,
waiter = list_entry(el, JSAtomicsWaiter, link);
if (waiter->ptr == ptr) {
list_del(&waiter->link);
- waiter->linked = FALSE;
+ waiter->linked = false;
list_add_tail(&waiter->link, &waiter_list);
n++;
if (n >= count)
@@ -55476,7 +55493,7 @@ static double js__now_ms(void)
return js__hrtime_ns() / 1e6;
}
-static JSValue js_perf_now(JSContext *ctx, JSValue this_val, int argc, JSValue *argv)
+static JSValue js_perf_now(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
return js_float64(js__now_ms() - ctx->time_origin);
}
@@ -55501,7 +55518,7 @@ void JS_AddPerformance(JSContext *ctx)
}
/* Equality comparisons and sameness */
-int JS_IsEqual(JSContext *ctx, JSValue op1, JSValue op2)
+int JS_IsEqual(JSContext *ctx, JSValueConst op1, JSValueConst op2)
{
JSValue sp[2] = { js_dup(op1), js_dup(op2) };
if (js_eq_slow(ctx, endof(sp), 0))
@@ -55509,17 +55526,17 @@ int JS_IsEqual(JSContext *ctx, JSValue op1, JSValue op2)
return JS_VALUE_GET_BOOL(sp[0]);
}
-JS_BOOL JS_IsStrictEqual(JSContext *ctx, JSValue op1, JSValue op2)
+bool JS_IsStrictEqual(JSContext *ctx, JSValueConst op1, JSValueConst op2)
{
return js_strict_eq2(ctx, js_dup(op1), js_dup(op2), JS_EQ_STRICT);
}
-JS_BOOL JS_IsSameValue(JSContext *ctx, JSValue op1, JSValue op2)
+bool JS_IsSameValue(JSContext *ctx, JSValueConst op1, JSValueConst op2)
{
return js_same_value(ctx, op1, op2);
}
-JS_BOOL JS_IsSameValueZero(JSContext *ctx, JSValue op1, JSValue op2)
+bool JS_IsSameValueZero(JSContext *ctx, JSValueConst op1, JSValueConst op2)
{
return js_same_value_zero(ctx, op1, op2);
}
@@ -55527,13 +55544,13 @@ JS_BOOL JS_IsSameValueZero(JSContext *ctx, JSValue op1, JSValue op2)
/* WeakRef */
typedef struct JSWeakRefData {
- JSValue target;
+ JSValueConst target;
JSValue obj;
} JSWeakRefData;
static JSWeakRefData js_weakref_sentinel;
-static void js_weakref_finalizer(JSRuntime *rt, JSValue val)
+static void js_weakref_finalizer(JSRuntime *rt, JSValueConst val)
{
JSWeakRefData *wrd = JS_GetOpaque(val, JS_CLASS_WEAK_REF);
if (!wrd || wrd == &js_weakref_sentinel)
@@ -55555,11 +55572,12 @@ static void js_weakref_finalizer(JSRuntime *rt, JSValue val)
js_free_rt(rt, wr);
}
-static JSValue js_weakref_constructor(JSContext *ctx, JSValue new_target, int argc, JSValue *argv)
+static JSValue js_weakref_constructor(JSContext *ctx, JSValueConst new_target,
+ int argc, JSValueConst *argv)
{
if (JS_IsUndefined(new_target))
return JS_ThrowTypeError(ctx, "constructor requires 'new'");
- JSValue arg = argv[0];
+ JSValueConst arg = argv[0];
if (!is_valid_weakref_target(arg))
return JS_ThrowTypeError(ctx, "invalid target");
// TODO(saghul): short-circuit if the refcount is 1?
@@ -55587,7 +55605,7 @@ static JSValue js_weakref_constructor(JSContext *ctx, JSValue new_target, int ar
return obj;
}
-static JSValue js_weakref_deref(JSContext *ctx, JSValue this_val, int argc, JSValue *argv)
+static JSValue js_weakref_deref(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
JSWeakRefData *wrd = JS_GetOpaque2(ctx, this_val, JS_CLASS_WEAK_REF);
if (!wrd)
@@ -55608,8 +55626,8 @@ static const JSClassShortDef js_weakref_class_def[] = {
typedef struct JSFinRecEntry {
struct list_head link;
- JSValue obj;
- JSValue target;
+ JSValueConst obj;
+ JSValueConst target;
JSValue held_val;
JSValue token;
} JSFinRecEntry;
@@ -55636,7 +55654,7 @@ static void delete_finrec_weakref(JSRuntime *rt, JSFinRecEntry *fre)
js_free_rt(rt, wr);
}
-static void js_finrec_finalizer(JSRuntime *rt, JSValue val)
+static void js_finrec_finalizer(JSRuntime *rt, JSValueConst val)
{
JSFinalizationRegistryData *frd = JS_GetOpaque(val, JS_CLASS_FINALIZATION_REGISTRY);
if (frd) {
@@ -55660,7 +55678,8 @@ static void js_finrec_finalizer(JSRuntime *rt, JSValue val)
}
}
-static void js_finrec_mark(JSRuntime *rt, JSValue val, JS_MarkFunc *mark_func)
+static void js_finrec_mark(JSRuntime *rt, JSValueConst val,
+ JS_MarkFunc *mark_func)
{
JSFinalizationRegistryData *frd = JS_GetOpaque(val, JS_CLASS_FINALIZATION_REGISTRY);
if (frd) {
@@ -55674,11 +55693,12 @@ static void js_finrec_mark(JSRuntime *rt, JSValue val, JS_MarkFunc *mark_func)
}
}
-static JSValue js_finrec_constructor(JSContext *ctx, JSValue new_target, int argc, JSValue *argv)
+static JSValue js_finrec_constructor(JSContext *ctx, JSValueConst new_target,
+ int argc, JSValueConst *argv)
{
if (JS_IsUndefined(new_target))
return JS_ThrowTypeError(ctx, "constructor requires 'new'");
- JSValue cb = argv[0];
+ JSValueConst cb = argv[0];
if (!JS_IsFunction(ctx, cb))
return JS_ThrowTypeError(ctx, "argument must be a function");
@@ -55697,16 +55717,17 @@ static JSValue js_finrec_constructor(JSContext *ctx, JSValue new_target, int arg
return obj;
}
-static JSValue js_finrec_register(JSContext *ctx, JSValue this_val, int argc, JSValue *argv)
+static JSValue js_finrec_register(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSFinalizationRegistryData *frd = JS_GetOpaque2(ctx, this_val, JS_CLASS_FINALIZATION_REGISTRY);
if (!frd)
return JS_EXCEPTION;
- JSValue target = argv[0];
- JSValue held_val = argv[1];
+ JSValueConst target = argv[0];
+ JSValueConst held_val = argv[1];
// The function length needs to return 2, so the 3rd argument won't be initialized.
- JSValue token = argc > 2 ? argv[2] : JS_UNDEFINED;
+ JSValueConst token = argc > 2 ? argv[2] : JS_UNDEFINED;
if (!is_valid_weakref_target(target))
return JS_ThrowTypeError(ctx, "invalid target");
@@ -55737,18 +55758,18 @@ static JSValue js_finrec_register(JSContext *ctx, JSValue this_val, int argc, JS
return JS_UNDEFINED;
}
-static JSValue js_finrec_unregister(JSContext *ctx, JSValue this_val, int argc, JSValue *argv)
+static JSValue js_finrec_unregister(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
JSFinalizationRegistryData *frd = JS_GetOpaque2(ctx, this_val, JS_CLASS_FINALIZATION_REGISTRY);
if (!frd)
return JS_EXCEPTION;
- JSValue token = argv[0];
+ JSValueConst token = argv[0];
if (!is_valid_weakref_target(token))
return JS_ThrowTypeError(ctx, "invalid unregister token");
struct list_head *el, *el1;
- BOOL removed = FALSE;
+ bool removed = false;
list_for_each_safe(el, el1, &frd->entries) {
JSFinRecEntry *fre = list_entry(el, JSFinRecEntry, link);
if (js_same_value(ctx, fre->token, token)) {
@@ -55757,7 +55778,7 @@ static JSValue js_finrec_unregister(JSContext *ctx, JSValue this_val, int argc,
JS_FreeValue(ctx, fre->held_val);
JS_FreeValue(ctx, fre->token);
js_free(ctx, fre);
- removed = TRUE;
+ removed = true;
}
}
@@ -55774,7 +55795,7 @@ static const JSClassShortDef js_finrec_class_def[] = {
{ JS_ATOM_FinalizationRegistry, js_finrec_finalizer, js_finrec_mark }, /* JS_CLASS_FINALIZATION_REGISTRY */
};
-static JSValue js_finrec_job(JSContext *ctx, int argc, JSValue *argv)
+static JSValue js_finrec_job(JSContext *ctx, int argc, JSValueConst *argv)
{
return JS_Call(ctx, argv[0], JS_UNDEFINED, 1, &argv[1]);
}
@@ -55862,7 +55883,7 @@ static void reset_weak_ref(JSRuntime *rt, JSWeakRefRecord **first_weak_ref)
* During the GC sweep phase the held object might be collected first.
*/
if (!rt->in_free && (!JS_IsObject(fre->held_val) || JS_IsLiveObject(rt, fre->held_val))) {
- JSValue args[2];
+ JSValueConst args[2];
args[0] = frd->cb;
args[1] = fre->held_val;
JS_EnqueueJob(frd->ctx, js_finrec_job, 2, args);
@@ -55881,7 +55902,7 @@ static void reset_weak_ref(JSRuntime *rt, JSWeakRefRecord **first_weak_ref)
*first_weak_ref = NULL; /* fail safe */
}
-static BOOL is_valid_weakref_target(JSValue val)
+static bool is_valid_weakref_target(JSValueConst val)
{
switch (JS_VALUE_GET_TAG(val)) {
case JS_TAG_OBJECT:
@@ -55894,13 +55915,14 @@ static BOOL is_valid_weakref_target(JSValue val)
// fallthru
}
default:
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
}
-static void insert_weakref_record(JSValue target, struct JSWeakRefRecord *wr)
+static void insert_weakref_record(JSValueConst target,
+ struct JSWeakRefRecord *wr)
{
JSWeakRefRecord **pwr = get_first_weak_ref(target);
/* Add the weak reference */
@@ -55908,148 +55930,9 @@ static void insert_weakref_record(JSValue target, struct JSWeakRefRecord *wr)
*pwr = wr;
}
-/* Poly IC */
-
-JSInlineCache *init_ic(JSContext *ctx)
-{
- JSInlineCache *ic;
- ic = js_malloc(ctx, sizeof(JSInlineCache));
- if (unlikely(!ic))
- goto fail;
- ic->count = 0;
- ic->hash_bits = 2;
- ic->capacity = 1 << ic->hash_bits;
- ic->hash = js_mallocz(ctx, sizeof(ic->hash[0]) * ic->capacity);
- if (unlikely(!ic->hash))
- goto fail;
- ic->cache = NULL;
- return ic;
-fail:
- js_free(ctx, ic);
- return NULL;
-}
-
-int rebuild_ic(JSContext *ctx, JSInlineCache *ic)
-{
- uint32_t i, count;
- JSInlineCacheHashSlot *ch;
- if (ic->count == 0)
- goto end;
- count = 0;
- ic->cache = js_mallocz(ctx, sizeof(JSInlineCacheRingSlot) * ic->count);
- if (unlikely(!ic->cache))
- goto fail;
- for (i = 0; i < ic->capacity; i++) {
- for (ch = ic->hash[i]; ch != NULL; ch = ch->next) {
- ch->index = count++;
- ic->cache[ch->index].atom = JS_DupAtom(ctx, ch->atom);
- ic->cache[ch->index].index = 0;
- }
- }
-end:
- return 0;
-fail:
- return -1;
-}
-
-int resize_ic_hash(JSContext *ctx, JSInlineCache *ic)
-{
- uint32_t new_capacity, i, h;
- JSInlineCacheHashSlot *ch, *ch_next;
- JSInlineCacheHashSlot **new_hash;
- new_capacity = 1 << (ic->hash_bits + 1);
- new_hash = js_mallocz(ctx, sizeof(ic->hash[0]) * new_capacity);
- if (unlikely(!new_hash))
- goto fail;
- ic->hash_bits += 1;
- for (i = 0; i < ic->capacity; i++) {
- for (ch = ic->hash[i]; ch != NULL; ch = ch_next) {
- h = get_index_hash(ch->atom, ic->hash_bits);
- ch_next = ch->next;
- ch->next = new_hash[h];
- new_hash[h] = ch;
- }
- }
- js_free(ctx, ic->hash);
- ic->hash = new_hash;
- ic->capacity = new_capacity;
- return 0;
-fail:
- return -1;
-}
-
-int free_ic(JSRuntime* rt, JSInlineCache *ic)
-{
- uint32_t i;
- JSInlineCacheHashSlot *ch, *ch_next;
- JSShape **shape, *(*shapes)[IC_CACHE_ITEM_CAPACITY];
- if (ic->cache) {
- for (i = 0; i < ic->count; i++) {
- shapes = &ic->cache[i].shape;
- JS_FreeAtomRT(rt, ic->cache[i].atom);
- for (shape = *shapes; shape != endof(*shapes); shape++)
- js_free_shape_null(rt, *shape);
- }
- }
- for (i = 0; i < ic->capacity; i++) {
- for (ch = ic->hash[i]; ch != NULL; ch = ch_next) {
- ch_next = ch->next;
- JS_FreeAtomRT(rt, ch->atom);
- js_free_rt(rt, ch);
- }
- }
- if (ic->count > 0)
- js_free_rt(rt, ic->cache);
- js_free_rt(rt, ic->hash);
- js_free_rt(rt, ic);
- return 0;
-}
-
-static void add_ic_slot(JSContext *ctx, JSInlineCacheUpdate *icu,
- JSAtom atom, JSObject *object, uint32_t prop_offset)
-{
- int32_t i;
- uint32_t h;
- JSInlineCacheHashSlot *ch;
- JSInlineCacheRingSlot *cr;
- JSInlineCache *ic;
- JSShape *sh;
-
- if (!icu)
- return;
- ic = icu->ic;
- if (!ic)
- return;
- sh = object->shape;
- if (!sh->is_hashed)
- return;
- cr = NULL;
- h = get_index_hash(atom, ic->hash_bits);
- for (ch = ic->hash[h]; ch != NULL; ch = ch->next) {
- if (ch->atom == atom) {
- cr = ic->cache + ch->index;
- break;
- }
- }
- assert(cr != NULL);
- i = cr->index;
- do {
- if (sh == cr->shape[i]) {
- cr->prop_offset[i] = prop_offset;
- goto end;
- }
- i = (i + 1) % countof(cr->shape);
- } while (i != cr->index);
- js_free_shape_null(ctx->rt, cr->shape[i]);
- cr->shape[i] = js_dup_shape(sh);
- cr->prop_offset[i] = prop_offset;
-end:
- icu->offset = ch->index;
-}
-
/* CallSite */
-static void js_callsite_finalizer(JSRuntime *rt, JSValue val)
+static void js_callsite_finalizer(JSRuntime *rt, JSValueConst val)
{
JSCallSiteData *csd = JS_GetOpaque(val, JS_CLASS_CALL_SITE);
if (csd) {
@@ -56060,7 +55943,8 @@ static void js_callsite_finalizer(JSRuntime *rt, JSValue val)
}
}
-static void js_callsite_mark(JSRuntime *rt, JSValue val, JS_MarkFunc *mark_func)
+static void js_callsite_mark(JSRuntime *rt, JSValueConst val,
+ JS_MarkFunc *mark_func)
{
JSCallSiteData *csd = JS_GetOpaque(val, JS_CLASS_CALL_SITE);
if (csd) {
@@ -56111,7 +55995,7 @@ static void js_new_callsite_data(JSContext *ctx, JSCallSiteData *csd, JSStackFra
line_num1 = find_line_num(ctx, b,
sf->cur_pc - b->byte_code_buf - 1,
&col_num1);
- csd->native = FALSE;
+ csd->native = false;
csd->line_num = line_num1;
csd->col_num = col_num1;
csd->filename = JS_AtomToString(ctx, b->filename);
@@ -56120,7 +56004,7 @@ static void js_new_callsite_data(JSContext *ctx, JSCallSiteData *csd, JSStackFra
JS_FreeValue(ctx, JS_GetException(ctx)); // Clear exception.
}
} else {
- csd->native = TRUE;
+ csd->native = true;
csd->line_num = -1;
csd->col_num = -1;
csd->filename = JS_NULL;
@@ -56131,7 +56015,7 @@ static void js_new_callsite_data2(JSContext *ctx, JSCallSiteData *csd, const cha
{
csd->func = JS_NULL;
csd->func_name = JS_NULL;
- csd->native = FALSE;
+ csd->native = false;
csd->line_num = line_num;
csd->col_num = col_num;
/* filename is UTF-8 encoded if needed (original argument to __JS_EvalInternal()) */
@@ -56142,7 +56026,7 @@ static void js_new_callsite_data2(JSContext *ctx, JSCallSiteData *csd, const cha
}
}
-static JSValue js_callsite_getfield(JSContext *ctx, JSValue this_val, int argc, JSValue *argv, int magic)
+static JSValue js_callsite_getfield(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic)
{
JSCallSiteData *csd = JS_GetOpaque2(ctx, this_val, JS_CLASS_CALL_SITE);
if (!csd)
@@ -56151,7 +56035,7 @@ static JSValue js_callsite_getfield(JSContext *ctx, JSValue this_val, int argc,
return js_dup(*field);
}
-static JSValue js_callsite_isnative(JSContext *ctx, JSValue this_val, int argc, JSValue *argv)
+static JSValue js_callsite_isnative(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
JSCallSiteData *csd = JS_GetOpaque2(ctx, this_val, JS_CLASS_CALL_SITE);
if (!csd)
@@ -56159,7 +56043,7 @@ static JSValue js_callsite_isnative(JSContext *ctx, JSValue this_val, int argc,
return JS_NewBool(ctx, csd->native);
}
-static JSValue js_callsite_getnumber(JSContext *ctx, JSValue this_val, int argc, JSValue *argv, int magic)
+static JSValue js_callsite_getnumber(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic)
{
JSCallSiteData *csd = JS_GetOpaque2(ctx, this_val, JS_CLASS_CALL_SITE);
if (!csd)
@@ -56196,24 +56080,24 @@ static void _JS_AddIntrinsicCallSite(JSContext *ctx)
countof(js_callsite_proto_funcs));
}
-BOOL JS_DetectModule(const char *input, size_t input_len)
+bool JS_DetectModule(const char *input, size_t input_len)
{
JSRuntime *rt;
JSContext *ctx;
JSValue val;
- BOOL is_module;
+ bool is_module;
- is_module = TRUE;
+ is_module = true;
rt = JS_NewRuntime();
if (!rt)
- return FALSE;
+ return false;
ctx = JS_NewContextRaw(rt);
if (!ctx) {
JS_FreeRuntime(rt);
- return FALSE;
+ return false;
}
- JS_AddIntrinsicRegExp(ctx); // otherwise regexp literals don't parse
- val = __JS_EvalInternal(ctx, JS_UNDEFINED, input, input_len, "<unnamed>",
+ JS_AddIntrinsicRegExpCompiler(ctx); // otherwise regexp literals don't parse
+ val = __JS_EvalInternal(ctx, JS_UNDEFINED, input, input_len, "<unnamed>", 1,
JS_EVAL_TYPE_MODULE|JS_EVAL_FLAG_COMPILE_ONLY, -1);
if (JS_IsException(val)) {
const char *msg = JS_ToCString(ctx, rt->current_exception);
@@ -56229,7 +56113,9 @@ BOOL JS_DetectModule(const char *input, size_t input_len)
}
uintptr_t js_std_cmd(int cmd, ...) {
+ JSContext *ctx;
JSRuntime *rt;
+ JSValue *pv;
uintptr_t rv;
va_list ap;
@@ -56244,6 +56130,12 @@ uintptr_t js_std_cmd(int cmd, ...) {
rt = va_arg(ap, JSRuntime *);
rt->libc_opaque = va_arg(ap, void *);
break;
+ case 2: // ErrorBackTrace
+ ctx = va_arg(ap, JSContext *);
+ pv = va_arg(ap, JSValue *);
+ *pv = ctx->error_back_trace;
+ ctx->error_back_trace = JS_UNDEFINED;
+ break;
default:
rv = -1;
}
diff --git a/lib/monoucha0/monoucha/qjs/quickjs.h b/lib/monoucha0/monoucha/qjs/quickjs.h
index ad1cfa40..5e2db75f 100644
--- a/lib/monoucha0/monoucha/qjs/quickjs.h
+++ b/lib/monoucha0/monoucha/qjs/quickjs.h
@@ -1,10 +1,10 @@
/*
* QuickJS Javascript Engine
*
- * Copyright (c) 2017-2021 Fabrice Bellard
- * Copyright (c) 2017-2021 Charlie Gordon
- * Copyright (c) 2023 Ben Noordhuis
- * Copyright (c) 2023 Saúl Ibarra Corretgé
+ * Copyright (c) 2017-2024 Fabrice Bellard
+ * Copyright (c) 2017-2024 Charlie Gordon
+ * Copyright (c) 2023-2025 Ben Noordhuis
+ * Copyright (c) 2023-2025 Saúl Ibarra Corretgé
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -27,6 +27,7 @@
#ifndef QUICKJS_H
#define QUICKJS_H
+#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
@@ -36,17 +37,33 @@
extern "C" {
#endif
+#define QUICKJS_NG 1
+
#if defined(__GNUC__) || defined(__clang__)
#define js_force_inline inline __attribute__((always_inline))
-#define __js_printf_like(f, a) __attribute__((format(printf, f, a)))
#define JS_EXTERN __attribute__((visibility("default")))
#else
#define js_force_inline inline
-#define __js_printf_like(a, b)
#define JS_EXTERN /* nothing */
#endif
-#define JS_BOOL int
+/* Borrowed from Folly */
+#ifndef JS_PRINTF_FORMAT
+#ifdef _MSC_VER
+#include <sal.h>
+#define JS_PRINTF_FORMAT _Printf_format_string_
+#define JS_PRINTF_FORMAT_ATTR(format_param, dots_param)
+#else
+#define JS_PRINTF_FORMAT
+#if !defined(__clang__) && defined(__GNUC__)
+#define JS_PRINTF_FORMAT_ATTR(format_param, dots_param) \
+ __attribute__((format(gnu_printf, format_param, dots_param)))
+#else
+#define JS_PRINTF_FORMAT_ATTR(format_param, dots_param) \
+ __attribute__((format(printf, format_param, dots_param)))
+#endif
+#endif
+#endif
typedef struct JSRuntime JSRuntime;
typedef struct JSContext JSContext;
@@ -89,10 +106,55 @@ enum {
/* any larger tag is FLOAT64 if JS_NAN_BOXING */
};
-#define JS_FLOAT64_NAN NAN
-#define JSValueConst JSValue /* For backwards compatibility. */
+#if !defined(JS_CHECK_JSVALUE)
+#define JSValueConst JSValue
+#endif
-#if defined(JS_NAN_BOXING) && JS_NAN_BOXING
+// JS_CHECK_JSVALUE build mode does not produce working code but is here to
+// help catch reference counting bugs at compile time, by making it harder
+// to mix up JSValue and JSValueConst
+//
+// rules:
+//
+// - a function with a JSValue parameter takes ownership;
+// caller must *not* call JS_FreeValue
+//
+// - a function with a JSValueConst parameter does not take ownership;
+// caller *must* call JS_FreeValue
+//
+// - a function returning a JSValue transfers ownership to caller;
+// caller *must* call JS_FreeValue
+//
+// - a function returning a JSValueConst does *not* transfer ownership;
+// caller must *not* call JS_FreeValue
+#if defined(JS_CHECK_JSVALUE)
+
+typedef struct JSValue *JSValue;
+typedef const struct JSValue *JSValueConst;
+
+#define JS_MKVAL(tag, val) ((JSValue)((tag) | (intptr_t)(val) << 4))
+#define JS_MKPTR(tag, ptr) ((JSValue)((tag) | (intptr_t)(ptr)))
+#define JS_VALUE_GET_NORM_TAG(v) ((int)((intptr_t)(v) & 15))
+#define JS_VALUE_GET_TAG(v) ((int)((intptr_t)(v) & 15))
+#define JS_VALUE_GET_PTR(v) ((void *)((intptr_t)(v) & ~15))
+#define JS_VALUE_GET_INT(v) ((int)((intptr_t)(v) >> 4))
+#define JS_VALUE_GET_BOOL(v) ((int)((intptr_t)(v) >> 4))
+#define JS_VALUE_GET_FLOAT64(v) ((double)((intptr_t)(v) >> 4))
+#define JS_TAG_IS_FLOAT64(tag) ((int)(tag) == JS_TAG_FLOAT64)
+#define JS_NAN JS_MKVAL(JS_TAG_FLOAT64, 0)
+
+static inline JSValue __JS_NewFloat64(double d)
+{
+ return JS_MKVAL(JS_TAG_FLOAT64, (int)d);
+}
+
+static inline bool JS_VALUE_IS_NAN(JSValue v)
+{
+ (void)&v;
+ return false;
+}
+
+#elif defined(JS_NAN_BOXING) && JS_NAN_BOXING
typedef uint64_t JSValue;
@@ -148,7 +210,7 @@ static inline int JS_VALUE_GET_NORM_TAG(JSValue v)
return tag;
}
-static inline JS_BOOL JS_VALUE_IS_NAN(JSValue v)
+static inline bool JS_VALUE_IS_NAN(JSValue v)
{
uint32_t tag;
tag = JS_VALUE_GET_TAG(v);
@@ -195,7 +257,7 @@ static inline JSValue JS_MKVAL(int64_t tag, int32_t int32)
static inline JSValue JS_MKNAN(void)
{
JSValue v;
- v.u.float64 = JS_FLOAT64_NAN;
+ v.u.float64 = NAN;
v.tag = JS_TAG_FLOAT64;
return v;
}
@@ -206,7 +268,7 @@ static inline JSValue JS_MKNAN(void)
#else
#define JS_MKPTR(tag, p) (JSValue){ (JSValueUnion){ .ptr = p }, tag }
#define JS_MKVAL(tag, val) (JSValue){ (JSValueUnion){ .int32 = val }, tag }
-#define JS_NAN (JSValue){ (JSValueUnion){ .float64 = JS_FLOAT64_NAN }, JS_TAG_FLOAT64 }
+#define JS_NAN (JSValue){ (JSValueUnion){ .float64 = NAN }, JS_TAG_FLOAT64 }
#endif
#define JS_TAG_IS_FLOAT64(tag) ((unsigned)(tag) == JS_TAG_FLOAT64)
@@ -219,7 +281,7 @@ static inline JSValue __JS_NewFloat64(double d)
return v;
}
-static inline JS_BOOL JS_VALUE_IS_NAN(JSValue v)
+static inline bool JS_VALUE_IS_NAN(JSValue v)
{
union {
double d;
@@ -303,9 +365,9 @@ static inline JS_BOOL JS_VALUE_IS_NAN(JSValue v)
promise. Only allowed with JS_EVAL_TYPE_GLOBAL */
#define JS_EVAL_FLAG_ASYNC (1 << 7)
-typedef JSValue JSCFunction(JSContext *ctx, JSValue this_val, int argc, JSValue *argv);
-typedef JSValue JSCFunctionMagic(JSContext *ctx, JSValue this_val, int argc, JSValue *argv, int magic);
-typedef JSValue JSCFunctionData(JSContext *ctx, JSValue this_val, int argc, JSValue *argv, int magic, JSValue *func_data);
+typedef JSValue JSCFunction(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv);
+typedef JSValue JSCFunctionMagic(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic);
+typedef JSValue JSCFunctionData(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic, JSValueConst *func_data);
typedef struct JSMallocFunctions {
void *(*js_calloc)(void *opaque, size_t count, size_t size);
@@ -315,6 +377,29 @@ typedef struct JSMallocFunctions {
size_t (*js_malloc_usable_size)(const void *ptr);
} JSMallocFunctions;
+// Debug trace system: the debug output will be produced to the dump stream (currently
+// stdout) if dumps are enabled and JS_SetDumpFlags is invoked with the corresponding
+// bit set.
+#define JS_DUMP_BYTECODE_FINAL 0x01 /* dump pass 3 final byte code */
+#define JS_DUMP_BYTECODE_PASS2 0x02 /* dump pass 2 code */
+#define JS_DUMP_BYTECODE_PASS1 0x04 /* dump pass 1 code */
+#define JS_DUMP_BYTECODE_HEX 0x10 /* dump bytecode in hex */
+#define JS_DUMP_BYTECODE_PC2LINE 0x20 /* dump line number table */
+#define JS_DUMP_BYTECODE_STACK 0x40 /* dump compute_stack_size */
+#define JS_DUMP_BYTECODE_STEP 0x80 /* dump executed bytecode */
+#define JS_DUMP_READ_OBJECT 0x100 /* dump the marshalled objects at load time */
+#define JS_DUMP_FREE 0x200 /* dump every object free */
+#define JS_DUMP_GC 0x400 /* dump the occurrence of the automatic GC */
+#define JS_DUMP_GC_FREE 0x800 /* dump objects freed by the GC */
+#define JS_DUMP_MODULE_RESOLVE 0x1000 /* dump module resolution steps */
+#define JS_DUMP_PROMISE 0x2000 /* dump promise steps */
+#define JS_DUMP_LEAKS 0x4000 /* dump leaked objects and strings in JS_FreeRuntime */
+#define JS_DUMP_ATOM_LEAKS 0x8000 /* dump leaked atoms in JS_FreeRuntime */
+#define JS_DUMP_MEM 0x10000 /* dump memory usage in JS_FreeRuntime */
+#define JS_DUMP_OBJECTS 0x20000 /* dump objects in JS_FreeRuntime */
+#define JS_DUMP_ATOMS 0x40000 /* dump atoms in JS_FreeRuntime */
+#define JS_DUMP_SHAPES 0x80000 /* dump shapes in JS_FreeRuntime */
+
// Finalizers run in LIFO order at the very end of JS_FreeRuntime.
// Intended for cleanup of associated resources; the runtime itself
// is no longer usable.
@@ -330,6 +415,7 @@ JS_EXTERN void JS_SetRuntimeInfo(JSRuntime *rt, const char *info);
/* use 0 to disable memory limit */
JS_EXTERN void JS_SetMemoryLimit(JSRuntime *rt, size_t limit);
JS_EXTERN void JS_SetDumpFlags(JSRuntime *rt, uint64_t flags);
+JS_EXTERN uint64_t JS_GetDumpFlags(JSRuntime *rt);
JS_EXTERN size_t JS_GetGCThreshold(JSRuntime *rt);
JS_EXTERN void JS_SetGCThreshold(JSRuntime *rt, size_t gc_threshold);
/* use 0 to disable maximum stack size check */
@@ -346,9 +432,10 @@ JS_EXTERN int JS_AddRuntimeFinalizer(JSRuntime *rt,
JS_EXTERN void JS_SetRuntimeCleanUpFunc(JSRuntime *rt,
JSRuntimeCleanUpFunc cleanup_func);
typedef void JS_MarkFunc(JSRuntime *rt, JSGCObjectHeader *gp);
-JS_EXTERN void JS_MarkValue(JSRuntime *rt, JSValue val, JS_MarkFunc *mark_func);
+JS_EXTERN void JS_MarkValue(JSRuntime *rt, JSValueConst val,
+ JS_MarkFunc *mark_func);
JS_EXTERN void JS_RunGC(JSRuntime *rt);
-JS_EXTERN JS_BOOL JS_IsLiveObject(JSRuntime *rt, JSValue obj);
+JS_EXTERN bool JS_IsLiveObject(JSRuntime *rt, JSValueConst obj);
JS_EXTERN JSContext *JS_NewContext(JSRuntime *rt);
JS_EXTERN void JS_FreeContext(JSContext *s);
@@ -378,15 +465,15 @@ JS_EXTERN void JS_AddIntrinsicWeakRef(JSContext *ctx);
JS_EXTERN void JS_AddPerformance(JSContext *ctx);
/* for equality comparisons and sameness */
-JS_EXTERN int JS_IsEqual(JSContext *ctx, JSValue op1, JSValue op2);
-JS_EXTERN JS_BOOL JS_IsStrictEqual(JSContext *ctx, JSValue op1, JSValue op2);
-JS_EXTERN JS_BOOL JS_IsSameValue(JSContext *ctx, JSValue op1, JSValue op2);
+JS_EXTERN int JS_IsEqual(JSContext *ctx, JSValueConst op1, JSValueConst op2);
+JS_EXTERN bool JS_IsStrictEqual(JSContext *ctx, JSValueConst op1, JSValueConst op2);
+JS_EXTERN bool JS_IsSameValue(JSContext *ctx, JSValueConst op1, JSValueConst op2);
/* Similar to same-value equality, but +0 and -0 are considered equal. */
-JS_EXTERN JS_BOOL JS_IsSameValueZero(JSContext *ctx, JSValue op1, JSValue op2);
+JS_EXTERN bool JS_IsSameValueZero(JSContext *ctx, JSValueConst op1, JSValueConst op2);
/* Only used for running 262 tests. TODO(saghul) add build time flag. */
-JS_EXTERN JSValue js_string_codePointRange(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv);
+JS_EXTERN JSValue js_string_codePointRange(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv);
JS_EXTERN void *js_calloc_rt(JSRuntime *rt, size_t count, size_t size);
JS_EXTERN void *js_malloc_rt(JSRuntime *rt, size_t size);
@@ -436,12 +523,12 @@ JS_EXTERN void JS_FreeAtomRT(JSRuntime *rt, JSAtom v);
JS_EXTERN JSValue JS_AtomToValue(JSContext *ctx, JSAtom atom);
JS_EXTERN JSValue JS_AtomToString(JSContext *ctx, JSAtom atom);
JS_EXTERN const char *JS_AtomToCString(JSContext *ctx, JSAtom atom);
-JS_EXTERN JSAtom JS_ValueToAtom(JSContext *ctx, JSValue val);
+JS_EXTERN JSAtom JS_ValueToAtom(JSContext *ctx, JSValueConst val);
/* object class support */
typedef struct JSPropertyEnum {
- JS_BOOL is_enumerable;
+ bool is_enumerable;
JSAtom atom;
} JSPropertyEnum;
@@ -454,42 +541,41 @@ typedef struct JSPropertyDescriptor {
typedef struct JSClassExoticMethods {
/* Return -1 if exception (can only happen in case of Proxy object),
- FALSE if the property does not exists, TRUE if it exists. If 1 is
+ false if the property does not exists, true if it exists. If 1 is
returned, the property descriptor 'desc' is filled if != NULL. */
int (*get_own_property)(JSContext *ctx, JSPropertyDescriptor *desc,
- JSValue obj, JSAtom prop);
+ JSValueConst obj, JSAtom prop);
/* '*ptab' should hold the '*plen' property keys. Return 0 if OK,
-1 if exception. The 'is_enumerable' field is ignored.
*/
int (*get_own_property_names)(JSContext *ctx, JSPropertyEnum **ptab,
- uint32_t *plen,
- JSValue obj);
- /* return < 0 if exception, or TRUE/FALSE */
- int (*delete_property)(JSContext *ctx, JSValue obj, JSAtom prop);
- /* return < 0 if exception or TRUE/FALSE */
- int (*define_own_property)(JSContext *ctx, JSValue this_obj,
- JSAtom prop, JSValue val,
- JSValue getter, JSValue setter,
+ uint32_t *plen, JSValueConst obj);
+ /* return < 0 if exception, or true/false */
+ int (*delete_property)(JSContext *ctx, JSValueConst obj, JSAtom prop);
+ /* return < 0 if exception or true/false */
+ int (*define_own_property)(JSContext *ctx, JSValueConst this_obj,
+ JSAtom prop, JSValueConst val,
+ JSValueConst getter, JSValueConst setter,
int flags);
/* The following methods can be emulated with the previous ones,
so they are usually not needed */
- /* return < 0 if exception or TRUE/FALSE */
- int (*has_property)(JSContext *ctx, JSValue obj, JSAtom atom);
- JSValue (*get_property)(JSContext *ctx, JSValue obj, JSAtom atom,
- JSValue receiver);
- /* return < 0 if exception or TRUE/FALSE */
- int (*set_property)(JSContext *ctx, JSValue obj, JSAtom atom,
- JSValue value, JSValue receiver, int flags);
+ /* return < 0 if exception or true/false */
+ int (*has_property)(JSContext *ctx, JSValueConst obj, JSAtom atom);
+ JSValue (*get_property)(JSContext *ctx, JSValueConst obj, JSAtom atom,
+ JSValueConst receiver);
+ /* return < 0 if exception or true/false */
+ int (*set_property)(JSContext *ctx, JSValueConst obj, JSAtom atom,
+ JSValueConst value, JSValueConst receiver, int flags);
} JSClassExoticMethods;
-typedef void JSClassFinalizer(JSRuntime *rt, JSValue val);
-typedef void JSClassGCMark(JSRuntime *rt, JSValue val,
+typedef void JSClassFinalizer(JSRuntime *rt, JSValueConst val);
+typedef void JSClassGCMark(JSRuntime *rt, JSValueConst val,
JS_MarkFunc *mark_func);
#define JS_CALL_FLAG_CONSTRUCTOR (1 << 0)
-typedef JSValue JSClassCall(JSContext *ctx, JSValue func_obj,
- JSValue this_val, int argc, JSValue *argv,
- int flags);
-typedef JS_BOOL JSClassCanDestroy(JSRuntime *rt, JSValue val);
+typedef JSValue JSClassCall(JSContext *ctx, JSValueConst func_obj,
+ JSValueConst this_val, int argc,
+ JSValueConst *argv, int flags);
+typedef bool JSClassCanDestroy(JSRuntime *rt, JSValue val);
typedef struct JSClassDef {
const char *class_name; /* pure ASCII only! */
@@ -507,16 +593,26 @@ typedef struct JSClassDef {
JSClassCanDestroy *can_destroy;
} JSClassDef;
+#define JS_EVAL_OPTIONS_VERSION 1
+
+typedef struct JSEvalOptions {
+ int version;
+ int eval_flags;
+ const char *filename;
+ int line_num;
+ // can add new fields in ABI-compatible manner by incrementing JS_EVAL_OPTIONS_VERSION
+} JSEvalOptions;
+
#define JS_INVALID_CLASS_ID 0
JS_EXTERN JSClassID JS_NewClassID(JSRuntime *rt, JSClassID *pclass_id);
/* Returns the class ID if `v` is an object, otherwise returns JS_INVALID_CLASS_ID. */
-JS_EXTERN JSClassID JS_GetClassID(JSValue v);
+JS_EXTERN JSClassID JS_GetClassID(JSValueConst v);
JS_EXTERN int JS_NewClass(JSRuntime *rt, JSClassID class_id, const JSClassDef *class_def);
-JS_EXTERN int JS_IsRegisteredClass(JSRuntime *rt, JSClassID class_id);
+JS_EXTERN bool JS_IsRegisteredClass(JSRuntime *rt, JSClassID class_id);
/* value handling */
-static js_force_inline JSValue JS_NewBool(JSContext *ctx, JS_BOOL val)
+static js_force_inline JSValue JS_NewBool(JSContext *ctx, bool val)
{
(void)&ctx;
return JS_MKVAL(JS_TAG_BOOL, (val != 0));
@@ -566,106 +662,120 @@ JS_EXTERN JSValue JS_NewNumber(JSContext *ctx, double d);
JS_EXTERN JSValue JS_NewBigInt64(JSContext *ctx, int64_t v);
JS_EXTERN JSValue JS_NewBigUint64(JSContext *ctx, uint64_t v);
-static inline JS_BOOL JS_IsNumber(JSValue v)
+static inline bool JS_IsNumber(JSValueConst v)
{
int tag = JS_VALUE_GET_TAG(v);
return tag == JS_TAG_INT || JS_TAG_IS_FLOAT64(tag);
}
-static inline JS_BOOL JS_IsBigInt(JSContext *ctx, JSValue v)
+static inline bool JS_IsBigInt(JSContext *ctx, JSValueConst v)
{
(void)&ctx;
return JS_VALUE_GET_TAG(v) == JS_TAG_BIG_INT;
}
-static inline JS_BOOL JS_IsBool(JSValue v)
+static inline bool JS_IsBool(JSValueConst v)
{
return JS_VALUE_GET_TAG(v) == JS_TAG_BOOL;
}
-static inline JS_BOOL JS_IsNull(JSValue v)
+static inline bool JS_IsNull(JSValueConst v)
{
return JS_VALUE_GET_TAG(v) == JS_TAG_NULL;
}
-static inline JS_BOOL JS_IsUndefined(JSValue v)
+static inline bool JS_IsUndefined(JSValueConst v)
{
return JS_VALUE_GET_TAG(v) == JS_TAG_UNDEFINED;
}
-static inline JS_BOOL JS_IsException(JSValue v)
+static inline bool JS_IsException(JSValueConst v)
{
return JS_VALUE_GET_TAG(v) == JS_TAG_EXCEPTION;
}
-static inline JS_BOOL JS_IsUninitialized(JSValue v)
+static inline bool JS_IsUninitialized(JSValueConst v)
{
return JS_VALUE_GET_TAG(v) == JS_TAG_UNINITIALIZED;
}
-static inline JS_BOOL JS_IsString(JSValue v)
+static inline bool JS_IsString(JSValueConst v)
{
return JS_VALUE_GET_TAG(v) == JS_TAG_STRING;
}
-static inline JS_BOOL JS_IsSymbol(JSValue v)
+static inline bool JS_IsSymbol(JSValueConst v)
{
return JS_VALUE_GET_TAG(v) == JS_TAG_SYMBOL;
}
-static inline JS_BOOL JS_IsObject(JSValue v)
+static inline bool JS_IsObject(JSValueConst v)
{
return JS_VALUE_GET_TAG(v) == JS_TAG_OBJECT;
}
+static inline bool JS_IsModule(JSValueConst v)
+{
+ return JS_VALUE_GET_TAG(v) == JS_TAG_MODULE;
+}
+
JS_EXTERN JSValue JS_Throw(JSContext *ctx, JSValue obj);
JS_EXTERN JSValue JS_GetException(JSContext *ctx);
-JS_BOOL JS_HasException(JSContext *ctx);
-JS_EXTERN JS_BOOL JS_IsError(JSContext *ctx, JSValue val);
-JS_EXTERN JS_BOOL JS_IsUncatchableError(JSContext* ctx, JSValue val);
-JS_EXTERN void JS_SetUncatchableError(JSContext *ctx, JSValue val,
- JS_BOOL flag);
+JS_EXTERN bool JS_HasException(JSContext *ctx);
+JS_EXTERN bool JS_IsError(JSContext *ctx, JSValueConst val);
+JS_EXTERN bool JS_IsUncatchableError(JSContext* ctx, JSValueConst val);
+JS_EXTERN void JS_SetUncatchableError(JSContext *ctx, JSValueConst val);
+JS_EXTERN void JS_ClearUncatchableError(JSContext *ctx, JSValueConst val);
+// Shorthand for:
+// JSValue exc = JS_GetException(ctx);
+// JS_ClearUncatchableError(ctx, exc);
+// JS_Throw(ctx, exc);
JS_EXTERN void JS_ResetUncatchableError(JSContext *ctx);
JS_EXTERN JSValue JS_NewError(JSContext *ctx);
-JS_EXTERN JSValue __js_printf_like(2, 3) JS_ThrowPlainError(JSContext *ctx, const char *fmt, ...);
-JS_EXTERN JSValue __js_printf_like(2, 3) JS_ThrowSyntaxError(JSContext *ctx, const char *fmt, ...);
-JS_EXTERN JSValue __js_printf_like(2, 3) JS_ThrowTypeError(JSContext *ctx, const char *fmt, ...);
-JS_EXTERN JSValue __js_printf_like(2, 3) JS_ThrowReferenceError(JSContext *ctx, const char *fmt, ...);
-JS_EXTERN JSValue __js_printf_like(2, 3) JS_ThrowRangeError(JSContext *ctx, const char *fmt, ...);
-JS_EXTERN JSValue __js_printf_like(2, 3) JS_ThrowInternalError(JSContext *ctx, const char *fmt, ...);
+JS_EXTERN JSValue JS_PRINTF_FORMAT_ATTR(2, 3) JS_ThrowPlainError(JSContext *ctx, JS_PRINTF_FORMAT const char *fmt, ...);
+JS_EXTERN JSValue JS_PRINTF_FORMAT_ATTR(2, 3) JS_ThrowSyntaxError(JSContext *ctx, JS_PRINTF_FORMAT const char *fmt, ...);
+JS_EXTERN JSValue JS_PRINTF_FORMAT_ATTR(2, 3) JS_ThrowTypeError(JSContext *ctx, JS_PRINTF_FORMAT const char *fmt, ...);
+JS_EXTERN JSValue JS_PRINTF_FORMAT_ATTR(2, 3) JS_ThrowReferenceError(JSContext *ctx, JS_PRINTF_FORMAT const char *fmt, ...);
+JS_EXTERN JSValue JS_PRINTF_FORMAT_ATTR(2, 3) JS_ThrowRangeError(JSContext *ctx, JS_PRINTF_FORMAT const char *fmt, ...);
+JS_EXTERN JSValue JS_PRINTF_FORMAT_ATTR(2, 3) JS_ThrowInternalError(JSContext *ctx, JS_PRINTF_FORMAT const char *fmt, ...);
JS_EXTERN JSValue JS_ThrowOutOfMemory(JSContext *ctx);
JS_EXTERN void JS_FreeValue(JSContext *ctx, JSValue v);
JS_EXTERN void JS_FreeValueRT(JSRuntime *rt, JSValue v);
-JS_EXTERN JSValue JS_DupValue(JSContext *ctx, JSValue v);
-JS_EXTERN JSValue JS_DupValueRT(JSRuntime *rt, JSValue v);
-JS_EXTERN int JS_ToBool(JSContext *ctx, JSValue val); /* return -1 for JS_EXCEPTION */
-JS_EXTERN int JS_ToInt32(JSContext *ctx, int32_t *pres, JSValue val);
-static inline int JS_ToUint32(JSContext *ctx, uint32_t *pres, JSValue val)
+JS_EXTERN JSValue JS_DupValue(JSContext *ctx, JSValueConst v);
+JS_EXTERN JSValue JS_DupValueRT(JSRuntime *rt, JSValueConst v);
+JS_EXTERN int JS_ToBool(JSContext *ctx, JSValueConst val); /* return -1 for JS_EXCEPTION */
+static inline JSValue JS_ToBoolean(JSContext *ctx, JSValueConst val)
+{
+ return JS_NewBool(ctx, JS_ToBool(ctx, val));
+}
+JS_EXTERN JSValue JS_ToNumber(JSContext *ctx, JSValueConst val);
+JS_EXTERN int JS_ToInt32(JSContext *ctx, int32_t *pres, JSValueConst val);
+static inline int JS_ToUint32(JSContext *ctx, uint32_t *pres, JSValueConst val)
{
return JS_ToInt32(ctx, (int32_t*)pres, val);
}
-JS_EXTERN int JS_ToInt64(JSContext *ctx, int64_t *pres, JSValue val);
-JS_EXTERN int JS_ToIndex(JSContext *ctx, uint64_t *plen, JSValue val);
-JS_EXTERN int JS_ToFloat64(JSContext *ctx, double *pres, JSValue val);
+JS_EXTERN int JS_ToInt64(JSContext *ctx, int64_t *pres, JSValueConst val);
+JS_EXTERN int JS_ToIndex(JSContext *ctx, uint64_t *plen, JSValueConst val);
+JS_EXTERN int JS_ToFloat64(JSContext *ctx, double *pres, JSValueConst val);
/* return an exception if 'val' is a Number */
-JS_EXTERN int JS_ToBigInt64(JSContext *ctx, int64_t *pres, JSValue val);
-JS_EXTERN int JS_ToBigUint64(JSContext *ctx, uint64_t *pres, JSValue val);
+JS_EXTERN int JS_ToBigInt64(JSContext *ctx, int64_t *pres, JSValueConst val);
+JS_EXTERN int JS_ToBigUint64(JSContext *ctx, uint64_t *pres, JSValueConst val);
/* same as JS_ToInt64() but allow BigInt */
-JS_EXTERN int JS_ToInt64Ext(JSContext *ctx, int64_t *pres, JSValue val);
+JS_EXTERN int JS_ToInt64Ext(JSContext *ctx, int64_t *pres, JSValueConst val);
JS_EXTERN JSValue JS_NewStringLen(JSContext *ctx, const char *str1, size_t len1);
static inline JSValue JS_NewString(JSContext *ctx, const char *str) {
return JS_NewStringLen(ctx, str, strlen(str));
}
JS_EXTERN JSValue JS_NewAtomString(JSContext *ctx, const char *str);
-JS_EXTERN JSValue JS_ToString(JSContext *ctx, JSValue val);
-JS_EXTERN JSValue JS_ToPropertyKey(JSContext *ctx, JSValue val);
-JS_EXTERN const char *JS_ToCStringLen2(JSContext *ctx, size_t *plen, JSValue val1, JS_BOOL cesu8);
-static inline const char *JS_ToCStringLen(JSContext *ctx, size_t *plen, JSValue val1)
+JS_EXTERN JSValue JS_ToString(JSContext *ctx, JSValueConst val);
+JS_EXTERN JSValue JS_ToPropertyKey(JSContext *ctx, JSValueConst val);
+JS_EXTERN const char *JS_ToCStringLen2(JSContext *ctx, size_t *plen, JSValueConst val1, bool cesu8);
+static inline const char *JS_ToCStringLen(JSContext *ctx, size_t *plen, JSValueConst val1)
{
return JS_ToCStringLen2(ctx, plen, val1, 0);
}
-static inline const char *JS_ToCString(JSContext *ctx, JSValue val1)
+static inline const char *JS_ToCString(JSContext *ctx, JSValueConst val1)
{
return JS_ToCStringLen2(ctx, NULL, val1, 0);
}
@@ -673,48 +783,76 @@ JS_EXTERN void JS_FreeCString(JSContext *ctx, const char *ptr);
JS_EXTERN JSValue JS_NewNarrowStringLen(JSContext *ctx, const char *str,
size_t len);
-JS_EXTERN JS_BOOL JS_IsStringWideChar(JSValue value);
-JS_EXTERN uint8_t *JS_GetNarrowStringBuffer(JSValue value);
-JS_EXTERN uint32_t JS_GetStringLength(JSValue value);
+JS_EXTERN bool JS_IsStringWideChar(JSValueConst value);
+JS_EXTERN uint8_t *JS_GetNarrowStringBuffer(JSValueConst value);
+JS_EXTERN uint32_t JS_GetStringLength(JSValueConst value);
-JS_EXTERN JSValue JS_NewObjectProtoClass(JSContext *ctx, JSValue proto, JSClassID class_id);
+JS_EXTERN JSValue JS_NewObjectProtoClass(JSContext *ctx, JSValueConst proto,
+ JSClassID class_id);
JS_EXTERN JSValue JS_NewObjectClass(JSContext *ctx, int class_id);
-JS_EXTERN JSValue JS_NewObjectProto(JSContext *ctx, JSValue proto);
+JS_EXTERN JSValue JS_NewObjectProto(JSContext *ctx, JSValueConst proto);
JS_EXTERN JSValue JS_NewObject(JSContext *ctx);
-
-JS_EXTERN JS_BOOL JS_IsFunction(JSContext* ctx, JSValue val);
-JS_EXTERN JS_BOOL JS_IsConstructor(JSContext* ctx, JSValue val);
-JS_EXTERN JS_BOOL JS_SetConstructorBit(JSContext *ctx, JSValue func_obj, JS_BOOL val);
+// takes ownership of the values
+JS_EXTERN JSValue JS_NewObjectFrom(JSContext *ctx, int count,
+ const JSAtom *props,
+ const JSValue *values);
+// takes ownership of the values
+JS_EXTERN JSValue JS_NewObjectFromStr(JSContext *ctx, int count,
+ const char **props,
+ const JSValue *values);
+JS_EXTERN JSValue JS_ToObject(JSContext *ctx, JSValueConst val);
+JS_EXTERN JSValue JS_ToObjectString(JSContext *ctx, JSValueConst val);
+
+JS_EXTERN bool JS_IsFunction(JSContext* ctx, JSValueConst val);
+JS_EXTERN bool JS_IsConstructor(JSContext* ctx, JSValueConst val);
+JS_EXTERN bool JS_SetConstructorBit(JSContext *ctx, JSValueConst func_obj, bool val);
+
+JS_EXTERN bool JS_IsRegExp(JSValueConst val);
+JS_EXTERN bool JS_IsMap(JSValueConst val);
JS_EXTERN JSValue JS_NewArray(JSContext *ctx);
-JS_EXTERN int JS_IsArray(JSContext *ctx, JSValue val);
+// takes ownership of the values
+JS_EXTERN JSValue JS_NewArrayFrom(JSContext *ctx, int count,
+ const JSValue *values);
+// reader beware: JS_IsArray used to "punch" through proxies and check
+// if the target object is an array but it no longer does; use JS_IsProxy
+// and JS_GetProxyTarget instead, and remember that the target itself can
+// also be a proxy, ad infinitum
+JS_EXTERN bool JS_IsArray(JSValueConst val);
+
+JS_EXTERN bool JS_IsProxy(JSValueConst val);
+JS_EXTERN JSValue JS_GetProxyTarget(JSContext *ctx, JSValueConst proxy);
+JS_EXTERN JSValue JS_GetProxyHandler(JSContext *ctx, JSValueConst proxy);
JS_EXTERN JSValue JS_NewDate(JSContext *ctx, double epoch_ms);
+JS_EXTERN bool JS_IsDate(JSValueConst v);
-JS_EXTERN JSValue JS_GetProperty(JSContext *ctx, JSValue this_obj, JSAtom prop);
-JS_EXTERN JSValue JS_GetPropertyUint32(JSContext *ctx, JSValue this_obj,
+JS_EXTERN JSValue JS_GetProperty(JSContext *ctx, JSValueConst this_obj, JSAtom prop);
+JS_EXTERN JSValue JS_GetPropertyUint32(JSContext *ctx, JSValueConst this_obj,
uint32_t idx);
-JS_EXTERN JSValue JS_GetPropertyInt64(JSContext *ctx, JSValue this_obj,
+JS_EXTERN JSValue JS_GetPropertyInt64(JSContext *ctx, JSValueConst this_obj,
int64_t idx);
-JS_EXTERN JSValue JS_GetPropertyStr(JSContext *ctx, JSValue this_obj,
+JS_EXTERN JSValue JS_GetPropertyStr(JSContext *ctx, JSValueConst this_obj,
const char *prop);
-JS_EXTERN int JS_SetProperty(JSContext *ctx, JSValue this_obj,
+JS_EXTERN int JS_SetProperty(JSContext *ctx, JSValueConst this_obj,
JSAtom prop, JSValue val);
-JS_EXTERN int JS_SetPropertyUint32(JSContext *ctx, JSValue this_obj,
+JS_EXTERN int JS_SetPropertyUint32(JSContext *ctx, JSValueConst this_obj,
uint32_t idx, JSValue val);
-JS_EXTERN int JS_SetPropertyInt64(JSContext *ctx, JSValue this_obj,
+JS_EXTERN int JS_SetPropertyInt64(JSContext *ctx, JSValueConst this_obj,
int64_t idx, JSValue val);
-JS_EXTERN int JS_SetPropertyStr(JSContext *ctx, JSValue this_obj,
+JS_EXTERN int JS_SetPropertyStr(JSContext *ctx, JSValueConst this_obj,
const char *prop, JSValue val);
-JS_EXTERN int JS_HasProperty(JSContext *ctx, JSValue this_obj, JSAtom prop);
-JS_EXTERN int JS_IsExtensible(JSContext *ctx, JSValue obj);
-JS_EXTERN int JS_PreventExtensions(JSContext *ctx, JSValue obj);
-JS_EXTERN int JS_DeleteProperty(JSContext *ctx, JSValue obj, JSAtom prop, int flags);
-JS_EXTERN int JS_SetPrototype(JSContext *ctx, JSValue obj, JSValue proto_val);
-JS_EXTERN JSValue JS_GetPrototype(JSContext *ctx, JSValue val);
-JS_EXTERN int JS_GetLength(JSContext *ctx, JSValue obj, int64_t *pres);
-JS_EXTERN int JS_SetLength(JSContext *ctx, JSValue obj, int64_t len);
+JS_EXTERN int JS_HasProperty(JSContext *ctx, JSValueConst this_obj, JSAtom prop);
+JS_EXTERN int JS_IsExtensible(JSContext *ctx, JSValueConst obj);
+JS_EXTERN int JS_PreventExtensions(JSContext *ctx, JSValueConst obj);
+JS_EXTERN int JS_DeleteProperty(JSContext *ctx, JSValueConst obj, JSAtom prop, int flags);
+JS_EXTERN int JS_SetPrototype(JSContext *ctx, JSValueConst obj, JSValue proto_val);
+JS_EXTERN JSValue JS_GetPrototype(JSContext *ctx, JSValueConst val);
+JS_EXTERN int JS_GetLength(JSContext *ctx, JSValueConst obj, int64_t *pres);
+JS_EXTERN int JS_SetLength(JSContext *ctx, JSValueConst obj, int64_t len);
+JS_EXTERN int JS_SealObject(JSContext *ctx, JSValueConst obj);
+JS_EXTERN int JS_FreezeObject(JSContext *ctx, JSValueConst obj);
#define JS_GPN_STRING_MASK (1 << 0)
#define JS_GPN_SYMBOL_MASK (1 << 1)
@@ -725,72 +863,78 @@ JS_EXTERN int JS_SetLength(JSContext *ctx, JSValue obj, int64_t len);
#define JS_GPN_SET_ENUM (1 << 5)
JS_EXTERN int JS_GetOwnPropertyNames(JSContext *ctx, JSPropertyEnum **ptab,
- uint32_t *plen, JSValue obj, int flags);
+ uint32_t *plen, JSValueConst obj,
+ int flags);
JS_EXTERN int JS_GetOwnProperty(JSContext *ctx, JSPropertyDescriptor *desc,
- JSValue obj, JSAtom prop);
+ JSValueConst obj, JSAtom prop);
JS_EXTERN void JS_FreePropertyEnum(JSContext *ctx, JSPropertyEnum *tab,
uint32_t len);
-JS_EXTERN JSValue JS_Call(JSContext *ctx, JSValue func_obj, JSValue this_obj,
- int argc, JSValue *argv);
+JS_EXTERN JSValue JS_Call(JSContext *ctx, JSValueConst func_obj,
+ JSValueConst this_obj, int argc, JSValueConst *argv);
JSValue JS_NewObjectFromCtor(JSContext *ctx, JSValueConst ctor,
JSClassID class_id);
-JS_EXTERN JSValue JS_Invoke(JSContext *ctx, JSValue this_val, JSAtom atom,
- int argc, JSValue *argv);
-JS_EXTERN JSValue JS_CallConstructor(JSContext *ctx, JSValue func_obj,
- int argc, JSValue *argv);
-JS_EXTERN JSValue JS_CallConstructor2(JSContext *ctx, JSValue func_obj,
- JSValue new_target,
- int argc, JSValue *argv);
-/* Try to detect if the input is a module. Returns TRUE if parsing the input
+JS_EXTERN JSValue JS_Invoke(JSContext *ctx, JSValueConst this_val, JSAtom atom,
+ int argc, JSValueConst *argv);
+JS_EXTERN JSValue JS_CallConstructor(JSContext *ctx, JSValueConst func_obj,
+ int argc, JSValueConst *argv);
+JS_EXTERN JSValue JS_CallConstructor2(JSContext *ctx, JSValueConst func_obj,
+ JSValueConst new_target,
+ int argc, JSValueConst *argv);
+/* Try to detect if the input is a module. Returns true if parsing the input
* as a module produces no syntax errors. It's a naive approach that is not
* wholly infallible: non-strict classic scripts may _parse_ okay as a module
* but not _execute_ as one (different runtime semantics.) Use with caution.
* |input| can be either ASCII or UTF-8 encoded source code.
*/
-JS_EXTERN JS_BOOL JS_DetectModule(const char *input, size_t input_len);
+JS_EXTERN bool JS_DetectModule(const char *input, size_t input_len);
/* 'input' must be zero terminated i.e. input[input_len] = '\0'. */
JS_EXTERN JSValue JS_Eval(JSContext *ctx, const char *input, size_t input_len,
const char *filename, int eval_flags);
-/* same as JS_Eval() but with an explicit 'this_obj' parameter */
-JS_EXTERN JSValue JS_EvalThis(JSContext *ctx, JSValue this_obj,
+JS_EXTERN JSValue JS_Eval2(JSContext *ctx, const char *input, size_t input_len,
+ JSEvalOptions *options);
+JS_EXTERN JSValue JS_EvalThis(JSContext *ctx, JSValueConst this_obj,
const char *input, size_t input_len,
const char *filename, int eval_flags);
+JS_EXTERN JSValue JS_EvalThis2(JSContext *ctx, JSValueConst this_obj,
+ const char *input, size_t input_len,
+ JSEvalOptions *options);
JS_EXTERN JSValue JS_GetGlobalObject(JSContext *ctx);
-JS_EXTERN int JS_IsInstanceOf(JSContext *ctx, JSValue val, JSValue obj);
-JS_EXTERN int JS_DefineProperty(JSContext *ctx, JSValue this_obj,
- JSAtom prop, JSValue val,
- JSValue getter, JSValue setter, int flags);
-JS_EXTERN int JS_DefinePropertyValue(JSContext *ctx, JSValue this_obj,
+JS_EXTERN int JS_IsInstanceOf(JSContext *ctx, JSValueConst val, JSValueConst obj);
+JS_EXTERN int JS_DefineProperty(JSContext *ctx, JSValueConst this_obj,
+ JSAtom prop, JSValueConst val,
+ JSValueConst getter, JSValueConst setter,
+ int flags);
+JS_EXTERN int JS_DefinePropertyValue(JSContext *ctx, JSValueConst this_obj,
JSAtom prop, JSValue val, int flags);
-JS_EXTERN int JS_DefinePropertyValueUint32(JSContext *ctx, JSValue this_obj,
+JS_EXTERN int JS_DefinePropertyValueUint32(JSContext *ctx, JSValueConst this_obj,
uint32_t idx, JSValue val, int flags);
-JS_EXTERN int JS_DefinePropertyValueStr(JSContext *ctx, JSValue this_obj,
+JS_EXTERN int JS_DefinePropertyValueStr(JSContext *ctx, JSValueConst this_obj,
const char *prop, JSValue val, int flags);
-JS_EXTERN int JS_DefinePropertyGetSet(JSContext *ctx, JSValue this_obj,
+JS_EXTERN int JS_DefinePropertyGetSet(JSContext *ctx, JSValueConst this_obj,
JSAtom prop, JSValue getter, JSValue setter,
int flags);
/* Only supported for custom classes, returns 0 on success < 0 otherwise. */
-JS_EXTERN int JS_SetOpaque(JSValue obj, void *opaque);
-JS_EXTERN void *JS_GetOpaque(JSValue obj, JSClassID class_id);
-JS_EXTERN void *JS_GetOpaque2(JSContext *ctx, JSValue obj, JSClassID class_id);
-JS_EXTERN void *JS_GetAnyOpaque(JSValue obj, JSClassID *class_id);
+JS_EXTERN int JS_SetOpaque(JSValueConst obj, void *opaque);
+JS_EXTERN void *JS_GetOpaque(JSValueConst obj, JSClassID class_id);
+JS_EXTERN void *JS_GetOpaque2(JSContext *ctx, JSValueConst obj, JSClassID class_id);
+JS_EXTERN void *JS_GetAnyOpaque(JSValueConst obj, JSClassID *class_id);
/* 'buf' must be zero terminated i.e. buf[buf_len] = '\0'. */
JS_EXTERN JSValue JS_ParseJSON(JSContext *ctx, const char *buf, size_t buf_len,
const char *filename);
-JS_EXTERN JSValue JS_JSONStringify(JSContext *ctx, JSValue obj,
- JSValue replacer, JSValue space0);
+JS_EXTERN JSValue JS_JSONStringify(JSContext *ctx, JSValueConst obj,
+ JSValueConst replacer, JSValueConst space0);
typedef void JSFreeArrayBufferDataFunc(JSRuntime *rt, void *opaque, void *ptr);
JS_EXTERN JSValue JS_NewArrayBuffer(JSContext *ctx, uint8_t *buf, size_t len,
JSFreeArrayBufferDataFunc *free_func, void *opaque,
- JS_BOOL is_shared);
+ bool is_shared);
JS_EXTERN JSValue JS_NewArrayBufferCopy(JSContext *ctx, const uint8_t *buf, size_t len);
-JS_EXTERN void JS_DetachArrayBuffer(JSContext *ctx, JSValue obj);
-JS_EXTERN uint8_t *JS_GetArrayBuffer(JSContext *ctx, size_t *psize, JSValue obj);
-JS_EXTERN JS_BOOL JS_IsArrayBuffer(JSValue obj);
-JS_EXTERN uint8_t *JS_GetUint8Array(JSContext *ctx, size_t *psize, JSValue obj);
+JS_EXTERN void JS_DetachArrayBuffer(JSContext *ctx, JSValueConst obj);
+JS_EXTERN uint8_t *JS_GetArrayBuffer(JSContext *ctx, size_t *psize, JSValueConst obj);
+JS_EXTERN bool JS_IsArrayBuffer(JSValueConst obj);
+JS_EXTERN uint8_t *JS_GetUint8Array(JSContext *ctx, size_t *psize, JSValueConst obj);
typedef enum JSTypedArrayEnum {
JS_TYPED_ARRAY_UINT8C = 0,
@@ -807,17 +951,17 @@ typedef enum JSTypedArrayEnum {
JS_TYPED_ARRAY_FLOAT64,
} JSTypedArrayEnum;
-JS_EXTERN JSValue JS_NewTypedArray(JSContext *ctx, int argc, JSValue *argv,
- JSTypedArrayEnum array_type);
-JS_EXTERN JSValue JS_GetTypedArrayBuffer(JSContext *ctx, JSValue obj,
+JS_EXTERN JSValue JS_NewTypedArray(JSContext *ctx, int argc, JSValueConst *argv,
+ JSTypedArrayEnum array_type);
+JS_EXTERN JSValue JS_GetTypedArrayBuffer(JSContext *ctx, JSValueConst obj,
size_t *pbyte_offset,
size_t *pbyte_length,
size_t *pbytes_per_element);
JS_EXTERN JSValue JS_NewUint8Array(JSContext *ctx, uint8_t *buf, size_t len,
JSFreeArrayBufferDataFunc *free_func, void *opaque,
- JS_BOOL is_shared);
+ bool is_shared);
/* returns -1 if not a typed array otherwise return a JSTypedArrayEnum value */
-JS_EXTERN int JS_GetTypedArrayType(JSValue obj);
+JS_EXTERN int JS_GetTypedArrayType(JSValueConst obj);
JS_EXTERN JSValue JS_NewUint8ArrayCopy(JSContext *ctx, const uint8_t *buf, size_t len);
typedef struct {
void *(*sab_alloc)(void *opaque, size_t size);
@@ -834,24 +978,26 @@ typedef enum JSPromiseStateEnum {
} JSPromiseStateEnum;
JS_EXTERN JSValue JS_NewPromiseCapability(JSContext *ctx, JSValue *resolving_funcs);
-JS_EXTERN JSPromiseStateEnum JS_PromiseState(JSContext *ctx, JSValue promise);
-JS_EXTERN JSValue JS_PromiseResult(JSContext *ctx, JSValue promise);
+JS_EXTERN JSPromiseStateEnum JS_PromiseState(JSContext *ctx,
+ JSValueConst promise);
+JS_EXTERN JSValue JS_PromiseResult(JSContext *ctx, JSValueConst promise);
+JS_EXTERN bool JS_IsPromise(JSValueConst val);
-JS_EXTERN JSValue JS_NewSymbol(JSContext *ctx, const char *description, JS_BOOL is_global);
+JS_EXTERN JSValue JS_NewSymbol(JSContext *ctx, const char *description, bool is_global);
-/* is_handled = TRUE means that the rejection is handled */
-typedef void JSHostPromiseRejectionTracker(JSContext *ctx, JSValue promise,
- JSValue reason,
- JS_BOOL is_handled, void *opaque);
+/* is_handled = true means that the rejection is handled */
+typedef void JSHostPromiseRejectionTracker(JSContext *ctx, JSValueConst promise,
+ JSValueConst reason,
+ bool is_handled, void *opaque);
JS_EXTERN void JS_SetHostPromiseRejectionTracker(JSRuntime *rt, JSHostPromiseRejectionTracker *cb, void *opaque);
/* return != 0 if the JS code needs to be interrupted */
typedef int JSInterruptHandler(JSRuntime *rt, void *opaque);
JS_EXTERN void JS_SetInterruptHandler(JSRuntime *rt, JSInterruptHandler *cb, void *opaque);
-/* if can_block is TRUE, Atomics.wait() can be used */
-JS_EXTERN void JS_SetCanBlock(JSRuntime *rt, JS_BOOL can_block);
+/* if can_block is true, Atomics.wait() can be used */
+JS_EXTERN void JS_SetCanBlock(JSRuntime *rt, bool can_block);
/* set the [IsHTMLDDA] internal slot */
-JS_EXTERN void JS_SetIsHTMLDDA(JSContext *ctx, JSValue obj);
+JS_EXTERN void JS_SetIsHTMLDDA(JSContext *ctx, JSValueConst obj);
typedef struct JSModuleDef JSModuleDef;
@@ -875,10 +1021,11 @@ JS_EXTERN JSValue JS_GetModuleNamespace(JSContext *ctx, JSModuleDef *m);
/* JS Job support */
-typedef JSValue JSJobFunc(JSContext *ctx, int argc, JSValue *argv);
-JS_EXTERN int JS_EnqueueJob(JSContext *ctx, JSJobFunc *job_func, int argc, JSValue *argv);
+typedef JSValue JSJobFunc(JSContext *ctx, int argc, JSValueConst *argv);
+JS_EXTERN int JS_EnqueueJob(JSContext *ctx, JSJobFunc *job_func,
+ int argc, JSValueConst *argv);
-JS_EXTERN JS_BOOL JS_IsJobPending(JSRuntime *rt);
+JS_EXTERN bool JS_IsJobPending(JSRuntime *rt);
JS_EXTERN int JS_ExecutePendingJob(JSRuntime *rt, JSContext **pctx);
/* Structure to retrieve (de)serialized SharedArrayBuffer objects. */
@@ -894,8 +1041,8 @@ typedef struct JSSABTab {
#define JS_WRITE_OBJ_REFERENCE (1 << 3) /* allow object references to encode arbitrary object graph */
#define JS_WRITE_OBJ_STRIP_SOURCE (1 << 4) /* do not write source code information */
#define JS_WRITE_OBJ_STRIP_DEBUG (1 << 5) /* do not write debug information */
-JS_EXTERN uint8_t *JS_WriteObject(JSContext *ctx, size_t *psize, JSValue obj, int flags);
-JS_EXTERN uint8_t *JS_WriteObject2(JSContext *ctx, size_t *psize, JSValue obj,
+JS_EXTERN uint8_t *JS_WriteObject(JSContext *ctx, size_t *psize, JSValueConst obj, int flags);
+JS_EXTERN uint8_t *JS_WriteObject2(JSContext *ctx, size_t *psize, JSValueConst obj,
int flags, JSSABTab *psab_tab);
#define JS_READ_OBJ_BYTECODE (1 << 0) /* allow function/module */
@@ -910,13 +1057,13 @@ JS_EXTERN JSValue JS_ReadObject2(JSContext *ctx, const uint8_t *buf, size_t buf_
JS_EXTERN JSValue JS_EvalFunction(JSContext *ctx, JSValue fun_obj);
/* load the dependencies of the module 'obj'. Useful when JS_ReadObject()
returns a module. */
-JS_EXTERN int JS_ResolveModule(JSContext *ctx, JSValue obj);
+JS_EXTERN int JS_ResolveModule(JSContext *ctx, JSValueConst obj);
/* only exported for os.Worker() */
JS_EXTERN JSAtom JS_GetScriptOrModuleName(JSContext *ctx, int n_stack_levels);
/* only exported for os.Worker() */
JS_EXTERN JSValue JS_LoadModule(JSContext *ctx, const char *basename,
- const char *filename);
+ const char *filename);
/* C function definition */
typedef enum JSCFunctionEnum { /* XXX: should rename for namespace isolation */
@@ -937,18 +1084,18 @@ typedef enum JSCFunctionEnum { /* XXX: should rename for namespace isolation */
typedef union JSCFunctionType {
JSCFunction *generic;
- JSValue (*generic_magic)(JSContext *ctx, JSValue this_val, int argc, JSValue *argv, int magic);
+ JSValue (*generic_magic)(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic);
JSCFunction *constructor;
- JSValue (*constructor_magic)(JSContext *ctx, JSValue new_target, int argc, JSValue *argv, int magic);
+ JSValue (*constructor_magic)(JSContext *ctx, JSValueConst new_target, int argc, JSValueConst *argv, int magic);
JSCFunction *constructor_or_func;
double (*f_f)(double);
double (*f_f_f)(double, double);
- JSValue (*getter)(JSContext *ctx, JSValue this_val);
- JSValue (*setter)(JSContext *ctx, JSValue this_val, JSValue val);
- JSValue (*getter_magic)(JSContext *ctx, JSValue this_val, int magic);
- JSValue (*setter_magic)(JSContext *ctx, JSValue this_val, JSValue val, int magic);
- JSValue (*iterator_next)(JSContext *ctx, JSValue this_val,
- int argc, JSValue *argv, int *pdone, int magic);
+ JSValue (*getter)(JSContext *ctx, JSValueConst this_val);
+ JSValue (*setter)(JSContext *ctx, JSValueConst this_val, JSValueConst val);
+ JSValue (*getter_magic)(JSContext *ctx, JSValueConst this_val, int magic);
+ JSValue (*setter_magic)(JSContext *ctx, JSValueConst this_val, JSValueConst val, int magic);
+ JSValue (*iterator_next)(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv, int *pdone, int magic);
} JSCFunctionType;
JS_EXTERN JSValue JS_NewCFunction2(JSContext *ctx, JSCFunction *func,
@@ -960,25 +1107,25 @@ JS_EXTERN JSValue JS_NewCFunction3(JSContext *ctx, JSCFunction *func,
JSValue proto_val);
JS_EXTERN JSValue JS_NewCFunctionData(JSContext *ctx, JSCFunctionData *func,
int length, int magic, int data_len,
- JSValue *data);
+ JSValueConst *data);
-static inline JSValue JS_NewCFunction(JSContext *ctx, JSCFunction *func, const char *name,
- int length)
+static inline JSValue JS_NewCFunction(JSContext *ctx, JSCFunction *func,
+ const char *name, int length)
{
return JS_NewCFunction2(ctx, func, name, length, JS_CFUNC_generic, 0);
}
static inline JSValue JS_NewCFunctionMagic(JSContext *ctx, JSCFunctionMagic *func,
- const char *name,
- int length, JSCFunctionEnum cproto, int magic)
+ const char *name, int length,
+ JSCFunctionEnum cproto, int magic)
{
/* Used to squelch a -Wcast-function-type warning. */
JSCFunctionType ft;
ft.generic_magic = func;
return JS_NewCFunction2(ctx, ft.generic, name, length, cproto, magic);
}
-JS_EXTERN void JS_SetConstructor(JSContext *ctx, JSValue func_obj,
- JSValue proto);
+JS_EXTERN void JS_SetConstructor(JSContext *ctx, JSValueConst func_obj,
+ JSValueConst proto);
/* C property definition */
@@ -1066,7 +1213,7 @@ JS_EXTERN int JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m,
/* Version */
#define QJS_VERSION_MAJOR 0
-#define QJS_VERSION_MINOR 8
+#define QJS_VERSION_MINOR 9
#define QJS_VERSION_PATCH 0
#define QJS_VERSION_SUFFIX ""
@@ -1077,7 +1224,6 @@ JS_EXTERN uintptr_t js_std_cmd(int cmd, ...);
#undef JS_EXTERN
#undef js_force_inline
-#undef __js_printf_like
#ifdef __cplusplus
} /* extern "C" { */
diff --git a/lib/monoucha0/monoucha/quickjs.nim b/lib/monoucha0/monoucha/quickjs.nim
index 1ec0f2f0..f4d7fab2 100644
--- a/lib/monoucha0/monoucha/quickjs.nim
+++ b/lib/monoucha0/monoucha/quickjs.nim
@@ -245,7 +245,7 @@ type
magic*: int16
u* {.importc.}: JSCFunctionListEntryU
- JS_BOOL* = distinct cint
+ JS_BOOL* {.importc: "bool".} = bool
JSPropertyEnum* {.importc.} = object
is_enumerable*: JS_BOOL
@@ -277,12 +277,6 @@ type
func `==`*(a, b: JSAtom): bool {.borrow.}
-converter toBool*(js: JS_BOOL): bool {.inline.} =
- cast[cint](js) != 0
-
-converter toJSBool*(b: bool): JS_BOOL {.inline.} =
- cast[JS_BOOL](cint(b))
-
converter toJSClassID*(e: JSClassEnum): JSClassID {.inline.} =
JSClassID(e)
@@ -524,7 +518,7 @@ proc JS_Throw*(ctx: JSContext; obj: JSValue): JSValue
proc JS_GetException*(ctx: JSContext): JSValue
proc JS_IsError*(ctx: JSContext; v: JSValue): JS_BOOL
proc JS_IsUncatchableError*(ctx: JSContext; val: JSValue): JS_BOOL
-proc JS_SetUncatchableError*(ctx: JSContext; val: JSValue; flag: JS_BOOL)
+proc JS_SetUncatchableError*(ctx: JSContext; val: JSValue)
proc JS_ResetUncatchableError*(ctx: JSContext)
proc JS_NewError*(ctx: JSContext): JSValue
proc JS_ThrowPlainError*(ctx: JSContext; fmt: cstring): JSValue {.varargs,