From 285758127119bf700c3a0348b14f39b2dee5293b Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Tue, 27 Jan 2026 10:42:49 -0600 Subject: [PATCH] cleanup --- source/quickjs.c | 327 +++++++++++++++++++++++------------------------ source/quickjs.h | 65 +++++----- 2 files changed, 187 insertions(+), 205 deletions(-) diff --git a/source/quickjs.c b/source/quickjs.c index ee68e0f5..494e6771 100644 --- a/source/quickjs.c +++ b/source/quickjs.c @@ -185,7 +185,6 @@ typedef enum JSErrorEnum { JS_REFERENCE_ERROR, JS_SYNTAX_ERROR, JS_TYPE_ERROR, - JS_URI_ERROR, JS_INTERNAL_ERROR, JS_AGGREGATE_ERROR, @@ -272,7 +271,7 @@ struct JSRuntime { /* see JS_SetStripInfo() */ uint8_t strip_flags; - + /* Shape hash table */ int shape_hash_bits; int shape_hash_size; @@ -382,7 +381,7 @@ enum mist_obj_type { OBJ_ARRAY = 0, OBJ_BLOB = 1, OBJ_TEXT = 2, - OBJ_RECORD = 3, + OBJ_RECORD = 3, // js style objects OBJ_FUNCTION= 4, OBJ_CODE = 5, OBJ_FRAME = 6, @@ -480,10 +479,10 @@ typedef struct mist_slot { typedef struct mist_record { objhdr_t hdr; word_t len_fields; + word_t parent; // objref_t to parent record or 0 mist_slot slot[]; // slot[0] corresponds to field #1, ..., slot[cap-1] is field #cap } mist_record; - #ifdef RC_TRACE typedef struct RcEvent { JSGCObjectHeader *ptr; @@ -614,7 +613,7 @@ typedef struct JSVarRef { }; /* used when is_detached = FALSE */ }; } JSVarRef; - + /* must be large enough to have a negligible runtime cost and small enough to call the interrupt callback often. */ #define JS_INTERRUPT_COUNTER_INIT 10000 @@ -654,7 +653,7 @@ struct JSContext { const char *input, size_t input_len, const char *filename, int flags, int scope_idx); void *user_opaque; - + js_hook trace_hook; int trace_type; void *trace_data; @@ -1160,14 +1159,12 @@ static int JS_NewClass1(JSRuntime *rt, JSClassID class_id, typedef enum JSStrictEqModeEnum { JS_EQ_STRICT, JS_EQ_SAME_VALUE, - JS_EQ_SAME_VALUE_ZERO, } JSStrictEqModeEnum; static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2, JSStrictEqModeEnum eq_mode); static BOOL js_strict_eq(JSContext *ctx, JSValueConst op1, JSValueConst op2); static BOOL js_same_value(JSContext *ctx, JSValueConst op1, JSValueConst op2); -static BOOL js_same_value_zero(JSContext *ctx, JSValueConst op1, JSValueConst op2); static JSValue JS_ToObject(JSContext *ctx, JSValueConst val); static JSValue JS_ToObjectFree(JSContext *ctx, JSValue val); static JSValue js_cell_text(JSContext *ctx, JSValueConst this_val, @@ -4061,13 +4058,13 @@ static int js_string_rope_compare(JSContext *ctx, JSValueConst op1, int res; JSStringRopeIter it1, it2; JSString *p1, *p2; - + len1 = string_rope_get_len(op1); len2 = string_rope_get_len(op2); /* no need to go further for equality test if different length */ if (eq_only && len1 != len2) - return 1; + return 1; len = min_uint32(len1, len2); string_rope_iter_init(&it1, op1); string_rope_iter_init(&it2, op2); @@ -4110,7 +4107,7 @@ static JSValue js_linearize_string_rope(JSContext *ctx, JSValue rope) StringBuffer b_s, *b = &b_s; JSStringRope *r; JSValue ret; - + r = JS_VALUE_GET_STRING_ROPE(rope); /* check whether it is already linearized */ @@ -4148,7 +4145,7 @@ static JSValue js_new_string_rope(JSContext *ctx, JSValue op1, JSValue op2) int is_wide_char, depth; JSStringRope *r; JSValue res; - + if (JS_VALUE_GET_TAG(op1) == JS_TAG_STRING) { JSString *p1 = JS_VALUE_GET_STRING(op1); len = p1->len; @@ -4192,7 +4189,7 @@ static JSValue js_new_string_rope(JSContext *ctx, JSValue op1, JSValue op2) #endif res2 = js_rebalancee_string_rope(ctx, res); #ifdef DUMP_ROPE_REBALANCE - if (JS_VALUE_GET_TAG(res2) == JS_TAG_STRING_ROPE) + if (JS_VALUE_GET_TAG(res2) == JS_TAG_STRING_ROPE) printf("rebalance: final depth=%d\n", JS_VALUE_GET_STRING_ROPE(res2)->depth); #endif JS_FreeValue(ctx, res); @@ -4230,7 +4227,7 @@ static int js_rebalancee_string_rope_rec(JSContext *ctx, JSValue *buckets, JSString *p = JS_VALUE_GET_STRING(val); uint32_t len, i; JSValue a, b; - + len = p->len; if (len == 0) return 0; /* nothing to do */ @@ -4283,7 +4280,7 @@ static JSValue js_rebalancee_string_rope(JSContext *ctx, JSValueConst rope) { JSValue buckets[ROPE_N_BUCKETS], a, b; int i; - + for(i = 0; i < ROPE_N_BUCKETS; i++) buckets[i] = JS_NULL; if (js_rebalancee_string_rope_rec(ctx, buckets, rope)) @@ -6624,7 +6621,7 @@ static int find_line_num(JSContext *ctx, JSFunctionBytecode *b, goto fail; p += ret; new_col_num = col_num + v; - + if (pc_value < pc) goto done; line_num = new_line_num; @@ -6662,7 +6659,7 @@ static const char *get_prop_string(JSContext *ctx, JSValueConst obj, JSAtom prop if (!prs) return NULL; } - + if ((prs->flags & JS_PROP_TMASK) != JS_PROP_NORMAL) return NULL; val = pr->u.value; @@ -6710,7 +6707,7 @@ static void build_backtrace(JSContext *ctx, JSValueConst error_obj, if (!JS_IsObject(error_obj)) return; /* protection in the out of memory case */ - + js_dbuf_init(ctx, &dbuf); if (filename) { dbuf_printf(&dbuf, " at %s", filename); @@ -7024,6 +7021,25 @@ static JSValue JS_GetPrototypeFree(JSContext *ctx, JSValue obj) return obj1; } +JSValue JS_GetPropertyV(JSContext *ctx, JSValue obj, JSValue prop) +{ + int otag = JS_VALUE_GET_TAG(obj); + int ptag = JS_VALUE_GET_TAG(prop); + + if (otag == JS_TAG_NULL) + return JS_NULL; + + jf (otag != JS_TAG_OBJECT) + return JS_ThrowtypeError("cannot get property from this object."); + + MistObject *mobj = JS_VALUE_GET_OBJ(obj); +} + +JSValue JS_SetPropertyV(JSContext *ctx, JSValue obj, JSValue prop) +{ + +} + /* This is for getting string or symbol based properties */ JSValue JS_GetPropertyInternal(JSContext *ctx, JSValueConst obj, JSAtom prop, JSValueConst this_obj, @@ -7291,8 +7307,7 @@ static uint32_t js_string_get_length(JSValueConst val) } } -static JSValue JS_GetPropertyValue(JSContext *ctx, JSValueConst this_obj, - JSValue prop) +static JSValue JS_GetPropertyValue(JSContext *ctx, JSValueConst this_obj, JSValue prop) { JSAtom atom; JSValue ret; @@ -8263,7 +8278,7 @@ static JSValue js_atof(JSContext *ctx, const char *str, const char **pp, BOOL buf_allocated = FALSE; JSValue val; JSATODTempMem atod_mem; - + /* optional separator between digits */ sep = (flags & ATOD_ACCEPT_UNDERSCORES) ? '_' : 256; @@ -8471,7 +8486,7 @@ static __exception int __JS_ToFloat64Free(JSContext *ctx, double *pres, { double d; uint32_t tag; - + val = JS_ToNumberFree(ctx, val); if (JS_IsException(val)) goto fail; @@ -8825,20 +8840,6 @@ static __exception int JS_ToArrayLengthFree(JSContext *ctx, uint32_t *plen, #define MAX_SAFE_INTEGER (((int64_t)1 << 53) - 1) -int JS_ToIndex(JSContext *ctx, uint64_t *plen, JSValueConst val) -{ - int64_t v; - if (JS_ToInt64Sat(ctx, &v, val)) - return -1; - if (v < 0 || v > MAX_SAFE_INTEGER) { - JS_ThrowRangeError(ctx, "invalid array index"); - *plen = 0; - return -1; - } - *plen = v; - return 0; -} - /* convert a value to a length between 0 and MAX_SAFE_INTEGER. return -1 for exception */ static __exception int JS_ToLengthFree(JSContext *ctx, int64_t *plen, @@ -8857,7 +8858,7 @@ static JSValue js_dtoa2(JSContext *ctx, JSValue res; JSDTOATempMem dtoa_mem; len_max = js_dtoa_max_len(d, radix, n_digits, flags); - + /* longer buffer may be used if radix != 10 */ if (len_max > sizeof(static_buf) - 1) { tmp_buf = js_malloc(ctx, len_max + 1); @@ -9053,7 +9054,7 @@ static void __attribute__((format(printf, 2, 3))) js_printf(JSPrintValueState *s { va_list ap; char buf[256]; - + va_start(ap, fmt); vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); @@ -9211,7 +9212,7 @@ static void js_print_object(JSPrintValueState *s, JSObject *p) int comma_state; BOOL is_array; uint32_t i; - + comma_state = 0; is_array = FALSE; if (p->class_id == JS_CLASS_REGEXP && s->ctx && !s->options.raw_dump) { @@ -9245,11 +9246,11 @@ static void js_print_object(JSPrintValueState *s, JSObject *p) } js_printf(s, "{ "); } - + sh = p->shape; /* the shape can be NULL while freeing an object */ if (sh) { uint32_t j; - + j = 0; for(i = 0, prs = get_shape_prop(sh); i < sh->prop_count; i++, prs++) { if (prs->atom != JS_ATOM_NULL) { @@ -9258,7 +9259,7 @@ static void js_print_object(JSPrintValueState *s, JSObject *p) js_print_comma(s, &comma_state); js_print_atom(s, prs->atom); js_printf(s, ": "); - + /* XXX: autoinit property */ if ((prs->flags & JS_PROP_TMASK) == JS_PROP_VARREF) { if (s->options.raw_dump) { @@ -9426,7 +9427,7 @@ void JS_PrintValueSetDefaultOptions(JSPrintValueOptions *options) options->max_item_count = 100; } -static void JS_PrintValueInternal(JSRuntime *rt, JSContext *ctx, +static void JS_PrintValueInternal(JSRuntime *rt, JSContext *ctx, JSPrintValueWrite *write_func, void *write_opaque, JSValueConst val, const JSPrintValueOptions *options) { @@ -9505,7 +9506,7 @@ static __maybe_unused void JS_DumpObject(JSRuntime *rt, JSObject *p) { JSShape *sh; JSPrintValueOptions options; - + /* XXX: should encode atoms with special characters */ sh = p->shape; /* the shape can be NULL while freeing an object */ printf("%14p %4d ", @@ -9686,7 +9687,7 @@ static no_inline __exception int js_binary_arith_slow(JSContext *ctx, JSValue *s d2 = JS_VALUE_GET_FLOAT64(op2); goto handle_float64; } - + if ((tag1 == JS_TAG_INT && tag2 == JS_TAG_FLOAT64) || (tag1 == JS_TAG_FLOAT64 && tag2 == JS_TAG_INT)) { if(tag1 == JS_TAG_INT) d1 = (double)JS_VALUE_GET_INT(op1); @@ -9698,7 +9699,7 @@ static no_inline __exception int js_binary_arith_slow(JSContext *ctx, JSValue *s d2 = JS_VALUE_GET_FLOAT64(op2); goto handle_float64; } - + op1 = JS_ToNumberFree(ctx, op1); if (JS_IsException(op1)) { JS_FreeValue(ctx, op2); @@ -9853,7 +9854,7 @@ exception: static BOOL tag_is_number(uint32_t tag) { - return (tag == JS_TAG_INT || + return (tag == JS_TAG_INT || tag == JS_TAG_FLOAT64); } @@ -9867,7 +9868,7 @@ static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2, tag1 = JS_VALUE_GET_NORM_TAG(op1); tag2 = JS_VALUE_GET_NORM_TAG(op2); - + switch(tag1) { case JS_TAG_BOOL: if (tag1 != tag2) { @@ -9933,8 +9934,6 @@ static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2, /* NaN is not always normalized, so this test is necessary */ if (isnan(d1) || isnan(d2)) { res = isnan(d1) == isnan(d2); - } else if (eq_mode == JS_EQ_SAME_VALUE_ZERO) { - res = (d1 == d2); /* +0 == -0 */ } else { u1.d = d1; u2.d = d2; @@ -9978,18 +9977,6 @@ BOOL JS_SameValue(JSContext *ctx, JSValueConst op1, JSValueConst op2) return js_same_value(ctx, op1, op2); } -static BOOL js_same_value_zero(JSContext *ctx, JSValueConst op1, JSValueConst op2) -{ - return js_strict_eq2(ctx, - JS_DupValue(ctx, op1), JS_DupValue(ctx, op2), - JS_EQ_SAME_VALUE_ZERO); -} - -BOOL JS_SameValueZero(JSContext *ctx, JSValueConst op1, JSValueConst op2) -{ - return js_same_value_zero(ctx, op1, op2); -} - static no_inline int js_strict_eq_slow(JSContext *ctx, JSValue *sp, BOOL is_neq) { @@ -10314,13 +10301,13 @@ static JSValue js_call_c_function(JSContext *ctx, JSValueConst func_obj, sf->arg_buf = (JSValue*)arg_buf; func = f->u.cfunc.c_function; - + if (unlikely(ctx->trace_hook) && (ctx->trace_type & JS_HOOK_CALL)) { js_debug dbg; js_debug_info(ctx, func_obj, &dbg); ctx->trace_hook(ctx, JS_HOOK_CALL, &dbg, ctx->trace_data); } - + switch(cproto) { case JS_CFUNC_generic: ret_val = func.generic(ctx, this_obj, argc, arg_buf); @@ -10575,7 +10562,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, } else { arg_allocated_size = 0; } - + alloca_size = sizeof(JSValue) * (arg_allocated_size + b->var_count + b->stack_size); if (js_check_stack_overflow(rt, alloca_size)) @@ -11848,7 +11835,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, if (op_flags == OP_DEFINE_METHOD_METHOD) { value = sp[-1]; - } + } ret = js_method_set_properties(ctx, sp[-1], atom, 0, obj); if (ret >= 0) { /* JS_SetProperty consumes value, so don't free sp[-1] on success */ @@ -11925,13 +11912,13 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, goto exception; } BREAK; - + CASE(OP_get_ref_value): { JSValue val; JSAtom atom; int ret; - + sf->cur_pc = pc; atom = JS_ValueToAtom(ctx, sp[-1]); if (atom == JS_ATOM_NULL) @@ -12046,7 +12033,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, JSValue op1 = sp[-2], op2 = sp[-1], res; int tag1 = JS_VALUE_GET_NORM_TAG(op1); int tag2 = JS_VALUE_GET_NORM_TAG(op2); - + /* 1) both ints? keep fast int path with overflow check */ if (likely(JS_VALUE_IS_BOTH_INT(op1, op2))) { int64_t tmp = (int64_t)JS_VALUE_GET_INT(op1) @@ -12109,7 +12096,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, JSValue res; int tag1 = JS_VALUE_GET_NORM_TAG(lhs); int tag2 = JS_VALUE_GET_NORM_TAG(rhs); - + /* 1) both ints? fast path, overflow → float64 */ if (likely(JS_VALUE_IS_BOTH_INT(lhs, rhs))) { int a_i = JS_VALUE_GET_INT(lhs); @@ -12754,10 +12741,10 @@ CASE(OP_template_concat): JS_FreeValue(ctx, *pval); } rt->current_stack_frame = sf->prev_frame; - + if (unlikely(caller_ctx->trace_hook) && (caller_ctx->trace_type & JS_HOOK_RET)) caller_ctx->trace_hook(caller_ctx, JS_HOOK_RET, NULL, caller_ctx->trace_data); - + return ret_val; } @@ -13267,7 +13254,7 @@ static int get_line_col(int *pcol_num, const uint8_t *buf, size_t len) { int line_num, col_num, c; size_t i; - + line_num = 0; col_num = 0; for(i = 0; i < len; i++) { @@ -13334,7 +13321,7 @@ static __attribute__((format(printf, 3, 4))) int js_parse_error_pos(JSParseState { va_list ap; int ret; - + va_start(ap, fmt); ret = js_parse_error_v(s, ptr, fmt, ap); va_end(ap); @@ -13345,7 +13332,7 @@ static __attribute__((format(printf, 2, 3))) int js_parse_error(JSParseState *s, { va_list ap; int ret; - + va_start(ap, fmt); ret = js_parse_error_v(s, s->token.ptr, fmt, ap); va_end(ap); @@ -14257,7 +14244,7 @@ static int json_parse_string(JSParseState *s, const uint8_t **pp, int sep) case 'r': c = '\r'; break; case 't': c = '\t'; break; case '\\': break; - case '/': break; + case '/': break; case 'u': c = 0; for(i = 0; i < 4; i++) { @@ -14320,7 +14307,7 @@ static int json_parse_number(JSParseState *s, const uint8_t **pp) int radix; double d; JSATODTempMem atod_mem; - + if (*p == '+' || *p == '-') p++; @@ -15504,7 +15491,7 @@ static int js_parse_skip_parens_token(JSParseState *s, int *pbits, BOOL no_line_ int last_tok, tok = TOK_EOF; int c, tok_len, bits = 0; const uint8_t *last_token_ptr; - + /* protect from underflow */ state[level++] = 0; @@ -16357,7 +16344,7 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) int optional_chaining_label; BOOL accept_lparen = (parse_flags & PF_POSTFIX_CALL) != 0; const uint8_t *op_token_ptr; - + call_type = FUNC_CALL_NORMAL; switch(s->token.val) { case TOK_NUMBER: @@ -16788,7 +16775,7 @@ static __exception int js_parse_delete(JSParseState *s) name = get_u32(fd->byte_code.buf + fd->last_opcode_pos + 1); if (name == JS_ATOM_this || name == JS_ATOM_new_target) goto ret_true; - + return js_parse_error(s, "cannot delete a direct reference in strict mode"); break; default: @@ -16911,7 +16898,7 @@ static __exception int js_parse_expr_binary(JSParseState *s, int level, { int op, opcode; const uint8_t *op_token_ptr; - + if (level == 0) { return js_parse_unary(s, PF_POW_ALLOWED); } else { @@ -17504,7 +17491,7 @@ static int is_let(JSParseState *s, int decl_mask) { int res = FALSE; const uint8_t *last_token_ptr; - + if (token_is_pseudo_keyword(s, JS_ATOM_let)) { JSParsePos pos; js_parse_get_pos(s, &pos); @@ -18316,7 +18303,7 @@ static JSFunctionDef *js_new_function_def(JSContext *ctx, fd->filename = JS_NewAtom(ctx, filename); fd->source_pos = source_ptr - get_line_col_cache->buf_start; fd->get_line_col_cache = get_line_col_cache; - + js_dbuf_init(ctx, &fd->pc2line); //fd->pc2line_last_line_num = line_num; //fd->pc2line_last_pc = 0; @@ -18463,7 +18450,7 @@ static void dump_byte_code(JSContext *ctx, int pass, int col_num; line_num = find_line_num(ctx, b, -1, &col_num); } - + /* scan for jump targets */ for (pos = 0; pos < len; pos = pos_next) { op = tab[pos]; @@ -18728,7 +18715,7 @@ static __maybe_unused void dump_pc2line(JSContext *ctx, const uint8_t *buf, int int pc, v, line_num, col_num, ret; unsigned int op; uint32_t val; - + if (len <= 0) return; @@ -18736,7 +18723,7 @@ static __maybe_unused void dump_pc2line(JSContext *ctx, const uint8_t *buf, int p = buf; p_end = buf + len; - + /* get the function line and column numbers */ ret = get_leb128(&val, p, p_end); if (ret < 0) @@ -18751,7 +18738,7 @@ static __maybe_unused void dump_pc2line(JSContext *ctx, const uint8_t *buf, int col_num = val + 1; printf("%5s %5d %5d\n", "-", line_num, col_num); - + pc = 0; while (p < p_end) { op = *p++; @@ -18776,7 +18763,7 @@ static __maybe_unused void dump_pc2line(JSContext *ctx, const uint8_t *buf, int goto fail; p += ret; col_num += v; - + printf("%5d %5d %5d\n", pc, line_num, col_num); } fail: ; @@ -20233,7 +20220,7 @@ static __exception int resolve_variables(JSContext *ctx, JSFunctionDef *s) JSVarDef *vd = &s->vars[scope_idx]; if (vd->scope_level != scope) break; - + if (vd->var_kind == JS_VAR_FUNCTION_DECL || vd->var_kind == JS_VAR_NEW_FUNCTION_DECL) { /* Initialize lexical variable upon entering scope */ @@ -20433,7 +20420,7 @@ static void compute_pc2line_info(JSFunctionDef *s) dbuf_put_sleb128(&s->pc2line, diff_line); } dbuf_put_sleb128(&s->pc2line, diff_col); - + last_pc = pc; last_line_num = line_num; last_col_num = col_num; @@ -22065,7 +22052,7 @@ static __exception int js_parse_function_decl2(JSParseState *s, fd->has_prototype = (func_type == JS_PARSE_FUNC_STATEMENT || func_type == JS_PARSE_FUNC_VAR || func_type == JS_PARSE_FUNC_EXPR); - + fd->has_this_binding = (func_type != JS_PARSE_FUNC_ARROW && func_type != JS_PARSE_FUNC_CLASS_STATIC_INIT); @@ -22563,7 +22550,7 @@ static JSValue JS_EvalInternal(JSContext *ctx, JSValueConst this_obj, BOOL backtrace_barrier = ((flags & JS_EVAL_FLAG_BACKTRACE_BARRIER) != 0); int saved_js_mode = 0; JSValue ret; - + if (unlikely(!ctx->eval_internal)) { return JS_ThrowTypeError(ctx, "eval is not supported"); } @@ -24300,7 +24287,7 @@ static JSValue JS_GetOwnPropertyNames2(JSContext *ctx, JSValueConst obj1, val = JS_AtomToValue(ctx, atom); if (JS_IsException(val)) goto exception; - + JS_ArrayPush(ctx, r, val); } goto done; @@ -24483,7 +24470,7 @@ static JSValue js_error_constructor(JSContext *ctx, JSValueConst this_val, goto exception; JS_SetPropertyInternal(ctx, obj, JS_ATOM_message, msg); } - + if (arg_index < argc) { options = argv[arg_index]; if (JS_IsObject(options)) { @@ -24663,7 +24650,7 @@ static JSValue js_compile_regexp(JSContext *ctx, JSValueConst pattern, bad_flags1: return JS_ThrowSyntaxError(ctx, "invalid regular expression flags"); } - + str = JS_ToCStringLen2(ctx, &len, pattern, !(re_flags & (LRE_FLAG_UNICODE | LRE_FLAG_UNICODE_SETS))); if (!str) return JS_EXCEPTION; @@ -24886,7 +24873,7 @@ int lre_check_timeout(void *opaque) { JSContext *ctx = opaque; JSRuntime *rt = ctx->rt; - return (rt->interrupt_handler && + return (rt->interrupt_handler && rt->interrupt_handler(rt, rt->interrupt_opaque)); } @@ -25348,8 +25335,8 @@ static JSValue json_parse_value(JSParseState *s) } else if (s->token.u.ident.atom == JS_ATOM_null) { val = JS_NULL; } else if (s->token.u.ident.atom == JS_ATOM_NaN && s->ext_json) { - /* Note: json5 identifier handling is ambiguous e.g. is - '{ NaN: 1 }' a valid JSON5 production ? */ + /* Note: json5 identifier handling is ambiguous e.g. is + '{ NaN: 1 }' a valid JSON5 production ? */ val = JS_NewFloat64(s->ctx, NAN); } else if (s->token.u.ident.atom == JS_ATOM_Infinity && s->ext_json) { val = JS_NewFloat64(s->ctx, INFINITY); @@ -27173,7 +27160,7 @@ static int JS_IsRegExp(JSContext *ctx, JSValueConst v) * Example: replace("abc", "", "-") => "-a-b-c-" * Boundaries count toward limit even if replacement returns null. */ - + static JSValue js_cell_text_replace(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { if (argc < 2) return JS_NULL; @@ -29583,7 +29570,7 @@ int JS_ArrayPush(JSContext *ctx, JSValueConst obj, JSValueConst val) JSValue stack[2]; stack[0] = obj; stack[1] = val; - + if (JS_IsException(js_cell_push(ctx, JS_NULL, 2, stack))) return -1; @@ -30121,7 +30108,7 @@ static void JS_AddIntrinsicBasicObjects(JSContext *ctx) int i; ctx->class_proto[JS_CLASS_OBJECT] = JS_NewObjectProto(ctx, JS_NULL); - + /* function_proto is kept for API compatibility but functions are now intrinsic types */ ctx->function_proto = JS_NewCFunction3(ctx, js_function_proto, "", 0, JS_CFUNC_generic, 0, @@ -30264,7 +30251,7 @@ void JS_AddIntrinsicBaseObjects(JSContext *ctx) JS_NewCFunction(ctx, js_cell_array_filter, "filter", 2)); JS_SetPropertyStr(ctx, ctx->global_obj, "sort", JS_NewCFunction(ctx, js_cell_array_sort, "sort", 2)); - + /* Number utility functions as globals */ JS_SetPropertyStr(ctx, ctx->global_obj, "whole", JS_NewCFunction(ctx, js_cell_number_whole, "whole", 1)); @@ -30328,7 +30315,7 @@ void JS_AddIntrinsicBaseObjects(JSContext *ctx) JS_NewCFunction(ctx, js_cell_pop, "pop", 1)); JS_SetPropertyStr(ctx, ctx->global_obj, "meme", JS_NewCFunction(ctx, js_cell_meme, "meme", 2)); - + } } @@ -30413,7 +30400,7 @@ JSValue js_debugger_backtrace_fns(JSContext *ctx, const uint8_t *cur_pc) uint32_t stack_index = 0; for(sf = ctx->rt->current_stack_frame; sf != NULL; sf = sf->prev_frame) { - uint32_t id = stack_index++; + uint32_t id = stack_index++; JS_SetPropertyUint32(ctx, ret, id, JS_DupValue(ctx,sf->cur_func)); } return ret; @@ -30504,30 +30491,30 @@ JSValue js_debugger_fn_info(JSContext *ctx, JSValue fn) JS_SetPropertyStr(ctx, ret, "args", args_array); } - // Local variables + // Local variables if (b->var_count && b->vardefs) { JSValue locals_array = JS_NewArray(ctx); for (i = 0; i < b->var_count; i++) { JSVarDef *vd = &b->vardefs[b->arg_count + i]; JSValue local_obj = JS_NewObject(ctx); - + str = JS_AtomGetStr(ctx, atom_buf, sizeof(atom_buf), vd->var_name); JS_SetPropertyStr(ctx, local_obj, "name", JS_NewString(ctx, str)); - - const char *var_type = + + const char *var_type = vd->var_kind == JS_VAR_CATCH ? "catch" : - (vd->var_kind == JS_VAR_FUNCTION_DECL || + (vd->var_kind == JS_VAR_FUNCTION_DECL || vd->var_kind == JS_VAR_NEW_FUNCTION_DECL) ? "function" : vd->is_const ? "const" : vd->is_lexical ? "let" : "var"; JS_SetPropertyStr(ctx, local_obj, "type", JS_NewString(ctx, var_type)); JS_SetPropertyStr(ctx, local_obj, "index", JS_NewInt32(ctx, i)); - + if (vd->scope_level) { JS_SetPropertyStr(ctx, local_obj, "scope_level", JS_NewInt32(ctx, vd->scope_level)); JS_SetPropertyStr(ctx, local_obj, "scope_next", JS_NewInt32(ctx, vd->scope_next)); } - + JS_SetPropertyUint32(ctx, locals_array, i, local_obj); } JS_SetPropertyStr(ctx, ret, "locals", locals_array); @@ -30539,16 +30526,16 @@ JSValue js_debugger_fn_info(JSContext *ctx, JSValue fn) for (i = 0; i < b->closure_var_count; i++) { JSClosureVar *cv = &b->closure_var[i]; JSValue closure_obj = JS_NewObject(ctx); - + str = JS_AtomGetStr(ctx, atom_buf, sizeof(atom_buf), cv->var_name); JS_SetPropertyStr(ctx, closure_obj, "name", JS_NewString(ctx, str)); JS_SetPropertyStr(ctx, closure_obj, "is_local", JS_NewBool(ctx, cv->is_local)); JS_SetPropertyStr(ctx, closure_obj, "is_arg", JS_NewBool(ctx, cv->is_arg)); JS_SetPropertyStr(ctx, closure_obj, "var_idx", JS_NewInt32(ctx, cv->var_idx)); - + const char *var_type = cv->is_const ? "const" : cv->is_lexical ? "let" : "var"; JS_SetPropertyStr(ctx, closure_obj, "type", JS_NewString(ctx, var_type)); - + JS_SetPropertyUint32(ctx, closure_array, i, closure_obj); } JS_SetPropertyStr(ctx, ret, "closure_vars", closure_array); @@ -30576,102 +30563,102 @@ JSValue js_debugger_fn_bytecode(JSContext *ctx, JSValue fn) { if (!js_is_bytecode_function(fn)) return JS_NULL; - + JSFunction *f = JS_VALUE_GET_FUNCTION(fn); JSFunctionBytecode *b = f->u.func.function_bytecode; JSValue ret = JS_NewArray(ctx); - + const uint8_t *tab = b->byte_code_buf; int len = b->byte_code_len; int pos = 0; int idx = 0; BOOL use_short_opcodes = TRUE; char opcode_str[256]; - + while (pos < len) { int op = tab[pos]; const JSOpCode *oi; - + if (use_short_opcodes) oi = &short_opcode_info(op); else oi = &opcode_info[op]; - + int size = oi->size; if (pos + size > len) { break; } - + if (op >= sizeof(opcode_names)/sizeof(opcode_names[0])) { snprintf(opcode_str, sizeof(opcode_str), "unknown"); } else { const char *opcode_name = opcode_names[op]; snprintf(opcode_str, sizeof(opcode_str), "%s", opcode_name); - + // Add arguments based on opcode format int arg_pos = pos + 1; switch(oi->fmt) { case OP_FMT_none_int: - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %d", op - OP_push_0); break; case OP_FMT_npopx: - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %d", op - OP_call0); break; case OP_FMT_u8: - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u", get_u8(tab + arg_pos)); break; case OP_FMT_i8: - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %d", get_i8(tab + arg_pos)); break; case OP_FMT_u16: case OP_FMT_npop: - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u", get_u16(tab + arg_pos)); break; case OP_FMT_npop_u16: - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u %u", get_u16(tab + arg_pos), get_u16(tab + arg_pos + 2)); break; case OP_FMT_i16: - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %d", get_i16(tab + arg_pos)); break; case OP_FMT_i32: - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %d", get_i32(tab + arg_pos)); break; case OP_FMT_u32: - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u", get_u32(tab + arg_pos)); break; #if SHORT_OPCODES case OP_FMT_label8: - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u", get_i8(tab + arg_pos) + arg_pos); break; case OP_FMT_label16: - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u", get_i16(tab + arg_pos) + arg_pos); break; case OP_FMT_const8: - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u", get_u8(tab + arg_pos)); break; #endif case OP_FMT_const: - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u", get_u32(tab + arg_pos)); break; case OP_FMT_label: - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u", get_u32(tab + arg_pos) + arg_pos); break; case OP_FMT_label_u16: - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u %u", get_u32(tab + arg_pos) + arg_pos, get_u16(tab + arg_pos + 4)); break; case OP_FMT_atom: @@ -30679,11 +30666,11 @@ JSValue js_debugger_fn_bytecode(JSContext *ctx, JSValue fn) JSAtom atom = get_u32(tab + arg_pos); const char *atom_str = JS_AtomToCString(ctx, atom); if (atom_str) { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %s", atom_str); JS_FreeCString(ctx, atom_str); } else { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u", atom); } } @@ -30693,11 +30680,11 @@ JSValue js_debugger_fn_bytecode(JSContext *ctx, JSValue fn) JSAtom atom = get_u32(tab + arg_pos); const char *atom_str = JS_AtomToCString(ctx, atom); if (atom_str) { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %s %d", atom_str, get_u8(tab + arg_pos + 4)); JS_FreeCString(ctx, atom_str); } else { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u %d", atom, get_u8(tab + arg_pos + 4)); } } @@ -30707,11 +30694,11 @@ JSValue js_debugger_fn_bytecode(JSContext *ctx, JSValue fn) JSAtom atom = get_u32(tab + arg_pos); const char *atom_str = JS_AtomToCString(ctx, atom); if (atom_str) { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %s %d", atom_str, get_u16(tab + arg_pos + 4)); JS_FreeCString(ctx, atom_str); } else { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u %d", atom, get_u16(tab + arg_pos + 4)); } } @@ -30721,15 +30708,15 @@ JSValue js_debugger_fn_bytecode(JSContext *ctx, JSValue fn) { JSAtom atom = get_u32(tab + arg_pos); int addr = get_u32(tab + arg_pos + 4); - int extra = (oi->fmt == OP_FMT_atom_label_u8) ? + int extra = (oi->fmt == OP_FMT_atom_label_u8) ? get_u8(tab + arg_pos + 8) : get_u16(tab + arg_pos + 8); const char *atom_str = JS_AtomToCString(ctx, atom); if (atom_str) { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %s %u %u", atom_str, addr + arg_pos + 4, extra); JS_FreeCString(ctx, atom_str); } else { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u %u %u", atom, addr + arg_pos + 4, extra); } } @@ -30740,15 +30727,15 @@ JSValue js_debugger_fn_bytecode(JSContext *ctx, JSValue fn) if (idx < b->var_count) { const char *var_name = JS_AtomToCString(ctx, b->vardefs[idx].var_name); if (var_name) { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %d: %s", idx, var_name); JS_FreeCString(ctx, var_name); } else { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %d", idx); } } else { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %d", idx); } } @@ -30759,15 +30746,15 @@ JSValue js_debugger_fn_bytecode(JSContext *ctx, JSValue fn) if (idx < b->var_count) { const char *var_name = JS_AtomToCString(ctx, b->vardefs[idx].var_name); if (var_name) { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u: %s", idx, var_name); JS_FreeCString(ctx, var_name); } else { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u", idx); } } else { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u", idx); } } @@ -30778,15 +30765,15 @@ JSValue js_debugger_fn_bytecode(JSContext *ctx, JSValue fn) if (idx < b->var_count) { const char *var_name = JS_AtomToCString(ctx, b->vardefs[idx].var_name); if (var_name) { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u: %s", idx, var_name); JS_FreeCString(ctx, var_name); } else { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u", idx); } } else { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u", idx); } } @@ -30797,15 +30784,15 @@ JSValue js_debugger_fn_bytecode(JSContext *ctx, JSValue fn) if (idx < b->arg_count) { const char *arg_name = JS_AtomToCString(ctx, b->vardefs[idx].var_name); if (arg_name) { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %d: %s", idx, arg_name); JS_FreeCString(ctx, arg_name); } else { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %d", idx); } } else { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %d", idx); } } @@ -30816,15 +30803,15 @@ JSValue js_debugger_fn_bytecode(JSContext *ctx, JSValue fn) if (idx < b->arg_count) { const char *arg_name = JS_AtomToCString(ctx, b->vardefs[idx].var_name); if (arg_name) { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u: %s", idx, arg_name); JS_FreeCString(ctx, arg_name); } else { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u", idx); } } else { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u", idx); } } @@ -30835,15 +30822,15 @@ JSValue js_debugger_fn_bytecode(JSContext *ctx, JSValue fn) if (idx < b->closure_var_count) { const char *var_name = JS_AtomToCString(ctx, b->closure_var[idx].var_name); if (var_name) { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %d: %s", idx, var_name); JS_FreeCString(ctx, var_name); } else { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %d", idx); } } else { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %d", idx); } } @@ -30854,15 +30841,15 @@ JSValue js_debugger_fn_bytecode(JSContext *ctx, JSValue fn) if (idx < b->closure_var_count) { const char *var_name = JS_AtomToCString(ctx, b->closure_var[idx].var_name); if (var_name) { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u: %s", idx, var_name); JS_FreeCString(ctx, var_name); } else { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u", idx); } } else { - snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), + snprintf(opcode_str + strlen(opcode_str), sizeof(opcode_str) - strlen(opcode_str), " %u", idx); } } @@ -30871,13 +30858,13 @@ JSValue js_debugger_fn_bytecode(JSContext *ctx, JSValue fn) break; } } - + JSValue js_opcode_str = JS_NewString(ctx, opcode_str); JS_SetPropertyUint32(ctx, ret, idx++, js_opcode_str); - + pos += size; } - + return ret; } @@ -30948,7 +30935,7 @@ void js_debugger_set_closure_variable(JSContext *ctx, JSValue fn, JSValue var_na const char *cvar_name = JS_AtomToCString(ctx, cvar->var_name); if (!cvar_name) continue; - + if (strcmp(name_str, cvar_name) == 0) { JS_FreeCString(ctx, cvar_name); JSVarRef *var_ref = NULL; diff --git a/source/quickjs.h b/source/quickjs.h index c80e1dac..09440cb6 100644 --- a/source/quickjs.h +++ b/source/quickjs.h @@ -45,10 +45,25 @@ extern "C" { #define __js_printf_like(a, b) #endif +// #define BINARY32 // 32 bit word type (float) +// #define BINARY64 // 64 bit word type (double) +// #define DEC64 // 64 bit word type (dec) + +/* + NaN boxing is used, always. A value is the length of the word. + Half: 10 bits + Float: 23 bits + Double: 52 bits + Dec64: 56 bits + + On double builds, 48 bits + On Dec64, max +*/ + #define JS_BOOL int -typedef struct JSRuntime JSRuntime; -typedef struct JSContext JSContext; +typedef struct JSRuntime JSRuntime; // the entire VM +typedef struct JSContext JSContext; // Each actor - has its own GC typedef struct JSClass JSClass; typedef uint32_t JSClassID; typedef uint32_t JSAtom; @@ -64,14 +79,14 @@ typedef uint32_t JSAtom; #define JS_NAN_BOXING #endif -#if defined(__SIZEOF_INT128__) && (INTPTR_MAX >= INT64_MAX) -#define JS_LIMB_BITS 64 -#else -#define JS_LIMB_BITS 32 -#endif +/* + Mist tags: + 0: false + 1: true + 2: null + 4: object +*/ -#define JS_SHORT_BIG_INT_BITS JS_LIMB_BITS - enum { /* all tags with a reference count are negative */ JS_TAG_FIRST = -10, /* first negative tag */ @@ -80,7 +95,6 @@ enum { JS_TAG_STRING_ROPE = -7, JS_TAG_ARRAY = -6, /* intrinsic array type */ JS_TAG_FUNCTION = -5, /* intrinsic function type */ - JS_TAG_MODULE = -3, /* used internally */ JS_TAG_FUNCTION_BYTECODE = -2, /* used internally */ JS_TAG_OBJECT = -1, @@ -90,7 +104,6 @@ enum { JS_TAG_UNINITIALIZED = 4, JS_TAG_CATCH_OFFSET = 5, JS_TAG_EXCEPTION = 6, - JS_TAG_SHORT_BIG_INT = 7, JS_TAG_FLOAT64 = 8, /* any larger tag is FLOAT64 if JS_NAN_BOXING */ }; @@ -116,7 +129,6 @@ typedef const struct __JSValue *JSValueConst; #define JS_VALUE_GET_INT(v) (int)((intptr_t)(v) >> 4) #define JS_VALUE_GET_BOOL(v) JS_VALUE_GET_INT(v) #define JS_VALUE_GET_FLOAT64(v) (double)JS_VALUE_GET_INT(v) -#define JS_VALUE_GET_SHORT_BIG_INT(v) JS_VALUE_GET_INT(v) #define JS_VALUE_GET_PTR(v) (void *)((intptr_t)(v) & ~0xf) #define JS_MKVAL(tag, val) (JSValue)(intptr_t)(((val) << 4) | (tag)) @@ -145,7 +157,6 @@ typedef uint64_t JSValue; #define JS_VALUE_GET_TAG(v) (int)((v) >> 32) #define JS_VALUE_GET_INT(v) (int)(v) #define JS_VALUE_GET_BOOL(v) (int)(v) -#define JS_VALUE_GET_SHORT_BIG_INT(v) (int)(v) #define JS_VALUE_GET_PTR(v) (void *)(intptr_t)(v) #define JS_MKVAL(tag, val) (((uint64_t)(tag) << 32) | (uint32_t)(val)) @@ -208,11 +219,6 @@ typedef union JSValueUnion { int32_t int32; double float64; void *ptr; -#if JS_SHORT_BIG_INT_BITS == 32 - int32_t short_big_int; -#else - int64_t short_big_int; -#endif } JSValueUnion; typedef struct JSValue { @@ -228,7 +234,6 @@ typedef struct JSValue { #define JS_VALUE_GET_INT(v) ((v).u.int32) #define JS_VALUE_GET_BOOL(v) ((v).u.int32) #define JS_VALUE_GET_FLOAT64(v) ((v).u.float64) -#define JS_VALUE_GET_SHORT_BIG_INT(v) ((v).u.short_big_int) #define JS_VALUE_GET_PTR(v) ((v).u.ptr) #define JS_MKVAL(tag, val) (JSValue){ (JSValueUnion){ .int32 = val }, tag } @@ -298,7 +303,6 @@ static inline JS_BOOL JS_VALUE_IS_NAN(JSValue v) typedef JSValue JSCFunction(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv); typedef JSValue JSCFunctionMagic(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic); -typedef JSValue JSCFunctionData(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic, JSValue *func_data); typedef struct JSMallocState { size_t malloc_count; @@ -613,7 +617,6 @@ static inline JSValue JS_DupValueRT(JSRuntime *rt, JSValueConst v) JS_BOOL JS_StrictEq(JSContext *ctx, JSValueConst op1, JSValueConst op2); JS_BOOL JS_SameValue(JSContext *ctx, JSValueConst op1, JSValueConst op2); -JS_BOOL JS_SameValueZero(JSContext *ctx, JSValueConst op1, JSValueConst op2); int JS_ToBool(JSContext *ctx, JSValueConst val); /* return -1 for JS_EXCEPTION */ int JS_ToInt32(JSContext *ctx, int32_t *pres, JSValueConst val); @@ -623,7 +626,6 @@ static inline int JS_ToUint32(JSContext *ctx, uint32_t *pres, JSValueConst val) } int JS_AtomIsNumericIndex(JSContext *ctx, JSAtom atom); int JS_ToInt64(JSContext *ctx, int64_t *pres, JSValueConst val); -int JS_ToIndex(JSContext *ctx, uint64_t *plen, JSValueConst val); int JS_ToFloat64(JSContext *ctx, double *pres, JSValueConst val); /* return an exception if 'val' is a Number */ @@ -665,22 +667,18 @@ static js_force_inline JSValue JS_GetProperty(JSContext *ctx, JSValueConst this_ return JS_GetPropertyInternal(ctx, this_obj, prop, this_obj, 0); } +// generic +JSValue JS_GetPropertyV(JSContext *js, JSValue obj, JSValue prop); +JSValue JS_SetPropertyV(JSContext *js, JSValue obj, JSValue prop, JSValue val); + // For records JSValue JS_GetPropertyStr(JSContext *ctx, JSValueConst this_obj, const char *prop); int JS_SetPropertyStr(JSContext *ctx, JSValueConst this_obj, const char *prop, JSValue val); -int JS_SetProperty(JSContext *ctx, JSValueConst this_obj, JSAtom prop, JSValue val); -JSValue JS_GetPropertyKey(JSContext *ctx, JSValueConst this_obj, JSValueConst key); -int JS_SetPropertyKey(JSContext *ctx, JSValueConst this_obj, JSValueConst key, JSValue val); +JSValue JS_GetPrototype(JSContext *ctx, JSValueConst val); // Must be an array JSValue JS_GetPropertyNumber(JSContext *ctx, JSValueConst this_obj, int idx); -JSValue JS_GetPropertyUint32(JSContext *ctx, JSValueConst this_obj, uint32_t idx); -int JS_SetPropertyUint32(JSContext *ctx, JSValueConst this_obj, uint32_t idx, JSValue val); -int JS_SetPropertyInt64(JSContext *ctx, JSValueConst this_obj, int64_t idx, JSValue val); - -int JS_HasProperty(JSContext *ctx, JSValueConst this_obj, JSAtom prop); -int JS_DeleteProperty(JSContext *ctx, JSValueConst obj, JSAtom prop); -JSValue JS_GetPrototype(JSContext *ctx, JSValueConst val); +JSValue JS_SetPropertyNumber(JSContext *ctx, JSValue obj, int idx, JSValue val); /* Get Own Property Names flags */ #define JS_GPN_STRING_MASK (1 << 0) @@ -788,9 +786,6 @@ typedef union JSCFunctionType { JSValue JS_NewCFunction2(JSContext *ctx, JSCFunction *func, const char *name, int length, JSCFunctionEnum cproto, int magic); -JSValue JS_NewCFunctionData(JSContext *ctx, JSCFunctionData *func, - int length, int magic, int data_len, - JSValueConst *data); static inline JSValue JS_NewCFunction(JSContext *ctx, JSCFunction *func, const char *name, int length)