Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 65 additions & 62 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,11 @@ struct JSRuntime {

JSValue current_exception;
/* true if inside an out of memory error, to avoid recursing */
bool in_out_of_memory;
_Bool in_out_of_memory : 1;
/* true if inside build_backtrace, to avoid recursing */
bool in_build_stack_trace;
_Bool in_build_stack_trace : 1;
/* true if inside JS_FreeRuntime */
bool in_free;
_Bool in_free : 1;

struct JSStackFrame *current_stack_frame;

Expand All @@ -314,7 +314,7 @@ struct JSRuntime {
/* used to allocate, free and clone SharedArrayBuffers */
JSSharedArrayBufferFunctions sab_funcs;

bool can_block; /* true if Atomics.wait can block */
_Bool can_block : 1; /* true if Atomics.wait can block */
uint32_t dump_flags : 24;

/* Shape hash table */
Expand Down Expand Up @@ -512,7 +512,7 @@ typedef struct JSWeakRefRecord {

typedef struct JSMapRecord {
int ref_count; /* used during enumeration to avoid freeing the record */
bool empty; /* true if the record is deleted */
_Bool empty : 1; /* true if the record is deleted */
struct JSMapState *map;
struct list_head link;
struct list_head hash_link;
Expand All @@ -521,7 +521,7 @@ typedef struct JSMapRecord {
} JSMapRecord;

typedef struct JSMapState {
bool is_weak; /* true if WeakSet/WeakMap */
_Bool is_weak : 1; /* true if WeakSet/WeakMap */
struct list_head records; /* list of JSMapRecord.link */
uint32_t record_count;
struct list_head *hash_table;
Expand Down Expand Up @@ -751,7 +751,7 @@ typedef enum JSIteratorHelperKindEnum {

typedef struct JSForInIterator {
JSValue obj;
bool is_array;
_Bool is_array : 1;
uint32_t array_length;
uint32_t idx;
} JSForInIterator;
Expand Down Expand Up @@ -785,13 +785,13 @@ typedef struct JSTypedArray {
JSObject *buffer; /* based array buffer */
uint32_t offset; /* byte offset in the array buffer */
uint32_t length; /* byte length in the array buffer */
bool track_rab; /* auto-track length of backing array buffer */
_Bool track_rab : 1; /* auto-track length of backing array buffer */
} JSTypedArray;

typedef struct JSAsyncFunctionState {
JSValue this_val; /* 'this' generator argument */
int argc; /* number of function arguments */
bool throw_flag; /* used to throw an exception in JS_CallInternal() */
_Bool throw_flag : 1; /* used to throw an exception in JS_CallInternal() */
JSStackFrame frame;
} JSAsyncFunctionState;

Expand All @@ -800,7 +800,7 @@ typedef struct JSAsyncFunctionState {
typedef struct JSAsyncFunctionData {
JSGCObjectHeader header; /* must come first */
JSValue resolving_funcs[2];
bool is_active; /* true if the async function state is valid */
_Bool is_active : 1; /* true if the async function state is valid */
JSAsyncFunctionState func_state;
} JSAsyncFunctionData;

Expand Down Expand Up @@ -871,9 +871,9 @@ struct JSModuleDef {
JSValue module_ns;
JSValue func_obj; /* only used for JS modules */
JSModuleInitFunc *init_func; /* only used for C modules */
bool has_tla; /* true if func_obj contains await */
bool resolved;
bool func_created;
_Bool has_tla : 1; /* true if func_obj contains await */
_Bool resolved : 1;
_Bool func_created : 1;
JSModuleStatus status : 8;
/* temp use during js_module_link() & js_module_evaluate() */
int dfs_index, dfs_ancestor_index;
Expand All @@ -883,14 +883,14 @@ struct JSModuleDef {
int async_parent_modules_count;
int async_parent_modules_size;
int pending_async_dependencies;
bool async_evaluation;
_Bool async_evaluation : 1;
int64_t async_evaluation_timestamp;
JSModuleDef *cycle_root;
JSValue promise; /* corresponds to spec field: capability */
JSValue resolving_funcs[2]; /* corresponds to spec field: capability */
/* true if evaluation yielded an exception. It is saved in
eval_exception */
bool eval_has_exception;
_Bool eval_has_exception : 1;
JSValue eval_exception;
JSValue meta_obj; /* for import.meta */
};
Expand Down Expand Up @@ -1043,7 +1043,7 @@ typedef struct JSCallSiteData {
JSValue filename;
JSValue func;
JSValue func_name;
bool native;
_Bool native : 1;
int line_num;
int col_num;
} JSCallSiteData;
Expand Down Expand Up @@ -20008,6 +20008,7 @@ typedef enum JSParseExportEnum {
JS_PARSE_EXPORT_DEFAULT,
} JSParseExportEnum;


typedef struct JSFunctionDef {
JSContext *ctx;
struct JSFunctionDef *parent;
Expand All @@ -20017,36 +20018,38 @@ typedef struct JSFunctionDef {
struct list_head child_list; /* list of JSFunctionDef.link */
struct list_head link;

bool is_eval; /* true if eval code */
/* change from `bool` to `_Bool flag : 1` which can reduce3 around 20 bytes per instance */
/* while still maintaining readablity comapared to `unsigned flag : 1`*/
_Bool is_eval : 1; /* true if eval code */
int eval_type; /* only valid if is_eval = true */
bool is_global_var; /* true if variables are not defined locally:
_Bool is_global_var : 1; /* true if variables are not defined locally:
eval global, eval module or non strict eval */
bool is_func_expr; /* true if function expression */
bool has_home_object; /* true if the home object is available */
bool has_prototype; /* true if a prototype field is necessary */
bool has_simple_parameter_list;
bool has_parameter_expressions; /* if true, an argument scope is created */
bool has_use_strict; /* to reject directive in special cases */
bool has_eval_call; /* true if the function contains a call to eval() */
bool has_arguments_binding; /* true if the 'arguments' binding is
_Bool is_func_expr : 1; /* true if function expression */
_Bool has_home_object : 1; /* true if the home object is available */
_Bool has_prototype : 1; /* true if a prototype field is necessary */
_Bool has_simple_parameter_list : 1;
_Bool has_parameter_expressions : 1; /* if true, an argument scope is created */
_Bool has_use_strict : 1; /* to reject directive in special cases */
_Bool has_eval_call : 1; /* true if the function contains a call to eval() */
_Bool has_arguments_binding : 1; /* true if the 'arguments' binding is
available in the function */
bool has_this_binding; /* true if the 'this' and new.target binding are
_Bool has_this_binding : 1; /* true if the 'this' and new.target binding are
available in the function */
bool new_target_allowed; /* true if the 'new.target' does not
_Bool new_target_allowed : 1; /* true if the 'new.target' does not
throw a syntax error */
bool super_call_allowed; /* true if super() is allowed */
bool super_allowed; /* true if super. or super[] is allowed */
bool arguments_allowed; /* true if the 'arguments' identifier is allowed */
bool is_derived_class_constructor;
bool in_function_body;
bool backtrace_barrier;
_Bool super_call_allowed : 1; /* true if super() is allowed */
_Bool super_allowed : 1; /* true if super. or super[] is allowed */
_Bool arguments_allowed : 1; /* true if the 'arguments' identifier is allowed */
_Bool is_derived_class_constructor : 1;
_Bool in_function_body : 1;
_Bool backtrace_barrier : 1;
JSFunctionKindEnum func_kind : 8;
JSParseFunctionEnum func_type : 7;
uint8_t is_strict_mode : 1;
JSAtom func_name; /* JS_ATOM_NULL if no name */

JSVarDef *vars;
uint32_t *vars_htab; // indexes into vars[]
uint32_t *vars_htab; /* indexes into vars[] */
int var_size; /* allocated size for vars[] */
int var_count;
JSVarDef *args;
Expand All @@ -20065,7 +20068,7 @@ typedef struct JSFunctionDef {
int new_target_var_idx; /* variable containg the 'new.target' value, -1 if none */
int this_active_func_var_idx; /* variable containg the 'this.active_func' value, -1 if none */
int home_object_var_idx;
bool need_home_object;
_Bool need_home_object : 1;

int scope_level; /* index into fd->scopes if the current lexical scope */
int scope_first; /* index into vd->vars of first lexically scoped variable */
Expand All @@ -20081,7 +20084,7 @@ typedef struct JSFunctionDef {

DynBuf byte_code;
int last_opcode_pos; /* -1 if no last opcode */
bool use_short_opcodes; /* true if short opcodes are used in byte_code */
_Bool use_short_opcodes : 1; /* true if short opcodes are used in byte_code */

LabelSlot *label_slots;
int label_size; /* allocated size for label_slots[] */
Expand Down Expand Up @@ -20119,7 +20122,7 @@ typedef struct JSFunctionDef {
int source_len;

JSModuleDef *module; /* != NULL when parsing a module */
bool has_await; /* true if await is used (used in module eval) */
_Bool has_await : 1; /* true if await is used (used in module eval) */
} JSFunctionDef;

typedef struct JSToken {
Expand All @@ -20137,8 +20140,8 @@ typedef struct JSToken {
} num;
struct {
JSAtom atom;
bool has_escape;
bool is_reserved;
_Bool has_escape : 1;
_Bool is_reserved : 1;
} ident;
struct {
JSValue body;
Expand All @@ -20155,18 +20158,18 @@ typedef struct JSParseState {
int col_num; /* column number of current offset */
const char *filename;
JSToken token;
bool got_lf; /* true if got line feed before the current token */
_Bool got_lf : 1; /* true if got line feed before the current token */
const uint8_t *last_ptr;
const uint8_t *buf_start;
const uint8_t *buf_ptr;
const uint8_t *buf_end;
const uint8_t *eol; // most recently seen end-of-line character
const uint8_t *mark; // first token character, invariant: eol < mark
const uint8_t *eol; /* most recently seen end-of-line character */
const uint8_t *mark; /* first token character, invariant: eol < mark */

/* current function code */
JSFunctionDef *cur_func;
bool is_module; /* parsing a module */
bool allow_html_comments;
_Bool is_module : 1; /* parsing a module */
_Bool allow_html_comments : 1;
} JSParseState;

typedef struct JSOpCode {
Expand Down Expand Up @@ -22700,7 +22703,7 @@ typedef struct JSParsePos {
int last_col_num;
int line_num;
int col_num;
bool got_lf;
_Bool got_lf : 1;
const uint8_t *ptr;
const uint8_t *eol;
const uint8_t *mark;
Expand Down Expand Up @@ -23113,9 +23116,9 @@ static JSAtom get_private_setter_name(JSContext *ctx, JSAtom name)
typedef struct {
JSFunctionDef *fields_init_fd;
int computed_fields_count;
bool need_brand;
_Bool need_brand : 1;
int brand_push_pos;
bool is_static;
_Bool is_static : 1;
} ClassFieldsDef;

static __exception int emit_class_init_start(JSParseState *s,
Expand Down Expand Up @@ -35134,11 +35137,11 @@ typedef enum BCTagEnum {
typedef struct BCWriterState {
JSContext *ctx;
DynBuf dbuf;
bool allow_bytecode;
bool allow_sab;
bool allow_reference;
bool allow_source;
bool allow_debug;
_Bool allow_bytecode : 1;
_Bool allow_sab : 1;
_Bool allow_reference : 1;
_Bool allow_source : 1;
_Bool allow_debug : 1;
uint32_t first_atom;
uint32_t *atom_to_idx;
int atom_to_idx_size;
Expand Down Expand Up @@ -36001,9 +36004,9 @@ typedef struct BCReaderState {
uint32_t idx_to_atom_count;
JSAtom *idx_to_atom;
int error_state;
bool allow_sab;
bool allow_bytecode;
bool allow_reference;
_Bool allow_sab : 1;
_Bool allow_bytecode : 1;
_Bool allow_reference : 1;
/* object references */
JSObject **objects;
int objects_count;
Expand Down Expand Up @@ -41615,7 +41618,7 @@ static JSValue js_iterator_constructor(JSContext *ctx, JSValueConst new_target,
// |index|, |count| and |running| because tcc miscompiles them
typedef struct JSIteratorConcatData {
int index, count; // elements (not pairs!) in values[] array
bool running;
_Bool running : 1;
JSValue iter, next, values[]; // array of (object, method) pairs
} JSIteratorConcatData;

Expand Down Expand Up @@ -46222,8 +46225,8 @@ static JSValue js_regexp_Symbol_match(JSContext *ctx, JSValueConst this_val,
typedef struct JSRegExpStringIteratorData {
JSValue iterating_regexp;
JSValue iterated_string;
bool global;
bool unicode;
_Bool global : 1;
_Bool unicode : 1;
int done;
} JSRegExpStringIteratorData;

Expand Down Expand Up @@ -50418,13 +50421,13 @@ typedef struct JSPromiseData {
JSPromiseStateEnum promise_state;
/* 0=fulfill, 1=reject, list of JSPromiseReactionData.link */
struct list_head promise_reactions[2];
bool is_handled; /* Note: only useful to debug */
_Bool is_handled : 1; /* Note: only useful to debug */
JSValue promise_result;
} JSPromiseData;

typedef struct JSPromiseFunctionDataResolved {
int ref_count;
bool already_resolved;
_Bool already_resolved : 1;
} JSPromiseFunctionDataResolved;

typedef struct JSPromiseFunctionData {
Expand Down Expand Up @@ -57089,7 +57092,7 @@ static JSValue js_atomics_isLockFree(JSContext *ctx,

typedef struct JSAtomicsWaiter {
struct list_head link;
bool linked;
_Bool linked : 1;
js_cond_t cond;
int32_t *ptr;
} JSAtomicsWaiter;
Expand Down