diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 002fd763c..ed2ce08aa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -592,3 +592,11 @@ jobs: - name: test run: | make test RUN262=$RUNNER_TEMP/run-test262 + + jscheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: jscheck + run: | + make jscheck diff --git a/Makefile b/Makefile index 403461dad..4ea5f46fd 100644 --- a/Makefile +++ b/Makefile @@ -90,6 +90,23 @@ distclean: stats: $(QJS) $(QJS) -qd +jscheck: CFLAGS=-I. -D_GNU_SOURCE -DJS_CHECK_JSVALUE -Wall -Werror -fsyntax-only -c -o /dev/null +jscheck: + $(CC) $(CFLAGS) api-test.c + $(CC) $(CFLAGS) ctest.c + $(CC) $(CFLAGS) fuzz.c + $(CC) $(CFLAGS) gen/function_source.c + $(CC) $(CFLAGS) gen/hello.c + $(CC) $(CFLAGS) gen/hello_module.c + $(CC) $(CFLAGS) gen/repl.c + $(CC) $(CFLAGS) gen/standalone.c + $(CC) $(CFLAGS) gen/test_fib.c + $(CC) $(CFLAGS) qjs.c + $(CC) $(CFLAGS) qjsc.c + $(CC) $(CFLAGS) quickjs-libc.c + $(CC) $(CFLAGS) quickjs.c + $(CC) $(CFLAGS) run-test262.c + # effectively .PHONY because it doesn't generate output ctest: CFLAGS=-std=c11 -fsyntax-only -Wall -Wextra -Werror -pedantic ctest: ctest.c quickjs.h @@ -126,4 +143,4 @@ unicode_gen: $(BUILD_DIR) libunicode-table.h: unicode_gen $(BUILD_DIR)/unicode_gen unicode $@ -.PHONY: all amalgam ctest cxxtest debug fuzz install clean codegen distclean stats test test262 test262-update test262-check microbench unicode_gen $(QJS) $(QJSC) +.PHONY: all amalgam ctest cxxtest debug fuzz jscheck install clean codegen distclean stats test test262 test262-update test262-check microbench unicode_gen $(QJS) $(QJSC) diff --git a/api-test.c b/api-test.c index 84b275815..d0d69c22a 100644 --- a/api-test.c +++ b/api-test.c @@ -74,7 +74,8 @@ static void async_call(void) JS_FreeRuntime(rt); } -static JSValue save_value(JSContext *ctx, JSValue this_val, int argc, JSValue *argv) +static JSValue save_value(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { assert(argc == 1); JSValue *p = (JSValue *)JS_GetContextOpaque(ctx); diff --git a/qjs.c b/qjs.c index cb66fdf96..d2a68dfc1 100644 --- a/qjs.c +++ b/qjs.c @@ -199,14 +199,14 @@ static int64_t parse_limit(const char *arg) { return (int64_t)(d * unit); } -static JSValue js_gc(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_gc(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { JS_RunGC(JS_GetRuntime(ctx)); return JS_UNDEFINED; } -static JSValue js_navigator_get_userAgent(JSContext *ctx, JSValue this_val) +static JSValue js_navigator_get_userAgent(JSContext *ctx, JSValueConst this_val) { char version[32]; snprintf(version, sizeof(version), "quickjs-ng/%s", JS_GetVersion()); @@ -667,7 +667,7 @@ int main(int argc, char **argv) args[0] = JS_NewString(ctx, compile_file); args[1] = JS_NewString(ctx, out); args[2] = JS_NewString(ctx, exe != NULL ? exe : argv[0]); - ret = JS_Call(ctx, func, JS_UNDEFINED, countof(args), args); + ret = JS_Call(ctx, func, JS_UNDEFINED, 3, (JSValueConst *)args); JS_FreeValue(ctx, func); JS_FreeValue(ctx, args[0]); JS_FreeValue(ctx, args[1]); diff --git a/quickjs-libc.c b/quickjs-libc.c index ce1aa1c09..2529fb840 100644 --- a/quickjs-libc.c +++ b/quickjs-libc.c @@ -197,7 +197,7 @@ static void js_set_thread_state(JSRuntime *rt, JSThreadState *ts) #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif // __GNUC__ static JSValue js_printf_internal(JSContext *ctx, - int argc, JSValue *argv, FILE *fp) + int argc, JSValueConst *argv, FILE *fp) { char fmtbuf[32]; uint8_t cbuf[UTF8_CHAR_LEN_MAX+1]; @@ -453,8 +453,8 @@ uint8_t *js_load_file(JSContext *ctx, size_t *pbuf_len, const char *filename) } /* load and evaluate a file */ -static JSValue js_loadScript(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_loadScript(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { uint8_t *buf; const char *filename; @@ -478,7 +478,7 @@ static JSValue js_loadScript(JSContext *ctx, JSValue this_val, } static int get_bool_option(JSContext *ctx, bool *pbool, - JSValue obj, + JSValueConst obj, const char *option) { JSValue val; @@ -497,12 +497,13 @@ static void free_buf(JSRuntime *rt, void *opaque, void *ptr) { } /* load a file as a UTF-8 encoded string or Uint8Array */ -static JSValue js_std_loadFile(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_loadFile(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { uint8_t *buf; const char *filename; - JSValue ret, options_obj; + JSValueConst options_obj; + JSValue ret; size_t buf_len; bool binary = false; @@ -530,15 +531,16 @@ static JSValue js_std_loadFile(JSContext *ctx, JSValue this_val, return ret; } -static JSValue js_std_writeFile(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_writeFile(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { const char *filename; const char *mode; const void *buf; size_t len, n; - JSValue data, val, ret; - bool release, unref; + JSValueConst data; + JSValue val, ret, unref; + bool release; FILE *fp; ret = JS_EXCEPTION; @@ -546,7 +548,7 @@ static JSValue js_std_writeFile(JSContext *ctx, JSValue this_val, buf = ""; mode = "w"; data = argv[1]; - unref = false; + unref = JS_UNDEFINED; release = false; filename = JS_ToCString(ctx, argv[0]); if (!filename) @@ -556,8 +558,7 @@ static JSValue js_std_writeFile(JSContext *ctx, JSValue this_val, if (JS_IsException(val)) goto exception; if (JS_IsArrayBuffer(val)) { - data = val; - unref = true; + data = unref = val; } else { JS_FreeValue(ctx, val); } @@ -587,8 +588,7 @@ static JSValue js_std_writeFile(JSContext *ctx, JSValue this_val, JS_FreeCString(ctx, filename); if (release) JS_FreeCString(ctx, buf); - if (unref) - JS_FreeValue(ctx, data); + JS_FreeValue(ctx, unref); return ret; } @@ -700,7 +700,7 @@ static JSModuleDef *js_module_loader_so(JSContext *ctx, } #endif /* !_WIN32 */ -int js_module_set_import_meta(JSContext *ctx, JSValue func_val, +int js_module_set_import_meta(JSContext *ctx, JSValueConst func_val, bool use_realpath, bool is_main) { JSModuleDef *m; @@ -789,8 +789,8 @@ JSModuleDef *js_module_loader(JSContext *ctx, return m; } -static JSValue js_std_exit(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_exit(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { int status; if (JS_ToInt32(ctx, &status, argv[0])) @@ -799,8 +799,8 @@ static JSValue js_std_exit(JSContext *ctx, JSValue this_val, return JS_UNDEFINED; } -static JSValue js_std_getenv(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_getenv(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { const char *name, *str; name = JS_ToCString(ctx, argv[0]); @@ -836,8 +836,8 @@ static void unsetenv(const char *name) } #endif /* _WIN32 */ -static JSValue js_std_setenv(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_setenv(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { const char *name, *value; name = JS_ToCString(ctx, argv[0]); @@ -854,8 +854,8 @@ static JSValue js_std_setenv(JSContext *ctx, JSValue this_val, return JS_UNDEFINED; } -static JSValue js_std_unsetenv(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_unsetenv(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { const char *name; name = JS_ToCString(ctx, argv[0]); @@ -868,8 +868,8 @@ static JSValue js_std_unsetenv(JSContext *ctx, JSValue this_val, /* return an object containing the list of the available environment variables. */ -static JSValue js_std_getenviron(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_getenviron(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { char **envp; const char *name, *p, *value; @@ -905,8 +905,8 @@ static JSValue js_std_getenviron(JSContext *ctx, JSValue this_val, return JS_EXCEPTION; } -static JSValue js_std_gc(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_gc(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { JS_RunGC(JS_GetRuntime(ctx)); return JS_UNDEFINED; @@ -917,15 +917,15 @@ static int interrupt_handler(JSRuntime *rt, void *opaque) return (os_pending_signals >> SIGINT) & 1; } -static JSValue js_evalScript(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_evalScript(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { JSRuntime *rt = JS_GetRuntime(ctx); JSThreadState *ts = js_get_thread_state(rt); const char *str = NULL; size_t len; JSValue ret, obj; - JSValue options_obj; + JSValueConst options_obj, arg; bool backtrace_barrier = false; bool eval_function = false; bool eval_module = false; @@ -957,17 +957,17 @@ static JSValue js_evalScript(JSContext *ctx, JSValue this_val, } if (eval_module) { - obj = argv[0]; - if (JS_VALUE_GET_TAG(obj) != JS_TAG_MODULE) + arg = argv[0]; + if (JS_VALUE_GET_TAG(arg) != JS_TAG_MODULE) return JS_ThrowTypeError(ctx, "not a module"); - if (JS_ResolveModule(ctx, obj) < 0) + if (JS_ResolveModule(ctx, arg) < 0) return JS_EXCEPTION; - if (js_module_set_import_meta(ctx, obj, false, false) < 0) + if (js_module_set_import_meta(ctx, arg, false, false) < 0) return JS_EXCEPTION; - return JS_EvalFunction(ctx, obj); + return JS_EvalFunction(ctx, JS_DupValue(ctx, arg)); } if (!eval_function) { @@ -1015,7 +1015,7 @@ static bool is_stdio(FILE *f) return f == stdin || f == stdout || f == stderr; } -static void js_std_file_finalizer(JSRuntime *rt, JSValue val) +static void js_std_file_finalizer(JSRuntime *rt, JSValueConst val) { JSThreadState *ts = js_get_thread_state(rt); JSSTDFile *s = JS_GetOpaque(val, ts->std_file_class_id); @@ -1039,8 +1039,8 @@ static ssize_t js_get_errno(ssize_t ret) return ret; } -static JSValue js_std_strerror(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_strerror(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { int err; if (JS_ToInt32(ctx, &err, argv[0])) @@ -1068,15 +1068,15 @@ static JSValue js_new_std_file(JSContext *ctx, FILE *f, bool is_popen) return obj; } -static void js_set_error_object(JSContext *ctx, JSValue obj, int err) +static void js_set_error_object(JSContext *ctx, JSValueConst obj, int err) { if (!JS_IsUndefined(obj)) { JS_SetPropertyStr(ctx, obj, "errno", JS_NewInt32(ctx, err)); } } -static JSValue js_std_open(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_open(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { const char *filename, *mode = NULL; FILE *f; @@ -1112,8 +1112,8 @@ static JSValue js_std_open(JSContext *ctx, JSValue this_val, } #if !defined(__wasi__) -static JSValue js_std_popen(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_popen(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { const char *filename, *mode = NULL; FILE *f; @@ -1149,8 +1149,8 @@ static JSValue js_std_popen(JSContext *ctx, JSValue this_val, } #endif // !defined(__wasi__) -static JSValue js_std_fdopen(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_fdopen(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { const char *mode; FILE *f; @@ -1183,8 +1183,8 @@ static JSValue js_std_fdopen(JSContext *ctx, JSValue this_val, } #if !defined(__wasi__) -static JSValue js_std_tmpfile(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_tmpfile(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { FILE *f; f = tmpfile(); @@ -1196,19 +1196,19 @@ static JSValue js_std_tmpfile(JSContext *ctx, JSValue this_val, } #endif -static JSValue js_std_sprintf(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_sprintf(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { return js_printf_internal(ctx, argc, argv, NULL); } -static JSValue js_std_printf(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_printf(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { return js_printf_internal(ctx, argc, argv, stdout); } -static FILE *js_std_file_get(JSContext *ctx, JSValue obj) +static FILE *js_std_file_get(JSContext *ctx, JSValueConst obj) { JSRuntime *rt = JS_GetRuntime(ctx); JSThreadState *ts = js_get_thread_state(rt); @@ -1222,8 +1222,8 @@ static FILE *js_std_file_get(JSContext *ctx, JSValue obj) return s->f; } -static JSValue js_std_file_puts(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv, int magic) +static JSValue js_std_file_puts(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv, int magic) { FILE *f; int i; @@ -1248,8 +1248,8 @@ static JSValue js_std_file_puts(JSContext *ctx, JSValue this_val, return JS_UNDEFINED; } -static JSValue js_std_file_close(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_file_close(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { JSRuntime *rt = JS_GetRuntime(ctx); JSThreadState *ts = js_get_thread_state(rt); @@ -1271,8 +1271,8 @@ static JSValue js_std_file_close(JSContext *ctx, JSValue this_val, return JS_NewInt32(ctx, err); } -static JSValue js_std_file_printf(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_file_printf(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { FILE *f = js_std_file_get(ctx, this_val); if (!f) @@ -1280,8 +1280,8 @@ static JSValue js_std_file_printf(JSContext *ctx, JSValue this_val, return js_printf_internal(ctx, argc, argv, f); } -static JSValue js_std_file_flush(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_file_flush(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { FILE *f = js_std_file_get(ctx, this_val); if (!f) @@ -1290,8 +1290,8 @@ static JSValue js_std_file_flush(JSContext *ctx, JSValue this_val, return JS_UNDEFINED; } -static JSValue js_std_file_tell(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv, int is_bigint) +static JSValue js_std_file_tell(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv, int is_bigint) { FILE *f = js_std_file_get(ctx, this_val); int64_t pos; @@ -1308,8 +1308,8 @@ static JSValue js_std_file_tell(JSContext *ctx, JSValue this_val, return JS_NewInt64(ctx, pos); } -static JSValue js_std_file_seek(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_file_seek(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { FILE *f = js_std_file_get(ctx, this_val); int64_t pos; @@ -1330,8 +1330,8 @@ static JSValue js_std_file_seek(JSContext *ctx, JSValue this_val, return JS_NewInt32(ctx, ret); } -static JSValue js_std_file_eof(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_file_eof(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { FILE *f = js_std_file_get(ctx, this_val); if (!f) @@ -1339,8 +1339,8 @@ static JSValue js_std_file_eof(JSContext *ctx, JSValue this_val, return JS_NewBool(ctx, feof(f)); } -static JSValue js_std_file_error(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_file_error(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { FILE *f = js_std_file_get(ctx, this_val); if (!f) @@ -1348,8 +1348,8 @@ static JSValue js_std_file_error(JSContext *ctx, JSValue this_val, return JS_NewBool(ctx, ferror(f)); } -static JSValue js_std_file_clearerr(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_file_clearerr(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { FILE *f = js_std_file_get(ctx, this_val); if (!f) @@ -1358,8 +1358,8 @@ static JSValue js_std_file_clearerr(JSContext *ctx, JSValue this_val, return JS_UNDEFINED; } -static JSValue js_std_file_fileno(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_file_fileno(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { FILE *f = js_std_file_get(ctx, this_val); if (!f) @@ -1367,8 +1367,8 @@ static JSValue js_std_file_fileno(JSContext *ctx, JSValue this_val, return JS_NewInt32(ctx, fileno(f)); } -static JSValue js_std_file_read_write(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv, int magic) +static JSValue js_std_file_read_write(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv, int magic) { FILE *f = js_std_file_get(ctx, this_val); uint64_t pos, len; @@ -1394,8 +1394,8 @@ static JSValue js_std_file_read_write(JSContext *ctx, JSValue this_val, } /* XXX: could use less memory and go faster */ -static JSValue js_std_file_getline(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_file_getline(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { FILE *f = js_std_file_get(ctx, this_val); int c; @@ -1430,8 +1430,8 @@ static JSValue js_std_file_getline(JSContext *ctx, JSValue this_val, } /* XXX: could use less memory and go faster */ -static JSValue js_std_file_readAs(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv, int magic) +static JSValue js_std_file_readAs(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv, int magic) { FILE *f = js_std_file_get(ctx, this_val); int c; @@ -1439,7 +1439,7 @@ static JSValue js_std_file_readAs(JSContext *ctx, JSValue this_val, JSValue obj; uint64_t max_size64; size_t max_size; - JSValue max_size_val; + JSValueConst max_size_val; if (!f) return JS_EXCEPTION; @@ -1476,8 +1476,8 @@ static JSValue js_std_file_readAs(JSContext *ctx, JSValue this_val, return obj; } -static JSValue js_std_file_getByte(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_file_getByte(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { FILE *f = js_std_file_get(ctx, this_val); if (!f) @@ -1485,8 +1485,8 @@ static JSValue js_std_file_getByte(JSContext *ctx, JSValue this_val, return JS_NewInt32(ctx, fgetc(f)); } -static JSValue js_std_file_putByte(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_file_putByte(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { FILE *f = js_std_file_get(ctx, this_val); int c; @@ -1538,8 +1538,8 @@ static int http_get_status(const char *buf) return atoi(p); } -static JSValue js_std_urlGet(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_std_urlGet(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { const char *url; DynBuf cmd_buf; @@ -1549,7 +1549,7 @@ static JSValue js_std_urlGet(JSContext *ctx, JSValue this_val, size_t i, len; int status; JSValue response = JS_UNDEFINED, ret_obj; - JSValue options_obj; + JSValueConst options_obj; FILE *f; bool binary_flag, full_flag; @@ -1811,8 +1811,8 @@ JSModuleDef *js_init_module_std(JSContext *ctx, const char *module_name) /**********************************************************/ /* 'os' object */ -static JSValue js_os_open(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_open(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { const char *filename; int flags, mode, ret; @@ -1841,8 +1841,8 @@ static JSValue js_os_open(JSContext *ctx, JSValue this_val, return JS_NewInt32(ctx, ret); } -static JSValue js_os_close(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_close(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { int fd, ret; if (JS_ToInt32(ctx, &fd, argv[0])) @@ -1851,8 +1851,8 @@ static JSValue js_os_close(JSContext *ctx, JSValue this_val, return JS_NewInt32(ctx, ret); } -static JSValue js_os_seek(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_seek(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { int fd, whence; int64_t pos, ret; @@ -1874,8 +1874,8 @@ static JSValue js_os_seek(JSContext *ctx, JSValue this_val, return JS_NewInt64(ctx, ret); } -static JSValue js_os_read_write(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv, int magic) +static JSValue js_os_read_write(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv, int magic) { int fd; uint64_t pos, len; @@ -1901,8 +1901,8 @@ static JSValue js_os_read_write(JSContext *ctx, JSValue this_val, return JS_NewInt64(ctx, ret); } -static JSValue js_os_isatty(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_isatty(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { int fd; if (JS_ToInt32(ctx, &fd, argv[0])) @@ -1911,8 +1911,8 @@ static JSValue js_os_isatty(JSContext *ctx, JSValue this_val, } #if defined(_WIN32) -static JSValue js_os_ttyGetWinSize(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_ttyGetWinSize(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { int fd; HANDLE handle; @@ -1937,8 +1937,8 @@ static JSValue js_os_ttyGetWinSize(JSContext *ctx, JSValue this_val, #define __ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 #define __ENABLE_VIRTUAL_TERMINAL_INPUT 0x0200 -static JSValue js_os_ttySetRaw(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_ttySetRaw(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { int fd; HANDLE handle; @@ -1955,8 +1955,8 @@ static JSValue js_os_ttySetRaw(JSContext *ctx, JSValue this_val, return JS_UNDEFINED; } #elif !defined(__wasi__) -static JSValue js_os_ttyGetWinSize(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_ttyGetWinSize(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { int fd; struct winsize ws; @@ -1985,8 +1985,8 @@ static void term_exit(void) } /* XXX: should add a way to go back to normal mode */ -static JSValue js_os_ttySetRaw(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_ttySetRaw(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { struct termios tty; int fd; @@ -2015,8 +2015,8 @@ static JSValue js_os_ttySetRaw(JSContext *ctx, JSValue this_val, #endif /* !_WIN32 && !__wasi__ */ -static JSValue js_os_remove(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_remove(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { const char *filename; int ret; @@ -2041,8 +2041,8 @@ static JSValue js_os_remove(JSContext *ctx, JSValue this_val, return JS_NewInt32(ctx, ret); } -static JSValue js_os_rename(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_rename(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { const char *oldpath, *newpath; int ret; @@ -2090,14 +2090,14 @@ static void free_rw_handler(JSRuntime *rt, JSOSRWHandler *rh) js_free_rt(rt, rh); } -static JSValue js_os_setReadHandler(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv, int magic) +static JSValue js_os_setReadHandler(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv, int magic) { JSRuntime *rt = JS_GetRuntime(ctx); JSThreadState *ts = js_get_thread_state(rt); JSOSRWHandler *rh; int fd; - JSValue func; + JSValueConst func; if (JS_ToInt32(ctx, &fd, argv[0])) return JS_EXCEPTION; @@ -2160,14 +2160,14 @@ static void os_signal_handler(int sig_num) typedef void (*sighandler_t)(int sig_num); #endif -static JSValue js_os_signal(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_signal(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { JSRuntime *rt = JS_GetRuntime(ctx); JSThreadState *ts = js_get_thread_state(rt); JSOSSignalHandler *sh; uint32_t sig_num; - JSValue func; + JSValueConst func; sighandler_t handler; if (!is_main_thread(rt)) @@ -2208,8 +2208,8 @@ static JSValue js_os_signal(JSContext *ctx, JSValue this_val, } #if !defined(_WIN32) && !defined(__wasi__) -static JSValue js_os_cputime(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_cputime(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { struct rusage ru; int64_t cputime; @@ -2222,8 +2222,8 @@ static JSValue js_os_cputime(JSContext *ctx, JSValue this_val, } #endif -static JSValue js_os_now(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_now(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { return JS_NewInt64(ctx, js__hrtime_ns() / 1000); } @@ -2242,13 +2242,13 @@ static void free_timer(JSRuntime *rt, JSOSTimer *th) // TODO(bnoordhuis) accept string as first arg and eval at timer expiry // TODO(bnoordhuis) retain argv[2..] as args for callback if argc > 2 -static JSValue js_os_setTimeout(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv, int magic) +static JSValue js_os_setTimeout(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv, int magic) { JSRuntime *rt = JS_GetRuntime(ctx); JSThreadState *ts = js_get_thread_state(rt); int64_t delay; - JSValue func; + JSValueConst func; JSOSTimer *th; func = argv[0]; @@ -2285,8 +2285,8 @@ static JSOSTimer *find_timer_by_id(JSThreadState *ts, int timer_id) return NULL; } -static JSValue js_os_clearTimeout(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_clearTimeout(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { JSRuntime *rt = JS_GetRuntime(ctx); JSThreadState *ts = js_get_thread_state(rt); @@ -2303,8 +2303,8 @@ static JSValue js_os_clearTimeout(JSContext *ctx, JSValue this_val, } /* return a promise */ -static JSValue js_os_sleepAsync(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_sleepAsync(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { JSRuntime *rt = JS_GetRuntime(ctx); JSThreadState *ts = js_get_thread_state(rt); @@ -2494,7 +2494,7 @@ static int handle_posted_message(JSRuntime *rt, JSContext *ctx, /* 'func' might be destroyed when calling itself (if it frees the handler), so must take extra care */ func = JS_DupValue(ctx, port->on_message_func); - retval = JS_Call(ctx, func, JS_UNDEFINED, 1, &obj); + retval = JS_Call(ctx, func, JS_UNDEFINED, 1, (JSValueConst *)&obj); JS_FreeValue(ctx, obj); JS_FreeValue(ctx, func); if (JS_IsException(retval)) { @@ -2637,8 +2637,8 @@ static JSValue make_string_error(JSContext *ctx, } /* return [cwd, errorcode] */ -static JSValue js_os_getcwd(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_getcwd(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { char buf[PATH_MAX]; int err; @@ -2652,8 +2652,8 @@ static JSValue js_os_getcwd(JSContext *ctx, JSValue this_val, return make_string_error(ctx, buf, err); } -static JSValue js_os_chdir(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_chdir(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { const char *target; int err; @@ -2666,8 +2666,8 @@ static JSValue js_os_chdir(JSContext *ctx, JSValue this_val, return JS_NewInt32(ctx, err); } -static JSValue js_os_mkdir(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_mkdir(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { int mode, ret; const char *path; @@ -2692,8 +2692,8 @@ static JSValue js_os_mkdir(JSContext *ctx, JSValue this_val, } /* return [array, errorcode] */ -static JSValue js_os_readdir(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_readdir(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { const char *path; DIR *f; @@ -2743,8 +2743,8 @@ static int64_t timespec_to_ms(const struct timespec *tv) #endif /* return [obj, errcode] */ -static JSValue js_os_stat(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv, int is_lstat) +static JSValue js_os_stat(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv, int is_lstat) { const char *path; int err, res; @@ -2842,8 +2842,8 @@ static void ms_to_timeval(struct timeval *tv, uint64_t v) } #endif -static JSValue js_os_utimes(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_utimes(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { const char *path; int64_t atime, mtime; @@ -2876,8 +2876,8 @@ static JSValue js_os_utimes(JSContext *ctx, JSValue this_val, } /* sleep(delay_ms) */ -static JSValue js_os_sleep(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_sleep(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { int64_t delay; int ret; @@ -2919,8 +2919,8 @@ static char *realpath(const char *path, char *buf) #if !defined(__wasi__) /* return [path, errorcode] */ -static JSValue js_os_realpath(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_realpath(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { const char *path; char buf[PATH_MAX], *res; @@ -2942,8 +2942,8 @@ static JSValue js_os_realpath(JSContext *ctx, JSValue this_val, #endif #if !defined(_WIN32) && !defined(__wasi__) -static JSValue js_os_symlink(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_symlink(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { const char *target, *linkpath; int err; @@ -2963,8 +2963,8 @@ static JSValue js_os_symlink(JSContext *ctx, JSValue this_val, } /* return [path, errorcode] */ -static JSValue js_os_readlink(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_readlink(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { const char *path; char buf[PATH_MAX]; @@ -3115,10 +3115,10 @@ static void js_os_exec_once_init(void) #endif /* exec(args[, options]) -> exitcode */ -static JSValue js_os_exec(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_exec(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { - JSValue options, args = argv[0]; + JSValueConst options, args = argv[0]; JSValue val, ret_val; const char **exec_argv, *file = NULL, *str, *cwd = NULL; char **envp = environ; @@ -3323,15 +3323,15 @@ static JSValue js_os_exec(JSContext *ctx, JSValue this_val, } /* getpid() -> pid */ -static JSValue js_os_getpid(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_getpid(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { return JS_NewInt32(ctx, getpid()); } /* waitpid(pid, block) -> [pid, status] */ -static JSValue js_os_waitpid(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_waitpid(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { int pid, status, options, ret; JSValue obj; @@ -3358,8 +3358,8 @@ static JSValue js_os_waitpid(JSContext *ctx, JSValue this_val, } /* pipe() -> [read_fd, write_fd] or null if error */ -static JSValue js_os_pipe(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_pipe(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { int pipe_fds[2], ret; JSValue obj; @@ -3378,8 +3378,8 @@ static JSValue js_os_pipe(JSContext *ctx, JSValue this_val, } /* kill(pid, sig) */ -static JSValue js_os_kill(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_kill(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { int pid, sig, ret; @@ -3392,8 +3392,8 @@ static JSValue js_os_kill(JSContext *ctx, JSValue this_val, } /* dup(fd) */ -static JSValue js_os_dup(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_dup(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { int fd, ret; @@ -3404,8 +3404,8 @@ static JSValue js_os_dup(JSContext *ctx, JSValue this_val, } /* dup2(fd) */ -static JSValue js_os_dup2(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_os_dup2(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { int fd, fd2, ret; @@ -3550,7 +3550,7 @@ static void js_free_port(JSRuntime *rt, JSWorkerMessageHandler *port) } } -static void js_worker_finalizer(JSRuntime *rt, JSValue val) +static void js_worker_finalizer(JSRuntime *rt, JSValueConst val) { JSThreadState *ts = js_get_thread_state(rt); JSWorkerData *worker = JS_GetOpaque(val, ts->worker_class_id); @@ -3617,7 +3617,7 @@ static void *worker_func(void *opaque) return NULL; } -static JSValue js_worker_ctor_internal(JSContext *ctx, JSValue new_target, +static JSValue js_worker_ctor_internal(JSContext *ctx, JSValueConst new_target, JSWorkerMessagePipe *recv_pipe, JSWorkerMessagePipe *send_pipe) { @@ -3651,8 +3651,8 @@ static JSValue js_worker_ctor_internal(JSContext *ctx, JSValue new_target, return JS_EXCEPTION; } -static JSValue js_worker_ctor(JSContext *ctx, JSValue new_target, - int argc, JSValue *argv) +static JSValue js_worker_ctor(JSContext *ctx, JSValueConst new_target, + int argc, JSValueConst *argv) { JSRuntime *rt = JS_GetRuntime(ctx); WorkerFuncArgs *args = NULL; @@ -3735,8 +3735,8 @@ static JSValue js_worker_ctor(JSContext *ctx, JSValue new_target, return JS_EXCEPTION; } -static JSValue js_worker_postMessage(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_worker_postMessage(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { JSRuntime *rt = JS_GetRuntime(ctx); JSThreadState *ts = js_get_thread_state(rt); @@ -3814,8 +3814,8 @@ static JSValue js_worker_postMessage(JSContext *ctx, JSValue this_val, } -static JSValue js_worker_set_onmessage(JSContext *ctx, JSValue this_val, - JSValue func) +static JSValue js_worker_set_onmessage(JSContext *ctx, JSValueConst this_val, + JSValueConst func) { JSRuntime *rt = JS_GetRuntime(ctx); JSThreadState *ts = js_get_thread_state(rt); @@ -3849,7 +3849,7 @@ static JSValue js_worker_set_onmessage(JSContext *ctx, JSValue this_val, return JS_UNDEFINED; } -static JSValue js_worker_get_onmessage(JSContext *ctx, JSValue this_val) +static JSValue js_worker_get_onmessage(JSContext *ctx, JSValueConst this_val) { JSRuntime *rt = JS_GetRuntime(ctx); JSThreadState *ts = js_get_thread_state(rt); @@ -4047,15 +4047,15 @@ JSModuleDef *js_init_module_os(JSContext *ctx, const char *module_name) /**********************************************************/ -static JSValue js_print(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_print(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { #ifdef _WIN32 HANDLE handle; DWORD mode; #endif const char *s; - JSValue v; + JSValueConst v; DynBuf b; int i; @@ -4065,9 +4065,9 @@ static JSValue js_print(JSContext *ctx, JSValue this_val, s = JS_ToCString(ctx, v); if (!s && JS_IsObject(v)) { JS_FreeValue(ctx, JS_GetException(ctx)); - v = JS_ToObjectString(ctx, v); - s = JS_ToCString(ctx, v); - JS_FreeValue(ctx, v); + JSValue t = JS_ToObjectString(ctx, v); + s = JS_ToCString(ctx, t); + JS_FreeValue(ctx, t); } if (s) { dbuf_printf(&b, "%s%s", &" "[!i], s); @@ -4200,7 +4200,7 @@ void js_std_free_handlers(JSRuntime *rt) #endif } -static void js_dump_obj(JSContext *ctx, FILE *f, JSValue val) +static void js_dump_obj(JSContext *ctx, FILE *f, JSValueConst val) { const char *str; @@ -4213,7 +4213,7 @@ static void js_dump_obj(JSContext *ctx, FILE *f, JSValue val) } } -static void js_std_dump_error1(JSContext *ctx, JSValue exception_val) +static void js_std_dump_error1(JSContext *ctx, JSValueConst exception_val) { JSValue val; bool is_error; @@ -4240,8 +4240,8 @@ void js_std_dump_error(JSContext *ctx) JS_FreeValue(ctx, exception_val); } -void js_std_promise_rejection_tracker(JSContext *ctx, JSValue promise, - JSValue reason, +void js_std_promise_rejection_tracker(JSContext *ctx, JSValueConst promise, + JSValueConst reason, bool is_handled, void *opaque) { if (!is_handled) { @@ -4350,8 +4350,8 @@ void js_std_eval_binary(JSContext *ctx, const uint8_t *buf, size_t buf_len, } } -static JSValue js_bjson_read(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_bjson_read(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { uint8_t *buf; uint64_t pos, len; @@ -4374,8 +4374,8 @@ static JSValue js_bjson_read(JSContext *ctx, JSValue this_val, return obj; } -static JSValue js_bjson_write(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_bjson_write(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { size_t len; uint8_t *buf; diff --git a/quickjs-libc.h b/quickjs-libc.h index 6b49363f7..6ab5a7208 100644 --- a/quickjs-libc.h +++ b/quickjs-libc.h @@ -44,14 +44,14 @@ void js_std_init_handlers(JSRuntime *rt); void js_std_free_handlers(JSRuntime *rt); void js_std_dump_error(JSContext *ctx); uint8_t *js_load_file(JSContext *ctx, size_t *pbuf_len, const char *filename); -int js_module_set_import_meta(JSContext *ctx, JSValue func_val, +int js_module_set_import_meta(JSContext *ctx, JSValueConst func_val, bool use_realpath, bool is_main); JSModuleDef *js_module_loader(JSContext *ctx, const char *module_name, void *opaque); void js_std_eval_binary(JSContext *ctx, const uint8_t *buf, size_t buf_len, int flags); -void js_std_promise_rejection_tracker(JSContext *ctx, JSValue promise, - JSValue reason, +void js_std_promise_rejection_tracker(JSContext *ctx, JSValueConst promise, + JSValueConst reason, bool is_handled, void *opaque); void js_std_set_worker_new_context_func(JSContext *(*func)(JSRuntime *rt)); diff --git a/quickjs.c b/quickjs.c index 212b3a894..cb87b50e9 100644 --- a/quickjs.c +++ b/quickjs.c @@ -98,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 */ @@ -419,10 +442,10 @@ 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 line, int flags, int scope_idx); void *user_opaque; @@ -986,91 +1009,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); +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, 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 @@ -1084,15 +1108,15 @@ 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, const JSClassDef *class_def, JSAtom name); -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); typedef enum JSStrictEqModeEnum { JS_EQ_STRICT, @@ -1103,13 +1127,13 @@ typedef enum JSStrictEqModeEnum { 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 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; @@ -1117,42 +1141,43 @@ 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(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); static void js_array_buffer_free(JSRuntime *rt, void *opaque, void *ptr); -static JSArrayBuffer *js_get_array_buffer(JSContext *ctx, JSValue obj); +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 is_typed_array(JSClassID class_id); static bool typed_array_is_oob(JSObject *p); @@ -1161,39 +1186,40 @@ 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, +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 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); -static JSValue js_promise_then(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv); + 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 bool js_string_eq(JSString *p1, JSString *p2); static int js_string_compare(JSString *p1, JSString *p2); -static int JS_SetPropertyValue(JSContext *ctx, JSValue this_obj, +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); @@ -1207,27 +1233,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 JSValue js_create_array(JSContext *ctx, int len, JSValue *tab); + 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); @@ -1238,14 +1264,15 @@ static JSValue js_module_ns_autoinit(JSContext *ctx, JSObject *p, JSAtom atom, static JSValue JS_InstantiateFunctionListItem2(JSContext *ctx, JSObject *p, JSAtom atom, void *opaque); -static void js_set_uncatchable_error(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; @@ -1322,21 +1349,21 @@ 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); } @@ -1895,7 +1922,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; @@ -1939,7 +1966,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)) @@ -3447,7 +3474,7 @@ 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; } @@ -3465,7 +3492,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) @@ -3867,7 +3894,7 @@ static int string_buffer_concat(StringBuffer *s, JSString *p, 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; @@ -4045,7 +4072,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; @@ -4909,7 +4937,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; @@ -4918,7 +4946,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; @@ -4936,7 +4964,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; @@ -4965,7 +4993,7 @@ 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); } @@ -5101,7 +5129,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) @@ -5221,7 +5249,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; @@ -5234,7 +5262,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); @@ -5247,12 +5275,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 */ @@ -5266,12 +5294,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; @@ -5382,7 +5410,7 @@ static force_inline JSShapeProperty *find_own_property(JSProperty **ppr, } /* 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) { } @@ -5402,7 +5430,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; @@ -5413,7 +5441,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); @@ -5424,21 +5452,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); @@ -5446,7 +5474,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); @@ -5455,7 +5483,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; @@ -5478,7 +5506,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); @@ -5505,7 +5533,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; @@ -5519,7 +5547,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); @@ -5532,7 +5560,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; @@ -5540,7 +5568,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); @@ -5726,7 +5754,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)) { @@ -5971,7 +5999,7 @@ 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)) @@ -6594,7 +6622,7 @@ static int find_line_num(JSContext *ctx, JSFunctionBytecode *b, /* 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; @@ -6614,7 +6642,7 @@ static const char *get_func_name(JSContext *ctx, JSValue func) } /* Note: it is important that no exception is returned by this function */ -static bool can_add_backtrace(JSValue obj) +static bool can_add_backtrace(JSValueConst obj) { JSObject *p; if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT) @@ -6634,9 +6662,9 @@ static bool can_add_backtrace(JSValue obj) /* 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_val, 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; @@ -6800,7 +6828,7 @@ static void build_backtrace(JSContext *ctx, JSValue error_val, JSValue filter_fu JS_FreeValue(ctx, csd[k].func); JS_FreeValue(ctx, csd[k].func_name); } - JSValue args[] = { + JSValueConst args[] = { error_val, stack, }; @@ -7105,9 +7133,8 @@ 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) +static int JS_SetPrototypeInternal(JSContext *ctx, JSValueConst obj, + JSValueConst proto_val, bool throw_flag) { JSObject *proto, *p, *p1; JSShape *sh; @@ -7183,43 +7210,44 @@ static int JS_SetPrototypeInternal(JSContext *ctx, JSValue obj, } /* return -1 (exception) or true/false */ -int JS_SetPrototype(JSContext *ctx, JSValue obj, JSValue proto_val) +int JS_SetPrototype(JSContext *ctx, JSValueConst obj, JSValue proto_val) { 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) { @@ -7248,17 +7276,17 @@ 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) +static int JS_OrdinaryIsInstanceOf(JSContext *ctx, JSValueConst val, + JSValueConst obj) { JSValue obj_proto; JSObject *proto; @@ -7331,7 +7359,7 @@ static int JS_OrdinaryIsInstanceOf(JSContext *ctx, JSValue val, } /* return true, false or (-1) in case of exception */ -int JS_IsInstanceOf(JSContext *ctx, JSValue val, JSValue obj) +int JS_IsInstanceOf(JSContext *ctx, JSValueConst val, JSValueConst obj) { JSValue method; @@ -7388,8 +7416,8 @@ static int JS_AutoInitProperty(JSContext *ctx, JSObject *p, JSAtom prop, return 0; } -static JSValue JS_GetPropertyInternal(JSContext *ctx, JSValue obj, - JSAtom prop, JSValue this_obj, +static JSValue JS_GetPropertyInternal(JSContext *ctx, JSValueConst obj, + JSAtom prop, JSValueConst this_obj, bool throw_ref_error) { JSObject *p; @@ -7531,7 +7559,7 @@ static JSValue JS_GetPropertyInternal(JSContext *ctx, JSValue obj, } } -JSValue JS_GetProperty(JSContext *ctx, JSValue this_obj, JSAtom prop) +JSValue JS_GetProperty(JSContext *ctx, JSValueConst this_obj, JSAtom prop) { return JS_GetPropertyInternal(ctx, this_obj, prop, this_obj, false); } @@ -7544,7 +7572,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; @@ -7579,8 +7607,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; @@ -7602,8 +7630,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; @@ -7634,7 +7662,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; @@ -7723,8 +7751,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; @@ -7962,7 +7989,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); @@ -8054,7 +8081,7 @@ static int JS_GetOwnPropertyInternal(JSContext *ctx, JSPropertyDescriptor *desc, } 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); @@ -8070,7 +8097,7 @@ void JS_FreePropertyEnum(JSContext *ctx, JSPropertyEnum *tab, } /* return -1 if exception (Proxy object only) or true/false */ -int JS_IsExtensible(JSContext *ctx, JSValue obj) +int JS_IsExtensible(JSContext *ctx, JSValueConst obj) { JSObject *p; @@ -8084,7 +8111,7 @@ int JS_IsExtensible(JSContext *ctx, JSValue obj) } /* return -1 if exception (Proxy object only) or true/false */ -int JS_PreventExtensions(JSContext *ctx, JSValue obj) +int JS_PreventExtensions(JSContext *ctx, JSValueConst obj) { JSObject *p; @@ -8098,7 +8125,7 @@ int JS_PreventExtensions(JSContext *ctx, JSValue obj) } /* return -1 if exception otherwise true or false */ -int JS_HasProperty(JSContext *ctx, JSValue obj, JSAtom prop) +int JS_HasProperty(JSContext *ctx, JSValueConst obj, JSAtom prop) { JSObject *p; int ret; @@ -8140,14 +8167,14 @@ int JS_HasProperty(JSContext *ctx, JSValue obj, JSAtom prop) } /* 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; @@ -8232,7 +8259,7 @@ static bool js_get_fast_array_element(JSContext *ctx, JSObject *p, } } -static JSValue JS_GetPropertyValue(JSContext *ctx, JSValue this_obj, +static JSValue JS_GetPropertyValue(JSContext *ctx, JSValueConst this_obj, JSValue prop) { JSAtom atom; @@ -8268,7 +8295,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); @@ -8279,7 +8306,7 @@ JSValue JS_GetPropertyUint32(JSContext *ctx, JSValue this_obj, 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; @@ -8310,7 +8337,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; @@ -8332,7 +8359,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; @@ -8509,14 +8536,14 @@ static int delete_property(JSContext *ctx, JSObject *p, JSAtom atom) } 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; @@ -8686,8 +8713,8 @@ static void js_free_desc(JSContext *ctx, JSPropertyDescriptor *desc) 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) +static int JS_SetPropertyInternal2(JSContext *ctx, JSValueConst obj, JSAtom prop, + JSValue val, JSValueConst this_obj, int flags) { JSObject *p, *p1; JSShapeProperty *prs; @@ -8931,19 +8958,19 @@ static int JS_SetPropertyInternal2(JSContext *ctx, JSValue obj, JSAtom prop, return -1; } -static int JS_SetPropertyInternal(JSContext *ctx, JSValue obj, JSAtom prop, +static int JS_SetPropertyInternal(JSContext *ctx, JSValueConst obj, JSAtom prop, JSValue val, int flags) { 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_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 && @@ -9088,14 +9115,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; @@ -9117,7 +9144,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; @@ -9140,8 +9167,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; @@ -9331,9 +9358,9 @@ static int js_update_property_flags(JSContext *ctx, JSObject *p, define_own_property callback. 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; @@ -9464,8 +9491,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) */ @@ -9482,8 +9508,7 @@ 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; } @@ -9598,7 +9623,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) { @@ -9629,7 +9654,7 @@ static int JS_DefineAutoInitProperty(JSContext *ctx, JSValue this_obj, } /* 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; @@ -9639,7 +9664,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; @@ -9655,14 +9680,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), @@ -9670,7 +9695,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; @@ -9682,7 +9707,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) { @@ -9695,7 +9720,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), @@ -9979,7 +10004,7 @@ static int JS_SetGlobalVar(JSContext *ctx, JSAtom prop, JSValue val, /* 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; @@ -10001,7 +10026,7 @@ int JS_DeleteProperty(JSContext *ctx, JSValue obj, JSAtom prop, int flags) 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; @@ -10018,7 +10043,7 @@ 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) @@ -10034,7 +10059,8 @@ 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) @@ -10046,7 +10072,7 @@ bool JS_IsCFunction(JSContext *ctx, JSValue val, JSCFunction *func, int magic) 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) @@ -10055,7 +10081,7 @@ bool JS_IsConstructor(JSContext *ctx, JSValue 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) @@ -10065,21 +10091,21 @@ bool JS_SetConstructorBit(JSContext *ctx, JSValue func_obj, bool val) return true; } -bool JS_IsRegExp(JSValue val) +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_IsMap(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, JSValue val) +bool JS_IsError(JSContext *ctx, JSValueConst val) { JSObject *p; if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT) @@ -10089,7 +10115,7 @@ bool JS_IsError(JSContext *ctx, JSValue val) } /* 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) @@ -10098,7 +10124,7 @@ bool JS_IsUncatchableError(JSContext *ctx, JSValue val) return p->class_id == JS_CLASS_ERROR && p->is_uncatchable_error; } -static void js_set_uncatchable_error(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) @@ -10108,12 +10134,12 @@ static void js_set_uncatchable_error(JSContext *ctx, JSValue val, bool flag) p->is_uncatchable_error = flag; } -void JS_SetUncatchableError(JSContext *ctx, JSValue val) +void JS_SetUncatchableError(JSContext *ctx, JSValueConst val) { js_set_uncatchable_error(ctx, val, true); } -void JS_ClearUncatchableError(JSContext *ctx, JSValue val) +void JS_ClearUncatchableError(JSContext *ctx, JSValueConst val) { js_set_uncatchable_error(ctx, val, false); } @@ -10123,7 +10149,7 @@ void JS_ResetUncatchableError(JSContext *ctx) 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) { @@ -10139,7 +10165,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); @@ -10149,7 +10175,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) @@ -10160,7 +10186,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)) { @@ -10169,7 +10195,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) { @@ -10214,7 +10240,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; @@ -10255,12 +10281,12 @@ static JSValue JS_ToPrimitiveFree(JSContext *ctx, JSValue val, int hint) 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) @@ -10269,7 +10295,7 @@ void JS_SetIsHTMLDDA(JSContext *ctx, JSValue obj) 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) @@ -10323,7 +10349,7 @@ static int JS_ToBoolFree(JSContext *ctx, JSValue val) } } -int JS_ToBool(JSContext *ctx, JSValue val) +int JS_ToBool(JSContext *ctx, JSValueConst val) { return JS_ToBoolFree(ctx, js_dup(val)); } @@ -10671,7 +10697,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)); } @@ -10728,12 +10754,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)); } -JSValue JS_ToNumber(JSContext *ctx, JSValue val) +JSValue JS_ToNumber(JSContext *ctx, JSValueConst val) { return JS_ToNumberFree(ctx, js_dup(val)); } @@ -10819,13 +10845,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) { @@ -10882,12 +10908,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)); @@ -10956,12 +10982,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); @@ -11023,7 +11049,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)); } @@ -11160,7 +11186,7 @@ static bool is_safe_integer(double 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)) @@ -11185,7 +11211,7 @@ 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)) @@ -11195,7 +11221,7 @@ static int JS_NumberIsInteger(JSContext *ctx, JSValue val) 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; @@ -11224,7 +11250,7 @@ static bool JS_NumberIsNegativeOrMinusZero(JSContext *ctx, JSValue val) } } -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; @@ -11249,7 +11275,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); } @@ -11677,7 +11703,8 @@ static JSValue js_dtoa_radix(JSContext *ctx, double d, int radix) 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]; @@ -11729,7 +11756,7 @@ 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); } @@ -11749,12 +11776,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); } -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) @@ -11762,7 +11789,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; @@ -11973,7 +12000,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; @@ -12059,7 +12086,7 @@ static __maybe_unused void JS_DumpValue(JSRuntime *rt, JSValue val) } } -bool JS_IsArray(JSValue val) +bool JS_IsArray(JSValueConst val) { if (JS_VALUE_GET_TAG(val) == JS_TAG_OBJECT) { JSObject *p = JS_VALUE_GET_OBJ(val); @@ -12069,7 +12096,7 @@ bool JS_IsArray(JSValue val) } /* return -1 if exception (proxy case) or true/false */ -static int js_is_array(JSContext *ctx, JSValue val) +static int js_is_array(JSContext *ctx, JSValueConst val) { JSObject *p; if (JS_VALUE_GET_TAG(val) == JS_TAG_OBJECT) { @@ -12128,7 +12155,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; @@ -12239,7 +12266,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)); } @@ -12298,12 +12325,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)); } @@ -13215,7 +13242,6 @@ 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, JSStrictEqModeEnum eq_mode) { @@ -13338,12 +13364,12 @@ 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); } @@ -13522,8 +13548,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"); } @@ -13531,8 +13557,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) { @@ -13542,7 +13568,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) { @@ -13552,7 +13578,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); @@ -13564,9 +13590,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; @@ -13586,7 +13613,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; @@ -13638,7 +13665,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; @@ -13883,8 +13910,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; @@ -13898,7 +13925,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; @@ -13933,9 +13960,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; @@ -13946,7 +13973,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) { @@ -13973,9 +14000,9 @@ static JSValue JS_IteratorNext2(JSContext *ctx, JSValue enum_obj, return JS_EXCEPTION; } -static JSValue JS_IteratorNext(JSContext *ctx, JSValue enum_obj, - JSValue method, - int argc, JSValue *argv, int *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; @@ -14005,7 +14032,7 @@ static JSValue JS_IteratorNext(JSContext *ctx, JSValue enum_obj, } /* return < 0 in case of exception */ -static int JS_IteratorClose(JSContext *ctx, JSValue enum_obj, +static int JS_IteratorClose(JSContext *ctx, JSValueConst enum_obj, bool is_exception_pending) { JSValue method, ret, ex_obj; @@ -14153,12 +14180,12 @@ 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, +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) { @@ -14348,7 +14375,7 @@ 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; } @@ -14644,16 +14671,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; @@ -14671,7 +14698,7 @@ static JSValue js_call_c_function(JSContext *ctx, JSValue func_obj, ctx = p->u.cfunc.realm; /* change the current realm */ sf->is_strict_mode = false; - sf->cur_func = func_obj; + sf->cur_func = unsafe_unconst(func_obj); sf->arg_count = argc; arg_buf = argv; @@ -14684,7 +14711,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) { @@ -14774,13 +14801,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); @@ -14841,9 +14868,9 @@ static bool needs_backtrace(JSValue exc) } /* 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; @@ -14934,9 +14961,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; @@ -15295,7 +15322,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) @@ -15313,8 +15341,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++) @@ -15331,7 +15359,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) @@ -15362,7 +15391,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]); @@ -15487,7 +15516,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; @@ -15519,8 +15549,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))) @@ -16155,7 +16184,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]); @@ -16184,7 +16213,7 @@ 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; @@ -17364,15 +17393,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); @@ -17382,7 +17411,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; @@ -17430,7 +17459,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; @@ -17457,9 +17486,10 @@ static JSValue js_create_from_ctor(JSContext *ctx, JSValue 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; @@ -17504,25 +17534,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); @@ -17532,7 +17562,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); @@ -17541,8 +17571,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; @@ -17625,7 +17656,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); } @@ -17652,7 +17684,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); @@ -17667,7 +17699,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); @@ -17683,8 +17715,8 @@ 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, +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); @@ -17770,9 +17802,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; @@ -17830,7 +17862,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; @@ -17839,7 +17872,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); @@ -17884,7 +17917,8 @@ static bool js_async_function_resume(JSContext *ctx, JSAsyncFunctionData *s) is_success = false; } else { JSValue error = JS_GetException(ctx); - ret2 = JS_Call(ctx, s->resolving_funcs[1], JS_UNDEFINED, 1, &error); + ret2 = JS_Call(ctx, s->resolving_funcs[1], JS_UNDEFINED, + 1, vc(&error)); JS_FreeValue(ctx, error); resolved: if (unlikely(JS_IsException(ret2))) { @@ -17904,7 +17938,7 @@ static bool 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); + 1, vc(&value)); JS_FreeValue(ctx, value); goto resolved; } else { @@ -17914,7 +17948,7 @@ static bool 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; @@ -17928,8 +17962,8 @@ static bool 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]); @@ -17941,15 +17975,15 @@ static bool js_async_function_resume(JSContext *ctx, JSAsyncFunctionData *s) } 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; + JSValueConst arg; if (argc > 0) arg = argv[0]; @@ -17967,9 +18001,9 @@ static JSValue js_async_function_resolve_call(JSContext *ctx, 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; @@ -18052,7 +18086,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); @@ -18061,7 +18095,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); @@ -18083,9 +18117,9 @@ 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, @@ -18097,7 +18131,7 @@ static int js_async_generator_resolve_function_create(JSContext *ctx, 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]); @@ -18116,7 +18150,7 @@ 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; @@ -18131,8 +18165,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]); @@ -18145,7 +18179,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; @@ -18165,7 +18199,7 @@ static void js_async_generator_resolve_or_reject(JSContext *ctx, static void js_async_generator_resolve(JSContext *ctx, JSAsyncGeneratorData *s, - JSValue value, + JSValueConst value, bool done) { JSValue result; @@ -18177,7 +18211,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); } @@ -18199,13 +18233,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)) @@ -18221,8 +18255,8 @@ static int js_async_generator_completed_return(JSContext *ctx, 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); @@ -18332,13 +18366,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; JSAsyncGeneratorData *s = JS_GetOpaque(func_data[0], JS_CLASS_ASYNC_GENERATOR); - JSValue arg = argv[0]; + JSValueConst arg = argv[0]; /* XXX: what if s == NULL */ @@ -18368,8 +18402,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); @@ -18384,7 +18418,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]); @@ -18411,9 +18445,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; @@ -26720,7 +26755,7 @@ static __exception int get_exported_names(JSContext *ctx, } /* 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); } @@ -27337,12 +27372,12 @@ static JSValue JS_NewModuleValue(JSContext *ctx, JSModuleDef *m) return js_dup(JS_MKPTR(JS_TAG_MODULE, m)); } -static JSValue js_load_module_rejected(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv, int magic, - JSValue *func_data) +static JSValue js_load_module_rejected(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv, int magic, + JSValueConst *func_data) { - JSValue *resolving_funcs = func_data; - JSValue error; + JSValueConst *resolving_funcs = func_data; + JSValueConst error; JSValue ret; /* XXX: check if the test is necessary */ @@ -27355,11 +27390,11 @@ static JSValue js_load_module_rejected(JSContext *ctx, JSValue this_val, return JS_UNDEFINED; } -static JSValue js_load_module_fulfilled(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv, int magic, - JSValue *func_data) +static JSValue js_load_module_fulfilled(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv, int magic, + JSValueConst *func_data) { - JSValue *resolving_funcs = func_data; + JSValueConst *resolving_funcs = func_data; JSModuleDef *m = JS_VALUE_GET_PTR(func_data[2]); JSValue ret, ns; @@ -27367,10 +27402,10 @@ static JSValue js_load_module_fulfilled(JSContext *ctx, JSValue this_val, ns = JS_GetModuleNamespace(ctx, m); if (JS_IsException(ns)) { JSValue err = JS_GetException(ctx); - js_load_module_rejected(ctx, JS_UNDEFINED, 1, &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, &ns); + ret = JS_Call(ctx, resolving_funcs[0], JS_UNDEFINED, 1, vc(&ns)); JS_FreeValue(ctx, ret); JS_FreeValue(ctx, ns); return JS_UNDEFINED; @@ -27378,12 +27413,12 @@ static JSValue js_load_module_fulfilled(JSContext *ctx, JSValue this_val, static void JS_LoadModuleInternal(JSContext *ctx, const char *basename, const char *filename, - JSValue *resolving_funcs) + JSValueConst *resolving_funcs) { JSValue evaluate_promise; JSModuleDef *m; JSValue ret, err, func_obj, evaluate_resolving_funcs[2]; - JSValue func_data[3]; + JSValueConst func_data[3]; m = js_host_resolve_imported_module(ctx, basename, filename); if (!m) @@ -27400,7 +27435,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, &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; @@ -27413,7 +27448,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, 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]); @@ -27430,18 +27465,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, 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; @@ -27464,15 +27499,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; @@ -27496,11 +27530,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]); @@ -27512,9 +27546,9 @@ 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; + JSValueConst value = JS_UNDEFINED; ret_val = JS_Call(ctx, m->resolving_funcs[0], JS_UNDEFINED, 1, &value); JS_FreeValue(ctx, ret_val); } @@ -27582,12 +27616,12 @@ static int js_execute_async_module(JSContext *ctx, JSModuleDef *m); static int js_execute_sync_module(JSContext *ctx, JSModuleDef *m, JSValue *pvalue); -static JSValue js_async_module_execution_rejected(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv, int magic, - JSValue *func_data) +static JSValue js_async_module_execution_rejected(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv, int magic, + JSValueConst *func_data) { JSModuleDef *module = JS_VALUE_GET_PTR(func_data[0]); - JSValue error = argv[0]; + JSValueConst error = argv[0]; int i; if (js_check_stack_overflow(ctx->rt, 0)) @@ -27610,7 +27644,7 @@ static JSValue js_async_module_execution_rejected(JSContext *ctx, JSValue this_v 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); } @@ -27624,9 +27658,9 @@ static JSValue js_async_module_execution_rejected(JSContext *ctx, JSValue this_v return JS_UNDEFINED; } -static JSValue js_async_module_execution_fulfilled(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv, int magic, - JSValue *func_data) +static JSValue js_async_module_execution_fulfilled(JSContext *ctx, JSValueConst this_val, + 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; @@ -27666,7 +27700,8 @@ static JSValue js_async_module_execution_fulfilled(JSContext *ctx, JSValue this_ 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, &error, 0, &m_obj); + 1, vc(&error), + 0, vc(&m_obj)); JS_FreeValue(ctx, m_obj); JS_FreeValue(ctx, error); } else { @@ -27686,9 +27721,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, &m_obj); - resolve_funcs[1] = JS_NewCFunctionData(ctx, js_async_module_execution_rejected, 0, 0, 1, &m_obj); - ret_val = js_promise_then(ctx, promise, 2, 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]); @@ -27882,16 +27917,15 @@ 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, &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, &value); JS_FreeValue(ctx, ret_val); @@ -33200,7 +33234,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; @@ -33238,7 +33272,7 @@ 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 line, int flags, int scope_idx) { @@ -33353,7 +33387,7 @@ 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 line, int flags, int scope_idx) { @@ -33370,8 +33404,8 @@ static JSValue JS_EvalInternal(JSContext *ctx, JSValue this_obj, 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; @@ -33388,7 +33422,7 @@ static JSValue JS_EvalObject(JSContext *ctx, JSValue this_obj, } -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) { @@ -33401,7 +33435,7 @@ JSValue JS_EvalThis(JSContext *ctx, JSValue this_obj, return JS_EvalThis2(ctx, this_obj, input, input_len, &options); } -JSValue JS_EvalThis2(JSContext *ctx, JSValue this_obj, +JSValue JS_EvalThis2(JSContext *ctx, JSValueConst this_obj, const char *input, size_t input_len, JSEvalOptions *options) { @@ -33443,7 +33477,7 @@ JSValue JS_Eval2(JSContext *ctx, const char *input, size_t input_len, JSEvalOpti return JS_EvalThis2(ctx, ctx->global_obj, input, input_len, options); } -int JS_ResolveModule(JSContext *ctx, JSValue obj) +int JS_ResolveModule(JSContext *ctx, JSValueConst obj) { if (JS_VALUE_GET_TAG(obj) == JS_TAG_MODULE) { JSModuleDef *m = JS_VALUE_GET_PTR(obj); @@ -33856,7 +33890,7 @@ static void JS_WriteString(BCWriterState *s, JSString *p) } } -static int JS_WriteBigInt(BCWriterState *s, JSValue obj) +static int JS_WriteBigInt(BCWriterState *s, JSValueConst obj) { uint32_t tag, tag1; int64_t e; @@ -33928,9 +33962,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; @@ -34023,7 +34057,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; @@ -34073,7 +34107,7 @@ 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; @@ -34116,7 +34150,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; @@ -34153,7 +34187,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; @@ -34167,7 +34201,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; @@ -34182,7 +34216,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; @@ -34220,7 +34254,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; @@ -34418,7 +34452,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; @@ -34466,7 +34500,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); @@ -35331,7 +35365,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)) @@ -35788,14 +35822,14 @@ 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; @@ -36015,8 +36049,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, @@ -36027,8 +36061,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); @@ -36037,18 +36071,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); @@ -36057,8 +36091,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); @@ -36066,14 +36100,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; @@ -36082,8 +36116,8 @@ 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; double d; @@ -36094,13 +36128,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; @@ -36111,7 +36145,7 @@ static JSValue js_global_queueMicrotask(JSContext *ctx, JSValue this_val, /* Object class */ -JSValue JS_ToObject(JSContext *ctx, JSValue val) +JSValue JS_ToObject(JSContext *ctx, JSValueConst val) { int tag = JS_VALUE_GET_NORM_TAG(val); JSValue obj; @@ -36159,7 +36193,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; @@ -36256,8 +36290,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; @@ -36273,8 +36307,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; @@ -36314,8 +36348,8 @@ static __exception int JS_ObjectDefineProperties(JSContext *ctx, 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) && @@ -36337,10 +36371,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]; @@ -36359,12 +36393,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 */ @@ -36375,21 +36407,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]; + 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; @@ -36416,24 +36447,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; @@ -36475,10 +36504,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; @@ -36542,8 +36571,8 @@ static JSValue js_object_getOwnPropertyDescriptor(JSContext *ctx, JSValue this_v 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; @@ -36565,7 +36594,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)) @@ -36593,7 +36622,7 @@ static JSValue js_object_getOwnPropertyDescriptors(JSContext *ctx, JSValue this_ 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; @@ -36672,25 +36701,25 @@ static JSValue JS_GetOwnPropertyNames2(JSContext *ctx, JSValue obj1, 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; int done; @@ -36749,7 +36778,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 @@ -36776,17 +36805,17 @@ static JSValue js_object_groupBy(JSContext *ctx, JSValue this_val, 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]; @@ -36803,10 +36832,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]; @@ -36828,8 +36857,8 @@ 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; @@ -36854,8 +36883,8 @@ 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; @@ -36880,14 +36909,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; @@ -36941,19 +36970,19 @@ static JSValue js_object_toString(JSContext *ctx, JSValue this_val, return JS_ConcatString3(ctx, "[object ", tag, "]"); } -JSValue JS_ToObjectString(JSContext *ctx, JSValue val) +JSValue JS_ToObjectString(JSContext *ctx, JSValueConst val) { return js_object_toString(ctx, val, 0, NULL); } -static JSValue js_object_toLocaleString(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +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; @@ -36980,10 +37009,10 @@ static JSValue js_object_assign(JSContext *ctx, JSValue this_val, 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; @@ -37045,10 +37074,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; @@ -37091,7 +37120,7 @@ static JSValue js_object_isSealed(JSContext *ctx, JSValue this_val, return JS_EXCEPTION; } -int JS_SealObject(JSContext *ctx, JSValue obj) +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; @@ -37099,7 +37128,7 @@ int JS_SealObject(JSContext *ctx, JSValue obj) return result; } -int JS_FreezeObject(JSContext *ctx, JSValue obj) +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; @@ -37107,11 +37136,11 @@ int JS_FreezeObject(JSContext *ctx, JSValue obj) return result; } -static JSValue js_object_fromEntries(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_object_fromEntries(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { JSValue obj, iter, next_method = JS_UNDEFINED; - JSValue iterable; + JSValueConst iterable; int done; /* RequireObjectCoercible() not necessary because it is tested in @@ -37175,14 +37204,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; @@ -37210,7 +37239,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; @@ -37222,8 +37251,8 @@ 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); @@ -37235,11 +37264,11 @@ static JSValue js_object_set___proto__(JSContext *ctx, JSValue this_val, 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]; @@ -37275,8 +37304,8 @@ static JSValue js_object_isPrototypeOf(JSContext *ctx, JSValue this_val, 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; @@ -37306,8 +37335,8 @@ static JSValue js_object_propertyIsEnumerable(JSContext *ctx, JSValue this_val, 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; @@ -37393,15 +37422,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; @@ -37471,7 +37500,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); @@ -37483,7 +37512,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); @@ -37494,7 +37523,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)); } @@ -37510,7 +37540,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; @@ -37555,10 +37585,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; @@ -37574,16 +37604,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); @@ -37592,8 +37622,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; @@ -37677,8 +37707,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; @@ -37720,8 +37750,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); @@ -37746,7 +37776,7 @@ 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; @@ -37784,11 +37814,11 @@ static JSValue iterator_to_array(JSContext *ctx, JSValue items) 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; + JSValueConst message; int present, opts; if (JS_IsUndefined(new_target)) @@ -37860,8 +37890,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; @@ -37895,13 +37925,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; @@ -37912,7 +37942,7 @@ static JSValue js_error_get_stackTraceLimit(JSContext *ctx, JSValue this_val) 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); @@ -37920,7 +37950,7 @@ static JSValue js_error_set_stackTraceLimit(JSContext *ctx, JSValue this_val, JS 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; @@ -37931,7 +37961,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); @@ -37940,10 +37970,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); @@ -37961,7 +37991,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; @@ -38047,8 +38077,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; @@ -38074,12 +38104,12 @@ static JSValue js_array_constructor(JSContext *ctx, JSValue new_target, 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; @@ -38187,15 +38217,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); } @@ -38215,8 +38245,8 @@ 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_is_array(ctx, argv[0]); @@ -38226,14 +38256,13 @@ static JSValue js_array_isArray(JSContext *ctx, JSValue this_val, 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; @@ -38285,7 +38314,7 @@ 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; @@ -38299,8 +38328,8 @@ static int JS_isConcatSpreadable(JSContext *ctx, JSValue 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; @@ -38327,8 +38356,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; @@ -38401,11 +38430,11 @@ static JSValue js_array_with(JSContext *ctx, JSValue this_val, 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; @@ -38474,7 +38503,7 @@ static JSValue js_array_concat(JSContext *ctx, JSValue this_val, #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) @@ -38496,7 +38525,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); @@ -38510,15 +38539,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; @@ -38666,12 +38695,12 @@ static JSValue js_array_every(JSContext *ctx, JSValue this_val, #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; @@ -38755,8 +38784,8 @@ static JSValue js_array_reduce(JSContext *ctx, JSValue this_val, 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; @@ -38790,8 +38819,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; @@ -38838,8 +38867,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; @@ -38885,8 +38914,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; @@ -38939,11 +38968,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; @@ -39010,8 +39039,8 @@ static JSValue js_array_find(JSContext *ctx, JSValue this_val, 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; @@ -39033,8 +39062,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; @@ -39090,8 +39119,8 @@ static JSValue js_array_join(JSContext *ctx, JSValue this_val, 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; @@ -39143,8 +39172,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; @@ -39179,8 +39208,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; @@ -39252,8 +39281,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; @@ -39311,8 +39340,8 @@ static JSValue js_array_toReversed(JSContext *ctx, JSValue this_val, 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; @@ -39417,8 +39446,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; @@ -39512,8 +39541,8 @@ static JSValue js_array_toSpliced(JSContext *ctx, JSValue this_val, 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; @@ -39547,11 +39576,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; @@ -39569,12 +39598,14 @@ 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_is_array(ctx, element); @@ -39609,11 +39640,11 @@ static int64_t JS_FlattenIntoArray(JSContext *ctx, JSValue target, 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; @@ -39665,13 +39696,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; @@ -39729,8 +39760,8 @@ static int js_array_cmp_generic(const void *a, const void *b, void *opaque) { 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; @@ -39819,8 +39850,8 @@ static JSValue js_array_sort(JSContext *ctx, JSValue this_val, // 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; @@ -39892,7 +39923,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; @@ -39902,7 +39933,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); @@ -39912,7 +39943,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; @@ -39929,8 +39960,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; @@ -39966,8 +39997,8 @@ 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, +static JSValue js_array_iterator_next(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv, int *pdone, int magic) { JSArrayIteratorData *it; @@ -40013,7 +40044,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; @@ -40031,7 +40062,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; @@ -40042,7 +40073,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); @@ -40053,8 +40084,8 @@ 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, +static JSValue js_iterator_wrap_next(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv, int *pdone, int magic) { JSIteratorWrapData *it; @@ -40081,8 +40112,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; @@ -40095,14 +40126,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)) @@ -40145,7 +40176,7 @@ static JSValue js_iterator_from(JSContext *ctx, JSValue this_val, 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); @@ -40165,10 +40196,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; @@ -40254,11 +40286,11 @@ 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; int done; @@ -40404,11 +40436,11 @@ static JSValue js_iterator_proto_func(JSContext *ctx, JSValue this_val, 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; int done; @@ -40466,8 +40498,8 @@ static JSValue js_iterator_proto_reduce(JSContext *ctx, JSValue this_val, 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; @@ -40502,18 +40534,18 @@ static JSValue js_iterator_proto_toArray(JSContext *ctx, JSValue this_val, 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; @@ -40534,7 +40566,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; @@ -40547,7 +40579,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); @@ -40560,8 +40592,8 @@ 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, +static JSValue js_iterator_helper_next(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv, int *pdone, int magic) { JSIteratorHelperData *it; @@ -40619,7 +40651,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 { @@ -40657,7 +40690,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) { @@ -40740,7 +40774,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 { @@ -40884,8 +40919,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) { @@ -40918,24 +40953,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]); @@ -40945,8 +40980,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])) @@ -40974,7 +41009,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); @@ -40989,13 +41024,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)) @@ -41007,8 +41042,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; @@ -41043,8 +41078,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; @@ -41068,8 +41103,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; @@ -41093,8 +41128,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; @@ -41126,8 +41161,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; @@ -41151,8 +41186,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; @@ -41169,8 +41204,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])); @@ -41184,7 +41219,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); @@ -41199,8 +41234,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)) @@ -41209,8 +41244,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); } @@ -41224,7 +41259,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; @@ -41252,10 +41287,10 @@ static int js_string_get_own_property(JSContext *ctx, } 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; @@ -41292,7 +41327,7 @@ 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; @@ -41311,8 +41346,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) { @@ -41341,7 +41376,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); @@ -41356,8 +41391,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; @@ -41380,8 +41415,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; @@ -41429,8 +41464,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; @@ -41470,8 +41505,8 @@ static JSValue js_string_raw(JSContext *ctx, JSValue this_val, } /* 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; @@ -41496,8 +41531,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; @@ -41523,8 +41558,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; @@ -41548,8 +41583,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; @@ -41573,8 +41608,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; @@ -41598,8 +41633,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; @@ -41674,8 +41709,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; @@ -41710,8 +41745,8 @@ static JSValue js_string_isWellFormed(JSContext *ctx, JSValue this_val, 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; @@ -41749,8 +41784,8 @@ static JSValue js_string_toWellFormed(JSContext *ctx, JSValue this_val, 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; @@ -41815,10 +41850,10 @@ static JSValue js_string_indexOf(JSContext *ctx, JSValue this_val, } /* return < 0 if exception or true/false */ -static int js_is_regexp(JSContext *ctx, JSValue obj); +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; @@ -41881,7 +41916,7 @@ static JSValue js_string_includes(JSContext *ctx, JSValue this_val, 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; @@ -41910,12 +41945,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; @@ -41955,16 +41990,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; @@ -42068,13 +42103,13 @@ static JSValue js_string___GetSubstitution(JSContext *ctx, JSValue this_val, 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; @@ -42181,12 +42216,12 @@ static JSValue js_string_replace(JSContext *ctx, JSValue this_val, 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; @@ -42271,8 +42306,8 @@ static JSValue js_string_split(JSContext *ctx, JSValue this_val, 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; @@ -42305,8 +42340,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; @@ -42333,8 +42368,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; @@ -42361,8 +42396,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; @@ -42432,8 +42467,8 @@ static JSValue js_string_pad(JSContext *ctx, JSValue this_val, 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; @@ -42476,8 +42511,8 @@ static JSValue js_string_repeat(JSContext *ctx, JSValue this_val, 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; @@ -42570,8 +42605,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; @@ -42631,8 +42666,8 @@ static JSValue js_string_localeCompare(JSContext *ctx, JSValue this_val, 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; @@ -42699,8 +42734,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; @@ -42759,16 +42794,16 @@ 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, +static JSValue js_string_iterator_next(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv, int *pdone, int magic) { JSArrayIteratorData *it; @@ -42820,8 +42855,8 @@ 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; JSString *p; @@ -42972,8 +43007,8 @@ 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; double r, a; @@ -43063,8 +43098,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; @@ -43097,8 +43132,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; @@ -43112,8 +43147,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; @@ -43126,8 +43161,8 @@ 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; @@ -43204,8 +43239,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; @@ -43358,7 +43393,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; @@ -43367,8 +43402,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; @@ -43445,7 +43480,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; @@ -43474,7 +43509,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); @@ -43488,7 +43524,7 @@ static JSRegExp *js_get_regexp(JSContext *ctx, JSValue obj, bool throw_error) } /* return < 0 if exception or true/false */ -static int js_is_regexp(JSContext *ctx, JSValue obj) +static int js_is_regexp(JSContext *ctx, JSValueConst obj) { JSValue m; @@ -43502,11 +43538,11 @@ static int js_is_regexp(JSContext *ctx, JSValue obj) 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; @@ -43580,11 +43616,11 @@ 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); @@ -43624,7 +43660,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; @@ -43690,7 +43726,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; @@ -43710,7 +43746,7 @@ static JSValue js_regexp_get_flag(JSContext *ctx, JSValue this_val, int mask) 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; @@ -43766,8 +43802,8 @@ static JSValue js_regexp_get_flags(JSContext *ctx, JSValue this_val) 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; @@ -43804,8 +43840,8 @@ void *lre_realloc(void *opaque, void *ptr, size_t size) return js_realloc_rt(ctx->rt, ptr, size); } -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; @@ -43851,8 +43887,8 @@ 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); JSString *str; @@ -44051,7 +44087,7 @@ static JSValue js_regexp_exec(JSContext *ctx, JSValue this_val, } /* 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); JSString *str; @@ -44146,7 +44182,7 @@ static JSValue JS_RegExpDelete(JSContext *ctx, JSValue this_val, JSValue arg) 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; @@ -44167,8 +44203,8 @@ 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; @@ -44181,11 +44217,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; @@ -44274,7 +44310,8 @@ typedef struct JSRegExpStringIteratorData { 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; @@ -44285,7 +44322,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); @@ -44297,8 +44334,8 @@ 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, + JSValueConst this_val, + int argc, JSValueConst *argv, int *pdone, int magic) { JSRegExpStringIteratorData *it; @@ -44349,13 +44386,13 @@ static JSValue js_regexp_string_iterator_next(JSContext *ctx, 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; @@ -44474,7 +44511,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; @@ -44496,12 +44533,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; @@ -44689,10 +44726,10 @@ static JSValue js_regexp_Symbol_replace(JSContext *ctx, JSValue this_val, 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)) @@ -44747,12 +44784,12 @@ static JSValue js_regexp_Symbol_search(JSContext *ctx, JSValue this_val, 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; @@ -45092,11 +45129,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; @@ -45161,11 +45198,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; @@ -45196,7 +45233,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; @@ -45211,10 +45248,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); @@ -45265,8 +45303,8 @@ static JSValue js_json_check(JSContext *ctx, JSONStringifyContext *jsc, } 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; @@ -45297,7 +45335,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)) { @@ -45318,7 +45356,7 @@ 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_is_array(ctx, val); @@ -45358,7 +45396,8 @@ 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)) @@ -45444,8 +45483,8 @@ static int js_json_to_str(JSContext *ctx, JSONStringifyContext *jsc, 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; @@ -45504,7 +45543,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; @@ -45578,8 +45617,8 @@ JSValue JS_JSONStringify(JSContext *ctx, JSValue obj, 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]); @@ -45603,16 +45642,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; @@ -45628,15 +45667,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; @@ -45654,10 +45693,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; @@ -45677,10 +45716,10 @@ static JSValue js_reflect_get(JSContext *ctx, JSValue this_val, 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; @@ -45699,10 +45738,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; @@ -45726,8 +45765,8 @@ 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); @@ -45737,8 +45776,8 @@ static JSValue js_reflect_setPrototypeOf(JSContext *ctx, JSValue this_val, 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); @@ -45770,7 +45809,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) { @@ -45780,7 +45819,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); @@ -45796,7 +45835,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; @@ -45821,7 +45860,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; @@ -45832,7 +45871,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 && @@ -45862,12 +45901,12 @@ 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]; + JSValueConst args[2]; bool res; int res2; @@ -45907,7 +45946,7 @@ static int js_proxy_setPrototypeOf(JSContext *ctx, JSValue obj, 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; @@ -45919,7 +45958,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); @@ -45933,7 +45972,7 @@ 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; @@ -45945,7 +45984,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); @@ -45961,13 +46000,13 @@ 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 res; JSObject *p; - JSValue args[2]; + JSValueConst args[2]; bool ret, res2; s = get_proxy_method(ctx, &method, obj, JS_ATOM_has); @@ -46005,13 +46044,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); @@ -46055,14 +46094,14 @@ 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; bool ret; int res; - JSValue args[4]; + JSValueConst args[4]; s = get_proxy_method(ctx, &method, obj, JS_ATOM_set); if (!s) @@ -46113,8 +46152,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; @@ -46152,13 +46191,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); @@ -46248,16 +46287,16 @@ 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; JSObject *p; - JSValue args[3]; + JSValueConst args[3]; JSPropertyDescriptor desc; bool ret, setting_not_configurable; @@ -46348,14 +46387,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 res2, is_extensible; bool res; - JSValue args[2]; + JSValueConst args[2]; s = get_proxy_method(ctx, &method, obj, JS_ATOM_deleteProperty); if (!s) @@ -46414,7 +46453,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; @@ -46432,7 +46471,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; @@ -46529,13 +46568,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) @@ -46563,13 +46602,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); @@ -46598,7 +46637,7 @@ 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) @@ -46626,10 +46665,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; @@ -46656,29 +46695,29 @@ static JSValue js_proxy_constructor(JSContext *ctx, JSValue this_val, 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]); + 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; @@ -46730,7 +46769,7 @@ void JS_AddIntrinsicProxy(JSContext *ctx) obj1, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE); } -bool JS_IsProxy(JSValue val) +bool JS_IsProxy(JSValueConst val) { if (JS_VALUE_GET_TAG(val) == JS_TAG_OBJECT) { JSObject *p = JS_VALUE_GET_OBJ(val); @@ -46739,7 +46778,8 @@ bool JS_IsProxy(JSValue val) return false; } -static JSValue js_get_proxy_field(JSContext *ctx, JSValue proxy, int offset) +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); @@ -46753,20 +46793,20 @@ static JSValue js_get_proxy_field(JSContext *ctx, JSValue proxy, int offset) return JS_ThrowTypeError(ctx, "not a proxy"); } -JSValue JS_GetProxyTarget(JSContext *ctx, JSValue proxy) +JSValue JS_GetProxyTarget(JSContext *ctx, JSValueConst proxy) { return js_get_proxy_field(ctx, proxy, offsetof(JSProxyData, target)); } -JSValue JS_GetProxyHandler(JSContext *ctx, JSValue proxy) +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; @@ -46784,7 +46824,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); @@ -46799,26 +46839,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; @@ -46845,8 +46885,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; @@ -46856,8 +46896,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; @@ -46899,12 +46939,12 @@ 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; + JSValueConst arr; bool is_set, is_weak; is_set = magic & MAGIC_SET; @@ -46956,14 +46996,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)) { @@ -47013,15 +47053,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; @@ -47065,7 +47110,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; @@ -47112,7 +47157,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: @@ -47134,7 +47179,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; @@ -47154,10 +47199,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); @@ -47221,18 +47266,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) @@ -47251,16 +47296,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; @@ -47268,30 +47313,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; @@ -47299,8 +47344,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; @@ -47315,7 +47360,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) @@ -47323,11 +47368,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; @@ -47354,8 +47399,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]); @@ -47371,11 +47416,11 @@ 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; int done; @@ -47414,7 +47459,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; @@ -47430,7 +47475,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 @@ -47457,7 +47502,7 @@ static JSValue js_map_groupBy(JSContext *ctx, JSValue this_val, 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; @@ -47485,7 +47530,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; @@ -47511,7 +47557,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; @@ -47529,7 +47575,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); @@ -47541,8 +47587,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; @@ -47571,8 +47617,8 @@ 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, +static JSValue js_map_iterator_next(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv, int *pdone, int magic) { JSMapIteratorData *it; @@ -47622,7 +47668,7 @@ static JSValue js_map_iterator_next(JSContext *ctx, JSValue this_val, 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; @@ -47660,7 +47706,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); @@ -47719,7 +47765,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; @@ -47747,7 +47794,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; @@ -47767,7 +47815,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; @@ -47787,8 +47836,8 @@ 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; int done; @@ -47841,7 +47890,7 @@ static JSValue js_set_isDisjointFrom(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)); JS_FreeValue(ctx, item); ok = JS_ToBoolFree(ctx, rv); // returns -1 if rv is JS_EXCEPTION if (ok < 0) @@ -47858,8 +47907,8 @@ static JSValue js_set_isDisjointFrom(JSContext *ctx, JSValue this_val, 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 found; @@ -47895,7 +47944,7 @@ static JSValue js_set_isSubsetOf(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)); JS_FreeValue(ctx, item); ok = JS_ToBoolFree(ctx, rv); // returns -1 if rv is JS_EXCEPTION if (ok < 0) @@ -47912,8 +47961,8 @@ static JSValue js_set_isSubsetOf(JSContext *ctx, JSValue this_val, 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; int done; @@ -47966,8 +48015,8 @@ static JSValue js_set_isSupersetOf(JSContext *ctx, JSValue this_val, 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; @@ -48033,7 +48082,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); @@ -48064,8 +48113,8 @@ static JSValue js_set_intersection(JSContext *ctx, JSValue this_val, 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; @@ -48126,7 +48175,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); @@ -48157,8 +48206,8 @@ static JSValue js_set_difference(JSContext *ctx, JSValue this_val, 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; @@ -48245,8 +48294,8 @@ static JSValue js_set_symmetricDifference(JSContext *ctx, JSValue this_val, 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; @@ -48294,7 +48343,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; @@ -48469,7 +48518,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) @@ -48477,7 +48526,7 @@ 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) @@ -48485,7 +48534,7 @@ JSValue JS_PromiseResult(JSContext *ctx, JSValue promise) return js_dup(s->promise_result); } -bool JS_IsPromise(JSValue val) +bool JS_IsPromise(JSValueConst val) { if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT) return false; @@ -48493,7 +48542,7 @@ bool JS_IsPromise(JSValue val) } static int js_create_resolving_functions(JSContext *ctx, JSValue *args, - JSValue promise); + JSValueConst promise); static void promise_reaction_data_free(JSRuntime *rt, JSPromiseReactionData *rd) @@ -48515,10 +48564,11 @@ 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; + JSValueConst arg; bool is_reject; assert(argc == 5); @@ -48548,8 +48598,7 @@ static JSValue promise_reaction_job(JSContext *ctx, int argc, 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; } @@ -48566,13 +48615,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 */ @@ -48608,16 +48657,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); } 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"); @@ -48628,10 +48677,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]); @@ -48649,7 +48698,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; @@ -48689,7 +48738,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) { @@ -48699,7 +48749,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; @@ -48709,14 +48759,15 @@ 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; @@ -48763,7 +48814,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; @@ -48782,7 +48833,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); @@ -48803,10 +48854,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; @@ -48829,11 +48880,11 @@ static JSValue js_promise_constructor(JSContext *ctx, JSValue new_target, 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; @@ -48852,9 +48903,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; @@ -48868,7 +48919,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; @@ -48878,7 +48929,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; @@ -48889,11 +48940,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; @@ -48917,8 +48966,8 @@ 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; @@ -48950,8 +48999,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)) @@ -48972,8 +49021,8 @@ 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; @@ -48988,7 +49037,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); @@ -49001,7 +49050,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; @@ -49024,17 +49073,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]; + JSValueConst values = func_data[2]; + JSValueConst resolve = func_data[3]; + JSValueConst resolve_element_env = func_data[4]; JSValue ret, obj; int is_zero, index; @@ -49081,7 +49130,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); @@ -49094,14 +49143,14 @@ 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]; + 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)) @@ -49118,8 +49167,7 @@ static JSValue js_promise_all(JSContext *ctx, JSValue this_val, 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; @@ -49150,7 +49198,7 @@ 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: @@ -49218,7 +49266,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; } @@ -49238,8 +49286,8 @@ 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; @@ -49260,8 +49308,7 @@ static JSValue js_promise_race(JSContext *ctx, JSValue this_val, 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; @@ -49280,7 +49327,7 @@ 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: @@ -49288,7 +49335,7 @@ static JSValue js_promise_race(JSContext *ctx, JSValue this_val, 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; } @@ -49308,9 +49355,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; @@ -49319,7 +49366,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) @@ -49339,7 +49386,7 @@ 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) { @@ -49362,8 +49409,8 @@ static __exception int perform_promise_then(JSContext *ctx, 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; @@ -49380,8 +49427,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) { @@ -49391,41 +49437,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; @@ -49440,18 +49486,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); @@ -49474,7 +49520,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; @@ -49505,9 +49551,9 @@ 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])); @@ -49516,7 +49562,7 @@ static JSValue js_async_from_sync_iterator_unwrap(JSContext *ctx, static JSValue js_async_from_sync_iterator_unwrap_func_create(JSContext *ctx, 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, @@ -49536,7 +49582,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); @@ -49547,7 +49594,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 = @@ -49584,8 +49631,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; @@ -49642,7 +49689,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]); @@ -49654,7 +49701,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; @@ -49670,8 +49717,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]); @@ -49850,8 +49897,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; @@ -49961,8 +50008,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; @@ -50026,8 +50073,8 @@ static JSValue js_global_encodeURI(JSContext *ctx, JSValue this_val, 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; @@ -50052,8 +50099,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; @@ -50122,10 +50169,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); @@ -50136,7 +50184,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); @@ -50185,7 +50233,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) { @@ -50305,8 +50353,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]; @@ -50326,8 +50374,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]; @@ -50370,8 +50418,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]; @@ -50485,8 +50533,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; @@ -50513,7 +50561,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; @@ -50553,8 +50601,8 @@ static JSValue js_date_constructor(JSContext *ctx, JSValue new_target, 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 }; @@ -50986,8 +51034,8 @@ static bool js_date_parse_otherstring(const uint8_t *sp, 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]; @@ -51036,18 +51084,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; @@ -51075,8 +51123,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; @@ -51090,8 +51138,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; @@ -51101,8 +51149,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; @@ -51112,12 +51160,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; @@ -51129,12 +51177,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; @@ -51236,7 +51286,7 @@ JSValue JS_NewDate(JSContext *ctx, double epoch_ms) return obj; } -bool JS_IsDate(JSValue v) +bool JS_IsDate(JSValueConst v) { if (JS_VALUE_GET_TAG(v) != JS_TAG_OBJECT) return false; @@ -51330,15 +51380,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); @@ -51353,8 +51403,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; @@ -51378,15 +51428,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; @@ -51521,7 +51571,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)); + 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, @@ -51742,7 +51792,7 @@ 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, @@ -51823,7 +51873,7 @@ 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) { @@ -51833,7 +51883,7 @@ static JSValue js_array_buffer_constructor2(JSContext *ctx, } 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, @@ -51850,7 +51900,7 @@ JSValue JS_NewArrayBuffer(JSContext *ctx, uint8_t *buf, size_t len, buf, free_func, opaque, false); } -bool JS_IsArrayBuffer(JSValue obj) { +bool JS_IsArrayBuffer(JSValueConst obj) { return JS_GetClassID(obj) == JS_CLASS_ARRAY_BUFFER; } @@ -51864,8 +51914,8 @@ JSValue JS_NewArrayBufferCopy(JSContext *ctx, const uint8_t *buf, size_t len) 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; @@ -51899,23 +51949,23 @@ static JSValue js_array_buffer_constructor0(JSContext *ctx, JSValue new_target, 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; @@ -51950,8 +52000,8 @@ 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; @@ -51980,7 +52030,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) @@ -51991,7 +52041,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); @@ -52002,7 +52052,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); @@ -52013,7 +52063,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); @@ -52022,7 +52073,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; @@ -52050,7 +52101,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) @@ -52067,7 +52118,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) @@ -52089,8 +52140,8 @@ static bool array_buffer_is_resizable(const JSArrayBuffer *abuf) } // 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; JSArrayBuffer *abuf; @@ -52146,8 +52197,8 @@ static JSValue js_array_buffer_transfer(JSContext *ctx, JSValue this_val, 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; @@ -52223,8 +52274,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; @@ -52255,7 +52306,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]); } @@ -52356,7 +52407,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); @@ -52369,7 +52420,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); @@ -52378,7 +52429,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; @@ -52389,7 +52440,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; @@ -52407,7 +52458,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; @@ -52420,7 +52471,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) @@ -52433,7 +52484,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) @@ -52458,7 +52509,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; @@ -52485,7 +52536,7 @@ 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) @@ -52497,9 +52548,9 @@ static JSValue js_typed_array_get_toStringTag(JSContext *ctx, } 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; @@ -52582,8 +52633,8 @@ static JSValue js_typed_array_set_internal(JSContext *ctx, 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; @@ -52635,8 +52686,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; @@ -52678,26 +52729,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; @@ -52725,10 +52776,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; @@ -52751,12 +52802,12 @@ 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; @@ -52808,8 +52859,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; @@ -52844,15 +52894,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; @@ -52865,8 +52914,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; @@ -52906,8 +52955,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; @@ -52999,11 +53048,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; @@ -53065,8 +53113,8 @@ static JSValue js_typed_array_find(JSContext *ctx, JSValue this_val, #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; @@ -53357,8 +53405,8 @@ static JSValue js_typed_array_indexOf(JSContext *ctx, JSValue this_val, 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; @@ -53436,8 +53484,8 @@ static JSValue js_typed_array_join(JSContext *ctx, JSValue this_val, 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; @@ -53499,8 +53547,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; @@ -53517,10 +53565,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; @@ -53585,12 +53633,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; @@ -53626,9 +53674,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; @@ -53752,8 +53800,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; }; @@ -53781,7 +53829,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; @@ -53809,8 +53857,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; @@ -53953,8 +54001,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; @@ -54018,8 +54066,8 @@ 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"); } @@ -54056,7 +54104,7 @@ 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; int done; @@ -54097,8 +54145,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; @@ -54151,8 +54199,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; @@ -54208,8 +54256,8 @@ 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; @@ -54279,7 +54327,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; @@ -54294,7 +54342,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); @@ -54305,15 +54353,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; JSArrayBuffer *abuf; uint64_t offset; uint32_t len; - JSValue buffer; + JSValueConst buffer; JSValue obj; JSTypedArray *ta; JSObject *p; @@ -54397,7 +54445,7 @@ static bool dataview_is_oob(JSObject *p) 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) @@ -54411,7 +54459,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; @@ -54422,7 +54470,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; @@ -54441,7 +54489,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; @@ -54456,8 +54504,8 @@ 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; @@ -54569,8 +54617,8 @@ 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; @@ -54580,7 +54628,7 @@ static JSValue js_dataview_setValue(JSContext *ctx, uint64_t v64; uint32_t v; uint64_t pos; - JSValue val; + JSValueConst val; ta = JS_GetOpaque2(ctx, this_obj, JS_CLASS_DATAVIEW); if (!ta) @@ -54734,7 +54782,7 @@ JSValue JS_NewUint8ArrayCopy(JSContext *ctx, const uint8_t *buf, size_t len) return js_new_uint8array(ctx, buffer); } -int JS_GetTypedArrayType(JSValue obj) +int JS_GetTypedArrayType(JSValueConst obj) { JSClassID class_id = JS_GetClassID(obj); if (is_typed_array(class_id)) @@ -54760,7 +54808,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; @@ -54817,8 +54865,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; @@ -54960,8 +55008,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; @@ -55014,8 +55062,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])) @@ -55039,8 +55087,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; @@ -55063,8 +55111,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; @@ -55134,8 +55182,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; @@ -55311,7 +55359,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); } @@ -55336,7 +55384,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)) @@ -55344,17 +55392,17 @@ int JS_IsEqual(JSContext *ctx, JSValue op1, JSValue op2) return JS_VALUE_GET_BOOL(sp[0]); } -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); } -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); } -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); } @@ -55362,13 +55410,13 @@ 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) @@ -55390,11 +55438,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? @@ -55422,7 +55471,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) @@ -55443,8 +55492,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; @@ -55471,7 +55520,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) { @@ -55495,7 +55544,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) { @@ -55509,11 +55559,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"); @@ -55532,16 +55583,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"); @@ -55572,13 +55624,13 @@ 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"); @@ -55609,7 +55661,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]); } @@ -55697,7 +55749,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); @@ -55716,7 +55768,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: @@ -55735,7 +55787,8 @@ static bool is_valid_weakref_target(JSValue val) 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 */ @@ -55745,7 +55798,7 @@ static void insert_weakref_record(JSValue target, struct JSWeakRefRecord *wr) /* 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) { @@ -55756,7 +55809,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) { @@ -55838,7 +55892,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) @@ -55847,7 +55901,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) @@ -55855,7 +55909,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) diff --git a/quickjs.h b/quickjs.h index 1826472cd..a73f6d758 100644 --- a/quickjs.h +++ b/quickjs.h @@ -106,9 +106,55 @@ enum { /* any larger tag is FLOAT64 if JS_NAN_BOXING */ }; -#define JSValueConst JSValue /* For backwards compatibility. */ +#if !defined(JS_CHECK_JSVALUE) +#define JSValueConst JSValue +#endif + +// 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); +} -#if defined(JS_NAN_BOXING) && JS_NAN_BOXING +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; @@ -319,9 +365,9 @@ static inline 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); @@ -382,9 +428,10 @@ JS_EXTERN void JS_SetRuntimeOpaque(JSRuntime *rt, void *opaque); JS_EXTERN int JS_AddRuntimeFinalizer(JSRuntime *rt, JSRuntimeFinalizer *finalizer, void *arg); 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 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); @@ -414,15 +461,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 bool JS_IsStrictEqual(JSContext *ctx, JSValue op1, JSValue op2); -JS_EXTERN 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 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); @@ -472,7 +519,7 @@ 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 */ @@ -493,38 +540,37 @@ typedef struct JSClassExoticMethods { 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); + uint32_t *plen, JSValueConst obj); /* return < 0 if exception, or true/false */ - int (*delete_property)(JSContext *ctx, JSValue obj, JSAtom prop); + int (*delete_property)(JSContext *ctx, JSValueConst 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, + 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); + 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, JSValue obj, JSAtom atom, - JSValue value, JSValue receiver, int flags); + 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 JSValue JSClassCall(JSContext *ctx, JSValueConst func_obj, + JSValueConst this_val, int argc, + JSValueConst *argv, int flags); typedef struct JSClassDef { const char *class_name; /* pure ASCII only! */ @@ -554,7 +600,7 @@ typedef struct 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 bool JS_IsRegisteredClass(JSRuntime *rt, JSClassID class_id); @@ -610,59 +656,59 @@ 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 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 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 bool JS_IsBool(JSValue v) +static inline bool JS_IsBool(JSValueConst v) { return JS_VALUE_GET_TAG(v) == JS_TAG_BOOL; } -static inline bool JS_IsNull(JSValue v) +static inline bool JS_IsNull(JSValueConst v) { return JS_VALUE_GET_TAG(v) == JS_TAG_NULL; } -static inline bool JS_IsUndefined(JSValue v) +static inline bool JS_IsUndefined(JSValueConst v) { return JS_VALUE_GET_TAG(v) == JS_TAG_UNDEFINED; } -static inline bool JS_IsException(JSValue v) +static inline bool JS_IsException(JSValueConst v) { return JS_VALUE_GET_TAG(v) == JS_TAG_EXCEPTION; } -static inline bool JS_IsUninitialized(JSValue v) +static inline bool JS_IsUninitialized(JSValueConst v) { return JS_VALUE_GET_TAG(v) == JS_TAG_UNINITIALIZED; } -static inline bool JS_IsString(JSValue v) +static inline bool JS_IsString(JSValueConst v) { return JS_VALUE_GET_TAG(v) == JS_TAG_STRING; } -static inline bool JS_IsSymbol(JSValue v) +static inline bool JS_IsSymbol(JSValueConst v) { return JS_VALUE_GET_TAG(v) == JS_TAG_SYMBOL; } -static inline 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(JSValue v) +static inline bool JS_IsModule(JSValueConst v) { return JS_VALUE_GET_TAG(v) == JS_TAG_MODULE; } @@ -670,10 +716,10 @@ static inline bool JS_IsModule(JSValue v) JS_EXTERN JSValue JS_Throw(JSContext *ctx, JSValue obj); JS_EXTERN JSValue JS_GetException(JSContext *ctx); JS_EXTERN bool JS_HasException(JSContext *ctx); -JS_EXTERN bool JS_IsError(JSContext *ctx, JSValue val); -JS_EXTERN bool JS_IsUncatchableError(JSContext* ctx, JSValue val); -JS_EXTERN void JS_SetUncatchableError(JSContext *ctx, JSValue val); -JS_EXTERN void JS_ClearUncatchableError(JSContext *ctx, JSValue val); +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); @@ -689,65 +735,68 @@ JS_EXTERN JSValue JS_PRINTF_FORMAT_ATTR(2, 3) JS_ThrowInternalError(JSContext *c 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 */ -static inline JSValue JS_ToBoolean(JSContext *ctx, 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, JSValue val); -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_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, 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); } JS_EXTERN void JS_FreeCString(JSContext *ctx, const char *ptr); -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); +// 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, JSValue val); -JS_EXTERN JSValue JS_ToObjectString(JSContext *ctx, JSValue val); +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, JSValue val); -JS_EXTERN bool JS_IsConstructor(JSContext* ctx, JSValue val); -JS_EXTERN bool JS_SetConstructorBit(JSContext *ctx, JSValue func_obj, bool 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(JSValue val); -JS_EXTERN bool JS_IsMap(JSValue val); +JS_EXTERN bool JS_IsRegExp(JSValueConst val); +JS_EXTERN bool JS_IsMap(JSValueConst val); JS_EXTERN JSValue JS_NewArray(JSContext *ctx); // takes ownership of the values @@ -757,41 +806,41 @@ JS_EXTERN JSValue JS_NewArrayFrom(JSContext *ctx, int count, // 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(JSValue val); +JS_EXTERN bool JS_IsArray(JSValueConst val); -JS_EXTERN bool JS_IsProxy(JSValue val); -JS_EXTERN JSValue JS_GetProxyTarget(JSContext *ctx, JSValue proxy); -JS_EXTERN JSValue JS_GetProxyHandler(JSContext *ctx, JSValue proxy); +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(JSValue v); +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_SealObject(JSContext *ctx, JSValue obj); -JS_EXTERN int JS_FreezeObject(JSContext *ctx, JSValue obj); +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) @@ -802,21 +851,22 @@ JS_EXTERN int JS_FreezeObject(JSContext *ctx, JSValue obj); #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_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); +JS_EXTERN JSValue JS_Call(JSContext *ctx, JSValueConst func_obj, + JSValueConst this_obj, int argc, JSValueConst *argv); +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 @@ -829,47 +879,48 @@ JS_EXTERN JSValue JS_Eval(JSContext *ctx, const char *input, size_t input_len, const char *filename, int eval_flags); JS_EXTERN JSValue JS_Eval2(JSContext *ctx, const char *input, size_t input_len, JSEvalOptions *options); -JS_EXTERN JSValue JS_EvalThis(JSContext *ctx, JSValue this_obj, +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, JSValue this_obj, +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, 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 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, @@ -886,9 +937,9 @@ 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); @@ -896,7 +947,7 @@ JS_EXTERN JSValue JS_NewUint8Array(JSContext *ctx, uint8_t *buf, size_t len, JSFreeArrayBufferDataFunc *free_func, void *opaque, 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); @@ -913,15 +964,16 @@ 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 bool JS_IsPromise(JSValue val); +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, bool is_global); /* is_handled = true means that the rejection is handled */ -typedef void JSHostPromiseRejectionTracker(JSContext *ctx, JSValue promise, - JSValue reason, +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); @@ -931,7 +983,7 @@ JS_EXTERN void JS_SetInterruptHandler(JSRuntime *rt, JSInterruptHandler *cb, voi /* 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; @@ -955,8 +1007,9 @@ 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 bool JS_IsJobPending(JSRuntime *rt); JS_EXTERN int JS_ExecutePendingJob(JSRuntime *rt, JSContext **pctx); @@ -974,8 +1027,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 */ @@ -990,13 +1043,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 */ @@ -1017,18 +1070,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, @@ -1040,25 +1093,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 */ diff --git a/run-test262.c b/run-test262.c index 64cf575a8..d44402f7e 100644 --- a/run-test262.c +++ b/run-test262.c @@ -459,12 +459,12 @@ static void enumerate_tests(const char *path) namelist_cmp_indirect); } -static JSValue js_print_262(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_print_262(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { ThreadLocalStorage *tls = JS_GetRuntimeOpaque(JS_GetRuntime(ctx)); const char *s; - JSValue v; + JSValueConst v; int i; for (i = 0; i < argc; i++) { @@ -473,9 +473,9 @@ static JSValue js_print_262(JSContext *ctx, JSValue this_val, // same logic as js_print in quickjs-libc.c if (local && !s && JS_IsObject(v)) { JS_FreeValue(ctx, JS_GetException(ctx)); - v = JS_ToObjectString(ctx, v); - s = JS_ToCString(ctx, v); - JS_FreeValue(ctx, v); + JSValue t = JS_ToObjectString(ctx, v); + s = JS_ToCString(ctx, t); + JS_FreeValue(ctx, t); } if (!s) return JS_EXCEPTION; @@ -500,15 +500,15 @@ static JSValue js_print_262(JSContext *ctx, JSValue this_val, return JS_UNDEFINED; } -static JSValue js_detachArrayBuffer(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_detachArrayBuffer(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { JS_DetachArrayBuffer(ctx, argv[0]); return JS_UNDEFINED; } -static JSValue js_evalScript_262(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_evalScript_262(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { const char *str; size_t len; @@ -673,7 +673,7 @@ static void *agent_start(void *arg) NULL, NULL, true); args[1] = JS_NewInt32(ctx, agent->broadcast_val); ret_val = JS_Call(ctx, agent->broadcast_func, JS_UNDEFINED, - 2, args); + 2, (JSValueConst *)args); JS_FreeValue(ctx, args[0]); JS_FreeValue(ctx, args[1]); if (JS_IsException(ret_val)) @@ -691,8 +691,8 @@ static void *agent_start(void *arg) return NULL; } -static JSValue js_agent_start(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_agent_start(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { ThreadLocalStorage *tls = JS_GetRuntimeOpaque(JS_GetRuntime(ctx)); const char *script; @@ -731,8 +731,8 @@ static void js_agent_free(JSContext *ctx) } } -static JSValue js_agent_leaving(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_agent_leaving(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { Test262Agent *agent = JS_GetContextOpaque(ctx); if (!agent) @@ -753,11 +753,11 @@ static bool is_broadcast_pending(ThreadLocalStorage *tls) return false; } -static JSValue js_agent_broadcast(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_agent_broadcast(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { ThreadLocalStorage *tls = JS_GetRuntimeOpaque(JS_GetRuntime(ctx)); - JSValue sab = argv[0]; + JSValueConst sab = argv[0]; struct list_head *el; Test262Agent *agent; uint8_t *buf; @@ -795,8 +795,8 @@ static JSValue js_agent_broadcast(JSContext *ctx, JSValue this_val, return JS_UNDEFINED; } -static JSValue js_agent_receiveBroadcast(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_agent_receiveBroadcast(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { Test262Agent *agent = JS_GetContextOpaque(ctx); if (!agent) @@ -808,8 +808,8 @@ static JSValue js_agent_receiveBroadcast(JSContext *ctx, JSValue this_val, return JS_UNDEFINED; } -static JSValue js_agent_sleep(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_agent_sleep(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { uint32_t duration; if (JS_ToUint32(ctx, &duration, argv[0])) @@ -833,14 +833,14 @@ static int64_t get_clock_ms(void) #endif } -static JSValue js_agent_monotonicNow(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_agent_monotonicNow(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { return JS_NewInt64(ctx, get_clock_ms()); } -static JSValue js_agent_getReport(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_agent_getReport(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { ThreadLocalStorage *tls = JS_GetRuntimeOpaque(JS_GetRuntime(ctx)); AgentReport *rep; @@ -864,8 +864,8 @@ static JSValue js_agent_getReport(JSContext *ctx, JSValue this_val, return ret; } -static JSValue js_agent_report(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_agent_report(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { ThreadLocalStorage *tls = JS_GetRuntimeOpaque(JS_GetRuntime(ctx)); const char *str; @@ -907,8 +907,8 @@ static JSValue js_new_agent(JSContext *ctx) return agent; } -static JSValue js_createRealm(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_createRealm(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { JSContext *ctx1; JSValue ret; @@ -922,8 +922,8 @@ static JSValue js_createRealm(JSContext *ctx, JSValue this_val, return ret; } -static JSValue js_IsHTMLDDA(JSContext *ctx, JSValue this_val, - int argc, JSValue *argv) +static JSValue js_IsHTMLDDA(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) { return JS_NULL; } @@ -1428,7 +1428,7 @@ static int eval_buf(JSContext *ctx, const char *buf, size_t buf_len, if (JS_IsException(res_val)) { exception_val = JS_GetException(ctx); is_error = JS_IsError(ctx, exception_val); - js_print_262(ctx, JS_NULL, 1, &exception_val); + js_print_262(ctx, JS_NULL, 1, (JSValueConst *)&exception_val); if (is_error) { JSValue name, stack; const char *stack_str;