From 72f60d2e20b8c40bc19fae3fa7921619ee0ef743 Mon Sep 17 00:00:00 2001 From: theMackabu Date: Wed, 4 Mar 2026 01:12:45 -0800 Subject: [PATCH] rename type for consistency --- examples/embed/embed.c | 90 +- include/ant.h | 174 +- include/common.h | 8 +- include/descriptors.h | 28 +- include/errors.h | 10 +- include/esm/commonjs.h | 4 +- include/esm/library.h | 4 +- include/esm/loader.h | 14 +- include/gc.h | 24 +- include/internal.h | 180 +- include/modules/async_hooks.h | 2 +- include/modules/buffer.h | 10 +- include/modules/child_process.h | 2 +- include/modules/collections.h | 20 +- include/modules/crypto.h | 2 +- include/modules/date.h | 6 +- include/modules/dns.h | 2 +- include/modules/events.h | 4 +- include/modules/ffi.h | 4 +- include/modules/fs.h | 4 +- include/modules/io.h | 12 +- include/modules/json.h | 4 +- include/modules/lmdb.h | 14 +- include/modules/module.h | 2 +- include/modules/napi.h | 6 +- include/modules/net.h | 2 +- include/modules/os.h | 2 +- include/modules/path.h | 2 +- include/modules/performance.h | 2 +- include/modules/process.h | 4 +- include/modules/readline.h | 4 +- include/modules/regex.h | 22 +- include/modules/shell.h | 2 +- include/modules/symbol.h | 16 +- include/modules/timer.h | 2 +- include/modules/tty.h | 2 +- include/modules/url.h | 2 +- include/modules/util.h | 2 +- include/modules/worker_threads.h | 2 +- include/roots.h | 8 +- include/runtime.h | 2 +- include/silver/ast.h | 2 +- include/silver/compiler.h | 2 +- include/silver/engine.h | 172 +- include/silver/glue.h | 160 +- include/silver/lexer.h | 16 +- include/silver/swarm.h | 2 +- include/silver/vm.h | 20 +- include/snapshot.h | 2 +- include/sugar.h | 26 +- include/types.h | 4 - src/ant.c | 5328 +++++++++++++++--------------- src/descriptors.c | 44 +- src/errors.c | 102 +- src/esm/commonjs.c | 74 +- src/esm/library.c | 2 +- src/esm/loader.c | 106 +- src/gc.c | 402 +-- src/main.c | 10 +- src/modules/async_hooks.c | 74 +- src/modules/atomics.c | 40 +- src/modules/buffer.c | 420 +-- src/modules/builtin.c | 32 +- src/modules/child_process.c | 230 +- src/modules/collections.c | 436 +-- src/modules/crypto.c | 26 +- src/modules/date.c | 198 +- src/modules/dns.c | 12 +- src/modules/events.c | 106 +- src/modules/fetch.c | 70 +- src/modules/ffi.c | 116 +- src/modules/fs.c | 228 +- src/modules/io.c | 48 +- src/modules/json.c | 120 +- src/modules/lmdb.c | 172 +- src/modules/localstorage.c | 20 +- src/modules/module.c | 62 +- src/modules/napi.c | 374 +-- src/modules/navigator.c | 88 +- src/modules/net.c | 10 +- src/modules/observable.c | 246 +- src/modules/os.c | 112 +- src/modules/path.c | 50 +- src/modules/performance.c | 12 +- src/modules/process.c | 232 +- src/modules/readline.c | 170 +- src/modules/reflect.c | 116 +- src/modules/regex.c | 464 +-- src/modules/server.c | 86 +- src/modules/sessionstorage.c | 18 +- src/modules/shell.c | 40 +- src/modules/symbol.c | 106 +- src/modules/textcodec.c | 44 +- src/modules/timer.c | 40 +- src/modules/tty.c | 152 +- src/modules/uri.c | 26 +- src/modules/url.c | 160 +- src/modules/util.c | 84 +- src/modules/worker_threads.c | 264 +- src/reactor.c | 2 +- src/repl.c | 10 +- src/roots.c | 14 +- src/runtime.c | 2 +- src/silver/ast.c | 16 +- src/silver/compiler.c | 44 +- src/silver/engine.c | 172 +- src/silver/glue.c | 204 +- src/silver/lexer.c | 106 +- src/silver/ops/arithmetic.h | 94 +- src/silver/ops/async.h | 54 +- src/silver/ops/bitwise.h | 50 +- src/silver/ops/calls.h | 66 +- src/silver/ops/coercion.h | 78 +- src/silver/ops/comparison.h | 84 +- src/silver/ops/control.h | 14 +- src/silver/ops/exceptions.h | 22 +- src/silver/ops/globals.h | 16 +- src/silver/ops/iteration.h | 102 +- src/silver/ops/literals.h | 28 +- src/silver/ops/locals.h | 30 +- src/silver/ops/objects.h | 114 +- src/silver/ops/optional.h | 12 +- src/silver/ops/private.h | 26 +- src/silver/ops/property.h | 120 +- src/silver/ops/returns.h | 4 +- src/silver/ops/stack.h | 30 +- src/silver/ops/super.h | 24 +- src/silver/ops/unary.h | 22 +- src/silver/ops/upvalues.h | 38 +- src/silver/swarm.c | 178 +- src/snapshot.c | 4 +- src/sugar.c | 14 +- 132 files changed, 7137 insertions(+), 7141 deletions(-) diff --git a/examples/embed/embed.c b/examples/embed/embed.c index 357bb33..79bcdec 100644 --- a/examples/embed/embed.c +++ b/examples/embed/embed.c @@ -49,7 +49,7 @@ static void example_basic_eval(void) { const char *code = "1 + 2 * 3"; - jsval_t result = js_eval_bytecode_eval(js, code, strlen(code)); + ant_value_t result = js_eval_bytecode_eval(js, code, strlen(code)); if (vtype(result) == T_NUM) { printf(" Result: %g\n", js_getnum(result)); @@ -60,7 +60,7 @@ static void example_basic_eval(void) { js_destroy(js); } -static jsval_t my_add(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t my_add(ant_t *js, ant_value_t *args, int nargs) { if (!js_chkargs(args, nargs, "dd")) { return js_mkerr(js, "add() expects two numbers"); } @@ -71,7 +71,7 @@ static jsval_t my_add(ant_t *js, jsval_t *args, int nargs) { return js_mknum(a + b); } -static jsval_t my_greet(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t my_greet(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || vtype(args[0]) != T_STR) { return js_mkerr(js, "greet() expects a string"); } @@ -85,12 +85,12 @@ static jsval_t my_greet(ant_t *js, jsval_t *args, int nargs) { return js_mkstr(js, buf, strlen(buf)); } -static jsval_t my_create_point(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t my_create_point(ant_t *js, ant_value_t *args, int nargs) { if (!js_chkargs(args, nargs, "dd")) { return js_mkerr(js, "createPoint() expects two numbers"); } - jsval_t obj = js_mkobj(js); + ant_value_t obj = js_mkobj(js); js_set(js, obj, "x", args[0]); js_set(js, obj, "y", args[1]); @@ -106,21 +106,21 @@ static void example_c_functions(void) { - jsval_t global = js_glob(js); + ant_value_t global = js_glob(js); js_set(js, global, "add", js_mkfun(my_add)); js_set(js, global, "greet", js_mkfun(my_greet)); js_set(js, global, "createPoint", js_mkfun(my_create_point)); const char *code1 = "add(10, 32)"; - jsval_t r1 = js_eval_bytecode_eval(js, code1, strlen(code1)); + ant_value_t r1 = js_eval_bytecode_eval(js, code1, strlen(code1)); printf(" add(10, 32) = %g\n", js_getnum(r1)); const char *code2 = "greet('World')"; - jsval_t r2 = js_eval_bytecode_eval(js, code2, strlen(code2)); + ant_value_t r2 = js_eval_bytecode_eval(js, code2, strlen(code2)); printf(" greet('World') = %s\n", js_str(js, r2)); const char *code3 = "let p = createPoint(3, 4); p.x * p.x + p.y * p.y"; - jsval_t r3 = js_eval_bytecode_eval(js, code3, strlen(code3)); + ant_value_t r3 = js_eval_bytecode_eval(js, code3, strlen(code3)); printf(" distance² = %g\n", js_getnum(r3)); js_destroy(js); @@ -134,28 +134,28 @@ static void example_objects_arrays(void) { if (!js) return; - jsval_t global = js_glob(js); + ant_value_t global = js_glob(js); - jsval_t config = js_mkobj(js); + ant_value_t config = js_mkobj(js); js_set(js, config, "debug", js_true); js_set(js, config, "version", js_mknum(1.0)); js_set(js, config, "name", js_mkstr(js, "MyApp", 5)); js_set(js, global, "config", config); - jsval_t arr = js_mkarr(js); + ant_value_t arr = js_mkarr(js); js_arr_push(js, arr, js_mknum(10)); js_arr_push(js, arr, js_mknum(20)); js_arr_push(js, arr, js_mknum(30)); js_set(js, global, "numbers", arr); const char *code = "config.name + ' v' + config.version + ' - sum: ' + numbers.reduce((a,b) => a+b, 0)"; - jsval_t result = js_eval_bytecode_eval(js, code, strlen(code)); + ant_value_t result = js_eval_bytecode_eval(js, code, strlen(code)); printf(" Result: %s\n", js_str(js, result)); - jsval_t name_val = js_get(js, config, "name"); + ant_value_t name_val = js_get(js, config, "name"); printf(" config.name: %s\n", js_str(js, name_val)); - jsval_t debug_val = js_get(js, config, "debug"); + ant_value_t debug_val = js_get(js, config, "debug"); printf(" config.debug: %s\n", js_str(js, debug_val)); js_destroy(js); @@ -171,22 +171,22 @@ static void example_error_handling(void) { const char *bad_code = "let x = {"; - jsval_t r1 = js_eval_bytecode_eval(js, bad_code, strlen(bad_code)); + ant_value_t r1 = js_eval_bytecode_eval(js, bad_code, strlen(bad_code)); if (vtype(r1) == T_ERR) { printf(" Syntax error: %s\n", js_str(js, r1)); } const char *ref_err = "undefinedVariable + 1"; - jsval_t r2 = js_eval_bytecode_eval(js, ref_err, strlen(ref_err)); + ant_value_t r2 = js_eval_bytecode_eval(js, ref_err, strlen(ref_err)); if (vtype(r2) == T_ERR) { printf(" Reference error: %s\n", js_str(js, r2)); } - jsval_t global = js_glob(js); + ant_value_t global = js_glob(js); js_set(js, global, "add", js_mkfun(my_add)); const char *type_err = "add('not', 'numbers')"; - jsval_t r3 = js_eval_bytecode_eval(js, type_err, strlen(type_err)); + ant_value_t r3 = js_eval_bytecode_eval(js, type_err, strlen(type_err)); if (vtype(r3) == T_ERR) { printf(" Type error: %s\n", js_str(js, r3)); } @@ -211,20 +211,20 @@ static void example_call_js_from_c(void) { js_eval_bytecode_eval(js, code, strlen(code)); - jsval_t glob = js_glob(js); - jsval_t multiply_fn = js_get(js, glob, "multiply"); - jsval_t format_fn = js_get(js, glob, "formatName"); + ant_value_t glob = js_glob(js); + ant_value_t multiply_fn = js_get(js, glob, "multiply"); + ant_value_t format_fn = js_get(js, glob, "formatName"); - jsval_t args1[] = { js_mknum(6), js_mknum(7) }; - jsval_t result1 = sv_vm_call(js->vm, js, multiply_fn, js_mkundef(), args1, 2, NULL, false); + ant_value_t args1[] = { js_mknum(6), js_mknum(7) }; + ant_value_t result1 = sv_vm_call(js->vm, js, multiply_fn, js_mkundef(), args1, 2, NULL, false); printf(" multiply(6, 7) = %g\n", js_getnum(result1)); - jsval_t args2[] = { + ant_value_t args2[] = { js_mkstr(js, "John", 4), js_mkstr(js, "Doe", 3) }; - jsval_t result2 = sv_vm_call(js->vm, js, format_fn, js_mkundef(), args2, 2, NULL, false); + ant_value_t result2 = sv_vm_call(js->vm, js, format_fn, js_mkundef(), args2, 2, NULL, false); printf(" formatName('John', 'Doe') = %s\n", js_str(js, result2)); js_destroy(js); @@ -238,12 +238,12 @@ static void example_iterate_properties(void) { if (!js) return; const char *code = "({ name: 'Alice', age: 30, city: 'NYC' })"; - jsval_t obj = js_eval_bytecode_eval(js, code, strlen(code)); + ant_value_t obj = js_eval_bytecode_eval(js, code, strlen(code)); ant_iter_t iter = js_prop_iter_begin(js, obj); const char *key; size_t key_len; - jsval_t value; + ant_value_t value; printf(" Object properties:\n"); while (js_prop_iter_next(&iter, &key, &key_len, &value)) { @@ -254,13 +254,13 @@ static void example_iterate_properties(void) { js_destroy(js); } -static jsval_t method_get_full_name(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t method_get_full_name(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t this_obj = js_getthis(js); + ant_value_t this_obj = js_getthis(js); - jsval_t first = js_get(js, this_obj, "firstName"); - jsval_t last = js_get(js, this_obj, "lastName"); + ant_value_t first = js_get(js, this_obj, "firstName"); + ant_value_t last = js_get(js, this_obj, "lastName"); size_t first_len, last_len; char *first_str = js_getstr(js, first, &first_len); @@ -281,7 +281,7 @@ static void example_this_context(void) { - jsval_t person = js_mkobj(js); + ant_value_t person = js_mkobj(js); js_set(js, person, "firstName", js_mkstr(js, "Jane", 4)); js_set(js, person, "lastName", js_mkstr(js, "Smith", 5)); js_set(js, person, "getFullName", js_mkfun(method_get_full_name)); @@ -289,7 +289,7 @@ static void example_this_context(void) { js_set(js, js_glob(js), "person", person); const char *code = "person.getFullName()"; - jsval_t result = js_eval_bytecode_eval(js, code, strlen(code)); + ant_value_t result = js_eval_bytecode_eval(js, code, strlen(code)); printf(" person.getFullName() = %s\n", js_str(js, result)); js_destroy(js); @@ -312,7 +312,7 @@ static void example_stateful_session(void) { "getCount()" }; - jsval_t result = js_mkundef(); + ant_value_t result = js_mkundef(); for (int i = 0; i < 5; i++) { result = js_eval_bytecode_eval(js, scripts[i], strlen(scripts[i])); if (vtype(result) == T_ERR) { @@ -358,7 +358,7 @@ static void example_async_event_loop(void) { "" "results.push('sync');"; - jsval_t result = js_eval_bytecode_eval(js, code, strlen(code)); + ant_value_t result = js_eval_bytecode_eval(js, code, strlen(code)); if (vtype(result) == T_ERR) { printf(" Error: %s\n", js_str(js, result)); js_destroy(js); @@ -367,12 +367,12 @@ static void example_async_event_loop(void) { js_run_event_loop(js); - jsval_t results = js_get(js, js_glob(js), "results"); + ant_value_t results = js_get(js, js_glob(js), "results"); printf(" Execution order:\n"); - jsoff_t len = js_arr_len(js, results); - for (jsoff_t i = 0; i < len; i++) { - jsval_t item = js_arr_get(js, results, i); + ant_offset_t len = js_arr_len(js, results); + for (ant_offset_t i = 0; i < len; i++) { + ant_value_t item = js_arr_get(js, results, i); printf(" %llu. %s\n", (unsigned long long)i + 1, js_str(js, item)); } @@ -398,7 +398,7 @@ static void example_console_logging(void) { "console.error('This is an error');" "'done'"; - jsval_t result = js_eval_bytecode_eval(js, code, strlen(code)); + ant_value_t result = js_eval_bytecode_eval(js, code, strlen(code)); if (vtype(result) == T_ERR) { printf(" Error: %s\n", js_str(js, result)); } @@ -416,12 +416,12 @@ static void example_global_this(void) { init_console_module(); - jsval_t global = js_glob(js); + ant_value_t global = js_glob(js); js_set(js, global, "myNumber", js_mknum(42)); js_set(js, global, "myString", js_mkstr(js, "hello from C", 12)); js_set(js, global, "myBool", js_true); - jsval_t myObj = js_mkobj(js); + ant_value_t myObj = js_mkobj(js); js_set(js, myObj, "a", js_mknum(1)); js_set(js, myObj, "b", js_mknum(2)); js_set(js, global, "myObject", myObj); @@ -443,12 +443,12 @@ static void example_global_this(void) { "console.log(' addedFromJS:', addedFromJS);" "console.log(this)"; - jsval_t result = js_eval_bytecode_eval(js, code, strlen(code)); + ant_value_t result = js_eval_bytecode_eval(js, code, strlen(code)); if (vtype(result) == T_ERR) { printf(" Error: %s\n", js_str(js, result)); } - jsval_t added = js_get(js, global, "addedFromJS"); + ant_value_t added = js_get(js, global, "addedFromJS"); printf("\n Read from C: addedFromJS = %s\n", js_str(js, added)); js_destroy(js); diff --git a/include/ant.h b/include/ant.h index d414403..0974ad9 100644 --- a/include/ant.h +++ b/include/ant.h @@ -29,152 +29,152 @@ #define JS_INF ((double)INFINITY) #define JS_NEG_INF ((double)(-INFINITY)) -#define js_true (NANBOX_PREFIX | ((jsval_t)T_BOOL << NANBOX_TYPE_SHIFT) | 1) -#define js_false (NANBOX_PREFIX | ((jsval_t)T_BOOL << NANBOX_TYPE_SHIFT)) -#define js_bool(x) (js_false | (jsval_t)!!(x)) +#define js_true (NANBOX_PREFIX | ((ant_value_t)T_BOOL << NANBOX_TYPE_SHIFT) | 1) +#define js_false (NANBOX_PREFIX | ((ant_value_t)T_BOOL << NANBOX_TYPE_SHIFT)) +#define js_bool(x) (js_false | (ant_value_t)!!(x)) ant_t *js_create(void *buf, size_t len); ant_t *js_create_dynamic(); -jsval_t js_glob(ant_t *); +ant_value_t js_glob(ant_t *); // TODO: improve naming -jsval_t js_eval_bytecode(ant_t *, const char *, size_t); -jsval_t js_eval_bytecode_module(ant_t *, const char *, size_t); -jsval_t js_eval_bytecode_eval(ant_t *, const char *, size_t); -jsval_t js_eval_bytecode_eval_with_strict(ant_t *, const char *, size_t, bool); -jsval_t js_eval_bytecode_repl(ant_t *, const char *, size_t); +ant_value_t js_eval_bytecode(ant_t *, const char *, size_t); +ant_value_t js_eval_bytecode_module(ant_t *, const char *, size_t); +ant_value_t js_eval_bytecode_eval(ant_t *, const char *, size_t); +ant_value_t js_eval_bytecode_eval_with_strict(ant_t *, const char *, size_t, bool); +ant_value_t js_eval_bytecode_repl(ant_t *, const char *, size_t); void js_destroy(ant_t *); -bool js_truthy(ant_t *, jsval_t); +bool js_truthy(ant_t *, ant_value_t); void js_setstackbase(ant_t *, void *); void js_setstacklimit(ant_t *, size_t); uint32_t js_to_uint32(double d); int32_t js_to_int32(double d); -bool js_chkargs(jsval_t *, int, const char *); +bool js_chkargs(ant_value_t *, int, const char *); void js_set_filename(ant_t *, const char *); void js_stats(ant_t *, size_t *total, size_t *min, size_t *cstacksize); size_t js_getbrk(ant_t *); -jshdl_t js_root(ant_t *, jsval_t); -jsval_t js_deref(ant_t *, jshdl_t); +ant_handle_t js_root(ant_t *, ant_value_t); +ant_value_t js_deref(ant_t *, ant_handle_t); -void js_unroot(ant_t *, jshdl_t); -void js_root_update(ant_t *, jshdl_t, jsval_t); +void js_unroot(ant_t *, ant_handle_t); +void js_root_update(ant_t *, ant_handle_t, ant_value_t); -jsval_t js_mkundef(void); -jsval_t js_mknull(void); -jsval_t js_mknum(double); +ant_value_t js_mkundef(void); +ant_value_t js_mknull(void); +ant_value_t js_mknum(double); -jsval_t js_getthis(ant_t *); -void js_setthis(ant_t *, jsval_t); +ant_value_t js_getthis(ant_t *); +void js_setthis(ant_t *, ant_value_t); -jsval_t js_getcurrentfunc(ant_t *); -jsval_t js_get(ant_t *, jsval_t, const char *); -jsval_t js_getprop_proto(ant_t *, jsval_t, const char *); -jsval_t js_getprop_fallback(ant_t *js, jsval_t obj, const char *name); -jsval_t js_getprop_super(ant_t *js, jsval_t super_obj, jsval_t receiver, const char *name); +ant_value_t js_getcurrentfunc(ant_t *); +ant_value_t js_get(ant_t *, ant_value_t, const char *); +ant_value_t js_getprop_proto(ant_t *, ant_value_t, const char *); +ant_value_t js_getprop_fallback(ant_t *js, ant_value_t obj, const char *name); +ant_value_t js_getprop_super(ant_t *js, ant_value_t super_obj, ant_value_t receiver, const char *name); -jsoff_t js_arr_len(ant_t *js, jsval_t arr); -jsval_t js_arr_get(ant_t *js, jsval_t arr, jsoff_t idx); +ant_offset_t js_arr_len(ant_t *js, ant_value_t arr); +ant_value_t js_arr_get(ant_t *js, ant_value_t arr, ant_offset_t idx); bool js_iter( ant_t *js, - jsval_t iterable, + ant_value_t iterable, bool (*callback)( ant_t *js, - jsval_t value, + ant_value_t value, void *udata ), void *udata ); -uint64_t js_sym_id(jsval_t sym); -const char *js_sym_desc(ant_t *js, jsval_t sym); -const char *js_sym_key(jsval_t sym); +uint64_t js_sym_id(ant_value_t sym); +const char *js_sym_desc(ant_t *js, ant_value_t sym); +const char *js_sym_key(ant_value_t sym); -jsval_t js_mksym_for(ant_t *, const char *key); -jsval_t js_symbol_to_string(ant_t *js, jsval_t sym); -jsval_t js_get_sym(ant_t *, jsval_t obj, jsval_t sym); +ant_value_t js_mksym_for(ant_t *, const char *key); +ant_value_t js_symbol_to_string(ant_t *js, ant_value_t sym); +ant_value_t js_get_sym(ant_t *, ant_value_t obj, ant_value_t sym); -jsval_t js_mkobj(ant_t *); -jsval_t js_newobj(ant_t *); -jsval_t js_mkarr(ant_t *); -jsval_t js_mkstr(ant_t *, const void *, size_t); -jsval_t js_mkbigint(ant_t *, const char *digits, size_t len, bool negative); -jsval_t js_mksym(ant_t *, const char *desc); -jsval_t js_mkfun(jsval_t (*fn)(ant_t *, jsval_t *, int)); -jsval_t js_heavy_mkfun(ant_t *js, jsval_t (*fn)(ant_t *, jsval_t *, int), jsval_t data); +ant_value_t js_mkobj(ant_t *); +ant_value_t js_newobj(ant_t *); +ant_value_t js_mkarr(ant_t *); +ant_value_t js_mkstr(ant_t *, const void *, size_t); +ant_value_t js_mkbigint(ant_t *, const char *digits, size_t len, bool negative); +ant_value_t js_mksym(ant_t *, const char *desc); +ant_value_t js_mkfun(ant_value_t (*fn)(ant_t *, ant_value_t *, int)); +ant_value_t js_heavy_mkfun(ant_t *js, ant_value_t (*fn)(ant_t *, ant_value_t *, int), ant_value_t data); -jsval_t js_mkprop_fast(ant_t *js, jsval_t obj, const char *key, size_t len, jsval_t v); -jsoff_t js_mkprop_fast_off(ant_t *js, jsval_t obj, const char *key, size_t len, jsval_t v); +ant_value_t js_mkprop_fast(ant_t *js, ant_value_t obj, const char *key, size_t len, ant_value_t v); +ant_offset_t js_mkprop_fast_off(ant_t *js, ant_value_t obj, const char *key, size_t len, ant_value_t v); -void js_set(ant_t *, jsval_t, const char *, jsval_t); -void js_set_sym(ant_t *, jsval_t obj, jsval_t sym, jsval_t val); -void js_saveval(ant_t *js, jsoff_t off, jsval_t v); -bool js_del(ant_t *, jsval_t obj, const char *key); -void js_merge_obj(ant_t *, jsval_t dst, jsval_t src); -void js_arr_push(ant_t *, jsval_t arr, jsval_t val); -void js_set_proto(ant_t *, jsval_t obj, jsval_t proto); +void js_set(ant_t *, ant_value_t, const char *, ant_value_t); +void js_set_sym(ant_t *, ant_value_t obj, ant_value_t sym, ant_value_t val); +void js_saveval(ant_t *js, ant_offset_t off, ant_value_t v); +bool js_del(ant_t *, ant_value_t obj, const char *key); +void js_merge_obj(ant_t *, ant_value_t dst, ant_value_t src); +void js_arr_push(ant_t *, ant_value_t arr, ant_value_t val); +void js_set_proto(ant_t *, ant_value_t obj, ant_value_t proto); -jsval_t js_setprop(ant_t *, jsval_t obj, jsval_t key, jsval_t val); -jsval_t js_setprop_nonconfigurable(ant_t *, jsval_t obj, const char *key, size_t keylen, jsval_t val); +ant_value_t js_setprop(ant_t *, ant_value_t obj, ant_value_t key, ant_value_t val); +ant_value_t js_setprop_nonconfigurable(ant_t *, ant_value_t obj, const char *key, size_t keylen, ant_value_t val); -jsval_t js_get_proto(ant_t *, jsval_t obj); -jsval_t js_get_ctor_proto(ant_t *, const char *name, size_t len); -jsval_t js_tostring_val(ant_t *js, jsval_t value); +ant_value_t js_get_proto(ant_t *, ant_value_t obj); +ant_value_t js_get_ctor_proto(ant_t *, const char *name, size_t len); +ant_value_t js_tostring_val(ant_t *js, ant_value_t value); -uint8_t vtype(jsval_t val); -size_t vdata(jsval_t val); +uint8_t vtype(ant_value_t val); +size_t vdata(ant_value_t val); -double js_getnum(jsval_t val); -char *js_getstr(ant_t *js, jsval_t val, size_t *len); +double js_getnum(ant_value_t val); +char *js_getstr(ant_t *js, ant_value_t val, size_t *len); -const char *js_str(ant_t *, jsval_t val); -const char *get_str_prop(ant_t *js, jsval_t obj, const char *key, jsoff_t klen, jsoff_t *out_len); +const char *js_str(ant_t *, ant_value_t val); +const char *get_str_prop(ant_t *js, ant_value_t obj, const char *key, ant_offset_t klen, ant_offset_t *out_len); typedef struct { void *ctx; - jsoff_t off; + ant_offset_t off; } ant_iter_t; -ant_iter_t js_prop_iter_begin(ant_t *js, jsval_t obj); +ant_iter_t js_prop_iter_begin(ant_t *js, ant_value_t obj); -bool js_prop_iter_next(ant_iter_t *iter, const char **key, size_t *key_len, jsval_t *value); +bool js_prop_iter_next(ant_iter_t *iter, const char **key, size_t *key_len, ant_value_t *value); void js_prop_iter_end(ant_iter_t *iter); -jsval_t js_obj_to_func(jsval_t obj); -jsval_t js_mkpromise(ant_t *js); +ant_value_t js_obj_to_func(ant_value_t obj); +ant_value_t js_mkpromise(ant_t *js); -jsval_t js_mktypedarray(void *data); -void *js_gettypedarray(jsval_t val); +ant_value_t js_mktypedarray(void *data); +void *js_gettypedarray(ant_value_t val); -jsval_t js_mkffi(unsigned int index); -int js_getffi(jsval_t val); +ant_value_t js_mkffi(unsigned int index); +int js_getffi(ant_value_t val); -void js_resolve_promise(ant_t *js, jsval_t promise, jsval_t value); -void js_reject_promise(ant_t *js, jsval_t promise, jsval_t value); +void js_resolve_promise(ant_t *js, ant_value_t promise, ant_value_t value); +void js_reject_promise(ant_t *js, ant_value_t promise, ant_value_t value); void js_check_unhandled_rejections(ant_t *js); void js_process_promise_handlers(ant_t *js, uint32_t promise_id); void js_setup_import_meta(ant_t *js, const char *filename); -typedef jsval_t (*js_getter_fn)(ant_t *js, jsval_t obj, const char *key, size_t key_len); -typedef bool (*js_setter_fn)(ant_t *js, jsval_t obj, const char *key, size_t key_len, jsval_t value); -typedef bool (*js_deleter_fn)(ant_t *js, jsval_t obj, const char *key, size_t key_len); -typedef jsval_t (*js_keys_fn)(ant_t *js, jsval_t obj); +typedef ant_value_t (*js_getter_fn)(ant_t *js, ant_value_t obj, const char *key, size_t key_len); +typedef bool (*js_setter_fn)(ant_t *js, ant_value_t obj, const char *key, size_t key_len, ant_value_t value); +typedef bool (*js_deleter_fn)(ant_t *js, ant_value_t obj, const char *key, size_t key_len); +typedef ant_value_t (*js_keys_fn)(ant_t *js, ant_value_t obj); -void js_set_getter(ant_t *js, jsval_t obj, js_getter_fn getter); -void js_set_setter(ant_t *js, jsval_t obj, js_setter_fn setter); -void js_set_deleter(ant_t *js, jsval_t obj, js_deleter_fn deleter); -void js_set_keys(ant_t *js, jsval_t obj, js_keys_fn keys); +void js_set_getter(ant_t *js, ant_value_t obj, js_getter_fn getter); +void js_set_setter(ant_t *js, ant_value_t obj, js_setter_fn setter); +void js_set_deleter(ant_t *js, ant_value_t obj, js_deleter_fn deleter); +void js_set_keys(ant_t *js, ant_value_t obj, js_keys_fn keys); -jsval_t js_get_slot(ant_t *js, jsval_t obj, internal_slot_t slot); -void js_set_slot(ant_t *js, jsval_t obj, internal_slot_t slot, jsval_t value); +ant_value_t js_get_slot(ant_t *js, ant_value_t obj, internal_slot_t slot); +void js_set_slot(ant_t *js, ant_value_t obj, internal_slot_t slot, ant_value_t value); -bool js_is_slot_prop(jsoff_t header); -jsoff_t js_next_prop(jsoff_t header); -jsoff_t js_loadoff(ant_t *js, jsoff_t off); +bool js_is_slot_prop(ant_offset_t header); +ant_offset_t js_next_prop(ant_offset_t header); +ant_offset_t js_loadoff(ant_t *js, ant_offset_t off); #endif diff --git a/include/common.h b/include/common.h index ccd610d..2022705 100644 --- a/include/common.h +++ b/include/common.h @@ -1,10 +1,10 @@ #ifndef COMMON_H #define COMMON_H -#define SLOTMASK ~(((jsoff_t) ~0) >> 1) -#define CONSTMASK (~(((jsoff_t) ~0) >> 1) >> 1) -#define ARRMASK (~(((jsoff_t) ~0) >> 1) >> 2) -#define NONCONFIGMASK (~(((jsoff_t) ~0) >> 1) >> 3) +#define SLOTMASK ~(((ant_offset_t) ~0) >> 1) +#define CONSTMASK (~(((ant_offset_t) ~0) >> 1) >> 1) +#define ARRMASK (~(((ant_offset_t) ~0) >> 1) >> 2) +#define NONCONFIGMASK (~(((ant_offset_t) ~0) >> 1) >> 3) #define FLAGMASK (SLOTMASK | CONSTMASK | ARRMASK | NONCONFIGMASK) typedef enum { diff --git a/include/descriptors.h b/include/descriptors.h index f9ed416..7d2780d 100644 --- a/include/descriptors.h +++ b/include/descriptors.h @@ -10,8 +10,8 @@ typedef struct descriptor_entry { uint64_t key; - jsoff_t obj_off; - jsoff_t sym_off; + ant_offset_t obj_off; + ant_offset_t sym_off; char *prop_name; size_t prop_len; bool writable; @@ -19,25 +19,25 @@ typedef struct descriptor_entry { bool configurable; bool has_getter; bool has_setter; - jsval_t getter; - jsval_t setter; + ant_value_t getter; + ant_value_t setter; UT_hash_handle hh; } descriptor_entry_t; extern descriptor_entry_t *desc_registry; -descriptor_entry_t *lookup_descriptor(ant_t *js, jsoff_t obj_off, const char *key, size_t klen); -descriptor_entry_t *lookup_sym_descriptor(jsoff_t obj_off, jsoff_t sym_off); +descriptor_entry_t *lookup_descriptor(ant_t *js, ant_offset_t obj_off, const char *key, size_t klen); +descriptor_entry_t *lookup_sym_descriptor(ant_offset_t obj_off, ant_offset_t sym_off); -uint64_t make_desc_key(jsoff_t obj_off, const char *key, size_t klen); -uint64_t make_sym_desc_key(jsoff_t obj_off, jsoff_t sym_off); +uint64_t make_desc_key(ant_offset_t obj_off, const char *key, size_t klen); +uint64_t make_sym_desc_key(ant_offset_t obj_off, ant_offset_t sym_off); -void js_set_descriptor(ant_t *js, jsval_t obj, const char *key, size_t klen, int flags); -void js_set_getter_desc(ant_t *js, jsval_t obj, const char *key, size_t klen, jsval_t getter, int flags); -void js_set_setter_desc(ant_t *js, jsval_t obj, const char *key, size_t klen, jsval_t setter, int flags); -void js_set_accessor_desc(ant_t *js, jsval_t obj, const char *key, size_t klen, jsval_t getter, jsval_t setter, int flags); +void js_set_descriptor(ant_t *js, ant_value_t obj, const char *key, size_t klen, int flags); +void js_set_getter_desc(ant_t *js, ant_value_t obj, const char *key, size_t klen, ant_value_t getter, int flags); +void js_set_setter_desc(ant_t *js, ant_value_t obj, const char *key, size_t klen, ant_value_t setter, int flags); +void js_set_accessor_desc(ant_t *js, ant_value_t obj, const char *key, size_t klen, ant_value_t getter, ant_value_t setter, int flags); -void js_set_sym_getter_desc(ant_t *js, jsval_t obj, jsval_t sym, jsval_t getter, int flags); -void js_set_sym_setter_desc(ant_t *js, jsval_t obj, jsval_t sym, jsval_t setter, int flags); +void js_set_sym_getter_desc(ant_t *js, ant_value_t obj, ant_value_t sym, ant_value_t getter, int flags); +void js_set_sym_setter_desc(ant_t *js, ant_value_t obj, ant_value_t sym, ant_value_t setter, int flags); #endif diff --git a/include/errors.h b/include/errors.h index 68ab4df..1a55dc2 100644 --- a/include/errors.h +++ b/include/errors.h @@ -25,7 +25,7 @@ typedef enum { js_err_type_t get_error_type(ant_t *js); bool print_uncaught_throw(ant_t *js); -bool print_unhandled_promise_rejection(ant_t *js, jsval_t value); +bool print_unhandled_promise_rejection(ant_t *js, ant_value_t value); void js_clear_error_site(ant_t *js); void js_print_stack_trace_vm(ant_t *js, FILE *stream); @@ -38,13 +38,13 @@ void js_set_error_site_from_bc( void js_set_error_site( ant_t *js, const char *src, - jsoff_t src_len, const char *filename, - jsoff_t off, jsoff_t span_len + ant_offset_t src_len, const char *filename, + ant_offset_t off, ant_offset_t span_len ); __attribute__((format(printf, 4, 5))) -jsval_t js_create_error(ant_t *js, js_err_type_t err_type, jsval_t props, const char *fmt, ...); -jsval_t js_throw(ant_t *js, jsval_t value); +ant_value_t js_create_error(ant_t *js, js_err_type_t err_type, ant_value_t props, const char *fmt, ...); +ant_value_t js_throw(ant_t *js, ant_value_t value); #define js_mkerr(js, ...) js_create_error(js, JS_ERR_TYPE, js_mkundef(), __VA_ARGS__) #define js_mkerr_typed(js, err_type, ...) js_create_error(js, err_type, js_mkundef(), __VA_ARGS__) diff --git a/include/esm/commonjs.h b/include/esm/commonjs.h index ff011a3..4b7e44c 100644 --- a/include/esm/commonjs.h +++ b/include/esm/commonjs.h @@ -6,10 +6,10 @@ #include #include -jsval_t esm_load_commonjs_module( +ant_value_t esm_load_commonjs_module( ant_t *js, const char *module_path, const char *code, - size_t code_len, jsval_t ns + size_t code_len, ant_value_t ns ); #endif diff --git a/include/esm/library.h b/include/esm/library.h index f794452..55f7493 100644 --- a/include/esm/library.h +++ b/include/esm/library.h @@ -6,7 +6,7 @@ #include #include -typedef jsval_t (*ant_library_init_fn)(ant_t *js); +typedef ant_value_t (*ant_library_init_fn)(ant_t *js); typedef void (*ant_library_iter_fn)(const char *name, void *userdata); void ant_register_library(ant_library_init_fn init_fn, const char *name, ...); @@ -15,7 +15,7 @@ void ant_library_foreach(ant_library_iter_fn cb, void *userdata); #define ant_standard_library(name, lib) \ ant_register_library(lib, name, "ant:" name, "node:" name, NULL) -jsval_t js_esm_load_registered_library( +ant_value_t js_esm_load_registered_library( ant_t *js, const char *specifier, size_t spec_len, bool *loaded ); diff --git a/include/esm/loader.h b/include/esm/loader.h index 9046537..ada275c 100644 --- a/include/esm/loader.h +++ b/include/esm/loader.h @@ -7,18 +7,18 @@ #include void js_esm_cleanup_module_cache(void); -void js_esm_gc_roots(void (*visit)(void *ctx, jsval_t *val), void *ctx); +void js_esm_gc_roots(void (*visit)(void *ctx, ant_value_t *val), void *ctx); -jsval_t js_esm_import_sync(ant_t *js, jsval_t specifier); -jsval_t js_esm_make_file_url(ant_t *js, const char *path); +ant_value_t js_esm_import_sync(ant_t *js, ant_value_t specifier); +ant_value_t js_esm_make_file_url(ant_t *js, const char *path); -jsval_t js_esm_eval_module_source( +ant_value_t js_esm_eval_module_source( ant_t *js, const char *resolved_path, const char *js_code, - size_t js_len, jsval_t ns + size_t js_len, ant_value_t ns ); -jsval_t js_esm_import_sync_cstr(ant_t *js, const char *specifier, size_t spec_len); -jsval_t js_esm_resolve_specifier(ant_t *js, jsval_t specifier, const char *base_path); +ant_value_t js_esm_import_sync_cstr(ant_t *js, const char *specifier, size_t spec_len); +ant_value_t js_esm_resolve_specifier(ant_t *js, ant_value_t specifier, const char *base_path); #endif diff --git a/include/gc.h b/include/gc.h index 61a1133..66bcc49 100644 --- a/include/gc.h +++ b/include/gc.h @@ -11,10 +11,10 @@ #define ROPE_FLATTEN_THRESHOLD (32 * 1024) typedef struct { - jsoff_t header; - jsval_t left; - jsval_t right; - jsval_t cached; + ant_offset_t header; + ant_value_t left; + ant_value_t right; + ant_value_t cached; } rope_node_t; #define GC_FWD_LOAD_FACTOR 70 @@ -22,24 +22,24 @@ typedef struct { #define GC_CB(ret, name, arg) ret (*name)(void *ctx, arg old) #define GC_CTX void *ctx -#define GC_FWD_OFF GC_CB(jsoff_t, fwd_off, jsoff_t) -#define GC_FWD_VAL GC_CB(jsval_t, fwd_val, jsval_t) -#define GC_WEAK_OFF GC_CB(jsoff_t, weak_off, jsoff_t) -#define GC_OP_VAL void (*op_val)(void *ctx, jsval_t *val) +#define GC_FWD_OFF GC_CB(ant_offset_t, fwd_off, ant_offset_t) +#define GC_FWD_VAL GC_CB(ant_value_t, fwd_val, ant_value_t) +#define GC_WEAK_OFF GC_CB(ant_offset_t, weak_off, ant_offset_t) +#define GC_OP_VAL void (*op_val)(void *ctx, ant_value_t *val) #define GC_FWD_ARGS GC_FWD_VAL, GC_CTX #define GC_RESERVE_ARGS ant_t *js, GC_FWD_OFF, GC_FWD_ARGS #define GC_UPDATE_ARGS ant_t *js, GC_FWD_OFF, GC_WEAK_OFF, GC_FWD_ARGS #define GC_OP_VAL_ARGS GC_OP_VAL, GC_CTX -#define FWD_EMPTY ((jsoff_t)~0) -#define FWD_TOMBSTONE ((jsoff_t)~1) +#define FWD_EMPTY ((ant_offset_t)~0) +#define FWD_TOMBSTONE ((ant_offset_t)~1) #define GC_BIGINT_HEADER_SHIFT 4 #define GC_SYM_HEADER_SHIFT 4 -#define GC_BIGINT_HEADER_LOW_MASK ((jsoff_t)((1u << GC_BIGINT_HEADER_SHIFT) - 1u)) -#define GC_SYM_HEADER_LOW_MASK ((jsoff_t)((1u << GC_SYM_HEADER_SHIFT) - 1u)) +#define GC_BIGINT_HEADER_LOW_MASK ((ant_offset_t)((1u << GC_BIGINT_HEADER_SHIFT) - 1u)) +#define GC_SYM_HEADER_LOW_MASK ((ant_offset_t)((1u << GC_SYM_HEADER_SHIFT) - 1u)) #define GC_SYM_HEAP_FIXED (sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uintptr_t)) #ifdef _WIN32 diff --git a/include/internal.h b/include/internal.h index 18d5ac9..b7d8be3 100644 --- a/include/internal.h +++ b/include/internal.h @@ -67,7 +67,7 @@ typedef struct sv_func sv_func_t; #define PROTO_WALK_F_OBJECT_ONLY (1u << 0) #define PROTO_WALK_F_LOOKUP (1u << 1) -#define T_EMPTY (NANBOX_PREFIX | ((jsval_t)T_SENTINEL << NANBOX_TYPE_SHIFT) | 0xDEADULL) +#define T_EMPTY (NANBOX_PREFIX | ((ant_value_t)T_SENTINEL << NANBOX_TYPE_SHIFT) | 0xDEADULL) #define T_SPECIAL_OBJECT_MASK (JS_TYPE_FLAG(T_OBJ) | JS_TYPE_FLAG(T_ARR)) #define T_NEEDS_PROTO_FALLBACK (JS_TYPE_FLAG(T_FUNC) | JS_TYPE_FLAG(T_ARR) | JS_TYPE_FLAG(T_PROMISE)) #define T_OBJECT_MASK (JS_TYPE_FLAG(T_OBJ) | JS_TYPE_FLAG(T_ARR) | JS_TYPE_FLAG(T_FUNC) | JS_TYPE_FLAG(T_PROMISE)) @@ -111,9 +111,9 @@ enum { typedef struct { const char *src; const char *filename; - jsoff_t src_len; - jsoff_t off; - jsoff_t span_len; + ant_offset_t src_len; + ant_offset_t off; + ant_offset_t span_len; bool valid; } js_error_site_t; @@ -130,19 +130,19 @@ struct ant { uint64_t sym_counter; js_error_site_t errsite; - jsval_t global; - jsval_t object; - jsval_t this_val; - jsval_t new_target; - jsval_t current_func; + ant_value_t global; + ant_value_t object; + ant_value_t this_val; + ant_value_t new_target; + ant_value_t current_func; - jsval_t module_ns; - jsval_t import_meta; - jsval_t length_str; + ant_value_t module_ns; + ant_value_t import_meta; + ant_value_t length_str; uint8_t *mem; - jsoff_t size; - jsoff_t brk; + ant_offset_t size; + ant_offset_t brk; struct { void *base; @@ -151,14 +151,14 @@ struct ant { size_t limit; } cstk; - jsoff_t max_size; - jsval_t thrown_value; - jsval_t thrown_stack; - jsoff_t gc_alloc_since; + ant_offset_t max_size; + ant_value_t thrown_value; + ant_value_t thrown_stack; + ant_offset_t gc_alloc_since; - jsval_t *gc_roots; - jshdl_t gc_roots_len; - jshdl_t gc_roots_cap; + ant_value_t *gc_roots; + ant_handle_t gc_roots_len; + ant_handle_t gc_roots_cap; bool owns_mem; bool needs_gc; @@ -178,117 +178,117 @@ typedef struct { size_t bytes; } js_intern_stats_t; -typedef jsval_t - (*js_cfunc_fn_t)(ant_t *, jsval_t *, int); +typedef ant_value_t + (*js_cfunc_fn_t)(ant_t *, ant_value_t *, int); -static inline js_cfunc_fn_t js_as_cfunc(jsval_t fn_val) { +static inline js_cfunc_fn_t js_as_cfunc(ant_value_t fn_val) { return (js_cfunc_fn_t)(uintptr_t)vdata(fn_val); } -static inline bool is_err(jsval_t v) { +static inline bool is_err(ant_value_t v) { return vtype(v) == T_ERR; } -static inline bool is_null(jsval_t v) { +static inline bool is_null(ant_value_t v) { return vtype(v) == T_NULL; } -static inline bool is_undefined(jsval_t v) { +static inline bool is_undefined(ant_value_t v) { return vtype(v) == T_UNDEF; } -static inline bool is_empty_slot(jsval_t v) { +static inline bool is_empty_slot(ant_value_t v) { return v == T_EMPTY; } -static inline jsoff_t loadoff(ant_t *js, jsoff_t off) { - assert(off + sizeof(jsoff_t) <= js->brk); jsoff_t val; +static inline ant_offset_t loadoff(ant_t *js, ant_offset_t off) { + assert(off + sizeof(ant_offset_t) <= js->brk); ant_offset_t val; memcpy(&val, &js->mem[off], sizeof(val)); return val; } -static inline jsval_t loadval(ant_t *js, jsoff_t off) { - return *(jsval_t *)(&js->mem[off]); +static inline ant_value_t loadval(ant_t *js, ant_offset_t off) { + return *(ant_value_t *)(&js->mem[off]); } -static inline bool is_arr_off(ant_t *js, jsoff_t off) { +static inline bool is_arr_off(ant_t *js, ant_offset_t off) { return (loadoff(js, off) & ARRMASK) != 0; } -bool is_internal_prop(const char *key, jsoff_t klen); +bool is_internal_prop(const char *key, ant_offset_t klen); size_t uint_to_str(char *buf, size_t bufsize, uint64_t val); void js_gc_reserve_roots(GC_RESERVE_ARGS); void js_gc_update_roots(GC_UPDATE_ARGS); void js_gc_visit_frame_funcs(ant_t *js, void (*visitor)(void *, sv_func_t *), void *ctx); -jsoff_t esize(jsoff_t w); -jsval_t tov(double d); +ant_offset_t esize(ant_offset_t w); +ant_value_t tov(double d); -double tod(jsval_t v); -double js_to_number(ant_t *js, jsval_t arg); +double tod(ant_value_t v); +double js_to_number(ant_t *js, ant_value_t arg); -jsval_t resolveprop(ant_t *js, jsval_t v); -jsval_t mkprop(ant_t *js, jsval_t obj, jsval_t k, jsval_t v, jsoff_t flags); -jsval_t setprop_cstr(ant_t *js, jsval_t obj, const char *key, size_t len, jsval_t v); -jsval_t setprop_interned(ant_t *js, jsval_t obj, const char *key, size_t len, jsval_t v); -jsval_t js_define_own_prop(ant_t *js, jsval_t obj, const char *key, size_t klen, jsval_t v); +ant_value_t resolveprop(ant_t *js, ant_value_t v); +ant_value_t mkprop(ant_t *js, ant_value_t obj, ant_value_t k, ant_value_t v, ant_offset_t flags); +ant_value_t setprop_cstr(ant_t *js, ant_value_t obj, const char *key, size_t len, ant_value_t v); +ant_value_t setprop_interned(ant_t *js, ant_value_t obj, const char *key, size_t len, ant_value_t v); +ant_value_t js_define_own_prop(ant_t *js, ant_value_t obj, const char *key, size_t klen, ant_value_t v); -jsval_t coerce_to_str(ant_t *js, jsval_t v); -jsval_t coerce_to_str_concat(ant_t *js, jsval_t v); -jsval_t get_ctor_species_value(ant_t *js, jsval_t ctor); +ant_value_t coerce_to_str(ant_t *js, ant_value_t v); +ant_value_t coerce_to_str_concat(ant_t *js, ant_value_t v); +ant_value_t get_ctor_species_value(ant_t *js, ant_value_t ctor); -bool is_rope(ant_t *js, jsval_t value); -bool proto_chain_contains(ant_t *js, jsval_t obj, jsval_t proto_target); -bool same_ctor_identity(ant_t *js, jsval_t a, jsval_t b); +bool is_rope(ant_t *js, ant_value_t value); +bool proto_chain_contains(ant_t *js, ant_value_t obj, ant_value_t proto_target); +bool same_ctor_identity(ant_t *js, ant_value_t a, ant_value_t b); js_intern_stats_t js_intern_stats(void); -js_cstr_t js_to_cstr(ant_t *js, jsval_t value, char *stack_buf, size_t stack_size); -jsval_t js_instance_proto_from_new_target(ant_t *js, jsval_t fallback_proto); +js_cstr_t js_to_cstr(ant_t *js, ant_value_t value, char *stack_buf, size_t stack_size); +ant_value_t js_instance_proto_from_new_target(ant_t *js, ant_value_t fallback_proto); -jsoff_t lkp(ant_t *js, jsval_t obj, const char *buf, size_t len); -jsoff_t lkp_proto(ant_t *js, jsval_t obj, const char *buf, size_t len); -jsoff_t lkp_sym(ant_t *js, jsval_t obj, jsoff_t sym_off); -jsoff_t lkp_sym_proto(ant_t *js, jsval_t obj, jsoff_t sym_off); -jsoff_t vstr(ant_t *js, jsval_t value, jsoff_t *len); -jsoff_t vstrlen(ant_t *js, jsval_t value); -jsval_t rope_flatten(ant_t *js, jsval_t rope); -jsoff_t str_len_fast(ant_t *js, jsval_t str); +ant_offset_t lkp(ant_t *js, ant_value_t obj, const char *buf, size_t len); +ant_offset_t lkp_proto(ant_t *js, ant_value_t obj, const char *buf, size_t len); +ant_offset_t lkp_sym(ant_t *js, ant_value_t obj, ant_offset_t sym_off); +ant_offset_t lkp_sym_proto(ant_t *js, ant_value_t obj, ant_offset_t sym_off); +ant_offset_t vstr(ant_t *js, ant_value_t value, ant_offset_t *len); +ant_offset_t vstrlen(ant_t *js, ant_value_t value); +ant_value_t rope_flatten(ant_t *js, ant_value_t rope); +ant_offset_t str_len_fast(ant_t *js, ant_value_t str); -jsval_t mkarr(ant_t *js); -jsval_t mkval(uint8_t type, uint64_t data); -jsval_t mkobj(ant_t *js, jsoff_t parent); +ant_value_t mkarr(ant_t *js); +ant_value_t mkval(uint8_t type, uint64_t data); +ant_value_t mkobj(ant_t *js, ant_offset_t parent); -jsval_t js_for_in_keys(ant_t *js, jsval_t obj); -jsval_t js_delete_prop(ant_t *js, jsval_t obj, const char *key, size_t len); -jsval_t js_delete_sym_prop(ant_t *js, jsval_t obj, jsval_t sym); +ant_value_t js_for_in_keys(ant_t *js, ant_value_t obj); +ant_value_t js_delete_prop(ant_t *js, ant_value_t obj, const char *key, size_t len); +ant_value_t js_delete_sym_prop(ant_t *js, ant_value_t obj, ant_value_t sym); -bool is_proxy(ant_t *js, jsval_t obj); -bool strict_eq_values(ant_t *js, jsval_t l, jsval_t r); +bool is_proxy(ant_t *js, ant_value_t obj); +bool strict_eq_values(ant_t *js, ant_value_t l, ant_value_t r); -jsval_t js_proxy_apply(ant_t *js, jsval_t proxy, jsval_t this_arg, jsval_t *args, int argc); -jsval_t js_proxy_construct(ant_t *js, jsval_t proxy, jsval_t *args, int argc, jsval_t new_target); -jsval_t sv_call_native(ant_t *js, jsval_t func, jsval_t this_val, jsval_t *args, int nargs); +ant_value_t js_proxy_apply(ant_t *js, ant_value_t proxy, ant_value_t this_arg, ant_value_t *args, int argc); +ant_value_t js_proxy_construct(ant_t *js, ant_value_t proxy, ant_value_t *args, int argc, ant_value_t new_target); +ant_value_t sv_call_native(ant_t *js, ant_value_t func, ant_value_t this_val, ant_value_t *args, int nargs); const char *typestr(uint8_t t); -jsval_t unwrap_primitive(ant_t *js, jsval_t val); -jsval_t do_string_op(ant_t *js, uint8_t op, jsval_t l, jsval_t r); -jsval_t js_to_primitive(ant_t *js, jsval_t value, int hint); - -jsval_t do_instanceof(ant_t *js, jsval_t l, jsval_t r); -jsval_t do_in(ant_t *js, jsval_t l, jsval_t r); - -jsval_t bigint_add(ant_t *js, jsval_t a, jsval_t b); -jsval_t bigint_sub(ant_t *js, jsval_t a, jsval_t b); -jsval_t bigint_mul(ant_t *js, jsval_t a, jsval_t b); -jsval_t bigint_div(ant_t *js, jsval_t a, jsval_t b); -jsval_t bigint_mod(ant_t *js, jsval_t a, jsval_t b); -jsval_t bigint_neg(ant_t *js, jsval_t a); -jsval_t bigint_exp(ant_t *js, jsval_t base, jsval_t exp); -int bigint_compare(ant_t *js, jsval_t a, jsval_t b); - -jsval_t bigint_shift_left(ant_t *js, jsval_t value, uint64_t shift); -jsval_t bigint_shift_right(ant_t *js, jsval_t value, uint64_t shift); -jsval_t bigint_shift_right_logical(ant_t *js, jsval_t value, uint64_t shift); -jsval_t bigint_asint_bits(ant_t *js, jsval_t arg, uint64_t *bits_out); +ant_value_t unwrap_primitive(ant_t *js, ant_value_t val); +ant_value_t do_string_op(ant_t *js, uint8_t op, ant_value_t l, ant_value_t r); +ant_value_t js_to_primitive(ant_t *js, ant_value_t value, int hint); + +ant_value_t do_instanceof(ant_t *js, ant_value_t l, ant_value_t r); +ant_value_t do_in(ant_t *js, ant_value_t l, ant_value_t r); + +ant_value_t bigint_add(ant_t *js, ant_value_t a, ant_value_t b); +ant_value_t bigint_sub(ant_t *js, ant_value_t a, ant_value_t b); +ant_value_t bigint_mul(ant_t *js, ant_value_t a, ant_value_t b); +ant_value_t bigint_div(ant_t *js, ant_value_t a, ant_value_t b); +ant_value_t bigint_mod(ant_t *js, ant_value_t a, ant_value_t b); +ant_value_t bigint_neg(ant_t *js, ant_value_t a); +ant_value_t bigint_exp(ant_t *js, ant_value_t base, ant_value_t exp); +int bigint_compare(ant_t *js, ant_value_t a, ant_value_t b); + +ant_value_t bigint_shift_left(ant_t *js, ant_value_t value, uint64_t shift); +ant_value_t bigint_shift_right(ant_t *js, ant_value_t value, uint64_t shift); +ant_value_t bigint_shift_right_logical(ant_t *js, ant_value_t value, uint64_t shift); +ant_value_t bigint_asint_bits(ant_t *js, ant_value_t arg, uint64_t *bits_out); #endif diff --git a/include/modules/async_hooks.h b/include/modules/async_hooks.h index 77a6765..16a2732 100644 --- a/include/modules/async_hooks.h +++ b/include/modules/async_hooks.h @@ -3,6 +3,6 @@ #include "types.h" -jsval_t async_hooks_library(ant_t *js); +ant_value_t async_hooks_library(ant_t *js); #endif diff --git a/include/modules/buffer.h b/include/modules/buffer.h index 591c1bc..90bd591 100644 --- a/include/modules/buffer.h +++ b/include/modules/buffer.h @@ -48,19 +48,19 @@ void free_array_buffer_data(ArrayBufferData *data); size_t buffer_get_external_memory(void); ArrayBufferData *create_array_buffer_data(size_t length); -jsval_t create_arraybuffer_obj(ant_t *js, ArrayBufferData *buffer); +ant_value_t create_arraybuffer_obj(ant_t *js, ArrayBufferData *buffer); -jsval_t create_typed_array( +ant_value_t create_typed_array( ant_t *js, TypedArrayType type, ArrayBufferData *buffer, size_t byte_offset, size_t length, const char *type_name ); -jsval_t create_typed_array_with_buffer( +ant_value_t create_typed_array_with_buffer( ant_t *js, TypedArrayType type, ArrayBufferData *buffer, size_t byte_offset, size_t length, - const char *type_name, jsval_t arraybuffer_obj + const char *type_name, ant_value_t arraybuffer_obj ); -jsval_t buffer_library(ant_t *js); +ant_value_t buffer_library(ant_t *js); #endif diff --git a/include/modules/child_process.h b/include/modules/child_process.h index 6df05b7..4375a96 100644 --- a/include/modules/child_process.h +++ b/include/modules/child_process.h @@ -4,7 +4,7 @@ #include "gc.h" #include "types.h" -jsval_t child_process_library(ant_t *js); +ant_value_t child_process_library(ant_t *js); int has_pending_child_processes(void); void child_process_gc_update_roots(GC_OP_VAL_ARGS); diff --git a/include/modules/collections.h b/include/modules/collections.h index 560303a..ca9f6f8 100644 --- a/include/modules/collections.h +++ b/include/modules/collections.h @@ -7,24 +7,24 @@ typedef struct map_entry { char *key; - jsval_t value; + ant_value_t value; UT_hash_handle hh; } map_entry_t; typedef struct set_entry { - jsval_t value; + ant_value_t value; char *key; UT_hash_handle hh; } set_entry_t; typedef struct weakmap_entry { - jsval_t key_obj; - jsval_t value; + ant_value_t key_obj; + ant_value_t value; UT_hash_handle hh; } weakmap_entry_t; typedef struct weakset_entry { - jsval_t value_obj; + ant_value_t value_obj; UT_hash_handle hh; } weakset_entry_t; @@ -50,12 +50,12 @@ typedef struct set_iterator_state { typedef struct map_registry_entry { map_entry_t **head; - jsoff_t obj_offset; + ant_offset_t obj_offset; } map_registry_entry_t; typedef struct set_registry_entry { set_entry_t **head; - jsoff_t obj_offset; + ant_offset_t obj_offset; } set_registry_entry_t; void init_collections_module(void); @@ -63,9 +63,9 @@ void cleanup_collections_module(void); size_t collections_get_external_memory(void); void collections_gc_reserve_roots(GC_OP_VAL_ARGS); -void collections_gc_update_roots(jsoff_t (*weak_off)(void *ctx, jsoff_t old), GC_OP_VAL_ARGS); +void collections_gc_update_roots(ant_offset_t (*weak_off)(void *ctx, ant_offset_t old), GC_OP_VAL_ARGS); -map_entry_t **get_map_from_obj(ant_t *js, jsval_t obj); -set_entry_t **get_set_from_obj(ant_t *js, jsval_t obj); +map_entry_t **get_map_from_obj(ant_t *js, ant_value_t obj); +set_entry_t **get_set_from_obj(ant_t *js, ant_value_t obj); #endif diff --git a/include/modules/crypto.h b/include/modules/crypto.h index 0c6c3d0..6f4c256 100644 --- a/include/modules/crypto.h +++ b/include/modules/crypto.h @@ -4,6 +4,6 @@ #include "types.h" void init_crypto_module(); -jsval_t crypto_library(ant_t *js); +ant_value_t crypto_library(ant_t *js); #endif \ No newline at end of file diff --git a/include/modules/date.h b/include/modules/date.h index b424941..deeed4a 100644 --- a/include/modules/date.h +++ b/include/modules/date.h @@ -66,13 +66,13 @@ typedef struct { typedef struct { const char *name; size_t len; - jsval_t (*fn)(ant_t *, jsval_t *, int); + ant_value_t (*fn)(ant_t *, ant_value_t *, int); } date_method_entry_t; void init_date_module(void); -jsval_t get_date_string( - ant_t *js, jsval_t this_val, +ant_value_t get_date_string( + ant_t *js, ant_value_t this_val, date_string_spec_t spec ); diff --git a/include/modules/dns.h b/include/modules/dns.h index 46fda18..be75137 100644 --- a/include/modules/dns.h +++ b/include/modules/dns.h @@ -3,6 +3,6 @@ #include "types.h" -jsval_t dns_library(ant_t *js); +ant_value_t dns_library(ant_t *js); #endif diff --git a/include/modules/events.h b/include/modules/events.h index 84e5b8a..57df90d 100644 --- a/include/modules/events.h +++ b/include/modules/events.h @@ -4,8 +4,8 @@ #include "types.h" void init_events_module(void); -void events_gc_update_roots(void (*op_val)(void *, jsval_t *), void *ctx); +void events_gc_update_roots(void (*op_val)(void *, ant_value_t *), void *ctx); -jsval_t events_library(ant_t *js); +ant_value_t events_library(ant_t *js); #endif \ No newline at end of file diff --git a/include/modules/ffi.h b/include/modules/ffi.h index 16cfb97..566ed7c 100644 --- a/include/modules/ffi.h +++ b/include/modules/ffi.h @@ -4,8 +4,8 @@ #include "gc.h" #include "types.h" -jsval_t ffi_library(ant_t *js); -jsval_t ffi_call_by_index(ant_t *js, unsigned int func_index, jsval_t *args, int nargs); +ant_value_t ffi_library(ant_t *js); +ant_value_t ffi_call_by_index(ant_t *js, unsigned int func_index, ant_value_t *args, int nargs); void ffi_gc_update_roots(GC_OP_VAL_ARGS); diff --git a/include/modules/fs.h b/include/modules/fs.h index 469e480..f23a3b1 100644 --- a/include/modules/fs.h +++ b/include/modules/fs.h @@ -4,8 +4,8 @@ #include "gc.h" #include "types.h" -jsval_t fs_library(ant_t *js); -jsval_t fs_promises_library(ant_t *js); +ant_value_t fs_library(ant_t *js); +ant_value_t fs_promises_library(ant_t *js); int has_pending_fs_ops(void); diff --git a/include/modules/io.h b/include/modules/io.h index 3dbce06..cc9721c 100644 --- a/include/modules/io.h +++ b/include/modules/io.h @@ -8,7 +8,7 @@ extern bool io_no_color; typedef struct { - jsoff_t *visited; + ant_offset_t *visited; int count; int capacity; } inspect_visited_t; @@ -30,23 +30,23 @@ typedef struct { void init_console_module(void); void print_value_colored(const char *str, FILE *stream); -void print_repl_value(ant_t *js, jsval_t val, FILE *stream); +void print_repl_value(ant_t *js, ant_value_t val, FILE *stream); bool print_uncaught_throw(ant_t *js); void inspect_object( - ant_t *js, jsval_t obj, + ant_t *js, ant_value_t obj, FILE *stream, int depth, inspect_visited_t *visited ); void inspect_value( - ant_t *js, jsval_t val, + ant_t *js, ant_value_t val, FILE *stream, int depth, inspect_visited_t *visited ); -jsval_t console_print( - ant_t *js, jsval_t *args, +ant_value_t console_print( + ant_t *js, ant_value_t *args, int nargs, const char *color, FILE *stream ); diff --git a/include/modules/json.h b/include/modules/json.h index 6c39bdd..a937527 100644 --- a/include/modules/json.h +++ b/include/modules/json.h @@ -6,7 +6,7 @@ void init_json_module(void); -jsval_t js_json_parse(ant_t *js, jsval_t *args, int nargs); -jsval_t js_json_stringify(ant_t *js, jsval_t *args, int nargs); +ant_value_t js_json_parse(ant_t *js, ant_value_t *args, int nargs); +ant_value_t js_json_stringify(ant_t *js, ant_value_t *args, int nargs); #endif diff --git a/include/modules/lmdb.h b/include/modules/lmdb.h index 7540240..594743c 100644 --- a/include/modules/lmdb.h +++ b/include/modules/lmdb.h @@ -13,16 +13,16 @@ typedef struct lmdb_db_ref lmdb_db_ref_t; typedef struct lmdb_txn_ref lmdb_txn_ref_t; typedef struct { - jsval_t env_ctor; - jsval_t db_ctor; - jsval_t txn_ctor; - jsval_t env_proto; - jsval_t db_proto; - jsval_t txn_proto; + ant_value_t env_ctor; + ant_value_t db_ctor; + ant_value_t txn_ctor; + ant_value_t env_proto; + ant_value_t db_proto; + ant_value_t txn_proto; bool ready; } lmdb_js_types_t; -jsval_t lmdb_library(ant_t *js); +ant_value_t lmdb_library(ant_t *js); void lmdb_gc_update_roots(GC_OP_VAL_ARGS); void cleanup_lmdb_module(void); diff --git a/include/modules/module.h b/include/modules/module.h index 0452ac5..ee4d670 100644 --- a/include/modules/module.h +++ b/include/modules/module.h @@ -3,6 +3,6 @@ #include "types.h" -jsval_t module_library(ant_t *js); +ant_value_t module_library(ant_t *js); #endif diff --git a/include/modules/napi.h b/include/modules/napi.h index 97707ab..133d071 100644 --- a/include/modules/napi.h +++ b/include/modules/napi.h @@ -26,7 +26,7 @@ #endif #endif -typedef jsval_t napi_value; +typedef ant_value_t napi_value; #define NAPI_MODULE_VERSION 1 typedef struct ant_napi_env__* napi_env; @@ -168,7 +168,7 @@ typedef struct napi_module { } napi_module; napi_env ant_napi_get_env(ant_t *js); -jsval_t napi_process_dlopen_js(ant_t *js, jsval_t *args, int nargs); -jsval_t napi_load_native_module(ant_t *js, const char *module_path, jsval_t ns); +ant_value_t napi_process_dlopen_js(ant_t *js, ant_value_t *args, int nargs); +ant_value_t napi_load_native_module(ant_t *js, const char *module_path, ant_value_t ns); #endif diff --git a/include/modules/net.h b/include/modules/net.h index c602e0e..6ee13f3 100644 --- a/include/modules/net.h +++ b/include/modules/net.h @@ -3,6 +3,6 @@ #include "types.h" -jsval_t net_library(ant_t *js); +ant_value_t net_library(ant_t *js); #endif diff --git a/include/modules/os.h b/include/modules/os.h index aff4316..c528975 100644 --- a/include/modules/os.h +++ b/include/modules/os.h @@ -3,6 +3,6 @@ #include "types.h" -jsval_t os_library(ant_t *js); +ant_value_t os_library(ant_t *js); #endif diff --git a/include/modules/path.h b/include/modules/path.h index 0f69bd0..59cc1d3 100644 --- a/include/modules/path.h +++ b/include/modules/path.h @@ -3,6 +3,6 @@ #include "types.h" -jsval_t path_library(ant_t *js); +ant_value_t path_library(ant_t *js); #endif diff --git a/include/modules/performance.h b/include/modules/performance.h index 7db886a..3a1f2b3 100644 --- a/include/modules/performance.h +++ b/include/modules/performance.h @@ -4,6 +4,6 @@ #include "types.h" void init_performance_module(void); -jsval_t perf_hooks_library(ant_t *js); +ant_value_t perf_hooks_library(ant_t *js); #endif diff --git a/include/modules/process.h b/include/modules/process.h index 15a539f..8ff6a66 100644 --- a/include/modules/process.h +++ b/include/modules/process.h @@ -5,11 +5,11 @@ void process_gc_update_roots(GC_OP_VAL_ARGS); void process_enable_keypress_events(void); -void emit_process_event(const char *event_type, jsval_t *args, int nargs); +void emit_process_event(const char *event_type, ant_value_t *args, int nargs); void init_process_module(void); bool has_active_stdin(void); -jsval_t process_library(ant_t *js); +ant_value_t process_library(ant_t *js); #endif diff --git a/include/modules/readline.h b/include/modules/readline.h index e87211c..5abfdfb 100644 --- a/include/modules/readline.h +++ b/include/modules/readline.h @@ -5,8 +5,8 @@ #include "types.h" #include -jsval_t readline_library(ant_t *js); -jsval_t readline_promises_library(ant_t *js); +ant_value_t readline_library(ant_t *js); +ant_value_t readline_promises_library(ant_t *js); bool has_active_readline_interfaces(void); void readline_gc_update_roots(GC_OP_VAL_ARGS); diff --git a/include/modules/regex.h b/include/modules/regex.h index 1adee02..8fe9022 100644 --- a/include/modules/regex.h +++ b/include/modules/regex.h @@ -7,21 +7,21 @@ void init_regex_module(void); void cleanup_regex_module(void); -void regex_gc_update_roots(jsoff_t (*weak_off)(void *ctx, jsoff_t old), GC_OP_VAL_ARGS); +void regex_gc_update_roots(ant_offset_t (*weak_off)(void *ctx, ant_offset_t old), GC_OP_VAL_ARGS); size_t js_to_pcre2_pattern(const char *src, size_t src_len, char *dst, size_t dst_size); -jsval_t builtin_regexp_symbol_split(ant_t *js, jsval_t *args, int nargs); -jsval_t builtin_regexp_symbol_match(ant_t *js, jsval_t *args, int nargs); -jsval_t builtin_regexp_symbol_replace(ant_t *js, jsval_t *args, int nargs); -jsval_t builtin_regexp_symbol_search(ant_t *js, jsval_t *args, int nargs); -jsval_t builtin_regexp_flags_getter(ant_t *js, jsval_t *args, int nargs); +ant_value_t builtin_regexp_symbol_split(ant_t *js, ant_value_t *args, int nargs); +ant_value_t builtin_regexp_symbol_match(ant_t *js, ant_value_t *args, int nargs); +ant_value_t builtin_regexp_symbol_replace(ant_t *js, ant_value_t *args, int nargs); +ant_value_t builtin_regexp_symbol_search(ant_t *js, ant_value_t *args, int nargs); +ant_value_t builtin_regexp_flags_getter(ant_t *js, ant_value_t *args, int nargs); -jsval_t is_regexp_like(ant_t *js, jsval_t value); -jsval_t reject_regexp_arg(ant_t *js, jsval_t value, const char *method_name); +ant_value_t is_regexp_like(ant_t *js, ant_value_t value); +ant_value_t reject_regexp_arg(ant_t *js, ant_value_t value, const char *method_name); -jsval_t do_regex_match_pcre2( - ant_t *js, const char *pattern_ptr, jsoff_t pattern_len, - const char *str_ptr, jsoff_t str_len, +ant_value_t do_regex_match_pcre2( + ant_t *js, const char *pattern_ptr, ant_offset_t pattern_len, + const char *str_ptr, ant_offset_t str_len, bool global_flag, bool ignore_case, bool multiline ); diff --git a/include/modules/shell.h b/include/modules/shell.h index 3679045..03e319a 100644 --- a/include/modules/shell.h +++ b/include/modules/shell.h @@ -3,6 +3,6 @@ #include "types.h" -jsval_t shell_library(ant_t *js); +ant_value_t shell_library(ant_t *js); #endif diff --git a/include/modules/symbol.h b/include/modules/symbol.h index 88d78e7..e84825f 100644 --- a/include/modules/symbol.h +++ b/include/modules/symbol.h @@ -5,15 +5,15 @@ #include "internal.h" // IWYU pragma: keep void init_symbol_module(void); -void js_define_species_getter(ant_t *js, jsval_t ctor); +void js_define_species_getter(ant_t *js, ant_value_t ctor); void symbol_gc_update_roots(GC_OP_VAL_ARGS); -jsval_t sym_lookup_by_id(uint32_t id); -void sym_gc_update_all(void (*op_val)(void *, jsval_t *), void *ctx); +ant_value_t sym_lookup_by_id(uint32_t id); +void sym_gc_update_all(void (*op_val)(void *, ant_value_t *), void *ctx); -jsval_t maybe_call_symbol_method( - ant_t *js, jsval_t target, jsval_t sym, - jsval_t this_arg, jsval_t *args, +ant_value_t maybe_call_symbol_method( + ant_t *js, ant_value_t target, ant_value_t sym, + ant_value_t this_arg, ant_value_t *args, int nargs, bool *called ); @@ -32,11 +32,11 @@ jsval_t maybe_call_symbol_method( X(species, "Symbol.species") \ X(unscopables, "Symbol.unscopables") -#define DECL_GET_SYM(name, _desc) jsval_t get_##name##_sym(void); +#define DECL_GET_SYM(name, _desc) ant_value_t get_##name##_sym(void); WELLKNOWN_SYMBOLS(DECL_GET_SYM) #undef DECL_GET_SYM -static inline jsval_t sym_this_cb(ant_t *js, jsval_t *args, int nargs) { +static inline ant_value_t sym_this_cb(ant_t *js, ant_value_t *args, int nargs) { return js->this_val; } diff --git a/include/modules/timer.h b/include/modules/timer.h index 9d9f593..5324855 100644 --- a/include/modules/timer.h +++ b/include/modules/timer.h @@ -7,7 +7,7 @@ void init_timer_module(void); void process_microtasks(ant_t *js); void process_immediates(ant_t *js); -void queue_microtask(ant_t *js, jsval_t callback); +void queue_microtask(ant_t *js, ant_value_t callback); void queue_promise_trigger(uint32_t promise_id); void timer_gc_update_roots(GC_OP_VAL_ARGS); diff --git a/include/modules/tty.h b/include/modules/tty.h index fd0ecdd..d6e6d7e 100644 --- a/include/modules/tty.h +++ b/include/modules/tty.h @@ -4,6 +4,6 @@ #include "types.h" void init_tty_module(void); -jsval_t tty_library(ant_t *js); +ant_value_t tty_library(ant_t *js); #endif diff --git a/include/modules/url.h b/include/modules/url.h index 4185432..6ad35e2 100644 --- a/include/modules/url.h +++ b/include/modules/url.h @@ -4,6 +4,6 @@ #include "types.h" void init_url_module(void); -jsval_t url_library(ant_t *js); +ant_value_t url_library(ant_t *js); #endif diff --git a/include/modules/util.h b/include/modules/util.h index 7cab6c2..0664ae7 100644 --- a/include/modules/util.h +++ b/include/modules/util.h @@ -3,6 +3,6 @@ #include "types.h" -jsval_t util_library(ant_t *js); +ant_value_t util_library(ant_t *js); #endif diff --git a/include/modules/worker_threads.h b/include/modules/worker_threads.h index 98455f8..8334b4c 100644 --- a/include/modules/worker_threads.h +++ b/include/modules/worker_threads.h @@ -3,6 +3,6 @@ #include "types.h" -jsval_t worker_threads_library(ant_t *js); +ant_value_t worker_threads_library(ant_t *js); #endif diff --git a/include/roots.h b/include/roots.h index af2461a..5c9fec7 100644 --- a/include/roots.h +++ b/include/roots.h @@ -3,10 +3,10 @@ #include "types.h" -jshdl_t js_root(ant_t *js, jsval_t val); -jsval_t js_deref(ant_t *js, jshdl_t h); +ant_handle_t js_root(ant_t *js, ant_value_t val); +ant_value_t js_deref(ant_t *js, ant_handle_t h); -void js_unroot(ant_t *js, jshdl_t h); -void js_root_update(ant_t *js, jshdl_t h, jsval_t val); +void js_unroot(ant_t *js, ant_handle_t h); +void js_root_update(ant_t *js, ant_handle_t h, ant_value_t val); #endif \ No newline at end of file diff --git a/include/runtime.h b/include/runtime.h index 720dbd1..d298bff 100644 --- a/include/runtime.h +++ b/include/runtime.h @@ -10,7 +10,7 @@ struct arg_file; struct ant_runtime { ant_t *js; char **argv; - jsval_t ant_obj; + ant_value_t ant_obj; int argc; int pid; unsigned int flags; diff --git a/include/silver/ast.h b/include/silver/ast.h index 890be0c..79b5929 100644 --- a/include/silver/ast.h +++ b/include/silver/ast.h @@ -156,6 +156,6 @@ bool sv_ast_can_be_expression_statement(const sv_ast_t *node); bool ast_references_arguments(const sv_ast_t *node); sv_ast_t *sv_ast_new(sv_node_type_t type); -sv_ast_t *sv_parse(ant_t *js, const char *code, jsoff_t clen, bool strict); +sv_ast_t *sv_parse(ant_t *js, const char *code, ant_offset_t clen, bool strict); #endif diff --git a/include/silver/compiler.h b/include/silver/compiler.h index 31d1ad1..3cbc36d 100644 --- a/include/silver/compiler.h +++ b/include/silver/compiler.h @@ -14,7 +14,7 @@ typedef enum { sv_func_t *sv_compile( ant_t *js, sv_ast_t *program, sv_compile_mode_t mode, - const char *source, jsoff_t source_len + const char *source, ant_offset_t source_len ); sv_func_t *sv_compile_function( diff --git a/include/silver/engine.h b/include/silver/engine.h index c3be8c9..b6816d0 100644 --- a/include/silver/engine.h +++ b/include/silver/engine.h @@ -47,7 +47,7 @@ struct sv_func { uint8_t *code; int code_len; - jsval_t *constants; + ant_value_t *constants; int const_count; sv_atom_t *atoms; @@ -100,7 +100,7 @@ typedef enum { typedef struct { sv_completion_kind_t kind; - jsval_t value; + ant_value_t value; } sv_completion_t; typedef struct @@ -108,14 +108,14 @@ typedef struct typedef struct { uint8_t *ip; - jsval_t *bp; - jsval_t *lp; + ant_value_t *bp; + ant_value_t *lp; sv_func_t *func; - jsval_t callee; - jsval_t this; - jsval_t new_target; - jsval_t super_val; + ant_value_t callee; + ant_value_t this; + ant_value_t new_target; + ant_value_t super_val; int prev_sp; int handler_base; @@ -125,7 +125,7 @@ typedef struct { sv_completion_t completion; sv_upvalue_t **upvalues; int upvalue_count; - jsval_t with_obj; + ant_value_t with_obj; } sv_frame_t; typedef enum { @@ -140,8 +140,8 @@ typedef struct { } sv_handler_t; struct sv_upvalue { - jsval_t *location; - jsval_t closed; + ant_value_t *location; + ant_value_t closed; struct sv_upvalue *next; uint32_t gc_epoch; }; @@ -152,41 +152,41 @@ struct sv_upvalue { typedef struct sv_closure { sv_func_t *func; sv_upvalue_t **upvalues; - jsval_t bound_this; - jsval_t func_obj; + ant_value_t bound_this; + ant_value_t func_obj; uint32_t gc_epoch; uint8_t call_flags; } sv_closure_t; -static inline sv_closure_t *js_func_closure(jsval_t func) { +static inline sv_closure_t *js_func_closure(ant_value_t func) { return (sv_closure_t *)(uintptr_t)vdata(func); } -static inline jsval_t js_func_obj(jsval_t func) { +static inline ant_value_t js_func_obj(ant_value_t func) { return js_func_closure(func)->func_obj; } -static inline jsval_t js_as_obj(jsval_t v) { +static inline ant_value_t js_as_obj(ant_value_t v) { uint8_t t = vtype(v); if (t == T_OBJ) return v; if (t == T_FUNC) return js_func_obj(v); return mkval(T_OBJ, vdata(v)); } -jsval_t sv_execute_closure_entry( +ant_value_t sv_execute_closure_entry( sv_vm_t *vm,sv_closure_t *closure, - jsval_t callee_func, jsval_t super_val, - jsval_t this_val, jsval_t *args, - int argc, jsval_t *out_this + ant_value_t callee_func, ant_value_t super_val, + ant_value_t this_val, ant_value_t *args, + int argc, ant_value_t *out_this ); #ifdef ANT_JIT typedef struct { bool active; int bc_offset; - jsval_t *locals; + ant_value_t *locals; int n_locals; - jsval_t *lp; + ant_value_t *lp; } sv_jit_osr_t; #endif @@ -200,7 +200,7 @@ typedef struct { struct sv_vm { ant_t *js; - jsval_t *stack; + ant_value_t *stack; int sp; int stack_size; @@ -216,9 +216,9 @@ struct sv_vm { struct { bool active; int64_t ip_offset; - jsval_t *locals; + ant_value_t *locals; int64_t n_locals; - jsval_t *vstack; + ant_value_t *vstack; int64_t vstack_sp; } jit_resume; @@ -256,13 +256,13 @@ static inline bool sv_frame_is_strict(const sv_frame_t *frame) { return frame && frame->func && frame->func->is_strict; } -static inline bool sv_is_nullish_this(jsval_t v) { +static inline bool sv_is_nullish_this(ant_value_t v) { return vtype(v) == T_UNDEF || vtype(v) == T_NULL || (vtype(v) == T_OBJ && vdata(v) == 0); } -static inline jsval_t sv_normalize_this_for_frame(ant_t *js, sv_func_t *func, jsval_t this_val) { +static inline ant_value_t sv_normalize_this_for_frame(ant_t *js, sv_func_t *func, ant_value_t this_val) { if (!func || func->is_arrow) return this_val; if (func->is_strict) return sv_is_nullish_this(this_val) ? js_mkundef() : this_val; return sv_is_nullish_this(this_val) ? js->global : this_val; @@ -276,12 +276,12 @@ static inline bool sv_vm_is_strict(const sv_vm_t *vm) { return false; } -static inline jsval_t sv_vm_get_new_target(const sv_vm_t *vm, ant_t *js) { +static inline ant_value_t sv_vm_get_new_target(const sv_vm_t *vm, ant_t *js) { if (vm && vm->fp >= 0) return vm->frames[vm->fp].new_target; return js->new_target; } -static inline jsval_t sv_vm_get_super_val(const sv_vm_t *vm) { +static inline ant_value_t sv_vm_get_super_val(const sv_vm_t *vm) { if (vm && vm->fp >= 0) return vm->frames[vm->fp].super_val; return js_mkundef(); } @@ -291,19 +291,19 @@ static inline int sv_frame_arg_slots(const sv_frame_t *frame) { return frame->argc > frame->func->param_count ? frame->argc : frame->func->param_count; } -static inline jsval_t sv_frame_get_arg_value(const sv_frame_t *frame, uint16_t idx) { +static inline ant_value_t sv_frame_get_arg_value(const sv_frame_t *frame, uint16_t idx) { int arg_slots = sv_frame_arg_slots(frame); if (!frame || !frame->bp || (int)idx >= arg_slots) return js_mkundef(); return frame->bp[idx]; } -static inline void sv_frame_set_arg_value(sv_frame_t *frame, uint16_t idx, jsval_t val) { +static inline void sv_frame_set_arg_value(sv_frame_t *frame, uint16_t idx, ant_value_t val) { int arg_slots = sv_frame_arg_slots(frame); if (!frame || !frame->bp || (int)idx >= arg_slots) return; frame->bp[idx] = val; } -static inline jsval_t *sv_frame_slot_ptr(sv_frame_t *frame, uint16_t slot_idx) { +static inline ant_value_t *sv_frame_slot_ptr(sv_frame_t *frame, uint16_t slot_idx) { if (!frame || !frame->func) return NULL; int param_count = frame->func->param_count; if ((int)slot_idx < param_count) { @@ -315,43 +315,43 @@ static inline jsval_t *sv_frame_slot_ptr(sv_frame_t *frame, uint16_t slot_idx) { return &frame->lp[slot_idx - param_count]; } -static inline jsval_t sv_vm_call( - sv_vm_t *vm, ant_t *js, jsval_t func, - jsval_t this_val, jsval_t *args, int argc, - jsval_t *out_this, bool is_construct_call +static inline ant_value_t sv_vm_call( + sv_vm_t *vm, ant_t *js, ant_value_t func, + ant_value_t this_val, ant_value_t *args, int argc, + ant_value_t *out_this, bool is_construct_call ); typedef struct { - jsval_t this_val; - jsval_t super_val; - jsval_t *args; + ant_value_t this_val; + ant_value_t super_val; + ant_value_t *args; int argc; - jsval_t *alloc; + ant_value_t *alloc; } sv_call_ctx_t; -static inline jsval_t sv_call_cfunc( - ant_t *js, jsval_t func, - jsval_t this_val, jsval_t *args, int argc +static inline ant_value_t sv_call_cfunc( + ant_t *js, ant_value_t func, + ant_value_t this_val, ant_value_t *args, int argc ) { js->this_val = this_val; return js_as_cfunc(func)(js, args, argc); } -static inline jsval_t sv_call_resolve_bound(ant_t *js, jsval_t func_obj, sv_call_ctx_t *ctx) { - jsval_t bound_this = js_get_slot(js, func_obj, SLOT_BOUND_THIS); +static inline ant_value_t sv_call_resolve_bound(ant_t *js, ant_value_t func_obj, sv_call_ctx_t *ctx) { + ant_value_t bound_this = js_get_slot(js, func_obj, SLOT_BOUND_THIS); if (js_get_slot(js, func_obj, SLOT_ARROW) == js_true) { ctx->this_val = bound_this; } else if (vtype(bound_this) != T_UNDEF) ctx->this_val = bound_this; - jsval_t bound_arr = js_get_slot(js, func_obj, SLOT_BOUND_ARGS); + ant_value_t bound_arr = js_get_slot(js, func_obj, SLOT_BOUND_ARGS); if (vtype(bound_arr) == T_ARR) { int bound_argc = (int)js_arr_len(js, bound_arr); if (bound_argc > 0) { int total = bound_argc + ctx->argc; - jsval_t *combined = malloc(sizeof(jsval_t) * (size_t)total); + ant_value_t *combined = malloc(sizeof(ant_value_t) * (size_t)total); if (!combined) return js_mkerr(js, "out of memory"); for (int i = 0; i < bound_argc; i++) - combined[i] = js_arr_get(js, bound_arr, (jsoff_t)i); + combined[i] = js_arr_get(js, bound_arr, (ant_offset_t)i); for (int i = 0; i < ctx->argc; i++) combined[bound_argc + i] = ctx->args[i]; ctx->args = combined; @@ -360,7 +360,7 @@ static inline jsval_t sv_call_resolve_bound(ant_t *js, jsval_t func_obj, sv_call } } - jsval_t func_super = js_get_slot(js, func_obj, SLOT_SUPER); + ant_value_t func_super = js_get_slot(js, func_obj, SLOT_SUPER); if (vtype(func_super) != T_UNDEF) ctx->super_val = func_super; return js_mkundef(); @@ -370,9 +370,9 @@ static inline void sv_call_cleanup(ant_t *js, sv_call_ctx_t *ctx) { if (ctx->alloc) { free(ctx->alloc); ctx->alloc = NULL; } } -static inline jsval_t sv_call_default_ctor( - sv_vm_t *vm, ant_t *js, jsval_t func_obj, - sv_call_ctx_t *ctx, jsval_t *out_this +static inline ant_value_t sv_call_default_ctor( + sv_vm_t *vm, ant_t *js, ant_value_t func_obj, + sv_call_ctx_t *ctx, ant_value_t *out_this ) { if (vtype(js->new_target) == T_UNDEF) { sv_call_cleanup(js, ctx); @@ -382,11 +382,11 @@ static inline jsval_t sv_call_default_ctor( ); } - jsval_t super_ctor = js_get_slot(js, func_obj, SLOT_SUPER); + ant_value_t super_ctor = js_get_slot(js, func_obj, SLOT_SUPER); uint8_t st = vtype(super_ctor); if (st == T_FUNC || st == T_CFUNC) { - jsval_t super_this = ctx->this_val; - jsval_t result = sv_vm_call( + ant_value_t super_this = ctx->this_val; + ant_value_t result = sv_vm_call( vm, js, super_ctor, ctx->this_val, ctx->args, ctx->argc, &super_this, true ); @@ -399,17 +399,17 @@ static inline jsval_t sv_call_default_ctor( return js_mkundef(); } -jsval_t sv_call_async_closure_dispatch( +ant_value_t sv_call_async_closure_dispatch( sv_vm_t *vm, ant_t *js, sv_closure_t *closure, - jsval_t callee_func, jsval_t super_val, - jsval_t this_val, jsval_t *args, int argc + ant_value_t callee_func, ant_value_t super_val, + ant_value_t this_val, ant_value_t *args, int argc ); -static inline jsval_t sv_call_async_closure( +static inline ant_value_t sv_call_async_closure( sv_vm_t *vm, ant_t *js, sv_closure_t *closure, - jsval_t callee_func, sv_call_ctx_t *ctx + ant_value_t callee_func, sv_call_ctx_t *ctx ) { - jsval_t result = sv_call_async_closure_dispatch( + ant_value_t result = sv_call_async_closure_dispatch( vm, js, closure, callee_func, ctx->super_val, ctx->this_val, ctx->args, ctx->argc ); @@ -417,11 +417,11 @@ static inline jsval_t sv_call_async_closure( return result; } -static inline jsval_t sv_call_closure( +static inline ant_value_t sv_call_closure( sv_vm_t *vm, ant_t *js, sv_closure_t *closure, - jsval_t callee_func, sv_call_ctx_t *ctx, jsval_t *out_this + ant_value_t callee_func, sv_call_ctx_t *ctx, ant_value_t *out_this ) { - jsval_t result = sv_execute_closure_entry( + ant_value_t result = sv_execute_closure_entry( vm, closure, callee_func, ctx->super_val, ctx->this_val, ctx->args, ctx->argc, out_this ); @@ -444,10 +444,10 @@ static inline jsval_t sv_call_closure( #define SV_JIT_BAILOUT \ (NANBOX_PREFIX \ - | ((jsval_t)T_SENTINEL << NANBOX_TYPE_SHIFT) \ + | ((ant_value_t)T_SENTINEL << NANBOX_TYPE_SHIFT) \ | SV_JIT_MAGIC) -static inline bool sv_is_jit_bailout(jsval_t v) { +static inline bool sv_is_jit_bailout(ant_value_t v) { return v == SV_JIT_BAILOUT; } @@ -457,22 +457,22 @@ static inline void sv_jit_on_bailout(sv_func_t *fn) { fn->call_count = SV_JIT_THRESHOLD - SV_JIT_RECOMPILE_DELAY; } -typedef jsval_t (*sv_jit_func_t) - (sv_vm_t *, jsval_t, jsval_t *, int, sv_closure_t *); +typedef ant_value_t (*sv_jit_func_t) + (sv_vm_t *, ant_value_t, ant_value_t *, int, sv_closure_t *); -jsval_t sv_jit_try_compile_and_call(sv_vm_t *vm, ant_t *js, - sv_closure_t *closure, jsval_t callee_func, - sv_call_ctx_t *ctx, jsval_t *out_this +ant_value_t sv_jit_try_compile_and_call(sv_vm_t *vm, ant_t *js, + sv_closure_t *closure, ant_value_t callee_func, + sv_call_ctx_t *ctx, ant_value_t *out_this ); -static inline uint8_t sv_tfb_classify(jsval_t v) { +static inline uint8_t sv_tfb_classify(ant_value_t v) { if (vtype(v) == T_NUM) return SV_TFB_NUM; if (vtype(v) == T_STR) return SV_TFB_STR; if (vtype(v) == T_BOOL) return SV_TFB_BOOL; return SV_TFB_OTHER; } -static inline void sv_tfb_record2(sv_func_t *func, uint8_t *ip, jsval_t l, jsval_t r) { +static inline void sv_tfb_record2(sv_func_t *func, uint8_t *ip, ant_value_t l, ant_value_t r) { if (func->type_feedback) { int off = (int)(ip - func->code); uint8_t old = func->type_feedback[off]; @@ -480,7 +480,7 @@ if (func->type_feedback) { if (neu != old) { func->type_feedback[off] = neu; func->tfb_version++; } }} -static inline void sv_tfb_record1(sv_func_t *func, uint8_t *ip, jsval_t v) { +static inline void sv_tfb_record1(sv_func_t *func, uint8_t *ip, ant_value_t v) { if (func->type_feedback) { int off = (int)(ip - func->code); uint8_t old = func->type_feedback[off]; @@ -494,9 +494,9 @@ static inline void sv_tfb_ensure(sv_func_t *fn) { } #endif -static inline jsval_t sv_call_resolve_closure( +static inline ant_value_t sv_call_resolve_closure( sv_vm_t *vm, ant_t *js, sv_closure_t *closure, - jsval_t callee_func, sv_call_ctx_t *ctx, jsval_t *out_this + ant_value_t callee_func, sv_call_ctx_t *ctx, ant_value_t *out_this ) { if (closure->func->is_async) return sv_call_async_closure(vm, js, closure, callee_func, ctx); @@ -504,7 +504,7 @@ static inline jsval_t sv_call_resolve_closure( if (!closure->func->is_generator) { sv_func_t *fn = closure->func; if (fn->jit_code) { - jsval_t result = ((sv_jit_func_t)fn->jit_code)(vm, ctx->this_val, ctx->args, ctx->argc, closure); + ant_value_t result = ((sv_jit_func_t)fn->jit_code)(vm, ctx->this_val, ctx->args, ctx->argc, closure); if (sv_is_jit_bailout(result)) { sv_jit_on_bailout(fn); } else { sv_call_cleanup(js, ctx); return result; } @@ -514,7 +514,7 @@ static inline jsval_t sv_call_resolve_closure( if (__builtin_expect(cc == SV_TFB_ALLOC_THRESHOLD, 0)) sv_tfb_ensure(fn); if (cc > SV_JIT_THRESHOLD) { - jsval_t result = sv_jit_try_compile_and_call(vm, js, closure, callee_func, ctx, out_this); + ant_value_t result = sv_jit_try_compile_and_call(vm, js, closure, callee_func, ctx, out_this); if (result != SV_JIT_RETRY_INTERP) return result; } } @@ -523,10 +523,10 @@ static inline jsval_t sv_call_resolve_closure( return sv_call_closure(vm, js, closure, callee_func, ctx, out_this); } -static inline jsval_t sv_vm_call( - sv_vm_t *vm, ant_t *js, jsval_t func, - jsval_t this_val, jsval_t *args, int argc, - jsval_t *out_this, bool is_construct_call +static inline ant_value_t sv_vm_call( + sv_vm_t *vm, ant_t *js, ant_value_t func, + ant_value_t this_val, ant_value_t *args, int argc, + ant_value_t *out_this, bool is_construct_call ) { if (!is_construct_call) js->new_target = js_mkundef(); if (out_this) *out_this = this_val; @@ -535,7 +535,7 @@ static inline jsval_t sv_vm_call( return js_proxy_apply(js, func, this_val, args, argc); if (vtype(func) == T_CFUNC) { - jsval_t cfunc_this = sv_is_nullish_this(this_val) ? js->global : this_val; + ant_value_t cfunc_this = sv_is_nullish_this(this_val) ? js->global : this_val; return sv_call_cfunc(js, func, cfunc_this, args, argc); } @@ -543,14 +543,14 @@ static inline jsval_t sv_vm_call( return sv_call_native(js, func, this_val, args, argc); sv_closure_t *closure = js_func_closure(func); - jsval_t func_obj = closure->func_obj; + ant_value_t func_obj = closure->func_obj; sv_call_ctx_t ctx = { .this_val = this_val, .super_val = js_mkundef(), .args = args, .argc = argc, .alloc = NULL, }; - jsval_t err = sv_call_resolve_bound(js, func_obj, &ctx); + ant_value_t err = sv_call_resolve_bound(js, func_obj, &ctx); if (is_err(err)) return err; if (is_construct_call) ctx.this_val = this_val; @@ -562,7 +562,7 @@ static inline jsval_t sv_vm_call( if (closure->func != NULL) return sv_call_resolve_closure(vm, js, closure, func, &ctx, out_this); - jsval_t result = sv_call_native(js, func, ctx.this_val, ctx.args, ctx.argc); + ant_value_t result = sv_call_native(js, func, ctx.this_val, ctx.args, ctx.argc); sv_call_cleanup(js, &ctx); return result; diff --git a/include/silver/glue.h b/include/silver/glue.h index 3c1b039..7d327a6 100644 --- a/include/silver/glue.h +++ b/include/silver/glue.h @@ -4,139 +4,139 @@ #ifdef ANT_JIT #include "silver/engine.h" -double jit_helper_tod(jsval_t v); -uint64_t jit_helper_vtype(jsval_t v); -int64_t jit_helper_is_truthy(ant_t *js, jsval_t v); +double jit_helper_tod(ant_value_t v); +uint64_t jit_helper_vtype(ant_value_t v); +int64_t jit_helper_is_truthy(ant_t *js, ant_value_t v); -jsval_t jit_helper_tov(double d); -jsval_t jit_helper_mkbool(int b); +ant_value_t jit_helper_tov(double d); +ant_value_t jit_helper_mkbool(int b); bool jit_helper_stack_overflow(ant_t *js); -sv_closure_t *jit_helper_get_closure(jsval_t v); - -jsval_t jit_helper_add(sv_vm_t *vm, ant_t *js, jsval_t l, jsval_t r); -jsval_t jit_helper_sub(sv_vm_t *vm, ant_t *js, jsval_t l, jsval_t r); -jsval_t jit_helper_mul(sv_vm_t *vm, ant_t *js, jsval_t l, jsval_t r); -jsval_t jit_helper_div(sv_vm_t *vm, ant_t *js, jsval_t l, jsval_t r); -jsval_t jit_helper_mod(sv_vm_t *vm, ant_t *js, jsval_t l, jsval_t r); - -jsval_t jit_helper_object(sv_vm_t *vm, ant_t *js); -jsval_t jit_helper_get_length(sv_vm_t *vm, ant_t *js, jsval_t obj); -jsval_t jit_helper_catch_value(sv_vm_t *vm, ant_t *js, jsval_t err); -jsval_t jit_helper_throw(sv_vm_t *vm, ant_t *js, jsval_t val); - -jsval_t jit_helper_lt(sv_vm_t *vm, ant_t *js, jsval_t l, jsval_t r); -jsval_t jit_helper_le(sv_vm_t *vm, ant_t *js, jsval_t l, jsval_t r); -jsval_t jit_helper_seq(sv_vm_t *vm, ant_t *js, jsval_t l, jsval_t r); -jsval_t jit_helper_eq(sv_vm_t *vm, ant_t *js, jsval_t l, jsval_t r); -jsval_t jit_helper_in(sv_vm_t *vm, ant_t *js, jsval_t l, jsval_t r); -jsval_t jit_helper_gt(sv_vm_t *vm, ant_t *js, jsval_t l, jsval_t r); -jsval_t jit_helper_ge(sv_vm_t *vm, ant_t *js, jsval_t l, jsval_t r); -jsval_t jit_helper_ne(sv_vm_t *vm, ant_t *js, jsval_t l, jsval_t r); -jsval_t jit_helper_sne(sv_vm_t *vm, ant_t *js, jsval_t l, jsval_t r); - -jsval_t jit_helper_band(sv_vm_t *vm, ant_t *js, jsval_t l, jsval_t r); -jsval_t jit_helper_bor(sv_vm_t *vm, ant_t *js, jsval_t l, jsval_t r); -jsval_t jit_helper_bxor(sv_vm_t *vm, ant_t *js, jsval_t l, jsval_t r); -jsval_t jit_helper_bnot(sv_vm_t *vm, ant_t *js, jsval_t v); -jsval_t jit_helper_shl(sv_vm_t *vm, ant_t *js, jsval_t l, jsval_t r); -jsval_t jit_helper_shr(sv_vm_t *vm, ant_t *js, jsval_t l, jsval_t r); -jsval_t jit_helper_ushr(sv_vm_t *vm, ant_t *js, jsval_t l, jsval_t r); -jsval_t jit_helper_not(sv_vm_t *vm, ant_t *js, jsval_t v); - -jsval_t jit_helper_get_global(ant_t *js, const char *str, uint32_t len); -jsval_t jit_helper_to_propkey(sv_vm_t *vm, ant_t *js, jsval_t v); -jsval_t jit_helper_stack_overflow_error(sv_vm_t *vm, ant_t *js); -jsval_t jit_helper_instanceof(sv_vm_t *vm, ant_t *js, jsval_t l, jsval_t r); -jsval_t jit_helper_delete(sv_vm_t *vm, ant_t *js, jsval_t obj, jsval_t key); -jsval_t jit_helper_typeof(sv_vm_t *vm, ant_t *js, jsval_t v); - -jsval_t jit_helper_call( +sv_closure_t *jit_helper_get_closure(ant_value_t v); + +ant_value_t jit_helper_add(sv_vm_t *vm, ant_t *js, ant_value_t l, ant_value_t r); +ant_value_t jit_helper_sub(sv_vm_t *vm, ant_t *js, ant_value_t l, ant_value_t r); +ant_value_t jit_helper_mul(sv_vm_t *vm, ant_t *js, ant_value_t l, ant_value_t r); +ant_value_t jit_helper_div(sv_vm_t *vm, ant_t *js, ant_value_t l, ant_value_t r); +ant_value_t jit_helper_mod(sv_vm_t *vm, ant_t *js, ant_value_t l, ant_value_t r); + +ant_value_t jit_helper_object(sv_vm_t *vm, ant_t *js); +ant_value_t jit_helper_get_length(sv_vm_t *vm, ant_t *js, ant_value_t obj); +ant_value_t jit_helper_catch_value(sv_vm_t *vm, ant_t *js, ant_value_t err); +ant_value_t jit_helper_throw(sv_vm_t *vm, ant_t *js, ant_value_t val); + +ant_value_t jit_helper_lt(sv_vm_t *vm, ant_t *js, ant_value_t l, ant_value_t r); +ant_value_t jit_helper_le(sv_vm_t *vm, ant_t *js, ant_value_t l, ant_value_t r); +ant_value_t jit_helper_seq(sv_vm_t *vm, ant_t *js, ant_value_t l, ant_value_t r); +ant_value_t jit_helper_eq(sv_vm_t *vm, ant_t *js, ant_value_t l, ant_value_t r); +ant_value_t jit_helper_in(sv_vm_t *vm, ant_t *js, ant_value_t l, ant_value_t r); +ant_value_t jit_helper_gt(sv_vm_t *vm, ant_t *js, ant_value_t l, ant_value_t r); +ant_value_t jit_helper_ge(sv_vm_t *vm, ant_t *js, ant_value_t l, ant_value_t r); +ant_value_t jit_helper_ne(sv_vm_t *vm, ant_t *js, ant_value_t l, ant_value_t r); +ant_value_t jit_helper_sne(sv_vm_t *vm, ant_t *js, ant_value_t l, ant_value_t r); + +ant_value_t jit_helper_band(sv_vm_t *vm, ant_t *js, ant_value_t l, ant_value_t r); +ant_value_t jit_helper_bor(sv_vm_t *vm, ant_t *js, ant_value_t l, ant_value_t r); +ant_value_t jit_helper_bxor(sv_vm_t *vm, ant_t *js, ant_value_t l, ant_value_t r); +ant_value_t jit_helper_bnot(sv_vm_t *vm, ant_t *js, ant_value_t v); +ant_value_t jit_helper_shl(sv_vm_t *vm, ant_t *js, ant_value_t l, ant_value_t r); +ant_value_t jit_helper_shr(sv_vm_t *vm, ant_t *js, ant_value_t l, ant_value_t r); +ant_value_t jit_helper_ushr(sv_vm_t *vm, ant_t *js, ant_value_t l, ant_value_t r); +ant_value_t jit_helper_not(sv_vm_t *vm, ant_t *js, ant_value_t v); + +ant_value_t jit_helper_get_global(ant_t *js, const char *str, uint32_t len); +ant_value_t jit_helper_to_propkey(sv_vm_t *vm, ant_t *js, ant_value_t v); +ant_value_t jit_helper_stack_overflow_error(sv_vm_t *vm, ant_t *js); +ant_value_t jit_helper_instanceof(sv_vm_t *vm, ant_t *js, ant_value_t l, ant_value_t r); +ant_value_t jit_helper_delete(sv_vm_t *vm, ant_t *js, ant_value_t obj, ant_value_t key); +ant_value_t jit_helper_typeof(sv_vm_t *vm, ant_t *js, ant_value_t v); + +ant_value_t jit_helper_call( sv_vm_t *vm, ant_t *js, - jsval_t func, jsval_t this_val, - jsval_t *args, int argc + ant_value_t func, ant_value_t this_val, + ant_value_t *args, int argc ); -jsval_t jit_helper_get_field( - sv_vm_t *vm, ant_t *js, jsval_t obj, +ant_value_t jit_helper_get_field( + sv_vm_t *vm, ant_t *js, ant_value_t obj, const char *str, uint32_t len, sv_func_t *func, int32_t bc_off ); -jsval_t jit_helper_closure( +ant_value_t jit_helper_closure( sv_vm_t *vm, ant_t *js, - sv_closure_t *parent_closure, jsval_t this_val, - jsval_t *args, int argc, - uint32_t const_idx, jsval_t *locals, int n_locals + sv_closure_t *parent_closure, ant_value_t this_val, + ant_value_t *args, int argc, + uint32_t const_idx, ant_value_t *locals, int n_locals ); -jsval_t jit_helper_bailout_resume( +ant_value_t jit_helper_bailout_resume( sv_vm_t *vm, sv_closure_t *closure, - jsval_t this_val, jsval_t *args, int argc, - jsval_t *vstack, int64_t vstack_sp, - jsval_t *locals, int64_t n_locals, + ant_value_t this_val, ant_value_t *args, int argc, + ant_value_t *vstack, int64_t vstack_sp, + ant_value_t *locals, int64_t n_locals, int64_t bc_offset ); void jit_helper_close_upval( sv_vm_t *vm, uint16_t slot_idx, - jsval_t *locals, int n_locals + ant_value_t *locals, int n_locals ); void jit_helper_define_field( - sv_vm_t *vm, ant_t *js, jsval_t obj, - jsval_t val, const char *str, uint32_t len + sv_vm_t *vm, ant_t *js, ant_value_t obj, + ant_value_t val, const char *str, uint32_t len ); void jit_helper_set_name( - sv_vm_t *vm, ant_t *js, jsval_t fn, + sv_vm_t *vm, ant_t *js, ant_value_t fn, const char *str, uint32_t len ); -jsval_t jit_helper_put_field( - sv_vm_t *vm, ant_t *js, jsval_t obj, - jsval_t val, const char *str, uint32_t len +ant_value_t jit_helper_put_field( + sv_vm_t *vm, ant_t *js, ant_value_t obj, + ant_value_t val, const char *str, uint32_t len ); -jsval_t jit_helper_get_elem( +ant_value_t jit_helper_get_elem( sv_vm_t *vm, ant_t *js, - jsval_t obj, jsval_t key, sv_func_t *func, int32_t bc_off + ant_value_t obj, ant_value_t key, sv_func_t *func, int32_t bc_off ); -jsval_t jit_helper_put_elem( +ant_value_t jit_helper_put_elem( sv_vm_t *vm, ant_t *js, - jsval_t obj, jsval_t key, jsval_t val + ant_value_t obj, ant_value_t key, ant_value_t val ); -jsval_t jit_helper_put_global( - sv_vm_t *vm, ant_t *js, jsval_t val, +ant_value_t jit_helper_put_global( + sv_vm_t *vm, ant_t *js, ant_value_t val, const char *str, uint32_t len, int is_strict ); -jsval_t jit_helper_array( +ant_value_t jit_helper_array( sv_vm_t *vm, ant_t *js, - jsval_t *elements, int count + ant_value_t *elements, int count ); -jsval_t jit_helper_throw_error( +ant_value_t jit_helper_throw_error( sv_vm_t *vm, ant_t *js, const char *str, uint32_t len, int err_type ); -jsval_t jit_helper_get_elem2( +ant_value_t jit_helper_get_elem2( sv_vm_t *vm, ant_t *js, - jsval_t obj, jsval_t key + ant_value_t obj, ant_value_t key ); -jsval_t jit_helper_set_proto( +ant_value_t jit_helper_set_proto( sv_vm_t *vm, ant_t *js, - jsval_t obj, jsval_t proto + ant_value_t obj, ant_value_t proto ); -jsval_t jit_helper_new( +ant_value_t jit_helper_new( sv_vm_t *vm, ant_t *js, - jsval_t func, jsval_t new_target, - jsval_t *args, int argc + ant_value_t func, ant_value_t new_target, + ant_value_t *args, int argc ); #endif diff --git a/include/silver/lexer.h b/include/silver/lexer.h index ed73b13..f9f8003 100644 --- a/include/silver/lexer.h +++ b/include/silver/lexer.h @@ -5,10 +5,10 @@ #include "types.h" typedef struct { - jsoff_t pos; - jsoff_t toff; - jsoff_t tlen; - jsval_t tval; + ant_offset_t pos; + ant_offset_t toff; + ant_offset_t tlen; + ant_value_t tval; uint8_t tok; uint8_t consumed; bool had_newline; @@ -17,7 +17,7 @@ typedef struct { typedef struct { ant_t *js; const char *code; - jsoff_t clen; + ant_offset_t clen; bool strict; sv_lexer_state_t st; } sv_lexer_t; @@ -30,20 +30,20 @@ typedef struct { typedef struct { const char *code; - jsoff_t clen; + ant_offset_t clen; bool strict; sv_lexer_state_t st; } sv_lexer_checkpoint_t; sv_lex_string_t sv_lexer_str_literal(sv_lexer_t *lx); -void sv_lexer_init(sv_lexer_t *lx, ant_t *js, const char *code, jsoff_t clen, bool strict); +void sv_lexer_init(sv_lexer_t *lx, ant_t *js, const char *code, ant_offset_t clen, bool strict); void sv_lexer_set_error_site(sv_lexer_t *lx); void sv_lexer_save_state(const sv_lexer_t *lx, sv_lexer_state_t *st); void sv_lexer_restore_state(sv_lexer_t *lx, const sv_lexer_state_t *st); -void sv_lexer_push_source(sv_lexer_t *lx, sv_lexer_checkpoint_t *cp, const char *code, jsoff_t clen); +void sv_lexer_push_source(sv_lexer_t *lx, sv_lexer_checkpoint_t *cp, const char *code, ant_offset_t clen); void sv_lexer_pop_source(sv_lexer_t *lx, const sv_lexer_checkpoint_t *cp); uint8_t sv_lexer_next(sv_lexer_t *lx); diff --git a/include/silver/swarm.h b/include/silver/swarm.h index 9f053a6..51db16d 100644 --- a/include/silver/swarm.h +++ b/include/silver/swarm.h @@ -14,7 +14,7 @@ sv_jit_func_t sv_jit_compile( sv_closure_t *hint_closure ); -jsval_t sv_jit_try_osr( +ant_value_t sv_jit_try_osr( sv_vm_t *vm, ant_t *js, sv_frame_t *frame, sv_func_t *func, int bc_offset diff --git a/include/silver/vm.h b/include/silver/vm.h index 50cde6a..f1e06d2 100644 --- a/include/silver/vm.h +++ b/include/silver/vm.h @@ -18,27 +18,27 @@ sv_vm_t *sv_vm_create(ant_t *js, sv_vm_kind_t kind); void sv_vm_destroy(sv_vm_t *vm); void sv_vm_limits(sv_vm_kind_t kind, int *out_stack_size, int *out_max_frames); -void sv_vm_gc_roots(sv_vm_t *vm, void (*op_val)(void *, jsval_t *), void *ctx); -void sv_vm_gc_roots_pending(void (*op_val)(void *, jsval_t *), void *ctx); +void sv_vm_gc_roots(sv_vm_t *vm, void (*op_val)(void *, ant_value_t *), void *ctx); +void sv_vm_gc_roots_pending(void (*op_val)(void *, ant_value_t *), void *ctx); void sv_vm_visit_frame_funcs(sv_vm_t *vm, void (*visitor)(void *, sv_func_t *), void *ctx); void sv_disasm(ant_t *js, sv_func_t *func, const char *label); -jsval_t sv_execute_frame( +ant_value_t sv_execute_frame( sv_vm_t *vm, sv_func_t *func, - jsval_t this_val, jsval_t super_val, - jsval_t *args, int argc + ant_value_t this_val, ant_value_t super_val, + ant_value_t *args, int argc ); -jsval_t sv_execute_entry( +ant_value_t sv_execute_entry( sv_vm_t *vm, sv_func_t *func, - jsval_t this_val, - jsval_t *args, int argc + ant_value_t this_val, + ant_value_t *args, int argc ); -jsval_t sv_execute_entry_tla( +ant_value_t sv_execute_entry_tla( ant_t *js, sv_func_t *func, - jsval_t this_val + ant_value_t this_val ); #endif diff --git a/include/snapshot.h b/include/snapshot.h index 06b3383..ff5339c 100644 --- a/include/snapshot.h +++ b/include/snapshot.h @@ -4,7 +4,7 @@ #include #include "types.h" -jsval_t ant_load_snapshot(ant_t *js); +ant_value_t ant_load_snapshot(ant_t *js); const uint8_t *ant_get_snapshot_source(size_t *len); #endif \ No newline at end of file diff --git a/include/sugar.h b/include/sugar.h index fcbaf9f..3553643 100644 --- a/include/sugar.h +++ b/include/sugar.h @@ -38,16 +38,16 @@ typedef enum { typedef struct coroutine { ant_t *js; - jsval_t this_val; - jsval_t super_val; - jsval_t new_target; - jsval_t result; - jsval_t async_func; - jsval_t yield_value; - jsval_t *args; + ant_value_t this_val; + ant_value_t super_val; + ant_value_t new_target; + ant_value_t result; + ant_value_t async_func; + ant_value_t yield_value; + ant_value_t *args; - jsval_t awaited_promise; - jsval_t async_promise; + ant_value_t awaited_promise; + ant_value_t async_promise; struct coroutine *prev; struct coroutine *next; @@ -55,7 +55,7 @@ typedef struct coroutine { mco_coro *mco; struct sv_vm *sv_vm; - jsoff_t resume_point; + ant_offset_t resume_point; coroutine_type_t type; int nargs; @@ -78,9 +78,9 @@ void enqueue_coroutine(coroutine_t *coro); void remove_coroutine(coroutine_t *coro); void free_coroutine(coroutine_t *coro); -jsval_t start_async_in_coroutine(ant_t *js, const char *code, size_t code_len, jsval_t closure_scope, jsval_t *args, int nargs); -jsval_t resume_coroutine_wrapper(ant_t *js, jsval_t *args, int nargs); -jsval_t reject_coroutine_wrapper(ant_t *js, jsval_t *args, int nargs); +ant_value_t start_async_in_coroutine(ant_t *js, const char *code, size_t code_len, ant_value_t closure_scope, ant_value_t *args, int nargs); +ant_value_t resume_coroutine_wrapper(ant_t *js, ant_value_t *args, int nargs); +ant_value_t reject_coroutine_wrapper(ant_t *js, ant_value_t *args, int nargs); bool has_ready_coroutines(void); bool has_pending_coroutines(void); diff --git a/include/types.h b/include/types.h index d332ca5..f2b14ec 100644 --- a/include/types.h +++ b/include/types.h @@ -9,10 +9,6 @@ struct ant; typedef struct ant ant_t; typedef unsigned long long u64; -typedef size_t jshdl_t; -typedef uint64_t jsoff_t; -typedef uint64_t jsval_t; - typedef size_t ant_handle_t; typedef uint64_t ant_offset_t; typedef uint64_t ant_value_t; diff --git a/src/ant.c b/src/ant.c index 6533353..225a12e 100644 --- a/src/ant.c +++ b/src/ant.c @@ -105,9 +105,9 @@ static size_t intern_bytes = 0; static interned_string_t *intern_buckets[ANT_LIMIT_SIZE_CACHE]; typedef struct promise_handler { - jsval_t onFulfilled; - jsval_t onRejected; - jsval_t nextPromise; + ant_value_t onFulfilled; + ant_value_t onRejected; + ant_value_t nextPromise; } promise_handler_t; static const UT_icd promise_handler_icd = { @@ -118,10 +118,10 @@ static const UT_icd promise_handler_icd = { }; typedef struct { - jsoff_t obj_off; + ant_offset_t obj_off; const char *intern_ptr; - jsoff_t prop_off; - jsoff_t tail; + ant_offset_t prop_off; + ant_offset_t tail; uint64_t generation; } intern_prop_cache_entry_t; @@ -129,11 +129,11 @@ static uint64_t intern_prop_cache_gen = 1; static intern_prop_cache_entry_t intern_prop_cache[ANT_LIMIT_SIZE_CACHE]; typedef struct promise_data_entry { - jsval_t value; + ant_value_t value; UT_array *handlers; uint32_t promise_id; uint32_t trigger_pid; - jsoff_t obj_offset; + ant_offset_t obj_offset; int state; bool has_rejection_handler; bool processing; @@ -146,19 +146,19 @@ static promise_data_entry_t *unhandled_rejections = NULL; static uint32_t next_promise_id = 1; static promise_data_entry_t *get_promise_data(uint32_t promise_id, bool create); -static uint32_t get_promise_id(ant_t *js, jsval_t p); +static uint32_t get_promise_id(ant_t *js, ant_value_t p); static bool js_try_grow_memory(ant_t *js, size_t needed); typedef struct proxy_data { - jsoff_t obj_offset; - jsval_t target; - jsval_t handler; + ant_offset_t obj_offset; + ant_value_t target; + ant_value_t handler; bool revoked; UT_hash_handle hh; } proxy_data_t; typedef struct dynamic_accessors { - jsoff_t obj_offset; + ant_offset_t obj_offset; js_getter_fn getter; js_setter_fn setter; js_deleter_fn deleter; @@ -167,43 +167,43 @@ typedef struct dynamic_accessors { } dynamic_accessors_t; static proxy_data_t *proxy_registry = NULL; -static proxy_data_t *get_proxy_data(jsval_t obj); +static proxy_data_t *get_proxy_data(ant_value_t obj); static dynamic_accessors_t *accessor_registry = NULL; -jsval_t tov(double d) { - union { double d; jsval_t v; } u = {d}; +ant_value_t tov(double d) { + union { double d; ant_value_t v; } u = {d}; if (__builtin_expect(isnan(d), 0)) return (u.v > NANBOX_PREFIX) ? 0x7FF8000000000000ULL : u.v; // canonical NaN return u.v; } -double tod(jsval_t v) { - union { jsval_t v; double d; } u = {v}; return u.d; +double tod(ant_value_t v) { + union { ant_value_t v; double d; } u = {v}; return u.d; } -static bool is_tagged(jsval_t v) { +static bool is_tagged(ant_value_t v) { return v > NANBOX_PREFIX; } -size_t vdata(jsval_t v) { +size_t vdata(ant_value_t v) { return (size_t)(v & NANBOX_DATA_MASK); } -static jsval_t get_slot(ant_t *js, jsval_t obj, internal_slot_t slot); -static void set_slot(ant_t *js, jsval_t obj, internal_slot_t slot, jsval_t value); +static ant_value_t get_slot(ant_t *js, ant_value_t obj, internal_slot_t slot); +static void set_slot(ant_t *js, ant_value_t obj, internal_slot_t slot, ant_value_t value); -static jsval_t get_proto(ant_t *js, jsval_t obj); -static void set_proto(ant_t *js, jsval_t obj, jsval_t proto); +static ant_value_t get_proto(ant_t *js, ant_value_t obj); +static void set_proto(ant_t *js, ant_value_t obj, ant_value_t proto); -static inline jsoff_t offtolen(jsoff_t off) { return (off >> 3) - 1; } -static inline jsoff_t align64(jsoff_t v) { return (v + 7) & ~7ULL; } +static inline ant_offset_t offtolen(ant_offset_t off) { return (off >> 3) - 1; } +static inline ant_offset_t align64(ant_offset_t v) { return (v + 7) & ~7ULL; } -static void saveoff(ant_t *js, jsoff_t off, jsoff_t val) { +static void saveoff(ant_t *js, ant_offset_t off, ant_offset_t val) { memcpy(&js->mem[off], &val, sizeof(val)); } -static void saveval(ant_t *js, jsoff_t off, jsval_t val) { +static void saveval(ant_t *js, ant_offset_t off, ant_value_t val) { memcpy(&js->mem[off], &val, sizeof(val)); } @@ -221,44 +221,44 @@ const char *typestr(uint8_t t) { return (t < sizeof(names) / sizeof(names[0])) ? names[t] : "??"; } -uint8_t vtype(jsval_t v) { +uint8_t vtype(ant_value_t v) { return is_tagged(v) ? ((v >> NANBOX_TYPE_SHIFT) & NANBOX_TYPE_MASK) : (uint8_t)T_NUM; } -jsval_t mkval(uint8_t type, uint64_t data) { +ant_value_t mkval(uint8_t type, uint64_t data) { return NANBOX_PREFIX - | ((jsval_t)(type & NANBOX_TYPE_MASK) << NANBOX_TYPE_SHIFT) + | ((ant_value_t)(type & NANBOX_TYPE_MASK) << NANBOX_TYPE_SHIFT) | (data & NANBOX_DATA_MASK); } -jsval_t js_obj_to_func(jsval_t obj) { +ant_value_t js_obj_to_func(ant_value_t obj) { sv_closure_t *closure = calloc(1, sizeof(sv_closure_t)); closure->func_obj = (vtype(obj) == T_OBJ) ? obj : mkval(T_OBJ, vdata(obj)); return mkval(T_FUNC, (uintptr_t)closure); } -jsval_t js_mktypedarray(void *data) { +ant_value_t js_mktypedarray(void *data) { return mkval(T_TYPEDARRAY, (uintptr_t)data); } -void *js_gettypedarray(jsval_t val) { +void *js_gettypedarray(ant_value_t val) { if (vtype(val) != T_TYPEDARRAY) return NULL; return (void *)vdata(val); } -jsval_t js_get_slot(ant_t *js, jsval_t obj, internal_slot_t slot) { +ant_value_t js_get_slot(ant_t *js, ant_value_t obj, internal_slot_t slot) { return get_slot(js, js_as_obj(obj), slot); } -void js_set_slot(ant_t *js, jsval_t obj, internal_slot_t slot, jsval_t value) { +void js_set_slot(ant_t *js, ant_value_t obj, internal_slot_t slot, ant_value_t value) { set_slot(js, js_as_obj(obj), slot, value); } -jsval_t js_mkffi(unsigned int index) { +ant_value_t js_mkffi(unsigned int index) { return mkval(T_FFI, (uint64_t)index); } -int js_getffi(jsval_t val) { +int js_getffi(ant_value_t val) { if (vtype(val) != T_FFI) return -1; return (int)vdata(val); } @@ -272,10 +272,10 @@ inline size_t js_getbrk(ant_t *js) { return (size_t) js->brk; } -static inline bool is_unboxed_obj(ant_t *js, jsval_t val, jsval_t expected_proto) { +static inline bool is_unboxed_obj(ant_t *js, ant_value_t val, ant_value_t expected_proto) { if (vtype(val) != T_OBJ) return false; if (vtype(get_slot(js, val, SLOT_PRIMITIVE)) != T_UNDEF) return false; - jsval_t proto = get_slot(js, val, SLOT_PROTO); + ant_value_t proto = get_slot(js, val, SLOT_PROTO); return vdata(proto) == vdata(expected_proto); } @@ -294,65 +294,65 @@ int32_t js_to_int32(double d) { return (int32_t) uint32; } -static size_t strstring(ant_t *js, jsval_t value, char *buf, size_t len); -static size_t strkey(ant_t *js, jsval_t value, char *buf, size_t len); +static size_t strstring(ant_t *js, ant_value_t value, char *buf, size_t len); +static size_t strkey(ant_t *js, ant_value_t value, char *buf, size_t len); -jsoff_t vstrlen(ant_t *js, jsval_t v) { - jsoff_t off = (jsoff_t) vdata(v); - jsoff_t header = loadoff(js, off); +ant_offset_t vstrlen(ant_t *js, ant_value_t v) { + ant_offset_t off = (ant_offset_t) vdata(v); + ant_offset_t header = loadoff(js, off); if (header & ROPE_FLAG) { return offtolen(header & ~(ROPE_FLAG | (ROPE_DEPTH_MASK << ROPE_DEPTH_SHIFT))); } return offtolen(header); } -static jsval_t proxy_read_target(ant_t *js, jsval_t obj); -static jsoff_t proxy_aware_length(ant_t *js, jsval_t obj); -static jsval_t proxy_aware_get_elem(ant_t *js, jsval_t obj, const char *key, size_t key_len); -static bool bigint_is_zero(ant_t *js, jsval_t v); +static ant_value_t proxy_read_target(ant_t *js, ant_value_t obj); +static ant_offset_t proxy_aware_length(ant_t *js, ant_value_t obj); +static ant_value_t proxy_aware_get_elem(ant_t *js, ant_value_t obj, const char *key, size_t key_len); +static bool bigint_is_zero(ant_t *js, ant_value_t v); -static jsoff_t get_dense_buf(ant_t *js, jsval_t arr); -static jsoff_t dense_length(ant_t *js, jsoff_t doff); -static jsoff_t get_array_length(ant_t *js, jsval_t arr); -static jsval_t arr_get(ant_t *js, jsval_t arr, jsoff_t idx); -static bool arr_has(ant_t *js, jsval_t arr, jsoff_t idx); +static ant_offset_t get_dense_buf(ant_t *js, ant_value_t arr); +static ant_offset_t dense_length(ant_t *js, ant_offset_t doff); +static ant_offset_t get_array_length(ant_t *js, ant_value_t arr); +static ant_value_t arr_get(ant_t *js, ant_value_t arr, ant_offset_t idx); +static bool arr_has(ant_t *js, ant_value_t arr, ant_offset_t idx); static bool streq(const char *buf, size_t len, const char *p, size_t n); static bool parse_func_params(ant_t *js, uint8_t *flags, int *out_count); -static bool try_dynamic_setter(ant_t *js, jsval_t obj, const char *key, size_t key_len, jsval_t value); -static jsoff_t lkp_with_setter(ant_t *js, jsval_t obj, const char *buf, size_t len, jsval_t *setter_out, bool *has_setter_out); -static jsval_t call_proto_accessor(ant_t *js, jsval_t prim, jsval_t accessor, bool has_accessor, jsval_t *arg, int arg_count, bool is_setter); -static jsval_t get_prototype_for_type(ant_t *js, uint8_t type); +static bool try_dynamic_setter(ant_t *js, ant_value_t obj, const char *key, size_t key_len, ant_value_t value); +static ant_offset_t lkp_with_setter(ant_t *js, ant_value_t obj, const char *buf, size_t len, ant_value_t *setter_out, bool *has_setter_out); +static ant_value_t call_proto_accessor(ant_t *js, ant_value_t prim, ant_value_t accessor, bool has_accessor, ant_value_t *arg, int arg_count, bool is_setter); +static ant_value_t get_prototype_for_type(ant_t *js, uint8_t type); -static size_t strbigint(ant_t *js, jsval_t value, char *buf, size_t len); -static size_t tostr(ant_t *js, jsval_t value, char *buf, size_t len); -static size_t strpromise(ant_t *js, jsval_t value, char *buf, size_t len); -static jsval_t js_call_valueOf(ant_t *js, jsval_t value); -static jsval_t js_call_toString(ant_t *js, jsval_t value); -static jsval_t js_call_method(ant_t *js, jsval_t obj, const char *method, size_t method_len, jsval_t *args, int nargs); +static size_t strbigint(ant_t *js, ant_value_t value, char *buf, size_t len); +static size_t tostr(ant_t *js, ant_value_t value, char *buf, size_t len); +static size_t strpromise(ant_t *js, ant_value_t value, char *buf, size_t len); +static ant_value_t js_call_valueOf(ant_t *js, ant_value_t value); +static ant_value_t js_call_toString(ant_t *js, ant_value_t value); +static ant_value_t js_call_method(ant_t *js, ant_value_t obj, const char *method, size_t method_len, ant_value_t *args, int nargs); -static inline bool is_slot_prop(jsoff_t header); -static inline jsoff_t next_prop(jsoff_t header); +static inline bool is_slot_prop(ant_offset_t header); +static inline ant_offset_t next_prop(ant_offset_t header); -static jsval_t builtin_Object(ant_t *js, jsval_t *args, int nargs); -static jsval_t builtin_promise_then(ant_t *js, jsval_t *args, int nargs); -static jsval_t string_split_impl(ant_t *js, jsval_t str, jsval_t *args, int nargs); +static ant_value_t builtin_Object(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t builtin_promise_then(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t string_split_impl(ant_t *js, ant_value_t str, ant_value_t *args, int nargs); -static jsval_t proxy_get(ant_t *js, jsval_t proxy, const char *key, size_t key_len); -static jsval_t proxy_get_val(ant_t *js, jsval_t proxy, jsval_t key_val); -static jsval_t proxy_set(ant_t *js, jsval_t proxy, const char *key, size_t key_len, jsval_t value); -static jsval_t proxy_has(ant_t *js, jsval_t proxy, const char *key, size_t key_len); -static jsval_t proxy_has_val(ant_t *js, jsval_t proxy, jsval_t key_val); -static jsval_t proxy_delete(ant_t *js, jsval_t proxy, const char *key, size_t key_len); -static jsval_t proxy_delete_val(ant_t *js, jsval_t proxy, jsval_t key_val); +static ant_value_t proxy_get(ant_t *js, ant_value_t proxy, const char *key, size_t key_len); +static ant_value_t proxy_get_val(ant_t *js, ant_value_t proxy, ant_value_t key_val); +static ant_value_t proxy_set(ant_t *js, ant_value_t proxy, const char *key, size_t key_len, ant_value_t value); +static ant_value_t proxy_has(ant_t *js, ant_value_t proxy, const char *key, size_t key_len); +static ant_value_t proxy_has_val(ant_t *js, ant_value_t proxy, ant_value_t key_val); +static ant_value_t proxy_delete(ant_t *js, ant_value_t proxy, const char *key, size_t key_len); +static ant_value_t proxy_delete_val(ant_t *js, ant_value_t proxy, ant_value_t key_val); -static jsval_t get_prototype_for_type(ant_t *js, uint8_t type); -static jsval_t get_ctor_proto(ant_t *js, const char *name, size_t len); -static jsoff_t lkp_interned(ant_t *js, jsval_t obj, const char *search_intern, size_t len); +static ant_value_t get_prototype_for_type(ant_t *js, uint8_t type); +static ant_value_t get_ctor_proto(ant_t *js, const char *name, size_t len); +static ant_offset_t lkp_interned(ant_t *js, ant_value_t obj, const char *search_intern, size_t len); -static const char *bigint_digits(ant_t *js, jsval_t v, size_t *len); +static const char *bigint_digits(ant_t *js, ant_value_t v, size_t *len); -typedef struct { jsval_t handle; bool is_new; } ctor_t; +typedef struct { ant_value_t handle; bool is_new; } ctor_t; static ctor_t get_constructor(ant_t *js, const char *name, size_t len) { ctor_t ctor; @@ -363,24 +363,24 @@ static ctor_t get_constructor(ant_t *js, const char *name, size_t len) { return ctor; } -jsval_t unwrap_primitive(ant_t *js, jsval_t val) { +ant_value_t unwrap_primitive(ant_t *js, ant_value_t val) { if (vtype(val) != T_OBJ) return val; - jsval_t prim = get_slot(js, val, SLOT_PRIMITIVE); + ant_value_t prim = get_slot(js, val, SLOT_PRIMITIVE); if (vtype(prim) == T_UNDEF) return val; return prim; } -static jsval_t to_string_val(ant_t *js, jsval_t val) { +static ant_value_t to_string_val(ant_t *js, ant_value_t val) { uint8_t t = vtype(val); if (t == T_STR) return val; if (t == T_OBJ) { - jsval_t prim = get_slot(js, val, SLOT_PRIMITIVE); + ant_value_t prim = get_slot(js, val, SLOT_PRIMITIVE); if (vtype(prim) == T_STR) return prim; } return js_call_toString(js, val); } -bool js_truthy(ant_t *js, jsval_t v) { +bool js_truthy(ant_t *js, ant_value_t v) { static const void *dispatch[] = { [T_OBJ] = &&l_true, [T_FUNC] = &&l_true, @@ -436,38 +436,38 @@ size_t uint_to_str(char *buf, size_t bufsize, uint64_t val) { return len; } -static jsval_t bigint_from_u64(ant_t *js, uint64_t value) { +static ant_value_t bigint_from_u64(ant_t *js, uint64_t value) { char buf[32]; size_t len = uint_to_str(buf, sizeof(buf), value); return js_mkbigint(js, buf, len, false); } -static jsval_t stringify_stack[MAX_STRINGIFY_DEPTH]; +static ant_value_t stringify_stack[MAX_STRINGIFY_DEPTH]; static int stringify_depth = 0; static int stringify_indent = 0; -static jsval_t multiref_objs[MAX_MULTIREF_OBJS]; +static ant_value_t multiref_objs[MAX_MULTIREF_OBJS]; static int multiref_ids[MAX_MULTIREF_OBJS]; static int multiref_count = 0; static int multiref_next_id = 0; -static void scan_refs(ant_t *js, jsval_t value); +static void scan_refs(ant_t *js, ant_value_t value); -static int find_multiref(jsval_t obj) { +static int find_multiref(ant_value_t obj) { for (int i = 0; i < multiref_count; i++) { if (multiref_objs[i] == obj) return multiref_ids[i]; } return 0; } -static bool is_on_stack(jsval_t obj) { +static bool is_on_stack(ant_value_t obj) { for (int i = 0; i < stringify_depth; i++) { if (stringify_stack[i] == obj) return true; } return false; } -static void mark_multiref(jsval_t obj) { +static void mark_multiref(ant_value_t obj) { for (int i = 0; i < multiref_count; i++) { if (multiref_objs[i] == obj) { if (multiref_ids[i] == 0) multiref_ids[i] = ++multiref_next_id; @@ -481,7 +481,7 @@ static void mark_multiref(jsval_t obj) { } } -static void scan_obj_refs(ant_t *js, jsval_t obj) { +static void scan_obj_refs(ant_t *js, ant_value_t obj) { if (is_on_stack(obj)) { mark_multiref(obj); return; @@ -490,24 +490,24 @@ static void scan_obj_refs(ant_t *js, jsval_t obj) { if (stringify_depth >= MAX_STRINGIFY_DEPTH) return; stringify_stack[stringify_depth++] = obj; - jsoff_t next = loadoff(js, (jsoff_t) vdata(js_as_obj(obj))) & ~(3U | FLAGMASK); + ant_offset_t next = loadoff(js, (ant_offset_t) vdata(js_as_obj(obj))) & ~(3U | FLAGMASK); while (next < js->brk && next != 0) { - jsoff_t header = loadoff(js, next); + ant_offset_t header = loadoff(js, next); if (!is_slot_prop(header)) { - jsoff_t koff = loadoff(js, next + (jsoff_t) sizeof(next)); - jsval_t val = loadval(js, next + (jsoff_t) (sizeof(next) + sizeof(koff))); + ant_offset_t koff = loadoff(js, next + (ant_offset_t) sizeof(next)); + ant_value_t val = loadval(js, next + (ant_offset_t) (sizeof(next) + sizeof(koff))); scan_refs(js, val); } next = next_prop(header); } - jsval_t proto_val = get_slot(js, obj, SLOT_PROTO); + ant_value_t proto_val = get_slot(js, obj, SLOT_PROTO); if (vtype(proto_val) == T_OBJ) scan_refs(js, proto_val); stringify_depth--; } -static void scan_arr_refs(ant_t *js, jsval_t obj) { +static void scan_arr_refs(ant_t *js, ant_value_t obj) { if (is_on_stack(obj)) { mark_multiref(obj); return; @@ -516,12 +516,12 @@ static void scan_arr_refs(ant_t *js, jsval_t obj) { if (stringify_depth >= MAX_STRINGIFY_DEPTH) return; stringify_stack[stringify_depth++] = obj; - jsoff_t next = loadoff(js, (jsoff_t) vdata(js_as_obj(obj))) & ~(3U | FLAGMASK); + ant_offset_t next = loadoff(js, (ant_offset_t) vdata(js_as_obj(obj))) & ~(3U | FLAGMASK); while (next < js->brk && next != 0) { - jsoff_t header = loadoff(js, next); + ant_offset_t header = loadoff(js, next); if (!is_slot_prop(header)) { - jsoff_t koff = loadoff(js, next + (jsoff_t) sizeof(next)); - jsval_t val = loadval(js, next + (jsoff_t) (sizeof(next) + sizeof(koff))); + ant_offset_t koff = loadoff(js, next + (ant_offset_t) sizeof(next)); + ant_value_t val = loadval(js, next + (ant_offset_t) (sizeof(next) + sizeof(koff))); scan_refs(js, val); } next = next_prop(header); @@ -530,8 +530,8 @@ static void scan_arr_refs(ant_t *js, jsval_t obj) { stringify_depth--; } -static void scan_func_refs(ant_t *js, jsval_t value) { - jsval_t func_obj = js_func_obj(value); +static void scan_func_refs(ant_t *js, ant_value_t value) { + ant_value_t func_obj = js_func_obj(value); if (is_on_stack(func_obj)) { mark_multiref(func_obj); @@ -541,12 +541,12 @@ static void scan_func_refs(ant_t *js, jsval_t value) { if (stringify_depth >= MAX_STRINGIFY_DEPTH) return; stringify_stack[stringify_depth++] = func_obj; - jsoff_t next = loadoff(js, (jsoff_t) vdata(func_obj)) & ~(3U | FLAGMASK); + ant_offset_t next = loadoff(js, (ant_offset_t) vdata(func_obj)) & ~(3U | FLAGMASK); while (next < js->brk && next != 0) { - jsoff_t header = loadoff(js, next); + ant_offset_t header = loadoff(js, next); if (!is_slot_prop(header)) { - jsoff_t koff = loadoff(js, next + (jsoff_t) sizeof(next)); - jsval_t val = loadval(js, next + (jsoff_t) (sizeof(next) + sizeof(koff))); + ant_offset_t koff = loadoff(js, next + (ant_offset_t) sizeof(next)); + ant_value_t val = loadval(js, next + (ant_offset_t) (sizeof(next) + sizeof(koff))); scan_refs(js, val); } next = next_prop(header); @@ -555,7 +555,7 @@ static void scan_func_refs(ant_t *js, jsval_t value) { stringify_depth--; } -static void scan_refs(ant_t *js, jsval_t value) { +static void scan_refs(ant_t *js, ant_value_t value) { switch (vtype(value)) { case T_OBJ: scan_obj_refs(js, value); break; case T_ARR: scan_arr_refs(js, value); break; @@ -564,7 +564,7 @@ static void scan_refs(ant_t *js, jsval_t value) { } } -static int get_circular_ref(jsval_t obj) { +static int get_circular_ref(ant_value_t obj) { if (is_on_stack(obj)) { int ref = find_multiref(obj); return ref ? ref : -1; @@ -572,15 +572,15 @@ static int get_circular_ref(jsval_t obj) { return 0; } -static bool is_circular(jsval_t obj) { +static bool is_circular(ant_value_t obj) { return is_on_stack(obj); } -static int get_self_ref(jsval_t obj) { +static int get_self_ref(ant_value_t obj) { return find_multiref(obj); } -static void push_stringify(jsval_t obj) { +static void push_stringify(ant_value_t obj) { if (stringify_depth < MAX_STRINGIFY_DEPTH) { stringify_stack[stringify_depth++] = obj; } @@ -599,41 +599,41 @@ static size_t add_indent(char *buf, size_t len, int level) { return wanted; } -static inline jsoff_t get_prop_koff(ant_t *js, jsoff_t prop) { - return loadoff(js, prop + (jsoff_t) sizeof(prop)); +static inline ant_offset_t get_prop_koff(ant_t *js, ant_offset_t prop) { + return loadoff(js, prop + (ant_offset_t) sizeof(prop)); } -static inline bool is_sym_key_prop(ant_t *js, jsoff_t prop) { - jsoff_t koff = get_prop_koff(js, prop); +static inline bool is_sym_key_prop(ant_t *js, ant_offset_t prop) { + ant_offset_t koff = get_prop_koff(js, prop); return koff < js->brk && (loadoff(js, koff) & 0xF) == 0; } -static void get_prop_key(ant_t *js, jsoff_t prop, const char **key, jsoff_t *klen) { - jsoff_t koff = get_prop_koff(js, prop); +static void get_prop_key(ant_t *js, ant_offset_t prop, const char **key, ant_offset_t *klen) { + ant_offset_t koff = get_prop_koff(js, prop); *klen = offtolen(loadoff(js, koff)); *key = (char *) &js->mem[koff + sizeof(koff)]; } -static jsval_t get_prop_val(ant_t *js, jsoff_t prop) { - jsoff_t koff = get_prop_koff(js, prop); - return loadval(js, prop + (jsoff_t) (sizeof(prop) + sizeof(koff))); +static ant_value_t get_prop_val(ant_t *js, ant_offset_t prop) { + ant_offset_t koff = get_prop_koff(js, prop); + return loadval(js, prop + (ant_offset_t) (sizeof(prop) + sizeof(koff))); } -const char *get_str_prop(ant_t *js, jsval_t obj, const char *key, jsoff_t klen, jsoff_t *out_len) { - jsoff_t off = lkp(js, obj, key, klen); +const char *get_str_prop(ant_t *js, ant_value_t obj, const char *key, ant_offset_t klen, ant_offset_t *out_len) { + ant_offset_t off = lkp(js, obj, key, klen); if (off <= 0) return NULL; - jsval_t v = resolveprop(js, mkval(T_PROP, off)); + ant_value_t v = resolveprop(js, mkval(T_PROP, off)); if (vtype(v) != T_STR) return NULL; return (const char *)&js->mem[vstr(js, v, out_len)]; } -static bool is_small_array(ant_t *js, jsval_t obj, int *elem_count) { - jsoff_t length = get_array_length(js, obj); +static bool is_small_array(ant_t *js, ant_value_t obj, int *elem_count) { + ant_offset_t length = get_array_length(js, obj); if (length > 64) { if (elem_count) *elem_count = (int)length; return false; } int count = 0; bool has_nested = false; - for (jsoff_t i = 0; i < length; i++) { - jsval_t val = arr_get(js, obj, i); uint8_t t = vtype(val); + for (ant_offset_t i = 0; i < length; i++) { + ant_value_t val = arr_get(js, obj, i); uint8_t t = vtype(val); if (t == T_OBJ || t == T_ARR || t == T_FUNC) has_nested = true; count++; } @@ -642,15 +642,15 @@ static bool is_small_array(ant_t *js, jsval_t obj, int *elem_count) { return count <= 4 && !has_nested; } -static inline bool is_array_index(const char *key, jsoff_t klen) { +static inline bool is_array_index(const char *key, ant_offset_t klen) { if (klen == 0 || (klen > 1 && key[0] == '0')) return false; - for (jsoff_t i = 0; i < klen; i++) { + for (ant_offset_t i = 0; i < klen; i++) { if (key[i] < '0' || key[i] > '9') return false; } return true; } -static inline bool parse_array_index(const char *key, size_t klen, jsoff_t max_len, unsigned long *out_idx) { +static inline bool parse_array_index(const char *key, size_t klen, ant_offset_t max_len, unsigned long *out_idx) { if (klen == 0 || key[0] < '0' || key[0] > '9') return false; unsigned long parsed_idx = 0; @@ -664,62 +664,62 @@ static inline bool parse_array_index(const char *key, size_t klen, jsoff_t max_l return true; } -static jsoff_t get_array_length(ant_t *js, jsval_t arr) { - jsoff_t doff = get_dense_buf(js, arr); - jsoff_t dense_len = doff ? dense_length(js, doff) : 0; - jsoff_t off = lkp_interned(js, arr, INTERN_LENGTH, 6); +static ant_offset_t get_array_length(ant_t *js, ant_value_t arr) { + ant_offset_t doff = get_dense_buf(js, arr); + ant_offset_t dense_len = doff ? dense_length(js, doff) : 0; + ant_offset_t off = lkp_interned(js, arr, INTERN_LENGTH, 6); if (off) { - jsval_t val = resolveprop(js, mkval(T_PROP, off)); + ant_value_t val = resolveprop(js, mkval(T_PROP, off)); if (vtype(val) == T_NUM) { - jsoff_t prop_len = (jsoff_t) tod(val); + ant_offset_t prop_len = (ant_offset_t) tod(val); return prop_len > dense_len ? prop_len : dense_len; } } return dense_len; } -static jsval_t get_obj_ctor(ant_t *js, jsval_t obj) { - jsval_t ctor = get_slot(js, obj, SLOT_CTOR); +static ant_value_t get_obj_ctor(ant_t *js, ant_value_t obj) { + ant_value_t ctor = get_slot(js, obj, SLOT_CTOR); if (vtype(ctor) == T_FUNC) return ctor; - jsval_t proto = get_slot(js, obj, SLOT_PROTO); + ant_value_t proto = get_slot(js, obj, SLOT_PROTO); if (vtype(proto) != T_OBJ) return js_mkundef(); - jsoff_t off = lkp_interned(js, proto, INTERN_CONSTRUCTOR, 11); + ant_offset_t off = lkp_interned(js, proto, INTERN_CONSTRUCTOR, 11); return off ? resolveprop(js, mkval(T_PROP, off)) : js_mkundef(); } -static const char *get_func_name(ant_t *js, jsval_t func, jsoff_t *out_len) { +static const char *get_func_name(ant_t *js, ant_value_t func, ant_offset_t *out_len) { if (vtype(func) != T_FUNC) return NULL; - jsoff_t off = lkp(js, js_func_obj(func), "name", 4); + ant_offset_t off = lkp(js, js_func_obj(func), "name", 4); if (!off) return NULL; - jsval_t name = resolveprop(js, mkval(T_PROP, off)); + ant_value_t name = resolveprop(js, mkval(T_PROP, off)); if (vtype(name) != T_STR) return NULL; - jsoff_t str_off = vstr(js, name, out_len); + ant_offset_t str_off = vstr(js, name, out_len); return (const char *) &js->mem[str_off]; } -static const char *get_class_name(ant_t *js, jsval_t obj, jsoff_t *out_len, const char *skip) { +static const char *get_class_name(ant_t *js, ant_value_t obj, ant_offset_t *out_len, const char *skip) { const char *name = get_func_name(js, get_obj_ctor(js, obj), out_len); if (!name) return NULL; - if (skip && *out_len == (jsoff_t)strlen(skip) && memcmp(name, skip, *out_len) == 0) return NULL; + if (skip && *out_len == (ant_offset_t)strlen(skip) && memcmp(name, skip, *out_len) == 0) return NULL; return name; } -static inline jsoff_t dense_iterable_length(ant_t *js, jsval_t obj) { - jsoff_t doff = get_dense_buf(js, obj); +static inline ant_offset_t dense_iterable_length(ant_t *js, ant_value_t obj) { + ant_offset_t doff = get_dense_buf(js, obj); return doff ? dense_length(js, doff) : 0; } -static size_t strarr(ant_t *js, jsval_t obj, char *buf, size_t len) { +static size_t strarr(ant_t *js, ant_value_t obj, char *buf, size_t len) { int ref = get_circular_ref(obj); if (ref) return ref > 0 ? (size_t) snprintf(buf, len, "[Circular *%d]", ref) : cpy(buf, len, "[Circular]", 10); push_stringify(obj); - jsoff_t first = loadoff(js, (jsoff_t) vdata(js_as_obj(obj))) & ~(3U | FLAGMASK); - jsoff_t length = get_array_length(js, obj); - jsoff_t d_len = dense_iterable_length(js, obj); - jsoff_t iter_len = (d_len >= length) ? length : d_len; + ant_offset_t first = loadoff(js, (ant_offset_t) vdata(js_as_obj(obj))) & ~(3U | FLAGMASK); + ant_offset_t length = get_array_length(js, obj); + ant_offset_t d_len = dense_iterable_length(js, obj); + ant_offset_t iter_len = (d_len >= length) ? length : d_len; - jsoff_t class_len = 0; + ant_offset_t class_len = 0; const char *class_name = get_class_name(js, obj, &class_len, "Array"); int elem_count = 0; @@ -741,20 +741,20 @@ static size_t strarr(ant_t *js, jsval_t obj, char *buf, size_t len) { if (!inline_mode) stringify_indent++; bool printed_first = false; - for (jsoff_t i = 0; i < iter_len; i++) { + for (ant_offset_t i = 0; i < iter_len; i++) { if (printed_first) n += cpy(buf + n, REMAIN(n, len), inline_mode ? ", " : ",\n", 2); if (!inline_mode) n += add_indent(buf + n, REMAIN(n, len), stringify_indent); - jsval_t val = arr_get(js, obj, i); bool found = arr_has(js, obj, i); + ant_value_t val = arr_get(js, obj, i); bool found = arr_has(js, obj, i); n += found ? tostr(js, val, buf + n, REMAIN(n, len)) : cpy(buf + n, REMAIN(n, len), "undefined", 9); printed_first = true; } - for (jsoff_t p = first; p < js->brk && p != 0; p = next_prop(loadoff(js, p))) { - jsoff_t header = loadoff(js, p); + for (ant_offset_t p = first; p < js->brk && p != 0; p = next_prop(loadoff(js, p))) { + ant_offset_t header = loadoff(js, p); if (is_slot_prop(header)) continue; - const char *key; jsoff_t klen; + const char *key; ant_offset_t klen; get_prop_key(js, p, &key, &klen); if (streq(key, klen, "length", 6)) continue; @@ -782,33 +782,33 @@ static size_t strarr(ant_t *js, jsval_t obj, char *buf, size_t len) { return n; } -static size_t strdate(ant_t *js, jsval_t obj, char *buf, size_t len) { - jsval_t time_val = js_get_slot(js, obj, SLOT_DATA); +static size_t strdate(ant_t *js, ant_value_t obj, char *buf, size_t len) { + ant_value_t time_val = js_get_slot(js, obj, SLOT_DATA); if (vtype(time_val) != T_NUM) return cpy(buf, len, "Invalid Date", 12); static const date_string_spec_t kSpec = {DATE_STRING_FMT_ISO, DATE_STRING_PART_ALL}; - jsval_t iso = get_date_string(js, obj, kSpec); + ant_value_t iso = get_date_string(js, obj, kSpec); if (is_err(iso) || vtype(iso) != T_STR) return cpy(buf, len, "Invalid Date", 12); - jsoff_t slen; - jsoff_t soff = vstr(js, iso, &slen); + ant_offset_t slen; + ant_offset_t soff = vstr(js, iso, &slen); return cpy(buf, len, (const char *)&js->mem[soff], slen); } -static bool is_valid_identifier(const char *str, jsoff_t slen) { +static bool is_valid_identifier(const char *str, ant_offset_t slen) { if (slen == 0) return false; char c = str[0]; if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || c == '$')) return false; - for (jsoff_t i = 1; i < slen; i++) { + for (ant_offset_t i = 1; i < slen; i++) { c = str[i]; if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_' || c == '$')) return false; } return true; } -static size_t strkey(ant_t *js, jsval_t value, char *buf, size_t len) { - jsoff_t slen, off = vstr(js, value, &slen); +static size_t strkey(ant_t *js, ant_value_t value, char *buf, size_t len) { + ant_offset_t slen, off = vstr(js, value, &slen); const char *str = (const char *) &js->mem[off]; if (is_valid_identifier(str, slen)) { @@ -817,15 +817,15 @@ static size_t strkey(ant_t *js, jsval_t value, char *buf, size_t len) { return strstring(js, value, buf, len); } -static bool is_small_object(ant_t *js, jsval_t obj, int *prop_count) { +static bool is_small_object(ant_t *js, ant_value_t obj, int *prop_count) { int count = 0; bool has_nested = false; - jsoff_t obj_off = (jsoff_t)vdata(js_as_obj(obj)); - jsoff_t next = loadoff(js, obj_off) & ~(3U | FLAGMASK); + ant_offset_t obj_off = (ant_offset_t)vdata(js_as_obj(obj)); + ant_offset_t next = loadoff(js, obj_off) & ~(3U | FLAGMASK); while (next < js->brk && next != 0) { - jsoff_t header = loadoff(js, next); + ant_offset_t header = loadoff(js, next); if (is_slot_prop(header)) { next = next_prop(header); continue; } if (is_sym_key_prop(js, next)) { @@ -834,13 +834,13 @@ static bool is_small_object(ant_t *js, jsval_t obj, int *prop_count) { continue; } - const char *key; jsoff_t klen; + const char *key; ant_offset_t klen; get_prop_key(js, next, &key, &klen); descriptor_entry_t *desc = lookup_descriptor(js, obj_off, key, klen); if (desc && !desc->enumerable) { next = next_prop(header); continue; } - jsval_t val = get_prop_val(js, next); + ant_value_t val = get_prop_val(js, next); uint8_t t = vtype(val); if (t == T_OBJ || t == T_ARR || t == T_FUNC) has_nested = true; count++; @@ -861,9 +861,9 @@ static bool is_small_object(ant_t *js, jsval_t obj, int *prop_count) { } // todo: split into smaller functions -static size_t strobj(ant_t *js, jsval_t obj, char *buf, size_t len) { - jsval_t obj_proto = js_get_proto(js, obj); - jsval_t date_proto = js_get_ctor_proto(js, "Date", 4); +static size_t strobj(ant_t *js, ant_value_t obj, char *buf, size_t len) { + ant_value_t obj_proto = js_get_proto(js, obj); + ant_value_t date_proto = js_get_ctor_proto(js, "Date", 4); if (obj_proto == date_proto) return strdate(js, obj, buf, len); int ref = get_circular_ref(obj); @@ -877,17 +877,17 @@ static size_t strobj(ant_t *js, jsval_t obj, char *buf, size_t len) { n += (size_t) snprintf(buf + n, REMAIN(n, len), " ", self_ref); } - jsval_t tag_sym = get_toStringTag_sym(); - jsoff_t tag_off = (vtype(tag_sym) == T_SYMBOL) ? lkp_sym_proto(js, obj, (jsoff_t)vdata(tag_sym)) : 0; + ant_value_t tag_sym = get_toStringTag_sym(); + ant_offset_t tag_off = (vtype(tag_sym) == T_SYMBOL) ? lkp_sym_proto(js, obj, (ant_offset_t)vdata(tag_sym)) : 0; bool is_map = false, is_set = false, is_arraybuffer = false; - jsoff_t tlen = 0, toff = 0; + ant_offset_t tlen = 0, toff = 0; const char *tag_str = NULL; int prop_count = 0; bool inline_mode = false; if (tag_off == 0) goto print_plain_object; - jsval_t tag_val = resolveprop(js, mkval(T_PROP, tag_off)); + ant_value_t tag_val = resolveprop(js, mkval(T_PROP, tag_off)); if (vtype(tag_val) != T_STR) goto print_plain_object; toff = vstr(js, tag_val, &tlen); @@ -896,7 +896,7 @@ static size_t strobj(ant_t *js, jsval_t obj, char *buf, size_t len) { is_set = (tlen == 3 && memcmp(tag_str, "Set", 3) == 0); is_arraybuffer = (tlen >= 11 && memcmp(tag_str + tlen - 11, "ArrayBuffer", 11) == 0); - jsval_t ta_slot = js_get_slot(js, obj, SLOT_BUFFER); + ant_value_t ta_slot = js_get_slot(js, obj, SLOT_BUFFER); if (vtype(ta_slot) == T_TYPEDARRAY) { TypedArrayData *ta = (TypedArrayData *)vdata(ta_slot); if (ta && ta->buffer) { @@ -909,8 +909,8 @@ static size_t strobj(ant_t *js, jsval_t obj, char *buf, size_t len) { const char *type_name = NULL; size_t type_len = 0; - jsval_t proto = js_get_proto(js, obj); - jsval_t buffer_proto = get_ctor_proto(js, "Buffer", 6); + ant_value_t proto = js_get_proto(js, obj); + ant_value_t buffer_proto = get_ctor_proto(js, "Buffer", 6); if (vtype(proto) == T_OBJ && vtype(buffer_proto) == T_OBJ && vdata(proto) == vdata(buffer_proto)) { type_name = "Buffer"; type_len = 6; @@ -977,7 +977,7 @@ static size_t strobj(ant_t *js, jsval_t obj, char *buf, size_t len) { } if (is_arraybuffer) { - jsval_t buf_val = js_get_slot(js, obj, SLOT_BUFFER); + ant_value_t buf_val = js_get_slot(js, obj, SLOT_BUFFER); if (vtype(buf_val) == T_NUM) { ArrayBufferData *ab_data = (ArrayBufferData *)(uintptr_t)tod(buf_val); size_t bytelen = ab_data ? ab_data->length : 0; @@ -1004,7 +1004,7 @@ static size_t strobj(ant_t *js, jsval_t obj, char *buf, size_t len) { bool is_dataview = (tlen == 8 && memcmp(tag_str, "DataView", 8) == 0); if (is_dataview) { - jsval_t dv_data_val = js_get_slot(js, obj, SLOT_DATA); + ant_value_t dv_data_val = js_get_slot(js, obj, SLOT_DATA); if (vtype(dv_data_val) == T_NUM) { DataViewData *dv = (DataViewData *)(uintptr_t)tod(dv_data_val); if (dv && dv->buffer) { @@ -1036,7 +1036,7 @@ static size_t strobj(ant_t *js, jsval_t obj, char *buf, size_t len) { } if (is_map) { - jsval_t map_val = js_get_slot(js, obj, SLOT_MAP); + ant_value_t map_val = js_get_slot(js, obj, SLOT_MAP); if (vtype(map_val) == T_UNDEF) goto print_tagged_object; map_entry_t **map_ptr = (map_entry_t**)(size_t)tod(map_val); @@ -1078,7 +1078,7 @@ static size_t strobj(ant_t *js, jsval_t obj, char *buf, size_t len) { } if (is_set) { - jsval_t set_val = js_get_slot(js, obj, SLOT_SET); + ant_value_t set_val = js_get_slot(js, obj, SLOT_SET); if (vtype(set_val) == T_UNDEF) goto print_tagged_object; set_entry_t **set_ptr = (set_entry_t**)(size_t)tod(set_val); @@ -1122,19 +1122,19 @@ print_tagged_object: print_plain_object: inline_mode = is_small_object(js, obj, &prop_count); - jsval_t proto_val = js_get_proto(js, obj); + ant_value_t proto_val = js_get_proto(js, obj); bool is_null_proto = (vtype(proto_val) == T_NULL); bool proto_is_null_proto = false; const char *class_name = NULL; - jsoff_t class_name_len = 0; + ant_offset_t class_name_len = 0; do { if (is_null_proto) break; uint8_t pt = vtype(proto_val); if (pt != T_OBJ && pt != T_FUNC) break; - jsval_t proto_proto = js_get_proto(js, proto_val); - jsval_t object_proto = get_ctor_proto(js, "Object", 6); + ant_value_t proto_proto = js_get_proto(js, proto_val); + ant_value_t object_proto = get_ctor_proto(js, "Object", 6); proto_is_null_proto = (vtype(proto_proto) == T_NULL) && (vdata(proto_val) != vdata(object_proto)); @@ -1172,23 +1172,23 @@ print_plain_object: continue_object_print:; if (!inline_mode) stringify_indent++; - jsoff_t next = loadoff(js, (jsoff_t) vdata(js_as_obj(obj))) & ~(3U | FLAGMASK); + ant_offset_t next = loadoff(js, (ant_offset_t) vdata(js_as_obj(obj))) & ~(3U | FLAGMASK); bool first = true; - jsoff_t obj_off = (jsoff_t)vdata(js_as_obj(obj)); + ant_offset_t obj_off = (ant_offset_t)vdata(js_as_obj(obj)); int prop_capacity = 64; - jsoff_t *prop_offsets = malloc(prop_capacity * sizeof(jsoff_t)); + ant_offset_t *prop_offsets = malloc(prop_capacity * sizeof(ant_offset_t)); int num_props = 0; while (next < js->brk && next != 0) { - jsoff_t header = loadoff(js, next); + ant_offset_t header = loadoff(js, next); if (is_slot_prop(header)) { next = next_prop(header); continue; } if (is_sym_key_prop(js, next)) { next = next_prop(header); continue; } - jsoff_t koff = loadoff(js, next + (jsoff_t) sizeof(next)); - jsoff_t klen = offtolen(loadoff(js, koff)); + ant_offset_t koff = loadoff(js, next + (ant_offset_t) sizeof(next)); + ant_offset_t klen = offtolen(loadoff(js, koff)); const char *key = (char *) &js->mem[koff + sizeof(koff)]; descriptor_entry_t *desc = lookup_descriptor(js, obj_off, key, klen); @@ -1196,18 +1196,18 @@ continue_object_print:; if (num_props >= prop_capacity) { prop_capacity *= 2; - prop_offsets = realloc(prop_offsets, prop_capacity * sizeof(jsoff_t)); + prop_offsets = realloc(prop_offsets, prop_capacity * sizeof(ant_offset_t)); } prop_offsets[num_props++] = next; next = next_prop(header); } for (int i = 0; i < num_props; i++) { - jsoff_t prop = prop_offsets[i]; - jsoff_t koff = loadoff(js, prop + (jsoff_t) sizeof(prop)); - jsoff_t klen = offtolen(loadoff(js, koff)); + ant_offset_t prop = prop_offsets[i]; + ant_offset_t koff = loadoff(js, prop + (ant_offset_t) sizeof(prop)); + ant_offset_t klen = offtolen(loadoff(js, koff)); const char *key = (char *) &js->mem[koff + sizeof(koff)]; - jsval_t val = loadval(js, prop + (jsoff_t) (sizeof(prop) + sizeof(koff))); + ant_value_t val = loadval(js, prop + (ant_offset_t) (sizeof(prop) + sizeof(koff))); if (!first) n += cpy(buf + n, REMAIN(n, len), inline_mode ? ", " : ",\n", 2); first = false; @@ -1235,18 +1235,18 @@ continue_object_print:; next = loadoff(js, obj_off) & ~(3U | FLAGMASK); while (next < js->brk && next != 0) { - jsoff_t header = loadoff(js, next); + ant_offset_t header = loadoff(js, next); if (is_slot_prop(header) || !is_sym_key_prop(js, next)) { next = next_prop(header); continue; } - jsoff_t sym_off = get_prop_koff(js, next); - if (vtype(tag_sym) == T_SYMBOL && sym_off == (jsoff_t)vdata(tag_sym)) { + ant_offset_t sym_off = get_prop_koff(js, next); + if (vtype(tag_sym) == T_SYMBOL && sym_off == (ant_offset_t)vdata(tag_sym)) { next = next_prop(header); continue; } - jsval_t sym = mkval(T_SYMBOL, sym_off); - jsval_t val = loadval(js, next + (jsoff_t)(sizeof(jsoff_t) * 2)); + ant_value_t sym = mkval(T_SYMBOL, sym_off); + ant_value_t val = loadval(js, next + (ant_offset_t)(sizeof(ant_offset_t) * 2)); if (!first) n += cpy(buf + n, REMAIN(n, len), inline_mode ? ", " : ",\n", 2); first = false; @@ -1311,7 +1311,7 @@ static size_t fix_exponent(char *buf, size_t n) { return n; } -static size_t strnum(jsval_t value, char *buf, size_t len) { +static size_t strnum(ant_value_t value, char *buf, size_t len) { double dv = tod(value); if (isnan(dv)) return cpy(buf, len, "NaN", 3); @@ -1345,111 +1345,111 @@ static size_t strnum(jsval_t value, char *buf, size_t len) { return cpy(buf, len, temp, strlen(temp)); } -static inline jsoff_t assert_string_header(ant_t *js, jsval_t value, jsoff_t *out_off) { +static inline ant_offset_t assert_string_header(ant_t *js, ant_value_t value, ant_offset_t *out_off) { assert(vtype(value) == T_STR); - jsoff_t off = (jsoff_t) vdata(value); - assert(off + sizeof(jsoff_t) <= js->brk); - jsoff_t header = loadoff(js, off); + ant_offset_t off = (ant_offset_t) vdata(value); + assert(off + sizeof(ant_offset_t) <= js->brk); + ant_offset_t header = loadoff(js, off); assert((header & 3) == T_STR); if (out_off) *out_off = off; return header; } -static inline jsoff_t assert_flat_string_len(ant_t *js, jsval_t value, jsoff_t *out_off) { - jsoff_t off; - jsoff_t header = assert_string_header(js, value, &off); +static inline ant_offset_t assert_flat_string_len(ant_t *js, ant_value_t value, ant_offset_t *out_off) { + ant_offset_t off; + ant_offset_t header = assert_string_header(js, value, &off); assert((header & ROPE_FLAG) == 0); - jsoff_t len = offtolen(header); - assert(off + sizeof(jsoff_t) + len <= js->brk); + ant_offset_t len = offtolen(header); + assert(off + sizeof(ant_offset_t) + len <= js->brk); if (out_off) *out_off = off; return len; } -static inline jsoff_t assert_rope_header(ant_t *js, jsval_t value, jsoff_t *out_off) { - jsoff_t off; - jsoff_t header = assert_string_header(js, value, &off); +static inline ant_offset_t assert_rope_header(ant_t *js, ant_value_t value, ant_offset_t *out_off) { + ant_offset_t off; + ant_offset_t header = assert_string_header(js, value, &off); assert((header & ROPE_FLAG) != 0); assert(off + sizeof(rope_node_t) <= js->brk); - jsoff_t payload_header = header & ~(ROPE_FLAG | (ROPE_DEPTH_MASK << ROPE_DEPTH_SHIFT)); + ant_offset_t payload_header = header & ~(ROPE_FLAG | (ROPE_DEPTH_MASK << ROPE_DEPTH_SHIFT)); assert((payload_header >> 3) > 0); if (out_off) *out_off = off; return header; } -bool is_rope(ant_t *js, jsval_t value) { - jsoff_t header = assert_string_header(js, value, NULL); +bool is_rope(ant_t *js, ant_value_t value) { + ant_offset_t header = assert_string_header(js, value, NULL); if ((header & ROPE_FLAG) != 0) assert_rope_header(js, value, NULL); return (header & ROPE_FLAG) != 0; } -static inline jsoff_t rope_len(ant_t *js, jsval_t value) { - jsoff_t header = assert_rope_header(js, value, NULL); +static inline ant_offset_t rope_len(ant_t *js, ant_value_t value) { + ant_offset_t header = assert_rope_header(js, value, NULL); return offtolen(header & ~(ROPE_FLAG | (ROPE_DEPTH_MASK << ROPE_DEPTH_SHIFT))); } -static inline uint8_t rope_depth(ant_t *js, jsval_t value) { - jsoff_t off = (jsoff_t) vdata(value); - jsoff_t header = loadoff(js, off); +static inline uint8_t rope_depth(ant_t *js, ant_value_t value) { + ant_offset_t off = (ant_offset_t) vdata(value); + ant_offset_t header = loadoff(js, off); return (uint8_t)((header >> ROPE_DEPTH_SHIFT) & ROPE_DEPTH_MASK); } -static inline jsval_t rope_left(ant_t *js, jsval_t value) { - jsoff_t off = (jsoff_t) vdata(value); +static inline ant_value_t rope_left(ant_t *js, ant_value_t value) { + ant_offset_t off = (ant_offset_t) vdata(value); return loadval(js, off + offsetof(rope_node_t, left)); } -static inline jsval_t rope_right(ant_t *js, jsval_t value) { - jsoff_t off = (jsoff_t) vdata(value); +static inline ant_value_t rope_right(ant_t *js, ant_value_t value) { + ant_offset_t off = (ant_offset_t) vdata(value); return loadval(js, off + offsetof(rope_node_t, right)); } -static inline jsval_t rope_cached_flat(ant_t *js, jsval_t value) { - jsoff_t off = (jsoff_t) vdata(value); +static inline ant_value_t rope_cached_flat(ant_t *js, ant_value_t value) { + ant_offset_t off = (ant_offset_t) vdata(value); return loadval(js, off + offsetof(rope_node_t, cached)); } -static inline void rope_set_cached_flat(ant_t *js, jsval_t rope, jsval_t flat) { - jsoff_t off = (jsoff_t) vdata(rope); +static inline void rope_set_cached_flat(ant_t *js, ant_value_t rope, ant_value_t flat) { + ant_offset_t off = (ant_offset_t) vdata(rope); saveval(js, off + offsetof(rope_node_t, cached), flat); } -static void rope_flatten_into(ant_t *js, jsval_t str, char *dest, jsoff_t *pos) { +static void rope_flatten_into(ant_t *js, ant_value_t str, char *dest, ant_offset_t *pos) { assert(vtype(str) == T_STR); if (!is_rope(js, str)) { - jsoff_t soff; - jsoff_t slen = assert_flat_string_len(js, str, &soff); - memcpy(dest + *pos, &js->mem[soff + sizeof(jsoff_t)], slen); + ant_offset_t soff; + ant_offset_t slen = assert_flat_string_len(js, str, &soff); + memcpy(dest + *pos, &js->mem[soff + sizeof(ant_offset_t)], slen); *pos += slen; return; } - jsval_t cached = rope_cached_flat(js, str); + ant_value_t cached = rope_cached_flat(js, str); if (vtype(cached) == T_STR && !is_rope(js, cached)) { - jsoff_t coff; - jsoff_t clen = assert_flat_string_len(js, cached, &coff); - memcpy(dest + *pos, &js->mem[coff + sizeof(jsoff_t)], clen); + ant_offset_t coff; + ant_offset_t clen = assert_flat_string_len(js, cached, &coff); + memcpy(dest + *pos, &js->mem[coff + sizeof(ant_offset_t)], clen); *pos += clen; return; } - jsval_t stack[ROPE_MAX_DEPTH + 8]; + ant_value_t stack[ROPE_MAX_DEPTH + 8]; int sp = 0; stack[sp++] = str; while (sp > 0) { - jsval_t node = stack[--sp]; + ant_value_t node = stack[--sp]; assert(vtype(node) == T_STR); if (!is_rope(js, node)) { - jsoff_t soff; - jsoff_t slen = assert_flat_string_len(js, node, &soff); - memcpy(dest + *pos, &js->mem[soff + sizeof(jsoff_t)], slen); + ant_offset_t soff; + ant_offset_t slen = assert_flat_string_len(js, node, &soff); + memcpy(dest + *pos, &js->mem[soff + sizeof(ant_offset_t)], slen); *pos += slen; continue; } - jsval_t c = rope_cached_flat(js, node); + ant_value_t c = rope_cached_flat(js, node); if (vtype(c) == T_STR && !is_rope(js, c)) { - jsoff_t coff; - jsoff_t clen = assert_flat_string_len(js, c, &coff); - memcpy(dest + *pos, &js->mem[coff + sizeof(jsoff_t)], clen); + ant_offset_t coff; + ant_offset_t clen = assert_flat_string_len(js, c, &coff); + memcpy(dest + *pos, &js->mem[coff + sizeof(ant_offset_t)], clen); *pos += clen; continue; } @@ -1460,23 +1460,23 @@ static void rope_flatten_into(ant_t *js, jsval_t str, char *dest, jsoff_t *pos) } } -jsval_t rope_flatten(ant_t *js, jsval_t rope) { +ant_value_t rope_flatten(ant_t *js, ant_value_t rope) { assert(vtype(rope) == T_STR); if (!is_rope(js, rope)) return rope; - jsval_t cached = rope_cached_flat(js, rope); + ant_value_t cached = rope_cached_flat(js, rope); if (vtype(cached) == T_STR && !is_rope(js, cached)) return cached; - jsoff_t total_len = rope_len(js, rope); + ant_offset_t total_len = rope_len(js, rope); char *buf = (char *)ant_calloc(total_len + 1); if (!buf) return js_mkerr(js, "oom"); - jsoff_t pos = 0; + ant_offset_t pos = 0; rope_flatten_into(js, rope, buf, &pos); buf[pos] = '\0'; - jsval_t flat = js_mkstr(js, buf, pos); + ant_value_t flat = js_mkstr(js, buf, pos); free(buf); if (!is_err(flat)) { @@ -1486,27 +1486,27 @@ jsval_t rope_flatten(ant_t *js, jsval_t rope) { return flat; } -jsoff_t vstr(ant_t *js, jsval_t value, jsoff_t *len) { - jsoff_t header = assert_string_header(js, value, NULL); +ant_offset_t vstr(ant_t *js, ant_value_t value, ant_offset_t *len) { + ant_offset_t header = assert_string_header(js, value, NULL); if (header & ROPE_FLAG) { - jsval_t flat = rope_flatten(js, value); + ant_value_t flat = rope_flatten(js, value); assert(!is_err(flat)); value = flat; } - jsoff_t off; - jsoff_t slen = assert_flat_string_len(js, value, &off); + ant_offset_t off; + ant_offset_t slen = assert_flat_string_len(js, value, &off); if (len) *len = slen; - return (jsoff_t) (off + sizeof(off)); + return (ant_offset_t) (off + sizeof(off)); } -static size_t strstring(ant_t *js, jsval_t value, char *buf, size_t len) { - jsoff_t slen, off = vstr(js, value, &slen); +static size_t strstring(ant_t *js, ant_value_t value, char *buf, size_t len) { + ant_offset_t slen, off = vstr(js, value, &slen); const char *str = (const char *) &js->mem[off]; size_t n = 0; n += cpy(buf + n, REMAIN(n, len), "'", 1); - for (jsoff_t i = 0; i < slen && n < len - 1; i++) { + for (ant_offset_t i = 0; i < slen && n < len - 1; i++) { char c = str[i]; if (c == '\n') { n += cpy(buf + n, REMAIN(n, len), "\\n", 2); } else if (c == '\r') { n += cpy(buf + n, REMAIN(n, len), "\\r", 2); } @@ -1553,7 +1553,7 @@ js_intern_stats_t js_intern_stats(void) { }; } -bool is_internal_prop(const char *key, jsoff_t klen) { +bool is_internal_prop(const char *key, ant_offset_t klen) { if (klen < 2) return false; if (key[0] != '_' || key[1] != '_') return false; if (klen == STR_PROTO_LEN && memcmp(key, STR_PROTO, STR_PROTO_LEN) == 0) return false; @@ -1574,14 +1574,14 @@ static const struct func_format formats[] = { }; // todo: make it work with bytecode NAME -static size_t strfunc(ant_t *js, jsval_t value, char *buf, size_t len) { - jsoff_t name_len = 0; +static size_t strfunc(ant_t *js, ant_value_t value, char *buf, size_t len) { + ant_offset_t name_len = 0; const char *name = get_func_name(js, value, &name_len); - jsval_t func_obj = js_func_obj(value); - jsval_t code_slot = get_slot(js, func_obj, SLOT_CODE); - jsval_t builtin_slot = get_slot(js, func_obj, SLOT_BUILTIN); - jsval_t async_slot = get_slot(js, func_obj, SLOT_ASYNC); + ant_value_t func_obj = js_func_obj(value); + ant_value_t code_slot = get_slot(js, func_obj, SLOT_CODE); + ant_value_t builtin_slot = get_slot(js, func_obj, SLOT_BUILTIN); + ant_value_t async_slot = get_slot(js, func_obj, SLOT_ASYNC); bool is_async = (async_slot == js_true); bool has_code = (vtype(code_slot) == T_CFUNC); @@ -1599,7 +1599,7 @@ static size_t strfunc(ant_t *js, jsval_t value, char *buf, size_t len) { } if (!has_code) { - jsval_t cfunc_slot = get_slot(js, func_obj, SLOT_CFUNC); + ant_value_t cfunc_slot = get_slot(js, func_obj, SLOT_CFUNC); bool is_native = (vtype(cfunc_slot) == T_CFUNC); size_t n; @@ -1613,18 +1613,18 @@ static size_t strfunc(ant_t *js, jsval_t value, char *buf, size_t len) { if (!is_native) return n; - jsval_t proto = get_slot(js, func_obj, SLOT_PROTO); + ant_value_t proto = get_slot(js, func_obj, SLOT_PROTO); uint8_t pt = vtype(proto); if (pt != T_OBJ && pt != T_FUNC) return n; - jsoff_t ctor_off = lkp(js, proto, "constructor", 11); + ant_offset_t ctor_off = lkp(js, proto, "constructor", 11); if (ctor_off == 0) return n; - jsval_t ctor = resolveprop(js, mkval(T_PROP, ctor_off)); + ant_value_t ctor = resolveprop(js, mkval(T_PROP, ctor_off)); uint8_t ct = vtype(ctor); if (ct != T_FUNC && ct != T_CFUNC) return n; - jsoff_t ctor_name_len = 0; + ant_offset_t ctor_name_len = 0; const char *ctor_name = get_func_name(js, ctor, &ctor_name_len); if (ctor_name && ctor_name_len > 0) { n += cpy(buf + n, REMAIN(n, len), " ", 1); @@ -1643,7 +1643,7 @@ static size_t strfunc(ant_t *js, jsval_t value, char *buf, size_t len) { return cpy(buf, len, fmt->anon, fmt->anon_len); } -static size_t tostr(ant_t *js, jsval_t value, char *buf, size_t len) { +static size_t tostr(ant_t *js, ant_value_t value, char *buf, size_t len) { switch (vtype(value)) { case T_UNDEF: return ANT_COPY(buf, len, "undefined"); case T_NULL: return ANT_COPY(buf, len, "null"); @@ -1667,11 +1667,11 @@ static size_t tostr(ant_t *js, jsval_t value, char *buf, size_t len) { case T_ERR: { uint64_t data = vdata(value); if (data != 0) { - jsval_t obj = mkval(T_OBJ, data); - jsval_t stack = js_get(js, obj, "stack"); + ant_value_t obj = mkval(T_OBJ, data); + ant_value_t stack = js_get(js, obj, "stack"); if (vtype(stack) == T_STR) { - jsoff_t slen; - jsoff_t off = vstr(js, stack, &slen); + ant_offset_t slen; + ant_offset_t off = vstr(js, stack, &slen); return cpy(buf, len, (const char *)&js->mem[off], slen); } } @@ -1689,7 +1689,7 @@ static size_t tostr(ant_t *js, jsval_t value, char *buf, size_t len) { } } -static char *tostr_alloc(ant_t *js, jsval_t value) { +static char *tostr_alloc(ant_t *js, ant_value_t value) { size_t cap = 64; char *buf = ant_calloc(cap); size_t n = tostr(js, value, buf, cap); @@ -1701,17 +1701,17 @@ static char *tostr_alloc(ant_t *js, jsval_t value) { return buf; } -js_cstr_t js_to_cstr(ant_t *js, jsval_t value, char *stack_buf, size_t stack_size) { +js_cstr_t js_to_cstr(ant_t *js, ant_value_t value, char *stack_buf, size_t stack_size) { js_cstr_t out = { .ptr = "", .len = 0, .needs_free = false }; if (is_err(value)) { uint64_t data = vdata(value); if (data != 0) { - jsval_t obj = mkval(T_OBJ, data); - jsval_t stack = js_get(js, obj, "stack"); + ant_value_t obj = mkval(T_OBJ, data); + ant_value_t stack = js_get(js, obj, "stack"); if (vtype(stack) == T_STR) { - jsoff_t slen; - jsoff_t off = vstr(js, stack, &slen); + ant_offset_t slen; + ant_offset_t off = vstr(js, stack, &slen); out.ptr = (const char *)&js->mem[off]; out.len = slen; return out; @@ -1778,7 +1778,7 @@ js_cstr_t js_to_cstr(ant_t *js, jsval_t value, char *stack_buf, size_t stack_siz } } -jsval_t js_tostring_val(ant_t *js, jsval_t value) { +ant_value_t js_tostring_val(ant_t *js, ant_value_t value) { uint8_t t = vtype(value); char *buf; size_t len, buflen; @@ -1804,7 +1804,7 @@ jsval_t js_tostring_val(ant_t *js, jsval_t value) { L_NUM: { buf = (char *)ant_calloc(32); len = strnum(value, buf, 32); - jsval_t result = js_mkstr(js, buf, len); + ant_value_t result = js_mkstr(js, buf, len); free(buf); return result; } @@ -1812,26 +1812,26 @@ jsval_t js_tostring_val(ant_t *js, jsval_t value) { bigint_digits(js, value, &buflen); buf = (char *)ant_calloc(buflen + 2); len = strbigint(js, value, buf, buflen + 2); - jsval_t result = js_mkstr(js, buf, len); + ant_value_t result = js_mkstr(js, buf, len); free(buf); return result; } L_DEFAULT: { buf = (char *)ant_calloc(64); len = tostr(js, value, buf, 64); - jsval_t result = js_mkstr(js, buf, len); + ant_value_t result = js_mkstr(js, buf, len); free(buf); return result; } } -const char *js_str(ant_t *js, jsval_t value) { +const char *js_str(ant_t *js, ant_value_t value) { if (is_err(value)) { uint64_t data = vdata(value); if (data != 0) { - jsval_t obj = mkval(T_OBJ, data); - jsval_t stack = js_get(js, obj, "stack"); + ant_value_t obj = mkval(T_OBJ, data); + ant_value_t stack = js_get(js, obj, "stack"); if (vtype(stack) == T_STR) { - jsoff_t slen, off = vstr(js, stack, &slen); + ant_offset_t slen, off = vstr(js, stack, &slen); return (const char *)&js->mem[off]; } } @@ -1860,11 +1860,11 @@ const char *js_str(ant_t *js, jsval_t value) { if (!buf) return ""; } - jsval_t str = js_mkstr(js, buf, len); + ant_value_t str = js_mkstr(js, buf, len); free(buf); if (is_err(str)) return ""; - return (const char *)&js->mem[vdata(str) + sizeof(jsoff_t)]; + return (const char *)&js->mem[vdata(str) + sizeof(ant_offset_t)]; } static bool js_try_grow_memory(ant_t *js, size_t needed) { @@ -1879,7 +1879,7 @@ static bool js_try_grow_memory(ant_t *js, size_t needed) { if (new_mem_size <= current) return false; if (ant_arena_commit(js->mem, js->size, new_mem_size) != 0) return false; - js->size = (jsoff_t)(new_mem_size / 8U * 8U); + js->size = (ant_offset_t)(new_mem_size / 8U * 8U); return true; } @@ -1901,93 +1901,93 @@ static bool js_ensure_space(ant_t *js, size_t size) { } static void js_track_allocation(ant_t *js, size_t size) { - js->brk += (jsoff_t) size; - js->gc_alloc_since += (jsoff_t) size; + js->brk += (ant_offset_t) size; + js->gc_alloc_since += (ant_offset_t) size; - jsoff_t threshold = js->brk / 2; + ant_offset_t threshold = js->brk / 2; if (threshold < 4 * 1024 * 1024) threshold = 4 * 1024 * 1024; if (js->gc_alloc_since > threshold) js->needs_gc = true; } -static inline jsoff_t js_alloc(ant_t *js, size_t size) { - size = align64((jsoff_t) size); - if (!js_ensure_space(js, size)) return ~(jsoff_t) 0; +static inline ant_offset_t js_alloc(ant_t *js, size_t size) { + size = align64((ant_offset_t) size); + if (!js_ensure_space(js, size)) return ~(ant_offset_t) 0; - jsoff_t ofs = js->brk; + ant_offset_t ofs = js->brk; js_track_allocation(js, size); return ofs; } -static jsoff_t dense_alloc(ant_t *js, jsoff_t capacity) { - jsoff_t size = sizeof(jsoff_t) * 2 + sizeof(jsval_t) * capacity; - jsoff_t off = js_alloc(js, size); - if (off == (jsoff_t)~0) return 0; +static ant_offset_t dense_alloc(ant_t *js, ant_offset_t capacity) { + ant_offset_t size = sizeof(ant_offset_t) * 2 + sizeof(ant_value_t) * capacity; + ant_offset_t off = js_alloc(js, size); + if (off == (ant_offset_t)~0) return 0; saveoff(js, off, capacity); - saveoff(js, off + sizeof(jsoff_t), 0); + saveoff(js, off + sizeof(ant_offset_t), 0); - for (jsoff_t i = 0; i < capacity; i++) saveval( - js, off + sizeof(jsoff_t) * 2 + sizeof(jsval_t) * i, T_EMPTY + for (ant_offset_t i = 0; i < capacity; i++) saveval( + js, off + sizeof(ant_offset_t) * 2 + sizeof(ant_value_t) * i, T_EMPTY ); return off; } -static inline jsoff_t get_dense_buf(ant_t *js, jsval_t arr) { - jsoff_t off = (jsoff_t) vdata(js_as_obj(arr)); +static inline ant_offset_t get_dense_buf(ant_t *js, ant_value_t arr) { + ant_offset_t off = (ant_offset_t) vdata(js_as_obj(arr)); if (__builtin_expect(off >= js->brk, 0)) return 0; - jsoff_t next = loadoff(js, off) & ~(3U | FLAGMASK); + ant_offset_t next = loadoff(js, off) & ~(3U | FLAGMASK); if (__builtin_expect(next == 0 || next >= js->brk, 0)) return 0; - jsoff_t header = loadoff(js, next); + ant_offset_t header = loadoff(js, next); if ((header & SLOTMASK) && - loadoff(js, next + sizeof(jsoff_t)) == (jsoff_t)SLOT_DENSE_BUF) { - jsval_t slot = loadval(js, next + sizeof(jsoff_t) * 2); - return (jsoff_t) tod(slot); + loadoff(js, next + sizeof(ant_offset_t)) == (ant_offset_t)SLOT_DENSE_BUF) { + ant_value_t slot = loadval(js, next + sizeof(ant_offset_t) * 2); + return (ant_offset_t) tod(slot); } - jsval_t slot = get_slot(js, arr, SLOT_DENSE_BUF); + ant_value_t slot = get_slot(js, arr, SLOT_DENSE_BUF); if (vtype(slot) == T_UNDEF) return 0; - return (jsoff_t) tod(slot); + return (ant_offset_t) tod(slot); } -static inline jsoff_t get_dense_buf_off(ant_t *js, jsoff_t obj_off) { +static inline ant_offset_t get_dense_buf_off(ant_t *js, ant_offset_t obj_off) { return get_dense_buf(js, mkval(T_ARR, (uint64_t)obj_off)); } -static inline jsoff_t dense_capacity(ant_t *js, jsoff_t doff) { +static inline ant_offset_t dense_capacity(ant_t *js, ant_offset_t doff) { return loadoff(js, doff); } -static inline jsoff_t dense_length(ant_t *js, jsoff_t doff) { - return loadoff(js, doff + sizeof(jsoff_t)); +static inline ant_offset_t dense_length(ant_t *js, ant_offset_t doff) { + return loadoff(js, doff + sizeof(ant_offset_t)); } -static inline void dense_set_length(ant_t *js, jsoff_t doff, jsoff_t len) { - saveoff(js, doff + sizeof(jsoff_t), len); +static inline void dense_set_length(ant_t *js, ant_offset_t doff, ant_offset_t len) { + saveoff(js, doff + sizeof(ant_offset_t), len); } -static inline jsval_t dense_get(ant_t *js, jsoff_t doff, jsoff_t idx) { - return loadval(js, doff + sizeof(jsoff_t) * 2 + sizeof(jsval_t) * idx); +static inline ant_value_t dense_get(ant_t *js, ant_offset_t doff, ant_offset_t idx) { + return loadval(js, doff + sizeof(ant_offset_t) * 2 + sizeof(ant_value_t) * idx); } -static inline void dense_set(ant_t *js, jsoff_t doff, jsoff_t idx, jsval_t val) { - saveval(js, doff + sizeof(jsoff_t) * 2 + sizeof(jsval_t) * idx, val); +static inline void dense_set(ant_t *js, ant_offset_t doff, ant_offset_t idx, ant_value_t val) { + saveval(js, doff + sizeof(ant_offset_t) * 2 + sizeof(ant_value_t) * idx, val); } -static jsoff_t dense_grow(ant_t *js, jsval_t arr, jsoff_t needed) { - jsoff_t doff = get_dense_buf(js, arr); - jsoff_t old_cap = doff ? dense_capacity(js, doff) : 0; - jsoff_t old_len = doff ? dense_length(js, doff) : 0; - jsoff_t new_cap = old_cap ? old_cap : MAX_DENSE_INITIAL_CAP; +static ant_offset_t dense_grow(ant_t *js, ant_value_t arr, ant_offset_t needed) { + ant_offset_t doff = get_dense_buf(js, arr); + ant_offset_t old_cap = doff ? dense_capacity(js, doff) : 0; + ant_offset_t old_len = doff ? dense_length(js, doff) : 0; + ant_offset_t new_cap = old_cap ? old_cap : MAX_DENSE_INITIAL_CAP; while (new_cap < needed) new_cap *= 2; - jsoff_t new_doff = dense_alloc(js, new_cap); + ant_offset_t new_doff = dense_alloc(js, new_cap); if (new_doff == 0) return 0; if (doff && old_len > 0) memcpy( - &js->mem[new_doff + sizeof(jsoff_t) * 2], - &js->mem[doff + sizeof(jsoff_t) * 2], - sizeof(jsval_t) * old_len + &js->mem[new_doff + sizeof(ant_offset_t) * 2], + &js->mem[doff + sizeof(ant_offset_t) * 2], + sizeof(ant_value_t) * old_len ); dense_set_length(js, new_doff, old_len); @@ -1996,13 +1996,13 @@ static jsoff_t dense_grow(ant_t *js, jsval_t arr, jsoff_t needed) { return new_doff; } -static inline jsval_t arr_get(ant_t *js, jsval_t arr, jsoff_t idx) { - jsoff_t doff = get_dense_buf(js, arr); +static inline ant_value_t arr_get(ant_t *js, ant_value_t arr, ant_offset_t idx) { + ant_offset_t doff = get_dense_buf(js, arr); if (doff) { - jsoff_t len = dense_length(js, doff); + ant_offset_t len = dense_length(js, doff); if (idx < len) { - jsval_t v = dense_get(js, doff, idx); + ant_value_t v = dense_get(js, doff, idx); if (!is_empty_slot(v)) return v; return js_mkundef(); } @@ -2010,33 +2010,33 @@ static inline jsval_t arr_get(ant_t *js, jsval_t arr, jsoff_t idx) { char idxstr[16]; size_t idxlen = uint_to_str(idxstr, sizeof(idxstr), (unsigned)idx); - jsoff_t prop = lkp(js, arr, idxstr, idxlen); + ant_offset_t prop = lkp(js, arr, idxstr, idxlen); return prop ? resolveprop(js, mkval(T_PROP, prop)) : js_mkundef(); } -static inline void arr_set(ant_t *js, jsval_t arr, jsoff_t idx, jsval_t val) { - jsoff_t doff = get_dense_buf(js, arr); +static inline void arr_set(ant_t *js, ant_value_t arr, ant_offset_t idx, ant_value_t val) { + ant_offset_t doff = get_dense_buf(js, arr); if (doff) { - jsoff_t len = dense_length(js, doff); + ant_offset_t len = dense_length(js, doff); if (idx < len) { dense_set(js, doff, idx, val); return; } - jsoff_t density_limit = len > 0 ? len * 4 : 64; + ant_offset_t density_limit = len > 0 ? len * 4 : 64; if (idx >= density_limit) goto sparse; - jsoff_t cap = dense_capacity(js, doff); + ant_offset_t cap = dense_capacity(js, doff); if (idx >= cap) { doff = dense_grow(js, arr, idx + 1); if (doff == 0) goto sparse; } - for (jsoff_t i = len; i < idx; i++) { - jsval_t v = dense_get(js, doff, i); + for (ant_offset_t i = len; i < idx; i++) { + ant_value_t v = dense_get(js, doff, i); if (!is_empty_slot(v) && vtype(v) == T_UNDEF) dense_set(js, doff, i, T_EMPTY); } dense_set(js, doff, idx, val); @@ -2047,16 +2047,16 @@ static inline void arr_set(ant_t *js, jsval_t arr, jsoff_t idx, jsval_t val) { sparse:; char idxstr[24]; size_t idxlen = uint_to_str(idxstr, sizeof(idxstr), (uint64_t)idx); - jsval_t key = js_mkstr(js, idxstr, idxlen); + ant_value_t key = js_mkstr(js, idxstr, idxlen); js_setprop(js, arr, key, val); } -static inline bool arr_has(ant_t *js, jsval_t arr, jsoff_t idx) { - jsoff_t doff = get_dense_buf(js, arr); +static inline bool arr_has(ant_t *js, ant_value_t arr, ant_offset_t idx) { + ant_offset_t doff = get_dense_buf(js, arr); if (doff) { - jsoff_t len = dense_length(js, doff); + ant_offset_t len = dense_length(js, doff); if (idx < len) return !is_empty_slot(dense_get(js, doff, idx)); } @@ -2065,11 +2065,11 @@ static inline bool arr_has(ant_t *js, jsval_t arr, jsoff_t idx) { return lkp(js, arr, idxstr, idxlen) != 0; } -static inline void arr_del(ant_t *js, jsval_t arr, jsoff_t idx) { - jsoff_t doff = get_dense_buf(js, arr); +static inline void arr_del(ant_t *js, ant_value_t arr, ant_offset_t idx) { + ant_offset_t doff = get_dense_buf(js, arr); if (doff) { - jsoff_t len = dense_length(js, doff); + ant_offset_t len = dense_length(js, doff); if (idx < len) dense_set(js, doff, idx, T_EMPTY); return; } @@ -2079,9 +2079,9 @@ static inline void arr_del(ant_t *js, jsval_t arr, jsoff_t idx) { js_del(js, arr, idxstr); } -static jsval_t mkentity(ant_t *js, jsoff_t b, const void *buf, size_t len) { - jsoff_t ofs = js_alloc(js, len + sizeof(b)); - if (ofs == (jsoff_t) ~0) return js_mkerr(js, "oom"); +static ant_value_t mkentity(ant_t *js, ant_offset_t b, const void *buf, size_t len) { + ant_offset_t ofs = js_alloc(js, len + sizeof(b)); + if (ofs == (ant_offset_t) ~0) return js_mkerr(js, "oom"); memcpy(&js->mem[ofs], &b, sizeof(b)); if (buf != NULL) { @@ -2093,17 +2093,17 @@ static jsval_t mkentity(ant_t *js, jsoff_t b, const void *buf, size_t len) { return mkval(b & 3, ofs); } -jsval_t js_mkstr(ant_t *js, const void *ptr, size_t len) { - jsoff_t n = (jsoff_t) (len + 1); - return mkentity(js, (jsoff_t) ((n << 3) | T_STR), ptr, n); +ant_value_t js_mkstr(ant_t *js, const void *ptr, size_t len) { + ant_offset_t n = (ant_offset_t) (len + 1); + return mkentity(js, (ant_offset_t) ((n << 3) | T_STR), ptr, n); } -static jsval_t js_mkrope(ant_t *js, jsval_t left, jsval_t right, jsoff_t total_len, uint8_t depth) { - jsoff_t ofs = js_alloc(js, sizeof(rope_node_t)); - if (ofs == (jsoff_t) ~0) return js_mkerr(js, "oom"); +static ant_value_t js_mkrope(ant_t *js, ant_value_t left, ant_value_t right, ant_offset_t total_len, uint8_t depth) { + ant_offset_t ofs = js_alloc(js, sizeof(rope_node_t)); + if (ofs == (ant_offset_t) ~0) return js_mkerr(js, "oom"); - jsoff_t header = ((total_len + 1) << 3) | T_STR | ROPE_FLAG | ((jsoff_t)depth << ROPE_DEPTH_SHIFT); - jsval_t undef = js_mkundef(); + ant_offset_t header = ((total_len + 1) << 3) | T_STR | ROPE_FLAG | ((ant_offset_t)depth << ROPE_DEPTH_SHIFT); + ant_value_t undef = js_mkundef(); memcpy(&js->mem[ofs + offsetof(rope_node_t, header)], &header, sizeof(header)); memcpy(&js->mem[ofs + offsetof(rope_node_t, left)], &left, sizeof(left)); @@ -2113,7 +2113,7 @@ static jsval_t js_mkrope(ant_t *js, jsval_t left, jsval_t right, jsoff_t total_l return mkval(T_STR, ofs); } -static bool bigint_parse_abs_u64(ant_t *js, jsval_t value, uint64_t *out) { +static bool bigint_parse_abs_u64(ant_t *js, ant_value_t value, uint64_t *out) { size_t len = 0; const char *digits = bigint_digits(js, value, &len); uint64_t acc = 0; @@ -2130,21 +2130,21 @@ static bool bigint_parse_abs_u64(ant_t *js, jsval_t value, uint64_t *out) { return true; } -static bool bigint_IsNegative(ant_t *js, jsval_t v) { - jsoff_t ofs = (jsoff_t) vdata(v); - return js->mem[ofs + sizeof(jsoff_t)] == 1; +static bool bigint_IsNegative(ant_t *js, ant_value_t v) { + ant_offset_t ofs = (ant_offset_t) vdata(v); + return js->mem[ofs + sizeof(ant_offset_t)] == 1; } -static bool bigint_parse_u64(ant_t *js, jsval_t value, uint64_t *out) { +static bool bigint_parse_u64(ant_t *js, ant_value_t value, uint64_t *out) { if (bigint_IsNegative(js, value)) return false; return bigint_parse_abs_u64(js, value, out); } -jsval_t js_mkbigint(ant_t *js, const char *digits, size_t len, bool negative) { +ant_value_t js_mkbigint(ant_t *js, const char *digits, size_t len, bool negative) { size_t total = len + 2; - jsoff_t ofs = js_alloc(js, total + sizeof(jsoff_t)); - if (ofs == (jsoff_t) ~0) return js_mkerr(js, "oom"); - jsoff_t header = (jsoff_t) (total << 4); + ant_offset_t ofs = js_alloc(js, total + sizeof(ant_offset_t)); + if (ofs == (ant_offset_t) ~0) return js_mkerr(js, "oom"); + ant_offset_t header = (ant_offset_t) (total << 4); memcpy(&js->mem[ofs], &header, sizeof(header)); js->mem[ofs + sizeof(header)] = negative ? 1 : 0; if (digits) memcpy(&js->mem[ofs + sizeof(header) + 1], digits, len); @@ -2152,12 +2152,12 @@ jsval_t js_mkbigint(ant_t *js, const char *digits, size_t len, bool negative) { return mkval(T_BIGINT, ofs); } -static const char *bigint_digits(ant_t *js, jsval_t v, size_t *len) { - jsoff_t ofs = (jsoff_t) vdata(v); - jsoff_t header = loadoff(js, ofs); +static const char *bigint_digits(ant_t *js, ant_value_t v, size_t *len) { + ant_offset_t ofs = (ant_offset_t) vdata(v); + ant_offset_t header = loadoff(js, ofs); size_t total = (header >> 4) - 2; if (len) *len = total; - return (const char *)&js->mem[ofs + sizeof(jsoff_t) + 1]; + return (const char *)&js->mem[ofs + sizeof(ant_offset_t) + 1]; } static int bigint_cmp_abs(const char *a, size_t alen, const char *b, size_t blen) { @@ -2269,7 +2269,7 @@ static char *bigint_div_abs(const char *a, size_t alen, const char *b, size_t bl return result; } -jsval_t bigint_add(ant_t *js, jsval_t a, jsval_t b) { +ant_value_t bigint_add(ant_t *js, ant_value_t a, ant_value_t b) { bool aneg = bigint_IsNegative(js, a), bneg = bigint_IsNegative(js, b); size_t alen, blen; const char *ad = bigint_digits(js, a, &alen), *bd = bigint_digits(js, b, &blen); @@ -2283,12 +2283,12 @@ jsval_t bigint_add(ant_t *js, jsval_t a, jsval_t b) { } if (!result) return js_mkerr(js, "oom"); if (rlen == 1 && result[0] == '0') rneg = false; - jsval_t r = js_mkbigint(js, result, rlen, rneg); + ant_value_t r = js_mkbigint(js, result, rlen, rneg); free(result); return r; } -jsval_t bigint_sub(ant_t *js, jsval_t a, jsval_t b) { +ant_value_t bigint_sub(ant_t *js, ant_value_t a, ant_value_t b) { bool aneg = bigint_IsNegative(js, a), bneg = bigint_IsNegative(js, b); size_t alen, blen; const char *ad = bigint_digits(js, a, &alen), *bd = bigint_digits(js, b, &blen); @@ -2302,12 +2302,12 @@ jsval_t bigint_sub(ant_t *js, jsval_t a, jsval_t b) { } if (!result) return js_mkerr(js, "oom"); if (rlen == 1 && result[0] == '0') rneg = false; - jsval_t r = js_mkbigint(js, result, rlen, rneg); + ant_value_t r = js_mkbigint(js, result, rlen, rneg); free(result); return r; } -jsval_t bigint_mul(ant_t *js, jsval_t a, jsval_t b) { +ant_value_t bigint_mul(ant_t *js, ant_value_t a, ant_value_t b) { bool aneg = bigint_IsNegative(js, a), bneg = bigint_IsNegative(js, b); size_t alen, blen; const char *ad = bigint_digits(js, a, &alen), *bd = bigint_digits(js, b, &blen); @@ -2315,12 +2315,12 @@ jsval_t bigint_mul(ant_t *js, jsval_t a, jsval_t b) { char *result = bigint_mul_abs(ad, alen, bd, blen, &rlen); if (!result) return js_mkerr(js, "oom"); bool rneg = (aneg != bneg) && !(rlen == 1 && result[0] == '0'); - jsval_t r = js_mkbigint(js, result, rlen, rneg); + ant_value_t r = js_mkbigint(js, result, rlen, rneg); free(result); return r; } -jsval_t bigint_div(ant_t *js, jsval_t a, jsval_t b) { +ant_value_t bigint_div(ant_t *js, ant_value_t a, ant_value_t b) { bool aneg = bigint_IsNegative(js, a), bneg = bigint_IsNegative(js, b); size_t alen, blen; const char *ad = bigint_digits(js, a, &alen), *bd = bigint_digits(js, b, &blen); @@ -2329,12 +2329,12 @@ jsval_t bigint_div(ant_t *js, jsval_t a, jsval_t b) { char *result = bigint_div_abs(ad, alen, bd, blen, &rlen, NULL, NULL); if (!result) return js_mkerr(js, "oom"); bool rneg = (aneg != bneg) && !(rlen == 1 && result[0] == '0'); - jsval_t r = js_mkbigint(js, result, rlen, rneg); + ant_value_t r = js_mkbigint(js, result, rlen, rneg); free(result); return r; } -jsval_t bigint_mod(ant_t *js, jsval_t a, jsval_t b) { +ant_value_t bigint_mod(ant_t *js, ant_value_t a, ant_value_t b) { bool aneg = bigint_IsNegative(js, a); size_t alen, blen; const char *ad = bigint_digits(js, a, &alen), *bd = bigint_digits(js, b, &blen); @@ -2344,12 +2344,12 @@ jsval_t bigint_mod(ant_t *js, jsval_t a, jsval_t b) { if (!result) return js_mkerr(js, "oom"); free(result); bool rneg = aneg && !(remlen == 1 && rem[0] == '0'); - jsval_t r = js_mkbigint(js, rem, remlen, rneg); + ant_value_t r = js_mkbigint(js, rem, remlen, rneg); free(rem); return r; } -jsval_t bigint_neg(ant_t *js, jsval_t a) { +ant_value_t bigint_neg(ant_t *js, ant_value_t a) { size_t len; const char *digits = bigint_digits(js, a, &len); bool neg = bigint_IsNegative(js, a); @@ -2357,15 +2357,15 @@ jsval_t bigint_neg(ant_t *js, jsval_t a) { return js_mkbigint(js, digits, len, !neg); } -jsval_t bigint_exp(ant_t *js, jsval_t base, jsval_t exp) { +ant_value_t bigint_exp(ant_t *js, ant_value_t base, ant_value_t exp) { if (bigint_IsNegative(js, exp)) return js_mkerr(js, "Exponent must be positive"); size_t explen; const char *expd = bigint_digits(js, exp, &explen); if (explen == 1 && expd[0] == '0') return js_mkbigint(js, "1", 1, false); - jsval_t result = js_mkbigint(js, "1", 1, false); - jsval_t b = base; - jsval_t e = exp; - jsval_t two = js_mkbigint(js, "2", 1, false); + ant_value_t result = js_mkbigint(js, "1", 1, false); + ant_value_t b = base; + ant_value_t e = exp; + ant_value_t two = js_mkbigint(js, "2", 1, false); while (true) { size_t elen; const char *ed = bigint_digits(js, e, &elen); @@ -2383,15 +2383,15 @@ jsval_t bigint_exp(ant_t *js, jsval_t base, jsval_t exp) { return result; } -static inline jsval_t bigint_pow2(ant_t *js, uint64_t bits) { - jsval_t two = js_mkbigint(js, "2", 1, false); +static inline ant_value_t bigint_pow2(ant_t *js, uint64_t bits) { + ant_value_t two = js_mkbigint(js, "2", 1, false); if (is_err(two)) return two; - jsval_t exp = bigint_from_u64(js, bits); + ant_value_t exp = bigint_from_u64(js, bits); if (is_err(exp)) return exp; return bigint_exp(js, two, exp); } -jsval_t bigint_shift_left(ant_t *js, jsval_t value, uint64_t shift) { +ant_value_t bigint_shift_left(ant_t *js, ant_value_t value, uint64_t shift) { if (shift == 0) return value; if (shift > 18446744073709551615ULL) return js_mkerr(js, "Shift count too large"); @@ -2402,12 +2402,12 @@ jsval_t bigint_shift_left(ant_t *js, jsval_t value, uint64_t shift) { if (u64 <= (UINT64_MAX >> shift)) return bigint_from_u64(js, u64 << shift); } - jsval_t pow = bigint_pow2(js, shift); + ant_value_t pow = bigint_pow2(js, shift); if (is_err(pow)) return pow; return bigint_mul(js, value, pow); } -jsval_t bigint_shift_right(ant_t *js, jsval_t value, uint64_t shift) { +ant_value_t bigint_shift_right(ant_t *js, ant_value_t value, uint64_t shift) { if (shift == 0) return value; if (shift > 18446744073709551615ULL) return js_mkerr(js, "Shift count too large"); @@ -2427,23 +2427,23 @@ jsval_t bigint_shift_right(ant_t *js, jsval_t value, uint64_t shift) { uint64_t shifted = u64 >> shift; if (bigint_IsNegative(js, value)) { if ((u64 & ((1ULL << shift) - 1)) != 0) shifted += 1; - jsval_t pos = bigint_from_u64(js, shifted); + ant_value_t pos = bigint_from_u64(js, shifted); if (is_err(pos)) return pos; return bigint_neg(js, pos); } return bigint_from_u64(js, shifted); } - jsval_t pow = bigint_pow2(js, shift); + ant_value_t pow = bigint_pow2(js, shift); if (is_err(pow)) return pow; return bigint_div(js, value, pow); } -jsval_t bigint_shift_right_logical(ant_t *js, jsval_t value, uint64_t shift) { +ant_value_t bigint_shift_right_logical(ant_t *js, ant_value_t value, uint64_t shift) { return js_mkerr_typed(js, JS_ERR_TYPE, "BigInts have no unsigned right shift, use >> instead"); } -int bigint_compare(ant_t *js, jsval_t a, jsval_t b) { +int bigint_compare(ant_t *js, ant_value_t a, ant_value_t b) { bool aneg = bigint_IsNegative(js, a), bneg = bigint_IsNegative(js, b); size_t alen, blen; const char *ad = bigint_digits(js, a, &alen), *bd = bigint_digits(js, b, &blen); @@ -2453,13 +2453,13 @@ int bigint_compare(ant_t *js, jsval_t a, jsval_t b) { return aneg ? -cmp : cmp; } -static bool bigint_is_zero(ant_t *js, jsval_t v) { +static bool bigint_is_zero(ant_t *js, ant_value_t v) { size_t len; const char *digits = bigint_digits(js, v, &len); return len == 1 && digits[0] == '0'; } -static size_t strbigint(ant_t *js, jsval_t value, char *buf, size_t len) { +static size_t strbigint(ant_t *js, ant_value_t value, char *buf, size_t len) { bool neg = bigint_IsNegative(js, value); size_t dlen; const char *digits = bigint_digits(js, value, &dlen); @@ -2469,11 +2469,11 @@ static size_t strbigint(ant_t *js, jsval_t value, char *buf, size_t len) { return n; } -static jsval_t builtin_BigInt(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_BigInt(ant_t *js, ant_value_t *args, int nargs) { if (vtype(js->new_target) != T_UNDEF) return js_mkerr_typed(js, JS_ERR_TYPE, "BigInt is not a constructor"); if (nargs < 1) return js_mkbigint(js, "0", 1, false); - jsval_t arg = args[0]; + ant_value_t arg = args[0]; if (vtype(arg) == T_BIGINT) return arg; if (vtype(arg) == T_NUM) { double d = tod(arg); @@ -2486,7 +2486,7 @@ static jsval_t builtin_BigInt(ant_t *js, jsval_t *args, int nargs) { return js_mkbigint(js, buf, strlen(buf), neg); } if (vtype(arg) == T_STR) { - jsoff_t slen, off = vstr(js, arg, &slen); + ant_offset_t slen, off = vstr(js, arg, &slen); const char *str = (const char *)&js->mem[off]; bool neg = false; size_t i = 0; @@ -2505,14 +2505,14 @@ static jsval_t builtin_BigInt(ant_t *js, jsval_t *args, int nargs) { return js_mkerr(js, "Cannot convert to BigInt"); } -static jsval_t bigint_to_u64(ant_t *js, jsval_t value, uint64_t *out) { +static ant_value_t bigint_to_u64(ant_t *js, ant_value_t value, uint64_t *out) { if (!bigint_parse_u64(js, value, out)) { return js_mkerr_typed(js, JS_ERR_RANGE, "Invalid bits"); } return js_mkundef(); } -jsval_t bigint_asint_bits(ant_t *js, jsval_t arg, uint64_t *bits_out) { +ant_value_t bigint_asint_bits(ant_t *js, ant_value_t arg, uint64_t *bits_out) { if (vtype(arg) == T_BIGINT) { return bigint_to_u64(js, arg, bits_out); } @@ -2527,60 +2527,60 @@ jsval_t bigint_asint_bits(ant_t *js, jsval_t arg, uint64_t *bits_out) { return js_mkundef(); } -static jsval_t builtin_BigInt_asIntN(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_BigInt_asIntN(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "BigInt.asIntN requires 2 arguments"); uint64_t bits = 0; - jsval_t err = bigint_asint_bits(js, args[0], &bits); + ant_value_t err = bigint_asint_bits(js, args[0], &bits); if (is_err(err)) return err; if (vtype(args[1]) != T_BIGINT) { return js_mkerr_typed(js, JS_ERR_TYPE, "Cannot convert to BigInt"); } if (bits == 0) return js_mkbigint(js, "0", 1, false); - jsval_t mod = bigint_pow2(js, bits); + ant_value_t mod = bigint_pow2(js, bits); if (is_err(mod)) return mod; - jsval_t res = bigint_mod(js, args[1], mod); + ant_value_t res = bigint_mod(js, args[1], mod); if (is_err(res)) return res; if (bigint_IsNegative(js, res)) { - jsval_t adj = bigint_add(js, res, mod); + ant_value_t adj = bigint_add(js, res, mod); if (is_err(adj)) return adj; res = adj; } - jsval_t threshold = bigint_pow2(js, bits - 1); + ant_value_t threshold = bigint_pow2(js, bits - 1); if (is_err(threshold)) return threshold; if (bigint_compare(js, res, threshold) >= 0) { - jsval_t adj = bigint_sub(js, res, mod); + ant_value_t adj = bigint_sub(js, res, mod); if (is_err(adj)) return adj; res = adj; } return res; } -static jsval_t builtin_BigInt_asUintN(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_BigInt_asUintN(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "BigInt.asUintN requires 2 arguments"); uint64_t bits = 0; - jsval_t err = bigint_asint_bits(js, args[0], &bits); + ant_value_t err = bigint_asint_bits(js, args[0], &bits); if (is_err(err)) return err; if (vtype(args[1]) != T_BIGINT) { return js_mkerr_typed(js, JS_ERR_TYPE, "Cannot convert to BigInt"); } if (bits == 0) return js_mkbigint(js, "0", 1, false); - jsval_t mod = bigint_pow2(js, bits); + ant_value_t mod = bigint_pow2(js, bits); if (is_err(mod)) return mod; - jsval_t res = bigint_mod(js, args[1], mod); + ant_value_t res = bigint_mod(js, args[1], mod); if (is_err(res)) return res; if (bigint_IsNegative(js, res)) { - jsval_t adj = bigint_add(js, res, mod); + ant_value_t adj = bigint_add(js, res, mod); if (is_err(adj)) return adj; res = adj; } return res; } -static jsval_t builtin_bigint_toString(ant_t *js, jsval_t *args, int nargs) { - jsval_t val = js->this_val; +static ant_value_t builtin_bigint_toString(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t val = js->this_val; if (vtype(val) != T_BIGINT) return js_mkerr(js, "toString called on non-BigInt"); int radix = 10; @@ -2598,7 +2598,7 @@ static jsval_t builtin_bigint_toString(ant_t *js, jsval_t *args, int nargs) { if (!buf) return js_mkerr(js, "oom"); size_t n = 0; if (neg) buf[n++] = '-'; memcpy(buf + n, digits, dlen); n += dlen; - jsval_t ret = js_mkstr(js, buf, n); free(buf); + ant_value_t ret = js_mkstr(js, buf, n); free(buf); return ret; } @@ -2666,59 +2666,59 @@ static jsval_t builtin_bigint_toString(ant_t *js, jsval_t *args, int nargs) { if (rpos == result_cap - 1) result[--rpos] = '0'; if (neg) result[--rpos] = '-'; - jsval_t ret = js_mkstr(js, result + rpos, result_cap - 1 - rpos); + ant_value_t ret = js_mkstr(js, result + rpos, result_cap - 1 - rpos); free(result); return ret; } -jsval_t mkobj(ant_t *js, jsoff_t parent) { - jsoff_t buf[2] = { parent, 0 }; +ant_value_t mkobj(ant_t *js, ant_offset_t parent) { + ant_offset_t buf[2] = { parent, 0 }; return mkentity(js, 0 | T_OBJ, buf, sizeof(buf)); } -jsval_t mkarr(ant_t *js) { - jsval_t arr = mkobj(js, 0); - jsoff_t off = (jsoff_t) vdata(arr); - jsoff_t header = loadoff(js, off); +ant_value_t mkarr(ant_t *js) { + ant_value_t arr = mkobj(js, 0); + ant_offset_t off = (ant_offset_t) vdata(arr); + ant_offset_t header = loadoff(js, off); saveoff(js, off, header | ARRMASK); - jsval_t array_proto = get_ctor_proto(js, "Array", 5); + ant_value_t array_proto = get_ctor_proto(js, "Array", 5); if (vtype(array_proto) == T_OBJ) set_proto(js, arr, array_proto); - jsval_t arr_val = mkval(T_ARR, vdata(arr)); - jsoff_t doff = dense_alloc(js, MAX_DENSE_INITIAL_CAP); + ant_value_t arr_val = mkval(T_ARR, vdata(arr)); + ant_offset_t doff = dense_alloc(js, MAX_DENSE_INITIAL_CAP); if (doff) set_slot(js, arr_val, SLOT_DENSE_BUF, tov((double)doff)); return arr_val; } -jsval_t js_mkarr(ant_t *js) { +ant_value_t js_mkarr(ant_t *js) { return mkarr(js); } -jsval_t js_newobj(ant_t *js) { - jsval_t obj = mkobj(js, 0); - jsval_t proto = get_ctor_proto(js, "Object", 6); +ant_value_t js_newobj(ant_t *js) { + ant_value_t obj = mkobj(js, 0); + ant_value_t proto = get_ctor_proto(js, "Object", 6); if (vtype(proto) == T_OBJ) set_proto(js, obj, proto); return obj; } -jsoff_t js_arr_len(ant_t *js, jsval_t arr) { +ant_offset_t js_arr_len(ant_t *js, ant_value_t arr) { if (vtype(arr) != T_ARR) return 0; return get_array_length(js, arr); } -jsval_t js_arr_get(ant_t *js, jsval_t arr, jsoff_t idx) { +ant_value_t js_arr_get(ant_t *js, ant_value_t arr, ant_offset_t idx) { if (vtype(arr) != T_ARR) return js_mkundef(); return arr_get(js, arr, idx); } -static inline bool is_const_prop(ant_t *js, jsoff_t propoff) { - jsoff_t v = loadoff(js, propoff); +static inline bool is_const_prop(ant_t *js, ant_offset_t propoff) { + ant_offset_t v = loadoff(js, propoff); return (v & CONSTMASK) != 0; } -static inline bool is_nonconfig_prop(ant_t *js, jsoff_t propoff) { - jsoff_t v = loadoff(js, propoff); +static inline bool is_nonconfig_prop(ant_t *js, ant_offset_t propoff) { + ant_offset_t v = loadoff(js, propoff); return (v & NONCONFIGMASK) != 0; } @@ -2747,11 +2747,11 @@ static void intern_init(void) { INTERN_IDX[9] = intern_string("9", 1); } -static void invalidate_prop_cache(ant_t *js, jsoff_t obj_off, jsoff_t prop_off) { - jsoff_t koff = loadoff(js, prop_off + sizeof(jsoff_t)); - jsoff_t klen = (loadoff(js, koff) >> 3) - 1; +static void invalidate_prop_cache(ant_t *js, ant_offset_t obj_off, ant_offset_t prop_off) { + ant_offset_t koff = loadoff(js, prop_off + sizeof(ant_offset_t)); + ant_offset_t klen = (loadoff(js, koff) >> 3) - 1; - const char *key = (char *)&js->mem[koff + sizeof(jsoff_t)]; + const char *key = (char *)&js->mem[koff + sizeof(ant_offset_t)]; const char *interned = intern_string(key, klen); if (!interned) return; @@ -2760,158 +2760,158 @@ static void invalidate_prop_cache(ant_t *js, jsoff_t obj_off, jsoff_t prop_off) if (ce->obj_off == obj_off && ce->intern_ptr == interned) ce->generation = 0; } -jsval_t mkprop(ant_t *js, jsval_t obj, jsval_t k, jsval_t v, jsoff_t flags) { +ant_value_t mkprop(ant_t *js, ant_value_t obj, ant_value_t k, ant_value_t v, ant_offset_t flags) { obj = js_as_obj(obj); - jsoff_t koff_entity; + ant_offset_t koff_entity; if (vtype(k) == T_SYMBOL) { - koff_entity = (jsoff_t)vdata(k); + koff_entity = (ant_offset_t)vdata(k); } else { - jsoff_t klen; jsoff_t koff = vstr(js, k, &klen); - koff_entity = koff - sizeof(jsoff_t); + ant_offset_t klen; ant_offset_t koff = vstr(js, k, &klen); + koff_entity = koff - sizeof(ant_offset_t); const char *p = (char *) &js->mem[koff]; (void)intern_string(p, klen); } - jsoff_t head = (jsoff_t) vdata(obj); + ant_offset_t head = (ant_offset_t) vdata(obj); char buf[sizeof(koff_entity) + sizeof(v)]; - jsoff_t header = loadoff(js, head); - jsoff_t first_prop = header & ~(3U | FLAGMASK); - jsoff_t tail = loadoff(js, head + sizeof(jsoff_t) + sizeof(jsoff_t)); + ant_offset_t header = loadoff(js, head); + ant_offset_t first_prop = header & ~(3U | FLAGMASK); + ant_offset_t tail = loadoff(js, head + sizeof(ant_offset_t) + sizeof(ant_offset_t)); memcpy(buf, &koff_entity, sizeof(koff_entity)); memcpy(buf + sizeof(koff_entity), &v, sizeof(v)); - jsoff_t new_prop_off = js->brk; - jsval_t prop = mkentity(js, 0 | T_PROP | flags, buf, sizeof(buf)); + ant_offset_t new_prop_off = js->brk; + ant_value_t prop = mkentity(js, 0 | T_PROP | flags, buf, sizeof(buf)); if (is_err(prop)) return prop; if (first_prop == 0) { - jsoff_t new_header = new_prop_off | (header & (3U | FLAGMASK)); + ant_offset_t new_header = new_prop_off | (header & (3U | FLAGMASK)); saveoff(js, head, new_header); } else { - jsoff_t tail_header = loadoff(js, tail); - jsoff_t new_tail_header = new_prop_off | (tail_header & (3U | FLAGMASK)); + ant_offset_t tail_header = loadoff(js, tail); + ant_offset_t new_tail_header = new_prop_off | (tail_header & (3U | FLAGMASK)); saveoff(js, tail, new_tail_header); } - saveoff(js, head + sizeof(jsoff_t) + sizeof(jsoff_t), new_prop_off); + saveoff(js, head + sizeof(ant_offset_t) + sizeof(ant_offset_t), new_prop_off); return prop; } -static inline jsval_t mkprop_fast(ant_t *js, jsval_t obj, jsval_t k, jsval_t v, jsoff_t flags) { +static inline ant_value_t mkprop_fast(ant_t *js, ant_value_t obj, ant_value_t k, ant_value_t v, ant_offset_t flags) { obj = js_as_obj(obj); - jsoff_t koff_entity; + ant_offset_t koff_entity; if (vtype(k) == T_SYMBOL) { - koff_entity = (jsoff_t)vdata(k); + koff_entity = (ant_offset_t)vdata(k); } else { - jsoff_t klen; jsoff_t koff = vstr(js, k, &klen); - koff_entity = koff - sizeof(jsoff_t); + ant_offset_t klen; ant_offset_t koff = vstr(js, k, &klen); + koff_entity = koff - sizeof(ant_offset_t); } - jsoff_t head = (jsoff_t) vdata(obj); + ant_offset_t head = (ant_offset_t) vdata(obj); char buf[sizeof(koff_entity) + sizeof(v)]; - jsoff_t header = loadoff(js, head); - jsoff_t first_prop = header & ~(3U | FLAGMASK); - jsoff_t tail = loadoff(js, head + sizeof(jsoff_t) + sizeof(jsoff_t)); + ant_offset_t header = loadoff(js, head); + ant_offset_t first_prop = header & ~(3U | FLAGMASK); + ant_offset_t tail = loadoff(js, head + sizeof(ant_offset_t) + sizeof(ant_offset_t)); memcpy(buf, &koff_entity, sizeof(koff_entity)); memcpy(buf + sizeof(koff_entity), &v, sizeof(v)); - jsoff_t new_prop_off = js->brk; - jsval_t prop = mkentity(js, 0 | T_PROP | flags, buf, sizeof(buf)); + ant_offset_t new_prop_off = js->brk; + ant_value_t prop = mkentity(js, 0 | T_PROP | flags, buf, sizeof(buf)); if (is_err(prop)) return prop; if (first_prop == 0) { - jsoff_t new_header = new_prop_off | (header & (3U | FLAGMASK)); + ant_offset_t new_header = new_prop_off | (header & (3U | FLAGMASK)); saveoff(js, head, new_header); } else { - jsoff_t tail_header = loadoff(js, tail); - jsoff_t new_tail_header = new_prop_off | (tail_header & (3U | FLAGMASK)); + ant_offset_t tail_header = loadoff(js, tail); + ant_offset_t new_tail_header = new_prop_off | (tail_header & (3U | FLAGMASK)); saveoff(js, tail, new_tail_header); } - saveoff(js, head + sizeof(jsoff_t) + sizeof(jsoff_t), new_prop_off); + saveoff(js, head + sizeof(ant_offset_t) + sizeof(ant_offset_t), new_prop_off); return prop; } -jsval_t js_mkprop_fast(ant_t *js, jsval_t obj, const char *key, size_t len, jsval_t v) { - jsval_t k = js_mkstr(js, key, len); +ant_value_t js_mkprop_fast(ant_t *js, ant_value_t obj, const char *key, size_t len, ant_value_t v) { + ant_value_t k = js_mkstr(js, key, len); if (is_err(k)) return k; return mkprop_fast(js, obj, k, v, 0); } -jsoff_t js_mkprop_fast_off(ant_t *js, jsval_t obj, const char *key, size_t len, jsval_t v) { - jsval_t k = js_mkstr(js, key, len); +ant_offset_t js_mkprop_fast_off(ant_t *js, ant_value_t obj, const char *key, size_t len, ant_value_t v) { + ant_value_t k = js_mkstr(js, key, len); if (is_err(k)) return 0; - jsoff_t prop_off = js->brk; + ant_offset_t prop_off = js->brk; mkprop_fast(js, obj, k, v, 0); - return prop_off + sizeof(jsoff_t) * 2; + return prop_off + sizeof(ant_offset_t) * 2; } -void js_saveval(ant_t *js, jsoff_t off, jsval_t v) { saveval(js, off, v); } +void js_saveval(ant_t *js, ant_offset_t off, ant_value_t v) { saveval(js, off, v); } -static jsval_t mkslot(ant_t *js, jsval_t obj, internal_slot_t slot, jsval_t v) { +static ant_value_t mkslot(ant_t *js, ant_value_t obj, internal_slot_t slot, ant_value_t v) { obj = js_as_obj(obj); - jsoff_t head = (jsoff_t) vdata(obj); - char buf[sizeof(jsoff_t) + sizeof(v)]; + ant_offset_t head = (ant_offset_t) vdata(obj); + char buf[sizeof(ant_offset_t) + sizeof(v)]; - jsoff_t header = loadoff(js, head); - jsoff_t first_prop = header & ~(3U | FLAGMASK); + ant_offset_t header = loadoff(js, head); + ant_offset_t first_prop = header & ~(3U | FLAGMASK); - jsoff_t slot_key = (jsoff_t)slot; + ant_offset_t slot_key = (ant_offset_t)slot; memcpy(buf, &slot_key, sizeof(slot_key)); memcpy(buf + sizeof(slot_key), &v, sizeof(v)); - jsoff_t new_prop_off = js->brk; - jsval_t prop = mkentity(js, first_prop | T_PROP | SLOTMASK, buf, sizeof(buf)); + ant_offset_t new_prop_off = js->brk; + ant_value_t prop = mkentity(js, first_prop | T_PROP | SLOTMASK, buf, sizeof(buf)); if (is_err(prop)) return prop; - jsoff_t new_header = new_prop_off | (header & (3U | FLAGMASK)); + ant_offset_t new_header = new_prop_off | (header & (3U | FLAGMASK)); saveoff(js, head, new_header); if (first_prop == 0) { - saveoff(js, head + sizeof(jsoff_t) + sizeof(jsoff_t), new_prop_off); + saveoff(js, head + sizeof(ant_offset_t) + sizeof(ant_offset_t), new_prop_off); } return prop; } -static inline jsoff_t search_slot(ant_t *js, jsval_t obj, internal_slot_t slot) { +static inline ant_offset_t search_slot(ant_t *js, ant_value_t obj, internal_slot_t slot) { obj = js_as_obj(obj); - jsoff_t off = (jsoff_t) vdata(obj); + ant_offset_t off = (ant_offset_t) vdata(obj); if (__builtin_expect(off >= js->brk, 0)) return 0; - jsoff_t next = loadoff(js, off) & ~(3U | FLAGMASK); + ant_offset_t next = loadoff(js, off) & ~(3U | FLAGMASK); while (next != 0 && next < js->brk) { - jsoff_t header = loadoff(js, next); + ant_offset_t header = loadoff(js, next); if ((header & SLOTMASK) == 0) return 0; - jsoff_t koff = loadoff(js, next + sizeof(jsoff_t)); - if (koff == (jsoff_t)slot) return next; + ant_offset_t koff = loadoff(js, next + sizeof(ant_offset_t)); + if (koff == (ant_offset_t)slot) return next; next = header & ~(3U | FLAGMASK); } return 0; } -static void set_slot(ant_t *js, jsval_t obj, internal_slot_t slot, jsval_t val) { - jsoff_t existing = search_slot(js, obj, slot); +static void set_slot(ant_t *js, ant_value_t obj, internal_slot_t slot, ant_value_t val) { + ant_offset_t existing = search_slot(js, obj, slot); if (existing > 0) { - saveval(js, existing + sizeof(jsoff_t) * 2, val); + saveval(js, existing + sizeof(ant_offset_t) * 2, val); } else mkslot(js, obj, slot, val); } -static jsval_t get_slot(ant_t *js, jsval_t obj, internal_slot_t slot) { - jsoff_t off = search_slot(js, obj, slot); +static ant_value_t get_slot(ant_t *js, ant_value_t obj, internal_slot_t slot) { + ant_offset_t off = search_slot(js, obj, slot); if (off == 0) return js_mkundef(); - return loadval(js, off + sizeof(jsoff_t) * 2); + return loadval(js, off + sizeof(ant_offset_t) * 2); } -static void set_func_code_ptr(ant_t *js, jsval_t func_obj, const char *code, size_t len) { +static void set_func_code_ptr(ant_t *js, ant_value_t func_obj, const char *code, size_t len) { set_slot(js, func_obj, SLOT_CODE, mkval(T_CFUNC, (size_t)code)); set_slot(js, func_obj, SLOT_CODE_LEN, tov((double)len)); } -static void set_func_code(ant_t *js, jsval_t func_obj, const char *code, size_t len) { +static void set_func_code(ant_t *js, ant_value_t func_obj, const char *code, size_t len) { const char *arena_code = code_arena_alloc(code, len); if (!arena_code) return; set_func_code_ptr(js, func_obj, arena_code, len); @@ -2927,35 +2927,35 @@ static void set_func_code(ant_t *js, jsval_t func_obj, const char *code, size_t } } -static const char *get_func_code(ant_t *js, jsval_t func_obj, jsoff_t *len) { - jsval_t code_val = get_slot(js, func_obj, SLOT_CODE); - jsval_t len_val = get_slot(js, func_obj, SLOT_CODE_LEN); +static const char *get_func_code(ant_t *js, ant_value_t func_obj, ant_offset_t *len) { + ant_value_t code_val = get_slot(js, func_obj, SLOT_CODE); + ant_value_t len_val = get_slot(js, func_obj, SLOT_CODE_LEN); if (vtype(code_val) != T_CFUNC) { if (len) *len = 0; return NULL; } - if (len) *len = (jsoff_t)tod(len_val); + if (len) *len = (ant_offset_t)tod(len_val); return (const char *)vdata(code_val); } -static inline bool is_slot_prop(jsoff_t header) { +static inline bool is_slot_prop(ant_offset_t header) { return (header & SLOTMASK) != 0; } -static inline jsoff_t next_prop(jsoff_t header) { +static inline ant_offset_t next_prop(ant_offset_t header) { return header & ~(3U | FLAGMASK); } -double js_to_number(ant_t *js, jsval_t arg) { +double js_to_number(ant_t *js, ant_value_t arg) { if (vtype(arg) == T_NUM) return tod(arg); if (vtype(arg) == T_BOOL) return vdata(arg) ? 1.0 : 0.0; if (vtype(arg) == T_NULL) return 0.0; if (vtype(arg) == T_UNDEF) return JS_NAN; if (vtype(arg) == T_STR) { - jsoff_t len, off = vstr(js, arg, &len); + ant_offset_t len, off = vstr(js, arg, &len); const char *s = (char *)&js->mem[off], *end; while (*s == ' ' || *s == '\t' || *s == '\n' || *s == '\r') s++; if (!*s) return 0.0; @@ -2966,12 +2966,12 @@ double js_to_number(ant_t *js, jsval_t arg) { if (vtype(arg) == T_OBJ || vtype(arg) == T_ARR) { if (vtype(arg) == T_OBJ) { - jsval_t prim = js_call_valueOf(js, arg); + ant_value_t prim = js_call_valueOf(js, arg); uint8_t pt = vtype(prim); if (pt != T_OBJ && pt != T_ARR && pt != T_FUNC) return js_to_number(js, prim); } - jsval_t str_val = js_tostring_val(js, arg); + ant_value_t str_val = js_tostring_val(js, arg); if (is_err(str_val) || vtype(str_val) != T_STR) return JS_NAN; return js_to_number(js, str_val); } @@ -2979,23 +2979,23 @@ double js_to_number(ant_t *js, jsval_t arg) { return JS_NAN; } -static jsval_t setup_func_prototype(ant_t *js, jsval_t func) { - jsval_t proto_obj = mkobj(js, 0); +static ant_value_t setup_func_prototype(ant_t *js, ant_value_t func) { + ant_value_t proto_obj = mkobj(js, 0); if (is_err(proto_obj)) return proto_obj; - jsval_t object_proto = get_ctor_proto(js, "Object", 6); + ant_value_t object_proto = get_ctor_proto(js, "Object", 6); if (vtype(object_proto) == T_OBJ) { set_proto(js, proto_obj, object_proto); } - jsval_t constructor_key = js_mkstr(js, "constructor", 11); + ant_value_t constructor_key = js_mkstr(js, "constructor", 11); if (is_err(constructor_key)) return constructor_key; - jsval_t res = mkprop(js, proto_obj, constructor_key, func, 0); + ant_value_t res = mkprop(js, proto_obj, constructor_key, func, 0); if (is_err(res)) return res; js_set_descriptor(js, proto_obj, "constructor", 11, JS_DESC_W | JS_DESC_C); - jsval_t prototype_key = js_mkstr(js, "prototype", 9); + ant_value_t prototype_key = js_mkstr(js, "prototype", 9); if (is_err(prototype_key)) return prototype_key; res = js_setprop(js, func, prototype_key, proto_obj); @@ -3005,12 +3005,12 @@ static jsval_t setup_func_prototype(ant_t *js, jsval_t func) { return js_mkundef(); } -static inline bool proto_walk_next(ant_t *js, jsval_t *cur, uint8_t *t, uint8_t flags) { +static inline bool proto_walk_next(ant_t *js, ant_value_t *cur, uint8_t *t, uint8_t flags) { uint8_t ct = *t; if (flags & PROTO_WALK_F_OBJECT_ONLY) { if (!is_object_type(*cur)) return false; - jsval_t next = get_proto(js, *cur); + ant_value_t next = get_proto(js, *cur); uint8_t nt = vtype(next); if (nt == T_NULL || nt == T_UNDEF || !is_object_type(next)) return false; *cur = next; *t = nt; @@ -3018,8 +3018,8 @@ static inline bool proto_walk_next(ant_t *js, jsval_t *cur, uint8_t *t, uint8_t } if (ct == T_OBJ || ct == T_ARR || ct == T_FUNC || ct == T_PROMISE) { - jsval_t as_obj = js_as_obj(*cur); - jsval_t proto = get_slot(js, as_obj, SLOT_PROTO); + ant_value_t as_obj = js_as_obj(*cur); + ant_value_t proto = get_slot(js, as_obj, SLOT_PROTO); uint8_t pt = vtype(proto); if (pt == T_OBJ || pt == T_ARR || pt == T_FUNC) { @@ -3029,7 +3029,7 @@ static inline bool proto_walk_next(ant_t *js, jsval_t *cur, uint8_t *t, uint8_t } if (JS_TYPE_FLAG(ct) & T_NEEDS_PROTO_FALLBACK) { - jsval_t fallback = get_prototype_for_type(js, ct); + ant_value_t fallback = get_prototype_for_type(js, ct); uint8_t ft = vtype(fallback); if (ft == T_NULL || ft == T_UNDEF) return false; *cur = fallback; @@ -3041,7 +3041,7 @@ static inline bool proto_walk_next(ant_t *js, jsval_t *cur, uint8_t *t, uint8_t } if (ct == T_STR || ct == T_NUM || ct == T_BOOL || ct == T_BIGINT || ct == T_SYMBOL) { - jsval_t proto = get_prototype_for_type(js, ct); + ant_value_t proto = get_prototype_for_type(js, ct); uint8_t pt = vtype(proto); if (pt == T_NULL || pt == T_UNDEF) return false; *cur = proto; *t = pt; @@ -3051,14 +3051,14 @@ static inline bool proto_walk_next(ant_t *js, jsval_t *cur, uint8_t *t, uint8_t return false; } -jsval_t js_instance_proto_from_new_target(ant_t *js, jsval_t fallback_proto) { - jsval_t instance_proto = js_mkundef(); +ant_value_t js_instance_proto_from_new_target(ant_t *js, ant_value_t fallback_proto) { + ant_value_t instance_proto = js_mkundef(); if (vtype(js->new_target) == T_FUNC || vtype(js->new_target) == T_CFUNC) { - jsval_t nt_obj = js_as_obj(js->new_target); - jsoff_t nt_proto_off = lkp_interned(js, nt_obj, INTERN_PROTOTYPE, 9); + ant_value_t nt_obj = js_as_obj(js->new_target); + ant_offset_t nt_proto_off = lkp_interned(js, nt_obj, INTERN_PROTOTYPE, 9); if (nt_proto_off != 0) { - jsval_t nt_proto = resolveprop(js, mkval(T_PROP, nt_proto_off)); + ant_value_t nt_proto = resolveprop(js, mkval(T_PROP, nt_proto_off)); if (is_object_type(nt_proto)) instance_proto = nt_proto; } } @@ -3068,9 +3068,9 @@ jsval_t js_instance_proto_from_new_target(ant_t *js, jsval_t fallback_proto) { } return instance_proto; } -bool proto_chain_contains(ant_t *js, jsval_t obj, jsval_t proto_target) { +bool proto_chain_contains(ant_t *js, ant_value_t obj, ant_value_t proto_target) { if (!is_object_type(obj) || !is_object_type(proto_target)) return false; - jsval_t cur = obj; uint8_t t = vtype(cur); + ant_value_t cur = obj; uint8_t t = vtype(cur); for (int depth = 0; depth < MAX_PROTO_CHAIN_DEPTH; depth++) { if (!proto_walk_next(js, &cur, &t, PROTO_WALK_F_OBJECT_ONLY)) break; if (vdata(cur) == vdata(proto_target)) return true; @@ -3078,61 +3078,61 @@ bool proto_chain_contains(ant_t *js, jsval_t obj, jsval_t proto_target) { return false; } -static inline bool is_wrapper_ctor_target(ant_t *js, jsval_t this_val, jsval_t expected_proto) { +static inline bool is_wrapper_ctor_target(ant_t *js, ant_value_t this_val, ant_value_t expected_proto) { if (vtype(js->new_target) == T_UNDEF) return false; if (vtype(this_val) != T_OBJ) return false; if (vtype(get_slot(js, this_val, SLOT_PRIMITIVE)) != T_UNDEF) return false; return proto_chain_contains(js, this_val, expected_proto); } -jsval_t get_ctor_species_value(ant_t *js, jsval_t ctor) { +ant_value_t get_ctor_species_value(ant_t *js, ant_value_t ctor) { if (!is_object_type(ctor) && vtype(ctor) != T_CFUNC) return js_mkundef(); return js_get_sym(js, ctor, get_species_sym()); } -bool same_ctor_identity(ant_t *js, jsval_t a, jsval_t b) { +bool same_ctor_identity(ant_t *js, ant_value_t a, ant_value_t b) { if (vtype(a) == vtype(b) && vdata(a) == vdata(b)) return true; if (vtype(a) == T_FUNC && vtype(b) == T_CFUNC) { - jsval_t c = get_slot(js, a, SLOT_CFUNC); + ant_value_t c = get_slot(js, a, SLOT_CFUNC); return vtype(c) == T_CFUNC && vdata(c) == vdata(b); } if (vtype(a) == T_CFUNC && vtype(b) == T_FUNC) { - jsval_t c = get_slot(js, b, SLOT_CFUNC); + ant_value_t c = get_slot(js, b, SLOT_CFUNC); return vtype(c) == T_CFUNC && vdata(c) == vdata(a); } if (vtype(a) == T_FUNC && vtype(b) == T_FUNC) { - jsval_t ca = get_slot(js, a, SLOT_CFUNC); - jsval_t cb = get_slot(js, b, SLOT_CFUNC); + ant_value_t ca = get_slot(js, a, SLOT_CFUNC); + ant_value_t cb = get_slot(js, b, SLOT_CFUNC); if (vtype(ca) == T_CFUNC && vtype(cb) == T_CFUNC && vdata(ca) == vdata(cb)) return true; } return false; } -static jsval_t array_constructor_from_receiver(ant_t *js, jsval_t receiver) { +static ant_value_t array_constructor_from_receiver(ant_t *js, ant_value_t receiver) { if (!is_object_type(receiver)) return js_mkundef(); - jsval_t species_source = receiver; + ant_value_t species_source = receiver; if (is_proxy(js, species_source)) { species_source = proxy_read_target(js, species_source); } bool receiver_is_array = (vtype(species_source) == T_ARR); if (!receiver_is_array) { - jsval_t array_proto = get_ctor_proto(js, "Array", 5); + ant_value_t array_proto = get_ctor_proto(js, "Array", 5); if (is_object_type(array_proto) && is_object_type(species_source)) { receiver_is_array = proto_chain_contains(js, species_source, array_proto); } } if (!receiver_is_array) return js_mkundef(); - jsval_t ctor = js_getprop_fallback(js, receiver, "constructor"); + ant_value_t ctor = js_getprop_fallback(js, receiver, "constructor"); if (is_err(ctor)) return ctor; - jsval_t species = get_ctor_species_value(js, ctor); + ant_value_t species = get_ctor_species_value(js, ctor); if (is_err(species)) return species; if (vtype(species) == T_NULL) return js_mkundef(); @@ -3142,41 +3142,41 @@ static jsval_t array_constructor_from_receiver(ant_t *js, jsval_t receiver) { return ctor; } -static jsval_t array_alloc_from_ctor_with_length(ant_t *js, jsval_t ctor, jsoff_t length_hint) { +static ant_value_t array_alloc_from_ctor_with_length(ant_t *js, ant_value_t ctor, ant_offset_t length_hint) { if (vtype(ctor) != T_FUNC && vtype(ctor) != T_CFUNC) { return mkarr(js); } - jsval_t seed = js_mkobj(js); + ant_value_t seed = js_mkobj(js); if (is_err(seed)) return seed; - jsval_t proto = js_get(js, ctor, "prototype"); + ant_value_t proto = js_get(js, ctor, "prototype"); if (is_err(proto)) return proto; if (is_object_type(proto)) set_proto(js, seed, proto); - jsval_t ctor_args[1] = { tov((double)length_hint) }; - jsval_t saved_new_target = js->new_target; + ant_value_t ctor_args[1] = { tov((double)length_hint) }; + ant_value_t saved_new_target = js->new_target; js->new_target = ctor; - jsval_t constructed = sv_vm_call(js->vm, js, ctor, seed, ctor_args, 1, NULL, true); + ant_value_t constructed = sv_vm_call(js->vm, js, ctor, seed, ctor_args, 1, NULL, true); js->new_target = saved_new_target; if (is_err(constructed)) return constructed; - jsval_t result = is_object_type(constructed) ? constructed : seed; + ant_value_t result = is_object_type(constructed) ? constructed : seed; set_slot(js, js_as_obj(result), SLOT_CTOR, ctor); return result; } -static inline jsval_t array_alloc_from_ctor(ant_t *js, jsval_t ctor) { +static inline ant_value_t array_alloc_from_ctor(ant_t *js, ant_value_t ctor) { return array_alloc_from_ctor_with_length(js, ctor, 0); } -static inline jsval_t array_alloc_like(ant_t *js, jsval_t receiver) { - jsval_t ctor = array_constructor_from_receiver(js, receiver); +static inline ant_value_t array_alloc_like(ant_t *js, ant_value_t receiver) { + ant_value_t ctor = array_constructor_from_receiver(js, receiver); if (is_err(ctor)) return ctor; return array_alloc_from_ctor(js, ctor); } -static jsval_t validate_array_length(ant_t *js, jsval_t v) { +static ant_value_t validate_array_length(ant_t *js, ant_value_t v) { if (vtype(v) != T_NUM) { return js_mkerr_typed(js, JS_ERR_RANGE, "Invalid array length"); } @@ -3187,31 +3187,31 @@ static jsval_t validate_array_length(ant_t *js, jsval_t v) { return js_mkundef(); } -static inline jsval_t check_object_extensibility(ant_t *js, jsval_t obj) { +static inline ant_value_t check_object_extensibility(ant_t *js, ant_value_t obj) { obj = js_as_obj(obj); - jsoff_t obj_off_fp = (jsoff_t)vdata(obj); - jsoff_t next = loadoff(js, obj_off_fp) & ~(3U | FLAGMASK); + ant_offset_t obj_off_fp = (ant_offset_t)vdata(obj); + ant_offset_t next = loadoff(js, obj_off_fp) & ~(3U | FLAGMASK); while (next != 0 && next < js->brk) { - jsoff_t hdr = loadoff(js, next); + ant_offset_t hdr = loadoff(js, next); if ((hdr & SLOTMASK) == 0) break; - jsoff_t sk = loadoff(js, next + sizeof(jsoff_t)); - jsval_t sv = loadval(js, next + sizeof(jsoff_t) * 2); + ant_offset_t sk = loadoff(js, next + sizeof(ant_offset_t)); + ant_value_t sv = loadval(js, next + sizeof(ant_offset_t) * 2); - if (sk == (jsoff_t)SLOT_FROZEN && js_truthy(js, sv)) { + if (sk == (ant_offset_t)SLOT_FROZEN && js_truthy(js, sv)) { return sv_vm_is_strict(js->vm) ? js_mkerr(js, "cannot add property to frozen object") : js_mkundef(); } - if (sk == (jsoff_t)SLOT_SEALED && js_truthy(js, sv)) { + if (sk == (ant_offset_t)SLOT_SEALED && js_truthy(js, sv)) { return sv_vm_is_strict(js->vm) ? js_mkerr(js, "cannot add property to sealed object") : js_mkundef(); } - if (sk == (jsoff_t)SLOT_EXTENSIBLE && !js_truthy(js, sv)) { + if (sk == (ant_offset_t)SLOT_EXTENSIBLE && !js_truthy(js, sv)) { return sv_vm_is_strict(js->vm) ? js_mkerr(js, "cannot add property to non-extensible object") : js_mkundef(); @@ -3223,56 +3223,56 @@ static inline jsval_t check_object_extensibility(ant_t *js, jsval_t obj) { return js_mkundef(); } -static inline void update_array_length(ant_t *js, jsval_t obj, jsoff_t new_len) { - jsoff_t len_off = lkp_interned(js, obj, INTERN_LENGTH, 6); - jsval_t new_len_val = tov((double)new_len); +static inline void update_array_length(ant_t *js, ant_value_t obj, ant_offset_t new_len) { + ant_offset_t len_off = lkp_interned(js, obj, INTERN_LENGTH, 6); + ant_value_t new_len_val = tov((double)new_len); - if (len_off != 0) saveval(js, len_off + sizeof(jsoff_t) * 2, new_len_val); else { + if (len_off != 0) saveval(js, len_off + sizeof(ant_offset_t) * 2, new_len_val); else { js_mkprop_fast(js, obj, "length", 6, new_len_val); } } -static jsval_t js_setprop_array_fast(ant_t *js, jsval_t obj, jsval_t k, jsval_t v, jsoff_t klen, const char *key) { +static ant_value_t js_setprop_array_fast(ant_t *js, ant_value_t obj, ant_value_t k, ant_value_t v, ant_offset_t klen, const char *key) { unsigned long idx; - if (!parse_array_index(key, klen, (jsoff_t)-1, &idx)) return js_mkundef(); + if (!parse_array_index(key, klen, (ant_offset_t)-1, &idx)) return js_mkundef(); - jsoff_t doff = get_dense_buf(js, obj); + ant_offset_t doff = get_dense_buf(js, obj); if (doff) { - jsoff_t cur_len = dense_length(js, doff); - if (idx < cur_len) { dense_set(js, doff, (jsoff_t)idx, v); return v; } + ant_offset_t cur_len = dense_length(js, doff); + if (idx < cur_len) { dense_set(js, doff, (ant_offset_t)idx, v); return v; } - jsoff_t density_limit = cur_len > 0 ? cur_len * 4 : 64; + ant_offset_t density_limit = cur_len > 0 ? cur_len * 4 : 64; if (idx >= density_limit) goto sparse; - jsval_t extensibility_error = check_object_extensibility(js, obj); + ant_value_t extensibility_error = check_object_extensibility(js, obj); if (!is_undefined(extensibility_error)) return extensibility_error; - arr_set(js, obj, (jsoff_t)idx, v); + arr_set(js, obj, (ant_offset_t)idx, v); return v; } sparse:; - jsoff_t cur_len = get_array_length(js, obj); + ant_offset_t cur_len = get_array_length(js, obj); if (idx < cur_len) return js_mkundef(); - jsval_t extensibility_error = check_object_extensibility(js, obj); + ant_value_t extensibility_error = check_object_extensibility(js, obj); if (!is_undefined(extensibility_error)) return extensibility_error; - jsval_t result = mkprop_fast(js, obj, k, v, 0); + ant_value_t result = mkprop_fast(js, obj, k, v, 0); update_array_length(js, obj, idx + 1); return result; } -jsval_t js_setprop(ant_t *js, jsval_t obj, jsval_t k, jsval_t v) { +ant_value_t js_setprop(ant_t *js, ant_value_t obj, ant_value_t k, ant_value_t v) { uint8_t ot = vtype(obj); if (ot == T_STR || ot == T_NUM || ot == T_BOOL) { - jsoff_t klen; jsoff_t koff = vstr(js, k, &klen); + ant_offset_t klen; ant_offset_t koff = vstr(js, k, &klen); const char *key = (char *)&js->mem[koff]; - jsval_t proto = get_prototype_for_type(js, ot); + ant_value_t proto = get_prototype_for_type(js, ot); if (is_object_type(proto)) { - jsval_t setter = js_mkundef(); + ant_value_t setter = js_mkundef(); bool has_setter = false; lkp_with_setter(js, proto, key, klen, &setter, &has_setter); if (has_setter && (vtype(setter) == T_FUNC || vtype(setter) == T_CFUNC)) { @@ -3289,16 +3289,16 @@ jsval_t js_setprop(ant_t *js, jsval_t obj, jsval_t k, jsval_t v) { if (vtype(obj) == T_FUNC) obj = js_func_obj(obj); if (vtype(k) == T_SYMBOL) { - jsoff_t sym_off = (jsoff_t)vdata(k); - jsval_t cur = obj; + ant_offset_t sym_off = (ant_offset_t)vdata(k); + ant_value_t cur = obj; for (int i = 0; i < MAX_PROTO_CHAIN_DEPTH; i++) { - jsoff_t cur_off = (jsoff_t)vdata(js_as_obj(cur)); + ant_offset_t cur_off = (ant_offset_t)vdata(js_as_obj(cur)); descriptor_entry_t *sd = lookup_sym_descriptor(cur_off, sym_off); if (sd && sd->has_setter) { - jsval_t setter = sd->setter; + ant_value_t setter = sd->setter; if (vtype(setter) == T_FUNC || vtype(setter) == T_CFUNC) { - jsval_t result = sv_vm_call(js->vm, js, setter, obj, &v, 1, NULL, false); + ant_value_t result = sv_vm_call(js->vm, js, setter, obj, &v, 1, NULL, false); if (is_err(result)) return result; return v; } @@ -3309,16 +3309,16 @@ jsval_t js_setprop(ant_t *js, jsval_t obj, jsval_t k, jsval_t v) { return v; } - jsval_t proto = get_proto(js, js_as_obj(cur)); + ant_value_t proto = get_proto(js, js_as_obj(cur)); if (!is_object_type(proto)) break; cur = proto; } - jsoff_t existing = lkp_sym(js, obj, sym_off); + ant_offset_t existing = lkp_sym(js, obj, sym_off); if (existing > 0) { if (is_const_prop(js, existing)) return js_mkerr(js, "assignment to constant"); - saveval(js, existing + sizeof(jsoff_t) * 2, v); + saveval(js, existing + sizeof(ant_offset_t) * 2, v); return mkval(T_PROP, existing); } @@ -3330,23 +3330,23 @@ jsval_t js_setprop(ant_t *js, jsval_t obj, jsval_t k, jsval_t v) { return mkprop(js, obj, k, v, 0); } - jsoff_t klen; jsoff_t koff = vstr(js, k, &klen); + ant_offset_t klen; ant_offset_t koff = vstr(js, k, &klen); const char *key = (char *) &js->mem[koff]; if (vtype(obj) == T_ARR && !is_proxy(js, obj) && klen > 0 && key[0] >= '0' && key[0] <= '9') { - jsval_t result = js_setprop_array_fast(js, obj, k, v, klen, key); + ant_value_t result = js_setprop_array_fast(js, obj, k, v, klen, key); if (vtype(result) != T_UNDEF) return result; } if (vtype(obj) == T_ARR && streq(key, klen, "length", 6)) { - jsval_t err = validate_array_length(js, v); + ant_value_t err = validate_array_length(js, v); if (is_err(err)) return err; - jsoff_t doff = get_dense_buf(js, obj); + ant_offset_t doff = get_dense_buf(js, obj); if (doff) { - jsoff_t new_len_val = (jsoff_t) tod(v); - jsoff_t cur_len = dense_length(js, doff); + ant_offset_t new_len_val = (ant_offset_t) tod(v); + ant_offset_t cur_len = dense_length(js, doff); if (new_len_val < cur_len) { - for (jsoff_t i = new_len_val; i < cur_len; i++) + for (ant_offset_t i = new_len_val; i < cur_len; i++) dense_set(js, doff, i, T_EMPTY); dense_set_length(js, doff, new_len_val); return v; @@ -3358,24 +3358,24 @@ jsval_t js_setprop(ant_t *js, jsval_t obj, jsval_t k, jsval_t v) { } if (is_proxy(js, obj)) { - jsval_t result = proxy_set(js, obj, key, klen, v); + ant_value_t result = proxy_set(js, obj, key, klen, v); if (is_err(result)) return result; return v; } if (try_dynamic_setter(js, obj, key, klen, v)) return v; - jsoff_t existing = lkp(js, obj, key, klen); + ant_offset_t existing = lkp(js, obj, key, klen); { - jsoff_t obj_off = (jsoff_t)vdata(js_as_obj(obj)); + ant_offset_t obj_off = (ant_offset_t)vdata(js_as_obj(obj)); descriptor_entry_t *desc = lookup_descriptor(js, obj_off, key, klen); if (!desc) { - jsval_t cur = obj; + ant_value_t cur = obj; for (int i = 0; i < MAX_PROTO_CHAIN_DEPTH && !desc; i++) { cur = get_proto(js, cur); if (vtype(cur) != T_OBJ && vtype(cur) != T_FUNC) break; - desc = lookup_descriptor(js, (jsoff_t)vdata(js_as_obj(cur)), key, klen); + desc = lookup_descriptor(js, (ant_offset_t)vdata(js_as_obj(cur)), key, klen); } if (desc && !desc->has_setter && !desc->has_getter && desc->writable) desc = NULL; } @@ -3383,11 +3383,11 @@ jsval_t js_setprop(ant_t *js, jsval_t obj, jsval_t k, jsval_t v) { if (!desc) goto no_descriptor; if (desc->has_setter) { - jsval_t setter = desc->setter; + ant_value_t setter = desc->setter; uint8_t setter_type = vtype(setter); if (setter_type == T_FUNC || setter_type == T_CFUNC) { js_error_site_t saved_errsite = js->errsite; - jsval_t result = sv_vm_call(js->vm, js, setter, obj, &v, 1, NULL, false); + ant_value_t result = sv_vm_call(js->vm, js, setter, obj, &v, 1, NULL, false); js->errsite = saved_errsite; if (is_err(result)) return result; return v; @@ -3411,24 +3411,24 @@ no_descriptor: if (existing <= 0) goto create_new; if (is_const_prop(js, existing)) return js_mkerr(js, "assignment to constant"); - saveval(js, existing + sizeof(jsoff_t) * 2, v); + saveval(js, existing + sizeof(ant_offset_t) * 2, v); if (vtype(obj) != T_ARR || klen == 0 || key[0] < '0' || key[0] > '9') goto done_update; - { jsoff_t doff = get_dense_buf(js, obj); if (doff) goto done_update; } + { ant_offset_t doff = get_dense_buf(js, obj); if (doff) goto done_update; } char *endptr; unsigned long update_idx = strtoul(key, &endptr, 10); if (endptr != key + klen) goto done_update; - jsoff_t len_off = lkp_interned(js, obj, INTERN_LENGTH, 6); - jsoff_t cur_len = 0; + ant_offset_t len_off = lkp_interned(js, obj, INTERN_LENGTH, 6); + ant_offset_t cur_len = 0; if (len_off != 0) { - jsval_t len_val = resolveprop(js, mkval(T_PROP, len_off)); - if (vtype(len_val) == T_NUM) cur_len = (jsoff_t) tod(len_val); + ant_value_t len_val = resolveprop(js, mkval(T_PROP, len_off)); + if (vtype(len_val) == T_NUM) cur_len = (ant_offset_t) tod(len_val); } if (update_idx < cur_len) goto done_update; - jsval_t new_len = tov((double)(update_idx + 1)); - if (len_off != 0) saveval(js, len_off + sizeof(jsoff_t) * 2, new_len); else { + ant_value_t new_len = tov((double)(update_idx + 1)); + if (len_off != 0) saveval(js, len_off + sizeof(ant_offset_t) * 2, new_len); else { mkprop(js, obj, js->length_str, new_len, 0); } @@ -3446,7 +3446,7 @@ create_new: return js_mkundef(); } - jsval_t ext_slot = get_slot(js, obj, SLOT_EXTENSIBLE); + ant_value_t ext_slot = get_slot(js, obj, SLOT_EXTENSIBLE); if (vtype(ext_slot) != T_UNDEF && !js_truthy(js, ext_slot)) { if (sv_vm_is_strict(js->vm)) return js_mkerr(js, "cannot add property to non-extensible object"); return js_mkundef(); @@ -3459,21 +3459,21 @@ create_new: char *inner_endptr; idx = strtoul(key, &inner_endptr, 10); if (inner_endptr == key + klen) { - jsoff_t inner_len_off = lkp_interned(js, obj, INTERN_LENGTH, 6); - jsoff_t inner_cur_len = 0; + ant_offset_t inner_len_off = lkp_interned(js, obj, INTERN_LENGTH, 6); + ant_offset_t inner_cur_len = 0; if (inner_len_off != 0) { - jsval_t len_val = resolveprop(js, mkval(T_PROP, inner_len_off)); - if (vtype(len_val) == T_NUM) inner_cur_len = (jsoff_t) tod(len_val); + ant_value_t len_val = resolveprop(js, mkval(T_PROP, inner_len_off)); + if (vtype(len_val) == T_NUM) inner_cur_len = (ant_offset_t) tod(len_val); } if (idx >= inner_cur_len) need_length_update = 1; } } - jsval_t result = mkprop(js, obj, k, v, 0); + ant_value_t result = mkprop(js, obj, k, v, 0); if (need_length_update) { - jsoff_t inner_len_off = lkp_interned(js, obj, INTERN_LENGTH, 6); - jsval_t inner_new_len = tov((double)(idx + 1)); - if (inner_len_off != 0) saveval(js, inner_len_off + sizeof(jsoff_t) * 2, inner_new_len); else { + ant_offset_t inner_len_off = lkp_interned(js, obj, INTERN_LENGTH, 6); + ant_value_t inner_new_len = tov((double)(idx + 1)); + if (inner_len_off != 0) saveval(js, inner_len_off + sizeof(ant_offset_t) * 2, inner_new_len); else { mkprop(js, obj, js->length_str, inner_new_len, 0); } } @@ -3481,26 +3481,26 @@ create_new: return result; } -jsval_t setprop_cstr(ant_t *js, jsval_t obj, const char *key, size_t len, jsval_t v) { +ant_value_t setprop_cstr(ant_t *js, ant_value_t obj, const char *key, size_t len, ant_value_t v) { obj = js_as_obj(obj); - jsval_t k = js_mkstr(js, key, len); + ant_value_t k = js_mkstr(js, key, len); if (is_err(k)) return k; return mkprop(js, obj, k, v, 0); } -jsval_t js_define_own_prop(ant_t *js, jsval_t obj, const char *key, size_t klen, jsval_t v) { +ant_value_t js_define_own_prop(ant_t *js, ant_value_t obj, const char *key, size_t klen, ant_value_t v) { obj = js_as_obj(obj); if (is_proxy(js, obj)) { - jsval_t result = proxy_set(js, obj, key, klen, v); + ant_value_t result = proxy_set(js, obj, key, klen, v); if (is_err(result)) return result; return v; } if (try_dynamic_setter(js, obj, key, klen, v)) return v; - jsoff_t existing = lkp(js, obj, key, klen); + ant_offset_t existing = lkp(js, obj, key, klen); { - jsoff_t obj_off = (jsoff_t)vdata(js_as_obj(obj)); + ant_offset_t obj_off = (ant_offset_t)vdata(js_as_obj(obj)); descriptor_entry_t *desc = lookup_descriptor(js, obj_off, key, klen); if (desc) { if (!desc->writable && !desc->has_setter) { @@ -3508,10 +3508,10 @@ jsval_t js_define_own_prop(ant_t *js, jsval_t obj, const char *key, size_t klen, return v; } if (desc->has_setter) { - jsval_t setter = desc->setter; + ant_value_t setter = desc->setter; uint8_t setter_type = vtype(setter); if (setter_type == T_FUNC || setter_type == T_CFUNC) { - jsval_t result = sv_vm_call(js->vm, js, setter, obj, &v, 1, NULL, false); + ant_value_t result = sv_vm_call(js->vm, js, setter, obj, &v, 1, NULL, false); if (is_err(result)) return result; return v; } @@ -3521,7 +3521,7 @@ jsval_t js_define_own_prop(ant_t *js, jsval_t obj, const char *key, size_t klen, if (existing > 0) { if (is_const_prop(js, existing)) return js_mkerr(js, "assignment to constant"); - saveval(js, existing + sizeof(jsoff_t) * 2, v); + saveval(js, existing + sizeof(ant_offset_t) * 2, v); return mkval(T_PROP, existing); } @@ -3533,27 +3533,27 @@ jsval_t js_define_own_prop(ant_t *js, jsval_t obj, const char *key, size_t klen, if (sv_vm_is_strict(js->vm)) return js_mkerr(js, "cannot add property to sealed object"); return js_mkundef(); } - jsval_t ext_slot = get_slot(js, obj, SLOT_EXTENSIBLE); + ant_value_t ext_slot = get_slot(js, obj, SLOT_EXTENSIBLE); if (vtype(ext_slot) != T_UNDEF && !js_truthy(js, ext_slot)) { if (sv_vm_is_strict(js->vm)) return js_mkerr(js, "cannot add property to non-extensible object"); return js_mkundef(); } - jsval_t k = js_mkstr(js, key, klen); + ant_value_t k = js_mkstr(js, key, klen); if (is_err(k)) return k; return mkprop(js, obj, k, v, 0); } -jsval_t setprop_interned(ant_t *js, jsval_t obj, const char *key, size_t len, jsval_t v) { - jsval_t k = js_mkstr(js, key, len); +ant_value_t setprop_interned(ant_t *js, ant_value_t obj, const char *key, size_t len, ant_value_t v) { + ant_value_t k = js_mkstr(js, key, len); if (is_err(k)) return k; return js_setprop(js, obj, k, v); } -jsval_t js_setprop_nonconfigurable(ant_t *js, jsval_t obj, const char *key, size_t keylen, jsval_t v) { - jsval_t k = js_mkstr(js, key, keylen); +ant_value_t js_setprop_nonconfigurable(ant_t *js, ant_value_t obj, const char *key, size_t keylen, ant_value_t v) { + ant_value_t k = js_mkstr(js, key, keylen); if (is_err(k)) return k; - jsval_t result = js_setprop(js, obj, k, v); + ant_value_t result = js_setprop(js, obj, k, v); if (is_err(result)) return result; js_set_descriptor(js, obj, key, keylen, JS_DESC_W); @@ -3572,12 +3572,12 @@ static struct { static size_t g_sym_registry_count = 0; static size_t g_sym_all_count = 0; static size_t g_sym_all_cap = 0; -static jsval_t *g_sym_all = NULL; +static ant_value_t *g_sym_all = NULL; -static void sym_table_add(jsval_t sym) { +static void sym_table_add(ant_value_t sym) { if (g_sym_all_count >= g_sym_all_cap) { size_t new_cap = g_sym_all_cap ? g_sym_all_cap * 2 : 64; - jsval_t *new_buf = realloc(g_sym_all, new_cap * sizeof(jsval_t)); + ant_value_t *new_buf = realloc(g_sym_all, new_cap * sizeof(ant_value_t)); if (!new_buf) return; g_sym_all = new_buf; g_sym_all_cap = new_cap; @@ -3585,18 +3585,18 @@ static void sym_table_add(jsval_t sym) { g_sym_all[g_sym_all_count++] = sym; } -jsval_t js_mksym(ant_t *js, const char *desc) { +ant_value_t js_mksym(ant_t *js, const char *desc) { uint32_t id = (uint32_t)(++js->sym_counter); size_t desc_len = (desc && *desc) ? strlen(desc) : 0; size_t payload = SYM_HEAP_FIXED + (desc_len ? desc_len + 1 : 0); - jsoff_t ofs = js_alloc(js, payload + sizeof(jsoff_t)); - if (ofs == (jsoff_t)~0) return js_mkerr(js, "oom"); + ant_offset_t ofs = js_alloc(js, payload + sizeof(ant_offset_t)); + if (ofs == (ant_offset_t)~0) return js_mkerr(js, "oom"); - jsoff_t header = (jsoff_t)(payload << 4); + ant_offset_t header = (ant_offset_t)(payload << 4); memcpy(&js->mem[ofs], &header, sizeof(header)); - jsoff_t p = ofs + sizeof(jsoff_t); + ant_offset_t p = ofs + sizeof(ant_offset_t); memcpy(&js->mem[p], &id, sizeof(id)); p += sizeof(uint32_t); uint32_t flags = 0; @@ -3611,48 +3611,48 @@ jsval_t js_mksym(ant_t *js, const char *desc) { js->mem[p + desc_len] = '\0'; } - jsval_t sym = mkval(T_SYMBOL, ofs); + ant_value_t sym = mkval(T_SYMBOL, ofs); sym_table_add(sym); return sym; } -static inline uint32_t sym_get_id(ant_t *js, jsval_t v) { - jsoff_t ofs = (jsoff_t)vdata(v); +static inline uint32_t sym_get_id(ant_t *js, ant_value_t v) { + ant_offset_t ofs = (ant_offset_t)vdata(v); uint32_t id; - memcpy(&id, &js->mem[ofs + sizeof(jsoff_t)], sizeof(id)); + memcpy(&id, &js->mem[ofs + sizeof(ant_offset_t)], sizeof(id)); return id; } -static inline uint32_t sym_get_flags(ant_t *js, jsval_t v) { - jsoff_t ofs = (jsoff_t)vdata(v); +static inline uint32_t sym_get_flags(ant_t *js, ant_value_t v) { + ant_offset_t ofs = (ant_offset_t)vdata(v); uint32_t flags; - memcpy(&flags, &js->mem[ofs + sizeof(jsoff_t) + sizeof(uint32_t)], sizeof(flags)); + memcpy(&flags, &js->mem[ofs + sizeof(ant_offset_t) + sizeof(uint32_t)], sizeof(flags)); return flags; } -static inline uintptr_t sym_get_key_ptr(ant_t *js, jsval_t v) { - jsoff_t ofs = (jsoff_t)vdata(v); +static inline uintptr_t sym_get_key_ptr(ant_t *js, ant_value_t v) { + ant_offset_t ofs = (ant_offset_t)vdata(v); uintptr_t kp; - memcpy(&kp, &js->mem[ofs + sizeof(jsoff_t) + sizeof(uint32_t) * 2], sizeof(kp)); + memcpy(&kp, &js->mem[ofs + sizeof(ant_offset_t) + sizeof(uint32_t) * 2], sizeof(kp)); return kp; } -static const char *sym_get_desc(ant_t *js, jsval_t v) { - jsoff_t ofs = (jsoff_t)vdata(v); - jsoff_t header; +static const char *sym_get_desc(ant_t *js, ant_value_t v) { + ant_offset_t ofs = (ant_offset_t)vdata(v); + ant_offset_t header; memcpy(&header, &js->mem[ofs], sizeof(header)); size_t payload = (size_t)(header >> 4); if (payload <= SYM_HEAP_FIXED) return NULL; - return (const char *)&js->mem[ofs + sizeof(jsoff_t) + SYM_HEAP_FIXED]; + return (const char *)&js->mem[ofs + sizeof(ant_offset_t) + SYM_HEAP_FIXED]; } -uint64_t inline js_sym_id(jsval_t sym) { +uint64_t inline js_sym_id(ant_value_t sym) { // TODO: fix to not use the global runtime ant_t *js = rt->js; return sym_get_id(js, sym); } -jsval_t js_mksym_for(ant_t *js, const char *key) { +ant_value_t js_mksym_for(ant_t *js, const char *key) { const char *interned = intern_string(key, strlen(key)); for (size_t i = 0; i < g_sym_registry_count; i++) { @@ -3662,14 +3662,14 @@ jsval_t js_mksym_for(ant_t *js, const char *key) { } } - jsval_t sym = js_mksym(js, key); + ant_value_t sym = js_mksym(js, key); if (is_err(sym)) return sym; - jsoff_t ofs = (jsoff_t)vdata(sym); + ant_offset_t ofs = (ant_offset_t)vdata(sym); uint32_t flags = SYM_FLAG_GLOBAL; - memcpy(&js->mem[ofs + sizeof(jsoff_t) + sizeof(uint32_t)], &flags, sizeof(flags)); + memcpy(&js->mem[ofs + sizeof(ant_offset_t) + sizeof(uint32_t)], &flags, sizeof(flags)); uintptr_t kp = (uintptr_t)interned; - memcpy(&js->mem[ofs + sizeof(jsoff_t) + sizeof(uint32_t) * 2], &kp, sizeof(kp)); + memcpy(&js->mem[ofs + sizeof(ant_offset_t) + sizeof(uint32_t) * 2], &kp, sizeof(kp)); if (g_sym_registry_count < SYM_REGISTRY_MAX) { uint32_t id = sym_get_id(js, sym); @@ -3681,35 +3681,35 @@ jsval_t js_mksym_for(ant_t *js, const char *key) { return sym; } -const char *js_sym_key(jsval_t sym) { +const char *js_sym_key(ant_value_t sym) { if (vtype(sym) != T_SYMBOL) return NULL; ant_t *js = rt->js; if (!(sym_get_flags(js, sym) & SYM_FLAG_GLOBAL)) return NULL; return (const char *)sym_get_key_ptr(js, sym); } -const inline char *js_sym_desc(ant_t *js, jsval_t sym) { +const inline char *js_sym_desc(ant_t *js, ant_value_t sym) { return sym_get_desc(js, sym); } -jsval_t sym_lookup_by_id(uint32_t id) { - if (id == 0 || id - 1 >= g_sym_all_count) return (jsval_t)0; +ant_value_t sym_lookup_by_id(uint32_t id) { + if (id == 0 || id - 1 >= g_sym_all_count) return (ant_value_t)0; return g_sym_all[id - 1]; } -void sym_gc_update_all(void (*op_val)(void *, jsval_t *), void *ctx) { +void sym_gc_update_all(void (*op_val)(void *, ant_value_t *), void *ctx) { for (size_t i = 0; i < g_sym_all_count; i++) { op_val(ctx, &g_sym_all[i]); } } -jsoff_t esize(jsoff_t w) { - jsoff_t cleaned = w & ~FLAGMASK; +ant_offset_t esize(ant_offset_t w) { + ant_offset_t cleaned = w & ~FLAGMASK; switch (cleaned & 3U) { - case T_OBJ: return (jsoff_t) (sizeof(jsoff_t) + sizeof(jsoff_t) + sizeof(jsoff_t)); - case T_PROP: return (jsoff_t) (sizeof(jsoff_t) + sizeof(jsoff_t) + sizeof(jsval_t)); - case T_STR: return (jsoff_t) (sizeof(jsoff_t) + align64(cleaned >> 3U)); - default: return (jsoff_t) ~0U; + case T_OBJ: return (ant_offset_t) (sizeof(ant_offset_t) + sizeof(ant_offset_t) + sizeof(ant_offset_t)); + case T_PROP: return (ant_offset_t) (sizeof(ant_offset_t) + sizeof(ant_offset_t) + sizeof(ant_value_t)); + case T_STR: return (ant_offset_t) (sizeof(ant_offset_t) + align64(cleaned >> 3U)); + default: return (ant_offset_t) ~0U; } } @@ -3717,10 +3717,10 @@ static inline bool streq(const char *buf, size_t len, const char *s, size_t n) { return len == n && !memcmp(buf, s, n); } -static inline jsoff_t lkp_interned(ant_t *js, jsval_t obj, const char *search_intern, size_t len) { +static inline ant_offset_t lkp_interned(ant_t *js, ant_value_t obj, const char *search_intern, size_t len) { obj = js_as_obj(obj); - jsoff_t obj_off = (jsoff_t)vdata(obj); - jsoff_t tail = loadoff(js, obj_off + sizeof(jsoff_t) * 2); + ant_offset_t obj_off = (ant_offset_t)vdata(obj); + ant_offset_t tail = loadoff(js, obj_off + sizeof(ant_offset_t) * 2); uint32_t slot = (((uintptr_t)search_intern >> 3) ^ obj_off) & (ANT_LIMIT_SIZE_CACHE - 1); intern_prop_cache_entry_t *ce = &intern_prop_cache[slot]; @@ -3731,18 +3731,18 @@ static inline jsoff_t lkp_interned(ant_t *js, jsval_t obj, const char *search_in && ce->tail == tail ) return ce->prop_off; - jsoff_t first_prop = loadoff(js, obj_off) & ~(3U | FLAGMASK); - jsoff_t off = first_prop; jsoff_t result = 0; + ant_offset_t first_prop = loadoff(js, obj_off) & ~(3U | FLAGMASK); + ant_offset_t off = first_prop; ant_offset_t result = 0; while (off < js->brk && off != 0) { - jsoff_t header = loadoff(js, off); + ant_offset_t header = loadoff(js, off); if (is_slot_prop(header)) { off = next_prop(header); continue; } - jsoff_t koff = loadoff(js, off + sizeof(jsoff_t)); - jsoff_t klen = (loadoff(js, koff) >> 3) - 1; + ant_offset_t koff = loadoff(js, off + sizeof(ant_offset_t)); + ant_offset_t klen = (loadoff(js, koff) >> 3) - 1; if (klen == len) { - const char *p = (char *)&js->mem[koff + sizeof(jsoff_t)]; + const char *p = (char *)&js->mem[koff + sizeof(ant_offset_t)]; if (intern_string(p, klen) == search_intern) { result = off; break; } } off = next_prop(header); @@ -3757,43 +3757,43 @@ static inline jsoff_t lkp_interned(ant_t *js, jsval_t obj, const char *search_in return result; } -inline jsoff_t lkp(ant_t *js, jsval_t obj, const char *buf, size_t len) { +inline ant_offset_t lkp(ant_t *js, ant_value_t obj, const char *buf, size_t len) { const char *search_intern = intern_string(buf, len); if (!search_intern) return 0; return lkp_interned(js, obj, search_intern, len); } -jsoff_t lkp_sym(ant_t *js, jsval_t obj, jsoff_t sym_off) { +ant_offset_t lkp_sym(ant_t *js, ant_value_t obj, ant_offset_t sym_off) { obj = js_as_obj(obj); - jsoff_t obj_off = (jsoff_t)vdata(obj); - jsoff_t first_prop = loadoff(js, obj_off) & ~(3U | FLAGMASK); - jsoff_t off = first_prop; + ant_offset_t obj_off = (ant_offset_t)vdata(obj); + ant_offset_t first_prop = loadoff(js, obj_off) & ~(3U | FLAGMASK); + ant_offset_t off = first_prop; while (off < js->brk && off != 0) { - jsoff_t header = loadoff(js, off); + ant_offset_t header = loadoff(js, off); if (is_slot_prop(header)) { off = next_prop(header); continue; } - jsoff_t koff = loadoff(js, off + sizeof(jsoff_t)); + ant_offset_t koff = loadoff(js, off + sizeof(ant_offset_t)); if (koff == sym_off) return off; off = next_prop(header); } return 0; } -jsoff_t lkp_sym_proto(ant_t *js, jsval_t obj, jsoff_t sym_off) { +ant_offset_t lkp_sym_proto(ant_t *js, ant_value_t obj, ant_offset_t sym_off) { for (int i = 0; i < MAX_PROTO_CHAIN_DEPTH; i++) { - jsoff_t off = lkp_sym(js, obj, sym_off); + ant_offset_t off = lkp_sym(js, obj, sym_off); if (off != 0) return off; - jsval_t proto = get_proto(js, js_as_obj(obj)); + ant_value_t proto = get_proto(js, js_as_obj(obj)); if (!is_object_type(proto)) break; obj = proto; } return 0; } -static jsval_t *resolve_bound_args(ant_t *js, jsval_t func_obj, jsval_t *args, int nargs, int *out_nargs) { +static ant_value_t *resolve_bound_args(ant_t *js, ant_value_t func_obj, ant_value_t *args, int nargs, int *out_nargs) { *out_nargs = nargs; - jsval_t bound_arr = get_slot(js, func_obj, SLOT_BOUND_ARGS); + ant_value_t bound_arr = get_slot(js, func_obj, SLOT_BOUND_ARGS); int bound_argc = 0; if (vtype(bound_arr) == T_ARR) { @@ -3801,22 +3801,22 @@ static jsval_t *resolve_bound_args(ant_t *js, jsval_t func_obj, jsval_t *args, i } if (bound_argc <= 0) return NULL; *out_nargs = bound_argc + nargs; - jsval_t *combined = (jsval_t *)ant_calloc(sizeof(jsval_t) * (*out_nargs)); + ant_value_t *combined = (ant_value_t *)ant_calloc(sizeof(ant_value_t) * (*out_nargs)); if (!combined) return NULL; - for (int i = 0; i < bound_argc; i++) combined[i] = arr_get(js, bound_arr, (jsoff_t)i); + for (int i = 0; i < bound_argc; i++) combined[i] = arr_get(js, bound_arr, (ant_offset_t)i); for (int i = 0; i < nargs; i++) combined[bound_argc + i] = args[i]; return combined; } -static jsoff_t lkp_with_getter(ant_t *js, jsval_t obj, const char *buf, size_t len, jsval_t *getter_out, bool *has_getter_out) { +static ant_offset_t lkp_with_getter(ant_t *js, ant_value_t obj, const char *buf, size_t len, ant_value_t *getter_out, bool *has_getter_out) { *has_getter_out = false; *getter_out = js_mkundef(); - for (jsval_t current = obj; is_object_type(current); ) { + for (ant_value_t current = obj; is_object_type(current); ) { current = js_as_obj(current); - jsoff_t current_off = (jsoff_t)vdata(current); + ant_offset_t current_off = (ant_offset_t)vdata(current); descriptor_entry_t *desc = lookup_descriptor(js, current_off, buf, len); if (desc && desc->has_getter) { @@ -3825,10 +3825,10 @@ static jsoff_t lkp_with_getter(ant_t *js, jsval_t obj, const char *buf, size_t l return current_off; } - jsoff_t prop_off = lkp_interned(js, current, intern_string(buf, len), len); + ant_offset_t prop_off = lkp_interned(js, current, intern_string(buf, len), len); if (prop_off != 0) return prop_off; - jsval_t proto = get_proto(js, current); + ant_value_t proto = get_proto(js, current); if (!is_object_type(proto)) break; current = proto; } @@ -3836,14 +3836,14 @@ static jsoff_t lkp_with_getter(ant_t *js, jsval_t obj, const char *buf, size_t l return 0; } -static jsoff_t lkp_with_setter(ant_t *js, jsval_t obj, const char *buf, size_t len, jsval_t *setter_out, bool *has_setter_out) { +static ant_offset_t lkp_with_setter(ant_t *js, ant_value_t obj, const char *buf, size_t len, ant_value_t *setter_out, bool *has_setter_out) { *has_setter_out = false; *setter_out = js_mkundef(); - jsval_t current = obj; + ant_value_t current = obj; while (vtype(current) == T_OBJ || vtype(current) == T_FUNC) { current = js_as_obj(current); - jsoff_t current_off = (jsoff_t)vdata(current); + ant_offset_t current_off = (ant_offset_t)vdata(current); descriptor_entry_t *desc = lookup_descriptor(js, current_off, buf, len); if (desc && desc->has_setter) { @@ -3852,10 +3852,10 @@ static jsoff_t lkp_with_setter(ant_t *js, jsval_t obj, const char *buf, size_t l return current_off; } - jsoff_t prop_off = lkp_interned(js, current, intern_string(buf, len), len); + ant_offset_t prop_off = lkp_interned(js, current, intern_string(buf, len), len); if (prop_off != 0) return prop_off; - jsval_t proto = get_proto(js, current); + ant_value_t proto = get_proto(js, current); if (vtype(proto) != T_OBJ && vtype(proto) != T_FUNC) break; current = proto; } @@ -3863,14 +3863,14 @@ static jsoff_t lkp_with_setter(ant_t *js, jsval_t obj, const char *buf, size_t l return 0; } -static jsval_t call_proto_accessor(ant_t *js, jsval_t prim, jsval_t accessor, bool has_accessor, jsval_t *arg, int arg_count, bool is_setter) { +static ant_value_t call_proto_accessor(ant_t *js, ant_value_t prim, ant_value_t accessor, bool has_accessor, ant_value_t *arg, int arg_count, bool is_setter) { if (!has_accessor || (vtype(accessor) != T_FUNC && vtype(accessor) != T_CFUNC)) return js_mkundef(); js_error_site_t saved_errsite = js->errsite; - jsval_t result = sv_vm_call(js->vm, js, accessor, prim, arg, arg_count, NULL, false); + ant_value_t result = sv_vm_call(js->vm, js, accessor, prim, arg, arg_count, NULL, false); bool had_throw = js->thrown_exists; - jsval_t thrown = js->thrown_value; + ant_value_t thrown = js->thrown_value; js->errsite = saved_errsite; if (had_throw) { @@ -3882,50 +3882,50 @@ static jsval_t call_proto_accessor(ant_t *js, jsval_t prim, jsval_t accessor, bo return result; } -jsval_t js_get_proto(ant_t *js, jsval_t obj) { +ant_value_t js_get_proto(ant_t *js, ant_value_t obj) { uint8_t t = vtype(obj); if (!is_object_type(obj)) return js_mknull(); - jsval_t as_obj = js_as_obj(obj); + ant_value_t as_obj = js_as_obj(obj); - jsval_t proto = get_slot(js, as_obj, SLOT_PROTO); + ant_value_t proto = get_slot(js, as_obj, SLOT_PROTO); if (is_object_type(proto)) return proto; if (t != T_OBJ) return get_prototype_for_type(js, t); return js_mknull(); } -static jsval_t get_proto(ant_t *js, jsval_t obj) { +static ant_value_t get_proto(ant_t *js, ant_value_t obj) { return js_get_proto(js, obj); } -void js_set_proto(ant_t *js, jsval_t obj, jsval_t proto) { +void js_set_proto(ant_t *js, ant_value_t obj, ant_value_t proto) { if (!is_object_type(obj)) return; - jsval_t as_obj = js_as_obj(obj); + ant_value_t as_obj = js_as_obj(obj); set_slot(js, as_obj, SLOT_PROTO, proto); } -static void set_proto(ant_t *js, jsval_t obj, jsval_t proto) { +static void set_proto(ant_t *js, ant_value_t obj, ant_value_t proto) { js_set_proto(js, obj, proto); } -jsval_t js_get_ctor_proto(ant_t *js, const char *name, size_t len) { - jsoff_t ctor_off = lkp_interned(js, js->global, intern_string(name, len), len); +ant_value_t js_get_ctor_proto(ant_t *js, const char *name, size_t len) { + ant_offset_t ctor_off = lkp_interned(js, js->global, intern_string(name, len), len); if (ctor_off == 0) return js_mknull(); - jsval_t ctor = resolveprop(js, mkval(T_PROP, ctor_off)); + ant_value_t ctor = resolveprop(js, mkval(T_PROP, ctor_off)); if (vtype(ctor) != T_FUNC) return js_mknull(); - jsval_t ctor_obj = js_as_obj(ctor); - jsoff_t proto_off = lkp_interned(js, ctor_obj, INTERN_PROTOTYPE, 9); + ant_value_t ctor_obj = js_as_obj(ctor); + ant_offset_t proto_off = lkp_interned(js, ctor_obj, INTERN_PROTOTYPE, 9); if (proto_off == 0) return js_mknull(); return resolveprop(js, mkval(T_PROP, proto_off)); } -static inline jsval_t get_ctor_proto(ant_t *js, const char *name, size_t len) { +static inline ant_value_t get_ctor_proto(ant_t *js, const char *name, size_t len) { return js_get_ctor_proto(js, name, len); } -static jsval_t get_prototype_for_type(ant_t *js, uint8_t type) { +static ant_value_t get_prototype_for_type(ant_t *js, uint8_t type) { switch (type) { case T_STR: return get_ctor_proto(js, "String", 6); case T_NUM: return get_ctor_proto(js, "Number", 6); @@ -3939,24 +3939,24 @@ switch (type) { default: return js_mknull(); }} -jsoff_t lkp_proto(ant_t *js, jsval_t obj, const char *key, size_t len) { +ant_offset_t lkp_proto(ant_t *js, ant_value_t obj, const char *key, size_t len) { uint8_t t = vtype(obj); const char *key_intern = intern_string(key, len); if (!key_intern) return 0; - jsval_t cur = obj; + ant_value_t cur = obj; int depth = 0; while (depth < MAX_PROTO_CHAIN_DEPTH) { if (t == T_OBJ || t == T_ARR || t == T_FUNC || t == T_PROMISE) { - jsval_t as_obj = js_as_obj(cur); - jsoff_t off = lkp_interned(js, as_obj, key_intern, len); + ant_value_t as_obj = js_as_obj(cur); + ant_offset_t off = lkp_interned(js, as_obj, key_intern, len); if (off != 0) return off; } else if (t == T_CFUNC) { - jsval_t func_proto = get_ctor_proto(js, "Function", 8); + ant_value_t func_proto = get_ctor_proto(js, "Function", 8); uint8_t ft = vtype(func_proto); if (ft == T_OBJ || ft == T_ARR || ft == T_FUNC) { - jsoff_t off = lkp(js, js_as_obj(func_proto), key, len); + ant_offset_t off = lkp(js, js_as_obj(func_proto), key, len); if (off != 0) return off; } break; @@ -3967,24 +3967,24 @@ jsoff_t lkp_proto(ant_t *js, jsval_t obj, const char *key, size_t len) { return 0; } -static jsval_t getprop_any(ant_t *js, jsval_t obj, const char *key, size_t key_len) { +static ant_value_t getprop_any(ant_t *js, ant_value_t obj, const char *key, size_t key_len) { uint8_t t = vtype(obj); if (t == T_STR && key_len == 6 && memcmp(key, "length", 6) == 0) { - jsoff_t byte_len; - jsoff_t str_off = vstr(js, obj, &byte_len); + ant_offset_t byte_len; + ant_offset_t str_off = vstr(js, obj, &byte_len); return tov(D(utf16_strlen((const char *)&js->mem[str_off], byte_len))); } if (t == T_STR || t == T_NUM || t == T_BOOL || t == T_BIGINT) { - jsoff_t off = lkp_proto(js, obj, key, key_len); + ant_offset_t off = lkp_proto(js, obj, key, key_len); if (off != 0) return resolveprop(js, mkval(T_PROP, off)); return js_mkundef(); } if (t == T_OBJ || t == T_ARR || t == T_FUNC) { - jsval_t as_obj = js_as_obj(obj); - jsoff_t off = lkp(js, as_obj, key, key_len); + ant_value_t as_obj = js_as_obj(obj); + ant_offset_t off = lkp(js, as_obj, key, key_len); if (off != 0) return resolveprop(js, mkval(T_PROP, off)); off = lkp_proto(js, obj, key, key_len); if (off != 0) return resolveprop(js, mkval(T_PROP, off)); @@ -3993,36 +3993,36 @@ static jsval_t getprop_any(ant_t *js, jsval_t obj, const char *key, size_t key_l return js_mkundef(); } -static jsval_t try_dynamic_getter(ant_t *js, jsval_t obj, const char *key, size_t key_len) { - jsoff_t obj_off = (jsoff_t)vdata(js_as_obj(obj)); +static ant_value_t try_dynamic_getter(ant_t *js, ant_value_t obj, const char *key, size_t key_len) { + ant_offset_t obj_off = (ant_offset_t)vdata(js_as_obj(obj)); dynamic_accessors_t *entry = NULL; - HASH_FIND(hh, accessor_registry, &obj_off, sizeof(jsoff_t), entry); + HASH_FIND(hh, accessor_registry, &obj_off, sizeof(ant_offset_t), entry); if (!entry || !entry->getter) return js_mkundef(); return entry->getter(js, obj, key, key_len); } -static bool try_dynamic_setter(ant_t *js, jsval_t obj, const char *key, size_t key_len, jsval_t value) { - jsoff_t obj_off = (jsoff_t)vdata(js_as_obj(obj)); +static bool try_dynamic_setter(ant_t *js, ant_value_t obj, const char *key, size_t key_len, ant_value_t value) { + ant_offset_t obj_off = (ant_offset_t)vdata(js_as_obj(obj)); dynamic_accessors_t *entry = NULL; - HASH_FIND(hh, accessor_registry, &obj_off, sizeof(jsoff_t), entry); + HASH_FIND(hh, accessor_registry, &obj_off, sizeof(ant_offset_t), entry); if (!entry || !entry->setter) return false; return entry->setter(js, obj, key, key_len, value); } -static bool try_dynamic_deleter(ant_t *js, jsval_t obj, const char *key, size_t key_len) { - jsoff_t obj_off = (jsoff_t)vdata(js_as_obj(obj)); +static bool try_dynamic_deleter(ant_t *js, ant_value_t obj, const char *key, size_t key_len) { + ant_offset_t obj_off = (ant_offset_t)vdata(js_as_obj(obj)); dynamic_accessors_t *entry = NULL; - HASH_FIND(hh, accessor_registry, &obj_off, sizeof(jsoff_t), entry); + HASH_FIND(hh, accessor_registry, &obj_off, sizeof(ant_offset_t), entry); if (!entry || !entry->deleter) return false; return entry->deleter(js, obj, key, key_len); } -static bool try_accessor_getter(ant_t *js, jsval_t obj, const char *key, size_t key_len, jsval_t *out) { - jsval_t getter = js_mkundef(); +static bool try_accessor_getter(ant_t *js, ant_value_t obj, const char *key, size_t key_len, ant_value_t *out) { + ant_value_t getter = js_mkundef(); bool has_getter = false; lkp_with_getter(js, obj, key, key_len, &getter, &has_getter); - jsval_t result = call_proto_accessor(js, obj, getter, has_getter, NULL, 0, false); + ant_value_t result = call_proto_accessor(js, obj, getter, has_getter, NULL, 0, false); if (vtype(result) != T_UNDEF) { *out = result; return true; @@ -4030,14 +4030,14 @@ static bool try_accessor_getter(ant_t *js, jsval_t obj, const char *key, size_t return false; } -static bool try_accessor_setter(ant_t *js, jsval_t obj, const char *key, size_t key_len, jsval_t val, jsval_t *out) { - jsval_t setter = js_mkundef(); +static bool try_accessor_setter(ant_t *js, ant_value_t obj, const char *key, size_t key_len, ant_value_t val, ant_value_t *out) { + ant_value_t setter = js_mkundef(); bool has_setter = false; lkp_with_setter(js, obj, key, key_len, &setter, &has_setter); if (!has_setter) return false; - jsval_t result = call_proto_accessor(js, obj, setter, has_setter, &val, 1, true); + ant_value_t result = call_proto_accessor(js, obj, setter, has_setter, &val, 1, true); if (is_err(result)) { *out = result; return true; @@ -4047,9 +4047,9 @@ static bool try_accessor_setter(ant_t *js, jsval_t obj, const char *key, size_t return true; } -jsval_t resolveprop(ant_t *js, jsval_t v) { +ant_value_t resolveprop(ant_t *js, ant_value_t v) { if (vtype(v) != T_PROP) return v; - return resolveprop(js, loadval(js, (jsoff_t) (vdata(v) + sizeof(jsoff_t) * 2))); + return resolveprop(js, loadval(js, (ant_offset_t) (vdata(v) + sizeof(ant_offset_t) * 2))); } typedef struct { @@ -4090,23 +4090,23 @@ static bool string_builder_append(string_builder_t *sb, const char *data, size_t return true; } -static jsval_t string_builder_finalize(ant_t *js, string_builder_t *sb) { - jsval_t result = js_mkstr(js, sb->buffer, sb->size); +static ant_value_t string_builder_finalize(ant_t *js, string_builder_t *sb) { + ant_value_t result = js_mkstr(js, sb->buffer, sb->size); if (sb->is_dynamic && sb->buffer) free(sb->buffer); return result; } -jsoff_t str_len_fast(ant_t *js, jsval_t str) { +ant_offset_t str_len_fast(ant_t *js, ant_value_t str) { if (vtype(str) != T_STR) return 0; if (is_rope(js, str)) return rope_len(js, str); return assert_flat_string_len(js, str, NULL); } -jsval_t do_string_op(ant_t *js, uint8_t op, jsval_t l, jsval_t r) { +ant_value_t do_string_op(ant_t *js, uint8_t op, ant_value_t l, ant_value_t r) { if (op == TOK_PLUS) { - jsoff_t n1 = str_len_fast(js, l); - jsoff_t n2 = str_len_fast(js, r); - jsoff_t total_len = n1 + n2; + ant_offset_t n1 = str_len_fast(js, l); + ant_offset_t n2 = str_len_fast(js, r); + ant_offset_t total_len = n1 + n2; if (n2 == 0) return l; if (n1 == 0) return r; @@ -4116,13 +4116,13 @@ jsval_t do_string_op(ant_t *js, uint8_t op, jsval_t l, jsval_t r) { uint8_t new_depth = (left_depth > right_depth ? left_depth : right_depth) + 1; if (new_depth >= ROPE_MAX_DEPTH || total_len >= ROPE_FLATTEN_THRESHOLD) { - jsval_t flat_l = l, flat_r = r; + ant_value_t flat_l = l, flat_r = r; if (is_rope(js, l)) flat_l = rope_flatten(js, l); if (is_err(flat_l)) return flat_l; if (is_rope(js, r)) flat_r = rope_flatten(js, r); if (is_err(flat_r)) return flat_r; - jsoff_t off1, off2, len1, len2; + ant_offset_t off1, off2, len1, len2; off1 = vstr(js, flat_l, &len1); off2 = vstr(js, flat_r, &len2); @@ -4141,8 +4141,8 @@ jsval_t do_string_op(ant_t *js, uint8_t op, jsval_t l, jsval_t r) { return js_mkrope(js, l, r, total_len, new_depth); } - jsoff_t n1, off1 = vstr(js, l, &n1); - jsoff_t n2, off2 = vstr(js, r, &n2); + ant_offset_t n1, off1 = vstr(js, l, &n1); + ant_offset_t n2, off2 = vstr(js, r, &n2); if (op == TOK_EQ) { bool eq = n1 == n2 && memcmp(&js->mem[off1], &js->mem[off2], n1) == 0; @@ -4151,7 +4151,7 @@ jsval_t do_string_op(ant_t *js, uint8_t op, jsval_t l, jsval_t r) { bool eq = n1 == n2 && memcmp(&js->mem[off1], &js->mem[off2], n1) == 0; return mkval(T_BOOL, eq ? 0 : 1); } else if (op == TOK_LT || op == TOK_LE || op == TOK_GT || op == TOK_GE) { - jsoff_t min_len = n1 < n2 ? n1 : n2; + ant_offset_t min_len = n1 < n2 ? n1 : n2; int cmp = memcmp(&js->mem[off1], &js->mem[off2], min_len); if (cmp == 0) { @@ -4172,15 +4172,15 @@ jsval_t do_string_op(ant_t *js, uint8_t op, jsval_t l, jsval_t r) { typedef enum { ITER_CONTINUE, ITER_BREAK, ITER_ERROR } iter_action_t; -typedef iter_action_t (*iter_callback_t)(ant_t *js, jsval_t value, void *ctx, jsval_t *out); -static jsval_t iter_foreach(ant_t *js, jsval_t iterable, iter_callback_t cb, void *ctx); +typedef iter_action_t (*iter_callback_t)(ant_t *js, ant_value_t value, void *ctx, ant_value_t *out); +static ant_value_t iter_foreach(ant_t *js, ant_value_t iterable, iter_callback_t cb, void *ctx); -static bool js_try_call_method(ant_t *js, jsval_t obj, const char *method, size_t method_len, jsval_t *args, int nargs, jsval_t *out_result) { - jsval_t getter = js_mkundef(); bool has_getter = false; - jsoff_t off = lkp_with_getter(js, obj, method, method_len, &getter, &has_getter); +static bool js_try_call_method(ant_t *js, ant_value_t obj, const char *method, size_t method_len, ant_value_t *args, int nargs, ant_value_t *out_result) { + ant_value_t getter = js_mkundef(); bool has_getter = false; + ant_offset_t off = lkp_with_getter(js, obj, method, method_len, &getter, &has_getter); - jsval_t fn; + ant_value_t fn; if (has_getter) { fn = call_proto_accessor(js, obj, getter, true, NULL, 0, false); if (is_err(fn)) { *out_result = fn; return true; } @@ -4191,15 +4191,15 @@ static bool js_try_call_method(ant_t *js, jsval_t obj, const char *method, size_ uint8_t ft = vtype(fn); if (ft != T_FUNC && ft != T_CFUNC) return false; - jsval_t saved_this = js->this_val; + ant_value_t saved_this = js->this_val; js->this_val = obj; - jsval_t result; - if (ft == T_CFUNC) result = ((jsval_t (*)(ant_t *, jsval_t *, int))vdata(fn))(js, args, nargs); + ant_value_t result; + if (ft == T_CFUNC) result = ((ant_value_t (*)(ant_t *, ant_value_t *, int))vdata(fn))(js, args, nargs); else result = sv_vm_call(js->vm, js, fn, obj, args, nargs, NULL, false); bool had_throw = js->thrown_exists; - jsval_t thrown = js->thrown_value; + ant_value_t thrown = js->thrown_value; js->this_val = saved_this; if (had_throw) { @@ -4211,14 +4211,14 @@ static bool js_try_call_method(ant_t *js, jsval_t obj, const char *method, size_ return true; } -static jsval_t js_call_method(ant_t *js, jsval_t obj, const char *method, size_t method_len, jsval_t *args, int nargs) { - jsval_t result; +static ant_value_t js_call_method(ant_t *js, ant_value_t obj, const char *method, size_t method_len, ant_value_t *args, int nargs) { + ant_value_t result; if (!js_try_call_method(js, obj, method, method_len, args, nargs, &result)) return js_mkundef(); return result; } -static jsval_t js_call_toString(ant_t *js, jsval_t value) { - jsval_t result = js_call_method(js, value, "toString", 8, NULL, 0); +static ant_value_t js_call_toString(ant_t *js, ant_value_t value) { + ant_value_t result = js_call_method(js, value, "toString", 8, NULL, 0); if (is_err(result)) return result; if (vtype(result) == T_STR) return result; @@ -4240,24 +4240,24 @@ fallback:; return js_mkstr(js, buf, len); } -static jsval_t js_call_valueOf(ant_t *js, jsval_t value) { - jsval_t result = js_call_method(js, value, "valueOf", 7, NULL, 0); +static ant_value_t js_call_valueOf(ant_t *js, ant_value_t value) { + ant_value_t result = js_call_method(js, value, "valueOf", 7, NULL, 0); if (vtype(result) == T_UNDEF) return value; return result; } -static inline bool is_primitive(jsval_t v) { +static inline bool is_primitive(ant_value_t v) { uint8_t t = vtype(v); return t == T_STR || t == T_NUM || t == T_BOOL || t == T_NULL || t == T_UNDEF || t == T_SYMBOL || t == T_BIGINT; } -static jsval_t try_exotic_to_primitive(ant_t *js, jsval_t value, int hint) { - jsval_t tp_sym = get_toPrimitive_sym(); +static ant_value_t try_exotic_to_primitive(ant_t *js, ant_value_t value, int hint) { + ant_value_t tp_sym = get_toPrimitive_sym(); if (vtype(tp_sym) != T_SYMBOL) return mkval(T_UNDEF, 0); - jsoff_t tp_off = lkp_sym_proto(js, value, (jsoff_t)vdata(tp_sym)); + ant_offset_t tp_off = lkp_sym_proto(js, value, (ant_offset_t)vdata(tp_sym)); if (tp_off == 0) return mkval(T_UNDEF, 0); - jsval_t tp_fn = resolveprop(js, mkval(T_PROP, tp_off)); + ant_value_t tp_fn = resolveprop(js, mkval(T_PROP, tp_off)); uint8_t ft = vtype(tp_fn); if (ft == T_UNDEF) return mkval(T_UNDEF, 0); @@ -4266,19 +4266,19 @@ static jsval_t try_exotic_to_primitive(ant_t *js, jsval_t value, int hint) { } const char *hint_str = hint == 1 ? "string" : (hint == 2 ? "number" : "default"); - jsval_t hint_arg = js_mkstr(js, hint_str, strlen(hint_str)); - jsval_t result = sv_vm_call(js->vm, js, tp_fn, value, &hint_arg, 1, NULL, false); + ant_value_t hint_arg = js_mkstr(js, hint_str, strlen(hint_str)); + ant_value_t result = sv_vm_call(js->vm, js, tp_fn, value, &hint_arg, 1, NULL, false); if (is_err(result) || is_primitive(result)) return result; return js_mkerr_typed(js, JS_ERR_TYPE, "Cannot convert object to primitive value"); } -static jsval_t try_ordinary_to_primitive(ant_t *js, jsval_t value, int hint) { +static ant_value_t try_ordinary_to_primitive(ant_t *js, ant_value_t value, int hint) { static const char *names[] = {"valueOf", "toString"}; static const size_t lens[] = {7, 8}; int first = (hint == 1); - jsval_t result; + ant_value_t result; for (int i = 0; i < 2; i++) { int idx = first ^ i; @@ -4289,21 +4289,21 @@ static jsval_t try_ordinary_to_primitive(ant_t *js, jsval_t value, int hint) { return js_mkerr_typed(js, JS_ERR_TYPE, "Cannot convert object to primitive value"); } -jsval_t js_to_primitive(ant_t *js, jsval_t value, int hint) { +ant_value_t js_to_primitive(ant_t *js, ant_value_t value, int hint) { if (is_primitive(value)) return value; if (!is_object_type(value)) return value; - jsval_t result = try_exotic_to_primitive(js, value, hint); + ant_value_t result = try_exotic_to_primitive(js, value, hint); if (vtype(result) != T_UNDEF) return result; return try_ordinary_to_primitive(js, value, hint); } -bool strict_eq_values(ant_t *js, jsval_t l, jsval_t r) { +bool strict_eq_values(ant_t *js, ant_value_t l, ant_value_t r) { uint8_t t = vtype(l); if (t != vtype(r)) return false; if (t == T_STR) { - jsoff_t n1, n2, off1 = vstr(js, l, &n1), off2 = vstr(js, r, &n2); + ant_offset_t n1, n2, off1 = vstr(js, l, &n1), off2 = vstr(js, r, &n2); return n1 == n2 && memcmp(&js->mem[off1], &js->mem[off2], n1) == 0; } if (t == T_NUM) return tod(l) == tod(r); @@ -4311,11 +4311,11 @@ bool strict_eq_values(ant_t *js, jsval_t l, jsval_t r) { return vdata(l) == vdata(r); } -jsval_t coerce_to_str(ant_t *js, jsval_t v) { +ant_value_t coerce_to_str(ant_t *js, ant_value_t v) { if (vtype(v) == T_STR) return v; if (is_object_type(v)) { - jsval_t prim = js_to_primitive(js, v, 1); + ant_value_t prim = js_to_primitive(js, v, 1); if (is_err(prim)) return prim; if (vtype(prim) == T_STR) return prim; return js_tostring_val(js, prim); @@ -4324,11 +4324,11 @@ jsval_t coerce_to_str(ant_t *js, jsval_t v) { return js_tostring_val(js, v); } -jsval_t coerce_to_str_concat(ant_t *js, jsval_t v) { +ant_value_t coerce_to_str_concat(ant_t *js, ant_value_t v) { if (vtype(v) == T_STR) return v; if (is_object_type(v)) { - jsval_t prim = js_to_primitive(js, v, 0); + ant_value_t prim = js_to_primitive(js, v, 0); if (is_err(prim)) return prim; if (vtype(prim) == T_STR) return prim; return js_tostring_val(js, prim); @@ -4337,23 +4337,23 @@ jsval_t coerce_to_str_concat(ant_t *js, jsval_t v) { return js_tostring_val(js, v); } -static void unlink_prop(ant_t *js, jsoff_t obj_off, jsoff_t prop_off, jsoff_t prev_off) { - jsoff_t deleted_next = loadoff(js, prop_off) & ~FLAGMASK; - jsoff_t target = prev_off ? prev_off : obj_off; - jsoff_t current = loadoff(js, target); +static void unlink_prop(ant_t *js, ant_offset_t obj_off, ant_offset_t prop_off, ant_offset_t prev_off) { + ant_offset_t deleted_next = loadoff(js, prop_off) & ~FLAGMASK; + ant_offset_t target = prev_off ? prev_off : obj_off; + ant_offset_t current = loadoff(js, target); saveoff(js, target, (deleted_next & ~3ULL) | (current & (FLAGMASK | 3ULL))); - jsoff_t tail = loadoff(js, obj_off + sizeof(jsoff_t) + sizeof(jsoff_t)); + ant_offset_t tail = loadoff(js, obj_off + sizeof(ant_offset_t) + sizeof(ant_offset_t)); if (tail == prop_off) { - saveoff(js, obj_off + sizeof(jsoff_t) + sizeof(jsoff_t), prev_off); + saveoff(js, obj_off + sizeof(ant_offset_t) + sizeof(ant_offset_t), prev_off); } invalidate_prop_cache(js, obj_off, prop_off); js->needs_gc = true; } -static jsval_t check_frozen_sealed(ant_t *js, jsval_t obj, const char *action) { +static ant_value_t check_frozen_sealed(ant_t *js, ant_value_t obj, const char *action) { if (js_truthy(js, get_slot(js, obj, SLOT_FROZEN))) { if (sv_vm_is_strict(js->vm)) return js_mkerr(js, "cannot %s property of frozen object", action); return js_false; @@ -4365,28 +4365,28 @@ static jsval_t check_frozen_sealed(ant_t *js, jsval_t obj, const char *action) { return js_mkundef(); } -jsval_t js_delete_prop(ant_t *js, jsval_t obj, const char *key, size_t len) { +ant_value_t js_delete_prop(ant_t *js, ant_value_t obj, const char *key, size_t len) { obj = js_as_obj(obj); if (is_proxy(js, obj)) { - jsval_t result = proxy_delete(js, obj, key, len); + ant_value_t result = proxy_delete(js, obj, key, len); return is_err(result) ? result : js_bool(js_truthy(js, result)); } - jsval_t err = check_frozen_sealed(js, obj, "delete"); + ant_value_t err = check_frozen_sealed(js, obj, "delete"); if (vtype(err) != T_UNDEF) return err; - jsoff_t obj_off = (jsoff_t)vdata(js_as_obj(obj)); + ant_offset_t obj_off = (ant_offset_t)vdata(js_as_obj(obj)); if (is_arr_off(js, obj_off)) { - jsoff_t doff = get_dense_buf_off(js, obj_off); + ant_offset_t doff = get_dense_buf_off(js, obj_off); unsigned long del_idx; if (doff && parse_array_index(key, len, dense_length(js, doff), &del_idx)) { - arr_del(js, mkval(T_ARR, (uint64_t)obj_off), (jsoff_t)del_idx); + arr_del(js, mkval(T_ARR, (uint64_t)obj_off), (ant_offset_t)del_idx); return js_true; } } - jsoff_t prop_off = lkp(js, obj, key, len); + ant_offset_t prop_off = lkp(js, obj, key, len); if (prop_off == 0) { try_dynamic_deleter(js, obj, key, len); return js_true; @@ -4403,13 +4403,13 @@ jsval_t js_delete_prop(ant_t *js, jsval_t obj, const char *key, size_t len) { return js_false; } - jsoff_t first_prop = loadoff(js, obj_off) & ~(3U | FLAGMASK); + ant_offset_t first_prop = loadoff(js, obj_off) & ~(3U | FLAGMASK); if (first_prop == prop_off) { unlink_prop(js, obj_off, prop_off, 0); return js_true; } - for (jsoff_t prev = first_prop; prev != 0; ) { - jsoff_t next_prop = loadoff(js, prev) & ~(3U | FLAGMASK); + for (ant_offset_t prev = first_prop; prev != 0; ) { + ant_offset_t next_prop = loadoff(js, prev) & ~(3U | FLAGMASK); if (next_prop == prop_off) { unlink_prop(js, obj_off, prop_off, prev); return js_true; @@ -4419,19 +4419,19 @@ jsval_t js_delete_prop(ant_t *js, jsval_t obj, const char *key, size_t len) { return js_true; } -jsval_t js_delete_sym_prop(ant_t *js, jsval_t obj, jsval_t sym) { +ant_value_t js_delete_sym_prop(ant_t *js, ant_value_t obj, ant_value_t sym) { obj = js_as_obj(obj); if (is_proxy(js, obj)) { - jsval_t result = proxy_delete_val(js, obj, sym); + ant_value_t result = proxy_delete_val(js, obj, sym); return is_err(result) ? result : js_bool(js_truthy(js, result)); } - jsval_t err = check_frozen_sealed(js, obj, "delete"); + ant_value_t err = check_frozen_sealed(js, obj, "delete"); if (vtype(err) != T_UNDEF) return err; - jsoff_t obj_off = (jsoff_t)vdata(obj); - jsoff_t sym_off = (jsoff_t)vdata(sym); - jsoff_t prop_off = lkp_sym(js, obj, sym_off); + ant_offset_t obj_off = (ant_offset_t)vdata(obj); + ant_offset_t sym_off = (ant_offset_t)vdata(sym); + ant_offset_t prop_off = lkp_sym(js, obj, sym_off); if (prop_off == 0) return js_true; if (is_nonconfig_prop(js, prop_off)) { @@ -4439,13 +4439,13 @@ jsval_t js_delete_sym_prop(ant_t *js, jsval_t obj, jsval_t sym) { return js_false; } - jsoff_t first_prop = loadoff(js, obj_off) & ~(3U | FLAGMASK); + ant_offset_t first_prop = loadoff(js, obj_off) & ~(3U | FLAGMASK); if (first_prop == prop_off) { unlink_prop(js, obj_off, prop_off, 0); return js_true; } - for (jsoff_t prev = first_prop; prev != 0; ) { - jsoff_t np = loadoff(js, prev) & ~(3U | FLAGMASK); + for (ant_offset_t prev = first_prop; prev != 0; ) { + ant_offset_t np = loadoff(js, prev) & ~(3U | FLAGMASK); if (np == prop_off) { unlink_prop(js, obj_off, prop_off, prev); return js_true; @@ -4455,63 +4455,63 @@ jsval_t js_delete_sym_prop(ant_t *js, jsval_t obj, jsval_t sym) { return js_true; } -static jsval_t iter_call_noargs_with_this(ant_t *js, jsval_t this_val, jsval_t method) { - jsval_t result = sv_vm_call(js->vm, js, method, this_val, NULL, 0, NULL, false); +static ant_value_t iter_call_noargs_with_this(ant_t *js, ant_value_t this_val, ant_value_t method) { + ant_value_t result = sv_vm_call(js->vm, js, method, this_val, NULL, 0, NULL, false); return result; } -static jsval_t iter_close_iterator(ant_t *js, jsval_t iterator) { - jsoff_t return_off = lkp_proto(js, iterator, "return", 6); +static ant_value_t iter_close_iterator(ant_t *js, ant_value_t iterator) { + ant_offset_t return_off = lkp_proto(js, iterator, "return", 6); if (return_off == 0) return js_mkundef(); - jsval_t return_method = loadval(js, return_off + sizeof(jsoff_t) * 2); + ant_value_t return_method = loadval(js, return_off + sizeof(ant_offset_t) * 2); if (vtype(return_method) != T_FUNC && vtype(return_method) != T_CFUNC) { return js_mkerr(js, "iterator.return is not a function"); } return iter_call_noargs_with_this(js, iterator, return_method); } -static jsval_t iter_foreach(ant_t *js, jsval_t iterable, iter_callback_t cb, void *ctx) { - jsval_t iter_sym = get_iterator_sym(); - jsoff_t iter_prop = (vtype(iter_sym) == T_SYMBOL) ? lkp_sym_proto(js, iterable, (jsoff_t)vdata(iter_sym)) : 0; +static ant_value_t iter_foreach(ant_t *js, ant_value_t iterable, iter_callback_t cb, void *ctx) { + ant_value_t iter_sym = get_iterator_sym(); + ant_offset_t iter_prop = (vtype(iter_sym) == T_SYMBOL) ? lkp_sym_proto(js, iterable, (ant_offset_t)vdata(iter_sym)) : 0; if (iter_prop == 0) return js_mkerr(js, "not iterable"); - jsval_t iter_method = loadval(js, iter_prop + sizeof(jsoff_t) * 2); - jsval_t iterator = iter_call_noargs_with_this(js, iterable, iter_method); + ant_value_t iter_method = loadval(js, iter_prop + sizeof(ant_offset_t) * 2); + ant_value_t iterator = iter_call_noargs_with_this(js, iterable, iter_method); if (is_err(iterator)) return iterator; - jshdl_t h_iterator = js_root(js, iterator); - jsval_t out = js_mkundef(); + ant_handle_t h_iterator = js_root(js, iterator); + ant_value_t out = js_mkundef(); while (true) { - jsval_t cur_iter = js_deref(js, h_iterator); - jsoff_t next_off = lkp_proto(js, cur_iter, "next", 4); + ant_value_t cur_iter = js_deref(js, h_iterator); + ant_offset_t next_off = lkp_proto(js, cur_iter, "next", 4); if (next_off == 0) { js_unroot(js, h_iterator); return js_mkerr(js, "iterator.next is not a function"); } - jsval_t next_method = loadval(js, next_off + sizeof(jsoff_t) * 2); + ant_value_t next_method = loadval(js, next_off + sizeof(ant_offset_t) * 2); if (vtype(next_method) != T_FUNC && vtype(next_method) != T_CFUNC) { js_unroot(js, h_iterator); return js_mkerr(js, "iterator.next is not a function"); } cur_iter = js_deref(js, h_iterator); - jsval_t result = iter_call_noargs_with_this(js, cur_iter, next_method); + ant_value_t result = iter_call_noargs_with_this(js, cur_iter, next_method); if (is_err(result)) { js_unroot(js, h_iterator); return result; } - jsoff_t done_off = lkp(js, result, "done", 4); - jsval_t done_val = done_off ? loadval(js, done_off + sizeof(jsoff_t) * 2) : js_mkundef(); + ant_offset_t done_off = lkp(js, result, "done", 4); + ant_value_t done_val = done_off ? loadval(js, done_off + sizeof(ant_offset_t) * 2) : js_mkundef(); if (js_truthy(js, done_val)) break; - jsoff_t value_off = lkp(js, result, "value", 5); - jsval_t value = value_off ? loadval(js, value_off + sizeof(jsoff_t) * 2) : js_mkundef(); + ant_offset_t value_off = lkp(js, result, "value", 5); + ant_value_t value = value_off ? loadval(js, value_off + sizeof(ant_offset_t) * 2) : js_mkundef(); iter_action_t action = cb(js, value, ctx, &out); if (action == ITER_BREAK) { - jsval_t close_result = iter_close_iterator(js, cur_iter); + ant_value_t close_result = iter_close_iterator(js, cur_iter); if (is_err(close_result)) { js_unroot(js, h_iterator); return close_result; } break; } if (action == ITER_ERROR) { - jsval_t close_result = iter_close_iterator(js, cur_iter); + ant_value_t close_result = iter_close_iterator(js, cur_iter); js_unroot(js, h_iterator); if (is_err(close_result)) return close_result; return out; @@ -4522,7 +4522,7 @@ static jsval_t iter_foreach(ant_t *js, jsval_t iterable, iter_callback_t cb, voi return out; } -jsval_t js_symbol_to_string(ant_t *js, jsval_t sym) { +ant_value_t js_symbol_to_string(ant_t *js, ant_value_t sym) { const char *desc = js_sym_desc(js, sym); if (!desc) return js_mkstr(js, "Symbol()", 8); @@ -4538,13 +4538,13 @@ jsval_t js_symbol_to_string(ant_t *js, jsval_t sym) { buf[7 + desc_len] = ')'; buf[total] = '\0'; - jsval_t result = js_mkstr(js, buf, total); + ant_value_t result = js_mkstr(js, buf, total); if (buf != stack_buf) free(buf); return result; } -static jsval_t builtin_String(ant_t *js, jsval_t *args, int nargs) { - jsval_t sval; +static ant_value_t builtin_String(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t sval; if (nargs == 0) { sval = js_mkstr(js, "", 0); @@ -4558,10 +4558,10 @@ static jsval_t builtin_String(ant_t *js, jsval_t *args, int nargs) { if (is_err(sval)) return sval; } - jsval_t string_proto = js_get_ctor_proto(js, "String", 6); + ant_value_t string_proto = js_get_ctor_proto(js, "String", 6); if (is_wrapper_ctor_target(js, js->this_val, string_proto)) { set_slot(js, js->this_val, SLOT_PRIMITIVE, sval); - jsoff_t slen; + ant_offset_t slen; vstr(js, sval, &slen); js_setprop(js, js->this_val, js->length_str, tov((double)slen)); js_set_descriptor(js, js->this_val, "length", 6, 0); @@ -4569,9 +4569,9 @@ static jsval_t builtin_String(ant_t *js, jsval_t *args, int nargs) { return sval; } -static jsval_t builtin_Number_isNaN(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Number_isNaN(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return mkval(T_BOOL, 0); - jsval_t arg = args[0]; + ant_value_t arg = args[0]; if (vtype(arg) != T_NUM) return mkval(T_BOOL, 0); @@ -4579,9 +4579,9 @@ static jsval_t builtin_Number_isNaN(ant_t *js, jsval_t *args, int nargs) { return mkval(T_BOOL, isnan(val) ? 1 : 0); } -static jsval_t builtin_Number_isFinite(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Number_isFinite(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return mkval(T_BOOL, 0); - jsval_t arg = args[0]; + ant_value_t arg = args[0]; if (vtype(arg) != T_NUM) return mkval(T_BOOL, 0); @@ -4589,31 +4589,31 @@ static jsval_t builtin_Number_isFinite(ant_t *js, jsval_t *args, int nargs) { return mkval(T_BOOL, isfinite(val) ? 1 : 0); } -static jsval_t builtin_global_isNaN(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_global_isNaN(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return mkval(T_BOOL, 1); double val = js_to_number(js, args[0]); return mkval(T_BOOL, isnan(val) ? 1 : 0); } -static jsval_t builtin_global_isFinite(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_global_isFinite(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return mkval(T_BOOL, 0); double val = js_to_number(js, args[0]); return mkval(T_BOOL, isfinite(val) ? 1 : 0); } -static jsval_t builtin_eval(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_eval(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return js_mkundef(); - jsval_t code = args[0]; + ant_value_t code = args[0]; if (vtype(code) != T_STR) return code; - jsoff_t code_len = 0; - jsoff_t code_off = vstr(js, code, &code_len); + ant_offset_t code_len = 0; + ant_offset_t code_off = vstr(js, code, &code_len); const char *code_str = (const char *)&js->mem[code_off]; return js_eval_bytecode_eval_with_strict(js, code_str, (size_t)code_len, false); } -static jsval_t builtin_Number_isInteger(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Number_isInteger(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return mkval(T_BOOL, 0); - jsval_t arg = args[0]; + ant_value_t arg = args[0]; if (vtype(arg) != T_NUM) return mkval(T_BOOL, 0); @@ -4622,9 +4622,9 @@ static jsval_t builtin_Number_isInteger(ant_t *js, jsval_t *args, int nargs) { return mkval(T_BOOL, (val == floor(val)) ? 1 : 0); } -static jsval_t builtin_Number_isSafeInteger(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Number_isSafeInteger(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return mkval(T_BOOL, 0); - jsval_t arg = args[0]; + ant_value_t arg = args[0]; if (vtype(arg) != T_NUM) return mkval(T_BOOL, 0); @@ -4635,40 +4635,40 @@ static jsval_t builtin_Number_isSafeInteger(ant_t *js, jsval_t *args, int nargs) return mkval(T_BOOL, (val >= -9007199254740991.0 && val <= 9007199254740991.0) ? 1 : 0); } -static jsval_t builtin_Number(ant_t *js, jsval_t *args, int nargs) { - jsval_t nval = tov(nargs > 0 ? js_to_number(js, args[0]) : 0.0); - jsval_t number_proto = js_get_ctor_proto(js, "Number", 6); +static ant_value_t builtin_Number(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t nval = tov(nargs > 0 ? js_to_number(js, args[0]) : 0.0); + ant_value_t number_proto = js_get_ctor_proto(js, "Number", 6); if (is_wrapper_ctor_target(js, js->this_val, number_proto)) { set_slot(js, js->this_val, SLOT_PRIMITIVE, nval); } return nval; } -static jsval_t builtin_Boolean(ant_t *js, jsval_t *args, int nargs) { - jsval_t bval = mkval(T_BOOL, nargs > 0 && js_truthy(js, args[0]) ? 1 : 0); - jsval_t boolean_proto = js_get_ctor_proto(js, "Boolean", 7); +static ant_value_t builtin_Boolean(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t bval = mkval(T_BOOL, nargs > 0 && js_truthy(js, args[0]) ? 1 : 0); + ant_value_t boolean_proto = js_get_ctor_proto(js, "Boolean", 7); if (is_wrapper_ctor_target(js, js->this_val, boolean_proto)) { set_slot(js, js->this_val, SLOT_PRIMITIVE, bval); } return bval; } -static jsval_t builtin_Object(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Object(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0 || vtype(args[0]) == T_NULL || vtype(args[0]) == T_UNDEF) { - jsval_t obj_proto = js_get_ctor_proto(js, "Object", 6); + ant_value_t obj_proto = js_get_ctor_proto(js, "Object", 6); if (is_unboxed_obj(js, js->this_val, obj_proto)) return js->this_val; return js_mkobj(js); } - jsval_t arg = args[0]; + ant_value_t arg = args[0]; uint8_t t = vtype(arg); if (t == T_OBJ || t == T_ARR || t == T_FUNC) return arg; if (t == T_STR || t == T_NUM || t == T_BOOL || t == T_BIGINT) { - jsval_t wrapper = js_mkobj(js); + ant_value_t wrapper = js_mkobj(js); if (is_err(wrapper)) return wrapper; set_slot(js, wrapper, SLOT_PRIMITIVE, arg); - jsval_t proto = get_prototype_for_type(js, t); + ant_value_t proto = get_prototype_for_type(js, t); if (vtype(proto) == T_OBJ) set_proto(js, wrapper, proto); return wrapper; } @@ -4676,27 +4676,27 @@ static jsval_t builtin_Object(ant_t *js, jsval_t *args, int nargs) { return arg; } -static jsval_t builtin_function_empty(ant_t *, jsval_t *, int); +static ant_value_t builtin_function_empty(ant_t *, ant_value_t *, int); -static jsval_t build_dynamic_function(ant_t *js, jsval_t *args, int nargs, bool is_async) { +static ant_value_t build_dynamic_function(ant_t *js, ant_value_t *args, int nargs, bool is_async) { if (nargs == 0) { - jsval_t func_obj = mkobj(js, 0); + ant_value_t func_obj = mkobj(js, 0); if (is_err(func_obj)) return func_obj; set_func_code_ptr(js, func_obj, "(){}", 4); if (is_async) { set_slot(js, func_obj, SLOT_ASYNC, js_true); - jsval_t async_proto = get_slot(js, js_glob(js), SLOT_ASYNC_PROTO); + ant_value_t async_proto = get_slot(js, js_glob(js), SLOT_ASYNC_PROTO); if (vtype(async_proto) == T_FUNC) set_proto(js, func_obj, async_proto); } else { - jsval_t func_proto = get_slot(js, js_glob(js), SLOT_FUNC_PROTO); - jsval_t instance_proto = js_instance_proto_from_new_target(js, func_proto); + ant_value_t func_proto = get_slot(js, js_glob(js), SLOT_FUNC_PROTO); + ant_value_t instance_proto = js_instance_proto_from_new_target(js, func_proto); if (is_object_type(instance_proto)) set_proto(js, func_obj, instance_proto); } set_slot(js, func_obj, SLOT_CFUNC, js_mkfun(builtin_function_empty)); - jsval_t func = js_obj_to_func(func_obj); - jsval_t proto_setup = setup_func_prototype(js, func); + ant_value_t func = js_obj_to_func(func_obj); + ant_value_t proto_setup = setup_func_prototype(js, func); if (is_err(proto_setup)) return proto_setup; return func; } @@ -4712,7 +4712,7 @@ static jsval_t build_dynamic_function(ant_t *js, jsval_t *args, int nargs, bool total_len += 2; - jsval_t body = coerce_to_str(js, args[nargs - 1]); + ant_value_t body = coerce_to_str(js, args[nargs - 1]); if (is_err(body)) return body; total_len += vstrlen(js, body); total_len += 1; @@ -4723,20 +4723,20 @@ static jsval_t build_dynamic_function(ant_t *js, jsval_t *args, int nargs, bool code_buf[pos++] = '('; for (int i = 0; i < nargs - 1; i++) { - jsoff_t param_len, param_off = vstr(js, args[i], ¶m_len); + ant_offset_t param_len, param_off = vstr(js, args[i], ¶m_len); memcpy(code_buf + pos, &js->mem[param_off], param_len); pos += param_len; if (i < nargs - 2) code_buf[pos++] = ','; } code_buf[pos++] = ')'; code_buf[pos++] = '{'; - jsoff_t body_len, body_off = vstr(js, body, &body_len); + ant_offset_t body_len, body_off = vstr(js, body, &body_len); memcpy(code_buf + pos, &js->mem[body_off], body_len); pos += body_len; code_buf[pos++] = '}'; code_buf[pos] = '\0'; - jsval_t func_obj = mkobj(js, 0); + ant_value_t func_obj = mkobj(js, 0); if (is_err(func_obj)) { free(code_buf); return func_obj; } sv_func_t *compiled = sv_compile_function(js, code_buf, pos, is_async); @@ -4772,42 +4772,42 @@ static jsval_t build_dynamic_function(ant_t *js, jsval_t *args, int nargs, bool if (is_async) { set_slot(js, func_obj, SLOT_ASYNC, js_true); - jsval_t async_proto = get_slot(js, js_glob(js), SLOT_ASYNC_PROTO); + ant_value_t async_proto = get_slot(js, js_glob(js), SLOT_ASYNC_PROTO); if (vtype(async_proto) == T_FUNC) set_proto(js, func_obj, async_proto); } else { - jsval_t func_proto = get_slot(js, js_glob(js), SLOT_FUNC_PROTO); - jsval_t instance_proto = js_instance_proto_from_new_target(js, func_proto); + ant_value_t func_proto = get_slot(js, js_glob(js), SLOT_FUNC_PROTO); + ant_value_t instance_proto = js_instance_proto_from_new_target(js, func_proto); if (is_object_type(instance_proto)) set_proto(js, func_obj, instance_proto); } - jsval_t func = mkval(T_FUNC, (uintptr_t)closure); - jsval_t proto_setup = setup_func_prototype(js, func); + ant_value_t func = mkval(T_FUNC, (uintptr_t)closure); + ant_value_t proto_setup = setup_func_prototype(js, func); if (is_err(proto_setup)) return proto_setup; return func; } -static jsval_t builtin_Function(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Function(ant_t *js, ant_value_t *args, int nargs) { return build_dynamic_function(js, args, nargs, false); } -static jsval_t builtin_AsyncFunction(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_AsyncFunction(ant_t *js, ant_value_t *args, int nargs) { return build_dynamic_function(js, args, nargs, true); } -static jsval_t builtin_function_empty(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_function_empty(ant_t *js, ant_value_t *args, int nargs) { (void)js; (void)args; (void)nargs; return js_mkundef(); } -static jsval_t builtin_function_call(ant_t *js, jsval_t *args, int nargs) { - jsval_t func = js->this_val; +static ant_value_t builtin_function_call(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t func = js->this_val; if (vtype(func) != T_FUNC && vtype(func) != T_CFUNC) { return js_mkerr(js, "call requires a function"); } - jsval_t this_arg = (nargs > 0) ? args[0] : js_mkundef(); + ant_value_t this_arg = (nargs > 0) ? args[0] : js_mkundef(); - jsval_t *call_args = NULL; + ant_value_t *call_args = NULL; int call_nargs = (nargs > 1) ? nargs - 1 : 0; if (call_nargs > 0) { call_args = &args[1]; @@ -4816,23 +4816,23 @@ static jsval_t builtin_function_call(ant_t *js, jsval_t *args, int nargs) { return sv_vm_call(js->vm, js, func, this_arg, call_args, call_nargs, NULL, false); } -static int extract_array_args(ant_t *js, jsval_t arr, jsval_t **out_args) { +static int extract_array_args(ant_t *js, ant_value_t arr, ant_value_t **out_args) { int len = (int) get_array_length(js, arr); if (len <= 0) return 0; - jsval_t *args_out = (jsval_t *)ant_calloc(sizeof(jsval_t) * len); + ant_value_t *args_out = (ant_value_t *)ant_calloc(sizeof(ant_value_t) * len); if (!args_out) return 0; for (int i = 0; i < len; i++) { - args_out[i] = arr_get(js, arr, (jsoff_t)i); + args_out[i] = arr_get(js, arr, (ant_offset_t)i); } *out_args = args_out; return len; } -static jsval_t builtin_function_toString(ant_t *js, jsval_t *args, int nargs) { - jsval_t func = js->this_val; +static ant_value_t builtin_function_toString(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t func = js->this_val; uint8_t t = vtype(func); if (t != T_FUNC && t != T_CFUNC) { @@ -4841,11 +4841,11 @@ static jsval_t builtin_function_toString(ant_t *js, jsval_t *args, int nargs) { if (t == T_CFUNC) return ANT_STRING("function() { [native code] }"); - jsval_t func_obj = js_func_obj(func); - jsval_t cfunc_slot = get_slot(js, func_obj, SLOT_CFUNC); + ant_value_t func_obj = js_func_obj(func); + ant_value_t cfunc_slot = get_slot(js, func_obj, SLOT_CFUNC); if (vtype(cfunc_slot) == T_CFUNC) { - jsoff_t name_len = 0; + ant_offset_t name_len = 0; const char *name = get_func_name(js, func, &name_len); if (name && name_len > 0) { size_t total = 9 + name_len + 21 + 1; @@ -4854,23 +4854,23 @@ static jsval_t builtin_function_toString(ant_t *js, jsval_t *args, int nargs) { n += cpy(buf + n, total - n, "function ", 9); n += cpy(buf + n, total - n, name, name_len); n += cpy(buf + n, total - n, "() { [native code] }", 20); - jsval_t result = js_mkstr(js, buf, n); + ant_value_t result = js_mkstr(js, buf, n); free(buf); return result; } return ANT_STRING("function() { [native code] }"); } - jsval_t code_val = get_slot(js, func_obj, SLOT_CODE); - jsval_t len_val = get_slot(js, func_obj, SLOT_CODE_LEN); + ant_value_t code_val = get_slot(js, func_obj, SLOT_CODE); + ant_value_t len_val = get_slot(js, func_obj, SLOT_CODE_LEN); if (vtype(code_val) == T_CFUNC && vtype(len_val) == T_NUM) { const char *code = (const char *)(uintptr_t)vdata(code_val); size_t code_len = (size_t)tod(len_val); if (code && code_len > 0) { - jsval_t async_slot = get_slot(js, func_obj, SLOT_ASYNC); - jsval_t arrow_slot = get_slot(js, func_obj, SLOT_ARROW); + ant_value_t async_slot = get_slot(js, func_obj, SLOT_ASYNC); + ant_value_t arrow_slot = get_slot(js, func_obj, SLOT_ARROW); bool is_async = (async_slot == js_true); bool is_arrow = (arrow_slot == js_true); @@ -4892,7 +4892,7 @@ static jsval_t builtin_function_toString(ant_t *js, jsval_t *args, int nargs) { n += cpy(buf + n, REMAIN(n, len), " => ", 4); n += cpy(buf + n, REMAIN(n, len), body, body_len); - jsval_t result = js_mkstr(js, buf, n); + ant_value_t result = js_mkstr(js, buf, n); free(buf); return result; fallback_arrow:; @@ -4918,50 +4918,50 @@ static jsval_t builtin_function_toString(ant_t *js, jsval_t *args, int nargs) { return js_mkstr(js, buf, len); } -static jsval_t builtin_function_apply(ant_t *js, jsval_t *args, int nargs) { - jsval_t func = js->this_val; +static ant_value_t builtin_function_apply(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t func = js->this_val; if (vtype(func) != T_FUNC && vtype(func) != T_CFUNC) { return js_mkerr_typed(js, JS_ERR_TYPE, "Function.prototype.apply requires that 'this' be a Function"); } - jsval_t this_arg = (nargs > 0) ? args[0] : js_mkundef(); - jsval_t *call_args = NULL; + ant_value_t this_arg = (nargs > 0) ? args[0] : js_mkundef(); + ant_value_t *call_args = NULL; int call_nargs = 0; if (nargs > 1) { - jsval_t arg_array = args[1]; + ant_value_t arg_array = args[1]; uint8_t t = vtype(arg_array); if (t == T_ARR || t == T_OBJ) { call_nargs = extract_array_args(js, arg_array, &call_args); } else if (t != T_UNDEF && t != T_NULL) {} } - jsval_t result = sv_vm_call(js->vm, js, func, this_arg, call_args, call_nargs, NULL, false); + ant_value_t result = sv_vm_call(js->vm, js, func, this_arg, call_args, call_nargs, NULL, false); if (call_args) free(call_args); return result; } -static jsval_t builtin_function_bind(ant_t *js, jsval_t *args, int nargs) { - jsval_t func = js->this_val; +static ant_value_t builtin_function_bind(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t func = js->this_val; if (vtype(func) != T_FUNC && vtype(func) != T_CFUNC) { return js_mkerr_typed(js, JS_ERR_TYPE, "bind requires a function"); } - jsval_t this_arg = (nargs > 0) ? args[0] : js_mkundef(); + ant_value_t this_arg = (nargs > 0) ? args[0] : js_mkundef(); int bound_argc = (nargs > 1) ? nargs - 1 : 0; - jsval_t *bound_args = (bound_argc > 0) ? &args[1] : NULL; + ant_value_t *bound_args = (bound_argc > 0) ? &args[1] : NULL; int orig_length = 0; - jsval_t target_func_obj; + ant_value_t target_func_obj; if (vtype(func) == T_CFUNC) { orig_length = 0; } else { target_func_obj = js_func_obj(func); - jsoff_t len_off = lkp_interned(js, target_func_obj, INTERN_LENGTH, 6); + ant_offset_t len_off = lkp_interned(js, target_func_obj, INTERN_LENGTH, 6); if (len_off != 0) { - jsval_t len_val = resolveprop(js, mkval(T_PROP, len_off)); + ant_value_t len_val = resolveprop(js, mkval(T_PROP, len_off)); if (vtype(len_val) == T_NUM) { orig_length = (int) tod(len_val); } @@ -4972,35 +4972,35 @@ static jsval_t builtin_function_bind(ant_t *js, jsval_t *args, int nargs) { if (bound_length < 0) bound_length = 0; if (vtype(func) == T_CFUNC) { - jsval_t bound_func = mkobj(js, 0); + ant_value_t bound_func = mkobj(js, 0); if (is_err(bound_func)) return bound_func; set_slot(js, bound_func, SLOT_CFUNC, func); set_slot(js, bound_func, SLOT_BOUND_THIS, this_arg); if (bound_argc > 0) { - jsval_t bound_arr = mkarr(js); - for (int i = 0; i < bound_argc; i++) arr_set(js, bound_arr, (jsoff_t)i, bound_args[i]); + ant_value_t bound_arr = mkarr(js); + for (int i = 0; i < bound_argc; i++) arr_set(js, bound_arr, (ant_offset_t)i, bound_args[i]); set_slot(js, bound_func, SLOT_BOUND_ARGS, bound_arr); } - jsval_t func_proto = get_slot(js, js_glob(js), SLOT_FUNC_PROTO); + ant_value_t func_proto = get_slot(js, js_glob(js), SLOT_FUNC_PROTO); if (vtype(func_proto) == T_FUNC) set_proto(js, bound_func, func_proto); - jsval_t bound = js_obj_to_func(bound_func); + ant_value_t bound = js_obj_to_func(bound_func); js_setprop(js, bound_func, js->length_str, tov((double) bound_length)); - jsval_t proto_setup = setup_func_prototype(js, bound); + ant_value_t proto_setup = setup_func_prototype(js, bound); if (is_err(proto_setup)) return proto_setup; return bound; } - jsval_t func_obj = js_func_obj(func); - jsval_t bound_func = mkobj(js, 0); + ant_value_t func_obj = js_func_obj(func); + ant_value_t bound_func = mkobj(js, 0); if (is_err(bound_func)) return bound_func; - jsval_t code_val = get_slot(js, func_obj, SLOT_CODE); + ant_value_t code_val = get_slot(js, func_obj, SLOT_CODE); if (vtype(code_val) == T_STR || vtype(code_val) == T_CFUNC) { set_slot(js, bound_func, SLOT_CODE, code_val); set_slot(js, bound_func, SLOT_CODE_LEN, get_slot(js, func_obj, SLOT_CODE_LEN)); @@ -5016,23 +5016,23 @@ static jsval_t builtin_function_bind(ant_t *js, jsval_t *args, int nargs) { if (bound_argc > 0) bound_closure->call_flags |= SV_CALL_HAS_BOUND_ARGS; - jsval_t async_slot = get_slot(js, func_obj, SLOT_ASYNC); + ant_value_t async_slot = get_slot(js, func_obj, SLOT_ASYNC); if (vtype(async_slot) == T_BOOL && vdata(async_slot) == 1) { set_slot(js, bound_func, SLOT_ASYNC, js_true); } - jsval_t target_proto = get_proto(js, func); + ant_value_t target_proto = get_proto(js, func); if (is_object_type(target_proto)) { set_proto(js, bound_func, target_proto); } else if (vtype(async_slot) == T_BOOL && vdata(async_slot) == 1) { - jsval_t async_proto = get_slot(js, js_glob(js), SLOT_ASYNC_PROTO); + ant_value_t async_proto = get_slot(js, js_glob(js), SLOT_ASYNC_PROTO); if (vtype(async_proto) == T_FUNC) set_proto(js, bound_func, async_proto); } else { - jsval_t func_proto = get_slot(js, js_glob(js), SLOT_FUNC_PROTO); + ant_value_t func_proto = get_slot(js, js_glob(js), SLOT_FUNC_PROTO); if (vtype(func_proto) == T_FUNC) set_proto(js, bound_func, func_proto); } - jsval_t data_slot = get_slot(js, func_obj, SLOT_DATA); + ant_value_t data_slot = get_slot(js, func_obj, SLOT_DATA); if (vtype(data_slot) != T_UNDEF) { set_slot(js, bound_func, SLOT_DATA, data_slot); } @@ -5041,45 +5041,45 @@ static jsval_t builtin_function_bind(ant_t *js, jsval_t *args, int nargs) { set_slot(js, bound_func, SLOT_BOUND_THIS, this_arg); if (bound_argc > 0) { - jsval_t bound_arr = mkarr(js); - for (int i = 0; i < bound_argc; i++) arr_set(js, bound_arr, (jsoff_t)i, bound_args[i]); + ant_value_t bound_arr = mkarr(js); + for (int i = 0; i < bound_argc; i++) arr_set(js, bound_arr, (ant_offset_t)i, bound_args[i]); set_slot(js, bound_func, SLOT_BOUND_ARGS, bound_arr); } - jsval_t cfunc_slot = get_slot(js, func_obj, SLOT_CFUNC); + ant_value_t cfunc_slot = get_slot(js, func_obj, SLOT_CFUNC); if (vtype(cfunc_slot) == T_CFUNC) { set_slot(js, bound_func, SLOT_CFUNC, cfunc_slot); } js_setprop(js, bound_func, js->length_str, tov((double) bound_length)); - jsval_t bound = mkval(T_FUNC, (uintptr_t)bound_closure); - jsval_t proto_setup = setup_func_prototype(js, bound); + ant_value_t bound = mkval(T_FUNC, (uintptr_t)bound_closure); + ant_value_t proto_setup = setup_func_prototype(js, bound); if (is_err(proto_setup)) return proto_setup; return bound; } -static jsval_t builtin_Array(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = mkarr(js); +static ant_value_t builtin_Array(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = mkarr(js); if (is_err(arr)) return arr; if (nargs == 1 && vtype(args[0]) == T_NUM) { - jsval_t err = validate_array_length(js, args[0]); + ant_value_t err = validate_array_length(js, args[0]); if (is_err(err)) return err; - jsoff_t new_len = (jsoff_t)tod(args[0]); - jsoff_t doff = get_dense_buf(js, arr); + ant_offset_t new_len = (ant_offset_t)tod(args[0]); + ant_offset_t doff = get_dense_buf(js, arr); if (doff && new_len <= 1024) { if (new_len > dense_capacity(js, doff)) doff = dense_grow(js, arr, new_len); if (doff) dense_set_length(js, doff, new_len); } update_array_length(js, arr, new_len); } else if (nargs > 0) { - for (int i = 0; i < nargs; i++) arr_set(js, arr, (jsoff_t)i, args[i]); + for (int i = 0; i < nargs; i++) arr_set(js, arr, (ant_offset_t)i, args[i]); } - jsval_t array_proto = get_ctor_proto(js, "Array", 5); - jsval_t instance_proto = js_instance_proto_from_new_target(js, array_proto); + ant_value_t array_proto = get_ctor_proto(js, "Array", 5); + ant_value_t instance_proto = js_instance_proto_from_new_target(js, array_proto); if (is_object_type(instance_proto)) set_proto(js, arr, instance_proto); if (vtype(js->new_target) == T_FUNC || vtype(js->new_target) == T_CFUNC) { @@ -5089,27 +5089,27 @@ static jsval_t builtin_Array(ant_t *js, jsval_t *args, int nargs) { return arr; } -static jsval_t builtin_Error(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Error(ant_t *js, ant_value_t *args, int nargs) { bool is_new = (vtype(js->new_target) != T_UNDEF); - jsval_t this_val = js->this_val; + ant_value_t this_val = js->this_val; - jsval_t target = is_new ? js->new_target : js->current_func; - jsval_t name = ANT_STRING("Error"); + ant_value_t target = is_new ? js->new_target : js->current_func; + ant_value_t name = ANT_STRING("Error"); if (vtype(target) == T_FUNC) { - jsoff_t off = lkp(js, js_func_obj(target), "name", 4); + ant_offset_t off = lkp(js, js_func_obj(target), "name", 4); if (off) name = resolveprop(js, mkval(T_PROP, off)); } if (!is_new) { this_val = js_mkobj(js); - jsoff_t proto_off = lkp_interned(js, js_func_obj(js->current_func), INTERN_PROTOTYPE, 9); + ant_offset_t proto_off = lkp_interned(js, js_func_obj(js->current_func), INTERN_PROTOTYPE, 9); if (proto_off) set_proto(js, this_val, resolveprop(js, mkval(T_PROP, proto_off))); else set_proto(js, this_val, get_ctor_proto(js, "Error", 5)); } if (nargs > 0) { - jsval_t msg = args[0]; + ant_value_t msg = args[0]; if (vtype(msg) != T_STR) { const char *str = js_str(js, msg); msg = js_mkstr(js, str, strlen(str)); @@ -5118,7 +5118,7 @@ static jsval_t builtin_Error(ant_t *js, jsval_t *args, int nargs) { } if (nargs > 1 && vtype(args[1]) == T_OBJ) { - jsoff_t cause_off = lkp(js, args[1], "cause", 5); + ant_offset_t cause_off = lkp(js, args[1], "cause", 5); if (cause_off) js_mkprop_fast(js, this_val, "cause", 5, resolveprop(js, mkval(T_PROP, cause_off))); } @@ -5128,26 +5128,26 @@ static jsval_t builtin_Error(ant_t *js, jsval_t *args, int nargs) { return this_val; } -static jsval_t builtin_Error_toString(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_val = js_getthis(js); +static ant_value_t builtin_Error_toString(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_val = js_getthis(js); - jsval_t name = js_get(js, this_val, "name"); + ant_value_t name = js_get(js, this_val, "name"); if (vtype(name) == T_UNDEF) name = js_mkstr(js, "Error", 5); else if (vtype(name) != T_STR) { const char *s = js_str(js, name); name = js_mkstr(js, s, strlen(s)); } - jsval_t msg = js_get(js, this_val, "message"); + ant_value_t msg = js_get(js, this_val, "message"); if (vtype(msg) == T_UNDEF) msg = js_mkstr(js, "", 0); else if (vtype(msg) != T_STR) { const char *s = js_str(js, msg); msg = js_mkstr(js, s, strlen(s)); } - jsoff_t name_len, msg_len; - jsoff_t name_off = vstr(js, name, &name_len); - jsoff_t msg_off = vstr(js, msg, &msg_len); + ant_offset_t name_len, msg_len; + ant_offset_t name_off = vstr(js, name, &name_len); + ant_offset_t msg_off = vstr(js, msg, &msg_len); const char *name_str = (const char *)&js->mem[name_off]; const char *msg_str = (const char *)&js->mem[msg_off]; @@ -5165,28 +5165,28 @@ static jsval_t builtin_Error_toString(ant_t *js, jsval_t *args, int nargs) { memcpy(buf + name_len + 2, msg_str, (size_t)msg_len); buf[total] = '\0'; - jsval_t result = js_mkstr(js, buf, total); + ant_value_t result = js_mkstr(js, buf, total); free(buf); return result; } -static jsval_t builtin_AggregateError(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_AggregateError(ant_t *js, ant_value_t *args, int nargs) { bool is_new = (vtype(js->new_target) != T_UNDEF); - jsval_t this_val = js->this_val; + ant_value_t this_val = js->this_val; if (!is_new) { this_val = js_mkobj(js); - jsoff_t proto_off = lkp_interned(js, js_func_obj(js->current_func), INTERN_PROTOTYPE, 9); + ant_offset_t proto_off = lkp_interned(js, js_func_obj(js->current_func), INTERN_PROTOTYPE, 9); if (proto_off) set_proto(js, this_val, resolveprop(js, mkval(T_PROP, proto_off))); else set_proto(js, this_val, get_ctor_proto(js, "AggregateError", 14)); } - jsval_t errors = nargs > 0 ? args[0] : mkarr(js); + ant_value_t errors = nargs > 0 ? args[0] : mkarr(js); if (vtype(errors) != T_ARR) errors = mkarr(js); js_mkprop_fast(js, this_val, "errors", 6, errors); if (nargs > 1 && vtype(args[1]) != T_UNDEF) { - jsval_t msg = args[1]; + ant_value_t msg = args[1]; if (vtype(msg) != T_STR) { const char *str = js_str(js, msg); msg = js_mkstr(js, str, strlen(str)); @@ -5195,7 +5195,7 @@ static jsval_t builtin_AggregateError(ant_t *js, jsval_t *args, int nargs) { } if (nargs > 2 && vtype(args[2]) == T_OBJ) { - jsoff_t cause_off = lkp(js, args[2], "cause", 5); + ant_offset_t cause_off = lkp(js, args[2], "cause", 5); if (cause_off) js_mkprop_fast(js, this_val, "cause", 5, resolveprop(js, mkval(T_PROP, cause_off))); } @@ -5205,68 +5205,68 @@ static jsval_t builtin_AggregateError(ant_t *js, jsval_t *args, int nargs) { return this_val; } -static jsval_t builtin_Math_abs(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_abs(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x)) return tov(JS_NAN); return tov(fabs(x)); } -static jsval_t builtin_Math_acos(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_acos(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x)) return tov(JS_NAN); return tov(acos(x)); } -static jsval_t builtin_Math_acosh(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_acosh(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x)) return tov(JS_NAN); return tov(acosh(x)); } -static jsval_t builtin_Math_asin(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_asin(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x)) return tov(JS_NAN); return tov(asin(x)); } -static jsval_t builtin_Math_asinh(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_asinh(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x)) return tov(JS_NAN); return tov(asinh(x)); } -static jsval_t builtin_Math_atan(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_atan(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x)) return tov(JS_NAN); return tov(atan(x)); } -static jsval_t builtin_Math_atanh(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_atanh(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x)) return tov(JS_NAN); return tov(atanh(x)); } -static jsval_t builtin_Math_atan2(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_atan2(ant_t *js, ant_value_t *args, int nargs) { double y = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); double x = (nargs < 2) ? JS_NAN : js_to_number(js, args[1]); if (isnan(y) || isnan(x)) return tov(JS_NAN); return tov(atan2(y, x)); } -static jsval_t builtin_Math_cbrt(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_cbrt(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x)) return tov(JS_NAN); return tov(cbrt(x)); } -static jsval_t builtin_Math_ceil(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_ceil(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x)) return tov(JS_NAN); return tov(ceil(x)); } -static jsval_t builtin_Math_clz32(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_clz32(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return tov(32); double x = js_to_number(js, args[0]); if (isnan(x) || isinf(x)) return tov(32); @@ -5277,43 +5277,43 @@ static jsval_t builtin_Math_clz32(ant_t *js, jsval_t *args, int nargs) { return tov((double) count); } -static jsval_t builtin_Math_cos(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_cos(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x)) return tov(JS_NAN); return tov(cos(x)); } -static jsval_t builtin_Math_cosh(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_cosh(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x)) return tov(JS_NAN); return tov(cosh(x)); } -static jsval_t builtin_Math_exp(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_exp(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x)) return tov(JS_NAN); return tov(exp(x)); } -static jsval_t builtin_Math_expm1(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_expm1(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x)) return tov(JS_NAN); return tov(expm1(x)); } -static jsval_t builtin_Math_floor(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_floor(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x)) return tov(JS_NAN); return tov(floor(x)); } -static jsval_t builtin_Math_fround(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_fround(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x)) return tov(JS_NAN); return tov((double)(float)x); } -static jsval_t builtin_Math_hypot(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_hypot(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return tov(0.0); double sum = 0.0; for (int i = 0; i < nargs; i++) { @@ -5335,38 +5335,38 @@ static int32_t toInt32(double d) { return (int32_t)mod_val; } -static jsval_t builtin_Math_imul(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_imul(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return tov(0); int32_t a = toInt32(js_to_number(js, args[0])); int32_t b = toInt32(js_to_number(js, args[1])); return tov((double)((int32_t)((uint32_t)a * (uint32_t)b))); } -static jsval_t builtin_Math_log(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_log(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x)) return tov(JS_NAN); return tov(log(x)); } -static jsval_t builtin_Math_log1p(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_log1p(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x)) return tov(JS_NAN); return tov(log1p(x)); } -static jsval_t builtin_Math_log10(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_log10(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x)) return tov(JS_NAN); return tov(log10(x)); } -static jsval_t builtin_Math_log2(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_log2(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x)) return tov(JS_NAN); return tov(log2(x)); } -static jsval_t builtin_Math_max(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_max(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return tov(JS_NEG_INF); double max_val = JS_NEG_INF; for (int i = 0; i < nargs; i++) { @@ -5377,7 +5377,7 @@ static jsval_t builtin_Math_max(ant_t *js, jsval_t *args, int nargs) { return tov(max_val); } -static jsval_t builtin_Math_min(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_min(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return tov(JS_INF); double min_val = JS_INF; for (int i = 0; i < nargs; i++) { @@ -5388,7 +5388,7 @@ static jsval_t builtin_Math_min(ant_t *js, jsval_t *args, int nargs) { return tov(min_val); } -static jsval_t builtin_Math_pow(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_pow(ant_t *js, ant_value_t *args, int nargs) { double base = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); double exp = (nargs < 2) ? JS_NAN : js_to_number(js, args[1]); if (isnan(base) || isnan(exp)) return tov(JS_NAN); @@ -5397,7 +5397,7 @@ static jsval_t builtin_Math_pow(ant_t *js, jsval_t *args, int nargs) { static bool random_seeded = false; -static jsval_t builtin_Math_random(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_random(ant_t *js, ant_value_t *args, int nargs) { if (!random_seeded) { srand((unsigned int) time(NULL)); random_seeded = true; @@ -5405,13 +5405,13 @@ static jsval_t builtin_Math_random(ant_t *js, jsval_t *args, int nargs) { return tov((double) rand() / ((double) RAND_MAX + 1.0)); } -static jsval_t builtin_Math_round(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_round(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x) || isinf(x)) return tov(x); return tov(floor(x + 0.5)); } -static jsval_t builtin_Math_sign(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_sign(ant_t *js, ant_value_t *args, int nargs) { double v = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(v)) return tov(JS_NAN); if (v > 0) return tov(1.0); @@ -5419,70 +5419,70 @@ static jsval_t builtin_Math_sign(ant_t *js, jsval_t *args, int nargs) { return tov(v); } -static jsval_t builtin_Math_sin(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_sin(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x)) return tov(JS_NAN); return tov(sin(x)); } -static jsval_t builtin_Math_sinh(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_sinh(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x)) return tov(JS_NAN); return tov(sinh(x)); } -static jsval_t builtin_Math_sqrt(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_sqrt(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x)) return tov(JS_NAN); return tov(sqrt(x)); } -static jsval_t builtin_Math_tan(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_tan(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x)) return tov(JS_NAN); return tov(tan(x)); } -static jsval_t builtin_Math_tanh(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_tanh(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x)) return tov(JS_NAN); return tov(tanh(x)); } -static jsval_t builtin_Math_trunc(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Math_trunc(ant_t *js, ant_value_t *args, int nargs) { double x = (nargs < 1) ? JS_NAN : js_to_number(js, args[0]); if (isnan(x)) return tov(JS_NAN); return tov(trunc(x)); } -typedef jsval_t (*dynamic_kv_mapper_fn)( +typedef ant_value_t (*dynamic_kv_mapper_fn)( ant_t *js, - jsval_t key, - jsval_t val + ant_value_t key, + ant_value_t val ); -static jsval_t iterate_dynamic_keys(ant_t *js, jsval_t obj, dynamic_accessors_t *acc, dynamic_kv_mapper_fn mapper) { - jsval_t keys_arr = acc->keys(js, obj); - jsval_t arr = mkarr(js); - jsoff_t len = get_array_length(js, keys_arr); +static ant_value_t iterate_dynamic_keys(ant_t *js, ant_value_t obj, dynamic_accessors_t *acc, dynamic_kv_mapper_fn mapper) { + ant_value_t keys_arr = acc->keys(js, obj); + ant_value_t arr = mkarr(js); + ant_offset_t len = get_array_length(js, keys_arr); - for (jsoff_t i = 0; i < len; i++) { - jsval_t key_val = arr_get(js, keys_arr, i); + for (ant_offset_t i = 0; i < len; i++) { + ant_value_t key_val = arr_get(js, keys_arr, i); if (vtype(key_val) != T_STR) continue; - jsoff_t klen; jsoff_t str_off = vstr(js, key_val, &klen); + ant_offset_t klen; ant_offset_t str_off = vstr(js, key_val, &klen); const char *key = (const char *)&js->mem[str_off]; - jsval_t val = acc->getter(js, obj, key, klen); + ant_value_t val = acc->getter(js, obj, key, klen); js_arr_push(js, arr, mapper ? mapper(js, key_val, val) : val); } return mkval(T_ARR, vdata(arr)); } -static jsval_t builtin_object_is(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_is(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_false; - jsval_t x = args[0]; - jsval_t y = args[1]; + ant_value_t x = args[0]; + ant_value_t y = args[1]; uint8_t tx = vtype(x); uint8_t ty = vtype(y); @@ -5513,20 +5513,20 @@ enum obj_enum_mode { OBJ_ENUM_ENTRIES }; -static jsval_t map_to_entry(ant_t *js, jsval_t key, jsval_t val) { - jsval_t pair = mkarr(js); +static ant_value_t map_to_entry(ant_t *js, ant_value_t key, ant_value_t val) { + ant_value_t pair = mkarr(js); arr_set(js, pair, 0, key); arr_set(js, pair, 1, val); return mkval(T_ARR, vdata(pair)); } -static jsval_t object_enum(ant_t *js, jsval_t obj, enum obj_enum_mode mode) { +static ant_value_t object_enum(ant_t *js, ant_value_t obj, enum obj_enum_mode mode) { bool is_arr = (vtype(obj) == T_ARR); if (vtype(obj) == T_FUNC) obj = js_func_obj(obj); - jsoff_t obj_off = (jsoff_t)vdata(obj); + ant_offset_t obj_off = (ant_offset_t)vdata(obj); dynamic_accessors_t *acc = NULL; - HASH_FIND(hh, accessor_registry, &obj_off, sizeof(jsoff_t), acc); + HASH_FIND(hh, accessor_registry, &obj_off, sizeof(ant_offset_t), acc); if (acc && acc->keys) { if (mode == OBJ_ENUM_KEYS && !acc->getter) return acc->keys(js, obj); if (acc->getter) { @@ -5535,18 +5535,18 @@ static jsval_t object_enum(ant_t *js, jsval_t obj, enum obj_enum_mode mode) { } } - jsval_t arr = mkarr(js); - jsoff_t idx = 0; + ant_value_t arr = mkarr(js); + ant_offset_t idx = 0; if (is_arr) { - jsoff_t doff = get_dense_buf_off(js, obj_off); + ant_offset_t doff = get_dense_buf_off(js, obj_off); if (doff) { - jsoff_t dense_len = dense_length(js, doff); - for (jsoff_t i = 0; i < dense_len; i++) { - jsval_t v = dense_get(js, doff, i); + ant_offset_t dense_len = dense_length(js, doff); + for (ant_offset_t i = 0; i < dense_len; i++) { + ant_value_t v = dense_get(js, doff, i); if (is_empty_slot(v)) continue; char idxstr[16]; size_t idxlen = uint_to_str(idxstr, sizeof(idxstr), (unsigned)i); - jsval_t key_val = js_mkstr(js, idxstr, idxlen); + ant_value_t key_val = js_mkstr(js, idxstr, idxlen); if (mode == OBJ_ENUM_KEYS) arr_set(js, arr, idx, key_val); else if (mode == OBJ_ENUM_VALUES) arr_set(js, arr, idx, v); else arr_set(js, arr, idx, map_to_entry(js, key_val, v)); @@ -5555,25 +5555,25 @@ static jsval_t object_enum(ant_t *js, jsval_t obj, enum obj_enum_mode mode) { } } - jsoff_t next = loadoff(js, obj_off) & ~(3U | FLAGMASK); + ant_offset_t next = loadoff(js, obj_off) & ~(3U | FLAGMASK); while (next < js->brk && next != 0) { - jsoff_t header = loadoff(js, next); + ant_offset_t header = loadoff(js, next); if (is_slot_prop(header)) { next = next_prop(header); continue; } if (is_sym_key_prop(js, next)) { next = next_prop(header); continue; } - jsoff_t koff = loadoff(js, next + (jsoff_t) sizeof(next)); - jsoff_t klen = offtolen(loadoff(js, koff)); + ant_offset_t koff = loadoff(js, next + (ant_offset_t) sizeof(next)); + ant_offset_t klen = offtolen(loadoff(js, koff)); const char *key = (char *) &js->mem[koff + sizeof(koff)]; - jsval_t val = loadval(js, next + (jsoff_t) (sizeof(next) + sizeof(koff))); + ant_value_t val = loadval(js, next + (ant_offset_t) (sizeof(next) + sizeof(koff))); next = next_prop(header); if (is_internal_prop(key, klen)) continue; if (is_arr && is_array_index(key, klen)) { - jsoff_t doff = get_dense_buf_off(js, obj_off); + ant_offset_t doff = get_dense_buf_off(js, obj_off); if (doff) { unsigned long pidx = 0; - for (jsoff_t ci = 0; ci < klen; ci++) pidx = pidx * 10 + (key[ci] - '0'); + for (ant_offset_t ci = 0; ci < klen; ci++) pidx = pidx * 10 + (key[ci] - '0'); if (pidx < dense_length(js, doff)) continue; } } @@ -5583,7 +5583,7 @@ static jsval_t object_enum(ant_t *js, jsval_t obj, enum obj_enum_mode mode) { if (desc) should_include = desc->enumerable; if (should_include) { - jsval_t key_val = js_mkstr(js, key, klen); + ant_value_t key_val = js_mkstr(js, key, klen); if (mode == OBJ_ENUM_KEYS) arr_set(js, arr, idx, key_val); else if (mode == OBJ_ENUM_VALUES) arr_set(js, arr, idx, val); else arr_set(js, arr, idx, map_to_entry(js, key_val, val)); @@ -5594,9 +5594,9 @@ static jsval_t object_enum(ant_t *js, jsval_t obj, enum obj_enum_mode mode) { return mkval(T_ARR, vdata(arr)); } -static jsval_t builtin_object_keys(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_keys(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return mkarr(js); - jsval_t obj = args[0]; + ant_value_t obj = args[0]; if (vtype(obj) != T_OBJ && vtype(obj) != T_ARR && vtype(obj) != T_FUNC) return mkarr(js); if (is_proxy(js, obj)) { @@ -5605,28 +5605,28 @@ static jsval_t builtin_object_keys(ant_t *js, jsval_t *args, int nargs) { if (data->revoked) return js_mkerr_typed(js, JS_ERR_TYPE, "Cannot perform 'ownKeys' on a proxy that has been revoked"); - jsoff_t trap_off = lkp(js, data->handler, "ownKeys", 7); + ant_offset_t trap_off = lkp(js, data->handler, "ownKeys", 7); if (!trap_off) return object_enum(js, data->target, OBJ_ENUM_KEYS); - jsval_t trap = resolveprop(js, mkval(T_PROP, trap_off)); + ant_value_t trap = resolveprop(js, mkval(T_PROP, trap_off)); uint8_t ft = vtype(trap); if (ft != T_FUNC && ft != T_CFUNC) return object_enum(js, data->target, OBJ_ENUM_KEYS); - jsval_t trap_args[1] = { data->target }; - jsval_t result = sv_vm_call(js->vm, js, trap, data->handler, trap_args, 1, NULL, false); + ant_value_t trap_args[1] = { data->target }; + ant_value_t result = sv_vm_call(js->vm, js, trap, data->handler, trap_args, 1, NULL, false); if (is_err(result)) return result; if (vtype(result) != T_ARR) return js_mkerr_typed(js, JS_ERR_TYPE, "ownKeys trap must return an array"); - jsoff_t len = get_array_length(js, result); - for (jsoff_t i = 0; i < len; i++) { - jsval_t ki = arr_get(js, result, i); + ant_offset_t len = get_array_length(js, result); + for (ant_offset_t i = 0; i < len; i++) { + ant_value_t ki = arr_get(js, result, i); if (vtype(ki) != T_STR && vtype(ki) != T_SYMBOL) return js_mkerr_typed(js, JS_ERR_TYPE, "ownKeys trap result must contain only strings or symbols"); - jsoff_t ki_len; jsoff_t ki_off = vstr(js, ki, &ki_len); - for (jsoff_t j = 0; j < i; j++) { - jsval_t kj = arr_get(js, result, j); - jsoff_t kj_len; jsoff_t kj_off = vstr(js, kj, &kj_len); + ant_offset_t ki_len; ant_offset_t ki_off = vstr(js, ki, &ki_len); + for (ant_offset_t j = 0; j < i; j++) { + ant_value_t kj = arr_get(js, result, j); + ant_offset_t kj_len; ant_offset_t kj_off = vstr(js, kj, &kj_len); if (ki_len == kj_len && memcmp(&js->mem[ki_off], &js->mem[kj_off], ki_len) == 0) return js_mkerr_typed(js, JS_ERR_TYPE, "ownKeys trap result must not contain duplicate entries"); } @@ -5637,11 +5637,11 @@ static jsval_t builtin_object_keys(ant_t *js, jsval_t *args, int nargs) { return object_enum(js, obj, OBJ_ENUM_KEYS); } -static jsval_t for_in_keys_add(ant_t *js, jsval_t out, jsval_t seen, jsval_t key) { +static ant_value_t for_in_keys_add(ant_t *js, ant_value_t out, ant_value_t seen, ant_value_t key) { if (vtype(key) != T_STR) return js_mkundef(); - jsoff_t key_len = 0; - jsoff_t key_off = vstr(js, key, &key_len); + ant_offset_t key_len = 0; + ant_offset_t key_off = vstr(js, key, &key_len); const char *key_ptr = (const char *)&js->mem[key_off]; if (is_internal_prop(key_ptr, key_len)) @@ -5649,34 +5649,34 @@ static jsval_t for_in_keys_add(ant_t *js, jsval_t out, jsval_t seen, jsval_t key if (lkp(js, seen, key_ptr, key_len) != 0) return js_mkundef(); - jsval_t mark = setprop_cstr(js, seen, key_ptr, key_len, js_true); + ant_value_t mark = setprop_cstr(js, seen, key_ptr, key_len, js_true); if (is_err(mark)) return mark; js_arr_push(js, out, key); return js_mkundef(); } -static jsval_t for_in_keys_add_string_indices(ant_t *js, jsval_t out, jsval_t seen, jsval_t str) { - jsoff_t slen = vstrlen(js, str); - for (jsoff_t i = 0; i < slen; i++) { +static ant_value_t for_in_keys_add_string_indices(ant_t *js, ant_value_t out, ant_value_t seen, ant_value_t str) { + ant_offset_t slen = vstrlen(js, str); + for (ant_offset_t i = 0; i < slen; i++) { char idx[16]; size_t idx_len = uint_to_str(idx, sizeof(idx), (uint64_t)i); - jsval_t key = js_mkstr(js, idx, idx_len); - jsval_t r = for_in_keys_add(js, out, seen, key); + ant_value_t key = js_mkstr(js, idx, idx_len); + ant_value_t r = for_in_keys_add(js, out, seen, key); if (is_err(r)) return r; } return js_mkundef(); } -jsval_t js_for_in_keys(ant_t *js, jsval_t obj) { +ant_value_t js_for_in_keys(ant_t *js, ant_value_t obj) { uint8_t t = vtype(obj); - jsval_t out = mkarr(js); + ant_value_t out = mkarr(js); if (t == T_NULL || t == T_UNDEF) return out; - jsval_t seen = mkobj(js, 0); - jshdl_t h_out = js_root(js, out); - jshdl_t h_seen = js_root(js, seen); - jsval_t result = js_mkundef(); + ant_value_t seen = mkobj(js, 0); + ant_handle_t h_out = js_root(js, out); + ant_handle_t h_seen = js_root(js, seen); + ant_value_t result = js_mkundef(); if (t == T_STR) { result = for_in_keys_add_string_indices(js, js_deref(js, h_out), js_deref(js, h_seen), obj); @@ -5684,7 +5684,7 @@ jsval_t js_for_in_keys(ant_t *js, jsval_t obj) { } if (t == T_OBJ) { - jsval_t prim = get_slot(js, obj, SLOT_PRIMITIVE); + ant_value_t prim = get_slot(js, obj, SLOT_PRIMITIVE); if (vtype(prim) == T_STR) { result = for_in_keys_add_string_indices(js, js_deref(js, h_out), js_deref(js, h_seen), prim); if (is_err(result)) goto done; @@ -5692,16 +5692,16 @@ jsval_t js_for_in_keys(ant_t *js, jsval_t obj) { } if (t == T_OBJ || t == T_ARR || t == T_FUNC) { - jsval_t own_keys = object_enum(js, obj, OBJ_ENUM_KEYS); + ant_value_t own_keys = object_enum(js, obj, OBJ_ENUM_KEYS); if (is_err(own_keys)) { result = own_keys; goto done; } if (vtype(own_keys) == T_ARR) { - jshdl_t h_own = js_root(js, own_keys); - jsoff_t own_len = js_arr_len(js, js_deref(js, h_own)); - for (jsoff_t i = 0; i < own_len; i++) { - jsval_t key = js_arr_get(js, js_deref(js, h_own), i); + ant_handle_t h_own = js_root(js, own_keys); + ant_offset_t own_len = js_arr_len(js, js_deref(js, h_own)); + for (ant_offset_t i = 0; i < own_len; i++) { + ant_value_t key = js_arr_get(js, js_deref(js, h_own), i); result = for_in_keys_add(js, js_deref(js, h_out), js_deref(js, h_seen), key); if (is_err(result)) { js_unroot(js, h_own); @@ -5718,29 +5718,29 @@ done: js_unroot(js, h_out); return result; } - jsval_t ret = js_deref(js, h_out); + ant_value_t ret = js_deref(js, h_out); js_unroot(js, h_seen); js_unroot(js, h_out); return ret; } -static jsval_t builtin_object_values(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_values(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return mkarr(js); - jsval_t obj = args[0]; + ant_value_t obj = args[0]; if (vtype(obj) != T_OBJ && vtype(obj) != T_ARR && vtype(obj) != T_FUNC) return mkarr(js); return object_enum(js, obj, OBJ_ENUM_VALUES); } -static jsval_t builtin_object_entries(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_entries(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return mkarr(js); - jsval_t obj = args[0]; + ant_value_t obj = args[0]; if (vtype(obj) != T_OBJ && vtype(obj) != T_ARR && vtype(obj) != T_FUNC) return mkarr(js); return object_enum(js, obj, OBJ_ENUM_ENTRIES); } -static jsval_t builtin_object_getPrototypeOf(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_getPrototypeOf(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return js_mkerr(js, "Object.getPrototypeOf requires an argument"); - jsval_t obj = args[0]; + ant_value_t obj = args[0]; uint8_t t = vtype(obj); if (t == T_STR || t == T_NUM || t == T_BOOL || t == T_BIGINT) return get_prototype_for_type(js, t); @@ -5749,11 +5749,11 @@ static jsval_t builtin_object_getPrototypeOf(ant_t *js, jsval_t *args, int nargs return js_mknull(); } -static jsval_t builtin_object_setPrototypeOf(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_setPrototypeOf(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "Object.setPrototypeOf requires 2 arguments"); - jsval_t obj = args[0]; - jsval_t proto = args[1]; + ant_value_t obj = args[0]; + ant_value_t proto = args[1]; uint8_t t = vtype(obj); if (t != T_OBJ && t != T_ARR && t != T_FUNC) { @@ -5765,7 +5765,7 @@ static jsval_t builtin_object_setPrototypeOf(ant_t *js, jsval_t *args, int nargs return js_mkerr(js, "Object.setPrototypeOf: prototype must be an object or null"); } - for (jsval_t cur = proto; pt != T_NULL && vtype(cur) != T_NULL; cur = get_proto(js, cur)) { + for (ant_value_t cur = proto; pt != T_NULL && vtype(cur) != T_NULL; cur = get_proto(js, cur)) { if (vdata(js_as_obj(cur)) == vdata(js_as_obj(obj))) return js_mkerr(js, "Cyclic __proto__ value"); } @@ -5773,8 +5773,8 @@ static jsval_t builtin_object_setPrototypeOf(ant_t *js, jsval_t *args, int nargs return obj; } -static jsval_t builtin_proto_getter(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_val = js->this_val; +static ant_value_t builtin_proto_getter(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_val = js->this_val; uint8_t t = vtype(this_val); if (t == T_UNDEF || t == T_NULL) { @@ -5788,8 +5788,8 @@ static jsval_t builtin_proto_getter(ant_t *js, jsval_t *args, int nargs) { return get_prototype_for_type(js, t); } -static jsval_t builtin_proto_setter(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_val = js->this_val; +static ant_value_t builtin_proto_setter(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_val = js->this_val; uint8_t t = vtype(this_val); if (t == T_UNDEF || t == T_NULL) { @@ -5802,14 +5802,14 @@ static jsval_t builtin_proto_setter(ant_t *js, jsval_t *args, int nargs) { if (nargs == 0) return js_mkundef(); - jsval_t proto = args[0]; + ant_value_t proto = args[0]; uint8_t pt = vtype(proto); if (pt != T_OBJ && pt != T_ARR && pt != T_FUNC && pt != T_NULL) { return js_mkundef(); } - for (jsval_t cur = proto; pt != T_NULL && vtype(cur) == T_OBJ; cur = get_proto(js, cur)) { + for (ant_value_t cur = proto; pt != T_NULL && vtype(cur) == T_OBJ; cur = get_proto(js, cur)) { if (vdata(cur) == vdata(this_val)) return js_mkundef(); } @@ -5817,39 +5817,39 @@ static jsval_t builtin_proto_setter(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t builtin_object_create(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_create(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return js_mkerr(js, "Object.create requires a prototype argument"); - jsval_t proto = args[0]; + ant_value_t proto = args[0]; uint8_t pt = vtype(proto); if (pt != T_OBJ && pt != T_ARR && pt != T_FUNC && pt != T_NULL) { return js_mkerr(js, "Object.create: prototype must be an object or null"); } - jsval_t obj = js_mkobj(js); + ant_value_t obj = js_mkobj(js); if (pt == T_NULL) { set_proto(js, obj, js_mknull()); } else set_proto(js, obj, proto); if (nargs >= 2 && vtype(args[1]) == T_OBJ) { - jsval_t props = args[1]; - jsoff_t next = loadoff(js, (jsoff_t) vdata(props)) & ~(3U | FLAGMASK); + ant_value_t props = args[1]; + ant_offset_t next = loadoff(js, (ant_offset_t) vdata(props)) & ~(3U | FLAGMASK); while (next < js->brk && next != 0) { - jsoff_t header = loadoff(js, next); + ant_offset_t header = loadoff(js, next); if (is_slot_prop(header)) { next = next_prop(header); continue; } - jsoff_t koff = loadoff(js, next + (jsoff_t) sizeof(next)); - jsoff_t klen = offtolen(loadoff(js, koff)); + ant_offset_t koff = loadoff(js, next + (ant_offset_t) sizeof(next)); + ant_offset_t klen = offtolen(loadoff(js, koff)); const char *key = (char *) &js->mem[koff + sizeof(koff)]; - jsval_t descriptor = resolveprop(js, mkval(T_PROP, next)); + ant_value_t descriptor = resolveprop(js, mkval(T_PROP, next)); if (vtype(descriptor) == T_OBJ) { - jsoff_t val_off = lkp(js, descriptor, "value", 5); + ant_offset_t val_off = lkp(js, descriptor, "value", 5); if (val_off != 0) { - jsval_t val = resolveprop(js, mkval(T_PROP, val_off)); - jsval_t key_str = js_mkstr(js, key, klen); + ant_value_t val = resolveprop(js, mkval(T_PROP, val_off)); + ant_value_t key_str = js_mkstr(js, key, klen); js_setprop(js, obj, key_str, val); } } @@ -5861,17 +5861,17 @@ static jsval_t builtin_object_create(ant_t *js, jsval_t *args, int nargs) { return obj; } -static jsval_t builtin_object_hasOwn(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_hasOwn(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return mkval(T_BOOL, 0); - jsval_t obj = args[0]; + ant_value_t obj = args[0]; uint8_t t = vtype(obj); if (t == T_NULL || t == T_UNDEF) { return js_mkerr_typed(js, JS_ERR_TYPE, "Cannot convert undefined or null to object"); } - jsval_t key = args[1]; + ant_value_t key = args[1]; if (vtype(key) != T_STR) { key = js_tostring_val(js, key); if (is_err(key)) return key; @@ -5879,42 +5879,42 @@ static jsval_t builtin_object_hasOwn(ant_t *js, jsval_t *args, int nargs) { if (t != T_OBJ && t != T_ARR && t != T_FUNC) return mkval(T_BOOL, 0); - jsval_t as_obj = js_as_obj(obj); - jsoff_t key_len, key_off = vstr(js, key, &key_len); + ant_value_t as_obj = js_as_obj(obj); + ant_offset_t key_len, key_off = vstr(js, key, &key_len); const char *key_str = (char *) &js->mem[key_off]; - jsoff_t off = lkp(js, as_obj, key_str, key_len); + ant_offset_t off = lkp(js, as_obj, key_str, key_len); return mkval(T_BOOL, off != 0 ? 1 : 0); } -static jsval_t builtin_object_groupBy(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_groupBy(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr_typed(js, JS_ERR_TYPE, "Object.groupBy requires 2 arguments"); - jsval_t items = args[0]; - jsval_t callback = args[1]; + ant_value_t items = args[0]; + ant_value_t callback = args[1]; if (vtype(callback) != T_FUNC && vtype(callback) != T_CFUNC) return js_mkerr_typed(js, JS_ERR_TYPE, "callback is not a function"); - jsval_t result = js_mkobj(js); + ant_value_t result = js_mkobj(js); set_proto(js, result, js_mknull()); - jsoff_t len = get_array_length(js, items); - for (jsoff_t i = 0; i < len; i++) { - jsval_t val = arr_get(js, items, i); - jsval_t cb_args[2] = { val, tov((double)i) }; - jsval_t key = sv_vm_call(js->vm, js, callback, js_mkundef(), cb_args, 2, NULL, false); + ant_offset_t len = get_array_length(js, items); + for (ant_offset_t i = 0; i < len; i++) { + ant_value_t val = arr_get(js, items, i); + ant_value_t cb_args[2] = { val, tov((double)i) }; + ant_value_t key = sv_vm_call(js->vm, js, callback, js_mkundef(), cb_args, 2, NULL, false); if (is_err(key)) return key; - jsval_t key_str = js_tostring_val(js, key); + ant_value_t key_str = js_tostring_val(js, key); if (is_err(key_str)) return key_str; - jsoff_t klen; - jsoff_t koff = vstr(js, key_str, &klen); + ant_offset_t klen; + ant_offset_t koff = vstr(js, key_str, &klen); const char *kptr = (char *)&js->mem[koff]; - jsoff_t grp_off = lkp(js, result, kptr, klen); - jsval_t group; + ant_offset_t grp_off = lkp(js, result, kptr, klen); + ant_value_t group; if (grp_off) { group = resolveprop(js, mkval(T_PROP, grp_off)); } else { @@ -5927,12 +5927,12 @@ static jsval_t builtin_object_groupBy(ant_t *js, jsval_t *args, int nargs) { return result; } -static jsval_t builtin_object_defineProperty(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_defineProperty(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 3) return js_mkerr(js, "Object.defineProperty requires 3 arguments"); - jsval_t obj = args[0]; - jsval_t prop = args[1]; - jsval_t descriptor = args[2]; + ant_value_t obj = args[0]; + ant_value_t prop = args[1]; + ant_value_t descriptor = args[2]; uint8_t t = vtype(obj); if (t != T_OBJ && t != T_ARR && t != T_FUNC) { @@ -5950,19 +5950,19 @@ static jsval_t builtin_object_defineProperty(ant_t *js, jsval_t *args, int nargs return js_mkerr(js, "Property descriptor must be an object"); } - jsval_t as_obj = js_as_obj(obj); + ant_value_t as_obj = js_as_obj(obj); - jsoff_t prop_len = 0; + ant_offset_t prop_len = 0; const char *prop_str = NULL; - jsoff_t sym_off = 0; + ant_offset_t sym_off = 0; if (sym_key) { - sym_off = (jsoff_t)vdata(prop); + sym_off = (ant_offset_t)vdata(prop); const char *desc = js_sym_desc(js, prop); prop_str = desc ? desc : "symbol"; - prop_len = (jsoff_t)strlen(prop_str); + prop_len = (ant_offset_t)strlen(prop_str); } else { - jsoff_t prop_off = vstr(js, prop, &prop_len); + ant_offset_t prop_off = vstr(js, prop, &prop_len); prop_str = (char *) &js->mem[prop_off]; if (streq(prop_str, prop_len, STR_PROTO, STR_PROTO_LEN)) { return js_mkerr(js, "Cannot define " STR_PROTO " property"); @@ -5970,28 +5970,28 @@ static jsval_t builtin_object_defineProperty(ant_t *js, jsval_t *args, int nargs } bool has_value = false, has_get = false, has_set = false, has_writable = false; - jsval_t value = js_mkundef(); + ant_value_t value = js_mkundef(); bool writable = false, enumerable = false, configurable = false; - jsoff_t value_off = lkp(js, descriptor, "value", 5); + ant_offset_t value_off = lkp(js, descriptor, "value", 5); if (value_off != 0) { has_value = true; value = resolveprop(js, mkval(T_PROP, value_off)); } - jsoff_t get_off = lkp_interned(js, descriptor, INTERN_GET, 3); + ant_offset_t get_off = lkp_interned(js, descriptor, INTERN_GET, 3); if (get_off != 0) { has_get = true; - jsval_t getter = resolveprop(js, mkval(T_PROP, get_off)); + ant_value_t getter = resolveprop(js, mkval(T_PROP, get_off)); if (vtype(getter) != T_FUNC && vtype(getter) != T_UNDEF) { return js_mkerr(js, "Getter must be a function"); } } - jsoff_t set_off = lkp_interned(js, descriptor, INTERN_SET, 3); + ant_offset_t set_off = lkp_interned(js, descriptor, INTERN_SET, 3); if (set_off != 0) { has_set = true; - jsval_t setter = resolveprop(js, mkval(T_PROP, set_off)); + ant_value_t setter = resolveprop(js, mkval(T_PROP, set_off)); if (vtype(setter) != T_FUNC && vtype(setter) != T_UNDEF) { return js_mkerr(js, "Setter must be a function"); } @@ -6001,26 +6001,26 @@ static jsval_t builtin_object_defineProperty(ant_t *js, jsval_t *args, int nargs return js_mkerr(js, "Invalid property descriptor. Cannot both specify accessors and a value or writable attribute"); } - jsoff_t writable_off = lkp(js, descriptor, "writable", 8); + ant_offset_t writable_off = lkp(js, descriptor, "writable", 8); if (writable_off != 0) { has_writable = true; - jsval_t w_val = resolveprop(js, mkval(T_PROP, writable_off)); + ant_value_t w_val = resolveprop(js, mkval(T_PROP, writable_off)); writable = js_truthy(js, w_val); } - jsoff_t enumerable_off = lkp(js, descriptor, "enumerable", 10); + ant_offset_t enumerable_off = lkp(js, descriptor, "enumerable", 10); if (enumerable_off != 0) { - jsval_t e_val = resolveprop(js, mkval(T_PROP, enumerable_off)); + ant_value_t e_val = resolveprop(js, mkval(T_PROP, enumerable_off)); enumerable = js_truthy(js, e_val); } - jsoff_t configurable_off = lkp(js, descriptor, "configurable", 12); + ant_offset_t configurable_off = lkp(js, descriptor, "configurable", 12); if (configurable_off != 0) { - jsval_t c_val = resolveprop(js, mkval(T_PROP, configurable_off)); + ant_value_t c_val = resolveprop(js, mkval(T_PROP, configurable_off)); configurable = js_truthy(js, c_val); } - jsoff_t existing_off = sym_key ? lkp_sym(js, as_obj, sym_off) : lkp(js, as_obj, prop_str, prop_len); + ant_offset_t existing_off = sym_key ? lkp_sym(js, as_obj, sym_off) : lkp(js, as_obj, prop_str, prop_len); if (existing_off == 0) { if (js_truthy(js, get_slot(js, as_obj, SLOT_FROZEN))) @@ -6038,14 +6038,14 @@ static jsval_t builtin_object_defineProperty(ant_t *js, jsval_t *args, int nargs if (!sym_key) { if (has_get && has_set) { - jsval_t getter = resolveprop(js, mkval(T_PROP, get_off)); - jsval_t setter = resolveprop(js, mkval(T_PROP, set_off)); + ant_value_t getter = resolveprop(js, mkval(T_PROP, get_off)); + ant_value_t setter = resolveprop(js, mkval(T_PROP, set_off)); js_set_accessor_desc(js, as_obj, prop_str, prop_len, getter, setter, desc_flags); } else if (has_get) { - jsval_t getter = resolveprop(js, mkval(T_PROP, get_off)); + ant_value_t getter = resolveprop(js, mkval(T_PROP, get_off)); js_set_getter_desc(js, as_obj, prop_str, prop_len, getter, desc_flags); } else { - jsval_t setter = resolveprop(js, mkval(T_PROP, set_off)); + ant_value_t setter = resolveprop(js, mkval(T_PROP, set_off)); js_set_setter_desc(js, as_obj, prop_str, prop_len, setter, desc_flags); } } @@ -6075,19 +6075,19 @@ static jsval_t builtin_object_defineProperty(ant_t *js, jsval_t *args, int nargs } if (is_readonly && has_value) return js_mkerr(js, "Cannot assign to read-only property '%.*s'", (int)prop_len, prop_str); - if (has_value) saveval(js, existing_off + sizeof(jsoff_t) * 2, value); + if (has_value) saveval(js, existing_off + sizeof(ant_offset_t) * 2, value); if (!writable || !configurable) { - jsoff_t head = (jsoff_t) vdata(as_obj); - jsoff_t firstprop = loadoff(js, head); + ant_offset_t head = (ant_offset_t) vdata(as_obj); + ant_offset_t firstprop = loadoff(js, head); if ((firstprop & ~(3U | FLAGMASK)) == existing_off) { - jsoff_t flags = 0; + ant_offset_t flags = 0; if (!writable) flags |= CONSTMASK; if (!configurable) flags |= NONCONFIGMASK; saveoff(js, head, firstprop | flags); } else { - jsoff_t prop_header = loadoff(js, existing_off); - jsoff_t flags = 0; + ant_offset_t prop_header = loadoff(js, existing_off); + ant_offset_t flags = 0; if (!writable) flags |= CONSTMASK; if (!configurable) flags |= NONCONFIGMASK; saveoff(js, existing_off, prop_header | flags); @@ -6095,8 +6095,8 @@ static jsval_t builtin_object_defineProperty(ant_t *js, jsval_t *args, int nargs } } else { if (!has_value) value = js_mkundef(); - jsval_t prop_key = sym_key ? prop : js_mkstr(js, prop_str, prop_len); - jsoff_t flags = (writable ? 0 : CONSTMASK) | (configurable ? 0 : NONCONFIGMASK); + ant_value_t prop_key = sym_key ? prop : js_mkstr(js, prop_str, prop_len); + ant_offset_t flags = (writable ? 0 : CONSTMASK) | (configurable ? 0 : NONCONFIGMASK); mkprop(js, as_obj, prop_key, value, flags); } } @@ -6104,11 +6104,11 @@ static jsval_t builtin_object_defineProperty(ant_t *js, jsval_t *args, int nargs return obj; } -static jsval_t builtin_object_defineProperties(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_defineProperties(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "Object.defineProperties requires 2 arguments"); - jsval_t obj = args[0]; - jsval_t props = args[1]; + ant_value_t obj = args[0]; + ant_value_t props = args[1]; uint8_t t = vtype(obj); if (t != T_OBJ && t != T_ARR && t != T_FUNC) { @@ -6119,34 +6119,34 @@ static jsval_t builtin_object_defineProperties(ant_t *js, jsval_t *args, int nar return js_mkerr(js, "Property descriptors must be an object"); } - jsval_t props_obj = props; - jsoff_t next = loadoff(js, (jsoff_t) vdata(props_obj)) & ~(3U | FLAGMASK); + ant_value_t props_obj = props; + ant_offset_t next = loadoff(js, (ant_offset_t) vdata(props_obj)) & ~(3U | FLAGMASK); while (next < js->brk && next != 0) { - jsoff_t header = loadoff(js, next); + ant_offset_t header = loadoff(js, next); if (is_slot_prop(header)) { next = next_prop(header); continue; } - jsoff_t koff = loadoff(js, next + (jsoff_t) sizeof(next)); - jsoff_t klen = offtolen(loadoff(js, koff)); + ant_offset_t koff = loadoff(js, next + (ant_offset_t) sizeof(next)); + ant_offset_t klen = offtolen(loadoff(js, koff)); const char *key = (char *) &js->mem[koff + sizeof(koff)]; - jsval_t descriptor = loadval(js, next + (jsoff_t) (sizeof(next) + sizeof(koff))); + ant_value_t descriptor = loadval(js, next + (ant_offset_t) (sizeof(next) + sizeof(koff))); next = next_prop(header); if (is_internal_prop(key, klen)) continue; - jsval_t prop_key = js_mkstr(js, key, klen); - jsval_t define_args[3] = { obj, prop_key, descriptor }; - jsval_t result = builtin_object_defineProperty(js, define_args, 3); + ant_value_t prop_key = js_mkstr(js, key, klen); + ant_value_t define_args[3] = { obj, prop_key, descriptor }; + ant_value_t result = builtin_object_defineProperty(js, define_args, 3); if (is_err(result)) return result; } return obj; } -static jsval_t builtin_object_assign(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_assign(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return js_mkerr(js, "Object.assign requires at least 1 argument"); - jsval_t target = args[0]; + ant_value_t target = args[0]; uint8_t t = vtype(target); if (t == T_NULL || t == T_UNDEF) { @@ -6157,38 +6157,38 @@ static jsval_t builtin_object_assign(ant_t *js, jsval_t *args, int nargs) { target = js_mkobj(js); } - jsval_t as_obj = js_as_obj(target); + ant_value_t as_obj = js_as_obj(target); for (int i = 1; i < nargs; i++) { - jsval_t source = args[i]; + ant_value_t source = args[i]; uint8_t st = vtype(source); if (st == T_NULL || st == T_UNDEF) continue; if (st != T_OBJ && st != T_ARR && st != T_FUNC) continue; - jsval_t src_obj = js_as_obj(source); - jsoff_t next = loadoff(js, (jsoff_t) vdata(src_obj)) & ~(3U | FLAGMASK); + ant_value_t src_obj = js_as_obj(source); + ant_offset_t next = loadoff(js, (ant_offset_t) vdata(src_obj)) & ~(3U | FLAGMASK); while (next < js->brk && next != 0) { - jsoff_t header = loadoff(js, next); + ant_offset_t header = loadoff(js, next); if (is_slot_prop(header)) { next = next_prop(header); continue; } - jsoff_t koff = loadoff(js, next + (jsoff_t) sizeof(next)); - jsoff_t klen = offtolen(loadoff(js, koff)); + ant_offset_t koff = loadoff(js, next + (ant_offset_t) sizeof(next)); + ant_offset_t klen = offtolen(loadoff(js, koff)); const char *key = (char *) &js->mem[koff + sizeof(koff)]; - jsval_t val = loadval(js, next + (jsoff_t) (sizeof(next) + sizeof(koff))); + ant_value_t val = loadval(js, next + (ant_offset_t) (sizeof(next) + sizeof(koff))); next = next_prop(header); if (is_internal_prop(key, klen)) continue; bool should_copy = true; - jsoff_t src_obj_off = (jsoff_t)vdata(src_obj); + ant_offset_t src_obj_off = (ant_offset_t)vdata(src_obj); descriptor_entry_t *desc = lookup_descriptor(js, src_obj_off, key, klen); if (desc) should_copy = desc->enumerable; if (should_copy) { - jsval_t key_str = js_mkstr(js, key, klen); + ant_value_t key_str = js_mkstr(js, key, klen); js_setprop(js, as_obj, key_str, val); } } @@ -6197,36 +6197,36 @@ static jsval_t builtin_object_assign(ant_t *js, jsval_t *args, int nargs) { return target; } -static jsval_t builtin_object_freeze(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_freeze(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return js_mkundef(); - jsval_t obj = args[0]; + ant_value_t obj = args[0]; uint8_t t = vtype(obj); if (t != T_OBJ && t != T_ARR && t != T_FUNC) return obj; - jsval_t as_obj = js_as_obj(obj); + ant_value_t as_obj = js_as_obj(obj); - jsoff_t next = loadoff(js, (jsoff_t) vdata(as_obj)) & ~(3U | FLAGMASK); + ant_offset_t next = loadoff(js, (ant_offset_t) vdata(as_obj)) & ~(3U | FLAGMASK); while (next < js->brk && next != 0) { - jsoff_t header = loadoff(js, next); + ant_offset_t header = loadoff(js, next); if (is_slot_prop(header)) { next = next_prop(header); continue; } - jsoff_t koff = loadoff(js, next + (jsoff_t) sizeof(next)); - jsoff_t klen = offtolen(loadoff(js, koff)); + ant_offset_t koff = loadoff(js, next + (ant_offset_t) sizeof(next)); + ant_offset_t klen = offtolen(loadoff(js, koff)); const char *key = (char *) &js->mem[koff + sizeof(koff)]; - jsoff_t cur_prop = next; + ant_offset_t cur_prop = next; next = next_prop(header); if (is_internal_prop(key, klen)) continue; - jsoff_t freeze_flags = CONSTMASK | NONCONFIGMASK; - jsoff_t head = (jsoff_t) vdata(as_obj); - jsoff_t firstprop = loadoff(js, head); + ant_offset_t freeze_flags = CONSTMASK | NONCONFIGMASK; + ant_offset_t head = (ant_offset_t) vdata(as_obj); + ant_offset_t firstprop = loadoff(js, head); if ((firstprop & ~(3U | FLAGMASK)) == cur_prop) { saveoff(js, head, firstprop | freeze_flags); } else { - jsoff_t prop_header = loadoff(js, cur_prop); + ant_offset_t prop_header = loadoff(js, cur_prop); saveoff(js, cur_prop, prop_header | freeze_flags); } @@ -6237,49 +6237,49 @@ static jsval_t builtin_object_freeze(ant_t *js, jsval_t *args, int nargs) { return obj; } -static jsval_t builtin_object_isFrozen(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_isFrozen(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return js_true; - jsval_t obj = args[0]; + ant_value_t obj = args[0]; uint8_t t = vtype(obj); if (t != T_OBJ && t != T_ARR && t != T_FUNC) return js_true; - jsval_t as_obj = js_as_obj(obj); + ant_value_t as_obj = js_as_obj(obj); return js_bool(js_truthy(js, get_slot(js, as_obj, SLOT_FROZEN))); } -static jsval_t builtin_object_seal(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_seal(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return js_mkundef(); - jsval_t obj = args[0]; + ant_value_t obj = args[0]; uint8_t t = vtype(obj); if (t != T_OBJ && t != T_ARR && t != T_FUNC) return obj; - jsval_t as_obj = js_as_obj(obj); + ant_value_t as_obj = js_as_obj(obj); set_slot(js, as_obj, SLOT_SEALED, js_true); - jsoff_t next = loadoff(js, (jsoff_t) vdata(as_obj)) & ~(3U | FLAGMASK); + ant_offset_t next = loadoff(js, (ant_offset_t) vdata(as_obj)) & ~(3U | FLAGMASK); while (next < js->brk && next != 0) { - jsoff_t header = loadoff(js, next); + ant_offset_t header = loadoff(js, next); if (is_slot_prop(header)) { next = next_prop(header); continue; } - jsoff_t koff = loadoff(js, next + (jsoff_t) sizeof(next)); - jsoff_t klen = offtolen(loadoff(js, koff)); + ant_offset_t koff = loadoff(js, next + (ant_offset_t) sizeof(next)); + ant_offset_t klen = offtolen(loadoff(js, koff)); const char *key = (char *) &js->mem[koff + sizeof(koff)]; - jsoff_t cur_prop = next; + ant_offset_t cur_prop = next; next = next_prop(header); if (is_internal_prop(key, klen)) continue; - jsoff_t head = (jsoff_t) vdata(as_obj); - jsoff_t firstprop = loadoff(js, head); + ant_offset_t head = (ant_offset_t) vdata(as_obj); + ant_offset_t firstprop = loadoff(js, head); if ((firstprop & ~(3U | FLAGMASK)) == cur_prop) { saveoff(js, head, firstprop | NONCONFIGMASK); } else { - jsoff_t prop_header = loadoff(js, cur_prop); + ant_offset_t prop_header = loadoff(js, cur_prop); saveoff(js, cur_prop, prop_header | NONCONFIGMASK); } @@ -6289,14 +6289,14 @@ static jsval_t builtin_object_seal(ant_t *js, jsval_t *args, int nargs) { return obj; } -static jsval_t builtin_object_isSealed(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_isSealed(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return js_true; - jsval_t obj = args[0]; + ant_value_t obj = args[0]; uint8_t t = vtype(obj); if (t != T_OBJ && t != T_ARR && t != T_FUNC) return js_true; - jsval_t as_obj = js_as_obj(obj); + ant_value_t as_obj = js_as_obj(obj); if (js_truthy(js, get_slot(js, as_obj, SLOT_SEALED))) return js_true; if (js_truthy(js, get_slot(js, as_obj, SLOT_FROZEN))) return js_true; @@ -6304,27 +6304,27 @@ static jsval_t builtin_object_isSealed(ant_t *js, jsval_t *args, int nargs) { return js_false; } -static jsval_t builtin_object_fromEntries(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_fromEntries(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return js_mkerr(js, "Object.fromEntries requires an iterable argument"); - jsval_t iterable = args[0]; + ant_value_t iterable = args[0]; uint8_t t = vtype(iterable); if (t != T_ARR && t != T_OBJ) { return js_mkerr(js, "Object.fromEntries requires an iterable"); } - jsval_t result = js_mkobj(js); - jsoff_t len = get_array_length(js, iterable); + ant_value_t result = js_mkobj(js); + ant_offset_t len = get_array_length(js, iterable); if (len == 0) return result; - for (jsoff_t i = 0; i < len; i++) { - jsval_t entry = arr_get(js, iterable, i); + for (ant_offset_t i = 0; i < len; i++) { + ant_value_t entry = arr_get(js, iterable, i); if (vtype(entry) != T_ARR && vtype(entry) != T_OBJ) continue; - jsval_t key = arr_get(js, entry, 0); + ant_value_t key = arr_get(js, entry, 0); if (is_undefined(key)) continue; - jsval_t val = arr_get(js, entry, 1); + ant_value_t val = arr_get(js, entry, 1); if (vtype(key) != T_STR) { char buf[64]; @@ -6338,47 +6338,47 @@ static jsval_t builtin_object_fromEntries(ant_t *js, jsval_t *args, int nargs) { return result; } -static jsval_t builtin_object_getOwnPropertyDescriptor(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_getOwnPropertyDescriptor(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkundef(); - jsval_t obj = args[0]; - jsval_t key = args[1]; + ant_value_t obj = args[0]; + ant_value_t key = args[1]; uint8_t t = vtype(obj); if (t != T_OBJ && t != T_ARR && t != T_FUNC) return js_mkundef(); const char *key_str; - jsoff_t key_len; + ant_offset_t key_len; bool is_sym = (vtype(key) == T_SYMBOL); if (is_sym) { const char *d = js_sym_desc(js, key); key_str = d ? d : "symbol"; - key_len = (jsoff_t)strlen(key_str); + key_len = (ant_offset_t)strlen(key_str); } else if (vtype(key) == T_STR) { - jsoff_t key_off = vstr(js, key, &key_len); + ant_offset_t key_off = vstr(js, key, &key_len); key_str = (char *) &js->mem[key_off]; } else { char buf[64]; size_t n = tostr(js, key, buf, sizeof(buf)); key = js_mkstr(js, buf, n); - jsoff_t key_off = vstr(js, key, &key_len); + ant_offset_t key_off = vstr(js, key, &key_len); key_str = (char *) &js->mem[key_off]; } - jsval_t as_obj = js_as_obj(obj); - jsoff_t obj_off = (jsoff_t)vdata(as_obj); + ant_value_t as_obj = js_as_obj(obj); + ant_offset_t obj_off = (ant_offset_t)vdata(as_obj); descriptor_entry_t *desc = is_sym - ? lookup_sym_descriptor(obj_off, (jsoff_t)vdata(key)) + ? lookup_sym_descriptor(obj_off, (ant_offset_t)vdata(key)) : lookup_descriptor(js, obj_off, key_str, key_len); - jsoff_t prop_off = is_sym ? lkp_sym(js, as_obj, (jsoff_t)vdata(key)) : lkp(js, as_obj, key_str, key_len); + ant_offset_t prop_off = is_sym ? lkp_sym(js, as_obj, (ant_offset_t)vdata(key)) : lkp(js, as_obj, key_str, key_len); if (prop_off == 0 && !desc) { return js_mkundef(); } - jsval_t result = js_mkobj(js); + ant_value_t result = js_mkobj(js); if (desc && (desc->has_getter || desc->has_setter)) { if (desc->has_getter) { @@ -6391,7 +6391,7 @@ static jsval_t builtin_object_getOwnPropertyDescriptor(ant_t *js, jsval_t *args, js_setprop(js, result, js_mkstr(js, "configurable", 12), js_bool(desc->configurable)); } else { if (prop_off != 0) { - jsval_t prop_val = resolveprop(js, mkval(T_PROP, prop_off)); + ant_value_t prop_val = resolveprop(js, mkval(T_PROP, prop_off)); js_setprop(js, result, js_mkstr(js, "value", 5), prop_val); } js_setprop(js, result, js_mkstr(js, "writable", 8), desc ? (js_bool(desc->writable)) : js_true); @@ -6405,56 +6405,56 @@ static jsval_t builtin_object_getOwnPropertyDescriptor(ant_t *js, jsval_t *args, } static inline bool own_prop_names_is_dense_shadow( - ant_t *js, jsoff_t obj_off, - const char *key, jsoff_t key_len + ant_t *js, ant_offset_t obj_off, + const char *key, ant_offset_t key_len ) { - jsoff_t doff = get_dense_buf_off(js, obj_off); + ant_offset_t doff = get_dense_buf_off(js, obj_off); if (!doff) return false; - jsoff_t dense_len = dense_length(js, doff); + ant_offset_t dense_len = dense_length(js, doff); if (dense_len <= 0 || !is_array_index(key, key_len)) return false; unsigned long dense_idx = 0; return parse_array_index(key, (size_t)key_len, dense_len, &dense_idx); } -static jsval_t builtin_object_getOwnPropertyNames(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_getOwnPropertyNames(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return mkarr(js); - jsval_t obj = args[0]; + ant_value_t obj = args[0]; if (vtype(obj) != T_OBJ && vtype(obj) != T_ARR && vtype(obj) != T_FUNC) return mkarr(js); if (vtype(obj) == T_FUNC) obj = js_func_obj(obj); - jsoff_t obj_off = (jsoff_t)vdata(obj); + ant_offset_t obj_off = (ant_offset_t)vdata(obj); bool is_arr_obj = (vtype(obj) == T_ARR); - jsval_t arr = mkarr(js); - jsoff_t idx = 0; + ant_value_t arr = mkarr(js); + ant_offset_t idx = 0; if (is_arr_obj) { - for (jsoff_t i = 0;; i++) { - jsoff_t doff = get_dense_buf_off(js, obj_off); + for (ant_offset_t i = 0;; i++) { + ant_offset_t doff = get_dense_buf_off(js, obj_off); if (!doff) break; - jsoff_t dense_len = dense_length(js, doff); + ant_offset_t dense_len = dense_length(js, doff); if (i >= dense_len) break; - jsval_t v = dense_get(js, doff, i); + ant_value_t v = dense_get(js, doff, i); if (is_empty_slot(v)) continue; char idxstr[16]; size_t idxlen = uint_to_str(idxstr, sizeof(idxstr), (unsigned)i); arr_set(js, arr, idx++, js_mkstr(js, idxstr, idxlen)); }} - jsoff_t next = loadoff(js, obj_off) & ~(3U | FLAGMASK); + ant_offset_t next = loadoff(js, obj_off) & ~(3U | FLAGMASK); while (next < js->brk && next != 0) { - jsoff_t prop = next; - jsoff_t header = loadoff(js, prop); + ant_offset_t prop = next; + ant_offset_t header = loadoff(js, prop); next = next_prop(header); if (is_slot_prop(header) || is_sym_key_prop(js, prop)) continue; - jsoff_t koff = loadoff(js, prop + (jsoff_t)sizeof(prop)); - jsoff_t klen = offtolen(loadoff(js, koff)); + ant_offset_t koff = loadoff(js, prop + (ant_offset_t)sizeof(prop)); + ant_offset_t klen = offtolen(loadoff(js, koff)); const char *key = (char *)&js->mem[koff + sizeof(koff)]; if (is_internal_prop(key, klen)) continue; @@ -6466,19 +6466,19 @@ static jsval_t builtin_object_getOwnPropertyNames(ant_t *js, jsval_t *args, int return mkval(T_ARR, vdata(arr)); } -static jsval_t builtin_object_getOwnPropertySymbols(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_getOwnPropertySymbols(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return mkarr(js); - jsval_t obj = args[0]; + ant_value_t obj = args[0]; uint8_t t = vtype(obj); if (t != T_OBJ && t != T_ARR && t != T_FUNC) return mkarr(js); if (t == T_FUNC) obj = js_func_obj(obj); - jsval_t arr = mkarr(js); jsoff_t idx = 0; - jsoff_t next = loadoff(js, (jsoff_t)vdata(obj)) & ~(3U | FLAGMASK); + ant_value_t arr = mkarr(js); ant_offset_t idx = 0; + ant_offset_t next = loadoff(js, (ant_offset_t)vdata(obj)) & ~(3U | FLAGMASK); while (next < js->brk && next != 0) { - jsoff_t header = loadoff(js, next); + ant_offset_t header = loadoff(js, next); if (!is_slot_prop(header) && is_sym_key_prop(js, next)) { arr_set(js, arr, idx++, mkval(T_SYMBOL, get_prop_koff(js, next))); } @@ -6488,127 +6488,127 @@ static jsval_t builtin_object_getOwnPropertySymbols(ant_t *js, jsval_t *args, in return mkval(T_ARR, vdata(arr)); } -static jsval_t builtin_object_isExtensible(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_isExtensible(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return js_true; - jsval_t obj = args[0]; + ant_value_t obj = args[0]; uint8_t t = vtype(obj); if (t != T_OBJ && t != T_ARR && t != T_FUNC) return js_true; - jsval_t as_obj = js_as_obj(obj); + ant_value_t as_obj = js_as_obj(obj); if (js_truthy(js, get_slot(js, as_obj, SLOT_FROZEN))) return js_false; if (js_truthy(js, get_slot(js, as_obj, SLOT_SEALED))) return js_false; - jsval_t ext_slot = get_slot(js, as_obj, SLOT_EXTENSIBLE); + ant_value_t ext_slot = get_slot(js, as_obj, SLOT_EXTENSIBLE); if (vtype(ext_slot) != T_UNDEF) return js_bool(js_truthy(js, ext_slot)); return js_true; } -static jsval_t builtin_object_preventExtensions(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_preventExtensions(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return js_mkundef(); - jsval_t obj = args[0]; + ant_value_t obj = args[0]; uint8_t t = vtype(obj); if (t != T_OBJ && t != T_ARR && t != T_FUNC) return obj; - jsval_t as_obj = js_as_obj(obj); + ant_value_t as_obj = js_as_obj(obj); set_slot(js, as_obj, SLOT_EXTENSIBLE, js_false); return obj; } -static jsval_t builtin_object_hasOwnProperty(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_hasOwnProperty(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return mkval(T_BOOL, 0); - jsval_t obj = js->this_val; - jsval_t key = args[0]; + ant_value_t obj = js->this_val; + ant_value_t key = args[0]; obj = resolveprop(js, obj); uint8_t t = vtype(obj); if (t != T_OBJ && t != T_ARR && t != T_FUNC) return mkval(T_BOOL, 0); - jsval_t as_obj = js_as_obj(obj); + ant_value_t as_obj = js_as_obj(obj); if (vtype(key) == T_SYMBOL) { - jsoff_t off = lkp_sym(js, as_obj, (jsoff_t)vdata(key)); + ant_offset_t off = lkp_sym(js, as_obj, (ant_offset_t)vdata(key)); return mkval(T_BOOL, off != 0 ? 1 : 0); } const char *key_str = NULL; - jsoff_t key_len = 0; + ant_offset_t key_len = 0; if (vtype(key) != T_STR) { char buf[64]; size_t n = tostr(js, key, buf, sizeof(buf)); key = js_mkstr(js, buf, n); } - jsoff_t key_off = vstr(js, key, &key_len); + ant_offset_t key_off = vstr(js, key, &key_len); key_str = (char *) &js->mem[key_off]; if (t == T_ARR && streq(key_str, key_len, "length", 6)) return mkval(T_BOOL, 1); if (t == T_ARR && is_array_index(key_str, key_len)) { unsigned long idx; if (parse_array_index(key_str, key_len, get_array_length(js, obj), &idx)) { - return mkval(T_BOOL, arr_has(js, obj, (jsoff_t)idx) ? 1 : 0); + return mkval(T_BOOL, arr_has(js, obj, (ant_offset_t)idx) ? 1 : 0); } } - jsoff_t off = lkp(js, as_obj, key_str, key_len); + ant_offset_t off = lkp(js, as_obj, key_str, key_len); if (off != 0) return mkval(T_BOOL, 1); - descriptor_entry_t *desc = lookup_descriptor(js, (jsoff_t)vdata(as_obj), key_str, key_len); + descriptor_entry_t *desc = lookup_descriptor(js, (ant_offset_t)vdata(as_obj), key_str, key_len); return mkval(T_BOOL, (desc && (desc->has_getter || desc->has_setter)) ? 1 : 0); } -static jsval_t builtin_object_isPrototypeOf(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_isPrototypeOf(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return mkval(T_BOOL, 0); - jsval_t proto_obj = resolveprop(js, js->this_val); - jsval_t obj = args[0]; + ant_value_t proto_obj = resolveprop(js, js->this_val); + ant_value_t obj = args[0]; uint8_t obj_type = vtype(obj); if (obj_type != T_OBJ && obj_type != T_ARR && obj_type != T_FUNC) return mkval(T_BOOL, 0); uint8_t proto_type = vtype(proto_obj); if (proto_type != T_OBJ && proto_type != T_ARR && proto_type != T_FUNC) return mkval(T_BOOL, 0); - jsoff_t proto_data = (jsoff_t)vdata(js_as_obj(proto_obj)); + ant_offset_t proto_data = (ant_offset_t)vdata(js_as_obj(proto_obj)); - jsval_t current = get_proto(js, obj); + ant_value_t current = get_proto(js, obj); while (!is_undefined(current) && !is_null(current)) { uint8_t cur_type = vtype(current); if (cur_type != T_OBJ && cur_type != T_ARR && cur_type != T_FUNC) break; - if ((jsoff_t)vdata(js_as_obj(current)) == proto_data) return mkval(T_BOOL, 1); + if ((ant_offset_t)vdata(js_as_obj(current)) == proto_data) return mkval(T_BOOL, 1); current = get_proto(js, current); } return mkval(T_BOOL, 0); } -static jsval_t builtin_object_propertyIsEnumerable(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_propertyIsEnumerable(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return mkval(T_BOOL, 0); - jsval_t obj = js->this_val; - jsval_t key = args[0]; + ant_value_t obj = js->this_val; + ant_value_t key = args[0]; obj = resolveprop(js, obj); uint8_t t = vtype(obj); if (t != T_OBJ && t != T_ARR && t != T_FUNC) return mkval(T_BOOL, 0); - jsval_t as_obj = js_as_obj(obj); + ant_value_t as_obj = js_as_obj(obj); if (vtype(key) == T_SYMBOL) { - jsoff_t off = lkp_sym(js, as_obj, (jsoff_t)vdata(key)); + ant_offset_t off = lkp_sym(js, as_obj, (ant_offset_t)vdata(key)); return mkval(T_BOOL, off != 0 ? 1 : 0); } const char *key_str = NULL; - jsoff_t key_len = 0; + ant_offset_t key_len = 0; if (vtype(key) != T_STR) { char buf[64]; size_t n = tostr(js, key, buf, sizeof(buf)); key = js_mkstr(js, buf, n); } - jsoff_t key_off = vstr(js, key, &key_len); + ant_offset_t key_off = vstr(js, key, &key_len); key_str = (char *) &js->mem[key_off]; if (t == T_ARR && streq(key_str, key_len, "length", 6)) { @@ -6616,19 +6616,19 @@ static jsval_t builtin_object_propertyIsEnumerable(ant_t *js, jsval_t *args, int } if (t == T_ARR) { - jsoff_t doff = get_dense_buf(js, obj); + ant_offset_t doff = get_dense_buf(js, obj); if (doff) { unsigned long idx; if (parse_array_index(key_str, key_len, dense_length(js, doff), &idx)) { - return mkval(T_BOOL, !is_empty_slot(dense_get(js, doff, (jsoff_t)idx)) ? 1 : 0); + return mkval(T_BOOL, !is_empty_slot(dense_get(js, doff, (ant_offset_t)idx)) ? 1 : 0); } } } - jsoff_t off = lkp(js, as_obj, key_str, key_len); + ant_offset_t off = lkp(js, as_obj, key_str, key_len); if (off == 0) return mkval(T_BOOL, 0); - jsoff_t obj_off = (jsoff_t)vdata(as_obj); + ant_offset_t obj_off = (ant_offset_t)vdata(as_obj); descriptor_entry_t *desc = lookup_descriptor(js, obj_off, key_str, key_len); if (desc) { return mkval(T_BOOL, desc->enumerable ? 1 : 0); @@ -6637,32 +6637,32 @@ static jsval_t builtin_object_propertyIsEnumerable(ant_t *js, jsval_t *args, int return mkval(T_BOOL, 1); } -static jsval_t builtin_object_toString(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_toString(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t obj = js->this_val; + ant_value_t obj = js->this_val; obj = resolveprop(js, obj); uint8_t t = vtype(obj); const char *tag = NULL; - jsoff_t tag_len = 0; + ant_offset_t tag_len = 0; - jsval_t tag_sym = get_toStringTag_sym(); + ant_value_t tag_sym = get_toStringTag_sym(); if (vtype(tag_sym) == T_SYMBOL) { - jsoff_t sym_off = (jsoff_t)vdata(tag_sym); - jsoff_t tag_off = 0; + ant_offset_t sym_off = (ant_offset_t)vdata(tag_sym); + ant_offset_t tag_off = 0; if (is_object_type(obj)) { tag_off = lkp_sym_proto(js, obj, sym_off); } else { - jsval_t proto = get_prototype_for_type(js, t); + ant_value_t proto = get_prototype_for_type(js, t); if (is_object_type(proto)) { tag_off = lkp_sym_proto(js, proto, sym_off); } } if (tag_off != 0) { - jsval_t tag_val = resolveprop(js, mkval(T_PROP, tag_off)); + ant_value_t tag_val = resolveprop(js, mkval(T_PROP, tag_off)); if (vtype(tag_val) == T_STR) { - jsoff_t str_off = vstr(js, tag_val, &tag_len); + ant_offset_t str_off = vstr(js, tag_val, &tag_len); tag = (const char *)&js->mem[str_off]; } } @@ -6699,33 +6699,33 @@ static jsval_t builtin_object_toString(ant_t *js, jsval_t *args, int nargs) { return string_builder_finalize(js, &sb); } -static jsval_t builtin_object_valueOf(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_valueOf(ant_t *js, ant_value_t *args, int nargs) { return js->this_val; } -static jsval_t builtin_object_toLocaleString(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_object_toLocaleString(ant_t *js, ant_value_t *args, int nargs) { return js_call_toString(js, js->this_val); } -static inline bool is_callable(jsval_t v) { +static inline bool is_callable(ant_value_t v) { uint8_t t = vtype(v); return t == T_FUNC || t == T_CFUNC; } -static inline jsval_t require_callback(ant_t *js, jsval_t *args, int nargs, const char *name) { +static inline ant_value_t require_callback(ant_t *js, ant_value_t *args, int nargs, const char *name) { if (nargs == 0 || !is_callable(args[0])) return js_mkerr(js, "%s requires a function argument", name); return args[0]; } -static jsval_t array_shallow_copy(ant_t *js, jsval_t arr, jsoff_t len) { - jsval_t result = mkarr(js); +static ant_value_t array_shallow_copy(ant_t *js, ant_value_t arr, ant_offset_t len) { + ant_value_t result = mkarr(js); if (is_err(result)) return result; - jsoff_t doff = get_dense_buf(js, arr); + ant_offset_t doff = get_dense_buf(js, arr); if (doff) { - for (jsoff_t i = 0; i < len; i++) { - jsval_t v = dense_get(js, doff, i); + for (ant_offset_t i = 0; i < len; i++) { + ant_value_t v = dense_get(js, doff, i); arr_set(js, result, i, v); } return result; @@ -6734,7 +6734,7 @@ static jsval_t array_shallow_copy(ant_t *js, jsval_t arr, jsoff_t len) { ant_iter_t iter = js_prop_iter_begin(js, arr); const char *key; size_t key_len; - jsval_t val; + ant_value_t val; while (js_prop_iter_next(&iter, &key, &key_len, &val)) { if (key_len == 0 || key[0] > '9' || key[0] < '0') continue; @@ -6746,8 +6746,8 @@ static jsval_t array_shallow_copy(ant_t *js, jsval_t arr, jsoff_t len) { return result; } -static jsval_t builtin_array_push(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_push(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; arr = resolveprop(js, arr); if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) { @@ -6755,31 +6755,31 @@ static jsval_t builtin_array_push(ant_t *js, jsval_t *args, int nargs) { } if (is_proxy(js, arr)) { - jsoff_t off = lkp_interned(js, arr, INTERN_LENGTH, 6); - jsoff_t len = 0; + ant_offset_t off = lkp_interned(js, arr, INTERN_LENGTH, 6); + ant_offset_t len = 0; if (off != 0) { - jsval_t len_val = resolveprop(js, mkval(T_PROP, off)); - if (vtype(len_val) == T_NUM) len = (jsoff_t) tod(len_val); + ant_value_t len_val = resolveprop(js, mkval(T_PROP, off)); + if (vtype(len_val) == T_NUM) len = (ant_offset_t) tod(len_val); } for (int i = 0; i < nargs; i++) { char idxstr[16]; size_t idxlen = uint_to_str(idxstr, sizeof(idxstr), (unsigned)len); - jsval_t key = js_mkstr(js, idxstr, idxlen); + ant_value_t key = js_mkstr(js, idxstr, idxlen); js_setprop(js, arr, key, args[i]); len++; } - jsval_t len_val = tov((double) len); + ant_value_t len_val = tov((double) len); js_setprop(js, arr, js->length_str, len_val); return len_val; } - jsoff_t len = get_array_length(js, arr); + ant_offset_t len = get_array_length(js, arr); - jsoff_t doff = get_dense_buf(js, arr); + ant_offset_t doff = get_dense_buf(js, arr); if (doff) { for (int i = 0; i < nargs; i++) { - jsoff_t cap = dense_capacity(js, doff); + ant_offset_t cap = dense_capacity(js, doff); if (len >= cap) { doff = dense_grow(js, arr, len + 1); if (doff == 0) return js_mkerr(js, "oom"); @@ -6791,7 +6791,7 @@ static jsval_t builtin_array_push(ant_t *js, jsval_t *args, int nargs) { return tov((double) len); } - jsoff_t off = lkp_interned(js, arr, INTERN_LENGTH, 6); + ant_offset_t off = lkp_interned(js, arr, INTERN_LENGTH, 6); for (int i = 0; i < nargs; i++) { char idxstr[16]; @@ -6799,21 +6799,21 @@ static jsval_t builtin_array_push(ant_t *js, jsval_t *args, int nargs) { js_mkprop_fast(js, arr, idxstr, idxlen, args[i]); len++; } - jsval_t new_len = tov((double) len); - if (off != 0) saveval(js, off + sizeof(jsoff_t) * 2, new_len); + ant_value_t new_len = tov((double) len); + if (off != 0) saveval(js, off + sizeof(ant_offset_t) * 2, new_len); else js_mkprop_fast(js, arr, "length", 6, new_len); return new_len; } -void js_arr_push(ant_t *js, jsval_t arr, jsval_t val) { +void js_arr_push(ant_t *js, ant_value_t arr, ant_value_t val) { arr = resolveprop(js, arr); if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) return; - jsoff_t doff = get_dense_buf(js, arr); + ant_offset_t doff = get_dense_buf(js, arr); if (doff) { - jsoff_t len = dense_length(js, doff); - jsoff_t cap = dense_capacity(js, doff); + ant_offset_t len = dense_length(js, doff); + ant_offset_t cap = dense_capacity(js, doff); if (len >= cap) { doff = dense_grow(js, arr, len + 1); if (doff == 0) return; @@ -6823,30 +6823,30 @@ void js_arr_push(ant_t *js, jsval_t arr, jsval_t val) { return; } - jsoff_t len_off = lkp_interned(js, arr, INTERN_LENGTH, 6); - jsoff_t len = 0; + ant_offset_t len_off = lkp_interned(js, arr, INTERN_LENGTH, 6); + ant_offset_t len = 0; if (len_off != 0) { - jsval_t len_val = resolveprop(js, mkval(T_PROP, len_off)); - if (vtype(len_val) == T_NUM) len = (jsoff_t) tod(len_val); + ant_value_t len_val = resolveprop(js, mkval(T_PROP, len_off)); + if (vtype(len_val) == T_NUM) len = (ant_offset_t) tod(len_val); } char idxstr[16]; size_t idxlen = uint_to_str(idxstr, sizeof(idxstr), (unsigned)len); js_mkprop_fast(js, arr, idxstr, idxlen, val); - if (len_off != 0) saveval(js, len_off + sizeof(jsoff_t) * 2, tov((double)(len + 1))); + if (len_off != 0) saveval(js, len_off + sizeof(ant_offset_t) * 2, tov((double)(len + 1))); else js_mkprop_fast(js, arr, "length", 6, tov((double)(len + 1))); } -static jsval_t builtin_array_pop(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_pop(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) { return js_mkerr(js, "pop called on non-array"); } if (is_proxy(js, arr)) { - jsoff_t len = proxy_aware_length(js, arr); + ant_offset_t len = proxy_aware_length(js, arr); if (len == 0) { js_setprop(js, arr, js->length_str, tov(0.0)); return js_mkundef(); @@ -6854,95 +6854,95 @@ static jsval_t builtin_array_pop(ant_t *js, jsval_t *args, int nargs) { len--; char idxstr[16]; size_t idxlen = uint_to_str(idxstr, sizeof(idxstr), (unsigned)len); - jsval_t result = proxy_aware_get_elem(js, arr, idxstr, idxlen); + ant_value_t result = proxy_aware_get_elem(js, arr, idxstr, idxlen); js_setprop(js, arr, js->length_str, tov((double) len)); js->needs_gc = true; return result; } - jsoff_t doff = get_dense_buf(js, arr); + ant_offset_t doff = get_dense_buf(js, arr); if (doff) { - jsoff_t len = dense_length(js, doff); + ant_offset_t len = dense_length(js, doff); if (len == 0) return js_mkundef(); len--; - jsval_t result = dense_get(js, doff, len); + ant_value_t result = dense_get(js, doff, len); if (is_empty_slot(result)) result = js_mkundef(); dense_set(js, doff, len, T_EMPTY); dense_set_length(js, doff, len); return result; } - jsoff_t off = lkp_interned(js, arr, INTERN_LENGTH, 6); - jsoff_t len = 0; + ant_offset_t off = lkp_interned(js, arr, INTERN_LENGTH, 6); + ant_offset_t len = 0; if (off != 0) { - jsval_t len_val = resolveprop(js, mkval(T_PROP, off)); - if (vtype(len_val) == T_NUM) len = (jsoff_t) tod(len_val); + ant_value_t len_val = resolveprop(js, mkval(T_PROP, off)); + if (vtype(len_val) == T_NUM) len = (ant_offset_t) tod(len_val); } if (len == 0) return js_mkundef(); len--; char idxstr[16]; size_t idxlen = uint_to_str(idxstr, sizeof(idxstr), (unsigned)len); - jsoff_t arr_off = (jsoff_t)vdata(js_as_obj(arr)); - jsoff_t tail = loadoff(js, arr_off + sizeof(jsoff_t) * 2); - jsoff_t elem_off = 0; + ant_offset_t arr_off = (ant_offset_t)vdata(js_as_obj(arr)); + ant_offset_t tail = loadoff(js, arr_off + sizeof(ant_offset_t) * 2); + ant_offset_t elem_off = 0; if (tail != 0 && tail < js->brk) { - jsoff_t tail_hdr = loadoff(js, tail); + ant_offset_t tail_hdr = loadoff(js, tail); if ((tail_hdr & SLOTMASK) == 0) { - jsoff_t tail_koff = loadoff(js, tail + sizeof(jsoff_t)); - jsoff_t tail_klen = offtolen(loadoff(js, tail_koff)); - const char *tail_key = (char *)&js->mem[tail_koff + sizeof(jsoff_t)]; + ant_offset_t tail_koff = loadoff(js, tail + sizeof(ant_offset_t)); + ant_offset_t tail_klen = offtolen(loadoff(js, tail_koff)); + const char *tail_key = (char *)&js->mem[tail_koff + sizeof(ant_offset_t)]; if (tail_klen == idxlen && memcmp(tail_key, idxstr, idxlen) == 0) elem_off = tail; } } if (elem_off == 0) elem_off = lkp(js, arr, idxstr, idxlen); - jsval_t result = js_mkundef(); + ant_value_t result = js_mkundef(); if (elem_off != 0) result = resolveprop(js, mkval(T_PROP, elem_off)); if (off != 0) { - saveval(js, off + sizeof(jsoff_t) * 2, tov((double) len)); + saveval(js, off + sizeof(ant_offset_t) * 2, tov((double) len)); } else js_setprop(js, arr, js->length_str, tov((double) len)); js->needs_gc = true; return result; } -static jsval_t builtin_array_slice(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_slice(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) { return js_mkerr(js, "slice called on non-array"); } - jsoff_t len = get_array_length(js, arr); + ant_offset_t len = get_array_length(js, arr); - jsoff_t start = 0, end = len; + ant_offset_t start = 0, end = len; double dlen = D(len); if (nargs >= 1 && vtype(args[0]) == T_NUM) { double d = tod(args[0]); if (d < 0) { - start = (jsoff_t) (d + dlen < 0 ? 0 : d + dlen); - } else start = (jsoff_t) (d > dlen ? dlen : d); + start = (ant_offset_t) (d + dlen < 0 ? 0 : d + dlen); + } else start = (ant_offset_t) (d > dlen ? dlen : d); } if (nargs >= 2 && vtype(args[1]) == T_NUM) { double d = tod(args[1]); if (d < 0) { - end = (jsoff_t) (d + dlen < 0 ? 0 : d + dlen); + end = (ant_offset_t) (d + dlen < 0 ? 0 : d + dlen); } else { - end = (jsoff_t) (d > dlen ? dlen : d); + end = (ant_offset_t) (d > dlen ? dlen : d); } } if (start > end) start = end; - jsval_t result = array_alloc_like(js, arr); + ant_value_t result = array_alloc_like(js, arr); if (is_err(result)) return result; - jsoff_t result_idx = 0; + ant_offset_t result_idx = 0; - for (jsoff_t i = start; i < end; i++) { - jsval_t elem = arr_get(js, arr, i); + for (ant_offset_t i = start; i < end; i++) { + ant_value_t elem = arr_get(js, arr, i); arr_set(js, result, result_idx, elem); result_idx++; } @@ -6950,27 +6950,27 @@ static jsval_t builtin_array_slice(ant_t *js, jsval_t *args, int nargs) { return result; } -static jsval_t builtin_array_join(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_join(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) { return js_mkerr(js, "join called on non-array"); } const char *sep = ","; - jsoff_t sep_len = 1; + ant_offset_t sep_len = 1; if (nargs >= 1) { if (vtype(args[0]) == T_STR) { sep_len = 0; - jsoff_t sep_off = vstr(js, args[0], &sep_len); + ant_offset_t sep_off = vstr(js, args[0], &sep_len); sep = (const char *) &js->mem[sep_off]; } else if (vtype(args[0]) != T_UNDEF) { const char *sep_str = js_str(js, args[0]); sep = sep_str; - sep_len = (jsoff_t) strlen(sep_str); + sep_len = (ant_offset_t) strlen(sep_str); } } - jsoff_t len = get_array_length(js, arr); + ant_offset_t len = get_array_length(js, arr); if (len == 0) return js_mkstr(js, "", 0); @@ -6979,7 +6979,7 @@ static jsval_t builtin_array_join(ant_t *js, jsval_t *args, int nargs) { char *result = (char *)ant_calloc(capacity); if (!result) return js_mkerr(js, "oom"); - for (jsoff_t i = 0; i < len; i++) { + for (ant_offset_t i = 0; i < len; i++) { if (i > 0) { if (result_len + sep_len >= capacity) { capacity = (result_len + sep_len + 1) * 2; @@ -6992,17 +6992,17 @@ static jsval_t builtin_array_join(ant_t *js, jsval_t *args, int nargs) { } { - jsval_t elem = arr_get(js, arr, i); + ant_value_t elem = arr_get(js, arr, i); uint8_t et = vtype(elem); if (et == T_NULL || et == T_UNDEF) continue; const char *elem_str = NULL; size_t elem_len = 0; char numstr[64]; - jsval_t str_val = js_mkundef(); + ant_value_t str_val = js_mkundef(); if (et == T_STR) { - jsoff_t soff, slen; + ant_offset_t soff, slen; soff = vstr(js, elem, &slen); elem_str = (const char *)&js->mem[soff]; elem_len = slen; @@ -7022,7 +7022,7 @@ static jsval_t builtin_array_join(ant_t *js, jsval_t *args, int nargs) { } if (vtype(str_val) == T_STR) { - jsoff_t soff, slen; + ant_offset_t soff, slen; soff = vstr(js, str_val, &slen); elem_str = (const char *)&js->mem[soff]; elem_len = slen; @@ -7043,32 +7043,32 @@ static jsval_t builtin_array_join(ant_t *js, jsval_t *args, int nargs) { } } - jsval_t ret = js_mkstr(js, result, result_len); + ant_value_t ret = js_mkstr(js, result, result_len); free(result); return ret; } -static jsval_t builtin_array_includes(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_includes(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) return js_mkerr(js, "includes called on non-array"); if (nargs == 0) return mkval(T_BOOL, 0); - jsval_t search = args[0]; + ant_value_t search = args[0]; - jsoff_t len = get_array_length(js, arr); + ant_offset_t len = get_array_length(js, arr); if (len == 0) return mkval(T_BOOL, 0); - jsoff_t start = 0; + ant_offset_t start = 0; if (nargs >= 2 && vtype(args[1]) == T_NUM) { int s = (int) tod(args[1]); if (s < 0) s = (int)len + s; if (s < 0) s = 0; - start = (jsoff_t) s; + start = (ant_offset_t) s; } - for (jsoff_t i = start; i < len; i++) { - jsval_t val = arr_get(js, arr, i); + for (ant_offset_t i = start; i < len; i++) { + ant_value_t val = arr_get(js, arr, i); if (vtype(val) == T_NUM && vtype(search) == T_NUM && isnan(tod(val)) && isnan(tod(search))) return mkval(T_BOOL, 1); if (strict_eq_values(js, val, search)) return mkval(T_BOOL, 1); } @@ -7076,23 +7076,23 @@ static jsval_t builtin_array_includes(ant_t *js, jsval_t *args, int nargs) { return mkval(T_BOOL, 0); } -static jsval_t builtin_array_every(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_every(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) return js_mkerr(js, "every called on non-array"); - jsval_t callback = require_callback(js, args, nargs, "every"); + ant_value_t callback = require_callback(js, args, nargs, "every"); if (is_err(callback)) return callback; - jsval_t this_arg = (nargs >= 2) ? args[1] : js_mkundef(); + ant_value_t this_arg = (nargs >= 2) ? args[1] : js_mkundef(); - jsoff_t len = get_array_length(js, arr); + ant_offset_t len = get_array_length(js, arr); - for (jsoff_t i = 0; i < len; i++) { + for (ant_offset_t i = 0; i < len; i++) { if (!arr_has(js, arr, i)) continue; - jsval_t val = arr_get(js, arr, i); - jsval_t call_args[3] = { val, tov((double)i), arr }; - jsval_t result = sv_vm_call(js->vm, js, callback, this_arg, call_args, 3, NULL, false); + ant_value_t val = arr_get(js, arr, i); + ant_value_t call_args[3] = { val, tov((double)i), arr }; + ant_value_t result = sv_vm_call(js->vm, js, callback, this_arg, call_args, 3, NULL, false); if (is_err(result)) return result; if (!js_truthy(js, result)) return mkval(T_BOOL, 0); } @@ -7100,47 +7100,47 @@ static jsval_t builtin_array_every(ant_t *js, jsval_t *args, int nargs) { return mkval(T_BOOL, 1); } -static jsval_t builtin_array_forEach(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_forEach(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) return js_mkerr(js, "forEach called on non-array"); - jsval_t callback = require_callback(js, args, nargs, "forEach"); + ant_value_t callback = require_callback(js, args, nargs, "forEach"); if (is_err(callback)) return callback; - jsval_t this_arg = (nargs >= 2) ? args[1] : js_mkundef(); + ant_value_t this_arg = (nargs >= 2) ? args[1] : js_mkundef(); - jsoff_t len = get_array_length(js, arr); + ant_offset_t len = get_array_length(js, arr); - for (jsoff_t i = 0; i < len; i++) { + for (ant_offset_t i = 0; i < len; i++) { if (!arr_has(js, arr, i)) continue; - jsval_t val = arr_get(js, arr, i); - jsval_t call_args[3] = { val, tov((double)i), arr }; - jsval_t result = sv_vm_call(js->vm, js, callback, this_arg, call_args, 3, NULL, false); + ant_value_t val = arr_get(js, arr, i); + ant_value_t call_args[3] = { val, tov((double)i), arr }; + ant_value_t result = sv_vm_call(js->vm, js, callback, this_arg, call_args, 3, NULL, false); if (is_err(result)) return result; } return js_mkundef(); } -static jsval_t builtin_array_reverse(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_array_reverse(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t arr = js->this_val; + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) return js_mkerr(js, "reverse called on non-array"); if (is_proxy(js, arr)) { - jsoff_t len = proxy_aware_length(js, arr); + ant_offset_t len = proxy_aware_length(js, arr); if (len <= 1) return arr; - jsval_t read_from = proxy_read_target(js, arr); - jsoff_t lower = 0; + ant_value_t read_from = proxy_read_target(js, arr); + ant_offset_t lower = 0; while (lower < len / 2) { - jsoff_t upper_idx = len - lower - 1; + ant_offset_t upper_idx = len - lower - 1; bool lower_exists = arr_has(js, read_from, lower); bool upper_exists = arr_has(js, read_from, upper_idx); - jsval_t lower_val = lower_exists ? arr_get(js, read_from, lower) : js_mkundef(); - jsval_t upper_val = upper_exists ? arr_get(js, read_from, upper_idx) : js_mkundef(); + ant_value_t lower_val = lower_exists ? arr_get(js, read_from, lower) : js_mkundef(); + ant_value_t upper_val = upper_exists ? arr_get(js, read_from, upper_idx) : js_mkundef(); if (lower_exists && upper_exists) { char s1[16]; size_t l1 = uint_to_str(s1, sizeof(s1), (unsigned)lower); js_setprop(js, arr, js_mkstr(js, s1, l1), upper_val); @@ -7156,29 +7156,29 @@ static jsval_t builtin_array_reverse(ant_t *js, jsval_t *args, int nargs) { } return arr; } - jsoff_t len = get_array_length(js, arr); + ant_offset_t len = get_array_length(js, arr); if (len <= 1) return arr; - jsoff_t doff = get_dense_buf(js, arr); + ant_offset_t doff = get_dense_buf(js, arr); if (doff) { - for (jsoff_t i = 0; i < len / 2; i++) { - jsval_t a = dense_get(js, doff, i); - jsval_t b = dense_get(js, doff, len - 1 - i); + for (ant_offset_t i = 0; i < len / 2; i++) { + ant_value_t a = dense_get(js, doff, i); + ant_value_t b = dense_get(js, doff, len - 1 - i); dense_set(js, doff, i, b); dense_set(js, doff, len - 1 - i, a); } return arr; } - jsval_t *vals = malloc(len * sizeof(jsval_t)); - jsoff_t *offs = malloc(len * sizeof(jsoff_t)); + ant_value_t *vals = malloc(len * sizeof(ant_value_t)); + ant_offset_t *offs = malloc(len * sizeof(ant_offset_t)); if (!vals || !offs) { free(vals); free(offs); return js_mkerr(js, "out of memory"); } - jsoff_t count = 0; + ant_offset_t count = 0; ant_iter_t iter = js_prop_iter_begin(js, arr); const char *key; size_t key_len; - jsval_t val; + ant_value_t val; while (js_prop_iter_next(&iter, &key, &key_len, &val)) { unsigned long parsed_idx; @@ -7190,14 +7190,14 @@ static jsval_t builtin_array_reverse(ant_t *js, jsval_t *args, int nargs) { } js_prop_iter_end(&iter); - for (jsoff_t i = 0; i < count / 2; i++) { - jsval_t tmp = vals[i]; + for (ant_offset_t i = 0; i < count / 2; i++) { + ant_value_t tmp = vals[i]; vals[i] = vals[count - 1 - i]; vals[count - 1 - i] = tmp; } - for (jsoff_t i = 0; i < count; i++) { - saveval(js, offs[i] + sizeof(jsoff_t) * 2, vals[i]); + for (ant_offset_t i = 0; i < count; i++) { + saveval(js, offs[i] + sizeof(ant_offset_t) * 2, vals[i]); } free(vals); @@ -7205,25 +7205,25 @@ static jsval_t builtin_array_reverse(ant_t *js, jsval_t *args, int nargs) { return arr; } -static jsval_t builtin_array_map(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_map(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) return js_mkerr(js, "map called on non-array"); - jsval_t callback = require_callback(js, args, nargs, "map"); + ant_value_t callback = require_callback(js, args, nargs, "map"); if (is_err(callback)) return callback; - jsval_t this_arg = (nargs >= 2) ? args[1] : js_mkundef(); + ant_value_t this_arg = (nargs >= 2) ? args[1] : js_mkundef(); - jsoff_t len = get_array_length(js, arr); - jsval_t result = array_alloc_like(js, arr); + ant_offset_t len = get_array_length(js, arr); + ant_value_t result = array_alloc_like(js, arr); if (is_err(result)) return result; - for (jsoff_t i = 0; i < len; i++) { + for (ant_offset_t i = 0; i < len; i++) { if (!arr_has(js, arr, i)) continue; - jsval_t val = arr_get(js, arr, i); - jsval_t call_args[3] = { val, tov((double)i), arr }; - jsval_t mapped = sv_vm_call(js->vm, js, callback, this_arg, call_args, 3, NULL, false); + ant_value_t val = arr_get(js, arr, i); + ant_value_t call_args[3] = { val, tov((double)i), arr }; + ant_value_t mapped = sv_vm_call(js->vm, js, callback, this_arg, call_args, 3, NULL, false); if (is_err(mapped)) return mapped; arr_set(js, result, i, mapped); } @@ -7231,27 +7231,27 @@ static jsval_t builtin_array_map(ant_t *js, jsval_t *args, int nargs) { return result; } -static jsval_t builtin_array_filter(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_filter(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) return js_mkerr(js, "filter called on non-array"); - jsval_t callback = require_callback(js, args, nargs, "filter"); + ant_value_t callback = require_callback(js, args, nargs, "filter"); if (is_err(callback)) return callback; - jsval_t this_arg = (nargs >= 2) ? args[1] : js_mkundef(); + ant_value_t this_arg = (nargs >= 2) ? args[1] : js_mkundef(); - jsoff_t len = get_array_length(js, arr); - jsval_t result = array_alloc_like(js, arr); + ant_offset_t len = get_array_length(js, arr); + ant_value_t result = array_alloc_like(js, arr); if (is_err(result)) return result; - jsoff_t result_idx = 0; + ant_offset_t result_idx = 0; - for (jsoff_t i = 0; i < len; i++) { + for (ant_offset_t i = 0; i < len; i++) { if (!arr_has(js, arr, i)) continue; - jsval_t val = arr_get(js, arr, i); - jsval_t call_args[3] = { val, tov((double)i), arr }; - jsval_t test = sv_vm_call(js->vm, js, callback, this_arg, call_args, 3, NULL, false); + ant_value_t val = arr_get(js, arr, i); + ant_value_t call_args[3] = { val, tov((double)i), arr }; + ant_value_t test = sv_vm_call(js->vm, js, callback, this_arg, call_args, 3, NULL, false); if (is_err(test)) return test; if (js_truthy(js, test)) { arr_set(js, result, result_idx, val); result_idx++; } @@ -7260,26 +7260,26 @@ static jsval_t builtin_array_filter(ant_t *js, jsval_t *args, int nargs) { return result; } -static jsval_t builtin_array_reduce(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_reduce(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) return js_mkerr(js, "reduce called on non-array"); - jsval_t callback = require_callback(js, args, nargs, "reduce"); + ant_value_t callback = require_callback(js, args, nargs, "reduce"); if (is_err(callback)) return callback; bool has_initial = (nargs >= 2); - jsoff_t len = get_array_length(js, arr); + ant_offset_t len = get_array_length(js, arr); - jsval_t accumulator = has_initial ? args[1] : js_mkundef(); + ant_value_t accumulator = has_initial ? args[1] : js_mkundef(); bool first = !has_initial; - for (jsoff_t i = 0; i < len; i++) { + for (ant_offset_t i = 0; i < len; i++) { if (!arr_has(js, arr, i)) continue; - jsval_t val = arr_get(js, arr, i); + ant_value_t val = arr_get(js, arr, i); if (first) { accumulator = val; first = false; continue; } - jsval_t call_args[4] = { accumulator, val, tov((double)i), arr }; + ant_value_t call_args[4] = { accumulator, val, tov((double)i), arr }; accumulator = sv_vm_call(js->vm, js, callback, js_mkundef(), call_args, 4, NULL, false); if (is_err(accumulator)) return accumulator; } @@ -7288,13 +7288,13 @@ static jsval_t builtin_array_reduce(ant_t *js, jsval_t *args, int nargs) { return accumulator; } -static void flat_helper(ant_t *js, jsval_t arr, jsval_t result, jsoff_t *result_idx, int depth) { - jsoff_t len = get_array_length(js, arr); +static void flat_helper(ant_t *js, ant_value_t arr, ant_value_t result, ant_offset_t *result_idx, int depth) { + ant_offset_t len = get_array_length(js, arr); if (len == 0) return; - for (jsoff_t i = 0; i < len; i++) { + for (ant_offset_t i = 0; i < len; i++) { if (!arr_has(js, arr, i)) continue; - jsval_t val = arr_get(js, arr, i); + ant_value_t val = arr_get(js, arr, i); if (depth > 0 && (vtype(val) == T_ARR || vtype(val) == T_OBJ)) { flat_helper(js, val, result, result_idx, depth - 1); @@ -7302,8 +7302,8 @@ static void flat_helper(ant_t *js, jsval_t arr, jsval_t result, jsoff_t *result_ } } -static jsval_t builtin_array_flat(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_flat(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) { return js_mkerr(js, "flat called on non-array"); } @@ -7314,51 +7314,51 @@ static jsval_t builtin_array_flat(ant_t *js, jsval_t *args, int nargs) { if (depth < 0) depth = 0; } - jsval_t result = array_alloc_like(js, arr); + ant_value_t result = array_alloc_like(js, arr); if (is_err(result)) return result; - jsoff_t result_idx = 0; + ant_offset_t result_idx = 0; flat_helper(js, arr, result, &result_idx, depth); return result; } -static jsval_t builtin_array_concat(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_concat(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) { return js_mkerr(js, "concat called on non-array"); } - jsval_t result = array_alloc_like(js, arr); + ant_value_t result = array_alloc_like(js, arr); if (is_err(result)) return result; - jsoff_t result_idx = 0; + ant_offset_t result_idx = 0; for (int a = -1; a < nargs; a++) { - jsval_t arg = (a < 0) ? arr : args[a]; + ant_value_t arg = (a < 0) ? arr : args[a]; bool spreadable = false; if (vtype(arg) == T_ARR || vtype(arg) == T_OBJ) { bool array_default_spreadable = (vtype(arg) == T_ARR); if (!array_default_spreadable && is_proxy(js, arg)) { - jsval_t target = proxy_read_target(js, arg); + ant_value_t target = proxy_read_target(js, arg); array_default_spreadable = (vtype(target) == T_ARR); } - jsval_t spread_val = js_get_sym(js, arg, get_isConcatSpreadable_sym()); + ant_value_t spread_val = js_get_sym(js, arg, get_isConcatSpreadable_sym()); if (is_err(spread_val)) return spread_val; if (vtype(spread_val) == T_UNDEF) spreadable = array_default_spreadable; else spreadable = js_truthy(js, spread_val); } if (spreadable) { - jsoff_t arg_len = 0; - jsval_t len_val = js_get(js, arg, "length"); + ant_offset_t arg_len = 0; + ant_value_t len_val = js_get(js, arg, "length"); if (is_err(len_val)) return len_val; - if (vtype(len_val) == T_NUM && tod(len_val) > 0) arg_len = (jsoff_t)tod(len_val); + if (vtype(len_val) == T_NUM && tod(len_val) > 0) arg_len = (ant_offset_t)tod(len_val); - for (jsoff_t i = 0; i < arg_len; i++) { + for (ant_offset_t i = 0; i < arg_len; i++) { char idxstr[32]; uint_to_str(idxstr, sizeof(idxstr), (uint64_t)i); - jsval_t elem = js_get(js, arg, idxstr); + ant_value_t elem = js_get(js, arg, idxstr); if (is_err(elem)) return elem; arr_set(js, result, result_idx, elem); result_idx++; @@ -7372,74 +7372,74 @@ static jsval_t builtin_array_concat(ant_t *js, jsval_t *args, int nargs) { return result; } -static jsval_t builtin_array_at(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_at(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) { return js_mkerr(js, "at called on non-array"); } if (nargs == 0 || vtype(args[0]) != T_NUM) return js_mkundef(); - jsoff_t len = get_array_length(js, arr); + ant_offset_t len = get_array_length(js, arr); int idx = (int) tod(args[0]); if (idx < 0) idx = (int)len + idx; - if (idx < 0 || (jsoff_t)idx >= len) return js_mkundef(); + if (idx < 0 || (ant_offset_t)idx >= len) return js_mkundef(); - return arr_get(js, arr, (jsoff_t)idx); + return arr_get(js, arr, (ant_offset_t)idx); } -static jsval_t builtin_array_fill(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_fill(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) { return js_mkerr(js, "fill called on non-array"); } - jsval_t value = nargs >= 1 ? args[0] : js_mkundef(); + ant_value_t value = nargs >= 1 ? args[0] : js_mkundef(); - jsoff_t len = proxy_aware_length(js, arr); + ant_offset_t len = proxy_aware_length(js, arr); - jsoff_t start = 0, end = len; + ant_offset_t start = 0, end = len; if (nargs >= 2 && vtype(args[1]) == T_NUM) { int s = (int) tod(args[1]); if (s < 0) s = (int)len + s; if (s < 0) s = 0; - start = (jsoff_t) s; + start = (ant_offset_t) s; } if (nargs >= 3 && vtype(args[2]) == T_NUM) { int e = (int) tod(args[2]); if (e < 0) e = (int)len + e; if (e < 0) e = 0; - end = (jsoff_t) e; + end = (ant_offset_t) e; } if (start > len) start = len; if (end > len) end = len; - for (jsoff_t i = start; i < end; i++) { + for (ant_offset_t i = start; i < end; i++) { arr_set(js, arr, i, value); } return arr; } -static jsval_t array_find_impl(ant_t *js, jsval_t *args, int nargs, bool return_index, const char *name) { - jsval_t arr = js->this_val; +static ant_value_t array_find_impl(ant_t *js, ant_value_t *args, int nargs, bool return_index, const char *name) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) return js_mkerr(js, "%s called on non-array", name); - jsval_t callback = require_callback(js, args, nargs, name); + ant_value_t callback = require_callback(js, args, nargs, name); if (is_err(callback)) return callback; - jsval_t this_arg = (nargs >= 2) ? args[1] : js_mkundef(); + ant_value_t this_arg = (nargs >= 2) ? args[1] : js_mkundef(); - jsoff_t len = get_array_length(js, arr); + ant_offset_t len = get_array_length(js, arr); if (len == 0) return return_index ? tov(-1) : js_mkundef(); - for (jsoff_t i = 0; i < len; i++) { - jsval_t val = arr_get(js, arr, i); + for (ant_offset_t i = 0; i < len; i++) { + ant_value_t val = arr_get(js, arr, i); - jsval_t call_args[3] = { val, tov((double)i), arr }; - jsval_t result = sv_vm_call(js->vm, js, callback, this_arg, call_args, 3, NULL, false); + ant_value_t call_args[3] = { val, tov((double)i), arr }; + ant_value_t result = sv_vm_call(js->vm, js, callback, this_arg, call_args, 3, NULL, false); if (is_err(result)) return result; if (js_truthy(js, result)) return return_index ? tov((double)i) : val; @@ -7448,32 +7448,32 @@ static jsval_t array_find_impl(ant_t *js, jsval_t *args, int nargs, bool return_ return return_index ? tov(-1) : js_mkundef(); } -static jsval_t builtin_array_find(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_array_find(ant_t *js, ant_value_t *args, int nargs) { return array_find_impl(js, args, nargs, false, "find"); } -static jsval_t builtin_array_findIndex(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_array_findIndex(ant_t *js, ant_value_t *args, int nargs) { return array_find_impl(js, args, nargs, true, "findIndex"); } -static jsval_t array_find_last_impl(ant_t *js, jsval_t *args, int nargs, bool return_index, const char *name) { - jsval_t arr = js->this_val; +static ant_value_t array_find_last_impl(ant_t *js, ant_value_t *args, int nargs, bool return_index, const char *name) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) return js_mkerr(js, "%s called on non-array", name); - jsval_t callback = require_callback(js, args, nargs, name); + ant_value_t callback = require_callback(js, args, nargs, name); if (is_err(callback)) return callback; - jsval_t this_arg = (nargs >= 2) ? args[1] : js_mkundef(); + ant_value_t this_arg = (nargs >= 2) ? args[1] : js_mkundef(); - jsoff_t len = get_array_length(js, arr); + ant_offset_t len = get_array_length(js, arr); if (len == 0) return return_index ? tov(-1) : js_mkundef(); - for (jsoff_t i = len; i > 0; i--) { - jsval_t val = arr_get(js, arr, i - 1); + for (ant_offset_t i = len; i > 0; i--) { + ant_value_t val = arr_get(js, arr, i - 1); - jsval_t call_args[3] = { val, tov((double)(i - 1)), arr }; - jsval_t result = sv_vm_call(js->vm, js, callback, this_arg, call_args, 3, NULL, false); + ant_value_t call_args[3] = { val, tov((double)(i - 1)), arr }; + ant_value_t result = sv_vm_call(js->vm, js, callback, this_arg, call_args, 3, NULL, false); if (is_err(result)) return result; if (js_truthy(js, result)) return return_index ? tov((double)(i - 1)) : val; @@ -7482,16 +7482,16 @@ static jsval_t array_find_last_impl(ant_t *js, jsval_t *args, int nargs, bool re return return_index ? tov(-1) : js_mkundef(); } -static jsval_t builtin_array_findLast(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_array_findLast(ant_t *js, ant_value_t *args, int nargs) { return array_find_last_impl(js, args, nargs, false, "findLast"); } -static jsval_t builtin_array_findLastIndex(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_array_findLastIndex(ant_t *js, ant_value_t *args, int nargs) { return array_find_last_impl(js, args, nargs, true, "findLastIndex"); } -static jsval_t builtin_array_flatMap(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_flatMap(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) { return js_mkerr(js, "flatMap called on non-array"); } @@ -7499,24 +7499,24 @@ static jsval_t builtin_array_flatMap(ant_t *js, jsval_t *args, int nargs) { return js_mkerr(js, "flatMap requires a function argument"); } - jsval_t callback = args[0]; - jsval_t this_arg = (nargs >= 2) ? args[1] : js_mkundef(); - jsoff_t len = get_array_length(js, arr); + ant_value_t callback = args[0]; + ant_value_t this_arg = (nargs >= 2) ? args[1] : js_mkundef(); + ant_offset_t len = get_array_length(js, arr); - jsval_t result = mkarr(js); + ant_value_t result = mkarr(js); if (is_err(result)) return result; - jsoff_t result_idx = 0; + ant_offset_t result_idx = 0; - for (jsoff_t i = 0; i < len; i++) { - jsval_t elem = arr_get(js, arr, i); - jsval_t call_args[3] = { elem, tov((double)i), arr }; - jsval_t mapped = sv_vm_call(js->vm, js, callback, this_arg, call_args, 3, NULL, false); + for (ant_offset_t i = 0; i < len; i++) { + ant_value_t elem = arr_get(js, arr, i); + ant_value_t call_args[3] = { elem, tov((double)i), arr }; + ant_value_t mapped = sv_vm_call(js->vm, js, callback, this_arg, call_args, 3, NULL, false); if (is_err(mapped)) return mapped; if (vtype(mapped) == T_ARR || vtype(mapped) == T_OBJ) { - jsoff_t m_len = get_array_length(js, mapped); - for (jsoff_t j = 0; j < m_len; j++) { - jsval_t m_elem = arr_get(js, mapped, j); + ant_offset_t m_len = get_array_length(js, mapped); + for (ant_offset_t j = 0; j < m_len; j++) { + ant_value_t m_elem = arr_get(js, mapped, j); arr_set(js, result, result_idx, m_elem); result_idx++; } @@ -7529,25 +7529,25 @@ static jsval_t builtin_array_flatMap(ant_t *js, jsval_t *args, int nargs) { return mkval(T_ARR, vdata(result)); } -static const char *js_tostring(ant_t *js, jsval_t v) { +static const char *js_tostring(ant_t *js, ant_value_t v) { if (vtype(v) == T_STR) { - jsoff_t slen, off = vstr(js, v, &slen); + ant_offset_t slen, off = vstr(js, v, &slen); return (const char *)&js->mem[off]; } return js_str(js, v); } -static int js_compare_values(ant_t *js, jsval_t a, jsval_t b, jsval_t compareFn) { +static int js_compare_values(ant_t *js, ant_value_t a, ant_value_t b, ant_value_t compareFn) { uint8_t t = vtype(compareFn); if (t == T_FUNC || t == T_CFUNC) { - jsval_t call_args[2] = { a, b }; - jsval_t result = sv_vm_call(js->vm, js, compareFn, js_mkundef(), call_args, 2, NULL, false); + ant_value_t call_args[2] = { a, b }; + ant_value_t result = sv_vm_call(js->vm, js, compareFn, js_mkundef(), call_args, 2, NULL, false); if (vtype(result) == T_NUM) return (int)tod(result); return 0; } if (vtype(a) == T_STR && vtype(b) == T_STR) { - jsoff_t len_a, len_b; + ant_offset_t len_a, len_b; const char *sa = (const char *)&js->mem[vstr(js, a, &len_a)]; const char *sb = (const char *)&js->mem[vstr(js, b, &len_b)]; return strcmp(sa, sb); @@ -7562,41 +7562,41 @@ static int js_compare_values(ant_t *js, jsval_t a, jsval_t b, jsval_t compareFn) return strcmp(copy, js_tostring(js, b)); } -static jsval_t builtin_array_indexOf(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_indexOf(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) { return js_mkerr(js, "indexOf called on non-array"); } if (nargs == 0) return tov(-1); - jsval_t search = args[0]; - jsoff_t len = get_array_length(js, arr); + ant_value_t search = args[0]; + ant_offset_t len = get_array_length(js, arr); - jsoff_t start = 0; + ant_offset_t start = 0; if (nargs >= 2 && vtype(args[1]) == T_NUM) { int s = (int) tod(args[1]); if (s < 0) s = (int)len + s; if (s < 0) s = 0; - start = (jsoff_t) s; + start = (ant_offset_t) s; } - for (jsoff_t i = start; i < len; i++) { - jsval_t elem = arr_get(js, arr, i); + for (ant_offset_t i = start; i < len; i++) { + ant_value_t elem = arr_get(js, arr, i); if (vtype(elem) == T_UNDEF && !arr_has(js, arr, i)) continue; if (strict_eq_values(js, elem, search)) return tov((double)i); } return tov(-1); } -static jsval_t builtin_array_lastIndexOf(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_lastIndexOf(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) { return js_mkerr(js, "lastIndexOf called on non-array"); } if (nargs == 0) return tov(-1); - jsval_t search = args[0]; - jsoff_t len = get_array_length(js, arr); + ant_value_t search = args[0]; + ant_offset_t len = get_array_length(js, arr); int start = (int)len - 1; if (nargs >= 2 && vtype(args[1]) == T_NUM) { @@ -7606,15 +7606,15 @@ static jsval_t builtin_array_lastIndexOf(ant_t *js, jsval_t *args, int nargs) { if (start >= (int)len) start = (int)len - 1; for (int i = start; i >= 0; i--) { - jsval_t elem = arr_get(js, arr, (jsoff_t)i); - if (vtype(elem) == T_UNDEF && !arr_has(js, arr, (jsoff_t)i)) continue; + ant_value_t elem = arr_get(js, arr, (ant_offset_t)i); + if (vtype(elem) == T_UNDEF && !arr_has(js, arr, (ant_offset_t)i)) continue; if (strict_eq_values(js, elem, search)) return tov((double)i); } return tov(-1); } -static jsval_t builtin_array_reduceRight(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_reduceRight(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) { return js_mkerr(js, "reduceRight called on non-array"); } @@ -7622,11 +7622,11 @@ static jsval_t builtin_array_reduceRight(ant_t *js, jsval_t *args, int nargs) { return js_mkerr(js, "reduceRight requires a function argument"); } - jsval_t callback = args[0]; - jsoff_t len = get_array_length(js, arr); + ant_value_t callback = args[0]; + ant_offset_t len = get_array_length(js, arr); int start_idx = (int)len - 1; - jsval_t accumulator; + ant_value_t accumulator; if (nargs >= 2) { accumulator = args[1]; @@ -7637,8 +7637,8 @@ static jsval_t builtin_array_reduceRight(ant_t *js, jsval_t *args, int nargs) { } for (int i = start_idx; i >= 0; i--) { - jsval_t elem = arr_get(js, arr, (jsoff_t)i); - jsval_t call_args[4] = { accumulator, elem, tov((double)i), arr }; + ant_value_t elem = arr_get(js, arr, (ant_offset_t)i); + ant_value_t call_args[4] = { accumulator, elem, tov((double)i), arr }; accumulator = sv_vm_call(js->vm, js, callback, js_mkundef(), call_args, 4, NULL, false); if (is_err(accumulator)) return accumulator; } @@ -7646,37 +7646,37 @@ static jsval_t builtin_array_reduceRight(ant_t *js, jsval_t *args, int nargs) { return accumulator; } -static jsval_t builtin_array_shift(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_array_shift(ant_t *js, ant_value_t *args, int nargs) { (void) args; (void) nargs; - jsval_t arr = js->this_val; + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) { return js_mkerr(js, "shift called on non-array"); } - jsoff_t len = proxy_aware_length(js, arr); + ant_offset_t len = proxy_aware_length(js, arr); if (len == 0) return js_mkundef(); - jsoff_t doff = get_dense_buf(js, arr); + ant_offset_t doff = get_dense_buf(js, arr); if (doff && !is_proxy(js, arr)) { - jsoff_t d_len = dense_length(js, doff); + ant_offset_t d_len = dense_length(js, doff); if (d_len == 0) return js_mkundef(); - jsval_t first = dense_get(js, doff, 0); + ant_value_t first = dense_get(js, doff, 0); if (is_empty_slot(first)) first = js_mkundef(); - memmove(&js->mem[doff + sizeof(jsoff_t) * 2], - &js->mem[doff + sizeof(jsoff_t) * 2 + sizeof(jsval_t)], - sizeof(jsval_t) * (d_len - 1)); + memmove(&js->mem[doff + sizeof(ant_offset_t) * 2], + &js->mem[doff + sizeof(ant_offset_t) * 2 + sizeof(ant_value_t)], + sizeof(ant_value_t) * (d_len - 1)); dense_set(js, doff, d_len - 1, T_EMPTY); dense_set_length(js, doff, d_len - 1); return first; } - jsval_t read_from = is_proxy(js, arr) ? proxy_read_target(js, arr) : arr; - jsval_t first = arr_get(js, read_from, 0); + ant_value_t read_from = is_proxy(js, arr) ? proxy_read_target(js, arr) : arr; + ant_value_t first = arr_get(js, read_from, 0); - for (jsoff_t i = 1; i < len; i++) { + for (ant_offset_t i = 1; i < len; i++) { if (arr_has(js, read_from, i)) { - jsval_t elem = arr_get(js, read_from, i); + ant_value_t elem = arr_get(js, read_from, i); char dst[16]; size_t dstlen = uint_to_str(dst, sizeof(dst), (unsigned)(i - 1)); js_setprop(js, arr, js_mkstr(js, dst, dstlen), elem); @@ -7689,37 +7689,37 @@ static jsval_t builtin_array_shift(ant_t *js, jsval_t *args, int nargs) { return first; } -static jsval_t builtin_array_unshift(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_unshift(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) { return js_mkerr(js, "unshift called on non-array"); } - jsoff_t len = proxy_aware_length(js, arr); + ant_offset_t len = proxy_aware_length(js, arr); - jsoff_t doff = get_dense_buf(js, arr); + ant_offset_t doff = get_dense_buf(js, arr); if (doff && !is_proxy(js, arr)) { - jsoff_t d_len = dense_length(js, doff); - jsoff_t new_len = d_len + nargs; - jsoff_t cap = dense_capacity(js, doff); + ant_offset_t d_len = dense_length(js, doff); + ant_offset_t new_len = d_len + nargs; + ant_offset_t cap = dense_capacity(js, doff); if (new_len > cap) { doff = dense_grow(js, arr, new_len); if (doff == 0) return js_mkerr(js, "oom"); } - memmove(&js->mem[doff + sizeof(jsoff_t) * 2 + sizeof(jsval_t) * nargs], - &js->mem[doff + sizeof(jsoff_t) * 2], - sizeof(jsval_t) * d_len); + memmove(&js->mem[doff + sizeof(ant_offset_t) * 2 + sizeof(ant_value_t) * nargs], + &js->mem[doff + sizeof(ant_offset_t) * 2], + sizeof(ant_value_t) * d_len); for (int i = 0; i < nargs; i++) - dense_set(js, doff, (jsoff_t)i, args[i]); + dense_set(js, doff, (ant_offset_t)i, args[i]); dense_set_length(js, doff, new_len); return tov((double) new_len); } - jsval_t read_from = is_proxy(js, arr) ? proxy_read_target(js, arr) : arr; + ant_value_t read_from = is_proxy(js, arr) ? proxy_read_target(js, arr) : arr; for (int i = (int)len - 1; i >= 0; i--) { - if (arr_has(js, read_from, (jsoff_t)i)) { - jsval_t elem = arr_get(js, read_from, (jsoff_t)i); + if (arr_has(js, read_from, (ant_offset_t)i)) { + ant_value_t elem = arr_get(js, read_from, (ant_offset_t)i); char dst[16]; size_t dstlen = uint_to_str(dst, sizeof(dst), (unsigned)(i + nargs)); js_setprop(js, arr, js_mkstr(js, dst, dstlen), elem); @@ -7729,35 +7729,35 @@ static jsval_t builtin_array_unshift(ant_t *js, jsval_t *args, int nargs) { for (int i = 0; i < nargs; i++) { char idxstr[16]; size_t idxlen = uint_to_str(idxstr, sizeof(idxstr), (unsigned)i); - jsval_t key = js_mkstr(js, idxstr, idxlen); + ant_value_t key = js_mkstr(js, idxstr, idxlen); js_setprop(js, arr, key, args[i]); } - jsoff_t new_len = len + nargs; + ant_offset_t new_len = len + nargs; js_setprop(js, arr, js->length_str, tov((double) new_len)); return tov((double) new_len); } -static jsval_t builtin_array_some(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_some(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) return js_mkerr(js, "some called on non-array"); - jsval_t callback = require_callback(js, args, nargs, "some"); + ant_value_t callback = require_callback(js, args, nargs, "some"); if (is_err(callback)) return callback; - jsval_t this_arg = (nargs >= 2) ? args[1] : js_mkundef(); + ant_value_t this_arg = (nargs >= 2) ? args[1] : js_mkundef(); - jsoff_t len = get_array_length(js, arr); + ant_offset_t len = get_array_length(js, arr); if (len == 0) return mkval(T_BOOL, 0); - for (jsoff_t i = 0; i < len; i++) { + for (ant_offset_t i = 0; i < len; i++) { if (!arr_has(js, arr, i)) continue; - jsval_t val = arr_get(js, arr, i); + ant_value_t val = arr_get(js, arr, i); - jsval_t call_args[3] = { val, tov((double)i), arr }; - jsval_t result = sv_vm_call(js->vm, js, callback, this_arg, call_args, 3, NULL, false); + ant_value_t call_args[3] = { val, tov((double)i), arr }; + ant_value_t result = sv_vm_call(js->vm, js, callback, this_arg, call_args, 3, NULL, false); if (is_err(result)) return result; if (js_truthy(js, result)) return mkval(T_BOOL, 1); @@ -7766,12 +7766,12 @@ static jsval_t builtin_array_some(ant_t *js, jsval_t *args, int nargs) { return mkval(T_BOOL, 0); } -static jsval_t builtin_array_sort(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; - jsval_t compareFn = js_mkundef(); - jsval_t *vals = NULL, *keys = NULL, *temp_vals = NULL, *temp_keys = NULL; - jsoff_t *offs = NULL; - jsoff_t count = 0, undef_count = 0, len = 0; +static ant_value_t builtin_array_sort(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; + ant_value_t compareFn = js_mkundef(); + ant_value_t *vals = NULL, *keys = NULL, *temp_vals = NULL, *temp_keys = NULL; + ant_offset_t *offs = NULL; + ant_offset_t count = 0, undef_count = 0, len = 0; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) return js_mkerr(js, "sort called on non-array"); @@ -7785,24 +7785,24 @@ static jsval_t builtin_array_sort(ant_t *js, jsval_t *args, int nargs) { len = get_array_length(js, arr); if (len == 0) return arr; - jsoff_t doff = get_dense_buf(js, arr); + ant_offset_t doff = get_dense_buf(js, arr); if (doff) { - vals = malloc(len * sizeof(jsval_t)); + vals = malloc(len * sizeof(ant_value_t)); if (!vals) goto oom; - for (jsoff_t i = 0; i < len; i++) { - jsval_t v = dense_get(js, doff, i); + for (ant_offset_t i = 0; i < len; i++) { + ant_value_t v = dense_get(js, doff, i); if (is_empty_slot(v) || vtype(v) == T_UNDEF) undef_count++; else vals[count++] = v; } } else { - vals = malloc(len * sizeof(jsval_t)); - offs = malloc(len * sizeof(jsoff_t)); + vals = malloc(len * sizeof(ant_value_t)); + offs = malloc(len * sizeof(ant_offset_t)); if (!vals || !offs) goto oom; ant_iter_t iter = js_prop_iter_begin(js, arr); const char *key; size_t key_len; - jsval_t val; + ant_value_t val; while (js_prop_iter_next(&iter, &key, &key_len, &val)) { if (key_len == 0 || key[0] > '9' || key[0] < '0') continue; @@ -7826,29 +7826,29 @@ static jsval_t builtin_array_sort(ant_t *js, jsval_t *args, int nargs) { bool use_keys = (vtype(compareFn) == T_UNDEF); if (use_keys) { - keys = malloc(count * sizeof(jsval_t)); + keys = malloc(count * sizeof(ant_value_t)); if (!keys) goto oom; - for (jsoff_t i = 0; i < count; i++) { + for (ant_offset_t i = 0; i < count; i++) { const char *s = js_tostring(js, vals[i]); keys[i] = js_mkstr(js, s, strlen(s)); } } - temp_vals = malloc(count * sizeof(jsval_t)); - if (use_keys) temp_keys = malloc(count * sizeof(jsval_t)); + temp_vals = malloc(count * sizeof(ant_value_t)); + if (use_keys) temp_keys = malloc(count * sizeof(ant_value_t)); if (!temp_vals || (use_keys && !temp_keys)) goto oom; - for (jsoff_t width = 1; width < count; width *= 2) { - for (jsoff_t left = 0; left < count; left += width * 2) { - jsoff_t mid = left + width; - jsoff_t right = (mid + width < count) ? mid + width : count; + for (ant_offset_t width = 1; width < count; width *= 2) { + for (ant_offset_t left = 0; left < count; left += width * 2) { + ant_offset_t mid = left + width; + ant_offset_t right = (mid + width < count) ? mid + width : count; if (mid >= count) break; - jsoff_t i = left, j = mid, k = 0; + ant_offset_t i = left, j = mid, k = 0; while (i < mid && j < right) { int cmp; if (use_keys) { - jsoff_t len_a, len_b; + ant_offset_t len_a, len_b; const char *sa = (const char *)&js->mem[vstr(js, keys[i], &len_a)]; const char *sb = (const char *)&js->mem[vstr(js, keys[j], &len_b)]; cmp = strcmp(sa, sb); @@ -7876,21 +7876,21 @@ static jsval_t builtin_array_sort(ant_t *js, jsval_t *args, int nargs) { k++; j++; } - memcpy(&vals[left], temp_vals, k * sizeof(jsval_t)); - if (use_keys) memcpy(&keys[left], temp_keys, k * sizeof(jsval_t)); + memcpy(&vals[left], temp_vals, k * sizeof(ant_value_t)); + if (use_keys) memcpy(&keys[left], temp_keys, k * sizeof(ant_value_t)); } } writeback: if (doff) { - for (jsoff_t i = 0; i < count; i++) dense_set(js, doff, i, vals[i]); - for (jsoff_t i = count; i < count + undef_count; i++) dense_set(js, doff, i, js_mkundef()); - for (jsoff_t i = count + undef_count; i < len; i++) dense_set(js, doff, i, T_EMPTY); + for (ant_offset_t i = 0; i < count; i++) dense_set(js, doff, i, vals[i]); + for (ant_offset_t i = count; i < count + undef_count; i++) dense_set(js, doff, i, js_mkundef()); + for (ant_offset_t i = count + undef_count; i < len; i++) dense_set(js, doff, i, T_EMPTY); } else { - for (jsoff_t i = 0; i < count; i++) - saveval(js, offs[i] + sizeof(jsoff_t) * 2, vals[i]); - for (jsoff_t i = 0; i < undef_count; i++) - saveval(js, offs[count + i] + sizeof(jsoff_t) * 2, js_mkundef()); + for (ant_offset_t i = 0; i < count; i++) + saveval(js, offs[i] + sizeof(ant_offset_t) * 2, vals[i]); + for (ant_offset_t i = 0; i < undef_count; i++) + saveval(js, offs[count + i] + sizeof(ant_offset_t) * 2, js_mkundef()); } free(temp_keys); @@ -7909,14 +7909,14 @@ oom: return js_mkerr(js, "out of memory"); } -static jsval_t builtin_array_splice(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_splice(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) { return js_mkerr(js, "splice called on non-array"); } - jsoff_t len = proxy_aware_length(js, arr); - jsval_t read_from = is_proxy(js, arr) ? proxy_read_target(js, arr) : arr; + ant_offset_t len = proxy_aware_length(js, arr); + ant_value_t read_from = is_proxy(js, arr) ? proxy_read_target(js, arr) : arr; int start = 0; if (nargs >= 1 && vtype(args[0]) == T_NUM) { @@ -7935,40 +7935,40 @@ static jsval_t builtin_array_splice(ant_t *js, jsval_t *args, int nargs) { int insertCount = nargs > 2 ? nargs - 2 : 0; - jsval_t removed = array_alloc_like(js, arr); + ant_value_t removed = array_alloc_like(js, arr); if (is_err(removed)) return removed; - jsoff_t doff = get_dense_buf(js, arr); + ant_offset_t doff = get_dense_buf(js, arr); if (doff && !is_proxy(js, arr)) { for (int i = 0; i < deleteCount; i++) { - jsval_t elem = arr_get(js, arr, (jsoff_t)(start + i)); - arr_set(js, removed, (jsoff_t)i, elem); + ant_value_t elem = arr_get(js, arr, (ant_offset_t)(start + i)); + arr_set(js, removed, (ant_offset_t)i, elem); } - jsoff_t d_len = dense_length(js, doff); + ant_offset_t d_len = dense_length(js, doff); int shift = insertCount - deleteCount; - jsoff_t new_len = (jsoff_t)((int)d_len + shift); + ant_offset_t new_len = (ant_offset_t)((int)d_len + shift); if (shift != 0) { if (new_len > dense_capacity(js, doff)) { doff = dense_grow(js, arr, new_len); if (doff == 0) return js_mkerr(js, "oom"); } - jsoff_t move_start = (jsoff_t)(start + deleteCount); - jsoff_t move_dest = (jsoff_t)(start + insertCount); - jsoff_t move_count = d_len - move_start; + ant_offset_t move_start = (ant_offset_t)(start + deleteCount); + ant_offset_t move_dest = (ant_offset_t)(start + insertCount); + ant_offset_t move_count = d_len - move_start; if (move_count > 0) memmove( - &js->mem[doff + sizeof(jsoff_t) * 2 + sizeof(jsval_t) * move_dest], - &js->mem[doff + sizeof(jsoff_t) * 2 + sizeof(jsval_t) * move_start], - sizeof(jsval_t) * move_count + &js->mem[doff + sizeof(ant_offset_t) * 2 + sizeof(ant_value_t) * move_dest], + &js->mem[doff + sizeof(ant_offset_t) * 2 + sizeof(ant_value_t) * move_start], + sizeof(ant_value_t) * move_count ); } for (int i = 0; i < insertCount; i++) - dense_set(js, doff, (jsoff_t)(start + i), args[2 + i]); + dense_set(js, doff, (ant_offset_t)(start + i), args[2 + i]); if (shift < 0) { - for (jsoff_t i = new_len; i < d_len; i++) + for (ant_offset_t i = new_len; i < d_len; i++) dense_set(js, doff, i, T_EMPTY); } @@ -7981,10 +7981,10 @@ static jsval_t builtin_array_splice(ant_t *js, jsval_t *args, int nargs) { char src[16], dst[16]; snprintf(src, sizeof(src), "%u", (unsigned)(start + i)); snprintf(dst, sizeof(dst), "%u", (unsigned) i); - jsoff_t elem_off = lkp(js, read_from, src, strlen(src)); + ant_offset_t elem_off = lkp(js, read_from, src, strlen(src)); if (elem_off != 0) { - jsval_t elem = resolveprop(js, mkval(T_PROP, elem_off)); - jsval_t key = js_mkstr(js, dst, strlen(dst)); + ant_value_t elem = resolveprop(js, mkval(T_PROP, elem_off)); + ant_value_t key = js_mkstr(js, dst, strlen(dst)); js_setprop(js, removed, key, elem); } } @@ -7997,9 +7997,9 @@ static jsval_t builtin_array_splice(ant_t *js, jsval_t *args, int nargs) { char src[16], dst[16]; snprintf(src, sizeof(src), "%u", (unsigned) i); snprintf(dst, sizeof(dst), "%u", (unsigned)(i + shift)); - jsoff_t elem_off = lkp(js, read_from, src, strlen(src)); - jsval_t elem = elem_off ? resolveprop(js, mkval(T_PROP, elem_off)) : js_mkundef(); - jsval_t key = js_mkstr(js, dst, strlen(dst)); + ant_offset_t elem_off = lkp(js, read_from, src, strlen(src)); + ant_value_t elem = elem_off ? resolveprop(js, mkval(T_PROP, elem_off)) : js_mkundef(); + ant_value_t key = js_mkstr(js, dst, strlen(dst)); js_setprop(js, arr, key, elem); } } else if (shift < 0) { @@ -8007,9 +8007,9 @@ static jsval_t builtin_array_splice(ant_t *js, jsval_t *args, int nargs) { char src[16], dst[16]; snprintf(src, sizeof(src), "%u", (unsigned) i); snprintf(dst, sizeof(dst), "%u", (unsigned)(i + shift)); - jsoff_t elem_off = lkp(js, read_from, src, strlen(src)); - jsval_t elem = elem_off ? resolveprop(js, mkval(T_PROP, elem_off)) : js_mkundef(); - jsval_t key = js_mkstr(js, dst, strlen(dst)); + ant_offset_t elem_off = lkp(js, read_from, src, strlen(src)); + ant_value_t elem = elem_off ? resolveprop(js, mkval(T_PROP, elem_off)) : js_mkundef(); + ant_value_t key = js_mkstr(js, dst, strlen(dst)); js_setprop(js, arr, key, elem); } } @@ -8017,7 +8017,7 @@ static jsval_t builtin_array_splice(ant_t *js, jsval_t *args, int nargs) { for (int i = 0; i < insertCount; i++) { char idxstr[16]; size_t idxlen = uint_to_str(idxstr, sizeof(idxstr), (unsigned)(start + i)); - jsval_t key = js_mkstr(js, idxstr, idxlen); + ant_value_t key = js_mkstr(js, idxstr, idxlen); js_setprop(js, arr, key, args[2 + i]); } @@ -8027,14 +8027,14 @@ static jsval_t builtin_array_splice(ant_t *js, jsval_t *args, int nargs) { return removed; } -static jsval_t builtin_array_copyWithin(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_copyWithin(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) { return js_mkerr(js, "copyWithin called on non-array"); } - jsoff_t len = proxy_aware_length(js, arr); - jsval_t read_from = is_proxy(js, arr) ? proxy_read_target(js, arr) : arr; + ant_offset_t len = proxy_aware_length(js, arr); + ant_value_t read_from = is_proxy(js, arr) ? proxy_read_target(js, arr) : arr; int target = 0, start = 0, end = (int)len; if (nargs >= 1 && vtype(args[0]) == T_NUM) { @@ -8058,34 +8058,34 @@ static jsval_t builtin_array_copyWithin(ant_t *js, jsval_t *args, int nargs) { if (count > (int)len - target) count = (int)len - target; if (count <= 0) return arr; - jsoff_t doff = get_dense_buf(js, arr); + ant_offset_t doff = get_dense_buf(js, arr); if (doff && !is_proxy(js, arr)) { if (start < target) { for (int i = count - 1; i >= 0; i--) { - jsval_t v = dense_get(js, doff, (jsoff_t)(start + i)); - dense_set(js, doff, (jsoff_t)(target + i), is_empty_slot(v) ? js_mkundef() : v); + ant_value_t v = dense_get(js, doff, (ant_offset_t)(start + i)); + dense_set(js, doff, (ant_offset_t)(target + i), is_empty_slot(v) ? js_mkundef() : v); } } else { for (int i = 0; i < count; i++) { - jsval_t v = dense_get(js, doff, (jsoff_t)(start + i)); - dense_set(js, doff, (jsoff_t)(target + i), is_empty_slot(v) ? js_mkundef() : v); + ant_value_t v = dense_get(js, doff, (ant_offset_t)(start + i)); + dense_set(js, doff, (ant_offset_t)(target + i), is_empty_slot(v) ? js_mkundef() : v); } } return arr; } - jsval_t *temp = (jsval_t *)malloc(count * sizeof(jsval_t)); + ant_value_t *temp = (ant_value_t *)malloc(count * sizeof(ant_value_t)); for (int i = 0; i < count; i++) { char idxstr[16]; size_t idxlen = uint_to_str(idxstr, sizeof(idxstr), (unsigned)(start + i)); - jsoff_t elem_off = lkp(js, read_from, idxstr, idxlen); + ant_offset_t elem_off = lkp(js, read_from, idxstr, idxlen); temp[i] = elem_off ? resolveprop(js, mkval(T_PROP, elem_off)) : js_mkundef(); } for (int i = 0; i < count; i++) { char idxstr[16]; size_t idxlen = uint_to_str(idxstr, sizeof(idxstr), (unsigned)(target + i)); - jsval_t key = js_mkstr(js, idxstr, idxlen); + ant_value_t key = js_mkstr(js, idxstr, idxlen); js_setprop(js, arr, key, temp[i]); } @@ -8093,50 +8093,50 @@ static jsval_t builtin_array_copyWithin(ant_t *js, jsval_t *args, int nargs) { return arr; } -static jsval_t builtin_array_toSorted(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_toSorted(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) return js_mkerr(js, "toSorted called on non-array"); - jsval_t result = array_shallow_copy(js, arr, get_array_length(js, arr)); + ant_value_t result = array_shallow_copy(js, arr, get_array_length(js, arr)); if (is_err(result)) return result; - jsval_t saved_this = js->this_val; + ant_value_t saved_this = js->this_val; js->this_val = result; - jsval_t sorted = builtin_array_sort(js, args, nargs); + ant_value_t sorted = builtin_array_sort(js, args, nargs); js->this_val = saved_this; if (is_err(sorted)) return sorted; return mkval(T_ARR, vdata(result)); } -static jsval_t builtin_array_toReversed(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_array_toReversed(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t arr = js->this_val; + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) return js_mkerr(js, "toReversed called on non-array"); - jsval_t result = array_shallow_copy(js, arr, get_array_length(js, arr)); + ant_value_t result = array_shallow_copy(js, arr, get_array_length(js, arr)); if (is_err(result)) return result; - jsval_t saved_this = js->this_val; + ant_value_t saved_this = js->this_val; js->this_val = result; - jsval_t reversed = builtin_array_reverse(js, NULL, 0); + ant_value_t reversed = builtin_array_reverse(js, NULL, 0); js->this_val = saved_this; if (is_err(reversed)) return reversed; return mkval(T_ARR, vdata(result)); } -static jsval_t builtin_array_toSpliced(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_toSpliced(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) return js_mkerr(js, "toSpliced called on non-array"); - jsval_t result = array_shallow_copy(js, arr, get_array_length(js, arr)); + ant_value_t result = array_shallow_copy(js, arr, get_array_length(js, arr)); if (is_err(result)) return result; - jsval_t saved_this = js->this_val; + ant_value_t saved_this = js->this_val; js->this_val = result; builtin_array_splice(js, args, nargs); js->this_val = saved_this; @@ -8144,89 +8144,89 @@ static jsval_t builtin_array_toSpliced(ant_t *js, jsval_t *args, int nargs) { return mkval(T_ARR, vdata(result)); } -static jsval_t builtin_array_with(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_with(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) { return js_mkerr(js, "with called on non-array"); } if (nargs < 2) return js_mkerr(js, "with requires index and value arguments"); - jsoff_t len = get_array_length(js, arr); + ant_offset_t len = get_array_length(js, arr); int idx = (int) tod(args[0]); if (idx < 0) idx = (int)len + idx; - if (idx < 0 || (jsoff_t)idx >= len) return js_mkerr(js, "Invalid index"); + if (idx < 0 || (ant_offset_t)idx >= len) return js_mkerr(js, "Invalid index"); - jsval_t result = mkarr(js); + ant_value_t result = mkarr(js); if (is_err(result)) return result; - for (jsoff_t i = 0; i < len; i++) { - jsval_t elem = ((jsoff_t)idx == i) ? args[1] : arr_get(js, arr, i); + for (ant_offset_t i = 0; i < len; i++) { + ant_value_t elem = ((ant_offset_t)idx == i) ? args[1] : arr_get(js, arr, i); arr_set(js, result, i, elem); } return mkval(T_ARR, vdata(result)); } -static jsval_t builtin_array_keys(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_array_keys(ant_t *js, ant_value_t *args, int nargs) { (void) args; (void) nargs; - jsval_t arr = js->this_val; + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) { return js_mkerr(js, "keys called on non-array"); } - jsoff_t len = get_array_length(js, arr); + ant_offset_t len = get_array_length(js, arr); - jsval_t result = mkarr(js); + ant_value_t result = mkarr(js); if (is_err(result)) return result; - for (jsoff_t i = 0; i < len; i++) { + for (ant_offset_t i = 0; i < len; i++) { arr_set(js, result, i, tov((double) i)); } return mkval(T_ARR, vdata(result)); } -static jsval_t builtin_array_values(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_array_values(ant_t *js, ant_value_t *args, int nargs) { (void) args; (void) nargs; - jsval_t arr = js->this_val; + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) { return js_mkerr(js, "values called on non-array"); } - jsoff_t len = get_array_length(js, arr); + ant_offset_t len = get_array_length(js, arr); - jsval_t result = mkarr(js); + ant_value_t result = mkarr(js); if (is_err(result)) return result; - for (jsoff_t i = 0; i < len; i++) { + for (ant_offset_t i = 0; i < len; i++) { arr_set(js, result, i, arr_get(js, arr, i)); } return mkval(T_ARR, vdata(result)); } -static jsval_t builtin_array_entries(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_array_entries(ant_t *js, ant_value_t *args, int nargs) { (void) args; (void) nargs; - jsval_t arr = js->this_val; + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR && vtype(arr) != T_OBJ) { return js_mkerr(js, "entries called on non-array"); } - jsoff_t len = get_array_length(js, arr); + ant_offset_t len = get_array_length(js, arr); - jsval_t result = mkarr(js); + ant_value_t result = mkarr(js); if (is_err(result)) return result; - for (jsoff_t i = 0; i < len; i++) { - jsval_t entry = mkarr(js); + for (ant_offset_t i = 0; i < len; i++) { + ant_value_t entry = mkarr(js); if (is_err(entry)) return entry; - jsval_t elem = arr_get(js, arr, i); + ant_value_t elem = arr_get(js, arr, i); arr_set(js, entry, 0, tov((double) i)); arr_set(js, entry, 1, elem); @@ -8237,10 +8237,10 @@ static jsval_t builtin_array_entries(ant_t *js, jsval_t *args, int nargs) { return mkval(T_ARR, vdata(result)); } -static jsval_t builtin_array_toString(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js->this_val; +static ant_value_t builtin_array_toString(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js->this_val; - jsval_t join_result; + ant_value_t join_result; if (js_try_call_method(js, arr, "join", 4, NULL, 0, &join_result)) { if (is_err(join_result)) return join_result; return join_result; @@ -8249,13 +8249,13 @@ static jsval_t builtin_array_toString(ant_t *js, jsval_t *args, int nargs) { return builtin_object_toString(js, args, nargs); } -static jsval_t builtin_array_toLocaleString(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_array_toLocaleString(ant_t *js, ant_value_t *args, int nargs) { (void) args; (void) nargs; - jsval_t arr = js->this_val; + ant_value_t arr = js->this_val; if (vtype(arr) != T_ARR) return js_mkerr(js, "toLocaleString called on non-array"); - jsoff_t len = get_array_length(js, arr); + ant_offset_t len = get_array_length(js, arr); if (len == 0) return js_mkstr(js, "", 0); char *result = NULL; @@ -8263,7 +8263,7 @@ static jsval_t builtin_array_toLocaleString(ant_t *js, jsval_t *args, int nargs) result = (char *)ant_calloc(result_cap); if (!result) return js_mkerr(js, "oom"); - for (jsoff_t i = 0; i < len; i++) { + for (ant_offset_t i = 0; i < len; i++) { if (i > 0) { if (result_len + 1 >= result_cap) { result_cap *= 2; @@ -8277,7 +8277,7 @@ static jsval_t builtin_array_toLocaleString(ant_t *js, jsval_t *args, int nargs) } if (!arr_has(js, arr, i)) continue; - jsval_t elem = arr_get(js, arr, i); + ant_value_t elem = arr_get(js, arr, i); if (vtype(elem) == T_NULL || vtype(elem) == T_UNDEF) continue; char buf[64]; @@ -8295,31 +8295,31 @@ static jsval_t builtin_array_toLocaleString(ant_t *js, jsval_t *args, int nargs) result_len += elem_len; } - jsval_t ret = js_mkstr(js, result, result_len); + ant_value_t ret = js_mkstr(js, result, result_len); free(result); return ret; } -static jsval_t builtin_Array_isArray(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Array_isArray(ant_t *js, ant_value_t *args, int nargs) { (void) js; if (nargs == 0) return mkval(T_BOOL, 0); return mkval(T_BOOL, vtype(args[0]) == T_ARR ? 1 : 0); } typedef struct { - jsval_t write_target; - jsval_t result; - jsval_t mapFn; - jsval_t mapThis; - jsoff_t index; + ant_value_t write_target; + ant_value_t result; + ant_value_t mapFn; + ant_value_t mapThis; + ant_offset_t index; } array_from_iter_ctx_t; -static iter_action_t array_from_iter_cb(ant_t *js, jsval_t value, void *ctx, jsval_t *out) { +static iter_action_t array_from_iter_cb(ant_t *js, ant_value_t value, void *ctx, ant_value_t *out) { array_from_iter_ctx_t *fctx = (array_from_iter_ctx_t *)ctx; - jsval_t elem = value; + ant_value_t elem = value; if (is_callable(fctx->mapFn)) { - jsval_t call_args[2] = { elem, tov((double)fctx->index) }; + ant_value_t call_args[2] = { elem, tov((double)fctx->index) }; elem = sv_vm_call(js->vm, js, fctx->mapFn, fctx->mapThis, call_args, 2, NULL, false); if (is_err(elem)) { *out = elem; return ITER_ERROR; } } @@ -8334,33 +8334,33 @@ static iter_action_t array_from_iter_cb(ant_t *js, jsval_t value, void *ctx, jsv return ITER_CONTINUE; } -static jsval_t builtin_Array_from(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Array_from(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return mkarr(js); - jsval_t src = args[0]; - jsval_t mapFn = (nargs >= 2 && is_callable(args[1])) ? args[1] : js_mkundef(); - jsval_t mapThis = (nargs >= 3) ? args[2] : js_mkundef(); + ant_value_t src = args[0]; + ant_value_t mapFn = (nargs >= 2 && is_callable(args[1])) ? args[1] : js_mkundef(); + ant_value_t mapThis = (nargs >= 3) ? args[2] : js_mkundef(); - jsval_t ctor = js->this_val; + ant_value_t ctor = js->this_val; bool use_ctor = (vtype(ctor) == T_FUNC || vtype(ctor) == T_CFUNC); - jsval_t result = use_ctor ? array_alloc_from_ctor_with_length(js, ctor, 0) : mkarr(js); + ant_value_t result = use_ctor ? array_alloc_from_ctor_with_length(js, ctor, 0) : mkarr(js); if (is_err(result)) return result; bool result_is_proxy = is_proxy(js, result); - jsval_t write_target = result_is_proxy ? proxy_read_target(js, result) : result; - jsval_t iter_sym = get_iterator_sym(); + ant_value_t write_target = result_is_proxy ? proxy_read_target(js, result) : result; + ant_value_t iter_sym = get_iterator_sym(); if (vtype(src) == T_STR) { if (is_rope(js, src)) { src = rope_flatten(js, src); if (is_err(src)) return src; } - jsoff_t slen = str_len_fast(js, src); + ant_offset_t slen = str_len_fast(js, src); array_from_iter_ctx_t ctx = { write_target, result, mapFn, mapThis, 0 }; - for (jsoff_t i = 0; i < slen; ) { - jsoff_t off = vstr(js, src, NULL); + for (ant_offset_t i = 0; i < slen; ) { + ant_offset_t off = vstr(js, src, NULL); utf8proc_int32_t cp; - jsoff_t cb_len = (jsoff_t)utf8_next((const utf8proc_uint8_t *)&js->mem[off + i], (utf8proc_ssize_t)(slen - i), &cp); - jsval_t ch = js_mkstr(js, (char *)&js->mem[off + i], cb_len); + ant_offset_t cb_len = (ant_offset_t)utf8_next((const utf8proc_uint8_t *)&js->mem[off + i], (utf8proc_ssize_t)(slen - i), &cp); + ant_value_t ch = js_mkstr(js, (char *)&js->mem[off + i], cb_len); - jsval_t out; + ant_value_t out; iter_action_t act = array_from_iter_cb(js, ch, &ctx, &out); if (act == ITER_ERROR) return out; @@ -8368,37 +8368,37 @@ static jsval_t builtin_Array_from(ant_t *js, jsval_t *args, int nargs) { } if (vtype(result) != T_ARR) js_setprop(js, result, js->length_str, tov((double)ctx.index)); } else if (vtype(src) == T_ARR) { - jsoff_t iter_off = (vtype(iter_sym) == T_SYMBOL) ? lkp_sym_proto(js, src, (jsoff_t)vdata(iter_sym)) : 0; - bool default_iter = iter_off != 0 && vtype(loadval(js, iter_off + sizeof(jsoff_t) * 2)) == T_CFUNC; + ant_offset_t iter_off = (vtype(iter_sym) == T_SYMBOL) ? lkp_sym_proto(js, src, (ant_offset_t)vdata(iter_sym)) : 0; + bool default_iter = iter_off != 0 && vtype(loadval(js, iter_off + sizeof(ant_offset_t) * 2)) == T_CFUNC; if (default_iter) { array_from_iter_ctx_t ctx = { write_target, result, mapFn, mapThis, 0 }; - jsoff_t len = get_array_length(js, src); - for (jsoff_t i = 0; i < len; i++) { - jsval_t unused; + ant_offset_t len = get_array_length(js, src); + for (ant_offset_t i = 0; i < len; i++) { + ant_value_t unused; iter_action_t act = array_from_iter_cb(js, arr_get(js, src, i), &ctx, &unused); if (act == ITER_ERROR) return unused; } if (vtype(result) != T_ARR) js_setprop(js, result, js->length_str, tov((double)len)); } else { array_from_iter_ctx_t ctx = { write_target, result, mapFn, mapThis, 0 }; - jsval_t iter_result = iter_foreach(js, src, array_from_iter_cb, &ctx); + ant_value_t iter_result = iter_foreach(js, src, array_from_iter_cb, &ctx); if (is_err(iter_result)) return iter_result; if (vtype(result) != T_ARR) js_setprop(js, result, js->length_str, tov((double)ctx.index)); } } else { - jsoff_t iter_prop = (vtype(iter_sym) == T_SYMBOL) ? lkp_sym_proto(js, src, (jsoff_t)vdata(iter_sym)) : 0; + ant_offset_t iter_prop = (vtype(iter_sym) == T_SYMBOL) ? lkp_sym_proto(js, src, (ant_offset_t)vdata(iter_sym)) : 0; if (iter_prop != 0) { array_from_iter_ctx_t ctx = { write_target, result, mapFn, mapThis, 0 }; - jsval_t iter_result = iter_foreach(js, src, array_from_iter_cb, &ctx); + ant_value_t iter_result = iter_foreach(js, src, array_from_iter_cb, &ctx); if (is_err(iter_result)) return iter_result; if (vtype(result) != T_ARR) js_setprop(js, result, js->length_str, tov((double)ctx.index)); } else if (vtype(src) == T_OBJ) { array_from_iter_ctx_t ctx = { write_target, result, mapFn, mapThis, 0 }; - jsoff_t len = get_array_length(js, src); - for (jsoff_t i = 0; i < len; i++) { - jsval_t unused; + ant_offset_t len = get_array_length(js, src); + for (ant_offset_t i = 0; i < len; i++) { + ant_value_t unused; iter_action_t act = array_from_iter_cb(js, arr_get(js, src, i), &ctx, &unused); if (act == ITER_ERROR) return unused; } @@ -8410,17 +8410,17 @@ static jsval_t builtin_Array_from(ant_t *js, jsval_t *args, int nargs) { return result; } -static jsval_t builtin_Array_of(ant_t *js, jsval_t *args, int nargs) { - jsval_t ctor = js->this_val; +static ant_value_t builtin_Array_of(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t ctor = js->this_val; bool use_ctor = (vtype(ctor) == T_FUNC || vtype(ctor) == T_CFUNC); - jsval_t arr = use_ctor ? array_alloc_from_ctor_with_length(js, ctor, (jsoff_t)nargs) : mkarr(js); + ant_value_t arr = use_ctor ? array_alloc_from_ctor_with_length(js, ctor, (ant_offset_t)nargs) : mkarr(js); if (is_err(arr)) return arr; bool arr_is_proxy = is_proxy(js, arr); - jsval_t write_target = arr_is_proxy ? proxy_read_target(js, arr) : arr; + ant_value_t write_target = arr_is_proxy ? proxy_read_target(js, arr) : arr; for (int i = 0; i < nargs; i++) { - if (vtype(write_target) == T_ARR) arr_set(js, write_target, (jsoff_t)i, args[i]); + if (vtype(write_target) == T_ARR) arr_set(js, write_target, (ant_offset_t)i, args[i]); else { char idxstr[16]; size_t idxlen = uint_to_str(idxstr, sizeof(idxstr), (unsigned)i); js_setprop(js, write_target, js_mkstr(js, idxstr, idxlen), args[i]); @@ -8433,24 +8433,24 @@ static jsval_t builtin_Array_of(ant_t *js, jsval_t *args, int nargs) { return arr; } -static jsval_t builtin_string_indexOf(ant_t *js, jsval_t *args, int nargs) { - jsval_t str = to_string_val(js, js->this_val); +static ant_value_t builtin_string_indexOf(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t str = to_string_val(js, js->this_val); if (vtype(str) != T_STR) return js_mkerr(js, "indexOf called on non-string"); if (nargs == 0) return tov(-1); - jsval_t search = args[0]; + ant_value_t search = args[0]; if (vtype(search) != T_STR) return tov(-1); - jsoff_t str_len, str_off = vstr(js, str, &str_len); - jsoff_t search_len, search_off = vstr(js, search, &search_len); + ant_offset_t str_len, str_off = vstr(js, str, &str_len); + ant_offset_t search_len, search_off = vstr(js, search, &search_len); - jsoff_t start = 0; + ant_offset_t start = 0; double dstr_len = D(str_len); if (nargs >= 2 && vtype(args[1]) == T_NUM) { double pos = tod(args[1]); if (pos < 0) pos = 0; if (pos > dstr_len) pos = dstr_len; - start = (jsoff_t) pos; + start = (ant_offset_t) pos; } if (search_len == 0) return tov(D(start)); @@ -8459,33 +8459,33 @@ static jsval_t builtin_string_indexOf(ant_t *js, jsval_t *args, int nargs) { const char *str_ptr = (char *) &js->mem[str_off]; const char *search_ptr = (char *) &js->mem[search_off]; - for (jsoff_t i = start; i <= str_len - search_len; i++) { + for (ant_offset_t i = start; i <= str_len - search_len; i++) { if (memcmp(str_ptr + i, search_ptr, search_len) == 0) return tov(D(i)); } return tov(-1); } -static jsval_t builtin_string_substring(ant_t *js, jsval_t *args, int nargs) { - jsval_t str = to_string_val(js, js->this_val); +static ant_value_t builtin_string_substring(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t str = to_string_val(js, js->this_val); if (vtype(str) != T_STR) return js_mkerr(js, "substring called on non-string"); - jsoff_t byte_len, str_off = vstr(js, str, &byte_len); + ant_offset_t byte_len, str_off = vstr(js, str, &byte_len); const char *str_ptr = (char *) &js->mem[str_off]; size_t utf16_len = utf16_strlen(str_ptr, byte_len); - jsoff_t start = 0, end = (jsoff_t)utf16_len; + ant_offset_t start = 0, end = (ant_offset_t)utf16_len; double dstr_len2 = D(utf16_len); if (nargs >= 1 && vtype(args[0]) == T_NUM) { double d = tod(args[0]); - start = (jsoff_t) (d < 0 ? 0 : (d > dstr_len2 ? dstr_len2 : d)); + start = (ant_offset_t) (d < 0 ? 0 : (d > dstr_len2 ? dstr_len2 : d)); } if (nargs >= 2 && vtype(args[1]) == T_NUM) { double d = tod(args[1]); - end = (jsoff_t) (d < 0 ? 0 : (d > dstr_len2 ? dstr_len2 : d)); + end = (ant_offset_t) (d < 0 ? 0 : (d > dstr_len2 ? dstr_len2 : d)); } if (start > end) { - jsoff_t tmp = start; + ant_offset_t tmp = start; start = end; end = tmp; } @@ -8495,43 +8495,43 @@ static jsval_t builtin_string_substring(ant_t *js, jsval_t *args, int nargs) { return js_mkstr(js, str_ptr + byte_start, byte_end - byte_start); } -static jsval_t builtin_string_substr(ant_t *js, jsval_t *args, int nargs) { - jsval_t str = to_string_val(js, js->this_val); +static ant_value_t builtin_string_substr(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t str = to_string_val(js, js->this_val); if (vtype(str) != T_STR) return js_mkerr(js, "substr called on non-string"); - jsoff_t byte_len, str_off = vstr(js, str, &byte_len); + ant_offset_t byte_len, str_off = vstr(js, str, &byte_len); const char *str_ptr = (char *) &js->mem[str_off]; size_t utf16_len = utf16_strlen(str_ptr, byte_len); if (nargs < 1) return js_mkstr(js, str_ptr, byte_len); double d_start = tod(args[0]); - jsoff_t start; + ant_offset_t start; if (d_start < 0) { - start = (jsoff_t)((double)utf16_len + d_start); + start = (ant_offset_t)((double)utf16_len + d_start); if ((int)start < 0) start = 0; } else { - start = (jsoff_t)d_start; + start = (ant_offset_t)d_start; } - if (start > (jsoff_t)utf16_len) start = (jsoff_t)utf16_len; + if (start > (ant_offset_t)utf16_len) start = (ant_offset_t)utf16_len; - jsoff_t len = (jsoff_t)utf16_len - start; + ant_offset_t len = (ant_offset_t)utf16_len - start; if (nargs >= 2 && vtype(args[1]) == T_NUM) { double d = tod(args[1]); if (d < 0) d = 0; - len = (jsoff_t)d; + len = (ant_offset_t)d; } - if (start + len > (jsoff_t)utf16_len) len = (jsoff_t)utf16_len - start; + if (start + len > (ant_offset_t)utf16_len) len = (ant_offset_t)utf16_len - start; size_t byte_start, byte_end; utf16_range_to_byte_range(str_ptr, byte_len, start, start + len, &byte_start, &byte_end); return js_mkstr(js, str_ptr + byte_start, byte_end - byte_start); } -static jsval_t string_split_impl(ant_t *js, jsval_t str, jsval_t *args, int nargs) { +static ant_value_t string_split_impl(ant_t *js, ant_value_t str, ant_value_t *args, int nargs) { if (vtype(str) != T_STR) return js_mkerr(js, "split called on non-string"); - jsoff_t str_len, str_off = vstr(js, str, &str_len); + ant_offset_t str_len, str_off = vstr(js, str, &str_len); const char *str_ptr = (char *) &js->mem[str_off]; - jsval_t arr = mkarr(js); + ant_value_t arr = mkarr(js); if (is_err(arr)) return arr; @@ -8547,20 +8547,20 @@ static jsval_t string_split_impl(ant_t *js, jsval_t str, jsval_t *args, int narg } if (nargs == 0) goto return_whole; - jsval_t sep_arg = args[0]; + ant_value_t sep_arg = args[0]; if (vtype(sep_arg) == T_OBJ) { - jsoff_t source_off = lkp(js, sep_arg, "source", 6); + ant_offset_t source_off = lkp(js, sep_arg, "source", 6); if (source_off == 0) goto return_whole; - jsval_t source_val = resolveprop(js, mkval(T_PROP, source_off)); + ant_value_t source_val = resolveprop(js, mkval(T_PROP, source_off)); if (vtype(source_val) != T_STR) goto return_whole; - jsoff_t plen, poff = vstr(js, source_val, &plen); + ant_offset_t plen, poff = vstr(js, source_val, &plen); const char *pattern_ptr = (char *) &js->mem[poff]; if (plen == 0 || (plen == 4 && memcmp(pattern_ptr, "(?:)", 4) == 0)) { - jsoff_t idx = 0; - for (jsoff_t i = 0; i < str_len && idx < limit; i++) { - jsval_t part = js_mkstr(js, str_ptr + i, 1); + ant_offset_t idx = 0; + for (ant_offset_t i = 0; i < str_len && idx < limit; i++) { + ant_value_t part = js_mkstr(js, str_ptr + i, 1); arr_set(js, arr, idx, part); idx++; } @@ -8589,7 +8589,7 @@ static jsval_t string_split_impl(ant_t *js, jsval_t str, jsval_t *args, int narg } } - jsoff_t idx = 0; + ant_offset_t idx = 0; PCRE2_SIZE search_pos = 0; PCRE2_SIZE segment_start = 0; PCRE2_SIZE last_match_end = (PCRE2_SIZE)-1; @@ -8626,7 +8626,7 @@ static jsval_t string_split_impl(ant_t *js, jsval_t str, jsval_t *args, int narg had_any_split = true; - jsval_t part = js_mkstr(js, str_ptr + segment_start, match_start - segment_start); + ant_value_t part = js_mkstr(js, str_ptr + segment_start, match_start - segment_start); arr_set(js, arr, idx, part); idx++; @@ -8659,7 +8659,7 @@ static jsval_t string_split_impl(ant_t *js, jsval_t str, jsval_t *args, int narg } if (idx < limit) { - jsval_t part = js_mkstr(js, str_ptr + segment_start, str_len - segment_start); + ant_value_t part = js_mkstr(js, str_ptr + segment_start, str_len - segment_start); arr_set(js, arr, idx, part); idx++; } @@ -8671,29 +8671,29 @@ static jsval_t string_split_impl(ant_t *js, jsval_t str, jsval_t *args, int narg if (vtype(sep_arg) != T_STR) goto return_whole; - jsoff_t sep_len, sep_off = vstr(js, sep_arg, &sep_len); + ant_offset_t sep_len, sep_off = vstr(js, sep_arg, &sep_len); const char *sep_ptr = (char *) &js->mem[sep_off]; - jsoff_t idx = 0, start = 0; + ant_offset_t idx = 0, start = 0; if (sep_len == 0) { - for (jsoff_t i = 0; i < str_len && idx < limit; i++) { - jsval_t part = js_mkstr(js, str_ptr + i, 1); + for (ant_offset_t i = 0; i < str_len && idx < limit; i++) { + ant_value_t part = js_mkstr(js, str_ptr + i, 1); arr_set(js, arr, idx, part); idx++; } return mkval(T_ARR, vdata(arr)); } - for (jsoff_t i = 0; i + sep_len <= str_len && idx < limit; i++) { + for (ant_offset_t i = 0; i + sep_len <= str_len && idx < limit; i++) { if (memcmp(str_ptr + i, sep_ptr, sep_len) != 0) continue; - jsval_t part = js_mkstr(js, str_ptr + start, i - start); + ant_value_t part = js_mkstr(js, str_ptr + start, i - start); arr_set(js, arr, idx, part); idx++; start = i + sep_len; i += sep_len - 1; } if (idx < limit && start <= str_len) { - jsval_t part = js_mkstr(js, str_ptr + start, str_len - start); + ant_value_t part = js_mkstr(js, str_ptr + start, str_len - start); arr_set(js, arr, idx, part); idx++; } @@ -8707,20 +8707,20 @@ return_whole: return mkval(T_ARR, vdata(arr)); } -static jsval_t builtin_string_split(ant_t *js, jsval_t *args, int nargs) { - jsval_t str = to_string_val(js, js->this_val); +static ant_value_t builtin_string_split(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t str = to_string_val(js, js->this_val); if (vtype(str) != T_STR) return js_mkerr(js, "split called on non-string"); if (nargs > 0 && is_object_type(args[0])) { bool called = false; - jsval_t call_args[2]; + ant_value_t call_args[2]; int call_nargs = 1; call_args[0] = str; if (nargs >= 2) { call_args[1] = args[1]; call_nargs = 2; } - jsval_t dispatched = maybe_call_symbol_method( + ant_value_t dispatched = maybe_call_symbol_method( js, args[0], get_split_sym(), args[0], call_args, call_nargs, &called ); if (is_err(dispatched)) return dispatched; @@ -8730,29 +8730,29 @@ static jsval_t builtin_string_split(ant_t *js, jsval_t *args, int nargs) { return string_split_impl(js, str, args, nargs); } -static jsval_t builtin_string_slice(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_unwrapped = unwrap_primitive(js, js->this_val); - jsval_t str = js_tostring_val(js, this_unwrapped); +static ant_value_t builtin_string_slice(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_unwrapped = unwrap_primitive(js, js->this_val); + ant_value_t str = js_tostring_val(js, this_unwrapped); if (is_err(str)) return str; - jsoff_t byte_len, str_off = vstr(js, str, &byte_len); + ant_offset_t byte_len, str_off = vstr(js, str, &byte_len); const char *str_ptr = (char *) &js->mem[str_off]; size_t utf16_len = utf16_strlen(str_ptr, byte_len); - jsoff_t start = 0, end = (jsoff_t)utf16_len; + ant_offset_t start = 0, end = (ant_offset_t)utf16_len; double dstr_len = D(utf16_len); if (nargs >= 1 && vtype(args[0]) == T_NUM) { double d = tod(args[0]); if (d < 0) { - start = (jsoff_t) (d + dstr_len < 0 ? 0 : d + dstr_len); - } else start = (jsoff_t) (d > dstr_len ? dstr_len : d); + start = (ant_offset_t) (d + dstr_len < 0 ? 0 : d + dstr_len); + } else start = (ant_offset_t) (d > dstr_len ? dstr_len : d); } if (nargs >= 2 && vtype(args[1]) == T_NUM) { double d = tod(args[1]); if (d < 0) { - end = (jsoff_t) (d + dstr_len < 0 ? 0 : d + dstr_len); - } else end = (jsoff_t) (d > dstr_len ? dstr_len : d); + end = (ant_offset_t) (d + dstr_len < 0 ? 0 : d + dstr_len); + } else end = (ant_offset_t) (d > dstr_len ? dstr_len : d); } if (start > end) start = end; @@ -8761,56 +8761,56 @@ static jsval_t builtin_string_slice(ant_t *js, jsval_t *args, int nargs) { return js_mkstr(js, str_ptr + byte_start, byte_end - byte_start); } -static jsval_t builtin_string_includes(ant_t *js, jsval_t *args, int nargs) { - jsval_t str = to_string_val(js, js->this_val); +static ant_value_t builtin_string_includes(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t str = to_string_val(js, js->this_val); if (vtype(str) != T_STR) return js_mkerr(js, "includes called on non-string"); if (nargs == 0) return mkval(T_BOOL, 0); - jsval_t search = args[0]; + ant_value_t search = args[0]; if (is_object_type(search)) { - jsval_t maybe_err = reject_regexp_arg(js, search, "includes"); + ant_value_t maybe_err = reject_regexp_arg(js, search, "includes"); if (is_err(maybe_err)) return maybe_err; } search = js_tostring_val(js, search); if (is_err(search)) return search; - jsoff_t str_len, str_off = vstr(js, str, &str_len); - jsoff_t search_len, search_off = vstr(js, search, &search_len); + ant_offset_t str_len, str_off = vstr(js, str, &str_len); + ant_offset_t search_len, search_off = vstr(js, search, &search_len); const char *str_ptr = (char *) &js->mem[str_off]; const char *search_ptr = (char *) &js->mem[search_off]; - jsoff_t start = 0; + ant_offset_t start = 0; if (nargs >= 2) { double pos = tod(args[1]); if (isnan(pos) || pos < 0) pos = 0; if (pos > D(str_len)) return mkval(T_BOOL, 0); - start = (jsoff_t) pos; + start = (ant_offset_t) pos; } if (search_len == 0) return mkval(T_BOOL, 1); if (start + search_len > str_len) return mkval(T_BOOL, 0); - for (jsoff_t i = start; i <= str_len - search_len; i++) { + for (ant_offset_t i = start; i <= str_len - search_len; i++) { if (memcmp(str_ptr + i, search_ptr, search_len) == 0) return mkval(T_BOOL, 1); } return mkval(T_BOOL, 0); } -static jsval_t builtin_string_startsWith(ant_t *js, jsval_t *args, int nargs) { - jsval_t str = to_string_val(js, js->this_val); +static ant_value_t builtin_string_startsWith(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t str = to_string_val(js, js->this_val); if (vtype(str) != T_STR) return js_mkerr(js, "startsWith called on non-string"); if (nargs == 0) return mkval(T_BOOL, 0); - jsval_t search = args[0]; + ant_value_t search = args[0]; if (is_object_type(search)) { - jsval_t maybe_err = reject_regexp_arg(js, search, "startsWith"); + ant_value_t maybe_err = reject_regexp_arg(js, search, "startsWith"); if (is_err(maybe_err)) return maybe_err; } search = js_tostring_val(js, search); if (is_err(search)) return search; - jsoff_t str_len, str_off = vstr(js, str, &str_len); - jsoff_t search_len, search_off = vstr(js, search, &search_len); + ant_offset_t str_len, str_off = vstr(js, str, &str_len); + ant_offset_t search_len, search_off = vstr(js, search, &search_len); const char *str_ptr = (char *) &js->mem[str_off]; const char *search_ptr = (char *) &js->mem[search_off]; @@ -8820,21 +8820,21 @@ static jsval_t builtin_string_startsWith(ant_t *js, jsval_t *args, int nargs) { return mkval(T_BOOL, memcmp(str_ptr, search_ptr, search_len) == 0 ? 1 : 0); } -static jsval_t builtin_string_endsWith(ant_t *js, jsval_t *args, int nargs) { - jsval_t str = to_string_val(js, js->this_val); +static ant_value_t builtin_string_endsWith(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t str = to_string_val(js, js->this_val); if (vtype(str) != T_STR) return js_mkerr(js, "endsWith called on non-string"); if (nargs == 0) return mkval(T_BOOL, 0); - jsval_t search = args[0]; + ant_value_t search = args[0]; if (is_object_type(search)) { - jsval_t maybe_err = reject_regexp_arg(js, search, "endsWith"); + ant_value_t maybe_err = reject_regexp_arg(js, search, "endsWith"); if (is_err(maybe_err)) return maybe_err; } search = js_tostring_val(js, search); if (is_err(search)) return search; - jsoff_t str_len, str_off = vstr(js, str, &str_len); - jsoff_t search_len, search_off = vstr(js, search, &search_len); + ant_offset_t str_len, str_off = vstr(js, str, &str_len); + ant_offset_t search_len, search_off = vstr(js, search, &search_len); const char *str_ptr = (char *) &js->mem[str_off]; const char *search_ptr = (char *) &js->mem[search_off]; @@ -8845,17 +8845,17 @@ static jsval_t builtin_string_endsWith(ant_t *js, jsval_t *args, int nargs) { return mkval(T_BOOL, memcmp(str_ptr + str_len - search_len, search_ptr, search_len) == 0 ? 1 : 0); } -static jsval_t builtin_string_replace(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_unwrapped = unwrap_primitive(js, js->this_val); - jsval_t str = js_tostring_val(js, this_unwrapped); +static ant_value_t builtin_string_replace(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_unwrapped = unwrap_primitive(js, js->this_val); + ant_value_t str = js_tostring_val(js, this_unwrapped); if (is_err(str)) return str; if (nargs < 1) return str; if (is_object_type(args[0])) { bool called = false; - jsval_t replacement_arg = nargs > 1 ? args[1] : js_mkundef(); - jsval_t call_args[2] = { str, replacement_arg }; - jsval_t dispatched = maybe_call_symbol_method( + ant_value_t replacement_arg = nargs > 1 ? args[1] : js_mkundef(); + ant_value_t call_args[2] = { str, replacement_arg }; + ant_value_t dispatched = maybe_call_symbol_method( js, args[0], get_replace_sym(), args[0], call_args, 2, &called ); if (is_err(dispatched)) return dispatched; @@ -8863,52 +8863,52 @@ static jsval_t builtin_string_replace(ant_t *js, jsval_t *args, int nargs) { } if (nargs < 2) return str; - jsval_t search = args[0]; - jsval_t replacement = args[1]; + ant_value_t search = args[0]; + ant_value_t replacement = args[1]; - jsoff_t str_len, str_off = vstr(js, str, &str_len); + ant_offset_t str_len, str_off = vstr(js, str, &str_len); const char *str_ptr = (char *) &js->mem[str_off]; bool is_regex = false; bool global_flag = false; bool is_func_replacement = (vtype(replacement) == T_FUNC); char *pattern_buf = NULL; - jsoff_t pattern_len = 0; + ant_offset_t pattern_len = 0; if (vtype(search) == T_OBJ) { - jsoff_t pattern_off = lkp(js, search, "source", 6); + ant_offset_t pattern_off = lkp(js, search, "source", 6); if (pattern_off == 0) goto not_regex; - jsval_t pattern_val = resolveprop(js, mkval(T_PROP, pattern_off)); + ant_value_t pattern_val = resolveprop(js, mkval(T_PROP, pattern_off)); if (vtype(pattern_val) != T_STR) goto not_regex; is_regex = true; - jsoff_t plen, poff = vstr(js, pattern_val, &plen); + ant_offset_t plen, poff = vstr(js, pattern_val, &plen); pattern_len = plen; pattern_buf = (char *)ant_calloc(plen + 1); if (!pattern_buf) return js_mkerr(js, "oom"); memcpy(pattern_buf, &js->mem[poff], plen); pattern_buf[plen] = '\0'; - jsoff_t flags_off = lkp(js, search, "flags", 5); + ant_offset_t flags_off = lkp(js, search, "flags", 5); if (flags_off == 0) { free(pattern_buf); pattern_buf = NULL; goto not_regex; } - jsval_t flags_val = resolveprop(js, mkval(T_PROP, flags_off)); + ant_value_t flags_val = resolveprop(js, mkval(T_PROP, flags_off)); if (vtype(flags_val) != T_STR) { free(pattern_buf); pattern_buf = NULL; goto not_regex; } - jsoff_t flen, foff = vstr(js, flags_val, &flen); + ant_offset_t flen, foff = vstr(js, flags_val, &flen); const char *flags_str = (char *) &js->mem[foff]; - for (jsoff_t i = 0; i < flen; i++) { + for (ant_offset_t i = 0; i < flen; i++) { if (flags_str[i] == 'g') global_flag = true; } } not_regex: - jsoff_t repl_len = 0; + ant_offset_t repl_len = 0; const char *repl_ptr = NULL; if (!is_func_replacement) { if (vtype(replacement) != T_STR) { if (pattern_buf) free(pattern_buf); return str; } - jsoff_t repl_off; + ant_offset_t repl_off; repl_off = vstr(js, replacement, &repl_len); repl_ptr = (char *) &js->mem[repl_off]; } @@ -8962,7 +8962,7 @@ static jsval_t builtin_string_replace(ant_t *js, jsval_t *args, int nargs) { if (is_func_replacement) { int nargs_cb = 1 + capture_count + 2; - jsval_t *cb_args = (jsval_t *)ant_calloc(nargs_cb * sizeof(jsval_t)); + ant_value_t *cb_args = (ant_value_t *)ant_calloc(nargs_cb * sizeof(ant_value_t)); if (!cb_args) { pcre2_match_data_free(match_data); pcre2_code_free(re); @@ -8981,7 +8981,7 @@ static jsval_t builtin_string_replace(ant_t *js, jsval_t *args, int nargs) { cb_args[1 + capture_count] = tov((double)match_start); cb_args[2 + capture_count] = str; - jsval_t cb_result = sv_vm_call(js->vm, js, replacement, js_mkundef(), cb_args, nargs_cb, NULL, false); + ant_value_t cb_result = sv_vm_call(js->vm, js, replacement, js_mkundef(), cb_args, nargs_cb, NULL, false); free(cb_args); if (vtype(cb_result) == T_ERR) { @@ -8991,7 +8991,7 @@ static jsval_t builtin_string_replace(ant_t *js, jsval_t *args, int nargs) { } if (vtype(cb_result) == T_STR) { - jsoff_t cb_len, cb_off = vstr(js, cb_result, &cb_len); + ant_offset_t cb_len, cb_off = vstr(js, cb_result, &cb_len); ENSURE_RESULT_CAP(cb_len); memcpy(result + result_len, &js->mem[cb_off], cb_len); result_len += cb_len; @@ -9036,30 +9036,30 @@ static jsval_t builtin_string_replace(ant_t *js, jsval_t *args, int nargs) { pcre2_match_data_free(match_data); pcre2_code_free(re); if (pattern_buf) free(pattern_buf); - jsval_t ret = replaced ? js_mkstr(js, result, result_len) : str; + ant_value_t ret = replaced ? js_mkstr(js, result, result_len) : str; free(result); return ret; } else { if (vtype(search) != T_STR) { free(result); return str; } - jsoff_t search_len, search_off = vstr(js, search, &search_len); + ant_offset_t search_len, search_off = vstr(js, search, &search_len); const char *search_ptr = (char *) &js->mem[search_off]; if (search_len > str_len) { free(result); return str; } - for (jsoff_t i = 0; i <= str_len - search_len; i++) { + for (ant_offset_t i = 0; i <= str_len - search_len; i++) { if (memcmp(str_ptr + i, search_ptr, search_len) == 0) { ENSURE_RESULT_CAP(i); memcpy(result + result_len, str_ptr, i); result_len += i; if (is_func_replacement) { - jsval_t match_str = js_mkstr(js, search_ptr, search_len); - jsval_t cb_args[1] = { match_str }; - jsval_t cb_result = sv_vm_call(js->vm, js, replacement, js_mkundef(), cb_args, 1, NULL, false); + ant_value_t match_str = js_mkstr(js, search_ptr, search_len); + ant_value_t cb_args[1] = { match_str }; + ant_value_t cb_result = sv_vm_call(js->vm, js, replacement, js_mkundef(), cb_args, 1, NULL, false); if (vtype(cb_result) == T_ERR) { free(result); return cb_result; } if (vtype(cb_result) == T_STR) { - jsoff_t cb_len, cb_off = vstr(js, cb_result, &cb_len); + ant_offset_t cb_len, cb_off = vstr(js, cb_result, &cb_len); ENSURE_RESULT_CAP(cb_len); memcpy(result + result_len, &js->mem[cb_off], cb_len); result_len += cb_len; @@ -9076,14 +9076,14 @@ static jsval_t builtin_string_replace(ant_t *js, jsval_t *args, int nargs) { result_len += repl_len; } - jsoff_t after_start = i + search_len; - jsoff_t after_len = str_len - after_start; + ant_offset_t after_start = i + search_len; + ant_offset_t after_len = str_len - after_start; if (after_len > 0) { ENSURE_RESULT_CAP(after_len); memcpy(result + result_len, str_ptr + after_start, after_len); result_len += after_len; } - jsval_t ret = js_mkstr(js, result, result_len); + ant_value_t ret = js_mkstr(js, result, result_len); free(result); return ret; } @@ -9094,24 +9094,24 @@ static jsval_t builtin_string_replace(ant_t *js, jsval_t *args, int nargs) { #undef ENSURE_RESULT_CAP } -static jsval_t builtin_string_replaceAll(ant_t *js, jsval_t *args, int nargs) { - jsval_t str = to_string_val(js, js->this_val); +static ant_value_t builtin_string_replaceAll(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t str = to_string_val(js, js->this_val); if (vtype(str) != T_STR) return js_mkerr(js, "replaceAll called on non-string"); if (nargs < 2) return str; - jsval_t search = args[0]; - jsval_t replacement = args[1]; + ant_value_t search = args[0]; + ant_value_t replacement = args[1]; if (vtype(search) != T_STR) return js_mkerr(js, "replaceAll requires string search pattern"); if (vtype(replacement) != T_STR) return js_mkerr(js, "replaceAll requires string replacement"); - jsoff_t str_len, str_off = vstr(js, str, &str_len); + ant_offset_t str_len, str_off = vstr(js, str, &str_len); const char *str_ptr = (char *) &js->mem[str_off]; - jsoff_t search_len, search_off = vstr(js, search, &search_len); + ant_offset_t search_len, search_off = vstr(js, search, &search_len); const char *search_ptr = (char *) &js->mem[search_off]; - jsoff_t repl_len, repl_off = vstr(js, replacement, &repl_len); + ant_offset_t repl_len, repl_off = vstr(js, replacement, &repl_len); const char *repl_ptr = (char *) &js->mem[repl_off]; if (search_len == 0) { @@ -9122,18 +9122,18 @@ static jsval_t builtin_string_replaceAll(ant_t *js, jsval_t *args, int nargs) { size_t pos = 0; memcpy(result + pos, repl_ptr, repl_len); pos += repl_len; - for (jsoff_t i = 0; i < str_len; i++) { + for (ant_offset_t i = 0; i < str_len; i++) { result[pos++] = str_ptr[i]; memcpy(result + pos, repl_ptr, repl_len); pos += repl_len; } - jsval_t ret = js_mkstr(js, result, pos); + ant_value_t ret = js_mkstr(js, result, pos); free(result); return ret; } - jsoff_t count = 0; - for (jsoff_t i = 0; i <= str_len - search_len; i++) { + ant_offset_t count = 0; + for (ant_offset_t i = 0; i <= str_len - search_len; i++) { if (memcmp(str_ptr + i, search_ptr, search_len) == 0) { count++; i += search_len - 1; @@ -9147,7 +9147,7 @@ static jsval_t builtin_string_replaceAll(ant_t *js, jsval_t *args, int nargs) { if (!result) return js_mkerr(js, "oom"); size_t result_pos = 0; - jsoff_t str_pos = 0; + ant_offset_t str_pos = 0; while (str_pos <= str_len - search_len) { if (memcmp(str_ptr + str_pos, search_ptr, search_len) == 0) { @@ -9163,26 +9163,26 @@ static jsval_t builtin_string_replaceAll(ant_t *js, jsval_t *args, int nargs) { result[result_pos++] = str_ptr[str_pos++]; } - jsval_t ret = js_mkstr(js, result, result_pos); + ant_value_t ret = js_mkstr(js, result, result_pos); free(result); return ret; } -static jsval_t builtin_string_template(ant_t *js, jsval_t *args, int nargs) { - jsval_t str = to_string_val(js, js->this_val); +static ant_value_t builtin_string_template(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t str = to_string_val(js, js->this_val); if (vtype(str) != T_STR) return js_mkerr(js, "template called on non-string"); if (nargs < 1 || vtype(args[0]) != T_OBJ) return str; - jsval_t data = args[0]; - jsoff_t str_len, str_off = vstr(js, str, &str_len); + ant_value_t data = args[0]; + ant_offset_t str_len, str_off = vstr(js, str, &str_len); const char *str_ptr = (char *) &js->mem[str_off]; size_t result_cap = str_len + 256; size_t result_len = 0; char *result = (char *)ant_calloc(result_cap); if (!result) return js_mkerr(js, "oom"); - jsoff_t i = 0; + ant_offset_t i = 0; #define ENSURE_CAP(need) do { \ if (result_len + (need) >= result_cap) { \ @@ -9195,19 +9195,19 @@ static jsval_t builtin_string_template(ant_t *js, jsval_t *args, int nargs) { while (i < str_len) { if (i < str_len - 3 && str_ptr[i] == '{' && str_ptr[i + 1] == '{') { - jsoff_t start = i + 2; - jsoff_t end = start; + ant_offset_t start = i + 2; + ant_offset_t end = start; while (end < str_len - 1 && !(str_ptr[end] == '}' && str_ptr[end + 1] == '}')) { end++; } if (end < str_len - 1 && str_ptr[end] == '}' && str_ptr[end + 1] == '}') { - jsoff_t key_len = end - start; - jsoff_t prop_off = lkp(js, data, str_ptr + start, key_len); + ant_offset_t key_len = end - start; + ant_offset_t prop_off = lkp(js, data, str_ptr + start, key_len); if (prop_off != 0) { - jsval_t value = resolveprop(js, mkval(T_PROP, prop_off)); + ant_value_t value = resolveprop(js, mkval(T_PROP, prop_off)); if (vtype(value) == T_STR) { - jsoff_t val_len, val_off = vstr(js, value, &val_len); + ant_offset_t val_len, val_off = vstr(js, value, &val_len); ENSURE_CAP(val_len); memcpy(result + result_len, &js->mem[val_off], val_len); result_len += val_len; @@ -9233,14 +9233,14 @@ static jsval_t builtin_string_template(ant_t *js, jsval_t *args, int nargs) { ENSURE_CAP(1); result[result_len++] = str_ptr[i++]; } - jsval_t ret = js_mkstr(js, result, result_len); + ant_value_t ret = js_mkstr(js, result, result_len); free(result); return ret; #undef ENSURE_CAP } -static jsval_t builtin_string_charCodeAt(ant_t *js, jsval_t *args, int nargs) { - jsval_t str = to_string_val(js, js->this_val); +static ant_value_t builtin_string_charCodeAt(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t str = to_string_val(js, js->this_val); if (vtype(str) != T_STR) return js_mkerr(js, "charCodeAt called on non-string"); double idx_d = nargs < 1 ? 0.0 : js_to_number(js, args[0]); @@ -9250,7 +9250,7 @@ static jsval_t builtin_string_charCodeAt(ant_t *js, jsval_t *args, int nargs) { long idx_l = (long) idx_d; if (idx_l < 0) return tov(JS_NAN); - jsoff_t byte_len; jsoff_t str_off = vstr(js, str, &byte_len); + ant_offset_t byte_len; ant_offset_t str_off = vstr(js, str, &byte_len); const char *str_data = (const char *)&js->mem[str_off]; uint32_t code_unit = utf16_code_unit_at(str_data, byte_len, idx_l); @@ -9259,8 +9259,8 @@ static jsval_t builtin_string_charCodeAt(ant_t *js, jsval_t *args, int nargs) { return tov((double) code_unit); } -static jsval_t builtin_string_codePointAt(ant_t *js, jsval_t *args, int nargs) { - jsval_t str = to_string_val(js, js->this_val); +static ant_value_t builtin_string_codePointAt(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t str = to_string_val(js, js->this_val); if (vtype(str) != T_STR) return js_mkerr(js, "codePointAt called on non-string"); double idx_d = nargs < 1 ? 0.0 : js_to_number(js, args[0]); @@ -9270,8 +9270,8 @@ static jsval_t builtin_string_codePointAt(ant_t *js, jsval_t *args, int nargs) { long idx_l = (long) idx_d; if (idx_l < 0) return js_mkundef(); - jsoff_t byte_len; - jsoff_t str_off = vstr(js, str, &byte_len); + ant_offset_t byte_len; + ant_offset_t str_off = vstr(js, str, &byte_len); const char *str_data = (const char *)&js->mem[str_off]; uint32_t cp = utf16_codepoint_at(str_data, byte_len, idx_l); @@ -9280,177 +9280,177 @@ static jsval_t builtin_string_codePointAt(ant_t *js, jsval_t *args, int nargs) { return tov((double) cp); } -static jsval_t builtin_string_toLowerCase(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_string_toLowerCase(ant_t *js, ant_value_t *args, int nargs) { (void) args; (void) nargs; - jsval_t str = to_string_val(js, js->this_val); + ant_value_t str = to_string_val(js, js->this_val); if (vtype(str) != T_STR) return js_mkerr(js, "toLowerCase called on non-string"); - jsoff_t str_len, str_off = vstr(js, str, &str_len); + ant_offset_t str_len, str_off = vstr(js, str, &str_len); const char *str_ptr = (char *) &js->mem[str_off]; if (str_len == 0) return js_mkstr(js, "", 0); const utf8proc_uint8_t *src = (const utf8proc_uint8_t *)str_ptr; utf8proc_ssize_t src_len = (utf8proc_ssize_t)str_len; - jsoff_t out_len = 0; + ant_offset_t out_len = 0; utf8proc_ssize_t pos = 0; while (pos < src_len) { utf8proc_int32_t cp; utf8proc_ssize_t n = utf8_next(src + pos, src_len - pos, &cp); if (cp < 0) { out_len++; pos++; continue; } utf8proc_uint8_t tmp[4]; - out_len += (jsoff_t)utf8proc_encode_char(utf8proc_tolower(cp), tmp); + out_len += (ant_offset_t)utf8proc_encode_char(utf8proc_tolower(cp), tmp); pos += n; } - jsval_t result = js_mkstr(js, NULL, out_len); + ant_value_t result = js_mkstr(js, NULL, out_len); if (is_err(result)) return result; - jsoff_t result_len, result_off = vstr(js, result, &result_len); + ant_offset_t result_len, result_off = vstr(js, result, &result_len); char *result_ptr = (char *) &js->mem[result_off]; pos = 0; - jsoff_t wpos = 0; + ant_offset_t wpos = 0; while (pos < src_len) { utf8proc_int32_t cp; utf8proc_ssize_t n = utf8_next(src + pos, src_len - pos, &cp); if (cp < 0) { result_ptr[wpos++] = (char)src[pos]; pos++; continue; } - wpos += (jsoff_t)utf8proc_encode_char(utf8proc_tolower(cp), (utf8proc_uint8_t *)(result_ptr + wpos)); + wpos += (ant_offset_t)utf8proc_encode_char(utf8proc_tolower(cp), (utf8proc_uint8_t *)(result_ptr + wpos)); pos += n; } return result; } -static jsval_t builtin_string_toUpperCase(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_string_toUpperCase(ant_t *js, ant_value_t *args, int nargs) { (void) args; (void) nargs; - jsval_t str = to_string_val(js, js->this_val); + ant_value_t str = to_string_val(js, js->this_val); if (vtype(str) != T_STR) return js_mkerr(js, "toUpperCase called on non-string"); - jsoff_t str_len, str_off = vstr(js, str, &str_len); + ant_offset_t str_len, str_off = vstr(js, str, &str_len); const char *str_ptr = (char *) &js->mem[str_off]; if (str_len == 0) return js_mkstr(js, "", 0); const utf8proc_uint8_t *src = (const utf8proc_uint8_t *)str_ptr; utf8proc_ssize_t src_len = (utf8proc_ssize_t)str_len; - jsoff_t out_len = 0; + ant_offset_t out_len = 0; utf8proc_ssize_t pos = 0; while (pos < src_len) { utf8proc_int32_t cp; utf8proc_ssize_t n = utf8_next(src + pos, src_len - pos, &cp); if (cp < 0) { out_len++; pos++; continue; } utf8proc_uint8_t tmp[4]; - out_len += (jsoff_t)utf8proc_encode_char(utf8proc_toupper(cp), tmp); + out_len += (ant_offset_t)utf8proc_encode_char(utf8proc_toupper(cp), tmp); pos += n; } - jsval_t result = js_mkstr(js, NULL, out_len); + ant_value_t result = js_mkstr(js, NULL, out_len); if (is_err(result)) return result; - jsoff_t result_len, result_off = vstr(js, result, &result_len); + ant_offset_t result_len, result_off = vstr(js, result, &result_len); char *result_ptr = (char *) &js->mem[result_off]; pos = 0; - jsoff_t wpos = 0; + ant_offset_t wpos = 0; while (pos < src_len) { utf8proc_int32_t cp; utf8proc_ssize_t n = utf8_next(src + pos, src_len - pos, &cp); if (cp < 0) { result_ptr[wpos++] = (char)src[pos]; pos++; continue; } - wpos += (jsoff_t)utf8proc_encode_char(utf8proc_toupper(cp), (utf8proc_uint8_t *)(result_ptr + wpos)); + wpos += (ant_offset_t)utf8proc_encode_char(utf8proc_toupper(cp), (utf8proc_uint8_t *)(result_ptr + wpos)); pos += n; } return result; } -static jsval_t builtin_string_trim(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_string_trim(ant_t *js, ant_value_t *args, int nargs) { (void) args; (void) nargs; - jsval_t str = to_string_val(js, js->this_val); + ant_value_t str = to_string_val(js, js->this_val); if (vtype(str) != T_STR) return js_mkerr(js, "trim called on non-string"); - jsoff_t str_len, str_off = vstr(js, str, &str_len); + ant_offset_t str_len, str_off = vstr(js, str, &str_len); const char *str_ptr = (char *) &js->mem[str_off]; - jsoff_t start = 0, end = str_len; + ant_offset_t start = 0, end = str_len; while (start < end && is_space(str_ptr[start])) start++; while (end > start && is_space(str_ptr[end - 1])) end--; return js_mkstr(js, str_ptr + start, end - start); } -static jsval_t builtin_string_trimStart(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_string_trimStart(ant_t *js, ant_value_t *args, int nargs) { (void) args; (void) nargs; - jsval_t str = to_string_val(js, js->this_val); + ant_value_t str = to_string_val(js, js->this_val); if (vtype(str) != T_STR) return js_mkerr(js, "trimStart called on non-string"); - jsoff_t str_len, str_off = vstr(js, str, &str_len); + ant_offset_t str_len, str_off = vstr(js, str, &str_len); const char *str_ptr = (char *) &js->mem[str_off]; - jsoff_t start = 0; + ant_offset_t start = 0; while (start < str_len && is_space(str_ptr[start])) start++; return js_mkstr(js, str_ptr + start, str_len - start); } -static jsval_t builtin_string_trimEnd(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_string_trimEnd(ant_t *js, ant_value_t *args, int nargs) { (void) args; (void) nargs; - jsval_t str = to_string_val(js, js->this_val); + ant_value_t str = to_string_val(js, js->this_val); if (vtype(str) != T_STR) return js_mkerr(js, "trimEnd called on non-string"); - jsoff_t str_len, str_off = vstr(js, str, &str_len); + ant_offset_t str_len, str_off = vstr(js, str, &str_len); const char *str_ptr = (char *) &js->mem[str_off]; - jsoff_t end = str_len; + ant_offset_t end = str_len; while (end > 0 && is_space(str_ptr[end - 1])) end--; return js_mkstr(js, str_ptr, end); } -static jsval_t builtin_string_repeat(ant_t *js, jsval_t *args, int nargs) { - jsval_t str = to_string_val(js, js->this_val); +static ant_value_t builtin_string_repeat(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t str = to_string_val(js, js->this_val); if (vtype(str) != T_STR) return js_mkerr(js, "repeat called on non-string"); if (nargs < 1 || vtype(args[0]) != T_NUM) return js_mkerr(js, "repeat count required"); double count_d = tod(args[0]); if (count_d < 0 || count_d != (double)(long)count_d) return js_mkerr(js, "invalid repeat count"); - jsoff_t count = (jsoff_t) count_d; + ant_offset_t count = (ant_offset_t) count_d; - jsoff_t str_len, str_off = vstr(js, str, &str_len); + ant_offset_t str_len, str_off = vstr(js, str, &str_len); const char *str_ptr = (char *) &js->mem[str_off]; if (count == 0 || str_len == 0) return js_mkstr(js, "", 0); - jsval_t result = js_mkstr(js, NULL, str_len * count); + ant_value_t result = js_mkstr(js, NULL, str_len * count); if (is_err(result)) return result; - jsoff_t result_len, result_off = vstr(js, result, &result_len); + ant_offset_t result_len, result_off = vstr(js, result, &result_len); char *result_ptr = (char *) &js->mem[result_off]; - for (jsoff_t i = 0; i < count; i++) { + for (ant_offset_t i = 0; i < count; i++) { memcpy(result_ptr + i * str_len, str_ptr, str_len); } return result; } -static jsval_t builtin_string_padStart(ant_t *js, jsval_t *args, int nargs) { - jsval_t str = to_string_val(js, js->this_val); +static ant_value_t builtin_string_padStart(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t str = to_string_val(js, js->this_val); if (vtype(str) != T_STR) return js_mkerr(js, "padStart called on non-string"); if (nargs < 1 || vtype(args[0]) != T_NUM) return str; - jsoff_t target_len = (jsoff_t)tod(args[0]); + ant_offset_t target_len = (ant_offset_t)tod(args[0]); if (target_len <= 0) return str; - jsoff_t str_len, str_off = vstr(js, str, &str_len); + ant_offset_t str_len, str_off = vstr(js, str, &str_len); const char *str_ptr = (char *) &js->mem[str_off]; size_t str_utf16_len = utf16_strlen(str_ptr, (size_t)str_len); if ((size_t)target_len <= str_utf16_len) return str; - jsval_t pad_val = js_mkstr(js, " ", 1); + ant_value_t pad_val = js_mkstr(js, " ", 1); if (nargs >= 2 && vtype(args[1]) != T_UNDEF) { pad_val = coerce_to_str(js, args[1]); if (is_err(pad_val)) return pad_val; } - jsoff_t pad_len, pad_off = vstr(js, pad_val, &pad_len); + ant_offset_t pad_len, pad_off = vstr(js, pad_val, &pad_len); const char *pad_str = (char *)&js->mem[pad_off]; size_t pad_utf16_len = utf16_strlen(pad_str, (size_t)pad_len); @@ -9468,10 +9468,10 @@ static jsval_t builtin_string_padStart(ant_t *js, jsval_t *args, int nargs) { size_t fill_bytes = full_repeats * (size_t)pad_len + rem_bytes; size_t total_bytes = fill_bytes + (size_t)str_len; - jsval_t result = js_mkstr(js, NULL, (jsoff_t)total_bytes); + ant_value_t result = js_mkstr(js, NULL, (ant_offset_t)total_bytes); if (is_err(result)) return result; - jsoff_t result_len, result_off = vstr(js, result, &result_len); + ant_offset_t result_len, result_off = vstr(js, result, &result_len); char *result_ptr = (char *) &js->mem[result_off]; size_t pos = 0; @@ -9488,25 +9488,25 @@ static jsval_t builtin_string_padStart(ant_t *js, jsval_t *args, int nargs) { return result; } -static jsval_t builtin_string_padEnd(ant_t *js, jsval_t *args, int nargs) { - jsval_t str = to_string_val(js, js->this_val); +static ant_value_t builtin_string_padEnd(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t str = to_string_val(js, js->this_val); if (vtype(str) != T_STR) return js_mkerr(js, "padEnd called on non-string"); if (nargs < 1 || vtype(args[0]) != T_NUM) return str; - jsoff_t target_len = (jsoff_t)tod(args[0]); + ant_offset_t target_len = (ant_offset_t)tod(args[0]); if (target_len <= 0) return str; - jsoff_t str_len, str_off = vstr(js, str, &str_len); + ant_offset_t str_len, str_off = vstr(js, str, &str_len); const char *str_ptr = (char *) &js->mem[str_off]; size_t str_utf16_len = utf16_strlen(str_ptr, (size_t)str_len); if ((size_t)target_len <= str_utf16_len) return str; - jsval_t pad_val = js_mkstr(js, " ", 1); + ant_value_t pad_val = js_mkstr(js, " ", 1); if (nargs >= 2 && vtype(args[1]) != T_UNDEF) { pad_val = coerce_to_str(js, args[1]); if (is_err(pad_val)) return pad_val; } - jsoff_t pad_len, pad_off = vstr(js, pad_val, &pad_len); + ant_offset_t pad_len, pad_off = vstr(js, pad_val, &pad_len); const char *pad_str = (char *) &js->mem[pad_off]; size_t pad_utf16_len = utf16_strlen(pad_str, (size_t)pad_len); @@ -9524,10 +9524,10 @@ static jsval_t builtin_string_padEnd(ant_t *js, jsval_t *args, int nargs) { size_t fill_bytes = full_repeats * (size_t)pad_len + rem_bytes; size_t total_bytes = (size_t)str_len + fill_bytes; - jsval_t result = js_mkstr(js, NULL, (jsoff_t)total_bytes); + ant_value_t result = js_mkstr(js, NULL, (ant_offset_t)total_bytes); if (is_err(result)) return result; - jsoff_t result_len, result_off = vstr(js, result, &result_len); + ant_offset_t result_len, result_off = vstr(js, result, &result_len); char *result_ptr = (char *) &js->mem[result_off]; memcpy(result_ptr, str_ptr, (size_t)str_len); @@ -9544,8 +9544,8 @@ static jsval_t builtin_string_padEnd(ant_t *js, jsval_t *args, int nargs) { return result; } -static jsval_t builtin_string_charAt(ant_t *js, jsval_t *args, int nargs) { - jsval_t str = to_string_val(js, js->this_val); +static ant_value_t builtin_string_charAt(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t str = to_string_val(js, js->this_val); if (vtype(str) != T_STR) return js_mkerr(js, "charAt called on non-string"); double idx_d = nargs < 1 ? 0.0 : js_to_number(js, args[0]); @@ -9554,9 +9554,9 @@ static jsval_t builtin_string_charAt(ant_t *js, jsval_t *args, int nargs) { else idx_d = floor(idx_d); if (idx_d < 0 || isinf(idx_d)) return js_mkstr(js, "", 0); - jsoff_t idx = (jsoff_t) idx_d; - jsoff_t byte_len; - jsoff_t str_off = vstr(js, str, &byte_len); + ant_offset_t idx = (ant_offset_t) idx_d; + ant_offset_t byte_len; + ant_offset_t str_off = vstr(js, str, &byte_len); const char *str_data = (const char *)&js->mem[str_off]; size_t char_bytes; @@ -9566,14 +9566,14 @@ static jsval_t builtin_string_charAt(ant_t *js, jsval_t *args, int nargs) { return js_mkstr(js, str_data + byte_offset, char_bytes); } -static jsval_t builtin_string_at(ant_t *js, jsval_t *args, int nargs) { - jsval_t str = to_string_val(js, js->this_val); +static ant_value_t builtin_string_at(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t str = to_string_val(js, js->this_val); if (vtype(str) != T_STR) return js_mkerr(js, "at called on non-string"); double idx_d = nargs < 1 ? 0.0 : js_to_number(js, args[0]); if (isnan(idx_d) || isinf(idx_d)) return js_mkundef(); - jsoff_t byte_len; jsoff_t str_off = vstr(js, str, &byte_len); + ant_offset_t byte_len; ant_offset_t str_off = vstr(js, str, &byte_len); const char *str_data = (const char *)&js->mem[str_off]; size_t utf16_len = utf16_strlen(str_data, byte_len); @@ -9588,20 +9588,20 @@ static jsval_t builtin_string_at(ant_t *js, jsval_t *args, int nargs) { return js_mkstr(js, str_data + byte_offset, char_bytes); } -static jsval_t builtin_string_localeCompare(ant_t *js, jsval_t *args, int nargs) { - jsval_t str = to_string_val(js, js->this_val); +static ant_value_t builtin_string_localeCompare(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t str = to_string_val(js, js->this_val); if (vtype(str) != T_STR) return js_mkerr(js, "localeCompare called on non-string"); if (nargs < 1) return tov(0); - jsval_t that = args[0]; + ant_value_t that = args[0]; if (vtype(that) != T_STR) { char buf[64]; size_t n = tostr(js, that, buf, sizeof(buf)); that = js_mkstr(js, buf, n); } - jsoff_t str_len, str_off = vstr(js, str, &str_len); - jsoff_t that_len, that_off = vstr(js, that, &that_len); + ant_offset_t str_len, str_off = vstr(js, str, &str_len); + ant_offset_t that_len, that_off = vstr(js, that, &that_len); const char *str_ptr = (char *)&js->mem[str_off]; const char *that_ptr = (char *)&js->mem[that_off]; @@ -9611,25 +9611,25 @@ static jsval_t builtin_string_localeCompare(ant_t *js, jsval_t *args, int nargs) return tov(0); } -static jsval_t builtin_string_lastIndexOf(ant_t *js, jsval_t *args, int nargs) { - jsval_t str = to_string_val(js, js->this_val); +static ant_value_t builtin_string_lastIndexOf(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t str = to_string_val(js, js->this_val); if (vtype(str) != T_STR) return js_mkerr(js, "lastIndexOf called on non-string"); if (nargs == 0) return tov(-1); - jsval_t search = args[0]; + ant_value_t search = args[0]; if (vtype(search) != T_STR) return tov(-1); - jsoff_t str_len, str_off = vstr(js, str, &str_len); - jsoff_t search_len, search_off = vstr(js, search, &search_len); + ant_offset_t str_len, str_off = vstr(js, str, &str_len); + ant_offset_t search_len, search_off = vstr(js, search, &search_len); - jsoff_t max_start = str_len; + ant_offset_t max_start = str_len; double dstr_len = D(str_len); if (nargs >= 2 && vtype(args[1]) == T_NUM) { double pos = tod(args[1]); if (isnan(pos)) pos = dstr_len; if (pos < 0) pos = 0; if (pos > dstr_len) pos = dstr_len; - max_start = (jsoff_t) pos; + max_start = (ant_offset_t) pos; } if (search_len == 0) return tov((double) (max_start > str_len ? str_len : max_start)); @@ -9638,24 +9638,24 @@ static jsval_t builtin_string_lastIndexOf(ant_t *js, jsval_t *args, int nargs) { const char *str_ptr = (char *) &js->mem[str_off]; const char *search_ptr = (char *) &js->mem[search_off]; - jsoff_t start = (max_start + search_len > str_len) ? str_len - search_len : max_start; - for (jsoff_t i = start + 1; i > 0; i--) { + ant_offset_t start = (max_start + search_len > str_len) ? str_len - search_len : max_start; + for (ant_offset_t i = start + 1; i > 0; i--) { if (memcmp(str_ptr + i - 1, search_ptr, search_len) == 0) return tov((double)(i - 1)); } return tov(-1); } -static jsval_t builtin_string_concat(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_unwrapped = unwrap_primitive(js, js->this_val); - jsval_t str = js_tostring_val(js, this_unwrapped); +static ant_value_t builtin_string_concat(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_unwrapped = unwrap_primitive(js, js->this_val); + ant_value_t str = js_tostring_val(js, this_unwrapped); if (is_err(str)) return str; - jsoff_t total_len; - jsoff_t base_off = vstr(js, str, &total_len); + ant_offset_t total_len; + ant_offset_t base_off = vstr(js, str, &total_len); - jsval_t *str_args = NULL; + ant_value_t *str_args = NULL; if (nargs > 0) { - str_args = (jsval_t *)ant_calloc(nargs * sizeof(jsval_t)); + str_args = (ant_value_t *)ant_calloc(nargs * sizeof(ant_value_t)); if (!str_args) return js_mkerr(js, "oom"); for (int i = 0; i < nargs; i++) { str_args[i] = js_tostring_val(js, args[i]); @@ -9663,7 +9663,7 @@ static jsval_t builtin_string_concat(ant_t *js, jsval_t *args, int nargs) { free(str_args); return str_args[i]; } - jsoff_t arg_len; + ant_offset_t arg_len; vstr(js, str_args[i], &arg_len); total_len += arg_len; } @@ -9675,38 +9675,38 @@ static jsval_t builtin_string_concat(ant_t *js, jsval_t *args, int nargs) { return js_mkerr(js, "oom"); } - jsoff_t base_len; + ant_offset_t base_len; base_off = vstr(js, str, &base_len); memcpy(result, &js->mem[base_off], base_len); - jsoff_t pos = base_len; + ant_offset_t pos = base_len; for (int i = 0; i < nargs; i++) { - jsoff_t arg_len, arg_off = vstr(js, str_args[i], &arg_len); + ant_offset_t arg_len, arg_off = vstr(js, str_args[i], &arg_len); memcpy(result + pos, &js->mem[arg_off], arg_len); pos += arg_len; } result[pos] = '\0'; - jsval_t ret = js_mkstr(js, result, pos); + ant_value_t ret = js_mkstr(js, result, pos); free(result); if (str_args) free(str_args); return ret; } -static jsval_t builtin_string_normalize(ant_t *js, jsval_t *args, int nargs) { - jsval_t str = to_string_val(js, js->this_val); +static ant_value_t builtin_string_normalize(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t str = to_string_val(js, js->this_val); if (vtype(str) != T_STR) return js_mkerr(js, "normalize called on non-string"); - jsoff_t str_len, str_off = vstr(js, str, &str_len); + ant_offset_t str_len, str_off = vstr(js, str, &str_len); const char *str_ptr = (const char *)&js->mem[str_off]; if (str_len == 0) return js_mkstr(js, "", 0); utf8proc_option_t opts = UTF8PROC_COMPOSE | UTF8PROC_STABLE; if (nargs >= 1 && vtype(args[0]) != T_UNDEF) { - jsval_t form_val = js_tostring_val(js, args[0]); + ant_value_t form_val = js_tostring_val(js, args[0]); if (is_err(form_val)) return form_val; - jsoff_t flen, foff = vstr(js, form_val, &flen); + ant_offset_t flen, foff = vstr(js, form_val, &flen); const char *form = (const char *)&js->mem[foff]; if (flen == 3 && memcmp(form, "NFC", 3) == 0) { @@ -9730,13 +9730,13 @@ static jsval_t builtin_string_normalize(ant_t *js, jsval_t *args, int nargs) { return js_mkstr(js, str_ptr, str_len); } - jsval_t ret = js_mkstr(js, (const char *)result, (jsoff_t)rlen); + ant_value_t ret = js_mkstr(js, (const char *)result, (ant_offset_t)rlen); free(result); return ret; } -static jsval_t builtin_string_fromCharCode(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_string_fromCharCode(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return js_mkstr(js, "", 0); char *buf = (char *)ant_calloc(nargs + 1); @@ -9749,12 +9749,12 @@ static jsval_t builtin_string_fromCharCode(ant_t *js, jsval_t *args, int nargs) } buf[nargs] = '\0'; - jsval_t ret = js_mkstr(js, buf, nargs); + ant_value_t ret = js_mkstr(js, buf, nargs); free(buf); return ret; } -static jsval_t builtin_string_fromCodePoint(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_string_fromCodePoint(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return js_mkstr(js, "", 0); char *buf = (char *)ant_calloc(nargs * 4 + 1); @@ -9787,7 +9787,7 @@ static jsval_t builtin_string_fromCodePoint(ant_t *js, jsval_t *args, int nargs) } buf[len] = '\0'; - jsval_t ret = js_mkstr(js, buf, len); + ant_value_t ret = js_mkstr(js, buf, len); free(buf); return ret; } @@ -9795,16 +9795,16 @@ static jsval_t builtin_string_fromCodePoint(ant_t *js, jsval_t *args, int nargs) static bool string_builder_append_value( ant_t *js, char **buf, size_t *len, size_t *cap, - jsval_t value, jsval_t *err + ant_value_t value, ant_value_t *err ) { - jsval_t s = js_tostring_val(js, value); + ant_value_t s = js_tostring_val(js, value); if (is_err(s)) { if (err) *err = s; return false; } - jsoff_t slen = 0; - jsoff_t soff = vstr(js, s, &slen); + ant_offset_t slen = 0; + ant_offset_t soff = vstr(js, s, &slen); size_t need = *len + (size_t)slen + 1; if (need > *cap) { @@ -9825,22 +9825,22 @@ static bool string_builder_append_value( return true; } -static jsval_t builtin_string_raw(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_string_raw(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || is_null(args[0]) || is_undefined(args[0])) { return js_mkerr_typed(js, JS_ERR_TYPE, "String.raw requires a template object"); } - jsval_t tmpl = args[0]; + ant_value_t tmpl = args[0]; if (!is_object_type(tmpl)) { return js_mkerr_typed(js, JS_ERR_TYPE, "String.raw requires a template object"); } - jsval_t raw = js_get(js, tmpl, "raw"); + ant_value_t raw = js_get(js, tmpl, "raw"); if (is_null(raw) || is_undefined(raw) || !is_object_type(raw)) { return js_mkerr_typed(js, JS_ERR_TYPE, "String.raw requires template.raw"); } - jsval_t raw_len_val = js_get(js, raw, "length"); + ant_value_t raw_len_val = js_get(js, raw, "length"); double raw_len_num = js_to_number(js, raw_len_val); if (!isfinite(raw_len_num) || raw_len_num <= 0) return js_mkstr(js, "", 0); @@ -9849,11 +9849,11 @@ static jsval_t builtin_string_raw(ant_t *js, jsval_t *args, int nargs) { char *buf = NULL; size_t len = 0; size_t cap = 0; - jsval_t err = js_mkundef(); + ant_value_t err = js_mkundef(); for (size_t i = 0; i < literal_count; i++) { - jsval_t chunk = js_mkundef(); - if (vtype(raw) == T_ARR) chunk = js_arr_get(js, raw, (jsoff_t)i); + ant_value_t chunk = js_mkundef(); + if (vtype(raw) == T_ARR) chunk = js_arr_get(js, raw, (ant_offset_t)i); else { char key[32]; snprintf(key, sizeof(key), "%zu", i); @@ -9872,14 +9872,14 @@ static jsval_t builtin_string_raw(ant_t *js, jsval_t *args, int nargs) { } } - jsval_t out = js_mkstr(js, buf ? buf : "", len); + ant_value_t out = js_mkstr(js, buf ? buf : "", len); free(buf); return out; } -static jsval_t builtin_number_toString(ant_t *js, jsval_t *args, int nargs) { - jsval_t num = unwrap_primitive(js, js->this_val); +static ant_value_t builtin_number_toString(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t num = unwrap_primitive(js, js->this_val); if (vtype(num) != T_NUM) return js_mkerr(js, "toString called on non-number"); int radix = 10; @@ -9948,8 +9948,8 @@ static jsval_t builtin_number_toString(ant_t *js, jsval_t *args, int nargs) { return js_mkstr(js, p, int_len); } -static jsval_t builtin_number_toFixed(ant_t *js, jsval_t *args, int nargs) { - jsval_t num = unwrap_primitive(js, js->this_val); +static ant_value_t builtin_number_toFixed(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t num = unwrap_primitive(js, js->this_val); if (vtype(num) != T_NUM) return js_mkerr(js, "toFixed called on non-number"); double d = tod(num); @@ -10009,8 +10009,8 @@ static jsval_t builtin_number_toFixed(ant_t *js, jsval_t *args, int nargs) { return js_mkstr(js, buf, pos); } -static jsval_t builtin_number_toPrecision(ant_t *js, jsval_t *args, int nargs) { - jsval_t num = unwrap_primitive(js, js->this_val); +static ant_value_t builtin_number_toPrecision(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t num = unwrap_primitive(js, js->this_val); if (vtype(num) != T_NUM) return js_mkerr(js, "toPrecision called on non-number"); double d = tod(num); @@ -10114,8 +10114,8 @@ static jsval_t builtin_number_toPrecision(ant_t *js, jsval_t *args, int nargs) { } } -static jsval_t builtin_number_toExponential(ant_t *js, jsval_t *args, int nargs) { - jsval_t num = unwrap_primitive(js, js->this_val); +static ant_value_t builtin_number_toExponential(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t num = unwrap_primitive(js, js->this_val); if (vtype(num) != T_NUM) return js_mkerr(js, "toExponential called on non-number"); double d = tod(num); @@ -10195,16 +10195,16 @@ static jsval_t builtin_number_toExponential(ant_t *js, jsval_t *args, int nargs) return js_mkstr(js, buf, strlen(buf)); } -static jsval_t builtin_number_valueOf(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_number_valueOf(ant_t *js, ant_value_t *args, int nargs) { (void) args; (void) nargs; - jsval_t num = unwrap_primitive(js, js->this_val); + ant_value_t num = unwrap_primitive(js, js->this_val); if (vtype(num) != T_NUM) return js_mkerr(js, "valueOf called on non-number"); return num; } -static jsval_t builtin_number_toLocaleString(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_number_toLocaleString(ant_t *js, ant_value_t *args, int nargs) { (void) args; (void) nargs; - jsval_t num = unwrap_primitive(js, js->this_val); + ant_value_t num = unwrap_primitive(js, js->this_val); if (vtype(num) != T_NUM) return js_mkerr(js, "toLocaleString called on non-number"); double d = tod(num); char raw[64]; @@ -10229,41 +10229,41 @@ static jsval_t builtin_number_toLocaleString(ant_t *js, jsval_t *args, int nargs return js_mkstr(js, buf, pos); } -static jsval_t builtin_string_valueOf(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_string_valueOf(ant_t *js, ant_value_t *args, int nargs) { (void) args; (void) nargs; - jsval_t str = to_string_val(js, js->this_val); + ant_value_t str = to_string_val(js, js->this_val); if (vtype(str) != T_STR) return js_mkerr(js, "valueOf called on non-string"); return str; } -static jsval_t builtin_string_toString(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_string_toString(ant_t *js, ant_value_t *args, int nargs) { return builtin_string_valueOf(js, args, nargs); } -static jsval_t builtin_boolean_valueOf(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_boolean_valueOf(ant_t *js, ant_value_t *args, int nargs) { (void) args; (void) nargs; - jsval_t b = unwrap_primitive(js, js->this_val); + ant_value_t b = unwrap_primitive(js, js->this_val); if (vtype(b) != T_BOOL) return js_mkerr(js, "valueOf called on non-boolean"); return b; } -static jsval_t builtin_boolean_toString(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_boolean_toString(ant_t *js, ant_value_t *args, int nargs) { (void) args; (void) nargs; - jsval_t b = unwrap_primitive(js, js->this_val); + ant_value_t b = unwrap_primitive(js, js->this_val); if (vtype(b) != T_BOOL) return js_mkerr(js, "toString called on non-boolean"); return vdata(b) ? js_mkstr(js, "true", 4) : js_mkstr(js, "false", 5); } -static jsval_t builtin_parseInt(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_parseInt(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return tov(JS_NAN); - jsval_t str_val = args[0]; + ant_value_t str_val = args[0]; if (vtype(str_val) != T_STR) { const char *str = js_str(js, str_val); str_val = js_mkstr(js, str, strlen(str)); } - jsoff_t str_len, str_off = vstr(js, str_val, &str_len); + ant_offset_t str_len, str_off = vstr(js, str_val, &str_len); const char *str = (char *) &js->mem[str_off]; int radix = 0; @@ -10272,7 +10272,7 @@ static jsval_t builtin_parseInt(ant_t *js, jsval_t *args, int nargs) { if (radix != 0 && (radix < 2 || radix > 36)) return tov(JS_NAN); } - jsoff_t i = 0; + ant_offset_t i = 0; while (i < str_len && is_space(str[i])) i++; if (i >= str_len) return tov(JS_NAN); @@ -10319,19 +10319,19 @@ static jsval_t builtin_parseInt(ant_t *js, jsval_t *args, int nargs) { return tov(sign * result); } -static jsval_t builtin_parseFloat(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_parseFloat(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return tov(JS_NAN); - jsval_t str_val = args[0]; + ant_value_t str_val = args[0]; if (vtype(str_val) != T_STR) { const char *str = js_str(js, str_val); str_val = js_mkstr(js, str, strlen(str)); } - jsoff_t str_len, str_off = vstr(js, str_val, &str_len); + ant_offset_t str_len, str_off = vstr(js, str_val, &str_len); const char *str = (char *) &js->mem[str_off]; - jsoff_t i = 0; + ant_offset_t i = 0; while (i < str_len && is_space(str[i])) i++; if (i >= str_len) return tov(JS_NAN); @@ -10344,38 +10344,38 @@ static jsval_t builtin_parseFloat(ant_t *js, jsval_t *args, int nargs) { return tov(result); } -static jsval_t builtin_btoa(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_btoa(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "btoa requires 1 argument"); - jsval_t str_val = args[0]; + ant_value_t str_val = args[0]; if (vtype(str_val) != T_STR) { const char *str = js_str(js, str_val); str_val = js_mkstr(js, str, strlen(str)); } - jsoff_t str_len, str_off = vstr(js, str_val, &str_len); + ant_offset_t str_len, str_off = vstr(js, str_val, &str_len); const char *str = (char *) &js->mem[str_off]; size_t out_len; char *out = ant_base64_encode((const uint8_t *)str, str_len, &out_len); if (!out) return js_mkerr(js, "out of memory"); - jsval_t result = js_mkstr(js, out, out_len); + ant_value_t result = js_mkstr(js, out, out_len); free(out); return result; } -static jsval_t builtin_atob(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_atob(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "atob requires 1 argument"); - jsval_t str_val = args[0]; + ant_value_t str_val = args[0]; if (vtype(str_val) != T_STR) { const char *str = js_str(js, str_val); str_val = js_mkstr(js, str, strlen(str)); } - jsoff_t str_len, str_off = vstr(js, str_val, &str_len); + ant_offset_t str_len, str_off = vstr(js, str_val, &str_len); const char *str = (char *) &js->mem[str_off]; if (str_len == 0) return js_mkstr(js, "", 0); @@ -10383,18 +10383,18 @@ static jsval_t builtin_atob(ant_t *js, jsval_t *args, int nargs) { uint8_t *out = ant_base64_decode(str, str_len, &out_len); if (!out) return js_mkerr(js, "atob: invalid base64 string"); - jsval_t result = js_mkstr(js, (char *)out, out_len); + ant_value_t result = js_mkstr(js, (char *)out, out_len); free(out); return result; } -static jsval_t builtin_resolve_internal(ant_t *js, jsval_t *args, int nargs); -static jsval_t builtin_reject_internal(ant_t *js, jsval_t *args, int nargs); -static void resolve_promise(ant_t *js, jsval_t p, jsval_t val); -static void reject_promise(ant_t *js, jsval_t p, jsval_t val); +static ant_value_t builtin_resolve_internal(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t builtin_reject_internal(ant_t *js, ant_value_t *args, int nargs); +static void resolve_promise(ant_t *js, ant_value_t p, ant_value_t val); +static void reject_promise(ant_t *js, ant_value_t p, ant_value_t val); -static size_t strpromise(ant_t *js, jsval_t value, char *buf, size_t len) { +static size_t strpromise(ant_t *js, ant_value_t value, char *buf, size_t len) { uint32_t pid = get_promise_id(js, value); promise_data_entry_t *pd = get_promise_data(pid, false); @@ -10438,36 +10438,36 @@ static promise_data_entry_t *get_promise_data(uint32_t promise_id, bool create) return entry; } -static uint32_t get_promise_id(ant_t *js, jsval_t p) { - jsval_t p_obj = js_as_obj(p); - jsval_t pid_val = get_slot(js, p_obj, SLOT_PID); +static uint32_t get_promise_id(ant_t *js, ant_value_t p) { + ant_value_t p_obj = js_as_obj(p); + ant_value_t pid_val = get_slot(js, p_obj, SLOT_PID); if (vtype(pid_val) == T_UNDEF) return 0; return (uint32_t)tod(pid_val); } -static jsval_t mkpromise(ant_t *js) { - jsval_t obj = mkobj(js, 0); +static ant_value_t mkpromise(ant_t *js) { + ant_value_t obj = mkobj(js, 0); if (is_err(obj)) return obj; uint32_t pid = next_promise_id++; set_slot(js, obj, SLOT_PID, tov((double)pid)); - jsval_t promise_ctor = js_get(js, js_glob(js), "Promise"); + ant_value_t promise_ctor = js_get(js, js_glob(js), "Promise"); if (vtype(promise_ctor) == T_FUNC || vtype(promise_ctor) == T_CFUNC) { set_slot(js, obj, SLOT_CTOR, promise_ctor); } - jsval_t promise_proto = get_ctor_proto(js, "Promise", 7); + ant_value_t promise_proto = get_ctor_proto(js, "Promise", 7); if (is_object_type(promise_proto)) { set_slot(js, obj, SLOT_PROTO, promise_proto); } promise_data_entry_t *pd = get_promise_data(pid, true); - if (pd) pd->obj_offset = (jsoff_t)vdata(js_as_obj(obj)); + if (pd) pd->obj_offset = (ant_offset_t)vdata(js_as_obj(obj)); return mkval(T_PROMISE, vdata(obj)); } -static inline void trigger_handlers(ant_t *js, jsval_t p) { +static inline void trigger_handlers(ant_t *js, ant_value_t p) { uint32_t pid = get_promise_id(js, p); queue_promise_trigger(pid); } @@ -10477,27 +10477,27 @@ void js_process_promise_handlers(ant_t *js, uint32_t pid) { if (!pd) return; int state = pd->state; - jsval_t val = pd->value; + ant_value_t val = pd->value; unsigned int len = utarray_len(pd->handlers); if (len == 0) { return; } pd->processing = true; for (unsigned int i = 0; i < len; i++) { promise_handler_t *h = (promise_handler_t *)utarray_eltptr(pd->handlers, i); - jsval_t handler = (state == 1) ? h->onFulfilled : h->onRejected; + ant_value_t handler = (state == 1) ? h->onFulfilled : h->onRejected; if (vtype(handler) == T_FUNC || vtype(handler) == T_CFUNC) { - jsval_t res; + ant_value_t res; if (vtype(handler) == T_CFUNC) { - jsval_t (*fn)(ant_t *, jsval_t *, int) = (jsval_t(*)(ant_t *, jsval_t *, int)) vdata(handler); + ant_value_t (*fn)(ant_t *, ant_value_t *, int) = (ant_value_t(*)(ant_t *, ant_value_t *, int)) vdata(handler); res = fn(js, &val, 1); } else { - jsval_t call_args[] = { val }; + ant_value_t call_args[] = { val }; res = sv_vm_call(js->vm, js, handler, js_mkundef(), call_args, 1, NULL, false); } if (is_err(res)) { - jsval_t reject_val = js->thrown_value; + ant_value_t reject_val = js->thrown_value; if (vtype(reject_val) == T_UNDEF) reject_val = res; js->thrown_exists = false; js->thrown_value = js_mkundef(); @@ -10514,7 +10514,7 @@ void js_process_promise_handlers(ant_t *js, uint32_t pid) { utarray_clear(pd->handlers); } -static void resolve_promise(ant_t *js, jsval_t p, jsval_t val) { +static void resolve_promise(ant_t *js, ant_value_t p, ant_value_t val) { uint32_t pid = get_promise_id(js, p); promise_data_entry_t *pd = get_promise_data(pid, false); if (!pd || pd->state != 0) return; @@ -10522,22 +10522,22 @@ static void resolve_promise(ant_t *js, jsval_t p, jsval_t val) { if (vtype(val) == T_PROMISE) { uint32_t val_pid = get_promise_id(js, val); if (val_pid == pid) { - jsval_t err = js_mkerr(js, "TypeError: Chaining cycle"); + ant_value_t err = js_mkerr(js, "TypeError: Chaining cycle"); return reject_promise(js, p, err); } - jsval_t res_obj = mkobj(js, 0); + ant_value_t res_obj = mkobj(js, 0); set_slot(js, res_obj, SLOT_DATA, p); set_slot(js, res_obj, SLOT_CFUNC, js_mkfun(builtin_resolve_internal)); - jsval_t res_fn = js_obj_to_func(res_obj); + ant_value_t res_fn = js_obj_to_func(res_obj); - jsval_t rej_obj = mkobj(js, 0); + ant_value_t rej_obj = mkobj(js, 0); set_slot(js, rej_obj, SLOT_DATA, p); set_slot(js, rej_obj, SLOT_CFUNC, js_mkfun(builtin_reject_internal)); - jsval_t rej_fn = js_obj_to_func(rej_obj); + ant_value_t rej_fn = js_obj_to_func(rej_obj); - jsval_t call_args[] = { res_fn, rej_fn }; - jsval_t then_prop = js_get(js, val, "then"); + ant_value_t call_args[] = { res_fn, rej_fn }; + ant_value_t then_prop = js_get(js, val, "then"); if (vtype(then_prop) == T_FUNC || vtype(then_prop) == T_CFUNC) { (void)sv_vm_call(js->vm, js, then_prop, val, call_args, 2, NULL, false); return; @@ -10549,7 +10549,7 @@ static void resolve_promise(ant_t *js, jsval_t p, jsval_t val) { trigger_handlers(js, p); } -static void reject_promise(ant_t *js, jsval_t p, jsval_t val) { +static void reject_promise(ant_t *js, ant_value_t p, ant_value_t val) { uint32_t pid = get_promise_id(js, p); promise_data_entry_t *pd = get_promise_data(pid, false); if (!pd || pd->state != 0) return; @@ -10568,23 +10568,23 @@ static void reject_promise(ant_t *js, jsval_t p, jsval_t val) { trigger_handlers(js, p); } -static jsval_t builtin_resolve_internal(ant_t *js, jsval_t *args, int nargs) { - jsval_t me = js->current_func; - jsval_t p = get_slot(js, me, SLOT_DATA); +static ant_value_t builtin_resolve_internal(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t me = js->current_func; + ant_value_t p = get_slot(js, me, SLOT_DATA); if (vtype(p) != T_PROMISE) return js_mkundef(); resolve_promise(js, p, nargs > 0 ? args[0] : js_mkundef()); return js_mkundef(); } -static jsval_t builtin_reject_internal(ant_t *js, jsval_t *args, int nargs) { - jsval_t me = js->current_func; - jsval_t p = get_slot(js, me, SLOT_DATA); +static ant_value_t builtin_reject_internal(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t me = js->current_func; + ant_value_t p = get_slot(js, me, SLOT_DATA); if (vtype(p) != T_PROMISE) return js_mkundef(); reject_promise(js, p, nargs > 0 ? args[0] : js_mkundef()); return js_mkundef(); } -static jsval_t builtin_Promise(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Promise(ant_t *js, ant_value_t *args, int nargs) { if (vtype(js->new_target) == T_UNDEF) { return js_mkerr_typed(js, JS_ERR_TYPE, "Promise constructor cannot be invoked without 'new'"); } @@ -10594,65 +10594,65 @@ static jsval_t builtin_Promise(ant_t *js, jsval_t *args, int nargs) { return js_mkerr_typed(js, JS_ERR_TYPE, "Promise resolver %s is not a function", val_str); } - jsval_t p = mkpromise(js); - jsval_t new_target = js->new_target; - jsval_t p_obj = js_as_obj(p); + ant_value_t p = mkpromise(js); + ant_value_t new_target = js->new_target; + ant_value_t p_obj = js_as_obj(p); - jsval_t promise_proto = get_ctor_proto(js, "Promise", 7); - jsval_t instance_proto = js_instance_proto_from_new_target(js, promise_proto); + ant_value_t promise_proto = get_ctor_proto(js, "Promise", 7); + ant_value_t instance_proto = js_instance_proto_from_new_target(js, promise_proto); if (vtype(new_target) == T_FUNC || vtype(new_target) == T_CFUNC) set_slot(js, p_obj, SLOT_CTOR, new_target); if (is_object_type(instance_proto)) set_slot(js, p_obj, SLOT_PROTO, instance_proto); - jsval_t res_obj = mkobj(js, 0); + ant_value_t res_obj = mkobj(js, 0); set_slot(js, res_obj, SLOT_DATA, p); set_slot(js, res_obj, SLOT_CFUNC, js_mkfun(builtin_resolve_internal)); - jsval_t res_fn = js_obj_to_func(res_obj); - jsval_t rej_obj = mkobj(js, 0); + ant_value_t res_fn = js_obj_to_func(res_obj); + ant_value_t rej_obj = mkobj(js, 0); set_slot(js, rej_obj, SLOT_DATA, p); set_slot(js, rej_obj, SLOT_CFUNC, js_mkfun(builtin_reject_internal)); - jsval_t rej_fn = js_obj_to_func(rej_obj); - jsval_t exec_args[] = { res_fn, rej_fn }; + ant_value_t rej_fn = js_obj_to_func(rej_obj); + ant_value_t exec_args[] = { res_fn, rej_fn }; sv_vm_call(js->vm, js, args[0], js_mkundef(), exec_args, 2, NULL, false); return p; } -static jsval_t builtin_Promise_resolve(ant_t *js, jsval_t *args, int nargs) { - jsval_t val = nargs > 0 ? args[0] : js_mkundef(); +static ant_value_t builtin_Promise_resolve(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t val = nargs > 0 ? args[0] : js_mkundef(); if (vtype(val) == T_PROMISE) return val; - jsval_t p = mkpromise(js); + ant_value_t p = mkpromise(js); resolve_promise(js, p, val); return p; } -static jsval_t builtin_Promise_reject(ant_t *js, jsval_t *args, int nargs) { - jsval_t val = nargs > 0 ? args[0] : js_mkundef(); - jsval_t p = mkpromise(js); +static ant_value_t builtin_Promise_reject(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t val = nargs > 0 ? args[0] : js_mkundef(); + ant_value_t p = mkpromise(js); reject_promise(js, p, val); return p; } -static jsval_t promise_species_noop_executor(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t promise_species_noop_executor(ant_t *js, ant_value_t *args, int nargs) { return js_mkundef(); } -static jsval_t builtin_promise_then(ant_t *js, jsval_t *args, int nargs) { - jsval_t p = js->this_val; +static ant_value_t builtin_promise_then(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t p = js->this_val; if (vtype(p) != T_PROMISE) return js_mkerr(js, "not a promise"); - jsval_t promise_ctor = js_get(js, js_glob(js), "Promise"); - jsval_t species_ctor = promise_ctor; - jsval_t p_obj = js_as_obj(p); - jsval_t ctor = js_get(js, p_obj, "constructor"); + ant_value_t promise_ctor = js_get(js, js_glob(js), "Promise"); + ant_value_t species_ctor = promise_ctor; + ant_value_t p_obj = js_as_obj(p); + ant_value_t ctor = js_get(js, p_obj, "constructor"); if (is_err(ctor)) return ctor; if (vtype(ctor) == T_UNDEF) ctor = get_slot(js, p_obj, SLOT_CTOR); - jsval_t species = get_ctor_species_value(js, ctor); + ant_value_t species = get_ctor_species_value(js, ctor); if (is_err(species)) return species; if (vtype(species) == T_FUNC || vtype(species) == T_CFUNC) { @@ -10663,25 +10663,25 @@ static jsval_t builtin_promise_then(ant_t *js, jsval_t *args, int nargs) { return js_mkerr_typed(js, JS_ERR_TYPE, "Promise species is not a constructor"); } - jsval_t nextP = mkpromise(js); + ant_value_t nextP = mkpromise(js); if ((vtype(species_ctor) == T_FUNC || vtype(species_ctor) == T_CFUNC) && !(vtype(species_ctor) == vtype(promise_ctor) && vdata(species_ctor) == vdata(promise_ctor))) { - jsval_t species_proto = js_get(js, species_ctor, "prototype"); + ant_value_t species_proto = js_get(js, species_ctor, "prototype"); if (is_object_type(species_proto)) set_proto(js, js_as_obj(nextP), species_proto); set_slot(js, js_as_obj(nextP), SLOT_CTOR, species_ctor); } else { - jsval_t p_proto = get_slot(js, js_as_obj(p), SLOT_PROTO); + ant_value_t p_proto = get_slot(js, js_as_obj(p), SLOT_PROTO); if (vtype(p_proto) == T_OBJ) { set_slot(js, js_as_obj(nextP), SLOT_PROTO, p_proto); - jsval_t p_ctor = get_slot(js, js_as_obj(p), SLOT_CTOR); + ant_value_t p_ctor = get_slot(js, js_as_obj(p), SLOT_CTOR); if (vtype(p_ctor) == T_FUNC) set_slot(js, js_as_obj(nextP), SLOT_CTOR, p_ctor); } } - jsval_t onFulfilled = nargs > 0 ? args[0] : js_mkundef(); - jsval_t onRejected = nargs > 1 ? args[1] : js_mkundef(); + ant_value_t onFulfilled = nargs > 0 ? args[0] : js_mkundef(); + ant_value_t onRejected = nargs > 1 ? args[1] : js_mkundef(); uint32_t pid = get_promise_id(js, p); uint32_t next_pid = get_promise_id(js, nextP); @@ -10706,138 +10706,138 @@ static jsval_t builtin_promise_then(ant_t *js, jsval_t *args, int nargs) { return nextP; } -static jsval_t builtin_promise_catch(ant_t *js, jsval_t *args, int nargs) { - jsval_t args_then[] = { js_mkundef(), nargs > 0 ? args[0] : js_mkundef() }; +static ant_value_t builtin_promise_catch(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t args_then[] = { js_mkundef(), nargs > 0 ? args[0] : js_mkundef() }; return builtin_promise_then(js, args_then, 2); } -static jsval_t finally_value_thunk(ant_t *js, jsval_t *args, int nargs) { - jsval_t me = js->current_func; +static ant_value_t finally_value_thunk(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t me = js->current_func; return get_slot(js, me, SLOT_DATA); } -static jsval_t finally_thrower(ant_t *js, jsval_t *args, int nargs) { - jsval_t me = js->current_func; - jsval_t reason = get_slot(js, me, SLOT_DATA); - jsval_t rejected = js_mkpromise(js); +static ant_value_t finally_thrower(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t me = js->current_func; + ant_value_t reason = get_slot(js, me, SLOT_DATA); + ant_value_t rejected = js_mkpromise(js); js_reject_promise(js, rejected, reason); return rejected; } -static jsval_t finally_identity_reject(ant_t *js, jsval_t *args, int nargs) { - jsval_t reason = nargs > 0 ? args[0] : js_mkundef(); - jsval_t rejected = js_mkpromise(js); +static ant_value_t finally_identity_reject(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t reason = nargs > 0 ? args[0] : js_mkundef(); + ant_value_t rejected = js_mkpromise(js); js_reject_promise(js, rejected, reason); return rejected; } -static jsval_t finally_fulfilled_wrapper(ant_t *js, jsval_t *args, int nargs) { - jsval_t me = js->current_func; - jsval_t callback = get_slot(js, me, SLOT_DATA); - jsval_t value = nargs > 0 ? args[0] : js_mkundef(); +static ant_value_t finally_fulfilled_wrapper(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t me = js->current_func; + ant_value_t callback = get_slot(js, me, SLOT_DATA); + ant_value_t value = nargs > 0 ? args[0] : js_mkundef(); - jsval_t result = js_mkundef(); + ant_value_t result = js_mkundef(); if (vtype(callback) == T_FUNC || vtype(callback) == T_CFUNC) { result = sv_vm_call(js->vm, js, callback, js_mkundef(), NULL, 0, NULL, false); if (is_err(result)) return result; } if (vtype(result) == T_PROMISE || (vtype(result) == T_OBJ && vtype(js_get(js, result, "then")) == T_FUNC)) { - jsval_t thunk_obj = mkobj(js, 0); + ant_value_t thunk_obj = mkobj(js, 0); set_slot(js, thunk_obj, SLOT_DATA, value); set_slot(js, thunk_obj, SLOT_CFUNC, js_mkfun(finally_value_thunk)); - jsval_t thunk_fn = js_obj_to_func(thunk_obj); + ant_value_t thunk_fn = js_obj_to_func(thunk_obj); - jsval_t identity_rej_fn = js_mkfun(finally_identity_reject); + ant_value_t identity_rej_fn = js_mkfun(finally_identity_reject); - jsval_t then_fn = js_get(js, result, "then"); - jsval_t call_args[] = { thunk_fn, identity_rej_fn }; + ant_value_t then_fn = js_get(js, result, "then"); + ant_value_t call_args[] = { thunk_fn, identity_rej_fn }; return sv_vm_call(js->vm, js, then_fn, result, call_args, 2, NULL, false); } return value; } -static jsval_t finally_rejected_wrapper(ant_t *js, jsval_t *args, int nargs) { - jsval_t me = js->current_func; - jsval_t callback = get_slot(js, me, SLOT_DATA); - jsval_t reason = nargs > 0 ? args[0] : js_mkundef(); +static ant_value_t finally_rejected_wrapper(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t me = js->current_func; + ant_value_t callback = get_slot(js, me, SLOT_DATA); + ant_value_t reason = nargs > 0 ? args[0] : js_mkundef(); - jsval_t result = js_mkundef(); + ant_value_t result = js_mkundef(); if (vtype(callback) == T_FUNC || vtype(callback) == T_CFUNC) { result = sv_vm_call(js->vm, js, callback, js_mkundef(), NULL, 0, NULL, false); if (is_err(result)) return result; } if (vtype(result) == T_PROMISE || (vtype(result) == T_OBJ && vtype(js_get(js, result, "then")) == T_FUNC)) { - jsval_t thrower_obj = mkobj(js, 0); + ant_value_t thrower_obj = mkobj(js, 0); set_slot(js, thrower_obj, SLOT_DATA, reason); set_slot(js, thrower_obj, SLOT_CFUNC, js_mkfun(finally_thrower)); - jsval_t thrower_fn = js_obj_to_func(thrower_obj); - jsval_t identity_rej_fn = js_mkfun(finally_identity_reject); + ant_value_t thrower_fn = js_obj_to_func(thrower_obj); + ant_value_t identity_rej_fn = js_mkfun(finally_identity_reject); - jsval_t then_prop = js_get(js, result, "then"); - jsval_t call_args[] = { thrower_fn, identity_rej_fn }; + ant_value_t then_prop = js_get(js, result, "then"); + ant_value_t call_args[] = { thrower_fn, identity_rej_fn }; return sv_vm_call(js->vm, js, then_prop, result, call_args, 2, NULL, false); } - jsval_t rejected = js_mkpromise(js); + ant_value_t rejected = js_mkpromise(js); js_reject_promise(js, rejected, reason); return rejected; } -static jsval_t builtin_promise_finally(ant_t *js, jsval_t *args, int nargs) { - jsval_t callback = nargs > 0 ? args[0] : js_mkundef(); +static ant_value_t builtin_promise_finally(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t callback = nargs > 0 ? args[0] : js_mkundef(); - jsval_t fulfilled_obj = mkobj(js, 0); + ant_value_t fulfilled_obj = mkobj(js, 0); set_slot(js, fulfilled_obj, SLOT_DATA, callback); set_slot(js, fulfilled_obj, SLOT_CFUNC, js_mkfun(finally_fulfilled_wrapper)); - jsval_t fulfilled_fn = js_obj_to_func(fulfilled_obj); + ant_value_t fulfilled_fn = js_obj_to_func(fulfilled_obj); - jsval_t rejected_obj = mkobj(js, 0); + ant_value_t rejected_obj = mkobj(js, 0); set_slot(js, rejected_obj, SLOT_DATA, callback); set_slot(js, rejected_obj, SLOT_CFUNC, js_mkfun(finally_rejected_wrapper)); - jsval_t rejected_fn = js_obj_to_func(rejected_obj); + ant_value_t rejected_fn = js_obj_to_func(rejected_obj); - jsval_t args_then[] = { fulfilled_fn, rejected_fn }; + ant_value_t args_then[] = { fulfilled_fn, rejected_fn }; return builtin_promise_then(js, args_then, 2); } -static jsval_t builtin_Promise_try(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Promise_try(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return builtin_Promise_resolve(js, args, 0); - jsval_t fn = args[0]; - jsval_t *call_args = nargs > 1 ? &args[1] : NULL; + ant_value_t fn = args[0]; + ant_value_t *call_args = nargs > 1 ? &args[1] : NULL; int call_nargs = nargs > 1 ? nargs - 1 : 0; - jsval_t res = sv_vm_call(js->vm, js, fn, js_mkundef(), call_args, call_nargs, NULL, false); + ant_value_t res = sv_vm_call(js->vm, js, fn, js_mkundef(), call_args, call_nargs, NULL, false); if (is_err(res)) { - jsval_t reject_val = js->thrown_value; + ant_value_t reject_val = js->thrown_value; if (vtype(reject_val) == T_UNDEF) reject_val = res; js->thrown_exists = false; js->thrown_value = js_mkundef(); js->thrown_stack = js_mkundef(); - jsval_t rej_args[] = { reject_val }; + ant_value_t rej_args[] = { reject_val }; return builtin_Promise_reject(js, rej_args, 1); } - jsval_t res_args[] = { res }; + ant_value_t res_args[] = { res }; return builtin_Promise_resolve(js, res_args, 1); } -static jsval_t builtin_Promise_withResolvers(ant_t *js, jsval_t *args, int nargs) { - jsval_t p = mkpromise(js); +static ant_value_t builtin_Promise_withResolvers(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t p = mkpromise(js); - jsval_t res_obj = mkobj(js, 0); + ant_value_t res_obj = mkobj(js, 0); set_slot(js, res_obj, SLOT_DATA, p); set_slot(js, res_obj, SLOT_CFUNC, js_mkfun(builtin_resolve_internal)); - jsval_t res_fn = js_obj_to_func(res_obj); + ant_value_t res_fn = js_obj_to_func(res_obj); - jsval_t rej_obj = mkobj(js, 0); + ant_value_t rej_obj = mkobj(js, 0); set_slot(js, rej_obj, SLOT_DATA, p); set_slot(js, rej_obj, SLOT_CFUNC, js_mkfun(builtin_reject_internal)); - jsval_t rej_fn = js_obj_to_func(rej_obj); + ant_value_t rej_fn = js_obj_to_func(rej_obj); - jsval_t result = js_newobj(js); + ant_value_t result = js_newobj(js); js_setprop(js, result, js_mkstr(js, "promise", 7), p); js_setprop(js, result, js_mkstr(js, "resolve", 7), res_fn); js_setprop(js, result, js_mkstr(js, "reject", 6), rej_fn); @@ -10845,81 +10845,81 @@ static jsval_t builtin_Promise_withResolvers(ant_t *js, jsval_t *args, int nargs return result; } -static jsval_t mkpromise_with_ctor(ant_t *js, jsval_t ctor) { - jsval_t p = mkpromise(js); +static ant_value_t mkpromise_with_ctor(ant_t *js, ant_value_t ctor) { + ant_value_t p = mkpromise(js); if (vtype(ctor) != T_FUNC && vtype(ctor) != T_CFUNC) return p; - jsval_t proto = js_get(js, ctor, "prototype"); + ant_value_t proto = js_get(js, ctor, "prototype"); if (is_err(proto)) return proto; if (is_object_type(proto)) { - jsval_t p_obj = js_as_obj(p); + ant_value_t p_obj = js_as_obj(p); set_slot(js, p_obj, SLOT_CTOR, ctor); set_slot(js, p_obj, SLOT_PROTO, proto); } return p; } -static jsval_t builtin_Promise_all_resolve_handler(ant_t *js, jsval_t *args, int nargs) { - jsval_t me = js->current_func; - jsval_t tracker = js_get(js, me, "tracker"); - jsval_t index_val = js_get(js, me, "index"); +static ant_value_t builtin_Promise_all_resolve_handler(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t me = js->current_func; + ant_value_t tracker = js_get(js, me, "tracker"); + ant_value_t index_val = js_get(js, me, "index"); int index = (int)tod(index_val); - jsval_t value = nargs > 0 ? args[0] : js_mkundef(); + ant_value_t value = nargs > 0 ? args[0] : js_mkundef(); - jsval_t results = js_get(js, tracker, "results"); - arr_set(js, results, (jsoff_t)index, value); + ant_value_t results = js_get(js, tracker, "results"); + arr_set(js, results, (ant_offset_t)index, value); - jsval_t remaining_val = js_get(js, tracker, "remaining"); + ant_value_t remaining_val = js_get(js, tracker, "remaining"); int remaining = (int)tod(remaining_val) - 1; js_setprop(js, tracker, js_mkstr(js, "remaining", 9), tov((double)remaining)); if (remaining == 0) { - jsval_t result_promise = get_slot(js, tracker, SLOT_DATA); + ant_value_t result_promise = get_slot(js, tracker, SLOT_DATA); resolve_promise(js, result_promise, mkval(T_ARR, vdata(results))); } return js_mkundef(); } -static jsval_t builtin_Promise_all_reject_handler(ant_t *js, jsval_t *args, int nargs) { - jsval_t me = js->current_func; - jsval_t tracker = js_get(js, me, "tracker"); - jsval_t result_promise = get_slot(js, tracker, SLOT_DATA); +static ant_value_t builtin_Promise_all_reject_handler(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t me = js->current_func; + ant_value_t tracker = js_get(js, me, "tracker"); + ant_value_t result_promise = get_slot(js, tracker, SLOT_DATA); - jsval_t reason = nargs > 0 ? args[0] : js_mkundef(); + ant_value_t reason = nargs > 0 ? args[0] : js_mkundef(); reject_promise(js, result_promise, reason); return js_mkundef(); } typedef struct { - jsval_t tracker; + ant_value_t tracker; int index; } promise_all_iter_ctx_t; -static iter_action_t promise_all_iter_cb(ant_t *js, jsval_t value, void *ctx, jsval_t *out) { +static iter_action_t promise_all_iter_cb(ant_t *js, ant_value_t value, void *ctx, ant_value_t *out) { promise_all_iter_ctx_t *pctx = (promise_all_iter_ctx_t *)ctx; - jsval_t item = value; + ant_value_t item = value; if (vtype(item) != T_PROMISE) { - jsval_t wrap_args[] = { item }; + ant_value_t wrap_args[] = { item }; item = builtin_Promise_resolve(js, wrap_args, 1); } - jsval_t resolve_obj = mkobj(js, 0); + ant_value_t resolve_obj = mkobj(js, 0); set_slot(js, resolve_obj, SLOT_CFUNC, js_mkfun(builtin_Promise_all_resolve_handler)); js_setprop(js, resolve_obj, js_mkstr(js, "index", 5), tov((double)pctx->index)); js_setprop(js, resolve_obj, js_mkstr(js, "tracker", 7), pctx->tracker); - jsval_t resolve_fn = js_obj_to_func(resolve_obj); + ant_value_t resolve_fn = js_obj_to_func(resolve_obj); - jsval_t reject_obj = mkobj(js, 0); + ant_value_t reject_obj = mkobj(js, 0); set_slot(js, reject_obj, SLOT_CFUNC, js_mkfun(builtin_Promise_all_reject_handler)); js_setprop(js, reject_obj, js_mkstr(js, "tracker", 7), pctx->tracker); - jsval_t reject_fn = js_obj_to_func(reject_obj); + ant_value_t reject_fn = js_obj_to_func(reject_obj); - jsval_t then_args[] = { resolve_fn, reject_fn }; - jsval_t saved_this = js->this_val; + ant_value_t then_args[] = { resolve_fn, reject_fn }; + ant_value_t saved_this = js->this_val; js->this_val = item; builtin_promise_then(js, then_args, 2); js->this_val = saved_this; @@ -10928,37 +10928,37 @@ static iter_action_t promise_all_iter_cb(ant_t *js, jsval_t value, void *ctx, js return ITER_CONTINUE; } -static jsval_t builtin_Promise_all(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Promise_all(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "Promise.all requires an iterable"); - jsval_t iterable = args[0]; + ant_value_t iterable = args[0]; uint8_t t = vtype(iterable); if (t != T_ARR && t != T_OBJ) return js_mkerr(js, "Promise.all requires an iterable"); - jsval_t ctor = js->this_val; + ant_value_t ctor = js->this_val; if (vtype(ctor) != T_FUNC && vtype(ctor) != T_CFUNC) ctor = js_mkundef(); - jsval_t result_promise = mkpromise_with_ctor(js, ctor); + ant_value_t result_promise = mkpromise_with_ctor(js, ctor); if (is_err(result_promise)) return result_promise; - jsval_t tracker = mkobj(js, 0); - jsval_t results = mkarr(js); + ant_value_t tracker = mkobj(js, 0); + ant_value_t results = mkarr(js); js_setprop(js, tracker, js_mkstr(js, "remaining", 9), tov(0.0)); js_setprop(js, tracker, js_mkstr(js, "results", 7), results); set_slot(js, tracker, SLOT_DATA, result_promise); promise_all_iter_ctx_t ctx = { .tracker = tracker, .index = 0 }; - jsval_t iter_result = iter_foreach(js, iterable, promise_all_iter_cb, &ctx); + ant_value_t iter_result = iter_foreach(js, iterable, promise_all_iter_cb, &ctx); if (is_err(iter_result)) return iter_result; int len = ctx.index; { - jsoff_t doff = get_dense_buf(js, results); + ant_offset_t doff = get_dense_buf(js, results); if (doff) { - if ((jsoff_t)len > dense_capacity(js, doff)) doff = dense_grow(js, results, (jsoff_t)len); - if (doff) dense_set_length(js, doff, (jsoff_t)len); + if ((ant_offset_t)len > dense_capacity(js, doff)) doff = dense_grow(js, results, (ant_offset_t)len); + if (doff) dense_set_length(js, doff, (ant_offset_t)len); } } @@ -10972,15 +10972,15 @@ static jsval_t builtin_Promise_all(ant_t *js, jsval_t *args, int nargs) { } typedef struct { - jsval_t result_promise; - jsval_t resolve_fn; - jsval_t reject_fn; + ant_value_t result_promise; + ant_value_t resolve_fn; + ant_value_t reject_fn; bool settled; } promise_race_iter_ctx_t; -static iter_action_t promise_race_iter_cb(ant_t *js, jsval_t value, void *ctx, jsval_t *out) { +static iter_action_t promise_race_iter_cb(ant_t *js, ant_value_t value, void *ctx, ant_value_t *out) { promise_race_iter_ctx_t *pctx = (promise_race_iter_ctx_t *)ctx; - jsval_t item = value; + ant_value_t item = value; if (vtype(item) != T_PROMISE) { resolve_promise(js, pctx->result_promise, item); @@ -11002,8 +11002,8 @@ static iter_action_t promise_race_iter_cb(ant_t *js, jsval_t value, void *ctx, j } } - jsval_t then_args[] = { pctx->resolve_fn, pctx->reject_fn }; - jsval_t saved_this = js->this_val; + ant_value_t then_args[] = { pctx->resolve_fn, pctx->reject_fn }; + ant_value_t saved_this = js->this_val; js->this_val = item; builtin_promise_then(js, then_args, 2); js->this_val = saved_this; @@ -11011,27 +11011,27 @@ static iter_action_t promise_race_iter_cb(ant_t *js, jsval_t value, void *ctx, j return ITER_CONTINUE; } -static jsval_t builtin_Promise_race(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Promise_race(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "Promise.race requires an iterable"); - jsval_t iterable = args[0]; + ant_value_t iterable = args[0]; uint8_t t = vtype(iterable); if (t != T_ARR && t != T_OBJ) return js_mkerr(js, "Promise.race requires an iterable"); - jsval_t ctor = js->this_val; + ant_value_t ctor = js->this_val; if (vtype(ctor) != T_FUNC && vtype(ctor) != T_CFUNC) ctor = js_mkundef(); - jsval_t result_promise = mkpromise_with_ctor(js, ctor); + ant_value_t result_promise = mkpromise_with_ctor(js, ctor); if (is_err(result_promise)) return result_promise; - jsval_t resolve_obj = mkobj(js, 0); + ant_value_t resolve_obj = mkobj(js, 0); set_slot(js, resolve_obj, SLOT_CFUNC, js_mkfun(builtin_resolve_internal)); set_slot(js, resolve_obj, SLOT_DATA, result_promise); - jsval_t resolve_fn = js_obj_to_func(resolve_obj); + ant_value_t resolve_fn = js_obj_to_func(resolve_obj); - jsval_t reject_obj = mkobj(js, 0); + ant_value_t reject_obj = mkobj(js, 0); set_slot(js, reject_obj, SLOT_CFUNC, js_mkfun(builtin_reject_internal)); set_slot(js, reject_obj, SLOT_DATA, result_promise); - jsval_t reject_fn = js_obj_to_func(reject_obj); + ant_value_t reject_fn = js_obj_to_func(reject_obj); promise_race_iter_ctx_t ctx = { .result_promise = result_promise, @@ -11040,29 +11040,29 @@ static jsval_t builtin_Promise_race(ant_t *js, jsval_t *args, int nargs) { .settled = false }; - jsval_t iter_result = iter_foreach(js, iterable, promise_race_iter_cb, &ctx); + ant_value_t iter_result = iter_foreach(js, iterable, promise_race_iter_cb, &ctx); if (is_err(iter_result)) return iter_result; return result_promise; } -static jsval_t mk_aggregate_error(ant_t *js, jsval_t errors) { - jsval_t args[] = { errors, js_mkstr(js, "All promises were rejected", 26) }; - jsoff_t off = lkp(js, js_glob(js), "AggregateError", 14); - jsval_t ctor = off ? resolveprop(js, mkval(T_PROP, off)) : js_mkundef(); +static ant_value_t mk_aggregate_error(ant_t *js, ant_value_t errors) { + ant_value_t args[] = { errors, js_mkstr(js, "All promises were rejected", 26) }; + ant_offset_t off = lkp(js, js_glob(js), "AggregateError", 14); + ant_value_t ctor = off ? resolveprop(js, mkval(T_PROP, off)) : js_mkundef(); return sv_vm_call(js->vm, js, ctor, js_mkundef(), args, 2, NULL, false); } -static bool promise_any_try_resolve(ant_t *js, jsval_t tracker, jsval_t value) { +static bool promise_any_try_resolve(ant_t *js, ant_value_t tracker, ant_value_t value) { if (js_truthy(js, js_get(js, tracker, "resolved"))) return false; js_set(js, tracker, "resolved", js_true); resolve_promise(js, get_slot(js, tracker, SLOT_DATA), value); return true; } -static void promise_any_record_rejection(ant_t *js, jsval_t tracker, int index, jsval_t reason) { - jsval_t errors = resolveprop(js, js_get(js, tracker, "errors")); - arr_set(js, errors, (jsoff_t)index, reason); +static void promise_any_record_rejection(ant_t *js, ant_value_t tracker, int index, ant_value_t reason) { + ant_value_t errors = resolveprop(js, js_get(js, tracker, "errors")); + arr_set(js, errors, (ant_offset_t)index, reason); int remaining = (int)tod(js_get(js, tracker, "remaining")) - 1; js_set(js, tracker, "remaining", tov((double)remaining)); @@ -11070,14 +11070,14 @@ static void promise_any_record_rejection(ant_t *js, jsval_t tracker, int index, if (remaining == 0) reject_promise(js, get_slot(js, tracker, SLOT_DATA), mk_aggregate_error(js, errors)); } -static jsval_t builtin_Promise_any_resolve_handler(ant_t *js, jsval_t *args, int nargs) { - jsval_t tracker = js_get(js, js->this_val, "tracker"); +static ant_value_t builtin_Promise_any_resolve_handler(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t tracker = js_get(js, js->this_val, "tracker"); promise_any_try_resolve(js, tracker, nargs > 0 ? args[0] : js_mkundef()); return js_mkundef(); } -static jsval_t builtin_Promise_any_reject_handler(ant_t *js, jsval_t *args, int nargs) { - jsval_t tracker = js_get(js, js->this_val, "tracker"); +static ant_value_t builtin_Promise_any_reject_handler(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t tracker = js_get(js, js->this_val, "tracker"); if (js_truthy(js, js_get(js, tracker, "resolved"))) return js_mkundef(); int index = (int)tod(js_get(js, js->this_val, "index")); @@ -11085,22 +11085,22 @@ static jsval_t builtin_Promise_any_reject_handler(ant_t *js, jsval_t *args, int return js_mkundef(); } -static jsval_t builtin_Promise_any(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Promise_any(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "Promise.any requires an array"); - jsval_t arr = args[0]; + ant_value_t arr = args[0]; if (vtype(arr) != T_ARR) return js_mkerr(js, "Promise.any requires an array"); int len = (int)get_array_length(js, arr); if (len == 0) { - jsval_t reject_args[] = { mk_aggregate_error(js, mkarr(js)) }; + ant_value_t reject_args[] = { mk_aggregate_error(js, mkarr(js)) }; return builtin_Promise_reject(js, reject_args, 1); } - jsval_t result_promise = mkpromise(js); - jsval_t tracker = mkobj(js, 0); - jsval_t errors = mkarr(js); + ant_value_t result_promise = mkpromise(js); + ant_value_t tracker = mkobj(js, 0); + ant_value_t errors = mkarr(js); set_slot(js, tracker, SLOT_DATA, result_promise); @@ -11109,15 +11109,15 @@ static jsval_t builtin_Promise_any(ant_t *js, jsval_t *args, int nargs) { js_setprop(js, tracker, js_mkstr(js, "resolved", 8), js_false); { - jsoff_t doff = get_dense_buf(js, errors); + ant_offset_t doff = get_dense_buf(js, errors); if (doff) { - if ((jsoff_t)len > dense_capacity(js, doff)) doff = dense_grow(js, errors, (jsoff_t)len); - if (doff) dense_set_length(js, doff, (jsoff_t)len); + if ((ant_offset_t)len > dense_capacity(js, doff)) doff = dense_grow(js, errors, (ant_offset_t)len); + if (doff) dense_set_length(js, doff, (ant_offset_t)len); } } for (int i = 0; i < len; i++) { - jsval_t item = arr_get(js, arr, (jsoff_t)i); + ant_value_t item = arr_get(js, arr, (ant_offset_t)i); item = resolveprop(js, item); if (vtype(item) != T_PROMISE) { @@ -11142,17 +11142,17 @@ static jsval_t builtin_Promise_any(ant_t *js, jsval_t *args, int nargs) { } } - jsval_t resolve_obj = mkobj(js, 0); + ant_value_t resolve_obj = mkobj(js, 0); set_slot(js, resolve_obj, SLOT_CFUNC, js_mkfun(builtin_Promise_any_resolve_handler)); js_setprop(js, resolve_obj, js_mkstr(js, "tracker", 7), tracker); - jsval_t reject_obj = mkobj(js, 0); + ant_value_t reject_obj = mkobj(js, 0); set_slot(js, reject_obj, SLOT_CFUNC, js_mkfun(builtin_Promise_any_reject_handler)); js_setprop(js, reject_obj, js_mkstr(js, "index", 5), tov((double)i)); js_setprop(js, reject_obj, js_mkstr(js, "tracker", 7), tracker); - jsval_t then_args[] = { js_obj_to_func(resolve_obj), js_obj_to_func(reject_obj) }; - jsval_t saved_this = js->this_val; + ant_value_t then_args[] = { js_obj_to_func(resolve_obj), js_obj_to_func(reject_obj) }; + ant_value_t saved_this = js->this_val; js->this_val = item; builtin_promise_then(js, then_args, 2); js->this_val = saved_this; @@ -11161,8 +11161,8 @@ static jsval_t builtin_Promise_any(ant_t *js, jsval_t *args, int nargs) { return result_promise; } -static jsval_t handle_proxy_instanceof(ant_t *js, jsval_t l, jsval_t r, uint8_t ltype) { - jsval_t target = proxy_read_target(js, r); +static ant_value_t handle_proxy_instanceof(ant_t *js, ant_value_t l, ant_value_t r, uint8_t ltype) { + ant_value_t target = proxy_read_target(js, r); uint8_t ttype = vtype(target); if (ttype != T_FUNC && ttype != T_CFUNC) { @@ -11170,12 +11170,12 @@ static jsval_t handle_proxy_instanceof(ant_t *js, jsval_t l, jsval_t r, uint8_t } { - jsval_t has_instance = js_get_sym(js, r, get_hasInstance_sym()); + ant_value_t has_instance = js_get_sym(js, r, get_hasInstance_sym()); if (is_err(has_instance)) return has_instance; uint8_t hit = vtype(has_instance); if (hit == T_FUNC || hit == T_CFUNC) { - jsval_t args[1] = { l }; - jsval_t result = sv_vm_call(js->vm, js, has_instance, r, args, 1, NULL, false); + ant_value_t args[1] = { l }; + ant_value_t result = sv_vm_call(js->vm, js, has_instance, r, args, 1, NULL, false); if (is_err(result)) return result; return js_bool(js_truthy(js, result)); } @@ -11184,7 +11184,7 @@ static jsval_t handle_proxy_instanceof(ant_t *js, jsval_t l, jsval_t r, uint8_t } } - jsval_t proto_val = proxy_get(js, r, "prototype", 9); + ant_value_t proto_val = proxy_get(js, r, "prototype", 9); uint8_t pt = vtype(proto_val); if (pt != T_OBJ && pt != T_ARR && pt != T_FUNC) { @@ -11195,7 +11195,7 @@ static jsval_t handle_proxy_instanceof(ant_t *js, jsval_t l, jsval_t r, uint8_t return mkval(T_BOOL, 0); } - jsval_t current = get_proto(js, l); + ant_value_t current = get_proto(js, l); for (int depth = 0; vtype(current) != T_NULL && depth < 32; depth++) { if (vdata(current) == vdata(proto_val)) { return mkval(T_BOOL, 1); @@ -11206,8 +11206,8 @@ static jsval_t handle_proxy_instanceof(ant_t *js, jsval_t l, jsval_t r, uint8_t return mkval(T_BOOL, 0); } -static jsval_t handle_cfunc_instanceof(jsval_t l, jsval_t r, uint8_t ltype) { - jsval_t (*fn)(ant_t *, jsval_t *, int) = (jsval_t(*)(ant_t *, jsval_t *, int)) vdata(r); +static ant_value_t handle_cfunc_instanceof(ant_value_t l, ant_value_t r, uint8_t ltype) { + ant_value_t (*fn)(ant_t *, ant_value_t *, int) = (ant_value_t(*)(ant_t *, ant_value_t *, int)) vdata(r); if (fn == builtin_Object) return mkval(T_BOOL, ltype == T_OBJ ? 1 : 0); if (fn == builtin_Function) return mkval(T_BOOL, (ltype == T_FUNC || ltype == T_CFUNC) ? 1 : 0); @@ -11220,8 +11220,8 @@ static jsval_t handle_cfunc_instanceof(jsval_t l, jsval_t r, uint8_t ltype) { return mkval(T_BOOL, 0); } -static jsval_t walk_prototype_chain(ant_t *js, jsval_t l, jsval_t ctor_proto) { - jsval_t current = get_proto(js, l); +static ant_value_t walk_prototype_chain(ant_t *js, ant_value_t l, ant_value_t ctor_proto) { + ant_value_t current = get_proto(js, l); const int MAX_DEPTH = 32; for (int depth = 0; vtype(current) != T_NULL && depth < MAX_DEPTH; depth++) { @@ -11232,7 +11232,7 @@ static jsval_t walk_prototype_chain(ant_t *js, jsval_t l, jsval_t ctor_proto) { return mkval(T_BOOL, 0); } -jsval_t do_instanceof(ant_t *js, jsval_t l, jsval_t r) { +ant_value_t do_instanceof(ant_t *js, ant_value_t l, ant_value_t r) { uint8_t ltype = vtype(l); uint8_t rtype = vtype(r); @@ -11246,12 +11246,12 @@ jsval_t do_instanceof(ant_t *js, jsval_t l, jsval_t r) { } { - jsval_t has_instance = js_get_sym(js, r, get_hasInstance_sym()); + ant_value_t has_instance = js_get_sym(js, r, get_hasInstance_sym()); if (is_err(has_instance)) return has_instance; uint8_t hit = vtype(has_instance); if (hit == T_FUNC || hit == T_CFUNC) { - jsval_t args[1] = { l }; - jsval_t result = sv_vm_call(js->vm, js, has_instance, r, args, 1, NULL, false); + ant_value_t args[1] = { l }; + ant_value_t result = sv_vm_call(js->vm, js, has_instance, r, args, 1, NULL, false); if (is_err(result)) return result; return js_bool(js_truthy(js, result)); } @@ -11260,16 +11260,16 @@ jsval_t do_instanceof(ant_t *js, jsval_t l, jsval_t r) { } } - jsval_t func_obj = js_func_obj(r); - jsoff_t proto_off = lkp_interned(js, func_obj, INTERN_PROTOTYPE, 9); + ant_value_t func_obj = js_func_obj(r); + ant_offset_t proto_off = lkp_interned(js, func_obj, INTERN_PROTOTYPE, 9); if (proto_off == 0) return mkval(T_BOOL, 0); - jsval_t ctor_proto = resolveprop(js, mkval(T_PROP, proto_off)); + ant_value_t ctor_proto = resolveprop(js, mkval(T_PROP, proto_off)); uint8_t pt = vtype(ctor_proto); if (pt != T_OBJ && pt != T_ARR && pt != T_FUNC) return mkval(T_BOOL, 0); if (ltype == T_STR || ltype == T_NUM || ltype == T_BOOL) { - jsval_t type_proto = get_prototype_for_type(js, ltype); + ant_value_t type_proto = get_prototype_for_type(js, ltype); return mkval(T_BOOL, vdata(ctor_proto) == vdata(type_proto) ? 1 : 0); } @@ -11280,12 +11280,12 @@ jsval_t do_instanceof(ant_t *js, jsval_t l, jsval_t r) { return walk_prototype_chain(js, l, ctor_proto); } -jsval_t do_in(ant_t *js, jsval_t l, jsval_t r) { - jsoff_t prop_len; +ant_value_t do_in(ant_t *js, ant_value_t l, ant_value_t r) { + ant_offset_t prop_len; const char *prop_name; char num_buf[32]; - jsval_t key = js_to_primitive(js, l, 1); + ant_value_t key = js_to_primitive(js, l, 1); if (is_err(key)) return key; bool is_sym = (vtype(key) == T_SYMBOL); @@ -11293,14 +11293,14 @@ jsval_t do_in(ant_t *js, jsval_t l, jsval_t r) { if (is_sym) { const char *d = js_sym_desc(js, key); prop_name = d ? d : "symbol"; - prop_len = (jsoff_t)strlen(prop_name); + prop_len = (ant_offset_t)strlen(prop_name); } else if (vtype(key) == T_NUM) { - prop_len = (jsoff_t)strnum(key, num_buf, sizeof(num_buf)); + prop_len = (ant_offset_t)strnum(key, num_buf, sizeof(num_buf)); prop_name = num_buf; } else { - jsval_t key_str = js_tostring_val(js, key); + ant_value_t key_str = js_tostring_val(js, key); if (is_err(key_str)) return key_str; - jsoff_t prop_off = vstr(js, key_str, &prop_len); + ant_offset_t prop_off = vstr(js, key_str, &prop_len); prop_name = (char *)&js->mem[prop_off]; } @@ -11310,37 +11310,37 @@ jsval_t do_in(ant_t *js, jsval_t l, jsval_t r) { } if (is_proxy(js, r)) { - jsval_t result = is_sym ? proxy_has_val(js, r, key) : proxy_has(js, r, prop_name, prop_len); + ant_value_t result = is_sym ? proxy_has_val(js, r, key) : proxy_has(js, r, prop_name, prop_len); if (is_err(result)) return result; return js_bool(js_truthy(js, result)); } if (!is_sym && vtype(r) == T_ARR) { unsigned long idx; - jsoff_t arr_len = get_array_length(js, r); - if (parse_array_index(prop_name, prop_len, arr_len, &idx)) return mkval(T_BOOL, arr_has(js, r, (jsoff_t)idx) ? 1 : 0); + ant_offset_t arr_len = get_array_length(js, r); + if (parse_array_index(prop_name, prop_len, arr_len, &idx)) return mkval(T_BOOL, arr_has(js, r, (ant_offset_t)idx) ? 1 : 0); if (prop_len == 6 && memcmp(prop_name, "length", 6) == 0) return mkval(T_BOOL, 1); } - jsoff_t found = is_sym ? lkp_sym_proto(js, r, (jsoff_t)vdata(key)) : lkp_proto(js, r, prop_name, prop_len); + ant_offset_t found = is_sym ? lkp_sym_proto(js, r, (ant_offset_t)vdata(key)) : lkp_proto(js, r, prop_name, prop_len); return mkval(T_BOOL, found != 0 ? 1 : 0); } -static jsval_t builtin_import(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_import(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "import() requires a string specifier"); - jsval_t ns = js_esm_import_sync(js, args[0]); + ant_value_t ns = js_esm_import_sync(js, args[0]); if (is_err(ns)) return builtin_Promise_reject(js, &ns, 1); - jsval_t promise_args[] = { ns }; + ant_value_t promise_args[] = { ns }; return builtin_Promise_resolve(js, promise_args, 1); } -static jsval_t builtin_import_meta_resolve(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_import_meta_resolve(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "import.meta.resolve() requires a string specifier"); if (vtype(js->import_meta) == T_OBJ) { - jsval_t filename = js_get(js, js->import_meta, "filename"); + ant_value_t filename = js_get(js, js->import_meta, "filename"); if (vtype(filename) == T_STR) { - jsoff_t n = 0; jsoff_t off = vstr(js, filename, &n); + ant_offset_t n = 0; ant_offset_t off = vstr(js, filename, &n); return js_esm_resolve_specifier(js, args[0], (const char *)&js->mem[off]); } } return js_esm_resolve_specifier(js, args[0], NULL); @@ -11349,14 +11349,14 @@ static jsval_t builtin_import_meta_resolve(ant_t *js, jsval_t *args, int nargs) void js_setup_import_meta(ant_t *js, const char *filename) { if (!filename) return; - jsval_t import_meta = mkobj(js, 0); + ant_value_t import_meta = mkobj(js, 0); if (is_err(import_meta)) return; bool is_url = esm_is_url(filename); - jsval_t url_val = is_url ? js_mkstr(js, filename, strlen(filename)) : js_esm_make_file_url(js, filename); + ant_value_t url_val = is_url ? js_mkstr(js, filename, strlen(filename)) : js_esm_make_file_url(js, filename); if (!is_err(url_val)) js_setprop(js, import_meta, js_mkstr(js, "url", 3), url_val); - jsval_t filename_val = js_mkstr(js, filename, strlen(filename)); + ant_value_t filename_val = js_mkstr(js, filename, strlen(filename)); if (!is_err(filename_val)) js_setprop(js, import_meta, js_mkstr(js, "filename", 8), filename_val); if (is_url) { @@ -11366,7 +11366,7 @@ void js_setup_import_meta(ant_t *js, const char *filename) { char *scheme_end = strstr(filename_copy, "://"); if (last_slash && scheme_end && last_slash > scheme_end + 2) { *last_slash = '\0'; - jsval_t dirname_val = js_mkstr(js, filename_copy, strlen(filename_copy)); + ant_value_t dirname_val = js_mkstr(js, filename_copy, strlen(filename_copy)); if (!is_err(dirname_val)) js_setprop(js, import_meta, js_mkstr(js, "dirname", 7), dirname_val); } free(filename_copy); @@ -11376,7 +11376,7 @@ void js_setup_import_meta(ant_t *js, const char *filename) { if (filename_copy) { char *dir = dirname(filename_copy); if (dir) { - jsval_t dirname_val = js_mkstr(js, dir, strlen(dir)); + ant_value_t dirname_val = js_mkstr(js, dir, strlen(dir)); if (!is_err(dirname_val)) js_setprop(js, import_meta, js_mkstr(js, "dirname", 7), dirname_val); } free(filename_copy); @@ -11384,126 +11384,126 @@ void js_setup_import_meta(ant_t *js, const char *filename) { } js_setprop(js, import_meta, js_mkstr(js, "main", 4), js_true); - jsval_t resolve_fn = js_mkfun(builtin_import_meta_resolve); + ant_value_t resolve_fn = js_mkfun(builtin_import_meta_resolve); js_setprop(js, import_meta, js_mkstr(js, "resolve", 7), resolve_fn); - jsval_t glob = js_glob(js); - jsoff_t import_off = lkp(js, glob, "import", 6); + ant_value_t glob = js_glob(js); + ant_offset_t import_off = lkp(js, glob, "import", 6); if (import_off != 0) { - jsval_t import_fn = resolveprop(js, mkval(T_PROP, import_off)); + ant_value_t import_fn = resolveprop(js, mkval(T_PROP, import_off)); if (vtype(import_fn) == T_FUNC) { - jsval_t import_obj = js_func_obj(import_fn); + ant_value_t import_obj = js_func_obj(import_fn); js_setprop(js, import_obj, js_mkstr(js, "meta", 4), import_meta); } } } -static proxy_data_t *get_proxy_data(jsval_t obj) { +static proxy_data_t *get_proxy_data(ant_value_t obj) { if (vtype(obj) != T_OBJ) return NULL; - jsoff_t off = (jsoff_t)vdata(obj); + ant_offset_t off = (ant_offset_t)vdata(obj); proxy_data_t *data = NULL; - HASH_FIND(hh, proxy_registry, &off, sizeof(jsoff_t), data); + HASH_FIND(hh, proxy_registry, &off, sizeof(ant_offset_t), data); return data; } -bool is_proxy(ant_t *js, jsval_t obj) { +bool is_proxy(ant_t *js, ant_value_t obj) { (void)js; return get_proxy_data(obj) != NULL; } -static jsval_t proxy_read_target(ant_t *js, jsval_t obj) { +static ant_value_t proxy_read_target(ant_t *js, ant_value_t obj) { proxy_data_t *data = get_proxy_data(obj); return data ? data->target : obj; } -static jsoff_t proxy_aware_length(ant_t *js, jsval_t obj) { - jsval_t src = is_proxy(js, obj) ? proxy_read_target(js, obj) : obj; +static ant_offset_t proxy_aware_length(ant_t *js, ant_value_t obj) { + ant_value_t src = is_proxy(js, obj) ? proxy_read_target(js, obj) : obj; if (vtype(src) == T_ARR) { - jsoff_t doff = get_dense_buf(js, src); + ant_offset_t doff = get_dense_buf(js, src); if (doff) return dense_length(js, doff); } - jsoff_t off = lkp_interned(js, src, INTERN_LENGTH, 6); + ant_offset_t off = lkp_interned(js, src, INTERN_LENGTH, 6); if (off == 0) return 0; - jsval_t len_val = resolveprop(js, mkval(T_PROP, off)); - return vtype(len_val) == T_NUM ? (jsoff_t)tod(len_val) : 0; + ant_value_t len_val = resolveprop(js, mkval(T_PROP, off)); + return vtype(len_val) == T_NUM ? (ant_offset_t)tod(len_val) : 0; } -static jsval_t proxy_aware_get_elem(ant_t *js, jsval_t obj, const char *key, size_t key_len) { - jsval_t src = is_proxy(js, obj) ? proxy_read_target(js, obj) : obj; - jsoff_t off = lkp(js, src, key, key_len); +static ant_value_t proxy_aware_get_elem(ant_t *js, ant_value_t obj, const char *key, size_t key_len) { + ant_value_t src = is_proxy(js, obj) ? proxy_read_target(js, obj) : obj; + ant_offset_t off = lkp(js, src, key, key_len); return off ? resolveprop(js, mkval(T_PROP, off)) : js_mkundef(); } -static jsval_t throw_proxy_error(ant_t *js, const char *message) { - jsval_t err_obj = mkobj(js, 0); +static ant_value_t throw_proxy_error(ant_t *js, const char *message) { + ant_value_t err_obj = mkobj(js, 0); js_setprop(js, err_obj, js_mkstr(js, "message", 7), js_mkstr(js, message, strlen(message))); js_setprop(js, err_obj, js_mkstr(js, "name", 4), js_mkstr(js, "TypeError", 9)); return js_throw(js, err_obj); } -static bool proxy_target_is_extensible(ant_t *js, jsval_t obj) { +static bool proxy_target_is_extensible(ant_t *js, ant_value_t obj) { uint8_t t = vtype(obj); if (t != T_OBJ && t != T_ARR && t != T_FUNC) return false; - jsval_t as_obj = js_as_obj(obj); + ant_value_t as_obj = js_as_obj(obj); if (js_truthy(js, get_slot(js, as_obj, SLOT_FROZEN))) return false; if (js_truthy(js, get_slot(js, as_obj, SLOT_SEALED))) return false; - jsval_t ext_slot = get_slot(js, as_obj, SLOT_EXTENSIBLE); + ant_value_t ext_slot = get_slot(js, as_obj, SLOT_EXTENSIBLE); if (vtype(ext_slot) != T_UNDEF) return js_truthy(js, ext_slot); return true; } -static jsoff_t proxy_target_prop_flags(ant_t *js, jsval_t target, jsoff_t prop_off) { +static ant_offset_t proxy_target_prop_flags(ant_t *js, ant_value_t target, ant_offset_t prop_off) { if (prop_off == 0) return 0; - jsoff_t obj_off = (jsoff_t)vdata(js_as_obj(target)); - jsoff_t head = loadoff(js, obj_off); + ant_offset_t obj_off = (ant_offset_t)vdata(js_as_obj(target)); + ant_offset_t head = loadoff(js, obj_off); if ((head & ~(3U | FLAGMASK)) == prop_off) return head; return loadoff(js, prop_off); } -static bool proxy_target_prop_is_nonconfig(ant_t *js, jsval_t target, jsoff_t prop_off) { +static bool proxy_target_prop_is_nonconfig(ant_t *js, ant_value_t target, ant_offset_t prop_off) { return (proxy_target_prop_flags(js, target, prop_off) & NONCONFIGMASK) != 0; } -static bool proxy_target_prop_is_const(ant_t *js, jsval_t target, jsoff_t prop_off) { +static bool proxy_target_prop_is_const(ant_t *js, ant_value_t target, ant_offset_t prop_off) { return (proxy_target_prop_flags(js, target, prop_off) & CONSTMASK) != 0; } -static jsval_t proxy_get(ant_t *js, jsval_t proxy, const char *key, size_t key_len) { +static ant_value_t proxy_get(ant_t *js, ant_value_t proxy, const char *key, size_t key_len) { proxy_data_t *data = get_proxy_data(proxy); if (!data) return js_mkundef(); if (data->revoked) return throw_proxy_error(js, "Cannot perform 'get' on a proxy that has been revoked"); - jsval_t target = data->target; - jsval_t handler = data->handler; + ant_value_t target = data->target; + ant_value_t handler = data->handler; - jsoff_t get_trap_off = vtype(handler) == T_OBJ + ant_offset_t get_trap_off = vtype(handler) == T_OBJ ? lkp_interned(js, handler, INTERN_GET, 3) : 0; if (get_trap_off != 0) { - jsval_t get_trap = resolveprop(js, mkval(T_PROP, get_trap_off)); + ant_value_t get_trap = resolveprop(js, mkval(T_PROP, get_trap_off)); if (vtype(get_trap) == T_FUNC || vtype(get_trap) == T_CFUNC) { - jsval_t key_val = js_mkstr(js, key, key_len); + ant_value_t key_val = js_mkstr(js, key, key_len); - jsval_t args[3] = { target, key_val, proxy }; - jsval_t result = sv_vm_call(js->vm, js, get_trap, js_mkundef(), args, 3, NULL, false); + ant_value_t args[3] = { target, key_val, proxy }; + ant_value_t result = sv_vm_call(js->vm, js, get_trap, js_mkundef(), args, 3, NULL, false); if (is_err(result)) return result; - jsoff_t prop_off = lkp(js, target, key, key_len); + ant_offset_t prop_off = lkp(js, target, key, key_len); if (prop_off != 0 && proxy_target_prop_is_nonconfig(js, target, prop_off) && proxy_target_prop_is_const(js, target, prop_off)) { - jsval_t target_value = resolveprop(js, mkval(T_PROP, prop_off)); + ant_value_t target_value = resolveprop(js, mkval(T_PROP, prop_off)); if (!strict_eq_values(js, result, target_value)) return js_mkerr_typed(js, JS_ERR_TYPE, "'get' on proxy: trap returned invalid value for non-configurable, non-writable property"); } - descriptor_entry_t *desc = lookup_descriptor(js, (jsoff_t)vdata(js_as_obj(target)), key, key_len); + descriptor_entry_t *desc = lookup_descriptor(js, (ant_offset_t)vdata(js_as_obj(target)), key, key_len); if (desc && !desc->configurable) { if (!desc->has_getter && !desc->has_setter && !desc->writable && prop_off != 0) { - jsval_t target_value = resolveprop(js, mkval(T_PROP, prop_off)); + ant_value_t target_value = resolveprop(js, mkval(T_PROP, prop_off)); if (!strict_eq_values(js, result, target_value)) return js_mkerr_typed(js, JS_ERR_TYPE, "'get' on proxy: trap returned invalid value for non-configurable, non-writable property"); } @@ -11520,44 +11520,44 @@ static jsval_t proxy_get(ant_t *js, jsval_t proxy, const char *key, size_t key_l memcpy(key_buf, key, len); key_buf[len] = '\0'; - jsoff_t off = lkp(js, target, key_buf, len); + ant_offset_t off = lkp(js, target, key_buf, len); if (off != 0) return resolveprop(js, mkval(T_PROP, off)); - jsoff_t proto_off = lkp_proto(js, target, key_buf, len); + ant_offset_t proto_off = lkp_proto(js, target, key_buf, len); if (proto_off != 0) return resolveprop(js, mkval(T_PROP, proto_off)); return js_mkundef(); } -static jsval_t proxy_set(ant_t *js, jsval_t proxy, const char *key, size_t key_len, jsval_t value) { +static ant_value_t proxy_set(ant_t *js, ant_value_t proxy, const char *key, size_t key_len, ant_value_t value) { proxy_data_t *data = get_proxy_data(proxy); if (!data) return js_mkundef(); if (data->revoked) return throw_proxy_error(js, "Cannot perform 'set' on a proxy that has been revoked"); - jsval_t target = data->target; - jsval_t handler = data->handler; + ant_value_t target = data->target; + ant_value_t handler = data->handler; - jsoff_t set_trap_off = vtype(handler) == T_OBJ ? lkp_interned(js, handler, INTERN_SET, 3) : 0; + ant_offset_t set_trap_off = vtype(handler) == T_OBJ ? lkp_interned(js, handler, INTERN_SET, 3) : 0; if (set_trap_off != 0) { - jsval_t set_trap = resolveprop(js, mkval(T_PROP, set_trap_off)); + ant_value_t set_trap = resolveprop(js, mkval(T_PROP, set_trap_off)); if (vtype(set_trap) == T_FUNC || vtype(set_trap) == T_CFUNC) { - jsval_t key_val = js_mkstr(js, key, key_len); - jsval_t args[4] = { target, key_val, value, proxy }; - jsval_t result = sv_vm_call(js->vm, js, set_trap, js_mkundef(), args, 4, NULL, false); + ant_value_t key_val = js_mkstr(js, key, key_len); + ant_value_t args[4] = { target, key_val, value, proxy }; + ant_value_t result = sv_vm_call(js->vm, js, set_trap, js_mkundef(), args, 4, NULL, false); if (is_err(result)) return result; if (js_truthy(js, result)) { - jsoff_t prop_off = lkp(js, target, key, key_len); + ant_offset_t prop_off = lkp(js, target, key, key_len); if (prop_off != 0 && proxy_target_prop_is_nonconfig(js, target, prop_off) && proxy_target_prop_is_const(js, target, prop_off)) { - jsval_t target_value = resolveprop(js, mkval(T_PROP, prop_off)); + ant_value_t target_value = resolveprop(js, mkval(T_PROP, prop_off)); if (!strict_eq_values(js, value, target_value)) return js_mkerr_typed(js, JS_ERR_TYPE, "'set' on proxy: trap returned truthy for non-configurable, non-writable property with different value"); } - descriptor_entry_t *desc = lookup_descriptor(js, (jsoff_t)vdata(js_as_obj(target)), key, key_len); + descriptor_entry_t *desc = lookup_descriptor(js, (ant_offset_t)vdata(js_as_obj(target)), key, key_len); if (desc && !desc->configurable) { if (!desc->has_getter && !desc->has_setter && !desc->writable && prop_off != 0) { - jsval_t target_value = resolveprop(js, mkval(T_PROP, prop_off)); + ant_value_t target_value = resolveprop(js, mkval(T_PROP, prop_off)); if (!strict_eq_values(js, value, target_value)) return js_mkerr_typed(js, JS_ERR_TYPE, "'set' on proxy: trap returned truthy for non-configurable, non-writable property with different value"); } @@ -11569,31 +11569,31 @@ static jsval_t proxy_set(ant_t *js, jsval_t proxy, const char *key, size_t key_l } } - jsval_t key_str = js_mkstr(js, key, key_len); + ant_value_t key_str = js_mkstr(js, key, key_len); js_setprop(js, target, key_str, value); return js_true; } -static jsval_t proxy_has(ant_t *js, jsval_t proxy, const char *key, size_t key_len) { +static ant_value_t proxy_has(ant_t *js, ant_value_t proxy, const char *key, size_t key_len) { proxy_data_t *data = get_proxy_data(proxy); if (!data) return js_false; if (data->revoked) return throw_proxy_error(js, "Cannot perform 'has' on a proxy that has been revoked"); - jsval_t target = data->target; - jsval_t handler = data->handler; + ant_value_t target = data->target; + ant_value_t handler = data->handler; - jsoff_t has_trap_off = vtype(handler) == T_OBJ ? lkp(js, handler, "has", 3) : 0; + ant_offset_t has_trap_off = vtype(handler) == T_OBJ ? lkp(js, handler, "has", 3) : 0; if (has_trap_off != 0) { - jsval_t has_trap = resolveprop(js, mkval(T_PROP, has_trap_off)); + ant_value_t has_trap = resolveprop(js, mkval(T_PROP, has_trap_off)); if (vtype(has_trap) == T_FUNC || vtype(has_trap) == T_CFUNC) { - jsval_t key_val = js_mkstr(js, key, key_len); - jsval_t args[2] = { target, key_val }; - jsval_t result = sv_vm_call(js->vm, js, has_trap, js_mkundef(), args, 2, NULL, false); + ant_value_t key_val = js_mkstr(js, key, key_len); + ant_value_t args[2] = { target, key_val }; + ant_value_t result = sv_vm_call(js->vm, js, has_trap, js_mkundef(), args, 2, NULL, false); if (is_err(result)) return result; if (!js_truthy(js, result)) { - jsoff_t prop_off = lkp(js, target, key, key_len); - descriptor_entry_t *desc = lookup_descriptor(js, (jsoff_t)vdata(js_as_obj(target)), key, key_len); + ant_offset_t prop_off = lkp(js, target, key, key_len); + descriptor_entry_t *desc = lookup_descriptor(js, (ant_offset_t)vdata(js_as_obj(target)), key, key_len); bool has_own = (prop_off != 0) || (desc != NULL); if ((prop_off != 0 && proxy_target_prop_is_nonconfig(js, target, prop_off)) || (desc && !desc->configurable)) @@ -11612,31 +11612,31 @@ static jsval_t proxy_has(ant_t *js, jsval_t proxy, const char *key, size_t key_l memcpy(key_buf, key, len); key_buf[len] = '\0'; - jsoff_t off = lkp_proto(js, target, key_buf, len); + ant_offset_t off = lkp_proto(js, target, key_buf, len); return js_bool(off != 0); } -static jsval_t proxy_delete(ant_t *js, jsval_t proxy, const char *key, size_t key_len) { +static ant_value_t proxy_delete(ant_t *js, ant_value_t proxy, const char *key, size_t key_len) { proxy_data_t *data = get_proxy_data(proxy); if (!data) return js_true; if (data->revoked) return throw_proxy_error(js, "Cannot perform 'deleteProperty' on a proxy that has been revoked"); - jsval_t target = data->target; - jsval_t handler = data->handler; + ant_value_t target = data->target; + ant_value_t handler = data->handler; - jsoff_t delete_trap_off = vtype(handler) == T_OBJ ? lkp(js, handler, "deleteProperty", 14) : 0; + ant_offset_t delete_trap_off = vtype(handler) == T_OBJ ? lkp(js, handler, "deleteProperty", 14) : 0; if (delete_trap_off != 0) { - jsval_t delete_trap = resolveprop(js, mkval(T_PROP, delete_trap_off)); + ant_value_t delete_trap = resolveprop(js, mkval(T_PROP, delete_trap_off)); if (vtype(delete_trap) == T_FUNC || vtype(delete_trap) == T_CFUNC) { - jsval_t key_val = js_mkstr(js, key, key_len); - jsval_t args[2] = { target, key_val }; - jsval_t result = sv_vm_call(js->vm, js, delete_trap, js_mkundef(), args, 2, NULL, false); + ant_value_t key_val = js_mkstr(js, key, key_len); + ant_value_t args[2] = { target, key_val }; + ant_value_t result = sv_vm_call(js->vm, js, delete_trap, js_mkundef(), args, 2, NULL, false); if (is_err(result)) return result; if (js_truthy(js, result)) { - jsoff_t prop_off = lkp(js, target, key, key_len); + ant_offset_t prop_off = lkp(js, target, key, key_len); if (prop_off != 0 && is_nonconfig_prop(js, prop_off)) return js_mkerr_typed(js, JS_ERR_TYPE, "'deleteProperty' on proxy: trap returned truthy for non-configurable property"); - descriptor_entry_t *desc = lookup_descriptor(js, (jsoff_t)vdata(js_as_obj(target)), key, key_len); + descriptor_entry_t *desc = lookup_descriptor(js, (ant_offset_t)vdata(js_as_obj(target)), key, key_len); if (desc && !desc->configurable) return js_mkerr_typed(js, JS_ERR_TYPE, "'deleteProperty' on proxy: trap returned truthy for non-configurable property"); } @@ -11644,78 +11644,78 @@ static jsval_t proxy_delete(ant_t *js, jsval_t proxy, const char *key, size_t ke } } - jsval_t key_str = js_mkstr(js, key, key_len); + ant_value_t key_str = js_mkstr(js, key, key_len); js_setprop(js, target, key_str, js_mkundef()); return js_true; } -static jsval_t proxy_get_val(ant_t *js, jsval_t proxy, jsval_t key_val) { +static ant_value_t proxy_get_val(ant_t *js, ant_value_t proxy, ant_value_t key_val) { proxy_data_t *data = get_proxy_data(proxy); if (!data) return js_mkundef(); if (data->revoked) return throw_proxy_error(js, "Cannot perform 'get' on a proxy that has been revoked"); - jsval_t target = data->target; - jsval_t handler = data->handler; + ant_value_t target = data->target; + ant_value_t handler = data->handler; - jsoff_t get_trap_off = vtype(handler) == T_OBJ + ant_offset_t get_trap_off = vtype(handler) == T_OBJ ? lkp_interned(js, handler, INTERN_GET, 3) : 0; if (get_trap_off != 0) { - jsval_t get_trap = resolveprop(js, mkval(T_PROP, get_trap_off)); + ant_value_t get_trap = resolveprop(js, mkval(T_PROP, get_trap_off)); if (vtype(get_trap) == T_FUNC || vtype(get_trap) == T_CFUNC) { - jsval_t args[3] = { target, key_val, proxy }; + ant_value_t args[3] = { target, key_val, proxy }; return sv_vm_call(js->vm, js, get_trap, js_mkundef(), args, 3, NULL, false); } } if (vtype(key_val) == T_SYMBOL) { - jsoff_t off = lkp_sym_proto(js, target, (jsoff_t)vdata(key_val)); + ant_offset_t off = lkp_sym_proto(js, target, (ant_offset_t)vdata(key_val)); return off != 0 ? resolveprop(js, mkval(T_PROP, off)) : js_mkundef(); } return proxy_get(js, proxy, "", 0); } -static jsval_t proxy_has_val(ant_t *js, jsval_t proxy, jsval_t key_val) { +static ant_value_t proxy_has_val(ant_t *js, ant_value_t proxy, ant_value_t key_val) { proxy_data_t *data = get_proxy_data(proxy); if (!data) return js_false; if (data->revoked) return throw_proxy_error(js, "Cannot perform 'has' on a proxy that has been revoked"); - jsval_t target = data->target; - jsval_t handler = data->handler; + ant_value_t target = data->target; + ant_value_t handler = data->handler; - jsoff_t has_trap_off = vtype(handler) == T_OBJ ? lkp(js, handler, "has", 3) : 0; + ant_offset_t has_trap_off = vtype(handler) == T_OBJ ? lkp(js, handler, "has", 3) : 0; if (has_trap_off != 0) { - jsval_t has_trap = resolveprop(js, mkval(T_PROP, has_trap_off)); + ant_value_t has_trap = resolveprop(js, mkval(T_PROP, has_trap_off)); if (vtype(has_trap) == T_FUNC || vtype(has_trap) == T_CFUNC) { - jsval_t args[2] = { target, key_val }; + ant_value_t args[2] = { target, key_val }; return sv_vm_call(js->vm, js, has_trap, js_mkundef(), args, 2, NULL, false); } } if (vtype(key_val) == T_SYMBOL) { - jsoff_t off = lkp_sym_proto(js, target, (jsoff_t)vdata(key_val)); + ant_offset_t off = lkp_sym_proto(js, target, (ant_offset_t)vdata(key_val)); return js_bool(off != 0); } return js_false; } -static jsval_t proxy_delete_val(ant_t *js, jsval_t proxy, jsval_t key_val) { +static ant_value_t proxy_delete_val(ant_t *js, ant_value_t proxy, ant_value_t key_val) { proxy_data_t *data = get_proxy_data(proxy); if (!data) return js_true; if (data->revoked) return throw_proxy_error(js, "Cannot perform 'deleteProperty' on a proxy that has been revoked"); - jsval_t target = data->target; - jsval_t handler = data->handler; + ant_value_t target = data->target; + ant_value_t handler = data->handler; - jsoff_t delete_trap_off = vtype(handler) == T_OBJ ? lkp(js, handler, "deleteProperty", 14) : 0; + ant_offset_t delete_trap_off = vtype(handler) == T_OBJ ? lkp(js, handler, "deleteProperty", 14) : 0; if (delete_trap_off != 0) { - jsval_t delete_trap = resolveprop(js, mkval(T_PROP, delete_trap_off)); + ant_value_t delete_trap = resolveprop(js, mkval(T_PROP, delete_trap_off)); if (vtype(delete_trap) == T_FUNC || vtype(delete_trap) == T_CFUNC) { - jsval_t args[2] = { target, key_val }; - jsval_t result = sv_vm_call(js->vm, js, delete_trap, js_mkundef(), args, 2, NULL, false); + ant_value_t args[2] = { target, key_val }; + ant_value_t result = sv_vm_call(js->vm, js, delete_trap, js_mkundef(), args, 2, NULL, false); if (is_err(result)) return result; if (js_truthy(js, result) && vtype(key_val) == T_SYMBOL) { - jsoff_t prop_off = lkp_sym(js, target, (jsoff_t)vdata(key_val)); + ant_offset_t prop_off = lkp_sym(js, target, (ant_offset_t)vdata(key_val)); if (prop_off != 0 && is_nonconfig_prop(js, prop_off)) return js_mkerr_typed(js, JS_ERR_TYPE, "'deleteProperty' on proxy: trap returned truthy for non-configurable property"); } @@ -11724,16 +11724,16 @@ static jsval_t proxy_delete_val(ant_t *js, jsval_t proxy, jsval_t key_val) { } if (vtype(key_val) == T_SYMBOL) { - jsoff_t sym_off = (jsoff_t)vdata(key_val); - jsoff_t prop_off = lkp_sym(js, target, sym_off); + ant_offset_t sym_off = (ant_offset_t)vdata(key_val); + ant_offset_t prop_off = lkp_sym(js, target, sym_off); if (prop_off != 0) { - jsoff_t obj_off = (jsoff_t)vdata(js_as_obj(target)); - jsoff_t first_prop = loadoff(js, obj_off) & ~(3U | FLAGMASK); + ant_offset_t obj_off = (ant_offset_t)vdata(js_as_obj(target)); + ant_offset_t first_prop = loadoff(js, obj_off) & ~(3U | FLAGMASK); if (first_prop == prop_off) { unlink_prop(js, obj_off, prop_off, 0); } else { - for (jsoff_t prev = first_prop; prev != 0; ) { - jsoff_t np = loadoff(js, prev) & ~(3U | FLAGMASK); + for (ant_offset_t prev = first_prop; prev != 0; ) { + ant_offset_t np = loadoff(js, prev) & ~(3U | FLAGMASK); if (np == prop_off) { unlink_prop(js, obj_off, prop_off, prev); break; } prev = np; } @@ -11743,26 +11743,26 @@ static jsval_t proxy_delete_val(ant_t *js, jsval_t proxy, jsval_t key_val) { return js_true; } -jsval_t js_proxy_apply(ant_t *js, jsval_t proxy, jsval_t this_arg, jsval_t *args, int argc) { +ant_value_t js_proxy_apply(ant_t *js, ant_value_t proxy, ant_value_t this_arg, ant_value_t *args, int argc) { proxy_data_t *data = get_proxy_data(proxy); if (!data) return js_mkerr_typed(js, JS_ERR_TYPE, "object is not a function"); if (data->revoked) return throw_proxy_error(js, "Cannot perform 'apply' on a proxy that has been revoked"); - jsval_t target = data->target; - jsval_t handler = data->handler; + ant_value_t target = data->target; + ant_value_t handler = data->handler; uint8_t target_type = vtype(target); if (target_type != T_FUNC && target_type != T_CFUNC && !(target_type == T_OBJ && is_proxy(js, target))) return js_mkerr_typed(js, JS_ERR_TYPE, "%s is not a function", typestr(target_type)); - jsoff_t trap_off = vtype(handler) == T_OBJ ? lkp(js, handler, "apply", 5) : 0; + ant_offset_t trap_off = vtype(handler) == T_OBJ ? lkp(js, handler, "apply", 5) : 0; if (trap_off != 0) { - jsval_t trap = resolveprop(js, mkval(T_PROP, trap_off)); + ant_value_t trap = resolveprop(js, mkval(T_PROP, trap_off)); if (vtype(trap) == T_FUNC || vtype(trap) == T_CFUNC) { - jsval_t args_arr = mkarr(js); + ant_value_t args_arr = mkarr(js); for (int i = 0; i < argc; i++) js_arr_push(js, args_arr, args[i]); - jsval_t trap_args[3] = { target, this_arg, args_arr }; + ant_value_t trap_args[3] = { target, this_arg, args_arr }; return sv_vm_call(js->vm, js, trap, handler, trap_args, 3, NULL, false); } } @@ -11770,26 +11770,26 @@ jsval_t js_proxy_apply(ant_t *js, jsval_t proxy, jsval_t this_arg, jsval_t *args return sv_vm_call(js->vm, js, target, this_arg, args, argc, NULL, false); } -jsval_t js_proxy_construct(ant_t *js, jsval_t proxy, jsval_t *args, int argc, jsval_t new_target) { +ant_value_t js_proxy_construct(ant_t *js, ant_value_t proxy, ant_value_t *args, int argc, ant_value_t new_target) { proxy_data_t *data = get_proxy_data(proxy); if (!data) return js_mkerr_typed(js, JS_ERR_TYPE, "not a constructor"); if (data->revoked) return throw_proxy_error(js, "Cannot perform 'construct' on a proxy that has been revoked"); - jsval_t target = data->target; - jsval_t handler = data->handler; + ant_value_t target = data->target; + ant_value_t handler = data->handler; if (vtype(target) != T_FUNC) return js_mkerr_typed(js, JS_ERR_TYPE, "not a constructor"); - jsoff_t trap_off = vtype(handler) == T_OBJ ? lkp(js, handler, "construct", 9) : 0; + ant_offset_t trap_off = vtype(handler) == T_OBJ ? lkp(js, handler, "construct", 9) : 0; if (trap_off != 0) { - jsval_t trap = resolveprop(js, mkval(T_PROP, trap_off)); + ant_value_t trap = resolveprop(js, mkval(T_PROP, trap_off)); if (vtype(trap) == T_FUNC || vtype(trap) == T_CFUNC) { - jsval_t args_arr = mkarr(js); + ant_value_t args_arr = mkarr(js); for (int i = 0; i < argc; i++) js_arr_push(js, args_arr, args[i]); - jsval_t trap_args[3] = { target, args_arr, new_target }; - jsval_t result = sv_vm_call(js->vm, js, trap, js_mkundef(), trap_args, 3, NULL, false); + ant_value_t trap_args[3] = { target, args_arr, new_target }; + ant_value_t result = sv_vm_call(js->vm, js, trap, js_mkundef(), trap_args, 3, NULL, false); if (is_err(result)) return result; if (!is_object_type(result)) return js_mkerr_typed(js, JS_ERR_TYPE, "'construct' on proxy: trap returned non-Object"); @@ -11797,21 +11797,21 @@ jsval_t js_proxy_construct(ant_t *js, jsval_t proxy, jsval_t *args, int argc, js } } - jsval_t obj = mkobj(js, 0); - jsval_t proto = js_getprop_fallback(js, target, "prototype"); + ant_value_t obj = mkobj(js, 0); + ant_value_t proto = js_getprop_fallback(js, target, "prototype"); if (is_object_type(proto)) js_set_proto(js, obj, proto); - jsval_t saved = js->new_target; + ant_value_t saved = js->new_target; js->new_target = new_target; - jsval_t ctor_this = obj; - jsval_t result = sv_vm_call(js->vm, js, target, obj, args, argc, &ctor_this, true); + ant_value_t ctor_this = obj; + ant_value_t result = sv_vm_call(js->vm, js, target, obj, args, argc, &ctor_this, true); js->new_target = saved; if (is_err(result)) return result; return is_object_type(result) ? result : (is_object_type(ctor_this) ? ctor_this : obj); } -static jsval_t mkproxy(ant_t *js, jsval_t target, jsval_t handler) { - jsval_t proxy_obj = mkobj(js, 0); - jsoff_t off = (jsoff_t)vdata(proxy_obj); +static ant_value_t mkproxy(ant_t *js, ant_value_t target, ant_value_t handler) { + ant_value_t proxy_obj = mkobj(js, 0); + ant_offset_t off = (ant_offset_t)vdata(proxy_obj); proxy_data_t *data = (proxy_data_t *)ant_calloc(sizeof(proxy_data_t)); if (!data) return js_mkerr(js, "out of memory"); @@ -11821,18 +11821,18 @@ static jsval_t mkproxy(ant_t *js, jsval_t target, jsval_t handler) { data->handler = handler; data->revoked = false; - HASH_ADD(hh, proxy_registry, obj_offset, sizeof(jsoff_t), data); + HASH_ADD(hh, proxy_registry, obj_offset, sizeof(ant_offset_t), data); return proxy_obj; } -static jsval_t create_proxy_checked(ant_t *js, jsval_t *args, int nargs, bool require_new) { +static ant_value_t create_proxy_checked(ant_t *js, ant_value_t *args, int nargs, bool require_new) { if (require_new && vtype(js->new_target) == T_UNDEF) { return js_mkerr_typed(js, JS_ERR_TYPE, "Proxy constructor requires 'new'"); } if (nargs < 2) return js_mkerr(js, "Proxy requires two arguments: target and handler"); - jsval_t target = args[0]; - jsval_t handler = args[1]; + ant_value_t target = args[0]; + ant_value_t handler = args[1]; uint8_t target_type = vtype(target); if (target_type != T_OBJ && target_type != T_FUNC && target_type != T_ARR) { @@ -11847,17 +11847,17 @@ static jsval_t create_proxy_checked(ant_t *js, jsval_t *args, int nargs, bool re return mkproxy(js, target, handler); } -static jsval_t builtin_Proxy(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Proxy(ant_t *js, ant_value_t *args, int nargs) { return create_proxy_checked(js, args, nargs, true); } -static jsval_t proxy_revoke_fn(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t proxy_revoke_fn(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t func = js->current_func; - jsval_t ref_slot = get_slot(js, func, SLOT_PROXY_REF); + ant_value_t func = js->current_func; + ant_value_t ref_slot = get_slot(js, func, SLOT_PROXY_REF); if (vtype(ref_slot) != T_UNDEF && vdata(ref_slot) != 0) { - jsval_t proxy = resolveprop(js, mkval(T_PROP, (jsoff_t)vdata(ref_slot))); + ant_value_t proxy = resolveprop(js, mkval(T_PROP, (ant_offset_t)vdata(ref_slot))); proxy_data_t *data = get_proxy_data(proxy); if (data) data->revoked = true; } @@ -11865,17 +11865,17 @@ static jsval_t proxy_revoke_fn(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t builtin_Proxy_revocable(ant_t *js, jsval_t *args, int nargs) { - jsval_t proxy = create_proxy_checked(js, args, nargs, false); +static ant_value_t builtin_Proxy_revocable(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t proxy = create_proxy_checked(js, args, nargs, false); if (is_err(proxy)) return proxy; - jsval_t revoke_obj = mkobj(js, 0); + ant_value_t revoke_obj = mkobj(js, 0); set_slot(js, revoke_obj, SLOT_CFUNC, js_mkfun(proxy_revoke_fn)); set_slot(js, revoke_obj, SLOT_PROXY_REF, proxy); - jsval_t revoke_func = js_obj_to_func(revoke_obj); + ant_value_t revoke_func = js_obj_to_func(revoke_obj); - jsval_t result = mkobj(js, 0); + ant_value_t result = mkobj(js, 0); js_setprop(js, result, js_mkstr(js, "proxy", 5), proxy); js_setprop(js, result, js_mkstr(js, "revoke", 6), revoke_func); @@ -11896,7 +11896,7 @@ ant_t *js_create(void *buf, size_t len) { js = (ant_t *) buf; js->mem = (uint8_t *) (js + 1); - js->size = (jsoff_t) (len - sizeof(*js)); + js->size = (ant_offset_t) (len - sizeof(*js)); js->brk = NANBOX_HEAP_OFFSET; js->global = mkobj(js, 0); js->size = js->size / 8U * 8U; @@ -11904,8 +11904,8 @@ ant_t *js_create(void *buf, size_t len) { js->new_target = js_mkundef(); js->length_str = ANT_STRING("length"); - jsval_t glob = js->global; - jsval_t object_proto = js_mkobj(js); + ant_value_t glob = js->global; + ant_value_t object_proto = js_mkobj(js); set_proto(js, object_proto, js_mknull()); js_setprop(js, object_proto, js_mkstr(js, "toString", 8), js_mkfun(builtin_object_toString)); @@ -11926,21 +11926,21 @@ ant_t *js_create(void *buf, size_t len) { js_setprop(js, object_proto, js_mkstr(js, "propertyIsEnumerable", 20), js_mkfun(builtin_object_propertyIsEnumerable)); js_set_descriptor(js, object_proto, "propertyIsEnumerable", 20, JS_DESC_W | JS_DESC_C); - jsval_t proto_getter = js_mkfun(builtin_proto_getter); - jsval_t proto_setter = js_mkfun(builtin_proto_setter); + ant_value_t proto_getter = js_mkfun(builtin_proto_getter); + ant_value_t proto_setter = js_mkfun(builtin_proto_setter); js_set_accessor_desc(js, object_proto, STR_PROTO, STR_PROTO_LEN, proto_getter, proto_setter, JS_DESC_C); - jsval_t function_proto_obj = js_mkobj(js); + ant_value_t function_proto_obj = js_mkobj(js); set_proto(js, function_proto_obj, object_proto); set_slot(js, function_proto_obj, SLOT_CFUNC, js_mkfun(builtin_function_empty)); js_setprop(js, function_proto_obj, ANT_STRING("call"), js_mkfun(builtin_function_call)); js_setprop(js, function_proto_obj, ANT_STRING("apply"), js_mkfun(builtin_function_apply)); js_setprop(js, function_proto_obj, ANT_STRING("bind"), js_mkfun(builtin_function_bind)); js_setprop(js, function_proto_obj, ANT_STRING("toString"), js_mkfun(builtin_function_toString)); - jsval_t function_proto = js_obj_to_func(function_proto_obj); + ant_value_t function_proto = js_obj_to_func(function_proto_obj); set_slot(js, glob, SLOT_FUNC_PROTO, function_proto); - jsval_t array_proto = js_mkobj(js); + ant_value_t array_proto = js_mkobj(js); set_proto(js, array_proto, object_proto); js_setprop(js, array_proto, js_mkstr(js, "push", 4), js_mkfun(builtin_array_push)); js_setprop(js, array_proto, js_mkstr(js, "pop", 3), js_mkfun(builtin_array_pop)); @@ -11981,7 +11981,7 @@ ant_t *js_create(void *buf, size_t len) { js_setprop(js, array_proto, js_mkstr(js, "toString", 8), js_mkfun(builtin_array_toString)); js_setprop(js, array_proto, js_mkstr(js, "toLocaleString", 14), js_mkfun(builtin_array_toLocaleString)); - jsval_t string_proto = js_mkobj(js); + ant_value_t string_proto = js_mkobj(js); set_proto(js, string_proto, object_proto); js_setprop(js, string_proto, js_mkstr(js, "indexOf", 7), js_mkfun(builtin_string_indexOf)); js_setprop(js, string_proto, js_mkstr(js, "substring", 9), js_mkfun(builtin_string_substring)); @@ -12015,7 +12015,7 @@ ant_t *js_create(void *buf, size_t len) { js_setprop(js, string_proto, js_mkstr(js, "valueOf", 7), js_mkfun(builtin_string_valueOf)); js_setprop(js, string_proto, js_mkstr(js, "toString", 8), js_mkfun(builtin_string_toString)); - jsval_t number_proto = js_mkobj(js); + ant_value_t number_proto = js_mkobj(js); set_proto(js, number_proto, object_proto); js_setprop(js, number_proto, js_mkstr(js, "toString", 8), js_mkfun(builtin_number_toString)); js_setprop(js, number_proto, js_mkstr(js, "toFixed", 7), js_mkfun(builtin_number_toFixed)); @@ -12024,41 +12024,41 @@ ant_t *js_create(void *buf, size_t len) { js_setprop(js, number_proto, js_mkstr(js, "valueOf", 7), js_mkfun(builtin_number_valueOf)); js_setprop(js, number_proto, js_mkstr(js, "toLocaleString", 14), js_mkfun(builtin_number_toLocaleString)); - jsval_t boolean_proto = js_mkobj(js); + ant_value_t boolean_proto = js_mkobj(js); set_proto(js, boolean_proto, object_proto); js_setprop(js, boolean_proto, js_mkstr(js, "valueOf", 7), js_mkfun(builtin_boolean_valueOf)); js_setprop(js, boolean_proto, js_mkstr(js, "toString", 8), js_mkfun(builtin_boolean_toString)); - jsval_t bigint_proto = js_mkobj(js); + ant_value_t bigint_proto = js_mkobj(js); set_proto(js, bigint_proto, object_proto); js_setprop(js, bigint_proto, js_mkstr(js, "toString", 8), js_mkfun(builtin_bigint_toString)); - jsval_t error_proto = js_mkobj(js); + ant_value_t error_proto = js_mkobj(js); set_proto(js, error_proto, object_proto); js_setprop(js, error_proto, ANT_STRING("name"), ANT_STRING("Error")); js_setprop(js, error_proto, ANT_STRING("message"), js_mkstr(js, "", 0)); js_setprop(js, error_proto, js_mkstr(js, "toString", 8), js_mkfun(builtin_Error_toString)); - jsval_t err_ctor_obj = mkobj(js, 0); + ant_value_t err_ctor_obj = mkobj(js, 0); set_proto(js, err_ctor_obj, function_proto); set_slot(js, err_ctor_obj, SLOT_CFUNC, js_mkfun(builtin_Error)); js_setprop_nonconfigurable(js, err_ctor_obj, "prototype", 9, error_proto); js_setprop(js, err_ctor_obj, ANT_STRING("name"), ANT_STRING("Error")); - jsval_t err_ctor_func = js_obj_to_func(err_ctor_obj); + ant_value_t err_ctor_func = js_obj_to_func(err_ctor_obj); js_setprop(js, glob, ANT_STRING("Error"), err_ctor_func); js_setprop(js, error_proto, js_mkstr(js, "constructor", 11), err_ctor_func); js_set_descriptor(js, error_proto, "constructor", 11, JS_DESC_W | JS_DESC_C); #define REGISTER_ERROR_SUBTYPE(name_str) do { \ - jsval_t proto = js_mkobj(js); \ + ant_value_t proto = js_mkobj(js); \ set_proto(js, proto, error_proto); \ js_setprop(js, proto, ANT_STRING("name"), ANT_STRING(name_str)); \ - jsval_t ctor = mkobj(js, 0); \ + ant_value_t ctor = mkobj(js, 0); \ set_proto(js, ctor, function_proto); \ set_slot(js, ctor, SLOT_CFUNC, js_mkfun(builtin_Error)); \ js_setprop_nonconfigurable(js, ctor, "prototype", 9, proto); \ js_setprop(js, ctor, ANT_STRING("name"), ANT_STRING(name_str)); \ - jsval_t ctor_func = js_obj_to_func(ctor); \ + ant_value_t ctor_func = js_obj_to_func(ctor); \ js_setprop(js, proto, ANT_STRING("constructor"), ctor_func); \ js_set_descriptor(js, proto, "constructor", 11, JS_DESC_W | JS_DESC_C); \ js_setprop(js, glob, ANT_STRING(name_str), ctor_func); \ @@ -12074,10 +12074,10 @@ ant_t *js_create(void *buf, size_t len) { #undef REGISTER_ERROR_SUBTYPE - jsval_t proto = js_mkobj(js); + ant_value_t proto = js_mkobj(js); set_proto(js, proto, error_proto); js_setprop(js, proto, ANT_STRING("name"), ANT_STRING("AggregateError")); - jsval_t ctor = mkobj(js, 0); + ant_value_t ctor = mkobj(js, 0); set_proto(js, ctor, function_proto); set_slot(js, ctor, SLOT_CFUNC, js_mkfun(builtin_AggregateError)); js_setprop_nonconfigurable(js, ctor, "prototype", 9, proto); @@ -12086,14 +12086,14 @@ ant_t *js_create(void *buf, size_t len) { js_set_descriptor(js, proto, "constructor", 11, JS_DESC_W | JS_DESC_C); js_setprop(js, glob, ANT_STRING("AggregateError"), js_obj_to_func(ctor)); - jsval_t promise_proto = js_mkobj(js); + ant_value_t promise_proto = js_mkobj(js); set_proto(js, promise_proto, object_proto); js_setprop(js, promise_proto, js_mkstr(js, "then", 4), js_mkfun(builtin_promise_then)); js_setprop(js, promise_proto, js_mkstr(js, "catch", 5), js_mkfun(builtin_promise_catch)); js_setprop(js, promise_proto, js_mkstr(js, "finally", 7), js_mkfun(builtin_promise_finally)); // Symbol.toStringTag is set in init_symbol_module after symbols are initialized - jsval_t obj_func_obj = mkobj(js, 0); + ant_value_t obj_func_obj = mkobj(js, 0); set_proto(js, obj_func_obj, function_proto); set_slot(js, obj_func_obj, SLOT_BUILTIN, tov(BUILTIN_OBJECT)); js_setprop(js, obj_func_obj, js_mkstr(js, "keys", 4), js_mkfun(builtin_object_keys)); @@ -12120,38 +12120,38 @@ ant_t *js_create(void *buf, size_t len) { js_setprop(js, obj_func_obj, js_mkstr(js, "preventExtensions", 17), js_mkfun(builtin_object_preventExtensions)); js_setprop(js, obj_func_obj, ANT_STRING("name"), ANT_STRING("Object")); js_setprop_nonconfigurable(js, obj_func_obj, "prototype", 9, object_proto); - jsval_t obj_func = js_obj_to_func(obj_func_obj); + ant_value_t obj_func = js_obj_to_func(obj_func_obj); js_setprop(js, glob, js_mkstr(js, "Object", 6), obj_func); - jsval_t func_ctor_obj = mkobj(js, 0); + ant_value_t func_ctor_obj = mkobj(js, 0); set_proto(js, func_ctor_obj, function_proto); set_slot(js, func_ctor_obj, SLOT_CFUNC, js_mkfun(builtin_Function)); js_setprop_nonconfigurable(js, func_ctor_obj, "prototype", 9, function_proto); js_setprop(js, func_ctor_obj, js->length_str, tov(1.0)); js_set_descriptor(js, func_ctor_obj, "length", 6, JS_DESC_C); js_setprop(js, func_ctor_obj, ANT_STRING("name"), ANT_STRING("Function")); - jsval_t func_ctor_func = js_obj_to_func(func_ctor_obj); + ant_value_t func_ctor_func = js_obj_to_func(func_ctor_obj); js_setprop(js, glob, js_mkstr(js, "Function", 8), func_ctor_func); - jsval_t async_func_proto_obj = js_mkobj(js); + ant_value_t async_func_proto_obj = js_mkobj(js); set_proto(js, async_func_proto_obj, function_proto); set_slot(js, async_func_proto_obj, SLOT_ASYNC, js_true); - jsval_t async_func_proto = js_obj_to_func(async_func_proto_obj); + ant_value_t async_func_proto = js_obj_to_func(async_func_proto_obj); set_slot(js, glob, SLOT_ASYNC_PROTO, async_func_proto); - jsval_t async_func_ctor_obj = mkobj(js, 0); + ant_value_t async_func_ctor_obj = mkobj(js, 0); set_proto(js, async_func_ctor_obj, function_proto); set_slot(js, async_func_ctor_obj, SLOT_CFUNC, js_mkfun(builtin_AsyncFunction)); js_setprop_nonconfigurable(js, async_func_ctor_obj, "prototype", 9, async_func_proto); js_setprop(js, async_func_ctor_obj, js->length_str, tov(1.0)); js_set_descriptor(js, async_func_ctor_obj, "length", 6, JS_DESC_C); js_setprop(js, async_func_ctor_obj, ANT_STRING("name"), ANT_STRING("AsyncFunction")); - jsval_t async_func_ctor = js_obj_to_func(async_func_ctor_obj); + ant_value_t async_func_ctor = js_obj_to_func(async_func_ctor_obj); js_setprop(js, async_func_proto_obj, js_mkstr(js, "constructor", 11), async_func_ctor); js_set_descriptor(js, async_func_proto_obj, "constructor", 11, JS_DESC_W | JS_DESC_C); - jsval_t str_ctor_obj = mkobj(js, 0); + ant_value_t str_ctor_obj = mkobj(js, 0); set_proto(js, str_ctor_obj, function_proto); set_slot(js, str_ctor_obj, SLOT_CFUNC, js_mkfun(builtin_String)); js_setprop_nonconfigurable(js, str_ctor_obj, "prototype", 9, string_proto); @@ -12159,10 +12159,10 @@ ant_t *js_create(void *buf, size_t len) { js_setprop(js, str_ctor_obj, js_mkstr(js, "fromCodePoint", 13), js_mkfun(builtin_string_fromCodePoint)); js_setprop(js, str_ctor_obj, js_mkstr(js, "raw", 3), js_mkfun(builtin_string_raw)); js_setprop(js, str_ctor_obj, ANT_STRING("name"), ANT_STRING("String")); - jsval_t str_ctor_func = js_obj_to_func(str_ctor_obj); + ant_value_t str_ctor_func = js_obj_to_func(str_ctor_obj); js_setprop(js, glob, js_mkstr(js, "String", 6), str_ctor_func); - jsval_t number_ctor_obj = mkobj(js, 0); + ant_value_t number_ctor_obj = mkobj(js, 0); set_proto(js, number_ctor_obj, function_proto); set_slot(js, number_ctor_obj, SLOT_CFUNC, js_mkfun(builtin_Number)); @@ -12184,18 +12184,18 @@ ant_t *js_create(void *buf, size_t len) { js_setprop_nonconfigurable(js, number_ctor_obj, "prototype", 9, number_proto); js_setprop(js, number_ctor_obj, ANT_STRING("name"), ANT_STRING("Number")); - jsval_t number_ctor_func = js_obj_to_func(number_ctor_obj); + ant_value_t number_ctor_func = js_obj_to_func(number_ctor_obj); js_setprop(js, glob, js_mkstr(js, "Number", 6), number_ctor_func); - jsval_t bool_ctor_obj = mkobj(js, 0); + ant_value_t bool_ctor_obj = mkobj(js, 0); set_proto(js, bool_ctor_obj, function_proto); set_slot(js, bool_ctor_obj, SLOT_CFUNC, js_mkfun(builtin_Boolean)); js_setprop_nonconfigurable(js, bool_ctor_obj, "prototype", 9, boolean_proto); js_setprop(js, bool_ctor_obj, ANT_STRING("name"), ANT_STRING("Boolean")); - jsval_t bool_ctor_func = js_obj_to_func(bool_ctor_obj); + ant_value_t bool_ctor_func = js_obj_to_func(bool_ctor_obj); js_setprop(js, glob, js_mkstr(js, "Boolean", 7), bool_ctor_func); - jsval_t arr_ctor_obj = mkobj(js, 0); + ant_value_t arr_ctor_obj = mkobj(js, 0); set_proto(js, arr_ctor_obj, function_proto); set_slot(js, arr_ctor_obj, SLOT_CFUNC, js_mkfun(builtin_Array)); js_setprop_nonconfigurable(js, arr_ctor_obj, "prototype", 9, array_proto); @@ -12205,17 +12205,17 @@ ant_t *js_create(void *buf, size_t len) { js_setprop(js, arr_ctor_obj, js->length_str, tov(1.0)); js_set_descriptor(js, arr_ctor_obj, "length", 6, JS_DESC_C); js_setprop(js, arr_ctor_obj, ANT_STRING("name"), ANT_STRING("Array")); - jsval_t arr_ctor_func = js_obj_to_func(arr_ctor_obj); + ant_value_t arr_ctor_func = js_obj_to_func(arr_ctor_obj); js_setprop(js, glob, js_mkstr(js, "Array", 5), arr_ctor_func); - jsval_t proxy_ctor_obj = mkobj(js, 0); + ant_value_t proxy_ctor_obj = mkobj(js, 0); set_proto(js, proxy_ctor_obj, function_proto); set_slot(js, proxy_ctor_obj, SLOT_CFUNC, js_mkfun(builtin_Proxy)); js_setprop(js, proxy_ctor_obj, js_mkstr(js, "revocable", 9), js_mkfun(builtin_Proxy_revocable)); js_setprop(js, proxy_ctor_obj, ANT_STRING("name"), ANT_STRING("Proxy")); js_setprop(js, glob, js_mkstr(js, "Proxy", 5), js_obj_to_func(proxy_ctor_obj)); - jsval_t p_ctor_obj = mkobj(js, 0); + ant_value_t p_ctor_obj = mkobj(js, 0); set_proto(js, p_ctor_obj, function_proto); set_slot(js, p_ctor_obj, SLOT_CFUNC, js_mkfun(builtin_Promise)); js_setprop(js, p_ctor_obj, js_mkstr(js, "resolve", 7), js_mkfun(builtin_Promise_resolve)); @@ -12229,7 +12229,7 @@ ant_t *js_create(void *buf, size_t len) { js_setprop(js, p_ctor_obj, ANT_STRING("name"), ANT_STRING("Promise")); js_setprop(js, glob, js_mkstr(js, "Promise", 7), js_obj_to_func(p_ctor_obj)); - jsval_t bigint_ctor_obj = mkobj(js, 0); + ant_value_t bigint_ctor_obj = mkobj(js, 0); set_proto(js, bigint_ctor_obj, function_proto); set_slot(js, bigint_ctor_obj, SLOT_CFUNC, js_mkfun(builtin_BigInt)); js_setprop(js, bigint_ctor_obj, js_mkstr(js, "asIntN", 6), js_mkfun(builtin_BigInt_asIntN)); @@ -12252,7 +12252,7 @@ ant_t *js_create(void *buf, size_t len) { js_setprop(js, glob, js_mkstr(js, "undefined", 9), js_mkundef()); js_set_descriptor(js, glob, "undefined", 9, 0); - jsval_t math_obj = mkobj(js, 0); + ant_value_t math_obj = mkobj(js, 0); set_proto(js, math_obj, object_proto); js_setprop(js, math_obj, js_mkstr(js, "E", 1), tov(M_E)); js_setprop(js, math_obj, js_mkstr(js, "LN10", 4), tov(M_LN10)); @@ -12299,7 +12299,7 @@ ant_t *js_create(void *buf, size_t len) { js_setprop(js, math_obj, js_mkstr(js, "trunc", 5), js_mkfun(builtin_Math_trunc)); js_setprop(js, glob, js_mkstr(js, "Math", 4), math_obj); - jsval_t import_obj = mkobj(js, 0); + ant_value_t import_obj = mkobj(js, 0); set_proto(js, import_obj, function_proto); set_slot(js, import_obj, SLOT_CFUNC, js_mkfun(builtin_import)); @@ -12354,7 +12354,7 @@ ant_t *js_create_dynamic() { js->mem = arena; js->owns_mem = true; - js->max_size = (jsoff_t) ANT_ARENA_MAX; + js->max_size = (ant_offset_t) ANT_ARENA_MAX; ant_t *new_js = (ant_t *)malloc(sizeof(ant_t)); if (new_js == NULL) { @@ -12393,25 +12393,25 @@ void js_destroy(ant_t *js) { destroy_runtime(js); } -inline double js_getnum(jsval_t value) { return tod(value); } +inline double js_getnum(ant_value_t value) { return tod(value); } inline void js_setstackbase(ant_t *js, void *base) { js->cstk.base = base; js->cstk.main_base = base; } inline void js_setstacklimit(ant_t *js, size_t max) { js->cstk.limit = max; } inline void js_set_filename(ant_t *js, const char *filename) { js->filename = filename; } -inline jsval_t js_mkundef(void) { return mkval(T_UNDEF, 0); } -inline jsval_t js_mknull(void) { return mkval(T_NULL, 0); } -inline jsval_t js_mknum(double value) { return tov(value); } -inline jsval_t js_mkobj(ant_t *js) { return mkobj(js, 0); } -inline jsval_t js_glob(ant_t *js) { return js->global; } -inline jsval_t js_mkfun(jsval_t (*fn)(ant_t *, jsval_t *, int)) { return mkval(T_CFUNC, (size_t) (void *) fn); } +inline ant_value_t js_mkundef(void) { return mkval(T_UNDEF, 0); } +inline ant_value_t js_mknull(void) { return mkval(T_NULL, 0); } +inline ant_value_t js_mknum(double value) { return tov(value); } +inline ant_value_t js_mkobj(ant_t *js) { return mkobj(js, 0); } +inline ant_value_t js_glob(ant_t *js) { return js->global; } +inline ant_value_t js_mkfun(ant_value_t (*fn)(ant_t *, ant_value_t *, int)) { return mkval(T_CFUNC, (size_t) (void *) fn); } -inline jsval_t js_getthis(ant_t *js) { return js->this_val; } -inline void js_setthis(ant_t *js, jsval_t val) { js->this_val = val; } -inline jsval_t js_getcurrentfunc(ant_t *js) { return js->current_func; } +inline ant_value_t js_getthis(ant_t *js) { return js->this_val; } +inline void js_setthis(ant_t *js, ant_value_t val) { js->this_val = val; } +inline ant_value_t js_getcurrentfunc(ant_t *js) { return js->current_func; } -jsval_t js_heavy_mkfun(ant_t *js, jsval_t (*fn)(ant_t *, jsval_t *, int), jsval_t data) { - jsval_t cfunc = js_mkfun(fn); - jsval_t fn_obj = mkobj(js, 0); +ant_value_t js_heavy_mkfun(ant_t *js, ant_value_t (*fn)(ant_t *, ant_value_t *, int), ant_value_t data) { + ant_value_t cfunc = js_mkfun(fn); + ant_value_t fn_obj = mkobj(js, 0); set_slot(js, fn_obj, SLOT_CFUNC, cfunc); set_slot(js, fn_obj, SLOT_DATA, data); @@ -12419,61 +12419,61 @@ jsval_t js_heavy_mkfun(ant_t *js, jsval_t (*fn)(ant_t *, jsval_t *, int), jsval_ return js_obj_to_func(fn_obj); } -void js_set(ant_t *js, jsval_t obj, const char *key, jsval_t val) { +void js_set(ant_t *js, ant_value_t obj, const char *key, ant_value_t val) { size_t key_len = strlen(key); if (vtype(obj) == T_OBJ) { - jsoff_t existing = lkp(js, obj, key, key_len); + ant_offset_t existing = lkp(js, obj, key, key_len); if (existing > 0) { if (is_const_prop(js, existing)) { js_mkerr(js, "assignment to constant"); return; } - saveval(js, existing + sizeof(jsoff_t) * 2, val); + saveval(js, existing + sizeof(ant_offset_t) * 2, val); } else { - jsval_t key_str = js_mkstr(js, key, key_len); + ant_value_t key_str = js_mkstr(js, key, key_len); mkprop(js, obj, key_str, val, 0); } } else if (vtype(obj) == T_FUNC) { - jsval_t func_obj = js_func_obj(obj); - jsoff_t existing = lkp(js, func_obj, key, key_len); + ant_value_t func_obj = js_func_obj(obj); + ant_offset_t existing = lkp(js, func_obj, key, key_len); if (existing > 0) { if (is_const_prop(js, existing)) { js_mkerr(js, "assignment to constant"); return; } - saveval(js, existing + sizeof(jsoff_t) * 2, val); + saveval(js, existing + sizeof(ant_offset_t) * 2, val); } else { - jsval_t key_str = js_mkstr(js, key, key_len); + ant_value_t key_str = js_mkstr(js, key, key_len); mkprop(js, func_obj, key_str, val, 0); } } } -void js_set_sym(ant_t *js, jsval_t obj, jsval_t sym, jsval_t val) { +void js_set_sym(ant_t *js, ant_value_t obj, ant_value_t sym, ant_value_t val) { if (vtype(sym) != T_SYMBOL) return; - jsoff_t sym_off = (jsoff_t)vdata(sym); + ant_offset_t sym_off = (ant_offset_t)vdata(sym); if (vtype(obj) == T_FUNC) obj = js_func_obj(obj); if (vtype(obj) != T_OBJ && vtype(obj) != T_ARR) return; - jsoff_t existing = lkp_sym(js, obj, sym_off); + ant_offset_t existing = lkp_sym(js, obj, sym_off); if (existing > 0) { if (is_const_prop(js, existing)) return; - saveval(js, existing + sizeof(jsoff_t) * 2, val); + saveval(js, existing + sizeof(ant_offset_t) * 2, val); } else mkprop(js, obj, sym, val, 0); } -jsval_t js_get_sym(ant_t *js, jsval_t obj, jsval_t sym) { +ant_value_t js_get_sym(ant_t *js, ant_value_t obj, ant_value_t sym) { if (vtype(sym) != T_SYMBOL) return js_mkundef(); - jsoff_t sym_off = (jsoff_t)vdata(sym); + ant_offset_t sym_off = (ant_offset_t)vdata(sym); - jsval_t receiver = obj; + ant_value_t receiver = obj; if (vtype(obj) == T_FUNC) obj = js_func_obj(obj); uint8_t ot = vtype(obj); if (!is_object_type(obj)) { if (ot == T_STR || ot == T_NUM || ot == T_BOOL || ot == T_BIGINT || ot == T_SYMBOL) { - jsval_t proto = get_prototype_for_type(js, ot); + ant_value_t proto = get_prototype_for_type(js, ot); if (!is_object_type(proto)) return js_mkundef(); obj = js_as_obj(proto); } else { @@ -12485,39 +12485,39 @@ jsval_t js_get_sym(ant_t *js, jsval_t obj, jsval_t sym) { if (is_proxy(js, obj)) return proxy_get_val(js, obj, sym); - jsval_t cur = obj; + ant_value_t cur = obj; for (int i = 0; i < MAX_PROTO_CHAIN_DEPTH; i++) { - jsoff_t cur_off = (jsoff_t)vdata(cur); + ant_offset_t cur_off = (ant_offset_t)vdata(cur); descriptor_entry_t *sd = lookup_sym_descriptor(cur_off, sym_off); if (sd && sd->has_getter) { - jsval_t g = sd->getter; + ant_value_t g = sd->getter; if (vtype(g) == T_FUNC || vtype(g) == T_CFUNC) return sv_vm_call(js->vm, js, g, receiver, NULL, 0, NULL, false); return js_mkundef(); } - jsval_t proto = get_proto(js, cur); + ant_value_t proto = get_proto(js, cur); if (!is_object_type(proto)) break; cur = js_as_obj(proto); } - jsoff_t off = lkp_sym_proto(js, obj, sym_off); + ant_offset_t off = lkp_sym_proto(js, obj, sym_off); if (off == 0) return js_mkundef(); return resolveprop(js, mkval(T_PROP, off)); } -bool js_del(ant_t *js, jsval_t obj, const char *key) { +bool js_del(ant_t *js, ant_value_t obj, const char *key) { size_t len = strlen(key); - jsoff_t obj_off; + ant_offset_t obj_off; if (vtype(obj) == T_OBJ) { - obj_off = (jsoff_t)vdata(obj); + obj_off = (ant_offset_t)vdata(obj); } else if (vtype(obj) == T_ARR || vtype(obj) == T_FUNC) { - obj_off = (jsoff_t)vdata(js_as_obj(obj)); + obj_off = (ant_offset_t)vdata(js_as_obj(obj)); if (vtype(obj) == T_ARR) { unsigned long del_idx; - jsoff_t arr_len = get_array_length(js, obj); + ant_offset_t arr_len = get_array_length(js, obj); if (parse_array_index(key, len, arr_len, &del_idx)) { - arr_del(js, obj, (jsoff_t)del_idx); + arr_del(js, obj, (ant_offset_t)del_idx); return true; } } @@ -12526,22 +12526,22 @@ bool js_del(ant_t *js, jsval_t obj, const char *key) { return false; } - jsoff_t prop_off = lkp(js, obj, key, len); + ant_offset_t prop_off = lkp(js, obj, key, len); if (prop_off == 0) return true; if (is_nonconfig_prop(js, prop_off)) return false; descriptor_entry_t *desc = lookup_descriptor(js, obj_off, key, len); if (desc && !desc->configurable) return false; - jsoff_t first_prop = loadoff(js, obj_off) & ~(3U | FLAGMASK); - jsoff_t tail = loadoff(js, obj_off + sizeof(jsoff_t) + sizeof(jsoff_t)); + ant_offset_t first_prop = loadoff(js, obj_off) & ~(3U | FLAGMASK); + ant_offset_t tail = loadoff(js, obj_off + sizeof(ant_offset_t) + sizeof(ant_offset_t)); if (first_prop == prop_off) { - jsoff_t deleted_next = loadoff(js, prop_off) & ~FLAGMASK; - jsoff_t current = loadoff(js, obj_off); + ant_offset_t deleted_next = loadoff(js, prop_off) & ~FLAGMASK; + ant_offset_t current = loadoff(js, obj_off); saveoff(js, obj_off, (deleted_next & ~3ULL) | (current & (FLAGMASK | 3ULL))); - if (tail == prop_off) saveoff(js, obj_off + sizeof(jsoff_t) + sizeof(jsoff_t), 0); + if (tail == prop_off) saveoff(js, obj_off + sizeof(ant_offset_t) + sizeof(ant_offset_t), 0); invalidate_prop_cache(js, obj_off, prop_off); js->needs_gc = true; @@ -12549,15 +12549,15 @@ bool js_del(ant_t *js, jsval_t obj, const char *key) { return true; } - jsoff_t prev = first_prop; + ant_offset_t prev = first_prop; while (prev != 0 && prev < js->brk) { - jsoff_t next = loadoff(js, prev) & ~(3U | FLAGMASK); + ant_offset_t next = loadoff(js, prev) & ~(3U | FLAGMASK); if (next == prop_off) { - jsoff_t deleted_next = loadoff(js, prop_off) & ~(3U | FLAGMASK); - jsoff_t prev_flags = loadoff(js, prev) & FLAGMASK; + ant_offset_t deleted_next = loadoff(js, prop_off) & ~(3U | FLAGMASK); + ant_offset_t prev_flags = loadoff(js, prev) & FLAGMASK; saveoff(js, prev, deleted_next | prev_flags); - if (tail == prop_off) saveoff(js, obj_off + sizeof(jsoff_t) + sizeof(jsoff_t), prev); + if (tail == prop_off) saveoff(js, obj_off + sizeof(ant_offset_t) + sizeof(ant_offset_t), prev); invalidate_prop_cache(js, obj_off, prop_off); js->needs_gc = true; @@ -12570,7 +12570,7 @@ bool js_del(ant_t *js, jsval_t obj, const char *key) { return false; } -static bool js_try_get(ant_t *js, jsval_t obj, const char *key, jsval_t *out) { +static bool js_try_get(ant_t *js, ant_value_t obj, const char *key, ant_value_t *out) { size_t key_len = strlen(key); if (vtype(obj) == T_FUNC) { @@ -12583,17 +12583,17 @@ static bool js_try_get(ant_t *js, jsval_t obj, const char *key, jsval_t *out) { return true; } - jsval_t func_obj = js_func_obj(obj); + ant_value_t func_obj = js_func_obj(obj); if (key_len == 4 && memcmp(key, "meta", 4) == 0 && vtype(js->import_meta) != T_UNDEF) { - jsval_t cfunc = js_get_slot(js, func_obj, SLOT_CFUNC); + ant_value_t cfunc = js_get_slot(js, func_obj, SLOT_CFUNC); if (vtype(cfunc) == T_CFUNC && js_as_cfunc(cfunc) == builtin_import) { *out = js->import_meta; return true; } } - jsoff_t off = lkp(js, func_obj, key, key_len); + ant_offset_t off = lkp(js, func_obj, key, key_len); if (off == 0) { - jsval_t accessor_result; + ant_value_t accessor_result; if (try_accessor_getter(js, obj, key, key_len, &accessor_result)) { *out = accessor_result; return true; @@ -12601,9 +12601,9 @@ static bool js_try_get(ant_t *js, jsval_t obj, const char *key, jsval_t *out) { return false; } - descriptor_entry_t *desc = lookup_descriptor(js, (jsoff_t)vdata(func_obj), key, key_len); + descriptor_entry_t *desc = lookup_descriptor(js, (ant_offset_t)vdata(func_obj), key, key_len); if (desc && desc->has_getter) { - jsval_t accessor_result; + ant_value_t accessor_result; if (try_accessor_getter(js, obj, key, key_len, &accessor_result)) { *out = accessor_result; return true; @@ -12629,26 +12629,26 @@ static bool js_try_get(ant_t *js, jsval_t obj, const char *key, jsval_t *out) { return true; } unsigned long idx; - jsoff_t arr_len = get_array_length(js, obj); + ant_offset_t arr_len = get_array_length(js, obj); if (parse_array_index(key, key_len, arr_len, &idx)) { - if (arr_has(js, obj, (jsoff_t)idx)) { - *out = arr_get(js, obj, (jsoff_t)idx); + if (arr_has(js, obj, (ant_offset_t)idx)) { + *out = arr_get(js, obj, (ant_offset_t)idx); return true; } return false; } - jsval_t arr_obj = js_as_obj(obj); - jsoff_t off = lkp(js, arr_obj, key, key_len); + ant_value_t arr_obj = js_as_obj(obj); + ant_offset_t off = lkp(js, arr_obj, key, key_len); if (off == 0) { - jsval_t accessor_result; + ant_value_t accessor_result; if (try_accessor_getter(js, arr_obj, key, key_len, &accessor_result)) { *out = accessor_result; return true; } return false; } - descriptor_entry_t *desc = lookup_descriptor(js, (jsoff_t)vdata(arr_obj), key, key_len); + descriptor_entry_t *desc = lookup_descriptor(js, (ant_offset_t)vdata(arr_obj), key, key_len); if (desc && desc->has_getter) { - jsval_t accessor_result; + ant_value_t accessor_result; if (try_accessor_getter(js, arr_obj, key, key_len, &accessor_result)) { *out = accessor_result; return true; } @@ -12667,27 +12667,27 @@ static bool js_try_get(ant_t *js, jsval_t obj, const char *key, jsval_t *out) { if (t == T_STR || t == T_NUM || t == T_BOOL) { if (t == T_STR && key_len == 6 && memcmp(key, "length", 6) == 0) { - jsoff_t byte_len = 0; jsoff_t str_off = vstr(js, obj, &byte_len); + ant_offset_t byte_len = 0; ant_offset_t str_off = vstr(js, obj, &byte_len); const char *str_data = (const char *)&js->mem[str_off]; *out = tov((double)utf16_strlen(str_data, byte_len)); return true; } - jsval_t boxed = mkobj(js, 0); + ant_value_t boxed = mkobj(js, 0); js_set_slot(js, js_as_obj(boxed), SLOT_PRIMITIVE, obj); obj = boxed; t = T_OBJ; } if (is_promise) obj = js_as_obj(obj); else if (t != T_OBJ) return false; - jsoff_t off = lkp(js, obj, key, key_len); + ant_offset_t off = lkp(js, obj, key, key_len); if (off == 0) { - jsval_t result = try_dynamic_getter(js, obj, key, key_len); + ant_value_t result = try_dynamic_getter(js, obj, key, key_len); if (vtype(result) != T_UNDEF) { *out = result; return true; } } if (off == 0 && is_promise) { - jsval_t promise_proto = get_ctor_proto(js, "Promise", 7); + ant_value_t promise_proto = get_ctor_proto(js, "Promise", 7); if (vtype(promise_proto) != T_UNDEF && vtype(promise_proto) != T_NULL) { off = lkp(js, promise_proto, key, key_len); if (off != 0) { *out = resolveprop(js, mkval(T_PROP, off)); return true; } @@ -12695,16 +12695,16 @@ static bool js_try_get(ant_t *js, jsval_t obj, const char *key, jsval_t *out) { } if (off == 0) { - jsval_t accessor_result; + ant_value_t accessor_result; if (try_accessor_getter(js, obj, key, key_len, &accessor_result)) { *out = accessor_result; return true; } return false; } - descriptor_entry_t *desc = lookup_descriptor(js, (jsoff_t)vdata(js_as_obj(obj)), key, key_len); + descriptor_entry_t *desc = lookup_descriptor(js, (ant_offset_t)vdata(js_as_obj(obj)), key, key_len); if (desc && desc->has_getter) { - jsval_t accessor_result; + ant_value_t accessor_result; if (try_accessor_getter(js, obj, key, key_len, &accessor_result)) { *out = accessor_result; return true; } @@ -12714,25 +12714,25 @@ static bool js_try_get(ant_t *js, jsval_t obj, const char *key, jsval_t *out) { return true; } -jsval_t js_get(ant_t *js, jsval_t obj, const char *key) { - jsval_t val; +ant_value_t js_get(ant_t *js, ant_value_t obj, const char *key) { + ant_value_t val; if (js_try_get(js, obj, key, &val)) return val; return js_mkundef(); } -jsval_t js_getprop_proto(ant_t *js, jsval_t obj, const char *key) { +ant_value_t js_getprop_proto(ant_t *js, ant_value_t obj, const char *key) { size_t key_len = strlen(key); - jsoff_t off = lkp_proto(js, obj, key, key_len); + ant_offset_t off = lkp_proto(js, obj, key, key_len); return off == 0 ? js_mkundef() : resolveprop(js, mkval(T_PROP, off)); } -jsval_t js_getprop_fallback(ant_t *js, jsval_t obj, const char *name) { - jsval_t val; +ant_value_t js_getprop_fallback(ant_t *js, ant_value_t obj, const char *name) { + ant_value_t val; if (js_try_get(js, obj, name, &val)) return val; return js_getprop_proto(js, obj, name); } -jsval_t js_getprop_super(ant_t *js, jsval_t super_obj, jsval_t receiver, const char *name) { +ant_value_t js_getprop_super(ant_t *js, ant_value_t super_obj, ant_value_t receiver, const char *name) { if (!name) return js_mkundef(); if (vtype(super_obj) == T_FUNC) super_obj = js_func_obj(super_obj); @@ -12744,13 +12744,13 @@ jsval_t js_getprop_super(ant_t *js, jsval_t super_obj, jsval_t receiver, const c const char *key_intern = intern_string(name, key_len); if (!key_intern) return js_mkundef(); - jsval_t cur = js_as_obj(super_obj); + ant_value_t cur = js_as_obj(super_obj); for (int i = 0; i < MAX_PROTO_CHAIN_DEPTH; i++) { - jsoff_t cur_off = (jsoff_t)vdata(cur); + ant_offset_t cur_off = (ant_offset_t)vdata(cur); descriptor_entry_t *desc = lookup_descriptor(js, cur_off, name, key_len); if (desc) { if (desc->has_getter) { - jsval_t getter = desc->getter; + ant_value_t getter = desc->getter; if (vtype(getter) == T_FUNC || vtype(getter) == T_CFUNC) return sv_vm_call(js->vm, js, getter, receiver, NULL, 0, NULL, false); return js_mkundef(); @@ -12758,10 +12758,10 @@ jsval_t js_getprop_super(ant_t *js, jsval_t super_obj, jsval_t receiver, const c if (desc->has_setter) return js_mkundef(); } - jsoff_t prop_off = lkp_interned(js, cur, key_intern, key_len); + ant_offset_t prop_off = lkp_interned(js, cur, key_intern, key_len); if (prop_off != 0) return resolveprop(js, mkval(T_PROP, prop_off)); - jsval_t proto = get_proto(js, cur); + ant_value_t proto = get_proto(js, cur); if (!is_object_type(proto)) break; cur = js_as_obj(proto); } @@ -12770,37 +12770,37 @@ jsval_t js_getprop_super(ant_t *js, jsval_t super_obj, jsval_t receiver, const c } typedef struct { - bool (*callback)(ant_t *js, jsval_t value, void *udata); + bool (*callback)(ant_t *js, ant_value_t value, void *udata); void *udata; } js_iter_ctx_t; -static iter_action_t js_iter_cb(ant_t *js, jsval_t value, void *ctx, jsval_t *out) { +static iter_action_t js_iter_cb(ant_t *js, ant_value_t value, void *ctx, ant_value_t *out) { js_iter_ctx_t *ictx = (js_iter_ctx_t *)ctx; return ictx->callback(js, value, ictx->udata) ? ITER_CONTINUE : ITER_BREAK; } -bool js_iter(ant_t *js, jsval_t iterable, bool (*callback)(ant_t *js, jsval_t value, void *udata), void *udata) { +bool js_iter(ant_t *js, ant_value_t iterable, bool (*callback)(ant_t *js, ant_value_t value, void *udata), void *udata) { js_iter_ctx_t ctx = { .callback = callback, .udata = udata }; - jsval_t result = iter_foreach(js, iterable, js_iter_cb, &ctx); + ant_value_t result = iter_foreach(js, iterable, js_iter_cb, &ctx); return !is_err(result); } -char *js_getstr(ant_t *js, jsval_t value, size_t *len) { +char *js_getstr(ant_t *js, ant_value_t value, size_t *len) { if (vtype(value) != T_STR) return NULL; - jsoff_t n, off = vstr(js, value, &n); + ant_offset_t n, off = vstr(js, value, &n); if (len != NULL) *len = n; return (char *) &js->mem[off]; } -void js_merge_obj(ant_t *js, jsval_t dst, jsval_t src) { +void js_merge_obj(ant_t *js, ant_value_t dst, ant_value_t src) { if (vtype(dst) != T_OBJ || vtype(src) != T_OBJ) return; - jsoff_t next = loadoff(js, (jsoff_t) vdata(src)) & ~(3U | FLAGMASK); + ant_offset_t next = loadoff(js, (ant_offset_t) vdata(src)) & ~(3U | FLAGMASK); while (next < js->brk && next != 0) { - jsoff_t header = loadoff(js, next); + ant_offset_t header = loadoff(js, next); if (is_slot_prop(header)) { next = next_prop(header); continue; } - jsoff_t koff = loadoff(js, next + (jsoff_t) sizeof(next)); - jsval_t val = loadval(js, next + (jsoff_t) (sizeof(next) + sizeof(koff))); + ant_offset_t koff = loadoff(js, next + (ant_offset_t) sizeof(next)); + ant_value_t val = loadval(js, next + (ant_offset_t) (sizeof(next) + sizeof(koff))); js_setprop(js, dst, mkval(T_STR, koff), val); next = next_prop(header); @@ -12818,10 +12818,10 @@ for (typeof(registry) new_reg = NULL, *_once = NULL; !_once; _once = (void*)1, r HASH_ADD(hh, new_reg, key_field, key_size, entry); \ } -typedef jsoff_t (*gc_fwd_off_fn)(void *ctx, jsoff_t old); -typedef jsval_t (*gc_fwd_val_fn)(void *ctx, jsval_t old); -typedef void (*gc_off_op_t)(void *cb_ctx, jsoff_t *off); -typedef void (*gc_val_op_t)(void *cb_ctx, jsval_t *val); +typedef ant_offset_t (*gc_fwd_off_fn)(void *ctx, ant_offset_t old); +typedef ant_value_t (*gc_fwd_val_fn)(void *ctx, ant_value_t old); +typedef void (*gc_off_op_t)(void *cb_ctx, ant_offset_t *off); +typedef void (*gc_val_op_t)(void *cb_ctx, ant_value_t *val); typedef struct { gc_fwd_off_fn fwd_off; @@ -12831,27 +12831,27 @@ typedef struct { ant_t *js; } gc_cb_ctx_t; -static inline void gc_reserve_off_cb(void *cb_ctx, jsoff_t *off) { +static inline void gc_reserve_off_cb(void *cb_ctx, ant_offset_t *off) { gc_cb_ctx_t *c = cb_ctx; if (*off) (void)c->fwd_off(c->ctx, *off); } -static inline void gc_reserve_val_cb(void *cb_ctx, jsval_t *val) { +static inline void gc_reserve_val_cb(void *cb_ctx, ant_value_t *val) { gc_cb_ctx_t *c = cb_ctx; (void)c->fwd_val(c->ctx, *val); } -static inline void gc_update_off_cb(void *cb_ctx, jsoff_t *off) { +static inline void gc_update_off_cb(void *cb_ctx, ant_offset_t *off) { gc_cb_ctx_t *c = cb_ctx; if (*off) *off = c->fwd_off(c->ctx, *off); } -static inline void gc_update_val_cb(void *cb_ctx, jsval_t *val) { +static inline void gc_update_val_cb(void *cb_ctx, ant_value_t *val) { gc_cb_ctx_t *c = cb_ctx; *val = c->fwd_val(c->ctx, *val); } -static inline jsoff_t gc_weak_off_cb(void *cb_ctx, jsoff_t old) { +static inline ant_offset_t gc_weak_off_cb(void *cb_ctx, ant_offset_t old) { gc_cb_ctx_t *c = cb_ctx; return c->weak_off(c->ctx, old); } @@ -12905,7 +12905,7 @@ static void gc_roots_common(gc_off_op_t op_off, gc_val_op_t op_val, gc_cb_ctx_t sv_vm_gc_roots(c->js->vm, op_val, c); sv_vm_gc_roots_pending(op_val, c); - for (jshdl_t i = 0; i < c->js->gc_roots_len; i++) op_val(c, &c->js->gc_roots[i]); + for (ant_handle_t i = 0; i < c->js->gc_roots_len; i++) op_val(c, &c->js->gc_roots[i]); } void js_gc_reserve_roots(GC_RESERVE_ARGS) { @@ -12978,9 +12978,9 @@ void js_gc_update_roots(GC_UPDATE_ARGS) { ); if (in_unhandled) HASH_DELETE(hh_unhandled, unhandled_rejections, pd); - jsoff_t new_off = weak_off(ctx, pd->obj_offset); + ant_offset_t new_off = weak_off(ctx, pd->obj_offset); - if (new_off == (jsoff_t)~0 && !pd->processing) { + if (new_off == (ant_offset_t)~0 && !pd->processing) { utarray_free(pd->handlers); free(pd); continue; } @@ -13012,35 +13012,35 @@ void js_gc_update_roots(GC_UPDATE_ARGS) { for (proxy_data_t *new_proxy_registry = NULL, *_once = NULL; !_once; _once = (void*)1, proxy_registry = new_proxy_registry) HASH_ITER(hh, proxy_registry, proxy, proxy_tmp) { HASH_DEL(proxy_registry, proxy); - jsoff_t new_off = weak_off(ctx, proxy->obj_offset); - if (new_off == (jsoff_t)~0) { free(proxy); continue; } + ant_offset_t new_off = weak_off(ctx, proxy->obj_offset); + if (new_off == (ant_offset_t)~0) { free(proxy); continue; } proxy->obj_offset = new_off; FWD_VAL(proxy->target); FWD_VAL(proxy->handler); - HASH_ADD(hh, new_proxy_registry, obj_offset, sizeof(jsoff_t), proxy); + HASH_ADD(hh, new_proxy_registry, obj_offset, sizeof(ant_offset_t), proxy); } dynamic_accessors_t *acc, *acc_tmp; for (dynamic_accessors_t *new_acc_registry = NULL, *_once = NULL; !_once; _once = (void*)1, accessor_registry = new_acc_registry) HASH_ITER(hh, accessor_registry, acc, acc_tmp) { HASH_DEL(accessor_registry, acc); - jsoff_t new_off = weak_off(ctx, acc->obj_offset); - if (new_off == (jsoff_t)~0) { free(acc); continue; } + ant_offset_t new_off = weak_off(ctx, acc->obj_offset); + if (new_off == (ant_offset_t)~0) { free(acc); continue; } acc->obj_offset = new_off; - HASH_ADD(hh, new_acc_registry, obj_offset, sizeof(jsoff_t), acc); + HASH_ADD(hh, new_acc_registry, obj_offset, sizeof(ant_offset_t), acc); } descriptor_entry_t *desc, *desc_tmp; for (descriptor_entry_t *new_desc_registry = NULL, *_once = NULL; !_once; _once = (void*)1, desc_registry = new_desc_registry) HASH_ITER(hh, desc_registry, desc, desc_tmp) { HASH_DEL(desc_registry, desc); - jsoff_t new_off = weak_off(ctx, (jsoff_t)(desc->key >> 32)); - if (new_off == (jsoff_t)~0) { free(desc); continue; } + ant_offset_t new_off = weak_off(ctx, (ant_offset_t)(desc->key >> 32)); + if (new_off == (ant_offset_t)~0) { free(desc); continue; } if (desc->has_getter) FWD_VAL(desc->getter); if (desc->has_setter) FWD_VAL(desc->setter); if (desc->prop_name) { desc->key = ((uint64_t)new_off << 32) | (uint32_t)(desc->key & 0xFFFFFFFF); } else { - jsoff_t new_sym = fwd_off(ctx, desc->sym_off); + ant_offset_t new_sym = fwd_off(ctx, desc->sym_off); desc->sym_off = new_sym; desc->key = make_sym_desc_key(new_off, new_sym); } @@ -13059,7 +13059,7 @@ void js_gc_update_roots(GC_UPDATE_ARGS) { #undef UTARRAY_EACH #undef REHASH_REGISTRY -bool js_chkargs(jsval_t *args, int nargs, const char *spec) { +bool js_chkargs(ant_value_t *args, int nargs, const char *spec) { int i = 0, ok = 1; for (; ok && i < nargs && spec[i]; i++) { uint8_t t = vtype(args[i]), c = (uint8_t) spec[i]; @@ -13070,25 +13070,25 @@ bool js_chkargs(jsval_t *args, int nargs, const char *spec) { return ok; } -static jsval_t js_eval_bytecode_mode(ant_t *js, const char *buf, size_t len, sv_compile_mode_t mode, bool parse_strict) { +static ant_value_t js_eval_bytecode_mode(ant_t *js, const char *buf, size_t len, sv_compile_mode_t mode, bool parse_strict) { if (len == (size_t)~0U) len = strlen(buf); - sv_ast_t *program = sv_parse(js, buf, (jsoff_t)len, parse_strict); + sv_ast_t *program = sv_parse(js, buf, (ant_offset_t)len, parse_strict); if (!program) { if (js->thrown_exists) return mkval(T_ERR, 0); return js_mkerr_typed(js, JS_ERR_INTERNAL | JS_ERR_NO_STACK, "Unexpected parse error"); } - sv_func_t *func = sv_compile(js, program, mode, buf, (jsoff_t)len); + sv_func_t *func = sv_compile(js, program, mode, buf, (ant_offset_t)len); if (!func) { if (js->thrown_exists) return mkval(T_ERR, 0); return js_mkerr_typed(js, JS_ERR_INTERNAL | JS_ERR_NO_STACK, "Unexpected compile error"); } js_clear_error_site(js); - jsval_t result; + ant_value_t result; // TODO: this-newtarget-frame-migration - jsval_t saved_this = js->this_val; + ant_value_t saved_this = js->this_val; if (sv_dump_bytecode_unlikely) sv_disasm(js, func, js->filename); if (func->is_tla) result = sv_execute_entry_tla(js, func, js->this_val); @@ -13098,68 +13098,68 @@ static jsval_t js_eval_bytecode_mode(ant_t *js, const char *buf, size_t len, sv_ return result; } -jsval_t js_eval_bytecode(ant_t *js, const char *buf, size_t len) { +ant_value_t js_eval_bytecode(ant_t *js, const char *buf, size_t len) { return js_eval_bytecode_mode(js, buf, len, SV_COMPILE_SCRIPT, false); } -jsval_t js_eval_bytecode_module(ant_t *js, const char *buf, size_t len) { +ant_value_t js_eval_bytecode_module(ant_t *js, const char *buf, size_t len) { return js_eval_bytecode_mode(js, buf, len, SV_COMPILE_MODULE, false); } -jsval_t js_eval_bytecode_eval(ant_t *js, const char *buf, size_t len) { +ant_value_t js_eval_bytecode_eval(ant_t *js, const char *buf, size_t len) { return js_eval_bytecode_mode(js, buf, len, SV_COMPILE_EVAL, false); } -jsval_t js_eval_bytecode_eval_with_strict(ant_t *js, const char *buf, size_t len, bool inherit_strict) { +ant_value_t js_eval_bytecode_eval_with_strict(ant_t *js, const char *buf, size_t len, bool inherit_strict) { return js_eval_bytecode_mode(js, buf, len, SV_COMPILE_EVAL, inherit_strict); } -jsval_t js_eval_bytecode_repl(ant_t *js, const char *buf, size_t len) { +ant_value_t js_eval_bytecode_repl(ant_t *js, const char *buf, size_t len) { return js_eval_bytecode_mode(js, buf, len, SV_COMPILE_REPL, false); } -jsval_t sv_call_native( - ant_t *js, jsval_t func, jsval_t this_val, - jsval_t *args, int nargs +ant_value_t sv_call_native( + ant_t *js, ant_value_t func, ant_value_t this_val, + ant_value_t *args, int nargs ) { if (vtype(func) == T_FFI) return ffi_call_by_index(js, (unsigned int)vdata(func), args, nargs); if (vtype(func) == T_CFUNC) { - jsval_t saved_this = js->this_val; + ant_value_t saved_this = js->this_val; js->this_val = this_val; - jsval_t (*fn)(ant_t *, jsval_t *, int) = (jsval_t(*)(ant_t *, jsval_t *, int))vdata(func); - jsval_t res = fn(js, args, nargs); + ant_value_t (*fn)(ant_t *, ant_value_t *, int) = (ant_value_t(*)(ant_t *, ant_value_t *, int))vdata(func); + ant_value_t res = fn(js, args, nargs); js->this_val = saved_this; return res; } if (vtype(func) == T_FUNC) { - jsval_t func_obj = js_func_obj(func); + ant_value_t func_obj = js_func_obj(func); - jsval_t cfunc_slot = get_slot(js, func_obj, SLOT_CFUNC); + ant_value_t cfunc_slot = get_slot(js, func_obj, SLOT_CFUNC); if (vtype(cfunc_slot) == T_CFUNC) { - jsval_t slot_bound_this = get_slot(js, func_obj, SLOT_BOUND_THIS); + ant_value_t slot_bound_this = get_slot(js, func_obj, SLOT_BOUND_THIS); int final_nargs; - jsval_t *combined = resolve_bound_args(js, func_obj, args, nargs, &final_nargs); - jsval_t *final_args = combined ? combined : args; - jsval_t saved_func = js->current_func; - jsval_t saved_this = js->this_val; + ant_value_t *combined = resolve_bound_args(js, func_obj, args, nargs, &final_nargs); + ant_value_t *final_args = combined ? combined : args; + ant_value_t saved_func = js->current_func; + ant_value_t saved_this = js->this_val; js->current_func = func; js->this_val = (vtype(slot_bound_this) != T_UNDEF) ? slot_bound_this : this_val; - jsval_t (*fn)(ant_t *, jsval_t *, int) = (jsval_t(*)(ant_t *, jsval_t *, int))vdata(cfunc_slot); - jsval_t res = fn(js, final_args, final_nargs); + ant_value_t (*fn)(ant_t *, ant_value_t *, int) = (ant_value_t(*)(ant_t *, ant_value_t *, int))vdata(cfunc_slot); + ant_value_t res = fn(js, final_args, final_nargs); js->current_func = saved_func; js->this_val = saved_this; if (combined) free(combined); return res; } - jsval_t builtin_slot = get_slot(js, func_obj, SLOT_BUILTIN); + ant_value_t builtin_slot = get_slot(js, func_obj, SLOT_BUILTIN); if (vtype(builtin_slot) == T_NUM && (int)tod(builtin_slot) == BUILTIN_OBJECT) { - jsval_t saved_this = js->this_val; + ant_value_t saved_this = js->this_val; js->this_val = this_val; - jsval_t res = builtin_Object(js, args, nargs); + ant_value_t res = builtin_Object(js, args, nargs); js->this_val = saved_this; return res; } @@ -13168,25 +13168,25 @@ jsval_t sv_call_native( return js_mkerr_typed(js, JS_ERR_TYPE, "%s is not a function", typestr(vtype(func))); } -ant_iter_t js_prop_iter_begin(ant_t *js, jsval_t obj) { +ant_iter_t js_prop_iter_begin(ant_t *js, ant_value_t obj) { ant_iter_t iter = {.ctx = js, .off = 0}; uint8_t t = vtype(obj); if (t == T_OBJ || t == T_ARR || t == T_FUNC) { - iter.off = (jsoff_t)vdata(js_as_obj(obj)); + iter.off = (ant_offset_t)vdata(js_as_obj(obj)); } return iter; } -bool js_prop_iter_next(ant_iter_t *iter, const char **key, size_t *key_len, jsval_t *value) { +bool js_prop_iter_next(ant_iter_t *iter, const char **key, size_t *key_len, ant_value_t *value) { if (!iter || !iter->ctx) return false; ant_t *js = (ant_t *)iter->ctx; - jsoff_t next = loadoff(js, iter->off) & ~(3U | FLAGMASK); + ant_offset_t next = loadoff(js, iter->off) & ~(3U | FLAGMASK); while (next < js->brk && next != 0) { - jsoff_t header = loadoff(js, next); + ant_offset_t header = loadoff(js, next); if (!is_slot_prop(header) && !is_sym_key_prop(js, next)) break; next = next_prop(header); } @@ -13194,12 +13194,12 @@ bool js_prop_iter_next(ant_iter_t *iter, const char **key, size_t *key_len, jsva if (next >= js->brk || next == 0) return false; iter->off = next; - jsoff_t koff = loadoff(js, next + (jsoff_t)sizeof(jsoff_t)); - jsval_t val = loadval(js, next + (jsoff_t)(sizeof(jsoff_t) * 2)); + ant_offset_t koff = loadoff(js, next + (ant_offset_t)sizeof(ant_offset_t)); + ant_value_t val = loadval(js, next + (ant_offset_t)(sizeof(ant_offset_t) * 2)); if (key) { - jsoff_t klen = offtolen(loadoff(js, koff)); - *key = (const char *)&js->mem[koff + sizeof(jsoff_t)]; + ant_offset_t klen = offtolen(loadoff(js, koff)); + *key = (const char *)&js->mem[koff + sizeof(ant_offset_t)]; if (key_len) *key_len = klen; } if (value) *value = val; @@ -13211,9 +13211,9 @@ void js_prop_iter_end(ant_iter_t *iter) { if (iter) { iter->off = 0; iter->ctx = NULL; } } -jsval_t js_mkpromise(ant_t *js) { return mkpromise(js); } -void js_resolve_promise(ant_t *js, jsval_t promise, jsval_t value) { resolve_promise(js, promise, value); } -void js_reject_promise(ant_t *js, jsval_t promise, jsval_t value) { reject_promise(js, promise, value); } +ant_value_t js_mkpromise(ant_t *js) { return mkpromise(js); } +void js_resolve_promise(ant_t *js, ant_value_t promise, ant_value_t value) { resolve_promise(js, promise, value); } +void js_reject_promise(ant_t *js, ant_value_t promise, ant_value_t value) { reject_promise(js, promise, value); } void js_check_unhandled_rejections(ant_t *js) { promise_data_entry_t *pd, *tmp; @@ -13244,74 +13244,74 @@ void js_check_unhandled_rejections(ant_t *js) { } } -bool js_is_slot_prop(jsoff_t header) { return is_slot_prop(header); } -jsoff_t js_next_prop(jsoff_t header) { return next_prop(header); } -jsoff_t js_loadoff(ant_t *js, jsoff_t off) { return loadoff(js, off); } +bool js_is_slot_prop(ant_offset_t header) { return is_slot_prop(header); } +ant_offset_t js_next_prop(ant_offset_t header) { return next_prop(header); } +ant_offset_t js_loadoff(ant_t *js, ant_offset_t off) { return loadoff(js, off); } -void js_set_getter(ant_t *js, jsval_t obj, js_getter_fn getter) { +void js_set_getter(ant_t *js, ant_value_t obj, js_getter_fn getter) { if (!is_object_type(obj)) return; if (vtype(obj) != T_OBJ) obj = js_as_obj(obj); - jsoff_t obj_off = (jsoff_t)vdata(obj); + ant_offset_t obj_off = (ant_offset_t)vdata(obj); dynamic_accessors_t *entry = NULL; - HASH_FIND(hh, accessor_registry, &obj_off, sizeof(jsoff_t), entry); + HASH_FIND(hh, accessor_registry, &obj_off, sizeof(ant_offset_t), entry); if (!entry) { entry = (dynamic_accessors_t *)malloc(sizeof(dynamic_accessors_t)); if (!entry) return; entry->obj_offset = obj_off; entry->getter = NULL; entry->setter = NULL; entry->deleter = NULL; entry->keys = NULL; - HASH_ADD(hh, accessor_registry, obj_offset, sizeof(jsoff_t), entry); + HASH_ADD(hh, accessor_registry, obj_offset, sizeof(ant_offset_t), entry); } entry->getter = getter; } -void js_set_setter(ant_t *js, jsval_t obj, js_setter_fn setter) { +void js_set_setter(ant_t *js, ant_value_t obj, js_setter_fn setter) { if (!is_object_type(obj)) return; if (vtype(obj) != T_OBJ) obj = js_as_obj(obj); - jsoff_t obj_off = (jsoff_t)vdata(obj); + ant_offset_t obj_off = (ant_offset_t)vdata(obj); dynamic_accessors_t *entry = NULL; - HASH_FIND(hh, accessor_registry, &obj_off, sizeof(jsoff_t), entry); + HASH_FIND(hh, accessor_registry, &obj_off, sizeof(ant_offset_t), entry); if (!entry) { entry = (dynamic_accessors_t *)malloc(sizeof(dynamic_accessors_t)); if (!entry) return; entry->obj_offset = obj_off; entry->getter = NULL; entry->setter = NULL; entry->deleter = NULL; entry->keys = NULL; - HASH_ADD(hh, accessor_registry, obj_offset, sizeof(jsoff_t), entry); + HASH_ADD(hh, accessor_registry, obj_offset, sizeof(ant_offset_t), entry); } entry->setter = setter; } -void js_set_deleter(ant_t *js, jsval_t obj, js_deleter_fn deleter) { +void js_set_deleter(ant_t *js, ant_value_t obj, js_deleter_fn deleter) { if (!is_object_type(obj)) return; if (vtype(obj) != T_OBJ) obj = js_as_obj(obj); - jsoff_t obj_off = (jsoff_t)vdata(obj); + ant_offset_t obj_off = (ant_offset_t)vdata(obj); dynamic_accessors_t *entry = NULL; - HASH_FIND(hh, accessor_registry, &obj_off, sizeof(jsoff_t), entry); + HASH_FIND(hh, accessor_registry, &obj_off, sizeof(ant_offset_t), entry); if (!entry) { entry = (dynamic_accessors_t *)malloc(sizeof(dynamic_accessors_t)); if (!entry) return; entry->obj_offset = obj_off; entry->getter = NULL; entry->setter = NULL; entry->deleter = NULL; entry->keys = NULL; - HASH_ADD(hh, accessor_registry, obj_offset, sizeof(jsoff_t), entry); + HASH_ADD(hh, accessor_registry, obj_offset, sizeof(ant_offset_t), entry); } entry->deleter = deleter; } -void js_set_keys(ant_t *js, jsval_t obj, js_keys_fn keys) { +void js_set_keys(ant_t *js, ant_value_t obj, js_keys_fn keys) { if (!is_object_type(obj)) return; if (vtype(obj) != T_OBJ) obj = js_as_obj(obj); - jsoff_t obj_off = (jsoff_t)vdata(obj); + ant_offset_t obj_off = (ant_offset_t)vdata(obj); dynamic_accessors_t *entry = NULL; - HASH_FIND(hh, accessor_registry, &obj_off, sizeof(jsoff_t), entry); + HASH_FIND(hh, accessor_registry, &obj_off, sizeof(ant_offset_t), entry); if (!entry) { entry = (dynamic_accessors_t *)malloc(sizeof(dynamic_accessors_t)); if (!entry) return; entry->obj_offset = obj_off; entry->getter = NULL; entry->setter = NULL; entry->deleter = NULL; entry->keys = NULL; - HASH_ADD(hh, accessor_registry, obj_offset, sizeof(jsoff_t), entry); + HASH_ADD(hh, accessor_registry, obj_offset, sizeof(ant_offset_t), entry); } entry->keys = keys; } diff --git a/src/descriptors.c b/src/descriptors.c index d80e65c..6140450 100644 --- a/src/descriptors.c +++ b/src/descriptors.c @@ -13,16 +13,16 @@ static descriptor_entry_t arr_length_desc = { .getter = 0, .setter = 0, }; -uint64_t make_desc_key(jsoff_t obj_off, const char *key, size_t klen) { +uint64_t make_desc_key(ant_offset_t obj_off, const char *key, size_t klen) { uint32_t key_hash = (uint32_t)hash_key(key, klen) & 0x7FFFFFFFu; return ((uint64_t)obj_off << 32) | key_hash; } -uint64_t make_sym_desc_key(jsoff_t obj_off, jsoff_t sym_off) { +uint64_t make_sym_desc_key(ant_offset_t obj_off, ant_offset_t sym_off) { return ((uint64_t)obj_off << 32) | ((uint32_t)sym_off | 0x80000000u); } -descriptor_entry_t *lookup_descriptor(ant_t *js, jsoff_t obj_off, const char *key, size_t klen) { +descriptor_entry_t *lookup_descriptor(ant_t *js, ant_offset_t obj_off, const char *key, size_t klen) { if (klen == 6 && memcmp(key, "length", 6) == 0 && is_arr_off(js, obj_off) @@ -35,17 +35,17 @@ descriptor_entry_t *lookup_descriptor(ant_t *js, jsoff_t obj_off, const char *ke return entry; } -descriptor_entry_t *lookup_sym_descriptor(jsoff_t obj_off, jsoff_t sym_off) { +descriptor_entry_t *lookup_sym_descriptor(ant_offset_t obj_off, ant_offset_t sym_off) { descriptor_entry_t *entry = NULL; uint64_t k = make_sym_desc_key(obj_off, sym_off); HASH_FIND(hh, desc_registry, &k, sizeof(uint64_t), entry); return entry; } -static descriptor_entry_t *get_or_create_desc(ant_t *js, jsval_t obj, const char *key, size_t klen) { +static descriptor_entry_t *get_or_create_desc(ant_t *js, ant_value_t obj, const char *key, size_t klen) { if (vtype(obj) != T_OBJ && vtype(obj) != T_FUNC && vtype(obj) != T_ARR) return NULL; obj = js_as_obj(obj); - jsoff_t obj_off = (jsoff_t)vdata(obj); + ant_offset_t obj_off = (ant_offset_t)vdata(obj); uint64_t desc_key = make_desc_key(obj_off, key, klen); descriptor_entry_t *entry = NULL; @@ -73,20 +73,20 @@ static descriptor_entry_t *get_or_create_desc(ant_t *js, jsval_t obj, const char return entry; } -static void ensure_string_prop_node(ant_t *js, jsval_t obj, const char *key, size_t klen) { +static void ensure_string_prop_node(ant_t *js, ant_value_t obj, const char *key, size_t klen) { if (vtype(obj) == T_FUNC) obj = js_func_obj(obj); if (vtype(obj) != T_OBJ && vtype(obj) != T_ARR) return; if (lkp(js, obj, key, klen) != 0) return; - jsval_t key_val = js_mkstr(js, key, klen); + ant_value_t key_val = js_mkstr(js, key, klen); if (is_err(key_val)) return; (void)mkprop(js, obj, key_val, js_mkundef(), 0); } -static descriptor_entry_t *get_or_create_sym_desc(ant_t *js, jsval_t obj, jsoff_t sym_off) { +static descriptor_entry_t *get_or_create_sym_desc(ant_t *js, ant_value_t obj, ant_offset_t sym_off) { if (vtype(obj) == T_FUNC) obj = js_func_obj(obj); if (vtype(obj) != T_OBJ && vtype(obj) != T_ARR) return NULL; - jsoff_t obj_off = (jsoff_t)vdata(obj); + ant_offset_t obj_off = (ant_offset_t)vdata(obj); uint64_t k = make_sym_desc_key(obj_off, sym_off); descriptor_entry_t *entry = NULL; @@ -109,16 +109,16 @@ static descriptor_entry_t *get_or_create_sym_desc(ant_t *js, jsval_t obj, jsoff_ return entry; } -static void ensure_symbol_prop_node(ant_t *js, jsval_t obj, jsoff_t sym_off) { +static void ensure_symbol_prop_node(ant_t *js, ant_value_t obj, ant_offset_t sym_off) { if (vtype(obj) == T_FUNC) obj = js_func_obj(obj); if (vtype(obj) != T_OBJ && vtype(obj) != T_ARR) return; if (lkp_sym(js, obj, sym_off) != 0) return; - jsval_t sym = mkval(T_SYMBOL, sym_off); + ant_value_t sym = mkval(T_SYMBOL, sym_off); (void)mkprop(js, obj, sym, js_mkundef(), 0); } -void js_set_descriptor(ant_t *js, jsval_t obj, const char *key, size_t klen, int flags) { +void js_set_descriptor(ant_t *js, ant_value_t obj, const char *key, size_t klen, int flags) { descriptor_entry_t *entry = get_or_create_desc(js, obj, key, klen); if (!entry) return; entry->writable = (flags & JS_DESC_W) != 0; @@ -126,7 +126,7 @@ void js_set_descriptor(ant_t *js, jsval_t obj, const char *key, size_t klen, int entry->configurable = (flags & JS_DESC_C) != 0; } -void js_set_getter_desc(ant_t *js, jsval_t obj, const char *key, size_t klen, jsval_t getter, int flags) { +void js_set_getter_desc(ant_t *js, ant_value_t obj, const char *key, size_t klen, ant_value_t getter, int flags) { ensure_string_prop_node(js, obj, key, klen); descriptor_entry_t *entry = get_or_create_desc(js, obj, key, klen); if (!entry) return; @@ -136,7 +136,7 @@ void js_set_getter_desc(ant_t *js, jsval_t obj, const char *key, size_t klen, js entry->getter = getter; } -void js_set_setter_desc(ant_t *js, jsval_t obj, const char *key, size_t klen, jsval_t setter, int flags) { +void js_set_setter_desc(ant_t *js, ant_value_t obj, const char *key, size_t klen, ant_value_t setter, int flags) { ensure_string_prop_node(js, obj, key, klen); descriptor_entry_t *entry = get_or_create_desc(js, obj, key, klen); if (!entry) return; @@ -146,7 +146,7 @@ void js_set_setter_desc(ant_t *js, jsval_t obj, const char *key, size_t klen, js entry->setter = setter; } -void js_set_accessor_desc(ant_t *js, jsval_t obj, const char *key, size_t klen, jsval_t getter, jsval_t setter, int flags) { +void js_set_accessor_desc(ant_t *js, ant_value_t obj, const char *key, size_t klen, ant_value_t getter, ant_value_t setter, int flags) { ensure_string_prop_node(js, obj, key, klen); descriptor_entry_t *entry = get_or_create_desc(js, obj, key, klen); if (!entry) return; @@ -158,10 +158,10 @@ void js_set_accessor_desc(ant_t *js, jsval_t obj, const char *key, size_t klen, entry->setter = setter; } -void js_set_sym_getter_desc(ant_t *js, jsval_t obj, jsval_t sym, jsval_t getter, int flags) { +void js_set_sym_getter_desc(ant_t *js, ant_value_t obj, ant_value_t sym, ant_value_t getter, int flags) { if (vtype(sym) != T_SYMBOL) return; - ensure_symbol_prop_node(js, obj, (jsoff_t)vdata(sym)); - descriptor_entry_t *entry = get_or_create_sym_desc(js, obj, (jsoff_t)vdata(sym)); + ensure_symbol_prop_node(js, obj, (ant_offset_t)vdata(sym)); + descriptor_entry_t *entry = get_or_create_sym_desc(js, obj, (ant_offset_t)vdata(sym)); if (!entry) return; entry->enumerable = (flags & JS_DESC_E) != 0; entry->configurable = (flags & JS_DESC_C) != 0; @@ -169,10 +169,10 @@ void js_set_sym_getter_desc(ant_t *js, jsval_t obj, jsval_t sym, jsval_t getter, entry->getter = getter; } -void js_set_sym_setter_desc(ant_t *js, jsval_t obj, jsval_t sym, jsval_t setter, int flags) { +void js_set_sym_setter_desc(ant_t *js, ant_value_t obj, ant_value_t sym, ant_value_t setter, int flags) { if (vtype(sym) != T_SYMBOL) return; - ensure_symbol_prop_node(js, obj, (jsoff_t)vdata(sym)); - descriptor_entry_t *entry = get_or_create_sym_desc(js, obj, (jsoff_t)vdata(sym)); + ensure_symbol_prop_node(js, obj, (ant_offset_t)vdata(sym)); + descriptor_entry_t *entry = get_or_create_sym_desc(js, obj, (ant_offset_t)vdata(sym)); if (!entry) return; entry->enumerable = (flags & JS_DESC_E) != 0; entry->configurable = (flags & JS_DESC_C) != 0; diff --git a/src/errors.c b/src/errors.c index ef81fdc..f3fe30a 100644 --- a/src/errors.c +++ b/src/errors.c @@ -20,15 +20,15 @@ typedef struct { char *buf; size_t size; } errbuf_t; -static void print_error_value(ant_t *js, jsval_t value, jsval_t fallback_stack, const char *prefix) { +static void print_error_value(ant_t *js, ant_value_t value, ant_value_t fallback_stack, const char *prefix) { const char *stack = NULL; if (vtype(value) == T_OBJ) stack = get_str_prop(js, value, "stack", 5, NULL); if (!stack && vtype(fallback_stack) == T_STR) { - jsoff_t slen; - jsoff_t soff = vstr(js, fallback_stack, &slen); + ant_offset_t slen; + ant_offset_t soff = vstr(js, fallback_stack, &slen); stack = (const char *)&js->mem[soff]; } @@ -58,7 +58,7 @@ bool print_uncaught_throw(ant_t *js) { return true; } -bool print_unhandled_promise_rejection(ant_t *js, jsval_t value) { +bool print_unhandled_promise_rejection(ant_t *js, ant_value_t value) { print_error_value(js, value, js_mkundef(), "Uncaught (in promise) "); return true; } @@ -131,7 +131,7 @@ static size_t append_error_header(errbuf_t *eb, ant_t *js, size_t used, int line return append_errbuf_fmt(eb, used, ":%d:%d\n", line, col); } -static void get_line_col(const char *code, jsoff_t code_len, jsoff_t pos, int *out_line, int *out_col) { +static void get_line_col(const char *code, ant_offset_t code_len, ant_offset_t pos, int *out_line, int *out_col) { if (!out_line || !out_col) return; *out_line = 1; @@ -140,7 +140,7 @@ static void get_line_col(const char *code, jsoff_t code_len, jsoff_t pos, int *o if (!code || code_len <= 0 || pos <= 0) return; if (pos > code_len) pos = code_len; - for (jsoff_t i = 0; i < pos; i++) { + for (ant_offset_t i = 0; i < pos; i++) { char ch = code[i]; if (ch == '\0') break; if (ch == '\n') { @@ -151,8 +151,8 @@ static void get_line_col(const char *code, jsoff_t code_len, jsoff_t pos, int *o } static void get_error_line( - const char *code, jsoff_t clen, jsoff_t pos, char *buf, size_t bufsize, - int *line_start_col, jsoff_t *out_line_start, jsoff_t *out_line_end + const char *code, ant_offset_t clen, ant_offset_t pos, char *buf, size_t bufsize, + int *line_start_col, ant_offset_t *out_line_start, ant_offset_t *out_line_end ) { if (!code || bufsize == 0) { if (bufsize > 0) buf[0] = '\0'; @@ -172,18 +172,18 @@ static void get_error_line( return; } - jsoff_t line_start = pos; + ant_offset_t line_start = pos; while (line_start > 0 && code[line_start - 1] != '\n') { line_start--; } - jsoff_t line_end = pos; + ant_offset_t line_end = pos; while (line_end < clen && code[line_end] != '\n' && code[line_end] != '\0') { line_end++; } - jsoff_t line_len = line_end - line_start; - if (line_len >= bufsize) line_len = (jsoff_t)(bufsize - 1); + ant_offset_t line_len = line_end - line_start; + if (line_len >= bufsize) line_len = (ant_offset_t)(bufsize - 1); memcpy(buf, &code[line_start], line_len); buf[line_len] = '\0'; @@ -193,12 +193,12 @@ static void get_error_line( if (out_line_end) *out_line_end = line_end; } -static size_t append_error_value(errbuf_t *eb, ant_t *js, size_t used, jsval_t value) { +static size_t append_error_value(errbuf_t *eb, ant_t *js, size_t used, ant_value_t value) { const char *name = "Error"; const char *msg = NULL; - jsoff_t name_len = 5; - jsoff_t msg_len = 0; + ant_offset_t name_len = 5; + ant_offset_t msg_len = 0; static const void *type_dispatch[] = { [T_STR] = &&l_type_str, @@ -241,7 +241,7 @@ static size_t append_error_value(errbuf_t *eb, ant_t *js, size_t used, jsval_t v l_type_default: msg = js_str(js, value); - msg_len = msg ? (jsoff_t)strlen(msg) : 0; + msg_len = msg ? (ant_offset_t)strlen(msg) : 0; goto l_type_done; l_type_done: @@ -288,17 +288,17 @@ static void append_error_caret(errbuf_t *eb, size_t *n, int error_col, int span_ eb->buf[*n] = '\0'; } -static int error_span_cols_for_line(jsoff_t src_pos, jsoff_t span_len, jsoff_t line_start, jsoff_t line_end) { +static int error_span_cols_for_line(ant_offset_t src_pos, ant_offset_t span_len, ant_offset_t line_start, ant_offset_t line_end) { if (line_end < line_start) return 1; if (src_pos < line_start) src_pos = line_start; if (src_pos > line_end) src_pos = line_end; if (span_len <= 0) return 1; - jsoff_t span_end = src_pos + span_len; + ant_offset_t span_end = src_pos + span_len; if (span_end < src_pos) span_end = src_pos; if (span_end > line_end) span_end = line_end; - jsoff_t width = span_end - src_pos; + ant_offset_t width = span_end - src_pos; if (width <= 0) width = 1; if (width > INT_MAX) width = INT_MAX; return (int)width; @@ -346,7 +346,7 @@ static int error_context_src_cols_limit(int gutter_w) { static const char *error_frame_name(ant_t *js, sv_frame_t *frame, sv_func_t *func) { if (func && func->name && func->name[0]) return func->name; if (js && frame && vtype(frame->callee) == T_FUNC) { - jsoff_t name_len = 0; + ant_offset_t name_len = 0; const char *name = get_str_prop(js, js_func_obj(frame->callee), "name", 4, &name_len); if (name && name_len > 0) return name; } @@ -449,24 +449,24 @@ static bool error_visit_frame_print_file(ant_t *js, const js_vm_frame_view_t *vi static bool append_error_context( errbuf_t *eb, size_t *n, - const char *src, jsoff_t src_len, - jsoff_t src_pos, + const char *src, ant_offset_t src_len, + ant_offset_t src_pos, int error_line_no, int error_col, int error_span_cols ) { if (!src || src_len <= 0 || !n) return false; if (src_pos < 0) src_pos = 0; if (src_pos > src_len) src_pos = src_len; - jsoff_t err_line_start = src_pos; + ant_offset_t err_line_start = src_pos; while (err_line_start > 0 && src[err_line_start - 1] != '\n') err_line_start--; - jsoff_t err_line_end = src_pos; + ant_offset_t err_line_end = src_pos; while (err_line_end < src_len && src[err_line_end] != '\n' && src[err_line_end] != '\0') err_line_end++; - jsoff_t ctx_start = err_line_start; + ant_offset_t ctx_start = err_line_start; int first_line_no = error_line_no; for (int i = 0; i < 5 && ctx_start > 0; i++) { - jsoff_t prev = ctx_start - 1; + ant_offset_t prev = ctx_start - 1; if (src[prev] == '\n') prev--; while (prev >= 0 && src[prev] != '\n') prev--; @@ -481,11 +481,11 @@ static bool append_error_context( char tagged[4096]; char rendered[8192]; highlight_state hl_state = HL_STATE_INIT; - jsoff_t cur = ctx_start; + ant_offset_t cur = ctx_start; int line_no = first_line_no; while (cur <= err_line_end && cur < src_len) { - jsoff_t ls = cur, le = cur; + ant_offset_t ls = cur, le = cur; while (le < src_len && src[le] != '\n' && src[le] != '\0') le++; int line_len = (int)(le - ls); @@ -574,7 +574,7 @@ static void format_error_stack(errbuf_t *eb, ant_t *js, size_t *n, int line, int eb->buf[eb->size - 1] = '\0'; } -void js_set_error_site(ant_t *js, const char *src, jsoff_t src_len, const char *filename, jsoff_t off, jsoff_t span_len) { +void js_set_error_site(ant_t *js, const char *src, ant_offset_t src_len, const char *filename, ant_offset_t off, ant_offset_t span_len) { if (!js) return; js->errsite.src = src; @@ -591,15 +591,15 @@ void js_clear_error_site(ant_t *js) { } static void resolve_error_site( - ant_t *js, const char **out_src, jsoff_t *out_src_len, - jsoff_t *out_src_pos, jsoff_t *out_span_len + ant_t *js, const char **out_src, ant_offset_t *out_src_len, + ant_offset_t *out_src_pos, ant_offset_t *out_span_len ) { if (js && !js->errsite.valid) js_set_error_site_from_vm_top(js); const char *src = NULL; - jsoff_t src_len = 0; - jsoff_t src_pos = 0; - jsoff_t span_len = 0; + ant_offset_t src_len = 0; + ant_offset_t src_pos = 0; + ant_offset_t span_len = 0; if (js->errsite.valid) { src = js->errsite.src; @@ -616,8 +616,8 @@ static void resolve_error_site( typedef struct { const char *src; - jsoff_t src_len; - jsoff_t src_pos; + ant_offset_t src_len; + ant_offset_t src_pos; int error_col; int error_span_cols; int line; @@ -633,8 +633,8 @@ static void js_prepare_error_render_site(ant_t *js, js_error_render_site_t *site site->error_col = 1; site->error_span_cols = 1; - jsoff_t src_span_len = 0; - jsoff_t line_start = 0, line_end = 0; + ant_offset_t src_span_len = 0; + ant_offset_t line_start = 0, line_end = 0; resolve_error_site(js, &site->src, &site->src_len, &site->src_pos, &src_span_len); get_line_col(site->src, site->src_len, site->src_pos, &site->line, &site->col); @@ -651,7 +651,7 @@ typedef enum { JS_STACK_TEXT_FROM_THROW_VALUE = 1, } js_stack_text_kind_t; -static jsval_t js_build_stack_text(ant_t *js, js_stack_text_kind_t kind, jsval_t value) { +static ant_value_t js_build_stack_text(ant_t *js, js_stack_text_kind_t kind, ant_value_t value) { js_error_render_site_t site; js_prepare_error_render_site(js, &site); @@ -683,7 +683,7 @@ static jsval_t js_build_stack_text(ant_t *js, js_stack_text_kind_t kind, jsval_t const char *err_name = "Error"; const char *err_msg = NULL; - jsoff_t name_len = 5, msg_len = 0; + ant_offset_t name_len = 5, msg_len = 0; const char *n_str = get_str_prop(js, value, "name", 4, &name_len); if (n_str) err_name = n_str; @@ -706,13 +706,13 @@ static jsval_t js_build_stack_text(ant_t *js, js_stack_text_kind_t kind, jsval_t site.error_line, site.error_col, site.error_span_cols ); - jsval_t stack_str = js_mkstr(js, eb.buf, n); + ant_value_t stack_str = js_mkstr(js, eb.buf, n); free(eb.buf); return stack_str; } -static void js_capture_stack(ant_t *js, jsval_t err_obj) { - jsval_t stack_str = js_build_stack_text(js, JS_STACK_TEXT_FROM_ERROR_OBJECT, err_obj); +static void js_capture_stack(ant_t *js, ant_value_t err_obj) { + ant_value_t stack_str = js_build_stack_text(js, JS_STACK_TEXT_FROM_ERROR_OBJECT, err_obj); if (vtype(stack_str) != T_STR) return; js_set(js, err_obj, "stack", stack_str); @@ -721,13 +721,13 @@ static void js_capture_stack(ant_t *js, jsval_t err_obj) { js_err_type_t get_error_type(ant_t *js) { if (!js->thrown_exists) return JS_ERR_GENERIC; - jsval_t err_type = js_get_slot(js, js->thrown_value, SLOT_ERR_TYPE); + ant_value_t err_type = js_get_slot(js, js->thrown_value, SLOT_ERR_TYPE); if (vtype(err_type) != T_NUM) return JS_ERR_GENERIC; return (js_err_type_t)((int)js_getnum(err_type) & ~JS_ERR_NO_STACK); } __attribute__((format(printf, 4, 5))) -jsval_t js_create_error(ant_t *js, js_err_type_t err_type, jsval_t props, const char *xx, ...) { +ant_value_t js_create_error(ant_t *js, js_err_type_t err_type, ant_value_t props, const char *xx, ...) { va_list ap; char error_msg[256] = {0}; @@ -742,7 +742,7 @@ jsval_t js_create_error(ant_t *js, js_err_type_t err_type, jsval_t props, const size_t err_name_len = strlen(err_name); size_t msg_len = strlen(error_msg); - jsval_t err_obj = js_mkobj(js); + ant_value_t err_obj = js_mkobj(js); js_set(js, err_obj, "name", js_mkstr(js, err_name, err_name_len)); js_set(js, err_obj, "message", js_mkstr(js, error_msg, msg_len)); js_set_slot(js, err_obj, SLOT_ERR_TYPE, js_mknum((double)err_type)); @@ -751,7 +751,7 @@ jsval_t js_create_error(ant_t *js, js_err_type_t err_type, jsval_t props, const if ((JS_TYPE_FLAG(props_type) & T_SPECIAL_OBJECT_MASK) != 0) { js_merge_obj(js, err_obj, props); } - jsval_t proto = js_get_ctor_proto(js, err_name, err_name_len); + ant_value_t proto = js_get_ctor_proto(js, err_name, err_name_len); int proto_type = vtype(proto); if ((JS_TYPE_FLAG(proto_type) & T_SPECIAL_OBJECT_MASK) != 0) { js_set_proto(js, err_obj, proto); @@ -768,16 +768,16 @@ jsval_t js_create_error(ant_t *js, js_err_type_t err_type, jsval_t props, const return mkval(T_ERR, vdata(err_obj)); } -jsval_t js_throw(ant_t *js, jsval_t value) { +ant_value_t js_throw(ant_t *js, ant_value_t value) { if (vtype(value) == T_OBJ) { - jsval_t existing = js_get(js, value, "stack"); + ant_value_t existing = js_get(js, value, "stack"); if (vtype(existing) == T_STR) { js->thrown_exists = true; js->thrown_value = value; js_clear_error_site(js); return mkval(T_ERR, vdata(value)); } - jsval_t slot = js_get_slot(js, value, SLOT_ERR_TYPE); + ant_value_t slot = js_get_slot(js, value, SLOT_ERR_TYPE); if (vtype(slot) == T_NUM && ((int)js_getnum(slot) & JS_ERR_NO_STACK)) { js->thrown_exists = true; js->thrown_value = value; @@ -786,7 +786,7 @@ jsval_t js_throw(ant_t *js, jsval_t value) { } } - jsval_t stack_str = js_build_stack_text(js, JS_STACK_TEXT_FROM_THROW_VALUE, value); + ant_value_t stack_str = js_build_stack_text(js, JS_STACK_TEXT_FROM_THROW_VALUE, value); if (vtype(stack_str) != T_STR) return mkval(T_ERR, 0); if (vtype(value) == T_OBJ) { diff --git a/src/esm/commonjs.c b/src/esm/commonjs.c index 15affc0..c4c73fd 100644 --- a/src/esm/commonjs.c +++ b/src/esm/commonjs.c @@ -12,53 +12,53 @@ #include #include -static jsval_t esm_cjs_require(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t esm_cjs_require(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || vtype(args[0]) != T_STR) return js_mkerr(js, "require() expects a string specifier"); - jsval_t fn = js_getcurrentfunc(js); - jsval_t data = js_get_slot(js, fn, SLOT_DATA); + ant_value_t fn = js_getcurrentfunc(js); + ant_value_t data = js_get_slot(js, fn, SLOT_DATA); const char *prev_filename = js->filename; if (vtype(data) == T_STR) { - jsoff_t path_len = 0; - jsoff_t path_off = vstr(js, data, &path_len); + ant_offset_t path_len = 0; + ant_offset_t path_off = vstr(js, data, &path_len); (void)path_len; js_set_filename(js, (const char *)&js->mem[path_off]); } - jsval_t ns = js_esm_import_sync(js, args[0]); + ant_value_t ns = js_esm_import_sync(js, args[0]); js_set_filename(js, prev_filename); if (is_err(ns)) return ns; if (vtype(ns) == T_OBJ) { - jsval_t default_export = js_get_slot(js, ns, SLOT_DEFAULT); + ant_value_t default_export = js_get_slot(js, ns, SLOT_DEFAULT); if (vtype(default_export) != T_UNDEF) return default_export; } return ns; } -static jsval_t esm_cjs_require_resolve(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t esm_cjs_require_resolve(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || vtype(args[0]) != T_STR) { return js_mkerr(js, "require.resolve() expects a string specifier"); } - jsval_t fn = js_getcurrentfunc(js); - jsval_t data = js_get_slot(js, fn, SLOT_DATA); + ant_value_t fn = js_getcurrentfunc(js); + ant_value_t data = js_get_slot(js, fn, SLOT_DATA); const char *base_path = js->filename ? js->filename : "."; if (vtype(data) == T_STR) { - jsoff_t data_len = 0; - jsoff_t data_off = vstr(js, data, &data_len); + ant_offset_t data_len = 0; + ant_offset_t data_off = vstr(js, data, &data_len); base_path = (const char *)&js->mem[data_off]; } - jsval_t resolved = js_esm_resolve_specifier(js, args[0], base_path); + ant_value_t resolved = js_esm_resolve_specifier(js, args[0], base_path); if (is_err(resolved)) return resolved; if (vtype(resolved) != T_STR) return resolved; - jsoff_t len = 0; - jsoff_t off = vstr(js, resolved, &len); + ant_offset_t len = 0; + ant_offset_t off = vstr(js, resolved, &len); const char *s = (const char *)&js->mem[off]; static const char *prefix = "file://"; @@ -72,8 +72,8 @@ static jsval_t esm_cjs_require_resolve(ant_t *js, jsval_t *args, int nargs) { return resolved; } -static jsval_t esm_populate_cjs_namespace(ant_t *js, jsval_t ns, jsval_t exports_val) { - jsval_t set_default = setprop_cstr(js, ns, "default", 7, exports_val); +static ant_value_t esm_populate_cjs_namespace(ant_t *js, ant_value_t ns, ant_value_t exports_val) { + ant_value_t set_default = setprop_cstr(js, ns, "default", 7, exports_val); if (is_err(set_default)) return set_default; js_set_slot(js, ns, SLOT_DEFAULT, exports_val); @@ -86,10 +86,10 @@ static jsval_t esm_populate_cjs_namespace(ant_t *js, jsval_t ns, jsval_t exports while (js_prop_iter_next(&iter, &key, &key_len, NULL)) { if (key_len == 7 && memcmp(key, "default", 7) == 0) continue; - jsval_t value = js_get(js, exports_val, key); + ant_value_t value = js_get(js, exports_val, key); if (is_err(value)) { js_prop_iter_end(&iter); return value; } - jsval_t res = setprop_cstr(js, ns, key, key_len, value); + ant_value_t res = setprop_cstr(js, ns, key, key_len, value); if (is_err(res)) { js_prop_iter_end(&iter); return res; } } @@ -97,15 +97,15 @@ static jsval_t esm_populate_cjs_namespace(ant_t *js, jsval_t ns, jsval_t exports return js_mkundef(); } -static jsval_t esm_eval_commonjs_function( +static ant_value_t esm_eval_commonjs_function( ant_t *js, const char *code, size_t code_len, - jsval_t require_fn, - jsval_t module_obj, - jsval_t exports_obj, - jsval_t filename_val, - jsval_t dirname_val + ant_value_t require_fn, + ant_value_t module_obj, + ant_value_t exports_obj, + ant_value_t filename_val, + ant_value_t dirname_val ) { static const char *cjs_params = "require,module,exports,__filename,__dirname"; @@ -122,32 +122,32 @@ static jsval_t esm_eval_commonjs_function( } js_clear_error_site(js); - jsval_t args[] = {require_fn, module_obj, exports_obj, filename_val, dirname_val}; + ant_value_t args[] = {require_fn, module_obj, exports_obj, filename_val, dirname_val}; return sv_execute_entry(js->vm, compiled, exports_obj, args, 5); } -jsval_t esm_load_commonjs_module( +ant_value_t esm_load_commonjs_module( ant_t *js, const char *module_path, const char *code, - size_t code_len, jsval_t ns + size_t code_len, ant_value_t ns ) { char *path_copy = strdup(module_path); if (!path_copy) return js_mkerr(js, "OOM loading CommonJS module"); - jsval_t module_obj = js_mkobj(js); - jsval_t exports_obj = js_mkobj(js); + ant_value_t module_obj = js_mkobj(js); + ant_value_t exports_obj = js_mkobj(js); js_set(js, module_obj, "exports", exports_obj); js_set(js, module_obj, "loaded", js_false); js_set(js, module_obj, "id", js_mkstr(js, module_path, strlen(module_path))); js_set(js, module_obj, "filename", js_mkstr(js, module_path, strlen(module_path))); - jsval_t require_fn = js_heavy_mkfun( + ant_value_t require_fn = js_heavy_mkfun( js, esm_cjs_require, js_mkstr(js, module_path, strlen(module_path)) ); - jsval_t require_resolve_fn = js_heavy_mkfun( + ant_value_t require_resolve_fn = js_heavy_mkfun( js, esm_cjs_require_resolve, js_mkstr(js, module_path, strlen(module_path)) ); @@ -155,13 +155,13 @@ jsval_t esm_load_commonjs_module( js_set(js, require_fn, "resolve", require_resolve_fn); char *dir = dirname(path_copy); - jsval_t dirname_val = js_mkstr(js, dir, strlen(dir)); - jsval_t filename_val = js_mkstr(js, module_path, strlen(module_path)); + ant_value_t dirname_val = js_mkstr(js, dir, strlen(dir)); + ant_value_t filename_val = js_mkstr(js, module_path, strlen(module_path)); const char *prev_filename = js->filename; js_set_filename(js, module_path); - jsval_t result = esm_eval_commonjs_function( + ant_value_t result = esm_eval_commonjs_function( js, code, code_len, require_fn, module_obj, exports_obj, filename_val, dirname_val @@ -169,10 +169,10 @@ jsval_t esm_load_commonjs_module( if (vtype(result) == T_PROMISE) js_run_event_loop(js); js_set(js, module_obj, "loaded", js_true); - jsval_t exports_val = js_get(js, module_obj, "exports"); + ant_value_t exports_val = js_get(js, module_obj, "exports"); if (!is_err(result) && !js->thrown_exists) { - jsval_t ns_res = esm_populate_cjs_namespace(js, ns, exports_val); + ant_value_t ns_res = esm_populate_cjs_namespace(js, ns, exports_val); if (is_err(ns_res)) result = ns_res; } diff --git a/src/esm/library.c b/src/esm/library.c index 42bd1e0..2e563f7 100644 --- a/src/esm/library.c +++ b/src/esm/library.c @@ -53,7 +53,7 @@ void ant_library_foreach(ant_library_iter_fn cb, void *userdata) { } } -jsval_t js_esm_load_registered_library(ant_t *js, const char *specifier, size_t spec_len, bool *loaded) { +ant_value_t js_esm_load_registered_library(ant_t *js, const char *specifier, size_t spec_len, bool *loaded) { ant_library_entry_t *lib = find_library(specifier, spec_len); if (!lib) { if (loaded) *loaded = false; diff --git a/src/esm/loader.c b/src/esm/loader.c index 947bffb..3128069 100644 --- a/src/esm/loader.c +++ b/src/esm/loader.c @@ -45,8 +45,8 @@ typedef struct esm_module { char *resolved_path; char *url_content; size_t url_content_len; - jsval_t namespace_obj; - jsval_t default_export; + ant_value_t namespace_obj; + ant_value_t default_export; UT_hash_handle hh; esm_module_kind_t kind; esm_module_format_t format; @@ -67,14 +67,14 @@ typedef struct { static esm_module_cache_t global_module_cache = {NULL, 0}; static char *esm_resolve_node_module(const char *specifier, const char *base_path); -static jsval_t esm_get_import_meta_raw(ant_t *js) { - jsval_t import_fn = js_get(js, js->global, "import"); +static ant_value_t esm_get_import_meta_raw(ant_t *js) { + ant_value_t import_fn = js_get(js, js->global, "import"); if (vtype(import_fn) != T_FUNC) return js_mkundef(); return js_get(js, js_func_obj(import_fn), "meta"); } static void esm_set_import_meta_main_flag(ant_t *js, bool is_main) { - jsval_t meta = esm_get_import_meta_raw(js); + ant_value_t meta = esm_get_import_meta_raw(js); if (vtype(meta) != T_OBJ) return; js_set(js, meta, "main", is_main ? js_true : js_false); } @@ -712,12 +712,12 @@ static esm_module_format_t esm_decide_module_format(const char *resolved_path) { return ESM_MODULE_FORMAT_ESM; } -static jsval_t esm_eval_module_with_format( +static ant_value_t esm_eval_module_with_format( ant_t *js, const char *resolved_path, const char *js_code, size_t js_len, - jsval_t ns, + ant_value_t ns, esm_module_format_t format ) { if (format == ESM_MODULE_FORMAT_CJS) { @@ -726,18 +726,18 @@ static jsval_t esm_eval_module_with_format( return js_eval_bytecode_module(js, js_code, js_len); } -jsval_t js_esm_eval_module_source( +ant_value_t js_esm_eval_module_source( ant_t *js, const char *resolved_path, const char *js_code, size_t js_len, - jsval_t ns + ant_value_t ns ) { esm_module_format_t format = esm_decide_module_format(resolved_path); - jsval_t prev_module = js->module_ns; + ant_value_t prev_module = js->module_ns; js->module_ns = ns; - jsval_t result = esm_eval_module_with_format( + ant_value_t result = esm_eval_module_with_format( js, resolved_path, js_code, js_len, ns, format ); @@ -851,7 +851,7 @@ void js_esm_cleanup_module_cache(void) { global_module_cache.count = 0; } -void js_esm_gc_roots(void (*visit)(void *ctx, jsval_t *val), void *ctx) { +void js_esm_gc_roots(void (*visit)(void *ctx, ant_value_t *val), void *ctx) { if (!visit) return; esm_module_t *mod = NULL, *tmp = NULL; HASH_ITER(hh, global_module_cache.modules, mod, tmp) { @@ -860,7 +860,7 @@ void js_esm_gc_roots(void (*visit)(void *ctx, jsval_t *val), void *ctx) { } } -static jsval_t esm_read_file(ant_t *js, const char *path, const char *kind, esm_file_data_t *out) { +static ant_value_t esm_read_file(ant_t *js, const char *path, const char *kind, esm_file_data_t *out) { FILE *fp = fopen(path, "rb"); if (!fp) return js_mkerr(js, "Cannot open %s: %s", kind, path); @@ -883,36 +883,36 @@ static jsval_t esm_read_file(ant_t *js, const char *path, const char *kind, esm_ return js_mkundef(); } -static jsval_t esm_load_json(ant_t *js, const char *path) { +static ant_value_t esm_load_json(ant_t *js, const char *path) { esm_file_data_t file; - jsval_t err = esm_read_file(js, path, "JSON file", &file); + ant_value_t err = esm_read_file(js, path, "JSON file", &file); if (is_err(err)) return err; - jsval_t json_str = js_mkstr(js, file.data, file.size); + ant_value_t json_str = js_mkstr(js, file.data, file.size); free(file.data); return js_json_parse(js, &json_str, 1); } -static jsval_t esm_load_text(ant_t *js, const char *path) { +static ant_value_t esm_load_text(ant_t *js, const char *path) { esm_file_data_t file; - jsval_t err = esm_read_file(js, path, "text file", &file); + ant_value_t err = esm_read_file(js, path, "text file", &file); if (is_err(err)) return err; - jsval_t result = js_mkstr(js, file.data, file.size); + ant_value_t result = js_mkstr(js, file.data, file.size); free(file.data); return result; } -static jsval_t esm_load_image(ant_t *js, const char *path) { +static ant_value_t esm_load_image(ant_t *js, const char *path) { esm_file_data_t file; - jsval_t err = esm_read_file(js, path, "image file", &file); + ant_value_t err = esm_read_file(js, path, "image file", &file); if (is_err(err)) return err; unsigned char *content = (unsigned char *)file.data; size_t size = file.size; - jsval_t obj = js_mkobj(js); - jsval_t data_arr = js_mkarr(js); + ant_value_t obj = js_mkobj(js); + ant_value_t data_arr = js_mkarr(js); for (size_t i = 0; i < size; i++) { js_arr_push(js, data_arr, tov((double)content[i])); @@ -926,7 +926,7 @@ static jsval_t esm_load_image(ant_t *js, const char *path) { return obj; } -static jsval_t esm_load_module(ant_t *js, esm_module_t *mod) { +static ant_value_t esm_load_module(ant_t *js, esm_module_t *mod) { if (mod->is_loaded) return mod->namespace_obj; if (mod->is_loading) return mod->namespace_obj; @@ -934,7 +934,7 @@ static jsval_t esm_load_module(ant_t *js, esm_module_t *mod) { switch (mod->kind) { case ESM_MODULE_KIND_JSON: { - jsval_t json_val = esm_load_json(js, mod->resolved_path); + ant_value_t json_val = esm_load_json(js, mod->resolved_path); if (is_err(json_val)) { mod->is_loading = false; return json_val; @@ -946,7 +946,7 @@ static jsval_t esm_load_module(ant_t *js, esm_module_t *mod) { return json_val; } case ESM_MODULE_KIND_TEXT: { - jsval_t text_val = esm_load_text(js, mod->resolved_path); + ant_value_t text_val = esm_load_text(js, mod->resolved_path); if (is_err(text_val)) { mod->is_loading = false; return text_val; @@ -958,7 +958,7 @@ static jsval_t esm_load_module(ant_t *js, esm_module_t *mod) { return text_val; } case ESM_MODULE_KIND_IMAGE: { - jsval_t img_val = esm_load_image(js, mod->resolved_path); + ant_value_t img_val = esm_load_image(js, mod->resolved_path); if (is_err(img_val)) { mod->is_loading = false; return img_val; @@ -970,16 +970,16 @@ static jsval_t esm_load_module(ant_t *js, esm_module_t *mod) { return img_val; } case ESM_MODULE_KIND_NATIVE: { - jsval_t ns = js_mkobj(js); + ant_value_t ns = js_mkobj(js); mod->namespace_obj = ns; - jsval_t native_exports = napi_load_native_module(js, mod->resolved_path, ns); + ant_value_t native_exports = napi_load_native_module(js, mod->resolved_path, ns); if (is_err(native_exports)) { mod->is_loading = false; return native_exports; } - jsval_t default_val = js_get_slot(js, ns, SLOT_DEFAULT); + ant_value_t default_val = js_get_slot(js, ns, SLOT_DEFAULT); mod->default_export = vtype(default_val) != T_UNDEF ? default_val : ns; mod->is_loaded = true; mod->is_loading = false; @@ -1008,7 +1008,7 @@ static jsval_t esm_load_module(ant_t *js, esm_module_t *mod) { content = esm_fetch_url(mod->resolved_path, &size, &error); if (!content) { mod->is_loading = false; - jsval_t err = js_mkerr(js, "Cannot fetch module %s: %s", mod->resolved_path, error ? error : "unknown error"); + ant_value_t err = js_mkerr(js, "Cannot fetch module %s: %s", mod->resolved_path, error ? error : "unknown error"); if (error) free(error); return err; } @@ -1017,7 +1017,7 @@ static jsval_t esm_load_module(ant_t *js, esm_module_t *mod) { } } else { esm_file_data_t file; - jsval_t err = esm_read_file(js, mod->resolved_path, "module", &file); + ant_value_t err = esm_read_file(js, mod->resolved_path, "module", &file); if (is_err(err)) { mod->is_loading = false; return err; @@ -1035,7 +1035,7 @@ static jsval_t esm_load_module(ant_t *js, esm_module_t *mod) { ); if (strip_result < 0) { - jsval_t err = js_mkerr( + ant_value_t err = js_mkerr( js, "TypeScript error: strip failed (%d): %s", strip_result, strip_detail ); @@ -1047,14 +1047,14 @@ static jsval_t esm_load_module(ant_t *js, esm_module_t *mod) { } char *js_code = content; - jsval_t ns = js_mkobj(js); + ant_value_t ns = js_mkobj(js); mod->namespace_obj = ns; - jsval_t prev_module = js->module_ns; + ant_value_t prev_module = js->module_ns; js->module_ns = ns; const char *prev_filename = js->filename; - jshdl_t prev_import_meta_h = js_root(js, js->import_meta); + ant_handle_t prev_import_meta_h = js_root(js, js->import_meta); js_set_filename(js, mod->resolved_path); js_setup_import_meta(js, mod->resolved_path); @@ -1066,7 +1066,7 @@ static jsval_t esm_load_module(ant_t *js, esm_module_t *mod) { mod->format = esm_decide_module_format(mod->resolved_path); } - jsval_t result = esm_eval_module_with_format( + ant_value_t result = esm_eval_module_with_format( js, mod->resolved_path, js_code, js_len, ns, mod->format ); @@ -1083,7 +1083,7 @@ static jsval_t esm_load_module(ant_t *js, esm_module_t *mod) { return result; } - jsval_t default_val = js_get_slot(js, ns, SLOT_DEFAULT); + ant_value_t default_val = js_get_slot(js, ns, SLOT_DEFAULT); mod->default_export = vtype(default_val) != T_UNDEF ? default_val : ns; mod->is_loaded = true; @@ -1092,7 +1092,7 @@ static jsval_t esm_load_module(ant_t *js, esm_module_t *mod) { return ns; } -static jsval_t esm_get_or_load(ant_t *js, const char *specifier, const char *resolved_path) { +static ant_value_t esm_get_or_load(ant_t *js, const char *specifier, const char *resolved_path) { esm_module_t *mod = esm_find_module(resolved_path); if (!mod) { mod = esm_create_module(specifier, resolved_path); @@ -1101,7 +1101,7 @@ static jsval_t esm_get_or_load(ant_t *js, const char *specifier, const char *res return esm_load_module(js, mod); } -jsval_t js_esm_import_sync_cstr(ant_t *js, const char *specifier, size_t spec_len) { +ant_value_t js_esm_import_sync_cstr(ant_t *js, const char *specifier, size_t spec_len) { char *spec_copy = strndup(specifier, spec_len); if (!spec_copy) return js_mkerr(js, "oom"); @@ -1112,7 +1112,7 @@ jsval_t js_esm_import_sync_cstr(ant_t *js, const char *specifier, size_t spec_le } bool loaded = false; - jsval_t lib = js_esm_load_registered_library(js, spec_copy, spec_len, &loaded); + ant_value_t lib = js_esm_load_registered_library(js, spec_copy, spec_len, &loaded); if (loaded) { free(spec_copy); return lib; @@ -1121,46 +1121,46 @@ jsval_t js_esm_import_sync_cstr(ant_t *js, const char *specifier, size_t spec_le const char *base_path = js->filename ? js->filename : "."; char *resolved_path = esm_resolve(spec_copy, base_path, esm_resolve_path); if (!resolved_path) { - jsval_t err = js_mkerr(js, "Cannot resolve module: %s", spec_copy); + ant_value_t err = js_mkerr(js, "Cannot resolve module: %s", spec_copy); free(spec_copy); return err; } - jsval_t ns = esm_get_or_load(js, spec_copy, resolved_path); + ant_value_t ns = esm_get_or_load(js, spec_copy, resolved_path); free(resolved_path); free(spec_copy); return ns; } -jsval_t js_esm_import_sync(ant_t *js, jsval_t specifier) { +ant_value_t js_esm_import_sync(ant_t *js, ant_value_t specifier) { if (vtype(specifier) != T_STR) return js_mkerr(js, "import() requires a string specifier"); - jsoff_t spec_len = 0; - jsoff_t spec_off = vstr(js, specifier, &spec_len); + ant_offset_t spec_len = 0; + ant_offset_t spec_off = vstr(js, specifier, &spec_len); const char *spec_str = (const char *)&js->mem[spec_off]; return js_esm_import_sync_cstr(js, spec_str, (size_t)spec_len); } -jsval_t js_esm_make_file_url(ant_t *js, const char *path) { +ant_value_t js_esm_make_file_url(ant_t *js, const char *path) { size_t url_len = strlen(path) + 8; char *url = malloc(url_len); if (!url) return js_mkerr(js, "oom"); snprintf(url, url_len, "file://%s", path); - jsval_t val = js_mkstr(js, url, strlen(url)); + ant_value_t val = js_mkstr(js, url, strlen(url)); free(url); return val; } -jsval_t js_esm_resolve_specifier(ant_t *js, jsval_t specifier, const char *base_path) { +ant_value_t js_esm_resolve_specifier(ant_t *js, ant_value_t specifier, const char *base_path) { if (vtype(specifier) != T_STR) { return js_mkerr(js, "import.meta.resolve() requires a string specifier"); } - jsoff_t spec_len = 0; - jsoff_t spec_off = vstr(js, specifier, &spec_len); + ant_offset_t spec_len = 0; + ant_offset_t spec_off = vstr(js, specifier, &spec_len); const char *spec_str = (const char *)&js->mem[spec_off]; char *spec_copy = strndup(spec_str, (size_t)spec_len); if (!spec_copy) return js_mkerr(js, "oom"); @@ -1174,12 +1174,12 @@ jsval_t js_esm_resolve_specifier(ant_t *js, jsval_t specifier, const char *base_ } if (esm_is_url(resolved_path)) { - jsval_t result = js_mkstr(js, resolved_path, strlen(resolved_path)); + ant_value_t result = js_mkstr(js, resolved_path, strlen(resolved_path)); free(resolved_path); return result; } - jsval_t result = js_esm_make_file_url(js, resolved_path); + ant_value_t result = js_esm_make_file_url(js, resolved_path); free(resolved_path); return result; } diff --git a/src/gc.c b/src/gc.c index 443cae9..94047d1 100644 --- a/src/gc.c +++ b/src/gc.c @@ -55,15 +55,15 @@ static bool gc_throttled = false; void js_gc_throttle(bool enabled) { gc_throttled = enabled; } typedef struct { - jsoff_t *old_offs; - jsoff_t *new_offs; + ant_offset_t *old_offs; + ant_offset_t *new_offs; size_t count; size_t capacity; size_t mask; } gc_forward_table_t; typedef struct { - jsoff_t *items; + ant_offset_t *items; size_t count; size_t capacity; } gc_work_queue_t; @@ -74,13 +74,13 @@ typedef struct { uint8_t *mark_bits; gc_forward_table_t fwd; gc_work_queue_t work; - jsoff_t new_brk; - jsoff_t new_size; + ant_offset_t new_brk; + ant_offset_t new_size; bool failed; } gc_ctx_t; -static jsval_t gc_update_val(gc_ctx_t *ctx, jsval_t val); -static jsval_t gc_apply_val(gc_ctx_t *ctx, jsval_t val); +static ant_value_t gc_update_val(gc_ctx_t *ctx, ant_value_t val); +static ant_value_t gc_apply_val(gc_ctx_t *ctx, ant_value_t val); /* inlined helpers from ant.c */ static inline bool gc_func_const_count_sane(int n) { @@ -91,26 +91,26 @@ static inline bool gc_upvalue_is_closed(const sv_upvalue_t *uv) { return uv && uv->location == &uv->closed; } -static inline bool gc_is_tagged(jsval_t v) { +static inline bool gc_is_tagged(ant_value_t v) { return v > NANBOX_PREFIX; } -static inline uint8_t gc_vtype(jsval_t v) { +static inline uint8_t gc_vtype(ant_value_t v) { return gc_is_tagged(v) ? ((v >> NANBOX_TYPE_SHIFT) & NANBOX_TYPE_MASK) : 255; } -static inline size_t gc_vdata(jsval_t v) { +static inline size_t gc_vdata(ant_value_t v) { return (size_t)(v & NANBOX_DATA_MASK); } -static inline jsval_t gc_mkval(uint8_t type, uint64_t data) { +static inline ant_value_t gc_mkval(uint8_t type, uint64_t data) { return NANBOX_PREFIX - | ((jsval_t)(type & NANBOX_TYPE_MASK) << NANBOX_TYPE_SHIFT) + | ((ant_value_t)(type & NANBOX_TYPE_MASK) << NANBOX_TYPE_SHIFT) | (data & NANBOX_DATA_MASK); } -static inline void mark_set(gc_ctx_t *ctx, jsoff_t off) { - jsoff_t idx = off >> 3; +static inline void mark_set(gc_ctx_t *ctx, ant_offset_t off) { + ant_offset_t idx = off >> 3; ctx->mark_bits[idx >> 3] |= (1 << (idx & 7)); } @@ -132,7 +132,7 @@ static void gc_update_func_constants(gc_ctx_t *ctx, sv_func_t *func, int depth) if (!func->constants || !gc_func_const_count_sane(func->const_count)) return; for (int i = 0; i < func->const_count; i++) { - jsval_t c = func->constants[i]; + ant_value_t c = func->constants[i]; if (vtype(c) == T_CFUNC) { sv_func_t *child = (sv_func_t *)(uintptr_t)vdata(c); @@ -170,10 +170,10 @@ static inline void gc_update_closure(gc_ctx_t *ctx, sv_closure_t *closure) { static bool fwd_init(gc_forward_table_t *fwd, size_t estimated) { size_t cap = next_pow2(estimated < 64 ? 64 : estimated); - size_t size = cap * sizeof(jsoff_t); + size_t size = cap * sizeof(ant_offset_t); - fwd->old_offs = (jsoff_t *)gc_mmap(size); - fwd->new_offs = (jsoff_t *)gc_mmap(size); + fwd->old_offs = (ant_offset_t *)gc_mmap(size); + fwd->new_offs = (ant_offset_t *)gc_mmap(size); if (!fwd->old_offs || !fwd->new_offs) { if (fwd->old_offs) gc_munmap(fwd->old_offs, size); @@ -193,11 +193,11 @@ static bool fwd_init(gc_forward_table_t *fwd, size_t estimated) { static bool fwd_grow(gc_forward_table_t *fwd) { size_t new_cap = fwd->capacity * 2; size_t new_mask = new_cap - 1; - size_t new_size = new_cap * sizeof(jsoff_t); - size_t old_size = fwd->capacity * sizeof(jsoff_t); + size_t new_size = new_cap * sizeof(ant_offset_t); + size_t old_size = fwd->capacity * sizeof(ant_offset_t); - jsoff_t *new_old = (jsoff_t *)gc_mmap(new_size); - jsoff_t *new_new = (jsoff_t *)gc_mmap(new_size); + ant_offset_t *new_old = (ant_offset_t *)gc_mmap(new_size); + ant_offset_t *new_new = (ant_offset_t *)gc_mmap(new_size); if (!new_old || !new_new) { if (new_old) gc_munmap(new_old, new_size); @@ -208,7 +208,7 @@ static bool fwd_grow(gc_forward_table_t *fwd) { for (size_t i = 0; i < new_cap; i++) new_old[i] = FWD_EMPTY; for (size_t i = 0; i < fwd->capacity; i++) { - jsoff_t key = fwd->old_offs[i]; + ant_offset_t key = fwd->old_offs[i]; if (key == FWD_EMPTY || key == FWD_TOMBSTONE) continue; size_t h = (key >> 3) & new_mask; while (new_old[h] != FWD_EMPTY) h = (h + 1) & new_mask; @@ -227,7 +227,7 @@ static bool fwd_grow(gc_forward_table_t *fwd) { return true; } -static inline bool fwd_add(gc_forward_table_t *fwd, jsoff_t old_off, jsoff_t new_off) { +static inline bool fwd_add(gc_forward_table_t *fwd, ant_offset_t old_off, ant_offset_t new_off) { if (fwd->count * 100 >= fwd->capacity * GC_FWD_LOAD_FACTOR) { if (!fwd_grow(fwd)) return false; } @@ -248,19 +248,19 @@ static inline bool fwd_add(gc_forward_table_t *fwd, jsoff_t old_off, jsoff_t new return true; } -static inline jsoff_t fwd_lookup(gc_forward_table_t *fwd, jsoff_t old_off) { +static inline ant_offset_t fwd_lookup(gc_forward_table_t *fwd, ant_offset_t old_off) { size_t h = (old_off >> 3) & fwd->mask; for (size_t i = 0; i < fwd->capacity; i++) { - jsoff_t key = fwd->old_offs[h]; - if (key == FWD_EMPTY) return (jsoff_t)~0; + ant_offset_t key = fwd->old_offs[h]; + if (key == FWD_EMPTY) return (ant_offset_t)~0; if (key == old_off) return fwd->new_offs[h]; h = (h + 1) & fwd->mask; } - return (jsoff_t)~0; + return (ant_offset_t)~0; } static void fwd_free(gc_forward_table_t *fwd) { - size_t size = fwd->capacity * sizeof(jsoff_t); + size_t size = fwd->capacity * sizeof(ant_offset_t); if (fwd->old_offs) gc_munmap(fwd->old_offs, size); if (fwd->new_offs) gc_munmap(fwd->new_offs, size); @@ -271,24 +271,24 @@ static void fwd_free(gc_forward_table_t *fwd) { } static bool work_init(gc_work_queue_t *work, size_t initial) { - size_t size = initial * sizeof(jsoff_t); - work->items = (jsoff_t *)gc_mmap(size); + size_t size = initial * sizeof(ant_offset_t); + work->items = (ant_offset_t *)gc_mmap(size); if (!work->items) return false; work->count = 0; work->capacity = initial; return true; } -static inline bool work_push(gc_work_queue_t *work, jsoff_t off) { +static inline bool work_push(gc_work_queue_t *work, ant_offset_t off) { if (work->count >= work->capacity) { size_t new_cap = work->capacity * 2; - size_t new_size = new_cap * sizeof(jsoff_t); - size_t old_size = work->capacity * sizeof(jsoff_t); + size_t new_size = new_cap * sizeof(ant_offset_t); + size_t old_size = work->capacity * sizeof(ant_offset_t); - jsoff_t *new_items = (jsoff_t *)gc_mmap(new_size); + ant_offset_t *new_items = (ant_offset_t *)gc_mmap(new_size); if (!new_items) return false; - memcpy(new_items, work->items, work->count * sizeof(jsoff_t)); + memcpy(new_items, work->items, work->count * sizeof(ant_offset_t)); gc_munmap(work->items, old_size); work->items = new_items; @@ -299,13 +299,13 @@ static inline bool work_push(gc_work_queue_t *work, jsoff_t off) { return true; } -static inline jsoff_t work_pop(gc_work_queue_t *work) { - if (work->count == 0) return (jsoff_t)~0; +static inline ant_offset_t work_pop(gc_work_queue_t *work) { + if (work->count == 0) return (ant_offset_t)~0; return work->items[--work->count]; } static void work_free(gc_work_queue_t *work) { - size_t size = work->capacity * sizeof(jsoff_t); + size_t size = work->capacity * sizeof(ant_offset_t); if (work->items) gc_munmap(work->items, size); work->items = NULL; @@ -313,92 +313,92 @@ static void work_free(gc_work_queue_t *work) { work->capacity = 0; } -static inline jsoff_t gc_loadoff(uint8_t *mem, jsoff_t off) { - jsoff_t val; +static inline ant_offset_t gc_loadoff(uint8_t *mem, ant_offset_t off) { + ant_offset_t val; memcpy(&val, &mem[off], sizeof(val)); return val; } -static inline jsval_t gc_loadval(uint8_t *mem, jsoff_t off) { - jsval_t val; +static inline ant_value_t gc_loadval(uint8_t *mem, ant_offset_t off) { + ant_value_t val; memcpy(&val, &mem[off], sizeof(val)); return val; } -static inline void gc_saveoff(uint8_t *mem, jsoff_t off, jsoff_t val) { +static inline void gc_saveoff(uint8_t *mem, ant_offset_t off, ant_offset_t val) { memcpy(&mem[off], &val, sizeof(val)); } -static inline void gc_saveval(uint8_t *mem, jsoff_t off, jsval_t val) { +static inline void gc_saveval(uint8_t *mem, ant_offset_t off, ant_value_t val) { memcpy(&mem[off], &val, sizeof(val)); } -static jsoff_t gc_alloc(gc_ctx_t *ctx, size_t size) { +static ant_offset_t gc_alloc(gc_ctx_t *ctx, size_t size) { size = (size + 7) / 8 * 8; if (ctx->new_brk + size > ctx->new_size) { ctx->failed = true; - return (jsoff_t)~0; + return (ant_offset_t)~0; } - jsoff_t off = ctx->new_brk; - ctx->new_brk += (jsoff_t)size; + ant_offset_t off = ctx->new_brk; + ctx->new_brk += (ant_offset_t)size; return off; } -static jsoff_t gc_copy_string(gc_ctx_t *ctx, jsoff_t old_off) { +static ant_offset_t gc_copy_string(gc_ctx_t *ctx, ant_offset_t old_off) { if (old_off >= ctx->js->brk) return old_off; - jsoff_t new_off = fwd_lookup(&ctx->fwd, old_off); - if (new_off != (jsoff_t)~0) return new_off; + ant_offset_t new_off = fwd_lookup(&ctx->fwd, old_off); + if (new_off != (ant_offset_t)~0) return new_off; - jsoff_t header = gc_loadoff(ctx->js->mem, old_off); + ant_offset_t header = gc_loadoff(ctx->js->mem, old_off); if ((header & 3) != T_STR) return old_off; bool is_rope_str = (header & ROPE_FLAG) != 0; - jsoff_t size; + ant_offset_t size; if (is_rope_str) { size = sizeof(rope_node_t); } else size = esize(header); - if (size == (jsoff_t)~0) return old_off; + if (size == (ant_offset_t)~0) return old_off; new_off = gc_alloc(ctx, size); - if (new_off == (jsoff_t)~0) return old_off; + if (new_off == (ant_offset_t)~0) return old_off; memcpy(&ctx->new_mem[new_off], &ctx->js->mem[old_off], size); if (!fwd_add(&ctx->fwd, old_off, new_off)) ctx->failed = true; mark_set(ctx, old_off); if (is_rope_str) { - jsval_t left, right, cached; - memcpy(&left, &ctx->js->mem[old_off + offsetof(rope_node_t, left)], sizeof(jsval_t)); - memcpy(&right, &ctx->js->mem[old_off + offsetof(rope_node_t, right)], sizeof(jsval_t)); - memcpy(&cached, &ctx->js->mem[old_off + offsetof(rope_node_t, cached)], sizeof(jsval_t)); + ant_value_t left, right, cached; + memcpy(&left, &ctx->js->mem[old_off + offsetof(rope_node_t, left)], sizeof(ant_value_t)); + memcpy(&right, &ctx->js->mem[old_off + offsetof(rope_node_t, right)], sizeof(ant_value_t)); + memcpy(&cached, &ctx->js->mem[old_off + offsetof(rope_node_t, cached)], sizeof(ant_value_t)); - jsval_t new_left = gc_update_val(ctx, left); - jsval_t new_right = gc_update_val(ctx, right); - jsval_t new_cached = gc_update_val(ctx, cached); + ant_value_t new_left = gc_update_val(ctx, left); + ant_value_t new_right = gc_update_val(ctx, right); + ant_value_t new_cached = gc_update_val(ctx, cached); - memcpy(&ctx->new_mem[new_off + offsetof(rope_node_t, left)], &new_left, sizeof(jsval_t)); - memcpy(&ctx->new_mem[new_off + offsetof(rope_node_t, right)], &new_right, sizeof(jsval_t)); - memcpy(&ctx->new_mem[new_off + offsetof(rope_node_t, cached)], &new_cached, sizeof(jsval_t)); + memcpy(&ctx->new_mem[new_off + offsetof(rope_node_t, left)], &new_left, sizeof(ant_value_t)); + memcpy(&ctx->new_mem[new_off + offsetof(rope_node_t, right)], &new_right, sizeof(ant_value_t)); + memcpy(&ctx->new_mem[new_off + offsetof(rope_node_t, cached)], &new_cached, sizeof(ant_value_t)); } return new_off; } -static jsoff_t gc_copy_bigint(gc_ctx_t *ctx, jsoff_t old_off) { +static ant_offset_t gc_copy_bigint(gc_ctx_t *ctx, ant_offset_t old_off) { if (old_off >= ctx->js->brk) return old_off; - jsoff_t new_off = fwd_lookup(&ctx->fwd, old_off); - if (new_off != (jsoff_t)~0) return new_off; + ant_offset_t new_off = fwd_lookup(&ctx->fwd, old_off); + if (new_off != (ant_offset_t)~0) return new_off; - jsoff_t header = gc_loadoff(ctx->js->mem, old_off); - size_t total = (header >> 4) + sizeof(jsoff_t); + ant_offset_t header = gc_loadoff(ctx->js->mem, old_off); + size_t total = (header >> 4) + sizeof(ant_offset_t); total = (total + 7) / 8 * 8; new_off = gc_alloc(ctx, total); - if (new_off == (jsoff_t)~0) return old_off; + if (new_off == (ant_offset_t)~0) return old_off; memcpy(&ctx->new_mem[new_off], &ctx->js->mem[old_off], total); if (!fwd_add(&ctx->fwd, old_off, new_off)) ctx->failed = true; @@ -407,18 +407,18 @@ static jsoff_t gc_copy_bigint(gc_ctx_t *ctx, jsoff_t old_off) { return new_off; } -static jsoff_t gc_copy_symbol(gc_ctx_t *ctx, jsoff_t old_off) { +static ant_offset_t gc_copy_symbol(gc_ctx_t *ctx, ant_offset_t old_off) { if (old_off >= ctx->js->brk) return old_off; - jsoff_t new_off = fwd_lookup(&ctx->fwd, old_off); - if (new_off != (jsoff_t)~0) return new_off; + ant_offset_t new_off = fwd_lookup(&ctx->fwd, old_off); + if (new_off != (ant_offset_t)~0) return new_off; - jsoff_t header = gc_loadoff(ctx->js->mem, old_off); - size_t total = (header >> GC_SYM_HEADER_SHIFT) + sizeof(jsoff_t); + ant_offset_t header = gc_loadoff(ctx->js->mem, old_off); + size_t total = (header >> GC_SYM_HEADER_SHIFT) + sizeof(ant_offset_t); total = (total + 7) / 8 * 8; new_off = gc_alloc(ctx, total); - if (new_off == (jsoff_t)~0) return old_off; + if (new_off == (ant_offset_t)~0) return old_off; memcpy(&ctx->new_mem[new_off], &ctx->js->mem[old_off], total); if (!fwd_add(&ctx->fwd, old_off, new_off)) ctx->failed = true; @@ -427,20 +427,20 @@ static jsoff_t gc_copy_symbol(gc_ctx_t *ctx, jsoff_t old_off) { return new_off; } -static jsoff_t gc_reserve_object(gc_ctx_t *ctx, jsoff_t old_off) { +static ant_offset_t gc_reserve_object(gc_ctx_t *ctx, ant_offset_t old_off) { if (old_off >= ctx->js->brk) return old_off; - jsoff_t new_off = fwd_lookup(&ctx->fwd, old_off); - if (new_off != (jsoff_t)~0) return new_off; + ant_offset_t new_off = fwd_lookup(&ctx->fwd, old_off); + if (new_off != (ant_offset_t)~0) return new_off; - jsoff_t header = gc_loadoff(ctx->js->mem, old_off); + ant_offset_t header = gc_loadoff(ctx->js->mem, old_off); if ((header & 3) != T_OBJ) return old_off; - jsoff_t size = esize(header); - if (size == (jsoff_t)~0) return old_off; + ant_offset_t size = esize(header); + if (size == (ant_offset_t)~0) return old_off; new_off = gc_alloc(ctx, size); - if (new_off == (jsoff_t)~0) return old_off; + if (new_off == (ant_offset_t)~0) return old_off; memcpy(&ctx->new_mem[new_off], &ctx->js->mem[old_off], size); if (!fwd_add(&ctx->fwd, old_off, new_off)) ctx->failed = true; @@ -450,20 +450,20 @@ static jsoff_t gc_reserve_object(gc_ctx_t *ctx, jsoff_t old_off) { return new_off; } -static jsoff_t gc_reserve_prop(gc_ctx_t *ctx, jsoff_t old_off) { +static ant_offset_t gc_reserve_prop(gc_ctx_t *ctx, ant_offset_t old_off) { if (old_off >= ctx->js->brk) return old_off; - jsoff_t new_off = fwd_lookup(&ctx->fwd, old_off); - if (new_off != (jsoff_t)~0) return new_off; + ant_offset_t new_off = fwd_lookup(&ctx->fwd, old_off); + if (new_off != (ant_offset_t)~0) return new_off; - jsoff_t header = gc_loadoff(ctx->js->mem, old_off); + ant_offset_t header = gc_loadoff(ctx->js->mem, old_off); if ((header & 3) != T_PROP) return old_off; - jsoff_t size = esize(header); - if (size == (jsoff_t)~0) return old_off; + ant_offset_t size = esize(header); + if (size == (ant_offset_t)~0) return old_off; new_off = gc_alloc(ctx, size); - if (new_off == (jsoff_t)~0) return old_off; + if (new_off == (ant_offset_t)~0) return old_off; memcpy(&ctx->new_mem[new_off], &ctx->js->mem[old_off], size); if (!fwd_add(&ctx->fwd, old_off, new_off)) ctx->failed = true; @@ -473,99 +473,99 @@ static jsoff_t gc_reserve_prop(gc_ctx_t *ctx, jsoff_t old_off) { return new_off; } -static void gc_process_prop(gc_ctx_t *ctx, jsoff_t old_off) { - jsoff_t new_off = fwd_lookup(&ctx->fwd, old_off); - if (new_off == (jsoff_t)~0) return; +static void gc_process_prop(gc_ctx_t *ctx, ant_offset_t old_off) { + ant_offset_t new_off = fwd_lookup(&ctx->fwd, old_off); + if (new_off == (ant_offset_t)~0) return; - jsoff_t header = gc_loadoff(ctx->js->mem, old_off); - jsoff_t next_prop = header & ~(3ULL | FLAGMASK); + ant_offset_t header = gc_loadoff(ctx->js->mem, old_off); + ant_offset_t next_prop = header & ~(3ULL | FLAGMASK); if (next_prop != 0 && next_prop < ctx->js->brk) { - jsoff_t new_next = gc_reserve_prop(ctx, next_prop); - jsoff_t new_header = (new_next & ~3ULL) | (header & (3ULL | FLAGMASK)); + ant_offset_t new_next = gc_reserve_prop(ctx, next_prop); + ant_offset_t new_header = (new_next & ~3ULL) | (header & (3ULL | FLAGMASK)); gc_saveoff(ctx->new_mem, new_off, new_header); } bool is_slot = (header & SLOTMASK) != 0; if (!is_slot) { - jsoff_t key_off = gc_loadoff(ctx->js->mem, old_off + sizeof(jsoff_t)); + ant_offset_t key_off = gc_loadoff(ctx->js->mem, old_off + sizeof(ant_offset_t)); if (key_off < ctx->js->brk) { - jsoff_t key_hdr = gc_loadoff(ctx->js->mem, key_off); jsoff_t new_key; + ant_offset_t key_hdr = gc_loadoff(ctx->js->mem, key_off); ant_offset_t new_key; if ((key_hdr & 3) == T_STR) new_key = gc_copy_string(ctx, key_off); else new_key = gc_copy_symbol(ctx, key_off); - gc_saveoff(ctx->new_mem, new_off + sizeof(jsoff_t), new_key); + gc_saveoff(ctx->new_mem, new_off + sizeof(ant_offset_t), new_key); } } - jsval_t val = gc_loadval(ctx->js->mem, old_off + sizeof(jsoff_t) + sizeof(jsoff_t)); + ant_value_t val = gc_loadval(ctx->js->mem, old_off + sizeof(ant_offset_t) + sizeof(ant_offset_t)); if (!is_slot) goto update_val; - jsoff_t slot_id = gc_loadoff(ctx->js->mem, old_off + sizeof(jsoff_t)); - if (slot_id != (jsoff_t)SLOT_DENSE_BUF) goto update_val; + ant_offset_t slot_id = gc_loadoff(ctx->js->mem, old_off + sizeof(ant_offset_t)); + if (slot_id != (ant_offset_t)SLOT_DENSE_BUF) goto update_val; - jsoff_t old_doff = (jsoff_t)tod(val); + ant_offset_t old_doff = (ant_offset_t)tod(val); if (old_doff == 0 || old_doff >= ctx->js->brk) goto update_val; - jsoff_t cap = gc_loadoff(ctx->js->mem, old_doff); - jsoff_t len = gc_loadoff(ctx->js->mem, old_doff + sizeof(jsoff_t)); - jsoff_t buf_size = (jsoff_t)(sizeof(jsoff_t) * 2 + sizeof(jsval_t) * cap); - jsoff_t new_doff = gc_alloc(ctx, buf_size); - if (new_doff == (jsoff_t)~0) return; + ant_offset_t cap = gc_loadoff(ctx->js->mem, old_doff); + ant_offset_t len = gc_loadoff(ctx->js->mem, old_doff + sizeof(ant_offset_t)); + ant_offset_t buf_size = (ant_offset_t)(sizeof(ant_offset_t) * 2 + sizeof(ant_value_t) * cap); + ant_offset_t new_doff = gc_alloc(ctx, buf_size); + if (new_doff == (ant_offset_t)~0) return; memcpy(&ctx->new_mem[new_doff], &ctx->js->mem[old_doff], buf_size); - for (jsoff_t i = 0; i < len; i++) { - jsoff_t voff = new_doff + (jsoff_t)(sizeof(jsoff_t) * 2 + sizeof(jsval_t) * i); - jsval_t v = gc_loadval(ctx->new_mem, voff); + for (ant_offset_t i = 0; i < len; i++) { + ant_offset_t voff = new_doff + (ant_offset_t)(sizeof(ant_offset_t) * 2 + sizeof(ant_value_t) * i); + ant_value_t v = gc_loadval(ctx->new_mem, voff); if (v != T_EMPTY) { - jsval_t nv = gc_update_val(ctx, v); + ant_value_t nv = gc_update_val(ctx, v); gc_saveval(ctx->new_mem, voff, nv); } } gc_saveval( ctx->new_mem, - new_off + sizeof(jsoff_t) + sizeof(jsoff_t), + new_off + sizeof(ant_offset_t) + sizeof(ant_offset_t), tov((double)new_doff) ); return; update_val: { - jsval_t new_val = gc_update_val(ctx, val); - gc_saveval(ctx->new_mem, new_off + sizeof(jsoff_t) + sizeof(jsoff_t), new_val); + ant_value_t new_val = gc_update_val(ctx, val); + gc_saveval(ctx->new_mem, new_off + sizeof(ant_offset_t) + sizeof(ant_offset_t), new_val); } } -static void gc_process_object(gc_ctx_t *ctx, jsoff_t old_off) { - jsoff_t new_off = fwd_lookup(&ctx->fwd, old_off); - if (new_off == (jsoff_t)~0) return; +static void gc_process_object(gc_ctx_t *ctx, ant_offset_t old_off) { + ant_offset_t new_off = fwd_lookup(&ctx->fwd, old_off); + if (new_off == (ant_offset_t)~0) return; - jsoff_t header = gc_loadoff(ctx->js->mem, old_off); + ant_offset_t header = gc_loadoff(ctx->js->mem, old_off); - jsoff_t first_prop = header & ~(3ULL | FLAGMASK); + ant_offset_t first_prop = header & ~(3ULL | FLAGMASK); if (first_prop != 0 && first_prop < ctx->js->brk) { - jsoff_t new_first = gc_reserve_prop(ctx, first_prop); - jsoff_t new_header = (new_first & ~3ULL) | (header & (3ULL | FLAGMASK)); + ant_offset_t new_first = gc_reserve_prop(ctx, first_prop); + ant_offset_t new_header = (new_first & ~3ULL) | (header & (3ULL | FLAGMASK)); gc_saveoff(ctx->new_mem, new_off, new_header); } - jsoff_t parent_off = gc_loadoff(ctx->js->mem, old_off + sizeof(jsoff_t)); + ant_offset_t parent_off = gc_loadoff(ctx->js->mem, old_off + sizeof(ant_offset_t)); if (parent_off < ctx->js->brk) { - jsoff_t new_parent = gc_reserve_object(ctx, parent_off); - gc_saveoff(ctx->new_mem, new_off + sizeof(jsoff_t), new_parent); + ant_offset_t new_parent = gc_reserve_object(ctx, parent_off); + gc_saveoff(ctx->new_mem, new_off + sizeof(ant_offset_t), new_parent); } - jsoff_t tail_off = gc_loadoff(ctx->js->mem, old_off + sizeof(jsoff_t) + sizeof(jsoff_t)); + ant_offset_t tail_off = gc_loadoff(ctx->js->mem, old_off + sizeof(ant_offset_t) + sizeof(ant_offset_t)); if (tail_off != 0 && tail_off < ctx->js->brk) { - jsoff_t new_tail = fwd_lookup(&ctx->fwd, tail_off); - if (new_tail == (jsoff_t)~0) new_tail = gc_reserve_prop(ctx, tail_off); - gc_saveoff(ctx->new_mem, new_off + sizeof(jsoff_t) + sizeof(jsoff_t), new_tail); + ant_offset_t new_tail = fwd_lookup(&ctx->fwd, tail_off); + if (new_tail == (ant_offset_t)~0) new_tail = gc_reserve_prop(ctx, tail_off); + gc_saveoff(ctx->new_mem, new_off + sizeof(ant_offset_t) + sizeof(ant_offset_t), new_tail); } } static void gc_drain_work_queue(gc_ctx_t *ctx) { - jsoff_t off; - while ((off = work_pop(&ctx->work)) != (jsoff_t)~0) { - jsoff_t header = gc_loadoff(ctx->js->mem, off); + ant_offset_t off; + while ((off = work_pop(&ctx->work)) != (ant_offset_t)~0) { + ant_offset_t header = gc_loadoff(ctx->js->mem, off); switch (header & 3) { case T_OBJ: gc_process_object(ctx, off); break; case T_PROP: gc_process_prop(ctx, off); break; @@ -574,11 +574,11 @@ static void gc_drain_work_queue(gc_ctx_t *ctx) { } } -static jsval_t gc_update_val(gc_ctx_t *ctx, jsval_t val) { +static ant_value_t gc_update_val(gc_ctx_t *ctx, ant_value_t val) { if (!gc_is_tagged(val)) return val; uint8_t type = gc_vtype(val); - jsoff_t old_off = (jsoff_t)gc_vdata(val); + ant_offset_t old_off = (ant_offset_t)gc_vdata(val); switch (type) { case T_OBJ: @@ -586,32 +586,32 @@ static jsval_t gc_update_val(gc_ctx_t *ctx, jsval_t val) { case T_PROMISE: case T_GENERATOR: { if (old_off >= ctx->js->brk) return val; - jsoff_t new_off = gc_reserve_object(ctx, old_off); - if (new_off != (jsoff_t)~0) return gc_mkval(type, new_off); + ant_offset_t new_off = gc_reserve_object(ctx, old_off); + if (new_off != (ant_offset_t)~0) return gc_mkval(type, new_off); break; } case T_STR: { if (old_off >= ctx->js->brk) return val; - jsoff_t new_off = gc_copy_string(ctx, old_off); - if (new_off != (jsoff_t)~0) return gc_mkval(type, new_off); + ant_offset_t new_off = gc_copy_string(ctx, old_off); + if (new_off != (ant_offset_t)~0) return gc_mkval(type, new_off); break; } case T_PROP: { if (old_off >= ctx->js->brk) return val; - jsoff_t new_off = gc_reserve_prop(ctx, old_off); - if (new_off != (jsoff_t)~0) return gc_mkval(type, new_off); + ant_offset_t new_off = gc_reserve_prop(ctx, old_off); + if (new_off != (ant_offset_t)~0) return gc_mkval(type, new_off); break; } case T_BIGINT: { if (old_off >= ctx->js->brk) return val; - jsoff_t new_off = gc_copy_bigint(ctx, old_off); - if (new_off != (jsoff_t)~0) return gc_mkval(type, new_off); + ant_offset_t new_off = gc_copy_bigint(ctx, old_off); + if (new_off != (ant_offset_t)~0) return gc_mkval(type, new_off); break; } case T_SYMBOL: { if (old_off >= ctx->js->brk) return val; - jsoff_t new_off = gc_copy_symbol(ctx, old_off); - if (new_off != (jsoff_t)~0) return gc_mkval(type, new_off); + ant_offset_t new_off = gc_copy_symbol(ctx, old_off); + if (new_off != (ant_offset_t)~0) return gc_mkval(type, new_off); break; } case T_FUNC: @@ -625,16 +625,16 @@ static jsval_t gc_update_val(gc_ctx_t *ctx, jsval_t val) { return val; } -static jsoff_t gc_fwd_off_callback(void *ctx_ptr, jsoff_t old_off) { +static ant_offset_t gc_fwd_off_callback(void *ctx_ptr, ant_offset_t old_off) { gc_ctx_t *ctx = (gc_ctx_t *)ctx_ptr; if (old_off == 0) return 0; if (old_off >= ctx->js->brk) return old_off; - jsoff_t new_off = fwd_lookup(&ctx->fwd, old_off); - if (new_off != (jsoff_t)~0) return new_off; + ant_offset_t new_off = fwd_lookup(&ctx->fwd, old_off); + if (new_off != (ant_offset_t)~0) return new_off; static const void *dispatch[] = { &&l_obj, &&l_prop, &&l_str, &&l_default }; - jsoff_t header = gc_loadoff(ctx->js->mem, old_off); + ant_offset_t header = gc_loadoff(ctx->js->mem, old_off); goto *dispatch[header & 3]; l_obj: new_off = gc_reserve_object(ctx, old_off); goto l_done; @@ -642,30 +642,30 @@ static jsoff_t gc_fwd_off_callback(void *ctx_ptr, jsoff_t old_off) { l_str: new_off = gc_copy_string(ctx, old_off); goto l_done; l_default: return old_off; - l_done: return (new_off != (jsoff_t)~0) ? new_off : old_off; + l_done: return (new_off != (ant_offset_t)~0) ? new_off : old_off; } -static jsval_t gc_fwd_val_callback(void *ctx_ptr, jsval_t val) { +static ant_value_t gc_fwd_val_callback(void *ctx_ptr, ant_value_t val) { gc_ctx_t *ctx = (gc_ctx_t *)ctx_ptr; return gc_update_val(ctx, val); } -static jsoff_t gc_apply_off_callback(void *ctx_ptr, jsoff_t old_off) { +static ant_offset_t gc_apply_off_callback(void *ctx_ptr, ant_offset_t old_off) { gc_ctx_t *ctx = (gc_ctx_t *)ctx_ptr; if (old_off == 0) return 0; if (old_off >= ctx->js->brk) return old_off; - jsoff_t new_off = fwd_lookup(&ctx->fwd, old_off); - return (new_off != (jsoff_t)~0) ? new_off : old_off; + ant_offset_t new_off = fwd_lookup(&ctx->fwd, old_off); + return (new_off != (ant_offset_t)~0) ? new_off : old_off; } -static jsval_t gc_apply_val(gc_ctx_t *ctx, jsval_t val) { +static ant_value_t gc_apply_val(gc_ctx_t *ctx, ant_value_t val) { if (!gc_is_tagged(val)) return val; uint8_t type = gc_vtype(val); if (type == T_FUNC || type == T_CLOSURE) return val; - jsoff_t old_off = (jsoff_t)gc_vdata(val); + ant_offset_t old_off = (ant_offset_t)gc_vdata(val); if (old_off >= ctx->js->brk) return val; switch (type) { @@ -677,8 +677,8 @@ static jsval_t gc_apply_val(gc_ctx_t *ctx, jsval_t val) { case T_PROP: case T_BIGINT: case T_SYMBOL: { - jsoff_t new_off = fwd_lookup(&ctx->fwd, old_off); - if (new_off != (jsoff_t)~0) return gc_mkval(type, new_off); + ant_offset_t new_off = fwd_lookup(&ctx->fwd, old_off); + if (new_off != (ant_offset_t)~0) return gc_mkval(type, new_off); break; } default: break; @@ -687,12 +687,12 @@ static jsval_t gc_apply_val(gc_ctx_t *ctx, jsval_t val) { return val; } -static jsval_t gc_apply_val_callback(void *ctx_ptr, jsval_t val) { +static ant_value_t gc_apply_val_callback(void *ctx_ptr, ant_value_t val) { gc_ctx_t *ctx = (gc_ctx_t *)ctx_ptr; return gc_apply_val(ctx, val); } -static jsoff_t gc_weak_off_callback(void *ctx_ptr, jsoff_t old_off) { +static ant_offset_t gc_weak_off_callback(void *ctx_ptr, ant_offset_t old_off) { gc_ctx_t *ctx = (gc_ctx_t *)ctx_ptr; if (old_off >= ctx->js->brk) return old_off; return fwd_lookup(&ctx->fwd, old_off); @@ -721,15 +721,15 @@ static inline bool gc_stack_word_readable(uintptr_t addr) { #endif } -static inline bool gc_off_has_bytes(jsoff_t off, jsoff_t need, jsoff_t brk) { +static inline bool gc_off_has_bytes(ant_offset_t off, ant_offset_t need, ant_offset_t brk) { return off <= brk && need <= brk - off; } -static inline bool gc_stack_word_valid(gc_ctx_t *ctx, uint8_t type, jsoff_t old_off, jsoff_t old_brk) { +static inline bool gc_stack_word_valid(gc_ctx_t *ctx, uint8_t type, ant_offset_t old_off, ant_offset_t old_brk) { if (old_off == 0 || old_off >= old_brk) return false; - if (!gc_off_has_bytes(old_off, (jsoff_t)sizeof(jsoff_t), old_brk)) return false; + if (!gc_off_has_bytes(old_off, (ant_offset_t)sizeof(ant_offset_t), old_brk)) return false; - jsoff_t header = gc_loadoff(ctx->js->mem, old_off); + ant_offset_t header = gc_loadoff(ctx->js->mem, old_off); switch (type) { case T_OBJ: @@ -737,44 +737,44 @@ static inline bool gc_stack_word_valid(gc_ctx_t *ctx, uint8_t type, jsoff_t old_ case T_PROMISE: case T_GENERATOR: { if ((header & 3) != T_OBJ) return false; - jsoff_t size = esize(header); - return size != (jsoff_t)~0 && gc_off_has_bytes(old_off, size, old_brk); + ant_offset_t size = esize(header); + return size != (ant_offset_t)~0 && gc_off_has_bytes(old_off, size, old_brk); } case T_PROP: { if ((header & 3) != T_PROP) return false; - jsoff_t size = esize(header); - return size != (jsoff_t)~0 && gc_off_has_bytes(old_off, size, old_brk); + ant_offset_t size = esize(header); + return size != (ant_offset_t)~0 && gc_off_has_bytes(old_off, size, old_brk); } case T_STR: { if ((header & 3) != T_STR) return false; if ((header & ROPE_FLAG) != 0) - return gc_off_has_bytes(old_off, (jsoff_t)sizeof(rope_node_t), old_brk); - jsoff_t size = esize(header); - return size != (jsoff_t)~0 && gc_off_has_bytes(old_off, size, old_brk); + return gc_off_has_bytes(old_off, (ant_offset_t)sizeof(rope_node_t), old_brk); + ant_offset_t size = esize(header); + return size != (ant_offset_t)~0 && gc_off_has_bytes(old_off, size, old_brk); } case T_BIGINT: { if ((header & GC_BIGINT_HEADER_LOW_MASK) != 0) return false; - jsoff_t payload = header >> GC_BIGINT_HEADER_SHIFT; + ant_offset_t payload = header >> GC_BIGINT_HEADER_SHIFT; if (payload < 2) return false; - jsoff_t total = payload + (jsoff_t)sizeof(jsoff_t); - total = (total + 7) & ~(jsoff_t)7; + ant_offset_t total = payload + (ant_offset_t)sizeof(ant_offset_t); + total = (total + 7) & ~(ant_offset_t)7; if (!gc_off_has_bytes(old_off, total, old_brk)) return false; - jsoff_t sign_off = old_off + (jsoff_t)sizeof(jsoff_t); + ant_offset_t sign_off = old_off + (ant_offset_t)sizeof(ant_offset_t); uint8_t sign = ctx->js->mem[sign_off]; if (sign > 1) return false; - jsoff_t nul_off = sign_off + payload - 1; + ant_offset_t nul_off = sign_off + payload - 1; return ctx->js->mem[nul_off] == 0; } case T_SYMBOL: { if ((header & GC_SYM_HEADER_LOW_MASK) != 0) return false; - jsoff_t payload = header >> GC_SYM_HEADER_SHIFT; + ant_offset_t payload = header >> GC_SYM_HEADER_SHIFT; if (payload < GC_SYM_HEAP_FIXED) return false; - jsoff_t total = payload + (jsoff_t)sizeof(jsoff_t); - total = (total + 7) & ~(jsoff_t)7; + ant_offset_t total = payload + (ant_offset_t)sizeof(ant_offset_t); + total = (total + 7) & ~(ant_offset_t)7; return gc_off_has_bytes(old_off, total, old_brk); } default: return false; @@ -789,7 +789,7 @@ static void gc_scan_stack_reserve(gc_ctx_t *ctx) { volatile uint8_t sp_marker = 0; uintptr_t lo, hi; if (!gc_get_stack_bounds((uintptr_t)ctx->js->cstk.base, (uintptr_t)&sp_marker, &lo, &hi)) return; - jsoff_t old_brk = ctx->js->brk; + ant_offset_t old_brk = ctx->js->brk; for (uintptr_t addr = lo; addr < hi; addr += sizeof(uint64_t)) { if (!gc_stack_word_readable(addr)) continue; @@ -802,11 +802,11 @@ static void gc_scan_stack_reserve(gc_ctx_t *ctx) { if (type > T_FFI) continue; if (!((1u << type) & GC_HEAP_TYPE_MASK)) continue; - jsoff_t old_off = (jsoff_t)(w & NANBOX_DATA_MASK); + ant_offset_t old_off = (ant_offset_t)(w & NANBOX_DATA_MASK); if (old_off == 0 || old_off >= old_brk) continue; if (!gc_stack_word_valid(ctx, type, old_off, old_brk)) continue; - if (fwd_lookup(&ctx->fwd, old_off) != (jsoff_t)~0) continue; + if (fwd_lookup(&ctx->fwd, old_off) != (ant_offset_t)~0) continue; gc_update_val(ctx, w); } } @@ -819,7 +819,7 @@ static void gc_scan_stack_update(gc_ctx_t *ctx) { volatile uint8_t sp_marker = 0; uintptr_t lo, hi; if (!gc_get_stack_bounds((uintptr_t)ctx->js->cstk.base, (uintptr_t)&sp_marker, &lo, &hi)) return; - jsoff_t old_brk = ctx->js->brk; + ant_offset_t old_brk = ctx->js->brk; for (uintptr_t addr = lo; addr < hi; addr += sizeof(uint64_t)) { if (!gc_stack_word_readable(addr)) continue; @@ -832,12 +832,12 @@ static void gc_scan_stack_update(gc_ctx_t *ctx) { if (type > T_FFI) continue; if (!((1u << type) & GC_HEAP_TYPE_MASK)) continue; - jsoff_t old_off = (jsoff_t)(w & NANBOX_DATA_MASK); + ant_offset_t old_off = (ant_offset_t)(w & NANBOX_DATA_MASK); if (old_off == 0 || old_off >= old_brk) continue; if (!gc_stack_word_valid(ctx, type, old_off, old_brk)) continue; - jsoff_t new_off = fwd_lookup(&ctx->fwd, old_off); - if (new_off == (jsoff_t)~0 || new_off == old_off) continue; + ant_offset_t new_off = fwd_lookup(&ctx->fwd, old_off); + if (new_off == (ant_offset_t)~0 || new_off == old_off) continue; uint64_t updated = gc_mkval(type, new_off); memcpy((void *)addr, &updated, sizeof(updated)); @@ -845,7 +845,7 @@ static void gc_scan_stack_update(gc_ctx_t *ctx) { } static void gc_scan_range_reserve(gc_ctx_t *ctx, uintptr_t lo, uintptr_t hi) { - jsoff_t old_brk = ctx->js->brk; + ant_offset_t old_brk = ctx->js->brk; for (uintptr_t addr = lo; addr < hi; addr += sizeof(uint64_t)) { if (!gc_stack_word_readable(addr)) continue; uint64_t w; @@ -854,16 +854,16 @@ static void gc_scan_range_reserve(gc_ctx_t *ctx, uintptr_t lo, uintptr_t hi) { uint8_t type = (w >> NANBOX_TYPE_SHIFT) & NANBOX_TYPE_MASK; if (type > T_FFI) continue; if (!((1u << type) & GC_HEAP_TYPE_MASK)) continue; - jsoff_t old_off = (jsoff_t)(w & NANBOX_DATA_MASK); + ant_offset_t old_off = (ant_offset_t)(w & NANBOX_DATA_MASK); if (old_off == 0 || old_off >= old_brk) continue; if (!gc_stack_word_valid(ctx, type, old_off, old_brk)) continue; - if (fwd_lookup(&ctx->fwd, old_off) != (jsoff_t)~0) continue; + if (fwd_lookup(&ctx->fwd, old_off) != (ant_offset_t)~0) continue; gc_update_val(ctx, w); } } static void gc_scan_range_update(gc_ctx_t *ctx, uintptr_t lo, uintptr_t hi) { - jsoff_t old_brk = ctx->js->brk; + ant_offset_t old_brk = ctx->js->brk; for (uintptr_t addr = lo; addr < hi; addr += sizeof(uint64_t)) { if (!gc_stack_word_readable(addr)) continue; uint64_t w; @@ -872,11 +872,11 @@ static void gc_scan_range_update(gc_ctx_t *ctx, uintptr_t lo, uintptr_t hi) { uint8_t type = (w >> NANBOX_TYPE_SHIFT) & NANBOX_TYPE_MASK; if (type > T_FFI) continue; if (!((1u << type) & GC_HEAP_TYPE_MASK)) continue; - jsoff_t old_off = (jsoff_t)(w & NANBOX_DATA_MASK); + ant_offset_t old_off = (ant_offset_t)(w & NANBOX_DATA_MASK); if (old_off == 0 || old_off >= old_brk) continue; if (!gc_stack_word_valid(ctx, type, old_off, old_brk)) continue; - jsoff_t new_off = fwd_lookup(&ctx->fwd, old_off); - if (new_off == (jsoff_t)~0 || new_off == old_off) continue; + ant_offset_t new_off = fwd_lookup(&ctx->fwd, old_off); + if (new_off == (ant_offset_t)~0 || new_off == old_off) continue; uint64_t updated = gc_mkval(type, new_off); memcpy((void *)addr, &updated, sizeof(updated)); } @@ -981,7 +981,7 @@ static void gc_compact(ant_t *js) { ctx.js = js; ctx.new_mem = new_mem; ctx.new_brk = NANBOX_HEAP_OFFSET; - ctx.new_size = (jsoff_t)new_size; + ctx.new_size = (ant_offset_t)new_size; ctx.mark_bits = mark_bits; if (!fwd_init(&ctx.fwd, estimated_objs)) { @@ -997,7 +997,7 @@ static void gc_compact(ant_t *js) { gc_epoch_counter++; if (js->brk > 0) { - jsoff_t header_at_0 = gc_loadoff(js->mem, 0); + ant_offset_t header_at_0 = gc_loadoff(js->mem, 0); if ((header_at_0 & 3) == T_OBJ) gc_reserve_object(&ctx, 0); } @@ -1045,18 +1045,18 @@ static void gc_compact(ant_t *js) { if (new_brk < old_size * 3 / 4 && old_size > ARENA_GROW_INCREMENT) { size_t target = ((new_brk * 3 / 2 + ARENA_GROW_INCREMENT - 1) / ARENA_GROW_INCREMENT) * ARENA_GROW_INCREMENT; if (target < ARENA_GROW_INCREMENT) target = ARENA_GROW_INCREMENT; - if (target < old_size) { ant_arena_decommit(js->mem, old_size, target); js->size = (jsoff_t)target; } + if (target < old_size) { ant_arena_decommit(js->mem, old_size, target); js->size = (ant_offset_t)target; } } } void js_gc_maybe(ant_t *js) { - jsoff_t thresh = js->brk / 4; + ant_offset_t thresh = js->brk / 4; - jsoff_t min_thresh = gc_throttled + ant_offset_t min_thresh = gc_throttled ? 8 * 1024 * 1024 : 2 * 1024 * 1024; - jsoff_t max_thresh = gc_throttled + ant_offset_t max_thresh = gc_throttled ? 64 * 1024 * 1024 : 16 * 1024 * 1024; diff --git a/src/main.c b/src/main.c index d2ebe99..863506f 100644 --- a/src/main.c +++ b/src/main.c @@ -254,7 +254,7 @@ static void eval_code(ant_t *js, const char *script, size_t len, const char *tag js_set(js, js_glob(js), "__dirname", js_mkstr(js, ".", 1)); js_set(js, js_glob(js), "__filename", js_mkstr(js, tag, strlen(tag))); - jsval_t result = js_eval_bytecode_eval(js, script, len); + ant_value_t result = js_eval_bytecode_eval(js, script, len); js_run_event_loop(js); if (print_uncaught_throw(js)) { @@ -334,14 +334,14 @@ static int execute_module(ant_t *js, const char *filename) { js_set_filename(js, use_path); js_setup_import_meta(js, use_path); - jsval_t import_fn = js_get(js, js->global, "import"); - jsval_t module_ns = mkobj(js, 0); + ant_value_t import_fn = js_get(js, js->global, "import"); + ant_value_t module_ns = mkobj(js, 0); js->import_meta = (vtype(import_fn) == T_FUNC) ? js_get(js, import_fn, "meta") : js_mkundef(); - jsval_t result = js_esm_eval_module_source( + ant_value_t result = js_esm_eval_module_source( js, use_path, js_code, js_len, module_ns ); @@ -620,7 +620,7 @@ int main(int argc, char *argv[]) { ant_standard_library("worker_threads", worker_threads_library); ant_standard_library("async_hooks", async_hooks_library); - jsval_t snapshot_result = ant_load_snapshot(js); + ant_value_t snapshot_result = ant_load_snapshot(js); if (vtype(snapshot_result) == T_ERR) { crfprintf(stderr, msg.snapshot_warn, js_str(js, snapshot_result)); } diff --git a/src/modules/async_hooks.c b/src/modules/async_hooks.c index 8d1e1d7..bf79b8b 100644 --- a/src/modules/async_hooks.c +++ b/src/modules/async_hooks.c @@ -11,62 +11,62 @@ #include "modules/async_hooks.h" #include "modules/symbol.h" -static inline bool async_hooks_is_callable(jsval_t v) { +static inline bool async_hooks_is_callable(ant_value_t v) { uint8_t t = vtype(v); return t == T_FUNC || t == T_CFUNC; } -static jsval_t async_hooks_call_with_tail_args( - ant_t *js, jsval_t fn, jsval_t this_arg, jsval_t *args, int nargs, int start_idx +static ant_value_t async_hooks_call_with_tail_args( + ant_t *js, ant_value_t fn, ant_value_t this_arg, ant_value_t *args, int nargs, int start_idx ) { int call_nargs = nargs - start_idx; if (call_nargs <= 0) return sv_vm_call(js->vm, js, fn, this_arg, NULL, 0, NULL, false); - jsval_t *call_args = (jsval_t *)malloc((size_t)call_nargs * sizeof(jsval_t)); + ant_value_t *call_args = (ant_value_t *)malloc((size_t)call_nargs * sizeof(ant_value_t)); if (!call_args) return js_mkerr(js, "Out of memory"); for (int i = 0; i < call_nargs; i++) call_args[i] = args[start_idx + i]; - jsval_t result = sv_vm_call(js->vm, js, fn, this_arg, call_args, call_nargs, NULL, false); + ant_value_t result = sv_vm_call(js->vm, js, fn, this_arg, call_args, call_nargs, NULL, false); free(call_args); return result; } -static jsval_t async_local_storage_run(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t async_local_storage_run(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2 || !async_hooks_is_callable(args[1])) { return js_mkerr(js, "AsyncLocalStorage.run(store, callback, ...args) requires a callback"); } - jsval_t this_obj = js_getthis(js); + ant_value_t this_obj = js_getthis(js); if (!is_object_type(this_obj)) { return js_mkerr(js, "AsyncLocalStorage.run() requires an AsyncLocalStorage instance"); } - jsval_t prev = js_get_slot(js, this_obj, SLOT_DATA); + ant_value_t prev = js_get_slot(js, this_obj, SLOT_DATA); js_set_slot(js, this_obj, SLOT_DATA, args[0]); - jsval_t result = async_hooks_call_with_tail_args(js, args[1], js_mkundef(), args, nargs, 2); + ant_value_t result = async_hooks_call_with_tail_args(js, args[1], js_mkundef(), args, nargs, 2); js_set_slot(js, this_obj, SLOT_DATA, prev); return result; } -static jsval_t async_local_storage_exit(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t async_local_storage_exit(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || !async_hooks_is_callable(args[0])) { return js_mkerr(js, "AsyncLocalStorage.exit(callback, ...args) requires a callback"); } - jsval_t this_obj = js_getthis(js); + ant_value_t this_obj = js_getthis(js); if (!is_object_type(this_obj)) { return js_mkerr(js, "AsyncLocalStorage.exit() requires an AsyncLocalStorage instance"); } - jsval_t prev = js_get_slot(js, this_obj, SLOT_DATA); + ant_value_t prev = js_get_slot(js, this_obj, SLOT_DATA); js_set_slot(js, this_obj, SLOT_DATA, js_mkundef()); - jsval_t result = async_hooks_call_with_tail_args(js, args[0], js_mkundef(), args, nargs, 1); + ant_value_t result = async_hooks_call_with_tail_args(js, args[0], js_mkundef(), args, nargs, 1); js_set_slot(js, this_obj, SLOT_DATA, prev); return result; } -static jsval_t async_local_storage_enterWith(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t async_local_storage_enterWith(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (!is_object_type(this_obj)) { return js_mkerr(js, "AsyncLocalStorage.enterWith() requires an AsyncLocalStorage instance"); } @@ -74,81 +74,81 @@ static jsval_t async_local_storage_enterWith(ant_t *js, jsval_t *args, int nargs return js_mkundef(); } -static jsval_t async_local_storage_getStore(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t async_local_storage_getStore(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t this_obj = js_getthis(js); + ant_value_t this_obj = js_getthis(js); if (!is_object_type(this_obj)) return js_mkundef(); return js_get_slot(js, this_obj, SLOT_DATA); } -static jsval_t async_local_storage_disable(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t async_local_storage_disable(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t this_obj = js_getthis(js); + ant_value_t this_obj = js_getthis(js); if (is_object_type(this_obj)) js_set_slot(js, this_obj, SLOT_DATA, js_mkundef()); return js_mkundef(); } -static jsval_t async_resource_runInAsyncScope(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t async_resource_runInAsyncScope(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || !async_hooks_is_callable(args[0])) { return js_mkerr(js, "AsyncResource.runInAsyncScope(fn[, thisArg, ...args]) requires a function"); } - jsval_t this_arg = nargs > 1 ? args[1] : js_mkundef(); + ant_value_t this_arg = nargs > 1 ? args[1] : js_mkundef(); return async_hooks_call_with_tail_args(js, args[0], this_arg, args, nargs, 2); } -static jsval_t async_resource_emitDestroy(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t async_resource_emitDestroy(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; return js_getthis(js); } -static jsval_t async_resource_asyncId(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t async_resource_asyncId(ant_t *js, ant_value_t *args, int nargs) { (void)js; (void)args; (void)nargs; return js_mknum(0); } -static jsval_t async_resource_triggerAsyncId(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t async_resource_triggerAsyncId(ant_t *js, ant_value_t *args, int nargs) { (void)js; (void)args; (void)nargs; return js_mknum(0); } -static jsval_t async_hook_enable(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t async_hook_enable(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; return js_getthis(js); } -static jsval_t async_hook_disable(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t async_hook_disable(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; return js_getthis(js); } -static jsval_t async_hooks_createHook(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t async_hooks_createHook(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t hook = js_mkobj(js); + ant_value_t hook = js_mkobj(js); js_set(js, hook, "enable", js_mkfun(async_hook_enable)); js_set(js, hook, "disable", js_mkfun(async_hook_disable)); return hook; } -static jsval_t async_hooks_executionAsyncId(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t async_hooks_executionAsyncId(ant_t *js, ant_value_t *args, int nargs) { (void)js; (void)args; (void)nargs; return js_mknum(1); } -static jsval_t async_hooks_triggerAsyncId(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t async_hooks_triggerAsyncId(ant_t *js, ant_value_t *args, int nargs) { (void)js; (void)args; (void)nargs; return js_mknum(0); } -static jsval_t async_hooks_executionAsyncResource(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t async_hooks_executionAsyncResource(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; return js_mkobj(js); } -jsval_t async_hooks_library(ant_t *js) { - jsval_t lib = js_mkobj(js); +ant_value_t async_hooks_library(ant_t *js) { + ant_value_t lib = js_mkobj(js); - jsval_t als_ctor = js_mkobj(js); - jsval_t als_proto = js_mkobj(js); + ant_value_t als_ctor = js_mkobj(js); + ant_value_t als_proto = js_mkobj(js); js_set(js, als_proto, "run", js_mkfun(async_local_storage_run)); js_set(js, als_proto, "exit", js_mkfun(async_local_storage_exit)); js_set(js, als_proto, "enterWith", js_mkfun(async_local_storage_enterWith)); @@ -161,8 +161,8 @@ jsval_t async_hooks_library(ant_t *js) { js_set_descriptor(js, als_ctor, "name", 4, 0); js_set(js, lib, "AsyncLocalStorage", js_obj_to_func(als_ctor)); - jsval_t resource_ctor = js_mkobj(js); - jsval_t resource_proto = js_mkobj(js); + ant_value_t resource_ctor = js_mkobj(js); + ant_value_t resource_proto = js_mkobj(js); js_set(js, resource_proto, "runInAsyncScope", js_mkfun(async_resource_runInAsyncScope)); js_set(js, resource_proto, "emitDestroy", js_mkfun(async_resource_emitDestroy)); js_set(js, resource_proto, "asyncId", js_mkfun(async_resource_asyncId)); diff --git a/src/modules/atomics.c b/src/modules/atomics.c index 22f5b6f..d05c8c7 100644 --- a/src/modules/atomics.c +++ b/src/modules/atomics.c @@ -82,8 +82,8 @@ int wait_queue_notify(WaitQueue *queue, int32_t *address, int count) { return notified; } -static bool get_atomic_array_data(ant_t *js, jsval_t this_val, TypedArrayData **out_data, uint8_t **out_ptr) { - jsval_t ta_data_val = js_get_slot(js, this_val, SLOT_BUFFER); +static bool get_atomic_array_data(ant_t *js, ant_value_t this_val, TypedArrayData **out_data, uint8_t **out_ptr) { + ant_value_t ta_data_val = js_get_slot(js, this_val, SLOT_BUFFER); TypedArrayData *ta_data = (TypedArrayData *)js_gettypedarray(ta_data_val); if (!ta_data || !ta_data->buffer) return false; @@ -93,7 +93,7 @@ static bool get_atomic_array_data(ant_t *js, jsval_t this_val, TypedArrayData ** } // Atomics.add(typedArray, index, value) -static jsval_t js_atomics_add(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_atomics_add(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 3) { return js_mkerr(js, "Atomics.add requires 3 arguments"); } @@ -151,7 +151,7 @@ static jsval_t js_atomics_add(ant_t *js, jsval_t *args, int nargs) { } // Atomics.and(typedArray, index, value) -static jsval_t js_atomics_and(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_atomics_and(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 3) { return js_mkerr(js, "Atomics.and requires 3 arguments"); } @@ -209,7 +209,7 @@ static jsval_t js_atomics_and(ant_t *js, jsval_t *args, int nargs) { } // Atomics.compareExchange(typedArray, index, expectedValue, replacementValue) -static jsval_t js_atomics_compareExchange(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_atomics_compareExchange(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 4) { return js_mkerr(js, "Atomics.compareExchange requires 4 arguments"); } @@ -277,7 +277,7 @@ static jsval_t js_atomics_compareExchange(ant_t *js, jsval_t *args, int nargs) { } // Atomics.exchange(typedArray, index, value) -static jsval_t js_atomics_exchange(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_atomics_exchange(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 3) { return js_mkerr(js, "Atomics.exchange requires 3 arguments"); } @@ -335,7 +335,7 @@ static jsval_t js_atomics_exchange(ant_t *js, jsval_t *args, int nargs) { } // Atomics.isLockFree(size) -static jsval_t js_atomics_isLockFree(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_atomics_isLockFree(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) { return js_mkerr(js, "Atomics.isLockFree requires 1 argument"); } @@ -364,7 +364,7 @@ static jsval_t js_atomics_isLockFree(ant_t *js, jsval_t *args, int nargs) { } // Atomics.load(typedArray, index) -static jsval_t js_atomics_load(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_atomics_load(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) { return js_mkerr(js, "Atomics.load requires 2 arguments"); } @@ -421,7 +421,7 @@ static jsval_t js_atomics_load(ant_t *js, jsval_t *args, int nargs) { } // Atomics.or(typedArray, index, value) -static jsval_t js_atomics_or(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_atomics_or(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 3) { return js_mkerr(js, "Atomics.or requires 3 arguments"); } @@ -479,7 +479,7 @@ static jsval_t js_atomics_or(ant_t *js, jsval_t *args, int nargs) { } // Atomics.store(typedArray, index, value) -static jsval_t js_atomics_store(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_atomics_store(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 3) { return js_mkerr(js, "Atomics.store requires 3 arguments"); } @@ -536,7 +536,7 @@ static jsval_t js_atomics_store(ant_t *js, jsval_t *args, int nargs) { } // Atomics.sub(typedArray, index, value) -static jsval_t js_atomics_sub(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_atomics_sub(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 3) { return js_mkerr(js, "Atomics.sub requires 3 arguments"); } @@ -594,7 +594,7 @@ static jsval_t js_atomics_sub(ant_t *js, jsval_t *args, int nargs) { } // Atomics.xor(typedArray, index, value) -static jsval_t js_atomics_xor(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_atomics_xor(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 3) { return js_mkerr(js, "Atomics.xor requires 3 arguments"); } @@ -652,7 +652,7 @@ static jsval_t js_atomics_xor(ant_t *js, jsval_t *args, int nargs) { } // Atomics.wait(typedArray, index, value, timeout) -static jsval_t js_atomics_wait(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_atomics_wait(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 3) { return js_mkerr(js, "Atomics.wait requires at least 3 arguments"); } @@ -725,7 +725,7 @@ static jsval_t js_atomics_wait(ant_t *js, jsval_t *args, int nargs) { } // Atomics.notify(typedArray, index, count) -static jsval_t js_atomics_notify(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_atomics_notify(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) { return js_mkerr(js, "Atomics.notify requires at least 2 arguments"); } @@ -759,7 +759,7 @@ static jsval_t js_atomics_notify(ant_t *js, jsval_t *args, int nargs) { } // Atomics.waitAsync(typedArray, index, value, timeout) -static jsval_t js_atomics_waitAsync(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_atomics_waitAsync(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 3) { return js_mkerr(js, "Atomics.waitAsync requires at least 3 arguments"); } @@ -783,14 +783,14 @@ static jsval_t js_atomics_waitAsync(ant_t *js, jsval_t *args, int nargs) { _Atomic int32_t *atomic_ptr = (_Atomic int32_t *)(ptr + index * 4); int32_t current_value = atomic_load(atomic_ptr); - jsval_t result_obj = js_mkobj(js); + ant_value_t result_obj = js_mkobj(js); if (current_value != expected_value) { js_set(js, result_obj, "async", js_false); js_set(js, result_obj, "value", js_mkstr(js, "not-equal", 9)); return result_obj; } - jsval_t promise = js_mkpromise(js); + ant_value_t promise = js_mkpromise(js); js_set(js, result_obj, "async", js_true); js_set(js, result_obj, "value", promise); js_resolve_promise(js, promise, js_mkstr(js, "ok", 2)); @@ -799,7 +799,7 @@ static jsval_t js_atomics_waitAsync(ant_t *js, jsval_t *args, int nargs) { } // Atomics.pause() -static jsval_t js_atomics_pause(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_atomics_pause(ant_t *js, ant_value_t *args, int nargs) { (void)js; (void)args; (void)nargs; @@ -816,8 +816,8 @@ static jsval_t js_atomics_pause(ant_t *js, jsval_t *args, int nargs) { void init_atomics_module(void) { ant_t *js = rt->js; - jsval_t glob = js_glob(js); - jsval_t atomics = js_mkobj(js); + ant_value_t glob = js_glob(js); + ant_value_t atomics = js_mkobj(js); js_set(js, atomics, "add", js_mkfun(js_atomics_add)); js_set(js, atomics, "and", js_mkfun(js_atomics_and)); diff --git a/src/modules/buffer.c b/src/modules/buffer.c index 5f9b099..f28d6a5 100644 --- a/src/modules/buffer.c +++ b/src/modules/buffer.c @@ -99,31 +99,31 @@ static void *ta_arena_alloc(size_t size) { return ptr; } -static jsval_t js_arraybuffer_slice(ant_t *js, jsval_t *args, int nargs); -static jsval_t js_typedarray_slice(ant_t *js, jsval_t *args, int nargs); -static jsval_t js_typedarray_subarray(ant_t *js, jsval_t *args, int nargs); -static jsval_t js_typedarray_fill(ant_t *js, jsval_t *args, int nargs); -static jsval_t js_typedarray_at(ant_t *js, jsval_t *args, int nargs); -static jsval_t js_typedarray_set(ant_t *js, jsval_t *args, int nargs); -static jsval_t js_typedarray_copyWithin(ant_t *js, jsval_t *args, int nargs); -static jsval_t js_typedarray_toReversed(ant_t *js, jsval_t *args, int nargs); -static jsval_t js_typedarray_toSorted(ant_t *js, jsval_t *args, int nargs); -static jsval_t js_typedarray_with(ant_t *js, jsval_t *args, int nargs); -static jsval_t js_dataview_getUint8(ant_t *js, jsval_t *args, int nargs); -static jsval_t js_dataview_setUint8(ant_t *js, jsval_t *args, int nargs); -static jsval_t js_dataview_getInt16(ant_t *js, jsval_t *args, int nargs); -static jsval_t js_dataview_setInt16(ant_t *js, jsval_t *args, int nargs); -static jsval_t js_dataview_getInt32(ant_t *js, jsval_t *args, int nargs); -static jsval_t js_dataview_setInt32(ant_t *js, jsval_t *args, int nargs); -static jsval_t js_dataview_getFloat32(ant_t *js, jsval_t *args, int nargs); -static jsval_t js_dataview_setFloat32(ant_t *js, jsval_t *args, int nargs); -static jsval_t js_dataview_getFloat64(ant_t *js, jsval_t *args, int nargs); -static jsval_t js_dataview_setFloat64(ant_t *js, jsval_t *args, int nargs); -static jsval_t js_typedarray_toString(ant_t *js, jsval_t *args, int nargs); -static jsval_t js_buffer_slice(ant_t *js, jsval_t *args, int nargs); -static jsval_t js_buffer_toString(ant_t *js, jsval_t *args, int nargs); -static jsval_t js_buffer_toBase64(ant_t *js, jsval_t *args, int nargs); -static jsval_t js_buffer_write(ant_t *js, jsval_t *args, int nargs); +static ant_value_t js_arraybuffer_slice(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t js_typedarray_slice(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t js_typedarray_subarray(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t js_typedarray_fill(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t js_typedarray_at(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t js_typedarray_set(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t js_typedarray_copyWithin(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t js_typedarray_toReversed(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t js_typedarray_toSorted(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t js_typedarray_with(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t js_dataview_getUint8(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t js_dataview_setUint8(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t js_dataview_getInt16(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t js_dataview_setInt16(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t js_dataview_getInt32(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t js_dataview_setInt32(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t js_dataview_getFloat32(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t js_dataview_setFloat32(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t js_dataview_getFloat64(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t js_dataview_setFloat64(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t js_typedarray_toString(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t js_buffer_slice(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t js_buffer_toString(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t js_buffer_toBase64(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t js_buffer_write(ant_t *js, ant_value_t *args, int nargs); ArrayBufferData *create_array_buffer_data(size_t length) { ArrayBufferData *data = ant_calloc(sizeof(ArrayBufferData) + length); @@ -188,28 +188,28 @@ switch (type) { default: return "Uint8Array"; }} -static jsval_t create_typed_array_like( +static ant_value_t create_typed_array_like( ant_t *js, - jsval_t this_val, + ant_value_t this_val, TypedArrayType type, ArrayBufferData *buffer, size_t byte_offset, size_t length ) { - jsval_t ab_obj = create_arraybuffer_obj(js, buffer); - jsval_t out = create_typed_array_with_buffer( + ant_value_t ab_obj = create_arraybuffer_obj(js, buffer); + ant_value_t out = create_typed_array_with_buffer( js,type, buffer, byte_offset, length, typedarray_type_name(type), ab_obj ); if (is_err(out)) return out; - jsval_t proto = js_get_proto(js, this_val); + ant_value_t proto = js_get_proto(js, this_val); if (is_special_object(proto)) js_set_proto(js, out, proto); return out; } -static jsval_t js_arraybuffer_constructor(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_arraybuffer_constructor(ant_t *js, ant_value_t *args, int nargs) { if (vtype(js->new_target) == T_UNDEF) { return js_mkerr_typed(js, JS_ERR_TYPE, "ArrayBuffer constructor requires 'new'"); } @@ -223,8 +223,8 @@ static jsval_t js_arraybuffer_constructor(ant_t *js, jsval_t *args, int nargs) { return js_mkerr(js, "Failed to allocate ArrayBuffer"); } - jsval_t obj = js_mkobj(js); - jsval_t proto = js_get_ctor_proto(js, "ArrayBuffer", 11); + ant_value_t obj = js_mkobj(js); + ant_value_t proto = js_get_ctor_proto(js, "ArrayBuffer", 11); if (is_special_object(proto)) js_set_proto(js, obj, proto); js_set_slot(js, obj, SLOT_BUFFER, ANT_PTR(data)); @@ -234,9 +234,9 @@ static jsval_t js_arraybuffer_constructor(ant_t *js, jsval_t *args, int nargs) { } // ArrayBuffer.prototype.slice(begin, end) -static jsval_t js_arraybuffer_slice(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_val = js_getthis(js); - jsval_t data_val = js_get_slot(js, this_val, SLOT_BUFFER); +static ant_value_t js_arraybuffer_slice(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_val = js_getthis(js); + ant_value_t data_val = js_get_slot(js, this_val, SLOT_BUFFER); if (vtype(data_val) != T_NUM) { return js_mkerr(js, "Not an ArrayBuffer"); @@ -261,8 +261,8 @@ static jsval_t js_arraybuffer_slice(ant_t *js, jsval_t *args, int nargs) { memcpy(new_data->data, data->data + begin, new_length); - jsval_t new_obj = js_mkobj(js); - jsval_t proto = js_get_ctor_proto(js, "ArrayBuffer", 11); + ant_value_t new_obj = js_mkobj(js); + ant_value_t proto = js_get_ctor_proto(js, "ArrayBuffer", 11); if (is_special_object(proto)) js_set_proto(js, new_obj, proto); js_set_slot(js, new_obj, SLOT_BUFFER, ANT_PTR(new_data)); @@ -272,9 +272,9 @@ static jsval_t js_arraybuffer_slice(ant_t *js, jsval_t *args, int nargs) { } // ArrayBuffer.prototype.transfer(newLength) -static jsval_t js_arraybuffer_transfer(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_val = js_getthis(js); - jsval_t data_val = js_get_slot(js, this_val, SLOT_BUFFER); +static ant_value_t js_arraybuffer_transfer(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_val = js_getthis(js); + ant_value_t data_val = js_get_slot(js, this_val, SLOT_BUFFER); if (vtype(data_val) != T_NUM) { return js_mkerr(js, "Not an ArrayBuffer"); @@ -306,8 +306,8 @@ static jsval_t js_arraybuffer_transfer(ant_t *js, jsval_t *args, int nargs) { data->length = 0; js_set(js, this_val, "byteLength", js_mknum(0)); - jsval_t new_obj = js_mkobj(js); - jsval_t proto = js_get_ctor_proto(js, "ArrayBuffer", 11); + ant_value_t new_obj = js_mkobj(js); + ant_value_t proto = js_get_ctor_proto(js, "ArrayBuffer", 11); if (is_special_object(proto)) js_set_proto(js, new_obj, proto); js_set_slot(js, new_obj, SLOT_BUFFER, ANT_PTR(new_data)); @@ -317,14 +317,14 @@ static jsval_t js_arraybuffer_transfer(ant_t *js, jsval_t *args, int nargs) { } // ArrayBuffer.prototype.transferToFixedLength(newLength) -static jsval_t js_arraybuffer_transferToFixedLength(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_arraybuffer_transferToFixedLength(ant_t *js, ant_value_t *args, int nargs) { return js_arraybuffer_transfer(js, args, nargs); } // ArrayBuffer.prototype.detached getter -static jsval_t js_arraybuffer_detached_getter(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_val = js_getthis(js); - jsval_t data_val = js_get_slot(js, this_val, SLOT_BUFFER); +static ant_value_t js_arraybuffer_detached_getter(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_val = js_getthis(js); + ant_value_t data_val = js_get_slot(js, this_val, SLOT_BUFFER); if (vtype(data_val) != T_NUM) return js_false; ArrayBufferData *data = (ArrayBufferData *)(uintptr_t)js_getnum(data_val); @@ -333,7 +333,7 @@ static jsval_t js_arraybuffer_detached_getter(ant_t *js, jsval_t *args, int narg return js_bool(data->is_detached); } -static jsval_t typedarray_index_getter(ant_t *js, jsval_t obj, const char *key, size_t key_len) { +static ant_value_t typedarray_index_getter(ant_t *js, ant_value_t obj, const char *key, size_t key_len) { if (key_len == 0 || key_len > 10) return js_mkundef(); size_t index = 0; @@ -343,7 +343,7 @@ static jsval_t typedarray_index_getter(ant_t *js, jsval_t obj, const char *key, index = index * 10 + (c - '0'); } - jsval_t ta_val = js_get_slot(js, obj, SLOT_BUFFER); + ant_value_t ta_val = js_get_slot(js, obj, SLOT_BUFFER); TypedArrayData *ta_data = (TypedArrayData *)js_gettypedarray(ta_val); if (!ta_data || index >= ta_data->length) return js_mkundef(); if (!ta_data->buffer || ta_data->buffer->is_detached) return js_mkundef(); @@ -371,7 +371,7 @@ static jsval_t typedarray_index_getter(ant_t *js, jsval_t obj, const char *key, L_DONE: return js_mknum(value); } -static bool typedarray_index_setter(ant_t *js, jsval_t obj, const char *key, size_t key_len, jsval_t value) { +static bool typedarray_index_setter(ant_t *js, ant_value_t obj, const char *key, size_t key_len, ant_value_t value) { if (key_len == 0 || key_len > 10) return false; size_t index = 0; @@ -381,7 +381,7 @@ static bool typedarray_index_setter(ant_t *js, jsval_t obj, const char *key, siz index = index * 10 + (c - '0'); } - jsval_t ta_val = js_get_slot(js, obj, SLOT_BUFFER); + ant_value_t ta_val = js_get_slot(js, obj, SLOT_BUFFER); TypedArrayData *ta_data = (TypedArrayData *)js_gettypedarray(ta_val); if (!ta_data || index >= ta_data->length) return true; if (!ta_data->buffer || ta_data->buffer->is_detached) return true; @@ -455,9 +455,9 @@ static bool typedarray_write_number(TypedArrayData *ta_data, size_t index, doubl W_FAIL: return false; } -jsval_t create_arraybuffer_obj(ant_t *js, ArrayBufferData *buffer) { - jsval_t ab_obj = js_mkobj(js); - jsval_t ab_proto = js_get_ctor_proto(js, "ArrayBuffer", 11); +ant_value_t create_arraybuffer_obj(ant_t *js, ArrayBufferData *buffer) { + ant_value_t ab_obj = js_mkobj(js); + ant_value_t ab_proto = js_get_ctor_proto(js, "ArrayBuffer", 11); if (is_special_object(ab_proto)) js_set_proto(js, ab_obj, ab_proto); js_set_slot(js, ab_obj, SLOT_BUFFER, js_mknum((double)(uintptr_t)buffer)); @@ -467,9 +467,9 @@ jsval_t create_arraybuffer_obj(ant_t *js, ArrayBufferData *buffer) { return ab_obj; } -jsval_t create_typed_array_with_buffer( +ant_value_t create_typed_array_with_buffer( ant_t *js, TypedArrayType type, ArrayBufferData *buffer, - size_t byte_offset, size_t length, const char *type_name, jsval_t arraybuffer_obj + size_t byte_offset, size_t length, const char *type_name, ant_value_t arraybuffer_obj ) { TypedArrayData *ta_data = ta_arena_alloc(sizeof(TypedArrayData)); if (!ta_data) return js_mkerr(js, "Failed to allocate TypedArray"); @@ -482,8 +482,8 @@ jsval_t create_typed_array_with_buffer( ta_data->length = length; buffer->ref_count++; - jsval_t obj = js_mkobj(js); - jsval_t proto = js_get_ctor_proto(js, type_name, strlen(type_name)); + ant_value_t obj = js_mkobj(js); + ant_value_t proto = js_get_ctor_proto(js, type_name, strlen(type_name)); if (is_special_object(proto)) js_set_proto(js, obj, proto); js_set_slot(js, obj, SLOT_BUFFER, js_mktypedarray(ta_data)); @@ -499,27 +499,27 @@ jsval_t create_typed_array_with_buffer( return obj; } -jsval_t create_typed_array( +ant_value_t create_typed_array( ant_t *js, TypedArrayType type, ArrayBufferData *buffer, size_t byte_offset, size_t length, const char *type_name ) { - jsval_t ab_obj = create_arraybuffer_obj(js, buffer); - jsval_t result = create_typed_array_with_buffer(js, type, buffer, byte_offset, length, type_name, ab_obj); + ant_value_t ab_obj = create_arraybuffer_obj(js, buffer); + ant_value_t result = create_typed_array_with_buffer(js, type, buffer, byte_offset, length, type_name, ab_obj); free_array_buffer_data(buffer); return result; } typedef struct { - jsval_t *values; + ant_value_t *values; size_t length; size_t capacity; } iter_collect_ctx_t; -static bool iter_collect_callback(ant_t *js, jsval_t value, void *udata) { +static bool iter_collect_callback(ant_t *js, ant_value_t value, void *udata) { (void)js; iter_collect_ctx_t *ctx = (iter_collect_ctx_t *)udata; if (ctx->length >= ctx->capacity) { ctx->capacity *= 2; - jsval_t *new_values = realloc(ctx->values, ctx->capacity * sizeof(jsval_t)); + ant_value_t *new_values = realloc(ctx->values, ctx->capacity * sizeof(ant_value_t)); if (!new_values) return false; ctx->values = new_values; } @@ -527,7 +527,7 @@ static bool iter_collect_callback(ant_t *js, jsval_t value, void *udata) { return true; } -static jsval_t js_typedarray_constructor(ant_t *js, jsval_t *args, int nargs, TypedArrayType type, const char *type_name) { +static ant_value_t js_typedarray_constructor(ant_t *js, ant_value_t *args, int nargs, TypedArrayType type, const char *type_name) { if (nargs == 0) { ArrayBufferData *buffer = create_array_buffer_data(0); return create_typed_array(js, type, buffer, 0, 0, type_name); @@ -541,7 +541,7 @@ static jsval_t js_typedarray_constructor(ant_t *js, jsval_t *args, int nargs, Ty return create_typed_array(js, type, buffer, 0, length, type_name); } - jsval_t buffer_data_val = js_get_slot(js, args[0], SLOT_BUFFER); + ant_value_t buffer_data_val = js_get_slot(js, args[0], SLOT_BUFFER); if (vtype(buffer_data_val) == T_NUM) { ArrayBufferData *buffer = (ArrayBufferData *)(uintptr_t)js_getnum(buffer_data_val); size_t byte_offset = 0; @@ -569,13 +569,13 @@ static jsval_t js_typedarray_constructor(ant_t *js, jsval_t *args, int nargs, Ty } if (is_special_object(args[0])) { - jsval_t len_val = js_get(js, args[0], "length"); - size_t length = 0; jsval_t *values = NULL; + ant_value_t len_val = js_get(js, args[0], "length"); + size_t length = 0; ant_value_t *values = NULL; bool is_iterable = false; if (vtype(len_val) == T_NUM) length = (size_t)js_getnum(len_val); else { iter_collect_ctx_t ctx = { .values = NULL, .length = 0, .capacity = 16 }; - ctx.values = malloc(ctx.capacity * sizeof(jsval_t)); + ctx.values = malloc(ctx.capacity * sizeof(ant_value_t)); if (!ctx.values) return js_mkerr(js, "Failed to allocate memory"); is_iterable = js_iter(js, args[0], iter_collect_callback, &ctx); @@ -590,7 +590,7 @@ static jsval_t js_typedarray_constructor(ant_t *js, jsval_t *args, int nargs, Ty ArrayBufferData *buffer = create_array_buffer_data(length * element_size); if (!buffer) { if (values) free(values); return js_mkerr(js, "Failed to allocate buffer"); } - jsval_t result = create_typed_array(js, type, buffer, 0, length, type_name); + ant_value_t result = create_typed_array(js, type, buffer, 0, length, type_name); uint8_t *data = buffer->data; static const void *write_dispatch[] = { @@ -599,7 +599,7 @@ static jsval_t js_typedarray_constructor(ant_t *js, jsval_t *args, int nargs, Ty }; for (size_t i = 0; i < length; i++) { - jsval_t elem; + ant_value_t elem; if (values) elem = values[i]; else { char idx_str[16]; snprintf(idx_str, sizeof(idx_str), "%zu", i); @@ -631,9 +631,9 @@ static jsval_t js_typedarray_constructor(ant_t *js, jsval_t *args, int nargs, Ty // TypedArray.prototype.slice(begin, end) // TypedArray.prototype.at(index) -static jsval_t js_typedarray_at(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_val = js_getthis(js); - jsval_t ta_data_val = js_get_slot(js, this_val, SLOT_BUFFER); +static ant_value_t js_typedarray_at(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_val = js_getthis(js); + ant_value_t ta_data_val = js_get_slot(js, this_val, SLOT_BUFFER); TypedArrayData *ta_data = (TypedArrayData *)js_gettypedarray(ta_data_val); if (!ta_data) return js_mkerr(js, "Invalid TypedArray"); @@ -665,9 +665,9 @@ static jsval_t js_typedarray_at(ant_t *js, jsval_t *args, int nargs) { return js_mknum(value); } -static jsval_t js_typedarray_slice(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_val = js_getthis(js); - jsval_t ta_data_val = js_get_slot(js, this_val, SLOT_BUFFER); +static ant_value_t js_typedarray_slice(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_val = js_getthis(js); + ant_value_t ta_data_val = js_get_slot(js, this_val, SLOT_BUFFER); TypedArrayData *ta_data = (TypedArrayData *)js_gettypedarray(ta_data_val); if (!ta_data) return js_mkerr(js, "Invalid TypedArray"); @@ -693,7 +693,7 @@ static jsval_t js_typedarray_slice(ant_t *js, jsval_t *args, int nargs) { new_length * element_size ); - jsval_t out = create_typed_array_like( + ant_value_t out = create_typed_array_like( js, this_val, ta_data->type, new_buffer, 0, new_length ); free_array_buffer_data(new_buffer); @@ -702,9 +702,9 @@ static jsval_t js_typedarray_slice(ant_t *js, jsval_t *args, int nargs) { } // TypedArray.prototype.subarray(begin, end) -static jsval_t js_typedarray_subarray(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_val = js_getthis(js); - jsval_t ta_data_val = js_get_slot(js, this_val, SLOT_BUFFER); +static ant_value_t js_typedarray_subarray(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_val = js_getthis(js); + ant_value_t ta_data_val = js_get_slot(js, this_val, SLOT_BUFFER); TypedArrayData *ta_data = (TypedArrayData *)js_gettypedarray(ta_data_val); if (!ta_data) return js_mkerr(js, "Invalid TypedArray"); @@ -730,9 +730,9 @@ static jsval_t js_typedarray_subarray(ant_t *js, jsval_t *args, int nargs) { } // TypedArray.prototype.fill(value, start, end) -static jsval_t js_typedarray_fill(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_val = js_getthis(js); - jsval_t ta_data_val = js_get_slot(js, this_val, SLOT_BUFFER); +static ant_value_t js_typedarray_fill(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_val = js_getthis(js); + ant_value_t ta_data_val = js_get_slot(js, this_val, SLOT_BUFFER); TypedArrayData *ta_data = (TypedArrayData *)js_gettypedarray(ta_data_val); if (!ta_data) return js_mkerr(js, "Invalid TypedArray"); @@ -789,11 +789,11 @@ static jsval_t js_typedarray_fill(ant_t *js, jsval_t *args, int nargs) { } // TypedArray.prototype.set(source, offset = 0) -static jsval_t js_typedarray_set(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_typedarray_set(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "set requires source argument"); - jsval_t this_val = js_getthis(js); - jsval_t dst_ta_val = js_get_slot(js, this_val, SLOT_BUFFER); + ant_value_t this_val = js_getthis(js); + ant_value_t dst_ta_val = js_get_slot(js, this_val, SLOT_BUFFER); TypedArrayData *dst = (TypedArrayData *)js_gettypedarray(dst_ta_val); if (!dst) return js_mkerr(js, "Invalid TypedArray"); if (!dst->buffer || dst->buffer->is_detached) return js_mkerr(js, "Cannot operate on a detached TypedArray"); @@ -804,8 +804,8 @@ static jsval_t js_typedarray_set(ant_t *js, jsval_t *args, int nargs) { size_t offset = (size_t)offset_i; if (offset > dst->length) return js_mkerr(js, "Offset out of bounds"); - jsval_t src_val = args[0]; - jsval_t src_ta_val = js_get_slot(js, src_val, SLOT_BUFFER); + ant_value_t src_val = args[0]; + ant_value_t src_ta_val = js_get_slot(js, src_val, SLOT_BUFFER); TypedArrayData *src_ta = (TypedArrayData *)js_gettypedarray(src_ta_val); if (src_ta && src_ta->buffer && !src_ta->buffer->is_detached) { @@ -836,7 +836,7 @@ static jsval_t js_typedarray_set(ant_t *js, jsval_t *args, int nargs) { if (vtype(src_val) == T_STR) { src_len = (size_t)vstrlen(js, src_val); } else { - jsval_t len_val = js_get(js, src_val, "length"); + ant_value_t len_val = js_get(js, src_val, "length"); src_len = vtype(len_val) == T_NUM ? (size_t)js_getnum(len_val) : 0; } @@ -845,14 +845,14 @@ static jsval_t js_typedarray_set(ant_t *js, jsval_t *args, int nargs) { for (size_t i = 0; i < src_len; i++) { double value = 0; if (vtype(src_val) == T_STR) { - jsoff_t slen = 0; - jsoff_t soff = vstr(js, src_val, &slen); - if (i < (size_t)slen) value = (unsigned char)js->mem[soff + (jsoff_t)i]; + ant_offset_t slen = 0; + ant_offset_t soff = vstr(js, src_val, &slen); + if (i < (size_t)slen) value = (unsigned char)js->mem[soff + (ant_offset_t)i]; } else { char idx[24]; size_t idx_len = uint_to_str(idx, sizeof(idx), (uint64_t)i); idx[idx_len] = '\0'; - jsval_t elem = js_get(js, src_val, idx); + ant_value_t elem = js_get(js, src_val, idx); value = vtype(elem) == T_NUM ? js_getnum(elem) : 0; } (void)typedarray_write_number(dst, offset + i, value); @@ -862,9 +862,9 @@ static jsval_t js_typedarray_set(ant_t *js, jsval_t *args, int nargs) { } // TypedArray.prototype.copyWithin(target, start, end) -static jsval_t js_typedarray_copyWithin(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_val = js_getthis(js); - jsval_t ta_data_val = js_get_slot(js, this_val, SLOT_BUFFER); +static ant_value_t js_typedarray_copyWithin(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_val = js_getthis(js); + ant_value_t ta_data_val = js_get_slot(js, this_val, SLOT_BUFFER); TypedArrayData *ta = (TypedArrayData *)js_gettypedarray(ta_data_val); if (!ta) return js_mkerr(js, "Invalid TypedArray"); if (!ta->buffer || ta->buffer->is_detached) return js_mkerr(js, "Cannot operate on a detached TypedArray"); @@ -895,10 +895,10 @@ static jsval_t js_typedarray_copyWithin(ant_t *js, jsval_t *args, int nargs) { } // TypedArray.prototype.toReversed() -static jsval_t js_typedarray_toReversed(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_typedarray_toReversed(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t this_val = js_getthis(js); - jsval_t ta_data_val = js_get_slot(js, this_val, SLOT_BUFFER); + ant_value_t this_val = js_getthis(js); + ant_value_t ta_data_val = js_get_slot(js, this_val, SLOT_BUFFER); TypedArrayData *ta_data = (TypedArrayData *)js_gettypedarray(ta_data_val); if (!ta_data) return js_mkerr(js, "Invalid TypedArray"); @@ -915,7 +915,7 @@ static jsval_t js_typedarray_toReversed(ant_t *js, jsval_t *args, int nargs) { memcpy(dst + i * element_size, src + (length - 1 - i) * element_size, element_size); } - jsval_t out = create_typed_array_like( + ant_value_t out = create_typed_array_like( js, this_val, ta_data->type, new_buffer, 0, length ); free_array_buffer_data(new_buffer); @@ -924,9 +924,9 @@ static jsval_t js_typedarray_toReversed(ant_t *js, jsval_t *args, int nargs) { } // TypedArray.prototype.toSorted(comparefn) -static jsval_t js_typedarray_toSorted(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_val = js_getthis(js); - jsval_t ta_data_val = js_get_slot(js, this_val, SLOT_BUFFER); +static ant_value_t js_typedarray_toSorted(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_val = js_getthis(js); + ant_value_t ta_data_val = js_get_slot(js, this_val, SLOT_BUFFER); TypedArrayData *ta_data = (TypedArrayData *)js_gettypedarray(ta_data_val); if (!ta_data) return js_mkerr(js, "Invalid TypedArray"); @@ -937,16 +937,16 @@ static jsval_t js_typedarray_toSorted(ant_t *js, jsval_t *args, int nargs) { if (!new_buffer) return js_mkerr(js, "Failed to allocate new buffer"); memcpy(new_buffer->data, ta_data->buffer->data + ta_data->byte_offset, length * element_size); - jsval_t result = create_typed_array_like(js, this_val, ta_data->type, new_buffer, 0, length); + ant_value_t result = create_typed_array_like(js, this_val, ta_data->type, new_buffer, 0, length); free_array_buffer_data(new_buffer); if (is_err(result)) return result; - jsval_t result_ta_val = js_get_slot(js, result, SLOT_BUFFER); + ant_value_t result_ta_val = js_get_slot(js, result, SLOT_BUFFER); TypedArrayData *result_ta = (TypedArrayData *)js_gettypedarray(result_ta_val); uint8_t *data = result_ta->buffer->data; - jsval_t comparefn = (nargs > 0 && vtype(args[0]) == T_FUNC) ? args[0] : js_mkundef(); + ant_value_t comparefn = (nargs > 0 && vtype(args[0]) == T_FUNC) ? args[0] : js_mkundef(); bool has_comparefn = vtype(comparefn) == T_FUNC; for (size_t i = 1; i < length; i++) { @@ -974,8 +974,8 @@ static jsval_t js_typedarray_toSorted(ant_t *js, jsval_t *args, int nargs) { R_COMPARE: if (has_comparefn) { - jsval_t cmp_args[2] = { js_mknum(a_val), js_mknum(b_val) }; - jsval_t cmp_result = sv_vm_call(js->vm, js, comparefn, js_mkundef(), cmp_args, 2, NULL, false); + ant_value_t cmp_args[2] = { js_mknum(a_val), js_mknum(b_val) }; + ant_value_t cmp_result = sv_vm_call(js->vm, js, comparefn, js_mkundef(), cmp_args, 2, NULL, false); cmp = (int)js_getnum(cmp_result); } else { cmp = (a_val > b_val) ? 1 : ((a_val < b_val) ? -1 : 0); @@ -1008,11 +1008,11 @@ static jsval_t js_typedarray_toSorted(ant_t *js, jsval_t *args, int nargs) { } // TypedArray.prototype.with(index, value) -static jsval_t js_typedarray_with(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_typedarray_with(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "with requires index and value"); - jsval_t this_val = js_getthis(js); - jsval_t ta_data_val = js_get_slot(js, this_val, SLOT_BUFFER); + ant_value_t this_val = js_getthis(js); + ant_value_t ta_data_val = js_get_slot(js, this_val, SLOT_BUFFER); TypedArrayData *ta_data = (TypedArrayData *)js_gettypedarray(ta_data_val); if (!ta_data) return js_mkerr(js, "Invalid TypedArray"); @@ -1052,7 +1052,7 @@ static jsval_t js_typedarray_with(ant_t *js, jsval_t *args, int nargs) { W_FLOAT64: ((double*)data)[index] = value; goto W_DONE; W_DONE: - jsval_t out = create_typed_array_like( + ant_value_t out = create_typed_array_like( js, this_val, ta_data->type, new_buffer, 0, length ); free_array_buffer_data(new_buffer); @@ -1061,7 +1061,7 @@ static jsval_t js_typedarray_with(ant_t *js, jsval_t *args, int nargs) { } #define DEFINE_TYPEDARRAY_CONSTRUCTOR(name, type) \ - static jsval_t js_##name##_constructor(ant_t *js, jsval_t *args, int nargs) { \ + static ant_value_t js_##name##_constructor(ant_t *js, ant_value_t *args, int nargs) { \ if (vtype(js->new_target) == T_UNDEF) return js_mkerr_typed(js, JS_ERR_TYPE, #name " constructor requires 'new'"); \ return js_typedarray_constructor(js, args, nargs, type, #name); \ } @@ -1078,7 +1078,7 @@ DEFINE_TYPEDARRAY_CONSTRUCTOR(Float64Array, TYPED_ARRAY_FLOAT64) DEFINE_TYPEDARRAY_CONSTRUCTOR(BigInt64Array, TYPED_ARRAY_BIGINT64) DEFINE_TYPEDARRAY_CONSTRUCTOR(BigUint64Array, TYPED_ARRAY_BIGUINT64) -static jsval_t js_dataview_constructor(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_dataview_constructor(ant_t *js, ant_value_t *args, int nargs) { if (vtype(js->new_target) == T_UNDEF) { return js_mkerr_typed(js, JS_ERR_TYPE, "DataView constructor requires 'new'"); } @@ -1086,7 +1086,7 @@ static jsval_t js_dataview_constructor(ant_t *js, jsval_t *args, int nargs) { return js_mkerr(js, "DataView requires an ArrayBuffer"); } - jsval_t buffer_data_val = js_get_slot(js, args[0], SLOT_BUFFER); + ant_value_t buffer_data_val = js_get_slot(js, args[0], SLOT_BUFFER); if (vtype(buffer_data_val) != T_NUM) { return js_mkerr(js, "First argument must be an ArrayBuffer"); } @@ -1118,8 +1118,8 @@ static jsval_t js_dataview_constructor(ant_t *js, jsval_t *args, int nargs) { dv_data->byte_length = byte_length; buffer->ref_count++; - jsval_t obj = js_mkobj(js); - jsval_t proto = js_get_ctor_proto(js, "DataView", 8); + ant_value_t obj = js_mkobj(js); + ant_value_t proto = js_get_ctor_proto(js, "DataView", 8); if (is_special_object(proto)) js_set_proto(js, obj, proto); js_set_slot(js, obj, SLOT_DATA, ANT_PTR(dv_data)); @@ -1133,11 +1133,11 @@ static jsval_t js_dataview_constructor(ant_t *js, jsval_t *args, int nargs) { } // DataView.prototype.getUint8(byteOffset) -static jsval_t js_dataview_getUint8(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_dataview_getUint8(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "getUint8 requires byteOffset"); - jsval_t this_val = js_getthis(js); - jsval_t dv_data_val = js_get_slot(js, this_val, SLOT_DATA); + ant_value_t this_val = js_getthis(js); + ant_value_t dv_data_val = js_get_slot(js, this_val, SLOT_DATA); if (vtype(dv_data_val) != T_NUM) { return js_mkerr(js, "Not a DataView"); @@ -1155,11 +1155,11 @@ static jsval_t js_dataview_getUint8(ant_t *js, jsval_t *args, int nargs) { } // DataView.prototype.setUint8(byteOffset, value) -static jsval_t js_dataview_setUint8(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_dataview_setUint8(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "setUint8 requires byteOffset and value"); - jsval_t this_val = js_getthis(js); - jsval_t dv_data_val = js_get_slot(js, this_val, SLOT_DATA); + ant_value_t this_val = js_getthis(js); + ant_value_t dv_data_val = js_get_slot(js, this_val, SLOT_DATA); if (vtype(dv_data_val) != T_NUM) { return js_mkerr(js, "Not a DataView"); @@ -1178,11 +1178,11 @@ static jsval_t js_dataview_setUint8(ant_t *js, jsval_t *args, int nargs) { } // DataView.prototype.getInt16(byteOffset, littleEndian) -static jsval_t js_dataview_getInt16(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_dataview_getInt16(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "getInt16 requires byteOffset"); - jsval_t this_val = js_getthis(js); - jsval_t dv_data_val = js_get_slot(js, this_val, SLOT_DATA); + ant_value_t this_val = js_getthis(js); + ant_value_t dv_data_val = js_get_slot(js, this_val, SLOT_DATA); if (vtype(dv_data_val) != T_NUM) { return js_mkerr(js, "Not a DataView"); @@ -1209,11 +1209,11 @@ static jsval_t js_dataview_getInt16(ant_t *js, jsval_t *args, int nargs) { } // DataView.prototype.getInt32(byteOffset, littleEndian) -static jsval_t js_dataview_getInt32(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_dataview_getInt32(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "getInt32 requires byteOffset"); - jsval_t this_val = js_getthis(js); - jsval_t dv_data_val = js_get_slot(js, this_val, SLOT_DATA); + ant_value_t this_val = js_getthis(js); + ant_value_t dv_data_val = js_get_slot(js, this_val, SLOT_DATA); if (vtype(dv_data_val) != T_NUM) { return js_mkerr(js, "Not a DataView"); @@ -1240,11 +1240,11 @@ static jsval_t js_dataview_getInt32(ant_t *js, jsval_t *args, int nargs) { } // DataView.prototype.getFloat32(byteOffset, littleEndian) -static jsval_t js_dataview_getFloat32(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_dataview_getFloat32(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "getFloat32 requires byteOffset"); - jsval_t this_val = js_getthis(js); - jsval_t dv_data_val = js_get_slot(js, this_val, SLOT_DATA); + ant_value_t this_val = js_getthis(js); + ant_value_t dv_data_val = js_get_slot(js, this_val, SLOT_DATA); if (vtype(dv_data_val) != T_NUM) { return js_mkerr(js, "Not a DataView"); @@ -1273,11 +1273,11 @@ static jsval_t js_dataview_getFloat32(ant_t *js, jsval_t *args, int nargs) { } // DataView.prototype.setInt16(byteOffset, value, littleEndian) -static jsval_t js_dataview_setInt16(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_dataview_setInt16(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "setInt16 requires byteOffset and value"); - jsval_t this_val = js_getthis(js); - jsval_t dv_data_val = js_get_slot(js, this_val, SLOT_DATA); + ant_value_t this_val = js_getthis(js); + ant_value_t dv_data_val = js_get_slot(js, this_val, SLOT_DATA); if (vtype(dv_data_val) != T_NUM) { return js_mkerr(js, "Not a DataView"); @@ -1306,11 +1306,11 @@ static jsval_t js_dataview_setInt16(ant_t *js, jsval_t *args, int nargs) { } // DataView.prototype.setInt32(byteOffset, value, littleEndian) -static jsval_t js_dataview_setInt32(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_dataview_setInt32(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "setInt32 requires byteOffset and value"); - jsval_t this_val = js_getthis(js); - jsval_t dv_data_val = js_get_slot(js, this_val, SLOT_DATA); + ant_value_t this_val = js_getthis(js); + ant_value_t dv_data_val = js_get_slot(js, this_val, SLOT_DATA); if (vtype(dv_data_val) != T_NUM) { return js_mkerr(js, "Not a DataView"); @@ -1343,11 +1343,11 @@ static jsval_t js_dataview_setInt32(ant_t *js, jsval_t *args, int nargs) { } // DataView.prototype.setFloat32(byteOffset, value, littleEndian) -static jsval_t js_dataview_setFloat32(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_dataview_setFloat32(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "setFloat32 requires byteOffset and value"); - jsval_t this_val = js_getthis(js); - jsval_t dv_data_val = js_get_slot(js, this_val, SLOT_DATA); + ant_value_t this_val = js_getthis(js); + ant_value_t dv_data_val = js_get_slot(js, this_val, SLOT_DATA); if (vtype(dv_data_val) != T_NUM) { return js_mkerr(js, "Not a DataView"); @@ -1382,11 +1382,11 @@ static jsval_t js_dataview_setFloat32(ant_t *js, jsval_t *args, int nargs) { } // DataView.prototype.getFloat64(byteOffset, littleEndian) -static jsval_t js_dataview_getFloat64(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_dataview_getFloat64(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "getFloat64 requires byteOffset"); - jsval_t this_val = js_getthis(js); - jsval_t dv_data_val = js_get_slot(js, this_val, SLOT_DATA); + ant_value_t this_val = js_getthis(js); + ant_value_t dv_data_val = js_get_slot(js, this_val, SLOT_DATA); if (vtype(dv_data_val) != T_NUM) { return js_mkerr(js, "Not a DataView"); @@ -1417,11 +1417,11 @@ static jsval_t js_dataview_getFloat64(ant_t *js, jsval_t *args, int nargs) { } // DataView.prototype.setFloat64(byteOffset, value, littleEndian) -static jsval_t js_dataview_setFloat64(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_dataview_setFloat64(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "setFloat64 requires byteOffset and value"); - jsval_t this_val = js_getthis(js); - jsval_t dv_data_val = js_get_slot(js, this_val, SLOT_DATA); + ant_value_t this_val = js_getthis(js); + ant_value_t dv_data_val = js_get_slot(js, this_val, SLOT_DATA); if (vtype(dv_data_val) != T_NUM) { return js_mkerr(js, "Not a DataView"); @@ -1510,7 +1510,7 @@ static BufferEncoding parse_encoding(const char *enc, size_t len) { } // Buffer.from(array/string/buffer, encoding) -static jsval_t js_buffer_from(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_buffer_from(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "Buffer.from requires at least one argument"); if (vtype(args[0]) == T_STR) { @@ -1566,7 +1566,7 @@ static jsval_t js_buffer_from(ant_t *js, jsval_t *args, int nargs) { } } - jsval_t length_val = js_get(js, args[0], "length"); + ant_value_t length_val = js_get(js, args[0], "length"); if (vtype(length_val) == T_NUM) { size_t len = (size_t)js_getnum(length_val); ArrayBufferData *buffer = create_array_buffer_data(len); @@ -1575,7 +1575,7 @@ static jsval_t js_buffer_from(ant_t *js, jsval_t *args, int nargs) { for (size_t i = 0; i < len; i++) { char idx_str[32]; snprintf(idx_str, sizeof(idx_str), "%zu", i); - jsval_t elem = js_get(js, args[0], idx_str); + ant_value_t elem = js_get(js, args[0], idx_str); if (vtype(elem) == T_NUM) { buffer->data[i] = (uint8_t)js_getnum(elem); } @@ -1588,7 +1588,7 @@ static jsval_t js_buffer_from(ant_t *js, jsval_t *args, int nargs) { } // Buffer.alloc(size) -static jsval_t js_buffer_alloc(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_buffer_alloc(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) { return js_mkerr(js, "Buffer.alloc requires a size argument"); } @@ -1602,7 +1602,7 @@ static jsval_t js_buffer_alloc(ant_t *js, jsval_t *args, int nargs) { } // Buffer.allocUnsafe(size) -static jsval_t js_buffer_allocUnsafe(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_buffer_allocUnsafe(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) { return js_mkerr(js, "Buffer.allocUnsafe requires a size argument"); } @@ -1613,8 +1613,8 @@ static jsval_t js_buffer_allocUnsafe(ant_t *js, jsval_t *args, int nargs) { return create_typed_array(js, TYPED_ARRAY_UINT8, buffer, 0, size, "Buffer"); } -static jsval_t typedarray_join_with(ant_t *js, jsval_t this_val, const char *sep, size_t sep_len) { - jsval_t ta_data_val = js_get_slot(js, this_val, SLOT_BUFFER); +static ant_value_t typedarray_join_with(ant_t *js, ant_value_t this_val, const char *sep, size_t sep_len) { + ant_value_t ta_data_val = js_get_slot(js, this_val, SLOT_BUFFER); TypedArrayData *ta_data = (TypedArrayData *)js_gettypedarray(ta_data_val); if (!ta_data) return js_mkstr(js, "", 0); @@ -1666,18 +1666,18 @@ static jsval_t typedarray_join_with(ant_t *js, jsval_t this_val, const char *sep if (written > 0) pos += (size_t)written; } - jsval_t ret = js_mkstr(js, buf, pos); + ant_value_t ret = js_mkstr(js, buf, pos); free(buf); return ret; } // TypedArray.prototype.toString() -static jsval_t js_typedarray_toString(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_typedarray_toString(ant_t *js, ant_value_t *args, int nargs) { return typedarray_join_with(js, js_getthis(js), ",", 1); } // TypedArray.prototype.join(separator) -static jsval_t js_typedarray_join(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_typedarray_join(ant_t *js, ant_value_t *args, int nargs) { const char *sep = ","; size_t sep_len = 1; if (nargs > 0 && vtype(args[0]) == T_STR) @@ -1686,14 +1686,14 @@ static jsval_t js_typedarray_join(ant_t *js, jsval_t *args, int nargs) { } // Buffer.prototype.toString(encoding) -static jsval_t js_buffer_slice(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_buffer_slice(ant_t *js, ant_value_t *args, int nargs) { return js_typedarray_subarray(js, args, nargs); } // Buffer.prototype.toString(encoding) -static jsval_t js_buffer_toString(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_val = js_getthis(js); - jsval_t ta_data_val = js_get_slot(js, this_val, SLOT_BUFFER); +static ant_value_t js_buffer_toString(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_val = js_getthis(js); + ant_value_t ta_data_val = js_get_slot(js, this_val, SLOT_BUFFER); TypedArrayData *ta_data = (TypedArrayData *)js_gettypedarray(ta_data_val); if (!ta_data) return js_mkerr(js, "Invalid Buffer"); @@ -1714,7 +1714,7 @@ static jsval_t js_buffer_toString(ant_t *js, jsval_t *args, int nargs) { char *encoded = ant_base64_encode(data, len, &out_len); if (!encoded) return js_mkerr(js, "Failed to encode base64"); - jsval_t result = js_mkstr(js, encoded, out_len); + ant_value_t result = js_mkstr(js, encoded, out_len); free(encoded); return result; } else if (encoding == ENC_HEX) { @@ -1725,7 +1725,7 @@ static jsval_t js_buffer_toString(ant_t *js, jsval_t *args, int nargs) { snprintf(hex + i * 2, 3, "%02x", data[i]); } - jsval_t result = js_mkstr(js, hex, len * 2); + ant_value_t result = js_mkstr(js, hex, len * 2); free(hex); return result; } else if (encoding == ENC_UCS2) { @@ -1736,26 +1736,26 @@ static jsval_t js_buffer_toString(ant_t *js, jsval_t *args, int nargs) { for (size_t i = 0; i < char_count; i++) str[i] = (char)data[i * 2]; str[char_count] = '\0'; - jsval_t result = js_mkstr(js, str, char_count); + ant_value_t result = js_mkstr(js, str, char_count); free(str); return result; } else return js_mkstr(js, (char *)data, len); } // Buffer.prototype.toBase64() -static jsval_t js_buffer_toBase64(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_buffer_toBase64(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t encoding_arg = js_mkstr(js, "base64", 6); - jsval_t new_args[1] = {encoding_arg}; + ant_value_t encoding_arg = js_mkstr(js, "base64", 6); + ant_value_t new_args[1] = {encoding_arg}; return js_buffer_toString(js, new_args, 1); } // Buffer.prototype.write(string, offset, length, encoding) -static jsval_t js_buffer_write(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_buffer_write(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "write requires a string"); - jsval_t this_val = js_getthis(js); - jsval_t ta_data_val = js_get_slot(js, this_val, SLOT_BUFFER); + ant_value_t this_val = js_getthis(js); + ant_value_t ta_data_val = js_get_slot(js, this_val, SLOT_BUFFER); TypedArrayData *ta_data = (TypedArrayData *)js_gettypedarray(ta_data_val); if (!ta_data) return js_mkerr(js, "Invalid Buffer"); @@ -1786,18 +1786,18 @@ static jsval_t js_buffer_write(ant_t *js, jsval_t *args, int nargs) { } // Buffer.isBuffer(obj) -static jsval_t js_buffer_isBuffer(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_buffer_isBuffer(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_false; if (!is_special_object(args[0])) return js_false; - jsval_t proto = js_get_proto(js, args[0]); - jsval_t buffer_proto = js_get_ctor_proto(js, "Buffer", 6); + ant_value_t proto = js_get_proto(js, args[0]); + ant_value_t buffer_proto = js_get_ctor_proto(js, "Buffer", 6); return js_bool(proto == buffer_proto); } // Buffer.isEncoding(encoding) -static jsval_t js_buffer_isEncoding(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_buffer_isEncoding(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || vtype(args[0]) != T_STR) return js_false; size_t len; @@ -1821,16 +1821,16 @@ static jsval_t js_buffer_isEncoding(ant_t *js, jsval_t *args, int nargs) { } // Buffer.byteLength(string, encoding) -static jsval_t js_buffer_byteLength(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_buffer_byteLength(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mknum(0); - jsval_t arg = args[0]; + ant_value_t arg = args[0]; if (is_special_object(arg)) { - jsval_t bytelen = js_get(js, arg, "byteLength"); + ant_value_t bytelen = js_get(js, arg, "byteLength"); if (vtype(bytelen) == T_NUM) return bytelen; - jsval_t len = js_get(js, arg, "length"); + ant_value_t len = js_get(js, arg, "length"); if (vtype(len) == T_NUM) return len; } @@ -1844,13 +1844,13 @@ static jsval_t js_buffer_byteLength(ant_t *js, jsval_t *args, int nargs) { } // Buffer.concat(list, totalLength) -static jsval_t js_buffer_concat(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_buffer_concat(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || !is_special_object(args[0])) { return js_mkerr(js, "First argument must be an array"); } - jsval_t list = args[0]; - jsval_t len_val = js_get(js, list, "length"); + ant_value_t list = args[0]; + ant_value_t len_val = js_get(js, list, "length"); if (vtype(len_val) != T_NUM) { return js_mkerr(js, "First argument must be an array"); } @@ -1864,8 +1864,8 @@ static jsval_t js_buffer_concat(ant_t *js, jsval_t *args, int nargs) { for (size_t i = 0; i < list_len; i++) { char idx[16]; snprintf(idx, sizeof(idx), "%zu", i); - jsval_t buf = js_get(js, list, idx); - jsval_t buf_len = js_get(js, buf, "length"); + ant_value_t buf = js_get(js, list, idx); + ant_value_t buf_len = js_get(js, buf, "length"); if (vtype(buf_len) == T_NUM) total_length += (size_t)js_getnum(buf_len); } } @@ -1877,9 +1877,9 @@ static jsval_t js_buffer_concat(ant_t *js, jsval_t *args, int nargs) { for (size_t i = 0; i < list_len && offset < total_length; i++) { char idx[16]; snprintf(idx, sizeof(idx), "%zu", i); - jsval_t buf = js_get(js, list, idx); + ant_value_t buf = js_get(js, list, idx); - jsval_t ta_data_val = js_get_slot(js, buf, SLOT_BUFFER); + ant_value_t ta_data_val = js_get_slot(js, buf, SLOT_BUFFER); TypedArrayData *ta = js_gettypedarray(ta_data_val); if (!ta || !ta->buffer) continue; @@ -1896,11 +1896,11 @@ static jsval_t js_buffer_concat(ant_t *js, jsval_t *args, int nargs) { } // Buffer.compare(buf1, buf2) -static jsval_t js_buffer_compare(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_buffer_compare(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "Buffer.compare requires two arguments"); - jsval_t ta1_val = js_get_slot(js, args[0], SLOT_BUFFER); - jsval_t ta2_val = js_get_slot(js, args[1], SLOT_BUFFER); + ant_value_t ta1_val = js_get_slot(js, args[0], SLOT_BUFFER); + ant_value_t ta2_val = js_get_slot(js, args[1], SLOT_BUFFER); TypedArrayData *ta1 = js_gettypedarray(ta1_val); TypedArrayData *ta2 = js_gettypedarray(ta2_val); @@ -1924,7 +1924,7 @@ static jsval_t js_buffer_compare(ant_t *js, jsval_t *args, int nargs) { return js_mknum((double)cmp); } -static jsval_t js_sharedarraybuffer_constructor(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_sharedarraybuffer_constructor(ant_t *js, ant_value_t *args, int nargs) { if (vtype(js->new_target) == T_UNDEF) { return js_mkerr_typed(js, JS_ERR_TYPE, "SharedArrayBuffer constructor requires 'new'"); } @@ -1938,8 +1938,8 @@ static jsval_t js_sharedarraybuffer_constructor(ant_t *js, jsval_t *args, int na return js_mkerr(js, "Failed to allocate SharedArrayBuffer"); } - jsval_t obj = js_mkobj(js); - jsval_t proto = js_get_ctor_proto(js, "SharedArrayBuffer", 17); + ant_value_t obj = js_mkobj(js); + ant_value_t proto = js_get_ctor_proto(js, "SharedArrayBuffer", 17); if (is_special_object(proto)) js_set_proto(js, obj, proto); js_set_slot(js, obj, SLOT_BUFFER, ANT_PTR(data)); @@ -1948,18 +1948,18 @@ static jsval_t js_sharedarraybuffer_constructor(ant_t *js, jsval_t *args, int na return obj; } -jsval_t buffer_library(ant_t *js) { +ant_value_t buffer_library(ant_t *js) { return js_get(js, js_glob(js), "Buffer"); } void init_buffer_module() { ant_t *js = rt->js; - jsval_t glob = js->global; - jsval_t object_proto = js->object; + ant_value_t glob = js->global; + ant_value_t object_proto = js->object; - jsval_t arraybuffer_ctor_obj = js_mkobj(js); - jsval_t arraybuffer_proto = js_mkobj(js); + ant_value_t arraybuffer_ctor_obj = js_mkobj(js); + ant_value_t arraybuffer_proto = js_mkobj(js); js_set_proto(js, arraybuffer_proto, object_proto); js_set(js, arraybuffer_proto, "slice", js_mkfun(js_arraybuffer_slice)); @@ -1975,7 +1975,7 @@ void init_buffer_module() { js_define_species_getter(js, arraybuffer_ctor_obj); js_set(js, glob, "ArrayBuffer", js_obj_to_func(arraybuffer_ctor_obj)); - jsval_t typedarray_proto = js_mkobj(js); + ant_value_t typedarray_proto = js_mkobj(js); js_set_proto(js, typedarray_proto, object_proto); js_set(js, typedarray_proto, "at", js_mkfun(js_typedarray_at)); @@ -1991,15 +1991,15 @@ void init_buffer_module() { js_set(js, typedarray_proto, "join", js_mkfun(js_typedarray_join)); js_set_sym(js, typedarray_proto, get_toStringTag_sym(), js_mkstr(js, "TypedArray", 10)); - jsval_t array_proto = js_get(js, js_get(js, glob, "Array"), "prototype"); - jsval_t iter_fn = js_get_sym(js, array_proto, get_iterator_sym()); + ant_value_t array_proto = js_get(js, js_get(js, glob, "Array"), "prototype"); + ant_value_t iter_fn = js_get_sym(js, array_proto, get_iterator_sym()); js_set_sym(js, typedarray_proto, get_iterator_sym(), iter_fn); js_set(js, typedarray_proto, "values", iter_fn); #define SETUP_TYPEDARRAY(name) \ do { \ - jsval_t name##_ctor_obj = js_mkobj(js); \ - jsval_t name##_proto = js_mkobj(js); \ + ant_value_t name##_ctor_obj = js_mkobj(js); \ + ant_value_t name##_proto = js_mkobj(js); \ js_set_proto(js, name##_proto, typedarray_proto); \ js_set_slot(js, name##_ctor_obj, SLOT_CFUNC, js_mkfun(js_##name##_constructor)); \ js_setprop(js, name##_ctor_obj, js_mkstr(js, "prototype", 9), name##_proto); \ @@ -2021,8 +2021,8 @@ void init_buffer_module() { SETUP_TYPEDARRAY(BigInt64Array); SETUP_TYPEDARRAY(BigUint64Array); - jsval_t dataview_ctor_obj = js_mkobj(js); - jsval_t dataview_proto = js_mkobj(js); + ant_value_t dataview_ctor_obj = js_mkobj(js); + ant_value_t dataview_proto = js_mkobj(js); js_set_proto(js, dataview_proto, object_proto); js_set(js, dataview_proto, "getUint8", js_mkfun(js_dataview_getUint8)); @@ -2043,8 +2043,8 @@ void init_buffer_module() { js_set_descriptor(js, dataview_ctor_obj, "name", 4, 0); js_set(js, glob, "DataView", js_obj_to_func(dataview_ctor_obj)); - jsval_t sharedarraybuffer_ctor_obj = js_mkobj(js); - jsval_t sharedarraybuffer_proto = js_mkobj(js); + ant_value_t sharedarraybuffer_ctor_obj = js_mkobj(js); + ant_value_t sharedarraybuffer_proto = js_mkobj(js); js_set_proto(js, sharedarraybuffer_proto, object_proto); js_set(js, sharedarraybuffer_proto, "slice", js_mkfun(js_arraybuffer_slice)); @@ -2056,11 +2056,11 @@ void init_buffer_module() { js_set_descriptor(js, sharedarraybuffer_ctor_obj, "name", 4, 0); js_set(js, glob, "SharedArrayBuffer", js_obj_to_func(sharedarraybuffer_ctor_obj)); - jsval_t buffer_ctor_obj = js_mkobj(js); - jsval_t buffer_proto = js_mkobj(js); + ant_value_t buffer_ctor_obj = js_mkobj(js); + ant_value_t buffer_proto = js_mkobj(js); - jsval_t uint8array_ctor = js_get(js, glob, "Uint8Array"); - jsval_t uint8array_proto = js_get(js, uint8array_ctor, "prototype"); + ant_value_t uint8array_ctor = js_get(js, glob, "Uint8Array"); + ant_value_t uint8array_proto = js_get(js, uint8array_ctor, "prototype"); if (is_special_object(uint8array_proto)) js_set_proto(js, buffer_proto, uint8array_proto); else js_set_proto(js, buffer_proto, typedarray_proto); diff --git a/src/modules/builtin.c b/src/modules/builtin.c index 119b64d..5b7d37d 100644 --- a/src/modules/builtin.c +++ b/src/modules/builtin.c @@ -24,16 +24,16 @@ static struct { ant_t *js; - jsval_t handler; + ant_value_t handler; } signal_handlers[NSIG] = {0}; static void general_signal_handler(int signum) { if (signum < 0 || signum >= NSIG) return; ant_t *js = signal_handlers[signum].js; - jsval_t handler = signal_handlers[signum].handler; + ant_value_t handler = signal_handlers[signum].handler; if (js && vtype(handler) != T_UNDEF) { - jsval_t args[] = {js_mknum(signum)}; + ant_value_t args[] = {js_mknum(signum)}; sv_vm_call(js->vm, js, handler, js_mkundef(), args, 1, NULL, false); } @@ -41,7 +41,7 @@ static void general_signal_handler(int signum) { } // Ant.signal(signal, handler) -static jsval_t js_signal(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_signal(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "Ant.signal() requires 2 arguments"); int signum = (int)js_getnum(args[0]); @@ -56,15 +56,15 @@ static jsval_t js_signal(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -// Ant.raw.typeof(jsval_t) -static jsval_t js_raw_typeof(ant_t *js, jsval_t *args, int nargs) { +// Ant.raw.typeof(ant_value_t) +static ant_value_t js_raw_typeof(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "Ant.raw.typeof() requires 1 argument"); const uint8_t type = vtype(args[0]); return js_mknum((double)type); } // Ant.sleep(seconds) -static jsval_t js_sleep(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_sleep(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "Ant.sleep() requires 1 argument"); unsigned int seconds = (unsigned int)js_getnum(args[0]); sleep(seconds); @@ -72,7 +72,7 @@ static jsval_t js_sleep(ant_t *js, jsval_t *args, int nargs) { } // Ant.msleep(milliseconds) -static jsval_t js_msleep(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_msleep(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "Ant.msleep() requires 1 argument"); long ms = (long)js_getnum(args[0]); struct timespec ts = { .tv_sec = ms / 1000, .tv_nsec = (ms % 1000) * 1000000 }; @@ -82,7 +82,7 @@ static jsval_t js_msleep(ant_t *js, jsval_t *args, int nargs) { } // Ant.usleep(microseconds) -static jsval_t js_usleep(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_usleep(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "Ant.usleep() requires 1 argument"); useconds_t us = (useconds_t)js_getnum(args[0]); usleep(us); @@ -90,9 +90,9 @@ static jsval_t js_usleep(ant_t *js, jsval_t *args, int nargs) { } // Ant.stats() -static jsval_t js_stats_fn(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_stats_fn(ant_t *js, ant_value_t *args, int nargs) { (void) args; (void) nargs; - jsval_t result = js_newobj(js); + ant_value_t result = js_newobj(js); js_set(js, result, "arenaUsed", js_mknum((double)js_getbrk(js))); js_set(js, result, "arenaSize", js_mknum((double)js->size)); @@ -102,7 +102,7 @@ static jsval_t js_stats_fn(ant_t *js, jsval_t *args, int nargs) { size_t collections_mem = collections_get_external_memory(); size_t external_total = buffer_mem + code_mem + collections_mem; - jsval_t ext = js_newobj(js); + ant_value_t ext = js_newobj(js); js_set(js, ext, "buffers", js_mknum((double)buffer_mem)); js_set(js, ext, "code", js_mknum((double)code_mem)); js_set(js, ext, "collections", js_mknum((double)collections_mem)); @@ -110,7 +110,7 @@ static jsval_t js_stats_fn(ant_t *js, jsval_t *args, int nargs) { js_set(js, result, "external", ext); js_intern_stats_t intern_stats = js_intern_stats(); - jsval_t intern = js_newobj(js); + ant_value_t intern = js_newobj(js); js_set(js, intern, "count", js_mknum((double)intern_stats.count)); js_set(js, intern, "bytes", js_mknum((double)intern_stats.bytes)); @@ -118,7 +118,7 @@ static jsval_t js_stats_fn(ant_t *js, jsval_t *args, int nargs) { if (js->vm) { sv_vm_t *vm = js->vm; - jsval_t vmobj = js_newobj(js); + ant_value_t vmobj = js_newobj(js); js_set(js, vmobj, "stackSize", js_mknum((double)vm->stack_size)); js_set(js, vmobj, "stackUsed", js_mknum((double)vm->sp)); js_set(js, vmobj, "maxFrames", js_mknum((double)vm->max_frames)); @@ -153,7 +153,7 @@ static jsval_t js_stats_fn(ant_t *js, jsval_t *args, int nargs) { void init_builtin_module() { ant_t *js = rt->js; - jsval_t ant_obj = rt->ant_obj; + ant_value_t ant_obj = rt->ant_obj; js_set(js, ant_obj, "stats", js_mkfun(js_stats_fn)); js_set(js, ant_obj, "signal", js_mkfun(js_signal)); @@ -161,7 +161,7 @@ void init_builtin_module() { js_set(js, ant_obj, "msleep", js_mkfun(js_msleep)); js_set(js, ant_obj, "usleep", js_mkfun(js_usleep)); - jsval_t raw_obj = js_newobj(js); + ant_value_t raw_obj = js_newobj(js); js_set(js, raw_obj, "typeof", js_mkfun(js_raw_typeof)); js_set(js, ant_obj, "raw", raw_obj); } \ No newline at end of file diff --git a/src/modules/child_process.c b/src/modules/child_process.c index aa5cd10..0e10909 100644 --- a/src/modules/child_process.c +++ b/src/modules/child_process.c @@ -50,7 +50,7 @@ typedef struct { } child_stream_ctx_t; typedef struct { - jsval_t callback; + ant_value_t callback; bool once; } child_listener_t; @@ -67,14 +67,14 @@ struct child_process_s { uv_pipe_t stdin_pipe; uv_pipe_t stdout_pipe; uv_pipe_t stderr_pipe; - jsval_t child_obj; - jsval_t stdin_obj; - jsval_t stdout_obj; - jsval_t stderr_obj; + ant_value_t child_obj; + ant_value_t stdin_obj; + ant_value_t stdout_obj; + ant_value_t stderr_obj; child_stream_ctx_t *stdin_ctx; child_stream_ctx_t *stdout_ctx; child_stream_ctx_t *stderr_ctx; - jsval_t promise; + ant_value_t promise; child_event_t *events; char *stdout_buf; size_t stdout_len; @@ -101,38 +101,38 @@ struct child_process_s { static child_process_t *pending_children_head = NULL; static child_process_t *pending_children_tail = NULL; -static void fprint_js_str_raw(FILE *out, ant_t *js, jsval_t s) { +static void fprint_js_str_raw(FILE *out, ant_t *js, ant_value_t s) { if (vtype(s) != T_STR) { fprintf(out, "%s\n", js_str(js, s)); return; } - jsoff_t len = 0; - jsoff_t off = vstr(js, s, &len); + ant_offset_t len = 0; + ant_offset_t off = vstr(js, s, &len); if (off > 0 && len > 0) fwrite(&js->mem[off], 1, (size_t)len, out); if (len == 0 || js->mem[off + len - 1] != '\n') fputc('\n', out); } -static void log_listener_error(ant_t *js, const char *event_name, jsval_t err) { - jsval_t thrown_stack = js->thrown_stack; +static void log_listener_error(ant_t *js, const char *event_name, ant_value_t err) { + ant_value_t thrown_stack = js->thrown_stack; if (vtype(thrown_stack) == T_STR) { fprintf(stderr, "Error in child_process '%s' listener:\n", event_name); fprint_js_str_raw(stderr, js, thrown_stack); return; } - jsval_t thrown_value = js->thrown_value; - jsval_t src = (vtype(thrown_value) != T_UNDEF) ? thrown_value : err; + ant_value_t thrown_value = js->thrown_value; + ant_value_t src = (vtype(thrown_value) != T_UNDEF) ? thrown_value : err; - jsval_t stack = js_get(js, src, "stack"); + ant_value_t stack = js_get(js, src, "stack"); if (vtype(stack) == T_STR) { fprintf(stderr, "Error in child_process '%s' listener:\n", event_name); fprint_js_str_raw(stderr, js, stack); return; } - jsval_t name = js_get(js, src, "name"); - jsval_t message = js_get(js, src, "message"); + ant_value_t name = js_get(js, src, "name"); + ant_value_t message = js_get(js, src, "message"); const char *detail = NULL; if (vtype(name) == T_STR && vtype(message) == T_STR) { @@ -148,7 +148,7 @@ static void log_listener_error(ant_t *js, const char *event_name, jsval_t err) { js_print_stack_trace_vm(js, stderr); } -static void emit_event(child_process_t *cp, const char *name, jsval_t *args, int nargs) { +static void emit_event(child_process_t *cp, const char *name, ant_value_t *args, int nargs) { child_event_t *evt = NULL; HASH_FIND_STR(cp->events, name, evt); if (!evt || evt->count == 0) return; @@ -156,7 +156,7 @@ static void emit_event(child_process_t *cp, const char *name, jsval_t *args, int int i = 0; while (i < evt->count) { child_listener_t *l = &evt->listeners[i]; - jsval_t result = sv_vm_call(cp->js->vm, cp->js, l->callback, js_mkundef(), args, nargs, NULL, false); + ant_value_t result = sv_vm_call(cp->js->vm, cp->js, l->callback, js_mkundef(), args, nargs, NULL, false); if (vtype(result) == T_ERR) log_listener_error(cp->js, name, result); if (l->once) { for (int j = i; j < evt->count - 1; j++) @@ -179,7 +179,7 @@ static void emit_stream_event( child_process_t *cp, child_stream_kind_t kind, const char *event, - jsval_t *args, + ant_value_t *args, int nargs ) { char full_name[64]; @@ -187,7 +187,7 @@ static void emit_stream_event( emit_event(cp, full_name, args, nargs); } -static jsval_t make_uint8array_chunk(ant_t *js, const char *data, size_t len) { +static ant_value_t make_uint8array_chunk(ant_t *js, const char *data, size_t len) { ArrayBufferData *ab = create_array_buffer_data(len); if (!ab) return js_mkerr(js, "Out of memory"); if (len > 0 && data) memcpy(ab->data, data, len); @@ -255,8 +255,8 @@ static void check_completion(child_process_t *cp) { if (cp->exited && cp->stdout_closed && cp->stderr_closed && !cp->close_emitted) { cp->close_emitted = true; - jsval_t stdout_val = js_mkstr(cp->js, cp->stdout_buf ? cp->stdout_buf : "", cp->stdout_len); - jsval_t stderr_val = js_mkstr(cp->js, cp->stderr_buf ? cp->stderr_buf : "", cp->stderr_len); + ant_value_t stdout_val = js_mkstr(cp->js, cp->stdout_buf ? cp->stdout_buf : "", cp->stdout_len); + ant_value_t stderr_val = js_mkstr(cp->js, cp->stderr_buf ? cp->stderr_buf : "", cp->stderr_len); if (vtype(cp->stdout_obj) == T_OBJ) { js_set(cp->js, cp->stdout_obj, "text", stdout_val); @@ -273,11 +273,11 @@ static void check_completion(child_process_t *cp) { js_set(cp->js, cp->child_obj, "exitCode", js_mknum((double)cp->exit_code)); js_set(cp->js, cp->child_obj, "signalCode", cp->term_signal ? js_mknum((double)cp->term_signal) : js_mknull()); - jsval_t close_args[2] = { js_mknum((double)cp->exit_code), cp->term_signal ? js_mknum((double)cp->term_signal) : js_mknull() }; + ant_value_t close_args[2] = { js_mknum((double)cp->exit_code), cp->term_signal ? js_mknum((double)cp->term_signal) : js_mknull() }; emit_event(cp, "close", close_args, 2); if (vtype(cp->promise) != T_UNDEF) { - jsval_t result = js_mkobj(cp->js); + ant_value_t result = js_mkobj(cp->js); js_set(cp->js, result, "stdout", stdout_val); js_set(cp->js, result, "stderr", stderr_val); js_set(cp->js, result, "exitCode", js_mknum((double)cp->exit_code)); @@ -286,7 +286,7 @@ static void check_completion(child_process_t *cp) { if (cp->exit_code != 0) { char err_msg[256]; snprintf(err_msg, sizeof(err_msg), "Command failed with exit code %lld", (long long)cp->exit_code); - jsval_t err = js_mkstr(cp->js, err_msg, strlen(err_msg)); + ant_value_t err = js_mkstr(cp->js, err_msg, strlen(err_msg)); js_reject_promise(cp->js, cp->promise, err); } else { js_resolve_promise(cp->js, cp->promise, result); @@ -317,7 +317,7 @@ static void on_process_exit(uv_process_t *proc, int64_t exit_status, int term_si js_set(cp->js, cp->child_obj, "killed", js_true); } - jsval_t exit_args[2] = { js_mknum((double)exit_status), term_signal ? js_mknum((double)term_signal) : js_mknull() }; + ant_value_t exit_args[2] = { js_mknum((double)exit_status), term_signal ? js_mknum((double)term_signal) : js_mknull() }; emit_event(cp, "exit", exit_args, 2); cp->pending_closes++; @@ -368,12 +368,12 @@ static void on_stdout_read(uv_stream_t *stream, ssize_t nread, const uv_buf_t *b cp->stdout_len += nread; } - jsval_t text_data = js_mkstr(cp->js, buf->base, nread); - jsval_t text_args[1] = { text_data }; + ant_value_t text_data = js_mkstr(cp->js, buf->base, nread); + ant_value_t text_args[1] = { text_data }; emit_event(cp, "stdout", text_args, 1); - jsval_t byte_data = make_uint8array_chunk(cp->js, buf->base, (size_t)nread); - jsval_t byte_args[1] = { byte_data }; + ant_value_t byte_data = make_uint8array_chunk(cp->js, buf->base, (size_t)nread); + ant_value_t byte_args[1] = { byte_data }; emit_stream_event(cp, CHILD_STREAM_STDOUT, "data", byte_args, 1); if (vtype(cp->stdout_obj) == T_OBJ) js_set( @@ -386,7 +386,7 @@ static void on_stdout_read(uv_stream_t *stream, ssize_t nread, const uv_buf_t *b if (nread < 0) { if (nread != UV_EOF) { - jsval_t err_args[1] = { js_mkstr(cp->js, uv_strerror((int)nread), (int)strlen(uv_strerror((int)nread))) }; + ant_value_t err_args[1] = { js_mkstr(cp->js, uv_strerror((int)nread), (int)strlen(uv_strerror((int)nread))) }; emit_event(cp, "error", err_args, 1); emit_stream_event(cp, CHILD_STREAM_STDOUT, "error", err_args, 1); } else emit_stream_event(cp, CHILD_STREAM_STDOUT, "end", NULL, 0); @@ -420,12 +420,12 @@ static void on_stderr_read(uv_stream_t *stream, ssize_t nread, const uv_buf_t *b cp->stderr_len += nread; } - jsval_t text_data = js_mkstr(cp->js, buf->base, nread); - jsval_t text_args[1] = { text_data }; + ant_value_t text_data = js_mkstr(cp->js, buf->base, nread); + ant_value_t text_args[1] = { text_data }; emit_event(cp, "stderr", text_args, 1); - jsval_t byte_data = make_uint8array_chunk(cp->js, buf->base, (size_t)nread); - jsval_t byte_args[1] = { byte_data }; + ant_value_t byte_data = make_uint8array_chunk(cp->js, buf->base, (size_t)nread); + ant_value_t byte_args[1] = { byte_data }; emit_stream_event(cp, CHILD_STREAM_STDERR, "data", byte_args, 1); if (vtype(cp->stderr_obj) == T_OBJ) js_set( @@ -438,7 +438,7 @@ static void on_stderr_read(uv_stream_t *stream, ssize_t nread, const uv_buf_t *b if (nread < 0) { if (nread != UV_EOF) { - jsval_t err_args[1] = { + ant_value_t err_args[1] = { js_mkstr(cp->js, uv_strerror((int)nread), (int)strlen(uv_strerror((int)nread))) }; @@ -454,13 +454,13 @@ static void on_stderr_read(uv_stream_t *stream, ssize_t nread, const uv_buf_t *b } } -static jsval_t child_on(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t child_on(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 2) return js_mkerr(js, "on() requires event name and callback"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "Event name must be a string"); if (vtype(args[1]) != T_FUNC) return js_mkerr(js, "Callback must be a function"); - jsval_t cp_ptr = js_get_slot(js, this_obj, SLOT_DATA); + ant_value_t cp_ptr = js_get_slot(js, this_obj, SLOT_DATA); if (vtype(cp_ptr) == T_UNDEF) return js_mkerr(js, "Invalid child process object"); child_process_t *cp = (child_process_t *)(uintptr_t)js_getnum(cp_ptr); @@ -483,13 +483,13 @@ static jsval_t child_on(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t child_once(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t child_once(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 2) return js_mkerr(js, "once() requires event name and callback"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "Event name must be a string"); if (vtype(args[1]) != T_FUNC) return js_mkerr(js, "Callback must be a function"); - jsval_t cp_ptr = js_get_slot(js, this_obj, SLOT_DATA); + ant_value_t cp_ptr = js_get_slot(js, this_obj, SLOT_DATA); if (vtype(cp_ptr) == T_UNDEF) return js_mkerr(js, "Invalid child process object"); child_process_t *cp = (child_process_t *)(uintptr_t)js_getnum(cp_ptr); @@ -512,10 +512,10 @@ static jsval_t child_once(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t child_kill(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t child_kill(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); - jsval_t cp_ptr = js_get_slot(js, this_obj, SLOT_DATA); + ant_value_t cp_ptr = js_get_slot(js, this_obj, SLOT_DATA); if (vtype(cp_ptr) == T_UNDEF) return js_false; child_process_t *cp = (child_process_t *)(uintptr_t)js_getnum(cp_ptr); @@ -540,7 +540,7 @@ static jsval_t child_kill(ant_t *js, jsval_t *args, int nargs) { return js_bool(result == 0); } -static jsval_t child_write_impl(ant_t *js, child_process_t *cp, jsval_t data_arg) { +static ant_value_t child_write_impl(ant_t *js, child_process_t *cp, ant_value_t data_arg) { if (cp->stdin_closed) return js_false; const char *data = NULL; @@ -550,7 +550,7 @@ static jsval_t child_write_impl(ant_t *js, child_process_t *cp, jsval_t data_arg data = js_getstr(js, data_arg, &data_len); if (!data) return js_mkerr(js, "Data must be a string or Buffer"); } else { - jsval_t ta_data_val = js_get_slot(js, data_arg, SLOT_BUFFER); + ant_value_t ta_data_val = js_get_slot(js, data_arg, SLOT_BUFFER); TypedArrayData *ta_data = (TypedArrayData *)js_gettypedarray(ta_data_val); if (!ta_data || !ta_data->buffer || !ta_data->buffer->data) { return js_mkerr(js, "Data must be a string or Buffer"); @@ -568,7 +568,7 @@ static jsval_t child_write_impl(ant_t *js, child_process_t *cp, jsval_t data_arg int result = uv_write(write_req, (uv_stream_t *)&cp->stdin_pipe, &buf, 1, NULL); if (result < 0) { - jsval_t err_args[1] = { js_mkstr(js, uv_strerror(result), strlen(uv_strerror(result))) }; + ant_value_t err_args[1] = { js_mkstr(js, uv_strerror(result), strlen(uv_strerror(result))) }; emit_stream_event(cp, CHILD_STREAM_STDIN, "error", err_args, 1); free(buf_data); free(write_req); return js_false; @@ -577,7 +577,7 @@ static jsval_t child_write_impl(ant_t *js, child_process_t *cp, jsval_t data_arg return js_true; } -static jsval_t child_end_impl(child_process_t *cp) { +static ant_value_t child_end_impl(child_process_t *cp) { if (!cp->stdin_closed) { uv_close((uv_handle_t *)&cp->stdin_pipe, NULL); cp->stdin_closed = true; @@ -586,20 +586,20 @@ static jsval_t child_end_impl(child_process_t *cp) { return js_mkundef(); } -static jsval_t child_write(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t child_write(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 1) return js_mkerr(js, "write() requires data argument"); - jsval_t cp_ptr = js_get_slot(js, this_obj, SLOT_DATA); + ant_value_t cp_ptr = js_get_slot(js, this_obj, SLOT_DATA); if (vtype(cp_ptr) == T_UNDEF) return js_mkerr(js, "Invalid child process object"); child_process_t *cp = (child_process_t *)(uintptr_t)js_getnum(cp_ptr); return child_write_impl(js, cp, args[0]); } -static jsval_t child_ref(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); - jsval_t cp_ptr = js_get_slot(js, this_obj, SLOT_DATA); +static ant_value_t child_ref(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); + ant_value_t cp_ptr = js_get_slot(js, this_obj, SLOT_DATA); if (vtype(cp_ptr) == T_UNDEF) return this_obj; child_process_t *cp = (child_process_t *)(uintptr_t)js_getnum(cp_ptr); @@ -614,9 +614,9 @@ static jsval_t child_ref(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t child_unref(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); - jsval_t cp_ptr = js_get_slot(js, this_obj, SLOT_DATA); +static ant_value_t child_unref(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); + ant_value_t cp_ptr = js_get_slot(js, this_obj, SLOT_DATA); if (vtype(cp_ptr) == T_UNDEF) return this_obj; child_process_t *cp = (child_process_t *)(uintptr_t)js_getnum(cp_ptr); @@ -629,10 +629,10 @@ static jsval_t child_unref(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t child_end(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t child_end(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); - jsval_t cp_ptr = js_get_slot(js, this_obj, SLOT_DATA); + ant_value_t cp_ptr = js_get_slot(js, this_obj, SLOT_DATA); if (vtype(cp_ptr) == T_UNDEF) return js_mkundef(); child_process_t *cp = (child_process_t *)(uintptr_t)js_getnum(cp_ptr); @@ -649,30 +649,30 @@ static uv_handle_t *child_stream_handle(child_process_t *cp, child_stream_kind_t } } -static jsval_t child_stream_write(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t child_stream_write(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 1) return js_mkerr(js, "write() requires data argument"); - jsval_t ctx_ptr = js_get_slot(js, this_obj, SLOT_DATA); + ant_value_t ctx_ptr = js_get_slot(js, this_obj, SLOT_DATA); if (vtype(ctx_ptr) == T_UNDEF) return js_mkerr(js, "Invalid stream object"); child_stream_ctx_t *ctx = (child_stream_ctx_t *)(uintptr_t)js_getnum(ctx_ptr); if (!ctx || !ctx->cp) return js_mkerr(js, "Invalid stream context"); return child_write_impl(js, ctx->cp, args[0]); } -static jsval_t child_stream_end(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t child_stream_end(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t this_obj = js_getthis(js); - jsval_t ctx_ptr = js_get_slot(js, this_obj, SLOT_DATA); + ant_value_t this_obj = js_getthis(js); + ant_value_t ctx_ptr = js_get_slot(js, this_obj, SLOT_DATA); if (vtype(ctx_ptr) == T_UNDEF) return js_mkundef(); child_stream_ctx_t *ctx = (child_stream_ctx_t *)(uintptr_t)js_getnum(ctx_ptr); if (!ctx || !ctx->cp) return js_mkundef(); return child_end_impl(ctx->cp); } -static jsval_t child_stream_ref(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t child_stream_ref(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t this_obj = js_getthis(js); - jsval_t ctx_ptr = js_get_slot(js, this_obj, SLOT_DATA); + ant_value_t this_obj = js_getthis(js); + ant_value_t ctx_ptr = js_get_slot(js, this_obj, SLOT_DATA); if (vtype(ctx_ptr) == T_UNDEF) return this_obj; child_stream_ctx_t *ctx = (child_stream_ctx_t *)(uintptr_t)js_getnum(ctx_ptr); if (!ctx || !ctx->cp) return this_obj; @@ -682,10 +682,10 @@ static jsval_t child_stream_ref(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t child_stream_unref(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t child_stream_unref(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t this_obj = js_getthis(js); - jsval_t ctx_ptr = js_get_slot(js, this_obj, SLOT_DATA); + ant_value_t this_obj = js_getthis(js); + ant_value_t ctx_ptr = js_get_slot(js, this_obj, SLOT_DATA); if (vtype(ctx_ptr) == T_UNDEF) return this_obj; child_stream_ctx_t *ctx = (child_stream_ctx_t *)(uintptr_t)js_getnum(ctx_ptr); if (!ctx || !ctx->cp) return this_obj; @@ -695,10 +695,10 @@ static jsval_t child_stream_unref(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t child_stream_destroy(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t child_stream_destroy(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t this_obj = js_getthis(js); - jsval_t ctx_ptr = js_get_slot(js, this_obj, SLOT_DATA); + ant_value_t this_obj = js_getthis(js); + ant_value_t ctx_ptr = js_get_slot(js, this_obj, SLOT_DATA); if (vtype(ctx_ptr) == T_UNDEF) return this_obj; child_stream_ctx_t *ctx = (child_stream_ctx_t *)(uintptr_t)js_getnum(ctx_ptr); if (!ctx || !ctx->cp) return this_obj; @@ -726,13 +726,13 @@ static jsval_t child_stream_destroy(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t child_stream_on(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t child_stream_on(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 2) return js_mkerr(js, "on() requires event name and callback"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "Event name must be a string"); if (vtype(args[1]) != T_FUNC) return js_mkerr(js, "Callback must be a function"); - jsval_t ctx_ptr = js_get_slot(js, this_obj, SLOT_DATA); + ant_value_t ctx_ptr = js_get_slot(js, this_obj, SLOT_DATA); if (vtype(ctx_ptr) == T_UNDEF) return js_mkerr(js, "Invalid stream object"); child_stream_ctx_t *ctx = (child_stream_ctx_t *)(uintptr_t)js_getnum(ctx_ptr); @@ -763,13 +763,13 @@ static jsval_t child_stream_on(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t child_stream_once(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t child_stream_once(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 2) return js_mkerr(js, "once() requires event name and callback"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "Event name must be a string"); if (vtype(args[1]) != T_FUNC) return js_mkerr(js, "Callback must be a function"); - jsval_t ctx_ptr = js_get_slot(js, this_obj, SLOT_DATA); + ant_value_t ctx_ptr = js_get_slot(js, this_obj, SLOT_DATA); if (vtype(ctx_ptr) == T_UNDEF) return js_mkerr(js, "Invalid stream object"); child_stream_ctx_t *ctx = (child_stream_ctx_t *)(uintptr_t)js_getnum(ctx_ptr); @@ -800,8 +800,8 @@ static jsval_t child_stream_once(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t create_child_stream_object(ant_t *js, child_process_t *cp, child_stream_kind_t kind) { - jsval_t obj = js_mkobj(js); +static ant_value_t create_child_stream_object(ant_t *js, child_process_t *cp, child_stream_kind_t kind) { + ant_value_t obj = js_mkobj(js); child_stream_ctx_t *ctx = calloc(1, sizeof(child_stream_ctx_t)); if (!ctx) return js_mkerr(js, "Out of memory"); @@ -828,8 +828,8 @@ static jsval_t create_child_stream_object(ant_t *js, child_process_t *cp, child_ return obj; } -static jsval_t create_child_object(ant_t *js, child_process_t *cp) { - jsval_t obj = js_mkobj(js); +static ant_value_t create_child_object(ant_t *js, child_process_t *cp) { + ant_value_t obj = js_mkobj(js); js_set_slot(js, obj, SLOT_DATA, ANT_PTR(cp)); js_set(js, obj, "pid", js_mknum((double)cp->process.pid)); @@ -859,8 +859,8 @@ static jsval_t create_child_object(ant_t *js, child_process_t *cp) { return obj; } -static char **parse_args_array(ant_t *js, jsval_t arr, int *count) { - jsval_t len_val = js_get(js, arr, "length"); +static char **parse_args_array(ant_t *js, ant_value_t arr, int *count) { + ant_value_t len_val = js_get(js, arr, "length"); int len = (int)js_getnum(len_val); char **args = calloc(len + 1, sizeof(char *)); @@ -872,7 +872,7 @@ static char **parse_args_array(ant_t *js, jsval_t arr, int *count) { for (int i = 0; i < len; i++) { char idx[16]; snprintf(idx, sizeof(idx), "%d", i); - jsval_t val = js_get(js, arr, idx); + ant_value_t val = js_get(js, arr, idx); if (vtype(val) == T_STR) { size_t arg_len; char *arg = js_getstr(js, val, &arg_len); @@ -893,7 +893,7 @@ static void free_args_array(char **args, int count) { free(args); } -static jsval_t builtin_spawn(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_spawn(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "spawn() requires a command"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "Command must be a string"); @@ -908,24 +908,24 @@ static jsval_t builtin_spawn(ant_t *js, jsval_t *args, int nargs) { bool detached = false; if (nargs >= 2 && is_special_object(args[1])) { - jsval_t len_val = js_get(js, args[1], "length"); + ant_value_t len_val = js_get(js, args[1], "length"); if (vtype(len_val) == T_NUM) { spawn_args = parse_args_array(js, args[1], &spawn_argc); } } if (nargs >= 3 && is_special_object(args[2])) { - jsval_t cwd_val = js_get(js, args[2], "cwd"); + ant_value_t cwd_val = js_get(js, args[2], "cwd"); if (vtype(cwd_val) == T_STR) { size_t cwd_len; char *cwd_str = js_getstr(js, cwd_val, &cwd_len); cwd = strndup(cwd_str, cwd_len); } - jsval_t shell_val = js_get(js, args[2], "shell"); + ant_value_t shell_val = js_get(js, args[2], "shell"); use_shell = js_truthy(js, shell_val); - jsval_t detached_val = js_get(js, args[2], "detached"); + ant_value_t detached_val = js_get(js, args[2], "detached"); detached = js_truthy(js, detached_val); } @@ -1036,7 +1036,7 @@ static jsval_t builtin_spawn(ant_t *js, jsval_t *args, int nargs) { return cp->child_obj; } -static jsval_t builtin_exec(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_exec(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "exec() requires a command"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "Command must be a string"); @@ -1046,7 +1046,7 @@ static jsval_t builtin_exec(ant_t *js, jsval_t *args, int nargs) { char *cwd = NULL; if (nargs >= 2 && is_special_object(args[1])) { - jsval_t cwd_val = js_get(js, args[1], "cwd"); + ant_value_t cwd_val = js_get(js, args[1], "cwd"); if (vtype(cwd_val) == T_STR) { size_t cwd_len; char *cwd_s = js_getstr(js, cwd_val, &cwd_len); @@ -1102,7 +1102,7 @@ static jsval_t builtin_exec(ant_t *js, jsval_t *args, int nargs) { free(cmd_str); if (r < 0) { - jsval_t promise = cp->promise; + ant_value_t promise = cp->promise; free_child_process(cp); js_reject_promise(js, promise, js_mkstr(js, uv_strerror(r), strlen(uv_strerror(r)))); return promise; @@ -1117,7 +1117,7 @@ static jsval_t builtin_exec(ant_t *js, jsval_t *args, int nargs) { return cp->promise; } -static jsval_t builtin_execSync(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_execSync(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "execSync() requires a command"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "Command must be a string"); @@ -1176,13 +1176,13 @@ static jsval_t builtin_execSync(ant_t *js, jsval_t *args, int nargs) { free(output); return js_mkerr(js, "%s", err_msg); } - jsval_t result = js_mkstr(js, output, output_len); + ant_value_t result = js_mkstr(js, output, output_len); free(output); return result; } #ifdef _WIN32 -static jsval_t builtin_spawnSync(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_spawnSync(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "spawnSync() requires a command"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "Command must be a string"); @@ -1196,14 +1196,14 @@ static jsval_t builtin_spawnSync(ant_t *js, jsval_t *args, int nargs) { size_t input_len = 0; if (nargs >= 2 && is_special_object(args[1])) { - jsval_t len_val = js_get(js, args[1], "length"); + ant_value_t len_val = js_get(js, args[1], "length"); if (vtype(len_val) == T_NUM) { spawn_args = parse_args_array(js, args[1], &spawn_argc); } } if (nargs >= 3 && is_special_object(args[2])) { - jsval_t input_val = js_get(js, args[2], "input"); + ant_value_t input_val = js_get(js, args[2], "input"); if (vtype(input_val) == T_STR) { input = js_getstr(js, input_val, &input_len); } @@ -1314,7 +1314,7 @@ static jsval_t builtin_spawnSync(ant_t *js, jsval_t *args, int nargs) { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); - jsval_t result = js_mkobj(js); + ant_value_t result = js_mkobj(js); js_set(js, result, "stdout", js_mkstr(js, stdout_buf ? stdout_buf : "", stdout_len)); js_set(js, result, "stderr", js_mkstr(js, stderr_buf ? stderr_buf : "", stderr_len)); js_set(js, result, "status", js_mknum((double)exit_code)); @@ -1327,7 +1327,7 @@ static jsval_t builtin_spawnSync(ant_t *js, jsval_t *args, int nargs) { return result; } #else -static jsval_t builtin_spawnSync(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_spawnSync(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "spawnSync() requires a command"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "Command must be a string"); @@ -1341,14 +1341,14 @@ static jsval_t builtin_spawnSync(ant_t *js, jsval_t *args, int nargs) { size_t input_len = 0; if (nargs >= 2 && is_special_object(args[1])) { - jsval_t len_val = js_get(js, args[1], "length"); + ant_value_t len_val = js_get(js, args[1], "length"); if (vtype(len_val) == T_NUM) { spawn_args = parse_args_array(js, args[1], &spawn_argc); } } if (nargs >= 3 && is_special_object(args[2])) { - jsval_t input_val = js_get(js, args[2], "input"); + ant_value_t input_val = js_get(js, args[2], "input"); if (vtype(input_val) == T_STR) { input = js_getstr(js, input_val, &input_len); } @@ -1453,7 +1453,7 @@ static jsval_t builtin_spawnSync(ant_t *js, jsval_t *args, int nargs) { int exit_code = WIFEXITED(status) ? WEXITSTATUS(status) : -1; int signal_code = WIFSIGNALED(status) ? WTERMSIG(status) : 0; - jsval_t result = js_mkobj(js); + ant_value_t result = js_mkobj(js); js_set(js, result, "stdout", js_mkstr(js, stdout_buf ? stdout_buf : "", stdout_len)); js_set(js, result, "stderr", js_mkstr(js, stderr_buf ? stderr_buf : "", stderr_len)); js_set(js, result, "status", js_mknum((double)exit_code)); @@ -1467,7 +1467,7 @@ static jsval_t builtin_spawnSync(ant_t *js, jsval_t *args, int nargs) { } #endif -static jsval_t builtin_fork(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fork(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "fork() requires a module path"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "Module path must be a string"); size_t path_len; @@ -1493,21 +1493,21 @@ static jsval_t builtin_fork(ant_t *js, jsval_t *args, int nargs) { strncpy(exe_path, "ant", sizeof(exe_path)); #endif - jsval_t spawn_args[3]; + ant_value_t spawn_args[3]; spawn_args[0] = js_mkstr(js, exe_path, strlen(exe_path)); - jsval_t args_arr = js_mkarr(js); + ant_value_t args_arr = js_mkarr(js); js_arr_push(js, args_arr, js_mkstr(js, path_str, path_len)); if (nargs >= 2 && is_special_object(args[1])) { - jsval_t exec_args = js_get(js, args[1], "execArgv"); + ant_value_t exec_args = js_get(js, args[1], "execArgv"); if (is_special_object(exec_args)) { - jsval_t len_val = js_get(js, exec_args, "length"); + ant_value_t len_val = js_get(js, exec_args, "length"); int arr_len = (int)js_getnum(len_val); for (int i = 0; i < arr_len; i++) { char idx[16]; snprintf(idx, sizeof(idx), "%d", i); - jsval_t arg = js_get(js, exec_args, idx); + ant_value_t arg = js_get(js, exec_args, idx); js_arr_push(js, args_arr, arg); } } @@ -1521,8 +1521,8 @@ static jsval_t builtin_fork(ant_t *js, jsval_t *args, int nargs) { return builtin_spawn(js, spawn_args, 3); } -jsval_t child_process_library(ant_t *js) { - jsval_t lib = js_mkobj(js); +ant_value_t child_process_library(ant_t *js) { + ant_value_t lib = js_mkobj(js); js_set(js, lib, "spawn", js_mkfun(builtin_spawn)); js_set(js, lib, "exec", js_mkfun(builtin_exec)); diff --git a/src/modules/collections.c b/src/modules/collections.c index 27b40a7..b26abf0 100644 --- a/src/modules/collections.c +++ b/src/modules/collections.c @@ -22,7 +22,7 @@ static set_registry_entry_t *set_registry = NULL; static size_t set_registry_count = 0; static size_t set_registry_cap = 0; -static void register_map(map_entry_t **head, jsoff_t obj_offset) { +static void register_map(map_entry_t **head, ant_offset_t obj_offset) { if (!head) return; if (map_registry_count >= map_registry_cap) { size_t new_cap = map_registry_cap ? map_registry_cap * 2 : 64; @@ -36,7 +36,7 @@ static void register_map(map_entry_t **head, jsoff_t obj_offset) { map_registry_count++; } -static void register_set(set_entry_t **head, jsoff_t obj_offset) { +static void register_set(set_entry_t **head, ant_offset_t obj_offset) { if (!head) return; if (set_registry_count >= set_registry_cap) { size_t new_cap = set_registry_cap ? set_registry_cap * 2 : 64; @@ -50,58 +50,58 @@ static void register_set(set_entry_t **head, jsoff_t obj_offset) { set_registry_count++; } -static const char *jsval_to_key(ant_t *js, jsval_t val) { +static const char *ant_value_to_key(ant_t *js, ant_value_t val) { if (vtype(val) == T_STR) { - jsoff_t len; - jsoff_t off = vstr(js, val, &len); + ant_offset_t len; + ant_offset_t off = vstr(js, val, &len); return (char *)&js->mem[off]; } return js_str(js, val); } -map_entry_t **get_map_from_obj(ant_t *js, jsval_t obj) { - jsval_t map_val = js_get_slot(js, obj, SLOT_MAP); +map_entry_t **get_map_from_obj(ant_t *js, ant_value_t obj) { + ant_value_t map_val = js_get_slot(js, obj, SLOT_MAP); if (vtype(map_val) == T_UNDEF) return NULL; return (map_entry_t **)(uintptr_t)js_getnum(map_val); } -set_entry_t **get_set_from_obj(ant_t *js, jsval_t obj) { - jsval_t set_val = js_get_slot(js, obj, SLOT_SET); +set_entry_t **get_set_from_obj(ant_t *js, ant_value_t obj) { + ant_value_t set_val = js_get_slot(js, obj, SLOT_SET); if (vtype(set_val) == T_UNDEF) return NULL; return (set_entry_t **)(uintptr_t)js_getnum(set_val); } -static weakmap_entry_t **get_weakmap_from_obj(ant_t *js, jsval_t obj) { - jsval_t wm_val = js_get_slot(js, obj, SLOT_DATA); +static weakmap_entry_t **get_weakmap_from_obj(ant_t *js, ant_value_t obj) { + ant_value_t wm_val = js_get_slot(js, obj, SLOT_DATA); if (vtype(wm_val) == T_UNDEF) return NULL; return (weakmap_entry_t **)(uintptr_t)js_getnum(wm_val); } -static weakset_entry_t **get_weakset_from_obj(ant_t *js, jsval_t obj) { - jsval_t ws_val = js_get_slot(js, obj, SLOT_DATA); +static weakset_entry_t **get_weakset_from_obj(ant_t *js, ant_value_t obj) { + ant_value_t ws_val = js_get_slot(js, obj, SLOT_DATA); if (vtype(ws_val) == T_UNDEF) return NULL; return (weakset_entry_t **)(uintptr_t)js_getnum(ws_val); } -static map_iterator_state_t *get_map_iter_state(ant_t *js, jsval_t obj) { - jsval_t state_val = js_get_slot(js, obj, SLOT_ITER_STATE); +static map_iterator_state_t *get_map_iter_state(ant_t *js, ant_value_t obj) { + ant_value_t state_val = js_get_slot(js, obj, SLOT_ITER_STATE); if (vtype(state_val) == T_UNDEF) return NULL; return (map_iterator_state_t *)(uintptr_t)js_getnum(state_val); } -static set_iterator_state_t *get_set_iter_state(ant_t *js, jsval_t obj) { - jsval_t state_val = js_get_slot(js, obj, SLOT_ITER_STATE); +static set_iterator_state_t *get_set_iter_state(ant_t *js, ant_value_t obj) { + ant_value_t state_val = js_get_slot(js, obj, SLOT_ITER_STATE); if (vtype(state_val) == T_UNDEF) return NULL; return (set_iterator_state_t *)(uintptr_t)js_getnum(state_val); } -static jsval_t map_set(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t map_set(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "Map.set() requires 2 arguments"); - jsval_t this_val = js->this_val; + ant_value_t this_val = js->this_val; map_entry_t **map_ptr = get_map_from_obj(js, this_val); if (!map_ptr) return js_mkerr(js, "Invalid Map object"); - const char *key_str = jsval_to_key(js, args[0]); + const char *key_str = ant_value_to_key(js, args[0]); map_entry_t *entry; HASH_FIND_STR(*map_ptr, key_str, entry); @@ -118,42 +118,42 @@ static jsval_t map_set(ant_t *js, jsval_t *args, int nargs) { return this_val; } -static jsval_t map_get(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t map_get(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "Map.get() requires 1 argument"); - jsval_t this_val = js->this_val; + ant_value_t this_val = js->this_val; map_entry_t **map_ptr = get_map_from_obj(js, this_val); if (!map_ptr) return js_mkundef(); - const char *key_str = jsval_to_key(js, args[0]); + const char *key_str = ant_value_to_key(js, args[0]); map_entry_t *entry; HASH_FIND_STR(*map_ptr, key_str, entry); return entry ? entry->value : js_mkundef(); } -static jsval_t map_has(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t map_has(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "Map.has() requires 1 argument"); - jsval_t this_val = js->this_val; + ant_value_t this_val = js->this_val; map_entry_t **map_ptr = get_map_from_obj(js, this_val); if (!map_ptr) return js_false; - const char *key_str = jsval_to_key(js, args[0]); + const char *key_str = ant_value_to_key(js, args[0]); map_entry_t *entry; HASH_FIND_STR(*map_ptr, key_str, entry); return js_bool(entry != NULL); } -static jsval_t map_delete(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t map_delete(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "Map.delete() requires 1 argument"); - jsval_t this_val = js->this_val; + ant_value_t this_val = js->this_val; map_entry_t **map_ptr = get_map_from_obj(js, this_val); if (!map_ptr) return js_false; - const char *key_str = jsval_to_key(js, args[0]); + const char *key_str = ant_value_to_key(js, args[0]); map_entry_t *entry; HASH_FIND_STR(*map_ptr, key_str, entry); @@ -166,8 +166,8 @@ static jsval_t map_delete(ant_t *js, jsval_t *args, int nargs) { return js_false; } -static jsval_t map_clear(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_val = js->this_val; +static ant_value_t map_clear(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_val = js->this_val; map_entry_t **map_ptr = get_map_from_obj(js, this_val); if (!map_ptr) return js_mkundef(); @@ -182,29 +182,29 @@ static jsval_t map_clear(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t map_size(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_val = js->this_val; +static ant_value_t map_size(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_val = js->this_val; map_entry_t **map_ptr = get_map_from_obj(js, this_val); if (!map_ptr) return js_mknum(0); return js_mknum((double)HASH_COUNT(*map_ptr)); } -static jsval_t map_forEach(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_val = js->this_val; +static ant_value_t map_forEach(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_val = js->this_val; map_entry_t **map_ptr = get_map_from_obj(js, this_val); if (nargs < 1 || vtype(args[0]) != T_FUNC) return js_mkerr(js, "forEach requires a callback function"); - jsval_t callback = args[0]; + ant_value_t callback = args[0]; if (map_ptr && *map_ptr) { map_entry_t *entry, *tmp; HASH_ITER(hh, *map_ptr, entry, tmp) { - jsval_t k = js_mkstr(js, entry->key, strlen(entry->key)); - jsval_t call_args[3] = { entry->value, k, this_val }; - jsval_t result = sv_vm_call(js->vm, js, callback, js_mkundef(), call_args, 3, NULL, false); + ant_value_t k = js_mkstr(js, entry->key, strlen(entry->key)); + ant_value_t call_args[3] = { entry->value, k, this_val }; + ant_value_t result = sv_vm_call(js->vm, js, callback, js_mkundef(), call_args, 3, NULL, false); if (is_err(result)) return result; } } @@ -212,14 +212,14 @@ static jsval_t map_forEach(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t map_iter_next(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t map_iter_next(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t this_val = js->this_val; + ant_value_t this_val = js->this_val; map_iterator_state_t *state = get_map_iter_state(js, this_val); if (!state) return js_mkerr(js, "Invalid iterator"); - jsval_t result = js_mkobj(js); + ant_value_t result = js_mkobj(js); if (!state->current) { js_set(js, result, "done", js_true); @@ -228,7 +228,7 @@ static jsval_t map_iter_next(ant_t *js, jsval_t *args, int nargs) { } map_entry_t *entry = state->current; - jsval_t value; + ant_value_t value; switch (state->type) { case ITER_TYPE_MAP_VALUES: @@ -238,7 +238,7 @@ static jsval_t map_iter_next(ant_t *js, jsval_t *args, int nargs) { value = js_mkstr(js, entry->key, strlen(entry->key)); break; case ITER_TYPE_MAP_ENTRIES: { - jsval_t pair = js_mkarr(js); + ant_value_t pair = js_mkarr(js); js_arr_push(js, pair, js_mkstr(js, entry->key, strlen(entry->key))); js_arr_push(js, pair, entry->value); value = pair; @@ -255,7 +255,7 @@ static jsval_t map_iter_next(ant_t *js, jsval_t *args, int nargs) { return result; } -static jsval_t create_map_iterator(ant_t *js, jsval_t map_obj, iter_type_t type) { +static ant_value_t create_map_iterator(ant_t *js, ant_value_t map_obj, iter_type_t type) { map_entry_t **map_ptr = get_map_from_obj(js, map_obj); map_iterator_state_t *state = ant_calloc(sizeof(map_iterator_state_t)); @@ -265,7 +265,7 @@ static jsval_t create_map_iterator(ant_t *js, jsval_t map_obj, iter_type_t type) state->current = map_ptr ? *map_ptr : NULL; state->type = type; - jsval_t iter = js_mkobj(js); + ant_value_t iter = js_mkobj(js); js_set_slot(js, iter, SLOT_ITER_STATE, ANT_PTR(state)); js_set(js, iter, "next", js_mkfun(map_iter_next)); @@ -274,34 +274,34 @@ static jsval_t create_map_iterator(ant_t *js, jsval_t map_obj, iter_type_t type) return iter; } -static jsval_t map_values(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t map_values(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; return create_map_iterator(js, js->this_val, ITER_TYPE_MAP_VALUES); } -static jsval_t map_keys(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t map_keys(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; return create_map_iterator(js, js->this_val, ITER_TYPE_MAP_KEYS); } -static jsval_t map_entries(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t map_entries(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; return create_map_iterator(js, js->this_val, ITER_TYPE_MAP_ENTRIES); } -static jsval_t map_iterator(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t map_iterator(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; return create_map_iterator(js, js->this_val, ITER_TYPE_MAP_ENTRIES); } -static jsval_t set_iter_next(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t set_iter_next(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t this_val = js->this_val; + ant_value_t this_val = js->this_val; set_iterator_state_t *state = get_set_iter_state(js, this_val); if (!state) return js_mkerr(js, "Invalid iterator"); - jsval_t result = js_mkobj(js); + ant_value_t result = js_mkobj(js); if (!state->current) { js_set(js, result, "done", js_true); @@ -310,10 +310,10 @@ static jsval_t set_iter_next(ant_t *js, jsval_t *args, int nargs) { } set_entry_t *entry = state->current; - jsval_t value; + ant_value_t value; if (state->type == ITER_TYPE_SET_ENTRIES) { - jsval_t pair = js_mkarr(js); + ant_value_t pair = js_mkarr(js); js_arr_push(js, pair, entry->value); js_arr_push(js, pair, entry->value); value = pair; @@ -328,7 +328,7 @@ static jsval_t set_iter_next(ant_t *js, jsval_t *args, int nargs) { return result; } -static jsval_t create_set_iterator(ant_t *js, jsval_t set_obj, iter_type_t type) { +static ant_value_t create_set_iterator(ant_t *js, ant_value_t set_obj, iter_type_t type) { set_entry_t **set_ptr = get_set_from_obj(js, set_obj); set_iterator_state_t *state = ant_calloc(sizeof(set_iterator_state_t)); @@ -338,7 +338,7 @@ static jsval_t create_set_iterator(ant_t *js, jsval_t set_obj, iter_type_t type) state->current = set_ptr ? *set_ptr : NULL; state->type = type; - jsval_t iter = js_mkobj(js); + ant_value_t iter = js_mkobj(js); js_set_slot(js, iter, SLOT_ITER_STATE, ANT_PTR(state)); js_set(js, iter, "next", js_mkfun(set_iter_next)); @@ -347,14 +347,14 @@ static jsval_t create_set_iterator(ant_t *js, jsval_t set_obj, iter_type_t type) return iter; } -static jsval_t set_add(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t set_add(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "Set.add() requires 1 argument"); - jsval_t this_val = js->this_val; + ant_value_t this_val = js->this_val; set_entry_t **set_ptr = get_set_from_obj(js, this_val); if (!set_ptr) return js_mkerr(js, "Invalid Set object"); - const char *key_str = jsval_to_key(js, args[0]); + const char *key_str = ant_value_to_key(js, args[0]); set_entry_t *entry; HASH_FIND_STR(*set_ptr, key_str, entry); @@ -370,28 +370,28 @@ static jsval_t set_add(ant_t *js, jsval_t *args, int nargs) { return this_val; } -static jsval_t set_has(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t set_has(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "Set.has() requires 1 argument"); - jsval_t this_val = js->this_val; + ant_value_t this_val = js->this_val; set_entry_t **set_ptr = get_set_from_obj(js, this_val); if (!set_ptr) return js_false; - const char *key_str = jsval_to_key(js, args[0]); + const char *key_str = ant_value_to_key(js, args[0]); set_entry_t *entry; HASH_FIND_STR(*set_ptr, key_str, entry); return js_bool(entry != NULL); } -static jsval_t set_delete(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t set_delete(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "Set.delete() requires 1 argument"); - jsval_t this_val = js->this_val; + ant_value_t this_val = js->this_val; set_entry_t **set_ptr = get_set_from_obj(js, this_val); if (!set_ptr) return js_false; - const char *key_str = jsval_to_key(js, args[0]); + const char *key_str = ant_value_to_key(js, args[0]); set_entry_t *entry; HASH_FIND_STR(*set_ptr, key_str, entry); @@ -404,9 +404,9 @@ static jsval_t set_delete(ant_t *js, jsval_t *args, int nargs) { return js_false; } -static jsval_t set_clear(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t set_clear(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t this_val = js->this_val; + ant_value_t this_val = js->this_val; set_entry_t **set_ptr = get_set_from_obj(js, this_val); if (!set_ptr) return js_mkundef(); @@ -421,44 +421,44 @@ static jsval_t set_clear(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t set_size(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t set_size(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t this_val = js->this_val; + ant_value_t this_val = js->this_val; set_entry_t **set_ptr = get_set_from_obj(js, this_val); if (!set_ptr) return js_mknum(0); return js_mknum((double)HASH_COUNT(*set_ptr)); } -static jsval_t set_values(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t set_values(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; return create_set_iterator(js, js->this_val, ITER_TYPE_SET_VALUES); } -static jsval_t set_entries(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t set_entries(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; return create_set_iterator(js, js->this_val, ITER_TYPE_SET_ENTRIES); } -static jsval_t set_iterator(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t set_iterator(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; return create_set_iterator(js, js->this_val, ITER_TYPE_SET_VALUES); } -static jsval_t set_forEach(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_val = js->this_val; +static ant_value_t set_forEach(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_val = js->this_val; set_entry_t **set_ptr = get_set_from_obj(js, this_val); if (nargs < 1 || vtype(args[0]) != T_FUNC) return js_mkerr(js, "forEach requires a callback function"); - jsval_t callback = args[0]; + ant_value_t callback = args[0]; if (set_ptr && *set_ptr) { set_entry_t *entry, *tmp; HASH_ITER(hh, *set_ptr, entry, tmp) { - jsval_t call_args[3] = { entry->value, entry->value, this_val }; - jsval_t result = sv_vm_call(js->vm, js, callback, js_mkundef(), call_args, 3, NULL, false); + ant_value_t call_args[3] = { entry->value, entry->value, this_val }; + ant_value_t result = sv_vm_call(js->vm, js, callback, js_mkundef(), call_args, 3, NULL, false); if (is_err(result)) return result; } } @@ -466,20 +466,20 @@ static jsval_t set_forEach(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t weakmap_set(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t weakmap_set(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "WeakMap.set() requires 2 arguments"); - jsval_t this_val = js->this_val; + ant_value_t this_val = js->this_val; weakmap_entry_t **wm_ptr = get_weakmap_from_obj(js, this_val); if (!wm_ptr) return js_mkerr(js, "Invalid WeakMap object"); if (vtype(args[0]) != T_OBJ) return js_mkerr(js, "WeakMap key must be an object"); - jsval_t key_obj = args[0]; + ant_value_t key_obj = args[0]; weakmap_entry_t *entry; - HASH_FIND(hh, *wm_ptr, &key_obj, sizeof(jsval_t), entry); + HASH_FIND(hh, *wm_ptr, &key_obj, sizeof(ant_value_t), entry); if (entry) { entry->value = args[1]; } else { @@ -487,54 +487,54 @@ static jsval_t weakmap_set(ant_t *js, jsval_t *args, int nargs) { if (!entry) return js_mkerr(js, "out of memory"); entry->key_obj = key_obj; entry->value = args[1]; - HASH_ADD(hh, *wm_ptr, key_obj, sizeof(jsval_t), entry); + HASH_ADD(hh, *wm_ptr, key_obj, sizeof(ant_value_t), entry); } return this_val; } -static jsval_t weakmap_get(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t weakmap_get(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "WeakMap.get() requires 1 argument"); - jsval_t this_val = js->this_val; + ant_value_t this_val = js->this_val; weakmap_entry_t **wm_ptr = get_weakmap_from_obj(js, this_val); if (!wm_ptr) return js_mkundef(); if (vtype(args[0]) != T_OBJ) return js_mkundef(); - jsval_t key_obj = args[0]; + ant_value_t key_obj = args[0]; weakmap_entry_t *entry; - HASH_FIND(hh, *wm_ptr, &key_obj, sizeof(jsval_t), entry); + HASH_FIND(hh, *wm_ptr, &key_obj, sizeof(ant_value_t), entry); return entry ? entry->value : js_mkundef(); } -static jsval_t weakmap_has(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t weakmap_has(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "WeakMap.has() requires 1 argument"); - jsval_t this_val = js->this_val; + ant_value_t this_val = js->this_val; weakmap_entry_t **wm_ptr = get_weakmap_from_obj(js, this_val); if (!wm_ptr) return js_false; if (vtype(args[0]) != T_OBJ) return js_false; - jsval_t key_obj = args[0]; + ant_value_t key_obj = args[0]; weakmap_entry_t *entry; - HASH_FIND(hh, *wm_ptr, &key_obj, sizeof(jsval_t), entry); + HASH_FIND(hh, *wm_ptr, &key_obj, sizeof(ant_value_t), entry); return js_bool(entry != NULL); } -static jsval_t weakmap_delete(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t weakmap_delete(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "WeakMap.delete() requires 1 argument"); - jsval_t this_val = js->this_val; + ant_value_t this_val = js->this_val; weakmap_entry_t **wm_ptr = get_weakmap_from_obj(js, this_val); if (!wm_ptr) return js_false; if (vtype(args[0]) != T_OBJ) return js_false; - jsval_t key_obj = args[0]; + ant_value_t key_obj = args[0]; weakmap_entry_t *entry; - HASH_FIND(hh, *wm_ptr, &key_obj, sizeof(jsval_t), entry); + HASH_FIND(hh, *wm_ptr, &key_obj, sizeof(ant_value_t), entry); if (entry) { HASH_DEL(*wm_ptr, entry); free(entry); @@ -543,58 +543,58 @@ static jsval_t weakmap_delete(ant_t *js, jsval_t *args, int nargs) { return js_false; } -static jsval_t weakset_add(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t weakset_add(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "WeakSet.add() requires 1 argument"); - jsval_t this_val = js->this_val; + ant_value_t this_val = js->this_val; weakset_entry_t **ws_ptr = get_weakset_from_obj(js, this_val); if (!ws_ptr) return js_mkerr(js, "Invalid WeakSet object"); if (vtype(args[0]) != T_OBJ) return js_mkerr(js, "WeakSet value must be an object"); - jsval_t value_obj = args[0]; + ant_value_t value_obj = args[0]; weakset_entry_t *entry; - HASH_FIND(hh, *ws_ptr, &value_obj, sizeof(jsval_t), entry); + HASH_FIND(hh, *ws_ptr, &value_obj, sizeof(ant_value_t), entry); if (!entry) { entry = ant_calloc(sizeof(weakset_entry_t)); if (!entry) return js_mkerr(js, "out of memory"); entry->value_obj = value_obj; - HASH_ADD(hh, *ws_ptr, value_obj, sizeof(jsval_t), entry); + HASH_ADD(hh, *ws_ptr, value_obj, sizeof(ant_value_t), entry); } return this_val; } -static jsval_t weakset_has(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t weakset_has(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "WeakSet.has() requires 1 argument"); - jsval_t this_val = js->this_val; + ant_value_t this_val = js->this_val; weakset_entry_t **ws_ptr = get_weakset_from_obj(js, this_val); if (!ws_ptr) return js_false; if (vtype(args[0]) != T_OBJ) return js_false; - jsval_t value_obj = args[0]; + ant_value_t value_obj = args[0]; weakset_entry_t *entry; - HASH_FIND(hh, *ws_ptr, &value_obj, sizeof(jsval_t), entry); + HASH_FIND(hh, *ws_ptr, &value_obj, sizeof(ant_value_t), entry); return js_bool(entry != NULL); } -static jsval_t weakset_delete(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t weakset_delete(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "WeakSet.delete() requires 1 argument"); - jsval_t this_val = js->this_val; + ant_value_t this_val = js->this_val; weakset_entry_t **ws_ptr = get_weakset_from_obj(js, this_val); if (!ws_ptr) return js_false; if (vtype(args[0]) != T_OBJ) return js_false; - jsval_t value_obj = args[0]; + ant_value_t value_obj = args[0]; weakset_entry_t *entry; - HASH_FIND(hh, *ws_ptr, &value_obj, sizeof(jsval_t), entry); + HASH_FIND(hh, *ws_ptr, &value_obj, sizeof(ant_value_t), entry); if (entry) { HASH_DEL(*ws_ptr, entry); @@ -604,37 +604,37 @@ static jsval_t weakset_delete(ant_t *js, jsval_t *args, int nargs) { return js_false; } -static jsval_t builtin_WeakRef(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_WeakRef(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || vtype(args[0]) != T_OBJ) { return js_mkerr(js, "WeakRef target must be an object"); } - jsval_t wr_obj = js_mkobj(js); - jsval_t wr_proto = js_get_ctor_proto(js, "WeakRef", 7); + ant_value_t wr_obj = js_mkobj(js); + ant_value_t wr_proto = js_get_ctor_proto(js, "WeakRef", 7); if (is_special_object(wr_proto)) js_set_proto(js, wr_obj, wr_proto); js_set_slot(js, wr_obj, SLOT_DATA, args[0]); return wr_obj; } -static jsval_t weakref_deref(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t weakref_deref(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t this_val = js->this_val; + ant_value_t this_val = js->this_val; if (vtype(this_val) != T_OBJ) return js_mkundef(); - jsval_t target = js_get_slot(js, this_val, SLOT_DATA); + ant_value_t target = js_get_slot(js, this_val, SLOT_DATA); if (vtype(target) != T_OBJ) return js_mkundef(); return target; } -static jsval_t builtin_FinalizationRegistry(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_FinalizationRegistry(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || (vtype(args[0]) != T_FUNC && vtype(args[0]) != T_CFUNC)) { return js_mkerr(js, "FinalizationRegistry callback must be a function"); } - jsval_t fr_obj = js_mkobj(js); - jsval_t fr_proto = js_get_ctor_proto(js, "FinalizationRegistry", 20); + ant_value_t fr_obj = js_mkobj(js); + ant_value_t fr_proto = js_get_ctor_proto(js, "FinalizationRegistry", 20); if (is_special_object(fr_proto)) js_set_proto(js, fr_obj, fr_proto); js_set_slot(js, fr_obj, SLOT_MAP, mkarr(js)); @@ -643,27 +643,27 @@ static jsval_t builtin_FinalizationRegistry(ant_t *js, jsval_t *args, int nargs) return fr_obj; } -static jsval_t finreg_register(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_val = js->this_val; +static ant_value_t finreg_register(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_val = js->this_val; if (vtype(this_val) != T_OBJ) return js_mkundef(); if (nargs < 1 || vtype(args[0]) != T_OBJ) { return js_mkerr(js, "FinalizationRegistry.register target must be an object"); } - jsval_t target = args[0]; - jsval_t held_value = nargs > 1 ? args[1] : js_mkundef(); - jsval_t unregister_token = nargs > 2 ? args[2] : js_mkundef(); + ant_value_t target = args[0]; + ant_value_t held_value = nargs > 1 ? args[1] : js_mkundef(); + ant_value_t unregister_token = nargs > 2 ? args[2] : js_mkundef(); if (vdata(target) == vdata(held_value) && vtype(held_value) == T_OBJ) { return js_mkerr(js, "target and held value must not be the same"); } - jsval_t registrations = js_get_slot(js, this_val, SLOT_MAP); + ant_value_t registrations = js_get_slot(js, this_val, SLOT_MAP); if (vtype(registrations) != T_ARR) return js_mkundef(); - jsval_t entry = mkarr(js); - jsoff_t len = js_arr_len(js, registrations); + ant_value_t entry = mkarr(js); + ant_offset_t len = js_arr_len(js, registrations); char idx[16]; size_t idx_len = uint_to_str(idx, sizeof(idx), 0); @@ -681,25 +681,25 @@ static jsval_t finreg_register(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t finreg_unregister(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_val = js->this_val; +static ant_value_t finreg_unregister(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_val = js->this_val; if (vtype(this_val) != T_OBJ) return js_false; if (nargs < 1 || vtype(args[0]) != T_OBJ) { return js_mkerr(js, "FinalizationRegistry.unregister token must be an object"); } - jsval_t token = args[0]; - jsval_t registrations = js_get_slot(js, this_val, SLOT_MAP); + ant_value_t token = args[0]; + ant_value_t registrations = js_get_slot(js, this_val, SLOT_MAP); if (vtype(registrations) != T_ARR) return js_false; - jsoff_t len = js_arr_len(js, registrations); + ant_offset_t len = js_arr_len(js, registrations); bool removed = false; - for (jsoff_t i = 0; i < len; i++) { - jsval_t entry = js_arr_get(js, registrations, i); + for (ant_offset_t i = 0; i < len; i++) { + ant_value_t entry = js_arr_get(js, registrations, i); if (vtype(entry) != T_ARR) continue; - jsval_t entry_token = js_arr_get(js, entry, 2); + ant_value_t entry_token = js_arr_get(js, entry, 2); if (vtype(entry_token) == T_OBJ && vdata(entry_token) == vdata(token)) { char idx[16]; size_t idx_len = uint_to_str(idx, sizeof(idx), i); @@ -711,19 +711,19 @@ static jsval_t finreg_unregister(ant_t *js, jsval_t *args, int nargs) { return js_bool(removed); } -static jsval_t map_groupBy(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t map_groupBy(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr_typed(js, JS_ERR_TYPE, "Map.groupBy requires 2 arguments"); - jsval_t items = args[0]; - jsval_t callback = args[1]; + ant_value_t items = args[0]; + ant_value_t callback = args[1]; if (vtype(callback) != T_FUNC && vtype(callback) != T_CFUNC) return js_mkerr_typed(js, JS_ERR_TYPE, "callback is not a function"); - jsval_t map_obj = js_mkobj(js); - jsoff_t obj_offset = (jsoff_t)vdata(map_obj); + ant_value_t map_obj = js_mkobj(js); + ant_offset_t obj_offset = (ant_offset_t)vdata(map_obj); - jsval_t map_proto = js_get_ctor_proto(js, "Map", 3); + ant_value_t map_proto = js_get_ctor_proto(js, "Map", 3); if (is_special_object(map_proto)) js_set_proto(js, map_obj, map_proto); map_entry_t **map_head = ant_calloc(sizeof(map_entry_t *)); @@ -732,18 +732,18 @@ static jsval_t map_groupBy(ant_t *js, jsval_t *args, int nargs) { register_map(map_head, obj_offset); js_set_slot(js, map_obj, SLOT_MAP, ANT_PTR(map_head)); - jsoff_t len = js_arr_len(js, items); - for (jsoff_t i = 0; i < len; i++) { - jsval_t val = js_arr_get(js, items, i); - jsval_t cb_args[2] = { val, tov((double)i) }; - jsval_t key = sv_vm_call(js->vm, js, callback, js_mkundef(), cb_args, 2, NULL, false); + ant_offset_t len = js_arr_len(js, items); + for (ant_offset_t i = 0; i < len; i++) { + ant_value_t val = js_arr_get(js, items, i); + ant_value_t cb_args[2] = { val, tov((double)i) }; + ant_value_t key = sv_vm_call(js->vm, js, callback, js_mkundef(), cb_args, 2, NULL, false); if (is_err(key)) return key; - const char *key_str = jsval_to_key(js, key); + const char *key_str = ant_value_to_key(js, key); map_entry_t *entry; HASH_FIND_STR(*map_head, key_str, entry); - jsval_t group; + ant_value_t group; if (entry) { group = entry->value; } else { @@ -760,18 +760,18 @@ static jsval_t map_groupBy(ant_t *js, jsval_t *args, int nargs) { return map_obj; } -static jsval_t builtin_Map(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Map(ant_t *js, ant_value_t *args, int nargs) { if (vtype(js->new_target) == T_UNDEF) { return js_mkerr_typed(js, JS_ERR_TYPE, "Map constructor requires 'new'"); } - jsval_t map_obj = js->this_val; + ant_value_t map_obj = js->this_val; if (vtype(map_obj) != T_OBJ) map_obj = js_mkobj(js); if (is_err(map_obj)) return map_obj; - jsoff_t obj_offset = (jsoff_t)vdata(map_obj); + ant_offset_t obj_offset = (ant_offset_t)vdata(map_obj); - jsval_t map_proto = js_get_ctor_proto(js, "Map", 3); - jsval_t instance_proto = js_instance_proto_from_new_target(js, map_proto); + ant_value_t map_proto = js_get_ctor_proto(js, "Map", 3); + ant_value_t instance_proto = js_instance_proto_from_new_target(js, map_proto); if (is_special_object(instance_proto)) js_set_proto(js, map_obj, instance_proto); @@ -787,19 +787,19 @@ static jsval_t builtin_Map(ant_t *js, jsval_t *args, int nargs) { if (nargs == 0 || vtype(args[0]) != T_ARR) return map_obj; - jsval_t iterable = args[0]; - jsoff_t length = js_arr_len(js, iterable); + ant_value_t iterable = args[0]; + ant_offset_t length = js_arr_len(js, iterable); - for (jsoff_t i = 0; i < length; i++) { - jsval_t entry = js_arr_get(js, iterable, i); + for (ant_offset_t i = 0; i < length; i++) { + ant_value_t entry = js_arr_get(js, iterable, i); if (vtype(entry) != T_ARR) continue; - jsoff_t entry_len = js_arr_len(js, entry); + ant_offset_t entry_len = js_arr_len(js, entry); if (entry_len < 2) continue; - jsval_t key = js_arr_get(js, entry, 0); - jsval_t value = js_arr_get(js, entry, 1); - const char *key_str = jsval_to_key(js, key); + ant_value_t key = js_arr_get(js, entry, 0); + ant_value_t value = js_arr_get(js, entry, 1); + const char *key_str = ant_value_to_key(js, key); map_entry_t *map_entry; HASH_FIND_STR(*map_head, key_str, map_entry); @@ -818,18 +818,18 @@ static jsval_t builtin_Map(ant_t *js, jsval_t *args, int nargs) { return map_obj; } -static jsval_t builtin_Set(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Set(ant_t *js, ant_value_t *args, int nargs) { if (vtype(js->new_target) == T_UNDEF) { return js_mkerr_typed(js, JS_ERR_TYPE, "Set constructor requires 'new'"); } - jsval_t set_obj = js->this_val; + ant_value_t set_obj = js->this_val; if (vtype(set_obj) != T_OBJ) set_obj = js_mkobj(js); if (is_err(set_obj)) return set_obj; - jsoff_t obj_offset = (jsoff_t)vdata(set_obj); + ant_offset_t obj_offset = (ant_offset_t)vdata(set_obj); - jsval_t set_proto = js_get_ctor_proto(js, "Set", 3); - jsval_t instance_proto = js_instance_proto_from_new_target(js, set_proto); + ant_value_t set_proto = js_get_ctor_proto(js, "Set", 3); + ant_value_t instance_proto = js_instance_proto_from_new_target(js, set_proto); if (is_special_object(instance_proto)) js_set_proto(js, set_obj, instance_proto); @@ -845,12 +845,12 @@ static jsval_t builtin_Set(ant_t *js, jsval_t *args, int nargs) { if (nargs == 0 || vtype(args[0]) != T_ARR) return set_obj; - jsval_t iterable = args[0]; - jsoff_t length = js_arr_len(js, iterable); + ant_value_t iterable = args[0]; + ant_offset_t length = js_arr_len(js, iterable); - for (jsoff_t i = 0; i < length; i++) { - jsval_t value = js_arr_get(js, iterable, i); - const char *key_str = jsval_to_key(js, value); + for (ant_offset_t i = 0; i < length; i++) { + ant_value_t value = js_arr_get(js, iterable, i); + const char *key_str = ant_value_to_key(js, value); set_entry_t *entry; HASH_FIND_STR(*set_head, key_str, entry); @@ -866,17 +866,17 @@ static jsval_t builtin_Set(ant_t *js, jsval_t *args, int nargs) { return set_obj; } -static jsval_t builtin_WeakMap(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_WeakMap(ant_t *js, ant_value_t *args, int nargs) { if (vtype(js->new_target) == T_UNDEF) { return js_mkerr_typed(js, JS_ERR_TYPE, "WeakMap constructor requires 'new'"); } - jsval_t wm_obj = js->this_val; + ant_value_t wm_obj = js->this_val; if (vtype(wm_obj) != T_OBJ) wm_obj = js_mkobj(js); if (is_err(wm_obj)) return wm_obj; - jsval_t wm_proto = js_get_ctor_proto(js, "WeakMap", 7); - jsval_t instance_proto = js_instance_proto_from_new_target(js, wm_proto); + ant_value_t wm_proto = js_get_ctor_proto(js, "WeakMap", 7); + ant_value_t instance_proto = js_instance_proto_from_new_target(js, wm_proto); if (is_special_object(instance_proto)) js_set_proto(js, wm_obj, instance_proto); @@ -891,23 +891,23 @@ static jsval_t builtin_WeakMap(ant_t *js, jsval_t *args, int nargs) { if (nargs == 0 || vtype(args[0]) != T_ARR) return wm_obj; - jsval_t iterable = args[0]; - jsoff_t length = js_arr_len(js, iterable); + ant_value_t iterable = args[0]; + ant_offset_t length = js_arr_len(js, iterable); - for (jsoff_t i = 0; i < length; i++) { - jsval_t entry = js_arr_get(js, iterable, i); + for (ant_offset_t i = 0; i < length; i++) { + ant_value_t entry = js_arr_get(js, iterable, i); if (vtype(entry) != T_ARR) continue; - jsoff_t entry_len = js_arr_len(js, entry); + ant_offset_t entry_len = js_arr_len(js, entry); if (entry_len < 2) continue; - jsval_t key = js_arr_get(js, entry, 0); - jsval_t value = js_arr_get(js, entry, 1); + ant_value_t key = js_arr_get(js, entry, 0); + ant_value_t value = js_arr_get(js, entry, 1); if (vtype(key) != T_OBJ) return js_mkerr(js, "WeakMap key must be an object"); weakmap_entry_t *wm_entry; - HASH_FIND(hh, *wm_head, &key, sizeof(jsval_t), wm_entry); + HASH_FIND(hh, *wm_head, &key, sizeof(ant_value_t), wm_entry); if (wm_entry) { wm_entry->value = value; continue; @@ -917,23 +917,23 @@ static jsval_t builtin_WeakMap(ant_t *js, jsval_t *args, int nargs) { if (!wm_entry) return js_mkerr(js, "out of memory"); wm_entry->key_obj = key; wm_entry->value = value; - HASH_ADD(hh, *wm_head, key_obj, sizeof(jsval_t), wm_entry); + HASH_ADD(hh, *wm_head, key_obj, sizeof(ant_value_t), wm_entry); } return wm_obj; } -static jsval_t builtin_WeakSet(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_WeakSet(ant_t *js, ant_value_t *args, int nargs) { if (vtype(js->new_target) == T_UNDEF) { return js_mkerr_typed(js, JS_ERR_TYPE, "WeakSet constructor requires 'new'"); } - jsval_t ws_obj = js->this_val; + ant_value_t ws_obj = js->this_val; if (vtype(ws_obj) != T_OBJ) ws_obj = js_mkobj(js); if (is_err(ws_obj)) return ws_obj; - jsval_t ws_proto = js_get_ctor_proto(js, "WeakSet", 7); - jsval_t instance_proto = js_instance_proto_from_new_target(js, ws_proto); + ant_value_t ws_proto = js_get_ctor_proto(js, "WeakSet", 7); + ant_value_t instance_proto = js_instance_proto_from_new_target(js, ws_proto); if (is_special_object(instance_proto)) js_set_proto(js, ws_obj, instance_proto); @@ -948,22 +948,22 @@ static jsval_t builtin_WeakSet(ant_t *js, jsval_t *args, int nargs) { if (nargs == 0 || vtype(args[0]) != T_ARR) return ws_obj; - jsval_t iterable = args[0]; - jsoff_t length = js_arr_len(js, iterable); + ant_value_t iterable = args[0]; + ant_offset_t length = js_arr_len(js, iterable); - for (jsoff_t i = 0; i < length; i++) { - jsval_t value = js_arr_get(js, iterable, i); + for (ant_offset_t i = 0; i < length; i++) { + ant_value_t value = js_arr_get(js, iterable, i); if (vtype(value) != T_OBJ) return js_mkerr(js, "WeakSet value must be an object"); weakset_entry_t *entry; - HASH_FIND(hh, *ws_head, &value, sizeof(jsval_t), entry); + HASH_FIND(hh, *ws_head, &value, sizeof(ant_value_t), entry); if (entry) continue; entry = ant_calloc(sizeof(weakset_entry_t)); if (!entry) return js_mkerr(js, "out of memory"); entry->value_obj = value; - HASH_ADD(hh, *ws_head, value_obj, sizeof(jsval_t), entry); + HASH_ADD(hh, *ws_head, value_obj, sizeof(ant_value_t), entry); } return ws_obj; @@ -972,13 +972,13 @@ static jsval_t builtin_WeakSet(ant_t *js, jsval_t *args, int nargs) { void init_collections_module(void) { ant_t *js = rt->js; - jsval_t glob = js->global; - jsval_t object_proto = js->object; + ant_value_t glob = js->global; + ant_value_t object_proto = js->object; - jsval_t iter_sym = get_iterator_sym(); - jsval_t tag_sym = get_toStringTag_sym(); + ant_value_t iter_sym = get_iterator_sym(); + ant_value_t tag_sym = get_toStringTag_sym(); - jsval_t map_proto = js_mkobj(js); + ant_value_t map_proto = js_mkobj(js); js_set_proto(js, map_proto, object_proto); js_set(js, map_proto, "set", js_mkfun(map_set)); js_set(js, map_proto, "get", js_mkfun(map_get)); @@ -993,7 +993,7 @@ void init_collections_module(void) { js_set_sym(js, map_proto, iter_sym, js_mkfun(map_iterator)); js_set_sym(js, map_proto, tag_sym, js_mkstr(js, "Map", 3)); - jsval_t map_ctor = js_mkobj(js); + ant_value_t map_ctor = js_mkobj(js); js_set_slot(js, map_ctor, SLOT_CFUNC, js_mkfun(builtin_Map)); js_mkprop_fast(js, map_ctor, "prototype", 9, map_proto); js_mkprop_fast(js, map_ctor, "name", 4, ANT_STRING("Map")); @@ -1002,7 +1002,7 @@ void init_collections_module(void) { js_define_species_getter(js, map_ctor); js_set(js, glob, "Map", js_obj_to_func(map_ctor)); - jsval_t set_proto = js_mkobj(js); + ant_value_t set_proto = js_mkobj(js); js_set_proto(js, set_proto, object_proto); js_set(js, set_proto, "add", js_mkfun(set_add)); js_set(js, set_proto, "has", js_mkfun(set_has)); @@ -1016,7 +1016,7 @@ void init_collections_module(void) { js_set_sym(js, set_proto, iter_sym, js_mkfun(set_iterator)); js_set_sym(js, set_proto, tag_sym, js_mkstr(js, "Set", 3)); - jsval_t set_ctor = js_mkobj(js); + ant_value_t set_ctor = js_mkobj(js); js_set_slot(js, set_ctor, SLOT_CFUNC, js_mkfun(builtin_Set)); js_mkprop_fast(js, set_ctor, "prototype", 9, set_proto); js_mkprop_fast(js, set_ctor, "name", 4, ANT_STRING("Set")); @@ -1024,7 +1024,7 @@ void init_collections_module(void) { js_define_species_getter(js, set_ctor); js_set(js, glob, "Set", js_obj_to_func(set_ctor)); - jsval_t weakmap_proto = js_mkobj(js); + ant_value_t weakmap_proto = js_mkobj(js); js_set_proto(js, weakmap_proto, object_proto); js_set(js, weakmap_proto, "set", js_mkfun(weakmap_set)); js_set(js, weakmap_proto, "get", js_mkfun(weakmap_get)); @@ -1032,46 +1032,46 @@ void init_collections_module(void) { js_set(js, weakmap_proto, "delete", js_mkfun(weakmap_delete)); js_set_sym(js, weakmap_proto, tag_sym, js_mkstr(js, "WeakMap", 7)); - jsval_t weakmap_ctor = js_mkobj(js); + ant_value_t weakmap_ctor = js_mkobj(js); js_set_slot(js, weakmap_ctor, SLOT_CFUNC, js_mkfun(builtin_WeakMap)); js_mkprop_fast(js, weakmap_ctor, "prototype", 9, weakmap_proto); js_mkprop_fast(js, weakmap_ctor, "name", 4, ANT_STRING("WeakMap")); js_set_descriptor(js, weakmap_ctor, "name", 4, 0); js_set(js, glob, "WeakMap", js_obj_to_func(weakmap_ctor)); - jsval_t weakset_proto = js_mkobj(js); + ant_value_t weakset_proto = js_mkobj(js); js_set_proto(js, weakset_proto, object_proto); js_set(js, weakset_proto, "add", js_mkfun(weakset_add)); js_set(js, weakset_proto, "has", js_mkfun(weakset_has)); js_set(js, weakset_proto, "delete", js_mkfun(weakset_delete)); js_set_sym(js, weakset_proto, tag_sym, js_mkstr(js, "WeakSet", 7)); - jsval_t weakset_ctor = js_mkobj(js); + ant_value_t weakset_ctor = js_mkobj(js); js_set_slot(js, weakset_ctor, SLOT_CFUNC, js_mkfun(builtin_WeakSet)); js_mkprop_fast(js, weakset_ctor, "prototype", 9, weakset_proto); js_mkprop_fast(js, weakset_ctor, "name", 4, ANT_STRING("WeakSet")); js_set_descriptor(js, weakset_ctor, "name", 4, 0); js_set(js, glob, "WeakSet", js_obj_to_func(weakset_ctor)); - jsval_t weakref_proto = js_mkobj(js); + ant_value_t weakref_proto = js_mkobj(js); js_set_proto(js, weakref_proto, object_proto); js_set(js, weakref_proto, "deref", js_mkfun(weakref_deref)); js_set_sym(js, weakref_proto, tag_sym, js_mkstr(js, "WeakRef", 7)); - jsval_t weakref_ctor = js_mkobj(js); + ant_value_t weakref_ctor = js_mkobj(js); js_set_slot(js, weakref_ctor, SLOT_CFUNC, js_mkfun(builtin_WeakRef)); js_mkprop_fast(js, weakref_ctor, "prototype", 9, weakref_proto); js_mkprop_fast(js, weakref_ctor, "name", 4, ANT_STRING("WeakRef")); js_set_descriptor(js, weakref_ctor, "name", 4, 0); js_set(js, glob, "WeakRef", js_obj_to_func(weakref_ctor)); - jsval_t finreg_proto = js_mkobj(js); + ant_value_t finreg_proto = js_mkobj(js); js_set_proto(js, finreg_proto, object_proto); js_set(js, finreg_proto, "register", js_mkfun(finreg_register)); js_set(js, finreg_proto, "unregister", js_mkfun(finreg_unregister)); js_set_sym(js, finreg_proto, tag_sym, js_mkstr(js, "FinalizationRegistry", 20)); - jsval_t finreg_ctor = js_mkobj(js); + ant_value_t finreg_ctor = js_mkobj(js); js_set_slot(js, finreg_ctor, SLOT_CFUNC, js_mkfun(builtin_FinalizationRegistry)); js_mkprop_fast(js, finreg_ctor, "prototype", 9, finreg_proto); js_mkprop_fast(js, finreg_ctor, "name", 4, ANT_STRING("FinalizationRegistry")); @@ -1079,9 +1079,9 @@ void init_collections_module(void) { js_set(js, glob, "FinalizationRegistry", js_obj_to_func(finreg_ctor)); } -void collections_gc_reserve_roots(void (*op_val)(void *, jsval_t *), void *ctx) { +void collections_gc_reserve_roots(void (*op_val)(void *, ant_value_t *), void *ctx) { for (size_t i = 0; i < map_registry_count; i++) { - jsval_t map_obj = mkval(T_OBJ, map_registry[i].obj_offset); + ant_value_t map_obj = mkval(T_OBJ, map_registry[i].obj_offset); op_val(ctx, &map_obj); map_entry_t **head = map_registry[i].head; if (head && *head) { map_entry_t *entry, *tmp; @@ -1090,7 +1090,7 @@ void collections_gc_reserve_roots(void (*op_val)(void *, jsval_t *), void *ctx) } for (size_t i = 0; i < set_registry_count; i++) { - jsval_t set_obj = mkval(T_OBJ, set_registry[i].obj_offset); + ant_value_t set_obj = mkval(T_OBJ, set_registry[i].obj_offset); op_val(ctx, &set_obj); set_entry_t **head = set_registry[i].head; if (head && *head) { set_entry_t *entry, *tmp; @@ -1119,14 +1119,14 @@ static void free_set_entries(set_entry_t **head) { } } -void collections_gc_update_roots(jsoff_t (*weak_off)(void *ctx, jsoff_t old), GC_OP_VAL_ARGS) { +void collections_gc_update_roots(ant_offset_t (*weak_off)(void *ctx, ant_offset_t old), GC_OP_VAL_ARGS) { size_t write_idx = 0; for (size_t i = 0; i < map_registry_count; i++) { - jsoff_t old_off = map_registry[i].obj_offset; - jsoff_t new_off = weak_off(ctx, old_off); + ant_offset_t old_off = map_registry[i].obj_offset; + ant_offset_t new_off = weak_off(ctx, old_off); - if (new_off == (jsoff_t)~0) { + if (new_off == (ant_offset_t)~0) { free_map_entries(map_registry[i].head); free(map_registry[i].head); continue; @@ -1147,10 +1147,10 @@ void collections_gc_update_roots(jsoff_t (*weak_off)(void *ctx, jsoff_t old), GC write_idx = 0; for (size_t i = 0; i < set_registry_count; i++) { - jsoff_t old_off = set_registry[i].obj_offset; - jsoff_t new_off = weak_off(ctx, old_off); + ant_offset_t old_off = set_registry[i].obj_offset; + ant_offset_t new_off = weak_off(ctx, old_off); - if (new_off == (jsoff_t)~0) { + if (new_off == (ant_offset_t)~0) { free_set_entries(set_registry[i].head); free(set_registry[i].head); continue; diff --git a/src/modules/crypto.c b/src/modules/crypto.c index a2f9d50..d81c83a 100644 --- a/src/modules/crypto.c +++ b/src/modules/crypto.c @@ -52,7 +52,7 @@ int uuidv7_new(uint8_t *uuid_out) { } // crypto.random() -static jsval_t js_crypto_random(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_crypto_random(ant_t *js, ant_value_t *args, int nargs) { (void) args; (void) nargs; (void) js; @@ -66,7 +66,7 @@ static jsval_t js_crypto_random(ant_t *js, jsval_t *args, int nargs) { } // crypto.randomBytes(length) -static jsval_t js_crypto_random_bytes(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_crypto_random_bytes(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) { return js_mkerr(js, "randomBytes requires a length argument"); } @@ -88,7 +88,7 @@ static jsval_t js_crypto_random_bytes(ant_t *js, jsval_t *args, int nargs) { randombytes_buf(random_bytes, length); - jsval_t array = js_mkobj(js); + ant_value_t array = js_mkobj(js); js_set(js, array, "length", js_mknum((double)length)); for (int i = 0; i < length; i++) { @@ -102,7 +102,7 @@ static jsval_t js_crypto_random_bytes(ant_t *js, jsval_t *args, int nargs) { } // crypto.randomUUID() -static jsval_t js_crypto_random_uuid(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_crypto_random_uuid(ant_t *js, ant_value_t *args, int nargs) { (void) args; (void) nargs; @@ -130,7 +130,7 @@ static jsval_t js_crypto_random_uuid(ant_t *js, jsval_t *args, int nargs) { } // crypto.randomUUIDv7() -static jsval_t js_crypto_random_uuidv7(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_crypto_random_uuidv7(ant_t *js, ant_value_t *args, int nargs) { (void) args; (void) nargs; @@ -152,7 +152,7 @@ static jsval_t js_crypto_random_uuidv7(ant_t *js, jsval_t *args, int nargs) { } // crypto.getRandomValues(typedArray) -static jsval_t js_crypto_get_random_values(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_crypto_get_random_values(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) { return js_mkerr(js, "getRandomValues requires a TypedArray argument"); } @@ -161,7 +161,7 @@ static jsval_t js_crypto_get_random_values(ant_t *js, jsval_t *args, int nargs) return js_mkerr(js, "libsodium initialization failed"); } - jsval_t ta_data_val = js_get_slot(js, args[0], SLOT_BUFFER); + ant_value_t ta_data_val = js_get_slot(js, args[0], SLOT_BUFFER); TypedArrayData *ta_data = (TypedArrayData *)js_gettypedarray(ta_data_val); if (!ta_data || !ta_data->buffer) { return js_mkerr(js, "argument must be a TypedArray"); @@ -177,8 +177,8 @@ static jsval_t js_crypto_get_random_values(ant_t *js, jsval_t *args, int nargs) return args[0]; } -static jsval_t create_crypto_obj(ant_t *js) { - jsval_t crypto_obj = js_mkobj(js); +static ant_value_t create_crypto_obj(ant_t *js) { + ant_value_t crypto_obj = js_mkobj(js); js_set(js, crypto_obj, "random", js_mkfun(js_crypto_random)); js_set(js, crypto_obj, "randomBytes", js_mkfun(js_crypto_random_bytes)); @@ -192,13 +192,13 @@ static jsval_t create_crypto_obj(ant_t *js) { void init_crypto_module() { ant_t *js = rt->js; - jsval_t crypto_obj = create_crypto_obj(js); + ant_value_t crypto_obj = create_crypto_obj(js); js_set(js, js_glob(js), "crypto", crypto_obj); } -jsval_t crypto_library(ant_t *js) { - jsval_t lib = js_mkobj(js); - jsval_t webcrypto = create_crypto_obj(js); +ant_value_t crypto_library(ant_t *js) { + ant_value_t lib = js_mkobj(js); + ant_value_t webcrypto = create_crypto_obj(js); js_set(js, lib, "webcrypto", webcrypto); js_set(js, lib, "randomBytes", js_mkfun(js_crypto_random_bytes)); diff --git a/src/modules/date.c b/src/modules/date.c index 7f1138b..e6ffe83 100644 --- a/src/modules/date.c +++ b/src/modules/date.c @@ -68,7 +68,7 @@ static inline int to_upper_ascii(int c) { return c; } -static inline bool date_is_primitive(jsval_t v) { +static inline bool date_is_primitive(ant_value_t v) { uint8_t t = vtype(v); return t == T_STR @@ -80,9 +80,9 @@ static inline bool date_is_primitive(jsval_t v) { || t == T_BIGINT; } -static bool is_date_instance(ant_t *js, jsval_t value) { +static bool is_date_instance(ant_t *js, ant_value_t value) { if (!is_object_type(value)) return false; - jsval_t date_proto = js_get_ctor_proto(js, "Date", 4); + ant_value_t date_proto = js_get_ctor_proto(js, "Date", 4); if (!is_object_type(date_proto)) return false; if (value == date_proto) return true; @@ -90,18 +90,18 @@ static bool is_date_instance(ant_t *js, jsval_t value) { return proto_chain_contains(js, value, date_proto); } -static bool date_this_time_value(ant_t *js, jsval_t this_val, double *out, jsval_t *err) { +static bool date_this_time_value(ant_t *js, ant_value_t this_val, double *out, ant_value_t *err) { if (!is_date_instance(js, this_val)) { if (err) *err = js_mkerr_typed(js, JS_ERR_TYPE, "not a Date object"); return false; } - jsval_t t = js_get_slot(js, js_as_obj(this_val), SLOT_DATA); + ant_value_t t = js_get_slot(js, js_as_obj(this_val), SLOT_DATA); *out = (vtype(t) == T_NUM) ? tod(t) : JS_NAN; return true; } -static jsval_t date_set_this_time_value(ant_t *js, jsval_t this_val, double v) { +static ant_value_t date_set_this_time_value(ant_t *js, ant_value_t this_val, double v) { if (!is_date_instance(js, this_val)) { return js_mkerr_typed(js, JS_ERR_TYPE, "not a Date object"); } @@ -243,9 +243,9 @@ static int date_extract_fields_from_time(double dval, date_fields_t *fields, int } static int date_extract_fields( - ant_t *js, jsval_t this_val, + ant_t *js, ant_value_t this_val, date_fields_t *fields, - int is_local, int force, jsval_t *err + int is_local, int force, ant_value_t *err ) { double dval; if (!date_this_time_value(js, this_val, &dval, err)) return -1; @@ -304,13 +304,13 @@ static double date_make_fields(const date_fields_t *fields, int is_local) { return d; } -jsval_t get_date_string(ant_t *js, jsval_t this_val, date_string_spec_t spec) { +ant_value_t get_date_string(ant_t *js, ant_value_t this_val, date_string_spec_t spec) { char buf[96]; date_fields_t fields; int res, fmt, pos; int y, mon, d, h, m, s, ms, wd, tz; - jsval_t err; + ant_value_t err; fmt = (int)spec.fmt; res = date_extract_fields( @@ -745,12 +745,12 @@ static bool parse_otherstring(const uint8_t *sp, int fields[9], bool *is_local) return true; } -static bool date_parse_string_to_ms(ant_t *js, jsval_t arg, double *out_ms) { - jsval_t s = coerce_to_str(js, arg); +static bool date_parse_string_to_ms(ant_t *js, ant_value_t arg, double *out_ms) { + ant_value_t s = coerce_to_str(js, arg); if (is_err(s)) return false; - jsoff_t len = 0; - jsoff_t off = vstr(js, s, &len); + ant_offset_t len = 0; + ant_offset_t off = vstr(js, s, &len); char *buf = (char *)malloc((size_t)len + 1); if (!buf) { @@ -798,7 +798,7 @@ static bool date_parse_string_to_ms(ant_t *js, jsval_t arg, double *out_ms) { return true; } -static jsval_t builtin_Date(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date(ant_t *js, ant_value_t *args, int nargs) { double val; static const date_string_spec_t kDateToStringSpec = { DATE_STRING_FMT_LOCAL, @@ -807,8 +807,8 @@ static jsval_t builtin_Date(ant_t *js, jsval_t *args, int nargs) { if (vtype(js->new_target) == T_UNDEF) { val = (double)date_now(); - jsval_t tmp = js_mkobj(js); - jsval_t date_proto = js_get_ctor_proto(js, "Date", 4); + ant_value_t tmp = js_mkobj(js); + ant_value_t date_proto = js_get_ctor_proto(js, "Date", 4); if (is_object_type(date_proto)) js_set_proto(js, tmp, date_proto); js_set_slot(js, tmp, SLOT_DATA, tov(val)); return get_date_string(js, tmp, kDateToStringSpec); @@ -817,14 +817,14 @@ static jsval_t builtin_Date(ant_t *js, jsval_t *args, int nargs) { if (nargs == 0) { val = (double)date_now(); } else if (nargs == 1) { - jsval_t input = args[0]; + ant_value_t input = args[0]; if (is_object_type(input) && is_date_instance(js, input)) { - jsval_t tv = js_get_slot(js, js_as_obj(input), SLOT_DATA); + ant_value_t tv = js_get_slot(js, js_as_obj(input), SLOT_DATA); val = (vtype(tv) == T_NUM) ? tod(tv) : JS_NAN; val = date_timeclip(val); } else { - jsval_t prim = js_to_primitive(js, input, 0); + ant_value_t prim = js_to_primitive(js, input, 0); if (is_err(prim)) return prim; if (vtype(prim) == T_STR) { if (!date_parse_string_to_ms(js, prim, &val)) return js_mkerr_typed(js, JS_ERR_INTERNAL, "Date parse failed"); @@ -855,7 +855,7 @@ static jsval_t builtin_Date(ant_t *js, jsval_t *args, int nargs) { return js->this_val; } -static jsval_t builtin_Date_UTC(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_UTC(ant_t *js, ant_value_t *args, int nargs) { if (nargs == 0) return tov(JS_NAN); date_fields_t fields = {0}; @@ -874,7 +874,7 @@ static jsval_t builtin_Date_UTC(ant_t *js, jsval_t *args, int nargs) { return tov(date_make_fields(&fields, 0)); } -static jsval_t builtin_Date_parse(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_parse(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return tov(JS_NAN); double v; if (!date_parse_string_to_ms(js, args[0], &v)) { @@ -883,13 +883,13 @@ static jsval_t builtin_Date_parse(ant_t *js, jsval_t *args, int nargs) { return tov(v); } -static jsval_t builtin_Date_now(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_now(ant_t *js, ant_value_t *args, int nargs) { return tov((double)date_now()); } -static jsval_t date_get_field(ant_t *js, date_get_field_spec_t spec) { +static ant_value_t date_get_field(ant_t *js, date_get_field_spec_t spec) { date_fields_t fields; - jsval_t err; + ant_value_t err; int res = date_extract_fields(js, js->this_val, &fields, spec.local_time, 0, &err); if (res < 0) return err; @@ -899,9 +899,9 @@ static jsval_t date_get_field(ant_t *js, date_get_field_spec_t spec) { return tov(date_fields_get(&fields, spec.field)); } -static jsval_t date_set_field(ant_t *js, jsval_t *args, int nargs, date_set_field_spec_t spec) { +static ant_value_t date_set_field(ant_t *js, ant_value_t *args, int nargs, date_set_field_spec_t spec) { date_fields_t fields; - jsval_t err; + ant_value_t err; double d = JS_NAN; int res = date_extract_fields( @@ -925,232 +925,232 @@ static jsval_t date_set_field(ant_t *js, jsval_t *args, int nargs, date_set_fiel return date_set_this_time_value(js, js->this_val, d); } -static jsval_t builtin_Date_valueOf(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_valueOf(ant_t *js, ant_value_t *args, int nargs) { double v; - jsval_t err; + ant_value_t err; if (!date_this_time_value(js, js->this_val, &v, &err)) return err; return tov(v); } -static jsval_t builtin_Date_getTime(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_getTime(ant_t *js, ant_value_t *args, int nargs) { return builtin_Date_valueOf(js, args, nargs); } -static jsval_t builtin_Date_toUTCString(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_toUTCString(ant_t *js, ant_value_t *args, int nargs) { static const date_string_spec_t kSpec = {DATE_STRING_FMT_UTC, DATE_STRING_PART_ALL}; return get_date_string(js, js->this_val, kSpec); } -static jsval_t builtin_Date_toString(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_toString(ant_t *js, ant_value_t *args, int nargs) { static const date_string_spec_t kSpec = {DATE_STRING_FMT_LOCAL, DATE_STRING_PART_ALL}; return get_date_string(js, js->this_val, kSpec); } -static jsval_t builtin_Date_toISOString(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_toISOString(ant_t *js, ant_value_t *args, int nargs) { static const date_string_spec_t kSpec = {DATE_STRING_FMT_ISO, DATE_STRING_PART_ALL}; return get_date_string(js, js->this_val, kSpec); } -static jsval_t builtin_Date_toDateString(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_toDateString(ant_t *js, ant_value_t *args, int nargs) { static const date_string_spec_t kSpec = {DATE_STRING_FMT_LOCAL, DATE_STRING_PART_DATE}; return get_date_string(js, js->this_val, kSpec); } -static jsval_t builtin_Date_toTimeString(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_toTimeString(ant_t *js, ant_value_t *args, int nargs) { static const date_string_spec_t kSpec = {DATE_STRING_FMT_LOCAL, DATE_STRING_PART_TIME}; return get_date_string(js, js->this_val, kSpec); } -static jsval_t builtin_Date_toLocaleString(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_toLocaleString(ant_t *js, ant_value_t *args, int nargs) { static const date_string_spec_t kSpec = {DATE_STRING_FMT_LOCALE, DATE_STRING_PART_ALL}; return get_date_string(js, js->this_val, kSpec); } -static jsval_t builtin_Date_toLocaleDateString(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_toLocaleDateString(ant_t *js, ant_value_t *args, int nargs) { static const date_string_spec_t kSpec = {DATE_STRING_FMT_LOCALE, DATE_STRING_PART_DATE}; return get_date_string(js, js->this_val, kSpec); } -static jsval_t builtin_Date_toLocaleTimeString(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_toLocaleTimeString(ant_t *js, ant_value_t *args, int nargs) { static const date_string_spec_t kSpec = {DATE_STRING_FMT_LOCALE, DATE_STRING_PART_TIME}; return get_date_string(js, js->this_val, kSpec); } -static jsval_t builtin_Date_getTimezoneOffset(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_getTimezoneOffset(ant_t *js, ant_value_t *args, int nargs) { double v; - jsval_t err; + ant_value_t err; if (!date_this_time_value(js, js->this_val, &v, &err)) return err; if (isnan(v)) return tov(JS_NAN); return tov((double)get_timezone_offset((int64_t)trunc(v))); } -static jsval_t builtin_Date_setTime(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_setTime(ant_t *js, ant_value_t *args, int nargs) { double cur; - jsval_t err; + ant_value_t err; if (!date_this_time_value(js, js->this_val, &cur, &err)) return err; double v = (nargs > 0) ? js_to_number(js, args[0]) : JS_NAN; return date_set_this_time_value(js, js->this_val, date_timeclip(v)); } -static jsval_t builtin_Date_getYear(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_getYear(ant_t *js, ant_value_t *args, int nargs) { static const date_get_field_spec_t kSpec = {DATE_FIELD_YEAR, true, true}; return date_get_field(js, kSpec); } -static jsval_t builtin_Date_getFullYear(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_getFullYear(ant_t *js, ant_value_t *args, int nargs) { static const date_get_field_spec_t kSpec = {DATE_FIELD_YEAR, true, false}; return date_get_field(js, kSpec); } -static jsval_t builtin_Date_getUTCFullYear(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_getUTCFullYear(ant_t *js, ant_value_t *args, int nargs) { static const date_get_field_spec_t kSpec = {DATE_FIELD_YEAR, false, false}; return date_get_field(js, kSpec); } -static jsval_t builtin_Date_getMonth(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_getMonth(ant_t *js, ant_value_t *args, int nargs) { static const date_get_field_spec_t kSpec = {DATE_FIELD_MONTH, true, false}; return date_get_field(js, kSpec); } -static jsval_t builtin_Date_getUTCMonth(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_getUTCMonth(ant_t *js, ant_value_t *args, int nargs) { static const date_get_field_spec_t kSpec = {DATE_FIELD_MONTH, false, false}; return date_get_field(js, kSpec); } -static jsval_t builtin_Date_getDate(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_getDate(ant_t *js, ant_value_t *args, int nargs) { static const date_get_field_spec_t kSpec = {DATE_FIELD_DAY_OF_MONTH, true, false}; return date_get_field(js, kSpec); } -static jsval_t builtin_Date_getUTCDate(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_getUTCDate(ant_t *js, ant_value_t *args, int nargs) { static const date_get_field_spec_t kSpec = {DATE_FIELD_DAY_OF_MONTH, false, false}; return date_get_field(js, kSpec); } -static jsval_t builtin_Date_getHours(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_getHours(ant_t *js, ant_value_t *args, int nargs) { static const date_get_field_spec_t kSpec = {DATE_FIELD_HOUR, true, false}; return date_get_field(js, kSpec); } -static jsval_t builtin_Date_getUTCHours(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_getUTCHours(ant_t *js, ant_value_t *args, int nargs) { static const date_get_field_spec_t kSpec = {DATE_FIELD_HOUR, false, false}; return date_get_field(js, kSpec); } -static jsval_t builtin_Date_getMinutes(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_getMinutes(ant_t *js, ant_value_t *args, int nargs) { static const date_get_field_spec_t kSpec = {DATE_FIELD_MINUTE, true, false}; return date_get_field(js, kSpec); } -static jsval_t builtin_Date_getUTCMinutes(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_getUTCMinutes(ant_t *js, ant_value_t *args, int nargs) { static const date_get_field_spec_t kSpec = {DATE_FIELD_MINUTE, false, false}; return date_get_field(js, kSpec); } -static jsval_t builtin_Date_getSeconds(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_getSeconds(ant_t *js, ant_value_t *args, int nargs) { static const date_get_field_spec_t kSpec = {DATE_FIELD_SECOND, true, false}; return date_get_field(js, kSpec); } -static jsval_t builtin_Date_getUTCSeconds(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_getUTCSeconds(ant_t *js, ant_value_t *args, int nargs) { static const date_get_field_spec_t kSpec = {DATE_FIELD_SECOND, false, false}; return date_get_field(js, kSpec); } -static jsval_t builtin_Date_getMilliseconds(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_getMilliseconds(ant_t *js, ant_value_t *args, int nargs) { static const date_get_field_spec_t kSpec = {DATE_FIELD_MILLISECOND, true, false}; return date_get_field(js, kSpec); } -static jsval_t builtin_Date_getUTCMilliseconds(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_getUTCMilliseconds(ant_t *js, ant_value_t *args, int nargs) { static const date_get_field_spec_t kSpec = {DATE_FIELD_MILLISECOND, false, false}; return date_get_field(js, kSpec); } -static jsval_t builtin_Date_getDay(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_getDay(ant_t *js, ant_value_t *args, int nargs) { static const date_get_field_spec_t kSpec = {DATE_FIELD_DAY_OF_WEEK, true, false}; return date_get_field(js, kSpec); } -static jsval_t builtin_Date_getUTCDay(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_getUTCDay(ant_t *js, ant_value_t *args, int nargs) { static const date_get_field_spec_t kSpec = {DATE_FIELD_DAY_OF_WEEK, false, false}; return date_get_field(js, kSpec); } -static jsval_t builtin_Date_setMilliseconds(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_setMilliseconds(ant_t *js, ant_value_t *args, int nargs) { static const date_set_field_spec_t kSpec = {DATE_FIELD_MILLISECOND, DATE_FIELD_DAY_OF_WEEK, true}; return date_set_field(js, args, nargs, kSpec); } -static jsval_t builtin_Date_setUTCMilliseconds(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_setUTCMilliseconds(ant_t *js, ant_value_t *args, int nargs) { static const date_set_field_spec_t kSpec = {DATE_FIELD_MILLISECOND, DATE_FIELD_DAY_OF_WEEK, false}; return date_set_field(js, args, nargs, kSpec); } -static jsval_t builtin_Date_setSeconds(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_setSeconds(ant_t *js, ant_value_t *args, int nargs) { static const date_set_field_spec_t kSpec = {DATE_FIELD_SECOND, DATE_FIELD_DAY_OF_WEEK, true}; return date_set_field(js, args, nargs, kSpec); } -static jsval_t builtin_Date_setUTCSeconds(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_setUTCSeconds(ant_t *js, ant_value_t *args, int nargs) { static const date_set_field_spec_t kSpec = {DATE_FIELD_SECOND, DATE_FIELD_DAY_OF_WEEK, false}; return date_set_field(js, args, nargs, kSpec); } -static jsval_t builtin_Date_setMinutes(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_setMinutes(ant_t *js, ant_value_t *args, int nargs) { static const date_set_field_spec_t kSpec = {DATE_FIELD_MINUTE, DATE_FIELD_DAY_OF_WEEK, true}; return date_set_field(js, args, nargs, kSpec); } -static jsval_t builtin_Date_setUTCMinutes(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_setUTCMinutes(ant_t *js, ant_value_t *args, int nargs) { static const date_set_field_spec_t kSpec = {DATE_FIELD_MINUTE, DATE_FIELD_DAY_OF_WEEK, false}; return date_set_field(js, args, nargs, kSpec); } -static jsval_t builtin_Date_setHours(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_setHours(ant_t *js, ant_value_t *args, int nargs) { static const date_set_field_spec_t kSpec = {DATE_FIELD_HOUR, DATE_FIELD_DAY_OF_WEEK, true}; return date_set_field(js, args, nargs, kSpec); } -static jsval_t builtin_Date_setUTCHours(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_setUTCHours(ant_t *js, ant_value_t *args, int nargs) { static const date_set_field_spec_t kSpec = {DATE_FIELD_HOUR, DATE_FIELD_DAY_OF_WEEK, false}; return date_set_field(js, args, nargs, kSpec); } -static jsval_t builtin_Date_setDate(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_setDate(ant_t *js, ant_value_t *args, int nargs) { static const date_set_field_spec_t kSpec = {DATE_FIELD_DAY_OF_MONTH, DATE_FIELD_HOUR, true}; return date_set_field(js, args, nargs, kSpec); } -static jsval_t builtin_Date_setUTCDate(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_setUTCDate(ant_t *js, ant_value_t *args, int nargs) { static const date_set_field_spec_t kSpec = {DATE_FIELD_DAY_OF_MONTH, DATE_FIELD_HOUR, false}; return date_set_field(js, args, nargs, kSpec); } -static jsval_t builtin_Date_setMonth(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_setMonth(ant_t *js, ant_value_t *args, int nargs) { static const date_set_field_spec_t kSpec = {DATE_FIELD_MONTH, DATE_FIELD_DAY_OF_MONTH, true}; return date_set_field(js, args, nargs, kSpec); } -static jsval_t builtin_Date_setUTCMonth(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_setUTCMonth(ant_t *js, ant_value_t *args, int nargs) { static const date_set_field_spec_t kSpec = {DATE_FIELD_MONTH, DATE_FIELD_DAY_OF_MONTH, false}; return date_set_field(js, args, nargs, kSpec); } -static jsval_t builtin_Date_setFullYear(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_setFullYear(ant_t *js, ant_value_t *args, int nargs) { static const date_set_field_spec_t kSpec = {DATE_FIELD_YEAR, DATE_FIELD_HOUR, true}; return date_set_field(js, args, nargs, kSpec); } -static jsval_t builtin_Date_setUTCFullYear(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_setUTCFullYear(ant_t *js, ant_value_t *args, int nargs) { static const date_set_field_spec_t kSpec = {DATE_FIELD_YEAR, DATE_FIELD_HOUR, false}; return date_set_field(js, args, nargs, kSpec); } -static jsval_t builtin_Date_setYear(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Date_setYear(ant_t *js, ant_value_t *args, int nargs) { double y; - jsval_t err; + ant_value_t err; if (!date_this_time_value(js, js->this_val, &y, &err)) return err; y = (nargs > 0) ? js_to_number(js, args[0]) : JS_NAN; @@ -1161,21 +1161,21 @@ static jsval_t builtin_Date_setYear(ant_t *js, jsval_t *args, int nargs) { if (y >= 0 && y < 100) y += 1900; } - jsval_t darg = tov(y); + ant_value_t darg = tov(y); static const date_set_field_spec_t kSetYearSpec = { DATE_FIELD_YEAR, DATE_FIELD_MONTH, true }; return date_set_field(js, &darg, 1, kSetYearSpec); } -static jsval_t date_to_primitive_number(ant_t *js, jsval_t obj) { - jsval_t to_primitive_sym = get_toPrimitive_sym(); +static ant_value_t date_to_primitive_number(ant_t *js, ant_value_t obj) { + ant_value_t to_primitive_sym = get_toPrimitive_sym(); if (vtype(to_primitive_sym) == T_SYMBOL) { - jsval_t ex = js_get_sym(js, obj, to_primitive_sym); + ant_value_t ex = js_get_sym(js, obj, to_primitive_sym); uint8_t et = vtype(ex); if (et == T_FUNC || et == T_CFUNC) { - jsval_t hint = js_mkstr(js, "number", 6); - jsval_t result = sv_vm_call(js->vm, js, ex, obj, &hint, 1, NULL, false); + ant_value_t hint = js_mkstr(js, "number", 6); + ant_value_t result = sv_vm_call(js->vm, js, ex, obj, &hint, 1, NULL, false); if (is_err(result)) return result; if (date_is_primitive(result)) return result; return js_mkerr_typed(js, JS_ERR_TYPE, "Cannot convert object to primitive value"); @@ -1187,10 +1187,10 @@ static jsval_t date_to_primitive_number(ant_t *js, jsval_t obj) { const char *methods[2] = {"valueOf", "toString"}; for (int i = 0; i < 2; i++) { - jsval_t method = js_getprop_fallback(js, obj, methods[i]); + ant_value_t method = js_getprop_fallback(js, obj, methods[i]); uint8_t mt = vtype(method); if (mt == T_FUNC || mt == T_CFUNC) { - jsval_t result = sv_vm_call(js->vm, js, method, obj, NULL, 0, NULL, false); + ant_value_t result = sv_vm_call(js->vm, js, method, obj, NULL, 0, NULL, false); if (is_err(result)) return result; if (date_is_primitive(result)) return result; } @@ -1199,20 +1199,20 @@ static jsval_t date_to_primitive_number(ant_t *js, jsval_t obj) { return js_mkerr_typed(js, JS_ERR_TYPE, "Cannot convert object to primitive value"); } -static jsval_t builtin_Date_toJSON(ant_t *js, jsval_t *args, int nargs) { - jsval_t obj = js->this_val; +static ant_value_t builtin_Date_toJSON(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t obj = js->this_val; if (!is_object_type(obj)) { return js_mkerr_typed(js, JS_ERR_TYPE, "Date.prototype.toJSON called on non-object"); } - jsval_t tv = date_to_primitive_number(js, obj); + ant_value_t tv = date_to_primitive_number(js, obj); if (is_err(tv)) return tv; if (vtype(tv) == T_NUM && !isfinite(tod(tv))) { return js_mknull(); } - jsval_t method = js_getprop_fallback(js, obj, "toISOString"); + ant_value_t method = js_getprop_fallback(js, obj, "toISOString"); uint8_t mt = vtype(method); if (mt != T_FUNC && mt != T_CFUNC) { return js_mkerr_typed(js, JS_ERR_TYPE, "object needs toISOString method"); @@ -1221,8 +1221,8 @@ static jsval_t builtin_Date_toJSON(ant_t *js, jsval_t *args, int nargs) { return sv_vm_call(js->vm, js, method, obj, NULL, 0, NULL, false); } -static jsval_t date_toPrimitive(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_val = js_getthis(js); +static ant_value_t date_toPrimitive(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_val = js_getthis(js); if (!is_object_type(this_val)) { return js_mkerr_typed(js, JS_ERR_TYPE, "Not an object"); } @@ -1250,10 +1250,10 @@ static jsval_t date_toPrimitive(ant_t *js, jsval_t *args, int nargs) { const char **methods = hint_num ? methods1 : methods0; for (int i = 0; i < 2; i++) { - jsval_t method = js_getprop_fallback(js, this_val, methods[i]); + ant_value_t method = js_getprop_fallback(js, this_val, methods[i]); uint8_t mt = vtype(method); if (mt == T_FUNC || mt == T_CFUNC) { - jsval_t result = sv_vm_call(js->vm, js, method, this_val, NULL, 0, NULL, false); + ant_value_t result = sv_vm_call(js->vm, js, method, this_val, NULL, 0, NULL, false); if (is_err(result)) return result; if (date_is_primitive(result)) return result; } @@ -1263,7 +1263,7 @@ static jsval_t date_toPrimitive(ant_t *js, jsval_t *args, int nargs) { } static void date_define_methods( - ant_t *js, jsval_t target, + ant_t *js, ant_value_t target, const date_method_entry_t *methods, size_t count ) { @@ -1275,11 +1275,11 @@ static void date_define_methods( void init_date_module(void) { ant_t *js = rt->js; - jsval_t glob = js_glob(js); - jsval_t object_proto = js_get_ctor_proto(js, "Object", 6); - jsval_t function_proto = js_get_ctor_proto(js, "Function", 8); + ant_value_t glob = js_glob(js); + ant_value_t object_proto = js_get_ctor_proto(js, "Object", 6); + ant_value_t function_proto = js_get_ctor_proto(js, "Function", 8); - jsval_t date_proto = js_mkobj(js); + ant_value_t date_proto = js_mkobj(js); js_set_proto(js, date_proto, object_proto); static const date_method_entry_t kDateProtoMethods[] = { @@ -1332,12 +1332,12 @@ void init_date_module(void) { }; date_define_methods(js, date_proto, kDateProtoMethods, DATE_COUNT_OF(kDateProtoMethods)); - jsval_t to_primitive_sym = get_toPrimitive_sym(); + ant_value_t to_primitive_sym = get_toPrimitive_sym(); if (vtype(to_primitive_sym) == T_SYMBOL) { js_set_sym(js, date_proto, to_primitive_sym, js_mkfun(date_toPrimitive)); } - jsval_t date_ctor_obj = js_mkobj(js); + ant_value_t date_ctor_obj = js_mkobj(js); js_set_proto(js, date_ctor_obj, function_proto); js_set_slot(js, date_ctor_obj, SLOT_CFUNC, js_mkfun(builtin_Date)); static const date_method_entry_t kDateCtorMethods[] = { @@ -1349,7 +1349,7 @@ void init_date_module(void) { js_setprop_nonconfigurable(js, date_ctor_obj, "prototype", 9, date_proto); js_setprop(js, date_ctor_obj, ANT_STRING("name"), ANT_STRING("Date")); - jsval_t date_ctor_func = js_obj_to_func(date_ctor_obj); + ant_value_t date_ctor_func = js_obj_to_func(date_ctor_obj); js_setprop(js, glob, js_mkstr(js, "Date", 4), date_ctor_func); js_setprop(js, date_proto, js_mkstr(js, "constructor", 11), date_ctor_func); diff --git a/src/modules/dns.c b/src/modules/dns.c index b40ea19..af543b7 100644 --- a/src/modules/dns.c +++ b/src/modules/dns.c @@ -16,7 +16,7 @@ #include "ant.h" #include "errors.h" -static jsval_t dns_promises_lookup(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t dns_promises_lookup(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "hostname is required"); size_t len; @@ -50,18 +50,18 @@ static jsval_t dns_promises_lookup(ant_t *js, jsval_t *args, int nargs) { freeaddrinfo(res); - jsval_t result = js_mkobj(js); + ant_value_t result = js_mkobj(js); js_set(js, result, "address", js_mkstr(js, addr_str, strlen(addr_str))); js_set(js, result, "family", js_mknum(family)); - jsval_t promise = js_mkpromise(js); + ant_value_t promise = js_mkpromise(js); js_resolve_promise(js, promise, result); return promise; } -jsval_t dns_library(ant_t *js) { - jsval_t lib = js_mkobj(js); - jsval_t promises = js_mkobj(js); +ant_value_t dns_library(ant_t *js) { + ant_value_t lib = js_mkobj(js); + ant_value_t promises = js_mkobj(js); js_set(js, promises, "lookup", js_mkfun(dns_promises_lookup)); js_set(js, lib, "promises", promises); diff --git a/src/modules/events.c b/src/modules/events.c index 26b94dd..9e9597d 100644 --- a/src/modules/events.c +++ b/src/modules/events.c @@ -18,7 +18,7 @@ #define MAX_LISTENERS_PER_EVENT 32 typedef struct { - jsval_t listener; + ant_value_t listener; bool once; } __attribute__((packed)) EventListener; @@ -46,8 +46,8 @@ static inline void remove_listener_at(EventType *evt, int i) { evt->listener_count--; } -static EventType **get_or_create_emitter_events(ant_t *js, jsval_t this_obj) { - jsval_t slot = js_get_slot(js, this_obj, SLOT_DATA); +static EventType **get_or_create_emitter_events(ant_t *js, ant_value_t this_obj) { + ant_value_t slot = js_get_slot(js, this_obj, SLOT_DATA); if (vtype(slot) == T_UNDEF) { EventType **events = ant_calloc(sizeof(EventType *)); @@ -68,7 +68,7 @@ static EventType **get_or_create_emitter_events(ant_t *js, jsval_t this_obj) { return (EventType **)(uintptr_t)js_getnum(slot); } -static EventType *find_emitter_event_type(ant_t *js, jsval_t this_obj, const char *event_type) { +static EventType *find_emitter_event_type(ant_t *js, ant_value_t this_obj, const char *event_type) { EventType **events = get_or_create_emitter_events(js, this_obj); if (events == NULL) return NULL; @@ -77,7 +77,7 @@ static EventType *find_emitter_event_type(ant_t *js, jsval_t this_obj, const cha return evt; } -static EventType *find_or_create_emitter_event_type(ant_t *js, jsval_t this_obj, const char *event_type) { +static EventType *find_or_create_emitter_event_type(ant_t *js, ant_value_t this_obj, const char *event_type) { EventType **events = get_or_create_emitter_events(js, this_obj); if (events == NULL) return NULL; @@ -121,8 +121,8 @@ static inline EventType *find_global_event_type(const char *event_type) { } // addEventListener(eventType, listener, options) -static jsval_t js_add_event_listener_method(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t js_add_event_listener_method(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 2) { return js_mkerr(js, "addEventListener requires at least 2 arguments (eventType, listener)"); @@ -141,7 +141,7 @@ static jsval_t js_add_event_listener_method(ant_t *js, jsval_t *args, int nargs) bool once = false; if (nargs >= 3 && vtype(args[2]) != T_UNDEF) { - jsval_t once_val = js_get(js, args[2], "once"); + ant_value_t once_val = js_get(js, args[2], "once"); if (vtype(once_val) != T_UNDEF) once = js_truthy(js, once_val); } @@ -153,7 +153,7 @@ static jsval_t js_add_event_listener_method(ant_t *js, jsval_t *args, int nargs) } // addEventListener(eventType, listener, options) -static jsval_t js_add_event_listener(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_add_event_listener(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) { return js_mkerr(js, "addEventListener requires at least 2 arguments (eventType, listener)"); } @@ -178,7 +178,7 @@ static jsval_t js_add_event_listener(ant_t *js, jsval_t *args, int nargs) { bool once = false; if (nargs >= 3 && vtype(args[2]) != T_UNDEF) { - jsval_t once_val = js_get(js, args[2], "once"); + ant_value_t once_val = js_get(js, args[2], "once"); if (vtype(once_val) != T_UNDEF) once = js_truthy(js, once_val); } @@ -190,8 +190,8 @@ static jsval_t js_add_event_listener(ant_t *js, jsval_t *args, int nargs) { } // removeEventListener(eventType, listener) -static jsval_t js_remove_event_listener_method(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t js_remove_event_listener_method(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 2) { return js_mkerr(js, "removeEventListener requires 2 arguments (eventType, listener)"); @@ -213,7 +213,7 @@ static jsval_t js_remove_event_listener_method(ant_t *js, jsval_t *args, int nar } // removeEventListener(eventType, listener) -static jsval_t js_remove_event_listener(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_remove_event_listener(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) { return js_mkerr(js, "removeEventListener requires 2 arguments (eventType, listener)"); } @@ -234,8 +234,8 @@ static jsval_t js_remove_event_listener(ant_t *js, jsval_t *args, int nargs) { } // dispatchEvent(eventType, eventData) -static jsval_t js_dispatch_event_method(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t js_dispatch_event_method(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 1) { return js_mkerr(js, "dispatchEvent requires at least 1 argument (eventType)"); @@ -247,7 +247,7 @@ static jsval_t js_dispatch_event_method(ant_t *js, jsval_t *args, int nargs) { EventType *evt = find_emitter_event_type(js, this_obj, event_type); if (evt == NULL || evt->listener_count == 0) return js_true; - jsval_t event_obj = js_mkobj(js); + ant_value_t event_obj = js_mkobj(js); js_set(js, event_obj, "type", args[0]); js_set(js, event_obj, "target", this_obj); js_set_sym(js, event_obj, get_toStringTag_sym(), js_mkstr(js, "Event", 5)); @@ -256,11 +256,11 @@ static jsval_t js_dispatch_event_method(ant_t *js, jsval_t *args, int nargs) { js_set(js, event_obj, "detail", args[1]); } - jsval_t listener_args[1] = {event_obj}; + ant_value_t listener_args[1] = {event_obj}; int i = 0; while (i < evt->listener_count) { EventListener *listener = &evt->listeners[i]; - jsval_t result = sv_vm_call(js->vm, js, listener->listener, js_mkundef(), listener_args, 1, NULL, false); + ant_value_t result = sv_vm_call(js->vm, js, listener->listener, js_mkundef(), listener_args, 1, NULL, false); if (vtype(result) == T_ERR) { fprintf(stderr, "Error in event listener for '%s': %s\n", event_type, js_str(js, result)); @@ -275,7 +275,7 @@ static jsval_t js_dispatch_event_method(ant_t *js, jsval_t *args, int nargs) { } // dispatchEvent(eventType, eventData) -static jsval_t js_dispatch_event(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_dispatch_event(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) { return js_mkerr(js, "dispatchEvent requires at least 1 argument (eventType)"); } @@ -288,7 +288,7 @@ static jsval_t js_dispatch_event(ant_t *js, jsval_t *args, int nargs) { return js_true; } - jsval_t event_obj = js_mkobj(js); + ant_value_t event_obj = js_mkobj(js); js_set(js, event_obj, "type", args[0]); js_set_sym(js, event_obj, get_toStringTag_sym(), js_mkstr(js, "Event", 5)); @@ -296,11 +296,11 @@ static jsval_t js_dispatch_event(ant_t *js, jsval_t *args, int nargs) { js_set(js, event_obj, "detail", args[1]); } - jsval_t listener_args[1] = {event_obj}; + ant_value_t listener_args[1] = {event_obj}; int i = 0; while (i < evt->listener_count) { EventListener *listener = &evt->listeners[i]; - jsval_t result = sv_vm_call(js->vm, js, listener->listener, js_mkundef(), listener_args, 1, NULL, false); + ant_value_t result = sv_vm_call(js->vm, js, listener->listener, js_mkundef(), listener_args, 1, NULL, false); if (vtype(result) == T_ERR) { fprintf(stderr, "Error in event listener for '%s': %s\n", event_type, js_str(js, result)); @@ -314,20 +314,20 @@ static jsval_t js_dispatch_event(ant_t *js, jsval_t *args, int nargs) { return js_true; } -static jsval_t js_get_event_listeners(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_get_event_listeners(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; EventType *evt, *tmp; - jsval_t result = js_mkobj(js); + ant_value_t result = js_mkobj(js); HASH_ITER(hh, global_events, evt, tmp) { - jsval_t listeners_array = js_mkobj(js); + ant_value_t listeners_array = js_mkobj(js); for (int j = 0; j < evt->listener_count; j++) { char key[16]; snprintf(key, sizeof(key), "%d", j); - jsval_t listener_info = js_mkobj(js); + ant_value_t listener_info = js_mkobj(js); js_set(js, listener_info, "listener", evt->listeners[j].listener); js_set(js, listener_info, "once", js_bool(evt->listeners[j].once)); @@ -342,8 +342,8 @@ static jsval_t js_get_event_listeners(ant_t *js, jsval_t *args, int nargs) { } // EventEmitter.prototype.on(event, listener) -static jsval_t js_eventemitter_on(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t js_eventemitter_on(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 2) { return js_mkerr(js, "on requires 2 arguments (event, listener)"); @@ -375,8 +375,8 @@ static jsval_t js_eventemitter_on(ant_t *js, jsval_t *args, int nargs) { } // EventEmitter.prototype.once(event, listener) -static jsval_t js_eventemitter_once(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t js_eventemitter_once(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 2) { return js_mkerr(js, "once requires 2 arguments (event, listener)"); @@ -408,8 +408,8 @@ static jsval_t js_eventemitter_once(ant_t *js, jsval_t *args, int nargs) { } // EventEmitter.prototype.off(event, listener) -static jsval_t js_eventemitter_off(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t js_eventemitter_off(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 2) { return js_mkerr(js, "off requires 2 arguments (event, listener)"); @@ -435,8 +435,8 @@ static jsval_t js_eventemitter_off(ant_t *js, jsval_t *args, int nargs) { } // EventEmitter.prototype.emit(event, ...args) -static jsval_t js_eventemitter_emit(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t js_eventemitter_emit(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 1) { return js_mkerr(js, "emit requires at least 1 argument (event)"); @@ -453,12 +453,12 @@ static jsval_t js_eventemitter_emit(ant_t *js, jsval_t *args, int nargs) { } int listener_nargs = nargs - 1; - jsval_t *listener_args = (listener_nargs > 0) ? &args[1] : NULL; + ant_value_t *listener_args = (listener_nargs > 0) ? &args[1] : NULL; int i = 0; while (i < evt->listener_count) { EventListener *listener = &evt->listeners[i]; - jsval_t result = sv_vm_call(js->vm, js, listener->listener, js_mkundef(), listener_args, listener_nargs, NULL, false); + ant_value_t result = sv_vm_call(js->vm, js, listener->listener, js_mkundef(), listener_args, listener_nargs, NULL, false); if (vtype(result) == T_ERR) { fprintf(stderr, "Error in event listener for '%s': %s\n", event_type, js_str(js, result)); @@ -473,8 +473,8 @@ static jsval_t js_eventemitter_emit(ant_t *js, jsval_t *args, int nargs) { } // EventEmitter.prototype.removeAllListeners(event) -static jsval_t js_eventemitter_removeAllListeners(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t js_eventemitter_removeAllListeners(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 1) { return this_obj; @@ -494,8 +494,8 @@ static jsval_t js_eventemitter_removeAllListeners(ant_t *js, jsval_t *args, int } // EventEmitter.prototype.listenerCount(event) -static jsval_t js_eventemitter_listenerCount(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t js_eventemitter_listenerCount(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 1) { return js_mknum(0); @@ -515,11 +515,11 @@ static jsval_t js_eventemitter_listenerCount(ant_t *js, jsval_t *args, int nargs } // EventEmitter.prototype.eventNames() -static jsval_t js_eventemitter_eventNames(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_eventemitter_eventNames(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t this_obj = js_getthis(js); - jsval_t result = js_mkarr(js); + ant_value_t this_obj = js_getthis(js); + ant_value_t result = js_mkarr(js); EventType **events = get_or_create_emitter_events(js, this_obj); @@ -527,7 +527,7 @@ static jsval_t js_eventemitter_eventNames(ant_t *js, jsval_t *args, int nargs) { EventType *evt, *tmp; HASH_ITER(hh, *events, evt, tmp) { if (evt->listener_count > 0) { - jsval_t name = js_mkstr(js, evt->event_type, strlen(evt->event_type)); + ant_value_t name = js_mkstr(js, evt->event_type, strlen(evt->event_type)); js_arr_push(js, result, name); } } @@ -536,11 +536,11 @@ static jsval_t js_eventemitter_eventNames(ant_t *js, jsval_t *args, int nargs) { return result; } -jsval_t events_library(ant_t *js) { - jsval_t lib = js_mkobj(js); +ant_value_t events_library(ant_t *js) { + ant_value_t lib = js_mkobj(js); - jsval_t eventemitter_ctor = js_mkobj(js); - jsval_t eventemitter_proto = js_mkobj(js); + ant_value_t eventemitter_ctor = js_mkobj(js); + ant_value_t eventemitter_proto = js_mkobj(js); js_set(js, eventemitter_proto, "on", js_mkfun(js_eventemitter_on)); js_set(js, eventemitter_proto, "addListener", js_mkfun(js_eventemitter_on)); @@ -558,7 +558,7 @@ jsval_t events_library(ant_t *js) { js_mkprop_fast(js, eventemitter_ctor, "name", 4, ANT_STRING("EventEmitter")); js_set_descriptor(js, eventemitter_ctor, "name", 4, 0); - jsval_t ctor_fn = js_obj_to_func(eventemitter_ctor); + ant_value_t ctor_fn = js_obj_to_func(eventemitter_ctor); js_set(js, lib, "EventEmitter", ctor_fn); js_set(js, lib, "default", ctor_fn); js_set_sym(js, lib, get_toStringTag_sym(), js_mkstr(js, "events", 6)); @@ -568,10 +568,10 @@ jsval_t events_library(ant_t *js) { void init_events_module() { ant_t *js = rt->js; - jsval_t global = js_glob(js); + ant_value_t global = js_glob(js); - jsval_t eventtarget_ctor = js_mkobj(js); - jsval_t eventtarget_proto = js_mkobj(js); + ant_value_t eventtarget_ctor = js_mkobj(js); + ant_value_t eventtarget_proto = js_mkobj(js); js_set(js, eventtarget_proto, "addEventListener", js_mkfun(js_add_event_listener_method)); js_set(js, eventtarget_proto, "removeEventListener", js_mkfun(js_remove_event_listener_method)); @@ -590,7 +590,7 @@ void init_events_module() { js_set(js, global, "EventTarget", js_obj_to_func(eventtarget_ctor)); } -void events_gc_update_roots(void (*op_val)(void *, jsval_t *), void *ctx) { +void events_gc_update_roots(void (*op_val)(void *, ant_value_t *), void *ctx) { EventType *evt, *tmp; HASH_ITER(hh, global_events, evt, tmp) { for (int i = 0; i < evt->listener_count; i++) op_val(ctx, &evt->listeners[i].listener); diff --git a/src/modules/fetch.c b/src/modules/fetch.c index 204f3f6..d12765f 100644 --- a/src/modules/fetch.c +++ b/src/modules/fetch.c @@ -25,7 +25,7 @@ typedef struct { typedef struct fetch_request_s { ant_t *js; - jsval_t promise; + ant_value_t promise; tlsuv_http_t http_client; tlsuv_http_req_t *http_req; fetch_buffer_t response_buffer; @@ -33,7 +33,7 @@ typedef struct fetch_request_s { int completed; int failed; char *error_msg; - jsval_t headers_obj; + ant_value_t headers_obj; char *method; char *body; size_t body_len; @@ -64,29 +64,29 @@ static void remove_pending_request(fetch_request_t *req) { } } -static jsval_t fetch_fail_oom(ant_t *js, jsval_t promise, fetch_request_t *req, bool close_http, const char *msg, size_t len) { - jsval_t err = js_mkstr(js, msg, len); +static ant_value_t fetch_fail_oom(ant_t *js, ant_value_t promise, fetch_request_t *req, bool close_http, const char *msg, size_t len) { + ant_value_t err = js_mkstr(js, msg, len); js_reject_promise(js, promise, err); if (close_http) tlsuv_http_close(&req->http_client, NULL); remove_pending_request(req); free_fetch_request(req); return js_mkundef(); } -static jsval_t response_text(ant_t *js, jsval_t *args, int nargs) { - jsval_t this = js_getthis(js); - jsval_t body = js_get_slot(js, this, SLOT_DATA); +static ant_value_t response_text(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this = js_getthis(js); + ant_value_t body = js_get_slot(js, this, SLOT_DATA); - jsval_t promise = js_mkpromise(js); + ant_value_t promise = js_mkpromise(js); js_resolve_promise(js, promise, body); return promise; } -static jsval_t response_json(ant_t *js, jsval_t *args, int nargs) { - jsval_t this = js_getthis(js); - jsval_t body = js_get_slot(js, this, SLOT_DATA); - jsval_t parsed = js_json_parse(js, &body, 1); - jsval_t promise = js_mkpromise(js); +static ant_value_t response_json(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this = js_getthis(js); + ant_value_t body = js_get_slot(js, this, SLOT_DATA); + ant_value_t parsed = js_json_parse(js, &body, 1); + ant_value_t promise = js_mkpromise(js); if (vtype(parsed) == T_ERR) { js_reject_promise(js, promise, parsed); @@ -95,9 +95,9 @@ static jsval_t response_json(ant_t *js, jsval_t *args, int nargs) { return promise; } -static jsval_t create_response(ant_t *js, int status, const char *body, size_t body_len) { - jsval_t response_obj = js_mkobj(js); - jsval_t body_str = js_mkstr(js, body, body_len); +static ant_value_t create_response(ant_t *js, int status, const char *body, size_t body_len) { + ant_value_t response_obj = js_mkobj(js); + ant_value_t body_str = js_mkstr(js, body, body_len); js_set(js, response_obj, "ok", js_bool(status >= 200 && status < 300)); js_set(js, response_obj, "status", js_mknum(status)); @@ -112,12 +112,12 @@ static jsval_t create_response(ant_t *js, int status, const char *body, size_t b static void complete_request(fetch_request_t *req) { if (req->failed) { - jsval_t err = js_mkstr(req->js, req->error_msg ? req->error_msg : "Unknown error", req->error_msg ? strlen(req->error_msg) : 13); + ant_value_t err = js_mkstr(req->js, req->error_msg ? req->error_msg : "Unknown error", req->error_msg ? strlen(req->error_msg) : 13); js_reject_promise(req->js, req->promise, err); } else { const char *body = req->response_buffer.data ? req->response_buffer.data : ""; size_t body_len = req->response_buffer.data ? req->response_buffer.size : 0; - jsval_t response = create_response(req->js, req->status_code, body, body_len); + ant_value_t response = create_response(req->js, req->status_code, body, body_len); js_resolve_promise(req->js, req->promise, response); } @@ -184,25 +184,25 @@ static void resp_cb(tlsuv_http_resp_t *resp, void *data) { resp->body_cb = body_cb; } -static jsval_t do_fetch_microtask(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t do_fetch_microtask(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t current_func = js_getcurrentfunc(js); - jsval_t url_val = js_get(js, current_func, "url"); - jsval_t options_val = js_get(js, current_func, "options"); - jsval_t promise = js_get_slot(js, current_func, SLOT_DATA); + ant_value_t current_func = js_getcurrentfunc(js); + ant_value_t url_val = js_get(js, current_func, "url"); + ant_value_t options_val = js_get(js, current_func, "options"); + ant_value_t promise = js_get_slot(js, current_func, SLOT_DATA); char *url_str = js_getstr(js, url_val, NULL); if (!url_str) { - jsval_t err = js_mkstr(js, "Invalid URL", 11); + ant_value_t err = js_mkstr(js, "Invalid URL", 11); js_reject_promise(js, promise, err); return js_mkundef(); } fetch_request_t *req = calloc(1, sizeof(fetch_request_t)); if (!req) { - jsval_t err = js_mkstr(js, "Out of memory", 13); + ant_value_t err = js_mkstr(js, "Out of memory", 13); js_reject_promise(js, promise, err); return js_mkundef(); } @@ -216,7 +216,7 @@ static jsval_t do_fetch_microtask(ant_t *js, jsval_t *args, int nargs) { req->response_buffer.size = 0; if (!req->response_buffer.data) { - jsval_t err = js_mkstr(js, "Out of memory", 13); + ant_value_t err = js_mkstr(js, "Out of memory", 13); js_reject_promise(js, promise, err); free(req); return js_mkundef(); @@ -254,7 +254,7 @@ static jsval_t do_fetch_microtask(ant_t *js, jsval_t *args, int nargs) { req->body_len = 0; if (is_special_object(options_val)) { - jsval_t method_val = js_get(js, options_val, "method"); + ant_value_t method_val = js_get(js, options_val, "method"); if (vtype(method_val) == T_STR) { char *str = js_getstr(js, method_val, NULL); if (str) { @@ -263,7 +263,7 @@ static jsval_t do_fetch_microtask(ant_t *js, jsval_t *args, int nargs) { } } - jsval_t body_val = js_get(js, options_val, "body"); + ant_value_t body_val = js_get(js, options_val, "body"); if (vtype(body_val) == T_STR) { size_t len; char *str = js_getstr(js, body_val, &len); @@ -290,12 +290,12 @@ static jsval_t do_fetch_microtask(ant_t *js, jsval_t *args, int nargs) { tlsuv_http_req_header(req->http_req, "User-Agent", user_agent); if (is_special_object(options_val)) { - jsval_t headers_val = js_get(js, options_val, "headers"); + ant_value_t headers_val = js_get(js, options_val, "headers"); if (is_special_object(headers_val)) { ant_iter_t iter = js_prop_iter_begin(js, headers_val); const char *key; size_t key_len; - jsval_t value; + ant_value_t value; while (js_prop_iter_next(&iter, &key, &key_len, &value)) { char *value_str = js_getstr(js, value, NULL); @@ -315,15 +315,15 @@ static jsval_t do_fetch_microtask(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t js_fetch(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_fetch(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "fetch requires at least 1 argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "fetch URL must be a string"); - jsval_t url_val = args[0]; - jsval_t options_val = nargs > 1 ? args[1] : js_mkundef(); + ant_value_t url_val = args[0]; + ant_value_t options_val = nargs > 1 ? args[1] : js_mkundef(); - jsval_t promise = js_mkpromise(js); - jsval_t wrapper_obj = js_mkobj(js); + ant_value_t promise = js_mkpromise(js); + ant_value_t wrapper_obj = js_mkobj(js); js_set_slot(js, wrapper_obj, SLOT_DATA, promise); js_set_slot(js, wrapper_obj, SLOT_CFUNC, js_mkfun(do_fetch_microtask)); diff --git a/src/modules/ffi.c b/src/modules/ffi.c index 2ec7588..2eed60c 100644 --- a/src/modules/ffi.c +++ b/src/modules/ffi.c @@ -26,7 +26,7 @@ typedef struct ffi_lib { char name[256]; void *handle; - jsval_t js_obj; + ant_value_t js_obj; UT_hash_handle hh; } ffi_lib_t; @@ -60,7 +60,7 @@ typedef struct ffi_callback { char **arg_type_strs; int arg_count; ant_t *js; - jsval_t js_func; + ant_value_t js_func; uint64_t cb_key; UT_hash_handle hh; } ffi_callback_t; @@ -82,26 +82,26 @@ static const UT_icd ffi_func_icd = { .dtor = NULL, }; -static jsval_t ffi_dlopen(ant_t *js, jsval_t *args, int nargs); -static jsval_t ffi_define(ant_t *js, jsval_t *args, int nargs); -static jsval_t ffi_lib_call(ant_t *js, jsval_t *args, int nargs); -static jsval_t ffi_call_function(ant_t *js, ffi_func_t *func, jsval_t *args, int nargs); -static jsval_t ffi_alloc_memory(ant_t *js, jsval_t *args, int nargs); -static jsval_t ffi_free_memory(ant_t *js, jsval_t *args, int nargs); -static jsval_t ffi_read_memory(ant_t *js, jsval_t *args, int nargs); -static jsval_t ffi_write_memory(ant_t *js, jsval_t *args, int nargs); -static jsval_t ffi_get_pointer(ant_t *js, jsval_t *args, int nargs); -static jsval_t ffi_create_callback(ant_t *js, jsval_t *args, int nargs); -static jsval_t ffi_free_callback(ant_t *js, jsval_t *args, int nargs); -static jsval_t ffi_read_ptr(ant_t *js, jsval_t *args, int nargs); +static ant_value_t ffi_dlopen(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t ffi_define(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t ffi_lib_call(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t ffi_call_function(ant_t *js, ffi_func_t *func, ant_value_t *args, int nargs); +static ant_value_t ffi_alloc_memory(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t ffi_free_memory(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t ffi_read_memory(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t ffi_write_memory(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t ffi_get_pointer(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t ffi_create_callback(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t ffi_free_callback(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t ffi_read_ptr(ant_t *js, ant_value_t *args, int nargs); static ffi_type *get_ffi_type(const char *type_str); -static void *js_to_ffi_value(ant_t *js, jsval_t val, ffi_type *type, void *buffer); -static jsval_t ffi_to_js_value(ant_t *js, void *val, ffi_type *type, const char *type_str); +static void *js_to_ffi_value(ant_t *js, ant_value_t val, ffi_type *type, void *buffer); +static ant_value_t ffi_to_js_value(ant_t *js, void *val, ffi_type *type, const char *type_str); static void ffi_callback_handler(ffi_cif *cif, void *ret, void **args, void *user_data); -jsval_t ffi_library(ant_t *js) { - jsval_t ffi_obj = js_mkobj(js); +ant_value_t ffi_library(ant_t *js) { + ant_value_t ffi_obj = js_mkobj(js); js_set(js, ffi_obj, "dlopen", js_mkfun(ffi_dlopen)); js_set(js, ffi_obj, "alloc", js_mkfun(ffi_alloc_memory)); @@ -125,7 +125,7 @@ jsval_t ffi_library(ant_t *js) { #endif js_set(js, ffi_obj, "suffix", js_mkstr(js, suffix, strlen(suffix))); - jsval_t ffi_types = js_mkobj(js); + ant_value_t ffi_types = js_mkobj(js); js_set(js, ffi_types, "void", js_mkstr(js, "void", 4)); js_set(js, ffi_types, "int8", js_mkstr(js, "int8", 4)); js_set(js, ffi_types, "int16", js_mkstr(js, "int16", 5)); @@ -154,7 +154,7 @@ static void ffi_init_array(void) { utarray_new(ffi_functions_array, &ffi_func_icd); } -static jsval_t ffi_dlopen(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t ffi_dlopen(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || vtype(args[0]) != T_STR) { return js_mkerr(js, "dlopen() requires library name string"); } @@ -169,7 +169,7 @@ static jsval_t ffi_dlopen(ant_t *js, jsval_t *args, int nargs) { ffi_lib_t *lib = NULL; HASH_FIND_STR(ffi_libraries, lib_name, lib); if (lib) { - jsval_t result = lib->js_obj; + ant_value_t result = lib->js_obj; pthread_mutex_unlock(&ffi_libraries_mutex); return result; } @@ -203,13 +203,13 @@ static jsval_t ffi_dlopen(ant_t *js, jsval_t *args, int nargs) { return lib->js_obj; } -static jsval_t ffi_define(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t ffi_define(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2 || vtype(args[0]) != T_STR) { return js_mkerr(js, "define() requires function name string and signature"); } - jsval_t this_obj = js_getthis(js); - jsval_t lib_ptr_val = js_get(js, this_obj, "__lib_ptr"); + ant_value_t this_obj = js_getthis(js); + ant_value_t lib_ptr_val = js_get(js, this_obj, "__lib_ptr"); if (vtype(lib_ptr_val) != T_NUM) { return js_mkerr(js, "Invalid library object"); } @@ -217,7 +217,7 @@ static jsval_t ffi_define(ant_t *js, jsval_t *args, int nargs) { size_t func_name_len; const char *func_name = js_getstr(js, args[0], &func_name_len); - jsval_t sig = args[1]; + ant_value_t sig = args[1]; int sig_type = vtype(sig); if (sig_type == T_STR || sig_type == T_NUM || sig_type == T_NULL || sig_type == T_UNDEF) { @@ -227,11 +227,11 @@ static jsval_t ffi_define(ant_t *js, jsval_t *args, int nargs) { } const char *ret_type_str; - jsval_t arg_types_arr; + ant_value_t arg_types_arr; int arg_count; - jsval_t returns_val = js_get(js, sig, "returns"); - jsval_t args_val = js_get(js, sig, "args"); + ant_value_t returns_val = js_get(js, sig, "returns"); + ant_value_t args_val = js_get(js, sig, "args"); if (vtype(returns_val) != T_UNDEF && vtype(args_val) != T_UNDEF) { if (vtype(returns_val) != T_STR) { @@ -246,10 +246,10 @@ static jsval_t ffi_define(ant_t *js, jsval_t *args, int nargs) { return js_mkerr(js, "Argument types must be an array"); } - jsval_t length_val = js_get(js, arg_types_arr, "length"); + ant_value_t length_val = js_get(js, arg_types_arr, "length"); arg_count = (int)js_getnum(length_val); } else { - jsval_t ret_type_val = js_get(js, sig, "0"); + ant_value_t ret_type_val = js_get(js, sig, "0"); if (vtype(ret_type_val) != T_STR) { return js_mkerr(js, "Return type must be a string"); } @@ -263,7 +263,7 @@ static jsval_t ffi_define(ant_t *js, jsval_t *args, int nargs) { return js_mkerr(js, "Argument types must be an array"); } - jsval_t length_val = js_get(js, arg_types_arr, "length"); + ant_value_t length_val = js_get(js, arg_types_arr, "length"); arg_count = (int)js_getnum(length_val); } @@ -302,7 +302,7 @@ static jsval_t ffi_define(ant_t *js, jsval_t *args, int nargs) { for (int i = 0; i < arg_count; i++) { char idx_str[16]; snprintf(idx_str, sizeof(idx_str), "%d", i); - jsval_t arg_type_val = js_get(js, arg_types_arr, idx_str); + ant_value_t arg_type_val = js_get(js, arg_types_arr, idx_str); if (vtype(arg_type_val) != T_STR) { free(func->arg_types); @@ -350,15 +350,15 @@ static jsval_t ffi_define(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t ffi_lib_call(ant_t *js, jsval_t *args, int nargs) { - jsval_t lib_obj = js_getthis(js); +static ant_value_t ffi_lib_call(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t lib_obj = js_getthis(js); if (nargs < 1 || vtype(args[0]) != T_STR) return js_mkerr(js, "call() requires function name string"); size_t func_name_len; const char *func_name = js_getstr(js, args[0], &func_name_len); - jsval_t ffi_val = js_get(js, lib_obj, func_name); + ant_value_t ffi_val = js_get(js, lib_obj, func_name); int func_index = js_getffi(ffi_val); if (func_index < 0) { return js_mkerr(js, "Function '%s' not defined", func_name); @@ -367,7 +367,7 @@ static jsval_t ffi_lib_call(ant_t *js, jsval_t *args, int nargs) { return ffi_call_by_index(js, (unsigned int)func_index, args + 1, nargs - 1); } -static jsval_t ffi_call_function(ant_t *js, ffi_func_t *func, jsval_t *args,int nargs) { +static ant_value_t ffi_call_function(ant_t *js, ffi_func_t *func, ant_value_t *args,int nargs) { if (!func->is_variadic && nargs != func->arg_count) { return js_mkerr(js, "Function '%s' expects %d arguments, got %d", func->name, func->arg_count, nargs); } @@ -432,7 +432,7 @@ static jsval_t ffi_call_function(ant_t *js, ffi_func_t *func, jsval_t *args,int return ffi_to_js_value(js, &result, func->ret_type, func->ret_type_str); } -jsval_t ffi_call_by_index(ant_t *js, unsigned int func_index, jsval_t *args, int nargs) { +ant_value_t ffi_call_by_index(ant_t *js, unsigned int func_index, ant_value_t *args, int nargs) { pthread_mutex_lock(&ffi_functions_mutex); if (func_index >= utarray_len(ffi_functions_array)) { pthread_mutex_unlock(&ffi_functions_mutex); @@ -445,7 +445,7 @@ jsval_t ffi_call_by_index(ant_t *js, unsigned int func_index, jsval_t *args, int return ffi_call_function(js, func, args, nargs); } -static jsval_t ffi_alloc_memory(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t ffi_alloc_memory(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || vtype(args[0]) != T_NUM) { return js_mkerr(js, "alloc() requires size"); } @@ -478,7 +478,7 @@ static jsval_t ffi_alloc_memory(ant_t *js, jsval_t *args, int nargs) { return js_mknum((double)ffi_ptr->ptr_key); } -static jsval_t ffi_free_memory(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t ffi_free_memory(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || vtype(args[0]) != T_NUM) { return js_mkerr(js, "free() requires pointer"); } @@ -505,7 +505,7 @@ static jsval_t ffi_free_memory(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t ffi_read_memory(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t ffi_read_memory(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2 || vtype(args[0]) != T_NUM || vtype(args[1]) != T_STR) { return js_mkerr(js, "read() requires pointer and type"); } @@ -533,7 +533,7 @@ static jsval_t ffi_read_memory(ant_t *js, jsval_t *args, int nargs) { return ffi_to_js_value(js, ptr, type, type_str); } -static jsval_t ffi_write_memory(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t ffi_write_memory(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 3 || vtype(args[0]) != T_NUM || vtype(args[1]) != T_STR) { return js_mkerr(js, "write() requires pointer, type, and value"); } @@ -563,7 +563,7 @@ static jsval_t ffi_write_memory(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t ffi_get_pointer(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t ffi_get_pointer(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || vtype(args[0]) != T_NUM) return js_mkerr(js, "pointer() requires pointer"); uint64_t ptr_key = (uint64_t)js_getnum(args[0]); @@ -576,7 +576,7 @@ static jsval_t ffi_get_pointer(ant_t *js, jsval_t *args, int nargs) { return js_bool(exists); } -static jsval_t ffi_read_ptr(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t ffi_read_ptr(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2 || vtype(args[0]) != T_NUM || vtype(args[1]) != T_STR) { return js_mkerr(js, "readPtr() requires pointer and type"); } @@ -602,14 +602,14 @@ static void ffi_callback_handler(ffi_cif *cif, void *ret, void **args, void *use ffi_callback_t *cb = (ffi_callback_t *)user_data; ant_t *js = cb->js; - jsval_t js_args[32]; + ant_value_t js_args[32]; int arg_count = cb->arg_count > 32 ? 32 : cb->arg_count; for (int i = 0; i < arg_count; i++) { js_args[i] = ffi_to_js_value(js, args[i], cb->arg_types[i], cb->arg_type_strs[i]); } - jsval_t result = sv_vm_call(js->vm, js, cb->js_func, js_mkundef(), js_args, arg_count, NULL, false); + ant_value_t result = sv_vm_call(js->vm, js, cb->js_func, js_mkundef(), js_args, arg_count, NULL, false); if (cb->ret_type != &ffi_type_void) { if (cb->ret_type == &ffi_type_sint8) { @@ -640,35 +640,35 @@ static void ffi_callback_handler(ffi_cif *cif, void *ret, void **args, void *use } } -static jsval_t ffi_create_callback(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t ffi_create_callback(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "callback() requires function and signature"); - jsval_t js_func = args[0]; - jsval_t sig = args[1]; + ant_value_t js_func = args[0]; + ant_value_t sig = args[1]; int sig_type = vtype(sig); if (sig_type == T_STR || sig_type == T_NUM || sig_type == T_NULL || sig_type == T_UNDEF) { return js_mkerr(js, "Signature must be an object {args: [...], returns: type}"); } const char *ret_type_str; - jsval_t arg_types_arr; + ant_value_t arg_types_arr; int arg_count; - jsval_t returns_val = js_get(js, sig, "returns"); - jsval_t args_val = js_get(js, sig, "args"); + ant_value_t returns_val = js_get(js, sig, "returns"); + ant_value_t args_val = js_get(js, sig, "args"); if (vtype(returns_val) != T_UNDEF && vtype(args_val) != T_UNDEF) { if (vtype(returns_val) != T_STR) return js_mkerr(js, "Return type must be a string"); ret_type_str = js_getstr(js, returns_val, NULL); arg_types_arr = args_val; - jsval_t length_val = js_get(js, arg_types_arr, "length"); + ant_value_t length_val = js_get(js, arg_types_arr, "length"); arg_count = (int)js_getnum(length_val); } else { - jsval_t ret_type_val = js_get(js, sig, "0"); + ant_value_t ret_type_val = js_get(js, sig, "0"); if (vtype(ret_type_val) != T_STR) return js_mkerr(js, "Return type must be a string"); ret_type_str = js_getstr(js, ret_type_val, NULL); arg_types_arr = js_get(js, sig, "1"); - jsval_t length_val = js_get(js, arg_types_arr, "length"); + ant_value_t length_val = js_get(js, arg_types_arr, "length"); arg_count = (int)js_getnum(length_val); } @@ -698,7 +698,7 @@ static jsval_t ffi_create_callback(ant_t *js, jsval_t *args, int nargs) { for (int i = 0; i < arg_count; i++) { char idx_str[16]; snprintf(idx_str, sizeof(idx_str), "%d", i); - jsval_t arg_type_val = js_get(js, arg_types_arr, idx_str); + ant_value_t arg_type_val = js_get(js, arg_types_arr, idx_str); if (vtype(arg_type_val) != T_STR) { for (int j = 0; j < i; j++) free(cb->arg_type_strs[j]); @@ -761,7 +761,7 @@ static jsval_t ffi_create_callback(ant_t *js, jsval_t *args, int nargs) { return js_mknum((double)cb->cb_key); } -static jsval_t ffi_free_callback(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t ffi_free_callback(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || vtype(args[0]) != T_NUM) { return js_mkerr(js, "freeCallback() requires callback pointer"); } @@ -855,7 +855,7 @@ static ffi_type *get_ffi_type(const char *type_str) { return type_map[id]; } -static void *js_to_ffi_value(ant_t *js, jsval_t val, ffi_type *type, void *buffer) { +static void *js_to_ffi_value(ant_t *js, ant_value_t val, ffi_type *type, void *buffer) { static const void *dispatch[] = { &&do_sint8, &&do_sint16, &&do_sint32, &&do_sint64, &&do_uint8, &&do_uint16, &&do_uint64, @@ -938,7 +938,7 @@ do_done: return buffer; } -static jsval_t ffi_to_js_value(ant_t *js, void *val, ffi_type *type, const char *type_str) { +static ant_value_t ffi_to_js_value(ant_t *js, void *val, ffi_type *type, const char *type_str) { static const void *dispatch[] = { &&ret_void, &&ret_sint8, &&ret_sint16, &&ret_sint32, &&ret_sint64, &&ret_uint8, &&ret_uint16, &&ret_uint64, diff --git a/src/modules/fs.c b/src/modules/fs.c index 53a43d4..a8f6fcc 100644 --- a/src/modules/fs.c +++ b/src/modules/fs.c @@ -24,7 +24,7 @@ #include "modules/symbol.h" #define fs_err_code(js, code, op, path) ({ \ - jsval_t _props = js_mkobj(js); \ + ant_value_t _props = js_mkobj(js); \ js_set(js, _props, "code", js_mkstr(js, code, strlen(code))); \ js_mkerr_props(js, JS_ERR_TYPE, _props, "%s: %s, %s '%s'", code, strerror(errno), op, path); \ }) @@ -40,22 +40,22 @@ typedef enum { FS_ENC_ASCII, } fs_encoding_t; -static jsval_t fs_coerce_path(ant_t *js, jsval_t arg) { +static ant_value_t fs_coerce_path(ant_t *js, ant_value_t arg) { if (vtype(arg) == T_STR) return arg; if (is_object_type(arg)) { - jsval_t pathname = js_get(js, arg, "pathname"); + ant_value_t pathname = js_get(js, arg, "pathname"); if (vtype(pathname) == T_STR) return pathname; } return js_mkundef(); } -static fs_encoding_t parse_encoding(ant_t *js, jsval_t arg) { +static fs_encoding_t parse_encoding(ant_t *js, ant_value_t arg) { size_t len; const char *str = NULL; if (vtype(arg) == T_STR) str = js_getstr(js, arg, &len); else if (vtype(arg) == T_OBJ) { - jsval_t enc = js_get(js, arg, "encoding"); + ant_value_t enc = js_get(js, arg, "encoding"); if (vtype(enc) == T_STR) str = js_getstr(js, enc, &len); } @@ -76,7 +76,7 @@ static fs_encoding_t parse_encoding(ant_t *js, jsval_t arg) { return FS_ENC_NONE; } -static jsval_t encode_data(ant_t *js, const char *data, size_t len, fs_encoding_t enc) { +static ant_value_t encode_data(ant_t *js, const char *data, size_t len, fs_encoding_t enc) { switch (enc) { case FS_ENC_UTF8: case FS_ENC_LATIN1: @@ -89,7 +89,7 @@ static jsval_t encode_data(ant_t *js, const char *data, size_t len, fs_encoding_ out[i * 2] = hex_char((unsigned char)data[i] >> 4); out[i * 2 + 1] = hex_char(data[i]); } - jsval_t result = js_mkstr(js, out, len * 2); + ant_value_t result = js_mkstr(js, out, len * 2); free(out); return result; } @@ -97,7 +97,7 @@ static jsval_t encode_data(ant_t *js, const char *data, size_t len, fs_encoding_ size_t out_len; char *out = ant_base64_encode((const uint8_t *)data, len, &out_len); if (!out) return js_mkerr(js, "Out of memory"); - jsval_t result = js_mkstr(js, out, out_len); + ant_value_t result = js_mkstr(js, out, out_len); free(out); return result; } @@ -110,7 +110,7 @@ static jsval_t encode_data(ant_t *js, const char *data, size_t len, fs_encoding_ else if (out[i] == '/') out[i] = '_'; } while (out_len > 0 && out[out_len - 1] == '=') out_len--; - jsval_t result = js_mkstr(js, out, out_len); + ant_value_t result = js_mkstr(js, out, out_len); free(out); return result; } @@ -127,7 +127,7 @@ static jsval_t encode_data(ant_t *js, const char *data, size_t len, fs_encoding_ if (is_pair) { cp = 0x10000 + ((cp - 0xD800) << 10) + (lo - 0xDC00); i += 2; } j += utf8_encode(cp, out + j); } - jsval_t result = js_mkstr(js, out, j); + ant_value_t result = js_mkstr(js, out, j); free(out); return result; } @@ -154,7 +154,7 @@ typedef enum { typedef struct fs_request_s { uv_fs_t uv_req; ant_t *js; - jsval_t promise; + ant_value_t promise; char *path; char *data; char *error_msg; @@ -190,11 +190,11 @@ static void remove_pending_request(fs_request_t *req) { } } -static jsval_t fs_read_to_uint8array(ant_t *js, const char *data, size_t len) { +static ant_value_t fs_read_to_uint8array(ant_t *js, const char *data, size_t len) { ArrayBufferData *ab = create_array_buffer_data(len); if (!ab) return js_mkundef(); memcpy(ab->data, data, len); - jsval_t result = create_typed_array(js, TYPED_ARRAY_UINT8, ab, 0, len, "Buffer"); + ant_value_t result = create_typed_array(js, TYPED_ARRAY_UINT8, ab, 0, len, "Buffer"); if (vtype(result) == T_ERR) free_array_buffer_data(ab); return result; } @@ -202,7 +202,7 @@ static jsval_t fs_read_to_uint8array(ant_t *js, const char *data, size_t len) { static void complete_request(fs_request_t *req) { if (req->failed) { const char *err_msg = req->error_msg ? req->error_msg : "Unknown error"; - jsval_t reject_value = js_mkerr(req->js, "%s", err_msg); + ant_value_t reject_value = js_mkerr(req->js, "%s", err_msg); if (is_err(reject_value)) { reject_value = req->js->thrown_value; if (vtype(reject_value) == T_UNDEF) { @@ -213,7 +213,7 @@ static void complete_request(fs_request_t *req) { } js_reject_promise(req->js, req->promise, reject_value); } else { - jsval_t result = js_mkundef(); + ant_value_t result = js_mkundef(); if (req->op_type == FS_OP_READ && req->data) { if (req->encoding != FS_ENC_NONE) result = encode_data(req->js, req->data, req->data_len, req->encoding); @@ -403,8 +403,8 @@ static void on_stat_complete(uv_fs_t *uv_req) { return; } - jsval_t stat_obj = js_mkobj(req->js); - jsval_t proto = js_get_ctor_proto(req->js, "Stats", 5); + ant_value_t stat_obj = js_mkobj(req->js); + ant_value_t proto = js_get_ctor_proto(req->js, "Stats", 5); if (is_object_type(proto)) js_set_proto(req->js, stat_obj, proto); uv_stat_t *st = &uv_req->statbuf; @@ -422,7 +422,7 @@ static void on_stat_complete(uv_fs_t *uv_req) { static void on_exists_complete(uv_fs_t *uv_req) { fs_request_t *req = (fs_request_t *)uv_req->data; - jsval_t result = js_bool(uv_req->result >= 0); + ant_value_t result = js_bool(uv_req->result >= 0); req->completed = 1; js_resolve_promise(req->js, req->promise, result); @@ -458,11 +458,11 @@ static void on_readdir_complete(uv_fs_t *uv_req) { return; } - jsval_t arr = js_mkarr(req->js); + ant_value_t arr = js_mkarr(req->js); uv_dirent_t dirent; while (uv_fs_scandir_next(uv_req, &dirent) != UV_EOF) { - jsval_t name = js_mkstr(req->js, dirent.name, strlen(dirent.name)); + ant_value_t name = js_mkstr(req->js, dirent.name, strlen(dirent.name)); js_arr_push(req->js, arr, name); } @@ -472,10 +472,10 @@ static void on_readdir_complete(uv_fs_t *uv_req) { free_fs_request(req); } -static jsval_t builtin_fs_readFileSync(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_readFileSync(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "readFileSync() requires a path argument"); - jsval_t path_val = fs_coerce_path(js, args[0]); + ant_value_t path_val = fs_coerce_path(js, args[0]); if (vtype(path_val) != T_STR) return js_mkerr(js, "readFileSync() path must be a string or URL"); size_t path_len; @@ -519,7 +519,7 @@ static jsval_t builtin_fs_readFileSync(ant_t *js, jsval_t *args, int nargs) { } fs_encoding_t enc = (nargs > 1) ? parse_encoding(js, args[1]) : FS_ENC_NONE; - jsval_t result = (enc != FS_ENC_NONE) + ant_value_t result = (enc != FS_ENC_NONE) ? encode_data(js, data, file_size, enc) : fs_read_to_uint8array(js, data, file_size); @@ -527,7 +527,7 @@ static jsval_t builtin_fs_readFileSync(ant_t *js, jsval_t *args, int nargs) { return result; } -static jsval_t builtin_fs_readBytesSync(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_readBytesSync(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "readBytesSync() requires a path argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "readBytesSync() path must be a string"); @@ -571,13 +571,13 @@ static jsval_t builtin_fs_readBytesSync(ant_t *js, jsval_t *args, int nargs) { return js_mkerr(js, "Failed to read entire file"); } - jsval_t result = js_mkstr(js, data, file_size); + ant_value_t result = js_mkstr(js, data, file_size); free(data); return result; } -static jsval_t builtin_fs_readFile(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_readFile(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "readFile() requires a path argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "readFile() path must be a string"); @@ -610,7 +610,7 @@ static jsval_t builtin_fs_readFile(ant_t *js, jsval_t *args, int nargs) { return req->promise; } -static jsval_t builtin_fs_readBytes(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_readBytes(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "readBytes() requires a path argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "readBytes() path must be a string"); @@ -642,7 +642,7 @@ static jsval_t builtin_fs_readBytes(ant_t *js, jsval_t *args, int nargs) { return req->promise; } -static jsval_t builtin_fs_writeFileSync(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_writeFileSync(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "writeFileSync() requires path and data arguments"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "writeFileSync() path must be a string"); @@ -675,7 +675,7 @@ static jsval_t builtin_fs_writeFileSync(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t builtin_fs_copyFileSync(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_copyFileSync(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "copyFileSync() requires src and dest arguments"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "copyFileSync() src must be a string"); @@ -732,7 +732,7 @@ static jsval_t builtin_fs_copyFileSync(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t builtin_fs_renameSync(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_renameSync(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "renameSync() requires oldPath and newPath arguments"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "renameSync() oldPath must be a string"); @@ -765,7 +765,7 @@ static jsval_t builtin_fs_renameSync(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t builtin_fs_appendFileSync(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_appendFileSync(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "appendFileSync() requires path and data arguments"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "appendFileSync() path must be a string"); @@ -798,7 +798,7 @@ static jsval_t builtin_fs_appendFileSync(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t builtin_fs_writeFile(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_writeFile(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "writeFile() requires path and data arguments"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "writeFile() path must be a string"); @@ -842,7 +842,7 @@ static jsval_t builtin_fs_writeFile(ant_t *js, jsval_t *args, int nargs) { return req->promise; } -static jsval_t builtin_fs_unlinkSync(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_unlinkSync(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "unlinkSync() requires a path argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "unlinkSync() path must be a string"); @@ -866,7 +866,7 @@ static jsval_t builtin_fs_unlinkSync(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t builtin_fs_unlink(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_unlink(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "unlink() requires a path argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "unlink() path must be a string"); @@ -898,7 +898,7 @@ static jsval_t builtin_fs_unlink(ant_t *js, jsval_t *args, int nargs) { return req->promise; } -static jsval_t builtin_fs_mkdirSync(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_mkdirSync(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "mkdirSync() requires a path argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "mkdirSync() path must be a string"); @@ -917,9 +917,9 @@ static jsval_t builtin_fs_mkdirSync(ant_t *js, jsval_t *args, int nargs) { mode = (int)js_getnum(args[1]); break; case T_OBJ: { - jsval_t opt = args[1]; + ant_value_t opt = args[1]; recursive = js_get(js, opt, "recursive") == js_true; - jsval_t mode_val = js_get(js, opt, "mode"); + ant_value_t mode_val = js_get(js, opt, "mode"); if (vtype(mode_val) == T_NUM) mode = (int)js_getnum(mode_val); break; } @@ -950,7 +950,7 @@ do_mkdir: return js_mkundef(); } -static jsval_t builtin_fs_mkdir(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_mkdir(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "mkdir() requires a path argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "mkdir() path must be a string"); @@ -967,9 +967,9 @@ static jsval_t builtin_fs_mkdir(ant_t *js, jsval_t *args, int nargs) { mode = (int)js_getnum(args[1]); break; case T_OBJ: { - jsval_t opt = args[1]; + ant_value_t opt = args[1]; recursive = js_get(js, opt, "recursive") == js_true; - jsval_t mode_val = js_get(js, opt, "mode"); + ant_value_t mode_val = js_get(js, opt, "mode"); if (vtype(mode_val) == T_NUM) mode = (int)js_getnum(mode_val); break; } @@ -1004,7 +1004,7 @@ static jsval_t builtin_fs_mkdir(ant_t *js, jsval_t *args, int nargs) { return req->promise; } -static jsval_t builtin_fs_rmdirSync(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_rmdirSync(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "rmdirSync() requires a path argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "rmdirSync() path must be a string"); @@ -1032,7 +1032,7 @@ static jsval_t builtin_fs_rmdirSync(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t builtin_fs_rmdir(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_rmdir(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "rmdir() requires a path argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "rmdir() path must be a string"); @@ -1064,9 +1064,9 @@ static jsval_t builtin_fs_rmdir(ant_t *js, jsval_t *args, int nargs) { return req->promise; } -static jsval_t stat_isFile(ant_t *js, jsval_t *args, int nargs) { - jsval_t this = js_getthis(js); - jsval_t mode_val = js_get_slot(js, this, SLOT_DATA); +static ant_value_t stat_isFile(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this = js_getthis(js); + ant_value_t mode_val = js_get_slot(js, this, SLOT_DATA); if (vtype(mode_val) != T_NUM) return js_false; mode_t mode = (mode_t)js_getnum(mode_val); @@ -1074,9 +1074,9 @@ static jsval_t stat_isFile(ant_t *js, jsval_t *args, int nargs) { return js_bool(S_ISREG(mode)); } -static jsval_t stat_isDirectory(ant_t *js, jsval_t *args, int nargs) { - jsval_t this = js_getthis(js); - jsval_t mode_val = js_get_slot(js, this, SLOT_DATA); +static ant_value_t stat_isDirectory(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this = js_getthis(js); + ant_value_t mode_val = js_get_slot(js, this, SLOT_DATA); if (vtype(mode_val) != T_NUM) return js_false; mode_t mode = (mode_t)js_getnum(mode_val); @@ -1084,9 +1084,9 @@ static jsval_t stat_isDirectory(ant_t *js, jsval_t *args, int nargs) { return js_bool(S_ISDIR(mode)); } -static jsval_t stat_isSymbolicLink(ant_t *js, jsval_t *args, int nargs) { - jsval_t this = js_getthis(js); - jsval_t mode_val = js_get_slot(js, this, SLOT_DATA); +static ant_value_t stat_isSymbolicLink(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this = js_getthis(js); + ant_value_t mode_val = js_get_slot(js, this, SLOT_DATA); if (vtype(mode_val) != T_NUM) return js_false; mode_t mode = (mode_t)js_getnum(mode_val); @@ -1094,9 +1094,9 @@ static jsval_t stat_isSymbolicLink(ant_t *js, jsval_t *args, int nargs) { return js_bool(S_ISLNK(mode)); } -static jsval_t create_stats_object(ant_t *js, struct stat *st) { - jsval_t stat_obj = js_mkobj(js); - jsval_t proto = js_get_ctor_proto(js, "Stats", 5); +static ant_value_t create_stats_object(ant_t *js, struct stat *st) { + ant_value_t stat_obj = js_mkobj(js); + ant_value_t proto = js_get_ctor_proto(js, "Stats", 5); if (is_special_object(proto)) js_set_proto(js, stat_obj, proto); js_set_slot(js, stat_obj, SLOT_DATA, js_mknum((double)st->st_mode)); @@ -1129,7 +1129,7 @@ static const char *errno_to_code(int err_num) { } } -static jsval_t builtin_fs_statSync(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_statSync(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "statSync() requires a path argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "statSync() path must be a string"); @@ -1146,7 +1146,7 @@ static jsval_t builtin_fs_statSync(ant_t *js, jsval_t *args, int nargs) { if (result != 0) { const char *code = errno_to_code(errno); - jsval_t err = fs_err_code(js, code, "stat", path_cstr); + ant_value_t err = fs_err_code(js, code, "stat", path_cstr); free(path_cstr); return err; } @@ -1154,7 +1154,7 @@ static jsval_t builtin_fs_statSync(ant_t *js, jsval_t *args, int nargs) { return create_stats_object(js, &st); } -static jsval_t builtin_fs_stat(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_stat(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "stat() requires a path argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "stat() path must be a string"); @@ -1186,7 +1186,7 @@ static jsval_t builtin_fs_stat(ant_t *js, jsval_t *args, int nargs) { return req->promise; } -static jsval_t builtin_fs_existsSync(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_existsSync(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "existsSync() requires a path argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "existsSync() path must be a string"); @@ -1205,7 +1205,7 @@ static jsval_t builtin_fs_existsSync(ant_t *js, jsval_t *args, int nargs) { return js_bool(result == 0); } -static jsval_t builtin_fs_exists(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_exists(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "exists() requires a path argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "exists() path must be a string"); @@ -1237,7 +1237,7 @@ static jsval_t builtin_fs_exists(ant_t *js, jsval_t *args, int nargs) { return req->promise; } -static jsval_t builtin_fs_accessSync(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_accessSync(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "accessSync() requires a path argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "accessSync() path must be a string"); @@ -1257,7 +1257,7 @@ static jsval_t builtin_fs_accessSync(ant_t *js, jsval_t *args, int nargs) { if (result != 0) { const char *code = errno_to_code(errno); - jsval_t err = fs_err_code(js, code, "access", path_cstr); + ant_value_t err = fs_err_code(js, code, "access", path_cstr); free(path_cstr); return err; } @@ -1265,7 +1265,7 @@ static jsval_t builtin_fs_accessSync(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t builtin_fs_access(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_access(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "access() requires a path argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "access() path must be a string"); @@ -1302,7 +1302,7 @@ static jsval_t builtin_fs_access(ant_t *js, jsval_t *args, int nargs) { return req->promise; } -static jsval_t builtin_fs_readdirSync(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_readdirSync(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "readdirSync() requires a path argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "readdirSync() path must be a string"); @@ -1324,11 +1324,11 @@ static jsval_t builtin_fs_readdirSync(ant_t *js, jsval_t *args, int nargs) { uv_fs_req_cleanup(&req); return js_mkerr(js, "%s", err_msg); } - jsval_t arr = js_mkarr(js); + ant_value_t arr = js_mkarr(js); uv_dirent_t dirent; while (uv_fs_scandir_next(&req, &dirent) != UV_EOF) { - jsval_t name = js_mkstr(js, dirent.name, strlen(dirent.name)); + ant_value_t name = js_mkstr(js, dirent.name, strlen(dirent.name)); js_arr_push(js, arr, name); } @@ -1336,7 +1336,7 @@ static jsval_t builtin_fs_readdirSync(ant_t *js, jsval_t *args, int nargs) { return arr; } -static jsval_t builtin_fs_readdir(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_readdir(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "readdir() requires a path argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "readdir() path must be a string"); @@ -1385,13 +1385,13 @@ static void on_write_fd_complete(uv_fs_t *uv_req) { free_fs_request(req); } -static jsval_t builtin_fs_readSync(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_readSync(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "readSync() requires fd and buffer arguments"); if (vtype(args[0]) != T_NUM) return js_mkerr(js, "readSync() fd must be a number"); int fd = (int)js_getnum(args[0]); - jsval_t ta_data_val = js_get_slot(js, args[1], SLOT_BUFFER); + ant_value_t ta_data_val = js_get_slot(js, args[1], SLOT_BUFFER); TypedArrayData *ta_data = (TypedArrayData *)js_gettypedarray(ta_data_val); if (!ta_data || !ta_data->buffer || !ta_data->buffer->data) return js_mkerr(js, "readSync() second argument must be a Buffer, TypedArray, or DataView"); @@ -1404,9 +1404,9 @@ static jsval_t builtin_fs_readSync(ant_t *js, jsval_t *args, int nargs) { if (nargs >= 3) { if (vtype(args[2]) == T_OBJ) { - jsval_t off_val = js_get(js, args[2], "offset"); - jsval_t len_val = js_get(js, args[2], "length"); - jsval_t pos_val = js_get(js, args[2], "position"); + ant_value_t off_val = js_get(js, args[2], "offset"); + ant_value_t len_val = js_get(js, args[2], "length"); + ant_value_t pos_val = js_get(js, args[2], "position"); if (vtype(off_val) == T_NUM) offset = (size_t)js_getnum(off_val); if (vtype(len_val) == T_NUM) length = (size_t)js_getnum(len_val); else length = buf_len - offset; @@ -1431,7 +1431,7 @@ static jsval_t builtin_fs_readSync(ant_t *js, jsval_t *args, int nargs) { return js_mknum((double)result); } -static jsval_t builtin_fs_writeSync(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_writeSync(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "writeSync() requires fd and data arguments"); if (vtype(args[0]) != T_NUM) return js_mkerr(js, "writeSync() fd must be a number"); @@ -1455,7 +1455,7 @@ static jsval_t builtin_fs_writeSync(ant_t *js, jsval_t *args, int nargs) { return js_mknum((double)result); } - jsval_t ta_data_val = js_get_slot(js, args[1], SLOT_BUFFER); + ant_value_t ta_data_val = js_get_slot(js, args[1], SLOT_BUFFER); TypedArrayData *ta_data = (TypedArrayData *)js_gettypedarray(ta_data_val); if (!ta_data || !ta_data->buffer || !ta_data->buffer->data) return js_mkerr(js, "writeSync() second argument must be a Buffer, TypedArray, DataView, or string"); @@ -1468,9 +1468,9 @@ static jsval_t builtin_fs_writeSync(ant_t *js, jsval_t *args, int nargs) { if (nargs >= 3) { if (vtype(args[2]) == T_OBJ) { - jsval_t off_val = js_get(js, args[2], "offset"); - jsval_t len_val = js_get(js, args[2], "length"); - jsval_t pos_val = js_get(js, args[2], "position"); + ant_value_t off_val = js_get(js, args[2], "offset"); + ant_value_t len_val = js_get(js, args[2], "length"); + ant_value_t pos_val = js_get(js, args[2], "position"); if (vtype(off_val) == T_NUM) offset = (size_t)js_getnum(off_val); if (vtype(len_val) == T_NUM) length = (size_t)js_getnum(len_val); else length = buf_len - offset; @@ -1495,7 +1495,7 @@ static jsval_t builtin_fs_writeSync(ant_t *js, jsval_t *args, int nargs) { return js_mknum((double)result); } -static jsval_t builtin_fs_write_fd(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_write_fd(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "write() requires fd and data arguments"); if (vtype(args[0]) != T_NUM) return js_mkerr(js, "write() fd must be a number"); @@ -1515,7 +1515,7 @@ static jsval_t builtin_fs_write_fd(ant_t *js, jsval_t *args, int nargs) { write_data = str; write_len = str_len; } else { - jsval_t ta_data_val = js_get_slot(js, args[1], SLOT_BUFFER); + ant_value_t ta_data_val = js_get_slot(js, args[1], SLOT_BUFFER); TypedArrayData *ta_data = (TypedArrayData *)js_gettypedarray(ta_data_val); if (!ta_data || !ta_data->buffer || !ta_data->buffer->data) return js_mkerr(js, "write() second argument must be a Buffer, TypedArray, DataView, or string"); @@ -1527,9 +1527,9 @@ static jsval_t builtin_fs_write_fd(ant_t *js, jsval_t *args, int nargs) { if (nargs >= 3) { if (vtype(args[2]) == T_OBJ) { - jsval_t off_val = js_get(js, args[2], "offset"); - jsval_t len_val = js_get(js, args[2], "length"); - jsval_t pos_val = js_get(js, args[2], "position"); + ant_value_t off_val = js_get(js, args[2], "offset"); + ant_value_t len_val = js_get(js, args[2], "length"); + ant_value_t pos_val = js_get(js, args[2], "position"); if (vtype(off_val) == T_NUM) offset = (size_t)js_getnum(off_val); if (vtype(len_val) == T_NUM) length = (size_t)js_getnum(len_val); else length = buf_len - offset; @@ -1580,12 +1580,12 @@ static jsval_t builtin_fs_write_fd(ant_t *js, jsval_t *args, int nargs) { return req->promise; } -static jsval_t builtin_fs_writevSync(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_writevSync(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "writevSync() requires fd and buffers arguments"); if (vtype(args[0]) != T_NUM) return js_mkerr(js, "writevSync() fd must be a number"); int fd = (int)js_getnum(args[0]); - jsoff_t arr_len = js_arr_len(js, args[1]); + ant_offset_t arr_len = js_arr_len(js, args[1]); if (arr_len == 0) return js_mknum(0); int64_t position = -1; @@ -1595,9 +1595,9 @@ static jsval_t builtin_fs_writevSync(ant_t *js, jsval_t *args, int nargs) { uv_buf_t *bufs = calloc((size_t)arr_len, sizeof(uv_buf_t)); if (!bufs) return js_mkerr(js, "Out of memory"); - for (jsoff_t i = 0; i < arr_len; i++) { - jsval_t item = js_arr_get(js, args[1], i); - jsval_t ta_val = js_get_slot(js, item, SLOT_BUFFER); + for (ant_offset_t i = 0; i < arr_len; i++) { + ant_value_t item = js_arr_get(js, args[1], i); + ant_value_t ta_val = js_get_slot(js, item, SLOT_BUFFER); TypedArrayData *ta = (TypedArrayData *)js_gettypedarray(ta_val); if (!ta || !ta->buffer || !ta->buffer->data) { free(bufs); @@ -1615,15 +1615,15 @@ static jsval_t builtin_fs_writevSync(ant_t *js, jsval_t *args, int nargs) { return js_mknum((double)result); } -static jsval_t builtin_fs_writev_fd(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_writev_fd(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "writev() requires fd and buffers arguments"); if (vtype(args[0]) != T_NUM) return js_mkerr(js, "writev() fd must be a number"); int fd = (int)js_getnum(args[0]); - jsoff_t arr_len = js_arr_len(js, args[1]); + ant_offset_t arr_len = js_arr_len(js, args[1]); if (arr_len == 0) { - jsval_t promise = js_mkpromise(js); + ant_value_t promise = js_mkpromise(js); js_resolve_promise(js, promise, js_mknum(0)); return promise; } @@ -1633,9 +1633,9 @@ static jsval_t builtin_fs_writev_fd(ant_t *js, jsval_t *args, int nargs) { position = (int64_t)js_getnum(args[2]); size_t total_len = 0; - for (jsoff_t i = 0; i < arr_len; i++) { - jsval_t item = js_arr_get(js, args[1], i); - jsval_t ta_val = js_get_slot(js, item, SLOT_BUFFER); + for (ant_offset_t i = 0; i < arr_len; i++) { + ant_value_t item = js_arr_get(js, args[1], i); + ant_value_t ta_val = js_get_slot(js, item, SLOT_BUFFER); TypedArrayData *ta = (TypedArrayData *)js_gettypedarray(ta_val); if (!ta || !ta->buffer || !ta->buffer->data) return js_mkerr(js, "writev() buffers must contain ArrayBufferViews"); @@ -1652,9 +1652,9 @@ static jsval_t builtin_fs_writev_fd(ant_t *js, jsval_t *args, int nargs) { } size_t off = 0; - for (jsoff_t i = 0; i < arr_len; i++) { - jsval_t item = js_arr_get(js, args[1], i); - jsval_t ta_val = js_get_slot(js, item, SLOT_BUFFER); + for (ant_offset_t i = 0; i < arr_len; i++) { + ant_value_t item = js_arr_get(js, args[1], i); + ant_value_t ta_val = js_get_slot(js, item, SLOT_BUFFER); TypedArrayData *ta = (TypedArrayData *)js_gettypedarray(ta_val); memcpy(req->data + off, ta->buffer->data + ta->byte_offset, ta->byte_length); off += ta->byte_length; @@ -1682,7 +1682,7 @@ static jsval_t builtin_fs_writev_fd(ant_t *js, jsval_t *args, int nargs) { return req->promise; } -static int parse_open_flags(ant_t *js, jsval_t arg) { +static int parse_open_flags(ant_t *js, ant_value_t arg) { if (vtype(arg) == T_NUM) return (int)js_getnum(arg); if (vtype(arg) != T_STR) return O_RDONLY; @@ -1704,7 +1704,7 @@ static int parse_open_flags(ant_t *js, jsval_t arg) { return O_RDONLY; } -static jsval_t builtin_fs_openSync(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_openSync(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "openSync() requires a path argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "openSync() path must be a string"); @@ -1727,7 +1727,7 @@ static jsval_t builtin_fs_openSync(ant_t *js, jsval_t *args, int nargs) { return js_mknum((double)result); } -static jsval_t builtin_fs_closeSync(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_closeSync(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "closeSync() requires a fd argument"); if (vtype(args[0]) != T_NUM) return js_mkerr(js, "closeSync() fd must be a number"); @@ -1758,7 +1758,7 @@ static void on_open_fd_complete(uv_fs_t *uv_req) { free_fs_request(req); } -static jsval_t builtin_fs_open_fd(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_open_fd(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "open() requires a path argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "open() path must be a string"); @@ -1808,7 +1808,7 @@ static void on_close_fd_complete(uv_fs_t *uv_req) { free_fs_request(req); } -static jsval_t builtin_fs_close_fd(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fs_close_fd(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "close() requires a fd argument"); if (vtype(args[0]) != T_NUM) return js_mkerr(js, "close() fd must be a number"); @@ -1840,10 +1840,10 @@ void init_fs_module(void) { utarray_new(pending_requests, &ut_ptr_icd); ant_t *js = rt->js; - jsval_t glob = js->global; + ant_value_t glob = js->global; - jsval_t stats_ctor = js_mkobj(js); - jsval_t stats_proto = js_mkobj(js); + ant_value_t stats_ctor = js_mkobj(js); + ant_value_t stats_proto = js_mkobj(js); js_set(js, stats_proto, "isFile", js_mkfun(stat_isFile)); js_set(js, stats_proto, "isDirectory", js_mkfun(stat_isDirectory)); @@ -1857,7 +1857,7 @@ void init_fs_module(void) { js_set(js, glob, "Stats", js_obj_to_func(stats_ctor)); } -static void fs_set_promise_methods(ant_t *js, jsval_t lib) { +static void fs_set_promise_methods(ant_t *js, ant_value_t lib) { js_set(js, lib, "readFile", js_mkfun(builtin_fs_readFile)); js_set(js, lib, "open", js_mkfun(builtin_fs_open_fd)); js_set(js, lib, "close", js_mkfun(builtin_fs_close_fd)); @@ -1873,8 +1873,8 @@ static void fs_set_promise_methods(ant_t *js, jsval_t lib) { js_set(js, lib, "readdir", js_mkfun(builtin_fs_readdir)); } -static jsval_t fs_make_constants(ant_t *js) { - jsval_t constants = js_mkobj(js); +static ant_value_t fs_make_constants(ant_t *js) { + ant_value_t constants = js_mkobj(js); js_set(js, constants, "F_OK", js_mknum(F_OK)); js_set(js, constants, "R_OK", js_mknum(R_OK)); js_set(js, constants, "W_OK", js_mknum(W_OK)); @@ -1889,18 +1889,18 @@ static jsval_t fs_make_constants(ant_t *js) { return constants; } -static jsval_t builtin_fs_promises_getter(ant_t *js, jsval_t *args, int nargs) { - jsval_t getter_fn = js_getcurrentfunc(js); - jsval_t cached = js_get_slot(js, getter_fn, SLOT_DATA); +static ant_value_t builtin_fs_promises_getter(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t getter_fn = js_getcurrentfunc(js); + ant_value_t cached = js_get_slot(js, getter_fn, SLOT_DATA); if (is_object_type(cached)) return cached; - jsval_t promises = fs_promises_library(js); + ant_value_t promises = fs_promises_library(js); js_set_slot(js, getter_fn, SLOT_DATA, promises); return promises; } -jsval_t fs_library(ant_t *js) { - jsval_t lib = js_mkobj(js); +ant_value_t fs_library(ant_t *js) { + ant_value_t lib = js_mkobj(js); fs_set_promise_methods(js, lib); js_set(js, lib, "readFileSync", js_mkfun(builtin_fs_readFileSync)); @@ -1935,8 +1935,8 @@ jsval_t fs_library(ant_t *js) { return lib; } -jsval_t fs_promises_library(ant_t *js) { - jsval_t lib = js_mkobj(js); +ant_value_t fs_promises_library(ant_t *js) { + ant_value_t lib = js_mkobj(js); fs_set_promise_methods(js, lib); js_set(js, lib, "constants", fs_make_constants(js)); diff --git a/src/modules/io.c b/src/modules/io.c index 2f26991..7c8050c 100644 --- a/src/modules/io.c +++ b/src/modules/io.c @@ -332,7 +332,7 @@ other: #undef KEYWORD #undef EMIT_UNTIL -void print_repl_value(ant_t *js, jsval_t val, FILE *stream) { +void print_repl_value(ant_t *js, ant_value_t val, FILE *stream) { if (vtype(val) == T_STR) { char *str = js_getstr(js, val, NULL); fprintf(stream, "%s'%s'%s\n", C(JSON_STRING), str ? str : "", C(C_RESET)); @@ -350,7 +350,7 @@ void print_repl_value(ant_t *js, jsval_t val, FILE *stream) { if (cstr.needs_free) free((void *)cstr.ptr); } -jsval_t console_print(ant_t *js, jsval_t *args, int nargs, const char *color, FILE *stream) { +ant_value_t console_print(ant_t *js, ant_value_t *args, int nargs, const char *color, FILE *stream) { if (color && !io_no_color) fputs(color, stream); for (int i = 0; i < nargs; i++) { @@ -379,19 +379,19 @@ jsval_t console_print(ant_t *js, jsval_t *args, int nargs, const char *color, FI return js_mkundef(); } -static jsval_t js_console_log(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_console_log(ant_t *js, ant_value_t *args, int nargs) { return console_print(js, args, nargs, NULL, stdout); } -static jsval_t js_console_error(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_console_error(ant_t *js, ant_value_t *args, int nargs) { return console_print(js, args, nargs, C_RED, stderr); } -static jsval_t js_console_warn(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_console_warn(ant_t *js, ant_value_t *args, int nargs) { return console_print(js, args, nargs, C_YELLOW, stderr); } -static jsval_t js_console_assert(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_console_assert(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkundef(); bool is_truthy = js_truthy(js, args[0]); @@ -408,7 +408,7 @@ static jsval_t js_console_assert(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t js_console_trace(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_console_trace(ant_t *js, ant_value_t *args, int nargs) { fputs("Trace", stderr); if (nargs > 0) { fputs(": ", stderr); @@ -419,15 +419,15 @@ static jsval_t js_console_trace(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t js_console_info(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_console_info(ant_t *js, ant_value_t *args, int nargs) { return console_print(js, args, nargs, C_CYAN, stdout); } -static jsval_t js_console_debug(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_console_debug(ant_t *js, ant_value_t *args, int nargs) { return console_print(js, args, nargs, C_MAGENTA, stdout); } -static jsval_t js_console_clear(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_console_clear(ant_t *js, ant_value_t *args, int nargs) { if (!io_no_color) { fprintf(stdout, "\033[2J\033[H"); fflush(stdout); @@ -438,7 +438,7 @@ static jsval_t js_console_clear(ant_t *js, jsval_t *args, int nargs) { static struct { char *label; double start_time; } console_timers[64]; static int console_timer_count = 0; -static jsval_t js_console_time(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_console_time(ant_t *js, ant_value_t *args, int nargs) { const char *label = "default"; if (nargs > 0 && vtype(args[0]) == T_STR) { label = js_getstr(js, args[0], NULL); @@ -460,7 +460,7 @@ static jsval_t js_console_time(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t js_console_timeEnd(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_console_timeEnd(ant_t *js, ant_value_t *args, int nargs) { const char *label = "default"; if (nargs > 0 && vtype(args[0]) == T_STR) { label = js_getstr(js, args[0], NULL); @@ -567,7 +567,7 @@ static const char *get_type_name(int type) { return type_names[type] ? type_names[type] : "unknown"; } -static bool inspect_was_visited(inspect_visited_t *v, jsoff_t off) { +static bool inspect_was_visited(inspect_visited_t *v, ant_offset_t off) { for (int i = 0; i < v->count; i++) if (v->visited[i] == off) return true; return false; } @@ -576,15 +576,15 @@ static void inspect_print_indent(FILE *stream, int depth) { for (int i = 0; i < depth; i++) fprintf(stream, " "); } -static void inspect_mark_visited(inspect_visited_t *v, jsoff_t off) { +static void inspect_mark_visited(inspect_visited_t *v, ant_offset_t off) { if (v->count >= v->capacity) { v->capacity = v->capacity ? v->capacity * 2 : 32; - v->visited = realloc(v->visited, v->capacity * sizeof(jsoff_t)); + v->visited = realloc(v->visited, v->capacity * sizeof(ant_offset_t)); } v->visited[v->count++] = off; } -void inspect_value(ant_t *js, jsval_t val, FILE *stream, int depth, inspect_visited_t *visited) { +void inspect_value(ant_t *js, ant_value_t val, FILE *stream, int depth, inspect_visited_t *visited) { int t = vtype(val); if (t == T_UNDEF) { fprintf(stream, "undefined"); return; } @@ -620,10 +620,10 @@ void inspect_value(ant_t *js, jsval_t val, FILE *stream, int depth, inspect_visi fprintf(stream, "<%s rawtype=%d data=%" PRIu64 ">", get_type_name(t), vtype(val), (uint64_t)vdata(val)); } -void inspect_object(ant_t *js, jsval_t obj, FILE *stream, int depth, inspect_visited_t *visited) { +void inspect_object(ant_t *js, ant_value_t obj, FILE *stream, int depth, inspect_visited_t *visited) { int type = vtype(obj); obj = js_as_obj(obj); - jsoff_t obj_off = (jsoff_t)vdata(obj); + ant_offset_t obj_off = (ant_offset_t)vdata(obj); if (inspect_was_visited(visited, obj_off)) { fprintf(stream, "[Circular *%llu]", (u64)obj_off); @@ -639,7 +639,7 @@ void inspect_object(ant_t *js, jsval_t obj, FILE *stream, int depth, inspect_vis fprintf(stream, "[[Slots]]: {\n"); for (int slot = SLOT_NONE + 1; slot < SLOT_MAX; slot++) { - jsval_t slot_val = js_get_slot(js, obj, (internal_slot_t)slot); + ant_value_t slot_val = js_get_slot(js, obj, (internal_slot_t)slot); int t = vtype(slot_val); if (t == T_UNDEF) continue; @@ -657,7 +657,7 @@ void inspect_object(ant_t *js, jsval_t obj, FILE *stream, int depth, inspect_vis fprintf(stream, "%.0f", js_getnum(slot_val)); break; default: - if ((t == T_OBJ || t == T_FUNC || t == T_PROMISE) && inspect_was_visited(visited, (jsoff_t)vdata(js_as_obj(slot_val)))) + if ((t == T_OBJ || t == T_FUNC || t == T_PROMISE) && inspect_was_visited(visited, (ant_offset_t)vdata(js_as_obj(slot_val)))) fprintf(stream, "[Circular *%llu]", (u64)vdata(js_as_obj(slot_val))); else if (t == T_OBJ || t == T_FUNC || t == T_PROMISE) fprintf(stream, "<%s @%llu>", get_type_name(t), (u64)vdata(js_as_obj(slot_val))); @@ -678,7 +678,7 @@ void inspect_object(ant_t *js, jsval_t obj, FILE *stream, int depth, inspect_vis ant_iter_t iter = js_prop_iter_begin(js, obj); const char *key; size_t key_len; - jsval_t value; + ant_value_t value; while (js_prop_iter_next(&iter, &key, &key_len, &value)) { inspect_print_indent(stream, inner_depth + 1); @@ -691,7 +691,7 @@ void inspect_object(ant_t *js, jsval_t obj, FILE *stream, int depth, inspect_vis inspect_print_indent(stream, inner_depth); fprintf(stream, "}\n"); - jsval_t proto = js_get_proto(js, obj); + ant_value_t proto = js_get_proto(js, obj); inspect_print_indent(stream, inner_depth); fprintf(stream, "[[Prototype]]: "); if (vtype(proto) == T_NULL) { @@ -707,7 +707,7 @@ void inspect_object(ant_t *js, jsval_t obj, FILE *stream, int depth, inspect_vis fprintf(stream, "}"); } -static jsval_t js_console_inspect(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_console_inspect(ant_t *js, ant_value_t *args, int nargs) { FILE *stream = stdout; inspect_visited_t visited = {0}; @@ -724,7 +724,7 @@ static jsval_t js_console_inspect(ant_t *js, jsval_t *args, int nargs) { void init_console_module() { ant_t *js = rt->js; - jsval_t console_obj = js_mkobj(js); + ant_value_t console_obj = js_mkobj(js); js_set(js, console_obj, "log", js_mkfun(js_console_log)); js_set(js, console_obj, "error", js_mkfun(js_console_error)); diff --git a/src/modules/json.c b/src/modules/json.c index 40cc500..5ee05fb 100644 --- a/src/modules/json.c +++ b/src/modules/json.c @@ -16,11 +16,11 @@ typedef struct { const char *key; size_t key_len; - jsoff_t prop_off; + ant_offset_t prop_off; UT_hash_handle hh; } json_key_entry_t; -static jsval_t yyjson_to_jsval(ant_t *js, yyjson_val *val) { +static ant_value_t yyjson_to_jsval(ant_t *js, yyjson_val *val) { if (!val) return js_mkundef(); switch (yyjson_get_type(val)) { @@ -35,7 +35,7 @@ static jsval_t yyjson_to_jsval(ant_t *js, yyjson_val *val) { } case YYJSON_TYPE_ARR: { - jsval_t arr = js_mkarr(js); + ant_value_t arr = js_mkarr(js); size_t idx, max; yyjson_val *item; @@ -46,7 +46,7 @@ static jsval_t yyjson_to_jsval(ant_t *js, yyjson_val *val) { } case YYJSON_TYPE_OBJ: { - jsval_t obj = js_newobj(js); + ant_value_t obj = js_newobj(js); size_t idx, max; yyjson_val *key, *item; json_key_entry_t *hash = NULL, *entry, *tmp; @@ -54,11 +54,11 @@ static jsval_t yyjson_to_jsval(ant_t *js, yyjson_val *val) { yyjson_obj_foreach(val, idx, max, key, item) { const char *k = yyjson_get_str(key); size_t klen = yyjson_get_len(key); - jsval_t v = yyjson_to_jsval(js, item); + ant_value_t v = yyjson_to_jsval(js, item); HASH_FIND(hh, hash, k, klen, entry); if (entry) js_saveval(js, entry->prop_off, v); else { - jsoff_t off = js_mkprop_fast_off(js, obj, k, klen, v); + ant_offset_t off = js_mkprop_fast_off(js, obj, k, klen, v); entry = malloc(sizeof(json_key_entry_t)); entry->key = k; entry->key_len = klen; entry->prop_off = off; HASH_ADD_KEYPTR(hh, hash, entry->key, entry->key_len, entry); @@ -77,27 +77,27 @@ static jsval_t yyjson_to_jsval(ant_t *js, yyjson_val *val) { } typedef struct { - jsval_t *stack; + ant_value_t *stack; int stack_size; int stack_cap; int has_cycle; ant_t *js; - jsval_t replacer_func; - jsval_t replacer_arr; + ant_value_t replacer_func; + ant_value_t replacer_arr; int replacer_arr_len; - jsval_t holder; + ant_value_t holder; } json_cycle_ctx; -static int json_cycle_check(json_cycle_ctx *ctx, jsval_t val) { +static int json_cycle_check(json_cycle_ctx *ctx, ant_value_t val) { for (int i = 0; i < ctx->stack_size; i++) if (ctx->stack[i] == val) { ctx->has_cycle = 1; return 1; } return 0; } -static void json_cycle_push(json_cycle_ctx *ctx, jsval_t val) { +static void json_cycle_push(json_cycle_ctx *ctx, ant_value_t val) { if (ctx->stack_size >= ctx->stack_cap) { ctx->stack_cap = ctx->stack_cap ? ctx->stack_cap * 2 : 16; - ctx->stack = realloc(ctx->stack, ctx->stack_cap * sizeof(jsval_t)); + ctx->stack = realloc(ctx->stack, ctx->stack_cap * sizeof(ant_value_t)); } ctx->stack[ctx->stack_size++] = val; } @@ -106,20 +106,20 @@ static inline void json_cycle_pop(json_cycle_ctx *ctx) { if (ctx->stack_size > 0) ctx->stack_size--; } -typedef struct { char *key; size_t key_len; jsval_t value; } prop_entry; +typedef struct { char *key; size_t key_len; ant_value_t value; } prop_entry; -static int should_skip_prop(ant_t *js, const char *key, size_t key_len, jsval_t value) { - if (is_internal_prop(key, (jsoff_t)key_len)) return 1; +static int should_skip_prop(ant_t *js, const char *key, size_t key_len, ant_value_t value) { + if (is_internal_prop(key, (ant_offset_t)key_len)) return 1; if (!is_special_object(value)) return 0; return vtype(js_get_slot(js, value, SLOT_CODE)) == T_CFUNC; } -static prop_entry *collect_props(ant_t *js, jsval_t val, int *out_count) { +static prop_entry *collect_props(ant_t *js, ant_value_t val, int *out_count) { prop_entry *props = NULL; int count = 0, cap = 0; const char *key; size_t key_len; - jsval_t value; + ant_value_t value; ant_iter_t iter = js_prop_iter_begin(js, val); while (js_prop_iter_next(&iter, &key, &key_len, &value)) { @@ -158,7 +158,7 @@ static int is_key_in_replacer_arr(ant_t *js, json_cycle_ctx *ctx, const char *ke for (int i = 0; i < ctx->replacer_arr_len; i++) { char idxstr[32]; snprintf(idxstr, sizeof(idxstr), "%d", i); - jsval_t item = js_get(js, ctx->replacer_arr, idxstr); + ant_value_t item = js_get(js, ctx->replacer_arr, idxstr); int type = vtype(item); if (type == T_STR) { @@ -174,18 +174,18 @@ static int is_key_in_replacer_arr(ant_t *js, json_cycle_ctx *ctx, const char *ke return 0; } -static yyjson_mut_val *jsval_to_yyjson_with_key(ant_t *js, yyjson_mut_doc *doc, const char *key, jsval_t val, json_cycle_ctx *ctx, int in_array); +static yyjson_mut_val *ant_value_to_yyjson_with_key(ant_t *js, yyjson_mut_doc *doc, const char *key, ant_value_t val, json_cycle_ctx *ctx, int in_array); -static yyjson_mut_val *jsval_to_yyjson_impl(ant_t *js, yyjson_mut_doc *doc, jsval_t val, json_cycle_ctx *ctx, int in_array) { +static yyjson_mut_val *ant_value_to_yyjson_impl(ant_t *js, yyjson_mut_doc *doc, ant_value_t val, json_cycle_ctx *ctx, int in_array) { int type = vtype(val); yyjson_mut_val *result = NULL; if (is_special_object(val)) { - jsval_t toJSON = js_get(js, val, "toJSON"); + ant_value_t toJSON = js_get(js, val, "toJSON"); if (vtype(toJSON) == T_FUNC) { - jsval_t r = sv_vm_call(js->vm, js, toJSON, js_mkundef(), &val, 1, NULL, false); + ant_value_t r = sv_vm_call(js->vm, js, toJSON, js_mkundef(), &val, 1, NULL, false); if (vtype(r) == T_ERR) { ctx->has_cycle = 1; return NULL; } - return jsval_to_yyjson_impl(js, doc, r, ctx, in_array); + return ant_value_to_yyjson_impl(js, doc, r, ctx, in_array); } } @@ -221,20 +221,20 @@ static yyjson_mut_val *jsval_to_yyjson_impl(ant_t *js, yyjson_mut_doc *doc, jsva if (json_cycle_check(ctx, val)) return NULL; json_cycle_push(ctx, val); - jsval_t length_val = js_get(js, val, "length"); + ant_value_t length_val = js_get(js, val, "length"); if (vtype(length_val) == T_NUM) { yyjson_mut_val *arr = yyjson_mut_arr(doc); int length = (int)js_getnum(length_val); - jsval_t saved_holder = ctx->holder; + ant_value_t saved_holder = ctx->holder; ctx->holder = val; for (int i = 0; i < length; i++) { char idxstr[32]; snprintf(idxstr, sizeof(idxstr), "%d", i); - jsval_t elem = js_get(js, val, idxstr); - yyjson_mut_val *item = jsval_to_yyjson_with_key(js, doc, idxstr, elem, ctx, 1); + ant_value_t elem = js_get(js, val, idxstr); + yyjson_mut_val *item = ant_value_to_yyjson_with_key(js, doc, idxstr, elem, ctx, 1); if (ctx->has_cycle) { ctx->holder = saved_holder; goto done; } yyjson_mut_arr_add_val(arr, item); } @@ -247,7 +247,7 @@ static yyjson_mut_val *jsval_to_yyjson_impl(ant_t *js, yyjson_mut_doc *doc, jsva int prop_count; prop_entry *props = collect_props(js, val, &prop_count); - jsval_t saved_holder = ctx->holder; + ant_value_t saved_holder = ctx->holder; ctx->holder = val; for (int i = 0; i < prop_count; i++) { @@ -260,7 +260,7 @@ static yyjson_mut_val *jsval_to_yyjson_impl(ant_t *js, yyjson_mut_doc *doc, jsva int ptype = vtype(p->value); if (ptype == T_UNDEF || ptype == T_FUNC) { free(p->key); continue; } - yyjson_mut_val *jval = jsval_to_yyjson_with_key(js, doc, p->key, p->value, ctx, 0); + yyjson_mut_val *jval = ant_value_to_yyjson_with_key(js, doc, p->key, p->value, ctx, 0); if (ctx->has_cycle) { free_props(props, 0, i); ctx->holder = saved_holder; goto done; } if (jval == YYJSON_SKIP_VALUE) { free(p->key); continue; } @@ -277,50 +277,50 @@ done: return result; } -static yyjson_mut_val *jsval_to_yyjson_with_key(ant_t *js, yyjson_mut_doc *doc, const char *key, jsval_t val, json_cycle_ctx *ctx, int in_array) { +static yyjson_mut_val *ant_value_to_yyjson_with_key(ant_t *js, yyjson_mut_doc *doc, const char *key, ant_value_t val, json_cycle_ctx *ctx, int in_array) { if (vtype(ctx->replacer_func) != T_FUNC) - return jsval_to_yyjson_impl(js, doc, val, ctx, in_array); + return ant_value_to_yyjson_impl(js, doc, val, ctx, in_array); - jsval_t key_str = js_mkstr(js, key, strlen(key)); - jsval_t call_args[2] = { key_str, val }; - jsval_t transformed = sv_vm_call(js->vm, js, ctx->replacer_func, js_mkundef(), call_args, 2, NULL, false); + ant_value_t key_str = js_mkstr(js, key, strlen(key)); + ant_value_t call_args[2] = { key_str, val }; + ant_value_t transformed = sv_vm_call(js->vm, js, ctx->replacer_func, js_mkundef(), call_args, 2, NULL, false); if (vtype(transformed) == T_ERR) { ctx->has_cycle = 1; return NULL; } - return jsval_to_yyjson_impl(js, doc, transformed, ctx, in_array); + return ant_value_to_yyjson_impl(js, doc, transformed, ctx, in_array); } -static yyjson_mut_val *jsval_to_yyjson(ant_t *js, yyjson_mut_doc *doc, jsval_t val, json_cycle_ctx *ctx) { - return jsval_to_yyjson_with_key(js, doc, "", val, ctx, 0); +static yyjson_mut_val *ant_value_to_yyjson(ant_t *js, yyjson_mut_doc *doc, ant_value_t val, json_cycle_ctx *ctx) { + return ant_value_to_yyjson_with_key(js, doc, "", val, ctx, 0); } -static jsval_t apply_reviver(ant_t *js, jsval_t holder, const char *key, jsval_t reviver) { - jsval_t val = js_get(js, holder, key); +static ant_value_t apply_reviver(ant_t *js, ant_value_t holder, const char *key, ant_value_t reviver) { + ant_value_t val = js_get(js, holder, key); if (is_special_object(val)) { - jsval_t len_val = js_get(js, val, "length"); + ant_value_t len_val = js_get(js, val, "length"); if (vtype(len_val) == T_NUM) { int length = (int)js_getnum(len_val); for (int i = 0; i < length; i++) { char idxstr[32]; snprintf(idxstr, sizeof(idxstr), "%d", i); - jsval_t new_elem = apply_reviver(js, val, idxstr, reviver); + ant_value_t new_elem = apply_reviver(js, val, idxstr, reviver); if (vtype(new_elem) == T_UNDEF) js_del(js, val, idxstr); else js_set(js, val, idxstr, new_elem); } } else { const char *prop_key; size_t prop_key_len; - jsval_t prop_value; + ant_value_t prop_value; - jsval_t keys_arr = js_mkobj(js); + ant_value_t keys_arr = js_mkobj(js); int key_count = 0; ant_iter_t iter = js_prop_iter_begin(js, val); while (js_prop_iter_next(&iter, &prop_key, &prop_key_len, &prop_value)) { - if (is_internal_prop(prop_key, (jsoff_t)prop_key_len)) continue; + if (is_internal_prop(prop_key, (ant_offset_t)prop_key_len)) continue; char idxstr[32]; snprintf(idxstr, sizeof(idxstr), "%d", key_count); js_set(js, keys_arr, idxstr, js_mkstr(js, prop_key, prop_key_len)); @@ -331,23 +331,23 @@ static jsval_t apply_reviver(ant_t *js, jsval_t holder, const char *key, jsval_t for (int i = 0; i < key_count; i++) { char idxstr[32]; snprintf(idxstr, sizeof(idxstr), "%d", i); - jsval_t key_str = js_get(js, keys_arr, idxstr); + ant_value_t key_str = js_get(js, keys_arr, idxstr); size_t klen; char *kstr = js_getstr(js, key_str, &klen); - jsval_t new_val = apply_reviver(js, val, kstr, reviver); + ant_value_t new_val = apply_reviver(js, val, kstr, reviver); if (vtype(new_val) == T_UNDEF) js_del(js, val, kstr); else js_set(js, val, kstr, new_val); } } } - jsval_t key_str = js_mkstr(js, key, strlen(key)); - jsval_t call_args[2] = { key_str, js_get(js, holder, key) }; + ant_value_t key_str = js_mkstr(js, key, strlen(key)); + ant_value_t call_args[2] = { key_str, js_get(js, holder, key) }; return sv_vm_call(js->vm, js, reviver, holder, call_args, 2, NULL, false); } -jsval_t js_json_parse(ant_t *js, jsval_t *args, int nargs) { +ant_value_t js_json_parse(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "JSON.parse() requires at least 1 argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "JSON.parse() argument must be a string"); @@ -357,12 +357,12 @@ jsval_t js_json_parse(ant_t *js, jsval_t *args, int nargs) { yyjson_doc *doc = yyjson_read(json_str, len, 0); if (!doc) return js_mkerr_typed(js, JS_ERR_SYNTAX, "JSON.parse: unexpected character"); - jsval_t result = yyjson_to_jsval(js, yyjson_doc_get_root(doc)); + ant_value_t result = yyjson_to_jsval(js, yyjson_doc_get_root(doc)); yyjson_doc_free(doc); if (nargs >= 2 && vtype(args[1]) == T_FUNC) { - jsval_t reviver = args[1]; - jsval_t root = js_mkobj(js); + ant_value_t reviver = args[1]; + ant_value_t root = js_mkobj(js); js_set(js, root, "", result); result = apply_reviver(js, root, "", reviver); } @@ -370,7 +370,7 @@ jsval_t js_json_parse(ant_t *js, jsval_t *args, int nargs) { return result; } -static yyjson_write_flag get_write_flags(jsval_t *args, int nargs) { +static yyjson_write_flag get_write_flags(ant_value_t *args, int nargs) { if (nargs < 3) return 0; int type = vtype(args[2]); @@ -384,8 +384,8 @@ static yyjson_write_flag get_write_flags(jsval_t *args, int nargs) { return YYJSON_WRITE_PRETTY; } -jsval_t js_json_stringify(ant_t *js, jsval_t *args, int nargs) { - jsval_t result; +ant_value_t js_json_stringify(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t result; yyjson_mut_doc *doc = NULL; json_cycle_ctx ctx = {0}; char *json_str = NULL; @@ -404,11 +404,11 @@ jsval_t js_json_stringify(ant_t *js, jsval_t *args, int nargs) { ctx.holder = js_mkundef(); if (nargs >= 2) { - jsval_t replacer = args[1]; + ant_value_t replacer = args[1]; if (vtype(replacer) == T_FUNC) { ctx.replacer_func = replacer; } else if (is_special_object(replacer)) { - jsval_t len_val = js_get(js, replacer, "length"); + ant_value_t len_val = js_get(js, replacer, "length"); if (vtype(len_val) == T_NUM) { ctx.replacer_arr = replacer; ctx.replacer_arr_len = (int)js_getnum(len_val); @@ -419,7 +419,7 @@ jsval_t js_json_stringify(ant_t *js, jsval_t *args, int nargs) { doc = yyjson_mut_doc_new(NULL); if (!doc) return js_mkerr(js, "JSON.stringify() failed: out of memory"); - yyjson_mut_val *root = jsval_to_yyjson(js, doc, args[0], &ctx); + yyjson_mut_val *root = ant_value_to_yyjson(js, doc, args[0], &ctx); if (ctx.has_cycle) { result = js_mkerr_typed(js, JS_ERR_TYPE, "Converting circular structure to JSON"); @@ -450,7 +450,7 @@ cleanup: void init_json_module() { ant_t *js = rt->js; - jsval_t json_obj = js_mkobj(js); + ant_value_t json_obj = js_mkobj(js); js_set(js, json_obj, "parse", js_mkfun(js_json_parse)); js_set(js, json_obj, "stringify", js_mkfun(js_json_stringify)); diff --git a/src/modules/lmdb.c b/src/modules/lmdb.c index a453661..b84351c 100644 --- a/src/modules/lmdb.c +++ b/src/modules/lmdb.c @@ -44,19 +44,19 @@ struct lmdb_txn_handle { }; struct lmdb_env_ref { - jsval_t obj; + ant_value_t obj; lmdb_env_handle_t *env; lmdb_env_ref_t *next; }; struct lmdb_db_ref { - jsval_t obj; + ant_value_t obj; lmdb_db_handle_t *db; lmdb_db_ref_t *next; }; struct lmdb_txn_ref { - jsval_t obj; + ant_value_t obj; lmdb_txn_handle_t *txn; lmdb_txn_ref_t *next; }; @@ -69,9 +69,9 @@ static lmdb_env_ref_t *env_refs = NULL; static lmdb_db_ref_t *db_refs = NULL; static lmdb_txn_ref_t *txn_refs = NULL; -static jsval_t make_env_obj(ant_t *js, lmdb_env_handle_t *env); -static jsval_t make_db_obj(ant_t *js, lmdb_db_handle_t *db); -static jsval_t make_txn_obj(ant_t *js, lmdb_txn_handle_t *txn); +static ant_value_t make_env_obj(ant_t *js, lmdb_env_handle_t *env); +static ant_value_t make_db_obj(ant_t *js, lmdb_db_handle_t *db); +static ant_value_t make_txn_obj(ant_t *js, lmdb_txn_handle_t *txn); static void list_remove_db(lmdb_env_handle_t *env, lmdb_db_handle_t *target) { if (!env || !target) return; @@ -99,7 +99,7 @@ static void list_remove_txn(lmdb_env_handle_t *env, lmdb_txn_handle_t *target) { } } -static void register_env_ref(jsval_t obj, lmdb_env_handle_t *env) { +static void register_env_ref(ant_value_t obj, lmdb_env_handle_t *env) { lmdb_env_ref_t *ref = ant_calloc(sizeof(lmdb_env_ref_t)); if (!ref) return; ref->obj = obj; @@ -108,7 +108,7 @@ static void register_env_ref(jsval_t obj, lmdb_env_handle_t *env) { env_refs = ref; } -static void register_db_ref(jsval_t obj, lmdb_db_handle_t *db) { +static void register_db_ref(ant_value_t obj, lmdb_db_handle_t *db) { lmdb_db_ref_t *ref = ant_calloc(sizeof(lmdb_db_ref_t)); if (!ref) return; ref->obj = obj; @@ -117,7 +117,7 @@ static void register_db_ref(jsval_t obj, lmdb_db_handle_t *db) { db_refs = ref; } -static void register_txn_ref(jsval_t obj, lmdb_txn_handle_t *txn) { +static void register_txn_ref(ant_value_t obj, lmdb_txn_handle_t *txn) { lmdb_txn_ref_t *ref = ant_calloc(sizeof(lmdb_txn_ref_t)); if (!ref) return; ref->obj = obj; @@ -126,25 +126,25 @@ static void register_txn_ref(jsval_t obj, lmdb_txn_handle_t *txn) { txn_refs = ref; } -static lmdb_env_handle_t *find_env_by_obj(jsval_t obj) { +static lmdb_env_handle_t *find_env_by_obj(ant_value_t obj) { for (lmdb_env_ref_t *ref = env_refs; ref; ref = ref->next) if (ref->obj == obj) return ref->env; return NULL; } -static lmdb_db_handle_t *find_db_by_obj(jsval_t obj) { +static lmdb_db_handle_t *find_db_by_obj(ant_value_t obj) { for (lmdb_db_ref_t *ref = db_refs; ref; ref = ref->next) if (ref->obj == obj) return ref->db; return NULL; } -static lmdb_txn_handle_t *find_txn_by_obj(jsval_t obj) { +static lmdb_txn_handle_t *find_txn_by_obj(ant_value_t obj) { for (lmdb_txn_ref_t *ref = txn_refs; ref; ref = ref->next) if (ref->obj == obj) return ref->txn; return NULL; } -static void unregister_env_ref_by_obj(jsval_t obj) { +static void unregister_env_ref_by_obj(ant_value_t obj) { lmdb_env_ref_t **cur = &env_refs; while (*cur) { if ((*cur)->obj == obj) { @@ -157,7 +157,7 @@ static void unregister_env_ref_by_obj(jsval_t obj) { } } -static void unregister_db_ref_by_obj(jsval_t obj) { +static void unregister_db_ref_by_obj(ant_value_t obj) { lmdb_db_ref_t **cur = &db_refs; while (*cur) { if ((*cur)->obj == obj) { @@ -170,7 +170,7 @@ static void unregister_db_ref_by_obj(jsval_t obj) { } } -static void unregister_txn_ref_by_obj(jsval_t obj) { +static void unregister_txn_ref_by_obj(ant_value_t obj) { lmdb_txn_ref_t **cur = &txn_refs; while (*cur) { if ((*cur)->obj == obj) { @@ -241,53 +241,53 @@ static void env_handle_close(lmdb_env_handle_t *env) { unregister_txn_refs_by_env(env); } -static lmdb_env_handle_t *get_env_handle(ant_t *js, jsval_t obj, bool open_required) { +static lmdb_env_handle_t *get_env_handle(ant_t *js, ant_value_t obj, bool open_required) { lmdb_env_handle_t *env = find_env_by_obj(obj); if (!env) return NULL; if (open_required && env->closed) return NULL; return env; } -static lmdb_db_handle_t *get_db_handle(ant_t *js, jsval_t obj, bool open_required) { +static lmdb_db_handle_t *get_db_handle(ant_t *js, ant_value_t obj, bool open_required) { lmdb_db_handle_t *db = find_db_by_obj(obj); if (!db) return NULL; if (open_required && (db->closed || !db->env || db->env->closed)) return NULL; return db; } -static lmdb_txn_handle_t *get_txn_handle(ant_t *js, jsval_t obj, bool open_required) { +static lmdb_txn_handle_t *get_txn_handle(ant_t *js, ant_value_t obj, bool open_required) { lmdb_txn_handle_t *txn = find_txn_by_obj(obj); if (!txn) return NULL; if (open_required && (txn->closed || !txn->txn)) return NULL; return txn; } -static bool option_bool(ant_t *js, jsval_t options, const char *key, bool fallback) { +static bool option_bool(ant_t *js, ant_value_t options, const char *key, bool fallback) { if (vtype(options) != T_OBJ) return fallback; - jsval_t val = js_get(js, options, key); + ant_value_t val = js_get(js, options, key); if (vtype(val) == T_UNDEF) return fallback; return js_truthy(js, val); } -static unsigned int option_uint(ant_t *js, jsval_t options, const char *key, unsigned int fallback) { +static unsigned int option_uint(ant_t *js, ant_value_t options, const char *key, unsigned int fallback) { if (vtype(options) != T_OBJ) return fallback; - jsval_t val = js_get(js, options, key); + ant_value_t val = js_get(js, options, key); if (vtype(val) != T_NUM) return fallback; double n = js_getnum(val); if (n < 0.0) return fallback; return (unsigned int)n; } -static size_t option_size(ant_t *js, jsval_t options, const char *key, size_t fallback) { +static size_t option_size(ant_t *js, ant_value_t options, const char *key, size_t fallback) { if (vtype(options) != T_OBJ) return fallback; - jsval_t val = js_get(js, options, key); + ant_value_t val = js_get(js, options, key); if (vtype(val) != T_NUM) return fallback; double n = js_getnum(val); if (n < 0.0) return fallback; return (size_t)n; } -static bool js_to_mdb_val(ant_t *js, jsval_t input, MDB_val *out) { +static bool js_to_mdb_val(ant_t *js, ant_value_t input, MDB_val *out) { if (vtype(input) == T_STR) { size_t len = 0; const char *str = js_getstr(js, input, &len); @@ -298,7 +298,7 @@ static bool js_to_mdb_val(ant_t *js, jsval_t input, MDB_val *out) { } if (vtype(input) == T_OBJ) { - jsval_t slot = js_get_slot(js, input, SLOT_BUFFER); + ant_value_t slot = js_get_slot(js, input, SLOT_BUFFER); if (vtype(slot) == T_TYPEDARRAY) { TypedArrayData *ta = (TypedArrayData *)js_gettypedarray(slot); @@ -320,7 +320,7 @@ static bool js_to_mdb_val(ant_t *js, jsval_t input, MDB_val *out) { return false; } -static jsval_t mdb_val_to_js(ant_t *js, MDB_val *val, bool as_string) { +static ant_value_t mdb_val_to_js(ant_t *js, MDB_val *val, bool as_string) { if (as_string) { return js_mkstr(js, val->mv_data, val->mv_size); } @@ -332,12 +332,12 @@ static jsval_t mdb_val_to_js(ant_t *js, MDB_val *val, bool as_string) { memcpy(ab->data, val->mv_data, val->mv_size); } - jsval_t out = create_typed_array(js, TYPED_ARRAY_UINT8, ab, 0, ab->length, "Uint8Array"); + ant_value_t out = create_typed_array(js, TYPED_ARRAY_UINT8, ab, 0, ab->length, "Uint8Array"); if (vtype(out) == T_ERR) free_array_buffer_data(ab); return out; } -static bool parse_get_encoding(ant_t *js, jsval_t encoding, bool *as_string) { +static bool parse_get_encoding(ant_t *js, ant_value_t encoding, bool *as_string) { if (vtype(encoding) == T_UNDEF) return true; if (vtype(encoding) != T_STR) return false; @@ -357,7 +357,7 @@ static bool parse_get_encoding(ant_t *js, jsval_t encoding, bool *as_string) { return false; } -static jsval_t lmdb_open(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t lmdb_open(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || vtype(args[0]) != T_STR) { return js_mkerr(js, "lmdb.open(path, options?) requires a string path"); } @@ -368,7 +368,7 @@ static jsval_t lmdb_open(ant_t *js, jsval_t *args, int nargs) { return js_mkerr(js, "lmdb.open path cannot be empty"); } - jsval_t options = nargs > 1 ? args[1] : js_mkundef(); + ant_value_t options = nargs > 1 ? args[1] : js_mkundef(); bool read_only = option_bool(js, options, "readOnly", false); bool no_subdir = option_bool(js, options, "noSubdir", false); @@ -444,13 +444,13 @@ static jsval_t lmdb_open(ant_t *js, jsval_t *args, int nargs) { return make_env_obj(js, handle); } -static jsval_t lmdb_env_open_db(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t lmdb_env_open_db(ant_t *js, ant_value_t *args, int nargs) { lmdb_env_handle_t *env = get_env_handle(js, js_getthis(js), true); if (!env) return js_mkerr(js, "Invalid or closed LMDB env"); const char *name = NULL; size_t name_len = 0; - jsval_t options = js_mkundef(); + ant_value_t options = js_mkundef(); if (nargs > 0 && vtype(args[0]) == T_STR) { name = js_getstr(js, args[0], &name_len); @@ -514,11 +514,11 @@ static jsval_t lmdb_env_open_db(ant_t *js, jsval_t *args, int nargs) { return make_db_obj(js, db); } -static jsval_t lmdb_env_begin_txn(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t lmdb_env_begin_txn(ant_t *js, ant_value_t *args, int nargs) { lmdb_env_handle_t *env = get_env_handle(js, js_getthis(js), true); if (!env) return js_mkerr(js, "Invalid or closed LMDB env"); - jsval_t options = nargs > 0 ? args[0] : js_mkundef(); + ant_value_t options = nargs > 0 ? args[0] : js_mkundef(); bool read_only = option_bool(js, options, "readOnly", env->read_only); if (env->read_only && !read_only) { @@ -548,10 +548,10 @@ static jsval_t lmdb_env_begin_txn(ant_t *js, jsval_t *args, int nargs) { return make_txn_obj(js, handle); } -static jsval_t lmdb_env_close_method(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t lmdb_env_close_method(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t self = js_getthis(js); + ant_value_t self = js_getthis(js); lmdb_env_handle_t *env = get_env_handle(js, self, false); if (!env) return js_mkerr(js, "Invalid LMDB env"); @@ -560,7 +560,7 @@ static jsval_t lmdb_env_close_method(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t lmdb_env_sync_method(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t lmdb_env_sync_method(ant_t *js, ant_value_t *args, int nargs) { lmdb_env_handle_t *env = get_env_handle(js, js_getthis(js), true); if (!env) return js_mkerr(js, "Invalid or closed LMDB env"); @@ -572,7 +572,7 @@ static jsval_t lmdb_env_sync_method(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t lmdb_env_stat_method(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t lmdb_env_stat_method(ant_t *js, ant_value_t *args, int nargs) { lmdb_env_handle_t *env = get_env_handle(js, js_getthis(js), true); if (!env) return js_mkerr(js, "Invalid or closed LMDB env"); @@ -585,7 +585,7 @@ static jsval_t lmdb_env_stat_method(ant_t *js, jsval_t *args, int nargs) { mdb_txn_abort(txn); if (rc != 0) return js_mkerr(js, "lmdb_stat failed: %s", mdb_strerror(rc)); - jsval_t out = js_mkobj(js); + ant_value_t out = js_mkobj(js); js_set(js, out, "psize", js_mknum((double)stat.ms_psize)); js_set(js, out, "depth", js_mknum((double)stat.ms_depth)); js_set(js, out, "branchPages", js_mknum((double)stat.ms_branch_pages)); @@ -596,7 +596,7 @@ static jsval_t lmdb_env_stat_method(ant_t *js, jsval_t *args, int nargs) { return out; } -static jsval_t lmdb_env_info_method(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t lmdb_env_info_method(ant_t *js, ant_value_t *args, int nargs) { lmdb_env_handle_t *env = get_env_handle(js, js_getthis(js), true); if (!env) return js_mkerr(js, "Invalid or closed LMDB env"); @@ -604,7 +604,7 @@ static jsval_t lmdb_env_info_method(ant_t *js, jsval_t *args, int nargs) { int rc = mdb_env_info(env->env, &info); if (rc != 0) return js_mkerr(js, "lmdb_env_info failed: %s", mdb_strerror(rc)); - jsval_t out = js_mkobj(js); + ant_value_t out = js_mkobj(js); js_set(js, out, "mapSize", js_mknum((double)info.me_mapsize)); js_set(js, out, "lastPgNo", js_mknum((double)info.me_last_pgno)); js_set(js, out, "lastTxnId", js_mknum((double)info.me_last_txnid)); @@ -614,7 +614,7 @@ static jsval_t lmdb_env_info_method(ant_t *js, jsval_t *args, int nargs) { return out; } -static jsval_t lmdb_txn_get_impl(ant_t *js, jsval_t *args, int nargs, bool as_string) { +static ant_value_t lmdb_txn_get_impl(ant_t *js, ant_value_t *args, int nargs, bool as_string) { if (nargs < 2) return js_mkerr(js, "txn.getBytes/getString(db, key) requires db and key"); lmdb_txn_handle_t *txn = get_txn_handle(js, js_getthis(js), true); @@ -637,7 +637,7 @@ static jsval_t lmdb_txn_get_impl(ant_t *js, jsval_t *args, int nargs, bool as_st return mdb_val_to_js(js, &value, as_string); } -static jsval_t lmdb_txn_get(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t lmdb_txn_get(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "txn.get(db, key, encoding?) requires db and key"); bool as_string = false; if (nargs > 2 && !parse_get_encoding(js, args[2], &as_string)) { @@ -646,15 +646,15 @@ static jsval_t lmdb_txn_get(ant_t *js, jsval_t *args, int nargs) { return lmdb_txn_get_impl(js, args, nargs, as_string); } -static jsval_t lmdb_txn_get_bytes(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t lmdb_txn_get_bytes(ant_t *js, ant_value_t *args, int nargs) { return lmdb_txn_get_impl(js, args, nargs, false); } -static jsval_t lmdb_txn_get_string(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t lmdb_txn_get_string(ant_t *js, ant_value_t *args, int nargs) { return lmdb_txn_get_impl(js, args, nargs, true); } -static jsval_t lmdb_txn_put(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t lmdb_txn_put(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 3) return js_mkerr(js, "txn.put(db, key, value, options?) requires db, key, and value"); lmdb_txn_handle_t *txn = get_txn_handle(js, js_getthis(js), true); @@ -670,7 +670,7 @@ static jsval_t lmdb_txn_put(ant_t *js, jsval_t *args, int nargs) { if (!js_to_mdb_val(js, args[1], &key)) return js_mkerr(js, "LMDB key must be string, ArrayBuffer, or TypedArray"); if (!js_to_mdb_val(js, args[2], &value)) return js_mkerr(js, "LMDB value must be string, ArrayBuffer, or TypedArray"); - jsval_t options = nargs > 3 ? args[3] : js_mkundef(); + ant_value_t options = nargs > 3 ? args[3] : js_mkundef(); unsigned int flags = 0; if (option_bool(js, options, "noOverwrite", false)) flags |= MDB_NOOVERWRITE; if (option_bool(js, options, "noDupData", false)) flags |= MDB_NODUPDATA; @@ -683,7 +683,7 @@ static jsval_t lmdb_txn_put(ant_t *js, jsval_t *args, int nargs) { return js_true; } -static jsval_t lmdb_txn_del(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t lmdb_txn_del(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "txn.del(db, key, value?) requires db and key"); lmdb_txn_handle_t *txn = get_txn_handle(js, js_getthis(js), true); @@ -710,8 +710,8 @@ static jsval_t lmdb_txn_del(ant_t *js, jsval_t *args, int nargs) { return js_true; } -static jsval_t lmdb_txn_commit(ant_t *js, jsval_t *args, int nargs) { - jsval_t self = js_getthis(js); +static ant_value_t lmdb_txn_commit(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t self = js_getthis(js); lmdb_txn_handle_t *txn = get_txn_handle(js, self, true); if (!txn) return js_mkerr(js, "Invalid or closed LMDB transaction"); @@ -727,8 +727,8 @@ static jsval_t lmdb_txn_commit(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t lmdb_txn_abort(ant_t *js, jsval_t *args, int nargs) { - jsval_t self = js_getthis(js); +static ant_value_t lmdb_txn_abort(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t self = js_getthis(js); lmdb_txn_handle_t *txn = get_txn_handle(js, self, false); if (!txn) return js_mkerr(js, "Invalid LMDB transaction"); if (txn->closed || !txn->txn) { @@ -744,7 +744,7 @@ static jsval_t lmdb_txn_abort(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t lmdb_db_get_impl(ant_t *js, jsval_t *args, int nargs, bool as_string) { +static ant_value_t lmdb_db_get_impl(ant_t *js, ant_value_t *args, int nargs, bool as_string) { if (nargs < 1) return js_mkerr(js, "db.getBytes/getString(key) requires key"); lmdb_db_handle_t *db = get_db_handle(js, js_getthis(js), true); if (!db) return js_mkerr(js, "Invalid or closed LMDB database handle"); @@ -770,12 +770,12 @@ static jsval_t lmdb_db_get_impl(ant_t *js, jsval_t *args, int nargs, bool as_str return js_mkerr(js, "lmdb_get failed: %s", mdb_strerror(rc)); } - jsval_t out = mdb_val_to_js(js, &value, as_string); + ant_value_t out = mdb_val_to_js(js, &value, as_string); mdb_txn_abort(txn); return out; } -static jsval_t lmdb_db_get(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t lmdb_db_get(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "db.get(key, encoding?) requires key"); bool as_string = false; if (nargs > 1 && !parse_get_encoding(js, args[1], &as_string)) { @@ -784,15 +784,15 @@ static jsval_t lmdb_db_get(ant_t *js, jsval_t *args, int nargs) { return lmdb_db_get_impl(js, args, nargs, as_string); } -static jsval_t lmdb_db_get_bytes(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t lmdb_db_get_bytes(ant_t *js, ant_value_t *args, int nargs) { return lmdb_db_get_impl(js, args, nargs, false); } -static jsval_t lmdb_db_get_string(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t lmdb_db_get_string(ant_t *js, ant_value_t *args, int nargs) { return lmdb_db_get_impl(js, args, nargs, true); } -static jsval_t lmdb_db_put(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t lmdb_db_put(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "db.put(key, value, options?) requires key and value"); lmdb_db_handle_t *db = get_db_handle(js, js_getthis(js), true); if (!db) return js_mkerr(js, "Invalid or closed LMDB database handle"); @@ -809,7 +809,7 @@ static jsval_t lmdb_db_put(ant_t *js, jsval_t *args, int nargs) { return js_mkerr(js, "LMDB key/value must be string, ArrayBuffer, or TypedArray"); } - jsval_t options = nargs > 2 ? args[2] : js_mkundef(); + ant_value_t options = nargs > 2 ? args[2] : js_mkundef(); unsigned int flags = 0; if (option_bool(js, options, "noOverwrite", false)) flags |= MDB_NOOVERWRITE; if (option_bool(js, options, "noDupData", false)) flags |= MDB_NODUPDATA; @@ -831,7 +831,7 @@ static jsval_t lmdb_db_put(ant_t *js, jsval_t *args, int nargs) { return js_true; } -static jsval_t lmdb_db_del(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t lmdb_db_del(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "db.del(key, value?) requires key"); lmdb_db_handle_t *db = get_db_handle(js, js_getthis(js), true); if (!db) return js_mkerr(js, "Invalid or closed LMDB database handle"); @@ -872,7 +872,7 @@ static jsval_t lmdb_db_del(ant_t *js, jsval_t *args, int nargs) { return js_true; } -static jsval_t lmdb_db_clear(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t lmdb_db_clear(ant_t *js, ant_value_t *args, int nargs) { lmdb_db_handle_t *db = get_db_handle(js, js_getthis(js), true); if (!db) return js_mkerr(js, "Invalid or closed LMDB database handle"); if (db->env->read_only) return js_mkerr(js, "Cannot clear on read-only LMDB env"); @@ -892,8 +892,8 @@ static jsval_t lmdb_db_clear(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t lmdb_db_drop(ant_t *js, jsval_t *args, int nargs) { - jsval_t self = js_getthis(js); +static ant_value_t lmdb_db_drop(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t self = js_getthis(js); lmdb_db_handle_t *db = get_db_handle(js, self, true); if (!db) return js_mkerr(js, "Invalid or closed LMDB database handle"); if (db->env->read_only) return js_mkerr(js, "Cannot drop on read-only LMDB env"); @@ -926,10 +926,10 @@ static jsval_t lmdb_db_drop(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t lmdb_db_close(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t lmdb_db_close(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t self = js_getthis(js); + ant_value_t self = js_getthis(js); lmdb_db_handle_t *db = get_db_handle(js, self, false); if (!db) return js_mkerr(js, "Invalid LMDB database handle"); if (db->closed) { @@ -947,7 +947,7 @@ static jsval_t lmdb_db_close(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t lmdb_strerror_fn(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t lmdb_strerror_fn(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || vtype(args[0]) != T_NUM) { return js_mkerr(js, "lmdb.strerror(code) requires a numeric code"); } @@ -956,24 +956,24 @@ static jsval_t lmdb_strerror_fn(ant_t *js, jsval_t *args, int nargs) { return js_mkstr(js, err, strlen(err)); } -static jsval_t lmdb_env_constructor(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t lmdb_env_constructor(ant_t *js, ant_value_t *args, int nargs) { return js_mkerr(js, "LMDBEnv cannot be constructed directly; use lmdb.open()"); } -static jsval_t lmdb_db_constructor(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t lmdb_db_constructor(ant_t *js, ant_value_t *args, int nargs) { return js_mkerr(js, "LMDBDatabase cannot be constructed directly; use env.openDB()"); } -static jsval_t lmdb_txn_constructor(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t lmdb_txn_constructor(ant_t *js, ant_value_t *args, int nargs) { return js_mkerr(js, "LMDBTxn cannot be constructed directly; use env.beginTxn()"); } static void ensure_lmdb_prototypes(ant_t *js) { if (lmdb_types.ready) return; - jsval_t object_proto = js->object; + ant_value_t object_proto = js->object; - jsval_t env_ctor_obj = js_mkobj(js); - jsval_t env_proto = js_mkobj(js); + ant_value_t env_ctor_obj = js_mkobj(js); + ant_value_t env_proto = js_mkobj(js); js_set_proto(js, env_proto, object_proto); js_set(js, env_proto, "openDB", js_mkfun(lmdb_env_open_db)); @@ -988,8 +988,8 @@ static void ensure_lmdb_prototypes(ant_t *js) { js_mkprop_fast(js, env_ctor_obj, "name", 4, ANT_STRING("LMDBEnv")); js_set_descriptor(js, env_ctor_obj, "name", 4, 0); - jsval_t db_ctor_obj = js_mkobj(js); - jsval_t db_proto = js_mkobj(js); + ant_value_t db_ctor_obj = js_mkobj(js); + ant_value_t db_proto = js_mkobj(js); js_set_proto(js, db_proto, object_proto); js_set(js, db_proto, "get", js_mkfun(lmdb_db_get)); @@ -1006,8 +1006,8 @@ static void ensure_lmdb_prototypes(ant_t *js) { js_mkprop_fast(js, db_ctor_obj, "name", 4, ANT_STRING("LMDBDatabase")); js_set_descriptor(js, db_ctor_obj, "name", 4, 0); - jsval_t txn_ctor_obj = js_mkobj(js); - jsval_t txn_proto = js_mkobj(js); + ant_value_t txn_ctor_obj = js_mkobj(js); + ant_value_t txn_proto = js_mkobj(js); js_set_proto(js, txn_proto, object_proto); js_set(js, txn_proto, "get", js_mkfun(lmdb_txn_get)); @@ -1032,36 +1032,36 @@ static void ensure_lmdb_prototypes(ant_t *js) { lmdb_types.ready = true; } -static jsval_t make_env_obj(ant_t *js, lmdb_env_handle_t *env) { +static ant_value_t make_env_obj(ant_t *js, lmdb_env_handle_t *env) { ensure_lmdb_prototypes(js); - jsval_t obj = js_mkobj(js); + ant_value_t obj = js_mkobj(js); js_set_slot(js, obj, SLOT_DATA, ANT_PTR(env)); register_env_ref(obj, env); if (is_special_object(lmdb_types.env_proto)) js_set_proto(js, obj, lmdb_types.env_proto); return obj; } -static jsval_t make_db_obj(ant_t *js, lmdb_db_handle_t *db) { +static ant_value_t make_db_obj(ant_t *js, lmdb_db_handle_t *db) { ensure_lmdb_prototypes(js); - jsval_t obj = js_mkobj(js); + ant_value_t obj = js_mkobj(js); js_set_slot(js, obj, SLOT_DATA, ANT_PTR(db)); register_db_ref(obj, db); if (is_special_object(lmdb_types.db_proto)) js_set_proto(js, obj, lmdb_types.db_proto); return obj; } -static jsval_t make_txn_obj(ant_t *js, lmdb_txn_handle_t *txn) { +static ant_value_t make_txn_obj(ant_t *js, lmdb_txn_handle_t *txn) { ensure_lmdb_prototypes(js); - jsval_t obj = js_mkobj(js); + ant_value_t obj = js_mkobj(js); js_set_slot(js, obj, SLOT_DATA, ANT_PTR(txn)); register_txn_ref(obj, txn); if (is_special_object(lmdb_types.txn_proto)) js_set_proto(js, obj, lmdb_types.txn_proto); return obj; } -jsval_t lmdb_library(ant_t *js) { +ant_value_t lmdb_library(ant_t *js) { ensure_lmdb_prototypes(js); - jsval_t lib = js_mkobj(js); + ant_value_t lib = js_mkobj(js); js_set(js, lib, "open", js_mkfun(lmdb_open)); js_set(js, lib, "strerror", js_mkfun(lmdb_strerror_fn)); js_set(js, lib, "Env", lmdb_types.env_ctor); @@ -1076,7 +1076,7 @@ jsval_t lmdb_library(ant_t *js) { js_set(js, lib, "versionMinor", js_mknum((double)minor)); js_set(js, lib, "versionPatch", js_mknum((double)patch)); - jsval_t constants = js_mkobj(js); + ant_value_t constants = js_mkobj(js); js_set(js, constants, "NOOVERWRITE", js_mknum((double)MDB_NOOVERWRITE)); js_set(js, constants, "NODUPDATA", js_mknum((double)MDB_NODUPDATA)); js_set(js, constants, "APPEND", js_mknum((double)MDB_APPEND)); diff --git a/src/modules/localstorage.c b/src/modules/localstorage.c index ad75e12..e4d438b 100644 --- a/src/modules/localstorage.c +++ b/src/modules/localstorage.c @@ -158,7 +158,7 @@ static char *storage_key(size_t index) { } // localStorage.setItem(key, value) -static jsval_t js_localstorage_setItem(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_localstorage_setItem(ant_t *js, ant_value_t *args, int nargs) { CHECK_FILE_SET(js); if (nargs < 2) { @@ -175,7 +175,7 @@ static jsval_t js_localstorage_setItem(ant_t *js, jsval_t *args, int nargs) { } // localStorage.getItem(key) -static jsval_t js_localstorage_getItem(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_localstorage_getItem(ant_t *js, ant_value_t *args, int nargs) { CHECK_FILE_SET(js); if (nargs < 1) { @@ -192,7 +192,7 @@ static jsval_t js_localstorage_getItem(ant_t *js, jsval_t *args, int nargs) { } // localStorage.removeItem(key) -static jsval_t js_localstorage_removeItem(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_localstorage_removeItem(ant_t *js, ant_value_t *args, int nargs) { CHECK_FILE_SET(js); if (nargs < 1) { @@ -207,7 +207,7 @@ static jsval_t js_localstorage_removeItem(ant_t *js, jsval_t *args, int nargs) { } // localStorage.clear() -static jsval_t js_localstorage_clear(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_localstorage_clear(ant_t *js, ant_value_t *args, int nargs) { CHECK_FILE_SET(js); (void)args; (void)nargs; storage_clear(); @@ -216,7 +216,7 @@ static jsval_t js_localstorage_clear(ant_t *js, jsval_t *args, int nargs) { } // localStorage.key(index) -static jsval_t js_localstorage_key(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_localstorage_key(ant_t *js, ant_value_t *args, int nargs) { CHECK_FILE_SET(js); if (nargs < 1) { @@ -239,14 +239,14 @@ static jsval_t js_localstorage_key(ant_t *js, jsval_t *args, int nargs) { } // localStorage.length -static jsval_t js_localstorage_length(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_localstorage_length(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; CHECK_FILE_SET(js) return js_mknum((double)storage_length()); } // localStorage.setFile(path) -static jsval_t js_localstorage_setFile(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_localstorage_setFile(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) { return js_mkerr(js, "Failed to execute 'setFile' on 'Storage': 1 argument required"); } @@ -275,7 +275,7 @@ static jsval_t js_localstorage_setFile(ant_t *js, jsval_t *args, int nargs) { void init_localstorage_module() { ant_t *js = rt->js; - jsval_t glob = js_glob(js); + ant_value_t glob = js_glob(js); const char *file_path = rt->ls_fp; if (file_path) { @@ -283,7 +283,7 @@ void init_localstorage_module() { storage_load(); } - jsval_t storage_obj = js_mkobj(js); + ant_value_t storage_obj = js_mkobj(js); js_set(js, storage_obj, "setItem", js_mkfun(js_localstorage_setItem)); js_set(js, storage_obj, "getItem", js_mkfun(js_localstorage_getItem)); @@ -292,7 +292,7 @@ void init_localstorage_module() { js_set(js, storage_obj, "key", js_mkfun(js_localstorage_key)); js_set(js, storage_obj, "setFile", js_mkfun(js_localstorage_setFile)); - jsval_t length_getter = js_mkfun(js_localstorage_length); + ant_value_t length_getter = js_mkfun(js_localstorage_length); js_set_getter_desc(js, storage_obj, "length", 6, length_getter, JS_DESC_E); js_set_sym(js, storage_obj, get_toStringTag_sym(), js_mkstr(js, "Storage", 7)); diff --git a/src/modules/module.c b/src/modules/module.c index 57520e7..984d442 100644 --- a/src/modules/module.c +++ b/src/modules/module.c @@ -12,59 +12,59 @@ #include "esm/library.h" #include "modules/symbol.h" -typedef struct { ant_t *js; jsval_t arr; } builtin_iter_ctx_t; +typedef struct { ant_t *js; ant_value_t arr; } builtin_iter_ctx_t; static void push_builtin_name(const char *name, void *ud) { builtin_iter_ctx_t *ctx = (builtin_iter_ctx_t *)ud; js_arr_push(ctx->js, ctx->arr, js_mkstr(ctx->js, name, strlen(name))); } -static jsval_t builtin_createRequire_call(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_createRequire_call(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || vtype(args[0]) != T_STR) return js_mkerr(js, "require() expects a string specifier"); - jsval_t fn = js_getcurrentfunc(js); - jsval_t data = js_get_slot(js, fn, SLOT_DATA); + ant_value_t fn = js_getcurrentfunc(js); + ant_value_t data = js_get_slot(js, fn, SLOT_DATA); const char *prev_filename = js->filename; if (vtype(data) == T_STR) { - jsoff_t plen = 0; - jsoff_t poff = vstr(js, data, &plen); + ant_offset_t plen = 0; + ant_offset_t poff = vstr(js, data, &plen); js_set_filename(js, (const char *)&js->mem[poff]); } - jsval_t ns = js_esm_import_sync(js, args[0]); + ant_value_t ns = js_esm_import_sync(js, args[0]); js_set_filename(js, prev_filename); if (is_err(ns)) return ns; if (vtype(ns) == T_OBJ) { - jsval_t default_export = js_get_slot(js, ns, SLOT_DEFAULT); + ant_value_t default_export = js_get_slot(js, ns, SLOT_DEFAULT); if (vtype(default_export) != T_UNDEF) return default_export; } return ns; } // require.resolve(specifier) -static jsval_t builtin_createRequire_resolve(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_createRequire_resolve(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || vtype(args[0]) != T_STR) return js_mkerr(js, "require.resolve() expects a string specifier"); - jsval_t fn = js_getcurrentfunc(js); - jsval_t data = js_get_slot(js, fn, SLOT_DATA); + ant_value_t fn = js_getcurrentfunc(js); + ant_value_t data = js_get_slot(js, fn, SLOT_DATA); const char *base_path = js->filename ? js->filename : "."; if (vtype(data) == T_STR) { - jsoff_t dlen = 0; - jsoff_t doff = vstr(js, data, &dlen); + ant_offset_t dlen = 0; + ant_offset_t doff = vstr(js, data, &dlen); base_path = (const char *)&js->mem[doff]; } - jsval_t resolved = js_esm_resolve_specifier(js, args[0], base_path); + ant_value_t resolved = js_esm_resolve_specifier(js, args[0], base_path); if (is_err(resolved)) return resolved; if (vtype(resolved) != T_STR) return resolved; - jsoff_t len = 0; - jsoff_t off = vstr(js, resolved, &len); + ant_offset_t len = 0; + ant_offset_t off = vstr(js, resolved, &len); const char *s = (const char *)&js->mem[off]; static const char *prefix = "file://"; @@ -79,10 +79,10 @@ static jsval_t builtin_createRequire_resolve(ant_t *js, jsval_t *args, int nargs } // createRequire(filename) -static jsval_t builtin_createRequire(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_createRequire(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "createRequire() requires a filename argument"); - jsval_t filename_val = args[0]; + ant_value_t filename_val = args[0]; if (vtype(filename_val) != T_STR) return js_mkerr(js, "createRequire() filename must be a string"); @@ -101,35 +101,35 @@ static jsval_t builtin_createRequire(ant_t *js, jsval_t *args, int nargs) { path_len -= prefix_len; } - jsval_t path_val = js_mkstr(js, path, path_len); - jsval_t require_fn = js_heavy_mkfun(js, builtin_createRequire_call, path_val); - jsval_t resolve_fn = js_heavy_mkfun(js, builtin_createRequire_resolve, path_val); + ant_value_t path_val = js_mkstr(js, path, path_len); + ant_value_t require_fn = js_heavy_mkfun(js, builtin_createRequire_call, path_val); + ant_value_t resolve_fn = js_heavy_mkfun(js, builtin_createRequire_resolve, path_val); js_set(js, require_fn, "resolve", resolve_fn); return require_fn; } // Module._resolveFilename(request, parent) -static jsval_t builtin_resolveFilename(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_resolveFilename(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || vtype(args[0]) != T_STR) return js_mkerr(js, "Module._resolveFilename() requires a string request"); const char *base_path = js->filename ? js->filename : "."; if (nargs >= 2 && vtype(args[1]) == T_OBJ) { - jsval_t parent_filename = js_get(js, args[1], "filename"); + ant_value_t parent_filename = js_get(js, args[1], "filename"); if (vtype(parent_filename) == T_STR) { - jsoff_t plen = 0; - jsoff_t poff = vstr(js, parent_filename, &plen); + ant_offset_t plen = 0; + ant_offset_t poff = vstr(js, parent_filename, &plen); base_path = (const char *)&js->mem[poff]; } } - jsval_t resolved = js_esm_resolve_specifier(js, args[0], base_path); + ant_value_t resolved = js_esm_resolve_specifier(js, args[0], base_path); if (is_err(resolved)) return resolved; if (vtype(resolved) != T_STR) return resolved; - jsoff_t len = 0; - jsoff_t off = vstr(js, resolved, &len); + ant_offset_t len = 0; + ant_offset_t off = vstr(js, resolved, &len); const char *s = (const char *)&js->mem[off]; static const char *prefix = "file://"; @@ -143,11 +143,11 @@ static jsval_t builtin_resolveFilename(ant_t *js, jsval_t *args, int nargs) { return resolved; } -jsval_t module_library(ant_t *js) { - jsval_t lib = js_mkobj(js); +ant_value_t module_library(ant_t *js) { + ant_value_t lib = js_mkobj(js); js_set(js, lib, "createRequire", js_mkfun(builtin_createRequire)); - jsval_t modules_arr = js_mkarr(js); + ant_value_t modules_arr = js_mkarr(js); builtin_iter_ctx_t ctx = { js, modules_arr }; ant_library_foreach(push_builtin_name, &ctx); diff --git a/src/modules/napi.c b/src/modules/napi.c index b40e0e9..8ed4207 100644 --- a/src/modules/napi.c +++ b/src/modules/napi.c @@ -67,14 +67,14 @@ struct napi_callback_info__ { struct napi_ref__ { ant_napi_env_t *env; - jshdl_t root; + ant_handle_t root; napi_value value; uint32_t refcount; }; struct napi_deferred__ { ant_napi_env_t *env; - jshdl_t promise_root; + ant_handle_t promise_root; bool settled; }; @@ -128,7 +128,7 @@ typedef struct napi_tsfn_item { struct napi_threadsafe_function__ { ant_napi_env_t *env; - jshdl_t func_root; + ant_handle_t func_root; napi_threadsafe_function_call_js call_js_cb; node_api_basic_finalize thread_finalize_cb; void *thread_finalize_data; @@ -226,7 +226,7 @@ napi_env ant_napi_get_env(ant_t *js) { return (napi_env)napi_get_or_create_env(js); } -static inline bool napi_is_callable(jsval_t v) { +static inline bool napi_is_callable(ant_value_t v) { uint8_t t = vtype(v); return t == T_FUNC || t == T_CFUNC; } @@ -239,7 +239,7 @@ static void napi_mark_pending_exception(napi_env env, napi_value exception) { napi_set_last(env, napi_pending_exception, "pending exception"); } -static napi_status napi_check_pending_from_result(napi_env env, jsval_t result) { +static napi_status napi_check_pending_from_result(napi_env env, ant_value_t result) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; if (!nenv || !nenv->js) return napi_set_last(env, napi_invalid_arg, "invalid env"); @@ -253,30 +253,30 @@ static napi_status napi_check_pending_from_result(napi_env env, jsval_t result) return napi_set_last(env, napi_ok, NULL); } -static bool napi_slot_get_u64(ant_t *js, jsval_t obj, internal_slot_t slot, uint64_t *out) { - jsval_t value = js_get_slot(js, obj, slot); +static bool napi_slot_get_u64(ant_t *js, ant_value_t obj, internal_slot_t slot, uint64_t *out) { + ant_value_t value = js_get_slot(js, obj, slot); if (vtype(value) != T_NUM) return false; *out = (uint64_t)js_getnum(value); return true; } -static void napi_slot_set_u64(ant_t *js, jsval_t obj, internal_slot_t slot, uint64_t v) { +static void napi_slot_set_u64(ant_t *js, ant_value_t obj, internal_slot_t slot, uint64_t v) { js_set_slot(js, obj, slot, js_mknum((double)v)); } static napi_external_entry_t *napi_find_external(ant_t *js, napi_value value) { - if (!is_object_type((jsval_t)value)) return NULL; + if (!is_object_type((ant_value_t)value)) return NULL; uint64_t id = 0; - if (!napi_slot_get_u64(js, (jsval_t)value, SLOT_NAPI_EXTERNAL_ID, &id)) return NULL; + if (!napi_slot_get_u64(js, (ant_value_t)value, SLOT_NAPI_EXTERNAL_ID, &id)) return NULL; napi_external_entry_t *entry = NULL; HASH_FIND(hh, g_napi_externals, &id, sizeof(id), entry); return entry; } static napi_wrap_entry_t *napi_find_wrap(ant_t *js, napi_value value) { - if (!is_object_type((jsval_t)value)) return NULL; + if (!is_object_type((ant_value_t)value)) return NULL; uint64_t id = 0; - if (!napi_slot_get_u64(js, (jsval_t)value, SLOT_NAPI_WRAP_ID, &id)) return NULL; + if (!napi_slot_get_u64(js, (ant_value_t)value, SLOT_NAPI_WRAP_ID, &id)) return NULL; napi_wrap_entry_t *entry = NULL; HASH_FIND(hh, g_napi_wraps, &id, sizeof(id), entry); return entry; @@ -287,7 +287,7 @@ static bool napi_get_typedarray_data( napi_value value, TypedArrayData **out ) { - jsval_t slot = js_get_slot(js, (jsval_t)value, SLOT_BUFFER); + ant_value_t slot = js_get_slot(js, (ant_value_t)value, SLOT_BUFFER); if (vtype(slot) != T_TYPEDARRAY) return false; TypedArrayData *ta = (TypedArrayData *)js_gettypedarray(slot); if (!ta || !ta->buffer || ta->buffer->is_detached) return false; @@ -357,9 +357,9 @@ static int napi_desc_flags(napi_property_attributes attributes) { return flags; } -static jsval_t napi_callback_trampoline(ant_t *js, jsval_t *args, int nargs) { - jsval_t current = js_getcurrentfunc(js); - jsval_t data_slot = js_get_slot(js, current, SLOT_DATA); +static ant_value_t napi_callback_trampoline(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t current = js_getcurrentfunc(js); + ant_value_t data_slot = js_get_slot(js, current, SLOT_DATA); if (vtype(data_slot) != T_NUM) return js_mkundef(); napi_callback_binding_t *binding = (napi_callback_binding_t *)(uintptr_t)js_getnum(data_slot); @@ -379,14 +379,14 @@ static jsval_t napi_callback_trampoline(ant_t *js, jsval_t *args, int nargs) { napi_value ret = binding->cb((napi_env)nenv, (napi_callback_info)&info); if (nenv->has_pending_exception) { - jsval_t ex = (jsval_t)nenv->pending_exception; + ant_value_t ex = (ant_value_t)nenv->pending_exception; nenv->has_pending_exception = false; nenv->pending_exception = (napi_value)js_mkundef(); return js_throw(js, ex); } - if ((jsval_t)ret == 0) return js_mkundef(); - return (jsval_t)ret; + if ((ant_value_t)ret == 0) return js_mkundef(); + return (ant_value_t)ret; } static napi_status napi_create_function_common( @@ -409,7 +409,7 @@ static napi_status napi_create_function_common( binding->cb = cb; binding->data = data; - jsval_t fn = js_heavy_mkfun(nenv->js, napi_callback_trampoline, ANT_PTR(binding)); + ant_value_t fn = js_heavy_mkfun(nenv->js, napi_callback_trampoline, ANT_PTR(binding)); if (utf8name && utf8name[0]) { size_t nlen = (length == NAPI_AUTO_LENGTH) ? strlen(utf8name) : length; js_set(nenv->js, fn, "name", js_mkstr(nenv->js, utf8name, nlen)); @@ -419,7 +419,7 @@ static napi_status napi_create_function_common( return napi_set_last(env, napi_ok, NULL); } -static jsval_t napi_make_string(ant_t *js, const char *s, size_t len) { +static ant_value_t napi_make_string(ant_t *js, const char *s, size_t len) { if (!s) return js_mkstr(js, "", 0); if (len == NAPI_AUTO_LENGTH) len = strlen(s); return js_mkstr(js, s, len); @@ -437,17 +437,17 @@ static napi_status napi_make_error_object( } ant_t *js = nenv->js; - jsval_t message = (jsval_t)msg; + ant_value_t message = (ant_value_t)msg; if (vtype(message) != T_STR) { message = coerce_to_str(js, message); if (is_err(message)) return napi_check_pending_from_result(env, message); } - jsval_t err = js_mkobj(js); + ant_value_t err = js_mkobj(js); js_set(js, err, "name", js_mkstr(js, name, strlen(name))); js_set(js, err, "message", message); - jsval_t proto = js_get_ctor_proto(js, name, strlen(name)); + ant_value_t proto = js_get_ctor_proto(js, name, strlen(name)); if (is_object_type(proto)) js_set_proto(js, err, proto); *result = (napi_value)err; @@ -462,7 +462,7 @@ static napi_status napi_throw_with_message( ant_napi_env_t *nenv = (ant_napi_env_t *)env; if (!nenv || !nenv->js) return napi_set_last(env, napi_invalid_arg, "invalid env"); - jsval_t error = js_mkerr_typed(nenv->js, err_type, "%s", msg ? msg : ""); + ant_value_t error = js_mkerr_typed(nenv->js, err_type, "%s", msg ? msg : ""); if (is_err(error) && nenv->js->thrown_exists) { napi_mark_pending_exception(env, (napi_value)nenv->js->thrown_value); return napi_pending_exception; @@ -495,7 +495,7 @@ static void napi_tsfn_async_cb(uv_async_t *handle) { break; } - jsval_t cb = js_deref(js, tsfn->func_root); + ant_value_t cb = js_deref(js, tsfn->func_root); if (tsfn->call_js_cb) { tsfn->call_js_cb((napi_env)tsfn->env, (napi_value)cb, tsfn->context, item->data); } else if (napi_is_callable(cb)) { @@ -546,7 +546,7 @@ static void napi_async_work_after_cb(uv_work_t *req, int status) { if (work->delete_after_complete) free(work); } -static jsval_t napi_dlopen_common(ant_t *js, jsval_t module_obj, const char *filename) { +static ant_value_t napi_dlopen_common(ant_t *js, ant_value_t module_obj, const char *filename) { napi_env env = ant_napi_get_env(js); if (!env) return js_mkerr(js, "napi env allocation failed"); @@ -562,25 +562,25 @@ static jsval_t napi_dlopen_common(ant_t *js, jsval_t module_obj, const char *fil g_pending_napi_module = NULL; napi_register_module_v1_fn reg_fn = (napi_register_module_v1_fn)NAPI_DLSYM(handle, "napi_register_module_v1"); - jsval_t exports = js_get(js, module_obj, "exports"); + ant_value_t exports = js_get(js, module_obj, "exports"); if (!is_object_type(exports)) { exports = js_mkobj(js); js_set(js, module_obj, "exports", exports); } - jsval_t ret = js_mkundef(); + ant_value_t ret = js_mkundef(); if (reg_fn) { - ret = (jsval_t)reg_fn(env, (napi_value)exports); + ret = (ant_value_t)reg_fn(env, (napi_value)exports); } else if (g_pending_napi_module && g_pending_napi_module->nm_register_func) { - ret = (jsval_t)g_pending_napi_module->nm_register_func(env, (napi_value)exports); + ret = (ant_value_t)g_pending_napi_module->nm_register_func(env, (napi_value)exports); } else { return js_mkerr(js, "No N-API registration entrypoint found in '%s'", filename); } ant_napi_env_t *nenv = (ant_napi_env_t *)env; if (nenv->has_pending_exception || js->thrown_exists) { - jsval_t ex = nenv->has_pending_exception - ? (jsval_t)nenv->pending_exception + ant_value_t ex = nenv->has_pending_exception + ? (ant_value_t)nenv->pending_exception : js->thrown_value; nenv->has_pending_exception = false; nenv->pending_exception = (napi_value)js_mkundef(); @@ -601,7 +601,7 @@ static jsval_t napi_dlopen_common(ant_t *js, jsval_t module_obj, const char *fil return exports; } -jsval_t napi_process_dlopen_js(ant_t *js, jsval_t *args, int nargs) { +ant_value_t napi_process_dlopen_js(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "process.dlopen(module, filename) requires 2 arguments"); if (!is_object_type(args[0])) return js_mkerr(js, "process.dlopen module must be an object"); if (vtype(args[1]) != T_STR) return js_mkerr(js, "process.dlopen filename must be a string"); @@ -610,34 +610,34 @@ jsval_t napi_process_dlopen_js(ant_t *js, jsval_t *args, int nargs) { const char *path = js_getstr(js, args[1], &path_len); if (!path || path_len == 0) return js_mkerr(js, "process.dlopen filename must be non-empty"); - jsval_t loaded = napi_dlopen_common(js, args[0], path); + ant_value_t loaded = napi_dlopen_common(js, args[0], path); if (is_err(loaded)) return loaded; return js_mkundef(); } -jsval_t napi_load_native_module(ant_t *js, const char *module_path, jsval_t ns) { +ant_value_t napi_load_native_module(ant_t *js, const char *module_path, ant_value_t ns) { if (!module_path) return js_mkerr(js, "native module path is null"); - jsval_t module_obj = js_mkobj(js); - jsval_t exports_obj = js_mkobj(js); + ant_value_t module_obj = js_mkobj(js); + ant_value_t exports_obj = js_mkobj(js); js_set(js, module_obj, "exports", exports_obj); js_set(js, module_obj, "filename", js_mkstr(js, module_path, strlen(module_path))); js_set(js, module_obj, "id", js_mkstr(js, module_path, strlen(module_path))); js_set(js, module_obj, "loaded", js_false); - jsval_t process_obj = js_get(js, js_glob(js), "process"); - jsval_t dlopen_fn = is_object_type(process_obj) ? js_get(js, process_obj, "dlopen") : js_mkundef(); + ant_value_t process_obj = js_get(js, js_glob(js), "process"); + ant_value_t dlopen_fn = is_object_type(process_obj) ? js_get(js, process_obj, "dlopen") : js_mkundef(); if (napi_is_callable(dlopen_fn)) { - jsval_t argv[2] = {module_obj, js_mkstr(js, module_path, strlen(module_path))}; - jsval_t dl_res = sv_vm_call(js->vm, js, dlopen_fn, process_obj, argv, 2, NULL, false); + ant_value_t argv[2] = {module_obj, js_mkstr(js, module_path, strlen(module_path))}; + ant_value_t dl_res = sv_vm_call(js->vm, js, dlopen_fn, process_obj, argv, 2, NULL, false); if (is_err(dl_res) || js->thrown_exists) return js_throw(js, js->thrown_value); } else { - jsval_t load_res = napi_dlopen_common(js, module_obj, module_path); + ant_value_t load_res = napi_dlopen_common(js, module_obj, module_path); if (is_err(load_res)) return load_res; } - jsval_t exports_val = js_get(js, module_obj, "exports"); + ant_value_t exports_val = js_get(js, module_obj, "exports"); if (!is_object_type(ns)) return exports_val; setprop_cstr(js, ns, "default", 7, exports_val); @@ -647,7 +647,7 @@ jsval_t napi_load_native_module(ant_t *js, const char *module_path, jsval_t ns) ant_iter_t iter = js_prop_iter_begin(js, exports_val); const char *key = NULL; size_t key_len = 0; - jsval_t value = js_mkundef(); + ant_value_t value = js_mkundef(); while (js_prop_iter_next(&iter, &key, &key_len, &value)) { if (key_len == 7 && memcmp(key, "default", 7) == 0) continue; @@ -713,8 +713,8 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_array_with_length( ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; if (!nenv || !nenv->js || !result) return napi_set_last(env, napi_invalid_arg, "invalid argument"); - jsval_t arr = js_mkarr(nenv->js); - jsval_t r = js_setprop( + ant_value_t arr = js_mkarr(nenv->js); + ant_value_t r = js_setprop( nenv->js, arr, js_mkstr(nenv->js, "length", 6), js_mknum((double)length) @@ -781,10 +781,10 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_symbol( if (!nenv || !nenv->js || !result) return napi_set_last(env, napi_invalid_arg, "invalid argument"); const char *desc = NULL; - if (vtype((jsval_t)description) == T_STR) { - desc = js_getstr(nenv->js, (jsval_t)description, NULL); - } else if (!is_undefined((jsval_t)description) && !is_null((jsval_t)description)) { - jsval_t s = coerce_to_str(nenv->js, (jsval_t)description); + if (vtype((ant_value_t)description) == T_STR) { + desc = js_getstr(nenv->js, (ant_value_t)description, NULL); + } else if (!is_undefined((ant_value_t)description) && !is_null((ant_value_t)description)) { + ant_value_t s = coerce_to_str(nenv->js, (ant_value_t)description); if (is_err(s)) return napi_check_pending_from_result(env, s); desc = js_getstr(nenv->js, s, NULL); } @@ -853,7 +853,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_external( entry->finalize_hint = finalize_hint; HASH_ADD(hh, g_napi_externals, id, sizeof(entry->id), entry); - jsval_t obj = js_mkobj(nenv->js); + ant_value_t obj = js_mkobj(nenv->js); napi_slot_set_u64(nenv->js, obj, SLOT_NAPI_EXTERNAL_ID, entry->id); *result = (napi_value)obj; @@ -873,7 +873,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_promise( struct napi_deferred__ *def = (struct napi_deferred__ *)calloc(1, sizeof(*def)); if (!def) return napi_set_last(env, napi_generic_failure, "out of memory"); - jsval_t p = js_mkpromise(nenv->js); + ant_value_t p = js_mkpromise(nenv->js); def->env = nenv; def->promise_root = js_root(nenv->js, p); def->settled = false; @@ -894,8 +894,8 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_resolve_deferred( return napi_set_last(env, napi_invalid_arg, "invalid deferred"); } - jsval_t promise = js_deref(nenv->js, def->promise_root); - js_resolve_promise(nenv->js, promise, (jsval_t)resolution); + ant_value_t promise = js_deref(nenv->js, def->promise_root); + js_resolve_promise(nenv->js, promise, (ant_value_t)resolution); def->settled = true; js_root_update(nenv->js, def->promise_root, js_mkundef()); return napi_set_last(env, napi_ok, NULL); @@ -912,8 +912,8 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_reject_deferred( return napi_set_last(env, napi_invalid_arg, "invalid deferred"); } - jsval_t promise = js_deref(nenv->js, def->promise_root); - js_reject_promise(nenv->js, promise, (jsval_t)rejection); + ant_value_t promise = js_deref(nenv->js, def->promise_root); + js_reject_promise(nenv->js, promise, (ant_value_t)rejection); def->settled = true; js_root_update(nenv->js, def->promise_root, js_mkundef()); return napi_set_last(env, napi_ok, NULL); @@ -931,7 +931,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_buffer( ArrayBufferData *buf = create_array_buffer_data(length); if (!buf) return napi_set_last(env, napi_generic_failure, "allocation failed"); - jsval_t value = create_typed_array(nenv->js, TYPED_ARRAY_UINT8, buf, 0, length, "Buffer"); + ant_value_t value = create_typed_array(nenv->js, TYPED_ARRAY_UINT8, buf, 0, length, "Buffer"); if (is_err(value)) return napi_check_pending_from_result(env, value); if (data) *data = buf->data; @@ -980,7 +980,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_arraybuffer( ArrayBufferData *ab = create_array_buffer_data(byte_length); if (!ab) return napi_set_last(env, napi_generic_failure, "allocation failed"); - jsval_t ab_obj = create_arraybuffer_obj(nenv->js, ab); + ant_value_t ab_obj = create_arraybuffer_obj(nenv->js, ab); free_array_buffer_data(ab); if (data) *data = ab->data; @@ -1014,11 +1014,11 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_typedarray( napi_value *result ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; - if (!nenv || !nenv->js || !result || !is_object_type((jsval_t)arraybuffer)) { + if (!nenv || !nenv->js || !result || !is_object_type((ant_value_t)arraybuffer)) { return napi_set_last(env, napi_invalid_arg, "invalid argument"); } - jsval_t slot = js_get_slot(nenv->js, (jsval_t)arraybuffer, SLOT_BUFFER); + ant_value_t slot = js_get_slot(nenv->js, (ant_value_t)arraybuffer, SLOT_BUFFER); if (vtype(slot) != T_NUM) return napi_set_last(env, napi_arraybuffer_expected, "arraybuffer expected"); ArrayBufferData *ab = (ArrayBufferData *)(uintptr_t)js_getnum(slot); @@ -1047,14 +1047,14 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_typedarray( return napi_set_last(env, napi_invalid_arg, "typedarray out of bounds"); } - jsval_t out = create_typed_array_with_buffer( + ant_value_t out = create_typed_array_with_buffer( nenv->js, ta_type, ab, byte_offset, length, napi_typed_array_name(ta_type), - (jsval_t)arraybuffer + (ant_value_t)arraybuffer ); if (is_err(out)) return napi_check_pending_from_result(env, out); @@ -1077,7 +1077,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_reference( ref->env = nenv; ref->value = value; ref->refcount = initial_refcount; - ref->root = js_root(nenv->js, (jsval_t)value); + ref->root = js_root(nenv->js, (ant_value_t)value); if (initial_refcount == 0) js_root_update(nenv->js, ref->root, js_mkundef()); *result = (napi_ref)ref; @@ -1105,7 +1105,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_reference_ref( struct napi_ref__ *r = (struct napi_ref__ *)ref; if (!nenv || !nenv->js || !r) return napi_set_last(env, napi_invalid_arg, "invalid argument"); - if (r->refcount == 0) js_root_update(nenv->js, r->root, (jsval_t)r->value); + if (r->refcount == 0) js_root_update(nenv->js, r->root, (ant_value_t)r->value); r->refcount++; if (result) *result = r->refcount; @@ -1150,8 +1150,8 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_get_value_double( double *result ) { if (!env || !result) return napi_set_last(env, napi_invalid_arg, "invalid argument"); - if (vtype((jsval_t)value) != T_NUM) return napi_set_last(env, napi_number_expected, "number expected"); - *result = js_getnum((jsval_t)value); + if (vtype((ant_value_t)value) != T_NUM) return napi_set_last(env, napi_number_expected, "number expected"); + *result = js_getnum((ant_value_t)value); return napi_set_last(env, napi_ok, NULL); } @@ -1161,8 +1161,8 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_get_value_int32( int32_t *result ) { if (!env || !result) return napi_set_last(env, napi_invalid_arg, "invalid argument"); - if (vtype((jsval_t)value) != T_NUM) return napi_set_last(env, napi_number_expected, "number expected"); - *result = (int32_t)js_getnum((jsval_t)value); + if (vtype((ant_value_t)value) != T_NUM) return napi_set_last(env, napi_number_expected, "number expected"); + *result = (int32_t)js_getnum((ant_value_t)value); return napi_set_last(env, napi_ok, NULL); } @@ -1172,8 +1172,8 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_get_value_uint32( uint32_t *result ) { if (!env || !result) return napi_set_last(env, napi_invalid_arg, "invalid argument"); - if (vtype((jsval_t)value) != T_NUM) return napi_set_last(env, napi_number_expected, "number expected"); - *result = (uint32_t)js_getnum((jsval_t)value); + if (vtype((ant_value_t)value) != T_NUM) return napi_set_last(env, napi_number_expected, "number expected"); + *result = (uint32_t)js_getnum((ant_value_t)value); return napi_set_last(env, napi_ok, NULL); } @@ -1183,8 +1183,8 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_get_value_int64( int64_t *result ) { if (!env || !result) return napi_set_last(env, napi_invalid_arg, "invalid argument"); - if (vtype((jsval_t)value) != T_NUM) return napi_set_last(env, napi_number_expected, "number expected"); - *result = (int64_t)js_getnum((jsval_t)value); + if (vtype((ant_value_t)value) != T_NUM) return napi_set_last(env, napi_number_expected, "number expected"); + *result = (int64_t)js_getnum((ant_value_t)value); return napi_set_last(env, napi_ok, NULL); } @@ -1194,8 +1194,8 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_get_value_bool( bool *result ) { if (!env || !result) return napi_set_last(env, napi_invalid_arg, "invalid argument"); - if (vtype((jsval_t)value) != T_BOOL) return napi_set_last(env, napi_boolean_expected, "boolean expected"); - *result = ((jsval_t)value == js_true); + if (vtype((ant_value_t)value) != T_BOOL) return napi_set_last(env, napi_boolean_expected, "boolean expected"); + *result = ((ant_value_t)value == js_true); return napi_set_last(env, napi_ok, NULL); } @@ -1208,10 +1208,10 @@ static napi_status napi_get_string_common( ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; if (!nenv || !nenv->js) return napi_set_last(env, napi_invalid_arg, "invalid env"); - if (vtype((jsval_t)value) != T_STR) return napi_set_last(env, napi_string_expected, "string expected"); + if (vtype((ant_value_t)value) != T_STR) return napi_set_last(env, napi_string_expected, "string expected"); size_t len = 0; - const char *str = js_getstr(nenv->js, (jsval_t)value, &len); + const char *str = js_getstr(nenv->js, (ant_value_t)value, &len); if (!str) return napi_set_last(env, napi_string_expected, "string expected"); if (result) *result = len; @@ -1289,7 +1289,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_get_new_target( struct napi_callback_info__ *info = (struct napi_callback_info__ *)cbinfo; if (!env || !info || !result) return napi_set_last(env, napi_invalid_arg, "invalid argument"); - jsval_t nt = (jsval_t)info->new_target; + ant_value_t nt = (ant_value_t)info->new_target; *result = is_undefined(nt) ? (napi_value)0 : info->new_target; return napi_set_last(env, napi_ok, NULL); } @@ -1302,13 +1302,13 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_get_array_length( ant_napi_env_t *nenv = (ant_napi_env_t *)env; if (!nenv || !nenv->js || !result) return napi_set_last(env, napi_invalid_arg, "invalid argument"); - jsval_t v = (jsval_t)value; + ant_value_t v = (ant_value_t)value; if (vtype(v) == T_ARR) { *result = (uint32_t)js_arr_len(nenv->js, v); return napi_set_last(env, napi_ok, NULL); } - jsval_t len = js_get(nenv->js, v, "length"); + ant_value_t len = js_get(nenv->js, v, "length"); if (vtype(len) != T_NUM) return napi_set_last(env, napi_array_expected, "array expected"); *result = (uint32_t)js_getnum(len); return napi_set_last(env, napi_ok, NULL); @@ -1341,9 +1341,9 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_get_arraybuffer_info( ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; if (!nenv || !nenv->js) return napi_set_last(env, napi_invalid_arg, "invalid env"); - if (!is_object_type((jsval_t)arraybuffer)) return napi_set_last(env, napi_arraybuffer_expected, "arraybuffer expected"); + if (!is_object_type((ant_value_t)arraybuffer)) return napi_set_last(env, napi_arraybuffer_expected, "arraybuffer expected"); - jsval_t slot = js_get_slot(nenv->js, (jsval_t)arraybuffer, SLOT_BUFFER); + ant_value_t slot = js_get_slot(nenv->js, (ant_value_t)arraybuffer, SLOT_BUFFER); if (vtype(slot) != T_NUM) return napi_set_last(env, napi_arraybuffer_expected, "arraybuffer expected"); ArrayBufferData *ab = (ArrayBufferData *)(uintptr_t)js_getnum(slot); @@ -1374,7 +1374,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_get_typedarray_info( if (type) *type = napi_from_ant_typedarray_type(ta->type); if (length) *length = ta->length; if (data) *data = ta->buffer->data + ta->byte_offset; - if (arraybuffer) *arraybuffer = (napi_value)js_get(nenv->js, (jsval_t)typedarray, "buffer"); + if (arraybuffer) *arraybuffer = (napi_value)js_get(nenv->js, (ant_value_t)typedarray, "buffer"); if (byte_offset) *byte_offset = ta->byte_offset; return napi_set_last(env, napi_ok, NULL); } @@ -1386,7 +1386,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_get_prototype( ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; if (!nenv || !nenv->js || !result) return napi_set_last(env, napi_invalid_arg, "invalid argument"); - *result = (napi_value)js_get_proto(nenv->js, (jsval_t)object); + *result = (napi_value)js_get_proto(nenv->js, (ant_value_t)object); return napi_set_last(env, napi_ok, NULL); } @@ -1396,12 +1396,12 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_get_property_names( napi_value *result ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; - if (!nenv || !nenv->js || !result || !is_object_type((jsval_t)object)) { + if (!nenv || !nenv->js || !result || !is_object_type((ant_value_t)object)) { return napi_set_last(env, napi_invalid_arg, "invalid argument"); } - jsval_t out = js_mkarr(nenv->js); - ant_iter_t iter = js_prop_iter_begin(nenv->js, (jsval_t)object); + ant_value_t out = js_mkarr(nenv->js); + ant_iter_t iter = js_prop_iter_begin(nenv->js, (ant_value_t)object); const char *key = NULL; size_t key_len = 0; @@ -1439,10 +1439,10 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_set_property( napi_value value ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; - if (!nenv || !nenv->js || !is_object_type((jsval_t)object)) { + if (!nenv || !nenv->js || !is_object_type((ant_value_t)object)) { return napi_set_last(env, napi_invalid_arg, "invalid argument"); } - jsval_t r = js_setprop(nenv->js, (jsval_t)object, (jsval_t)key, (jsval_t)value); + ant_value_t r = js_setprop(nenv->js, (ant_value_t)object, (ant_value_t)key, (ant_value_t)value); if (is_err(r)) return napi_check_pending_from_result(env, r); return napi_set_last(env, napi_ok, NULL); } @@ -1454,18 +1454,18 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_get_property( napi_value *result ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; - if (!nenv || !nenv->js || !result || !is_object_type((jsval_t)object)) { + if (!nenv || !nenv->js || !result || !is_object_type((ant_value_t)object)) { return napi_set_last(env, napi_invalid_arg, "invalid argument"); } - jsval_t k = (jsval_t)key; + ant_value_t k = (ant_value_t)key; if (vtype(k) == T_SYMBOL) { - jsoff_t off = lkp_sym_proto(nenv->js, (jsval_t)object, (jsoff_t)vdata(k)); + ant_offset_t off = lkp_sym_proto(nenv->js, (ant_value_t)object, (ant_offset_t)vdata(k)); *result = (napi_value)(off ? resolveprop(nenv->js, mkval(T_PROP, off)) : js_mkundef()); return napi_set_last(env, napi_ok, NULL); } - jsval_t kstr = coerce_to_str(nenv->js, k); + ant_value_t kstr = coerce_to_str(nenv->js, k); if (is_err(kstr)) return napi_check_pending_from_result(env, kstr); size_t klen = 0; @@ -1477,7 +1477,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_get_property( memcpy(name, ks, klen); name[klen] = '\0'; - *result = (napi_value)js_getprop_fallback(nenv->js, (jsval_t)object, name); + *result = (napi_value)js_getprop_fallback(nenv->js, (ant_value_t)object, name); free(name); return napi_set_last(env, napi_ok, NULL); @@ -1490,21 +1490,21 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_has_property( bool *result ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; - if (!nenv || !nenv->js || !result || !is_object_type((jsval_t)object)) { + if (!nenv || !nenv->js || !result || !is_object_type((ant_value_t)object)) { return napi_set_last(env, napi_invalid_arg, "invalid argument"); } - jsval_t k = (jsval_t)key; + ant_value_t k = (ant_value_t)key; if (vtype(k) == T_SYMBOL) { - *result = lkp_sym_proto(nenv->js, (jsval_t)object, (jsoff_t)vdata(k)) != 0; + *result = lkp_sym_proto(nenv->js, (ant_value_t)object, (ant_offset_t)vdata(k)) != 0; return napi_set_last(env, napi_ok, NULL); } - jsval_t kstr = coerce_to_str(nenv->js, k); + ant_value_t kstr = coerce_to_str(nenv->js, k); if (is_err(kstr)) return napi_check_pending_from_result(env, kstr); size_t len = 0; const char *s = js_getstr(nenv->js, kstr, &len); - *result = s && lkp_proto(nenv->js, (jsval_t)object, s, len) != 0; + *result = s && lkp_proto(nenv->js, (ant_value_t)object, s, len) != 0; return napi_set_last(env, napi_ok, NULL); } @@ -1515,21 +1515,21 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_delete_property( bool *result ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; - if (!nenv || !nenv->js || !result || !is_object_type((jsval_t)object)) { + if (!nenv || !nenv->js || !result || !is_object_type((ant_value_t)object)) { return napi_set_last(env, napi_invalid_arg, "invalid argument"); } - jsval_t k = (jsval_t)key; - jsval_t del_result = js_mkundef(); + ant_value_t k = (ant_value_t)key; + ant_value_t del_result = js_mkundef(); if (vtype(k) == T_SYMBOL) { - del_result = js_delete_sym_prop(nenv->js, (jsval_t)object, k); + del_result = js_delete_sym_prop(nenv->js, (ant_value_t)object, k); } else { - jsval_t kstr = coerce_to_str(nenv->js, k); + ant_value_t kstr = coerce_to_str(nenv->js, k); if (is_err(kstr)) return napi_check_pending_from_result(env, kstr); size_t len = 0; const char *s = js_getstr(nenv->js, kstr, &len); - del_result = js_delete_prop(nenv->js, (jsval_t)object, s, len); + del_result = js_delete_prop(nenv->js, (ant_value_t)object, s, len); } if (is_err(del_result)) return napi_check_pending_from_result(env, del_result); @@ -1544,10 +1544,10 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_set_named_property( napi_value value ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; - if (!nenv || !nenv->js || !utf8name || !is_object_type((jsval_t)object)) { + if (!nenv || !nenv->js || !utf8name || !is_object_type((ant_value_t)object)) { return napi_set_last(env, napi_invalid_arg, "invalid argument"); } - js_set(nenv->js, (jsval_t)object, utf8name, (jsval_t)value); + js_set(nenv->js, (ant_value_t)object, utf8name, (ant_value_t)value); return napi_set_last(env, napi_ok, NULL); } @@ -1558,10 +1558,10 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_get_named_property( napi_value *result ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; - if (!nenv || !nenv->js || !result || !utf8name || !is_object_type((jsval_t)object)) { + if (!nenv || !nenv->js || !result || !utf8name || !is_object_type((ant_value_t)object)) { return napi_set_last(env, napi_invalid_arg, "invalid argument"); } - *result = (napi_value)js_getprop_fallback(nenv->js, (jsval_t)object, utf8name); + *result = (napi_value)js_getprop_fallback(nenv->js, (ant_value_t)object, utf8name); return napi_set_last(env, napi_ok, NULL); } @@ -1572,10 +1572,10 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_has_named_property( bool *result ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; - if (!nenv || !nenv->js || !result || !utf8name || !is_object_type((jsval_t)object)) { + if (!nenv || !nenv->js || !result || !utf8name || !is_object_type((ant_value_t)object)) { return napi_set_last(env, napi_invalid_arg, "invalid argument"); } - *result = lkp_proto(nenv->js, (jsval_t)object, utf8name, strlen(utf8name)) != 0; + *result = lkp_proto(nenv->js, (ant_value_t)object, utf8name, strlen(utf8name)) != 0; return napi_set_last(env, napi_ok, NULL); } @@ -1586,16 +1586,16 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_set_element( napi_value value ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; - if (!nenv || !nenv->js || !is_object_type((jsval_t)object)) { + if (!nenv || !nenv->js || !is_object_type((ant_value_t)object)) { return napi_set_last(env, napi_invalid_arg, "invalid argument"); } char idx[32]; int n = snprintf(idx, sizeof(idx), "%u", index); if (n < 0) return napi_set_last(env, napi_generic_failure, "index conversion failed"); - jsval_t key = js_mkstr(nenv->js, idx, (size_t)n); - jsval_t r = js_setprop( - nenv->js, (jsval_t)object, - key, (jsval_t)value + ant_value_t key = js_mkstr(nenv->js, idx, (size_t)n); + ant_value_t r = js_setprop( + nenv->js, (ant_value_t)object, + key, (ant_value_t)value ); if (is_err(r)) return napi_check_pending_from_result(env, r); return napi_set_last(env, napi_ok, NULL); @@ -1608,12 +1608,12 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_get_element( napi_value *result ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; - if (!nenv || !nenv->js || !result || !is_object_type((jsval_t)object)) { + if (!nenv || !nenv->js || !result || !is_object_type((ant_value_t)object)) { return napi_set_last(env, napi_invalid_arg, "invalid argument"); } char idx[32]; snprintf(idx, sizeof(idx), "%u", index); - *result = (napi_value)js_get(nenv->js, (jsval_t)object, idx); + *result = (napi_value)js_get(nenv->js, (ant_value_t)object, idx); return napi_set_last(env, napi_ok, NULL); } @@ -1624,12 +1624,12 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_has_element( bool *result ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; - if (!nenv || !nenv->js || !result || !is_object_type((jsval_t)object)) { + if (!nenv || !nenv->js || !result || !is_object_type((ant_value_t)object)) { return napi_set_last(env, napi_invalid_arg, "invalid argument"); } char idx[32]; snprintf(idx, sizeof(idx), "%u", index); - *result = lkp_proto(nenv->js, (jsval_t)object, idx, strlen(idx)) != 0; + *result = lkp_proto(nenv->js, (ant_value_t)object, idx, strlen(idx)) != 0; return napi_set_last(env, napi_ok, NULL); } @@ -1640,12 +1640,12 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_delete_element( bool *result ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; - if (!nenv || !nenv->js || !result || !is_object_type((jsval_t)object)) { + if (!nenv || !nenv->js || !result || !is_object_type((ant_value_t)object)) { return napi_set_last(env, napi_invalid_arg, "invalid argument"); } char idx[32]; snprintf(idx, sizeof(idx), "%u", index); - jsval_t del = js_delete_prop(nenv->js, (jsval_t)object, idx, strlen(idx)); + ant_value_t del = js_delete_prop(nenv->js, (ant_value_t)object, idx, strlen(idx)); if (is_err(del)) return napi_check_pending_from_result(env, del); *result = js_truthy(nenv->js, del); return napi_set_last(env, napi_ok, NULL); @@ -1658,13 +1658,13 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_define_properties( const napi_property_descriptor *properties ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; - if (!nenv || !nenv->js || !is_object_type((jsval_t)object) || (property_count > 0 && !properties)) { + if (!nenv || !nenv->js || !is_object_type((ant_value_t)object) || (property_count > 0 && !properties)) { return napi_set_last(env, napi_invalid_arg, "invalid argument"); } for (size_t i = 0; i < property_count; i++) { const napi_property_descriptor *p = &properties[i]; - jsval_t key = js_mkundef(); + ant_value_t key = js_mkundef(); const char *key_str = NULL; size_t key_len = 0; @@ -1672,7 +1672,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_define_properties( key_str = p->utf8name; key_len = strlen(p->utf8name); key = js_mkstr(nenv->js, key_str, key_len); - } else key = (jsval_t)p->name; + } else key = (ant_value_t)p->name; bool is_symbol = (vtype(key) == T_SYMBOL); if (!is_symbol && !key_str) { @@ -1680,7 +1680,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_define_properties( key_str = js_getstr(nenv->js, key, &key_len); } - jsval_t value = js_mkundef(); + ant_value_t value = js_mkundef(); if (p->method) { napi_value fn = 0; napi_status st = napi_create_function_common( @@ -1692,7 +1692,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_define_properties( &fn ); if (st != napi_ok) return st; - value = (jsval_t)fn; + value = (ant_value_t)fn; } else if (p->getter || p->setter) { napi_value getter_fn = 0; napi_value setter_fn = 0; @@ -1707,29 +1707,29 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_define_properties( int flags = napi_desc_flags(p->attributes); if (is_symbol) { - if (p->getter) js_set_sym_getter_desc(nenv->js, (jsval_t)object, key, (jsval_t)getter_fn, flags); - if (p->setter) js_set_sym_setter_desc(nenv->js, (jsval_t)object, key, (jsval_t)setter_fn, flags); + if (p->getter) js_set_sym_getter_desc(nenv->js, (ant_value_t)object, key, (ant_value_t)getter_fn, flags); + if (p->setter) js_set_sym_setter_desc(nenv->js, (ant_value_t)object, key, (ant_value_t)setter_fn, flags); } else { js_set_accessor_desc( nenv->js, - (jsval_t)object, + (ant_value_t)object, key_str, key_len, - p->getter ? (jsval_t)getter_fn : js_mkundef(), - p->setter ? (jsval_t)setter_fn : js_mkundef(), + p->getter ? (ant_value_t)getter_fn : js_mkundef(), + p->setter ? (ant_value_t)setter_fn : js_mkundef(), flags ); } continue; } else { - value = (jsval_t)p->value; + value = (ant_value_t)p->value; } if (is_symbol) { - js_set_sym(nenv->js, (jsval_t)object, key, value); + js_set_sym(nenv->js, (ant_value_t)object, key, value); } else { - js_set(nenv->js, (jsval_t)object, key_str, value); - js_set_descriptor(nenv->js, (jsval_t)object, key_str, key_len, napi_desc_flags(p->attributes)); + js_set(nenv->js, (ant_value_t)object, key_str, value); + js_set_descriptor(nenv->js, (ant_value_t)object, key_str, key_len, napi_desc_flags(p->attributes)); } } @@ -1756,8 +1756,8 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_define_class( ); if (st != napi_ok) return st; - jsval_t ctor = (jsval_t)*result; - jsval_t proto = js_get(nenv->js, ctor, "prototype"); + ant_value_t ctor = (ant_value_t)*result; + ant_value_t proto = js_get(nenv->js, ctor, "prototype"); if (!is_object_type(proto)) { proto = js_mkobj(nenv->js); js_set(nenv->js, ctor, "prototype", proto); @@ -1781,21 +1781,21 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_has_own_property( bool *result ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; - if (!nenv || !nenv->js || !result || !is_object_type((jsval_t)object)) { + if (!nenv || !nenv->js || !result || !is_object_type((ant_value_t)object)) { return napi_set_last(env, napi_invalid_arg, "invalid argument"); } - jsval_t k = (jsval_t)key; + ant_value_t k = (ant_value_t)key; if (vtype(k) == T_SYMBOL) { - *result = lkp_sym(nenv->js, (jsval_t)object, (jsoff_t)vdata(k)) != 0; + *result = lkp_sym(nenv->js, (ant_value_t)object, (ant_offset_t)vdata(k)) != 0; return napi_set_last(env, napi_ok, NULL); } - jsval_t kstr = coerce_to_str(nenv->js, k); + ant_value_t kstr = coerce_to_str(nenv->js, k); if (is_err(kstr)) return napi_check_pending_from_result(env, kstr); size_t len = 0; const char *s = js_getstr(nenv->js, kstr, &len); - *result = s && lkp(nenv->js, (jsval_t)object, s, len) != 0; + *result = s && lkp(nenv->js, (ant_value_t)object, s, len) != 0; return napi_set_last(env, napi_ok, NULL); } @@ -1807,7 +1807,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_typeof( ant_napi_env_t *nenv = (ant_napi_env_t *)env; if (!nenv || !nenv->js || !result) return napi_set_last(env, napi_invalid_arg, "invalid argument"); - jsval_t v = (jsval_t)value; + ant_value_t v = (ant_value_t)value; uint8_t t = vtype(v); if (napi_find_external(nenv->js, value)) { @@ -1837,7 +1837,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_is_array( bool *result ) { if (!env || !result) return napi_set_last(env, napi_invalid_arg, "invalid argument"); - *result = vtype((jsval_t)value) == T_ARR; + *result = vtype((ant_value_t)value) == T_ARR; return napi_set_last(env, napi_ok, NULL); } @@ -1848,13 +1848,13 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_is_arraybuffer( ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; if (!nenv || !nenv->js || !result) return napi_set_last(env, napi_invalid_arg, "invalid argument"); - if (!is_object_type((jsval_t)value)) { *result = false; return napi_set_last(env, napi_ok, NULL); } + if (!is_object_type((ant_value_t)value)) { *result = false; return napi_set_last(env, napi_ok, NULL); } - jsval_t slot = js_get_slot(nenv->js, (jsval_t)value, SLOT_BUFFER); + ant_value_t slot = js_get_slot(nenv->js, (ant_value_t)value, SLOT_BUFFER); if (vtype(slot) != T_NUM) { *result = false; } else { - jsval_t buf_prop = js_get(nenv->js, (jsval_t)value, "buffer"); + ant_value_t buf_prop = js_get(nenv->js, (ant_value_t)value, "buffer"); *result = vtype(buf_prop) == T_UNDEF; } return napi_set_last(env, napi_ok, NULL); @@ -1874,9 +1874,9 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_is_buffer( return napi_set_last(env, napi_ok, NULL); } - jsval_t buffer_proto = js_get_ctor_proto(nenv->js, "Buffer", 6); + ant_value_t buffer_proto = js_get_ctor_proto(nenv->js, "Buffer", 6); *result = is_object_type(buffer_proto) - && proto_chain_contains(nenv->js, (jsval_t)value, buffer_proto); + && proto_chain_contains(nenv->js, (ant_value_t)value, buffer_proto); return napi_set_last(env, napi_ok, NULL); } @@ -1899,11 +1899,11 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_is_dataview( ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; if (!nenv || !nenv->js || !result) return napi_set_last(env, napi_invalid_arg, "invalid argument"); - if (!is_object_type((jsval_t)value)) { + if (!is_object_type((ant_value_t)value)) { *result = false; } else { - jsval_t slot = js_get_slot(nenv->js, (jsval_t)value, SLOT_DATA); - jsval_t byte_len = js_get(nenv->js, (jsval_t)value, "byteLength"); + ant_value_t slot = js_get_slot(nenv->js, (ant_value_t)value, SLOT_DATA); + ant_value_t byte_len = js_get(nenv->js, (ant_value_t)value, "byteLength"); *result = vtype(slot) == T_NUM && vtype(byte_len) == T_NUM; } return napi_set_last(env, napi_ok, NULL); @@ -1916,10 +1916,10 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_is_error( ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; if (!nenv || !nenv->js || !result) return napi_set_last(env, napi_invalid_arg, "invalid argument"); - if (!is_object_type((jsval_t)value)) { + if (!is_object_type((ant_value_t)value)) { *result = false; } else { - jsval_t et = js_get_slot(nenv->js, (jsval_t)value, SLOT_ERR_TYPE); + ant_value_t et = js_get_slot(nenv->js, (ant_value_t)value, SLOT_ERR_TYPE); *result = vtype(et) == T_NUM; } return napi_set_last(env, napi_ok, NULL); @@ -1931,7 +1931,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_is_promise( bool *is_promise ) { if (!env || !is_promise) return napi_set_last(env, napi_invalid_arg, "invalid argument"); - *is_promise = vtype((jsval_t)value) == T_PROMISE; + *is_promise = vtype((ant_value_t)value) == T_PROMISE; return napi_set_last(env, napi_ok, NULL); } @@ -1943,7 +1943,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_instanceof( ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; if (!nenv || !nenv->js || !result) return napi_set_last(env, napi_invalid_arg, "invalid argument"); - jsval_t r = do_instanceof(nenv->js, (jsval_t)object, (jsval_t)constructor); + ant_value_t r = do_instanceof(nenv->js, (ant_value_t)object, (ant_value_t)constructor); if (is_err(r)) return napi_check_pending_from_result(env, r); *result = js_truthy(nenv->js, r); return napi_set_last(env, napi_ok, NULL); @@ -1957,7 +1957,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_strict_equals( ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; if (!nenv || !nenv->js || !result) return napi_set_last(env, napi_invalid_arg, "invalid argument"); - *result = strict_eq_values(nenv->js, (jsval_t)lhs, (jsval_t)rhs); + *result = strict_eq_values(nenv->js, (ant_value_t)lhs, (ant_value_t)rhs); return napi_set_last(env, napi_ok, NULL); } @@ -1970,16 +1970,16 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_call_function( napi_value *result ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; - if (!nenv || !nenv->js || !napi_is_callable((jsval_t)func)) { + if (!nenv || !nenv->js || !napi_is_callable((ant_value_t)func)) { return napi_set_last(env, napi_invalid_arg, "invalid argument"); } - jsval_t out = sv_vm_call( + ant_value_t out = sv_vm_call( nenv->js->vm, nenv->js, - (jsval_t)func, - (jsval_t)recv, - (jsval_t *)argv, + (ant_value_t)func, + (ant_value_t)recv, + (ant_value_t *)argv, (int)argc, NULL, false @@ -1998,23 +1998,23 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_new_instance( napi_value *result ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; - if (!nenv || !nenv->js || !result || !napi_is_callable((jsval_t)constructor)) { + if (!nenv || !nenv->js || !result || !napi_is_callable((ant_value_t)constructor)) { return napi_set_last(env, napi_invalid_arg, "invalid argument"); } - jsval_t ctor = (jsval_t)constructor; - jsval_t obj = js_mkobj(nenv->js); - jsval_t proto = js_get(nenv->js, ctor, "prototype"); + ant_value_t ctor = (ant_value_t)constructor; + ant_value_t obj = js_mkobj(nenv->js); + ant_value_t proto = js_get(nenv->js, ctor, "prototype"); if (is_object_type(proto)) js_set_proto(nenv->js, obj, proto); - jsval_t saved = nenv->js->new_target; + ant_value_t saved = nenv->js->new_target; nenv->js->new_target = ctor; - jsval_t out = sv_vm_call( + ant_value_t out = sv_vm_call( nenv->js->vm, nenv->js, ctor, obj, - (jsval_t *)argv, + (ant_value_t *)argv, (int)argc, NULL, true @@ -2033,7 +2033,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_coerce_to_bool( ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; if (!nenv || !nenv->js || !result) return napi_set_last(env, napi_invalid_arg, "invalid argument"); - *result = (napi_value)js_bool(js_truthy(nenv->js, (jsval_t)value)); + *result = (napi_value)js_bool(js_truthy(nenv->js, (ant_value_t)value)); return napi_set_last(env, napi_ok, NULL); } @@ -2044,7 +2044,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_coerce_to_number( ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; if (!nenv || !nenv->js || !result) return napi_set_last(env, napi_invalid_arg, "invalid argument"); - *result = (napi_value)js_mknum(js_to_number(nenv->js, (jsval_t)value)); + *result = (napi_value)js_mknum(js_to_number(nenv->js, (ant_value_t)value)); return napi_set_last(env, napi_ok, NULL); } @@ -2056,15 +2056,15 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_coerce_to_object( ant_napi_env_t *nenv = (ant_napi_env_t *)env; if (!nenv || !nenv->js || !result) return napi_set_last(env, napi_invalid_arg, "invalid argument"); - if (is_object_type((jsval_t)value)) { + if (is_object_type((ant_value_t)value)) { *result = value; return napi_set_last(env, napi_ok, NULL); } - jsval_t obj_ctor = js_get(nenv->js, js_glob(nenv->js), "Object"); + ant_value_t obj_ctor = js_get(nenv->js, js_glob(nenv->js), "Object"); if (!napi_is_callable(obj_ctor)) return napi_set_last(env, napi_generic_failure, "Object constructor missing"); - jsval_t arg = (jsval_t)value; - jsval_t out = sv_vm_call(nenv->js->vm, nenv->js, obj_ctor, js_mkundef(), &arg, 1, NULL, false); + ant_value_t arg = (ant_value_t)value; + ant_value_t out = sv_vm_call(nenv->js->vm, nenv->js, obj_ctor, js_mkundef(), &arg, 1, NULL, false); if (is_err(out) || nenv->js->thrown_exists) return napi_check_pending_from_result(env, out); *result = (napi_value)out; return napi_set_last(env, napi_ok, NULL); @@ -2077,7 +2077,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_coerce_to_string( ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; if (!nenv || !nenv->js || !result) return napi_set_last(env, napi_invalid_arg, "invalid argument"); - jsval_t out = coerce_to_str(nenv->js, (jsval_t)value); + ant_value_t out = coerce_to_str(nenv->js, (ant_value_t)value); if (is_err(out) || nenv->js->thrown_exists) return napi_check_pending_from_result(env, out); *result = (napi_value)out; return napi_set_last(env, napi_ok, NULL); @@ -2086,7 +2086,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_coerce_to_string( NAPI_EXTERN napi_status NAPI_CDECL napi_throw(napi_env env, napi_value error) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; if (!nenv || !nenv->js) return napi_set_last(env, napi_invalid_arg, "invalid env"); - js_throw(nenv->js, (jsval_t)error); + js_throw(nenv->js, (ant_value_t)error); napi_mark_pending_exception(env, error); return napi_pending_exception; } @@ -2181,7 +2181,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_wrap( napi_ref *result ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; - if (!nenv || !nenv->js || !is_object_type((jsval_t)js_object)) { + if (!nenv || !nenv->js || !is_object_type((ant_value_t)js_object)) { return napi_set_last(env, napi_invalid_arg, "invalid argument"); } @@ -2191,7 +2191,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_wrap( if (!entry) return napi_set_last(env, napi_generic_failure, "out of memory"); entry->id = g_napi_wrap_next_id++; HASH_ADD(hh, g_napi_wraps, id, sizeof(entry->id), entry); - napi_slot_set_u64(nenv->js, (jsval_t)js_object, SLOT_NAPI_WRAP_ID, entry->id); + napi_slot_set_u64(nenv->js, (ant_value_t)js_object, SLOT_NAPI_WRAP_ID, entry->id); } entry->native_object = native_object; @@ -2210,7 +2210,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_unwrap( void **result ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; - if (!nenv || !nenv->js || !result || !is_object_type((jsval_t)js_object)) { + if (!nenv || !nenv->js || !result || !is_object_type((ant_value_t)js_object)) { return napi_set_last(env, napi_invalid_arg, "invalid argument"); } napi_wrap_entry_t *entry = napi_find_wrap(nenv->js, js_object); @@ -2225,7 +2225,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_remove_wrap( void **result ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; - if (!nenv || !nenv->js || !is_object_type((jsval_t)js_object)) { + if (!nenv || !nenv->js || !is_object_type((ant_value_t)js_object)) { return napi_set_last(env, napi_invalid_arg, "invalid argument"); } @@ -2235,7 +2235,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_remove_wrap( if (result) *result = entry->native_object; HASH_DEL(g_napi_wraps, entry); free(entry); - js_set_slot(nenv->js, (jsval_t)js_object, SLOT_NAPI_WRAP_ID, js_mkundef()); + js_set_slot(nenv->js, (ant_value_t)js_object, SLOT_NAPI_WRAP_ID, js_mkundef()); return napi_set_last(env, napi_ok, NULL); } @@ -2396,7 +2396,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_threadsafe_function( tsfn->context = context; tsfn->max_queue_size = max_queue_size; tsfn->thread_count = initial_thread_count > 0 ? initial_thread_count : 1; - tsfn->func_root = js_root(nenv->js, (jsval_t)func); + tsfn->func_root = js_root(nenv->js, (ant_value_t)func); uv_mutex_init(&tsfn->mutex); int rc = uv_async_init(uv_default_loop(), &tsfn->async, napi_tsfn_async_cb); @@ -2517,13 +2517,13 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_run_script( ) { ant_napi_env_t *nenv = (ant_napi_env_t *)env; if (!nenv || !nenv->js || !result) return napi_set_last(env, napi_invalid_arg, "invalid argument"); - if (vtype((jsval_t)script) != T_STR) return napi_set_last(env, napi_string_expected, "script must be string"); + if (vtype((ant_value_t)script) != T_STR) return napi_set_last(env, napi_string_expected, "script must be string"); size_t len = 0; - const char *src = js_getstr(nenv->js, (jsval_t)script, &len); + const char *src = js_getstr(nenv->js, (ant_value_t)script, &len); if (!src) return napi_set_last(env, napi_string_expected, "script must be string"); - jsval_t out = js_eval_bytecode_eval(nenv->js, src, len); + ant_value_t out = js_eval_bytecode_eval(nenv->js, src, len); if (is_err(out) || nenv->js->thrown_exists) return napi_check_pending_from_result(env, out); *result = (napi_value)out; return napi_set_last(env, napi_ok, NULL); diff --git a/src/modules/navigator.c b/src/modules/navigator.c index 53954de..003932a 100644 --- a/src/modules/navigator.c +++ b/src/modules/navigator.c @@ -35,8 +35,8 @@ typedef struct lock_request { ant_t *js; char *name; lock_mode_t mode; - jsval_t callback; - jsval_t promise; + ant_value_t callback; + ant_value_t promise; struct lock_request *next; } lock_request_t; @@ -118,10 +118,10 @@ static void release_lock(const char *name) { static void process_pending_requests(ant_t *js); -static jsval_t make_lock_handler(ant_t *js, jsval_t cfunc, jsval_t lock_name, jsval_t outer_promise) { - jsval_t fn_obj = js_mkobj(js); +static ant_value_t make_lock_handler(ant_t *js, ant_value_t cfunc, ant_value_t lock_name, ant_value_t outer_promise) { + ant_value_t fn_obj = js_mkobj(js); - jsval_t data_obj = js_mkobj(js); + ant_value_t data_obj = js_mkobj(js); js_set(js, data_obj, "lockName", lock_name); js_set(js, data_obj, "outerPromise", outer_promise); js_set_slot(js, fn_obj, SLOT_DATA, data_obj); @@ -130,13 +130,13 @@ static jsval_t make_lock_handler(ant_t *js, jsval_t cfunc, jsval_t lock_name, js return js_obj_to_func(fn_obj); } -static jsval_t lock_then_handler(ant_t *js, jsval_t *args, int nargs) { - jsval_t current_func = js_getcurrentfunc(js); - jsval_t data_obj = js_get_slot(js, current_func, SLOT_DATA); +static ant_value_t lock_then_handler(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t current_func = js_getcurrentfunc(js); + ant_value_t data_obj = js_get_slot(js, current_func, SLOT_DATA); - jsval_t lock_name_val = js_get(js, data_obj, "lockName"); - jsval_t outer_promise = js_get(js, data_obj, "outerPromise"); - jsval_t result_val = (nargs > 0) ? args[0] : js_mkundef(); + ant_value_t lock_name_val = js_get(js, data_obj, "lockName"); + ant_value_t outer_promise = js_get(js, data_obj, "outerPromise"); + ant_value_t result_val = (nargs > 0) ? args[0] : js_mkundef(); size_t name_len; char *name = js_getstr(js, lock_name_val, &name_len); @@ -148,13 +148,13 @@ static jsval_t lock_then_handler(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t lock_catch_handler(ant_t *js, jsval_t *args, int nargs) { - jsval_t current_func = js_getcurrentfunc(js); - jsval_t data_obj = js_get_slot(js, current_func, SLOT_DATA); +static ant_value_t lock_catch_handler(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t current_func = js_getcurrentfunc(js); + ant_value_t data_obj = js_get_slot(js, current_func, SLOT_DATA); - jsval_t lock_name_val = js_get(js, data_obj, "lockName"); - jsval_t outer_promise = js_get(js, data_obj, "outerPromise"); - jsval_t error_val = (nargs > 0) ? args[0] : js_mkundef(); + ant_value_t lock_name_val = js_get(js, data_obj, "lockName"); + ant_value_t outer_promise = js_get(js, data_obj, "outerPromise"); + ant_value_t error_val = (nargs > 0) ? args[0] : js_mkundef(); size_t name_len; char *name = js_getstr(js, lock_name_val, &name_len); @@ -167,13 +167,13 @@ static jsval_t lock_catch_handler(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static void execute_lock_callback(ant_t *js, const char *name, lock_mode_t mode, jsval_t callback, jsval_t outer_promise) { - jsval_t lock_obj = js_mkobj(js); +static void execute_lock_callback(ant_t *js, const char *name, lock_mode_t mode, ant_value_t callback, ant_value_t outer_promise) { + ant_value_t lock_obj = js_mkobj(js); js_set(js, lock_obj, "name", js_mkstr(js, name, strlen(name))); js_set(js, lock_obj, "mode", js_mkstr(js, mode == LOCK_MODE_EXCLUSIVE ? "exclusive" : "shared", mode == LOCK_MODE_EXCLUSIVE ? 9 : 6)); js_set_sym(js, lock_obj, get_toStringTag_sym(), js_mkstr(js, "Lock", 4)); - jsval_t result = sv_vm_call(js->vm, js, callback, js_mkundef(), &lock_obj, 1, NULL, false); + ant_value_t result = sv_vm_call(js->vm, js, callback, js_mkundef(), &lock_obj, 1, NULL, false); if (vtype(result) == T_ERR) { release_lock(name); @@ -183,16 +183,16 @@ static void execute_lock_callback(ant_t *js, const char *name, lock_mode_t mode, } if (vtype(result) == T_PROMISE) { - jsval_t then_fn = js_get(js, result, "then"); + ant_value_t then_fn = js_get(js, result, "then"); int fn_type = vtype(then_fn); if (fn_type == T_FUNC || fn_type == T_CFUNC) { - jsval_t name_str = js_mkstr(js, name, strlen(name)); + ant_value_t name_str = js_mkstr(js, name, strlen(name)); - jsval_t on_resolve = make_lock_handler(js, js_mkfun(lock_then_handler), name_str, outer_promise); - jsval_t on_reject = make_lock_handler(js, js_mkfun(lock_catch_handler), name_str, outer_promise); + ant_value_t on_resolve = make_lock_handler(js, js_mkfun(lock_then_handler), name_str, outer_promise); + ant_value_t on_reject = make_lock_handler(js, js_mkfun(lock_catch_handler), name_str, outer_promise); - jsval_t then_args[2] = { on_resolve, on_reject }; + ant_value_t then_args[2] = { on_resolve, on_reject }; sv_vm_call(js->vm, js, then_fn, result, then_args, 2, NULL, false); return; } @@ -237,7 +237,7 @@ static void process_pending_requests(ant_t *js) { } } -static jsval_t locks_request(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t locks_request(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) { return js_mkerr_typed(js, JS_ERR_TYPE, "locks.request requires at least 2 arguments"); } @@ -248,8 +248,8 @@ static jsval_t locks_request(ant_t *js, jsval_t *args, int nargs) { return js_mkerr_typed(js, JS_ERR_TYPE, "First argument must be a string"); } - jsval_t options = js_mkundef(); - jsval_t callback; + ant_value_t options = js_mkundef(); + ant_value_t callback; lock_mode_t mode = LOCK_MODE_EXCLUSIVE; bool if_available = false; @@ -260,7 +260,7 @@ static jsval_t locks_request(ant_t *js, jsval_t *args, int nargs) { callback = args[2]; if (is_special_object(options)) { - jsval_t mode_val = js_get(js, options, "mode"); + ant_value_t mode_val = js_get(js, options, "mode"); if (vtype(mode_val) == T_STR) { size_t mode_len; char *mode_str = js_getstr(js, mode_val, &mode_len); @@ -275,17 +275,17 @@ static jsval_t locks_request(ant_t *js, jsval_t *args, int nargs) { return js_mkerr_typed(js, JS_ERR_TYPE, "Callback must be a function"); } - jsval_t promise = js_mkpromise(js); + ant_value_t promise = js_mkpromise(js); if (if_available && !can_acquire_lock(name, mode)) { - jsval_t null_val = js_mknull(); - jsval_t result = sv_vm_call(js->vm, js, callback, js_mkundef(), &null_val, 1, NULL, false); + ant_value_t null_val = js_mknull(); + ant_value_t result = sv_vm_call(js->vm, js, callback, js_mkundef(), &null_val, 1, NULL, false); if (vtype(result) == T_PROMISE) { - jsval_t then_fn = js_get(js, result, "then"); + ant_value_t then_fn = js_get(js, result, "then"); int fn_type = vtype(then_fn); if (fn_type == T_FUNC || fn_type == T_CFUNC) { - jsval_t on_resolve = make_lock_handler( + ant_value_t on_resolve = make_lock_handler( js, js_mkfun(lock_then_handler), js_mkstr(js, "", 0), promise ); @@ -328,17 +328,17 @@ static jsval_t locks_request(ant_t *js, jsval_t *args, int nargs) { return promise; } -static jsval_t locks_query(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t locks_query(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t result = js_mkobj(js); - jsval_t held_arr = js_mkarr(js); - jsval_t pending_arr = js_mkarr(js); + ant_value_t result = js_mkobj(js); + ant_value_t held_arr = js_mkarr(js); + ant_value_t pending_arr = js_mkarr(js); lock_entry_t *entry, *tmp; HASH_ITER(hh, locks, entry, tmp) { - jsval_t lock_info = js_mkobj(js); + ant_value_t lock_info = js_mkobj(js); js_set(js, lock_info, "name", js_mkstr(js, entry->name, strlen(entry->name))); js_set(js, lock_info, "mode", js_mkstr(js, entry->mode == LOCK_MODE_EXCLUSIVE ? "exclusive" : "shared", entry->mode == LOCK_MODE_EXCLUSIVE ? 9 : 6)); js_arr_push(js, held_arr, lock_info); @@ -346,7 +346,7 @@ static jsval_t locks_query(ant_t *js, jsval_t *args, int nargs) { lock_request_t *req = pending_requests; while (req) { - jsval_t req_info = js_mkobj(js); + ant_value_t req_info = js_mkobj(js); js_set(js, req_info, "name", js_mkstr(js, req->name, strlen(req->name))); js_set(js, req_info, "mode", js_mkstr(js, req->mode == LOCK_MODE_EXCLUSIVE ? "exclusive" : "shared", req->mode == LOCK_MODE_EXCLUSIVE ? 9 : 6)); js_arr_push(js, pending_arr, req_info); @@ -356,7 +356,7 @@ static jsval_t locks_query(ant_t *js, jsval_t *args, int nargs) { js_set(js, result, "held", held_arr); js_set(js, result, "pending", pending_arr); - jsval_t promise = js_mkpromise(js); + ant_value_t promise = js_mkpromise(js); js_resolve_promise(js, promise, result); return promise; @@ -365,12 +365,12 @@ static jsval_t locks_query(ant_t *js, jsval_t *args, int nargs) { void init_navigator_module(void) { ant_t *js = rt->js; - jsval_t navigator_obj = js_mkobj(js); + ant_value_t navigator_obj = js_mkobj(js); js_set(js, navigator_obj, "hardwareConcurrency", js_mknum((double)get_hardware_concurrency())); js_set(js, navigator_obj, "language", js_mkstr(js, "en-US", 5)); - jsval_t languages_arr = js_mkarr(js); + ant_value_t languages_arr = js_mkarr(js); js_arr_push(js, languages_arr, js_mkstr(js, "en-US", 5)); js_set(js, navigator_obj, "languages", languages_arr); @@ -381,7 +381,7 @@ void init_navigator_module(void) { snprintf(user_agent, sizeof(user_agent), "Ant/%s", ANT_VERSION); js_set(js, navigator_obj, "userAgent", js_mkstr(js, user_agent, strlen(user_agent))); - jsval_t locks_obj = js_mkobj(js); + ant_value_t locks_obj = js_mkobj(js); js_set(js, locks_obj, "request", js_mkfun(locks_request)); js_set(js, locks_obj, "query", js_mkfun(locks_query)); js_set_sym(js, locks_obj, get_toStringTag_sym(), js_mkstr(js, "LockManager", 11)); diff --git a/src/modules/net.c b/src/modules/net.c index e18a9d7..0d542cf 100644 --- a/src/modules/net.c +++ b/src/modules/net.c @@ -13,7 +13,7 @@ #include "ant.h" #include "internal.h" // IWYU pragma: keep -static jsval_t net_isIP(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t net_isIP(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mknum(0); size_t len; const char *host = js_getstr(js, args[0], &len); @@ -27,7 +27,7 @@ static jsval_t net_isIP(ant_t *js, jsval_t *args, int nargs) { return js_mknum(0); } -static jsval_t net_isIPv4(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t net_isIPv4(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_false; size_t len; const char *host = js_getstr(js, args[0], &len); @@ -37,7 +37,7 @@ static jsval_t net_isIPv4(ant_t *js, jsval_t *args, int nargs) { return inet_pton(AF_INET, host, &addr) == 1 ? js_true : js_false; } -static jsval_t net_isIPv6(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t net_isIPv6(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_false; size_t len; const char *host = js_getstr(js, args[0], &len); @@ -47,8 +47,8 @@ static jsval_t net_isIPv6(ant_t *js, jsval_t *args, int nargs) { return inet_pton(AF_INET6, host, &addr) == 1 ? js_true : js_false; } -jsval_t net_library(ant_t *js) { - jsval_t lib = js_mkobj(js); +ant_value_t net_library(ant_t *js) { + ant_value_t lib = js_mkobj(js); js_set(js, lib, "isIP", js_mkfun(net_isIP)); js_set(js, lib, "isIPv4", js_mkfun(net_isIPv4)); diff --git a/src/modules/observable.c b/src/modules/observable.c index f794fd8..220d6e8 100644 --- a/src/modules/observable.c +++ b/src/modules/observable.c @@ -11,38 +11,38 @@ #include "modules/symbol.h" #include "modules/observable.h" -static inline bool is_callable(jsval_t val) { +static inline bool is_callable(ant_value_t val) { uint8_t t = vtype(val); return t == T_FUNC || t == T_CFUNC; } -static bool subscription_closed(ant_t *js, jsval_t subscription) { - jsval_t observer = js_get_slot(js, subscription, SLOT_SUBSCRIPTION_OBSERVER); +static bool subscription_closed(ant_t *js, ant_value_t subscription) { + ant_value_t observer = js_get_slot(js, subscription, SLOT_SUBSCRIPTION_OBSERVER); return vtype(observer) == T_UNDEF; } -static void cleanup_subscription(ant_t *js, jsval_t subscription) { - jsval_t cleanup = js_get_slot(js, subscription, SLOT_SUBSCRIPTION_CLEANUP); +static void cleanup_subscription(ant_t *js, ant_value_t subscription) { + ant_value_t cleanup = js_get_slot(js, subscription, SLOT_SUBSCRIPTION_CLEANUP); if (vtype(cleanup) == T_UNDEF) return; if (!is_callable(cleanup)) return; js_set_slot(js, subscription, SLOT_SUBSCRIPTION_CLEANUP, js_mkundef()); - jsval_t result = sv_vm_call(js->vm, js, cleanup, js_mkundef(), NULL, 0, NULL, false); + ant_value_t result = sv_vm_call(js->vm, js, cleanup, js_mkundef(), NULL, 0, NULL, false); if (vtype(result) == T_ERR) fprintf(stderr, "Error in subscription cleanup: %s\n", js_str(js, result)); } -static jsval_t create_subscription(ant_t *js, jsval_t observer) { - jsval_t subscription = js_mkobj(js); +static ant_value_t create_subscription(ant_t *js, ant_value_t observer) { + ant_value_t subscription = js_mkobj(js); js_set_slot(js, subscription, SLOT_SUBSCRIPTION_OBSERVER, observer); js_set_slot(js, subscription, SLOT_SUBSCRIPTION_CLEANUP, js_mkundef()); js_set_sym(js, subscription, get_toStringTag_sym(), js_mkstr(js, "Subscription", 12)); return subscription; } -static jsval_t js_subscription_get_closed(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_subscription_get_closed(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t subscription = js_getthis(js); + ant_value_t subscription = js_getthis(js); if (!is_special_object(subscription)) { return js_mkerr_typed(js, JS_ERR_TYPE, "Subscription.closed getter called on non-object"); @@ -50,9 +50,9 @@ static jsval_t js_subscription_get_closed(ant_t *js, jsval_t *args, int nargs) { return js_bool(subscription_closed(js, subscription)); } -static jsval_t js_subscription_unsubscribe(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_subscription_unsubscribe(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t subscription = js_getthis(js); + ant_value_t subscription = js_getthis(js); if (!is_special_object(subscription)) { return js_mkerr_typed(js, JS_ERR_TYPE, "Subscription.unsubscribe called on non-object"); @@ -66,21 +66,21 @@ static jsval_t js_subscription_unsubscribe(ant_t *js, jsval_t *args, int nargs) return js_mkundef(); } -static void setup_subscription_methods(ant_t *js, jsval_t subscription) { +static void setup_subscription_methods(ant_t *js, ant_value_t subscription) { js_set(js, subscription, "unsubscribe", js_mkfun(js_subscription_unsubscribe)); - jsval_t closed_getter = js_mkfun(js_subscription_get_closed); + ant_value_t closed_getter = js_mkfun(js_subscription_get_closed); js_set_getter_desc(js, subscription, "closed", 6, closed_getter, JS_DESC_E | JS_DESC_C); } -static jsval_t js_subobs_get_closed(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_subobs_get_closed(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t O = js_getthis(js); + ant_value_t O = js_getthis(js); if (!is_special_object(O)) { return js_mkerr_typed(js, JS_ERR_TYPE, "SubscriptionObserver.closed getter called on non-object"); } - jsval_t subscription = js_get_slot(js, O, SLOT_DATA); + ant_value_t subscription = js_get_slot(js, O, SLOT_DATA); if (!is_special_object(subscription)) { return js_mkerr_typed(js, JS_ERR_TYPE, "Invalid SubscriptionObserver"); } @@ -88,57 +88,57 @@ static jsval_t js_subobs_get_closed(ant_t *js, jsval_t *args, int nargs) { return js_bool(subscription_closed(js, subscription)); } -static jsval_t js_subobs_next(ant_t *js, jsval_t *args, int nargs) { - jsval_t O = js_getthis(js); +static ant_value_t js_subobs_next(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t O = js_getthis(js); if (!is_special_object(O)) { return js_mkerr_typed(js, JS_ERR_TYPE, "SubscriptionObserver.next called on non-object"); } - jsval_t subscription = js_get_slot(js, O, SLOT_DATA); + ant_value_t subscription = js_get_slot(js, O, SLOT_DATA); if (!is_special_object(subscription)) { return js_mkerr_typed(js, JS_ERR_TYPE, "Invalid SubscriptionObserver"); } if (subscription_closed(js, subscription)) return js_mkundef(); - jsval_t observer = js_get_slot(js, subscription, SLOT_SUBSCRIPTION_OBSERVER); + ant_value_t observer = js_get_slot(js, subscription, SLOT_SUBSCRIPTION_OBSERVER); if (!is_special_object(observer)) return js_mkundef(); - jsval_t nextMethod = js_get(js, observer, "next"); + ant_value_t nextMethod = js_get(js, observer, "next"); if (is_callable(nextMethod)) { - jsval_t value = (nargs > 0) ? args[0] : js_mkundef(); - jsval_t call_args[1] = {value}; - jsval_t result = sv_vm_call(js->vm, js, nextMethod, observer, call_args, 1, NULL, false); + ant_value_t value = (nargs > 0) ? args[0] : js_mkundef(); + ant_value_t call_args[1] = {value}; + ant_value_t result = sv_vm_call(js->vm, js, nextMethod, observer, call_args, 1, NULL, false); if (vtype(result) == T_ERR) fprintf(stderr, "Error in observer.next: %s\n", js_str(js, result)); } return js_mkundef(); } -static jsval_t js_subobs_error(ant_t *js, jsval_t *args, int nargs) { - jsval_t O = js_getthis(js); +static ant_value_t js_subobs_error(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t O = js_getthis(js); if (!is_special_object(O)) { return js_mkerr_typed(js, JS_ERR_TYPE, "SubscriptionObserver.error called on non-object"); } - jsval_t subscription = js_get_slot(js, O, SLOT_DATA); + ant_value_t subscription = js_get_slot(js, O, SLOT_DATA); if (!is_special_object(subscription)) { return js_mkerr_typed(js, JS_ERR_TYPE, "Invalid SubscriptionObserver"); } if (subscription_closed(js, subscription)) return js_mkundef(); - jsval_t observer = js_get_slot(js, subscription, SLOT_SUBSCRIPTION_OBSERVER); + ant_value_t observer = js_get_slot(js, subscription, SLOT_SUBSCRIPTION_OBSERVER); js_set_slot(js, subscription, SLOT_SUBSCRIPTION_OBSERVER, js_mkundef()); if (is_special_object(observer)) { - jsval_t errorMethod = js_get(js, observer, "error"); + ant_value_t errorMethod = js_get(js, observer, "error"); if (is_callable(errorMethod)) { - jsval_t exception = (nargs > 0) ? args[0] : js_mkundef(); - jsval_t call_args[1] = {exception}; - jsval_t result = sv_vm_call(js->vm, js, errorMethod, observer, call_args, 1, NULL, false); + ant_value_t exception = (nargs > 0) ? args[0] : js_mkundef(); + ant_value_t call_args[1] = {exception}; + ant_value_t result = sv_vm_call(js->vm, js, errorMethod, observer, call_args, 1, NULL, false); if (vtype(result) == T_ERR) fprintf(stderr, "Error in observer.error: %s\n", js_str(js, result)); } } @@ -147,28 +147,28 @@ static jsval_t js_subobs_error(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t js_subobs_complete(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_subobs_complete(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t O = js_getthis(js); + ant_value_t O = js_getthis(js); if (!is_special_object(O)) { return js_mkerr_typed(js, JS_ERR_TYPE, "SubscriptionObserver.complete called on non-object"); } - jsval_t subscription = js_get_slot(js, O, SLOT_DATA); + ant_value_t subscription = js_get_slot(js, O, SLOT_DATA); if (!is_special_object(subscription)) { return js_mkerr_typed(js, JS_ERR_TYPE, "Invalid SubscriptionObserver"); } if (subscription_closed(js, subscription)) return js_mkundef(); - jsval_t observer = js_get_slot(js, subscription, SLOT_SUBSCRIPTION_OBSERVER); + ant_value_t observer = js_get_slot(js, subscription, SLOT_SUBSCRIPTION_OBSERVER); js_set_slot(js, subscription, SLOT_SUBSCRIPTION_OBSERVER, js_mkundef()); if (is_special_object(observer)) { - jsval_t completeMethod = js_get(js, observer, "complete"); + ant_value_t completeMethod = js_get(js, observer, "complete"); if (is_callable(completeMethod)) { - jsval_t result = sv_vm_call(js->vm, js, completeMethod, observer, NULL, 0, NULL, false); + ant_value_t result = sv_vm_call(js->vm, js, completeMethod, observer, NULL, 0, NULL, false); if (vtype(result) == T_ERR) fprintf(stderr, "Error in observer.complete: %s\n", js_str(js, result)); } } @@ -177,8 +177,8 @@ static jsval_t js_subobs_complete(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t create_subscription_observer(ant_t *js, jsval_t subscription) { - jsval_t subobs = js_mkobj(js); +static ant_value_t create_subscription_observer(ant_t *js, ant_value_t subscription) { + ant_value_t subobs = js_mkobj(js); js_set_slot(js, subobs, SLOT_DATA, subscription); js_set(js, subobs, "next", js_mkfun(js_subobs_next)); @@ -186,20 +186,20 @@ static jsval_t create_subscription_observer(ant_t *js, jsval_t subscription) { js_set(js, subobs, "complete", js_mkfun(js_subobs_complete)); js_set_sym(js, subobs, get_toStringTag_sym(), js_mkstr(js, "SubscriptionObserver", 20)); - jsval_t closed_getter = js_mkfun(js_subobs_get_closed); + ant_value_t closed_getter = js_mkfun(js_subobs_get_closed); js_set_getter_desc(js, subobs, "closed", 6, closed_getter, JS_DESC_E | JS_DESC_C); return subobs; } -static jsval_t js_cleanup_fn(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_cleanup_fn(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t F = js_getcurrentfunc(js); - jsval_t subscription = js_get_slot(js, F, SLOT_DATA); + ant_value_t F = js_getcurrentfunc(js); + ant_value_t subscription = js_get_slot(js, F, SLOT_DATA); if (!is_special_object(subscription)) return js_mkundef(); - jsval_t unsubscribe = js_get(js, subscription, "unsubscribe"); + ant_value_t unsubscribe = js_get(js, subscription, "unsubscribe"); if (is_callable(unsubscribe)) { return sv_vm_call(js->vm, js, unsubscribe, subscription, NULL, 0, NULL, false); } @@ -207,21 +207,21 @@ static jsval_t js_cleanup_fn(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t execute_subscriber(ant_t *js, jsval_t subscriber, jsval_t observer) { - jsval_t call_args[1] = {observer}; - jsval_t subscriberResult = sv_vm_call(js->vm, js, subscriber, js_mkundef(), call_args, 1, NULL, false); +static ant_value_t execute_subscriber(ant_t *js, ant_value_t subscriber, ant_value_t observer) { + ant_value_t call_args[1] = {observer}; + ant_value_t subscriberResult = sv_vm_call(js->vm, js, subscriber, js_mkundef(), call_args, 1, NULL, false); if (vtype(subscriberResult) == T_ERR) return subscriberResult; if (vtype(subscriberResult) == T_NULL || vtype(subscriberResult) == T_UNDEF) return js_mkundef(); if (is_callable(subscriberResult)) return subscriberResult; if (is_special_object(subscriberResult)) { - jsval_t result = js_get(js, subscriberResult, "unsubscribe"); + ant_value_t result = js_get(js, subscriberResult, "unsubscribe"); if (vtype(result) == T_UNDEF) { return js_mkerr_typed(js, JS_ERR_TYPE, "Subscriber return value must have an unsubscribe method"); } - jsval_t cleanupFunction = js_mkobj(js); + ant_value_t cleanupFunction = js_mkobj(js); js_set_slot(js, cleanupFunction, SLOT_DATA, subscriberResult); js_set_slot(js, cleanupFunction, SLOT_CFUNC, js_mkfun(js_cleanup_fn)); return js_obj_to_func(cleanupFunction); @@ -230,24 +230,24 @@ static jsval_t execute_subscriber(ant_t *js, jsval_t subscriber, jsval_t observe return js_mkerr_typed(js, JS_ERR_TYPE, "Subscriber must return a function, an object with unsubscribe, or undefined"); } -static jsval_t js_observable_subscribe(ant_t *js, jsval_t *args, int nargs) { - jsval_t O = js_getthis(js); +static ant_value_t js_observable_subscribe(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t O = js_getthis(js); if (!is_special_object(O)) { return js_mkerr_typed(js, JS_ERR_TYPE, "Observable.prototype.subscribe called on non-object"); } - jsval_t subscriber = js_get_slot(js, O, SLOT_OBSERVABLE_SUBSCRIBER); + ant_value_t subscriber = js_get_slot(js, O, SLOT_OBSERVABLE_SUBSCRIBER); if (!is_callable(subscriber)) { return js_mkerr_typed(js, JS_ERR_TYPE, "Observable has no [[Subscriber]] internal slot"); } - jsval_t observer; + ant_value_t observer; if (nargs > 0 && is_callable(args[0])) { - jsval_t nextCallback = args[0]; - jsval_t errorCallback = (nargs > 1) ? args[1] : js_mkundef(); - jsval_t completeCallback = (nargs > 2) ? args[2] : js_mkundef(); + ant_value_t nextCallback = args[0]; + ant_value_t errorCallback = (nargs > 1) ? args[1] : js_mkundef(); + ant_value_t completeCallback = (nargs > 2) ? args[2] : js_mkundef(); observer = js_mkobj(js); js_set(js, observer, "next", nextCallback); @@ -257,29 +257,29 @@ static jsval_t js_observable_subscribe(ant_t *js, jsval_t *args, int nargs) { observer = args[0]; } else observer = js_mkobj(js); - jsval_t subscription = create_subscription(js, observer); + ant_value_t subscription = create_subscription(js, observer); setup_subscription_methods(js, subscription); - jsval_t start = js_get(js, observer, "start"); + ant_value_t start = js_get(js, observer, "start"); if (is_callable(start)) { - jsval_t start_args[1] = {subscription}; - jsval_t result = sv_vm_call(js->vm, js, start, observer, start_args, 1, NULL, false); + ant_value_t start_args[1] = {subscription}; + ant_value_t result = sv_vm_call(js->vm, js, start, observer, start_args, 1, NULL, false); if (vtype(result) == T_ERR) { fprintf(stderr, "Error in observer.start: %s\n", js_str(js, result)); } if (subscription_closed(js, subscription)) return subscription; } - jsval_t subscriptionObserver = create_subscription_observer(js, subscription); - jsval_t subscriberResult = execute_subscriber(js, subscriber, subscriptionObserver); + ant_value_t subscriptionObserver = create_subscription_observer(js, subscription); + ant_value_t subscriberResult = execute_subscriber(js, subscriber, subscriptionObserver); if (vtype(subscriberResult) == T_ERR) { - jsval_t thrown_error = js->thrown_value; + ant_value_t thrown_error = js->thrown_value; js->thrown_value = js_mkundef(); js->thrown_exists = false; - jsval_t error_args[1] = {thrown_error}; - jsval_t error_method = js_get(js, subscriptionObserver, "error"); + ant_value_t error_args[1] = {thrown_error}; + ant_value_t error_method = js_get(js, subscriptionObserver, "error"); if (is_callable(error_method)) sv_vm_call(js->vm, js, error_method, subscriptionObserver, error_args, 1, NULL, false); } else js_set_slot(js, subscription, SLOT_SUBSCRIPTION_CLEANUP, subscriberResult); @@ -288,23 +288,23 @@ static jsval_t js_observable_subscribe(ant_t *js, jsval_t *args, int nargs) { return subscription; } -static jsval_t js_observable_symbol_observable(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_observable_symbol_observable(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; return js_getthis(js); } -static jsval_t js_observable_constructor(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_observable_constructor(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) { return js_mkerr_typed(js, JS_ERR_TYPE, "Observable constructor requires a subscriber function"); } - jsval_t subscriber = args[0]; + ant_value_t subscriber = args[0]; if (!is_callable(subscriber)) { return js_mkerr_typed(js, JS_ERR_TYPE, "Observable subscriber must be a function"); } - jsval_t proto = js_get_ctor_proto(js, "Observable", 10); - jsval_t observable = js_mkobj(js); + ant_value_t proto = js_get_ctor_proto(js, "Observable", 10); + ant_value_t observable = js_mkobj(js); js_set_proto(js, observable, proto); js_set_slot(js, observable, SLOT_OBSERVABLE_SUBSCRIBER, subscriber); @@ -312,55 +312,55 @@ static jsval_t js_observable_constructor(ant_t *js, jsval_t *args, int nargs) { return observable; } -static jsval_t js_of_subscriber(ant_t *js, jsval_t *args, int nargs) { - jsval_t F = js_getcurrentfunc(js); - jsval_t items = js_get_slot(js, F, SLOT_DATA); +static ant_value_t js_of_subscriber(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t F = js_getcurrentfunc(js); + ant_value_t items = js_get_slot(js, F, SLOT_DATA); if (nargs < 1) return js_mkundef(); - jsval_t observer = args[0]; - jsval_t subscription = js_get_slot(js, observer, SLOT_DATA); + ant_value_t observer = args[0]; + ant_value_t subscription = js_get_slot(js, observer, SLOT_DATA); - jsval_t length_val = js_get(js, items, "length"); + ant_value_t length_val = js_get(js, items, "length"); int length = (vtype(length_val) == T_NUM) ? (int)js_getnum(length_val) : 0; for (int i = 0; i < length; i++) { char key[16]; snprintf(key, sizeof(key), "%d", i); - jsval_t value = js_get(js, items, key); + ant_value_t value = js_get(js, items, key); - jsval_t next = js_get(js, observer, "next"); + ant_value_t next = js_get(js, observer, "next"); if (is_callable(next)) { - jsval_t next_args[1] = {value}; + ant_value_t next_args[1] = {value}; sv_vm_call(js->vm, js, next, observer, next_args, 1, NULL, false); } if (is_special_object(subscription) && subscription_closed(js, subscription)) return js_mkundef(); } - jsval_t complete = js_get(js, observer, "complete"); + ant_value_t complete = js_get(js, observer, "complete"); if (is_callable(complete)) sv_vm_call(js->vm, js, complete, observer, NULL, 0, NULL, false); return js_mkundef(); } -static jsval_t js_observable_of(ant_t *js, jsval_t *args, int nargs) { - jsval_t items = js_mkarr(js); +static ant_value_t js_observable_of(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t items = js_mkarr(js); for (int i = 0; i < nargs; i++) js_arr_push(js, items, args[i]); - jsval_t subscriber_func = js_heavy_mkfun(js, js_of_subscriber, items); - jsval_t ctor_args[1] = {subscriber_func}; + ant_value_t subscriber_func = js_heavy_mkfun(js, js_of_subscriber, items); + ant_value_t ctor_args[1] = {subscriber_func}; return js_observable_constructor(js, ctor_args, 1); } -static jsval_t js_from_delegating(ant_t *js, jsval_t *args, int nargs) { - jsval_t F = js_getcurrentfunc(js); +static ant_value_t js_from_delegating(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t F = js_getcurrentfunc(js); - jsval_t observable = js_get_slot(js, F, SLOT_DATA); + ant_value_t observable = js_get_slot(js, F, SLOT_DATA); if (!is_special_object(observable)) return js_mkundef(); - jsval_t subscribe = js_get(js, observable, "subscribe"); + ant_value_t subscribe = js_get(js, observable, "subscribe"); if (is_callable(subscribe)) { return sv_vm_call(js->vm, js, subscribe, observable, args, nargs, NULL, false); } @@ -368,89 +368,89 @@ static jsval_t js_from_delegating(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t js_from_iteration(ant_t *js, jsval_t *args, int nargs) { - jsval_t F = js_getcurrentfunc(js); - jsval_t data = js_get_slot(js, F, SLOT_DATA); +static ant_value_t js_from_iteration(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t F = js_getcurrentfunc(js); + ant_value_t data = js_get_slot(js, F, SLOT_DATA); - jsval_t iterable = js_get(js, data, "iterable"); - jsval_t iteratorMethod = js_get(js, data, "iteratorMethod"); + ant_value_t iterable = js_get(js, data, "iterable"); + ant_value_t iteratorMethod = js_get(js, data, "iteratorMethod"); if (nargs < 1) return js_mkundef(); - jsval_t observer = args[0]; - jsval_t subscription = js_get_slot(js, observer, SLOT_DATA); + ant_value_t observer = args[0]; + ant_value_t subscription = js_get_slot(js, observer, SLOT_DATA); if (!is_callable(iteratorMethod)) { return js_mkerr_typed(js, JS_ERR_TYPE, "Object is not iterable"); } - jsval_t iterator = sv_vm_call(js->vm, js, iteratorMethod, iterable, NULL, 0, NULL, false); + ant_value_t iterator = sv_vm_call(js->vm, js, iteratorMethod, iterable, NULL, 0, NULL, false); if (!is_special_object(iterator)) { return js_mkerr_typed(js, JS_ERR_TYPE, "Iterator must return an object"); } - jsval_t nextMethod = js_getprop_fallback(js, iterator, "next"); + ant_value_t nextMethod = js_getprop_fallback(js, iterator, "next"); if (!is_callable(nextMethod)) { return js_mkerr_typed(js, JS_ERR_TYPE, "Iterator must have a next method"); } while (true) { - jsval_t next = sv_vm_call(js->vm, js, nextMethod, iterator, NULL, 0, NULL, false); + ant_value_t next = sv_vm_call(js->vm, js, nextMethod, iterator, NULL, 0, NULL, false); if (vtype(next) == T_ERR) return next; - jsval_t done = js_get(js, next, "done"); + ant_value_t done = js_get(js, next, "done"); if (js_truthy(js, done)) { - jsval_t complete = js_get(js, observer, "complete"); + ant_value_t complete = js_get(js, observer, "complete"); if (is_callable(complete)) sv_vm_call(js->vm, js, complete, observer, NULL, 0, NULL, false); return js_mkundef(); } - jsval_t nextValue = js_get(js, next, "value"); - jsval_t obs_next = js_get(js, observer, "next"); + ant_value_t nextValue = js_get(js, next, "value"); + ant_value_t obs_next = js_get(js, observer, "next"); if (is_callable(obs_next)) { - jsval_t next_args[1] = {nextValue}; + ant_value_t next_args[1] = {nextValue}; sv_vm_call(js->vm, js, obs_next, observer, next_args, 1, NULL, false); } if (is_special_object(subscription) && subscription_closed(js, subscription)) { - jsval_t returnMethod = js_getprop_fallback(js, iterator, "return"); + ant_value_t returnMethod = js_getprop_fallback(js, iterator, "return"); if (is_callable(returnMethod)) sv_vm_call(js->vm, js, returnMethod, iterator, NULL, 0, NULL, false); return js_mkundef(); } } } -static jsval_t js_observable_from(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_observable_from(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr_typed(js, JS_ERR_TYPE, "Observable.from requires an argument"); - jsval_t x = args[0]; + ant_value_t x = args[0]; if (vtype(x) == T_NULL || vtype(x) == T_UNDEF) { return js_mkerr_typed(js, JS_ERR_TYPE, "Cannot convert null or undefined to observable"); } - jsval_t observableMethod = js_get_sym(js, x, get_observable_sym()); + ant_value_t observableMethod = js_get_sym(js, x, get_observable_sym()); if (is_callable(observableMethod)) { - jsval_t observable = sv_vm_call(js->vm, js, observableMethod, x, NULL, 0, NULL, false); + ant_value_t observable = sv_vm_call(js->vm, js, observableMethod, x, NULL, 0, NULL, false); if (!is_special_object(observable)) { return js_mkerr_typed(js, JS_ERR_TYPE, "@@observable must return an object"); } - jsval_t existing_subscriber = js_get_slot(js, observable, SLOT_OBSERVABLE_SUBSCRIBER); + ant_value_t existing_subscriber = js_get_slot(js, observable, SLOT_OBSERVABLE_SUBSCRIBER); if (is_callable(existing_subscriber)) return observable; - jsval_t subscriber_func = js_heavy_mkfun(js, js_from_delegating, observable); - jsval_t ctor_args[1] = {subscriber_func}; + ant_value_t subscriber_func = js_heavy_mkfun(js, js_from_delegating, observable); + ant_value_t ctor_args[1] = {subscriber_func}; return js_observable_constructor(js, ctor_args, 1); } - jsval_t iteratorMethod = js_get_sym(js, x, get_iterator_sym()); + ant_value_t iteratorMethod = js_get_sym(js, x, get_iterator_sym()); if (!is_callable(iteratorMethod) && vtype(x) == T_ARR) { - jsval_t array_ctor = js_get(js, js_glob(js), "Array"); - jsval_t array_proto = js_get(js, array_ctor, "prototype"); + ant_value_t array_ctor = js_get(js, js_glob(js), "Array"); + ant_value_t array_proto = js_get(js, array_ctor, "prototype"); iteratorMethod = js_get_sym(js, array_proto, get_iterator_sym()); } @@ -458,22 +458,22 @@ static jsval_t js_observable_from(ant_t *js, jsval_t *args, int nargs) { return js_mkerr_typed(js, JS_ERR_TYPE, "Object is not observable or iterable"); } - jsval_t data = js_mkobj(js); + ant_value_t data = js_mkobj(js); js_set(js, data, "iterable", x); js_set(js, data, "iteratorMethod", iteratorMethod); - jsval_t subscriber_func = js_heavy_mkfun(js, js_from_iteration, data); - jsval_t ctor_args[1] = {subscriber_func}; + ant_value_t subscriber_func = js_heavy_mkfun(js, js_from_iteration, data); + ant_value_t ctor_args[1] = {subscriber_func}; return js_observable_constructor(js, ctor_args, 1); } void init_observable_module(void) { ant_t *js = rt->js; - jsval_t global = js_glob(js); + ant_value_t global = js_glob(js); - jsval_t observable_ctor = js_mkobj(js); - jsval_t observable_proto = js_mkobj(js); + ant_value_t observable_ctor = js_mkobj(js); + ant_value_t observable_proto = js_mkobj(js); js_set(js, observable_proto, "subscribe", js_mkfun(js_observable_subscribe)); js_set_sym(js, observable_proto, get_observable_sym(), js_mkfun(js_observable_symbol_observable)); @@ -486,7 +486,7 @@ void init_observable_module(void) { js_set(js, observable_ctor, "of", js_mkfun(js_observable_of)); js_set(js, observable_ctor, "from", js_mkfun(js_observable_from)); - jsval_t Observable = js_obj_to_func(observable_ctor); + ant_value_t Observable = js_obj_to_func(observable_ctor); js_set(js, observable_proto, "constructor", Observable); js_set(js, global, "Observable", Observable); } diff --git a/src/modules/os.c b/src/modules/os.c index 006062d..49fcaec 100644 --- a/src/modules/os.c +++ b/src/modules/os.c @@ -49,7 +49,7 @@ #define OS_DEVNULL "/dev/null" #endif -static jsval_t os_arch(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t os_arch(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; #if defined(__x86_64__) || defined(_M_X64) return js_mkstr(js, "x64", 3); @@ -76,7 +76,7 @@ static jsval_t os_arch(ant_t *js, jsval_t *args, int nargs) { #endif } -static jsval_t os_platform(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t os_platform(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; #if defined(__APPLE__) return js_mkstr(js, "darwin", 6); @@ -97,7 +97,7 @@ static jsval_t os_platform(ant_t *js, jsval_t *args, int nargs) { #endif } -static jsval_t os_type(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t os_type(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; #if defined(__APPLE__) return js_mkstr(js, "Darwin", 6); @@ -114,7 +114,7 @@ static jsval_t os_type(ant_t *js, jsval_t *args, int nargs) { #endif } -static jsval_t os_release(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t os_release(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; #ifdef _WIN32 OSVERSIONINFOA osvi; @@ -138,7 +138,7 @@ static jsval_t os_release(ant_t *js, jsval_t *args, int nargs) { #endif } -static jsval_t os_version(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t os_version(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; #ifdef _WIN32 OSVERSIONINFOA osvi; @@ -162,7 +162,7 @@ static jsval_t os_version(ant_t *js, jsval_t *args, int nargs) { #endif } -static jsval_t os_machine(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t os_machine(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; #ifdef _WIN32 SYSTEM_INFO sysinfo; @@ -183,7 +183,7 @@ static jsval_t os_machine(ant_t *js, jsval_t *args, int nargs) { #endif } -static jsval_t os_hostname(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t os_hostname(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; char hostname[256]; if (gethostname(hostname, sizeof(hostname)) == 0) { @@ -192,7 +192,7 @@ static jsval_t os_hostname(ant_t *js, jsval_t *args, int nargs) { return js_mkstr(js, "", 0); } -static jsval_t os_homedir(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t os_homedir(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; #ifdef _WIN32 const char *userprofile = getenv("USERPROFILE"); @@ -220,7 +220,7 @@ static jsval_t os_homedir(ant_t *js, jsval_t *args, int nargs) { #endif } -static jsval_t os_tmpdir(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t os_tmpdir(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; const char *tmpdir = getenv("TMPDIR"); if (!tmpdir) tmpdir = getenv("TMP"); @@ -229,7 +229,7 @@ static jsval_t os_tmpdir(ant_t *js, jsval_t *args, int nargs) { return js_mkstr(js, tmpdir, strlen(tmpdir)); } -static jsval_t os_endianness(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t os_endianness(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; uint16_t test = 1; if (*(uint8_t *)&test == 1) { @@ -238,7 +238,7 @@ static jsval_t os_endianness(ant_t *js, jsval_t *args, int nargs) { return js_mkstr(js, "BE", 2); } -static jsval_t os_uptime(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t os_uptime(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; #ifdef _WIN32 return js_mknum((double)GetTickCount64() / 1000.0); @@ -262,7 +262,7 @@ static jsval_t os_uptime(ant_t *js, jsval_t *args, int nargs) { #endif } -static jsval_t os_totalmem(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t os_totalmem(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; #ifdef _WIN32 MEMORYSTATUSEX memInfo; @@ -289,7 +289,7 @@ static jsval_t os_totalmem(ant_t *js, jsval_t *args, int nargs) { #endif } -static jsval_t os_freemem(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t os_freemem(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; #ifdef _WIN32 MEMORYSTATUSEX memInfo; @@ -320,7 +320,7 @@ static jsval_t os_freemem(ant_t *js, jsval_t *args, int nargs) { #endif } -static jsval_t os_availableParallelism(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t os_availableParallelism(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; #ifdef _WIN32 SYSTEM_INFO sysinfo; @@ -345,12 +345,12 @@ typedef struct { double user, nice, sys, idle, irq; } cpu_times_t; -static void push_cpu_entry(ant_t *js, jsval_t arr, const char *model, double speed, cpu_times_t *times) { - jsval_t cpu = js_mkobj(js); +static void push_cpu_entry(ant_t *js, ant_value_t arr, const char *model, double speed, cpu_times_t *times) { + ant_value_t cpu = js_mkobj(js); js_set(js, cpu, "model", js_mkstr(js, model, strlen(model))); js_set(js, cpu, "speed", js_mknum(speed)); - jsval_t t = js_mkobj(js); + ant_value_t t = js_mkobj(js); js_set(js, t, "user", js_mknum(times->user)); js_set(js, t, "nice", js_mknum(times->nice)); js_set(js, t, "sys", js_mknum(times->sys)); @@ -362,8 +362,8 @@ static void push_cpu_entry(ant_t *js, jsval_t arr, const char *model, double spe } #ifdef __APPLE__ -static jsval_t os_cpus_darwin(ant_t *js) { - jsval_t arr = js_mkarr(js); +static ant_value_t os_cpus_darwin(ant_t *js) { + ant_value_t arr = js_mkarr(js); natural_t ncpu; processor_info_array_t cpu_info; @@ -411,8 +411,8 @@ static char *parse_colon_value(char *line) { return colon; } -static jsval_t os_cpus_linux(ant_t *js) { - jsval_t arr = js_mkarr(js); +static ant_value_t os_cpus_linux(ant_t *js) { + ant_value_t arr = js_mkarr(js); char model[256] = "Unknown"; double speed = 0; int ncpu = 0; @@ -462,7 +462,7 @@ read_stat: } #endif -static jsval_t os_cpus(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t os_cpus(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; #ifdef __APPLE__ return os_cpus_darwin(js); @@ -473,9 +473,9 @@ static jsval_t os_cpus(ant_t *js, jsval_t *args, int nargs) { #endif } -static jsval_t os_loadavg(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t os_loadavg(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t arr = js_mkarr(js); + ant_value_t arr = js_mkarr(js); #if defined(__APPLE__) || defined(__linux__) double loadavg[3]; @@ -499,9 +499,9 @@ static jsval_t os_loadavg(ant_t *js, jsval_t *args, int nargs) { #ifdef _WIN32 -static jsval_t os_networkInterfaces(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t os_networkInterfaces(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t result = js_mkobj(js); + ant_value_t result = js_mkobj(js); ULONG bufLen = 15000; PIP_ADAPTER_ADDRESSES pAddresses = NULL; @@ -525,7 +525,7 @@ static jsval_t os_networkInterfaces(ant_t *js, jsval_t *args, int nargs) { } for (pCurrAddresses = pAddresses; pCurrAddresses; pCurrAddresses = pCurrAddresses->Next) { - jsval_t iface_arr = js_get(js, result, pCurrAddresses->AdapterName); + ant_value_t iface_arr = js_get(js, result, pCurrAddresses->AdapterName); if (!is_special_object(iface_arr)) { iface_arr = js_mkarr(js); js_set(js, result, pCurrAddresses->AdapterName, iface_arr); @@ -542,7 +542,7 @@ static jsval_t os_networkInterfaces(ant_t *js, jsval_t *args, int nargs) { bool internal = (pCurrAddresses->IfType == IF_TYPE_SOFTWARE_LOOPBACK); for (pUnicast = pCurrAddresses->FirstUnicastAddress; pUnicast; pUnicast = pUnicast->Next) { - jsval_t entry = js_mkobj(js); + ant_value_t entry = js_mkobj(js); js_set(js, entry, "mac", js_mkstr(js, mac_str, strlen(mac_str))); js_set(js, entry, "internal", js_bool(internal)); @@ -576,9 +576,9 @@ static jsval_t os_networkInterfaces(ant_t *js, jsval_t *args, int nargs) { return result; } -static jsval_t os_userInfo(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t os_userInfo(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t info = js_mkobj(js); + ant_value_t info = js_mkobj(js); js_set(js, info, "uid", js_mknum(-1)); js_set(js, info, "gid", js_mknum(-1)); @@ -603,12 +603,12 @@ static jsval_t os_userInfo(ant_t *js, jsval_t *args, int nargs) { return info; } -static jsval_t os_getPriority(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t os_getPriority(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; return js_mknum(0); } -static jsval_t os_setPriority(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t os_setPriority(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; return js_mkundef(); } @@ -636,13 +636,13 @@ static int calc_prefix_len(struct sockaddr *netmask, int family) { return prefix; } -static void add_iface_entry(ant_t *js, jsval_t iface_arr, struct ifaddrs *ifa, int family) { +static void add_iface_entry(ant_t *js, ant_value_t iface_arr, struct ifaddrs *ifa, int family) { char addr_str[INET6_ADDRSTRLEN] = ""; char netmask_str[INET6_ADDRSTRLEN] = ""; char cidr[128]; bool internal = (ifa->ifa_flags & IFF_LOOPBACK) != 0; - jsval_t entry = js_mkobj(js); + ant_value_t entry = js_mkobj(js); js_set(js, entry, "mac", js_mkstr(js, "00:00:00:00:00:00", 17)); js_set(js, entry, "internal", js_bool(internal)); @@ -699,29 +699,29 @@ static unsigned char *get_mac_bytes(struct ifaddrs *ifa) { #endif } -static void apply_mac_to_iface(ant_t *js, jsval_t result, const char *name, unsigned char *mac_bytes) { +static void apply_mac_to_iface(ant_t *js, ant_value_t result, const char *name, unsigned char *mac_bytes) { char mac_str[18]; format_mac_address(mac_str, sizeof(mac_str), mac_bytes); - jsval_t iface_arr = js_get(js, result, name); + ant_value_t iface_arr = js_get(js, result, name); if (!is_special_object(iface_arr)) return; - jsval_t len_val = js_get(js, iface_arr, "length"); + ant_value_t len_val = js_get(js, iface_arr, "length"); int len = (vtype(len_val) == T_NUM) ? (int)js_getnum(len_val) : 0; for (int i = 0; i < len; i++) { char idx[16]; snprintf(idx, sizeof(idx), "%d", i); - jsval_t entry = js_get(js, iface_arr, idx); + ant_value_t entry = js_get(js, iface_arr, idx); if (is_special_object(entry)) { js_set(js, entry, "mac", js_mkstr(js, mac_str, strlen(mac_str))); } } } -static jsval_t os_networkInterfaces(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t os_networkInterfaces(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t result = js_mkobj(js); + ant_value_t result = js_mkobj(js); struct ifaddrs *addrs, *ifa; if (getifaddrs(&addrs) != 0) return result; @@ -732,7 +732,7 @@ static jsval_t os_networkInterfaces(ant_t *js, jsval_t *args, int nargs) { int family = ifa->ifa_addr->sa_family; if (family != AF_INET && family != AF_INET6) continue; - jsval_t iface_arr = js_get(js, result, ifa->ifa_name); + ant_value_t iface_arr = js_get(js, result, ifa->ifa_name); if (!is_special_object(iface_arr)) { iface_arr = js_mkarr(js); js_set(js, result, ifa->ifa_name, iface_arr); @@ -753,9 +753,9 @@ static jsval_t os_networkInterfaces(ant_t *js, jsval_t *args, int nargs) { return result; } -static jsval_t os_userInfo(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t os_userInfo(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t info = js_mkobj(js); + ant_value_t info = js_mkobj(js); uid_t uid = getuid(); gid_t gid = getgid(); @@ -782,7 +782,7 @@ static jsval_t os_userInfo(ant_t *js, jsval_t *args, int nargs) { return info; } -static jsval_t os_getPriority(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t os_getPriority(ant_t *js, ant_value_t *args, int nargs) { int pid = 0; if (nargs > 0 && vtype(args[0]) == T_NUM) { pid = (int)js_getnum(args[0]); @@ -796,7 +796,7 @@ static jsval_t os_getPriority(ant_t *js, jsval_t *args, int nargs) { return js_mknum((double)priority); } -static jsval_t os_setPriority(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t os_setPriority(ant_t *js, ant_value_t *args, int nargs) { int pid = 0; int priority = 0; @@ -823,7 +823,7 @@ static jsval_t os_setPriority(ant_t *js, jsval_t *args, int nargs) { #endif -static void add_signal_constants(ant_t *js, jsval_t signals) { +static void add_signal_constants(ant_t *js, ant_value_t signals) { #ifdef SIGHUP js_set(js, signals, "SIGHUP", js_mknum(SIGHUP)); #endif @@ -916,7 +916,7 @@ static void add_signal_constants(ant_t *js, jsval_t signals) { #endif } -static void add_errno_constants(ant_t *js, jsval_t errn) { +static void add_errno_constants(ant_t *js, ant_value_t errn) { js_set(js, errn, "E2BIG", js_mknum(E2BIG)); js_set(js, errn, "EACCES", js_mknum(EACCES)); js_set(js, errn, "EADDRINUSE", js_mknum(EADDRINUSE)); @@ -985,7 +985,7 @@ static void add_errno_constants(ant_t *js, jsval_t errn) { js_set(js, errn, "EXDEV", js_mknum(EXDEV)); } -static void add_priority_constants(ant_t *js, jsval_t priority) { +static void add_priority_constants(ant_t *js, ant_value_t priority) { js_set(js, priority, "PRIORITY_LOW", js_mknum(19)); js_set(js, priority, "PRIORITY_BELOW_NORMAL", js_mknum(10)); js_set(js, priority, "PRIORITY_NORMAL", js_mknum(0)); @@ -994,7 +994,7 @@ static void add_priority_constants(ant_t *js, jsval_t priority) { js_set(js, priority, "PRIORITY_HIGHEST", js_mknum(-20)); } -static void add_dlopen_constants(ant_t *js, jsval_t dlopen_obj) { +static void add_dlopen_constants(ant_t *js, ant_value_t dlopen_obj) { #ifdef RTLD_LAZY js_set(js, dlopen_obj, "RTLD_LAZY", js_mknum(RTLD_LAZY)); #endif @@ -1012,8 +1012,8 @@ static void add_dlopen_constants(ant_t *js, jsval_t dlopen_obj) { #endif } -jsval_t os_library(ant_t *js) { - jsval_t lib = js_mkobj(js); +ant_value_t os_library(ant_t *js) { + ant_value_t lib = js_mkobj(js); js_set(js, lib, "EOL", js_mkstr(js, OS_EOL, strlen(OS_EOL))); js_set(js, lib, "devNull", js_mkstr(js, OS_DEVNULL, strlen(OS_DEVNULL))); @@ -1039,11 +1039,11 @@ jsval_t os_library(ant_t *js) { js_set(js, lib, "getPriority", js_mkfun(os_getPriority)); js_set(js, lib, "setPriority", js_mkfun(os_setPriority)); - jsval_t constants = js_mkobj(js); - jsval_t signals = js_mkobj(js); - jsval_t errn = js_mkobj(js); - jsval_t priority = js_mkobj(js); - jsval_t dlopen_obj = js_mkobj(js); + ant_value_t constants = js_mkobj(js); + ant_value_t signals = js_mkobj(js); + ant_value_t errn = js_mkobj(js); + ant_value_t priority = js_mkobj(js); + ant_value_t dlopen_obj = js_mkobj(js); add_signal_constants(js, signals); add_errno_constants(js, errn); diff --git a/src/modules/path.c b/src/modules/path.c index 5053ca3..c9ff84a 100644 --- a/src/modules/path.c +++ b/src/modules/path.c @@ -38,7 +38,7 @@ static char* normalize_separators(const char *path, size_t len) { return result; } -static jsval_t builtin_path_basename(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_path_basename(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "basename() requires a path argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "basename() path must be a string"); @@ -60,13 +60,13 @@ static jsval_t builtin_path_basename(ant_t *js, jsval_t *args, int nargs) { } } - jsval_t result = js_mkstr(js, base, strlen(base)); + ant_value_t result = js_mkstr(js, base, strlen(base)); free(path_copy); return result; } // path.dirname(path) -static jsval_t builtin_path_dirname(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_path_dirname(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "dirname() requires a path argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "dirname() path must be a string"); @@ -78,13 +78,13 @@ static jsval_t builtin_path_dirname(ant_t *js, jsval_t *args, int nargs) { if (!path_copy) return js_mkerr(js, "Out of memory"); char *dir = dirname(path_copy); - jsval_t result = js_mkstr(js, dir, strlen(dir)); + ant_value_t result = js_mkstr(js, dir, strlen(dir)); free(path_copy); return result; } // path.extname(path) -static jsval_t builtin_path_extname(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_path_extname(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "extname() requires a path argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "extname() path must be a string"); @@ -99,7 +99,7 @@ static jsval_t builtin_path_extname(ant_t *js, jsval_t *args, int nargs) { char *last_dot = strrchr(base, '.'); if (last_dot && last_dot != base) { - jsval_t result = js_mkstr(js, last_dot, strlen(last_dot)); + ant_value_t result = js_mkstr(js, last_dot, strlen(last_dot)); free(path_copy); return result; } @@ -192,7 +192,7 @@ fail: } // path.normalize(path) -static jsval_t builtin_path_normalize(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_path_normalize(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "normalize() requires a path argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "normalize() path must be a string"); @@ -203,13 +203,13 @@ static jsval_t builtin_path_normalize(ant_t *js, jsval_t *args, int nargs) { char *result = normalize_path_full(path, path_len); if (!result) return js_mkerr(js, "Out of memory"); - jsval_t ret = js_mkstr(js, result, strlen(result)); + ant_value_t ret = js_mkstr(js, result, strlen(result)); free(result); return ret; } // path.join(...paths) -static jsval_t builtin_path_join(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_path_join(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkstr(js, ".", 1); size_t total_len = 0; @@ -274,13 +274,13 @@ static jsval_t builtin_path_join(ant_t *js, jsval_t *args, int nargs) { if (!normalized) return js_mkerr(js, "Out of memory"); - jsval_t ret = js_mkstr(js, normalized, strlen(normalized)); + ant_value_t ret = js_mkstr(js, normalized, strlen(normalized)); free(normalized); return ret; } // path.resolve(...paths) -static jsval_t builtin_path_resolve(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_path_resolve(ant_t *js, ant_value_t *args, int nargs) { char cwd[PATH_MAX]; if (getcwd(cwd, sizeof(cwd)) == NULL) { return js_mkerr(js, "Failed to get current working directory"); @@ -315,13 +315,13 @@ static jsval_t builtin_path_resolve(ant_t *js, jsval_t *args, int nargs) { } } - jsval_t ret = js_mkstr(js, result, strlen(result)); + ant_value_t ret = js_mkstr(js, result, strlen(result)); free(result); return ret; } // path.relative(from, to) -static jsval_t builtin_path_relative(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_path_relative(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "relative() requires from and to arguments"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "relative() from must be a string"); if (vtype(args[1]) != T_STR) return js_mkerr(js, "relative() to must be a string"); @@ -337,7 +337,7 @@ static jsval_t builtin_path_relative(ant_t *js, jsval_t *args, int nargs) { } // path.isAbsolute(path) -static jsval_t builtin_path_isAbsolute(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_path_isAbsolute(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "isAbsolute() requires a path argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "isAbsolute() path must be a string"); @@ -355,7 +355,7 @@ static jsval_t builtin_path_isAbsolute(ant_t *js, jsval_t *args, int nargs) { } // path.parse(path) -static jsval_t builtin_path_parse(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_path_parse(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "parse() requires a path argument"); if (vtype(args[0]) != T_STR) return js_mkerr(js, "parse() path must be a string"); @@ -363,7 +363,7 @@ static jsval_t builtin_path_parse(ant_t *js, jsval_t *args, int nargs) { char *path = js_getstr(js, args[0], &path_len); if (!path) return js_mkerr(js, "Failed to get path string"); - jsval_t result = js_mkobj(js); + ant_value_t result = js_mkobj(js); if (path_len > 0 && path[0] == PATH_SEP) { js_set(js, result, "root", js_mkstr(js, PATH_SEP_STR, 1)); @@ -397,17 +397,17 @@ static jsval_t builtin_path_parse(ant_t *js, jsval_t *args, int nargs) { } // path.format(pathObject) -static jsval_t builtin_path_format(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_path_format(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "format() requires a path object argument"); if (!is_special_object(args[0])) return js_mkerr(js, "format() argument must be an object"); - jsval_t obj = args[0]; + ant_value_t obj = args[0]; - jsval_t dir_val = js_get(js, obj, "dir"); - jsval_t root_val = js_get(js, obj, "root"); - jsval_t base_val = js_get(js, obj, "base"); - jsval_t name_val = js_get(js, obj, "name"); - jsval_t ext_val = js_get(js, obj, "ext"); + ant_value_t dir_val = js_get(js, obj, "dir"); + ant_value_t root_val = js_get(js, obj, "root"); + ant_value_t base_val = js_get(js, obj, "base"); + ant_value_t name_val = js_get(js, obj, "name"); + ant_value_t ext_val = js_get(js, obj, "ext"); char result[PATH_MAX] = {0}; size_t pos = 0; @@ -460,8 +460,8 @@ static jsval_t builtin_path_format(ant_t *js, jsval_t *args, int nargs) { return js_mkstr(js, result, pos); } -jsval_t path_library(ant_t *js) { - jsval_t lib = js_mkobj(js); +ant_value_t path_library(ant_t *js) { + ant_value_t lib = js_mkobj(js); js_set(js, lib, "basename", js_mkfun(builtin_path_basename)); js_set(js, lib, "dirname", js_mkfun(builtin_path_dirname)); diff --git a/src/modules/performance.c b/src/modules/performance.c index d442d5d..c5c2ad1 100644 --- a/src/modules/performance.c +++ b/src/modules/performance.c @@ -29,20 +29,20 @@ static double get_current_time_ms(void) { } // performance.now() -static jsval_t js_performance_now(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_performance_now(ant_t *js, ant_value_t *args, int nargs) { (void) args; (void) nargs; double now = get_current_time_ms() - time_origin_ms; return js_mknum(now); } // performance.timeOrigin -static jsval_t js_performance_time_origin(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_performance_time_origin(ant_t *js, ant_value_t *args, int nargs) { (void) args; (void) nargs; return js_mknum(time_origin_ms); } -jsval_t perf_hooks_library(ant_t *js) { - jsval_t lib = js_mkobj(js); +ant_value_t perf_hooks_library(ant_t *js) { + ant_value_t lib = js_mkobj(js); js_set(js, lib, "performance", js_get(js, js_glob(js), "performance")); js_set_sym(js, lib, get_toStringTag_sym(), ANT_STRING("perf_hooks")); return lib; @@ -51,8 +51,8 @@ jsval_t perf_hooks_library(ant_t *js) { void init_performance_module() { ant_t *js = rt->js; - jsval_t glob = js_glob(js); - jsval_t perf_obj = js_mkobj(js); + ant_value_t glob = js_glob(js); + ant_value_t perf_obj = js_mkobj(js); time_origin_ms = get_current_time_ms(); diff --git a/src/modules/process.c b/src/modules/process.c index 539c7d9..70dca38 100644 --- a/src/modules/process.c +++ b/src/modules/process.c @@ -50,7 +50,7 @@ extern char **environ; #define INITIAL_LISTENER_CAPACITY 4 typedef struct { - jsval_t listener; + ant_value_t listener; bool once; } ProcessEventListener; @@ -261,7 +261,7 @@ static void check_listener_warning(const char *event) { ); } -void emit_process_event(const char *event_type, jsval_t *args, int nargs) { +void emit_process_event(const char *event_type, ant_value_t *args, int nargs) { if (!rt->js) return; ProcessEventType *evt = NULL; @@ -291,14 +291,14 @@ void emit_process_event(const char *event_type, jsval_t *args, int nargs) { static void process_signal_handler(int signum) { const char *name = get_signal_name(signum); if (name) { - jsval_t sig_arg = js_mkstr(rt->js, name, strlen(name)); + ant_value_t sig_arg = js_mkstr(rt->js, name, strlen(name)); emit_process_event(name, &sig_arg, 1); } } -static void emit_stdio_event(ProcessEventType **events, const char *event_type, jsval_t *args, int nargs) { +static void emit_stdio_event(ProcessEventType **events, const char *event_type, ant_value_t *args, int nargs) { if (!rt->js) return; ProcessEventType *evt = NULL; @@ -420,8 +420,8 @@ static void emit_keypress_event( const char *sequence, size_t sequence_len ) { - jsval_t str_val = js_mkstr(js, str ? str : "", str ? str_len : 0); - jsval_t key_obj = js_mkobj(js); + ant_value_t str_val = js_mkstr(js, str ? str : "", str ? str_len : 0); + ant_value_t key_obj = js_mkobj(js); if (name) { js_set(js, key_obj, "name", js_mkstr(js, name, strlen(name))); @@ -437,7 +437,7 @@ static void emit_keypress_event( js_set(js, key_obj, "sequence", js_mkstr(js, sequence, sequence_len)); } - jsval_t args[2] = { str_val, key_obj }; + ant_value_t args[2] = { str_val, key_obj }; emit_stdio_event(&stdin_events, "keypress", args, 2); } @@ -516,7 +516,7 @@ static void process_keypress_data(ant_t *js, const char *data, size_t len) { } } -static bool remove_listener_from_events(ProcessEventType **events, const char *event, jsval_t listener) { +static bool remove_listener_from_events(ProcessEventType **events, const char *event, ant_value_t listener) { ProcessEventType *evt = NULL; HASH_FIND_STR(*events, event, evt); if (!evt) return false; @@ -609,7 +609,7 @@ static void on_stdin_read(uv_stream_t *stream, ssize_t nread, const uv_buf_t *bu if (nread > 0 && rt->js) { ArrayBufferData *ab = create_array_buffer_data((size_t)nread); if (ab) memcpy(ab->data, buf->base, (size_t)nread); - jsval_t data_val = ab + ant_value_t data_val = ab ? create_typed_array(rt->js, TYPED_ARRAY_UINT8, ab, 0, (size_t)nread, "Buffer") : js_mkstr(rt->js, buf->base, (size_t)nread); emit_stdio_event(&stdin_events, "data", &data_val, 1); @@ -648,10 +648,10 @@ static void on_sigwinch(uv_signal_t *handle, int signum) { (void)handle; (void)signum; if (!rt->js) return; - jsval_t process_obj = js_get(rt->js, js_glob(rt->js), "process"); + ant_value_t process_obj = js_get(rt->js, js_glob(rt->js), "process"); if (!is_special_object(process_obj)) return; - jsval_t stdout_obj = js_get(rt->js, process_obj, "stdout"); + ant_value_t stdout_obj = js_get(rt->js, process_obj, "stdout"); if (!is_special_object(stdout_obj)) return; int rows = 0, cols = 0; @@ -677,25 +677,25 @@ static void start_sigwinch_handler(void) { #endif } -static jsval_t js_stdin_set_raw_mode(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_stdin_set_raw_mode(ant_t *js, ant_value_t *args, int nargs) { bool enable = nargs > 0 ? js_truthy(js, args[0]) : true; return js_bool(stdin_set_raw_mode(enable)); } -static jsval_t js_stdin_resume(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_stdin_resume(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; stdin_start_reading(); return js_getthis(js); } -static jsval_t js_stdin_pause(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_stdin_pause(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; stdin_stop_reading(); return js_getthis(js); } -static jsval_t js_stdin_on(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t js_stdin_on(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 2) return this_obj; char *event = js_getstr(js, args[0], NULL); @@ -713,8 +713,8 @@ static jsval_t js_stdin_on(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t js_stdin_remove_all_listeners(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t js_stdin_remove_all_listeners(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 1) { ProcessEventType *evt, *tmp; @@ -736,8 +736,8 @@ static jsval_t js_stdin_remove_all_listeners(ant_t *js, jsval_t *args, int nargs return this_obj; } -static jsval_t js_stdin_remove_listener(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t js_stdin_remove_listener(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 2) return this_obj; char *event = js_getstr(js, args[0], NULL); @@ -749,7 +749,7 @@ static jsval_t js_stdin_remove_listener(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t js_stdout_write(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_stdout_write(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_false; size_t len = 0; char *data = js_getstr(js, args[0], &len); @@ -759,8 +759,8 @@ static jsval_t js_stdout_write(ant_t *js, jsval_t *args, int nargs) { return js_true; } -static jsval_t js_stdout_on(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t js_stdout_on(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 2) return this_obj; char *event = js_getstr(js, args[0], NULL); @@ -778,8 +778,8 @@ static jsval_t js_stdout_on(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t js_stdout_once(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t js_stdout_once(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 2) return this_obj; char *event = js_getstr(js, args[0], NULL); @@ -797,8 +797,8 @@ static jsval_t js_stdout_once(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t js_stdout_remove_all_listeners(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t js_stdout_remove_all_listeners(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 1) { ProcessEventType *evt, *tmp; @@ -818,8 +818,8 @@ static jsval_t js_stdout_remove_all_listeners(ant_t *js, jsval_t *args, int narg return this_obj; } -static jsval_t js_stdout_remove_listener(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t js_stdout_remove_listener(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 2) return this_obj; char *event = js_getstr(js, args[0], NULL); @@ -829,24 +829,24 @@ static jsval_t js_stdout_remove_listener(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t js_stdout_get_window_size(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_stdout_get_window_size(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; int rows = 0, cols = 0; get_tty_size(STDOUT_FILENO, &rows, &cols); - jsval_t arr = js_mkarr(js); + ant_value_t arr = js_mkarr(js); js_arr_push(js, arr, js_mknum(cols)); js_arr_push(js, arr, js_mknum(rows)); return arr; } -static jsval_t js_stdout_rows_getter(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_stdout_rows_getter(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; int rows = 0, cols = 0; get_tty_size(STDOUT_FILENO, &rows, &cols); return js_mknum(rows); } -static jsval_t js_stdout_columns_getter(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_stdout_columns_getter(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; int rows = 0, cols = 0; get_tty_size(STDOUT_FILENO, &rows, &cols); @@ -855,7 +855,7 @@ static jsval_t js_stdout_columns_getter(ant_t *js, jsval_t *args, int nargs) { -static jsval_t js_stderr_write(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_stderr_write(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_false; size_t len = 0; char *data = js_getstr(js, args[0], &len); @@ -865,8 +865,8 @@ static jsval_t js_stderr_write(ant_t *js, jsval_t *args, int nargs) { return js_true; } -static jsval_t js_stderr_on(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t js_stderr_on(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 2) return this_obj; char *event = js_getstr(js, args[0], NULL); @@ -882,8 +882,8 @@ static jsval_t js_stderr_on(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t js_stderr_once(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t js_stderr_once(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 2) return this_obj; char *event = js_getstr(js, args[0], NULL); @@ -899,8 +899,8 @@ static jsval_t js_stderr_once(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t js_stderr_remove_all_listeners(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t js_stderr_remove_all_listeners(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 1) { ProcessEventType *evt, *tmp; @@ -920,8 +920,8 @@ static jsval_t js_stderr_remove_all_listeners(ant_t *js, jsval_t *args, int narg return this_obj; } -static jsval_t js_stderr_remove_listener(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t js_stderr_remove_listener(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 2) return this_obj; char *event = js_getstr(js, args[0], NULL); @@ -931,26 +931,26 @@ static jsval_t js_stderr_remove_listener(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t process_uptime(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_uptime(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; uint64_t now = uv_hrtime(); double seconds = (double)(now - process_start_time) / 1e9; return js_mknum(seconds); } -static jsval_t process_hrtime(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_hrtime(ant_t *js, ant_value_t *args, int nargs) { uint64_t now = uv_hrtime(); if (nargs > 0 && vtype(args[0]) == T_ARR) { - jsval_t prev_sec = js_get(js, args[0], "0"); - jsval_t prev_nsec = js_get(js, args[0], "1"); + ant_value_t prev_sec = js_get(js, args[0], "0"); + ant_value_t prev_nsec = js_get(js, args[0], "1"); if (vtype(prev_sec) == T_NUM && vtype(prev_nsec) == T_NUM) { uint64_t prev = (uint64_t)js_getnum(prev_sec) * 1000000000ULL + (uint64_t)js_getnum(prev_nsec); now = now - prev; } } - jsval_t arr = js_mkarr(js); + ant_value_t arr = js_mkarr(js); uint64_t secs = now / 1000000000ULL; uint64_t nsecs = now % 1000000000ULL; @@ -961,7 +961,7 @@ static jsval_t process_hrtime(ant_t *js, jsval_t *args, int nargs) { return arr; } -static jsval_t process_hrtime_bigint(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_hrtime_bigint(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; uint64_t now = uv_hrtime(); char buf[32]; @@ -969,9 +969,9 @@ static jsval_t process_hrtime_bigint(ant_t *js, jsval_t *args, int nargs) { return js_mkbigint(js, buf, strlen(buf), false); } -static jsval_t process_memory_usage(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_memory_usage(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t obj = js_mkobj(js); + ant_value_t obj = js_mkobj(js); size_t rss = 0; uv_resident_set_memory(&rss); @@ -1003,15 +1003,15 @@ static jsval_t process_memory_usage(ant_t *js, jsval_t *args, int nargs) { return obj; } -static jsval_t process_memory_usage_rss(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_memory_usage_rss(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; size_t rss = 0; uv_resident_set_memory(&rss); return js_mknum((double)rss); } -static jsval_t process_cpu_usage(ant_t *js, jsval_t *args, int nargs) { - jsval_t obj = js_mkobj(js); +static ant_value_t process_cpu_usage(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t obj = js_mkobj(js); uv_rusage_t rusage; if (uv_getrusage(&rusage) == 0) { @@ -1019,8 +1019,8 @@ static jsval_t process_cpu_usage(ant_t *js, jsval_t *args, int nargs) { int64_t sys_usec = rusage.ru_stime.tv_sec * 1000000LL + rusage.ru_stime.tv_usec; if (nargs > 0 && is_special_object(args[0])) { - jsval_t prev_user = js_get(js, args[0], "user"); - jsval_t prev_system = js_get(js, args[0], "system"); + ant_value_t prev_user = js_get(js, args[0], "user"); + ant_value_t prev_system = js_get(js, args[0], "system"); if (vtype(prev_user) == T_NUM) user_usec -= (int64_t)js_getnum(prev_user); if (vtype(prev_system) == T_NUM) sys_usec -= (int64_t)js_getnum(prev_system); } @@ -1035,7 +1035,7 @@ static jsval_t process_cpu_usage(ant_t *js, jsval_t *args, int nargs) { return obj; } -static jsval_t process_kill(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_kill(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "process.kill requires at least 1 argument"); if (vtype(args[0]) != T_NUM) return js_mkerr(js, "pid must be a number"); @@ -1060,13 +1060,13 @@ static jsval_t process_kill(ant_t *js, jsval_t *args, int nargs) { return js_true; } -static jsval_t process_abort(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_abort(ant_t *js, ant_value_t *args, int nargs) { (void)js; (void)args; (void)nargs; abort(); return js_mkundef(); } -static jsval_t process_chdir(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_chdir(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "process.chdir requires 1 argument"); char *dir = js_getstr(js, args[0], NULL); @@ -1077,7 +1077,7 @@ static jsval_t process_chdir(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t process_umask(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_umask(ant_t *js, ant_value_t *args, int nargs) { #ifdef _WIN32 (void)args; (void)nargs; return js_mknum(0); @@ -1094,27 +1094,27 @@ static jsval_t process_umask(ant_t *js, jsval_t *args, int nargs) { } #ifndef _WIN32 -static jsval_t process_getuid(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_getuid(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; return js_mknum((double)getuid()); } -static jsval_t process_geteuid(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_geteuid(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; return js_mknum((double)geteuid()); } -static jsval_t process_getgid(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_getgid(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; return js_mknum((double)getgid()); } -static jsval_t process_getegid(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_getegid(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; return js_mknum((double)getegid()); } -static jsval_t process_getgroups(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_getgroups(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; int ngroups = getgroups(0, NULL); if (ngroups < 0) return js_mkarr(js); @@ -1123,7 +1123,7 @@ static jsval_t process_getgroups(ant_t *js, jsval_t *args, int nargs) { if (!groups) return js_mkarr(js); ngroups = getgroups(ngroups, groups); - jsval_t arr = js_mkarr(js); + ant_value_t arr = js_mkarr(js); for (int i = 0; i < ngroups; i++) { js_arr_push(js, arr, js_mknum((double)groups[i])); } @@ -1131,7 +1131,7 @@ static jsval_t process_getgroups(ant_t *js, jsval_t *args, int nargs) { return arr; } -static jsval_t process_setuid(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_setuid(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "process.setuid requires 1 argument"); uid_t uid; @@ -1150,7 +1150,7 @@ static jsval_t process_setuid(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t process_setgid(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_setgid(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "process.setgid requires 1 argument"); gid_t gid; @@ -1169,7 +1169,7 @@ static jsval_t process_setgid(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t process_seteuid(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_seteuid(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "process.seteuid requires 1 argument"); uid_t uid; @@ -1188,7 +1188,7 @@ static jsval_t process_seteuid(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t process_setegid(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_setegid(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "process.setegid requires 1 argument"); gid_t gid; @@ -1207,12 +1207,12 @@ static jsval_t process_setegid(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t process_setgroups(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_setgroups(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || vtype(args[0]) != T_ARR) { return js_mkerr(js, "process.setgroups requires an array"); } - jsval_t len_val = js_get(js, args[0], "length"); + ant_value_t len_val = js_get(js, args[0], "length"); int len = (int)js_getnum(len_val); gid_t *groups = malloc(sizeof(gid_t) * (size_t)len); @@ -1221,7 +1221,7 @@ static jsval_t process_setgroups(ant_t *js, jsval_t *args, int nargs) { for (int i = 0; i < len; i++) { char idx[16]; snprintf(idx, sizeof(idx), "%d", i); - jsval_t val = js_get(js, args[0], idx); + ant_value_t val = js_get(js, args[0], idx); if (vtype(val) == T_NUM) { groups[i] = (gid_t)js_getnum(val); } else if (vtype(val) == T_STR) { @@ -1243,7 +1243,7 @@ static jsval_t process_setgroups(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t process_initgroups(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_initgroups(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "process.initgroups requires 2 arguments"); char *user = js_getstr(js, args[0], NULL); @@ -1266,7 +1266,7 @@ static jsval_t process_initgroups(ant_t *js, jsval_t *args, int nargs) { } #endif -static jsval_t env_getter(ant_t *js, jsval_t obj, const char *key, size_t key_len) { +static ant_value_t env_getter(ant_t *js, ant_value_t obj, const char *key, size_t key_len) { CSTR_BUF(buf, 256); char *key_str = CSTR_INIT(buf, key, key_len); if (!key_str) return js_mkundef(); @@ -1278,8 +1278,8 @@ static jsval_t env_getter(ant_t *js, jsval_t obj, const char *key, size_t key_le return js_mkstr(js, value, strlen(value)); } -static bool env_setter(ant_t *js, jsval_t obj, const char *key, size_t key_len, jsval_t value) { - jsval_t str_val = coerce_to_str(js, value); +static bool env_setter(ant_t *js, ant_value_t obj, const char *key, size_t key_len, ant_value_t value) { + ant_value_t str_val = coerce_to_str(js, value); if (is_err(str_val)) return false; setprop_cstr(js, obj, key, key_len, str_val); @@ -1295,14 +1295,14 @@ static bool env_setter(ant_t *js, jsval_t obj, const char *key, size_t key_len, return true; } -static bool env_deleter(ant_t *js, jsval_t obj, const char *key, size_t key_len) { +static bool env_deleter(ant_t *js, ant_value_t obj, const char *key, size_t key_len) { CSTR_BUF(buf, 256); char *key_str = CSTR_INIT(buf, key, key_len); if (key_str) { unsetenv(key_str); cstr_free(&buf); } return true; } -static void load_dotenv_file(ant_t *js, jsval_t env_obj) { +static void load_dotenv_file(ant_t *js, ant_value_t env_obj) { FILE *fp = fopen(".env", "r"); if (fp == NULL) return; @@ -1353,7 +1353,7 @@ static void load_dotenv_file(ant_t *js, jsval_t env_obj) { fclose(fp); } -static jsval_t process_exit(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_exit(ant_t *js, ant_value_t *args, int nargs) { int code = 0; if (nargs > 0 && vtype(args[0]) == T_NUM) { @@ -1379,7 +1379,7 @@ typedef void (*env_iter_cb)( void *ctx ); -static void env_foreach(ant_t *js, jsval_t env_obj, env_iter_cb cb, void *ctx) { +static void env_foreach(ant_t *js, ant_value_t env_obj, env_iter_cb cb, void *ctx) { for (char **env = environ; *env != NULL; env++) { char *entry = *env; char *equals = strchr(entry, '='); @@ -1391,7 +1391,7 @@ static void env_foreach(ant_t *js, jsval_t env_obj, env_iter_cb cb, void *ctx) { } ant_iter_t iter = js_prop_iter_begin(js, env_obj); - const char *key; size_t key_len; jsval_t value; + const char *key; size_t key_len; ant_value_t value; while (js_prop_iter_next(&iter, &key, &key_len, &value)) { if (key_len >= 2 && key[0] == '_' && key[1] == '_') continue; @@ -1415,7 +1415,7 @@ static void env_foreach(ant_t *js, jsval_t env_obj, env_iter_cb cb, void *ctx) { } static void env_to_object_cb(ant_t *js, const char *key, size_t key_len, const char *value, size_t val_len, void *ctx) { - jsval_t obj = *(jsval_t *)ctx; + ant_value_t obj = *(ant_value_t *)ctx; CSTR_BUF(buf, 256); char *key_str = CSTR_INIT(buf, key, key_len); if (!key_str) return; @@ -1423,8 +1423,8 @@ static void env_to_object_cb(ant_t *js, const char *key, size_t key_len, const c cstr_free(&buf); } -static jsval_t env_to_object(ant_t *js, jsval_t *args, int nargs) { - jsval_t obj = js_mkobj(js); +static ant_value_t env_to_object(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t obj = js_mkobj(js); env_foreach(js, js->this_val, env_to_object_cb, &obj); return obj; } @@ -1449,30 +1449,30 @@ static void env_tostring_cb(ant_t *js, const char *key, size_t key_len, const ch c->pos += val_len; } -static jsval_t env_toString(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t env_toString(ant_t *js, ant_value_t *args, int nargs) { env_str_ctx ctx = { .buf = malloc(4096), .pos = 0, .cap = 4096 }; if (!ctx.buf) return js_mkstr(js, "", 0); env_foreach(js, js->this_val, env_tostring_cb, &ctx); ctx.buf[ctx.pos] = '\0'; - jsval_t ret = js_mkstr(js, ctx.buf, ctx.pos); + ant_value_t ret = js_mkstr(js, ctx.buf, ctx.pos); free(ctx.buf); return ret; } static void env_keys_cb(ant_t *js, const char *key, size_t key_len, const char *value, size_t val_len, void *ctx) { - jsval_t arr = *(jsval_t *)ctx; + ant_value_t arr = *(ant_value_t *)ctx; js_arr_push(js, arr, js_mkstr(js, key, key_len)); } -static jsval_t env_keys(ant_t *js, jsval_t obj) { - jsval_t arr = js_mkarr(js); +static ant_value_t env_keys(ant_t *js, ant_value_t obj) { + ant_value_t arr = js_mkarr(js); env_foreach(js, obj, env_keys_cb, &arr); return arr; } -static jsval_t process_cwd(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_cwd(ant_t *js, ant_value_t *args, int nargs) { char cwd[4096]; if (getcwd(cwd, sizeof(cwd)) != NULL) { return js_mkstr(js, cwd, strlen(cwd)); @@ -1480,7 +1480,7 @@ static jsval_t process_cwd(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t process_on(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_on(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "process.on requires 2 arguments"); char *event = js_getstr(js, args[0], NULL); @@ -1506,7 +1506,7 @@ static jsval_t process_on(ant_t *js, jsval_t *args, int nargs) { return js_get(js, js_glob(js), "process"); } -static jsval_t process_once(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_once(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "process.once requires 2 arguments"); char *event = js_getstr(js, args[0], NULL); @@ -1532,8 +1532,8 @@ static jsval_t process_once(ant_t *js, jsval_t *args, int nargs) { return js_get(js, js_glob(js), "process"); } -static jsval_t process_off(ant_t *js, jsval_t *args, int nargs) { - jsval_t process_obj = js_get(js, js_glob(js), "process"); +static ant_value_t process_off(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t process_obj = js_get(js, js_glob(js), "process"); if (nargs < 2) return process_obj; char *event = js_getstr(js, args[0], NULL); @@ -1560,8 +1560,8 @@ static jsval_t process_off(ant_t *js, jsval_t *args, int nargs) { return process_obj; } -static jsval_t process_remove_all_listeners(ant_t *js, jsval_t *args, int nargs) { - jsval_t process_obj = js_get(js, js_glob(js), "process"); +static ant_value_t process_remove_all_listeners(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t process_obj = js_get(js, js_glob(js), "process"); if (nargs > 0 && vtype(args[0]) == T_STR) { char *event = js_getstr(js, args[0], NULL); @@ -1586,7 +1586,7 @@ static jsval_t process_remove_all_listeners(ant_t *js, jsval_t *args, int nargs) return process_obj; } -static jsval_t process_emit(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_emit(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_false; char *event = js_getstr(js, args[0], NULL); @@ -1596,7 +1596,7 @@ static jsval_t process_emit(ant_t *js, jsval_t *args, int nargs) { return js_true; } -static jsval_t process_listener_count(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_listener_count(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mknum(0); char *event = js_getstr(js, args[0], NULL); @@ -1608,7 +1608,7 @@ static jsval_t process_listener_count(ant_t *js, jsval_t *args, int nargs) { return js_mknum(evt ? evt->listener_count : 0); } -static jsval_t process_set_max_listeners(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_set_max_listeners(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "setMaxListeners requires 1 argument"); if (vtype(args[0]) != T_NUM) return js_mkerr(js, "n must be a number"); @@ -1619,20 +1619,20 @@ static jsval_t process_set_max_listeners(ant_t *js, jsval_t *args, int nargs) { return js_get(js, js_glob(js), "process"); } -static jsval_t process_get_max_listeners(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t process_get_max_listeners(ant_t *js, ant_value_t *args, int nargs) { return js_mknum(max_listeners); } -jsval_t process_library(ant_t *js) { +ant_value_t process_library(ant_t *js) { return js_get(js, js_glob(js), "process"); } void init_process_module() { ant_t *js = rt->js; - jsval_t global = js_glob(js); + ant_value_t global = js_glob(js); process_start_time = uv_hrtime(); - jsval_t process_proto = js_mkobj(js); + ant_value_t process_proto = js_mkobj(js); js_set(js, process_proto, "exit", js_mkfun(process_exit)); js_set(js, process_proto, "on", js_mkfun(process_on)); @@ -1653,11 +1653,11 @@ void init_process_module() { js_set(js, process_proto, "abort", js_mkfun(process_abort)); js_set(js, process_proto, "umask", js_mkfun(process_umask)); - jsval_t mem_usage_fn = js_heavy_mkfun(js, process_memory_usage, js_mkundef()); + ant_value_t mem_usage_fn = js_heavy_mkfun(js, process_memory_usage, js_mkundef()); js_set(js, mem_usage_fn, "rss", js_mkfun(process_memory_usage_rss)); js_set(js, process_proto, "memoryUsage", mem_usage_fn); - jsval_t hrtime_fn = js_heavy_mkfun(js, process_hrtime, js_mkundef()); + ant_value_t hrtime_fn = js_heavy_mkfun(js, process_hrtime, js_mkundef()); js_set(js, hrtime_fn, "bigint", js_mkfun(process_hrtime_bigint)); js_set(js, process_proto, "hrtime", hrtime_fn); js_set(js, process_proto, "dlopen", js_mkfun(napi_process_dlopen_js)); @@ -1678,8 +1678,8 @@ void init_process_module() { js_set_sym(js, process_proto, get_toStringTag_sym(), js_mkstr(js, "process", 7)); - jsval_t process_obj = js_mkobj(js); - jsval_t env_obj = js_mkobj(js); + ant_value_t process_obj = js_mkobj(js); + ant_value_t env_obj = js_mkobj(js); js_set_proto(js, process_obj, process_proto); load_dotenv_file(js, env_obj); @@ -1693,7 +1693,7 @@ void init_process_module() { js_set(js, env_obj, "toString", js_mkfun(env_toString)); js_set(js, process_obj, "env", env_obj); - jsval_t argv_arr = js_mkarr(js); + ant_value_t argv_arr = js_mkarr(js); for (int i = 0; i < rt->argc; i++) { js_arr_push(js, argv_arr, js_mkstr(js, rt->argv[i], strlen(rt->argv[i]))); } @@ -1710,14 +1710,14 @@ void init_process_module() { snprintf(version_str, sizeof(version_str), "v%s", ANT_VERSION); js_set(js, process_obj, "version", js_mkstr(js, version_str, strlen(version_str))); - jsval_t versions_obj = js_mkobj(js); + ant_value_t versions_obj = js_mkobj(js); js_set(js, versions_obj, "ant", js_mkstr(js, ANT_VERSION, strlen(ANT_VERSION))); char uv_ver[32]; snprintf(uv_ver, sizeof(uv_ver), "%d.%d.%d", UV_VERSION_MAJOR, UV_VERSION_MINOR, UV_VERSION_PATCH); js_set(js, versions_obj, "uv", js_mkstr(js, uv_ver, strlen(uv_ver))); js_set(js, process_obj, "versions", versions_obj); - jsval_t release_obj = js_mkobj(js); + ant_value_t release_obj = js_mkobj(js); js_set(js, release_obj, "name", js_mkstr(js, "ant", 3)); js_set(js, process_obj, "release", release_obj); @@ -1747,7 +1747,7 @@ void init_process_module() { js_set(js, process_obj, "arch", js_mkstr(js, "unknown", 7)); #endif - jsval_t stdin_proto = js_mkobj(js); + ant_value_t stdin_proto = js_mkobj(js); js_set(js, stdin_proto, "setRawMode", js_mkfun(js_stdin_set_raw_mode)); js_set(js, stdin_proto, "resume", js_mkfun(js_stdin_resume)); js_set(js, stdin_proto, "pause", js_mkfun(js_stdin_pause)); @@ -1757,12 +1757,12 @@ void init_process_module() { js_set(js, stdin_proto, "removeAllListeners", js_mkfun(js_stdin_remove_all_listeners)); js_set_sym(js, stdin_proto, get_toStringTag_sym(), js_mkstr(js, "ReadStream", 10)); - jsval_t stdin_obj = js_mkobj(js); + ant_value_t stdin_obj = js_mkobj(js); js_set_proto(js, stdin_obj, stdin_proto); js_set(js, stdin_obj, "isTTY", js_bool(stdin_is_tty())); js_set(js, process_obj, "stdin", stdin_obj); - jsval_t stdout_proto = js_mkobj(js); + ant_value_t stdout_proto = js_mkobj(js); js_set(js, stdout_proto, "write", js_mkfun(js_stdout_write)); js_set(js, stdout_proto, "on", js_mkfun(js_stdout_on)); js_set(js, stdout_proto, "once", js_mkfun(js_stdout_once)); @@ -1772,14 +1772,14 @@ void init_process_module() { js_set(js, stdout_proto, "getWindowSize", js_mkfun(js_stdout_get_window_size)); js_set_sym(js, stdout_proto, get_toStringTag_sym(), js_mkstr(js, "WriteStream", 11)); - jsval_t stdout_obj = js_mkobj(js); + ant_value_t stdout_obj = js_mkobj(js); js_set_proto(js, stdout_obj, stdout_proto); js_set(js, stdout_obj, "isTTY", js_bool(stdout_is_tty())); js_set_getter_desc(js, stdout_obj, "rows", 4, js_mkfun(js_stdout_rows_getter), JS_DESC_E | JS_DESC_C); js_set_getter_desc(js, stdout_obj, "columns", 7, js_mkfun(js_stdout_columns_getter), JS_DESC_E | JS_DESC_C); js_set(js, process_obj, "stdout", stdout_obj); - jsval_t stderr_proto = js_mkobj(js); + ant_value_t stderr_proto = js_mkobj(js); js_set(js, stderr_proto, "write", js_mkfun(js_stderr_write)); js_set(js, stderr_proto, "on", js_mkfun(js_stderr_on)); js_set(js, stderr_proto, "once", js_mkfun(js_stderr_once)); @@ -1788,7 +1788,7 @@ void init_process_module() { js_set(js, stderr_proto, "removeAllListeners", js_mkfun(js_stderr_remove_all_listeners)); js_set_sym(js, stderr_proto, get_toStringTag_sym(), js_mkstr(js, "WriteStream", 11)); - jsval_t stderr_obj = js_mkobj(js); + ant_value_t stderr_obj = js_mkobj(js); js_set_proto(js, stderr_obj, stderr_proto); js_set(js, stderr_obj, "isTTY", js_bool(stderr_is_tty())); js_set(js, process_obj, "stderr", stderr_obj); diff --git a/src/modules/readline.c b/src/modules/readline.c index 62c379f..bbe5cb4 100644 --- a/src/modules/readline.c +++ b/src/modules/readline.c @@ -41,7 +41,7 @@ #define MAX_INTERFACES 64 typedef struct { - jsval_t listener; + ant_value_t listener; bool once; } RLEventListener; @@ -63,10 +63,10 @@ typedef struct { typedef struct rl_interface { uint64_t id; - jsval_t input_stream; - jsval_t output_stream; - jsval_t completer; - jsval_t js_obj; + ant_value_t input_stream; + ant_value_t output_stream; + ant_value_t completer; + ant_value_t js_obj; char *prompt; char *line_buffer; int line_pos; @@ -81,8 +81,8 @@ typedef struct rl_interface { int crlf_delay; int escape_code_timeout; int tab_size; - jsval_t pending_question_resolve; - jsval_t pending_question_reject; + ant_value_t pending_question_resolve; + ant_value_t pending_question_reject; RLEventType *events; uv_tty_t tty_in; uv_tty_t tty_out; @@ -177,7 +177,7 @@ static RLEventType *find_or_create_event_type(rl_interface_t *iface, const char return evt; } -static void emit_event(ant_t *js, rl_interface_t *iface, const char *event_type, jsval_t *args, int nargs) { +static void emit_event(ant_t *js, rl_interface_t *iface, const char *event_type, ant_value_t *args, int nargs) { RLEventType *evt = NULL; HASH_FIND_STR(iface->events, event_type, evt); @@ -197,8 +197,8 @@ static void emit_event(ant_t *js, rl_interface_t *iface, const char *event_type, } } -static jsval_t get_history_array(ant_t *js, rl_interface_t *iface) { - jsval_t arr = js_mkarr(js); +static ant_value_t get_history_array(ant_t *js, rl_interface_t *iface) { + ant_value_t arr = js_mkarr(js); for (int i = 0; i < iface->history.count; i++) { js_arr_push(js, arr, js_mkstr(js, iface->history.lines[i], strlen(iface->history.lines[i]))); } @@ -206,7 +206,7 @@ static jsval_t get_history_array(ant_t *js, rl_interface_t *iface) { } static void emit_history_event(ant_t *js, rl_interface_t *iface) { - jsval_t history_arr = get_history_array(js, iface); + ant_value_t history_arr = get_history_array(js, iface); emit_event(js, iface, "history", &history_arr, 1); } @@ -502,7 +502,7 @@ static void on_stdin_read(uv_stream_t *stream, ssize_t nread, const uv_buf_t *bu rl_history_add(&iface->history, line, iface->remove_history_duplicates); emit_history_event(js, iface); - jsval_t line_val = js_mkstr(js, line, strlen(line)); + ant_value_t line_val = js_mkstr(js, line, strlen(line)); emit_event(js, iface, "line", &line_val, 1); if (vtype(iface->pending_question_resolve) == T_FUNC) { @@ -595,7 +595,7 @@ static void process_line(ant_t *js, rl_interface_t *iface) { rl_history_add(&iface->history, line, iface->remove_history_duplicates); emit_history_event(js, iface); - jsval_t line_val = js_mkstr(js, line, strlen(line)); + ant_value_t line_val = js_mkstr(js, line, strlen(line)); emit_event(js, iface, "line", &line_val, 1); if (vtype(iface->pending_question_resolve) == T_FUNC) { @@ -611,8 +611,8 @@ static void process_line(ant_t *js, rl_interface_t *iface) { free(line); } -static rl_interface_t *get_interface(ant_t *js, jsval_t this_obj) { - jsval_t id_val = js_get(js, this_obj, "_rl_id"); +static rl_interface_t *get_interface(ant_t *js, ant_value_t this_obj) { + ant_value_t id_val = js_get(js, this_obj, "_rl_id"); if (vtype(id_val) != T_NUM) return NULL; uint64_t id = (uint64_t)js_getnum(id_val); @@ -621,8 +621,8 @@ static rl_interface_t *get_interface(ant_t *js, jsval_t this_obj) { return iface; } -static jsval_t rl_interface_on(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t rl_interface_on(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); rl_interface_t *iface = get_interface(js, this_obj); if (!iface) return js_mkerr(js, "Invalid Interface"); @@ -645,8 +645,8 @@ static jsval_t rl_interface_on(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t rl_interface_once(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t rl_interface_once(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); rl_interface_t *iface = get_interface(js, this_obj); if (!iface) return js_mkerr(js, "Invalid Interface"); @@ -669,8 +669,8 @@ static jsval_t rl_interface_once(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t rl_interface_off(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t rl_interface_off(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); rl_interface_t *iface = get_interface(js, this_obj); if (!iface) return js_mkerr(js, "Invalid Interface"); @@ -696,8 +696,8 @@ static jsval_t rl_interface_off(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t rl_interface_emit(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t rl_interface_emit(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); rl_interface_t *iface = get_interface(js, this_obj); if (!iface) return js_mkerr(js, "Invalid Interface"); @@ -710,9 +710,9 @@ static jsval_t rl_interface_emit(ant_t *js, jsval_t *args, int nargs) { return js_true; } -static jsval_t rl_interface_close(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t rl_interface_close(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t this_obj = js_getthis(js); + ant_value_t this_obj = js_getthis(js); rl_interface_t *iface = get_interface(js, this_obj); if (!iface || iface->closed) return js_mkundef(); @@ -735,9 +735,9 @@ static jsval_t rl_interface_close(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t rl_interface_pause(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t rl_interface_pause(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t this_obj = js_getthis(js); + ant_value_t this_obj = js_getthis(js); rl_interface_t *iface = get_interface(js, this_obj); if (!iface) return js_mkerr(js, "Invalid Interface"); @@ -751,9 +751,9 @@ static jsval_t rl_interface_pause(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t rl_interface_resume(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t rl_interface_resume(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t this_obj = js_getthis(js); + ant_value_t this_obj = js_getthis(js); rl_interface_t *iface = get_interface(js, this_obj); if (!iface) return js_mkerr(js, "Invalid Interface"); @@ -767,8 +767,8 @@ static jsval_t rl_interface_resume(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t rl_interface_prompt(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t rl_interface_prompt(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); rl_interface_t *iface = get_interface(js, this_obj); if (!iface || iface->closed) return js_mkundef(); @@ -797,8 +797,8 @@ static jsval_t rl_interface_prompt(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t rl_interface_set_prompt(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t rl_interface_set_prompt(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); rl_interface_t *iface = get_interface(js, this_obj); if (!iface) return js_mkerr(js, "Invalid Interface"); @@ -813,9 +813,9 @@ static jsval_t rl_interface_set_prompt(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t rl_interface_get_prompt(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t rl_interface_get_prompt(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t this_obj = js_getthis(js); + ant_value_t this_obj = js_getthis(js); rl_interface_t *iface = get_interface(js, this_obj); if (!iface) return js_mkerr(js, "Invalid Interface"); @@ -864,8 +864,8 @@ static void process_key_sequence(rl_interface_t *iface, const char *name, bool c } } -static jsval_t rl_interface_write(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t rl_interface_write(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); rl_interface_t *iface = get_interface(js, this_obj); if (!iface || iface->closed) return js_mkundef(); @@ -876,11 +876,11 @@ static jsval_t rl_interface_write(ant_t *js, jsval_t *args, int nargs) { } if (nargs >= 2 && is_special_object(args[1])) { - jsval_t key = args[1]; - jsval_t name_val = js_get(js, key, "name"); - jsval_t ctrl_val = js_get(js, key, "ctrl"); - jsval_t meta_val = js_get(js, key, "meta"); - jsval_t shift_val = js_get(js, key, "shift"); + ant_value_t key = args[1]; + ant_value_t name_val = js_get(js, key, "name"); + ant_value_t ctrl_val = js_get(js, key, "ctrl"); + ant_value_t meta_val = js_get(js, key, "meta"); + ant_value_t shift_val = js_get(js, key, "shift"); char *name = (vtype(name_val) == T_STR) ? js_getstr(js, name_val, NULL) : NULL; bool ctrl = js_truthy(js, ctrl_val); @@ -919,26 +919,26 @@ static jsval_t rl_interface_write(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t rl_interface_line_getter(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t rl_interface_line_getter(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t this_obj = js_getthis(js); + ant_value_t this_obj = js_getthis(js); rl_interface_t *iface = get_interface(js, this_obj); if (!iface) return js_mkundef(); return js_mkstr(js, iface->line_buffer, strlen(iface->line_buffer)); } -static jsval_t rl_interface_cursor_getter(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t rl_interface_cursor_getter(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t this_obj = js_getthis(js); + ant_value_t this_obj = js_getthis(js); rl_interface_t *iface = get_interface(js, this_obj); if (!iface) return js_mknum(0); return js_mknum((double)iface->line_pos); } -static jsval_t rl_interface_question_callback(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t rl_interface_question_callback(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); rl_interface_t *iface = get_interface(js, this_obj); if (!iface || iface->closed) return js_mkundef(); @@ -967,8 +967,8 @@ static jsval_t rl_interface_question_callback(ant_t *js, jsval_t *args, int narg return js_mkundef(); } -static jsval_t rl_interface_question_promise(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t rl_interface_question_promise(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); rl_interface_t *iface = get_interface(js, this_obj); if (!iface || iface->closed) return js_mkerr(js, "Interface is closed"); @@ -978,7 +978,7 @@ static jsval_t rl_interface_question_promise(ant_t *js, jsval_t *args, int nargs char *query = js_getstr(js, args[0], &query_len); if (!query) return js_mkerr(js, "query must be a string"); - jsval_t promise = js_mkpromise(js); + ant_value_t promise = js_mkpromise(js); write_output(iface, query); @@ -988,13 +988,13 @@ static jsval_t rl_interface_question_promise(ant_t *js, jsval_t *args, int nargs return promise; } -static jsval_t rl_interface_get_cursor_pos(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t rl_interface_get_cursor_pos(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t this_obj = js_getthis(js); + ant_value_t this_obj = js_getthis(js); rl_interface_t *iface = get_interface(js, this_obj); if (!iface) { - jsval_t result = js_mkobj(js); + ant_value_t result = js_mkobj(js); js_set(js, result, "rows", js_mknum(0)); js_set(js, result, "cols", js_mknum(0)); return result; @@ -1019,29 +1019,29 @@ static jsval_t rl_interface_get_cursor_pos(ant_t *js, jsval_t *args, int nargs) int rows = total_cols / cols; int col_pos = total_cols % cols; - jsval_t result = js_mkobj(js); + ant_value_t result = js_mkobj(js); js_set(js, result, "rows", js_mknum((double)rows)); js_set(js, result, "cols", js_mknum((double)col_pos)); return result; } -static jsval_t rl_interface_closed_getter(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t rl_interface_closed_getter(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t this_obj = js_getthis(js); + ant_value_t this_obj = js_getthis(js); rl_interface_t *iface = get_interface(js, this_obj); if (!iface) return js_true; return js_bool(iface->closed); } -static jsval_t rl_interface_async_iterator(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t rl_interface_async_iterator(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t this_obj = js_getthis(js); + ant_value_t this_obj = js_getthis(js); rl_interface_t *iface = get_interface(js, this_obj); if (!iface) return js_mkerr(js, "Invalid Interface"); - jsval_t iterator = js_mkobj(js); + ant_value_t iterator = js_mkobj(js); js_set(js, iterator, "_rl_id", js_mknum((double)iface->id)); js_set(js, iterator, "_lines", js_mkarr(js)); js_set(js, iterator, "_done", js_false); @@ -1068,10 +1068,10 @@ static void free_interface(rl_interface_t *iface) { free(iface); } -static jsval_t rl_create_interface(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t rl_create_interface(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "createInterface requires options"); - jsval_t options = args[0]; + ant_value_t options = args[0]; if (!is_special_object(options)) return js_mkerr(js, "options must be an object"); rl_interface_t *iface = calloc(1, sizeof(rl_interface_t)); @@ -1100,42 +1100,42 @@ static jsval_t rl_create_interface(ant_t *js, jsval_t *args, int nargs) { iface->input_stream = js_get(js, options, "input"); iface->output_stream = js_get(js, options, "output"); - jsval_t terminal_val = js_get(js, options, "terminal"); + ant_value_t terminal_val = js_get(js, options, "terminal"); iface->terminal = terminal_val == js_true || vtype(terminal_val) == T_UNDEF; - jsval_t history_size_val = js_get(js, options, "historySize"); + ant_value_t history_size_val = js_get(js, options, "historySize"); iface->history_size = (vtype(history_size_val) == T_NUM) ? (int)js_getnum(history_size_val) : DEFAULT_HISTORY_SIZE; - jsval_t remove_dup_val = js_get(js, options, "removeHistoryDuplicates"); + ant_value_t remove_dup_val = js_get(js, options, "removeHistoryDuplicates"); iface->remove_history_duplicates = js_truthy(js, remove_dup_val); - jsval_t prompt_val = js_get(js, options, "prompt"); + ant_value_t prompt_val = js_get(js, options, "prompt"); if (vtype(prompt_val) == T_STR) { free(iface->prompt); iface->prompt = strdup(js_getstr(js, prompt_val, NULL)); } - jsval_t crlf_delay_val = js_get(js, options, "crlfDelay"); + ant_value_t crlf_delay_val = js_get(js, options, "crlfDelay"); iface->crlf_delay = (vtype(crlf_delay_val) == T_NUM) ? (int)js_getnum(crlf_delay_val) : 100; if (iface->crlf_delay < 100) iface->crlf_delay = 100; - jsval_t tab_size_val = js_get(js, options, "tabSize"); + ant_value_t tab_size_val = js_get(js, options, "tabSize"); iface->tab_size = (vtype(tab_size_val) == T_NUM) ? (int)js_getnum(tab_size_val) : DEFAULT_TAB_SIZE; if (iface->tab_size < 1) iface->tab_size = 1; - jsval_t completer_val = js_get(js, options, "completer"); + ant_value_t completer_val = js_get(js, options, "completer"); int ctype = vtype(completer_val); iface->completer = (ctype == T_FUNC || ctype == T_CFUNC) ? completer_val : js_mkundef(); - jsval_t history_val = js_get(js, options, "history"); + ant_value_t history_val = js_get(js, options, "history"); if (is_special_object(history_val)) { - jsval_t len_val = js_get(js, history_val, "length"); + ant_value_t len_val = js_get(js, history_val, "length"); int len = (vtype(len_val) == T_NUM) ? (int)js_getnum(len_val) : 0; rl_history_init(&iface->history, iface->history_size); @@ -1143,7 +1143,7 @@ static jsval_t rl_create_interface(ant_t *js, jsval_t *args, int nargs) { for (int i = 0; i < len; i++) { char key[16]; snprintf(key, sizeof(key), "%d", i); - jsval_t item = js_get(js, history_val, key); + ant_value_t item = js_get(js, history_val, key); if (vtype(item) == T_STR) { char *line = js_getstr(js, item, NULL); if (line) rl_history_add(&iface->history, line, false); @@ -1152,7 +1152,7 @@ static jsval_t rl_create_interface(ant_t *js, jsval_t *args, int nargs) { } else rl_history_init(&iface->history, iface->history_size); HASH_ADD(hh, interfaces, id, sizeof(uint64_t), iface); - jsval_t obj = js_mkobj(js); + ant_value_t obj = js_mkobj(js); js_set(js, obj, "_rl_id", js_mknum((double)iface->id)); js_set(js, obj, "on", js_mkfun(rl_interface_on)); @@ -1183,15 +1183,15 @@ static jsval_t rl_create_interface(ant_t *js, jsval_t *args, int nargs) { return obj; } -static jsval_t rl_create_interface_promises(ant_t *js, jsval_t *args, int nargs) { - jsval_t iface_obj = rl_create_interface(js, args, nargs); +static ant_value_t rl_create_interface_promises(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t iface_obj = rl_create_interface(js, args, nargs); if (vtype(iface_obj) == T_ERR) return iface_obj; js_set(js, iface_obj, "question", js_mkfun(rl_interface_question_promise)); return iface_obj; } -static jsval_t rl_clear_line(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t rl_clear_line(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_false; int dir = (int)js_getnum(args[1]); @@ -1209,7 +1209,7 @@ static jsval_t rl_clear_line(ant_t *js, jsval_t *args, int nargs) { return js_true; } -static jsval_t rl_clear_screen_down(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t rl_clear_screen_down(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; printf("\033[J"); @@ -1218,7 +1218,7 @@ static jsval_t rl_clear_screen_down(ant_t *js, jsval_t *args, int nargs) { return js_true; } -static jsval_t rl_cursor_to(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t rl_cursor_to(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_false; int x = (int)js_getnum(args[1]); @@ -1233,7 +1233,7 @@ static jsval_t rl_cursor_to(ant_t *js, jsval_t *args, int nargs) { return js_true; } -static jsval_t rl_move_cursor(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t rl_move_cursor(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 3) return js_false; int dx = (int)js_getnum(args[1]); @@ -1249,9 +1249,9 @@ static jsval_t rl_move_cursor(ant_t *js, jsval_t *args, int nargs) { return js_true; } -static jsval_t rl_emit_keypress_events(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t rl_emit_keypress_events(ant_t *js, ant_value_t *args, int nargs) { if (nargs > 0) { - jsval_t stdin_obj = js_get(js, js_get(js, js_glob(js), "process"), "stdin"); + ant_value_t stdin_obj = js_get(js, js_get(js, js_glob(js), "process"), "stdin"); if (stdin_obj != args[0]) { return js_mkerr(js, "emitKeypressEvents only supports process.stdin"); } @@ -1285,8 +1285,8 @@ void readline_gc_update_roots(GC_OP_VAL_ARGS) { } } -jsval_t readline_library(ant_t *js) { - jsval_t lib = js_mkobj(js); +ant_value_t readline_library(ant_t *js) { + ant_value_t lib = js_mkobj(js); js_set(js, lib, "createInterface", js_mkfun(rl_create_interface)); js_set(js, lib, "clearLine", js_mkfun(rl_clear_line)); @@ -1299,8 +1299,8 @@ jsval_t readline_library(ant_t *js) { return lib; } -jsval_t readline_promises_library(ant_t *js) { - jsval_t lib = js_mkobj(js); +ant_value_t readline_promises_library(ant_t *js) { + ant_value_t lib = js_mkobj(js); js_set(js, lib, "createInterface", js_mkfun(rl_create_interface_promises)); js_set(js, lib, "clearLine", js_mkfun(rl_clear_line)); diff --git a/src/modules/reflect.c b/src/modules/reflect.c index afed5fb..2563041 100644 --- a/src/modules/reflect.c +++ b/src/modules/reflect.c @@ -10,11 +10,11 @@ #include "modules/reflect.h" #include "modules/symbol.h" -static jsval_t reflect_get(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t reflect_get(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkundef(); - jsval_t target = args[0]; - jsval_t key = args[1]; + ant_value_t target = args[0]; + ant_value_t key = args[1]; int t = vtype(target); if (t != T_OBJ && t != T_FUNC) return js_mkundef(); @@ -27,12 +27,12 @@ static jsval_t reflect_get(ant_t *js, jsval_t *args, int nargs) { return js_get(js, target, key_str); } -static jsval_t reflect_set(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t reflect_set(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 3) return js_false; - jsval_t target = args[0]; - jsval_t key = args[1]; - jsval_t value = args[2]; + ant_value_t target = args[0]; + ant_value_t key = args[1]; + ant_value_t value = args[2]; int t = vtype(target); if (t != T_OBJ && t != T_FUNC) return js_false; @@ -46,11 +46,11 @@ static jsval_t reflect_set(ant_t *js, jsval_t *args, int nargs) { return js_true; } -static jsval_t reflect_has(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t reflect_has(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_false; - jsval_t target = args[0]; - jsval_t key = args[1]; + ant_value_t target = args[0]; + ant_value_t key = args[1]; int t = vtype(target); if (t != T_OBJ && t != T_FUNC) return js_false; @@ -61,15 +61,15 @@ static jsval_t reflect_has(ant_t *js, jsval_t *args, int nargs) { char *key_str = js_getstr(js, key, &key_len); if (!key_str) return js_false; - jsoff_t off = lkp_proto(js, target, key_str, key_len); + ant_offset_t off = lkp_proto(js, target, key_str, key_len); return js_bool(off > 0); } -static jsval_t reflect_delete_property(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t reflect_delete_property(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_false; - jsval_t target = args[0]; - jsval_t key = args[1]; + ant_value_t target = args[0]; + ant_value_t key = args[1]; int t = vtype(target); if (t != T_OBJ && t != T_FUNC) return js_false; @@ -83,19 +83,19 @@ static jsval_t reflect_delete_property(ant_t *js, jsval_t *args, int nargs) { return js_bool(deleted); } -static jsval_t reflect_own_keys(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t reflect_own_keys(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkarr(js); - jsval_t target = args[0]; + ant_value_t target = args[0]; int t = vtype(target); if (t != T_OBJ && t != T_FUNC) { return js_mkerr(js, "Reflect.ownKeys called on non-object"); } - jsval_t keys_arr = js_mkarr(js); + ant_value_t keys_arr = js_mkarr(js); ant_iter_t iter = js_prop_iter_begin(js, target); - const char *key; size_t key_len; jsval_t value; + const char *key; size_t key_len; ant_value_t value; while (js_prop_iter_next(&iter, &key, &key_len, &value)) { if (key_len >= 9 && memcmp(key, STR_PROTO, STR_PROTO_LEN) == 0) continue; @@ -107,14 +107,14 @@ static jsval_t reflect_own_keys(ant_t *js, jsval_t *args, int nargs) { return keys_arr; } -static jsval_t reflect_construct(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t reflect_construct(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) { return js_mkerr(js, "Reflect.construct requires at least 2 arguments"); } - jsval_t target = args[0]; - jsval_t args_arr = args[1]; - jsval_t new_target = (nargs >= 3) ? args[2] : target; + ant_value_t target = args[0]; + ant_value_t args_arr = args[1]; + ant_value_t new_target = (nargs >= 3) ? args[2] : target; if (vtype(target) != T_FUNC && vtype(target) != T_CFUNC) { return js_mkerr(js, "Reflect.construct: first argument must be a constructor"); @@ -124,15 +124,15 @@ static jsval_t reflect_construct(ant_t *js, jsval_t *args, int nargs) { return js_mkerr(js, "Reflect.construct: third argument must be a constructor"); } - jsval_t length_val = js_get(js, args_arr, "length"); + ant_value_t length_val = js_get(js, args_arr, "length"); int arg_count = 0; if (vtype(length_val) == T_NUM) { arg_count = (int)js_getnum(length_val); } - jsval_t *call_args = NULL; + ant_value_t *call_args = NULL; if (arg_count > 0) { - call_args = malloc(arg_count * sizeof(jsval_t)); + call_args = malloc(arg_count * sizeof(ant_value_t)); if (!call_args) return js_mkerr(js, "Out of memory"); for (int i = 0; i < arg_count; i++) { @@ -142,14 +142,14 @@ static jsval_t reflect_construct(ant_t *js, jsval_t *args, int nargs) { } } - jsval_t new_obj = js_mkobj(js); - jsval_t proto = js_get(js, new_target, "prototype"); + ant_value_t new_obj = js_mkobj(js); + ant_value_t proto = js_get(js, new_target, "prototype"); if (vtype(proto) == T_OBJ) js_set_proto(js, new_obj, proto); - jsval_t saved_new_target = js->new_target; + ant_value_t saved_new_target = js->new_target; js->new_target = new_target; - jsval_t result = sv_vm_call(js->vm, js, target, new_obj, call_args, arg_count, NULL, true); + ant_value_t result = sv_vm_call(js->vm, js, target, new_obj, call_args, arg_count, NULL, true); js->new_target = saved_new_target; if (call_args) free(call_args); @@ -158,28 +158,28 @@ static jsval_t reflect_construct(ant_t *js, jsval_t *args, int nargs) { return new_obj; } -static jsval_t reflect_apply(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t reflect_apply(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 3) { return js_mkerr(js, "Reflect.apply requires 3 arguments"); } - jsval_t target = args[0]; - jsval_t this_arg = args[1]; - jsval_t args_arr = args[2]; + ant_value_t target = args[0]; + ant_value_t this_arg = args[1]; + ant_value_t args_arr = args[2]; if (vtype(target) != T_FUNC && vtype(target) != T_CFUNC) { return js_mkerr(js, "Reflect.apply: first argument must be a function"); } - jsval_t length_val = js_get(js, args_arr, "length"); + ant_value_t length_val = js_get(js, args_arr, "length"); int arg_count = 0; if (vtype(length_val) == T_NUM) { arg_count = (int)js_getnum(length_val); } - jsval_t *call_args = NULL; + ant_value_t *call_args = NULL; if (arg_count > 0) { - call_args = malloc(arg_count * sizeof(jsval_t)); + call_args = malloc(arg_count * sizeof(ant_value_t)); if (!call_args) return js_mkerr(js, "Out of memory"); for (int i = 0; i < arg_count; i++) { @@ -189,17 +189,17 @@ static jsval_t reflect_apply(ant_t *js, jsval_t *args, int nargs) { } } - jsval_t result = sv_vm_call(js->vm, js, target, this_arg, call_args, arg_count, NULL, false); + ant_value_t result = sv_vm_call(js->vm, js, target, this_arg, call_args, arg_count, NULL, false); if (call_args) free(call_args); return result; } -static jsval_t reflect_get_own_property_descriptor(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t reflect_get_own_property_descriptor(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkundef(); - jsval_t target = args[0]; - jsval_t key = args[1]; + ant_value_t target = args[0]; + ant_value_t key = args[1]; int t = vtype(target); if (t != T_OBJ && t != T_FUNC) return js_mkundef(); @@ -210,11 +210,11 @@ static jsval_t reflect_get_own_property_descriptor(ant_t *js, jsval_t *args, int char *key_str = js_getstr(js, key, &key_len); if (!key_str) return js_mkundef(); - jsoff_t off = lkp(js, target, key_str, key_len); + ant_offset_t off = lkp(js, target, key_str, key_len); if (off <= 0) return js_mkundef(); - jsval_t value = js_get(js, target, key_str); - jsval_t desc = js_mkobj(js); + ant_value_t value = js_get(js, target, key_str); + ant_value_t desc = js_mkobj(js); js_set(js, desc, "value", value); js_set(js, desc, "writable", js_true); js_set(js, desc, "enumerable", js_true); @@ -223,12 +223,12 @@ static jsval_t reflect_get_own_property_descriptor(ant_t *js, jsval_t *args, int return desc; } -static jsval_t reflect_define_property(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t reflect_define_property(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 3) return js_false; - jsval_t target = args[0]; - jsval_t key = args[1]; - jsval_t descriptor = args[2]; + ant_value_t target = args[0]; + ant_value_t key = args[1]; + ant_value_t descriptor = args[2]; int t = vtype(target); if (t != T_OBJ && t != T_FUNC) return js_false; @@ -239,18 +239,18 @@ static jsval_t reflect_define_property(ant_t *js, jsval_t *args, int nargs) { char *key_str = js_getstr(js, key, NULL); if (!key_str) return js_false; - jsval_t value = js_get(js, descriptor, "value"); + ant_value_t value = js_get(js, descriptor, "value"); js_set(js, target, key_str, value); return js_true; } -static jsval_t reflect_get_prototype_of(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t reflect_get_prototype_of(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) { return js_mkerr(js, "Reflect.getPrototypeOf requires an argument"); } - jsval_t target = args[0]; + ant_value_t target = args[0]; if (!is_object_type(target)) { return js_mkerr(js, "Reflect.getPrototypeOf: argument must be an object"); @@ -259,11 +259,11 @@ static jsval_t reflect_get_prototype_of(ant_t *js, jsval_t *args, int nargs) { return js_get_proto(js, target); } -static jsval_t reflect_set_prototype_of(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t reflect_set_prototype_of(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_false; - jsval_t target = args[0]; - jsval_t proto = args[1]; + ant_value_t target = args[0]; + ant_value_t proto = args[1]; int t = vtype(target); if (t != T_OBJ && t != T_FUNC) return js_false; @@ -275,10 +275,10 @@ static jsval_t reflect_set_prototype_of(ant_t *js, jsval_t *args, int nargs) { return js_true; } -static jsval_t reflect_is_extensible(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t reflect_is_extensible(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_false; - jsval_t target = args[0]; + ant_value_t target = args[0]; int t = vtype(target); if (t != T_OBJ && t != T_FUNC) return js_false; @@ -290,10 +290,10 @@ static jsval_t reflect_is_extensible(ant_t *js, jsval_t *args, int nargs) { return js_true; } -static jsval_t reflect_prevent_extensions(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t reflect_prevent_extensions(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_false; - jsval_t target = args[0]; + ant_value_t target = args[0]; int t = vtype(target); if (t != T_OBJ && t != T_FUNC) return js_false; @@ -304,7 +304,7 @@ static jsval_t reflect_prevent_extensions(ant_t *js, jsval_t *args, int nargs) { void init_reflect_module(void) { ant_t *js = rt->js; - jsval_t reflect_obj = js_mkobj(js); + ant_value_t reflect_obj = js_mkobj(js); js_set(js, reflect_obj, "get", js_mkfun(reflect_get)); js_set(js, reflect_obj, "set", js_mkfun(reflect_set)); diff --git a/src/modules/regex.c b/src/modules/regex.c index aa32fe9..da4027d 100644 --- a/src/modules/regex.c +++ b/src/modules/regex.c @@ -20,7 +20,7 @@ #include typedef struct { - jsoff_t obj_offset; + ant_offset_t obj_offset; pcre2_code *code; pcre2_match_data *match_data; } regex_cache_entry_t; @@ -30,19 +30,19 @@ static size_t regex_cache_count = 0; static size_t regex_cache_cap = 0; static void update_regexp_statics(ant_t *js, const char *str_ptr, PCRE2_SIZE *ovector, uint32_t ovcount) { - jsval_t regexp_ctor = js_get(js, js_glob(js), "RegExp"); + ant_value_t regexp_ctor = js_get(js, js_glob(js), "RegExp"); if (is_err(regexp_ctor) || vtype(regexp_ctor) == T_UNDEF) return; - jsval_t empty = js_mkstr(js, "", 0); + ant_value_t empty = js_mkstr(js, "", 0); for (int i = 1; i <= 9; i++) { char key[3] = {'$', (char)('0' + i), '\0'}; - jsval_t val = empty; + ant_value_t val = empty; if ((uint32_t)i < ovcount && ovector[2*i] != PCRE2_UNSET) val = js_mkstr(js, str_ptr + ovector[2*i], ovector[2*i+1] - ovector[2*i]); js_set(js, regexp_ctor, key, val); } - jsval_t match0 = empty; + ant_value_t match0 = empty; if (ovcount > 0 && ovector[0] != PCRE2_UNSET) match0 = js_mkstr(js, str_ptr + ovector[0], ovector[1] - ovector[0]); js_set(js, regexp_ctor, "lastMatch", match0); @@ -316,9 +316,9 @@ size_t js_to_pcre2_pattern(const char *src, size_t src_len, char *dst, size_t ds ((is_new) ? js_mkprop_fast(js, obj, key, klen, val) \ : js_setprop(js, obj, js_mkstr(js, key, klen), val)) -static void regexp_init_flags(ant_t *js, jsval_t obj, const char *fstr, jsoff_t flen, bool is_new) { +static void regexp_init_flags(ant_t *js, ant_value_t obj, const char *fstr, ant_offset_t flen, bool is_new) { bool g = false, i = false, m = false, s = false, u = false, y = false; - for (jsoff_t k = 0; k < flen; k++) { + for (ant_offset_t k = 0; k < flen; k++) { if (fstr[k] == 'g') g = true; if (fstr[k] == 'i') i = true; if (fstr[k] == 'm') m = true; @@ -345,48 +345,48 @@ static void regexp_init_flags(ant_t *js, jsval_t obj, const char *fstr, jsoff_t REGEXP_SET_PROP(js, obj, "lastIndex", 9, tov(0), is_new); } -jsval_t is_regexp_like(ant_t *js, jsval_t value) { +ant_value_t is_regexp_like(ant_t *js, ant_value_t value) { if (!is_object_type(value)) return js_false; - jsval_t match_sym = get_match_sym(); + ant_value_t match_sym = get_match_sym(); if (vtype(match_sym) == T_SYMBOL) { - jsval_t match_val = js_get_sym(js, value, match_sym); + ant_value_t match_val = js_get_sym(js, value, match_sym); if (is_err(match_val)) return match_val; if (vtype(match_val) != T_UNDEF) return js_bool(js_truthy(js, match_val)); } - jsval_t regexp_ctor = js_get(js, js_glob(js), "RegExp"); + ant_value_t regexp_ctor = js_get(js, js_glob(js), "RegExp"); if (is_err(regexp_ctor)) return regexp_ctor; - jsval_t regexp_proto = js_get(js, regexp_ctor, "prototype"); + ant_value_t regexp_proto = js_get(js, regexp_ctor, "prototype"); if (is_err(regexp_proto)) return regexp_proto; if (!is_object_type(regexp_proto)) return js_false; return js_bool(proto_chain_contains(js, value, regexp_proto)); } -static jsval_t should_regexp_passthrough(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t should_regexp_passthrough(ant_t *js, ant_value_t *args, int nargs) { if (vtype(js->new_target) != T_UNDEF) return js_false; if (nargs <= 0) return js_false; if (nargs >= 2 && vtype(args[1]) != T_UNDEF) return js_false; if (!is_object_type(args[0])) return js_false; - jsval_t is_re = is_regexp_like(js, args[0]); + ant_value_t is_re = is_regexp_like(js, args[0]); if (is_err(is_re)) return is_re; if (!js_truthy(js, is_re)) return js_false; - jsval_t ctor = js_getprop_fallback(js, args[0], "constructor"); + ant_value_t ctor = js_getprop_fallback(js, args[0], "constructor"); if (is_err(ctor)) return ctor; - jsval_t regexp_ctor = js_get(js, js_glob(js), "RegExp"); + ant_value_t regexp_ctor = js_get(js, js_glob(js), "RegExp"); if (is_err(regexp_ctor)) return regexp_ctor; return js_bool(same_ctor_identity(js, ctor, regexp_ctor)); } -jsval_t reject_regexp_arg(ant_t *js, jsval_t value, const char *method_name) { - jsval_t is_re = is_regexp_like(js, value); +ant_value_t reject_regexp_arg(ant_t *js, ant_value_t value, const char *method_name) { + ant_value_t is_re = is_regexp_like(js, value); if (is_err(is_re)) return is_re; if (js_truthy(js, is_re)) { return js_mkerr_typed(js, JS_ERR_TYPE, "First argument to %s must not be a RegExp", method_name); @@ -394,17 +394,17 @@ jsval_t reject_regexp_arg(ant_t *js, jsval_t value, const char *method_name) { return js_mkundef(); } -static jsval_t regexp_species_construct(ant_t *js, jsval_t rx, jsval_t ctor, jsval_t *ctor_args, int nargs) { - jsval_t seed = js_mkobj(js); +static ant_value_t regexp_species_construct(ant_t *js, ant_value_t rx, ant_value_t ctor, ant_value_t *ctor_args, int nargs) { + ant_value_t seed = js_mkobj(js); if (is_err(seed)) return seed; - jsval_t proto = js_get(js, ctor, "prototype"); + ant_value_t proto = js_get(js, ctor, "prototype"); if (is_err(proto)) return proto; if (is_object_type(proto)) js_set_proto(js, seed, proto); - jsval_t saved = js->new_target; + ant_value_t saved = js->new_target; js->new_target = ctor; - jsval_t result = sv_vm_call(js->vm, js, ctor, seed, ctor_args, nargs, NULL, true); + ant_value_t result = sv_vm_call(js->vm, js, ctor, seed, ctor_args, nargs, NULL, true); js->new_target = saved; if (is_err(result)) return result; @@ -414,17 +414,17 @@ static jsval_t regexp_species_construct(ant_t *js, jsval_t rx, jsval_t ctor, jsv return result; } -static jsval_t regexp_exec_abstract(ant_t *js, jsval_t rx, jsval_t str); -static jsval_t builtin_regexp_exec(ant_t *js, jsval_t *args, int nargs); +static ant_value_t regexp_exec_abstract(ant_t *js, ant_value_t rx, ant_value_t str); +static ant_value_t builtin_regexp_exec(ant_t *js, ant_value_t *args, int nargs); -static regex_cache_entry_t *regex_cache_lookup(jsoff_t obj_offset) { +static regex_cache_entry_t *regex_cache_lookup(ant_offset_t obj_offset) { for (size_t i = 0; i < regex_cache_count; i++) { if (regex_cache[i].obj_offset == obj_offset) return ®ex_cache[i]; } return NULL; } -static regex_cache_entry_t *regex_cache_insert(jsoff_t obj_offset, pcre2_code *code, pcre2_match_data *match_data) { +static regex_cache_entry_t *regex_cache_insert(ant_offset_t obj_offset, pcre2_code *code, pcre2_match_data *match_data) { if (regex_cache_count >= regex_cache_cap) { size_t new_cap = regex_cache_cap ? regex_cache_cap * 2 : 64; regex_cache_entry_t *new_cache = realloc(regex_cache, new_cap * sizeof(regex_cache_entry_t)); @@ -444,8 +444,8 @@ typedef struct { pcre2_match_data *match_data; } compiled_regex_t; -static bool regex_get_or_compile(ant_t *js, jsval_t regexp_obj, compiled_regex_t *out) { - jsoff_t obj_off = (jsoff_t)vdata(regexp_obj); +static bool regex_get_or_compile(ant_t *js, ant_value_t regexp_obj, compiled_regex_t *out) { + ant_offset_t obj_off = (ant_offset_t)vdata(regexp_obj); regex_cache_entry_t *cached = regex_cache_lookup(obj_off); if (cached) { @@ -454,22 +454,22 @@ static bool regex_get_or_compile(ant_t *js, jsval_t regexp_obj, compiled_regex_t return true; } - jsoff_t source_off = lkp(js, regexp_obj, "source", 6); + ant_offset_t source_off = lkp(js, regexp_obj, "source", 6); if (source_off == 0) return false; - jsval_t source_val = resolveprop(js, mkval(T_PROP, source_off)); + ant_value_t source_val = resolveprop(js, mkval(T_PROP, source_off)); if (vtype(source_val) != T_STR) return false; - jsoff_t plen, poff = vstr(js, source_val, &plen); + ant_offset_t plen, poff = vstr(js, source_val, &plen); const char *pattern_ptr = (char *)&js->mem[poff]; bool ignore_case = false, multiline = false, dotall = false, sticky = false, unicode = false; - jsoff_t flags_off = lkp(js, regexp_obj, "flags", 5); + ant_offset_t flags_off = lkp(js, regexp_obj, "flags", 5); if (flags_off != 0) { - jsval_t flags_val = resolveprop(js, mkval(T_PROP, flags_off)); + ant_value_t flags_val = resolveprop(js, mkval(T_PROP, flags_off)); if (vtype(flags_val) == T_STR) { - jsoff_t flen, foff = vstr(js, flags_val, &flen); + ant_offset_t flen, foff = vstr(js, flags_val, &flen); const char *flags_str = (char *)&js->mem[foff]; - for (jsoff_t i = 0; i < flen; i++) { + for (ant_offset_t i = 0; i < flen; i++) { if (flags_str[i] == 'i') ignore_case = true; if (flags_str[i] == 'm') multiline = true; if (flags_str[i] == 's') dotall = true; @@ -502,25 +502,25 @@ static bool regex_get_or_compile(ant_t *js, jsval_t regexp_obj, compiled_regex_t return true; } -static jsval_t builtin_RegExp(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_RegExp(ant_t *js, ant_value_t *args, int nargs) { bool pattern_is_regexp = false; if (nargs > 0) { - jsval_t is_re = is_regexp_like(js, args[0]); + ant_value_t is_re = is_regexp_like(js, args[0]); if (is_err(is_re)) return is_re; pattern_is_regexp = js_truthy(js, is_re); } if (vtype(js->new_target) == T_UNDEF && nargs > 0 && pattern_is_regexp) { if (nargs < 2 || vtype(args[1]) == T_UNDEF) { - jsval_t ctor = js_getprop_fallback(js, args[0], "constructor"); + ant_value_t ctor = js_getprop_fallback(js, args[0], "constructor"); if (is_err(ctor)) return ctor; - jsval_t regexp_ctor = js_get(js, js_glob(js), "RegExp"); + ant_value_t regexp_ctor = js_get(js, js_glob(js), "RegExp"); if (is_err(regexp_ctor)) return regexp_ctor; if (same_ctor_identity(js, ctor, regexp_ctor)) return args[0]; } } - jsval_t regexp_obj = js->this_val; + ant_value_t regexp_obj = js->this_val; bool use_this = (vtype(js->new_target) != T_UNDEF && vtype(regexp_obj) == T_OBJ); if (!use_this) { @@ -528,26 +528,26 @@ static jsval_t builtin_RegExp(ant_t *js, jsval_t *args, int nargs) { if (is_err(regexp_obj)) return regexp_obj; } - jsval_t regexp_proto = js_get_ctor_proto(js, "RegExp", 6); - jsval_t instance_proto = js_instance_proto_from_new_target(js, regexp_proto); + ant_value_t regexp_proto = js_get_ctor_proto(js, "RegExp", 6); + ant_value_t instance_proto = js_instance_proto_from_new_target(js, regexp_proto); if (is_object_type(instance_proto)) js_set_proto(js, regexp_obj, instance_proto); if (vtype(js->new_target) == T_FUNC || vtype(js->new_target) == T_CFUNC) { js_set_slot(js, regexp_obj, SLOT_CTOR, js->new_target); } - jsval_t pattern = js_mkstr(js, "", 0); - jsval_t flags = js_mkstr(js, "", 0); + ant_value_t pattern = js_mkstr(js, "", 0); + ant_value_t flags = js_mkstr(js, "", 0); if (nargs > 0) { if (pattern_is_regexp) { - jsval_t src = js_getprop_fallback(js, args[0], "source"); + ant_value_t src = js_getprop_fallback(js, args[0], "source"); if (is_err(src)) return src; pattern = js_tostring_val(js, src); if (is_err(pattern)) return pattern; if (nargs >= 2 && vtype(args[1]) != T_UNDEF) { flags = js_tostring_val(js, args[1]); } else { - jsval_t fl = js_getprop_fallback(js, args[0], "flags"); + ant_value_t fl = js_getprop_fallback(js, args[0], "flags"); if (is_err(fl)) return fl; flags = js_tostring_val(js, fl); } @@ -556,7 +556,7 @@ static jsval_t builtin_RegExp(ant_t *js, jsval_t *args, int nargs) { pattern = args[0]; if (nargs > 1 && vtype(args[1]) == T_STR) flags = args[1]; } else if (vtype(args[0]) != T_UNDEF) { - jsval_t s = js_tostring_val(js, args[0]); + ant_value_t s = js_tostring_val(js, args[0]); if (is_err(s)) return s; pattern = s; if (nargs > 1 && vtype(args[1]) == T_STR) flags = args[1]; @@ -564,31 +564,31 @@ static jsval_t builtin_RegExp(ant_t *js, jsval_t *args, int nargs) { } js_mkprop_fast(js, regexp_obj, "source", 6, pattern); - jsoff_t flags_len, flags_off = vstr(js, flags, &flags_len); + ant_offset_t flags_len, flags_off = vstr(js, flags, &flags_len); regexp_init_flags(js, regexp_obj, (const char *)&js->mem[flags_off], flags_len, true); return regexp_obj; } -static jsval_t builtin_regexp_exec(ant_t *js, jsval_t *args, int nargs) { - jsval_t regexp = js->this_val; +static ant_value_t builtin_regexp_exec(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t regexp = js->this_val; if (vtype(regexp) != T_OBJ) return js_mkerr(js, "exec called on non-regexp"); if (nargs < 1) return js_mknull(); - jsval_t str_arg = args[0]; + ant_value_t str_arg = args[0]; if (vtype(str_arg) != T_STR) return js_mknull(); - jsoff_t str_len, str_off = vstr(js, str_arg, &str_len); + ant_offset_t str_len, str_off = vstr(js, str_arg, &str_len); const char *str_ptr = (char *)&js->mem[str_off]; bool global_flag = false, sticky_flag = false; - jsoff_t flags_off = lkp(js, regexp, "flags", 5); + ant_offset_t flags_off = lkp(js, regexp, "flags", 5); if (flags_off != 0) { - jsval_t flags_val = resolveprop(js, mkval(T_PROP, flags_off)); + ant_value_t flags_val = resolveprop(js, mkval(T_PROP, flags_off)); if (vtype(flags_val) == T_STR) { - jsoff_t flen, foff = vstr(js, flags_val, &flen); + ant_offset_t flen, foff = vstr(js, flags_val, &flen); const char *flags_str = (char *)&js->mem[foff]; - for (jsoff_t i = 0; i < flen; i++) { + for (ant_offset_t i = 0; i < flen; i++) { if (flags_str[i] == 'g') global_flag = true; if (flags_str[i] == 'y') sticky_flag = true; } @@ -597,9 +597,9 @@ static jsval_t builtin_regexp_exec(ant_t *js, jsval_t *args, int nargs) { PCRE2_SIZE start_offset = 0; if (global_flag || sticky_flag) { - jsoff_t lastindex_off = lkp(js, regexp, "lastIndex", 9); + ant_offset_t lastindex_off = lkp(js, regexp, "lastIndex", 9); if (lastindex_off != 0) { - jsval_t li_val = resolveprop(js, mkval(T_PROP, lastindex_off)); + ant_value_t li_val = resolveprop(js, mkval(T_PROP, lastindex_off)); if (vtype(li_val) == T_NUM) { double li = tod(li_val); if (li >= 0 && li <= (double)str_len) start_offset = (PCRE2_SIZE)li; @@ -629,14 +629,14 @@ static jsval_t builtin_regexp_exec(ant_t *js, jsval_t *args, int nargs) { PCRE2_SIZE *ovector = pcre2_get_ovector_pointer(compiled.match_data); uint32_t ovcount = pcre2_get_ovector_count(compiled.match_data); - jsval_t result_arr = js_mkarr(js); + ant_value_t result_arr = js_mkarr(js); for (uint32_t i = 0; i < ovcount && i < 32; i++) { PCRE2_SIZE start = ovector[2*i]; PCRE2_SIZE end = ovector[2*i+1]; if (start == PCRE2_UNSET) { js_arr_push(js, result_arr, js_mkundef()); } else { - jsval_t match_str = js_mkstr(js, str_ptr + start, end - start); + ant_value_t match_str = js_mkstr(js, str_ptr + start, end - start); js_arr_push(js, result_arr, match_str); } } @@ -652,14 +652,14 @@ static jsval_t builtin_regexp_exec(ant_t *js, jsval_t *args, int nargs) { pcre2_pattern_info(compiled.code, PCRE2_INFO_NAMEENTRYSIZE, &nameentrysize); pcre2_pattern_info(compiled.code, PCRE2_INFO_NAMETABLE, (void *)&nametable); - jsval_t groups = js_mkobj(js); + ant_value_t groups = js_mkobj(js); js_set_proto(js, groups, js_mknull()); PCRE2_SPTR tabptr = nametable; for (uint32_t i = 0; i < namecount; i++) { int n = (tabptr[0] << 8) | tabptr[1]; const char *name = (const char *)(tabptr + 2); - jsval_t val = ((uint32_t)n < ovcount) ? js_arr_get(js, result_arr, n) : js_mkundef(); + ant_value_t val = ((uint32_t)n < ovcount) ? js_arr_get(js, result_arr, n) : js_mkundef(); js_setprop(js, groups, js_mkstr(js, name, strlen(name)), val); tabptr += nameentrysize; } @@ -677,24 +677,24 @@ static jsval_t builtin_regexp_exec(ant_t *js, jsval_t *args, int nargs) { return result_arr; } -static jsval_t builtin_regexp_toString(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_regexp_toString(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t regexp = js->this_val; + ant_value_t regexp = js->this_val; if (!is_object_type(regexp)) return js_mkerr_typed(js, JS_ERR_TYPE, "toString called on non-object"); - jsval_t source_val = js_getprop_fallback(js, regexp, "source"); + ant_value_t source_val = js_getprop_fallback(js, regexp, "source"); if (is_err(source_val)) return source_val; - jsval_t source_str = js_tostring_val(js, source_val); + ant_value_t source_str = js_tostring_val(js, source_val); if (is_err(source_str)) return source_str; - jsval_t flags_val = js_getprop_fallback(js, regexp, "flags"); + ant_value_t flags_val = js_getprop_fallback(js, regexp, "flags"); if (is_err(flags_val)) return flags_val; - jsval_t flags_str = js_tostring_val(js, flags_val); + ant_value_t flags_str = js_tostring_val(js, flags_val); if (is_err(flags_str)) return flags_str; - jsoff_t src_len, src_off = vstr(js, source_str, &src_len); - jsoff_t fl_len, fl_off = vstr(js, flags_str, &fl_len); + ant_offset_t src_len, src_off = vstr(js, source_str, &src_len); + ant_offset_t fl_len, fl_off = vstr(js, flags_str, &fl_len); size_t total = 1 + src_len + 1 + fl_len; char *buf = ant_calloc(total + 1); @@ -705,28 +705,28 @@ static jsval_t builtin_regexp_toString(ant_t *js, jsval_t *args, int nargs) { buf[n++] = '/'; memcpy(buf + n, &js->mem[fl_off], fl_len); n += fl_len; - jsval_t result = js_mkstr(js, buf, n); + ant_value_t result = js_mkstr(js, buf, n); free(buf); return result; } -static jsval_t builtin_regexp_compile(ant_t *js, jsval_t *args, int nargs) { - jsval_t rx = js->this_val; +static ant_value_t builtin_regexp_compile(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t rx = js->this_val; if (!is_object_type(rx)) return js_mkerr_typed(js, JS_ERR_TYPE, "compile called on non-object"); - jsval_t pattern = js_mkstr(js, "", 0); - jsval_t flags = js_mkstr(js, "", 0); + ant_value_t pattern = js_mkstr(js, "", 0); + ant_value_t flags = js_mkstr(js, "", 0); if (nargs > 0 && vtype(args[0]) != T_UNDEF) { - jsval_t is_re = is_regexp_like(js, args[0]); + ant_value_t is_re = is_regexp_like(js, args[0]); if (is_err(is_re)) return is_re; if (js_truthy(js, is_re)) { - jsval_t src = js_getprop_fallback(js, args[0], "source"); + ant_value_t src = js_getprop_fallback(js, args[0], "source"); if (is_err(src)) return src; pattern = js_tostring_val(js, src); if (is_err(pattern)) return pattern; - jsval_t fl = js_getprop_fallback(js, args[0], "flags"); + ant_value_t fl = js_getprop_fallback(js, args[0], "flags"); if (is_err(fl)) return fl; flags = js_tostring_val(js, fl); if (is_err(flags)) return flags; @@ -741,10 +741,10 @@ static jsval_t builtin_regexp_compile(ant_t *js, jsval_t *args, int nargs) { } js_setprop(js, rx, js_mkstr(js, "source", 6), pattern); - jsoff_t flen, foff = vstr(js, flags, &flen); + ant_offset_t flen, foff = vstr(js, flags, &flen); regexp_init_flags(js, rx, (const char *)&js->mem[foff], flen, false); - jsoff_t obj_off = (jsoff_t)vdata(rx); + ant_offset_t obj_off = (ant_offset_t)vdata(rx); for (size_t i = 0; i < regex_cache_count; i++) { if (regex_cache[i].obj_offset == obj_off) { pcre2_match_data_free(regex_cache[i].match_data); @@ -771,11 +771,11 @@ static inline bool is_other_punctuator(char c) { c == '#' || c == '%' || c == '&' || c == '\'' || c == '`' || c == '~'; } -static jsval_t builtin_regexp_escape(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_regexp_escape(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || vtype(args[0]) != T_STR) return js_mkerr_typed(js, JS_ERR_TYPE, "RegExp.escape requires a string argument"); - jsoff_t slen, soff = vstr(js, args[0], &slen); + ant_offset_t slen, soff = vstr(js, args[0], &slen); const char *src = (const char *)&js->mem[soff]; size_t buf_cap = slen * 6 + 1; @@ -822,47 +822,47 @@ static jsval_t builtin_regexp_escape(ant_t *js, jsval_t *args, int nargs) { si++; first = false; } - jsval_t result = js_mkstr(js, buf, di); + ant_value_t result = js_mkstr(js, buf, di); free(buf); return result; } -static jsval_t regexp_exec_abstract(ant_t *js, jsval_t rx, jsval_t str) { - jsval_t exec_fn = js_get(js, rx, "exec"); +static ant_value_t regexp_exec_abstract(ant_t *js, ant_value_t rx, ant_value_t str) { + ant_value_t exec_fn = js_get(js, rx, "exec"); if (is_err(exec_fn)) return exec_fn; if (vtype(exec_fn) == T_FUNC || vtype(exec_fn) == T_CFUNC) { - jsval_t call_args[1] = { str }; - jsval_t result = sv_vm_call(js->vm, js, exec_fn, rx, call_args, 1, NULL, false); + ant_value_t call_args[1] = { str }; + ant_value_t result = sv_vm_call(js->vm, js, exec_fn, rx, call_args, 1, NULL, false); if (is_err(result)) return result; if (!is_object_type(result) && vtype(result) != T_NULL) return js_mkerr_typed(js, JS_ERR_TYPE, "RegExp exec returned non-object"); return result; } - jsval_t call_args[1] = { str }; - jsval_t saved = js->this_val; + ant_value_t call_args[1] = { str }; + ant_value_t saved = js->this_val; js->this_val = rx; - jsval_t result = builtin_regexp_exec(js, call_args, 1); + ant_value_t result = builtin_regexp_exec(js, call_args, 1); js->this_val = saved; return result; } -static jsval_t builtin_regexp_test(ant_t *js, jsval_t *args, int nargs) { - jsval_t regexp = js->this_val; +static ant_value_t builtin_regexp_test(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t regexp = js->this_val; if (!is_object_type(regexp)) return js_mkerr_typed(js, JS_ERR_TYPE, "test called on non-object"); - jsval_t str_arg = nargs > 0 ? js_tostring_val(js, args[0]) : js_mkstr(js, "undefined", 9); + ant_value_t str_arg = nargs > 0 ? js_tostring_val(js, args[0]) : js_mkstr(js, "undefined", 9); if (is_err(str_arg)) return str_arg; - jsval_t result = regexp_exec_abstract(js, regexp, str_arg); + ant_value_t result = regexp_exec_abstract(js, regexp, str_arg); if (is_err(result)) return result; return mkval(T_BOOL, vtype(result) != T_NULL ? 1 : 0); } -jsval_t builtin_regexp_flags_getter(ant_t *js, jsval_t *args, int nargs) { +ant_value_t builtin_regexp_flags_getter(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t rx = js->this_val; + ant_value_t rx = js->this_val; if (!is_object_type(rx)) return js_mkerr_typed(js, JS_ERR_TYPE, "RegExp.prototype.flags called on non-object"); @@ -876,7 +876,7 @@ jsval_t builtin_regexp_flags_getter(ant_t *js, jsval_t *args, int nargs) { }; for (int i = 0; i < 8; i++) { - jsval_t v = js_getprop_fallback(js, rx, flag_props[i].name); + ant_value_t v = js_getprop_fallback(js, rx, flag_props[i].name); if (is_err(v)) return v; if (js_truthy(js, v)) buf[n++] = flag_props[i].flag; } @@ -884,116 +884,116 @@ jsval_t builtin_regexp_flags_getter(ant_t *js, jsval_t *args, int nargs) { return js_mkstr(js, buf, n); } -jsval_t builtin_regexp_symbol_match(ant_t *js, jsval_t *args, int nargs) { - jsval_t rx = js->this_val; +ant_value_t builtin_regexp_symbol_match(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t rx = js->this_val; if (!is_object_type(rx)) return js_mkerr_typed(js, JS_ERR_TYPE, "RegExp.prototype[@@match] called on non-object"); - jsval_t str = nargs > 0 ? js_tostring_val(js, args[0]) : js_mkstr(js, "undefined", 9); + ant_value_t str = nargs > 0 ? js_tostring_val(js, args[0]) : js_mkstr(js, "undefined", 9); if (is_err(str)) return str; - jsval_t global_val = js_getprop_fallback(js, rx, "global"); + ant_value_t global_val = js_getprop_fallback(js, rx, "global"); if (is_err(global_val)) return global_val; if (!js_truthy(js, global_val)) return regexp_exec_abstract(js, rx, str); - jsval_t unicode_val = js_getprop_fallback(js, rx, "unicode"); + ant_value_t unicode_val = js_getprop_fallback(js, rx, "unicode"); if (is_err(unicode_val)) return unicode_val; bool full_unicode = js_truthy(js, unicode_val); js_setprop(js, rx, js_mkstr(js, "lastIndex", 9), tov(0)); - jsval_t A = mkarr(js); + ant_value_t A = mkarr(js); if (is_err(A)) return A; - jsoff_t n = 0; + ant_offset_t n = 0; for (;;) { - jsval_t result = regexp_exec_abstract(js, rx, str); + ant_value_t result = regexp_exec_abstract(js, rx, str); if (is_err(result)) return result; if (vtype(result) == T_NULL) return n == 0 ? js_mknull() : mkval(T_ARR, vdata(A)); - jsval_t match_str = js_tostring_val(js, js_arr_get(js, result, 0)); + ant_value_t match_str = js_tostring_val(js, js_arr_get(js, result, 0)); if (is_err(match_str)) return match_str; js_arr_push(js, A, match_str); n++; - jsoff_t mlen; + ant_offset_t mlen; vstr(js, match_str, &mlen); if (mlen == 0) { - jsval_t li_val = js_getprop_fallback(js, rx, "lastIndex"); + ant_value_t li_val = js_getprop_fallback(js, rx, "lastIndex"); if (is_err(li_val)) return li_val; double li = vtype(li_val) == T_NUM ? tod(li_val) : 0; - jsoff_t str_len, str_off = vstr(js, str, &str_len); + ant_offset_t str_len, str_off = vstr(js, str, &str_len); double advance = 1; if (full_unicode && li < (double)str_len) { - advance = (double)utf8_char_len_at((const char *)&js->mem[str_off], str_len, (jsoff_t)li); + advance = (double)utf8_char_len_at((const char *)&js->mem[str_off], str_len, (ant_offset_t)li); } js_setprop(js, rx, js_mkstr(js, "lastIndex", 9), tov(li + advance)); } } } -jsval_t builtin_regexp_symbol_replace(ant_t *js, jsval_t *args, int nargs) { - jsval_t rx = js->this_val; +ant_value_t builtin_regexp_symbol_replace(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t rx = js->this_val; if (!is_object_type(rx)) return js_mkerr_typed(js, JS_ERR_TYPE, "RegExp.prototype[@@replace] called on non-object"); - jsval_t str = nargs > 0 ? js_tostring_val(js, args[0]) : js_mkstr(js, "undefined", 9); + ant_value_t str = nargs > 0 ? js_tostring_val(js, args[0]) : js_mkstr(js, "undefined", 9); if (is_err(str)) return str; - jsval_t replace_value = nargs > 1 ? args[1] : js_mkundef(); + ant_value_t replace_value = nargs > 1 ? args[1] : js_mkundef(); bool func_replace = (vtype(replace_value) == T_FUNC || vtype(replace_value) == T_CFUNC); - jsval_t replace_str = js_mkundef(); + ant_value_t replace_str = js_mkundef(); if (!func_replace) { replace_str = js_tostring_val(js, replace_value); if (is_err(replace_str)) return replace_str; } - jsval_t global_val = js_getprop_fallback(js, rx, "global"); + ant_value_t global_val = js_getprop_fallback(js, rx, "global"); if (is_err(global_val)) return global_val; bool global = js_truthy(js, global_val); bool full_unicode = false; if (global) { - jsval_t unicode_val = js_getprop_fallback(js, rx, "unicode"); + ant_value_t unicode_val = js_getprop_fallback(js, rx, "unicode"); if (is_err(unicode_val)) return unicode_val; full_unicode = js_truthy(js, unicode_val); js_setprop(js, rx, js_mkstr(js, "lastIndex", 9), tov(0)); } - jsval_t results = mkarr(js); + ant_value_t results = mkarr(js); if (is_err(results)) return results; - jsoff_t nresults = 0; + ant_offset_t nresults = 0; for (;;) { - jsval_t result = regexp_exec_abstract(js, rx, str); + ant_value_t result = regexp_exec_abstract(js, rx, str); if (is_err(result)) return result; if (vtype(result) == T_NULL) break; js_arr_push(js, results, result); nresults++; if (!global) break; - jsval_t match_str = js_tostring_val(js, js_arr_get(js, result, 0)); + ant_value_t match_str = js_tostring_val(js, js_arr_get(js, result, 0)); if (is_err(match_str)) return match_str; - jsoff_t mlen; vstr(js, match_str, &mlen); + ant_offset_t mlen; vstr(js, match_str, &mlen); if (mlen == 0) { - jsval_t li_val = js_getprop_fallback(js, rx, "lastIndex"); + ant_value_t li_val = js_getprop_fallback(js, rx, "lastIndex"); if (is_err(li_val)) return li_val; double li = vtype(li_val) == T_NUM ? tod(li_val) : 0; - jsoff_t sl, so = vstr(js, str, &sl); + ant_offset_t sl, so = vstr(js, str, &sl); double advance = 1; if (full_unicode && li < (double)sl) { - advance = (double)utf8_char_len_at((const char *)&js->mem[so], sl, (jsoff_t)li); + advance = (double)utf8_char_len_at((const char *)&js->mem[so], sl, (ant_offset_t)li); } js_setprop(js, rx, js_mkstr(js, "lastIndex", 9), tov(li + advance)); } } - jsoff_t str_len, str_off = vstr(js, str, &str_len); + ant_offset_t str_len, str_off = vstr(js, str, &str_len); size_t buf_cap = str_len + 256; char *buf = ant_calloc(buf_cap); if (!buf) return js_mkerr(js, "oom"); size_t buf_len = 0; - jsoff_t next_src_pos = 0; + ant_offset_t next_src_pos = 0; #define SB_APPEND(data, dlen) do { \ if (buf_len + (dlen) >= buf_cap) { \ @@ -1005,26 +1005,26 @@ jsval_t builtin_regexp_symbol_replace(ant_t *js, jsval_t *args, int nargs) { memcpy(buf + buf_len, data, dlen); buf_len += (dlen); \ } while(0) - for (jsoff_t i = 0; i < nresults; i++) { - jsval_t result = js_arr_get(js, results, i); - jsval_t matched = js_tostring_val(js, js_arr_get(js, result, 0)); + for (ant_offset_t i = 0; i < nresults; i++) { + ant_value_t result = js_arr_get(js, results, i); + ant_value_t matched = js_tostring_val(js, js_arr_get(js, result, 0)); if (is_err(matched)) { free(buf); return matched; } - jsoff_t matched_len; vstr(js, matched, &matched_len); + ant_offset_t matched_len; vstr(js, matched, &matched_len); - jsval_t pos_val = js_getprop_fallback(js, result, "index"); - jsoff_t position = 0; + ant_value_t pos_val = js_getprop_fallback(js, result, "index"); + ant_offset_t position = 0; if (!is_err(pos_val) && vtype(pos_val) == T_NUM) { double d = tod(pos_val); - position = d < 0 ? 0 : (jsoff_t)d; + position = d < 0 ? 0 : (ant_offset_t)d; } if (position > str_len) position = str_len; - jsval_t replacement; + ant_value_t replacement; if (func_replace) { - jsoff_t ncaptures = js_arr_len(js, result); - jsval_t call_args[32]; + ant_offset_t ncaptures = js_arr_len(js, result); + ant_value_t call_args[32]; int ca = 0; - for (jsoff_t c = 0; c < ncaptures && ca < 30; c++) + for (ant_offset_t c = 0; c < ncaptures && ca < 30; c++) call_args[ca++] = js_arr_get(js, result, c); call_args[ca++] = tov((double)position); call_args[ca++] = str; @@ -1033,26 +1033,26 @@ jsval_t builtin_regexp_symbol_replace(ant_t *js, jsval_t *args, int nargs) { replacement = replace_str; } if (is_err(replacement)) { free(buf); return replacement; } - jsval_t rep_str = js_tostring_val(js, replacement); + ant_value_t rep_str = js_tostring_val(js, replacement); if (is_err(rep_str)) { free(buf); return rep_str; } if (position >= next_src_pos) { str_off = vstr(js, str, &str_len); if (position > next_src_pos) SB_APPEND((const char *)&js->mem[str_off + next_src_pos], position - next_src_pos); - jsoff_t rep_len, rep_off = vstr(js, rep_str, &rep_len); + ant_offset_t rep_len, rep_off = vstr(js, rep_str, &rep_len); if (func_replace) { SB_APPEND((const char *)&js->mem[rep_off], rep_len); } else { - jsoff_t ncap = js_arr_len(js, result); + ant_offset_t ncap = js_arr_len(js, result); int num_caps = ncap > 1 ? (int)(ncap - 1) : 0; repl_capture_t caps_buf[16], *caps = num_caps <= 16 ? caps_buf : ant_calloc(sizeof(repl_capture_t) * (size_t)num_caps); for (int ci = 0; ci < num_caps; ci++) { - jsval_t cap = js_arr_get(js, result, (jsoff_t)(ci + 1)); - if (vtype(cap) == T_STR) { jsoff_t cl, co = vstr(js, cap, &cl); caps[ci] = (repl_capture_t){ (const char *)&js->mem[co], cl }; } + ant_value_t cap = js_arr_get(js, result, (ant_offset_t)(ci + 1)); + if (vtype(cap) == T_STR) { ant_offset_t cl, co = vstr(js, cap, &cl); caps[ci] = (repl_capture_t){ (const char *)&js->mem[co], cl }; } else caps[ci] = (repl_capture_t){ NULL, 0 }; } - jsoff_t mlen, moff = vstr(js, matched, &mlen); + ant_offset_t mlen, moff = vstr(js, matched, &mlen); str_off = vstr(js, str, &str_len); repl_template((const char *)&js->mem[rep_off], rep_len, (const char *)&js->mem[moff], mlen, (const char *)&js->mem[str_off], str_len, position, caps, num_caps, &buf, &buf_len, &buf_cap); @@ -1068,55 +1068,55 @@ jsval_t builtin_regexp_symbol_replace(ant_t *js, jsval_t *args, int nargs) { #undef SB_APPEND - jsval_t ret = js_mkstr(js, buf, buf_len); + ant_value_t ret = js_mkstr(js, buf, buf_len); free(buf); return ret; } -jsval_t builtin_regexp_symbol_search(ant_t *js, jsval_t *args, int nargs) { - jsval_t rx = js->this_val; +ant_value_t builtin_regexp_symbol_search(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t rx = js->this_val; if (!is_object_type(rx)) return js_mkerr_typed(js, JS_ERR_TYPE, "RegExp.prototype[@@search] called on non-object"); - jsval_t str = nargs > 0 ? js_tostring_val(js, args[0]) : js_mkstr(js, "undefined", 9); + ant_value_t str = nargs > 0 ? js_tostring_val(js, args[0]) : js_mkstr(js, "undefined", 9); if (is_err(str)) return str; - jsval_t prev_li = js_getprop_fallback(js, rx, "lastIndex"); + ant_value_t prev_li = js_getprop_fallback(js, rx, "lastIndex"); if (is_err(prev_li)) return prev_li; js_setprop(js, rx, js_mkstr(js, "lastIndex", 9), tov(0)); - jsval_t result = regexp_exec_abstract(js, rx, str); + ant_value_t result = regexp_exec_abstract(js, rx, str); if (is_err(result)) return result; - jsval_t cur_li = js_getprop_fallback(js, rx, "lastIndex"); + ant_value_t cur_li = js_getprop_fallback(js, rx, "lastIndex"); if (is_err(cur_li)) return cur_li; js_setprop(js, rx, js_mkstr(js, "lastIndex", 9), prev_li); if (vtype(result) == T_NULL) return tov(-1); - jsval_t idx = js_getprop_fallback(js, result, "index"); + ant_value_t idx = js_getprop_fallback(js, result, "index"); if (is_err(idx)) return idx; return vtype(idx) == T_NUM ? idx : tov(-1); } -jsval_t builtin_regexp_symbol_split(ant_t *js, jsval_t *args, int nargs) { - jsval_t rx = js_getthis(js); +ant_value_t builtin_regexp_symbol_split(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t rx = js_getthis(js); if (!is_object_type(rx)) return js_mkerr_typed(js, JS_ERR_TYPE, "RegExp.prototype[@@split] called on non-object"); - jsval_t str = nargs > 0 ? js_tostring_val(js, args[0]) : js_mkstr(js, "", 0); + ant_value_t str = nargs > 0 ? js_tostring_val(js, args[0]) : js_mkstr(js, "", 0); if (is_err(str)) return str; - jsval_t ctor = js_get(js, rx, "constructor"); + ant_value_t ctor = js_get(js, rx, "constructor"); if (is_err(ctor)) return ctor; - jsval_t C; + ant_value_t C; if (vtype(ctor) == T_UNDEF) { C = js_get(js, js_glob(js), "RegExp"); } else if (!is_object_type(ctor)) { return js_mkerr_typed(js, JS_ERR_TYPE, "RegExp.prototype[@@split]: constructor is not an object"); } else { - jsval_t species = get_ctor_species_value(js, ctor); + ant_value_t species = get_ctor_species_value(js, ctor); if (is_err(species)) return species; if (vtype(species) == T_UNDEF || vtype(species) == T_NULL) C = js_get(js, js_glob(js), "RegExp"); @@ -1127,20 +1127,20 @@ jsval_t builtin_regexp_symbol_split(ant_t *js, jsval_t *args, int nargs) { if (vtype(C) != T_FUNC && vtype(C) != T_CFUNC) return js_mkerr_typed(js, JS_ERR_TYPE, "RegExp species is not a constructor"); - jsval_t flags_val = js_get(js, rx, "flags"); + ant_value_t flags_val = js_get(js, rx, "flags"); if (is_err(flags_val)) return flags_val; - jsval_t flags_str = js_tostring_val(js, flags_val); + ant_value_t flags_str = js_tostring_val(js, flags_val); if (is_err(flags_str)) return flags_str; - jsoff_t flen, foff = vstr(js, flags_str, &flen); + ant_offset_t flen, foff = vstr(js, flags_str, &flen); const char *fptr = (const char *)&js->mem[foff]; bool unicode_matching = false, has_sticky = false; - for (jsoff_t i = 0; i < flen; i++) { + for (ant_offset_t i = 0; i < flen; i++) { if (fptr[i] == 'u' || fptr[i] == 'v') unicode_matching = true; if (fptr[i] == 'y') has_sticky = true; } - jsval_t new_flags; + ant_value_t new_flags; if (has_sticky) new_flags = flags_str; else { char fbuf[16]; if (flen > 14) flen = 14; @@ -1151,13 +1151,13 @@ jsval_t builtin_regexp_symbol_split(ant_t *js, jsval_t *args, int nargs) { new_flags = js_mkstr(js, fbuf, flen + 1); } - jsval_t ctor_args[2] = { rx, new_flags }; - jsval_t splitter = regexp_species_construct(js, rx, C, ctor_args, 2); + ant_value_t ctor_args[2] = { rx, new_flags }; + ant_value_t splitter = regexp_species_construct(js, rx, C, ctor_args, 2); if (is_err(splitter)) return splitter; - jsval_t A = mkarr(js); + ant_value_t A = mkarr(js); if (is_err(A)) return A; - jsoff_t lengthA = 0; + ant_offset_t lengthA = 0; uint32_t lim = UINT32_MAX; if (nargs >= 2 && vtype(args[1]) != T_UNDEF) { @@ -1165,23 +1165,23 @@ jsval_t builtin_regexp_symbol_split(ant_t *js, jsval_t *args, int nargs) { if (d >= 0 && d <= UINT32_MAX) lim = (uint32_t)d; } if (lim == 0) return mkval(T_ARR, vdata(A)); - jsoff_t str_len, str_off = vstr(js, str, &str_len); - jsoff_t size = str_len; + ant_offset_t str_len, str_off = vstr(js, str, &str_len); + ant_offset_t size = str_len; if (size == 0) { - jsval_t z = regexp_exec_abstract(js, splitter, str); + ant_value_t z = regexp_exec_abstract(js, splitter, str); if (is_err(z)) return z; if (vtype(z) == T_NULL) js_arr_push(js, A, str); return mkval(T_ARR, vdata(A)); } - jsoff_t p = 0, q = p; - jsval_t lastIndex_key = js_mkstr(js, "lastIndex", 9); + ant_offset_t p = 0, q = p; + ant_value_t lastIndex_key = js_mkstr(js, "lastIndex", 9); while (q < size) { js_setprop(js, splitter, lastIndex_key, tov((double)q)); - jsval_t z = regexp_exec_abstract(js, splitter, str); + ant_value_t z = regexp_exec_abstract(js, splitter, str); if (is_err(z)) return z; if (vtype(z) == T_NULL) { @@ -1192,10 +1192,10 @@ jsval_t builtin_regexp_symbol_split(ant_t *js, jsval_t *args, int nargs) { continue; } - jsval_t li_val = js_get(js, splitter, "lastIndex"); + ant_value_t li_val = js_get(js, splitter, "lastIndex"); if (is_err(li_val)) return li_val; double e_raw = vtype(li_val) == T_NUM ? tod(li_val) : 0; - jsoff_t e = (jsoff_t)(e_raw < 0 ? 0 : (e_raw > (double)size ? (double)size : e_raw)); + ant_offset_t e = (ant_offset_t)(e_raw < 0 ? 0 : (e_raw > (double)size ? (double)size : e_raw)); if (e == p) { if (unicode_matching) { @@ -1206,14 +1206,14 @@ jsval_t builtin_regexp_symbol_split(ant_t *js, jsval_t *args, int nargs) { } str_off = vstr(js, str, NULL); - jsval_t T_val = js_mkstr(js, (char *)&js->mem[str_off + p], q - p); + ant_value_t T_val = js_mkstr(js, (char *)&js->mem[str_off + p], q - p); js_arr_push(js, A, T_val); lengthA++; if (lengthA == lim) return mkval(T_ARR, vdata(A)); - jsoff_t num_caps = js_arr_len(js, z); - for (jsoff_t i = 1; i < num_caps; i++) { - jsval_t cap = js_arr_get(js, z, i); + ant_offset_t num_caps = js_arr_len(js, z); + for (ant_offset_t i = 1; i < num_caps; i++) { + ant_value_t cap = js_arr_get(js, z, i); js_arr_push(js, A, cap); lengthA++; if (lengthA == lim) return mkval(T_ARR, vdata(A)); @@ -1224,14 +1224,14 @@ jsval_t builtin_regexp_symbol_split(ant_t *js, jsval_t *args, int nargs) { } str_off = vstr(js, str, &str_len); - jsval_t trailing = js_mkstr(js, (char *)&js->mem[str_off + p], str_len - p); + ant_value_t trailing = js_mkstr(js, (char *)&js->mem[str_off + p], str_len - p); js_arr_push(js, A, trailing); return mkval(T_ARR, vdata(A)); } -jsval_t do_regex_match_pcre2( - ant_t *js, const char *pattern_ptr, jsoff_t pattern_len, - const char *str_ptr, jsoff_t str_len, +ant_value_t do_regex_match_pcre2( + ant_t *js, const char *pattern_ptr, ant_offset_t pattern_len, + const char *str_ptr, ant_offset_t str_len, bool global_flag, bool ignore_case, bool multiline ) { char pcre2_pattern[4096]; @@ -1250,7 +1250,7 @@ jsval_t do_regex_match_pcre2( uint32_t capture_count; pcre2_pattern_info(re, PCRE2_INFO_CAPTURECOUNT, &capture_count); - jsval_t result_arr = js_mkarr(js); + ant_value_t result_arr = js_mkarr(js); if (is_err(result_arr)) { pcre2_match_data_free(match_data); pcre2_code_free(re); @@ -1269,7 +1269,7 @@ jsval_t do_regex_match_pcre2( PCRE2_SIZE match_end = ovector[1]; if (global_flag) { - jsval_t match_str = js_mkstr(js, str_ptr + match_start, match_end - match_start); + ant_value_t match_str = js_mkstr(js, str_ptr + match_start, match_end - match_start); if (is_err(match_str)) { pcre2_match_data_free(match_data); pcre2_code_free(re); @@ -1283,7 +1283,7 @@ jsval_t do_regex_match_pcre2( if (start == PCRE2_UNSET) { js_arr_push(js, result_arr, js_mkundef()); } else { - jsval_t match_str = js_mkstr(js, str_ptr + start, end - start); + ant_value_t match_str = js_mkstr(js, str_ptr + start, end - start); if (is_err(match_str)) { pcre2_match_data_free(match_data); pcre2_code_free(re); @@ -1309,58 +1309,58 @@ jsval_t do_regex_match_pcre2( return result_arr; } -static jsval_t builtin_string_search(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_unwrapped = unwrap_primitive(js, js->this_val); - jsval_t str = js_tostring_val(js, this_unwrapped); +static ant_value_t builtin_string_search(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_unwrapped = unwrap_primitive(js, js->this_val); + ant_value_t str = js_tostring_val(js, this_unwrapped); if (is_err(str)) return str; if (nargs < 1) return tov(-1); if (is_object_type(args[0])) { bool called = false; - jsval_t call_args[1] = { str }; - jsval_t dispatched = maybe_call_symbol_method( + ant_value_t call_args[1] = { str }; + ant_value_t dispatched = maybe_call_symbol_method( js, args[0], get_search_sym(), args[0], call_args, 1, &called ); if (is_err(dispatched)) return dispatched; if (called) return dispatched; } - jsval_t pattern = args[0]; + ant_value_t pattern = args[0]; const char *pattern_ptr = NULL; - jsoff_t pattern_len = 0; + ant_offset_t pattern_len = 0; bool ignore_case = false, multiline = false; if (vtype(pattern) == T_OBJ) { - jsoff_t source_off = lkp(js, pattern, "source", 6); + ant_offset_t source_off = lkp(js, pattern, "source", 6); if (source_off == 0) return tov(-1); - jsval_t source_val = resolveprop(js, mkval(T_PROP, source_off)); + ant_value_t source_val = resolveprop(js, mkval(T_PROP, source_off)); if (vtype(source_val) != T_STR) return tov(-1); - jsoff_t poff; + ant_offset_t poff; poff = vstr(js, source_val, &pattern_len); pattern_ptr = (char *)&js->mem[poff]; - jsoff_t flags_off = lkp(js, pattern, "flags", 5); + ant_offset_t flags_off = lkp(js, pattern, "flags", 5); if (flags_off != 0) { - jsval_t flags_val = resolveprop(js, mkval(T_PROP, flags_off)); + ant_value_t flags_val = resolveprop(js, mkval(T_PROP, flags_off)); if (vtype(flags_val) == T_STR) { - jsoff_t flen, foff = vstr(js, flags_val, &flen); + ant_offset_t flen, foff = vstr(js, flags_val, &flen); const char *flags_str = (char *)&js->mem[foff]; - for (jsoff_t i = 0; i < flen; i++) { + for (ant_offset_t i = 0; i < flen; i++) { if (flags_str[i] == 'i') ignore_case = true; if (flags_str[i] == 'm') multiline = true; } } } } else if (vtype(pattern) == T_STR) { - jsoff_t poff; + ant_offset_t poff; poff = vstr(js, pattern, &pattern_len); pattern_ptr = (char *)&js->mem[poff]; } else { return tov(-1); } - jsoff_t str_len, str_off = vstr(js, str, &str_len); + ant_offset_t str_len, str_off = vstr(js, str, &str_len); const char *str_ptr = (char *)&js->mem[str_off]; char pcre2_pattern[4096]; @@ -1393,47 +1393,47 @@ static jsval_t builtin_string_search(ant_t *js, jsval_t *args, int nargs) { return tov(result); } -static jsval_t builtin_string_match(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_unwrapped = unwrap_primitive(js, js->this_val); - jsval_t str = js_tostring_val(js, this_unwrapped); +static ant_value_t builtin_string_match(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_unwrapped = unwrap_primitive(js, js->this_val); + ant_value_t str = js_tostring_val(js, this_unwrapped); if (is_err(str)) return str; if (nargs < 1) return js_mknull(); if (is_object_type(args[0])) { bool called = false; - jsval_t call_args[1] = { str }; - jsval_t dispatched = maybe_call_symbol_method( + ant_value_t call_args[1] = { str }; + ant_value_t dispatched = maybe_call_symbol_method( js, args[0], get_match_sym(), args[0], call_args, 1, &called ); if (is_err(dispatched)) return dispatched; if (called) return dispatched; } - jsval_t pattern = args[0]; + ant_value_t pattern = args[0]; const char *pattern_ptr = NULL; - jsoff_t pattern_len = 0; + ant_offset_t pattern_len = 0; bool global_flag = false; bool ignore_case = false; bool multiline = false; if (vtype(pattern) == T_OBJ) { - jsoff_t source_off = lkp(js, pattern, "source", 6); + ant_offset_t source_off = lkp(js, pattern, "source", 6); if (source_off == 0) return js_mknull(); - jsval_t source_val = resolveprop(js, mkval(T_PROP, source_off)); + ant_value_t source_val = resolveprop(js, mkval(T_PROP, source_off)); if (vtype(source_val) != T_STR) return js_mknull(); - jsoff_t poff; + ant_offset_t poff; poff = vstr(js, source_val, &pattern_len); pattern_ptr = (char *)&js->mem[poff]; - jsoff_t flags_off = lkp(js, pattern, "flags", 5); + ant_offset_t flags_off = lkp(js, pattern, "flags", 5); if (flags_off != 0) { - jsval_t flags_val = resolveprop(js, mkval(T_PROP, flags_off)); + ant_value_t flags_val = resolveprop(js, mkval(T_PROP, flags_off)); if (vtype(flags_val) == T_STR) { - jsoff_t flen, foff = vstr(js, flags_val, &flen); + ant_offset_t flen, foff = vstr(js, flags_val, &flen); const char *flags_str = (char *)&js->mem[foff]; - for (jsoff_t i = 0; i < flen; i++) { + for (ant_offset_t i = 0; i < flen; i++) { if (flags_str[i] == 'g') global_flag = true; if (flags_str[i] == 'i') ignore_case = true; if (flags_str[i] == 'm') multiline = true; @@ -1441,17 +1441,17 @@ static jsval_t builtin_string_match(ant_t *js, jsval_t *args, int nargs) { } } } else if (vtype(pattern) == T_STR) { - jsoff_t poff; + ant_offset_t poff; poff = vstr(js, pattern, &pattern_len); pattern_ptr = (char *)&js->mem[poff]; } else { return js_mknull(); } - jsoff_t str_len, str_off = vstr(js, str, &str_len); + ant_offset_t str_len, str_off = vstr(js, str, &str_len); const char *str_ptr = (char *)&js->mem[str_off]; - jsval_t result = do_regex_match_pcre2( + ant_value_t result = do_regex_match_pcre2( js, pattern_ptr, pattern_len, str_ptr, str_len, global_flag, ignore_case, multiline ); @@ -1465,10 +1465,10 @@ static jsval_t builtin_string_match(ant_t *js, jsval_t *args, int nargs) { void init_regex_module(void) { ant_t *js = rt->js; - jsval_t glob = js->global; - jsval_t object_proto = js->object; + ant_value_t glob = js->global; + ant_value_t object_proto = js->object; - jsval_t regexp_proto = js_mkobj(js); + ant_value_t regexp_proto = js_mkobj(js); js_set_proto(js, regexp_proto, object_proto); js_setprop(js, regexp_proto, js_mkstr(js, "test", 4), js_mkfun(builtin_regexp_test)); js_setprop(js, regexp_proto, js_mkstr(js, "exec", 4), js_mkfun(builtin_regexp_exec)); @@ -1490,20 +1490,20 @@ void init_regex_module(void) { js_set_getter_desc(js, regexp_proto, "flags", 5, js_mkfun(builtin_regexp_flags_getter), JS_DESC_C); js_setprop(js, regexp_proto, js_mkstr(js, "compile", 7), js_mkfun(builtin_regexp_compile)); - jsval_t regexp_ctor = js_mkobj(js); + ant_value_t regexp_ctor = js_mkobj(js); js_set_slot(js, regexp_ctor, SLOT_CFUNC, js_mkfun(builtin_RegExp)); js_mkprop_fast(js, regexp_ctor, "prototype", 9, regexp_proto); js_mkprop_fast(js, regexp_ctor, "name", 4, js_mkstr(js, "RegExp", 6)); js_set_descriptor(js, regexp_ctor, "name", 4, 0); js_define_species_getter(js, regexp_ctor); - jsval_t regexp_func = js_obj_to_func(regexp_ctor); + ant_value_t regexp_func = js_obj_to_func(regexp_ctor); js_setprop(js, regexp_proto, js_mkstr(js, "constructor", 11), regexp_func); js_set_descriptor(js, regexp_proto, "constructor", 11, JS_DESC_W | JS_DESC_C); js_set(js, regexp_ctor, "escape", js_mkfun(builtin_regexp_escape)); - jsval_t empty = js_mkstr(js, "", 0); + ant_value_t empty = js_mkstr(js, "", 0); for (int i = 1; i <= 9; i++) { char key[3] = {'$', (char)('0' + i), '\0'}; js_set(js, regexp_ctor, key, empty); @@ -1513,20 +1513,20 @@ void init_regex_module(void) { js_set(js, glob, "RegExp", regexp_func); - jsval_t string_ctor = js_get(js, glob, "String"); - jsval_t string_proto = js_get(js, string_ctor, "prototype"); + ant_value_t string_ctor = js_get(js, glob, "String"); + ant_value_t string_proto = js_get(js, string_ctor, "prototype"); js_setprop(js, string_proto, js_mkstr(js, "search", 6), js_mkfun(builtin_string_search)); js_setprop(js, string_proto, js_mkstr(js, "match", 5), js_mkfun(builtin_string_match)); } -void regex_gc_update_roots(jsoff_t (*weak_off)(void *ctx, jsoff_t old), GC_OP_VAL_ARGS) { +void regex_gc_update_roots(ant_offset_t (*weak_off)(void *ctx, ant_offset_t old), GC_OP_VAL_ARGS) { size_t write_idx = 0; for (size_t i = 0; i < regex_cache_count; i++) { - jsoff_t old_off = regex_cache[i].obj_offset; - jsoff_t new_off = weak_off(ctx, old_off); + ant_offset_t old_off = regex_cache[i].obj_offset; + ant_offset_t new_off = weak_off(ctx, old_off); - if (new_off == (jsoff_t)~0) { + if (new_off == (ant_offset_t)~0) { pcre2_match_data_free(regex_cache[i].match_data); pcre2_code_free(regex_cache[i].code); continue; diff --git a/src/modules/server.c b/src/modules/server.c index 150f727..6a3567e 100644 --- a/src/modules/server.c +++ b/src/modules/server.c @@ -87,9 +87,9 @@ static void res_set_body(response_ctx_t *ctx, const char *src, size_t len) { typedef struct http_server_s { ant_t *js; - jsval_t handler; - jsval_t store_obj; - jsval_t server_obj; + ant_value_t handler; + ant_value_t store_obj; + ant_value_t server_obj; int port; uv_tcp_t server; uv_loop_t *loop; @@ -345,11 +345,11 @@ static void free_http_request(http_request_t *req) { static void on_close(uv_handle_t *handle); static void send_response(uv_stream_t *client, response_ctx_t *res_ctx); -static jsval_t js_set_prop(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_set_prop(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkundef(); - jsval_t fn = js_getcurrentfunc(js); - jsval_t store_obj = js_get_slot(js, fn, SLOT_DATA); + ant_value_t fn = js_getcurrentfunc(js); + ant_value_t store_obj = js_get_slot(js, fn, SLOT_DATA); if (vtype(store_obj) == T_UNDEF) return js_mkundef(); if (vtype(args[0]) == T_STR) { @@ -361,11 +361,11 @@ static jsval_t js_set_prop(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t js_get_prop(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_get_prop(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkundef(); - jsval_t fn = js_getcurrentfunc(js); - jsval_t store_obj = js_get_slot(js, fn, SLOT_DATA); + ant_value_t fn = js_getcurrentfunc(js); + ant_value_t store_obj = js_get_slot(js, fn, SLOT_DATA); if (vtype(store_obj) == T_UNDEF) return js_mkundef(); if (vtype(args[0]) == T_STR) { @@ -377,11 +377,11 @@ static jsval_t js_get_prop(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t req_header(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t req_header(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkundef(); - jsval_t fn = js_getcurrentfunc(js); - jsval_t headers_val = js_get_slot(js, fn, SLOT_DATA); + ant_value_t fn = js_getcurrentfunc(js); + ant_value_t headers_val = js_get_slot(js, fn, SLOT_DATA); if (vtype(headers_val) != T_NUM) return js_mkundef(); UT_array *headers = (UT_array *)(unsigned long)js_getnum(headers_val); @@ -401,11 +401,11 @@ static jsval_t req_header(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t res_header(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t res_header(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkundef(); - jsval_t fn = js_getcurrentfunc(js); - jsval_t ctx_val = js_get_slot(js, fn, SLOT_DATA); + ant_value_t fn = js_getcurrentfunc(js); + ant_value_t ctx_val = js_get_slot(js, fn, SLOT_DATA); if (vtype(ctx_val) != T_NUM) return js_mkundef(); response_ctx_t *ctx = (response_ctx_t *)(unsigned long)js_getnum(ctx_val); @@ -421,11 +421,11 @@ static jsval_t res_header(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t res_status(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t res_status(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkundef(); - jsval_t fn = js_getcurrentfunc(js); - jsval_t ctx_val = js_get_slot(js, fn, SLOT_DATA); + ant_value_t fn = js_getcurrentfunc(js); + ant_value_t ctx_val = js_get_slot(js, fn, SLOT_DATA); if (vtype(ctx_val) != T_NUM) return js_mkundef(); response_ctx_t *ctx = (response_ctx_t *)(unsigned long)js_getnum(ctx_val); @@ -438,11 +438,11 @@ static jsval_t res_status(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t res_body(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t res_body(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkundef(); - jsval_t fn = js_getcurrentfunc(js); - jsval_t ctx_val = js_get_slot(js, fn, SLOT_DATA); + ant_value_t fn = js_getcurrentfunc(js); + ant_value_t ctx_val = js_get_slot(js, fn, SLOT_DATA); if (vtype(ctx_val) != T_NUM) return js_mkundef(); response_ctx_t *ctx = (response_ctx_t *)(unsigned long)js_getnum(ctx_val); @@ -467,11 +467,11 @@ static jsval_t res_body(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t res_html(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t res_html(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkundef(); - jsval_t fn = js_getcurrentfunc(js); - jsval_t ctx_val = js_get_slot(js, fn, SLOT_DATA); + ant_value_t fn = js_getcurrentfunc(js); + ant_value_t ctx_val = js_get_slot(js, fn, SLOT_DATA); if (vtype(ctx_val) != T_NUM) return js_mkundef(); response_ctx_t *ctx = (response_ctx_t *)(unsigned long)js_getnum(ctx_val); @@ -493,18 +493,18 @@ static jsval_t res_html(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t res_json(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t res_json(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkundef(); - jsval_t fn = js_getcurrentfunc(js); - jsval_t ctx_val = js_get_slot(js, fn, SLOT_DATA); + ant_value_t fn = js_getcurrentfunc(js); + ant_value_t ctx_val = js_get_slot(js, fn, SLOT_DATA); if (vtype(ctx_val) != T_NUM) return js_mkundef(); response_ctx_t *ctx = (response_ctx_t *)(unsigned long)js_getnum(ctx_val); if (!ctx) return js_mkundef(); - jsval_t stringify_args[1] = { args[0] }; - jsval_t result = js_json_stringify(js, stringify_args, 1); + ant_value_t stringify_args[1] = { args[0] }; + ant_value_t result = js_json_stringify(js, stringify_args, 1); if (vtype(result) == T_STR) { size_t len; @@ -525,11 +525,11 @@ static jsval_t res_json(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t res_notFound(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t res_notFound(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t fn = js_getcurrentfunc(js); - jsval_t ctx_val = js_get_slot(js, fn, SLOT_DATA); + ant_value_t fn = js_getcurrentfunc(js); + ant_value_t ctx_val = js_get_slot(js, fn, SLOT_DATA); if (vtype(ctx_val) != T_NUM) return js_mkundef(); response_ctx_t *ctx = (response_ctx_t *)(unsigned long)js_getnum(ctx_val); @@ -544,11 +544,11 @@ static jsval_t res_notFound(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t res_redirect(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t res_redirect(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkundef(); - jsval_t fn = js_getcurrentfunc(js); - jsval_t ctx_val = js_get_slot(js, fn, SLOT_DATA); + ant_value_t fn = js_getcurrentfunc(js); + ant_value_t ctx_val = js_get_slot(js, fn, SLOT_DATA); if (vtype(ctx_val) != T_NUM) return js_mkundef(); response_ctx_t *ctx = (response_ctx_t *)(unsigned long)js_getnum(ctx_val); @@ -706,14 +706,14 @@ static void send_response(uv_stream_t *client, response_ctx_t *res_ctx) { uv_write((uv_write_t *)write_req, client, &write_req->buf, 1, on_write); } -static jsval_t js_server_stop(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_server_stop(ant_t *js, ant_value_t *args, int nargs) { server_signal_cb(NULL, 0); return js_mkundef(); } static void handle_http_request(client_t *client, http_request_t *http_req) { http_server_t *server = client->server; - jsval_t result = js_mkundef(); + ant_value_t result = js_mkundef(); response_ctx_t *res_ctx = malloc(sizeof(response_ctx_t)); if (!res_ctx) { @@ -741,16 +741,16 @@ static void handle_http_request(client_t *client, http_request_t *http_req) { server->pending_responses = res_ctx; if (server->handler != 0 && vtype(server->handler) != T_UNDEF) { - jsval_t ctx = js_mkobj(server->js); + ant_value_t ctx = js_mkobj(server->js); - jsval_t req = js_mkobj(server->js); + ant_value_t req = js_mkobj(server->js); js_set(server->js, req, "method", js_mkstr(server->js, http_req->method, strlen(http_req->method))); js_set(server->js, req, "uri", js_mkstr(server->js, http_req->uri, strlen(http_req->uri))); js_set(server->js, req, "query", js_mkstr(server->js, http_req->query, strlen(http_req->query))); js_set(server->js, req, "body", js_mkstr(server->js, http_req->body ? http_req->body : "", http_req->body ? http_req->body_len : 0)); js_set(server->js, req, "header", js_heavy_mkfun(server->js, req_header, ANT_PTR(http_req->headers))); - jsval_t res_obj = js_mkobj(server->js); + ant_value_t res_obj = js_mkobj(server->js); js_set(server->js, res_obj, "header", js_heavy_mkfun(server->js, res_header, ANT_PTR(res_ctx))); js_set(server->js, res_obj, "status", js_heavy_mkfun(server->js, res_status, ANT_PTR(res_ctx))); js_set(server->js, res_obj, "body", js_heavy_mkfun(server->js, res_body, ANT_PTR(res_ctx))); @@ -765,7 +765,7 @@ static void handle_http_request(client_t *client, http_request_t *http_req) { js_set(server->js, ctx, "set", js_heavy_mkfun(server->js, js_set_prop, server->store_obj)); js_set(server->js, ctx, "get", js_heavy_mkfun(server->js, js_get_prop, server->store_obj)); - jsval_t args[2] = {ctx, server->server_obj}; + ant_value_t args[2] = {ctx, server->server_obj}; result = sv_vm_call(server->js->vm, server->js, server->handler, js_mkundef(), args, 2, NULL, false); if (vtype(result) == T_PROMISE) return; @@ -944,7 +944,7 @@ static void on_connection(uv_stream_t *server, int status) { } // Ant.serve(port, handler) -jsval_t js_serve(ant_t *js, jsval_t *args, int nargs) { +ant_value_t js_serve(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) { fprintf(stderr, "Error: Ant.serve() requires at least 1 argument (port)\n"); return js_mkundef(); @@ -967,7 +967,7 @@ jsval_t js_serve(ant_t *js, jsval_t *args, int nargs) { server->store_obj = js_mkobj(js); server->handler = (nargs >= 2) ? args[1] : js_mkundef(); - jsval_t server_obj = js_mkobj(js); + ant_value_t server_obj = js_mkobj(js); js_set(js, server_obj, "stop", js_mkfun(js_server_stop)); js_set(js, server_obj, "port", js_mknum(port)); diff --git a/src/modules/sessionstorage.c b/src/modules/sessionstorage.c index 8d552f6..5f52a01 100644 --- a/src/modules/sessionstorage.c +++ b/src/modules/sessionstorage.c @@ -85,7 +85,7 @@ static char *storage_key(size_t index) { } // sessionStorage.setItem(key, value) -static jsval_t js_sessionstorage_setItem(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_sessionstorage_setItem(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) { return js_mkerr(js, "Failed to execute 'setItem' on 'Storage': 2 arguments required"); } @@ -100,7 +100,7 @@ static jsval_t js_sessionstorage_setItem(ant_t *js, jsval_t *args, int nargs) { } // sessionStorage.getItem(key) -static jsval_t js_sessionstorage_getItem(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_sessionstorage_getItem(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) { return js_mkerr(js, "Failed to execute 'getItem' on 'Storage': 1 argument required"); } @@ -115,7 +115,7 @@ static jsval_t js_sessionstorage_getItem(ant_t *js, jsval_t *args, int nargs) { } // sessionStorage.removeItem(key) -static jsval_t js_sessionstorage_removeItem(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_sessionstorage_removeItem(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) { return js_mkerr(js, "Failed to execute 'removeItem' on 'Storage': 1 argument required"); } @@ -128,14 +128,14 @@ static jsval_t js_sessionstorage_removeItem(ant_t *js, jsval_t *args, int nargs) } // sessionStorage.clear() -static jsval_t js_sessionstorage_clear(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_sessionstorage_clear(ant_t *js, ant_value_t *args, int nargs) { (void)js; (void)args; (void)nargs; storage_clear(); return js_mkundef(); } // sessionStorage.key(index) -static jsval_t js_sessionstorage_key(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_sessionstorage_key(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) { return js_mkerr(js, "Failed to execute 'key' on 'Storage': 1 argument required"); } @@ -156,7 +156,7 @@ static jsval_t js_sessionstorage_key(ant_t *js, jsval_t *args, int nargs) { } // sessionStorage.length -static jsval_t js_sessionstorage_length(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_sessionstorage_length(ant_t *js, ant_value_t *args, int nargs) { (void)js; (void)args; (void)nargs; return js_mknum((double)storage_length()); } @@ -164,8 +164,8 @@ static jsval_t js_sessionstorage_length(ant_t *js, jsval_t *args, int nargs) { void init_sessionstorage_module(void) { ant_t *js = rt->js; - jsval_t glob = js_glob(js); - jsval_t storage_obj = js_mkobj(js); + ant_value_t glob = js_glob(js); + ant_value_t storage_obj = js_mkobj(js); js_set(js, storage_obj, "setItem", js_mkfun(js_sessionstorage_setItem)); js_set(js, storage_obj, "getItem", js_mkfun(js_sessionstorage_getItem)); @@ -173,7 +173,7 @@ void init_sessionstorage_module(void) { js_set(js, storage_obj, "clear", js_mkfun(js_sessionstorage_clear)); js_set(js, storage_obj, "key", js_mkfun(js_sessionstorage_key)); - jsval_t length_getter = js_mkfun(js_sessionstorage_length); + ant_value_t length_getter = js_mkfun(js_sessionstorage_length); js_set_getter_desc(js, storage_obj, "length", 6, length_getter, JS_DESC_E); js_set_sym(js, storage_obj, get_toStringTag_sym(), ANT_STRING("Storage")); diff --git a/src/modules/shell.c b/src/modules/shell.c index e97cc42..103048e 100644 --- a/src/modules/shell.c +++ b/src/modules/shell.c @@ -16,11 +16,11 @@ #include "internal.h" #include "modules/symbol.h" -static jsval_t builtin_shell_text(ant_t *js, jsval_t *args, int nargs); -static jsval_t builtin_shell_lines(ant_t *js, jsval_t *args, int nargs); +static ant_value_t builtin_shell_text(ant_t *js, ant_value_t *args, int nargs); +static ant_value_t builtin_shell_lines(ant_t *js, ant_value_t *args, int nargs); -static jsval_t shell_exec(ant_t *js, const char *cmd, size_t cmd_len) { - jsval_t result = js_mkobj(js); +static ant_value_t shell_exec(ant_t *js, const char *cmd, size_t cmd_len) { + ant_value_t result = js_mkobj(js); FILE *fp = popen(cmd, "r"); if (!fp) { @@ -65,7 +65,7 @@ static jsval_t shell_exec(ant_t *js, const char *cmd, size_t cmd_len) { #endif if (output_size > 0 && output[output_size - 1] == '\n') output_size--; - jsval_t stdout_val = js_mkstr(js, output, output_size); + ant_value_t stdout_val = js_mkstr(js, output, output_size); free(output); js_set(js, result, "exitCode", js_mknum(exit_code)); @@ -75,32 +75,32 @@ static jsval_t shell_exec(ant_t *js, const char *cmd, size_t cmd_len) { return result; } -static jsval_t builtin_shell_text(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_shell_text(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t fn = js_getcurrentfunc(js); + ant_value_t fn = js_getcurrentfunc(js); return js_get_slot(js, fn, SLOT_DATA); } -static jsval_t builtin_shell_lines(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_shell_lines(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t fn = js_getcurrentfunc(js); - jsval_t stdout_val = js_get_slot(js, fn, SLOT_DATA); + ant_value_t fn = js_getcurrentfunc(js); + ant_value_t stdout_val = js_get_slot(js, fn, SLOT_DATA); size_t text_len; char *text = js_getstr(js, stdout_val, &text_len); if (!text) return js_mkarr(js); - jsval_t lines_array = js_mkarr(js); + ant_value_t lines_array = js_mkarr(js); size_t line_start = 0; for (size_t i = 0; i <= text_len; i++) { if (i == text_len || text[i] == '\n') { size_t line_len = i - line_start; - jsval_t line_val = js_mkstr(js, text + line_start, line_len); + ant_value_t line_val = js_mkstr(js, text + line_start, line_len); js_arr_push(js, lines_array, line_val); line_start = i + 1; } @@ -109,7 +109,7 @@ static jsval_t builtin_shell_lines(ant_t *js, jsval_t *args, int nargs) { return lines_array; } -static jsval_t builtin_shell_dollar(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_shell_dollar(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "$() requires at least one argument"); if (!is_special_object(args[0])) { @@ -123,7 +123,7 @@ static jsval_t builtin_shell_dollar(ant_t *js, jsval_t *args, int nargs) { return js_mkerr(js, "$() requires a template string"); } - jsval_t strings_array = args[0]; + ant_value_t strings_array = args[0]; char *command = malloc(4096); if (!command) return js_mkerr(js, "Out of memory"); @@ -131,14 +131,14 @@ static jsval_t builtin_shell_dollar(ant_t *js, jsval_t *args, int nargs) { size_t cmd_pos = 0; size_t cmd_capacity = 4096; - jsval_t length_val = js_get(js, strings_array, "length"); + ant_value_t length_val = js_get(js, strings_array, "length"); int length = (int)js_getnum(length_val); for (int i = 0; i < length; i++) { char idx_str[32]; snprintf(idx_str, sizeof(idx_str), "%d", i); - jsval_t str_val = js_get(js, strings_array, idx_str); + ant_value_t str_val = js_get(js, strings_array, idx_str); if (vtype(str_val) == T_STR) { size_t str_len; char *str = js_getstr(js, str_val, &str_len); @@ -158,7 +158,7 @@ static jsval_t builtin_shell_dollar(ant_t *js, jsval_t *args, int nargs) { } if (i + 1 < nargs) { - jsval_t val = args[i + 1]; + ant_value_t val = args[i + 1]; char val_str[256]; size_t val_len = 0; @@ -188,14 +188,14 @@ static jsval_t builtin_shell_dollar(ant_t *js, jsval_t *args, int nargs) { command[cmd_pos] = '\0'; - jsval_t result = shell_exec(js, command, cmd_pos); + ant_value_t result = shell_exec(js, command, cmd_pos); free(command); return result; } -jsval_t shell_library(ant_t *js) { - jsval_t lib = js_mkobj(js); +ant_value_t shell_library(ant_t *js) { + ant_value_t lib = js_mkobj(js); js_set(js, lib, "$", js_mkfun(builtin_shell_dollar)); js_set_sym(js, lib, get_toStringTag_sym(), js_mkstr(js, "shell", 5)); diff --git a/src/modules/symbol.c b/src/modules/symbol.c index 0d6aa8b..fdf64cb 100644 --- a/src/modules/symbol.c +++ b/src/modules/symbol.c @@ -11,19 +11,19 @@ #include "modules/symbol.h" #include "descriptors.h" -static jsval_t g_iterator_proto_obj = {0}; -static jsval_t g_array_iterator_proto_obj = {0}; -static jsval_t g_string_iterator_proto_obj = {0}; +static ant_value_t g_iterator_proto_obj = {0}; +static ant_value_t g_array_iterator_proto_obj = {0}; +static ant_value_t g_string_iterator_proto_obj = {0}; -#define DECL_SYM(name, _desc) static jsval_t g_##name = {0}; +#define DECL_SYM(name, _desc) static ant_value_t g_##name = {0}; WELLKNOWN_SYMBOLS(DECL_SYM) #undef DECL_SYM -#define DEF_GET_SYM(name, _desc) jsval_t get_##name##_sym(void) { return g_##name; } +#define DEF_GET_SYM(name, _desc) ant_value_t get_##name##_sym(void) { return g_##name; } WELLKNOWN_SYMBOLS(DEF_GET_SYM) #undef DEF_GET_SYM -static jsval_t builtin_Symbol(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Symbol(ant_t *js, ant_value_t *args, int nargs) { const char *desc = NULL; if (nargs > 0 && vtype(args[0]) == T_STR) { desc = js_getstr(js, args[0], NULL); @@ -31,7 +31,7 @@ static jsval_t builtin_Symbol(ant_t *js, jsval_t *args, int nargs) { return js_mksym(js, desc); } -static jsval_t builtin_Symbol_for(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Symbol_for(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || vtype(args[0]) != T_STR) { return js_mkerr(js, "Symbol.for requires a string argument"); } @@ -42,7 +42,7 @@ static jsval_t builtin_Symbol_for(ant_t *js, jsval_t *args, int nargs) { return js_mksym_for(js, key); } -static jsval_t builtin_Symbol_keyFor(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_Symbol_keyFor(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || vtype(args[0]) != T_SYMBOL) { return js_mkundef(); } @@ -53,8 +53,8 @@ static jsval_t builtin_Symbol_keyFor(ant_t *js, jsval_t *args, int nargs) { return js_mkstr(js, key, strlen(key)); } -static jsval_t builtin_Symbol_toString(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_val = js_getthis(js); +static ant_value_t builtin_Symbol_toString(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_val = js_getthis(js); if (vtype(this_val) != T_SYMBOL) { return js_mkerr(js, "Symbol.prototype.toString requires a symbol"); @@ -63,18 +63,18 @@ static jsval_t builtin_Symbol_toString(ant_t *js, jsval_t *args, int nargs) { return js_symbol_to_string(js, this_val); } -static jsval_t iterator_next(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_val = js_getthis(js); +static ant_value_t iterator_next(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_val = js_getthis(js); // migrate to slots - jsval_t arr = js_get(js, this_val, "__arr"); - jsval_t idx_val = js_get(js, this_val, "__idx"); - jsval_t len_val = js_get(js, this_val, "__len"); + ant_value_t arr = js_get(js, this_val, "__arr"); + ant_value_t idx_val = js_get(js, this_val, "__idx"); + ant_value_t len_val = js_get(js, this_val, "__len"); int idx = (int)js_getnum(idx_val); int len = (int)js_getnum(len_val); - jsval_t result = js_mkobj(js); + ant_value_t result = js_mkobj(js); if (idx >= len) { js_set(js, result, "done", js_true); @@ -82,7 +82,7 @@ static jsval_t iterator_next(ant_t *js, jsval_t *args, int nargs) { } else { char idxstr[16]; snprintf(idxstr, sizeof(idxstr), "%d", idx); - jsval_t value = js_get(js, arr, idxstr); + ant_value_t value = js_get(js, arr, idxstr); js_set(js, result, "value", value); js_set(js, result, "done", js_false); js_set(js, this_val, "__idx", js_mknum(idx + 1)); @@ -91,7 +91,7 @@ static jsval_t iterator_next(ant_t *js, jsval_t *args, int nargs) { return result; } -static jsval_t get_iterator_prototype(ant_t *js) { +static ant_value_t get_iterator_prototype(ant_t *js) { if (vtype(g_iterator_proto_obj) == T_OBJ) return g_iterator_proto_obj; g_iterator_proto_obj = js_mkobj(js); @@ -101,10 +101,10 @@ static jsval_t get_iterator_prototype(ant_t *js) { return g_iterator_proto_obj; } -static jsval_t get_array_iterator_prototype(ant_t *js) { +static ant_value_t get_array_iterator_prototype(ant_t *js) { if (vtype(g_array_iterator_proto_obj) == T_OBJ) return g_array_iterator_proto_obj; - jsval_t iterator_proto = get_iterator_prototype(js); + ant_value_t iterator_proto = get_iterator_prototype(js); g_array_iterator_proto_obj = js_mkobj(js); js_set(js, g_array_iterator_proto_obj, "next", js_mkfun(iterator_next)); js_set_proto(js, g_array_iterator_proto_obj, iterator_proto); @@ -112,12 +112,12 @@ static jsval_t get_array_iterator_prototype(ant_t *js) { return g_array_iterator_proto_obj; } -static jsval_t array_iterator(ant_t *js, jsval_t *args, int nargs) { - jsval_t arr = js_getthis(js); - jsval_t len_val = js_get(js, arr, "length"); +static ant_value_t array_iterator(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t arr = js_getthis(js); + ant_value_t len_val = js_get(js, arr, "length"); int len = vtype(len_val) == T_NUM ? (int)js_getnum(len_val) : 0; - jsval_t iter = js_mkobj(js); + ant_value_t iter = js_mkobj(js); js_set(js, iter, "__arr", arr); js_set(js, iter, "__idx", js_mknum(0)); js_set(js, iter, "__len", js_mknum(len)); @@ -126,17 +126,17 @@ static jsval_t array_iterator(ant_t *js, jsval_t *args, int nargs) { return iter; } -static jsval_t string_iterator_next(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_val = js_getthis(js); +static ant_value_t string_iterator_next(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_val = js_getthis(js); - jsval_t str = js_get(js, this_val, "__str"); - jsval_t idx_val = js_get(js, this_val, "__idx"); - jsval_t len_val = js_get(js, this_val, "__len"); + ant_value_t str = js_get(js, this_val, "__str"); + ant_value_t idx_val = js_get(js, this_val, "__idx"); + ant_value_t len_val = js_get(js, this_val, "__len"); int idx = (int)js_getnum(idx_val); int len = (int)js_getnum(len_val); - jsval_t result = js_mkobj(js); + ant_value_t result = js_mkobj(js); if (idx >= len) { js_set(js, result, "done", js_true); @@ -149,7 +149,7 @@ static jsval_t string_iterator_next(ant_t *js, jsval_t *args, int nargs) { if (char_bytes < 1) char_bytes = 1; if (idx + char_bytes > len) char_bytes = len - idx; - js_set(js, result, "value", js_mkstr(js, s + idx, (jsoff_t)char_bytes)); + js_set(js, result, "value", js_mkstr(js, s + idx, (ant_offset_t)char_bytes)); js_set(js, result, "done", js_false); js_set(js, this_val, "__idx", js_mknum(idx + char_bytes)); } @@ -157,10 +157,10 @@ static jsval_t string_iterator_next(ant_t *js, jsval_t *args, int nargs) { return result; } -static jsval_t get_string_iterator_prototype(ant_t *js) { +static ant_value_t get_string_iterator_prototype(ant_t *js) { if (vtype(g_string_iterator_proto_obj) == T_OBJ) return g_string_iterator_proto_obj; - jsval_t iterator_proto = get_iterator_prototype(js); + ant_value_t iterator_proto = get_iterator_prototype(js); g_string_iterator_proto_obj = js_mkobj(js); js_set(js, g_string_iterator_proto_obj, "next", js_mkfun(string_iterator_next)); js_set_proto(js, g_string_iterator_proto_obj, iterator_proto); @@ -168,11 +168,11 @@ static jsval_t get_string_iterator_prototype(ant_t *js) { return g_string_iterator_proto_obj; } -static jsval_t string_iterator(ant_t *js, jsval_t *args, int nargs) { - jsval_t str = js_getthis(js); +static ant_value_t string_iterator(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t str = js_getthis(js); size_t len; js_getstr(js, str, &len); - jsval_t iter = js_mkobj(js); + ant_value_t iter = js_mkobj(js); js_set(js, iter, "__str", str); js_set(js, iter, "__idx", js_mknum(0)); js_set(js, iter, "__len", js_mknum((double)len)); @@ -181,16 +181,16 @@ static jsval_t string_iterator(ant_t *js, jsval_t *args, int nargs) { return iter; } -jsval_t maybe_call_symbol_method( - ant_t *js, jsval_t target, - jsval_t sym, - jsval_t this_arg, jsval_t *args, +ant_value_t maybe_call_symbol_method( + ant_t *js, ant_value_t target, + ant_value_t sym, + ant_value_t this_arg, ant_value_t *args, int nargs, bool *called ) { *called = false; if (vtype(sym) != T_SYMBOL || !is_object_type(target)) return js_mkundef(); - jsval_t method = js_get_sym(js, target, sym); + ant_value_t method = js_get_sym(js, target, sym); if (is_err(method)) return method; uint8_t mt = vtype(method); @@ -203,7 +203,7 @@ jsval_t maybe_call_symbol_method( return sv_vm_call(js->vm, js, method, this_arg, args, nargs, NULL, false); } -void js_define_species_getter(ant_t *js, jsval_t ctor) { +void js_define_species_getter(ant_t *js, ant_value_t ctor) { if (vtype(ctor) == T_FUNC) ctor = js_func_obj(ctor); if (vtype(ctor) != T_OBJ || vtype(g_species) != T_SYMBOL) return; js_set_sym_getter_desc(js, ctor, g_species, js_mkfun(sym_this_cb), JS_DESC_C); @@ -220,10 +220,10 @@ void init_symbol_module(void) { WELLKNOWN_SYMBOLS(INIT_SYM) #undef INIT_SYM - jsval_t symbol_proto = js_mkobj(js); + ant_value_t symbol_proto = js_mkobj(js); js_set(js, symbol_proto, "toString", js_mkfun(builtin_Symbol_toString)); - jsval_t symbol_ctor = js_mkobj(js); + ant_value_t symbol_ctor = js_mkobj(js); js_set_slot(js, symbol_ctor, SLOT_CFUNC, js_mkfun(builtin_Symbol)); js_setprop(js, symbol_ctor, js_mkstr(js, "for", 3), js_mkfun(builtin_Symbol_for)); js_set(js, symbol_ctor, "keyFor", js_mkfun(builtin_Symbol_keyFor)); @@ -233,20 +233,20 @@ void init_symbol_module(void) { WELLKNOWN_SYMBOLS(SET_CTOR_SYM) #undef SET_CTOR_SYM - jsval_t func_symbol = js_obj_to_func(symbol_ctor); + ant_value_t func_symbol = js_obj_to_func(symbol_ctor); js_set(js, js_glob(js), "Symbol", func_symbol); // set internal types before ant module snapshot js_set_sym(js, rt->ant_obj, g_toStringTag, js_mkstr(js, "Ant", 3)); - jsval_t array_ctor = js_get(js, js_glob(js), "Array"); - jsval_t array_proto = js_get(js, array_ctor, "prototype"); + ant_value_t array_ctor = js_get(js, js_glob(js), "Array"); + ant_value_t array_proto = js_get(js, array_ctor, "prototype"); (void)get_array_iterator_prototype(js); (void)get_string_iterator_prototype(js); js_set_sym(js, array_proto, g_iterator, js_mkfun(array_iterator)); - jsval_t array_unscopables = js_mkobj(js); + ant_value_t array_unscopables = js_mkobj(js); js_set(js, array_unscopables, "find", js_true); js_set(js, array_unscopables, "findIndex", js_true); js_set(js, array_unscopables, "fill", js_true); @@ -258,15 +258,15 @@ void init_symbol_module(void) { js_set(js, array_unscopables, "flatMap", js_true); js_set_sym(js, array_proto, g_unscopables, array_unscopables); - jsval_t string_ctor = js_get(js, js_glob(js), "String"); - jsval_t string_proto = js_get(js, string_ctor, "prototype"); + ant_value_t string_ctor = js_get(js, js_glob(js), "String"); + ant_value_t string_proto = js_get(js, string_ctor, "prototype"); js_set_sym(js, string_proto, g_iterator, js_mkfun(string_iterator)); - jsval_t promise_ctor = js_get(js, js_glob(js), "Promise"); - jsval_t promise_proto = js_get(js, promise_ctor, "prototype"); + ant_value_t promise_ctor = js_get(js, js_glob(js), "Promise"); + ant_value_t promise_proto = js_get(js, promise_ctor, "prototype"); js_set_sym(js, promise_proto, g_toStringTag, js_mkstr(js, "Promise", 7)); - jsval_t math_obj = js_get(js, js_glob(js), "Math"); + ant_value_t math_obj = js_get(js, js_glob(js), "Math"); if (is_object_type(math_obj)) js_set_sym(js, math_obj, g_toStringTag, js_mkstr(js, "Math", 4)); js_define_species_getter(js, promise_ctor); diff --git a/src/modules/textcodec.c b/src/modules/textcodec.c index 9fcc315..a720eab 100644 --- a/src/modules/textcodec.c +++ b/src/modules/textcodec.c @@ -12,7 +12,7 @@ #include "modules/symbol.h" // TextEncoder.prototype.encode(string) -static jsval_t js_textencoder_encode(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_textencoder_encode(ant_t *js, ant_value_t *args, int nargs) { size_t str_len = 0; const char *str = ""; @@ -21,24 +21,24 @@ static jsval_t js_textencoder_encode(ant_t *js, jsval_t *args, int nargs) { if (!str) { str = ""; str_len = 0; } } - jsval_t glob = js_glob(js); - jsval_t uint8array_ctor = js_get(js, glob, "Uint8Array"); + ant_value_t glob = js_glob(js); + ant_value_t uint8array_ctor = js_get(js, glob, "Uint8Array"); if (vtype(uint8array_ctor) != T_FUNC && vtype(uint8array_ctor) != T_CFUNC) { return js_mkerr_typed(js, JS_ERR_TYPE, "Uint8Array constructor missing"); } - jsval_t len_arg = js_mknum((double)str_len); - jsval_t saved_new_target = js->new_target; + ant_value_t len_arg = js_mknum((double)str_len); + ant_value_t saved_new_target = js->new_target; js->new_target = uint8array_ctor; - jsval_t arr = sv_vm_call(js->vm, js, uint8array_ctor, js_mkundef(), &len_arg, 1, NULL, true); + ant_value_t arr = sv_vm_call(js->vm, js, uint8array_ctor, js_mkundef(), &len_arg, 1, NULL, true); js->new_target = saved_new_target; if (vtype(arr) == T_ERR) return arr; if (str_len > 0) { - jsval_t ta_data_val = js_get_slot(js, arr, SLOT_BUFFER); + ant_value_t ta_data_val = js_get_slot(js, arr, SLOT_BUFFER); TypedArrayData *ta_data = (TypedArrayData *)js_gettypedarray(ta_data_val); if (ta_data && ta_data->buffer && ta_data->buffer->data) memcpy(ta_data->buffer->data, str, str_len); } @@ -47,7 +47,7 @@ static jsval_t js_textencoder_encode(ant_t *js, jsval_t *args, int nargs) { } // TextEncoder.prototype.encodeInto(string, uint8array) -static jsval_t js_textencoder_encodeInto(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_textencoder_encodeInto(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) { return js_mkerr(js, "encodeInto requires string and Uint8Array arguments"); } @@ -63,7 +63,7 @@ static jsval_t js_textencoder_encodeInto(ant_t *js, jsval_t *args, int nargs) { } } - jsval_t ta_data_val = js_get_slot(js, args[1], SLOT_BUFFER); + ant_value_t ta_data_val = js_get_slot(js, args[1], SLOT_BUFFER); TypedArrayData *ta_data = (TypedArrayData *)js_gettypedarray(ta_data_val); if (!ta_data) return js_mkerr(js, "Second argument must be a Uint8Array"); @@ -74,18 +74,18 @@ static jsval_t js_textencoder_encodeInto(ant_t *js, jsval_t *args, int nargs) { memcpy(ta_data->buffer->data + ta_data->byte_offset, str, to_write); } - jsval_t result = js_mkobj(js); + ant_value_t result = js_mkobj(js); js_set(js, result, "read", js_mknum((double)to_write)); js_set(js, result, "written", js_mknum((double)to_write)); return result; } -static jsval_t js_textencoder_constructor(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_textencoder_constructor(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; - jsval_t obj = js_mkobj(js); + ant_value_t obj = js_mkobj(js); js_set(js, obj, "encoding", js_mkstr(js, "utf-8", 5)); js_set(js, obj, "encode", js_mkfun(js_textencoder_encode)); js_set(js, obj, "encodeInto", js_mkfun(js_textencoder_encodeInto)); @@ -95,12 +95,12 @@ static jsval_t js_textencoder_constructor(ant_t *js, jsval_t *args, int nargs) { } // TextDecoder.prototype.decode(bufferSource) -static jsval_t js_textdecoder_decode(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_textdecoder_decode(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) { return js_mkstr(js, "", 0); } - jsval_t ta_data_val = js_get_slot(js, args[0], SLOT_BUFFER); + ant_value_t ta_data_val = js_get_slot(js, args[0], SLOT_BUFFER); TypedArrayData *ta_data = (TypedArrayData *)js_gettypedarray(ta_data_val); if (ta_data) { if (!ta_data->buffer) return js_mkstr(js, "", 0); @@ -109,7 +109,7 @@ static jsval_t js_textdecoder_decode(ant_t *js, jsval_t *args, int nargs) { return js_mkstr(js, (const char *)data, len); } - jsval_t ab_data_val = js_get_slot(js, args[0], SLOT_BUFFER); + ant_value_t ab_data_val = js_get_slot(js, args[0], SLOT_BUFFER); if (vtype(ab_data_val) == T_NUM) { ArrayBufferData *ab_data = (ArrayBufferData *)(uintptr_t)js_getnum(ab_data_val); if (!ab_data || !ab_data->data) return js_mkstr(js, "", 0); @@ -119,7 +119,7 @@ static jsval_t js_textdecoder_decode(ant_t *js, jsval_t *args, int nargs) { return js_mkstr(js, "", 0); } -static jsval_t js_textdecoder_constructor(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_textdecoder_constructor(ant_t *js, ant_value_t *args, int nargs) { const char *encoding = "utf-8"; size_t encoding_len = 5; @@ -131,7 +131,7 @@ static jsval_t js_textdecoder_constructor(ant_t *js, jsval_t *args, int nargs) { ) { encoding = "utf-8"; encoding_len = 5; } } - jsval_t obj = js_mkobj(js); + ant_value_t obj = js_mkobj(js); js_set(js, obj, "encoding", js_mkstr(js, encoding, encoding_len)); js_set(js, obj, "fatal", js_false); js_set(js, obj, "ignoreBOM", js_false); @@ -143,10 +143,10 @@ static jsval_t js_textdecoder_constructor(ant_t *js, jsval_t *args, int nargs) { void init_textcodec_module(void) { ant_t *js = rt->js; - jsval_t glob = js_glob(js); + ant_value_t glob = js_glob(js); - jsval_t textencoder_constructor = js_mkfun(js_textencoder_constructor); - jsval_t textencoder_proto = js_mkobj(js); + ant_value_t textencoder_constructor = js_mkfun(js_textencoder_constructor); + ant_value_t textencoder_proto = js_mkobj(js); js_set(js, textencoder_proto, "encode", js_mkfun(js_textencoder_encode)); js_set(js, textencoder_proto, "encodeInto", js_mkfun(js_textencoder_encodeInto)); @@ -154,8 +154,8 @@ void init_textcodec_module(void) { js_set(js, textencoder_constructor, "prototype", textencoder_proto); js_set(js, glob, "TextEncoder", textencoder_constructor); - jsval_t textdecoder_constructor = js_mkfun(js_textdecoder_constructor); - jsval_t textdecoder_proto = js_mkobj(js); + ant_value_t textdecoder_constructor = js_mkfun(js_textdecoder_constructor); + ant_value_t textdecoder_proto = js_mkobj(js); js_set(js, textdecoder_proto, "decode", js_mkfun(js_textdecoder_decode)); js_set(js, textdecoder_proto, "encoding", js_mkstr(js, "utf-8", 5)); diff --git a/src/modules/timer.c b/src/modules/timer.c index a144048..dbf4ed4 100644 --- a/src/modules/timer.c +++ b/src/modules/timer.c @@ -14,8 +14,8 @@ typedef struct timer_entry { uv_timer_t handle; - jsval_t callback; - jsval_t *args; + ant_value_t callback; + ant_value_t *args; int nargs; int timer_id; int active; @@ -26,13 +26,13 @@ typedef struct timer_entry { } timer_entry_t; typedef struct microtask_entry { - jsval_t callback; + ant_value_t callback; uint32_t promise_id; struct microtask_entry *next; } microtask_entry_t; typedef struct immediate_entry { - jsval_t callback; + ant_value_t callback; int immediate_id; int active; struct immediate_entry *next; @@ -72,12 +72,12 @@ static int timer_entry_is_registered(timer_entry_t *entry) { return 0; } -static int timer_copy_args(timer_entry_t *entry, jsval_t *args, int nargs) { +static int timer_copy_args(timer_entry_t *entry, ant_value_t *args, int nargs) { entry->nargs = nargs > 2 ? nargs - 2 : 0; if (entry->nargs > 0) { - entry->args = ant_calloc(sizeof(jsval_t) * entry->nargs); + entry->args = ant_calloc(sizeof(ant_value_t) * entry->nargs); if (!entry->args) return -1; - memcpy(entry->args, args + 2, sizeof(jsval_t) * entry->nargs); + memcpy(entry->args, args + 2, sizeof(ant_value_t) * entry->nargs); } else entry->args = NULL; return 0; } @@ -121,12 +121,12 @@ static void timer_callback(uv_timer_t *handle) { } // setTimeout(callback, delay, ...args) -static jsval_t js_set_timeout(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_set_timeout(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) { return js_mkerr(js, "setTimeout requires 2 arguments (callback, delay)"); } - jsval_t callback = args[0]; + ant_value_t callback = args[0]; double delay_ms = js_getnum(args[1]); uint64_t ms = delay_ms < 1 ? 0 : (uint64_t)delay_ms; @@ -154,12 +154,12 @@ static jsval_t js_set_timeout(ant_t *js, jsval_t *args, int nargs) { } // setInterval(callback, delay, ...args) -static jsval_t js_set_interval(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_set_interval(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) { return js_mkerr(js, "setInterval requires 2 arguments (callback, delay)"); } - jsval_t callback = args[0]; + ant_value_t callback = args[0]; double delay_ms = js_getnum(args[1]); uint64_t ms = delay_ms < 1 ? 1 : (uint64_t)delay_ms; @@ -187,7 +187,7 @@ static jsval_t js_set_interval(ant_t *js, jsval_t *args, int nargs) { } // clearTimeout(timerId) -static jsval_t js_clear_timeout(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_clear_timeout(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkundef(); int timer_id = (int)js_getnum(args[0]); @@ -204,12 +204,12 @@ static jsval_t js_clear_timeout(ant_t *js, jsval_t *args, int nargs) { } // setImmediate(callback) -static jsval_t js_set_immediate(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_set_immediate(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) { return js_mkerr(js, "setImmediate requires 1 argument (callback)"); } - jsval_t callback = args[0]; + ant_value_t callback = args[0]; immediate_entry_t *entry = ant_calloc(sizeof(immediate_entry_t)); if (entry == NULL) { @@ -233,7 +233,7 @@ static jsval_t js_set_immediate(ant_t *js, jsval_t *args, int nargs) { } // clearImmediate(immediateId) -static jsval_t js_clear_immediate(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_clear_immediate(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkundef(); int immediate_id = (int)js_getnum(args[0]); @@ -245,7 +245,7 @@ static jsval_t js_clear_immediate(ant_t *js, jsval_t *args, int nargs) { } // queueMicrotask(callback) -static jsval_t js_queue_microtask(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_queue_microtask(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) { return js_mkerr(js, "queueMicrotask requires 1 argument (callback)"); } @@ -254,7 +254,7 @@ static jsval_t js_queue_microtask(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -void queue_microtask(ant_t *js, jsval_t callback) { +void queue_microtask(ant_t *js, ant_value_t callback) { microtask_entry_t *entry = ant_calloc(sizeof(microtask_entry_t)); if (entry == NULL) return; @@ -300,7 +300,7 @@ void process_microtasks(ant_t *js) { if (entry->promise_id != 0) { js_process_promise_handlers(js, entry->promise_id); } else { - jsval_t args[0]; + ant_value_t args[0]; sv_vm_call(js->vm, js, entry->callback, js_mkundef(), args, 0, NULL, false); } @@ -320,7 +320,7 @@ void process_immediates(ant_t *js) { } if (entry->active) { - jsval_t args[0]; + ant_value_t args[0]; sv_vm_call(js->vm, js, entry->callback, js_mkundef(), args, 0, NULL, false); process_microtasks(js); } @@ -349,7 +349,7 @@ void init_timer_module() { ant_t *js = rt->js; timer_state.js = js; - jsval_t global = js_glob(js); + ant_value_t global = js_glob(js); js_set(js, global, "setTimeout", js_mkfun(js_set_timeout)); js_set(js, global, "clearTimeout", js_mkfun(js_clear_timeout)); diff --git a/src/modules/tty.c b/src/modules/tty.c index e3bc9b4..a3b226e 100644 --- a/src/modules/tty.c +++ b/src/modules/tty.c @@ -40,12 +40,12 @@ #include "modules/symbol.h" #include "modules/tty.h" -static inline bool is_callable(jsval_t value) { +static inline bool is_callable(ant_value_t value) { uint8_t t = vtype(value); return t == T_FUNC || t == T_CFUNC; } -static bool parse_int(jsval_t value, int *out) { +static bool parse_int(ant_value_t value, int *out) { if (vtype(value) != T_NUM) return false; double d = js_getnum(value); if (!isfinite(d)) return false; @@ -56,7 +56,7 @@ static bool parse_int(jsval_t value, int *out) { return true; } -static bool parse_fd(jsval_t value, int *fd_out) { +static bool parse_fd(ant_value_t value, int *fd_out) { int fd = 0; if (!parse_int(value, &fd)) return false; if (fd < 0) return false; @@ -70,10 +70,10 @@ static bool is_tty_fd(int fd) { } static int stream_fd_from_this(ant_t *js, int fallback_fd) { - jsval_t this_obj = js_getthis(js); + ant_value_t this_obj = js_getthis(js); if (!is_special_object(this_obj)) return fallback_fd; - jsval_t fd_val = js_get(js, this_obj, "fd"); + ant_value_t fd_val = js_get(js, this_obj, "fd"); int fd = 0; if (!parse_fd(fd_val, &fd)) return fallback_fd; return fd; @@ -177,17 +177,17 @@ static bool str_case_contains(const char *haystack, const char *needle) { static bool read_env_object_value( ant_t *js, - jsval_t env_obj, + ant_value_t env_obj, const char *key, char *buf, size_t buf_len ) { if (!is_special_object(env_obj) || !key || !buf || buf_len == 0) return false; - jsval_t value = js_get(js, env_obj, key); + ant_value_t value = js_get(js, env_obj, key); if (vtype(value) == T_UNDEF || vtype(value) == T_NULL) return false; - jsval_t str_val = js_tostring_val(js, value); + ant_value_t str_val = js_tostring_val(js, value); size_t len = 0; char *str = js_getstr(js, str_val, &len); if (!str) return false; @@ -200,7 +200,7 @@ static bool read_env_object_value( static const char *get_env_value( ant_t *js, - jsval_t env_obj, + ant_value_t env_obj, const char *key, char *buf, size_t buf_len @@ -219,7 +219,7 @@ static int force_color_depth(const char *force_color) { return 4; } -static int detect_color_depth(ant_t *js, int fd, jsval_t env_obj) { +static int detect_color_depth(ant_t *js, int fd, ant_value_t env_obj) { if (!is_tty_fd(fd)) return 1; char scratch[128]; @@ -266,20 +266,20 @@ static int palette_size_for_depth(int depth) { } } -static jsval_t make_stream_error(ant_t *js, const char *op, int fd) { +static ant_value_t make_stream_error(ant_t *js, const char *op, int fd) { return js_mkerr_typed(js, JS_ERR_GENERIC, "tty stream %s failed for fd %d", op, fd); } -static void invoke_callback_if_needed(ant_t *js, jsval_t cb, jsval_t arg) { +static void invoke_callback_if_needed(ant_t *js, ant_value_t cb, ant_value_t arg) { if (!is_callable(cb)) return; - jsval_t cb_args[1] = { arg }; + ant_value_t cb_args[1] = { arg }; sv_vm_call(js->vm, js, cb, js_mkundef(), cb_args, 1, NULL, false); } -static jsval_t maybe_callback_or_throw( +static ant_value_t maybe_callback_or_throw( ant_t *js, - jsval_t this_obj, - jsval_t cb, + ant_value_t this_obj, + ant_value_t cb, bool ok, const char *op, int fd @@ -288,7 +288,7 @@ static jsval_t maybe_callback_or_throw( if (ok) { invoke_callback_if_needed(js, cb, js_mknull()); } else { - jsval_t err = make_stream_error(js, op, fd); + ant_value_t err = make_stream_error(js, op, fd); invoke_callback_if_needed(js, cb, err); } return this_obj; @@ -351,22 +351,22 @@ static bool set_raw_mode_fd(int fd, bool enable) { #endif } -static jsval_t get_process_stream(ant_t *js, const char *name) { - jsval_t process_obj = js_get(js, js_glob(js), "process"); +static ant_value_t get_process_stream(ant_t *js, const char *name) { + ant_value_t process_obj = js_get(js, js_glob(js), "process"); if (!is_special_object(process_obj)) return js_mkundef(); - jsval_t stream = js_get(js, process_obj, name); + ant_value_t stream = js_get(js, process_obj, name); if (!is_special_object(stream)) return js_mkundef(); return stream; } -static void ensure_stream_common_props(ant_t *js, jsval_t stream, int fd) { +static void ensure_stream_common_props(ant_t *js, ant_value_t stream, int fd) { if (!is_special_object(stream)) return; js_set(js, stream, "fd", js_mknum((double)fd)); js_set(js, stream, "isTTY", js_bool(is_tty_fd(fd))); } -static jsval_t tty_isatty(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t tty_isatty(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_false; int fd = 0; @@ -374,15 +374,15 @@ static jsval_t tty_isatty(ant_t *js, jsval_t *args, int nargs) { return js_bool(ANT_ISATTY(fd) != 0); } -static jsval_t tty_stream_write(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t tty_stream_write(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 1) return js_false; size_t len = 0; char *data = js_getstr(js, args[0], &len); if (!data) return js_false; - jsval_t cb = js_mkundef(); + ant_value_t cb = js_mkundef(); if (nargs > 1 && is_callable(args[1])) cb = args[1]; int fd = stream_fd_from_this(js, ANT_STDOUT_FD); @@ -398,7 +398,7 @@ static jsval_t tty_stream_write(ant_t *js, jsval_t *args, int nargs) { return js_true; } -static jsval_t tty_write_stream_rows_getter(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t tty_write_stream_rows_getter(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; int fd = stream_fd_from_this(js, ANT_STDOUT_FD); @@ -410,7 +410,7 @@ static jsval_t tty_write_stream_rows_getter(ant_t *js, jsval_t *args, int nargs) return js_mknum((double)rows); } -static jsval_t tty_write_stream_columns_getter(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t tty_write_stream_columns_getter(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; int fd = stream_fd_from_this(js, ANT_STDOUT_FD); @@ -422,7 +422,7 @@ static jsval_t tty_write_stream_columns_getter(ant_t *js, jsval_t *args, int nar return js_mknum((double)cols); } -static jsval_t tty_write_stream_get_window_size(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t tty_write_stream_get_window_size(ant_t *js, ant_value_t *args, int nargs) { (void)args; (void)nargs; int fd = stream_fd_from_this(js, ANT_STDOUT_FD); @@ -430,21 +430,21 @@ static jsval_t tty_write_stream_get_window_size(ant_t *js, jsval_t *args, int na int cols = 0; get_tty_size(fd, &rows, &cols); - jsval_t arr = js_mkarr(js); + ant_value_t arr = js_mkarr(js); js_arr_push(js, arr, js_mknum((double)cols)); js_arr_push(js, arr, js_mknum((double)rows)); return arr; } -static jsval_t tty_write_stream_clear_line(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t tty_write_stream_clear_line(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); int dir = 0; if (nargs > 0 && vtype(args[0]) != T_UNDEF && !parse_int(args[0], &dir)) { return js_mkerr_typed(js, JS_ERR_TYPE, "clearLine(dir) requires a numeric dir"); } - jsval_t cb = js_mkundef(); + ant_value_t cb = js_mkundef(); if (nargs > 1 && is_callable(args[1])) cb = args[1]; const char *seq = "\033[2K\r"; @@ -456,10 +456,10 @@ static jsval_t tty_write_stream_clear_line(ant_t *js, jsval_t *args, int nargs) return maybe_callback_or_throw(js, this_obj, cb, ok, "clearLine", fd); } -static jsval_t tty_write_stream_clear_screen_down(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t tty_write_stream_clear_screen_down(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); - jsval_t cb = js_mkundef(); + ant_value_t cb = js_mkundef(); if (nargs > 0 && is_callable(args[0])) cb = args[0]; static const char seq[] = "\033[0J"; @@ -468,8 +468,8 @@ static jsval_t tty_write_stream_clear_screen_down(ant_t *js, jsval_t *args, int return maybe_callback_or_throw(js, this_obj, cb, ok, "clearScreenDown", fd); } -static jsval_t tty_write_stream_cursor_to(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t tty_write_stream_cursor_to(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 1 || !parse_int(args[0], &(int){0})) { return js_mkerr_typed(js, JS_ERR_TYPE, "cursorTo(x[, y][, callback]) requires numeric x"); } @@ -480,7 +480,7 @@ static jsval_t tty_write_stream_cursor_to(ant_t *js, jsval_t *args, int nargs) { bool has_y = false; int y = 0; - jsval_t cb = js_mkundef(); + ant_value_t cb = js_mkundef(); if (nargs > 1) { if (is_callable(args[1])) { @@ -508,8 +508,8 @@ static jsval_t tty_write_stream_cursor_to(ant_t *js, jsval_t *args, int nargs) { return maybe_callback_or_throw(js, this_obj, cb, ok, "cursorTo", fd); } -static jsval_t tty_write_stream_move_cursor(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t tty_write_stream_move_cursor(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (nargs < 2) { return js_mkerr_typed(js, JS_ERR_TYPE, "moveCursor(dx, dy[, callback]) requires dx and dy"); } @@ -520,7 +520,7 @@ static jsval_t tty_write_stream_move_cursor(ant_t *js, jsval_t *args, int nargs) return js_mkerr_typed(js, JS_ERR_TYPE, "moveCursor(dx, dy[, callback]) requires numeric dx and dy"); } - jsval_t cb = js_mkundef(); + ant_value_t cb = js_mkundef(); if (nargs > 2 && is_callable(args[2])) cb = args[2]; int fd = stream_fd_from_this(js, ANT_STDOUT_FD); @@ -547,8 +547,8 @@ static jsval_t tty_write_stream_move_cursor(ant_t *js, jsval_t *args, int nargs) return maybe_callback_or_throw(js, this_obj, cb, ok, "moveCursor", fd); } -static jsval_t tty_write_stream_get_color_depth(ant_t *js, jsval_t *args, int nargs) { - jsval_t env_obj = js_mkundef(); +static ant_value_t tty_write_stream_get_color_depth(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t env_obj = js_mkundef(); if (nargs > 0 && is_special_object(args[0])) env_obj = args[0]; int fd = stream_fd_from_this(js, ANT_STDOUT_FD); @@ -556,9 +556,9 @@ static jsval_t tty_write_stream_get_color_depth(ant_t *js, jsval_t *args, int na return js_mknum((double)depth); } -static jsval_t tty_write_stream_has_colors(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t tty_write_stream_has_colors(ant_t *js, ant_value_t *args, int nargs) { int count = 16; - jsval_t env_obj = js_mkundef(); + ant_value_t env_obj = js_mkundef(); if (nargs > 0) { if (vtype(args[0]) == T_NUM) { @@ -583,23 +583,23 @@ static jsval_t tty_write_stream_has_colors(ant_t *js, jsval_t *args, int nargs) return js_bool(max_colors >= count); } -static jsval_t tty_read_stream_set_raw_mode(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t tty_read_stream_set_raw_mode(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (!is_special_object(this_obj)) { return js_mkerr_typed(js, JS_ERR_TYPE, "setRawMode() requires a ReadStream receiver"); } bool enable = nargs > 0 ? js_truthy(js, args[0]) : true; - jsval_t native_fn = js_get(js, this_obj, "__antNativeSetRawMode"); + ant_value_t native_fn = js_get(js, this_obj, "__antNativeSetRawMode"); if (is_callable(native_fn)) { - jsval_t call_args[1]; + ant_value_t call_args[1]; int call_nargs = 0; if (nargs > 0) { call_args[0] = args[0]; call_nargs = 1; } - jsval_t result = sv_vm_call( + ant_value_t result = sv_vm_call( js->vm, js, native_fn, this_obj, call_nargs > 0 ? call_args : NULL, call_nargs, NULL, false @@ -617,7 +617,7 @@ static jsval_t tty_read_stream_set_raw_mode(ant_t *js, jsval_t *args, int nargs) return this_obj; } -static jsval_t tty_read_stream_constructor(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t tty_read_stream_constructor(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr_typed(js, JS_ERR_TYPE, "ReadStream(fd) requires a file descriptor"); int fd = 0; @@ -629,7 +629,7 @@ static jsval_t tty_read_stream_constructor(ant_t *js, jsval_t *args, int nargs) } if (fd == ANT_STDIN_FD) { - jsval_t stdin_obj = get_process_stream(js, "stdin"); + ant_value_t stdin_obj = get_process_stream(js, "stdin"); if (is_special_object(stdin_obj)) { ensure_stream_common_props(js, stdin_obj, fd); if (vtype(js_get(js, stdin_obj, "isRaw")) == T_UNDEF) js_set(js, stdin_obj, "isRaw", js_false); @@ -637,9 +637,9 @@ static jsval_t tty_read_stream_constructor(ant_t *js, jsval_t *args, int nargs) } } - jsval_t ctor = js_getcurrentfunc(js); - jsval_t proto = js_get(js, ctor, "prototype"); - jsval_t obj = js_mkobj(js); + ant_value_t ctor = js_getcurrentfunc(js); + ant_value_t proto = js_get(js, ctor, "prototype"); + ant_value_t obj = js_mkobj(js); if (is_special_object(proto)) js_set_proto(js, obj, proto); ensure_stream_common_props(js, obj, fd); @@ -647,7 +647,7 @@ static jsval_t tty_read_stream_constructor(ant_t *js, jsval_t *args, int nargs) return obj; } -static jsval_t tty_write_stream_constructor(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t tty_write_stream_constructor(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr_typed(js, JS_ERR_TYPE, "WriteStream(fd) requires a file descriptor"); int fd = 0; @@ -659,29 +659,29 @@ static jsval_t tty_write_stream_constructor(ant_t *js, jsval_t *args, int nargs) } if (fd == ANT_STDOUT_FD || fd == ANT_STDERR_FD) { - jsval_t stream = get_process_stream(js, fd == ANT_STDOUT_FD ? "stdout" : "stderr"); + ant_value_t stream = get_process_stream(js, fd == ANT_STDOUT_FD ? "stdout" : "stderr"); if (is_special_object(stream)) { ensure_stream_common_props(js, stream, fd); return stream; } } - jsval_t ctor = js_getcurrentfunc(js); - jsval_t proto = js_get(js, ctor, "prototype"); - jsval_t obj = js_mkobj(js); + ant_value_t ctor = js_getcurrentfunc(js); + ant_value_t proto = js_get(js, ctor, "prototype"); + ant_value_t obj = js_mkobj(js); if (is_special_object(proto)) js_set_proto(js, obj, proto); ensure_stream_common_props(js, obj, fd); return obj; } -static void setup_readstream_proto(ant_t *js, jsval_t proto) { +static void setup_readstream_proto(ant_t *js, ant_value_t proto) { if (!is_special_object(proto)) return; js_set(js, proto, "setRawMode", js_mkfun(tty_read_stream_set_raw_mode)); js_set_sym(js, proto, get_toStringTag_sym(), js_mkstr(js, "ReadStream", 10)); } -static void setup_writestream_proto(ant_t *js, jsval_t proto) { +static void setup_writestream_proto(ant_t *js, ant_value_t proto) { if (!is_special_object(proto)) return; js_set(js, proto, "write", js_mkfun(tty_stream_write)); @@ -701,17 +701,17 @@ void init_tty_module(void) { ant_t *js = rt->js; if (!js) return; - jsval_t process_obj = js_get(js, js_glob(js), "process"); + ant_value_t process_obj = js_get(js, js_glob(js), "process"); if (!is_special_object(process_obj)) return; - jsval_t stdin_obj = js_get(js, process_obj, "stdin"); + ant_value_t stdin_obj = js_get(js, process_obj, "stdin"); if (is_special_object(stdin_obj)) { ensure_stream_common_props(js, stdin_obj, ANT_STDIN_FD); if (vtype(js_get(js, stdin_obj, "isRaw")) == T_UNDEF) js_set(js, stdin_obj, "isRaw", js_false); - jsval_t stdin_proto = js_get_proto(js, stdin_obj); + ant_value_t stdin_proto = js_get_proto(js, stdin_obj); if (is_special_object(stdin_proto)) { - jsval_t native_set_raw = js_get(js, stdin_proto, "setRawMode"); + ant_value_t native_set_raw = js_get(js, stdin_proto, "setRawMode"); if (is_callable(native_set_raw)) { js_set(js, stdin_proto, "__antNativeSetRawMode", native_set_raw); } @@ -719,38 +719,38 @@ void init_tty_module(void) { } } - jsval_t stdout_obj = js_get(js, process_obj, "stdout"); + ant_value_t stdout_obj = js_get(js, process_obj, "stdout"); if (is_special_object(stdout_obj)) { ensure_stream_common_props(js, stdout_obj, ANT_STDOUT_FD); js_set_getter_desc(js, stdout_obj, "rows", 4, js_mkfun(tty_write_stream_rows_getter), JS_DESC_E | JS_DESC_C); js_set_getter_desc(js, stdout_obj, "columns", 7, js_mkfun(tty_write_stream_columns_getter), JS_DESC_E | JS_DESC_C); - jsval_t stdout_proto = js_get_proto(js, stdout_obj); + ant_value_t stdout_proto = js_get_proto(js, stdout_obj); setup_writestream_proto(js, stdout_proto); } - jsval_t stderr_obj = js_get(js, process_obj, "stderr"); + ant_value_t stderr_obj = js_get(js, process_obj, "stderr"); if (is_special_object(stderr_obj)) { ensure_stream_common_props(js, stderr_obj, ANT_STDERR_FD); js_set_getter_desc(js, stderr_obj, "rows", 4, js_mkfun(tty_write_stream_rows_getter), JS_DESC_E | JS_DESC_C); js_set_getter_desc(js, stderr_obj, "columns", 7, js_mkfun(tty_write_stream_columns_getter), JS_DESC_E | JS_DESC_C); - jsval_t stderr_proto = js_get_proto(js, stderr_obj); + ant_value_t stderr_proto = js_get_proto(js, stderr_obj); setup_writestream_proto(js, stderr_proto); } } -jsval_t tty_library(ant_t *js) { - jsval_t lib = js_mkobj(js); +ant_value_t tty_library(ant_t *js) { + ant_value_t lib = js_mkobj(js); - jsval_t read_ctor = js_mkfun(tty_read_stream_constructor); - jsval_t read_proto = js_mkobj(js); + ant_value_t read_ctor = js_mkfun(tty_read_stream_constructor); + ant_value_t read_proto = js_mkobj(js); setup_readstream_proto(js, read_proto); js_set(js, read_proto, "constructor", read_ctor); js_set(js, read_ctor, "prototype", read_proto); - jsval_t write_ctor = js_mkfun(tty_write_stream_constructor); - jsval_t write_proto = js_mkobj(js); + ant_value_t write_ctor = js_mkfun(tty_write_stream_constructor); + ant_value_t write_proto = js_mkobj(js); setup_writestream_proto(js, write_proto); js_set(js, write_proto, "constructor", write_ctor); js_set(js, write_ctor, "prototype", write_proto); diff --git a/src/modules/uri.c b/src/modules/uri.c index c3825a3..1630e2f 100644 --- a/src/modules/uri.c +++ b/src/modules/uri.c @@ -74,8 +74,8 @@ static int decode_escape_sequence(const char *str, size_t len, size_t *pos, unsi } // encodeURIComponent() -static jsval_t js_encodeURIComponent(ant_t *js, jsval_t *args, int nargs) { - jsval_t result; +static ant_value_t js_encodeURIComponent(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t result; char *out = NULL; if (nargs < 1) return js_mkstr(js, "undefined", 9); @@ -127,8 +127,8 @@ malformed: } // encodeURI() -static jsval_t js_encodeURI(ant_t *js, jsval_t *args, int nargs) { - jsval_t result; +static ant_value_t js_encodeURI(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t result; char *out = NULL; if (nargs < 1) return js_mkstr(js, "undefined", 9); @@ -180,8 +180,8 @@ malformed: } // decodeURIComponent() -static jsval_t js_decodeURIComponent(ant_t *js, jsval_t *args, int nargs) { - jsval_t result; +static ant_value_t js_decodeURIComponent(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t result; char *out = NULL; if (nargs < 1) return js_mkstr(js, "undefined", 9); @@ -229,8 +229,8 @@ malformed: } // decodeURI() -static jsval_t js_decodeURI(ant_t *js, jsval_t *args, int nargs) { - jsval_t result; +static ant_value_t js_decodeURI(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t result; char *out = NULL; if (nargs < 1) return js_mkstr(js, "undefined", 9); @@ -299,7 +299,7 @@ static int is_escape_unreserved(unsigned char c) { c == '-' || c == '.' || c == '/'; } -static jsval_t js_escape(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_escape(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkstr(js, "undefined", 9); char *str = js_getstr(js, args[0], NULL); @@ -321,12 +321,12 @@ static jsval_t js_escape(ant_t *js, jsval_t *args, int nargs) { } out[out_len] = '\0'; - jsval_t result = js_mkstr(js, out, out_len); + ant_value_t result = js_mkstr(js, out, out_len); free(out); return result; } -static jsval_t js_unescape(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_unescape(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkstr(js, "undefined", 9); char *str = js_getstr(js, args[0], NULL); @@ -353,14 +353,14 @@ static jsval_t js_unescape(ant_t *js, jsval_t *args, int nargs) { } out[out_len] = '\0'; - jsval_t result = js_mkstr(js, out, out_len); + ant_value_t result = js_mkstr(js, out, out_len); free(out); return result; } void init_uri_module(void) { ant_t *js = rt->js; - jsval_t glob = js_glob(js); + ant_value_t glob = js_glob(js); js_set(js, glob, "encodeURI", js_mkfun(js_encodeURI)); js_set(js, glob, "encodeURIComponent", js_mkfun(js_encodeURIComponent)); diff --git a/src/modules/url.c b/src/modules/url.c index fe83629..eeabdde 100644 --- a/src/modules/url.c +++ b/src/modules/url.c @@ -139,10 +139,10 @@ static void uri_to_parsed(const UriUriA *uri, parsed_url_t *out) { free(frag); } -static const char *coerce_to_string(ant_t *js, jsval_t val, size_t *len) { +static const char *coerce_to_string(ant_t *js, ant_value_t val, size_t *len) { if (vtype(val) == T_STR) return js_getstr(js, val, len); if (is_object_type(val)) { - jsval_t href = js_get(js, val, "href"); + ant_value_t href = js_get(js, val, "href"); if (vtype(href) == T_STR) return js_getstr(js, href, len); } return NULL; @@ -252,7 +252,7 @@ static char *build_href( return href; } -static void update_url_href(ant_t *js, jsval_t url_obj) { +static void update_url_href(ant_t *js, ant_value_t url_obj) { char *protocol = js_getstr(js, js_get(js, url_obj, "protocol"), NULL); char *username = js_getstr(js, js_get(js, url_obj, "username"), NULL); char *password = js_getstr(js, js_get(js, url_obj, "password"), NULL); @@ -298,16 +298,16 @@ static void update_url_href(ant_t *js, jsval_t url_obj) { free(href); } -static jsval_t url_toString(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t url_toString(ant_t *js, ant_value_t *args, int nargs) { return js_get(js, js_getthis(js), "href"); } -static jsval_t js_URLSearchParams(ant_t *js, jsval_t *args, int nargs) { - jsval_t usp = js_mkobj(js); - jsval_t proto = js_get_ctor_proto(js, "URLSearchParams", 15); +static ant_value_t js_URLSearchParams(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t usp = js_mkobj(js); + ant_value_t proto = js_get_ctor_proto(js, "URLSearchParams", 15); if (is_special_object(proto)) js_set_proto(js, usp, proto); - jsval_t entries = js_mkarr(js); + ant_value_t entries = js_mkarr(js); js_set_slot(js, usp, SLOT_ENTRIES, entries); if (nargs < 1 || vtype(args[0]) != T_STR) return usp; @@ -326,7 +326,7 @@ parse_pair: char *key = pair, *val = eq ? (eq[0] = '\0', eq + 1) : ""; char *dk = url_decode_component(key); char *dv = url_decode_component(val); - jsval_t entry = js_mkarr(js); + ant_value_t entry = js_mkarr(js); js_arr_push(js, entry, js_mkstr(js, dk, strlen(dk))); js_arr_push(js, entry, js_mkstr(js, dv, strlen(dv))); js_arr_push(js, entries, entry); @@ -336,7 +336,7 @@ parse_pair: goto parse_pair; } -static jsval_t js_URL(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t js_URL(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "TypeError: URL requires at least 1 argument"); char *url_str = js_getstr(js, args[0], NULL); @@ -348,8 +348,8 @@ static jsval_t js_URL(ant_t *js, jsval_t *args, int nargs) { return js_mkerr(js, "TypeError: Invalid URL"); } - jsval_t url_obj = js_mkobj(js); - jsval_t proto = js_get_ctor_proto(js, "URL", 3); + ant_value_t url_obj = js_mkobj(js); + ant_value_t proto = js_get_ctor_proto(js, "URL", 3); if (is_special_object(proto)) js_set_proto(js, url_obj, proto); js_set(js, url_obj, "protocol", js_mkstr(js, parsed.protocol, strlen(parsed.protocol))); @@ -363,14 +363,14 @@ static jsval_t js_URL(ant_t *js, jsval_t *args, int nargs) { update_url_href(js, url_obj); - jsval_t search_params = js_mkobj(js); - jsval_t usp_proto = js_get_ctor_proto(js, "URLSearchParams", 15); + ant_value_t search_params = js_mkobj(js); + ant_value_t usp_proto = js_get_ctor_proto(js, "URLSearchParams", 15); if (is_special_object(usp_proto)) js_set_proto(js, search_params, usp_proto); js_set_slot(js, search_params, SLOT_DATA, url_obj); if (parsed.search && *parsed.search) { const char *qs = parsed.search[0] == '?' ? parsed.search + 1 : parsed.search; - jsval_t arg = js_mkstr(js, qs, strlen(qs)); - jsval_t tmp = js_URLSearchParams(js, &arg, 1); + ant_value_t arg = js_mkstr(js, qs, strlen(qs)); + ant_value_t tmp = js_URLSearchParams(js, &arg, 1); js_set_slot(js, search_params, SLOT_ENTRIES, js_get_slot(js, tmp, SLOT_ENTRIES)); } else { js_set_slot(js, search_params, SLOT_ENTRIES, js_mkarr(js)); @@ -381,19 +381,19 @@ static jsval_t js_URL(ant_t *js, jsval_t *args, int nargs) { return url_obj; } -static jsval_t usp_get(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t usp_get(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mknull(); - jsval_t this_val = js_getthis(js); + ant_value_t this_val = js_getthis(js); char *key = js_getstr(js, args[0], NULL); if (!key) return js_mknull(); - jsval_t entries = js_get_slot(js, this_val, SLOT_ENTRIES); + ant_value_t entries = js_get_slot(js, this_val, SLOT_ENTRIES); if (!is_special_object(entries)) return js_mknull(); - jsoff_t len = js_arr_len(js, entries); - for (jsoff_t i = 0; i < len; i++) { - jsval_t entry = js_arr_get(js, entries, i); + ant_offset_t len = js_arr_len(js, entries); + for (ant_offset_t i = 0; i < len; i++) { + ant_value_t entry = js_arr_get(js, entries, i); char *ks = js_getstr(js, js_arr_get(js, entry, 0), NULL); if (ks && strcmp(ks, key) == 0) return js_arr_get(js, entry, 1); } @@ -401,20 +401,20 @@ static jsval_t usp_get(ant_t *js, jsval_t *args, int nargs) { return js_mknull(); } -static jsval_t usp_getAll(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t usp_getAll(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkarr(js); - jsval_t this_val = js_getthis(js); + ant_value_t this_val = js_getthis(js); char *key = js_getstr(js, args[0], NULL); if (!key) return js_mkarr(js); - jsval_t result = js_mkarr(js); - jsval_t entries = js_get_slot(js, this_val, SLOT_ENTRIES); + ant_value_t result = js_mkarr(js); + ant_value_t entries = js_get_slot(js, this_val, SLOT_ENTRIES); if (!is_special_object(entries)) return result; - jsoff_t len = js_arr_len(js, entries); - for (jsoff_t i = 0; i < len; i++) { - jsval_t entry = js_arr_get(js, entries, i); + ant_offset_t len = js_arr_len(js, entries); + for (ant_offset_t i = 0; i < len; i++) { + ant_value_t entry = js_arr_get(js, entries, i); char *ks = js_getstr(js, js_arr_get(js, entry, 0), NULL); if (ks && strcmp(ks, key) == 0) js_arr_push(js, result, js_arr_get(js, entry, 1)); } @@ -422,19 +422,19 @@ static jsval_t usp_getAll(ant_t *js, jsval_t *args, int nargs) { return result; } -static jsval_t usp_has(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t usp_has(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_false; - jsval_t this_val = js_getthis(js); + ant_value_t this_val = js_getthis(js); char *key = js_getstr(js, args[0], NULL); if (!key) return js_false; - jsval_t entries = js_get_slot(js, this_val, SLOT_ENTRIES); + ant_value_t entries = js_get_slot(js, this_val, SLOT_ENTRIES); if (!is_special_object(entries)) return js_false; - jsoff_t len = js_arr_len(js, entries); - for (jsoff_t i = 0; i < len; i++) { - jsval_t entry = js_arr_get(js, entries, i); + ant_offset_t len = js_arr_len(js, entries); + for (ant_offset_t i = 0; i < len; i++) { + ant_value_t entry = js_arr_get(js, entries, i); char *ks = js_getstr(js, js_arr_get(js, entry, 0), NULL); if (ks && strcmp(ks, key) == 0) return js_true; } @@ -442,19 +442,19 @@ static jsval_t usp_has(ant_t *js, jsval_t *args, int nargs) { return js_false; } -static void usp_sync_url(ant_t *js, jsval_t this_val) { - jsval_t url_obj = js_get_slot(js, this_val, SLOT_DATA); +static void usp_sync_url(ant_t *js, ant_value_t this_val) { + ant_value_t url_obj = js_get_slot(js, this_val, SLOT_DATA); if (!is_special_object(url_obj)) return; - jsval_t entries = js_get_slot(js, this_val, SLOT_ENTRIES); - jsoff_t len = js_arr_len(js, entries); + ant_value_t entries = js_get_slot(js, this_val, SLOT_ENTRIES); + ant_offset_t len = js_arr_len(js, entries); size_t buf_size = 1024; char *buf = try_oom(buf_size); size_t pos = 0; - for (jsoff_t i = 0; i < len; i++) { - jsval_t entry = js_arr_get(js, entries, i); + for (ant_offset_t i = 0; i < len; i++) { + ant_value_t entry = js_arr_get(js, entries, i); char *k = js_getstr(js, js_arr_get(js, entry, 0), NULL); char *v = js_getstr(js, js_arr_get(js, entry, 1), NULL); if (!k) continue; @@ -480,25 +480,25 @@ static void usp_sync_url(ant_t *js, jsval_t this_val) { free(buf); } -static jsval_t usp_set(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t usp_set(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkundef(); - jsval_t this_val = js_getthis(js); + ant_value_t this_val = js_getthis(js); char *key = js_getstr(js, args[0], NULL); if (!key) return js_mkundef(); - jsval_t entries = js_get_slot(js, this_val, SLOT_ENTRIES); - jsoff_t len = js_arr_len(js, entries); + ant_value_t entries = js_get_slot(js, this_val, SLOT_ENTRIES); + ant_offset_t len = js_arr_len(js, entries); - jsval_t new_entries = js_mkarr(js); + ant_value_t new_entries = js_mkarr(js); int found = 0; - for (jsoff_t i = 0; i < len; i++) { - jsval_t entry = js_arr_get(js, entries, i); + for (ant_offset_t i = 0; i < len; i++) { + ant_value_t entry = js_arr_get(js, entries, i); char *ks = js_getstr(js, js_arr_get(js, entry, 0), NULL); if (ks && strcmp(ks, key) == 0) { if (!found) { - jsval_t new_entry = js_mkarr(js); + ant_value_t new_entry = js_mkarr(js); js_arr_push(js, new_entry, args[0]); js_arr_push(js, new_entry, args[1]); js_arr_push(js, new_entries, new_entry); @@ -508,7 +508,7 @@ static jsval_t usp_set(ant_t *js, jsval_t *args, int nargs) { } if (!found) { - jsval_t new_entry = js_mkarr(js); + ant_value_t new_entry = js_mkarr(js); js_arr_push(js, new_entry, args[0]); js_arr_push(js, new_entry, args[1]); js_arr_push(js, new_entries, new_entry); @@ -520,12 +520,12 @@ static jsval_t usp_set(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t usp_append(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t usp_append(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkundef(); - jsval_t this_val = js_getthis(js); + ant_value_t this_val = js_getthis(js); - jsval_t entries = js_get_slot(js, this_val, SLOT_ENTRIES); - jsval_t entry = js_mkarr(js); + ant_value_t entries = js_get_slot(js, this_val, SLOT_ENTRIES); + ant_value_t entry = js_mkarr(js); js_arr_push(js, entry, args[0]); js_arr_push(js, entry, args[1]); js_arr_push(js, entries, entry); @@ -534,18 +534,18 @@ static jsval_t usp_append(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t usp_delete(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t usp_delete(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkundef(); - jsval_t this_val = js_getthis(js); + ant_value_t this_val = js_getthis(js); char *key = js_getstr(js, args[0], NULL); if (!key) return js_mkundef(); - jsval_t entries = js_get_slot(js, this_val, SLOT_ENTRIES); - jsoff_t len = js_arr_len(js, entries); + ant_value_t entries = js_get_slot(js, this_val, SLOT_ENTRIES); + ant_offset_t len = js_arr_len(js, entries); - jsval_t new_entries = js_mkarr(js); - for (jsoff_t i = 0; i < len; i++) { - jsval_t entry = js_arr_get(js, entries, i); + ant_value_t new_entries = js_mkarr(js); + for (ant_offset_t i = 0; i < len; i++) { + ant_value_t entry = js_arr_get(js, entries, i); char *ks = js_getstr(js, js_arr_get(js, entry, 0), NULL); if (!ks || strcmp(ks, key) != 0) js_arr_push(js, new_entries, entry); } @@ -557,17 +557,17 @@ static jsval_t usp_delete(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } -static jsval_t usp_toString(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_val = js_getthis(js); - jsval_t entries = js_get_slot(js, this_val, SLOT_ENTRIES); - jsoff_t len = js_arr_len(js, entries); +static ant_value_t usp_toString(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_val = js_getthis(js); + ant_value_t entries = js_get_slot(js, this_val, SLOT_ENTRIES); + ant_offset_t len = js_arr_len(js, entries); size_t buf_size = 1024; char *buf = try_oom(buf_size); size_t pos = 0; - for (jsoff_t i = 0; i < len; i++) { - jsval_t entry = js_arr_get(js, entries, i); + for (ant_offset_t i = 0; i < len; i++) { + ant_value_t entry = js_arr_get(js, entries, i); char *k = js_getstr(js, js_arr_get(js, entry, 0), NULL); char *v = js_getstr(js, js_arr_get(js, entry, 1), NULL); if (!k) continue; @@ -589,7 +589,7 @@ static jsval_t usp_toString(ant_t *js, jsval_t *args, int nargs) { } buf[pos] = '\0'; - jsval_t ret = js_mkstr(js, buf, pos); + ant_value_t ret = js_mkstr(js, buf, pos); free(buf); return ret; @@ -597,10 +597,10 @@ static jsval_t usp_toString(ant_t *js, jsval_t *args, int nargs) { void init_url_module(void) { ant_t *js = rt->js; - jsval_t glob = js->global; + ant_value_t glob = js->global; - jsval_t url_ctor = js_mkobj(js); - jsval_t url_proto = js_mkobj(js); + ant_value_t url_ctor = js_mkobj(js); + ant_value_t url_proto = js_mkobj(js); js_set(js, url_proto, "toString", js_mkfun(url_toString)); js_set_sym(js, url_proto, get_toStringTag_sym(), js_mkstr(js, "URL", 3)); @@ -612,8 +612,8 @@ void init_url_module(void) { js_set(js, glob, "URL", js_obj_to_func(url_ctor)); - jsval_t usp_ctor = js_mkobj(js); - jsval_t usp_proto = js_mkobj(js); + ant_value_t usp_ctor = js_mkobj(js); + ant_value_t usp_proto = js_mkobj(js); js_set(js, usp_proto, "get", js_mkfun(usp_get)); js_set(js, usp_proto, "getAll", js_mkfun(usp_getAll)); @@ -632,7 +632,7 @@ void init_url_module(void) { js_set(js, glob, "URLSearchParams", js_obj_to_func(usp_ctor)); } -static jsval_t builtin_fileURLToPath(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_fileURLToPath(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkerr(js, "fileURLToPath requires a string or URL argument"); size_t len; @@ -652,12 +652,12 @@ static jsval_t builtin_fileURLToPath(ant_t *js, jsval_t *args, int nargs) { free_parsed_url(&parsed); if (!decoded) return js_mkerr(js, "allocation failure"); - jsval_t ret = js_mkstr(js, decoded, strlen(decoded)); + ant_value_t ret = js_mkstr(js, decoded, strlen(decoded)); free(decoded); return ret; } -static jsval_t builtin_pathToFileURL(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t builtin_pathToFileURL(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || vtype(args[0]) != T_STR) return js_mkerr(js, "pathToFileURL requires a string argument"); @@ -672,15 +672,15 @@ static jsval_t builtin_pathToFileURL(ant_t *js, jsval_t *args, int nargs) { memcpy(buf + 7, path, len); buf[total] = '\0'; - jsval_t url_args[1] = { js_mkstr(js, buf, total) }; + ant_value_t url_args[1] = { js_mkstr(js, buf, total) }; free(buf); return js_URL(js, url_args, 1); } -jsval_t url_library(ant_t *js) { - jsval_t lib = js_mkobj(js); - jsval_t glob = js_glob(js); +ant_value_t url_library(ant_t *js) { + ant_value_t lib = js_mkobj(js); + ant_value_t glob = js_glob(js); js_set(js, lib, "URL", js_get(js, glob, "URL")); js_set(js, lib, "URLSearchParams", js_get(js, glob, "URLSearchParams")); diff --git a/src/modules/util.c b/src/modules/util.c index 21ee9fe..3724509 100644 --- a/src/modules/util.c +++ b/src/modules/util.c @@ -57,7 +57,7 @@ static const util_style_entry_t util_styles[] = { {"bgWhite", "\x1b[47m", "\x1b[49m"}, }; -static inline bool util_is_callable(jsval_t v) { +static inline bool util_is_callable(ant_value_t v) { uint8_t t = vtype(v); return t == T_FUNC || t == T_CFUNC; } @@ -93,7 +93,7 @@ static bool util_sb_append_c(util_sb_t *sb, char c) { return true; } -static bool util_sb_append_jsval(ant_t *js, util_sb_t *sb, jsval_t v) { +static bool util_sb_append_jsval(ant_t *js, util_sb_t *sb, ant_value_t v) { char cbuf[512]; js_cstr_t cstr = js_to_cstr(js, v, cbuf, sizeof(cbuf)); size_t len = strlen(cstr.ptr); @@ -102,9 +102,9 @@ static bool util_sb_append_jsval(ant_t *js, util_sb_t *sb, jsval_t v) { return ok; } -static bool util_sb_append_json(ant_t *js, util_sb_t *sb, jsval_t v) { - jsval_t stringify_args[1] = {v}; - jsval_t json = js_json_stringify(js, stringify_args, 1); +static bool util_sb_append_json(ant_t *js, util_sb_t *sb, ant_value_t v) { + ant_value_t stringify_args[1] = {v}; + ant_value_t json = js_json_stringify(js, stringify_args, 1); if (vtype(json) != T_STR) { return util_sb_append_n(sb, "[Circular]", 10); } @@ -113,10 +113,10 @@ static bool util_sb_append_json(ant_t *js, util_sb_t *sb, jsval_t v) { return s ? util_sb_append_n(sb, s, len) : util_sb_append_n(sb, "[Circular]", 10); } -static jsval_t util_format_impl(ant_t *js, jsval_t *args, int nargs, int fmt_index) { +static ant_value_t util_format_impl(ant_t *js, ant_value_t *args, int nargs, int fmt_index) { util_sb_t sb = {0}; if (fmt_index >= nargs) { - jsval_t out = js_mkstr(js, "", 0); + ant_value_t out = js_mkstr(js, "", 0); free(sb.buf); return out; } @@ -126,7 +126,7 @@ static jsval_t util_format_impl(ant_t *js, jsval_t *args, int nargs, int fmt_ind if (i > fmt_index) util_sb_append_c(&sb, ' '); util_sb_append_jsval(js, &sb, args[i]); } - jsval_t out = js_mkstr(js, sb.buf ? sb.buf : "", sb.len); + ant_value_t out = js_mkstr(js, sb.buf ? sb.buf : "", sb.len); free(sb.buf); return out; } @@ -160,7 +160,7 @@ static jsval_t util_format_impl(ant_t *js, jsval_t *args, int nargs, int fmt_ind continue; } - jsval_t v = (argi < nargs) ? args[argi++] : js_mkundef(); + ant_value_t v = (argi < nargs) ? args[argi++] : js_mkundef(); if (spec == 's') { util_sb_append_jsval(js, &sb, v); @@ -192,30 +192,30 @@ static jsval_t util_format_impl(ant_t *js, jsval_t *args, int nargs, int fmt_ind util_sb_append_jsval(js, &sb, args[argi]); } - jsval_t out = js_mkstr(js, sb.buf ? sb.buf : "", sb.len); + ant_value_t out = js_mkstr(js, sb.buf ? sb.buf : "", sb.len); free(sb.buf); return out; } -static jsval_t util_format(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t util_format(ant_t *js, ant_value_t *args, int nargs) { return util_format_impl(js, args, nargs, 0); } -static jsval_t util_format_with_options(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t util_format_with_options(ant_t *js, ant_value_t *args, int nargs) { if (nargs <= 1) return js_mkstr(js, "", 0); return util_format_impl(js, args, nargs, 1); } -static jsval_t util_inspect(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t util_inspect(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkstr(js, "undefined", 9); char cbuf[512]; js_cstr_t cstr = js_to_cstr(js, args[0], cbuf, sizeof(cbuf)); - jsval_t out = js_mkstr(js, cstr.ptr, strlen(cstr.ptr)); + ant_value_t out = js_mkstr(js, cstr.ptr, strlen(cstr.ptr)); if (cstr.needs_free) free((void *)cstr.ptr); return out; } -static jsval_t util_strip_vt_control_characters(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t util_strip_vt_control_characters(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkstr(js, "", 0); char cbuf[512]; @@ -255,7 +255,7 @@ static jsval_t util_strip_vt_control_characters(ant_t *js, jsval_t *args, int na } } - jsval_t out = js_mkstr(js, sb.buf ? sb.buf : "", sb.len); + ant_value_t out = js_mkstr(js, sb.buf ? sb.buf : "", sb.len); if (cstr.needs_free) free((void *)cstr.ptr); free(sb.buf); return out; @@ -268,7 +268,7 @@ static const util_style_entry_t *util_find_style(const char *name) { return NULL; } -static jsval_t util_style_text(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t util_style_text(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkstr(js, "", 0); char text_buf[512]; @@ -282,9 +282,9 @@ static jsval_t util_style_text(ant_t *js, jsval_t *args, int nargs) { const util_style_entry_t *e = name ? util_find_style(name) : NULL; if (e) picked[picked_n++] = e; } else if (vtype(args[0]) == T_ARR) { - jsoff_t len = js_arr_len(js, args[0]); - for (jsoff_t i = 0; i < len && picked_n < (int)(sizeof(picked) / sizeof(picked[0])); i++) { - jsval_t item = js_arr_get(js, args[0], i); + ant_offset_t len = js_arr_len(js, args[0]); + for (ant_offset_t i = 0; i < len && picked_n < (int)(sizeof(picked) / sizeof(picked[0])); i++) { + ant_value_t item = js_arr_get(js, args[0], i); if (vtype(item) != T_STR) continue; const char *name = js_getstr(js, item, NULL); const util_style_entry_t *e = name ? util_find_style(name) : NULL; @@ -293,7 +293,7 @@ static jsval_t util_style_text(ant_t *js, jsval_t *args, int nargs) { } if (picked_n == 0) { - jsval_t out = js_mkstr(js, text_cstr.ptr, strlen(text_cstr.ptr)); + ant_value_t out = js_mkstr(js, text_cstr.ptr, strlen(text_cstr.ptr)); if (text_cstr.needs_free) free((void *)text_cstr.ptr); return out; } @@ -307,22 +307,22 @@ static jsval_t util_style_text(ant_t *js, jsval_t *args, int nargs) { util_sb_append_n(&sb, picked[i]->close, strlen(picked[i]->close)); } - jsval_t out = js_mkstr(js, sb.buf ? sb.buf : "", sb.len); + ant_value_t out = js_mkstr(js, sb.buf ? sb.buf : "", sb.len); if (text_cstr.needs_free) free((void *)text_cstr.ptr); free(sb.buf); return out; } -static jsval_t util_promisify_callback(ant_t *js, jsval_t *args, int nargs) { - jsval_t fn = js_getcurrentfunc(js); - jsval_t ctx = js_get_slot(js, fn, SLOT_DATA); +static ant_value_t util_promisify_callback(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t fn = js_getcurrentfunc(js); + ant_value_t ctx = js_get_slot(js, fn, SLOT_DATA); if (!is_object_type(ctx)) return js_mkundef(); - jsval_t settled = js_get_slot(js, ctx, SLOT_SETTLED); + ant_value_t settled = js_get_slot(js, ctx, SLOT_SETTLED); if (vtype(settled) == T_BOOL && settled == js_true) return js_mkundef(); js_set_slot(js, ctx, SLOT_SETTLED, js_true); - jsval_t promise = js_get_slot(js, ctx, SLOT_DATA); + ant_value_t promise = js_get_slot(js, ctx, SLOT_DATA); if (!is_object_type(promise)) return js_mkundef(); if (nargs > 0 && !is_null(args[0]) && !is_undefined(args[0])) { @@ -340,24 +340,24 @@ static jsval_t util_promisify_callback(ant_t *js, jsval_t *args, int nargs) { return js_mkundef(); } - jsval_t arr = js_mkarr(js); + ant_value_t arr = js_mkarr(js); for (int i = 1; i < nargs; i++) js_arr_push(js, arr, args[i]); js_resolve_promise(js, promise, arr); return js_mkundef(); } -static jsval_t util_promisified_call(ant_t *js, jsval_t *args, int nargs) { - jsval_t fn = js_getcurrentfunc(js); - jsval_t original = js_get_slot(js, fn, SLOT_DATA); +static ant_value_t util_promisified_call(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t fn = js_getcurrentfunc(js); + ant_value_t original = js_get_slot(js, fn, SLOT_DATA); if (!util_is_callable(original)) return js_mkerr(js, "promisified target is not callable"); - jsval_t promise = js_mkpromise(js); - jsval_t ctx = js_mkobj(js); + ant_value_t promise = js_mkpromise(js); + ant_value_t ctx = js_mkobj(js); js_set_slot(js, ctx, SLOT_DATA, promise); js_set_slot(js, ctx, SLOT_SETTLED, js_false); - jsval_t cb = js_heavy_mkfun(js, util_promisify_callback, ctx); + ant_value_t cb = js_heavy_mkfun(js, util_promisify_callback, ctx); - jsval_t *call_args = (jsval_t *)malloc((size_t)(nargs + 1) * sizeof(jsval_t)); + ant_value_t *call_args = (ant_value_t *)malloc((size_t)(nargs + 1) * sizeof(ant_value_t)); if (!call_args) { js_reject_promise(js, promise, js_mkerr(js, "Out of memory")); return promise; @@ -365,16 +365,16 @@ static jsval_t util_promisified_call(ant_t *js, jsval_t *args, int nargs) { for (int i = 0; i < nargs; i++) call_args[i] = args[i]; call_args[nargs] = cb; - jsval_t this_arg = js_getthis(js); - jsval_t call_result = sv_vm_call( + ant_value_t this_arg = js_getthis(js); + ant_value_t call_result = sv_vm_call( js->vm, js, original, this_arg, call_args, nargs + 1, NULL, false ); free(call_args); - jsval_t settled = js_get_slot(js, ctx, SLOT_SETTLED); + ant_value_t settled = js_get_slot(js, ctx, SLOT_SETTLED); bool is_settled = (vtype(settled) == T_BOOL && settled == js_true); if (!is_settled && (is_err(call_result) || js->thrown_exists)) { - jsval_t ex = js->thrown_exists ? js->thrown_value : call_result; + ant_value_t ex = js->thrown_exists ? js->thrown_value : call_result; js->thrown_exists = false; js->thrown_value = js_mkundef(); js->thrown_stack = js_mkundef(); @@ -385,15 +385,15 @@ static jsval_t util_promisified_call(ant_t *js, jsval_t *args, int nargs) { return promise; } -static jsval_t util_promisify(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t util_promisify(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || !util_is_callable(args[0])) { return js_mkerr(js, "promisify(fn) requires a function"); } return js_heavy_mkfun(js, util_promisified_call, args[0]); } -jsval_t util_library(ant_t *js) { - jsval_t lib = js_mkobj(js); +ant_value_t util_library(ant_t *js) { + ant_value_t lib = js_mkobj(js); js_set(js, lib, "format", js_mkfun(util_format)); js_set(js, lib, "formatWithOptions", js_mkfun(util_format_with_options)); diff --git a/src/modules/worker_threads.c b/src/modules/worker_threads.c index c355ff0..7fb4d44 100644 --- a/src/modules/worker_threads.c +++ b/src/modules/worker_threads.c @@ -51,12 +51,12 @@ typedef struct ant_worker_thread { char *line_buf; size_t line_len; size_t line_cap; - jshdl_t self_root; - jshdl_t terminate_root; + ant_handle_t self_root; + ant_handle_t terminate_root; bool has_terminate_root; } ant_worker_thread_t; -static inline bool wt_is_callable(jsval_t v) { +static inline bool wt_is_callable(ant_value_t v) { uint8_t t = vtype(v); return t == T_FUNC || t == T_CFUNC; } @@ -66,8 +66,8 @@ static bool wt_is_worker_mode(void) { return mode && strcmp(mode, "1") == 0; } -static jsval_t wt_get_or_create_env_store(ant_t *js) { - jsval_t store = js_get_slot(js, js->global, SLOT_WT_ENV_STORE); +static ant_value_t wt_get_or_create_env_store(ant_t *js) { + ant_value_t store = js_get_slot(js, js->global, SLOT_WT_ENV_STORE); if (!is_object_type(store)) { store = js_mkobj(js); js_set_slot(js, js->global, SLOT_WT_ENV_STORE, store); @@ -76,40 +76,40 @@ static jsval_t wt_get_or_create_env_store(ant_t *js) { } static void wt_init_env_store(ant_t *js, bool is_worker) { - jsval_t store = js_mkobj(js); + ant_value_t store = js_mkobj(js); if (is_worker) { const char *raw = getenv(WT_ENV_STORE_JSON); if (raw && raw[0]) { - jsval_t input = js_mkstr(js, raw, strlen(raw)); - jsval_t parse_args[1] = {input}; - jsval_t parsed = js_json_parse(js, parse_args, 1); + ant_value_t input = js_mkstr(js, raw, strlen(raw)); + ant_value_t parse_args[1] = {input}; + ant_value_t parsed = js_json_parse(js, parse_args, 1); if (is_object_type(parsed)) store = parsed; } } js_set_slot(js, js->global, SLOT_WT_ENV_STORE, store); } -static ant_worker_thread_t *wt_get_worker(ant_t *js, jsval_t this_obj) { +static ant_worker_thread_t *wt_get_worker(ant_t *js, ant_value_t this_obj) { if (!is_object_type(this_obj)) return NULL; - jsval_t data = js_get_slot(js, this_obj, SLOT_DATA); + ant_value_t data = js_get_slot(js, this_obj, SLOT_DATA); if (vtype(data) != T_NUM) return NULL; return (ant_worker_thread_t *)(uintptr_t)js_getnum(data); } -static bool wt_is_message_port(ant_t *js, jsval_t obj) { +static bool wt_is_message_port(ant_t *js, ant_value_t obj) { if (!is_object_type(obj)) return false; - jsval_t tag = js_get_slot(js, obj, SLOT_WT_PORT_TAG); + ant_value_t tag = js_get_slot(js, obj, SLOT_WT_PORT_TAG); return js_truthy(js, tag); } -static jsval_t wt_get_message_port_proto(ant_t *js) { - jsval_t proto = js_get_slot(js, js->global, SLOT_WT_PORT_PROTO); +static ant_value_t wt_get_message_port_proto(ant_t *js) { + ant_value_t proto = js_get_slot(js, js->global, SLOT_WT_PORT_PROTO); if (!is_object_type(proto)) proto = js_mkobj(js); return proto; } -static jsval_t wt_make_message_port(ant_t *js) { - jsval_t port = js_mkobj(js); +static ant_value_t wt_make_message_port(ant_t *js) { + ant_value_t port = js_mkobj(js); js_set_proto(js, port, wt_get_message_port_proto(js)); js_set_slot(js, port, SLOT_WT_PORT_TAG, js_true); js_set_slot(js, port, SLOT_WT_PORT_QUEUE, js_mkarr(js)); @@ -123,21 +123,21 @@ static jsval_t wt_make_message_port(ant_t *js) { return port; } -static bool wt_port_is_closed(ant_t *js, jsval_t port) { +static bool wt_port_is_closed(ant_t *js, ant_value_t port) { return js_truthy(js, js_get_slot(js, port, SLOT_WT_PORT_CLOSED)); } -static void wt_port_set_closed(ant_t *js, jsval_t port, bool closed) { +static void wt_port_set_closed(ant_t *js, ant_value_t port, bool closed) { js_set_slot(js, port, SLOT_WT_PORT_CLOSED, js_bool(closed)); } -static bool wt_port_queue_dequeue(ant_t *js, jsval_t port, jsval_t *out) { - jsval_t queue = js_get_slot(js, port, SLOT_WT_PORT_QUEUE); +static bool wt_port_queue_dequeue(ant_t *js, ant_value_t port, ant_value_t *out) { + ant_value_t queue = js_get_slot(js, port, SLOT_WT_PORT_QUEUE); if (vtype(queue) != T_ARR) return false; - jsval_t head_val = js_get_slot(js, port, SLOT_WT_PORT_HEAD); - jsoff_t head = (vtype(head_val) == T_NUM) ? (jsoff_t)js_getnum(head_val) : 0; - jsoff_t len = js_arr_len(js, queue); + ant_value_t head_val = js_get_slot(js, port, SLOT_WT_PORT_HEAD); + ant_offset_t head = (vtype(head_val) == T_NUM) ? (ant_offset_t)js_getnum(head_val) : 0; + ant_offset_t len = js_arr_len(js, queue); if (len <= 0 || head >= len) { js_set_slot(js, port, SLOT_WT_PORT_QUEUE, js_mkarr(js)); js_set_slot(js, port, SLOT_WT_PORT_HEAD, js_mknum(0)); @@ -145,7 +145,7 @@ static bool wt_port_queue_dequeue(ant_t *js, jsval_t port, jsval_t *out) { } if (out) *out = js_arr_get(js, queue, head); - jsoff_t next_head = head + 1; + ant_offset_t next_head = head + 1; if (next_head >= len) { js_set_slot(js, port, SLOT_WT_PORT_QUEUE, js_mkarr(js)); @@ -154,8 +154,8 @@ static bool wt_port_queue_dequeue(ant_t *js, jsval_t port, jsval_t *out) { } if (next_head > 32 && next_head * 2 >= len) { - jsval_t compact = js_mkarr(js); - for (jsoff_t i = next_head; i < len; i++) js_arr_push(js, compact, js_arr_get(js, queue, i)); + ant_value_t compact = js_mkarr(js); + for (ant_offset_t i = next_head; i < len; i++) js_arr_push(js, compact, js_arr_get(js, queue, i)); js_set_slot(js, port, SLOT_WT_PORT_QUEUE, compact); js_set_slot(js, port, SLOT_WT_PORT_HEAD, js_mknum(0)); return true; @@ -165,8 +165,8 @@ static bool wt_port_queue_dequeue(ant_t *js, jsval_t port, jsval_t *out) { return true; } -static void wt_port_queue_push(ant_t *js, jsval_t port, jsval_t value) { - jsval_t queue = js_get_slot(js, port, SLOT_WT_PORT_QUEUE); +static void wt_port_queue_push(ant_t *js, ant_value_t port, ant_value_t value) { + ant_value_t queue = js_get_slot(js, port, SLOT_WT_PORT_QUEUE); if (vtype(queue) != T_ARR) { queue = js_mkarr(js); js_set_slot(js, port, SLOT_WT_PORT_QUEUE, queue); @@ -175,44 +175,44 @@ static void wt_port_queue_push(ant_t *js, jsval_t port, jsval_t value) { js_arr_push(js, queue, value); } -static void wt_port_call_listener(ant_t *js, jsval_t this_obj, jsval_t fn, jsval_t arg) { +static void wt_port_call_listener(ant_t *js, ant_value_t this_obj, ant_value_t fn, ant_value_t arg) { if (!wt_is_callable(fn)) return; - jsval_t argv[1] = {arg}; + ant_value_t argv[1] = {arg}; sv_vm_call(js->vm, js, fn, this_obj, argv, 1, NULL, false); } -static bool wt_port_should_deliver(ant_t *js, jsval_t port) { +static bool wt_port_should_deliver(ant_t *js, ant_value_t port) { if (wt_port_is_closed(js, port)) return false; bool started = js_truthy(js, js_get_slot(js, port, SLOT_WT_PORT_STARTED)); - jsval_t on_fn = js_get_slot(js, port, SLOT_WT_PORT_ON_MESSAGE); - jsval_t once_fn = js_get_slot(js, port, SLOT_WT_PORT_ONCE_MESSAGE); - jsval_t onmessage = js_get(js, port, "onmessage"); + ant_value_t on_fn = js_get_slot(js, port, SLOT_WT_PORT_ON_MESSAGE); + ant_value_t once_fn = js_get_slot(js, port, SLOT_WT_PORT_ONCE_MESSAGE); + ant_value_t onmessage = js_get(js, port, "onmessage"); bool has_event_listener = wt_is_callable(on_fn) || wt_is_callable(once_fn); if (wt_is_callable(onmessage)) return true; return started && has_event_listener; } -static void wt_port_drain(ant_t *js, jsval_t port) { +static void wt_port_drain(ant_t *js, ant_value_t port) { if (!wt_is_message_port(js, port)) return; while (wt_port_should_deliver(js, port)) { - jsval_t msg = js_mkundef(); + ant_value_t msg = js_mkundef(); if (!wt_port_queue_dequeue(js, port, &msg)) break; - jsval_t on_fn = js_get_slot(js, port, SLOT_WT_PORT_ON_MESSAGE); + ant_value_t on_fn = js_get_slot(js, port, SLOT_WT_PORT_ON_MESSAGE); wt_port_call_listener(js, port, on_fn, msg); - jsval_t once_fn = js_get_slot(js, port, SLOT_WT_PORT_ONCE_MESSAGE); + ant_value_t once_fn = js_get_slot(js, port, SLOT_WT_PORT_ONCE_MESSAGE); if (wt_is_callable(once_fn)) { wt_port_call_listener(js, port, once_fn, msg); js_set_slot(js, port, SLOT_WT_PORT_ONCE_MESSAGE, js_mkundef()); } - jsval_t onmessage = js_get(js, port, "onmessage"); + ant_value_t onmessage = js_get(js, port, "onmessage"); if (wt_is_callable(onmessage)) { - jsval_t event_obj = js_mkobj(js); + ant_value_t event_obj = js_mkobj(js); js_set(js, event_obj, "data", msg); wt_port_call_listener(js, port, onmessage, event_obj); } @@ -221,23 +221,23 @@ static void wt_port_drain(ant_t *js, jsval_t port) { } } -static jsval_t wt_make_resolved_promise(ant_t *js, jsval_t value) { - jsval_t p = js_mkpromise(js); +static ant_value_t wt_make_resolved_promise(ant_t *js, ant_value_t value) { + ant_value_t p = js_mkpromise(js); js_resolve_promise(js, p, value); return p; } -static void wt_call_listener(ant_t *js, jsval_t this_obj, jsval_t fn, jsval_t arg) { +static void wt_call_listener(ant_t *js, ant_value_t this_obj, ant_value_t fn, ant_value_t arg) { if (!wt_is_callable(fn)) return; - jsval_t argv[1] = {arg}; + ant_value_t argv[1] = {arg}; sv_vm_call(js->vm, js, fn, this_obj, argv, 1, NULL, false); } -static void wt_emit(ant_worker_thread_t *wt, const char *event, jsval_t arg) { +static void wt_emit(ant_worker_thread_t *wt, const char *event, ant_value_t arg) { if (!wt || !wt->js) return; ant_t *js = wt->js; - jsval_t this_obj = js_deref(js, wt->self_root); + ant_value_t this_obj = js_deref(js, wt->self_root); if (!is_object_type(this_obj)) return; internal_slot_t on_slot, once_slot; @@ -249,10 +249,10 @@ static void wt_emit(ant_worker_thread_t *wt, const char *event, jsval_t arg) { once_slot = SLOT_WT_ONCE_EXIT; } else return; - jsval_t on_fn = js_get_slot(js, this_obj, on_slot); + ant_value_t on_fn = js_get_slot(js, this_obj, on_slot); wt_call_listener(js, this_obj, on_fn, arg); - jsval_t once_fn = js_get_slot(js, this_obj, once_slot); + ant_value_t once_fn = js_get_slot(js, this_obj, once_slot); if (wt_is_callable(once_fn)) { wt_call_listener(js, this_obj, once_fn, arg); js_set_slot(js, this_obj, once_slot, js_mkundef()); @@ -392,7 +392,7 @@ static void wt_on_process_exit(uv_process_t *proc, int64_t exit_status, int term wt->term_signal = term_signal; if (wt->has_terminate_root) { - jsval_t p = js_deref(wt->js, wt->terminate_root); + ant_value_t p = js_deref(wt->js, wt->terminate_root); js_resolve_promise(wt->js, p, js_mknum((double)exit_status)); js_root_update(wt->js, wt->terminate_root, js_mkundef()); wt->has_terminate_root = false; @@ -411,9 +411,9 @@ static void wt_emit_message_from_json(ant_worker_thread_t *wt, const char *json, if (!wt || !wt->js) return; ant_t *js = wt->js; - jsval_t s = js_mkstr(js, json, len); - jsval_t parse_args[1] = {s}; - jsval_t msg = js_json_parse(js, parse_args, 1); + ant_value_t s = js_mkstr(js, json, len); + ant_value_t parse_args[1] = {s}; + ant_value_t msg = js_json_parse(js, parse_args, 1); if (is_err(msg)) msg = s; wt_emit(wt, "message", msg); @@ -478,17 +478,17 @@ static void wt_read_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) free(buf->base); } -static char *wt_path_from_specifier(ant_t *js, jsval_t spec) { +static char *wt_path_from_specifier(ant_t *js, ant_value_t spec) { const char *raw = NULL; size_t len = 0; if (vtype(spec) == T_STR) { raw = js_getstr(js, spec, &len); } else if (is_object_type(spec)) { - jsval_t pathname = js_get(js, spec, "pathname"); + ant_value_t pathname = js_get(js, spec, "pathname"); if (vtype(pathname) == T_STR) raw = js_getstr(js, pathname, &len); if (!raw) { - jsval_t href = js_get(js, spec, "href"); + ant_value_t href = js_get(js, spec, "href"); if (vtype(href) == T_STR) raw = js_getstr(js, href, &len); } } @@ -574,12 +574,12 @@ static int wt_spawn_worker( return rc; } -static jsval_t worker_threads_worker_on(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t worker_threads_worker_on(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2 || vtype(args[0]) != T_STR || !wt_is_callable(args[1])) { return js_mkerr(js, "Worker.on(event, listener) requires (string, function)"); } - jsval_t this_obj = js_getthis(js); + ant_value_t this_obj = js_getthis(js); if (!is_object_type(this_obj)) return js_mkerr(js, "invalid Worker receiver"); size_t len = 0; @@ -595,12 +595,12 @@ static jsval_t worker_threads_worker_on(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t worker_threads_worker_once(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t worker_threads_worker_once(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2 || vtype(args[0]) != T_STR || !wt_is_callable(args[1])) { return js_mkerr(js, "Worker.once(event, listener) requires (string, function)"); } - jsval_t this_obj = js_getthis(js); + ant_value_t this_obj = js_getthis(js); if (!is_object_type(this_obj)) return js_mkerr(js, "invalid Worker receiver"); size_t len = 0; @@ -616,8 +616,8 @@ static jsval_t worker_threads_worker_once(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t worker_threads_worker_unref(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t worker_threads_worker_unref(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); ant_worker_thread_t *wt = wt_get_worker(js, this_obj); if (!wt) return js_mkerr(js, "invalid Worker receiver"); if (wt->spawned && wt->refed) { @@ -628,8 +628,8 @@ static jsval_t worker_threads_worker_unref(ant_t *js, jsval_t *args, int nargs) return this_obj; } -static jsval_t worker_threads_worker_ref(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t worker_threads_worker_ref(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); ant_worker_thread_t *wt = wt_get_worker(js, this_obj); if (!wt) return js_mkerr(js, "invalid Worker receiver"); if (wt->spawned && !wt->refed) { @@ -640,22 +640,22 @@ static jsval_t worker_threads_worker_ref(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t worker_threads_worker_terminate(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t worker_threads_worker_terminate(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); ant_worker_thread_t *wt = wt_get_worker(js, this_obj); if (!wt) return js_mkerr(js, "invalid Worker receiver"); if (wt->exited) return wt_make_resolved_promise(js, js_mknum((double)wt->exit_status)); if (!wt->has_terminate_root) { - jsval_t p = js_mkpromise(js); + ant_value_t p = js_mkpromise(js); wt->terminate_root = js_root(js, p); wt->has_terminate_root = true; } int rc = uv_process_kill(&wt->process, SIGTERM); if (rc != 0) { - jsval_t p = js_deref(js, wt->terminate_root); + ant_value_t p = js_deref(js, wt->terminate_root); js_reject_promise(js, p, js_mkerr(js, "terminate failed: %s", uv_strerror(rc))); js_root_update(js, wt->terminate_root, js_mkundef()); wt->has_terminate_root = false; @@ -665,29 +665,29 @@ static jsval_t worker_threads_worker_terminate(ant_t *js, jsval_t *args, int nar return js_deref(js, wt->terminate_root); } -static jsval_t worker_threads_worker_post_message(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t worker_threads_worker_post_message(ant_t *js, ant_value_t *args, int nargs) { return js_mkerr(js, "Worker.postMessage is not implemented yet"); } -static jsval_t worker_threads_message_port_post_message(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t worker_threads_message_port_post_message(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (!wt_is_message_port(js, this_obj)) return js_mkerr(js, "invalid MessagePort receiver"); if (wt_port_is_closed(js, this_obj)) return js_mkundef(); - jsval_t peer = js_get_slot(js, this_obj, SLOT_WT_PORT_PEER); + ant_value_t peer = js_get_slot(js, this_obj, SLOT_WT_PORT_PEER); if (!wt_is_message_port(js, peer) || wt_port_is_closed(js, peer)) return js_mkundef(); - jsval_t value = (nargs > 0) ? args[0] : js_mkundef(); + ant_value_t value = (nargs > 0) ? args[0] : js_mkundef(); wt_port_queue_push(js, peer, value); wt_port_drain(js, peer); return js_mkundef(); } -static jsval_t worker_threads_message_port_on(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t worker_threads_message_port_on(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2 || vtype(args[0]) != T_STR || !wt_is_callable(args[1])) { return js_mkerr(js, "MessagePort.on(event, listener) requires (string, function)"); } - jsval_t this_obj = js_getthis(js); + ant_value_t this_obj = js_getthis(js); if (!wt_is_message_port(js, this_obj)) return js_mkerr(js, "invalid MessagePort receiver"); size_t len = 0; @@ -701,11 +701,11 @@ static jsval_t worker_threads_message_port_on(ant_t *js, jsval_t *args, int narg return this_obj; } -static jsval_t worker_threads_message_port_once(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t worker_threads_message_port_once(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2 || vtype(args[0]) != T_STR || !wt_is_callable(args[1])) { return js_mkerr(js, "MessagePort.once(event, listener) requires (string, function)"); } - jsval_t this_obj = js_getthis(js); + ant_value_t this_obj = js_getthis(js); if (!wt_is_message_port(js, this_obj)) return js_mkerr(js, "invalid MessagePort receiver"); size_t len = 0; @@ -719,45 +719,45 @@ static jsval_t worker_threads_message_port_once(ant_t *js, jsval_t *args, int na return this_obj; } -static jsval_t worker_threads_message_port_start(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t worker_threads_message_port_start(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (!wt_is_message_port(js, this_obj)) return js_mkerr(js, "invalid MessagePort receiver"); js_set_slot(js, this_obj, SLOT_WT_PORT_STARTED, js_true); wt_port_drain(js, this_obj); return js_mkundef(); } -static jsval_t worker_threads_message_port_close(ant_t *js, jsval_t *args, int nargs) { - jsval_t this_obj = js_getthis(js); +static ant_value_t worker_threads_message_port_close(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t this_obj = js_getthis(js); if (!wt_is_message_port(js, this_obj)) return js_mkerr(js, "invalid MessagePort receiver"); wt_port_set_closed(js, this_obj, true); - jsval_t peer = js_get_slot(js, this_obj, SLOT_WT_PORT_PEER); + ant_value_t peer = js_get_slot(js, this_obj, SLOT_WT_PORT_PEER); js_set_slot(js, this_obj, SLOT_WT_PORT_PEER, js_mknull()); if (wt_is_message_port(js, peer)) js_set_slot(js, peer, SLOT_WT_PORT_PEER, js_mknull()); return js_mkundef(); } -static jsval_t worker_threads_message_port_ref(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t worker_threads_message_port_ref(ant_t *js, ant_value_t *args, int nargs) { return js_mkundef(); } -static jsval_t worker_threads_message_port_unref(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t worker_threads_message_port_unref(ant_t *js, ant_value_t *args, int nargs) { return js_mkundef(); } -static jsval_t worker_threads_message_port_ctor(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t worker_threads_message_port_ctor(ant_t *js, ant_value_t *args, int nargs) { return js_mkerr(js, "MessagePort constructor is not public"); } -static jsval_t worker_threads_message_channel_ctor(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t worker_threads_message_channel_ctor(ant_t *js, ant_value_t *args, int nargs) { if (vtype(js->new_target) == T_UNDEF) { return js_mkerr(js, "MessageChannel constructor requires 'new'"); } - jsval_t this_obj = js_getthis(js); - jsval_t port1 = wt_make_message_port(js); - jsval_t port2 = wt_make_message_port(js); + ant_value_t this_obj = js_getthis(js); + ant_value_t port1 = wt_make_message_port(js); + ant_value_t port2 = wt_make_message_port(js); js_set_slot(js, port1, SLOT_WT_PORT_PEER, port2); js_set_slot(js, port2, SLOT_WT_PORT_PEER, port1); js_set(js, this_obj, "port1", port1); @@ -765,7 +765,7 @@ static jsval_t worker_threads_message_channel_ctor(ant_t *js, jsval_t *args, int return this_obj; } -static jsval_t worker_threads_worker_ctor(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t worker_threads_worker_ctor(ant_t *js, ant_value_t *args, int nargs) { if (vtype(js->new_target) == T_UNDEF) { return js_mkerr(js, "Worker constructor requires 'new'"); } @@ -779,10 +779,10 @@ static jsval_t worker_threads_worker_ctor(ant_t *js, jsval_t *args, int nargs) { char *worker_data_heap = NULL; char *env_store_heap = NULL; if (nargs >= 2 && is_object_type(args[1])) { - jsval_t worker_data = js_get(js, args[1], "workerData"); + ant_value_t worker_data = js_get(js, args[1], "workerData"); if (!is_undefined(worker_data)) { - jsval_t stringify_args[1] = {worker_data}; - jsval_t json = js_json_stringify(js, stringify_args, 1); + ant_value_t stringify_args[1] = {worker_data}; + ant_value_t json = js_json_stringify(js, stringify_args, 1); if (vtype(json) != T_STR) { free(script_path); return js_mkerr(js, "Worker options.workerData must be JSON-serializable"); @@ -802,9 +802,9 @@ static jsval_t worker_threads_worker_ctor(ant_t *js, jsval_t *args, int nargs) { } } - jsval_t env_store = wt_get_or_create_env_store(js); - jsval_t env_stringify_args[1] = {env_store}; - jsval_t env_json = js_json_stringify(js, env_stringify_args, 1); + ant_value_t env_store = wt_get_or_create_env_store(js); + ant_value_t env_stringify_args[1] = {env_store}; + ant_value_t env_json = js_json_stringify(js, env_stringify_args, 1); if (vtype(env_json) != T_STR) { free(script_path); free(worker_data_heap); @@ -825,7 +825,7 @@ static jsval_t worker_threads_worker_ctor(ant_t *js, jsval_t *args, int nargs) { } env_store_json = env_store_heap; - jsval_t this_obj = js_getthis(js); + ant_value_t this_obj = js_getthis(js); ant_worker_thread_t *wt = (ant_worker_thread_t *)calloc(1, sizeof(*wt)); if (!wt) { free(script_path); @@ -852,10 +852,10 @@ static jsval_t worker_threads_worker_ctor(ant_t *js, jsval_t *args, int nargs) { return this_obj; } -static jsval_t worker_threads_parent_post_message(ant_t *js, jsval_t *args, int nargs) { - jsval_t value = (nargs > 0) ? args[0] : js_mkundef(); - jsval_t stringify_args[1] = {value}; - jsval_t json = js_json_stringify(js, stringify_args, 1); +static ant_value_t worker_threads_parent_post_message(ant_t *js, ant_value_t *args, int nargs) { + ant_value_t value = (nargs > 0) ? args[0] : js_mkundef(); + ant_value_t stringify_args[1] = {value}; + ant_value_t json = js_json_stringify(js, stringify_args, 1); if (vtype(json) != T_STR) return js_mkerr(js, "parentPort.postMessage payload must be JSON-serializable"); size_t json_len = 0; @@ -878,40 +878,40 @@ static jsval_t worker_threads_parent_post_message(ant_t *js, jsval_t *args, int return js_mkundef(); } -static jsval_t worker_threads_parent_unref(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t worker_threads_parent_unref(ant_t *js, ant_value_t *args, int nargs) { return js_mkundef(); } -static jsval_t worker_threads_mark_as_untransferable(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t worker_threads_mark_as_untransferable(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkundef(); return args[0]; } -static jsval_t worker_threads_receive_message_on_port(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t worker_threads_receive_message_on_port(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || !wt_is_message_port(js, args[0])) { return js_mkerr(js, "receiveMessageOnPort(port) requires a MessagePort"); } - jsval_t msg = js_mkundef(); + ant_value_t msg = js_mkundef(); if (!wt_port_queue_dequeue(js, args[0], &msg)) return js_mkundef(); - jsval_t out = js_mkobj(js); + ant_value_t out = js_mkobj(js); js_set(js, out, "message", msg); return out; } -static jsval_t worker_threads_set_environment_data(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t worker_threads_set_environment_data(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 2) return js_mkerr(js, "setEnvironmentData(key, value) requires 2 arguments"); - jsval_t key_stringify_args[1] = {args[0]}; - jsval_t key_json = js_json_stringify(js, key_stringify_args, 1); + ant_value_t key_stringify_args[1] = {args[0]}; + ant_value_t key_json = js_json_stringify(js, key_stringify_args, 1); if (vtype(key_json) != T_STR) return js_mkerr(js, "setEnvironmentData key must be JSON-serializable"); - jsval_t value_stringify_args[1] = {args[1]}; - jsval_t value_json = js_json_stringify(js, value_stringify_args, 1); + ant_value_t value_stringify_args[1] = {args[1]}; + ant_value_t value_json = js_json_stringify(js, value_stringify_args, 1); if (vtype(value_json) != T_STR) return js_mkerr(js, "setEnvironmentData value must be JSON-serializable"); - jsval_t parse_args[1] = {value_json}; - jsval_t cloned = js_json_parse(js, parse_args, 1); + ant_value_t parse_args[1] = {value_json}; + ant_value_t cloned = js_json_parse(js, parse_args, 1); if (is_err(cloned)) return js_mkerr(js, "setEnvironmentData value must be JSON-serializable"); size_t key_len = 0; @@ -925,11 +925,11 @@ static jsval_t worker_threads_set_environment_data(ant_t *js, jsval_t *args, int return js_mkundef(); } -static jsval_t worker_threads_get_environment_data(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t worker_threads_get_environment_data(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1) return js_mkundef(); - jsval_t key_stringify_args[1] = {args[0]}; - jsval_t key_json = js_json_stringify(js, key_stringify_args, 1); + ant_value_t key_stringify_args[1] = {args[0]}; + ant_value_t key_json = js_json_stringify(js, key_stringify_args, 1); if (vtype(key_json) != T_STR) return js_mkundef(); size_t key_len = 0; @@ -939,27 +939,27 @@ static jsval_t worker_threads_get_environment_data(ant_t *js, jsval_t *args, int char *key = strndup(key_ptr, key_len); if (!key) return js_mkerr(js, "Out of memory"); - jsval_t store = wt_get_or_create_env_store(js); - jsoff_t off = lkp(js, store, key, key_len); + ant_value_t store = wt_get_or_create_env_store(js); + ant_offset_t off = lkp(js, store, key, key_len); if (off == 0) { free(key); return js_mkundef(); } - jsval_t value = js_get(js, store, key); + ant_value_t value = js_get(js, store, key); free(key); return value; } -static jsval_t worker_threads_move_message_port_to_context(ant_t *js, jsval_t *args, int nargs) { +static ant_value_t worker_threads_move_message_port_to_context(ant_t *js, ant_value_t *args, int nargs) { if (nargs < 1 || !wt_is_message_port(js, args[0])) { return js_mkerr(js, "moveMessagePortToContext(port, context) requires a MessagePort"); } return args[0]; } -jsval_t worker_threads_library(ant_t *js) { - jsval_t lib = js_mkobj(js); +ant_value_t worker_threads_library(ant_t *js) { + ant_value_t lib = js_mkobj(js); bool is_worker = wt_is_worker_mode(); wt_init_env_store(js, is_worker); @@ -968,8 +968,8 @@ jsval_t worker_threads_library(ant_t *js) { js_set(js, lib, "threadId", js_mknum((double)(is_worker ? rt->pid : 0))); js_set(js, lib, "SHARE_ENV", js_mksym(js, "SHARE_ENV")); - jsval_t message_port_ctor_obj = js_mkobj(js); - jsval_t message_port_proto = js_mkobj(js); + ant_value_t message_port_ctor_obj = js_mkobj(js); + ant_value_t message_port_proto = js_mkobj(js); js_set(js, message_port_proto, "postMessage", js_mkfun(worker_threads_message_port_post_message)); js_set(js, message_port_proto, "on", js_mkfun(worker_threads_message_port_on)); js_set(js, message_port_proto, "once", js_mkfun(worker_threads_message_port_once)); @@ -986,8 +986,8 @@ jsval_t worker_threads_library(ant_t *js) { js_set(js, lib, "MessagePort", js_obj_to_func(message_port_ctor_obj)); js_set_slot(js, js->global, SLOT_WT_PORT_PROTO, message_port_proto); - jsval_t message_channel_ctor_obj = js_mkobj(js); - jsval_t message_channel_proto = js_mkobj(js); + ant_value_t message_channel_ctor_obj = js_mkobj(js); + ant_value_t message_channel_proto = js_mkobj(js); js_set_sym(js, message_channel_proto, get_toStringTag_sym(), js_mkstr(js, "MessageChannel", 14)); js_set_slot(js, message_channel_ctor_obj, SLOT_CFUNC, js_mkfun(worker_threads_message_channel_ctor)); js_mkprop_fast(js, message_channel_ctor_obj, "prototype", 9, message_channel_proto); @@ -996,7 +996,7 @@ jsval_t worker_threads_library(ant_t *js) { js_set(js, lib, "MessageChannel", js_obj_to_func(message_channel_ctor_obj)); if (is_worker) { - jsval_t parent_port = js_mkobj(js); + ant_value_t parent_port = js_mkobj(js); js_set(js, parent_port, "postMessage", js_mkfun(worker_threads_parent_post_message)); js_set(js, parent_port, "unref", js_mkfun(worker_threads_parent_unref)); js_set(js, parent_port, "ref", js_mkfun(worker_threads_parent_unref)); @@ -1004,9 +1004,9 @@ jsval_t worker_threads_library(ant_t *js) { const char *worker_data_json = getenv(WT_ENV_DATA_JSON); if (worker_data_json && worker_data_json[0]) { - jsval_t raw = js_mkstr(js, worker_data_json, strlen(worker_data_json)); - jsval_t parse_args[1] = {raw}; - jsval_t parsed = js_json_parse(js, parse_args, 1); + ant_value_t raw = js_mkstr(js, worker_data_json, strlen(worker_data_json)); + ant_value_t parse_args[1] = {raw}; + ant_value_t parsed = js_json_parse(js, parse_args, 1); js_set(js, lib, "workerData", is_err(parsed) ? js_mkundef() : parsed); } else js_set(js, lib, "workerData", js_mkundef()); } else { @@ -1014,8 +1014,8 @@ jsval_t worker_threads_library(ant_t *js) { js_set(js, lib, "workerData", js_mkundef()); } - jsval_t worker_ctor_obj = js_mkobj(js); - jsval_t worker_proto = js_mkobj(js); + ant_value_t worker_ctor_obj = js_mkobj(js); + ant_value_t worker_proto = js_mkobj(js); js_set(js, worker_proto, "on", js_mkfun(worker_threads_worker_on)); js_set(js, worker_proto, "once", js_mkfun(worker_threads_worker_once)); diff --git a/src/reactor.c b/src/reactor.c index ca8fc98..a679f22 100644 --- a/src/reactor.c +++ b/src/reactor.c @@ -82,7 +82,7 @@ drain: } js_poll_events(js); - jsval_t code = js_mknum(0); + ant_value_t code = js_mknum(0); emit_process_event("beforeExit", &code, 1); if (event_loop_alive()) goto drain; diff --git a/src/repl.c b/src/repl.c index 16d6d30..9b985e8 100644 --- a/src/repl.c +++ b/src/repl.c @@ -235,7 +235,7 @@ static bool repl_precheck_and_commit_lexicals( bool ok = true; repl_clear_exception_state(js); - sv_ast_t *program = sv_parse(js, code, (jsoff_t)len, false); + sv_ast_t *program = sv_parse(js, code, (ant_offset_t)len, false); if (!program || js->thrown_exists) { ok = true; @@ -293,7 +293,7 @@ static void repl_eval_chunk( } repl_clear_exception_state(js); - jsval_t result = js_eval_bytecode_repl(js, code, len); + ant_value_t result = js_eval_bytecode_repl(js, code, len); js_run_event_loop(js); if (js->thrown_exists) { @@ -422,8 +422,8 @@ static cmd_result_t cmd_save(ant_t *js, history_t *history, const char *arg) { } static cmd_result_t cmd_stats(ant_t *js, history_t *history, const char *arg) { - jsval_t stats_fn = js_get(js, rt->ant_obj, "stats"); - jsval_t result = sv_vm_call(js->vm, js, stats_fn, js_mkundef(), NULL, 0, NULL, false); + ant_value_t stats_fn = js_get(js, rt->ant_obj, "stats"); + ant_value_t result = sv_vm_call(js->vm, js, stats_fn, js_mkundef(), NULL, 0, NULL, false); console_print(js, &result, 1, NULL, stdout); return CMD_OK; } @@ -482,7 +482,7 @@ static cmd_result_t cmd_copy(ant_t *js, history_t *history, const char *arg) { } repl_clear_exception_state(js); - jsval_t result = js_eval_bytecode_repl(js, arg, strlen(arg)); + ant_value_t result = js_eval_bytecode_repl(js, arg, strlen(arg)); js_run_event_loop(js); if (js->thrown_exists) { diff --git a/src/roots.c b/src/roots.c index 7a851fd..0ab89fa 100644 --- a/src/roots.c +++ b/src/roots.c @@ -3,10 +3,10 @@ #include "arena.h" #include "internal.h" // IWYU pragma: keep -jshdl_t js_root(ant_t *js, jsval_t val) { +ant_handle_t js_root(ant_t *js, ant_value_t val) { if (js->gc_roots_len >= js->gc_roots_cap) { - jshdl_t new_cap = js->gc_roots_cap ? js->gc_roots_cap * 2 : GC_ROOTS_INITIAL_CAP; - jsval_t *new_roots = ant_realloc(js->gc_roots, new_cap * sizeof(jsval_t)); + ant_handle_t new_cap = js->gc_roots_cap ? js->gc_roots_cap * 2 : GC_ROOTS_INITIAL_CAP; + ant_value_t *new_roots = ant_realloc(js->gc_roots, new_cap * sizeof(ant_value_t)); if (!new_roots) { fprintf(stderr, "FATAL: Out of memory allocating GC roots\n"); abort(); @@ -14,20 +14,20 @@ jshdl_t js_root(ant_t *js, jsval_t val) { js->gc_roots = new_roots; js->gc_roots_cap = new_cap; } - jshdl_t idx = js->gc_roots_len++; + ant_handle_t idx = js->gc_roots_len++; js->gc_roots[idx] = val; return idx; } -jsval_t js_deref(ant_t *js, jshdl_t h) { +ant_value_t js_deref(ant_t *js, ant_handle_t h) { if (h < 0 || h >= js->gc_roots_len) return js_mkundef(); return js->gc_roots[h]; } -void js_unroot(ant_t *js, jshdl_t h) { +void js_unroot(ant_t *js, ant_handle_t h) { if (h >= 0 && h == js->gc_roots_len - 1) js->gc_roots_len--; } -void js_root_update(ant_t *js, jshdl_t h, jsval_t val) { +void js_root_update(ant_t *js, ant_handle_t h, ant_value_t val) { if (h >= 0 && h < js->gc_roots_len) js->gc_roots[h] = val; } \ No newline at end of file diff --git a/src/runtime.c b/src/runtime.c index 07ffa93..8c8754a 100644 --- a/src/runtime.c +++ b/src/runtime.c @@ -171,7 +171,7 @@ struct ant_runtime *ant_runtime_init(ant_t *js, int argc, char **argv, struct ar .ls_fp = (ls_p && ls_p->count > 0) ? ls_p->filename[0] : NULL, }; - jsval_t global = js_glob(js); + ant_value_t global = js_glob(js); js_set(js, global, "global", global); js_set(js, global, "window", global); js_set(js, global, "globalThis", global); diff --git a/src/silver/ast.c b/src/silver/ast.c index 59ca151..a98aecb 100644 --- a/src/silver/ast.c +++ b/src/silver/ast.c @@ -230,9 +230,9 @@ static inline void sv_parse_unexpected_token(P) { size_t tok_len = 0; if (TOFF < CLEN && TLEN > 0) { - jsoff_t rem = CLEN - TOFF; + ant_offset_t rem = CLEN - TOFF; tok_len = (size_t)TLEN; - if ((jsoff_t)tok_len > rem) tok_len = (size_t)rem; + if ((ant_offset_t)tok_len > rem) tok_len = (size_t)rem; } if (tok_len == 0) { @@ -621,7 +621,7 @@ static sv_ast_t *parse_primary(P) { ? (tpl_len - 1 - expr_start) : 0; sv_lexer_checkpoint_t cp; - sv_lexer_push_source(&p->lx, &cp, (const char *)&in[expr_start], (jsoff_t)expr_max_len); + sv_lexer_push_source(&p->lx, &cp, (const char *)&in[expr_start], (ant_offset_t)expr_max_len); sv_ast_t *expr = parse_expr(p); sv_ast_list_push(&n->args, expr); @@ -768,7 +768,7 @@ static sv_ast_t *parse_primary(P) { l_regex: { CONSUME(); - jsoff_t pattern_start = (TOK == TOK_DIV_ASSIGN) ? (TOFF + 1) : POS; + ant_offset_t pattern_start = (TOK == TOK_DIV_ASSIGN) ? (TOFF + 1) : POS; if (TOK == TOK_DIV_ASSIGN) POS = pattern_start; bool in_class = false; @@ -784,10 +784,10 @@ static sv_ast_t *parse_primary(P) { POS++; } - jsoff_t pattern_end = POS; + ant_offset_t pattern_end = POS; if (POS < CLEN) POS++; - jsoff_t flags_start = POS; + ant_offset_t flags_start = POS; while (POS < CLEN) { char c = CODE[POS]; if (c == 'g' || c == 'i' || c == 'm' || c == 's' || c == 'u' || c == 'y') @@ -795,7 +795,7 @@ static sv_ast_t *parse_primary(P) { else break; } - jsoff_t flags_end = POS; + ant_offset_t flags_end = POS; sv_ast_t *n = mk(N_REGEXP); n->str = &CODE[pattern_start]; @@ -2047,7 +2047,7 @@ static sv_ast_t *parse_stmt(P) { } } -sv_ast_t *sv_parse(ant_t *js, const char *code, jsoff_t clen, bool strict){ +sv_ast_t *sv_parse(ant_t *js, const char *code, ant_offset_t clen, bool strict){ sv_parser_t parser = { .js = js }; sv_parser_t *p = &parser; sv_lexer_init(&p->lx, js, code, clen, strict); diff --git a/src/silver/compiler.c b/src/silver/compiler.c index 5ee8bde..07ec75f 100644 --- a/src/silver/compiler.c +++ b/src/silver/compiler.c @@ -44,13 +44,13 @@ typedef struct { typedef struct sv_compiler { ant_t *js; const char *source; - jsoff_t source_len; + ant_offset_t source_len; uint8_t *code; int code_len; int code_cap; - jsval_t *constants; + ant_value_t *constants; int const_count; int const_cap; @@ -153,7 +153,7 @@ static void compile_switch(sv_compiler_t *c, sv_ast_t *node); static void compile_label(sv_compiler_t *c, sv_ast_t *node); static void compile_class(sv_compiler_t *c, sv_ast_t *node); -static const char *pin_source_text(const char *source, jsoff_t source_len) { +static const char *pin_source_text(const char *source, ant_offset_t source_len) { if (!source || source_len <= 0) return source; const char *pinned = code_arena_alloc(source, (size_t)source_len); return pinned ? pinned : source; @@ -192,7 +192,7 @@ static void emit_op(sv_compiler_t *c, sv_op_t op) { static void emit_srcpos(sv_compiler_t *c, sv_ast_t *node) { if (!node) return; const char *code = c->source; - jsoff_t clen = c->source_len; + ant_offset_t clen = c->source_len; if (!code || clen <= 0) return; uint32_t off = node->src_off; @@ -231,16 +231,16 @@ static void patch_u32(sv_compiler_t *c, int offset, uint32_t val) { c->code[offset + 3] = (uint8_t)((val >> 24) & 0xFF); } -static int add_constant(sv_compiler_t *c, jsval_t val) { +static int add_constant(sv_compiler_t *c, ant_value_t val) { if (c->const_count >= c->const_cap) { c->const_cap = c->const_cap ? c->const_cap * 2 : 16; - c->constants = realloc(c->constants, (size_t)c->const_cap * sizeof(jsval_t)); + c->constants = realloc(c->constants, (size_t)c->const_cap * sizeof(ant_value_t)); } c->constants[c->const_count] = val; return c->const_count++; } -static void emit_constant(sv_compiler_t *c, jsval_t val) { +static void emit_constant(sv_compiler_t *c, ant_value_t val) { int idx = add_constant(c, val); if (idx <= 255) { emit_op(c, OP_CONST8); @@ -270,7 +270,7 @@ static inline bool is_invalid_cooked_string(const sv_ast_t *node) { return node && (node->flags & FN_INVALID_COOKED); } -static inline jsval_t ast_string_const(sv_compiler_t *c, const sv_ast_t *node) { +static inline ant_value_t ast_string_const(sv_compiler_t *c, const sv_ast_t *node) { if (!node || !node->str) return js_mkstr(c->js, "", 0); return js_mkstr(c->js, node->str, node->len); } @@ -1003,7 +1003,7 @@ static void compile_expr(sv_compiler_t *c, sv_ast_t *node) { neg = true; digits++; dlen--; } if (dlen > 0 && digits[dlen - 1] == 'n') dlen--; - jsval_t bi = js_mkbigint(c->js, digits, dlen, neg); + ant_value_t bi = js_mkbigint(c->js, digits, dlen, neg); emit_constant(c, bi); break; } @@ -1584,7 +1584,7 @@ static void compile_delete(sv_compiler_t *c, sv_ast_t *node) { sv_ast_t *arg = node->right; if (arg->type == N_MEMBER && !(arg->flags & 1)) { compile_expr(c, arg->left); - jsval_t key = js_mkstr(c->js, arg->right->str, arg->right->len); + ant_value_t key = js_mkstr(c->js, arg->right->str, arg->right->len); emit_constant(c, key); emit_op(c, OP_DELETE); } else if (arg->type == N_MEMBER && (arg->flags & 1)) { @@ -3429,8 +3429,8 @@ static void compile_class(sv_compiler_t *c, sv_ast_t *node) { memcpy(fn->code, comp.code, (size_t)comp.code_len); fn->code_len = comp.code_len; if (comp.const_count > 0) { - fn->constants = code_arena_bump((size_t)comp.const_count * sizeof(jsval_t)); - memcpy(fn->constants, comp.constants, (size_t)comp.const_count * sizeof(jsval_t)); + fn->constants = code_arena_bump((size_t)comp.const_count * sizeof(ant_value_t)); + memcpy(fn->constants, comp.constants, (size_t)comp.const_count * sizeof(ant_value_t)); fn->const_count = comp.const_count; } if (comp.atom_count > 0) { @@ -3861,8 +3861,8 @@ static sv_func_t *compile_function_body( func->code_len = comp.code_len; if (comp.const_count > 0) { - func->constants = code_arena_bump((size_t)comp.const_count * sizeof(jsval_t)); - memcpy(func->constants, comp.constants, (size_t)comp.const_count * sizeof(jsval_t)); + func->constants = code_arena_bump((size_t)comp.const_count * sizeof(ant_value_t)); + memcpy(func->constants, comp.constants, (size_t)comp.const_count * sizeof(ant_value_t)); func->const_count = comp.const_count; } @@ -3953,7 +3953,7 @@ void sv_disasm(ant_t *js, sv_func_t *func, const char *label) { fprintf(stderr, "Bytecode length: %d\n", func->code_len); fprintf(stderr, "Parameter count %d\n", func->param_count); fprintf(stderr, "Register count %d\n", func->max_locals); - fprintf(stderr, "Frame size %d\n", func->max_locals * (int)sizeof(jsval_t)); + fprintf(stderr, "Frame size %d\n", func->max_locals * (int)sizeof(ant_value_t)); int pc = 0; while (pc < func->code_len) { @@ -4067,11 +4067,11 @@ void sv_disasm(ant_t *js, sv_func_t *func, const char *label) { fprintf(stderr, "Constant pool (size = %d)\n", func->const_count); for (int i = 0; i < func->const_count; i++) { - jsval_t v = func->constants[i]; + ant_value_t v = func->constants[i]; uint8_t t = vtype(v); if (t == T_STR) { - jsoff_t slen; - jsoff_t soff = vstr(js, v, &slen); + ant_offset_t slen; + ant_offset_t soff = vstr(js, v, &slen); fprintf(stderr, " %d: \n", i, (int)slen, (int)slen, &js->mem[soff]); } else if (t == T_NUM) { fprintf(stderr, " %d: \n", i, tod(v)); @@ -4103,7 +4103,7 @@ void sv_disasm(ant_t *js, sv_func_t *func, const char *label) { } } -sv_func_t *sv_compile(ant_t *js, sv_ast_t *program, sv_compile_mode_t mode, const char *source, jsoff_t source_len) { +sv_func_t *sv_compile(ant_t *js, sv_ast_t *program, sv_compile_mode_t mode, const char *source, ant_offset_t source_len) { if (!program || program->type != N_PROGRAM) return NULL; static const char *k_top_name_script = "