clean up unused functions

This commit is contained in:
2025-06-16 15:49:54 -05:00
parent 7b16259c00
commit 233f59e04a

View File

@@ -913,7 +913,6 @@ static JSValue JS_ToStringFree(JSContext *ctx, JSValue val);
static int JS_ToBoolFree(JSContext *ctx, JSValue val);
static int JS_ToInt32Free(JSContext *ctx, int32_t *pres, JSValue val);
static int JS_ToFloat64Free(JSContext *ctx, double *pres, JSValue val);
static int JS_ToUint8ClampFree(JSContext *ctx, int32_t *pres, JSValue val);
static JSValue js_new_string8_len(JSContext *ctx, const char *buf, int len);
static JSValue js_compile_regexp(JSContext *ctx, JSValueConst pattern,
JSValueConst flags);
@@ -954,7 +953,6 @@ static JSVarRef *get_var_ref(JSContext *ctx, JSStackFrame *sf, int var_idx,
static JSValue JS_EvalInternal(JSContext *ctx, JSValueConst this_obj,
const char *input, size_t input_len,
const char *filename, int flags, int scope_idx);
static JSValue js_dynamic_import(JSContext *ctx, JSValueConst specifier, JSValueConst options);
static void free_var_ref(JSRuntime *rt, JSVarRef *var_ref);
static int js_string_compare(JSContext *ctx,
@@ -963,7 +961,6 @@ static JSValue JS_ToNumber(JSContext *ctx, JSValueConst val);
static int JS_SetPropertyValue(JSContext *ctx, JSValueConst this_obj,
JSValue prop, JSValue val, int flags);
static int JS_NumberIsInteger(JSContext *ctx, JSValueConst val);
static BOOL JS_NumberIsNegativeOrMinusZero(JSContext *ctx, JSValueConst val);
static JSValue JS_ToNumberFree(JSContext *ctx, JSValue val);
static int JS_GetOwnPropertyInternal(JSContext *ctx, JSPropertyDescriptor *desc,
JSObject *p, JSAtom prop);
@@ -1002,8 +999,6 @@ static void map_delete_weakrefs(JSRuntime *rt, JSWeakRefHeader *wh);
static void weakref_delete_weakref(JSRuntime *rt, JSWeakRefHeader *wh);
static void finrec_delete_weakref(JSRuntime *rt, JSWeakRefHeader *wh);
static void JS_RunGCInternal(JSRuntime *rt, BOOL remove_weak_objects);
static JSValue js_array_from_iterator(JSContext *ctx, uint32_t *plen,
JSValueConst obj, JSValueConst method);
static int js_string_find_invalid_codepoint(JSString *p);
static JSValue js_regexp_toString(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv);
@@ -1795,7 +1790,6 @@ static void JS_MarkContext(JSRuntime *rt, JSContext *ctx,
JS_MarkFunc *mark_func)
{
int i;
struct list_head *el;
JS_MarkValue(rt, ctx->global_obj, mark_func);
JS_MarkValue(rt, ctx->global_var_obj, mark_func);
@@ -2574,20 +2568,6 @@ static JSValue JS_NewSymbol(JSContext *ctx, JSString *p, int atom_type)
return JS_MKPTR(JS_TAG_SYMBOL, rt->atom_array[atom]);
}
/* descr must be a non-numeric string atom */
static JSValue JS_NewSymbolFromAtom(JSContext *ctx, JSAtom descr,
int atom_type)
{
JSRuntime *rt = ctx->rt;
JSString *p;
assert(!__JS_AtomIsTaggedInt(descr));
assert(descr < rt->atom_size);
p = rt->atom_array[descr];
JS_DupValue(ctx, JS_MKPTR(JS_TAG_STRING, p));
return JS_NewSymbol(ctx, p, atom_type);
}
#define ATOM_GET_STR_BUF_SIZE 64
/* Should only be used for debug. */
@@ -2816,48 +2796,6 @@ const char *JS_AtomToCStringLen(JSContext *ctx, size_t *plen, JSAtom atom)
return cstr;
}
/* return a string atom containing name concatenated with str1 */
static JSAtom js_atom_concat_str(JSContext *ctx, JSAtom name, const char *str1)
{
JSValue str;
JSAtom atom;
const char *cstr;
char *cstr2;
size_t len, len1;
str = JS_AtomToString(ctx, name);
if (JS_IsException(str))
return JS_ATOM_NULL;
cstr = JS_ToCStringLen(ctx, &len, str);
if (!cstr)
goto fail;
len1 = strlen(str1);
cstr2 = js_malloc(ctx, len + len1 + 1);
if (!cstr2)
goto fail;
memcpy(cstr2, cstr, len);
memcpy(cstr2 + len, str1, len1);
cstr2[len + len1] = '\0';
atom = JS_NewAtomLen(ctx, cstr2, len + len1);
js_free(ctx, cstr2);
JS_FreeCString(ctx, cstr);
JS_FreeValue(ctx, str);
return atom;
fail:
JS_FreeCString(ctx, cstr);
JS_FreeValue(ctx, str);
return JS_ATOM_NULL;
}
static JSAtom js_atom_concat_num(JSContext *ctx, JSAtom name, uint32_t n)
{
char buf[16];
size_t len;
len = u32toa(buf, n);
buf[len] = '\0';
return js_atom_concat_str(ctx, name, buf);
}
static inline BOOL JS_IsEmptyString(JSValueConst v)
{
return JS_VALUE_GET_TAG(v) == JS_TAG_STRING && JS_VALUE_GET_STRING(v)->len == 0;
@@ -5785,7 +5723,7 @@ static void compute_value_size(JSValueConst val, JSMemoryUsage_helper *hp)
void JS_ComputeMemoryUsage(JSRuntime *rt, JSMemoryUsage *s)
{
struct list_head *el, *el1;
struct list_head *el;
int i;
JSMemoryUsage_helper mem = { 0 }, *hp = &mem;
@@ -8366,8 +8304,6 @@ static int JS_SetPropertyValue(JSContext *ctx, JSValueConst this_obj,
JS_VALUE_GET_TAG(prop) == JS_TAG_INT)) {
JSObject *p;
uint32_t idx;
double d;
int32_t v;
/* fast path for array access */
p = JS_VALUE_GET_OBJ(this_obj);
@@ -11740,48 +11676,6 @@ static inline int JS_ToUint32Free(JSContext *ctx, uint32_t *pres, JSValue val)
return JS_ToInt32Free(ctx, (int32_t *)pres, val);
}
static int JS_ToUint8ClampFree(JSContext *ctx, int32_t *pres, JSValue val)
{
uint32_t tag;
int res;
redo:
tag = JS_VALUE_GET_NORM_TAG(val);
switch(tag) {
case JS_TAG_INT:
case JS_TAG_BOOL:
case JS_TAG_NULL:
case JS_TAG_UNDEFINED:
res = JS_VALUE_GET_INT(val);
res = max_int(0, min_int(255, res));
break;
case JS_TAG_FLOAT64:
{
double d = JS_VALUE_GET_FLOAT64(val);
if (isnan(d)) {
res = 0;
} else {
if (d < 0)
res = 0;
else if (d > 255)
res = 255;
else
res = lrint(d);
}
}
break;
default:
val = JS_ToNumberFree(ctx, val);
if (JS_IsException(val)) {
*pres = 0;
return -1;
}
goto redo;
}
*pres = res;
return 0;
}
static __exception int JS_ToArrayLengthFree(JSContext *ctx, uint32_t *plen,
JSValue val, BOOL is_array_ctor)
{
@@ -11887,36 +11781,6 @@ static int JS_NumberIsInteger(JSContext *ctx, JSValueConst val)
return isfinite(d) && floor(d) == d;
}
static BOOL JS_NumberIsNegativeOrMinusZero(JSContext *ctx, JSValueConst val)
{
uint32_t tag;
tag = JS_VALUE_GET_NORM_TAG(val);
switch(tag) {
case JS_TAG_INT:
{
int v;
v = JS_VALUE_GET_INT(val);
return (v < 0);
}
case JS_TAG_FLOAT64:
{
JSFloat64Union u;
u.d = JS_VALUE_GET_FLOAT64(val);
return (u.u64 >> 63);
}
case JS_TAG_SHORT_BIG_INT:
return (JS_VALUE_GET_SHORT_BIG_INT(val) < 0);
case JS_TAG_BIG_INT:
{
JSBigInt *p = JS_VALUE_GET_PTR(val);
return js_bigint_sign(p);
}
default:
return FALSE;
}
}
static JSValue js_bigint_to_string(JSContext *ctx, JSValueConst val)
{
return js_bigint_to_string1(ctx, val, 10);
@@ -14234,8 +14098,6 @@ static __exception int js_operator_typeof(JSContext *ctx, JSValueConst op1)
break;
case JS_TAG_OBJECT:
{
JSObject *p;
p = JS_VALUE_GET_OBJ(op1);
if (JS_IsFunction(ctx, op1))
atom = JS_ATOM_function;
else
@@ -14712,7 +14574,7 @@ static JSValue JS_GetIterator2(JSContext *ctx, JSValueConst obj,
static JSValue JS_GetIterator(JSContext *ctx, JSValueConst obj)
{
JSValue method, ret, sync_iter;
JSValue method, ret;
method = JS_GetProperty(ctx, obj, JS_ATOM_Symbol_iterator);
if (JS_IsException(method))
@@ -22655,10 +22517,8 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags)
if (next_token(s))
return -1;
} else if (s->token.val == '[') {
int prev_op;
op_token_ptr = s->token.ptr;
parse_array_access:
prev_op = get_prev_opcode(fd);
if (has_optional_chain) {
optional_chain_test(s, &optional_chaining_label, 1);
}
@@ -24505,9 +24365,6 @@ static int add_closure_var(JSContext *ctx, JSFunctionDef *s,
static __exception int js_parse_source_element(JSParseState *s)
{
JSFunctionDef *fd = s->cur_func;
int tok;
if (s->token.val == TOK_FUNCTION ||
(token_is_pseudo_keyword(s, JS_ATOM_async) &&
peek_token(s, TRUE) == TOK_FUNCTION)) {
@@ -25147,18 +25004,6 @@ static int add_closure_var(JSContext *ctx, JSFunctionDef *s,
return s->closure_var_count - 1;
}
static int find_closure_var(JSContext *ctx, JSFunctionDef *s,
JSAtom var_name)
{
int i;
for(i = 0; i < s->closure_var_count; i++) {
JSClosureVar *cv = &s->closure_var[i];
if (cv->var_name == var_name)
return i;
}
return -1;
}
/* 'fd' must be a parent of 's'. Create in 's' a closure referencing a
local variable (is_local = TRUE) or a closure (is_local = FALSE) in
'fd' */
@@ -25812,32 +25657,6 @@ done:
return pos_next;
}
/* search in all scopes */
static int find_private_class_field_all(JSContext *ctx, JSFunctionDef *fd,
JSAtom name, int scope_level)
{
int idx;
idx = fd->scopes[scope_level].first;
while (idx >= 0) {
if (fd->vars[idx].var_name == name)
return idx;
idx = fd->vars[idx].scope_next;
}
return -1;
}
static void get_loc_or_ref(DynBuf *bc, BOOL is_ref, int idx)
{
/* if the field is not initialized, the error is catched when
accessing it */
if (is_ref)
dbuf_putc(bc, OP_get_var_ref);
else
dbuf_putc(bc, OP_get_loc);
dbuf_put_u16(bc, idx);
}
static void mark_eval_captured_variables(JSContext *ctx, JSFunctionDef *s,
int scope_level)
{
@@ -26219,7 +26038,7 @@ static BOOL code_match(CodeContext *s, int pos, ...)
static void instantiate_hoisted_definitions(JSContext *ctx, JSFunctionDef *s, DynBuf *bc)
{
int i, idx, label_next = -1;
int i, idx;
/* add the hoisted functions in arguments and local variables */
for(i = 0; i < s->arg_count; i++) {
@@ -31115,16 +30934,6 @@ static JSValueConst JS_NewGlobalCConstructor(JSContext *ctx, const char *name,
return func_obj;
}
static JSValueConst JS_NewGlobalCConstructorOnly(JSContext *ctx, const char *name,
JSCFunction *func, int length,
JSValueConst proto)
{
JSValue func_obj;
func_obj = JS_NewCFunction2(ctx, func, name, length, JS_CFUNC_constructor, 0);
JS_NewGlobalCConstructor2(ctx, func_obj, name, proto);
return func_obj;
}
static JSValue js_global_eval(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv)
{
@@ -32890,24 +32699,6 @@ static const JSCFunctionListEntry js_error_proto_funcs[] = {
JS_PROP_STRING_DEF("message", "", JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE ),
};
/* AggregateError */
/* used by C code. */
static JSValue js_aggregate_error_constructor(JSContext *ctx,
JSValueConst errors)
{
JSValue obj;
obj = JS_NewObjectProtoClass(ctx,
ctx->native_error_proto[JS_AGGREGATE_ERROR],
JS_CLASS_ERROR);
if (JS_IsException(obj))
return obj;
JS_DefinePropertyValue(ctx, obj, JS_ATOM_errors, JS_DupValue(ctx, errors),
JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
return obj;
}
/* Array */
static int JS_CopySubArray(JSContext *ctx,
@@ -34780,14 +34571,12 @@ static JSValue js_array_iterator_next(JSContext *ctx, JSValueConst this_val,
JSArrayIteratorData *it;
uint32_t len, idx;
JSValue val, obj;
JSObject *p;
it = JS_GetOpaque2(ctx, this_val, JS_CLASS_ARRAY_ITERATOR);
if (!it)
goto fail1;
if (JS_IsUndefined(it->obj))
goto done;
p = JS_VALUE_GET_OBJ(it->obj);
if (js_get_length32(ctx, &len, it->obj)) {
fail1:
@@ -36895,60 +36684,6 @@ enum {
magic_string_sup,
};
static JSValue js_string_CreateHTML(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv, int magic)
{
JSValue str;
const JSString *p;
StringBuffer b_s, *b = &b_s;
static struct { const char *tag, *attr; } const defs[] = {
{ "a", "name" }, { "big", NULL }, { "blink", NULL }, { "b", NULL },
{ "tt", NULL }, { "font", "color" }, { "font", "size" }, { "i", NULL },
{ "a", "href" }, { "small", NULL }, { "strike", NULL },
{ "sub", NULL }, { "sup", NULL },
};
str = JS_ToStringCheckObject(ctx, this_val);
if (JS_IsException(str))
return JS_EXCEPTION;
string_buffer_init(ctx, b, 7);
string_buffer_putc8(b, '<');
string_buffer_puts8(b, defs[magic].tag);
if (defs[magic].attr) {
// r += " " + attr + "=\"" + value + "\"";
JSValue value;
int i;
string_buffer_putc8(b, ' ');
string_buffer_puts8(b, defs[magic].attr);
string_buffer_puts8(b, "=\"");
value = JS_ToStringCheckObject(ctx, argv[0]);
if (JS_IsException(value)) {
JS_FreeValue(ctx, str);
string_buffer_free(b);
return JS_EXCEPTION;
}
p = JS_VALUE_GET_STRING(value);
for (i = 0; i < p->len; i++) {
int c = string_get(p, i);
if (c == '"') {
string_buffer_puts8(b, "&quot;");
} else {
string_buffer_putc16(b, c);
}
}
JS_FreeValue(ctx, value);
string_buffer_putc8(b, '\"');
}
// return r + ">" + str + "</" + tag + ">";
string_buffer_putc8(b, '>');
string_buffer_concat_value_free(b, str);
string_buffer_puts8(b, "</");
string_buffer_puts8(b, defs[magic].tag);
string_buffer_putc8(b, '>');
return string_buffer_end(b);
}
static const JSCFunctionListEntry js_string_funcs[] = {
JS_CFUNC_DEF("fromCharCode", 1, js_string_fromCharCode ),
JS_CFUNC_DEF("fromCodePoint", 1, js_string_fromCodePoint ),
@@ -36999,20 +36734,6 @@ static const JSCFunctionListEntry js_string_proto_funcs[] = {
// JS_CFUNC_MAGIC_DEF("toLocaleLowerCase", 0, js_string_toLowerCase, 1 ),
// JS_CFUNC_MAGIC_DEF("toLocaleUpperCase", 0, js_string_toLowerCase, 0 ),
JS_CFUNC_MAGIC_DEF("[Symbol.iterator]", 0, js_create_array_iterator, JS_ITERATOR_KIND_VALUE | 4 ),
/* ES6 Annex B 2.3.2 etc. */
// JS_CFUNC_MAGIC_DEF("anchor", 1, js_string_CreateHTML, magic_string_anchor ),
// JS_CFUNC_MAGIC_DEF("big", 0, js_string_CreateHTML, magic_string_big ),
// JS_CFUNC_MAGIC_DEF("blink", 0, js_string_CreateHTML, magic_string_blink ),
// JS_CFUNC_MAGIC_DEF("bold", 0, js_string_CreateHTML, magic_string_bold ),
// JS_CFUNC_MAGIC_DEF("fixed", 0, js_string_CreateHTML, magic_string_fixed ),
// JS_CFUNC_MAGIC_DEF("fontcolor", 1, js_string_CreateHTML, magic_string_fontcolor ),
// JS_CFUNC_MAGIC_DEF("fontsize", 1, js_string_CreateHTML, magic_string_fontsize ),
// JS_CFUNC_MAGIC_DEF("italics", 0, js_string_CreateHTML, magic_string_italics ),
// JS_CFUNC_MAGIC_DEF("link", 1, js_string_CreateHTML, magic_string_link ),
// JS_CFUNC_MAGIC_DEF("small", 0, js_string_CreateHTML, magic_string_small ),
// JS_CFUNC_MAGIC_DEF("strike", 0, js_string_CreateHTML, magic_string_strike ),
// JS_CFUNC_MAGIC_DEF("sub", 0, js_string_CreateHTML, magic_string_sub ),
// JS_CFUNC_MAGIC_DEF("sup", 0, js_string_CreateHTML, magic_string_sup ),
};
static const JSCFunctionListEntry js_string_iterator_proto_funcs[] = {
@@ -42765,11 +42486,6 @@ static void js_finrec_mark(JSRuntime *rt, JSValueConst val,
}
}
static JSValue js_finrec_job(JSContext *ctx, int argc, JSValueConst *argv)
{
return JS_Call(ctx, argv[0], JS_UNDEFINED, 1, &argv[1]);
}
static void finrec_delete_weakref(JSRuntime *rt, JSWeakRefHeader *wh)
{
JSFinalizationRegistryData *frd = container_of(wh, JSFinalizationRegistryData, weakref_header);