remove unused vars, fix warnings
This commit is contained in:
353
source/quickjs.c
353
source/quickjs.c
@@ -352,9 +352,6 @@ typedef struct BuddyAllocator {
|
||||
} BuddyAllocator;
|
||||
|
||||
/* Forward declarations for buddy allocator functions */
|
||||
static int buddy_init (BuddyAllocator *b);
|
||||
static void *buddy_alloc (BuddyAllocator *b, size_t size);
|
||||
static void buddy_free (BuddyAllocator *b, void *ptr, size_t size);
|
||||
static void buddy_destroy (BuddyAllocator *b);
|
||||
|
||||
struct JSRuntime {
|
||||
@@ -543,11 +540,6 @@ typedef struct JSArray {
|
||||
JSValue values[]; /* inline flexible array member */
|
||||
} JSArray;
|
||||
|
||||
/* js_array_set_cap - helper to set array capacity in mist header */
|
||||
static inline void js_array_set_cap (JSArray *arr, uint32_t cap) {
|
||||
arr->mist_hdr = objhdr_set_cap56 (arr->mist_hdr, cap);
|
||||
}
|
||||
|
||||
/* JSBlob - binary data per memory.md */
|
||||
typedef struct JSBlob {
|
||||
objhdr_t mist_hdr;
|
||||
@@ -624,8 +616,6 @@ static inline JS_BOOL rec_key_is_tomb (JSValue key) {
|
||||
return JS_IsException (key);
|
||||
}
|
||||
|
||||
static inline JSValue rec_key_tomb (void) { return JS_EXCEPTION; }
|
||||
|
||||
typedef struct fash64_state {
|
||||
uint64_t result;
|
||||
uint64_t sum;
|
||||
@@ -708,12 +698,6 @@ static inline word_t JSText_len (const JSText *text) {
|
||||
return text->length;
|
||||
}
|
||||
|
||||
static inline uint32_t JSText_get (const JSText *text, word_t idx) {
|
||||
word_t word_idx = idx >> 1;
|
||||
int shift = (1 - (idx & 1)) * 32;
|
||||
return (uint32_t)(text->packed[word_idx] >> shift);
|
||||
}
|
||||
|
||||
static inline JS_BOOL JSText_equal (const JSText *a, const JSText *b) {
|
||||
word_t len_a = JSText_len (a);
|
||||
word_t len_b = JSText_len (b);
|
||||
@@ -937,8 +921,6 @@ typedef struct StonePage {
|
||||
|
||||
/* Allocate from stone arena (permanent, immutable memory) */
|
||||
static void *st_alloc (JSContext *ctx, size_t bytes, size_t align) {
|
||||
JSRuntime *rt = ctx->rt;
|
||||
|
||||
/* Align the request */
|
||||
bytes = (bytes + align - 1) & ~(align - 1);
|
||||
|
||||
@@ -963,7 +945,6 @@ static void *st_alloc (JSContext *ctx, size_t bytes, size_t align) {
|
||||
|
||||
/* Free all stone arena pages */
|
||||
static void st_free_all (JSContext *ctx) {
|
||||
JSRuntime *rt = ctx->rt;
|
||||
StonePage *page = ctx->st_pages;
|
||||
while (page) {
|
||||
StonePage *next = page->next;
|
||||
@@ -975,7 +956,6 @@ static void st_free_all (JSContext *ctx) {
|
||||
|
||||
/* Resize the stone text intern hash table */
|
||||
static int st_text_resize (JSContext *ctx) {
|
||||
JSRuntime *rt = ctx->rt;
|
||||
uint32_t new_size, new_resize;
|
||||
uint32_t *new_hash;
|
||||
JSText **new_array;
|
||||
@@ -1240,13 +1220,6 @@ typedef struct JSRegExp {
|
||||
/* Initial capacity for new records (mask = 7, 8 slots total) */
|
||||
#define JS_RECORD_INITIAL_MASK 7
|
||||
|
||||
static inline void rec_tab_init (JSRecordEntry *tab, uint32_t mask) {
|
||||
for (uint32_t i = 0; i <= mask; i++) {
|
||||
tab[i].key = JS_NULL;
|
||||
tab[i].val = JS_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* ============================================================
|
||||
JSRecord Core Operations
|
||||
============================================================ */
|
||||
@@ -1388,18 +1361,6 @@ static int rec_find_slot (JSRecord *rec, JSValue k) {
|
||||
return first_tomb ? -(int)first_tomb : -1;
|
||||
}
|
||||
|
||||
/* GC-SAFE: No allocations. Caller must pass freshly-chased rec.
|
||||
Get own property from record, returns JS_NULL if not found */
|
||||
static JSValue rec_get_own (JSContext *ctx, JSRecord *rec, JSValue k) {
|
||||
(void)ctx;
|
||||
|
||||
if (rec_key_is_empty (k) || rec_key_is_tomb (k)) return JS_NULL;
|
||||
|
||||
int slot = rec_find_slot (rec, k);
|
||||
if (slot > 0) { return rec->slots[slot].val; }
|
||||
return JS_NULL;
|
||||
}
|
||||
|
||||
/* GC-SAFE: No allocations. Walks prototype chain via direct pointers.
|
||||
Caller must pass freshly-chased rec. */
|
||||
static JSValue rec_get (JSContext *ctx, JSRecord *rec, JSValue k) {
|
||||
@@ -1588,11 +1549,6 @@ static JSRecord *js_new_record_class (JSContext *ctx, uint32_t initial_mask, JSC
|
||||
return rec;
|
||||
}
|
||||
|
||||
/* Allocate a new record (backward compatible - defaults to JS_CLASS_OBJECT) */
|
||||
static JSRecord *js_new_record (JSContext *ctx, uint32_t initial_mask) {
|
||||
return js_new_record_class (ctx, initial_mask, JS_CLASS_OBJECT);
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
JS_FUNC_KIND_C,
|
||||
JS_FUNC_KIND_BYTECODE,
|
||||
@@ -1789,11 +1745,8 @@ static __maybe_unused void JS_DumpObject (JSRuntime *rt, JSRecord *rec);
|
||||
static __maybe_unused void JS_DumpGCObject (JSRuntime *rt, objhdr_t *p);
|
||||
static __maybe_unused void JS_DumpValue (JSContext *ctx, const char *str, JSValue val);
|
||||
static void js_dump_value_write (void *opaque, const char *buf, size_t len);
|
||||
static JSValue js_function_apply (JSContext *ctx, JSValue this_val, int argc, JSValue *argv, int magic);
|
||||
static void js_regexp_finalizer (JSRuntime *rt, JSValue val);
|
||||
static JSValue js_new_function (JSContext *ctx, JSFunctionKind kind);
|
||||
static void mark_function_children (JSRuntime *rt, JSFunction *func, JS_MarkFunc *mark_func);
|
||||
static void mark_function_children_decref (JSRuntime *rt, JSFunction *func);
|
||||
|
||||
/* Forward declarations for intrinsics (now declared in quickjs.h) */
|
||||
|
||||
@@ -2142,164 +2095,6 @@ static inline BOOL js_check_stack_overflow (JSRuntime *rt,
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ============================================================
|
||||
Buddy Allocator Implementation
|
||||
============================================================ */
|
||||
|
||||
/* Get order (log2) for a given size, rounding up to minimum */
|
||||
static int buddy_get_order (size_t size) {
|
||||
int order = BUDDY_MIN_ORDER;
|
||||
size_t block_size = 1ULL << BUDDY_MIN_ORDER;
|
||||
while (block_size < size && order < BUDDY_MAX_ORDER) {
|
||||
order++;
|
||||
block_size <<= 1;
|
||||
}
|
||||
return order;
|
||||
}
|
||||
|
||||
/* Get offset of block from base */
|
||||
static size_t buddy_block_offset (BuddyAllocator *b, void *ptr) {
|
||||
return (uint8_t *)ptr - b->base;
|
||||
}
|
||||
|
||||
/* Get buddy address for a block at given offset and order */
|
||||
static void *buddy_get_buddy (BuddyAllocator *b, void *ptr, int order) {
|
||||
size_t offset = buddy_block_offset (b, ptr);
|
||||
size_t buddy_offset = offset ^ (1ULL << order);
|
||||
return b->base + buddy_offset;
|
||||
}
|
||||
|
||||
/* Remove block from its free list */
|
||||
static void buddy_list_remove (BuddyBlock *block) {
|
||||
if (block->prev) block->prev->next = block->next;
|
||||
if (block->next) block->next->prev = block->prev;
|
||||
block->next = NULL;
|
||||
block->prev = NULL;
|
||||
}
|
||||
|
||||
/* Add block to END of free list (FIFO policy).
|
||||
This ensures recently freed blocks are reused last, making stale pointer
|
||||
bugs crash deterministically instead of accidentally working. */
|
||||
static void buddy_list_add (BuddyAllocator *b, BuddyBlock *block, int order) {
|
||||
int level = order - BUDDY_MIN_ORDER;
|
||||
block->prev = NULL;
|
||||
block->next = NULL;
|
||||
block->order = order;
|
||||
block->is_free = 1;
|
||||
|
||||
if (!b->free_lists[level]) {
|
||||
b->free_lists[level] = block;
|
||||
return;
|
||||
}
|
||||
|
||||
/* FIFO: append to end */
|
||||
BuddyBlock *tail = b->free_lists[level];
|
||||
while (tail->next) tail = tail->next;
|
||||
tail->next = block;
|
||||
block->prev = tail;
|
||||
}
|
||||
|
||||
/* Initialize buddy allocator with 256MB pool */
|
||||
static int buddy_init (BuddyAllocator *b) {
|
||||
if (b->initialized) return 0;
|
||||
|
||||
/* Allocate the pool (using system malloc, not js_malloc) */
|
||||
b->base = (uint8_t *)malloc (BUDDY_POOL_SIZE);
|
||||
if (!b->base) return -1;
|
||||
|
||||
b->total_size = BUDDY_POOL_SIZE;
|
||||
|
||||
/* Initialize free lists */
|
||||
for (int i = 0; i < BUDDY_LEVELS; i++) {
|
||||
b->free_lists[i] = NULL;
|
||||
}
|
||||
|
||||
/* Add entire pool as one free block at max order */
|
||||
BuddyBlock *block = (BuddyBlock *)b->base;
|
||||
buddy_list_add (b, block, BUDDY_MAX_ORDER);
|
||||
|
||||
b->initialized = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Allocate a block of at least 'size' bytes */
|
||||
static void *buddy_alloc (BuddyAllocator *b, size_t size) {
|
||||
if (!b->initialized) {
|
||||
if (buddy_init (b) < 0) return NULL;
|
||||
}
|
||||
|
||||
int order = buddy_get_order (size);
|
||||
if (order > BUDDY_MAX_ORDER) return NULL;
|
||||
|
||||
/* Find smallest available block that fits */
|
||||
int level = order - BUDDY_MIN_ORDER;
|
||||
int found_level = -1;
|
||||
for (int i = level; i < BUDDY_LEVELS; i++) {
|
||||
if (b->free_lists[i]) {
|
||||
found_level = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found_level < 0) return NULL; /* Out of memory */
|
||||
|
||||
/* Remove block from free list */
|
||||
BuddyBlock *block = b->free_lists[found_level];
|
||||
if (block->prev) {
|
||||
block->prev->next = block->next;
|
||||
} else {
|
||||
b->free_lists[found_level] = block->next;
|
||||
}
|
||||
if (block->next) block->next->prev = NULL;
|
||||
|
||||
/* Split block down to required order */
|
||||
int current_order = found_level + BUDDY_MIN_ORDER;
|
||||
while (current_order > order) {
|
||||
current_order--;
|
||||
/* Create buddy block in upper half */
|
||||
BuddyBlock *buddy = (BuddyBlock *)((uint8_t *)block + (1ULL << current_order));
|
||||
buddy_list_add (b, buddy, current_order);
|
||||
}
|
||||
|
||||
block->order = order;
|
||||
block->is_free = 0;
|
||||
return block;
|
||||
}
|
||||
|
||||
/* Free a block */
|
||||
static void buddy_free (BuddyAllocator *b, void *ptr, size_t size) {
|
||||
if (!ptr || !b->initialized) return;
|
||||
|
||||
int order = buddy_get_order (size);
|
||||
BuddyBlock *block = (BuddyBlock *)ptr;
|
||||
|
||||
/* Try to coalesce with buddy */
|
||||
while (order < BUDDY_MAX_ORDER) {
|
||||
BuddyBlock *buddy = buddy_get_buddy (b, block, order);
|
||||
|
||||
/* Check if buddy is free and same order */
|
||||
if (!buddy->is_free || buddy->order != order) break;
|
||||
|
||||
/* Remove buddy from free list */
|
||||
int level = order - BUDDY_MIN_ORDER;
|
||||
if (buddy->prev) {
|
||||
buddy->prev->next = buddy->next;
|
||||
} else {
|
||||
b->free_lists[level] = buddy->next;
|
||||
}
|
||||
if (buddy->next) buddy->next->prev = NULL;
|
||||
|
||||
/* Coalesce: use lower address as merged block */
|
||||
if ((uint8_t *)buddy < (uint8_t *)block) {
|
||||
block = buddy;
|
||||
}
|
||||
order++;
|
||||
}
|
||||
|
||||
/* Add merged block to free list */
|
||||
buddy_list_add (b, block, order);
|
||||
}
|
||||
|
||||
/* Destroy buddy allocator and free pool */
|
||||
static void buddy_destroy (BuddyAllocator *b) {
|
||||
if (!b->initialized) return;
|
||||
@@ -2464,10 +2259,8 @@ static void gc_scan_object (JSContext *ctx, void *ptr, uint8_t *from_base, uint8
|
||||
case OBJ_RECORD: {
|
||||
JSRecord *rec = (JSRecord *)ptr;
|
||||
uint32_t mask = (uint32_t)objhdr_cap56 (rec->mist_hdr);
|
||||
uint32_t num_slots = mask + 1;
|
||||
uint32_t used_slots = (uint32_t)rec->len;
|
||||
#ifdef DUMP_GC_DETAIL
|
||||
printf(" record: slots=%u used=%u proto=%p\n", num_slots, used_slots, (void*)rec->proto);
|
||||
printf(" record: slots=%u used=%u proto=%p\n", mask + 1, (uint32_t)rec->len, (void*)rec->proto);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
/* Copy prototype */
|
||||
@@ -2747,8 +2540,8 @@ static int ctx_gc (JSContext *ctx, int allow_grow) {
|
||||
fflush(stdout);
|
||||
#endif
|
||||
while (scan < to_free) {
|
||||
objhdr_t scan_hdr = *(objhdr_t *)scan;
|
||||
#ifdef DUMP_GC_DETAIL
|
||||
objhdr_t scan_hdr = *(objhdr_t *)scan;
|
||||
printf(" scan %p: type=%d hdr=0x%llx", (void*)scan, objhdr_type(scan_hdr), (unsigned long long)scan_hdr);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
@@ -2787,12 +2580,16 @@ static int ctx_gc (JSContext *ctx, int allow_grow) {
|
||||
|
||||
/* If <20% recovered, double next block size for future allocations
|
||||
But only if allow_grow is set (i.e., GC was triggered due to low space) */
|
||||
#ifdef DUMP_GC
|
||||
int will_grow = 0;
|
||||
#endif
|
||||
if (allow_grow && old_used > 0 && recovered < old_used / 5) {
|
||||
size_t doubled = new_size * 2;
|
||||
if (doubled <= (1ULL << BUDDY_MAX_ORDER)) {
|
||||
ctx->next_block_size = doubled;
|
||||
#ifdef DUMP_GC
|
||||
will_grow = 1;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3014,8 +2811,7 @@ void JS_SetContextOpaque (JSContext *ctx, void *opaque) {
|
||||
/* set the new value and free the old value after (freeing the value
|
||||
can reallocate the object data) */
|
||||
static inline void set_value (JSContext *ctx, JSValue *pval, JSValue new_val) {
|
||||
JSValue old_val;
|
||||
old_val = *pval;
|
||||
(void)ctx;
|
||||
*pval = new_val;
|
||||
}
|
||||
|
||||
@@ -3031,25 +2827,6 @@ JSValue JS_GetClassProto (JSContext *ctx, JSClassID class_id) {
|
||||
return ctx->class_proto[class_id];
|
||||
}
|
||||
|
||||
/* used by the GC */
|
||||
static void JS_MarkContext (JSRuntime *rt, JSContext *ctx, JS_MarkFunc *mark_func) {
|
||||
int i;
|
||||
|
||||
JS_MarkValue (rt, ctx->global_obj, mark_func);
|
||||
JS_MarkValue (rt, ctx->eval_env, mark_func);
|
||||
|
||||
JS_MarkValue (rt, ctx->throw_type_error, mark_func);
|
||||
JS_MarkValue (rt, ctx->eval_obj, mark_func);
|
||||
|
||||
for (i = 0; i < JS_NATIVE_ERROR_COUNT; i++) {
|
||||
JS_MarkValue (rt, ctx->native_error_proto[i], mark_func);
|
||||
}
|
||||
for (i = 0; i < rt->class_count; i++) {
|
||||
JS_MarkValue (rt, ctx->class_proto[i], mark_func);
|
||||
}
|
||||
JS_MarkValue (rt, ctx->regexp_ctor, mark_func);
|
||||
}
|
||||
|
||||
void JS_FreeContext (JSContext *ctx) {
|
||||
JSRuntime *rt = ctx->rt;
|
||||
int i;
|
||||
@@ -3110,36 +2887,6 @@ static JSText *js_alloc_string (JSContext *ctx, int max_len);
|
||||
|
||||
static inline int is_num (int c) { return c >= '0' && c <= '9'; }
|
||||
|
||||
/* return TRUE if the string is a number n with 0 <= n <= 2^32-1 */
|
||||
static inline BOOL is_num_string (uint32_t *pval, const JSText *p) {
|
||||
uint32_t n;
|
||||
uint64_t n64;
|
||||
int c, i, len;
|
||||
|
||||
len = (int)JSText_len (p);
|
||||
if (len == 0 || len > 10) return FALSE;
|
||||
c = string_get (p, 0);
|
||||
if (is_num (c)) {
|
||||
if (c == '0') {
|
||||
if (len != 1) return FALSE;
|
||||
n = 0;
|
||||
} else {
|
||||
n = c - '0';
|
||||
for (i = 1; i < len; i++) {
|
||||
c = string_get (p, i);
|
||||
if (!is_num (c)) return FALSE;
|
||||
n64 = (uint64_t)n * 10 + (c - '0');
|
||||
if ((n64 >> 32) != 0) return FALSE;
|
||||
n = n64;
|
||||
}
|
||||
}
|
||||
*pval = n;
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static __maybe_unused void JS_DumpChar (FILE *fo, int c, int sep) {
|
||||
if (c == sep || c == '\\') {
|
||||
fputc ('\\', fo);
|
||||
@@ -3200,9 +2947,8 @@ BOOL JS_IsRegisteredClass (JSRuntime *rt, JSClassID class_id) {
|
||||
/* create a new object internal class. Return -1 if error, 0 if
|
||||
OK. The finalizer can be NULL if none is needed. */
|
||||
static int JS_NewClass1 (JSRuntime *rt, JSClassID class_id, const JSClassDef *class_def, const char *name) {
|
||||
int new_size, i;
|
||||
int new_size;
|
||||
JSClass *cl, *new_class_array;
|
||||
struct list_head *el;
|
||||
|
||||
if (class_id >= (1 << 16)) return -1;
|
||||
if (class_id < rt->class_count && rt->class_array[class_id].class_id != 0)
|
||||
@@ -3361,24 +3107,6 @@ static JSText *pretext_putc (JSContext *ctx, JSText *s, uint32_t c) {
|
||||
return pretext_putc_slow (ctx, s, c);
|
||||
}
|
||||
|
||||
static JSText *pretext_write32 (JSContext *ctx, JSText *s, const uint32_t *p, int len) {
|
||||
int cur_len = (int)s->length;
|
||||
int cap = (int)objhdr_cap56 (s->hdr);
|
||||
if (cur_len + len > cap) {
|
||||
s = pretext_realloc (ctx, s, cur_len + len);
|
||||
if (!s) return NULL;
|
||||
}
|
||||
for (int i = 0; i < len; i++) {
|
||||
string_put (s, cur_len + i, p[i]);
|
||||
}
|
||||
s->length += len;
|
||||
return s;
|
||||
}
|
||||
|
||||
static inline int string_getc (const JSText *p, int *pidx) {
|
||||
return string_get (p, (*pidx)++);
|
||||
}
|
||||
|
||||
static JSText *pretext_write8 (JSContext *ctx, JSText *s, const uint8_t *p, int len) {
|
||||
int cur_len = (int)s->length;
|
||||
int cap = (int)objhdr_cap56 (s->hdr);
|
||||
@@ -3631,9 +3359,10 @@ void JS_FreeCString (JSContext *ctx, const char *ptr) {
|
||||
|
||||
/* return < 0, 0 or > 0 */
|
||||
static int js_string_compare (JSContext *ctx, const JSText *p1, const JSText *p2) {
|
||||
int res, len, i;
|
||||
int len, i;
|
||||
int len1 = (int)JSText_len (p1);
|
||||
int len2 = (int)JSText_len (p2);
|
||||
(void)ctx;
|
||||
len = min_int (len1, len2);
|
||||
for (i = 0; i < len; i++) {
|
||||
uint32_t c1 = string_get (p1, i);
|
||||
@@ -3668,18 +3397,16 @@ static JSValue JS_ConcatString1 (JSContext *ctx, const JSText *p1, const JSText
|
||||
|
||||
// TODO: this function is fucked.
|
||||
static BOOL JS_ConcatStringInPlace (JSContext *ctx, JSText *p1, JSValue op2) {
|
||||
(void)ctx;
|
||||
if (JS_VALUE_GET_TAG (op2) == JS_TAG_STRING) {
|
||||
JSText *p2 = JS_VALUE_GET_STRING (op2);
|
||||
int64_t new_len;
|
||||
size_t words_needed;
|
||||
int64_t len1 = JSText_len (p1);
|
||||
int64_t len2 = JSText_len (p2);
|
||||
|
||||
if (len2 == 0) return TRUE;
|
||||
|
||||
new_len = len1 + len2;
|
||||
/* UTF-32: 2 chars per 64-bit word, round up */
|
||||
words_needed = (new_len + 1) / 2;
|
||||
|
||||
/* Append p2's characters using string_put/string_get */
|
||||
for (int64_t i = 0; i < len2; i++) {
|
||||
@@ -4330,7 +4057,6 @@ static void build_backtrace (JSContext *ctx, JSValue error_obj, const char *file
|
||||
DynBuf dbuf;
|
||||
const char *func_name_str;
|
||||
const char *str1;
|
||||
JSRecord *p;
|
||||
JSGCRef err_ref;
|
||||
|
||||
if (!JS_IsObject (error_obj))
|
||||
@@ -7180,8 +6906,6 @@ restart:
|
||||
}
|
||||
BREAK;
|
||||
CASE (OP_call_method) : CASE (OP_tail_call_method) : {
|
||||
BOOL is_proxy = FALSE;
|
||||
|
||||
call_argc = get_u16 (pc);
|
||||
pc += 2;
|
||||
call_argv = sp - call_argc;
|
||||
@@ -7225,7 +6949,7 @@ restart:
|
||||
}
|
||||
BREAK;
|
||||
CASE (OP_array_from) : {
|
||||
int i, ret;
|
||||
int i;
|
||||
|
||||
call_argc = get_u16 (pc);
|
||||
pc += 2;
|
||||
@@ -8153,9 +7877,7 @@ restart:
|
||||
} else {
|
||||
inc_loc_slow:
|
||||
sf->cur_pc = pc;
|
||||
/* must duplicate otherwise the variable value may
|
||||
be destroyed before JS code accesses it */
|
||||
op1 = op1;
|
||||
/* op1 is read from var_buf, passed by reference to js_unary_arith_slow */
|
||||
if (js_unary_arith_slow (ctx, &op1 + 1, OP_inc)) goto exception;
|
||||
set_value (ctx, &var_buf[idx], op1);
|
||||
}
|
||||
@@ -8176,9 +7898,7 @@ restart:
|
||||
} else {
|
||||
dec_loc_slow:
|
||||
sf->cur_pc = pc;
|
||||
/* must duplicate otherwise the variable value may
|
||||
be destroyed before JS code accesses it */
|
||||
op1 = op1;
|
||||
/* op1 is read from var_buf, passed by reference to js_unary_arith_slow */
|
||||
if (js_unary_arith_slow (ctx, &op1 + 1, OP_dec)) goto exception;
|
||||
set_value (ctx, &var_buf[idx], op1);
|
||||
}
|
||||
@@ -9461,7 +9181,6 @@ static __exception int js_parse_string (JSParseState *s, int sep, BOOL do_throw,
|
||||
/* LS or PS are skipped */
|
||||
if (c == CP_LS || c == CP_PS) continue;
|
||||
} else {
|
||||
parse_escape:
|
||||
ret = lre_parse_escape (&p, TRUE);
|
||||
if (ret == -1) {
|
||||
invalid_escape:
|
||||
@@ -9898,7 +9617,6 @@ redo:
|
||||
} else if (p[1] == '/') {
|
||||
/* line comment */
|
||||
p += 2;
|
||||
skip_line_comment:
|
||||
for (;;) {
|
||||
if (*p == '\0' && p >= s->buf_end) break;
|
||||
if (*p == '\r' || *p == '\n') break;
|
||||
@@ -11211,7 +10929,6 @@ static int define_var (JSParseState *s, JSFunctionDef *fd, JSValue name, JSVarDe
|
||||
|
||||
case JS_VAR_DEF_VAR:
|
||||
if (find_lexical_decl (ctx, fd, name, fd->scope_first, FALSE) >= 0) {
|
||||
invalid_lexical_redefinition:
|
||||
/* error to redefine a var that inside a lexical scope */
|
||||
return js_parse_error (s, "invalid redefinition of lexical identifier");
|
||||
}
|
||||
@@ -11657,7 +11374,6 @@ static __exception int js_parse_object_literal (JSParseState *s) {
|
||||
emit_prop_key (s, name);
|
||||
}
|
||||
}
|
||||
next:
|
||||
name = JS_NULL;
|
||||
if (s->token.val != ',') break;
|
||||
if (next_token (s)) goto fail;
|
||||
@@ -12245,7 +11961,6 @@ static __exception int js_parse_postfix_expr (JSParseState *s,
|
||||
emit_op (s, OP_push_i32);
|
||||
emit_u32 (s, JS_VALUE_GET_INT (val));
|
||||
} else {
|
||||
large_number:
|
||||
if (emit_push_const (s, val) < 0) return -1;
|
||||
}
|
||||
}
|
||||
@@ -12428,11 +12143,6 @@ static __exception int js_parse_postfix_expr (JSParseState *s,
|
||||
opcode = OP_get_array_el;
|
||||
} break;
|
||||
case OP_scope_get_var: {
|
||||
JSValue name;
|
||||
int scope;
|
||||
uint32_t idx = get_u32 (fd->byte_code.buf + fd->last_opcode_pos + 1);
|
||||
name = fd->cpool[idx];
|
||||
scope = get_u16 (fd->byte_code.buf + fd->last_opcode_pos + 5);
|
||||
/* verify if function name resolves to a simple
|
||||
get_loc/get_arg: a function call inside a `with`
|
||||
statement can resolve to a method call of the
|
||||
@@ -12930,7 +12640,6 @@ static __exception int js_parse_assign_expr2 (JSParseState *s,
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
next:
|
||||
if (s->token.val == TOK_IDENT) {
|
||||
/* name0 is used to check for OP_set_name pattern, not duplicated */
|
||||
name0 = s->token.u.ident.str;
|
||||
@@ -13176,7 +12885,6 @@ static __exception int js_parse_block (JSParseState *s) {
|
||||
|
||||
/* allowed parse_flags: PF_IN_ACCEPTED */
|
||||
static __exception int js_parse_var (JSParseState *s, int parse_flags, int tok, BOOL export_flag) {
|
||||
JSContext *ctx = s->ctx;
|
||||
JSFunctionDef *fd = s->cur_func;
|
||||
JSValue name = JS_NULL;
|
||||
|
||||
@@ -13297,7 +13005,6 @@ static void set_eval_ret_undefined (JSParseState *s) {
|
||||
|
||||
static __exception int js_parse_statement_or_decl (JSParseState *s,
|
||||
int decl_mask) {
|
||||
JSContext *ctx = s->ctx;
|
||||
JSValue label_name;
|
||||
int tok;
|
||||
|
||||
@@ -13371,7 +13078,6 @@ static __exception int js_parse_statement_or_decl (JSParseState *s,
|
||||
if (js_parse_expect_semi (s)) goto fail;
|
||||
} break;
|
||||
case TOK_DEF:
|
||||
haslet:
|
||||
if (!(decl_mask & DECL_MASK_OTHER)) {
|
||||
js_parse_error (
|
||||
s, "lexical declarations can't appear in single-statement context");
|
||||
@@ -15040,7 +14746,7 @@ static void instantiate_hoisted_definitions (JSContext *ctx, JSFunctionDef *s, D
|
||||
dbuf_put_u32 (bc, key_idx);
|
||||
}
|
||||
}
|
||||
done_global_var:
|
||||
done_global_var:;
|
||||
}
|
||||
|
||||
js_free (ctx, s->global_vars);
|
||||
@@ -16842,7 +16548,7 @@ static __exception int js_parse_function_decl2 (JSParseState *s,
|
||||
}
|
||||
|
||||
} else if (func_type != JS_PARSE_FUNC_ARROW) {
|
||||
func_name = func_name;
|
||||
/* func_name is already set, nothing to do */
|
||||
}
|
||||
|
||||
if (func_type == JS_PARSE_FUNC_VAR) {
|
||||
@@ -16989,7 +16695,6 @@ static __exception int js_parse_function_decl2 (JSParseState *s,
|
||||
}
|
||||
if ((func_type == JS_PARSE_FUNC_GETTER && fd->arg_count != 0)
|
||||
|| (func_type == JS_PARSE_FUNC_SETTER && fd->arg_count != 1)) {
|
||||
fail_accessor:
|
||||
js_parse_error (s, "invalid number of arguments for getter or setter");
|
||||
goto fail;
|
||||
}
|
||||
@@ -17967,9 +17672,8 @@ fail:
|
||||
|
||||
/* create the atom table */
|
||||
static int JS_WriteObjectAtoms (BCWriterState *s) {
|
||||
JSRuntime *rt = s->ctx->rt;
|
||||
DynBuf dbuf1;
|
||||
int i, atoms_size;
|
||||
int atoms_size;
|
||||
|
||||
dbuf1 = s->dbuf;
|
||||
js_dbuf_init (s->ctx, &s->dbuf);
|
||||
@@ -18657,7 +18361,6 @@ static JSValue find_key (JSContext *ctx, const char *name) {
|
||||
|
||||
static int JS_InstantiateFunctionListItem (JSContext *ctx, JSValue *obj_ptr, JSValue key, const JSCFunctionListEntry *e) {
|
||||
JSValue val;
|
||||
int prop_flags = e->prop_flags;
|
||||
|
||||
switch (e->def_type) {
|
||||
case JS_DEF_ALIAS: /* using autoinit for aliases is not safe */
|
||||
@@ -19227,7 +18930,7 @@ int lre_check_timeout (void *opaque) {
|
||||
}
|
||||
|
||||
void *lre_realloc (void *opaque, void *ptr, size_t size) {
|
||||
JSContext *ctx = opaque;
|
||||
(void)opaque;
|
||||
/* No JS exception is raised here */
|
||||
return js_realloc_rt (ptr, size);
|
||||
}
|
||||
@@ -19940,9 +19643,8 @@ exception:
|
||||
|
||||
static int js_json_to_str (JSContext *ctx, JSONStringifyContext *jsc, JSValue holder, JSValue val, JSValue indent) {
|
||||
JSValue indent1, sep, sep1, tab, v, prop;
|
||||
JSRecord *p;
|
||||
int64_t i, len;
|
||||
int cl, ret;
|
||||
int ret;
|
||||
BOOL has_content;
|
||||
JSGCRef val_ref;
|
||||
|
||||
@@ -20933,9 +20635,6 @@ static JSValue js_cell_character (JSContext *ctx, JSValue this_val, int argc, JS
|
||||
return JS_NewString (ctx, "");
|
||||
}
|
||||
|
||||
static JSText *mist_text (JSContext *ctx, JSValue arg, int argc, JSValue *argv) {
|
||||
}
|
||||
|
||||
/* text(arg, format) - main text function */
|
||||
static JSValue js_cell_text (JSContext *ctx, JSValue this_val, int argc, JSValue *argv) {
|
||||
if (argc < 1) return JS_NULL;
|
||||
@@ -22433,10 +22132,10 @@ void JS_DumpFunctionBytecode (JSContext *ctx, JSValue func_val) {
|
||||
|
||||
/* array(arg, arg2, arg3, arg4) - main array function */
|
||||
static JSValue js_cell_array (JSContext *ctx, JSValue this_val, int argc, JSValue *argv) {
|
||||
(void)this_val;
|
||||
if (argc < 1) return JS_NULL;
|
||||
|
||||
JSValue arg = argv[0];
|
||||
int tag = JS_VALUE_GET_TAG (arg);
|
||||
|
||||
/* array(number) - create array of size */
|
||||
/* array(number, initial_value) - create array with initial values */
|
||||
@@ -22699,8 +22398,6 @@ static JSValue js_cell_array (JSContext *ctx, JSValue this_val, int argc, JSValu
|
||||
return result;
|
||||
}
|
||||
|
||||
int tag2 = JS_VALUE_GET_TAG (argv[1]);
|
||||
|
||||
if (JS_VALUE_IS_TEXT (argv[1])) {
|
||||
/* Split by separator */
|
||||
const char *cstr = JS_ToCString (ctx, arg);
|
||||
@@ -23254,6 +22951,7 @@ static JSValue js_cell_array_filter (JSContext *ctx, JSValue this_val, int argc,
|
||||
|
||||
/* array.sort(arr, select) - GC-safe */
|
||||
static JSValue js_cell_array_sort (JSContext *ctx, JSValue this_val, int argc, JSValue *argv) {
|
||||
(void)this_val;
|
||||
if (argc < 1) return JS_NULL;
|
||||
if (!JS_IsArray (argv[0])) return JS_NULL;
|
||||
|
||||
@@ -23265,8 +22963,6 @@ static JSValue js_cell_array_sort (JSContext *ctx, JSValue this_val, int argc, J
|
||||
JSArray *arr = JS_VALUE_GET_ARRAY (arr_ref.val);
|
||||
word_t len = arr->len;
|
||||
|
||||
/* Protect result with GCRef */
|
||||
JSGCRef result_ref;
|
||||
JSValue result = JS_NewArrayLen (ctx, len);
|
||||
if (JS_IsException (result)) { JS_PopGCRef (ctx, &arr_ref); return result; }
|
||||
|
||||
@@ -24735,6 +24431,7 @@ static JSValue js_cell_push (JSContext *ctx, JSValue this_val, int argc, JSValue
|
||||
}
|
||||
|
||||
static JSValue js_cell_proto (JSContext *ctx, JSValue this_val, int argc, JSValue *argv) {
|
||||
(void)this_val;
|
||||
if (argc < 1) return JS_NULL;
|
||||
|
||||
JSValue obj = argv[0];
|
||||
@@ -24751,8 +24448,6 @@ static JSValue js_cell_proto (JSContext *ctx, JSValue this_val, int argc, JSValu
|
||||
|
||||
/* If prototype is Object.prototype, return null */
|
||||
if (JS_IsObject (proto)) {
|
||||
JSValue obj_proto
|
||||
= JS_GetPropertyStr (ctx, ctx->class_proto[JS_CLASS_OBJECT], "");
|
||||
if (JS_VALUE_GET_OBJ (proto)
|
||||
== JS_VALUE_GET_OBJ (ctx->class_proto[JS_CLASS_OBJECT])) {
|
||||
return JS_NULL;
|
||||
@@ -25098,9 +24793,9 @@ static JSValue js_cell_is_object (JSContext *ctx, JSValue this_val, int argc, JS
|
||||
|
||||
/* is_stone(val) - check if value is immutable */
|
||||
static JSValue js_cell_is_stone (JSContext *ctx, JSValue this_val, int argc, JSValue *argv) {
|
||||
(void)this_val;
|
||||
if (argc < 1) return JS_FALSE;
|
||||
|
||||
JSValue obj = argv[0];
|
||||
return JS_NewBool (ctx, JS_IsStone (argv[0]));
|
||||
}
|
||||
|
||||
@@ -25197,8 +24892,6 @@ static void js_set_global_cfunc(JSContext *ctx, const char *name, JSCFunction *f
|
||||
}
|
||||
|
||||
void JS_AddIntrinsicBaseObjects (JSContext *ctx) {
|
||||
int i;
|
||||
JSValue obj, number_obj;
|
||||
JSValue obj1;
|
||||
|
||||
ctx->throw_type_error = JS_NewCFunction (ctx, js_throw_type_error, NULL, 0);
|
||||
|
||||
Reference in New Issue
Block a user