From fdcb37440336acb8e82ed8ed98c15c6c2d9556d9 Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Sat, 31 Jan 2026 10:33:29 -0600 Subject: [PATCH] fix formatting --- .clang-format | 9 +- source/quickjs-opcode.h | 5 - source/quickjs.c | 3474 ++++++++++++++++----------------------- 3 files changed, 1425 insertions(+), 2063 deletions(-) diff --git a/.clang-format b/.clang-format index b18b2b92..c43c9290 100644 --- a/.clang-format +++ b/.clang-format @@ -1,9 +1,16 @@ BasedOnStyle: GNU +Language: C + IndentWidth: 2 TabWidth: 2 UseTab: Never -ContinuationIndentWidth: 2 # Indents continuation lines by 2 spaces +ContinuationIndentWidth: 2 + AllowShortFunctionsOnASingleLine: true AllowShortBlocksOnASingleLine: true AllowShortIfStatementsOnASingleLine: true BreakBeforeBraces: Attach + +# --- Fix the "static T\nname(...)" style --- +AlwaysBreakAfterDefinitionReturnType: None +BreakAfterReturnType: None diff --git a/source/quickjs-opcode.h b/source/quickjs-opcode.h index d219e6de..049aa7f5 100644 --- a/source/quickjs-opcode.h +++ b/source/quickjs-opcode.h @@ -47,11 +47,6 @@ FMT(u32) FMT(i32) FMT(const) FMT(label) -FMT(atom) -FMT(atom_u8) -FMT(atom_u16) -FMT(atom_label_u8) -FMT(atom_label_u16) FMT(label_u16) FMT(key) FMT(key_u8) diff --git a/source/quickjs.c b/source/quickjs.c index 2c7db104..efd0d53b 100644 --- a/source/quickjs.c +++ b/source/quickjs.c @@ -145,14 +145,12 @@ typedef struct JSProfileState { #endif /* DUMP_PROFILE */ -static inline JS_BOOL -JS_VALUE_IS_TEXT (JSValue v) { +static inline JS_BOOL JS_VALUE_IS_TEXT (JSValue v) { int tag = JS_VALUE_GET_TAG (v); return tag == JS_TAG_STRING || tag == JS_TAG_STRING_IMM; } -static inline JS_BOOL -JS_VALUE_IS_NUMBER (JSValue v) { +static inline JS_BOOL JS_VALUE_IS_NUMBER (JSValue v) { int tag = JS_VALUE_GET_TAG (v); return tag == JS_TAG_INT || tag == JS_TAG_FLOAT64; } @@ -219,7 +217,8 @@ static inline void JS_FreeAtomStruct (JSRuntime *rt, void *p) { (void)p; } -static inline JSAtom JS_NewAtomLen (JSContext *ctx, const char *str, size_t len) { +static inline JSAtom JS_NewAtomLen (JSContext *ctx, const char *str, + size_t len) { (void)ctx; (void)str; (void)len; @@ -227,83 +226,93 @@ static inline JSAtom JS_NewAtomLen (JSContext *ctx, const char *str, size_t len) } /* Well-known atom constants (stubs for compatibility during transition) */ -/* Legacy atom constants - kept for bytecode serialization backward compatibility */ +/* Legacy atom constants - kept for bytecode serialization backward + * compatibility */ #define JS_ATOM_END 100 /* JS_KEY_* macros: JSValue immediate ASCII strings for common property names. These replace JS_ATOM_* for use with the new JSValue-based property API. */ -#define _JS_KEY1(c1) \ +#define _JS_KEY1(c1) \ ((JSValue)JS_TAG_STRING_IMM | ((JSValue)1 << 5) | ((JSValue)(c1) << 8)) -#define _JS_KEY2(c1,c2) \ - ((JSValue)JS_TAG_STRING_IMM | ((JSValue)2 << 5) | ((JSValue)(c1) << 8) | ((JSValue)(c2) << 16)) -#define _JS_KEY3(c1,c2,c3) \ - ((JSValue)JS_TAG_STRING_IMM | ((JSValue)3 << 5) | ((JSValue)(c1) << 8) | ((JSValue)(c2) << 16) | ((JSValue)(c3) << 24)) -#define _JS_KEY4(c1,c2,c3,c4) \ - ((JSValue)JS_TAG_STRING_IMM | ((JSValue)4 << 5) | ((JSValue)(c1) << 8) | ((JSValue)(c2) << 16) | ((JSValue)(c3) << 24) | ((JSValue)(c4) << 32)) -#define _JS_KEY5(c1,c2,c3,c4,c5) \ - ((JSValue)JS_TAG_STRING_IMM | ((JSValue)5 << 5) | ((JSValue)(c1) << 8) | ((JSValue)(c2) << 16) | ((JSValue)(c3) << 24) | ((JSValue)(c4) << 32) | ((JSValue)(c5) << 40)) -#define _JS_KEY6(c1,c2,c3,c4,c5,c6) \ - ((JSValue)JS_TAG_STRING_IMM | ((JSValue)6 << 5) | ((JSValue)(c1) << 8) | ((JSValue)(c2) << 16) | ((JSValue)(c3) << 24) | ((JSValue)(c4) << 32) | ((JSValue)(c5) << 40) | ((JSValue)(c6) << 48)) -#define _JS_KEY7(c1,c2,c3,c4,c5,c6,c7) \ - ((JSValue)JS_TAG_STRING_IMM | ((JSValue)7 << 5) | ((JSValue)(c1) << 8) | ((JSValue)(c2) << 16) | ((JSValue)(c3) << 24) | ((JSValue)(c4) << 32) | ((JSValue)(c5) << 40) | ((JSValue)(c6) << 48) | ((JSValue)(c7) << 56)) +#define _JS_KEY2(c1, c2) \ + ((JSValue)JS_TAG_STRING_IMM | ((JSValue)2 << 5) | ((JSValue)(c1) << 8) \ + | ((JSValue)(c2) << 16)) +#define _JS_KEY3(c1, c2, c3) \ + ((JSValue)JS_TAG_STRING_IMM | ((JSValue)3 << 5) | ((JSValue)(c1) << 8) \ + | ((JSValue)(c2) << 16) | ((JSValue)(c3) << 24)) +#define _JS_KEY4(c1, c2, c3, c4) \ + ((JSValue)JS_TAG_STRING_IMM | ((JSValue)4 << 5) | ((JSValue)(c1) << 8) \ + | ((JSValue)(c2) << 16) | ((JSValue)(c3) << 24) | ((JSValue)(c4) << 32)) +#define _JS_KEY5(c1, c2, c3, c4, c5) \ + ((JSValue)JS_TAG_STRING_IMM | ((JSValue)5 << 5) | ((JSValue)(c1) << 8) \ + | ((JSValue)(c2) << 16) | ((JSValue)(c3) << 24) | ((JSValue)(c4) << 32) \ + | ((JSValue)(c5) << 40)) +#define _JS_KEY6(c1, c2, c3, c4, c5, c6) \ + ((JSValue)JS_TAG_STRING_IMM | ((JSValue)6 << 5) | ((JSValue)(c1) << 8) \ + | ((JSValue)(c2) << 16) | ((JSValue)(c3) << 24) | ((JSValue)(c4) << 32) \ + | ((JSValue)(c5) << 40) | ((JSValue)(c6) << 48)) +#define _JS_KEY7(c1, c2, c3, c4, c5, c6, c7) \ + ((JSValue)JS_TAG_STRING_IMM | ((JSValue)7 << 5) | ((JSValue)(c1) << 8) \ + | ((JSValue)(c2) << 16) | ((JSValue)(c3) << 24) | ((JSValue)(c4) << 32) \ + | ((JSValue)(c5) << 40) | ((JSValue)(c6) << 48) | ((JSValue)(c7) << 56)) /* Common property keys as JSValue immediate strings (max 7 ASCII chars) */ /* Empty string: tag with length 0 */ -#define JS_KEY_empty ((JSValue)JS_TAG_STRING_IMM) -#define JS_KEY_name _JS_KEY4('n','a','m','e') -#define JS_KEY_length _JS_KEY6('l','e','n','g','t','h') -#define JS_KEY_message _JS_KEY7('m','e','s','s','a','g','e') -#define JS_KEY_stack _JS_KEY5('s','t','a','c','k') -#define JS_KEY_cause _JS_KEY5('c','a','u','s','e') -#define JS_KEY_errors _JS_KEY6('e','r','r','o','r','s') -#define JS_KEY_Error _JS_KEY5('E','r','r','o','r') -#define JS_KEY_raw _JS_KEY3('r','a','w') -#define JS_KEY_flags _JS_KEY5('f','l','a','g','s') -#define JS_KEY_source _JS_KEY6('s','o','u','r','c','e') -#define JS_KEY_exec _JS_KEY4('e','x','e','c') -#define JS_KEY_toJSON _JS_KEY6('t','o','J','S','O','N') -#define JS_KEY_eval _JS_KEY4('e','v','a','l') -#define JS_KEY_this _JS_KEY4('t','h','i','s') -#define JS_KEY_true _JS_KEY4('t','r','u','e') -#define JS_KEY_false _JS_KEY5('f','a','l','s','e') -#define JS_KEY_null _JS_KEY4('n','u','l','l') -#define JS_KEY_NaN _JS_KEY3('N','a','N') -#define JS_KEY_default _JS_KEY7('d','e','f','a','u','l','t') -#define JS_KEY_value _JS_KEY5('v','a','l','u','e') -#define JS_KEY_index _JS_KEY5('i','n','d','e','x') -#define JS_KEY_input _JS_KEY5('i','n','p','u','t') -#define JS_KEY_groups _JS_KEY6('g','r','o','u','p','s') -#define JS_KEY_indices _JS_KEY7('i','n','d','i','c','e','s') -#define JS_KEY_let _JS_KEY3('l','e','t') -#define JS_KEY_var _JS_KEY3('v','a','r') -#define JS_KEY_new _JS_KEY3('n','e','w') -#define JS_KEY_of _JS_KEY2('o','f') -#define JS_KEY_yield _JS_KEY5('y','i','e','l','d') -#define JS_KEY_async _JS_KEY5('a','s','y','n','c') -#define JS_KEY_target _JS_KEY6('t','a','r','g','e','t') -#define JS_KEY_from _JS_KEY4('f','r','o','m') -#define JS_KEY_meta _JS_KEY4('m','e','t','a') -#define JS_KEY_as _JS_KEY2('a','s') -#define JS_KEY_get _JS_KEY3('g','e','t') -#define JS_KEY_set _JS_KEY3('s','e','t') -#define JS_KEY_with _JS_KEY4('w','i','t','h') +#define JS_KEY_empty ((JSValue)JS_TAG_STRING_IMM) +#define JS_KEY_name _JS_KEY4 ('n', 'a', 'm', 'e') +#define JS_KEY_length _JS_KEY6 ('l', 'e', 'n', 'g', 't', 'h') +#define JS_KEY_message _JS_KEY7 ('m', 'e', 's', 's', 'a', 'g', 'e') +#define JS_KEY_stack _JS_KEY5 ('s', 't', 'a', 'c', 'k') +#define JS_KEY_cause _JS_KEY5 ('c', 'a', 'u', 's', 'e') +#define JS_KEY_errors _JS_KEY6 ('e', 'r', 'r', 'o', 'r', 's') +#define JS_KEY_Error _JS_KEY5 ('E', 'r', 'r', 'o', 'r') +#define JS_KEY_raw _JS_KEY3 ('r', 'a', 'w') +#define JS_KEY_flags _JS_KEY5 ('f', 'l', 'a', 'g', 's') +#define JS_KEY_source _JS_KEY6 ('s', 'o', 'u', 'r', 'c', 'e') +#define JS_KEY_exec _JS_KEY4 ('e', 'x', 'e', 'c') +#define JS_KEY_toJSON _JS_KEY6 ('t', 'o', 'J', 'S', 'O', 'N') +#define JS_KEY_eval _JS_KEY4 ('e', 'v', 'a', 'l') +#define JS_KEY_this _JS_KEY4 ('t', 'h', 'i', 's') +#define JS_KEY_true _JS_KEY4 ('t', 'r', 'u', 'e') +#define JS_KEY_false _JS_KEY5 ('f', 'a', 'l', 's', 'e') +#define JS_KEY_null _JS_KEY4 ('n', 'u', 'l', 'l') +#define JS_KEY_NaN _JS_KEY3 ('N', 'a', 'N') +#define JS_KEY_default _JS_KEY7 ('d', 'e', 'f', 'a', 'u', 'l', 't') +#define JS_KEY_value _JS_KEY5 ('v', 'a', 'l', 'u', 'e') +#define JS_KEY_index _JS_KEY5 ('i', 'n', 'd', 'e', 'x') +#define JS_KEY_input _JS_KEY5 ('i', 'n', 'p', 'u', 't') +#define JS_KEY_groups _JS_KEY6 ('g', 'r', 'o', 'u', 'p', 's') +#define JS_KEY_indices _JS_KEY7 ('i', 'n', 'd', 'i', 'c', 'e', 's') +#define JS_KEY_let _JS_KEY3 ('l', 'e', 't') +#define JS_KEY_var _JS_KEY3 ('v', 'a', 'r') +#define JS_KEY_new _JS_KEY3 ('n', 'e', 'w') +#define JS_KEY_of _JS_KEY2 ('o', 'f') +#define JS_KEY_yield _JS_KEY5 ('y', 'i', 'e', 'l', 'd') +#define JS_KEY_async _JS_KEY5 ('a', 's', 'y', 'n', 'c') +#define JS_KEY_target _JS_KEY6 ('t', 'a', 'r', 'g', 'e', 't') +#define JS_KEY_from _JS_KEY4 ('f', 'r', 'o', 'm') +#define JS_KEY_meta _JS_KEY4 ('m', 'e', 't', 'a') +#define JS_KEY_as _JS_KEY2 ('a', 's') +#define JS_KEY_get _JS_KEY3 ('g', 'e', 't') +#define JS_KEY_set _JS_KEY3 ('s', 'e', 't') +#define JS_KEY_with _JS_KEY4 ('w', 'i', 't', 'h') /* Internal variable names */ -#define JS_KEY__ret_ _JS_KEY5('<','r','e','t','>') -#define JS_KEY__eval_ _JS_KEY6('<','e','v','a','l','>') -#define JS_KEY__var_ _JS_KEY5('<','v','a','r','>') +#define JS_KEY__ret_ _JS_KEY5 ('<', 'r', 'e', 't', '>') +#define JS_KEY__eval_ _JS_KEY6 ('<', 'e', 'v', 'a', 'l', '>') +#define JS_KEY__var_ _JS_KEY5 ('<', 'v', 'a', 'r', '>') -/* Keys for strings > 7 chars - these use string literals and are created at runtime. - The caller must free the returned JSValue if it's a heap string. */ -#define JS_KEY_STR(ctx, str) JS_NewStringLen((ctx), (str), sizeof(str) - 1) +/* Keys for strings > 7 chars - these use string literals and are created at + runtime. The caller must free the returned JSValue if it's a heap string. */ +#define JS_KEY_STR(ctx, str) JS_NewStringLen ((ctx), (str), sizeof (str) - 1) /* Buffer size for atom string conversion */ #define ATOM_GET_STR_BUF_SIZE 256 /* Convert JSValue key (string) to C string in buffer. Returns buf, filled with the string content or "[?]" if not a string. */ -static inline const char * -JS_KeyGetStr (JSContext *ctx, char *buf, size_t buf_size, JSValue key) { +static inline const char *JS_KeyGetStr (JSContext *ctx, char *buf, + size_t buf_size, JSValue key) { if (JS_IsString (key)) { const char *cstr = JS_ToCString (ctx, key); if (cstr) { @@ -317,7 +326,8 @@ JS_KeyGetStr (JSContext *ctx, char *buf, size_t buf_size, JSValue key) { } /* Stub: JS_AtomGetStr is deprecated - use JS_KeyGetStr */ -#define JS_AtomGetStr(ctx, buf, buf_size, key) JS_KeyGetStr(ctx, buf, buf_size, key) +#define JS_AtomGetStr(ctx, buf, buf_size, key) \ + JS_KeyGetStr (ctx, buf, buf_size, key) /* Property flags for legacy compatibility */ #define JS_PROP_VARREF (1 << 4) @@ -363,9 +373,10 @@ typedef struct JSPropertyEnum { #define JS_GPN_STRING_MASK 0 /* Stub: JS_GetOwnPropertyNamesInternal - legacy property enumeration */ -static inline int -JS_GetOwnPropertyNamesInternal (JSContext *ctx, JSPropertyEnum **ptab, - uint32_t *plen, void *obj, int flags) { +static inline int JS_GetOwnPropertyNamesInternal (JSContext *ctx, + JSPropertyEnum **ptab, + uint32_t *plen, void *obj, + int flags) { (void)ctx; (void)ptab; (void)plen; @@ -377,8 +388,8 @@ JS_GetOwnPropertyNamesInternal (JSContext *ctx, JSPropertyEnum **ptab, } /* Stub: JS_FreePropertyEnum - legacy property enumeration cleanup */ -static inline void -JS_FreePropertyEnum (JSContext *ctx, JSPropertyEnum *tab, uint32_t len) { +static inline void JS_FreePropertyEnum (JSContext *ctx, JSPropertyEnum *tab, + uint32_t len) { (void)ctx; (void)tab; (void)len; @@ -433,7 +444,8 @@ typedef struct JSObject JSObject; /* Forward declaration for bytecode freeing */ struct JSFunctionBytecode; -static void free_function_bytecode (JSRuntime *rt, struct JSFunctionBytecode *b); +static void free_function_bytecode (JSRuntime *rt, + struct JSFunctionBytecode *b); #define JS_VALUE_GET_OBJ(v) ((JSObject *)JS_VALUE_GET_PTR (v)) #define JS_VALUE_GET_STRING(v) ((JSString *)JS_VALUE_GET_PTR (v)) @@ -624,21 +636,14 @@ typedef uint64_t word_t; // one actor-memory word typedef uint64_t objhdr_t; // header word typedef uint64_t objref_t; // 56-bit word address (0 = null) -static inline uint8_t -objhdr_type (objhdr_t h) { - return (uint8_t)(h & 7u); -} -static inline bool -objhdr_s (objhdr_t h) { - return (h & OBJHDR_S_MASK) != 0; -} -static inline uint64_t -objhdr_cap56 (objhdr_t h) { +static inline uint8_t objhdr_type (objhdr_t h) { return (uint8_t)(h & 7u); } +static inline bool objhdr_s (objhdr_t h) { return (h & OBJHDR_S_MASK) != 0; } +static inline uint64_t objhdr_cap56 (objhdr_t h) { return (uint64_t)((h >> OBJHDR_CAP_SHIFT) & OBJHDR_CAP_MASK); } -static inline objhdr_t -objhdr_make (uint64_t cap56, uint8_t type, bool r, bool a, bool p, bool s) { +static inline objhdr_t objhdr_make (uint64_t cap56, uint8_t type, bool r, + bool a, bool p, bool s) { objhdr_t h = 0; h |= ((objhdr_t)(cap56 & OBJHDR_CAP_MASK)) << OBJHDR_CAP_SHIFT; h |= (objhdr_t)(type & 7u); @@ -689,16 +694,14 @@ typedef struct mist_text { word_t packed[]; // count = (cap + 1)/2 } mist_text; -static inline uint32_t -mist_string_get (const mist_text *t, int idx) { +static inline uint32_t mist_string_get (const mist_text *t, int idx) { int word_idx = idx / 2; int shift = (1 - (idx % 2)) * 32; /* high 32 (idx%2==0) then low 32 (idx%2==1) */ return (uint32_t)(t->packed[word_idx] >> shift); } -static inline void -mist_string_put (mist_text *t, int idx, uint32_t c) { +static inline void mist_string_put (mist_text *t, int idx, uint32_t c) { int word_idx = idx / 2; int shift = (1 - (idx % 2)) * 32; word_t mask = (word_t)0xFFFFFFFF << shift; @@ -732,20 +735,15 @@ typedef struct mist_record { /* ============================================================ Record key helpers (JSValue keys) ============================================================ */ -static inline JS_BOOL -rec_key_is_empty (JSValue key) { +static inline JS_BOOL rec_key_is_empty (JSValue key) { return JS_IsNull (key); } -static inline JS_BOOL -rec_key_is_tomb (JSValue key) { +static inline JS_BOOL rec_key_is_tomb (JSValue key) { return JS_IsException (key); } -static inline JSValue -rec_key_tomb (void) { - return JS_EXCEPTION; -} +static inline JSValue rec_key_tomb (void) { return JS_EXCEPTION; } typedef struct fash64_state { uint64_t result; @@ -758,8 +756,8 @@ enum { FASH64_PRIME_3 = 3333333333333333271ull }; -static inline void -fash64_mul_hi_lo (uint64_t a, uint64_t b, uint64_t *hi, uint64_t *lo) { +static inline void fash64_mul_hi_lo (uint64_t a, uint64_t b, uint64_t *hi, + uint64_t *lo) { #if defined(__SIZEOF_INT128__) __uint128_t p = (__uint128_t)a * (__uint128_t)b; *lo = (uint64_t)p; @@ -784,14 +782,12 @@ fash64_mul_hi_lo (uint64_t a, uint64_t b, uint64_t *hi, uint64_t *lo) { #endif } -static inline void -fash64_begin (fash64_state *s) { +static inline void fash64_begin (fash64_state *s) { s->result = (uint64_t)FASH64_PRIME_8; s->sum = (uint64_t)FASH64_PRIME_3; } -static inline void -fash64_word (fash64_state *s, uint64_t word) { +static inline void fash64_word (fash64_state *s, uint64_t word) { uint64_t high, low; uint64_t mixed = s->result ^ word; @@ -801,21 +797,18 @@ fash64_word (fash64_state *s, uint64_t word) { s->result = low ^ s->sum; } -static inline void -fash64_block (fash64_state *s, const uint64_t *block, size_t word_count) { +static inline void fash64_block (fash64_state *s, const uint64_t *block, + size_t word_count) { for (size_t i = 0; i < word_count; i++) fash64_word (s, block[i]); } -static inline uint64_t -fash64_end (const fash64_state *s) { - return s->result; -} +static inline uint64_t fash64_end (const fash64_state *s) { return s->result; } /* Convenience one-shot helper */ -static inline uint64_t -fash64_hash_words (const uint64_t *words, size_t word_count, - uint64_t extra_word) { +static inline uint64_t fash64_hash_words (const uint64_t *words, + size_t word_count, + uint64_t extra_word) { fash64_state s; fash64_begin (&s); fash64_block (&s, words, word_count); @@ -823,22 +816,20 @@ fash64_hash_words (const uint64_t *words, size_t word_count, return fash64_end (&s); } -static inline uint64_t -fash64_hash_one (uint64_t word) { +static inline uint64_t fash64_hash_one (uint64_t word) { fash64_state s; fash64_begin (&s); fash64_word (&s, word); return fash64_end (&s); } -static inline uint32_t -mist_text_len (const mist_text *text) { +static inline uint32_t mist_text_len (const mist_text *text) { if (objhdr_s (text->hdr)) return (uint32_t)objhdr_cap56 (text->hdr); return (uint32_t)text->length; } -static inline JS_BOOL -mist_text_equal (const mist_text *a, const mist_text *b) { +static inline JS_BOOL mist_text_equal (const mist_text *a, + const mist_text *b) { uint32_t len_a = mist_text_len (a); uint32_t len_b = mist_text_len (b); if (len_a != len_b) return FALSE; @@ -846,14 +837,14 @@ mist_text_equal (const mist_text *a, const mist_text *b) { return memcmp (a->packed, b->packed, word_count * sizeof (uint64_t)) == 0; } -static JS_BOOL -mist_text_equal_ascii (const mist_text *text, JSValue imm) { +static JS_BOOL mist_text_equal_ascii (const mist_text *text, JSValue imm) { int len = MIST_GetImmediateASCIILen (imm); if ((uint32_t)len != mist_text_len (text)) return FALSE; for (int i = 0; i < len; i++) { uint32_t c = mist_string_get (text, i); if (c >= 0x80) return FALSE; - if ((uint8_t)c != (uint8_t)MIST_GetImmediateASCIIChar (imm, i)) return FALSE; + if ((uint8_t)c != (uint8_t)MIST_GetImmediateASCIIChar (imm, i)) + return FALSE; } return TRUE; } @@ -861,8 +852,7 @@ mist_text_equal_ascii (const mist_text *text, JSValue imm) { /* Get hash for a mist_text value. For stoned text (s=1): hash is pre-computed in length field. For pre-text (s=0): compute hash on the fly. */ -static uint64_t -get_text_hash (mist_text *text) { +static uint64_t get_text_hash (mist_text *text) { if (objhdr_s (text->hdr)) { /* Stoned text: hash is stored in length field */ return text->length; @@ -875,8 +865,7 @@ get_text_hash (mist_text *text) { } /* Get hash for a JSValue if it's a text object */ -uint64_t -get_value_hash (JSValue val) { +uint64_t get_value_hash (JSValue val) { if (!JS_IsPtr (val)) return 0; mist_text *text = (mist_text *)JS_VALUE_GET_PTR (val); @@ -905,8 +894,8 @@ typedef struct StoneArenaPage { } StoneArenaPage; /* Pack UTF-32 characters into 64-bit words (2 chars per word) */ -static void -pack_utf32_to_words (const uint32_t *utf32, uint32_t len, uint64_t *packed) { +static void pack_utf32_to_words (const uint32_t *utf32, uint32_t len, + uint64_t *packed) { for (uint32_t i = 0; i < len; i += 2) { uint64_t hi = utf32[i]; uint64_t lo = (i + 1 < len) ? utf32[i + 1] : 0; @@ -915,8 +904,8 @@ pack_utf32_to_words (const uint32_t *utf32, uint32_t len, uint64_t *packed) { } /* Compare two packed UTF-32 texts for equality */ -static int -text_equal (mist_text *a, const uint64_t *packed_b, uint32_t len_b) { +static int text_equal (mist_text *a, const uint64_t *packed_b, + uint32_t len_b) { uint32_t len_a = (uint32_t)objhdr_cap56 (a->hdr); if (len_a != len_b) return 0; size_t word_count = (len_a + 1) / 2; @@ -930,7 +919,8 @@ text_equal (mist_text *a, const uint64_t *packed_b, uint32_t len_b) { static void *st_alloc (JSContext *ctx, size_t bytes, size_t align); static void st_free_all (JSContext *ctx); static int st_text_resize (JSContext *ctx); -static JSValue intern_text_to_value (JSContext *ctx, const uint32_t *utf32, uint32_t len); +static JSValue intern_text_to_value (JSContext *ctx, const uint32_t *utf32, + uint32_t len); static JSValue js_key_new (JSContext *ctx, const char *str); static JSValue js_key_new_len (JSContext *ctx, const char *str, size_t len); @@ -957,11 +947,12 @@ static uint32_t rc_log_i; static void rc_dump_atom (JSRuntime *rt, uint32_t atom); -static inline void -rc_log_event (JSGCObjectHeader *ptr, uint32_t tag, JSGCObjectHeader *parent, - uint32_t parent_type, int32_t parent_class_id, const char *edge, - uint32_t atom, int32_t prop_index, int32_t rb, int32_t ra, - const char *file, int line, const char *op) { +static inline void rc_log_event (JSGCObjectHeader *ptr, uint32_t tag, + JSGCObjectHeader *parent, + uint32_t parent_type, int32_t parent_class_id, + const char *edge, uint32_t atom, + int32_t prop_index, int32_t rb, int32_t ra, + const char *file, int line, const char *op) { RcEvent *e = &rc_log[rc_log_i++ & (RC_LOG_CAP - 1)]; e->ptr = ptr; e->tag = tag; @@ -978,16 +969,16 @@ rc_log_event (JSGCObjectHeader *ptr, uint32_t tag, JSGCObjectHeader *parent, e->op = op; } -static inline void -rc_trace_inc_gc (JSGCObjectHeader *p, const char *file, int line) { +static inline void rc_trace_inc_gc (JSGCObjectHeader *p, const char *file, + int line) { int32_t rb = p->ref_count; p->ref_count = rb + 1; rc_log_event (p, p->gc_obj_type, NULL, 0, -1, NULL, 0, -1, rb, p->ref_count, file, line, "++"); } -static inline void -rc_trace_dec_gc (JSGCObjectHeader *p, const char *file, int line) { +static inline void rc_trace_dec_gc (JSGCObjectHeader *p, const char *file, + int line) { int32_t rb = p->ref_count; p->ref_count = rb - 1; rc_log_event (p, p->gc_obj_type, NULL, 0, -1, NULL, 0, -1, rb, p->ref_count, @@ -1005,8 +996,7 @@ rc_trace_dec_gc_edge (JSGCObjectHeader *p, JSGCObjectHeader *parent, atom, prop_index, rb, p->ref_count, file, line, "--"); } -static void -rc_dump_history (JSGCObjectHeader *p, const char *why) { +static void rc_dump_history (JSGCObjectHeader *p, const char *why) { int count = 0; fprintf (stderr, "RC_TRACE: %s ptr=%p tag=%u ref=%d\n", why, (void *)p, (unsigned)p->gc_obj_type, p->ref_count); @@ -1087,8 +1077,7 @@ struct JSContext { int interrupt_counter; /* if NULL, RegExp compilation is not supported */ - JSValue (*compile_regexp) (JSContext *ctx, JSValue pattern, - JSValue flags); + JSValue (*compile_regexp) (JSContext *ctx, JSValue pattern, JSValue flags); /* if NULL, eval is not supported */ JSValue (*eval_internal) (JSContext *ctx, JSValue this_obj, const char *input, size_t input_len, @@ -1109,11 +1098,11 @@ struct JSContext { /* Stone arena for interned strings (per context) */ struct StoneArenaPage *st_pages; - struct mist_text **st_text_array; /* indexed by ID */ - uint32_t *st_text_hash; /* hash table mapping to IDs */ - uint32_t st_text_count; /* number of interned texts */ - uint32_t st_text_size; /* hash table size */ - uint32_t st_text_resize; /* threshold for resize */ + struct mist_text **st_text_array; /* indexed by ID */ + uint32_t *st_text_hash; /* hash table mapping to IDs */ + uint32_t st_text_count; /* number of interned texts */ + uint32_t st_text_size; /* hash table size */ + uint32_t st_text_resize; /* threshold for resize */ }; /* ============================================================ @@ -1122,8 +1111,7 @@ struct JSContext { /* Allocate bytes from the stone arena (bump allocator, never freed * individually) */ -static void * -st_alloc (JSContext *ctx, size_t bytes, size_t align) { +static void *st_alloc (JSContext *ctx, size_t bytes, size_t align) { JSRuntime *rt = ctx->rt; StoneArenaPage *page = ctx->st_pages; size_t offset; @@ -1155,8 +1143,7 @@ st_alloc (JSContext *ctx, size_t bytes, size_t align) { } /* Free all stone arena pages (called when freeing the context) */ -static void -st_free_all (JSContext *ctx) { +static void st_free_all (JSContext *ctx) { JSRuntime *rt = ctx->rt; StoneArenaPage *page = ctx->st_pages; while (page) { @@ -1168,8 +1155,7 @@ st_free_all (JSContext *ctx) { } /* Resize the stone text intern table */ -static int -st_text_resize (JSContext *ctx) { +static int st_text_resize (JSContext *ctx) { JSRuntime *rt = ctx->rt; uint32_t new_size = ctx->st_text_size ? ctx->st_text_size * 2 : 256; uint32_t new_mask = new_size - 1; @@ -1177,8 +1163,8 @@ st_text_resize (JSContext *ctx) { uint32_t *new_hash = js_mallocz_rt (rt, new_size * sizeof (uint32_t)); if (!new_hash) return -1; - mist_text **new_array = js_realloc_rt (rt, ctx->st_text_array, - (new_size + 1) * sizeof (mist_text *)); + mist_text **new_array = js_realloc_rt ( + rt, ctx->st_text_array, (new_size + 1) * sizeof (mist_text *)); if (!new_array) { js_free_rt (rt, new_hash); return -1; @@ -1207,8 +1193,8 @@ st_text_resize (JSContext *ctx) { } /* Intern a UTF-32 string as a stone text, returning a JSValue string */ -static JSValue -intern_text_to_value (JSContext *ctx, const uint32_t *utf32, uint32_t len) { +static JSValue intern_text_to_value (JSContext *ctx, const uint32_t *utf32, + uint32_t len) { /* Pack UTF-32 for hashing and comparison */ size_t word_count = (len + 1) / 2; uint64_t *packed = alloca (word_count * sizeof (uint64_t)); @@ -1261,11 +1247,10 @@ intern_text_to_value (JSContext *ctx, const uint32_t *utf32, uint32_t len) { } /* Create a stoned, interned key from a UTF-8 C string. - Returns immediate ASCII text if ≤7 ASCII chars, otherwise stoned interned text. - The returned JSValue does NOT need to be freed (it's either immediate or - part of the stone arena). */ -static JSValue -js_key_new (JSContext *ctx, const char *str) { + Returns immediate ASCII text if ≤7 ASCII chars, otherwise stoned interned + text. The returned JSValue does NOT need to be freed (it's either immediate + or part of the stone arena). */ +static JSValue js_key_new (JSContext *ctx, const char *str) { size_t len = strlen (str); /* Try immediate ASCII first (≤7 ASCII chars) */ @@ -1303,15 +1288,14 @@ js_key_new (JSContext *ctx, const char *str) { return intern_text_to_value (ctx, utf32_buf, utf32_len); } -/* JS_NewAtomString - creates JSValue string from C string (for compatibility) */ -static JSValue -JS_NewAtomString (JSContext *ctx, const char *str) { +/* JS_NewAtomString - creates JSValue string from C string (for compatibility) + */ +static JSValue JS_NewAtomString (JSContext *ctx, const char *str) { return js_key_new (ctx, str); } /* Create a key from a UTF-8 string with explicit length */ -static JSValue -js_key_new_len (JSContext *ctx, const char *str, size_t len) { +static JSValue js_key_new_len (JSContext *ctx, const char *str, size_t len) { /* Try immediate ASCII first (≤7 ASCII chars) */ if (len <= MIST_ASCII_MAX_LEN) { JSValue imm = MIST_TryNewImmediateASCII (str, len); @@ -1357,13 +1341,12 @@ struct JSString { JSRefCountHeader header; /* must come first, 32-bit */ uint32_t pad; /* align to 64-bit */ objhdr_t hdr; /* mist object header (64-bit) */ - int64_t len; /* length in characters (64-bit) */ // used for hash when stone - uint64_t u[]; /* packed UTF-32 characters */ + int64_t len; /* length in characters (64-bit) */ // used for hash when stone + uint64_t u[]; /* packed UTF-32 characters */ }; #ifdef RC_TRACE -static void -rc_dump_atom (JSRuntime *rt, uint32_t atom) { +static void rc_dump_atom (JSRuntime *rt, uint32_t atom) { /* stubbed for mist_text refactor */ fprintf (stderr, "RC_TRACE: atom=%u (stubbed)\n", atom); } @@ -1396,15 +1379,13 @@ typedef struct JSMistBase { } JSMistBase; /* Get mist type from a JSValue that points to a misty object */ -static inline uint8_t -JS_VALUE_GET_MIST_TYPE (JSValue v) { +static inline uint8_t JS_VALUE_GET_MIST_TYPE (JSValue v) { JSMistBase *p = (JSMistBase *)JS_VALUE_GET_PTR (v); return objhdr_type (p->mist_hdr); } /* Check if a JSValue points to a mist-based object (has mist_hdr) */ -static inline JS_BOOL -JS_VALUE_IS_MIST (JSValue v) { +static inline JS_BOOL JS_VALUE_IS_MIST (JSValue v) { if (JS_VALUE_GET_TAG (v) != JS_TAG_OBJECT) return FALSE; JSMistBase *p = (JSMistBase *)JS_VALUE_GET_PTR (v); uint8_t type = objhdr_type (p->mist_hdr); @@ -1413,8 +1394,7 @@ JS_VALUE_IS_MIST (JSValue v) { /* Get gc_obj_type from a JSValue that points to a GC object. Used to safely distinguish JSObject from JSArray/JSRecord before casting. */ -static inline JSGCObjectTypeEnum -js_gc_obj_type (JSValue v) { +static inline JSGCObjectTypeEnum js_gc_obj_type (JSValue v) { return ((JSGCObjectHeader *)JS_VALUE_GET_PTR (v))->gc_obj_type; } @@ -1430,14 +1410,12 @@ typedef struct JSArray { } JSArray; /* Helper to get array capacity from mist_hdr */ -static inline uint32_t -js_array_cap (JSArray *arr) { +static inline uint32_t js_array_cap (JSArray *arr) { return (uint32_t)objhdr_cap56 (arr->mist_hdr); } /* Helper to set array capacity in mist_hdr */ -static inline void -js_array_set_cap (JSArray *arr, uint32_t cap) { +static inline void js_array_set_cap (JSArray *arr, uint32_t cap) { arr->mist_hdr = objhdr_make (cap, OBJ_ARRAY, false, false, false, objhdr_s (arr->mist_hdr)); } @@ -1459,18 +1437,18 @@ typedef struct JSRecord { struct JSRecord *proto; /* prototype chain, NULL stops walk */ uint32_t len; /* number of live entries */ uint32_t tombs; /* number of tombstones */ - uint32_t rec_id; /* unique ID for record-key hashing */ + uint32_t rec_id; /* unique ID for record-key hashing */ JSRecordEntry *tab; /* size = (mask+1), index 0 reserved */ } JSRecord; #define JS_VALUE_GET_RECORD(v) ((JSRecord *)JS_VALUE_GET_PTR (v)) -/* Get prototype from object (works for both JSObject and JSRecord since they share layout) */ +/* Get prototype from object (works for both JSObject and JSRecord since they + * share layout) */ #define JS_OBJ_GET_PROTO(p) ((JSObject *)((JSRecord *)(p))->proto) /* Check if a JSValue is a JSRecord */ -static inline JS_BOOL -JS_VALUE_IS_RECORD (JSValue v) { +static inline JS_BOOL JS_VALUE_IS_RECORD (JSValue v) { if (JS_VALUE_GET_TAG (v) != JS_TAG_OBJECT) return FALSE; return ((JSGCObjectHeader *)JS_VALUE_GET_PTR (v))->gc_obj_type == JS_GC_OBJ_TYPE_RECORD; @@ -1479,8 +1457,7 @@ JS_VALUE_IS_RECORD (JSValue v) { /* 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) { +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; @@ -1491,8 +1468,7 @@ rec_tab_init (JSRecordEntry *tab, uint32_t mask) { JSRecord Core Operations ============================================================ */ -static uint64_t -js_key_hash (JSValue key) { +static uint64_t js_key_hash (JSValue key) { if (MIST_IsImmediateASCII (key)) return fash64_hash_one ((uint64_t)key); if (!JS_IsPtr (key)) return 0; @@ -1510,8 +1486,7 @@ js_key_hash (JSValue key) { return 0; } -static JS_BOOL -js_key_equal (JSValue a, JSValue b) { +static JS_BOOL js_key_equal (JSValue a, JSValue b) { if (a == b) return TRUE; if (MIST_IsImmediateASCII (a)) { @@ -1539,15 +1514,16 @@ js_key_equal (JSValue a, JSValue b) { if (ta != tb) return FALSE; if (ta == OBJ_RECORD) return FALSE; /* pointer equality handled above */ - if (ta == OBJ_TEXT) return mist_text_equal ((mist_text *)pa, (mist_text *)pb); + if (ta == OBJ_TEXT) + return mist_text_equal ((mist_text *)pa, (mist_text *)pb); return FALSE; } /* Compare a JSValue key with a C string literal. - Used for comparing with internal names that are too long for immediate ASCII. */ -static JS_BOOL -js_key_equal_str (JSValue a, const char *str) { + Used for comparing with internal names that are too long for immediate + ASCII. */ +static JS_BOOL js_key_equal_str (JSValue a, const char *str) { size_t len = strlen (str); if (MIST_IsImmediateASCII (a)) { @@ -1567,15 +1543,15 @@ js_key_equal_str (JSValue a, const char *str) { /* Compare character by character (UTF-32 vs ASCII) */ for (size_t i = 0; i < len; i++) { - if (mist_string_get (ta, i) != (uint32_t)(unsigned char)str[i]) return FALSE; + if (mist_string_get (ta, i) != (uint32_t)(unsigned char)str[i]) + return FALSE; } return TRUE; } /* Find slot for a key in record's own table. Returns slot index (>0) if found, or -(insert_slot) if not found. */ -static int -rec_find_slot (JSRecord *rec, JSValue k) { +static int rec_find_slot (JSRecord *rec, JSValue k) { uint32_t mask = (uint32_t)objhdr_cap56 (rec->mist_hdr); uint64_t h64 = js_key_hash (k); uint32_t slot = ((uint32_t)h64 & mask); @@ -1607,8 +1583,7 @@ rec_find_slot (JSRecord *rec, JSValue k) { } /* Get own property from record, returns JS_NULL if not found */ -static JSValue -rec_get_own (JSContext *ctx, JSRecord *rec, JSValue k) { +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; @@ -1619,8 +1594,7 @@ rec_get_own (JSContext *ctx, JSRecord *rec, JSValue k) { } /* Get property with proto chain lookup */ -static JSValue -rec_get (JSContext *ctx, JSRecord *rec, JSValue k) { +static JSValue rec_get (JSContext *ctx, JSRecord *rec, JSValue k) { if (rec_key_is_empty (k) || rec_key_is_tomb (k)) return JS_NULL; /* Walk prototype chain */ @@ -1634,8 +1608,7 @@ rec_get (JSContext *ctx, JSRecord *rec, JSValue k) { } /* Resize record table when load factor too high */ -static int -rec_resize (JSContext *ctx, JSRecord *rec, uint32_t new_mask) { +static int rec_resize (JSContext *ctx, JSRecord *rec, uint32_t new_mask) { uint32_t old_mask = (uint32_t)objhdr_cap56 (rec->mist_hdr); uint32_t new_size = new_mask + 1; @@ -1672,8 +1645,8 @@ rec_resize (JSContext *ctx, JSRecord *rec, uint32_t new_mask) { } /* Set own property on record, returns 0 on success, -1 on error */ -static int -rec_set_own (JSContext *ctx, JSRecord *rec, JSValue k, JSValue val) { +static int rec_set_own (JSContext *ctx, JSRecord *rec, JSValue k, + JSValue val) { if (rec_key_is_empty (k) || rec_key_is_tomb (k)) { JS_FreeValue (ctx, val); return -1; @@ -1712,8 +1685,7 @@ rec_set_own (JSContext *ctx, JSRecord *rec, JSValue k, JSValue val) { } /* Allocate a new record */ -static JSRecord * -js_new_record (JSContext *ctx, uint32_t initial_mask) { +static JSRecord *js_new_record (JSContext *ctx, uint32_t initial_mask) { JSRecord *rec; JSRuntime *rt = ctx->rt; @@ -1746,8 +1718,7 @@ js_new_record (JSContext *ctx, uint32_t initial_mask) { } /* Free a record's resources (called during GC) */ -static void -free_record (JSRuntime *rt, JSRecord *rec) { +static void free_record (JSRuntime *rt, JSRecord *rec) { uint32_t mask = (uint32_t)objhdr_cap56 (rec->mist_hdr); /* Free all values in the table */ @@ -1772,8 +1743,8 @@ typedef enum { typedef struct JSFunction { JSGCObjectHeader header; /* must come first */ - JSValue name; /* function name as JSValue text */ - uint16_t length; /* arity: max allowed arguments */ + JSValue name; /* function name as JSValue text */ + uint16_t length; /* arity: max allowed arguments */ uint8_t kind; uint8_t free_mark : 1; union { @@ -1797,8 +1768,7 @@ typedef struct JSFunction { /* Check if a JSValue is an intrinsic array (JS_TAG_OBJECT with OBJ_ARRAY mist * type) */ -static inline JS_BOOL -JS_VALUE_IS_INTRINSIC_ARRAY (JSValue v) { +static inline JS_BOOL JS_VALUE_IS_INTRINSIC_ARRAY (JSValue v) { if (JS_VALUE_GET_TAG (v) != JS_TAG_OBJECT) return FALSE; return JS_VALUE_GET_MIST_TYPE (v) == OBJ_ARRAY; } @@ -1877,8 +1847,8 @@ typedef struct JSFunctionBytecode { uint8_t func_kind : 2; uint8_t has_debug : 1; uint8_t read_only_bytecode : 1; - uint8_t - is_direct_or_indirect_eval : 1; /* used by JS_GetScriptOrModuleName() */ + uint8_t is_direct_or_indirect_eval + : 1; /* used by JS_GetScriptOrModuleName() */ /* XXX: 10 bits available */ uint8_t *byte_code_buf; /* (self pointer) */ int byte_code_len; @@ -1936,8 +1906,8 @@ typedef struct JSProperty { /* Stub: add_property - legacy shape-based property addition. Always returns NULL (failure) since shapes are removed. Code using this needs to be rewritten for JSRecord. */ -static inline JSProperty * -add_property (JSContext *ctx, JSObject *p, JSAtom atom, int flags) { +static inline JSProperty *add_property (JSContext *ctx, JSObject *p, + JSAtom atom, int flags) { (void)ctx; (void)p; (void)atom; @@ -2004,21 +1974,19 @@ enum OPCodeEnum { }; static JSValue js_call_c_function (JSContext *ctx, JSValue func_obj, - JSValue this_obj, int argc, - JSValue *argv); + JSValue this_obj, int argc, JSValue *argv); static JSValue js_call_bound_function (JSContext *ctx, JSValue func_obj, JSValue this_obj, int argc, JSValue *argv); static JSValue JS_CallInternal (JSContext *ctx, JSValue func_obj, JSValue this_obj, int argc, JSValue *argv, int flags); -static JSValue JS_CallFree (JSContext *ctx, JSValue func_obj, - JSValue this_obj, int argc, - JSValue *argv); +static JSValue JS_CallFree (JSContext *ctx, JSValue func_obj, JSValue this_obj, + int argc, JSValue *argv); static __exception int JS_ToArrayLengthFree (JSContext *ctx, uint32_t *plen, JSValue val, BOOL is_array_ctor); -static JSValue JS_EvalObject (JSContext *ctx, JSValue this_obj, - JSValue val, int flags, int scope_idx); +static JSValue JS_EvalObject (JSContext *ctx, JSValue this_obj, JSValue val, + int flags, int scope_idx); int JS_DeleteProperty (JSContext *ctx, JSValue obj, JSValue prop); JSValue __attribute__ ((format (printf, 2, 3))) JS_ThrowInternalError (JSContext *ctx, const char *fmt, ...); @@ -2034,8 +2002,8 @@ static __maybe_unused void JS_DumpValue (JSContext *ctx, const char *str, JSValue val); static __maybe_unused void JS_DumpShapes (JSRuntime *rt); 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 JSValue js_function_apply (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv, int magic); static void free_array (JSRuntime *rt, JSArray *arr); static void js_regexp_finalizer (JSRuntime *rt, JSValue val); static JSValue js_new_function (JSContext *ctx, JSFunctionKind kind); @@ -2045,9 +2013,9 @@ static void mark_function_children (JSRuntime *rt, JSFunction *func, static void mark_function_children_decref (JSRuntime *rt, JSFunction *func); #ifdef RC_TRACE static void gc_decref_child_dbg (JSRuntime *rt, JSGCObjectHeader *parent, - const char *edge, JSValue atom, int prop_index, - JSGCObjectHeader *child, const char *file, - int line); + const char *edge, JSValue atom, + int prop_index, JSGCObjectHeader *child, + const char *file, int line); #endif static void gc_decref_child (JSRuntime *rt, JSGCObjectHeader *p); @@ -2096,8 +2064,8 @@ static JSValue js_cell_push (JSContext *ctx, JSValue this_val, int argc, JSValue *argv); static JSValue js_cell_pop (JSContext *ctx, JSValue this_val, int argc, JSValue *argv); -static JSValue js_cell_array_find (JSContext *ctx, JSValue this_val, - int argc, JSValue *argv); +static JSValue js_cell_array_find (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv); JSValue JS_ThrowOutOfMemory (JSContext *ctx); static int js_string_memcmp (const JSString *p1, int pos1, const JSString *p2, int pos2, int len); @@ -2112,8 +2080,8 @@ static void free_var_ref (JSRuntime *rt, JSVarRef *var_ref); static int js_string_compare (JSContext *ctx, const JSString *p1, const JSString *p2); static JSValue JS_ToNumber (JSContext *ctx, JSValue val); -static int JS_SetPropertyValue (JSContext *ctx, JSValue this_obj, - JSValue prop, JSValue val); +static int JS_SetPropertyValue (JSContext *ctx, JSValue this_obj, JSValue prop, + JSValue val); static JSValue JS_ToNumberFree (JSContext *ctx, JSValue val); static int JS_GetOwnPropertyInternal (JSContext *ctx, JSPropertyDescriptor *desc, JSObject *p, @@ -2127,8 +2095,8 @@ static __exception int js_get_length64 (JSContext *ctx, int64_t *pres, static void free_arg_list (JSContext *ctx, JSValue *tab, uint32_t len); static JSValue *build_arg_list (JSContext *ctx, uint32_t *plen, JSValue array_arg); -static BOOL js_get_fast_array (JSContext *ctx, JSValue obj, - JSValue **arrpp, uint32_t *countp); +static BOOL js_get_fast_array (JSContext *ctx, JSValue obj, JSValue **arrpp, + uint32_t *countp); static JSValue js_c_function_data_call (JSContext *ctx, JSValue func_obj, JSValue this_val, int argc, JSValue *argv); @@ -2136,16 +2104,15 @@ static void add_gc_object (JSRuntime *rt, JSGCObjectHeader *h, JSGCObjectTypeEnum type); static void remove_gc_object (JSGCObjectHeader *h); static void JS_RunGCInternal (JSRuntime *rt); -static JSValue js_regexp_toString (JSContext *ctx, JSValue this_val, - int argc, JSValue *argv); +static JSValue js_regexp_toString (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv); -static JSValue js_error_toString (JSContext *ctx, JSValue this_val, - int argc, JSValue *argv); +static JSValue js_error_toString (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv); JSClassID js_class_id_alloc = JS_CLASS_INIT_COUNT; -static void -js_trigger_gc (JSRuntime *rt, size_t size) { +static void js_trigger_gc (JSRuntime *rt, size_t size) { BOOL force_gc; #ifdef FORCE_GC_AT_MALLOC force_gc = TRUE; @@ -2162,33 +2129,25 @@ js_trigger_gc (JSRuntime *rt, size_t size) { } } -static size_t -js_malloc_usable_size_unknown (const void *ptr) { - return 0; -} +static size_t js_malloc_usable_size_unknown (const void *ptr) { return 0; } -void * -js_malloc_rt (JSRuntime *rt, size_t size) { +void *js_malloc_rt (JSRuntime *rt, size_t size) { return rt->mf.js_malloc (&rt->malloc_state, size); } -void -js_free_rt (JSRuntime *rt, void *ptr) { +void js_free_rt (JSRuntime *rt, void *ptr) { rt->mf.js_free (&rt->malloc_state, ptr); } -void * -js_realloc_rt (JSRuntime *rt, void *ptr, size_t size) { +void *js_realloc_rt (JSRuntime *rt, void *ptr, size_t size) { return rt->mf.js_realloc (&rt->malloc_state, ptr, size); } -size_t -js_malloc_usable_size_rt (JSRuntime *rt, const void *ptr) { +size_t js_malloc_usable_size_rt (JSRuntime *rt, const void *ptr) { return rt->mf.js_malloc_usable_size (ptr); } -void * -js_mallocz_rt (JSRuntime *rt, size_t size) { +void *js_mallocz_rt (JSRuntime *rt, size_t size) { void *ptr; ptr = js_malloc_rt (rt, size); if (!ptr) return NULL; @@ -2196,8 +2155,7 @@ js_mallocz_rt (JSRuntime *rt, size_t size) { } /* Throw out of memory in case of error */ -void * -js_malloc (JSContext *ctx, size_t size) { +void *js_malloc (JSContext *ctx, size_t size) { void *ptr; ptr = js_malloc_rt (ctx->rt, size); if (unlikely (!ptr)) { @@ -2208,8 +2166,7 @@ js_malloc (JSContext *ctx, size_t size) { } /* Throw out of memory in case of error */ -void * -js_mallocz (JSContext *ctx, size_t size) { +void *js_mallocz (JSContext *ctx, size_t size) { void *ptr; ptr = js_mallocz_rt (ctx->rt, size); if (unlikely (!ptr)) { @@ -2219,14 +2176,10 @@ js_mallocz (JSContext *ctx, size_t size) { return ptr; } -void -js_free (JSContext *ctx, void *ptr) { - js_free_rt (ctx->rt, ptr); -} +void js_free (JSContext *ctx, void *ptr) { js_free_rt (ctx->rt, ptr); } /* Throw out of memory in case of error */ -void * -js_realloc (JSContext *ctx, void *ptr, size_t size) { +void *js_realloc (JSContext *ctx, void *ptr, size_t size) { void *ret; ret = js_realloc_rt (ctx->rt, ptr, size); if (unlikely (!ret && size != 0)) { @@ -2237,8 +2190,7 @@ js_realloc (JSContext *ctx, void *ptr, size_t size) { } /* store extra allocated size in *pslack if successful */ -void * -js_realloc2 (JSContext *ctx, void *ptr, size_t size, size_t *pslack) { +void *js_realloc2 (JSContext *ctx, void *ptr, size_t size, size_t *pslack) { void *ret; ret = js_realloc_rt (ctx->rt, ptr, size); if (unlikely (!ret && size != 0)) { @@ -2252,14 +2204,12 @@ js_realloc2 (JSContext *ctx, void *ptr, size_t size, size_t *pslack) { return ret; } -size_t -js_malloc_usable_size (JSContext *ctx, const void *ptr) { +size_t js_malloc_usable_size (JSContext *ctx, const void *ptr) { return js_malloc_usable_size_rt (ctx->rt, ptr); } /* Throw out of memory exception in case of error */ -char * -js_strndup (JSContext *ctx, const char *s, size_t n) { +char *js_strndup (JSContext *ctx, const char *s, size_t n) { char *ptr; ptr = js_malloc (ctx, n + 1); if (ptr) { @@ -2269,14 +2219,13 @@ js_strndup (JSContext *ctx, const char *s, size_t n) { return ptr; } -char * -js_strdup (JSContext *ctx, const char *str) { +char *js_strdup (JSContext *ctx, const char *str) { return js_strndup (ctx, str, strlen (str)); } -static no_inline int -js_realloc_array (JSContext *ctx, void **parray, int elem_size, int *psize, - int req_size) { +static no_inline int js_realloc_array (JSContext *ctx, void **parray, + int elem_size, int *psize, + int req_size) { int new_size; size_t slack; void *new_array; @@ -2291,34 +2240,27 @@ js_realloc_array (JSContext *ctx, void **parray, int elem_size, int *psize, } /* resize the array and update its size if req_size > *psize */ -static inline int -js_resize_array (JSContext *ctx, void **parray, int elem_size, int *psize, - int req_size) { +static inline int js_resize_array (JSContext *ctx, void **parray, + int elem_size, int *psize, int req_size) { if (unlikely (req_size > *psize)) return js_realloc_array (ctx, parray, elem_size, psize, req_size); else return 0; } -static inline void -js_dbuf_init (JSContext *ctx, DynBuf *s) { +static inline void js_dbuf_init (JSContext *ctx, DynBuf *s) { dbuf_init2 (s, ctx->rt, (DynBufReallocFunc *)js_realloc_rt); } -static inline int -is_digit (int c) { - return c >= '0' && c <= '9'; -} +static inline int is_digit (int c) { return c >= '0' && c <= '9'; } -static inline int -string_get (const JSString *p, int idx) { +static inline int string_get (const JSString *p, int idx) { int word_idx = idx >> 1; int shift = (1 - (idx & 1)) * 32; return (uint32_t)((p->u[word_idx] >> shift) & 0xFFFFFFFF); } -static inline void -string_put (JSString *p, int idx, uint32_t c) { +static inline void string_put (JSString *p, int idx, uint32_t c) { int word_idx = idx >> 1; int shift = (1 - (idx & 1)) * 32; uint64_t mask = 0xFFFFFFFFULL << shift; @@ -2326,8 +2268,7 @@ string_put (JSString *p, int idx, uint32_t c) { } /* Get character from any string value (immediate ASCII or JSString) */ -static inline uint32_t -js_string_value_get (JSValue v, int idx) { +static inline uint32_t js_string_value_get (JSValue v, int idx) { if (MIST_IsImmediateASCII (v)) { return MIST_GetImmediateASCIIChar (v, idx); } else { @@ -2337,8 +2278,7 @@ js_string_value_get (JSValue v, int idx) { } /* Get length from any string value */ -static inline int -js_string_value_len (JSValue v) { +static inline int js_string_value_len (JSValue v) { if (MIST_IsImmediateASCII (v)) { return MIST_GetImmediateASCIILen (v); } else { @@ -2350,10 +2290,9 @@ js_string_value_len (JSValue v) { /* Convert a JSValue string to a property key. For immediates, returns the value as-is (can be used directly as keys). For heap strings, returns interned version. */ -static JSValue -js_key_from_string (JSContext *ctx, JSValue val) { +static JSValue js_key_from_string (JSContext *ctx, JSValue val) { if (MIST_IsImmediateASCII (val)) { - return val; /* Immediates can be used directly as keys */ + return val; /* Immediates can be used directly as keys */ } if (JS_IsString (val)) { JSString *p = JS_VALUE_GET_STRING (val); @@ -2374,9 +2313,8 @@ static JSClass const js_std_class_def[] = { { "regexp", js_regexp_finalizer, NULL }, /* JS_CLASS_REGEXP */ }; -static int -init_class_range (JSRuntime *rt, JSClass const *tab, int start, - int count) { +static int init_class_range (JSRuntime *rt, JSClass const *tab, int start, + int count) { JSClassDef cm_s, *cm = &cm_s; int i, class_id; @@ -2392,32 +2330,27 @@ init_class_range (JSRuntime *rt, JSClass const *tab, int start, #if !defined(CONFIG_STACK_CHECK) /* no stack limitation */ -static inline uintptr_t -js_get_stack_pointer (void) { - return 0; -} +static inline uintptr_t js_get_stack_pointer (void) { return 0; } -static inline BOOL -js_check_stack_overflow (JSRuntime *rt, size_t alloca_size) { +static inline BOOL js_check_stack_overflow (JSRuntime *rt, + size_t alloca_size) { return FALSE; } #else /* Note: OS and CPU dependent */ -static inline uintptr_t -js_get_stack_pointer (void) { +static inline uintptr_t js_get_stack_pointer (void) { return (uintptr_t)__builtin_frame_address (0); } -static inline BOOL -js_check_stack_overflow (JSRuntime *rt, size_t alloca_size) { +static inline BOOL js_check_stack_overflow (JSRuntime *rt, + size_t alloca_size) { uintptr_t sp; sp = js_get_stack_pointer () - alloca_size; return unlikely (sp < rt->stack_limit); } #endif -JSRuntime * -JS_NewRuntime2 (const JSMallocFunctions *mf, void *opaque) { +JSRuntime *JS_NewRuntime2 (const JSMallocFunctions *mf, void *opaque) { JSRuntime *rt; JSMallocState ms; @@ -2473,19 +2406,14 @@ fail: return NULL; } -void * -JS_GetRuntimeOpaque (JSRuntime *rt) { - return rt->user_opaque; -} +void *JS_GetRuntimeOpaque (JSRuntime *rt) { return rt->user_opaque; } -void -JS_SetRuntimeOpaque (JSRuntime *rt, void *opaque) { +void JS_SetRuntimeOpaque (JSRuntime *rt, void *opaque) { rt->user_opaque = opaque; } /* default memory allocation functions with memory limitation */ -static size_t -js_def_malloc_usable_size (const void *ptr) { +static size_t js_def_malloc_usable_size (const void *ptr) { #if defined(__APPLE__) return malloc_size (ptr); #elif defined(_WIN32) @@ -2500,8 +2428,7 @@ js_def_malloc_usable_size (const void *ptr) { #endif } -static void * -js_def_malloc (JSMallocState *s, size_t size) { +static void *js_def_malloc (JSMallocState *s, size_t size) { void *ptr; /* Do not allocate zero bytes: behavior is platform dependent */ @@ -2517,8 +2444,7 @@ js_def_malloc (JSMallocState *s, size_t size) { return ptr; } -static void -js_def_free (JSMallocState *s, void *ptr) { +static void js_def_free (JSMallocState *s, void *ptr) { if (!ptr) return; s->malloc_count--; @@ -2526,8 +2452,7 @@ js_def_free (JSMallocState *s, void *ptr) { free (ptr); } -static void * -js_def_realloc (JSMallocState *s, void *ptr, size_t size) { +static void *js_def_realloc (JSMallocState *s, void *ptr, size_t size) { size_t old_size; if (!ptr) { @@ -2557,54 +2482,41 @@ static const JSMallocFunctions def_malloc_funcs = { js_def_malloc_usable_size, }; -JSRuntime * -JS_NewRuntime (void) { +JSRuntime *JS_NewRuntime (void) { return JS_NewRuntime2 (&def_malloc_funcs, NULL); } -void -JS_SetMemoryLimit (JSRuntime *rt, size_t limit) { +void JS_SetMemoryLimit (JSRuntime *rt, size_t limit) { rt->malloc_state.malloc_limit = limit; } /* use -1 to disable automatic GC */ -void -JS_SetGCThreshold (JSRuntime *rt, size_t gc_threshold) { +void JS_SetGCThreshold (JSRuntime *rt, size_t gc_threshold) { rt->malloc_gc_threshold = gc_threshold; } /* Helper to call system free (for memory allocated by external libs like * blob.h) */ -static void -sys_free (void *ptr) { - free (ptr); -} +static void sys_free (void *ptr) { free (ptr); } #define malloc(s) malloc_is_forbidden (s) #define free(p) free_is_forbidden (p) #define realloc(p, s) realloc_is_forbidden (p, s) -void -JS_SetInterruptHandler (JSRuntime *rt, JSInterruptHandler *cb, void *opaque) { +void JS_SetInterruptHandler (JSRuntime *rt, JSInterruptHandler *cb, + void *opaque) { rt->interrupt_handler = cb; rt->interrupt_opaque = opaque; } -void -JS_SetStripInfo (JSRuntime *rt, int flags) { - rt->strip_flags = flags; -} +void JS_SetStripInfo (JSRuntime *rt, int flags) { rt->strip_flags = flags; } -int -JS_GetStripInfo (JSRuntime *rt) { - return rt->strip_flags; -} +int JS_GetStripInfo (JSRuntime *rt) { return rt->strip_flags; } /* atom_get_free/is_free/set_free removed */ /* Note: the string contents are uninitialized */ -static JSString * -js_alloc_string_rt (JSRuntime *rt, int max_len) { +static JSString *js_alloc_string_rt (JSRuntime *rt, int max_len) { JSString *str; size_t size; /* Allocate packed UTF-32: 2 chars per 64-bit word. @@ -2631,8 +2543,7 @@ js_alloc_string_rt (JSRuntime *rt, int max_len) { return str; } -static JSString * -js_alloc_string (JSContext *ctx, int max_len) { +static JSString *js_alloc_string (JSContext *ctx, int max_len) { JSString *p; p = js_alloc_string_rt (ctx->rt, max_len); if (unlikely (!p)) { @@ -2643,12 +2554,11 @@ js_alloc_string (JSContext *ctx, int max_len) { } /* same as JS_FreeValueRT() but faster */ -static inline void -js_free_string (JSRuntime *rt, JSString *str) { +static inline void js_free_string (JSRuntime *rt, JSString *str) { if (--str->header.ref_count <= 0) { - #ifdef DUMP_LEAKS +#ifdef DUMP_LEAKS list_del (&str->link); - #endif +#endif js_free_rt (rt, str); } } @@ -2657,14 +2567,13 @@ static inline void JS_MarkValueEdgeEx (JSRuntime *rt, JSValue val, JSGCObjectHeader *parent, const char *edge, uint32_t atom, int32_t prop_index); -static inline void -JS_MarkValueEdge (JSRuntime *rt, JSValue val, JSGCObjectHeader *parent, - const char *edge) { +static inline void JS_MarkValueEdge (JSRuntime *rt, JSValue val, + JSGCObjectHeader *parent, + const char *edge) { JS_MarkValueEdgeEx (rt, val, parent, edge, 0, -1); } -void -JS_SetRuntimeInfo (JSRuntime *rt, const char *s) { +void JS_SetRuntimeInfo (JSRuntime *rt, const char *s) { if (rt) rt->rt_info = s; } @@ -2862,7 +2771,8 @@ void JS_FreeRuntime (JSRuntime *rt) { } #endif - /* Stone text tables and arena are now per-context, freed in JS_FreeContext */ + /* Stone text tables and arena are now per-context, freed in JS_FreeContext + */ { JSMallocState ms = rt->malloc_state; @@ -2870,8 +2780,7 @@ void JS_FreeRuntime (JSRuntime *rt) { } } -JSContext * -JS_NewContextRaw (JSRuntime *rt) { +JSContext *JS_NewContextRaw (JSRuntime *rt) { assert (!rt->js); JSContext *ctx; int i; @@ -2938,8 +2847,7 @@ JS_NewContextRaw (JSRuntime *rt) { return ctx; } -JSContext * -JS_NewContext (JSRuntime *rt) { +JSContext *JS_NewContext (JSRuntime *rt) { JSContext *ctx; ctx = JS_NewContextRaw (rt); @@ -2952,49 +2860,41 @@ JS_NewContext (JSRuntime *rt) { return ctx; } -void * -JS_GetContextOpaque (JSContext *ctx) { - return ctx->user_opaque; -} +void *JS_GetContextOpaque (JSContext *ctx) { return ctx->user_opaque; } -void -JS_SetContextOpaque (JSContext *ctx, void *opaque) { +void JS_SetContextOpaque (JSContext *ctx, void *opaque) { ctx->user_opaque = 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) { +static inline void set_value (JSContext *ctx, JSValue *pval, JSValue new_val) { JSValue old_val; old_val = *pval; *pval = new_val; JS_FreeValue (ctx, old_val); } -void -JS_SetClassProto (JSContext *ctx, JSClassID class_id, JSValue obj) { +void JS_SetClassProto (JSContext *ctx, JSClassID class_id, JSValue obj) { JSRuntime *rt = ctx->rt; assert (class_id < rt->class_count); set_value (ctx, &ctx->class_proto[class_id], obj); } -JSValue -JS_GetClassProto (JSContext *ctx, JSClassID class_id) { +JSValue JS_GetClassProto (JSContext *ctx, JSClassID class_id) { JSRuntime *rt = ctx->rt; assert (class_id < rt->class_count); return JS_DupValue (ctx, ctx->class_proto[class_id]); } -JSContext * -JS_DupContext (JSContext *ctx) { +JSContext *JS_DupContext (JSContext *ctx) { ctx->header.ref_count++; return ctx; } /* used by the GC */ -static void -JS_MarkContext (JSRuntime *rt, JSContext *ctx, JS_MarkFunc *mark_func) { +static void JS_MarkContext (JSRuntime *rt, JSContext *ctx, + JS_MarkFunc *mark_func) { int i; JS_MarkValue (rt, ctx->global_obj, mark_func); @@ -3014,8 +2914,7 @@ JS_MarkContext (JSRuntime *rt, JSContext *ctx, JS_MarkFunc *mark_func) { JS_MarkValue (rt, ctx->regexp_ctor, mark_func); } -void -JS_FreeContext (JSContext *ctx) { +void JS_FreeContext (JSContext *ctx) { JSRuntime *rt = ctx->rt; int i; @@ -3080,13 +2979,9 @@ JS_FreeContext (JSContext *ctx) { js_free_rt (ctx->rt, ctx); } -JSRuntime * -JS_GetRuntime (JSContext *ctx) { - return ctx->rt; -} +JSRuntime *JS_GetRuntime (JSContext *ctx) { return ctx->rt; } -static void -update_stack_limit (JSRuntime *rt) { +static void update_stack_limit (JSRuntime *rt) { if (rt->stack_size == 0) { rt->stack_limit = 0; /* no limit */ } else { @@ -3094,14 +2989,12 @@ update_stack_limit (JSRuntime *rt) { } } -void -JS_SetMaxStackSize (JSRuntime *rt, size_t stack_size) { +void JS_SetMaxStackSize (JSRuntime *rt, size_t stack_size) { rt->stack_size = stack_size; update_stack_limit (rt); } -void -JS_UpdateStackTop (JSRuntime *rt) { +void JS_UpdateStackTop (JSRuntime *rt) { rt->stack_top = js_get_stack_pointer (); update_stack_limit (rt); } @@ -3111,14 +3004,10 @@ static JSString *js_alloc_string (JSContext *ctx, int max_len); /* return the max count from the hash size */ #define JS_ATOM_COUNT_RESIZE(n) ((n) * 2) -static inline int -is_num (int c) { - return c >= '0' && c <= '9'; -} +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 JSString *p) { +static inline BOOL is_num_string (uint32_t *pval, const JSString *p) { uint32_t n; uint64_t n64; int c, i, len; @@ -3148,8 +3037,8 @@ is_num_string (uint32_t *pval, const JSString *p) { } /* XXX: could use faster version ? */ -static inline uint32_t -hash_string8 (const uint8_t *str, size_t len, uint32_t h) { +static inline uint32_t hash_string8 (const uint8_t *str, size_t len, + uint32_t h) { size_t i; for (i = 0; i < len; i++) @@ -3157,8 +3046,7 @@ hash_string8 (const uint8_t *str, size_t len, uint32_t h) { return h; } -static uint32_t -hash_string (const JSString *str, uint32_t h) { +static uint32_t hash_string (const JSString *str, uint32_t h) { /* hash_string32 inlined and adapted */ size_t i; for (i = 0; i < str->len; i++) { @@ -3169,8 +3057,7 @@ hash_string (const JSString *str, uint32_t h) { /* hash_string_rope deleted */ -static __maybe_unused void -JS_DumpChar (FILE *fo, int c, int sep) { +static __maybe_unused void JS_DumpChar (FILE *fo, int c, int sep) { if (c == sep || c == '\\') { fputc ('\\', fo); fputc (c, fo); @@ -3184,8 +3071,7 @@ JS_DumpChar (FILE *fo, int c, int sep) { } } -static __maybe_unused void -JS_DumpString (JSRuntime *rt, const JSString *p) { +static __maybe_unused void JS_DumpString (JSRuntime *rt, const JSString *p) { int i, sep; if (p == NULL) { @@ -3209,8 +3095,8 @@ static inline uint32_t objkey_hash (JSObject *key_obj) { If found is set to TRUE, the key exists at that slot. If found is FALSE, the slot is either empty (JS_TAG_NULL) or a tombstone (JS_TAG_UNINITIALIZED) and can be used for insertion. */ -static uint32_t objkey_find_slot (JSValue *tab, uint32_t size, JSObject *key_obj, - BOOL *found) { +static uint32_t objkey_find_slot (JSValue *tab, uint32_t size, + JSObject *key_obj, BOOL *found) { uint32_t mask = size - 1; uint32_t h = objkey_hash (key_obj) & mask; uint32_t i = h * 2; /* key at even index, value at odd */ @@ -3238,8 +3124,8 @@ static uint32_t objkey_find_slot (JSValue *tab, uint32_t size, JSObject *key_obj } /* Get value for object key from this object only (no prototype chain) */ -static JSValue -js_get_objkey_own (JSContext *ctx, JSObject *p, JSObject *key_obj) { +static JSValue js_get_objkey_own (JSContext *ctx, JSObject *p, + JSObject *key_obj) { if (p->objkey_size == 0) return JS_UNINITIALIZED; /* Not found marker */ BOOL found; @@ -3250,8 +3136,8 @@ js_get_objkey_own (JSContext *ctx, JSObject *p, JSObject *key_obj) { } /* Get value for object key, walking prototype chain */ -static JSValue -js_get_objkey_proto (JSContext *ctx, JSObject *p, JSObject *key_obj) { +static JSValue js_get_objkey_proto (JSContext *ctx, JSObject *p, + JSObject *key_obj) { for (;;) { JSValue val = js_get_objkey_own (ctx, p, key_obj); if (!JS_IsUninitialized (val)) return val; @@ -3263,8 +3149,7 @@ js_get_objkey_proto (JSContext *ctx, JSObject *p, JSObject *key_obj) { } /* Resize objkey table */ -static int -objkey_resize (JSContext *ctx, JSObject *p, uint32_t new_size) { +static int objkey_resize (JSContext *ctx, JSObject *p, uint32_t new_size) { JSValue *new_tab = js_mallocz (ctx, new_size * 2 * sizeof (JSValue)); if (!new_tab) return -1; @@ -3295,9 +3180,8 @@ objkey_resize (JSContext *ctx, JSObject *p, uint32_t new_size) { } /* Set value for object key on this object. Returns -1 on error. */ -static int -js_set_objkey_own (JSContext *ctx, JSObject *p, JSObject *key_obj, - JSValue val) { +static int js_set_objkey_own (JSContext *ctx, JSObject *p, JSObject *key_obj, + JSValue val) { if (p->stone) { JS_FreeValue (ctx, val); JS_ThrowTypeError (ctx, "cannot modify frozen object"); @@ -3337,8 +3221,7 @@ js_set_objkey_own (JSContext *ctx, JSObject *p, JSObject *key_obj, /* Delete object key from this object. Returns TRUE if deleted, FALSE if not * found, -1 on error. */ -static int -js_del_objkey_own (JSContext *ctx, JSObject *p, JSObject *key_obj) { +static int js_del_objkey_own (JSContext *ctx, JSObject *p, JSObject *key_obj) { if (p->objkey_size == 0) return FALSE; if (p->stone) { @@ -3362,8 +3245,7 @@ js_del_objkey_own (JSContext *ctx, JSObject *p, JSObject *key_obj) { } /* Check if object has object key (own property only) */ -static BOOL -js_has_objkey_own (JSObject *p, JSObject *key_obj) { +static BOOL js_has_objkey_own (JSObject *p, JSObject *key_obj) { if (p->objkey_size == 0) return FALSE; BOOL found; objkey_find_slot (p->objkey_tab, p->objkey_size, key_obj, &found); @@ -3371,8 +3253,7 @@ js_has_objkey_own (JSObject *p, JSObject *key_obj) { } /* Check if object has object key (including prototype chain) */ -static BOOL -js_has_objkey_proto (JSObject *p, JSObject *key_obj) { +static BOOL js_has_objkey_proto (JSObject *p, JSObject *key_obj) { for (;;) { if (js_has_objkey_own (p, key_obj)) return TRUE; /* Walk prototype chain via JSRecord */ @@ -3382,8 +3263,7 @@ js_has_objkey_proto (JSObject *p, JSObject *key_obj) { } } -static inline BOOL -JS_IsEmptyString (JSValue v) { +static inline BOOL JS_IsEmptyString (JSValue v) { return JS_VALUE_GET_TAG (v) == JS_TAG_STRING && JS_VALUE_GET_STRING (v)->len == 0; } @@ -3391,8 +3271,7 @@ JS_IsEmptyString (JSValue v) { /* JSClass support */ /* a new class ID is allocated if *pclass_id != 0 */ -JSClassID -JS_NewClassID (JSClassID *pclass_id) { +JSClassID JS_NewClassID (JSClassID *pclass_id) { JSClassID class_id; class_id = *pclass_id; if (class_id == 0) { @@ -3402,24 +3281,22 @@ JS_NewClassID (JSClassID *pclass_id) { return class_id; } -JSClassID -JS_GetClassID (JSValue v) { +JSClassID JS_GetClassID (JSValue v) { JSObject *p; if (JS_VALUE_GET_TAG (v) != JS_TAG_OBJECT) return JS_INVALID_CLASS_ID; p = JS_VALUE_GET_OBJ (v); return p->class_id; } -BOOL -JS_IsRegisteredClass (JSRuntime *rt, JSClassID class_id) { +BOOL JS_IsRegisteredClass (JSRuntime *rt, JSClassID class_id) { return (class_id < rt->class_count && rt->class_array[class_id].class_id != 0); } /* 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) { +static int JS_NewClass1 (JSRuntime *rt, JSClassID class_id, + const JSClassDef *class_def, const char *name) { int new_size, i; JSClass *cl, *new_class_array; struct list_head *el; @@ -3457,25 +3334,23 @@ JS_NewClass1 (JSRuntime *rt, JSClassID class_id, const JSClassDef *class_def, co cl->class_name = name; /* name is already a const char* */ cl->finalizer = class_def->finalizer; cl->gc_mark = class_def->gc_mark; - /* call field removed from JSClass - use class_def->call directly if needed */ + /* call field removed from JSClass - use class_def->call directly if needed + */ return 0; } -int -JS_NewClass (JSRuntime *rt, JSClassID class_id, const JSClassDef *class_def) { +int JS_NewClass (JSRuntime *rt, JSClassID class_id, + const JSClassDef *class_def) { /* class_name is stored directly as const char* */ return JS_NewClass1 (rt, class_id, class_def, class_def->class_name); } -static JSValue -js_new_string8_len (JSContext *ctx, const char *buf, int len) { +static JSValue js_new_string8_len (JSContext *ctx, const char *buf, int len) { JSString *str; int i; /* Empty string - return immediate empty */ - if (len <= 0) { - return MIST_TryNewImmediateASCII ("", 0); - } + if (len <= 0) { return MIST_TryNewImmediateASCII ("", 0); } /* Try immediate ASCII for short strings (≤7 chars) */ if (len <= MIST_ASCII_MAX_LEN) { @@ -3491,13 +3366,12 @@ js_new_string8_len (JSContext *ctx, const char *buf, int len) { return JS_MKPTR (JS_TAG_STRING, str); } -static JSValue -js_new_string8 (JSContext *ctx, const char *buf) { +static JSValue js_new_string8 (JSContext *ctx, const char *buf) { return js_new_string8_len (ctx, buf, strlen (buf)); } -static JSValue -js_new_string16_len (JSContext *ctx, const uint16_t *buf, int len) { +static JSValue js_new_string16_len (JSContext *ctx, const uint16_t *buf, + int len) { JSString *str; int i; str = js_alloc_string (ctx, len); @@ -3507,8 +3381,7 @@ js_new_string16_len (JSContext *ctx, const uint16_t *buf, int len) { return JS_MKPTR (JS_TAG_STRING, str); } -static JSValue -js_new_string_char (JSContext *ctx, uint16_t c) { +static JSValue js_new_string_char (JSContext *ctx, uint16_t c) { if (c < 0x100) { uint8_t ch8 = c; return js_new_string8_len (ctx, (const char *)&ch8, 1); @@ -3518,8 +3391,8 @@ js_new_string_char (JSContext *ctx, uint16_t c) { } } -static JSValue -js_sub_string (JSContext *ctx, JSString *p, int start, int end) { +static JSValue js_sub_string (JSContext *ctx, JSString *p, int start, + int end) { int i; int len = end - start; if (start == 0 && end == p->len) { @@ -3545,8 +3418,8 @@ typedef struct StringBuffer { if string_buffer_init() or another string_buffer function returns an error. If the error_status is set, string_buffer_end() returns JS_EXCEPTION. */ -static int -string_buffer_init2 (JSContext *ctx, StringBuffer *s, int size, int is_wide) { +static int string_buffer_init2 (JSContext *ctx, StringBuffer *s, int size, + int is_wide) { s->ctx = ctx; s->size = size; s->len = 0; @@ -3564,19 +3437,17 @@ string_buffer_init2 (JSContext *ctx, StringBuffer *s, int size, int is_wide) { return 0; } -static inline int -string_buffer_init (JSContext *ctx, StringBuffer *s, int size) { +static inline int string_buffer_init (JSContext *ctx, StringBuffer *s, + int size) { return string_buffer_init2 (ctx, s, size, 0); } -static void -string_buffer_free (StringBuffer *s) { +static void string_buffer_free (StringBuffer *s) { js_free (s->ctx, s->str); s->str = NULL; } -static int -string_buffer_set_error (StringBuffer *s) { +static int string_buffer_set_error (StringBuffer *s) { js_free (s->ctx, s->str); s->str = NULL; s->size = 0; @@ -3586,8 +3457,8 @@ string_buffer_set_error (StringBuffer *s) { /* string_buffer_widen removed */ -static no_inline int -string_buffer_realloc (StringBuffer *s, int new_len, int c) { +static no_inline int string_buffer_realloc (StringBuffer *s, int new_len, + int c) { JSString *new_str; int new_size; size_t new_size_bytes, slack; @@ -3601,17 +3472,18 @@ string_buffer_realloc (StringBuffer *s, int new_len, int c) { new_size = min_int (max_int (new_len, s->size * 3 / 2), JS_STRING_LEN_MAX); /* JSString stores UTF-32 packed into uint64_t (2 chars per word). */ - new_size_bytes = sizeof (JSString) + ((new_size + 1) / 2) * sizeof (uint64_t); + new_size_bytes + = sizeof (JSString) + ((new_size + 1) / 2) * sizeof (uint64_t); new_str = js_realloc2 (s->ctx, s->str, new_size_bytes, &slack); if (!new_str) return string_buffer_set_error (s); - new_size = min_int (new_size + (slack / sizeof (uint64_t)) * 2, JS_STRING_LEN_MAX); + new_size + = min_int (new_size + (slack / sizeof (uint64_t)) * 2, JS_STRING_LEN_MAX); s->size = new_size; s->str = new_str; return 0; } -static no_inline int -string_buffer_putc_slow (StringBuffer *s, uint32_t c) { +static no_inline int string_buffer_putc_slow (StringBuffer *s, uint32_t c) { if (unlikely (s->len >= s->size)) { if (string_buffer_realloc (s, s->len + 1, c)) return -1; } @@ -3620,8 +3492,7 @@ string_buffer_putc_slow (StringBuffer *s, uint32_t c) { } /* 0 <= c <= 0xff */ -static int -string_buffer_putc8 (StringBuffer *s, uint32_t c) { +static int string_buffer_putc8 (StringBuffer *s, uint32_t c) { if (unlikely (s->len >= s->size)) { if (string_buffer_realloc (s, s->len + 1, c)) return -1; } @@ -3630,8 +3501,7 @@ string_buffer_putc8 (StringBuffer *s, uint32_t c) { } /* 0 <= c <= 0xffff */ -static int -string_buffer_putc16 (StringBuffer *s, uint32_t c) { +static int string_buffer_putc16 (StringBuffer *s, uint32_t c) { if (likely (s->len < s->size)) { string_put (s->str, s->len++, c); return 0; @@ -3640,8 +3510,7 @@ string_buffer_putc16 (StringBuffer *s, uint32_t c) { } /* 0 <= c <= 0x10ffff */ -static int -string_buffer_putc (StringBuffer *s, uint32_t c) { +static int string_buffer_putc (StringBuffer *s, uint32_t c) { if (unlikely (c >= 0x10000)) { /* surrogate pair */ if (string_buffer_putc16 (s, get_hi_surrogate (c))) return -1; @@ -3650,8 +3519,8 @@ string_buffer_putc (StringBuffer *s, uint32_t c) { return string_buffer_putc16 (s, c); } -static int -string_buffer_write32 (StringBuffer *s, const uint32_t *p, int len) { +static int string_buffer_write32 (StringBuffer *s, const uint32_t *p, + int len) { int i; if (s->len + len > s->size) { if (string_buffer_realloc (s, s->len + len, 0)) return -1; @@ -3663,8 +3532,7 @@ string_buffer_write32 (StringBuffer *s, const uint32_t *p, int len) { return 0; } -static int -string_getc (const JSString *p, int *pidx) { +static int string_getc (const JSString *p, int *pidx) { int idx, c, c1; idx = *pidx; c = string_get (p, idx++); @@ -3679,8 +3547,7 @@ string_getc (const JSString *p, int *pidx) { return c; } -static int -string_buffer_write8 (StringBuffer *s, const uint8_t *p, int len) { +static int string_buffer_write8 (StringBuffer *s, const uint8_t *p, int len) { int i; if (s->len + len > s->size) { @@ -3693,8 +3560,8 @@ string_buffer_write8 (StringBuffer *s, const uint8_t *p, int len) { return 0; } -static int -string_buffer_write16 (StringBuffer *s, const uint16_t *p, int len) { +static int string_buffer_write16 (StringBuffer *s, const uint16_t *p, + int len) { int i; if (s->len + len > s->size) { @@ -3708,14 +3575,12 @@ string_buffer_write16 (StringBuffer *s, const uint16_t *p, int len) { } /* appending an ASCII string */ -static int -string_buffer_puts8 (StringBuffer *s, const char *str) { +static int string_buffer_puts8 (StringBuffer *s, const char *str) { return string_buffer_write8 (s, (const uint8_t *)str, strlen (str)); } -static int -string_buffer_concat (StringBuffer *s, const JSString *p, uint32_t from, - uint32_t to) { +static int string_buffer_concat (StringBuffer *s, const JSString *p, + uint32_t from, uint32_t to) { if (to <= from) return 0; int len = (int)(to - from); if (s->len + len > s->size) { @@ -3728,8 +3593,7 @@ string_buffer_concat (StringBuffer *s, const JSString *p, uint32_t from, return 0; } -static int -string_buffer_concat_value (StringBuffer *s, JSValue v) { +static int string_buffer_concat_value (StringBuffer *s, JSValue v) { if (MIST_IsImmediateASCII (v)) { int len = MIST_GetImmediateASCIILen (v); char buf[8]; @@ -3760,8 +3624,7 @@ string_buffer_concat_value (StringBuffer *s, JSValue v) { return res; } -static int -string_buffer_concat_value_free (StringBuffer *s, JSValue v) { +static int string_buffer_concat_value_free (StringBuffer *s, JSValue v) { JSString *p; int res; @@ -3780,8 +3643,7 @@ string_buffer_concat_value_free (StringBuffer *s, JSValue v) { return res; } -static int -string_buffer_fill (StringBuffer *s, int c, int count) { +static int string_buffer_fill (StringBuffer *s, int c, int count) { /* XXX: optimize */ if (s->len + count > s->size) { if (string_buffer_realloc (s, s->len + count, c)) return -1; @@ -3792,8 +3654,7 @@ string_buffer_fill (StringBuffer *s, int c, int count) { return 0; } -static JSValue -string_buffer_end (StringBuffer *s) { +static JSValue string_buffer_end (StringBuffer *s) { JSString *str; str = s->str; if (s->error_status) return JS_EXCEPTION; @@ -3822,8 +3683,7 @@ string_buffer_end (StringBuffer *s) { } /* Count leading ASCII characters in buffer */ -static size_t -count_ascii (const uint8_t *buf, size_t len) { +static size_t count_ascii (const uint8_t *buf, size_t len) { size_t i; for (i = 0; i < len && buf[i] < 128; i++) ; @@ -3831,8 +3691,7 @@ count_ascii (const uint8_t *buf, size_t len) { } /* create a string from a UTF-8 buffer */ -JSValue -JS_NewStringLen (JSContext *ctx, const char *buf, size_t buf_len) { +JSValue JS_NewStringLen (JSContext *ctx, const char *buf, size_t buf_len) { const uint8_t *p, *p_end, *p_start, *p_next; uint32_t c; StringBuffer b_s, *b = &b_s; @@ -3887,9 +3746,8 @@ fail: return JS_EXCEPTION; } -static JSValue -JS_ConcatString3 (JSContext *ctx, const char *str1, JSValue str2, - const char *str3) { +static JSValue JS_ConcatString3 (JSContext *ctx, const char *str1, + JSValue str2, const char *str3) { StringBuffer b_s, *b = &b_s; int len1, len3; JSString *p; @@ -3902,8 +3760,7 @@ JS_ConcatString3 (JSContext *ctx, const char *str1, JSValue str2, len1 = strlen (str1); len3 = strlen (str3); - if (string_buffer_init (ctx, b, len1 + p->len + len3)) - goto fail; + if (string_buffer_init (ctx, b, len1 + p->len + len3)) goto fail; string_buffer_write8 (b, (const uint8_t *)str1, len1); string_buffer_concat (b, p, 0, p->len); @@ -3921,9 +3778,8 @@ fail: /* return pointer into a JSString with a live ref_count */ /* cesu8 determines if non-BMP1 codepoints are encoded as 1 or 2 utf-8 * sequences */ -const char * -JS_ToCStringLen2 (JSContext *ctx, size_t *plen, JSValue val1, - BOOL cesu8) { +const char *JS_ToCStringLen2 (JSContext *ctx, size_t *plen, JSValue val1, + BOOL cesu8) { JSValue val; JSString *str; char *q, *ret; @@ -3975,14 +3831,13 @@ fail: return NULL; } -void -JS_FreeCString (JSContext *ctx, const char *ptr) { +void JS_FreeCString (JSContext *ctx, const char *ptr) { js_free (ctx, (void *)ptr); } /* return < 0, 0 or > 0 */ -static int -js_string_compare (JSContext *ctx, const JSString *p1, const JSString *p2) { +static int js_string_compare (JSContext *ctx, const JSString *p1, + const JSString *p2) { int res, len, i; len = min_int (p1->len, p2->len); for (i = 0; i < len; i++) { @@ -3994,8 +3849,8 @@ js_string_compare (JSContext *ctx, const JSString *p1, const JSString *p2) { return p1->len < p2->len ? -1 : 1; } -static JSValue -JS_ConcatString1 (JSContext *ctx, const JSString *p1, const JSString *p2) { +static JSValue JS_ConcatString1 (JSContext *ctx, const JSString *p1, + const JSString *p2) { JSString *p; uint32_t len; @@ -4015,8 +3870,8 @@ JS_ConcatString1 (JSContext *ctx, const JSString *p1, const JSString *p2) { return JS_MKPTR (JS_TAG_STRING, p); } -static BOOL -JS_ConcatStringInPlace (JSContext *ctx, JSString *p1, JSValue op2) { +static BOOL JS_ConcatStringInPlace (JSContext *ctx, JSString *p1, + JSValue op2) { if (JS_VALUE_GET_TAG (op2) == JS_TAG_STRING) { JSString *p2 = JS_VALUE_GET_STRING (op2); size_t size1; @@ -4043,8 +3898,7 @@ JS_ConcatStringInPlace (JSContext *ctx, JSString *p1, JSValue op2) { return FALSE; } -static JSValue -JS_ConcatString2 (JSContext *ctx, JSValue op1, JSValue op2) { +static JSValue JS_ConcatString2 (JSContext *ctx, JSValue op1, JSValue op2) { JSValue ret; JSString *p1, *p2; p1 = JS_VALUE_GET_STRING (op1); @@ -4060,9 +3914,8 @@ JS_ConcatString2 (JSContext *ctx, JSValue op1, JSValue op2) { } /* Helper for string value comparison (handles immediate and heap strings) */ -static int -js_string_compare_value (JSContext *ctx, JSValue op1, JSValue op2, - BOOL eq_only) { +static int js_string_compare_value (JSContext *ctx, JSValue op1, JSValue op2, + BOOL eq_only) { (void)ctx; if (eq_only && op1 == op2) return 0; @@ -4076,17 +3929,14 @@ js_string_compare_value (JSContext *ctx, JSValue op1, JSValue op2, for (int i = 0; i < len; i++) { uint32_t c1 = js_string_value_get (op1, i); uint32_t c2 = js_string_value_get (op2, i); - if (c1 != c2) { - return (c1 < c2) ? -1 : 1; - } + if (c1 != c2) { return (c1 < c2) ? -1 : 1; } } if (len1 == len2) return 0; return (len1 < len2) ? -1 : 1; } -static JSValue -JS_ConcatString (JSContext *ctx, JSValue op1, JSValue op2) { +static JSValue JS_ConcatString (JSContext *ctx, JSValue op1, JSValue op2) { if (unlikely (!JS_IsString (op1))) { op1 = JS_ToStringFree (ctx, op1); if (JS_IsException (op1)) { @@ -4113,17 +3963,19 @@ JS_ConcatString (JSContext *ctx, JSValue op1, JSValue op2) { BOOL all_ascii = TRUE; for (int i = 0; i < len1 && all_ascii; i++) { uint32_t c = js_string_value_get (op1, i); - if (c >= 0x80) all_ascii = FALSE; - else buf[i] = (char)c; + if (c >= 0x80) + all_ascii = FALSE; + else + buf[i] = (char)c; } for (int i = 0; i < len2 && all_ascii; i++) { uint32_t c = js_string_value_get (op2, i); - if (c >= 0x80) all_ascii = FALSE; - else buf[len1 + i] = (char)c; - } - if (all_ascii) { - ret_val = MIST_TryNewImmediateASCII (buf, new_len); + if (c >= 0x80) + all_ascii = FALSE; + else + buf[len1 + i] = (char)c; } + if (all_ascii) { ret_val = MIST_TryNewImmediateASCII (buf, new_len); } } if (JS_IsNull (ret_val)) { @@ -4157,7 +4009,7 @@ static JSObject *get_proto_obj (JSValue proto_val) { /* WARNING: proto must be an object or JS_NULL */ JSValue JS_NewObjectProtoClass (JSContext *ctx, JSValue proto_val, - JSClassID class_id) { + JSClassID class_id) { JSRecord *rec = js_new_record (ctx, 0); if (!rec) return JS_EXCEPTION; @@ -4208,29 +4060,23 @@ JSValue JS_NewArrayLen (JSContext *ctx, uint32_t len) { return JS_MKPTR (JS_TAG_OBJECT, arr); } -JSValue -JS_NewArray (JSContext *ctx) { - return JS_NewArrayLen (ctx, 0); -} +JSValue JS_NewArray (JSContext *ctx) { return JS_NewArrayLen (ctx, 0); } -JSValue -JS_NewObject (JSContext *ctx) { +JSValue JS_NewObject (JSContext *ctx) { /* inline JS_NewObjectClass(ctx, JS_CLASS_OBJECT); */ return JS_NewObjectProtoClass (ctx, ctx->class_proto[JS_CLASS_OBJECT], JS_CLASS_OBJECT); } /* Helper to check if a value is a bytecode function */ -static BOOL -js_is_bytecode_function (JSValue val) { +static BOOL js_is_bytecode_function (JSValue val) { if (JS_VALUE_GET_TAG (val) != JS_TAG_FUNCTION) return FALSE; JSFunction *f = JS_VALUE_GET_FUNCTION (val); return f->kind == JS_FUNC_KIND_BYTECODE; } /* return NULL without exception if not a function or no bytecode */ -static JSFunctionBytecode * -JS_GetFunctionBytecode (JSValue val) { +static JSFunctionBytecode *JS_GetFunctionBytecode (JSValue val) { JSFunction *f; if (JS_VALUE_GET_TAG (val) != JS_TAG_FUNCTION) return NULL; f = JS_VALUE_GET_FUNCTION (val); @@ -4245,25 +4091,24 @@ static JSValue js_get_function_name (JSContext *ctx, JSValue fn) { } // TODO: needs reworked -static int js_method_set_properties (JSContext *ctx, JSValue func_obj, JSValue name, - int flags, JSValue home_obj) { +static int js_method_set_properties (JSContext *ctx, JSValue func_obj, + JSValue name, int flags, + JSValue home_obj) { (void)ctx; (void)flags; (void)home_obj; if (JS_VALUE_GET_TAG (func_obj) != JS_TAG_FUNCTION) return -1; JSFunction *f = JS_VALUE_GET_FUNCTION (func_obj); /* name is now JSValue text */ - if (JS_IsString (name)) { - f->name = JS_DupValue (ctx, name); - } + if (JS_IsString (name)) { f->name = JS_DupValue (ctx, name); } return 0; } /* Note: at least 'length' arguments will be readable in 'argv' */ -static JSValue -JS_NewCFunction3 (JSContext *ctx, JSCFunction *func, const char *name, - int length, JSCFunctionEnum cproto, int magic, - JSValue proto_val) { +static JSValue JS_NewCFunction3 (JSContext *ctx, JSCFunction *func, + const char *name, int length, + JSCFunctionEnum cproto, int magic, + JSValue proto_val) { JSValue func_obj; JSFunction *f; (void)proto_val; @@ -4281,9 +4126,8 @@ JS_NewCFunction3 (JSContext *ctx, JSCFunction *func, const char *name, } /* Note: at least 'length' arguments will be readable in 'argv' */ -JSValue -JS_NewCFunction2 (JSContext *ctx, JSCFunction *func, const char *name, - int length, JSCFunctionEnum cproto, int magic) { +JSValue JS_NewCFunction2 (JSContext *ctx, JSCFunction *func, const char *name, + int length, JSCFunctionEnum cproto, int magic) { return JS_NewCFunction3 (ctx, func, name, length, cproto, magic, ctx->function_proto); } @@ -4296,9 +4140,9 @@ typedef struct JSCFunctionDataRecord { JSValue data[0]; } JSCFunctionDataRecord; -static JSValue -js_c_function_data_call (JSContext *ctx, JSValue func_obj, - JSValue this_val, int argc, JSValue *argv) { +static JSValue js_c_function_data_call (JSContext *ctx, JSValue func_obj, + JSValue this_val, int argc, + JSValue *argv) { JSFunction *f = JS_VALUE_GET_FUNCTION (func_obj); JSCFunctionDataRecord *s = f->u.c_function_data_record; JSValue *arg_buf; @@ -4318,9 +4162,8 @@ js_c_function_data_call (JSContext *ctx, JSValue func_obj, return s->func (ctx, this_val, argc, arg_buf, s->magic, s->data); } -JSValue -JS_NewCFunctionData (JSContext *ctx, JSCFunctionData *func, int length, - int magic, int data_len, JSValue *data) { +JSValue JS_NewCFunctionData (JSContext *ctx, JSCFunctionData *func, int length, + int magic, int data_len, JSValue *data) { JSCFunctionDataRecord *s; JSValue func_obj; JSFunction *f; @@ -4364,8 +4207,7 @@ static void free_var_ref (JSRuntime *rt, JSVarRef *var_ref) { } /* Free intrinsic array (JS_TAG_ARRAY) */ -static void -free_array (JSRuntime *rt, JSArray *arr) { +static void free_array (JSRuntime *rt, JSArray *arr) { assert (arr->header.gc_obj_type == JS_GC_OBJ_TYPE_ARRAY); arr->free_mark = 1; /* used to tell the array is invalid when @@ -4390,9 +4232,8 @@ free_array (JSRuntime *rt, JSArray *arr) { list_add_tail (&arr->header.link, &rt->gc_zero_ref_count_list); } -static int -js_intrinsic_array_ensure_capacity (JSContext *ctx, JSArray *arr, - uint32_t min_cap) { +static int js_intrinsic_array_ensure_capacity (JSContext *ctx, JSArray *arr, + uint32_t min_cap) { uint32_t old_cap = js_array_cap (arr); if (min_cap <= old_cap) return 0; @@ -4418,8 +4259,8 @@ js_intrinsic_array_ensure_capacity (JSContext *ctx, JSArray *arr, return 0; } -static int -js_intrinsic_array_push (JSContext *ctx, JSArray *arr, JSValue val) { +static int js_intrinsic_array_push (JSContext *ctx, JSArray *arr, + JSValue val) { if (js_intrinsic_array_ensure_capacity (ctx, arr, arr->len + 1) < 0) { JS_FreeValue (ctx, val); return -1; @@ -4428,9 +4269,8 @@ js_intrinsic_array_push (JSContext *ctx, JSArray *arr, JSValue val) { return 0; } -static int -js_intrinsic_array_set (JSContext *ctx, JSArray *arr, uint32_t idx, - JSValue val) { +static int js_intrinsic_array_set (JSContext *ctx, JSArray *arr, uint32_t idx, + JSValue val) { if (arr->stone) { JS_FreeValue (ctx, val); JS_ThrowInternalError (ctx, "cannot set on a stoned array"); @@ -4454,8 +4294,7 @@ js_intrinsic_array_set (JSContext *ctx, JSArray *arr, uint32_t idx, } /* Allocate intrinsic function (JS_TAG_FUNCTION) */ -static JSValue -js_new_function (JSContext *ctx, JSFunctionKind kind) { +static JSValue js_new_function (JSContext *ctx, JSFunctionKind kind) { JSRuntime *rt = ctx->rt; JSFunction *func = js_mallocz (ctx, sizeof (JSFunction)); if (!func) return JS_EXCEPTION; @@ -4469,8 +4308,7 @@ js_new_function (JSContext *ctx, JSFunctionKind kind) { } /* Free intrinsic function (JS_TAG_FUNCTION) */ -static void -free_function (JSRuntime *rt, JSFunction *func) { +static void free_function (JSRuntime *rt, JSFunction *func) { assert (func->header.gc_obj_type == JS_GC_OBJ_TYPE_FUNCTION); func->free_mark = 1; /* used to tell the function is invalid when @@ -4529,9 +4367,8 @@ free_function (JSRuntime *rt, JSFunction *func) { list_add_tail (&func->header.link, &rt->gc_zero_ref_count_list); } -static void -mark_function_children (JSRuntime *rt, JSFunction *func, - JS_MarkFunc *mark_func) { +static void mark_function_children (JSRuntime *rt, JSFunction *func, + JS_MarkFunc *mark_func) { switch (func->kind) { case JS_FUNC_KIND_C: if (func->u.cfunc.realm) mark_func (rt, &func->u.cfunc.realm->header); @@ -4571,8 +4408,7 @@ mark_function_children (JSRuntime *rt, JSFunction *func, } } -static void -mark_function_children_decref (JSRuntime *rt, JSFunction *func) { +static void mark_function_children_decref (JSRuntime *rt, JSFunction *func) { switch (func->kind) { case JS_FUNC_KIND_C: if (func->u.cfunc.realm) { @@ -4629,8 +4465,7 @@ mark_function_children_decref (JSRuntime *rt, JSFunction *func) { } } -static void -free_object (JSRuntime *rt, JSObject *p) { +static void free_object (JSRuntime *rt, JSObject *p) { JSClassFinalizer *finalizer; assert (p->header.gc_obj_type == JS_GC_OBJ_TYPE_JS_OBJECT); @@ -4669,8 +4504,7 @@ free_object (JSRuntime *rt, JSObject *p) { list_add_tail (&p->header.link, &rt->gc_zero_ref_count_list); } -static void -free_gc_object (JSRuntime *rt, JSGCObjectHeader *gp) { +static void free_gc_object (JSRuntime *rt, JSGCObjectHeader *gp) { switch (gp->gc_obj_type) { case JS_GC_OBJ_TYPE_JS_OBJECT: free_object (rt, (JSObject *)gp); @@ -4692,8 +4526,7 @@ free_gc_object (JSRuntime *rt, JSGCObjectHeader *gp) { } } -static void -free_zero_refcount (JSRuntime *rt) { +static void free_zero_refcount (JSRuntime *rt) { struct list_head *el; JSGCObjectHeader *p; @@ -4709,8 +4542,7 @@ free_zero_refcount (JSRuntime *rt) { } /* called with the ref_count of 'v' reaches zero. */ -void -__JS_FreeValueRT (JSRuntime *rt, JSValue v) { +void __JS_FreeValueRT (JSRuntime *rt, JSValue v) { uint32_t tag = JS_VALUE_GET_TAG (v); #ifdef DUMP_FREE @@ -4754,27 +4586,22 @@ __JS_FreeValueRT (JSRuntime *rt, JSValue v) { } } -void -__JS_FreeValue (JSContext *ctx, JSValue v) { +void __JS_FreeValue (JSContext *ctx, JSValue v) { __JS_FreeValueRT (ctx->rt, v); } /* garbage collection */ -static void -add_gc_object (JSRuntime *rt, JSGCObjectHeader *h, JSGCObjectTypeEnum type) { +static void add_gc_object (JSRuntime *rt, JSGCObjectHeader *h, + JSGCObjectTypeEnum type) { h->mark = 0; h->gc_obj_type = type; list_add_tail (&h->link, &rt->gc_obj_list); } -static void -remove_gc_object (JSGCObjectHeader *h) { - list_del (&h->link); -} +static void remove_gc_object (JSGCObjectHeader *h) { list_del (&h->link); } -void -JS_MarkValue (JSRuntime *rt, JSValue val, JS_MarkFunc *mark_func) { +void JS_MarkValue (JSRuntime *rt, JSValue val, JS_MarkFunc *mark_func) { if (JS_VALUE_HAS_REF_COUNT (val)) { switch (JS_VALUE_GET_TAG (val)) { case JS_TAG_OBJECT: /* includes arrays (OBJ_ARRAY) via mist_hdr */ @@ -4788,8 +4615,8 @@ JS_MarkValue (JSRuntime *rt, JSValue val, JS_MarkFunc *mark_func) { } } -static void -mark_children (JSRuntime *rt, JSGCObjectHeader *gp, JS_MarkFunc *mark_func) { +static void mark_children (JSRuntime *rt, JSGCObjectHeader *gp, + JS_MarkFunc *mark_func) { switch (gp->gc_obj_type) { case JS_GC_OBJ_TYPE_JS_OBJECT: { JSObject *p = (JSObject *)gp; @@ -4863,8 +4690,7 @@ mark_children (JSRuntime *rt, JSGCObjectHeader *gp, JS_MarkFunc *mark_func) { } } -static void -gc_decref_child (JSRuntime *rt, JSGCObjectHeader *p) { +static void gc_decref_child (JSRuntime *rt, JSGCObjectHeader *p) { #ifdef RC_TRACE if (p->ref_count <= 0) { rc_dump_history (p, "gc_decref_child pre-assert"); } #endif @@ -4876,8 +4702,7 @@ gc_decref_child (JSRuntime *rt, JSGCObjectHeader *p) { } } -static inline int32_t -gc_parent_class_id (JSGCObjectHeader *parent) { +static inline int32_t gc_parent_class_id (JSGCObjectHeader *parent) { if (parent && parent->gc_obj_type == JS_GC_OBJ_TYPE_JS_OBJECT) { return ((JSObject *)parent)->class_id; } @@ -4888,10 +4713,10 @@ gc_parent_class_id (JSGCObjectHeader *parent) { static JSGCObjectHeader *rc_edge_parent; static const char *rc_edge_name; -static void -gc_decref_child_dbg (JSRuntime *rt, JSGCObjectHeader *parent, const char *edge, - uint32_t atom, int32_t prop_index, JSGCObjectHeader *p, - const char *file, int line) { +static void gc_decref_child_dbg (JSRuntime *rt, JSGCObjectHeader *parent, + const char *edge, uint32_t atom, + int32_t prop_index, JSGCObjectHeader *p, + const char *file, int line) { uint32_t parent_type = parent ? parent->gc_obj_type : 0; int32_t parent_class_id = gc_parent_class_id (parent); if (p->ref_count <= 0) { @@ -4915,16 +4740,16 @@ gc_decref_child_dbg (JSRuntime *rt, JSGCObjectHeader *parent, const char *edge, } } -static void -gc_decref_child_edge (JSRuntime *rt, JSGCObjectHeader *p) { +static void gc_decref_child_edge (JSRuntime *rt, JSGCObjectHeader *p) { gc_decref_child_dbg (rt, rc_edge_parent, rc_edge_name, 0, -1, p, __FILE__, __LINE__); } #endif -static inline void -JS_MarkValueEdgeEx (JSRuntime *rt, JSValue val, JSGCObjectHeader *parent, - const char *edge, uint32_t atom, int32_t prop_index) { +static inline void JS_MarkValueEdgeEx (JSRuntime *rt, JSValue val, + JSGCObjectHeader *parent, + const char *edge, uint32_t atom, + int32_t prop_index) { if (!JS_VALUE_HAS_REF_COUNT (val)) { return; } switch (JS_VALUE_GET_TAG (val)) { @@ -4944,8 +4769,7 @@ JS_MarkValueEdgeEx (JSRuntime *rt, JSValue val, JSGCObjectHeader *parent, } } -static void -JS_MarkContextDecref (JSRuntime *rt, JSContext *ctx) { +static void JS_MarkContextDecref (JSRuntime *rt, JSContext *ctx) { int i; JS_MarkValueEdge (rt, ctx->global_obj, &ctx->header, "ctx.global_obj"); @@ -4970,8 +4794,7 @@ JS_MarkContextDecref (JSRuntime *rt, JSContext *ctx) { JS_MarkValueEdge (rt, ctx->regexp_ctor, &ctx->header, "ctx.regexp_ctor"); } -static void -mark_children_decref (JSRuntime *rt, JSGCObjectHeader *gp) { +static void mark_children_decref (JSRuntime *rt, JSGCObjectHeader *gp) { switch (gp->gc_obj_type) { case JS_GC_OBJ_TYPE_JS_OBJECT: { JSObject *p = (JSObject *)gp; @@ -5046,8 +4869,7 @@ mark_children_decref (JSRuntime *rt, JSGCObjectHeader *gp) { } } -static void -gc_decref (JSRuntime *rt) { +static void gc_decref (JSRuntime *rt) { struct list_head *el, *el1; JSGCObjectHeader *p; @@ -5068,8 +4890,7 @@ gc_decref (JSRuntime *rt) { } } -static void -gc_scan_incref_child (JSRuntime *rt, JSGCObjectHeader *p) { +static void gc_scan_incref_child (JSRuntime *rt, JSGCObjectHeader *p) { RC_GC_INC (p); if (p->ref_count == 1) { /* ref_count was 0: remove from tmp_obj_list and add at the @@ -5080,13 +4901,11 @@ gc_scan_incref_child (JSRuntime *rt, JSGCObjectHeader *p) { } } -static void -gc_scan_incref_child2 (JSRuntime *rt, JSGCObjectHeader *p) { +static void gc_scan_incref_child2 (JSRuntime *rt, JSGCObjectHeader *p) { RC_GC_INC (p); } -static void -gc_scan (JSRuntime *rt) { +static void gc_scan (JSRuntime *rt) { struct list_head *el; JSGCObjectHeader *p; @@ -5108,8 +4927,7 @@ gc_scan (JSRuntime *rt) { } } -static void -gc_free_cycles (JSRuntime *rt) { +static void gc_free_cycles (JSRuntime *rt) { struct list_head *el, *el1; JSGCObjectHeader *p; #ifdef DUMP_GC_FREE @@ -5162,8 +4980,7 @@ gc_free_cycles (JSRuntime *rt) { init_list_head (&rt->gc_zero_ref_count_list); } -static void -JS_RunGCInternal (JSRuntime *rt) { +static void JS_RunGCInternal (JSRuntime *rt) { /* decrement the reference of the children of each object. mark = 1 after this pass. */ gc_decref (rt); @@ -5175,16 +4992,12 @@ JS_RunGCInternal (JSRuntime *rt) { gc_free_cycles (rt); } -void -JS_RunGC (JSRuntime *rt) { - JS_RunGCInternal (rt); -} +void JS_RunGC (JSRuntime *rt) { JS_RunGCInternal (rt); } /* Return false if not an object or if the object has already been freed (zombie objects are visible in finalizers when freeing cycles). */ -BOOL -JS_IsLiveObject (JSRuntime *rt, JSValue obj) { +BOOL JS_IsLiveObject (JSRuntime *rt, JSValue obj) { JSObject *p; if (!JS_IsObject (obj)) return FALSE; p = JS_VALUE_GET_OBJ (obj); @@ -5206,17 +5019,17 @@ typedef struct JSMemoryUsage_helper { static void compute_value_size (JSValue val, JSMemoryUsage_helper *hp); -static void -compute_jsstring_size (JSString *str, JSMemoryUsage_helper *hp) { +static void compute_jsstring_size (JSString *str, JSMemoryUsage_helper *hp) { /* UTF-32 packs 2 chars per 64-bit word */ double s_ref_count = str->header.ref_count; size_t data_words = (str->len + 1) / 2; hp->str_count += 1 / s_ref_count; - hp->str_size += (sizeof (*str) + data_words * sizeof (uint64_t)) / s_ref_count; + hp->str_size + += (sizeof (*str) + data_words * sizeof (uint64_t)) / s_ref_count; } -static void -compute_bytecode_size (JSFunctionBytecode *b, JSMemoryUsage_helper *hp) { +static void compute_bytecode_size (JSFunctionBytecode *b, + JSMemoryUsage_helper *hp) { int memory_used_count, js_func_size, i; memory_used_count = 0; @@ -5254,8 +5067,7 @@ compute_bytecode_size (JSFunctionBytecode *b, JSMemoryUsage_helper *hp) { hp->memory_used_count += memory_used_count; } -static void -compute_value_size (JSValue val, JSMemoryUsage_helper *hp) { +static void compute_value_size (JSValue val, JSMemoryUsage_helper *hp) { switch (JS_VALUE_GET_TAG (val)) { case JS_TAG_STRING: compute_jsstring_size (JS_VALUE_GET_STRING (val), hp); @@ -5263,8 +5075,7 @@ compute_value_size (JSValue val, JSMemoryUsage_helper *hp) { } } -void -JS_ComputeMemoryUsage (JSRuntime *rt, JSMemoryUsage *s) { +void JS_ComputeMemoryUsage (JSRuntime *rt, JSMemoryUsage *s) { struct list_head *el; JSMemoryUsage_helper mem = { 0 }, *hp = &mem; @@ -5333,16 +5144,15 @@ JS_ComputeMemoryUsage (JSRuntime *rt, JSMemoryUsage *s) { s->js_func_code_size = mem.js_func_code_size; s->js_func_pc2line_count = mem.js_func_pc2line_count; s->js_func_pc2line_size = mem.js_func_pc2line_size; - s->memory_used_count += round (mem.memory_used_count) - + s->str_count + s->obj_count - + s->js_func_count + s->js_func_pc2line_count; - s->memory_used_size += s->str_size + s->obj_size - + s->prop_size + s->js_func_size - + s->js_func_code_size + s->js_func_pc2line_size; + s->memory_used_count += round (mem.memory_used_count) + s->str_count + + s->obj_count + s->js_func_count + + s->js_func_pc2line_count; + s->memory_used_size += s->str_size + s->obj_size + s->prop_size + + s->js_func_size + s->js_func_code_size + + s->js_func_pc2line_size; } -void -JS_DumpMemoryUsage (FILE *fp, const JSMemoryUsage *s, JSRuntime *rt) { +void JS_DumpMemoryUsage (FILE *fp, const JSMemoryUsage *s, JSRuntime *rt) { // fprintf(fp, "QuickJS memory usage -- " CONFIG_VERSION " version, %d-bit, // malloc limit: %"PRId64"\n\n", // (int)sizeof(void *) * 8, s->malloc_limit); @@ -5458,14 +5268,12 @@ JS_DumpMemoryUsage (FILE *fp, const JSMemoryUsage *s, JSRuntime *rt) { } } -JSValue -JS_GetGlobalObject (JSContext *ctx) { +JSValue JS_GetGlobalObject (JSContext *ctx) { return JS_DupValue (ctx, ctx->global_obj); } /* WARNING: obj is freed */ -JSValue -JS_Throw (JSContext *ctx, JSValue obj) { +JSValue JS_Throw (JSContext *ctx, JSValue obj) { JSRuntime *rt = ctx->rt; JS_FreeValue (ctx, rt->current_exception); rt->current_exception = obj; @@ -5474,8 +5282,7 @@ JS_Throw (JSContext *ctx, JSValue obj) { } /* return the pending exception (cannot be called twice). */ -JSValue -JS_GetException (JSContext *ctx) { +JSValue JS_GetException (JSContext *ctx) { JSValue val; JSRuntime *rt = ctx->rt; val = rt->current_exception; @@ -5488,8 +5295,7 @@ JS_HasException (JSContext *ctx) { return !JS_IsUninitialized (ctx->rt->current_exception); } -static void -dbuf_put_leb128 (DynBuf *s, uint32_t v) { +static void dbuf_put_leb128 (DynBuf *s, uint32_t v) { uint32_t a; for (;;) { a = v & 0x7f; @@ -5503,14 +5309,13 @@ dbuf_put_leb128 (DynBuf *s, uint32_t v) { } } -static void -dbuf_put_sleb128 (DynBuf *s, int32_t v1) { +static void dbuf_put_sleb128 (DynBuf *s, int32_t v1) { uint32_t v = v1; dbuf_put_leb128 (s, (2 * v) ^ -(v >> 31)); } -static int -get_leb128 (uint32_t *pval, const uint8_t *buf, const uint8_t *buf_end) { +static int get_leb128 (uint32_t *pval, const uint8_t *buf, + const uint8_t *buf_end) { const uint8_t *ptr = buf; uint32_t v, a, i; v = 0; @@ -5527,8 +5332,8 @@ get_leb128 (uint32_t *pval, const uint8_t *buf, const uint8_t *buf_end) { return -1; } -static int -get_sleb128 (int32_t *pval, const uint8_t *buf, const uint8_t *buf_end) { +static int get_sleb128 (int32_t *pval, const uint8_t *buf, + const uint8_t *buf_end) { int ret; uint32_t val; ret = get_leb128 (&val, buf, buf_end); @@ -5541,9 +5346,8 @@ get_sleb128 (int32_t *pval, const uint8_t *buf, const uint8_t *buf_end) { } /* use pc_value = -1 to get the position of the function definition */ -static int -find_line_num (JSContext *ctx, JSFunctionBytecode *b, uint32_t pc_value, - int *pcol_num) { +static int find_line_num (JSContext *ctx, JSFunctionBytecode *b, + uint32_t pc_value, int *pcol_num) { const uint8_t *p_end, *p; int new_line_num, line_num, pc, v, ret, new_col_num, col_num; uint32_t val; @@ -5604,8 +5408,8 @@ fail: /* return a string property without executing arbitrary JS code (used when dumping the stack trace or in debug print). */ -static const char * -get_prop_string (JSContext *ctx, JSValue obj, JSValue prop) { +static const char *get_prop_string (JSContext *ctx, JSValue obj, + JSValue prop) { if (JS_VALUE_GET_TAG (obj) != JS_TAG_OBJECT) return NULL; JSRecord *rec = (JSRecord *)JS_VALUE_GET_OBJ (obj); @@ -5628,8 +5432,7 @@ get_prop_string (JSContext *ctx, JSValue obj, JSValue prop) { /* in order to avoid executing arbitrary code during the stack trace generation, we only look at simple 'name' properties containing a string. */ -static const char * -get_func_name (JSContext *ctx, JSValue func) { +static const char *get_func_name (JSContext *ctx, JSValue func) { if (JS_VALUE_GET_TAG (func) != JS_TAG_OBJECT) return NULL; JSRecord *rec = (JSRecord *)JS_VALUE_GET_OBJ (func); @@ -5648,9 +5451,9 @@ get_func_name (JSContext *ctx, JSValue func) { /* if filename != NULL, an additional level is added with the filename and line number information (used for parse error). */ -static void -build_backtrace (JSContext *ctx, JSValue error_obj, const char *filename, - int line_num, int col_num, int backtrace_flags) { +static void build_backtrace (JSContext *ctx, JSValue error_obj, + const char *filename, int line_num, int col_num, + int backtrace_flags) { JSStackFrame *sf; JSValue str; DynBuf dbuf; @@ -5738,8 +5541,7 @@ build_backtrace (JSContext *ctx, JSValue error_obj, const char *filename, } /* Note: it is important that no exception is returned by this function */ -static BOOL -is_backtrace_needed (JSContext *ctx, JSValue obj) { +static BOOL is_backtrace_needed (JSContext *ctx, JSValue obj) { JSObject *p; if (JS_VALUE_GET_TAG (obj) != JS_TAG_OBJECT) return FALSE; p = JS_VALUE_GET_OBJ (obj); @@ -5752,14 +5554,13 @@ is_backtrace_needed (JSContext *ctx, JSValue obj) { return TRUE; } -JSValue -JS_NewError (JSContext *ctx) { +JSValue JS_NewError (JSContext *ctx) { return JS_NewObjectClass (ctx, JS_CLASS_ERROR); } -static JSValue -JS_ThrowError2 (JSContext *ctx, JSErrorEnum error_num, const char *fmt, - va_list ap, BOOL add_backtrace) { +static JSValue JS_ThrowError2 (JSContext *ctx, JSErrorEnum error_num, + const char *fmt, va_list ap, + BOOL add_backtrace) { char buf[256]; JSValue obj, ret; @@ -5770,17 +5571,15 @@ JS_ThrowError2 (JSContext *ctx, JSErrorEnum error_num, const char *fmt, /* out of memory: throw JS_NULL to avoid recursing */ obj = JS_NULL; } else { - JS_SetPropertyInternal (ctx, obj, JS_KEY_message, - JS_NewString (ctx, buf)); + JS_SetPropertyInternal (ctx, obj, JS_KEY_message, JS_NewString (ctx, buf)); if (add_backtrace) { build_backtrace (ctx, obj, NULL, 0, 0, 0); } } ret = JS_Throw (ctx, obj); return ret; } -static JSValue -JS_ThrowError (JSContext *ctx, JSErrorEnum error_num, const char *fmt, - va_list ap) { +static JSValue JS_ThrowError (JSContext *ctx, JSErrorEnum error_num, + const char *fmt, va_list ap) { JSRuntime *rt = ctx->rt; JSStackFrame *sf; BOOL add_backtrace; @@ -5870,8 +5669,7 @@ JS_ThrowInternalError (JSContext *ctx, const char *fmt, ...) { return val; } -JSValue -JS_ThrowOutOfMemory (JSContext *ctx) { +JSValue JS_ThrowOutOfMemory (JSContext *ctx) { JSRuntime *rt = ctx->rt; if (!rt->in_out_of_memory) { rt->in_out_of_memory = TRUE; @@ -5881,23 +5679,23 @@ JS_ThrowOutOfMemory (JSContext *ctx) { return JS_EXCEPTION; } -static JSValue -JS_ThrowStackOverflow (JSContext *ctx) { +static JSValue JS_ThrowStackOverflow (JSContext *ctx) { return JS_ThrowInternalError (ctx, "stack overflow"); } -static JSValue -JS_ThrowTypeErrorNotAnObject (JSContext *ctx) { +static JSValue JS_ThrowTypeErrorNotAnObject (JSContext *ctx) { return JS_ThrowTypeError (ctx, "not an object"); } -static JSValue JS_ThrowReferenceErrorNotDefined (JSContext *ctx, JSValue name) { +static JSValue JS_ThrowReferenceErrorNotDefined (JSContext *ctx, + JSValue name) { char buf[ATOM_GET_STR_BUF_SIZE]; return JS_ThrowReferenceError (ctx, "'%s' is not defined", JS_AtomGetStr (ctx, buf, sizeof (buf), name)); } -static JSValue JS_ThrowReferenceErrorUninitialized (JSContext *ctx, JSValue name) { +static JSValue JS_ThrowReferenceErrorUninitialized (JSContext *ctx, + JSValue name) { char buf[ATOM_GET_STR_BUF_SIZE]; return JS_ThrowReferenceError ( ctx, "%s is not initialized", @@ -5905,9 +5703,9 @@ static JSValue JS_ThrowReferenceErrorUninitialized (JSContext *ctx, JSValue name : JS_KeyGetStr (ctx, buf, sizeof (buf), name)); } -static JSValue -JS_ThrowReferenceErrorUninitialized2 (JSContext *ctx, JSFunctionBytecode *b, - int idx, BOOL is_ref) { +static JSValue JS_ThrowReferenceErrorUninitialized2 (JSContext *ctx, + JSFunctionBytecode *b, + int idx, BOOL is_ref) { JSValue name = JS_NULL; if (is_ref) { name = b->closure_var[idx].var_name; @@ -5918,21 +5716,19 @@ JS_ThrowReferenceErrorUninitialized2 (JSContext *ctx, JSFunctionBytecode *b, return JS_ThrowReferenceErrorUninitialized (ctx, name); } -static JSValue -JS_ThrowTypeErrorInvalidClass (JSContext *ctx, int class_id) { +static JSValue JS_ThrowTypeErrorInvalidClass (JSContext *ctx, int class_id) { JSRuntime *rt = ctx->rt; const char *name = rt->class_array[class_id].class_name; - return JS_ThrowTypeError (ctx, "%s object expected", name ? name : "unknown"); + return JS_ThrowTypeError (ctx, "%s object expected", + name ? name : "unknown"); } -static void -JS_ThrowInterrupted (JSContext *ctx) { +static void JS_ThrowInterrupted (JSContext *ctx) { JS_ThrowInternalError (ctx, "interrupted"); JS_SetUncatchableException (ctx, TRUE); } -static no_inline __exception int -__js_poll_interrupts (JSContext *ctx) { +static no_inline __exception int __js_poll_interrupts (JSContext *ctx) { JSRuntime *rt = ctx->rt; ctx->interrupt_counter = JS_INTERRUPT_COUNTER_INIT; if (rt->interrupt_handler) { @@ -5944,8 +5740,7 @@ __js_poll_interrupts (JSContext *ctx) { return 0; } -static inline __exception int -js_poll_interrupts (JSContext *ctx) { +static inline __exception int js_poll_interrupts (JSContext *ctx) { if (unlikely (--ctx->interrupt_counter <= 0)) { return __js_poll_interrupts (ctx); } else { @@ -5954,8 +5749,7 @@ js_poll_interrupts (JSContext *ctx) { } /* Return an Object, JS_NULL or JS_EXCEPTION in case of exotic object. */ -JSValue -JS_GetPrototype (JSContext *ctx, JSValue obj) { +JSValue JS_GetPrototype (JSContext *ctx, JSValue obj) { JSValue val; if (JS_VALUE_GET_TAG (obj) == JS_TAG_OBJECT) { JSObject *p; @@ -5972,8 +5766,7 @@ JS_GetPrototype (JSContext *ctx, JSValue obj) { return val; } -static JSValue -JS_GetPrototypeFree (JSContext *ctx, JSValue obj) { +static JSValue JS_GetPrototypeFree (JSContext *ctx, JSValue obj) { JSValue obj1; obj1 = JS_GetPrototype (ctx, obj); JS_FreeValue (ctx, obj); @@ -6006,9 +5799,8 @@ static int js_get_record_keys (JSContext *ctx, JSValue **ptab, uint32_t *plen, JSRecord *rec); /* Internal helper: get property keys for legacy JSObject (now just records) */ -static int __exception -js_get_object_keys (JSContext *ctx, JSValue **ptab, uint32_t *plen, - JSObject *p) { +static int __exception js_get_object_keys (JSContext *ctx, JSValue **ptab, + uint32_t *plen, JSObject *p) { /* Objects are now records */ JSRecord *rec = (JSRecord *)p; return js_get_record_keys (ctx, ptab, plen, rec); @@ -6016,9 +5808,8 @@ js_get_object_keys (JSContext *ctx, JSValue **ptab, uint32_t *plen, /* Get own property names from a JSRecord. Returns JSValue string keys directly (text values), not record-as-key. */ -static int -js_get_record_keys (JSContext *ctx, JSValue **ptab, uint32_t *plen, - JSRecord *rec) { +static int js_get_record_keys (JSContext *ctx, JSValue **ptab, uint32_t *plen, + JSRecord *rec) { uint32_t mask = (uint32_t)objhdr_cap56 (rec->mist_hdr); uint32_t count = 0; uint32_t i, j; @@ -6050,9 +5841,8 @@ js_get_record_keys (JSContext *ctx, JSValue **ptab, uint32_t *plen, return 0; } -int -JS_GetOwnPropertyNames (JSContext *ctx, JSValue **ptab, uint32_t *plen, - JSValue obj) { +int JS_GetOwnPropertyNames (JSContext *ctx, JSValue **ptab, uint32_t *plen, + JSValue obj) { if (JS_VALUE_GET_TAG (obj) != JS_TAG_OBJECT) { JS_ThrowTypeErrorNotAnObject (ctx); return -1; @@ -6067,9 +5857,9 @@ JS_GetOwnPropertyNames (JSContext *ctx, JSValue **ptab, uint32_t *plen, FALSE if the property does not exist, TRUE if it exists. If TRUE is returned, the property descriptor 'desc' is filled present. Now uses JSRecord-based lookup. */ -static int -JS_GetOwnPropertyInternal (JSContext *ctx, JSPropertyDescriptor *desc, - JSObject *p, JSValue prop) { +static int JS_GetOwnPropertyInternal (JSContext *ctx, + JSPropertyDescriptor *desc, JSObject *p, + JSValue prop) { JSRecord *rec = (JSRecord *)p; int slot = rec_find_slot (rec, prop); @@ -6085,8 +5875,8 @@ JS_GetOwnPropertyInternal (JSContext *ctx, JSPropertyDescriptor *desc, return FALSE; } -int JS_GetOwnProperty (JSContext *ctx, JSPropertyDescriptor *desc, - JSValue obj, JSAtom prop) { +int JS_GetOwnProperty (JSContext *ctx, JSPropertyDescriptor *desc, JSValue obj, + JSAtom prop) { if (JS_VALUE_GET_TAG (obj) != JS_TAG_OBJECT) { JS_ThrowTypeErrorNotAnObject (ctx); return -1; @@ -6123,7 +5913,8 @@ static uint32_t js_string_get_length (JSValue val) { } } -static JSValue JS_GetPropertyValue (JSContext *ctx, JSValue this_obj, JSValue prop) { +static JSValue JS_GetPropertyValue (JSContext *ctx, JSValue this_obj, + JSValue prop) { JSValue ret; uint32_t prop_tag = JS_VALUE_GET_TAG (prop); int this_tag = JS_VALUE_GET_TAG (this_obj); @@ -6181,8 +5972,8 @@ static JSValue JS_GetPropertyValue (JSContext *ctx, JSValue this_obj, JSValue pr return JS_NULL; } -JSValue -JS_SetPropertyNumber (JSContext *js, JSValue obj, int idx, JSValue val) { +JSValue JS_SetPropertyNumber (JSContext *js, JSValue obj, int idx, + JSValue val) { if (!JS_VALUE_IS_INTRINSIC_ARRAY (obj)) { JS_FreeValue (js, val); return JS_ThrowInternalError (js, @@ -6200,8 +5991,7 @@ JS_SetPropertyNumber (JSContext *js, JSValue obj, int idx, JSValue val) { return JS_DupValue (js, val); } -JSValue -JS_GetPropertyNumber (JSContext *js, JSValue obj, int idx) { +JSValue JS_GetPropertyNumber (JSContext *js, JSValue obj, int idx) { if (JS_VALUE_IS_INTRINSIC_ARRAY (obj)) { JSArray *a = JS_VALUE_GET_ARRAY (obj); int len = a->len; @@ -6219,18 +6009,16 @@ JS_GetPropertyNumber (JSContext *js, JSValue obj, int idx) { return JS_NULL; } -JSValue -JS_GetPropertyUint32 (JSContext *ctx, JSValue this_obj, uint32_t idx) { +JSValue JS_GetPropertyUint32 (JSContext *ctx, JSValue this_obj, uint32_t idx) { return JS_GetPropertyNumber (ctx, this_obj, idx); } -static JSValue -JS_GetPropertyInt64 (JSContext *ctx, JSValue obj, int64_t idx) { +static JSValue JS_GetPropertyInt64 (JSContext *ctx, JSValue obj, int64_t idx) { return JS_GetPropertyNumber (ctx, obj, idx); } -JSValue -JS_GetPropertyStr (JSContext *ctx, JSValue this_obj, const char *prop) { +JSValue JS_GetPropertyStr (JSContext *ctx, JSValue this_obj, + const char *prop) { if (JS_VALUE_GET_TAG (this_obj) != JS_TAG_OBJECT) return JS_NULL; size_t len = strlen (prop); @@ -6240,9 +6028,7 @@ JS_GetPropertyStr (JSContext *ctx, JSValue this_obj, const char *prop) { /* Try immediate ASCII first */ if (len <= MIST_ASCII_MAX_LEN) { key = MIST_TryNewImmediateASCII (prop, len); - if (JS_IsNull (key)) { - key = JS_NewStringLen (ctx, prop, len); - } + if (JS_IsNull (key)) { key = JS_NewStringLen (ctx, prop, len); } } else { key = JS_NewStringLen (ctx, prop, len); } @@ -6253,9 +6039,8 @@ JS_GetPropertyStr (JSContext *ctx, JSValue this_obj, const char *prop) { } /* JS_Invoke - invoke a method on an object by name */ -static JSValue -JS_Invoke (JSContext *ctx, JSValue this_val, JSValue method, int argc, - JSValue *argv) { +static JSValue JS_Invoke (JSContext *ctx, JSValue this_val, JSValue method, + int argc, JSValue *argv) { JSValue func = JS_GetProperty (ctx, this_val, method); if (JS_IsException (func)) return JS_EXCEPTION; if (!JS_IsFunction (func)) { @@ -6294,8 +6079,7 @@ static int delete_property (JSContext *ctx, JSObject *p, JSValue key) { return TRUE; } -static void -js_free_desc (JSContext *ctx, JSPropertyDescriptor *desc) { +static void js_free_desc (JSContext *ctx, JSPropertyDescriptor *desc) { JS_FreeValue (ctx, desc->getter); JS_FreeValue (ctx, desc->setter); JS_FreeValue (ctx, desc->value); @@ -6328,7 +6112,7 @@ int JS_SetProperty (JSContext *ctx, JSValue this_obj, JSValue prop, } int JS_SetPropertyUint32 (JSContext *ctx, JSValue this_obj, uint32_t idx, - JSValue val) { + JSValue val) { JSValue ret = JS_SetPropertyNumber (ctx, (JSValue)this_obj, (int)idx, val); if (JS_IsException (ret)) return -1; JS_FreeValue (ctx, ret); @@ -6336,7 +6120,7 @@ int JS_SetPropertyUint32 (JSContext *ctx, JSValue this_obj, uint32_t idx, } int JS_SetPropertyInt64 (JSContext *ctx, JSValue this_obj, int64_t idx, - JSValue val) { + JSValue val) { if (idx < INT32_MIN || idx > INT32_MAX) { JS_FreeValue (ctx, val); JS_ThrowRangeError (ctx, "array index out of bounds"); @@ -6348,15 +6132,14 @@ int JS_SetPropertyInt64 (JSContext *ctx, JSValue this_obj, int64_t idx, return 0; } -int JS_SetPropertyStr (JSContext *ctx, JSValue this_obj, const char *prop, JSValue val) { +int JS_SetPropertyStr (JSContext *ctx, JSValue this_obj, const char *prop, + JSValue val) { /* Create JSValue key from string - try immediate ASCII first */ int len = strlen (prop); JSValue key; if (len <= MIST_ASCII_MAX_LEN) { key = MIST_TryNewImmediateASCII (prop, len); - if (JS_IsNull (key)) { - key = js_new_string8_len (ctx, prop, len); - } + if (JS_IsNull (key)) { key = js_new_string8_len (ctx, prop, len); } } else { key = js_new_string8_len (ctx, prop, len); } @@ -6368,8 +6151,7 @@ int JS_SetPropertyStr (JSContext *ctx, JSValue this_obj, const char *prop, JSVal } /* Property access with JSValue key - supports object keys directly */ -JSValue -JS_GetPropertyKey (JSContext *ctx, JSValue this_obj, JSValue key) { +JSValue JS_GetPropertyKey (JSContext *ctx, JSValue this_obj, JSValue key) { uint32_t tag = JS_VALUE_GET_TAG (key); if (tag == JS_TAG_OBJECT) { if (JS_VALUE_GET_TAG (this_obj) != JS_TAG_OBJECT) return JS_NULL; @@ -6390,9 +6172,8 @@ JS_GetPropertyKey (JSContext *ctx, JSValue this_obj, JSValue key) { return JS_GetProperty (ctx, this_obj, key); } -int -JS_SetPropertyKey (JSContext *ctx, JSValue this_obj, JSValue key, - JSValue val) { +int JS_SetPropertyKey (JSContext *ctx, JSValue this_obj, JSValue key, + JSValue val) { uint32_t tag = JS_VALUE_GET_TAG (key); if (tag == JS_TAG_OBJECT) { if (JS_VALUE_GET_TAG (this_obj) != JS_TAG_OBJECT) { @@ -6416,8 +6197,7 @@ JS_SetPropertyKey (JSContext *ctx, JSValue this_obj, JSValue key, } /* Property existence check with JSValue key (supports object keys) */ -int -JS_HasPropertyKey (JSContext *ctx, JSValue obj, JSValue key) { +int JS_HasPropertyKey (JSContext *ctx, JSValue obj, JSValue key) { uint32_t tag = JS_VALUE_GET_TAG (key); if (tag == JS_TAG_OBJECT) { if (JS_VALUE_GET_TAG (obj) != JS_TAG_OBJECT) return FALSE; @@ -6436,8 +6216,7 @@ JS_HasPropertyKey (JSContext *ctx, JSValue obj, JSValue key) { } /* Property deletion with JSValue key (supports object keys) */ -int -JS_DeletePropertyKey (JSContext *ctx, JSValue obj, JSValue key) { +int JS_DeletePropertyKey (JSContext *ctx, JSValue obj, JSValue key) { uint32_t tag = JS_VALUE_GET_TAG (key); if (tag == JS_TAG_OBJECT) { if (JS_VALUE_GET_TAG (obj) != JS_TAG_OBJECT) return FALSE; @@ -6461,8 +6240,7 @@ JS_DeletePropertyKey (JSContext *ctx, JSValue obj, JSValue key) { */ /* return TRUE if 'obj' has a non empty 'name' string */ -static BOOL -js_object_has_name (JSContext *ctx, JSValue obj) { +static BOOL js_object_has_name (JSContext *ctx, JSValue obj) { if (JS_VALUE_GET_TAG (obj) != JS_TAG_OBJECT) return FALSE; JSRecord *rec = (JSRecord *)JS_VALUE_GET_OBJ (obj); JSValue name_key = MIST_TryNewImmediateASCII ("name", 4); @@ -6474,21 +6252,23 @@ js_object_has_name (JSContext *ctx, JSValue obj) { return (p->len != 0); } -static int -JS_DefineObjectName (JSContext *ctx, JSValue obj, JSValue name) { - if (!JS_IsNull (name) && JS_IsObject (obj) && !js_object_has_name (ctx, obj)) { +static int JS_DefineObjectName (JSContext *ctx, JSValue obj, JSValue name) { + if (!JS_IsNull (name) && JS_IsObject (obj) + && !js_object_has_name (ctx, obj)) { JSValue name_key = MIST_TryNewImmediateASCII ("name", 4); - if (JS_SetPropertyInternal (ctx, obj, name_key, JS_DupValue (ctx, name)) < 0) + if (JS_SetPropertyInternal (ctx, obj, name_key, JS_DupValue (ctx, name)) + < 0) return -1; } return 0; } -static int -JS_DefineObjectNameComputed (JSContext *ctx, JSValue obj, JSValue str) { +static int JS_DefineObjectNameComputed (JSContext *ctx, JSValue obj, + JSValue str) { if (JS_IsObject (obj) && !js_object_has_name (ctx, obj)) { JSValue name_key = MIST_TryNewImmediateASCII ("name", 4); - if (JS_SetPropertyInternal (ctx, obj, name_key, JS_DupValue (ctx, str)) < 0) + if (JS_SetPropertyInternal (ctx, obj, name_key, JS_DupValue (ctx, str)) + < 0) return -1; } return 0; @@ -6497,16 +6277,15 @@ JS_DefineObjectNameComputed (JSContext *ctx, JSValue obj, JSValue str) { #define DEFINE_GLOBAL_LEX_VAR (1 << 7) #define DEFINE_GLOBAL_FUNC_VAR (1 << 6) -static JSValue -JS_ThrowSyntaxErrorVarRedeclaration (JSContext *ctx, JSValue prop) { +static JSValue JS_ThrowSyntaxErrorVarRedeclaration (JSContext *ctx, + JSValue prop) { char buf[ATOM_GET_STR_BUF_SIZE]; return JS_ThrowSyntaxError (ctx, "redeclaration of '%s'", JS_KeyGetStr (ctx, buf, sizeof (buf), prop)); } /* flags is 0, DEFINE_GLOBAL_LEX_VAR or DEFINE_GLOBAL_FUNC_VAR */ -static int -JS_CheckDefineGlobalVar (JSContext *ctx, JSValue prop, int flags) { +static int JS_CheckDefineGlobalVar (JSContext *ctx, JSValue prop, int flags) { JSRecord *rec; int slot; @@ -6534,8 +6313,7 @@ JS_CheckDefineGlobalVar (JSContext *ctx, JSValue prop, int flags) { } /* Simplified: def_flags is (0, DEFINE_GLOBAL_LEX_VAR) */ -static int -JS_DefineGlobalVar (JSContext *ctx, JSValue prop, int def_flags) { +static int JS_DefineGlobalVar (JSContext *ctx, JSValue prop, int def_flags) { JSRecord *rec; JSValue val; int slot; @@ -6554,9 +6332,8 @@ JS_DefineGlobalVar (JSContext *ctx, JSValue prop, int def_flags) { } /* Simplified global function definition */ -static int -JS_DefineGlobalFunction (JSContext *ctx, JSValue prop, JSValue func, - int def_flags) { +static int JS_DefineGlobalFunction (JSContext *ctx, JSValue prop, JSValue func, + int def_flags) { (void)def_flags; /* JS_SetPropertyInternal consumes the value, so we must dup it */ if (JS_SetPropertyInternal (ctx, ctx->global_obj, prop, @@ -6566,8 +6343,8 @@ JS_DefineGlobalFunction (JSContext *ctx, JSValue prop, JSValue func, return 0; } -static JSValue -JS_GetGlobalVar (JSContext *ctx, JSValue prop, BOOL throw_ref_error) { +static JSValue JS_GetGlobalVar (JSContext *ctx, JSValue prop, + BOOL throw_ref_error) { JSRecord *rec; int slot; @@ -6580,15 +6357,15 @@ JS_GetGlobalVar (JSContext *ctx, JSValue prop, BOOL throw_ref_error) { return JS_DupValue (ctx, val); } /* Fall back to global object */ - JSValue val = rec_get (ctx, (JSRecord *)JS_VALUE_GET_OBJ (ctx->global_obj), prop); + JSValue val + = rec_get (ctx, (JSRecord *)JS_VALUE_GET_OBJ (ctx->global_obj), prop); if (JS_IsNull (val) && throw_ref_error) return JS_ThrowReferenceErrorNotDefined (ctx, prop); return val; } /* construct a reference to a global variable */ -static int -JS_GetGlobalVarRef (JSContext *ctx, JSValue prop, JSValue *sp) { +static int JS_GetGlobalVarRef (JSContext *ctx, JSValue prop, JSValue *sp) { JSRecord *rec; int slot; @@ -6615,8 +6392,7 @@ JS_GetGlobalVarRef (JSContext *ctx, JSValue prop, JSValue *sp) { } /* use for strict variable access: test if the variable exists */ -static int -JS_CheckGlobalVar (JSContext *ctx, JSValue prop) { +static int JS_CheckGlobalVar (JSContext *ctx, JSValue prop) { JSRecord *rec; int slot, ret; @@ -6635,8 +6411,8 @@ JS_CheckGlobalVar (JSContext *ctx, JSValue prop) { flag = 1: initialize lexical variable flag = 2: normal variable write, strict check was done before */ -static int -JS_SetGlobalVar (JSContext *ctx, JSValue prop, JSValue val, int flag) { +static int JS_SetGlobalVar (JSContext *ctx, JSValue prop, JSValue val, + int flag) { JSRecord *rec; int slot; @@ -6659,8 +6435,7 @@ JS_SetGlobalVar (JSContext *ctx, JSValue prop, JSValue val, int flag) { } /* return -1, FALSE or TRUE */ -static int -JS_DeleteGlobalVar (JSContext *ctx, JSValue prop) { +static int JS_DeleteGlobalVar (JSContext *ctx, JSValue prop) { JSRecord *rec; int slot, ret; @@ -6677,8 +6452,7 @@ JS_DeleteGlobalVar (JSContext *ctx, JSValue prop) { } } -int -JS_DeleteProperty (JSContext *ctx, JSValue obj, JSValue prop) { +int JS_DeleteProperty (JSContext *ctx, JSValue obj, JSValue prop) { JSRecord *rec; int slot; @@ -6713,9 +6487,8 @@ JS_DeleteProperty (JSContext *ctx, JSValue obj, JSValue prop) { return TRUE; /* property not found = deletion succeeded */ } -BOOL -JS_IsCFunction (JSContext *ctx, JSValue val, JSCFunction *func, - int magic) { +BOOL JS_IsCFunction (JSContext *ctx, JSValue val, JSCFunction *func, + int magic) { JSFunction *f; (void)ctx; /* unused */ if (JS_VALUE_GET_TAG (val) != JS_TAG_FUNCTION) return FALSE; @@ -6727,8 +6500,7 @@ JS_IsCFunction (JSContext *ctx, JSValue val, JSCFunction *func, return FALSE; } -BOOL -JS_IsError (JSContext *ctx, JSValue val) { +BOOL JS_IsError (JSContext *ctx, JSValue val) { JSObject *p; if (JS_VALUE_GET_TAG (val) != JS_TAG_OBJECT) return FALSE; p = JS_VALUE_GET_OBJ (val); @@ -6736,13 +6508,11 @@ JS_IsError (JSContext *ctx, JSValue val) { } /* must be called after JS_Throw() */ -void -JS_SetUncatchableException (JSContext *ctx, BOOL flag) { +void JS_SetUncatchableException (JSContext *ctx, BOOL flag) { ctx->rt->current_exception_is_uncatchable = flag; } -void -JS_SetOpaque (JSValue obj, void *opaque) { +void JS_SetOpaque (JSValue obj, void *opaque) { JSObject *p; if (JS_VALUE_GET_TAG (obj) == JS_TAG_OBJECT) { p = JS_VALUE_GET_OBJ (obj); @@ -6751,8 +6521,7 @@ JS_SetOpaque (JSValue obj, void *opaque) { } /* return NULL if not an object of class class_id */ -void * -JS_GetOpaque (JSValue obj, JSClassID class_id) { +void *JS_GetOpaque (JSValue obj, JSClassID class_id) { JSObject *p; if (JS_VALUE_GET_TAG (obj) != JS_TAG_OBJECT) return NULL; p = JS_VALUE_GET_OBJ (obj); @@ -6760,14 +6529,13 @@ JS_GetOpaque (JSValue obj, JSClassID class_id) { return p->u.opaque; } -void * -JS_GetOpaque2 (JSContext *ctx, JSValue obj, JSClassID class_id) { +void *JS_GetOpaque2 (JSContext *ctx, JSValue obj, JSClassID class_id) { void *p = JS_GetOpaque (obj, class_id); if (unlikely (!p)) { JS_ThrowTypeErrorInvalidClass (ctx, class_id); } return p; } -void * JS_GetAnyOpaque (JSValue obj, JSClassID *class_id) { +void *JS_GetAnyOpaque (JSValue obj, JSClassID *class_id) { JSObject *p; if (JS_VALUE_GET_TAG (obj) != JS_TAG_OBJECT) { *class_id = 0; @@ -6778,8 +6546,7 @@ void * JS_GetAnyOpaque (JSValue obj, JSClassID *class_id) { return p->u.opaque; } -static int -JS_ToBoolFree (JSContext *ctx, JSValue val) { +static int JS_ToBoolFree (JSContext *ctx, JSValue val) { uint32_t tag = JS_VALUE_GET_TAG (val); switch (tag) { case JS_TAG_INT: @@ -6813,13 +6580,11 @@ JS_ToBoolFree (JSContext *ctx, JSValue val) { } } -int -JS_ToBool (JSContext *ctx, JSValue val) { +int JS_ToBool (JSContext *ctx, JSValue val) { return JS_ToBoolFree (ctx, JS_DupValue (ctx, val)); } -static int -skip_spaces (const char *pc) { +static int skip_spaces (const char *pc) { const uint8_t *p, *p_next, *p_start; uint32_t c; @@ -6838,8 +6603,7 @@ skip_spaces (const char *pc) { return p - p_start; } -static inline int -to_digit (int c) { +static inline int to_digit (int c) { if (c >= '0' && c <= '9') return c - '0'; else if (c >= 'A' && c <= 'Z') @@ -6869,9 +6633,8 @@ to_digit (int c) { /* return an exception in case of memory error. Return JS_NAN if invalid syntax */ /* XXX: directly use js_atod() */ -static JSValue -js_atof (JSContext *ctx, const char *str, const char **pp, int radix, - int flags) { +static JSValue js_atof (JSContext *ctx, const char *str, const char **pp, + int radix, int flags) { const char *p, *p_start; int sep, is_neg; BOOL is_float; @@ -7025,8 +6788,7 @@ mem_error: goto done; } -static JSValue -JS_ToNumberFree (JSContext *ctx, JSValue val) { +static JSValue JS_ToNumberFree (JSContext *ctx, JSValue val) { uint32_t tag; JSValue ret; @@ -7063,8 +6825,8 @@ static JSValue JS_ToNumber (JSContext *ctx, JSValue val) { return JS_ToNumberFree (ctx, JS_DupValue (ctx, val)); } -static __exception int -__JS_ToFloat64Free (JSContext *ctx, double *pres, JSValue val) { +static __exception int __JS_ToFloat64Free (JSContext *ctx, double *pres, + JSValue val) { double d; uint32_t tag; @@ -7088,8 +6850,8 @@ fail: return -1; } -static inline int -JS_ToFloat64Free (JSContext *ctx, double *pres, JSValue val) { +static inline int JS_ToFloat64Free (JSContext *ctx, double *pres, + JSValue val) { uint32_t tag; tag = JS_VALUE_GET_TAG (val); @@ -7104,14 +6866,12 @@ JS_ToFloat64Free (JSContext *ctx, double *pres, JSValue val) { } } -int -JS_ToFloat64 (JSContext *ctx, double *pres, JSValue val) { +int JS_ToFloat64 (JSContext *ctx, double *pres, JSValue val) { return JS_ToFloat64Free (ctx, pres, JS_DupValue (ctx, val)); } /* Note: the integer value is satured to 32 bits */ -static int -JS_ToInt32SatFree (JSContext *ctx, int *pres, JSValue val) { +static int JS_ToInt32SatFree (JSContext *ctx, int *pres, JSValue val) { uint32_t tag; int ret; @@ -7151,14 +6911,12 @@ redo: return 0; } -int -JS_ToInt32Sat (JSContext *ctx, int *pres, JSValue val) { +int JS_ToInt32Sat (JSContext *ctx, int *pres, JSValue val) { return JS_ToInt32SatFree (ctx, pres, JS_DupValue (ctx, val)); } -int -JS_ToInt32Clamp (JSContext *ctx, int *pres, JSValue val, int min, int max, - int min_offset) { +int JS_ToInt32Clamp (JSContext *ctx, int *pres, JSValue val, int min, int max, + int min_offset) { int res = JS_ToInt32SatFree (ctx, pres, JS_DupValue (ctx, val)); if (res == 0) { if (*pres < min) { @@ -7171,8 +6929,7 @@ JS_ToInt32Clamp (JSContext *ctx, int *pres, JSValue val, int min, int max, return res; } -static int -JS_ToInt64SatFree (JSContext *ctx, int64_t *pres, JSValue val) { +static int JS_ToInt64SatFree (JSContext *ctx, int64_t *pres, JSValue val) { uint32_t tag; redo: @@ -7211,14 +6968,12 @@ redo: } } -int -JS_ToInt64Sat (JSContext *ctx, int64_t *pres, JSValue val) { +int JS_ToInt64Sat (JSContext *ctx, int64_t *pres, JSValue val) { return JS_ToInt64SatFree (ctx, pres, JS_DupValue (ctx, val)); } -int -JS_ToInt64Clamp (JSContext *ctx, int64_t *pres, JSValue val, int64_t min, - int64_t max, int64_t neg_offset) { +int JS_ToInt64Clamp (JSContext *ctx, int64_t *pres, JSValue val, int64_t min, + int64_t max, int64_t neg_offset) { int res = JS_ToInt64SatFree (ctx, pres, JS_DupValue (ctx, val)); if (res == 0) { if (*pres < 0) *pres += neg_offset; @@ -7232,8 +6987,7 @@ JS_ToInt64Clamp (JSContext *ctx, int64_t *pres, JSValue val, int64_t min, /* Same as JS_ToInt32Free() but with a 64 bit result. Return (<0, 0) in case of exception */ -static int -JS_ToInt64Free (JSContext *ctx, int64_t *pres, JSValue val) { +static int JS_ToInt64Free (JSContext *ctx, int64_t *pres, JSValue val) { uint32_t tag; int64_t ret; @@ -7279,14 +7033,12 @@ redo: return 0; } -int -JS_ToInt64 (JSContext *ctx, int64_t *pres, JSValue val) { +int JS_ToInt64 (JSContext *ctx, int64_t *pres, JSValue val) { return JS_ToInt64Free (ctx, pres, JS_DupValue (ctx, val)); } /* return (<0, 0) in case of exception */ -static int -JS_ToInt32Free (JSContext *ctx, int32_t *pres, JSValue val) { +static int JS_ToInt32Free (JSContext *ctx, int32_t *pres, JSValue val) { uint32_t tag; int32_t ret; @@ -7335,19 +7087,17 @@ redo: return 0; } -int -JS_ToInt32 (JSContext *ctx, int32_t *pres, JSValue val) { +int JS_ToInt32 (JSContext *ctx, int32_t *pres, JSValue val) { return JS_ToInt32Free (ctx, pres, JS_DupValue (ctx, val)); } -static inline int -JS_ToUint32Free (JSContext *ctx, uint32_t *pres, JSValue val) { +static inline int JS_ToUint32Free (JSContext *ctx, uint32_t *pres, + JSValue val) { return JS_ToInt32Free (ctx, (int32_t *)pres, val); } -static __exception int -JS_ToArrayLengthFree (JSContext *ctx, uint32_t *plen, JSValue val, - BOOL is_array_ctor) { +static __exception int JS_ToArrayLengthFree (JSContext *ctx, uint32_t *plen, + JSValue val, BOOL is_array_ctor) { uint32_t tag, len; tag = JS_VALUE_GET_TAG (val); @@ -7402,15 +7152,15 @@ JS_ToArrayLengthFree (JSContext *ctx, uint32_t *plen, JSValue val, /* 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, JSValue val) { +static __exception int JS_ToLengthFree (JSContext *ctx, int64_t *plen, + JSValue val) { int res = JS_ToInt64Clamp (ctx, plen, val, 0, MAX_SAFE_INTEGER, 0); JS_FreeValue (ctx, val); return res; } -static JSValue -js_dtoa2 (JSContext *ctx, double d, int radix, int n_digits, int flags) { +static JSValue js_dtoa2 (JSContext *ctx, double d, int radix, int n_digits, + int flags) { char static_buf[128], *buf, *tmp_buf; int len, len_max; JSValue res; @@ -7432,8 +7182,8 @@ js_dtoa2 (JSContext *ctx, double d, int radix, int n_digits, int flags) { return res; } -static JSValue -JS_ToStringInternal (JSContext *ctx, JSValue val, BOOL is_ToPropertyKey) { +static JSValue JS_ToStringInternal (JSContext *ctx, JSValue val, + BOOL is_ToPropertyKey) { uint32_t tag; char buf[32]; @@ -7472,28 +7222,24 @@ JS_ToStringInternal (JSContext *ctx, JSValue val, BOOL is_ToPropertyKey) { } } -JSValue -JS_ToString (JSContext *ctx, JSValue val) { +JSValue JS_ToString (JSContext *ctx, JSValue val) { return JS_ToStringInternal (ctx, val, FALSE); } -static JSValue -JS_ToStringFree (JSContext *ctx, JSValue val) { +static JSValue JS_ToStringFree (JSContext *ctx, JSValue val) { JSValue ret; ret = JS_ToString (ctx, val); JS_FreeValue (ctx, val); return ret; } -static JSValue -JS_ToLocaleStringFree (JSContext *ctx, JSValue val) { +static JSValue JS_ToLocaleStringFree (JSContext *ctx, JSValue val) { /* Simplified: just use toString for now since toLocaleString requires method lookup and atoms are removed */ return JS_ToStringFree (ctx, val); } -JSValue -JS_ToPropertyKey (JSContext *ctx, JSValue val) { +JSValue JS_ToPropertyKey (JSContext *ctx, JSValue val) { int tag = JS_VALUE_GET_TAG (val); /* Objects are handled directly via objkey map, not through atoms */ @@ -7502,15 +7248,13 @@ JS_ToPropertyKey (JSContext *ctx, JSValue val) { return JS_ToStringInternal (ctx, val, TRUE); } -static JSValue -JS_ToStringCheckObject (JSContext *ctx, JSValue val) { +static JSValue JS_ToStringCheckObject (JSContext *ctx, JSValue val) { uint32_t tag = JS_VALUE_GET_TAG (val); if (tag == JS_TAG_NULL) return JS_ThrowTypeError (ctx, "null is forbidden"); return JS_ToString (ctx, val); } -static JSValue -JS_ToQuotedString (JSContext *ctx, JSValue val1) { +static JSValue JS_ToQuotedString (JSContext *ctx, JSValue val1) { JSValue val; JSString *p; int i; @@ -7582,13 +7326,11 @@ typedef struct { static void js_print_value (JSPrintValueState *s, JSValue val); -static void -js_putc (JSPrintValueState *s, char c) { +static void js_putc (JSPrintValueState *s, char c) { s->write_func (s->write_opaque, &c, 1); } -static void -js_puts (JSPrintValueState *s, const char *str) { +static void js_puts (JSPrintValueState *s, const char *str) { s->write_func (s->write_opaque, str, strlen (str)); } @@ -7603,8 +7345,7 @@ js_printf (JSPrintValueState *s, const char *fmt, ...) { s->write_func (s->write_opaque, buf, strlen (buf)); } -static void -js_print_float64 (JSPrintValueState *s, double d) { +static void js_print_float64 (JSPrintValueState *s, double d) { JSDTOATempMem dtoa_mem; char buf[32]; int len; @@ -7613,8 +7354,7 @@ js_print_float64 (JSPrintValueState *s, double d) { s->write_func (s->write_opaque, buf, len); } -static void -js_dump_char (JSPrintValueState *s, int c, int sep) { +static void js_dump_char (JSPrintValueState *s, int c, int sep) { if (c == sep || c == '\\') { js_putc (s, '\\'); js_putc (s, c); @@ -7628,9 +7368,8 @@ js_dump_char (JSPrintValueState *s, int c, int sep) { } } -static void -js_print_string_rec (JSPrintValueState *s, JSValue val, int sep, - uint32_t pos) { +static void js_print_string_rec (JSPrintValueState *s, JSValue val, int sep, + uint32_t pos) { if (JS_VALUE_GET_TAG (val) == JS_TAG_STRING) { JSString *p = JS_VALUE_GET_STRING (val); uint32_t i, len; @@ -7654,8 +7393,7 @@ js_print_string_rec (JSPrintValueState *s, JSValue val, int sep, } } -static void -js_print_string (JSPrintValueState *s, JSValue val) { +static void js_print_string (JSPrintValueState *s, JSValue val) { int sep; if (s->options.raw_dump && JS_VALUE_GET_TAG (val) == JS_TAG_STRING) { JSString *p = JS_VALUE_GET_STRING (val); @@ -7673,9 +7411,8 @@ js_print_string (JSPrintValueState *s, JSValue val) { } } -static void -js_print_raw_string2 (JSPrintValueState *s, JSValue val, - BOOL remove_last_lf) { +static void js_print_raw_string2 (JSPrintValueState *s, JSValue val, + BOOL remove_last_lf) { const char *cstr; size_t len; cstr = JS_ToCStringLen (s->ctx, &len, val); @@ -7686,13 +7423,11 @@ js_print_raw_string2 (JSPrintValueState *s, JSValue val, } } -static void -js_print_raw_string (JSPrintValueState *s, JSValue val) { +static void js_print_raw_string (JSPrintValueState *s, JSValue val) { js_print_raw_string2 (s, val, FALSE); } -static BOOL -is_ascii_ident (const JSString *p) { +static BOOL is_ascii_ident (const JSString *p) { int i, c; if (p->len == 0) return FALSE; @@ -7705,8 +7440,7 @@ is_ascii_ident (const JSString *p) { return TRUE; } -static void -js_print_comma (JSPrintValueState *s, int *pcomma_state) { +static void js_print_comma (JSPrintValueState *s, int *pcomma_state) { switch (*pcomma_state) { case 0: break; @@ -7720,14 +7454,13 @@ js_print_comma (JSPrintValueState *s, int *pcomma_state) { *pcomma_state = 1; } -static void -js_print_more_items (JSPrintValueState *s, int *pcomma_state, uint32_t n) { +static void js_print_more_items (JSPrintValueState *s, int *pcomma_state, + uint32_t n) { js_print_comma (s, pcomma_state); js_printf (s, "... %u more item%s", n, n > 1 ? "s" : ""); } -static void -js_print_object (JSPrintValueState *s, JSObject *p) { +static void js_print_object (JSPrintValueState *s, JSObject *p) { JSRuntime *rt = s->rt; int comma_state; BOOL is_array; @@ -7792,16 +7525,14 @@ js_print_object (JSPrintValueState *s, JSObject *p) { } } -static int -js_print_stack_index (JSPrintValueState *s, JSObject *p) { +static int js_print_stack_index (JSPrintValueState *s, JSObject *p) { int i; for (i = 0; i < s->level; i++) if (s->print_stack[i] == p) return i; return -1; } -static void -js_print_value (JSPrintValueState *s, JSValue val) { +static void js_print_value (JSPrintValueState *s, JSValue val) { uint32_t tag = JS_VALUE_GET_NORM_TAG (val); const char *str; @@ -7911,18 +7642,17 @@ js_print_value (JSPrintValueState *s, JSValue val) { } } -void -JS_PrintValueSetDefaultOptions (JSPrintValueOptions *options) { +void JS_PrintValueSetDefaultOptions (JSPrintValueOptions *options) { memset (options, 0, sizeof (*options)); options->max_depth = 2; options->max_string_length = 1000; options->max_item_count = 100; } -static void -JS_PrintValueInternal (JSRuntime *rt, JSContext *ctx, - JSPrintValueWrite *write_func, void *write_opaque, - JSValue val, const JSPrintValueOptions *options) { +static void JS_PrintValueInternal (JSRuntime *rt, JSContext *ctx, + JSPrintValueWrite *write_func, + void *write_opaque, JSValue val, + const JSPrintValueOptions *options) { JSPrintValueState ss, *s = &ss; if (options) s->options = *options; @@ -7943,51 +7673,46 @@ JS_PrintValueInternal (JSRuntime *rt, JSContext *ctx, js_print_value (s, val); } -void -JS_PrintValueRT (JSRuntime *rt, JSPrintValueWrite *write_func, - void *write_opaque, JSValue val, - const JSPrintValueOptions *options) { +void JS_PrintValueRT (JSRuntime *rt, JSPrintValueWrite *write_func, + void *write_opaque, JSValue val, + const JSPrintValueOptions *options) { JS_PrintValueInternal (rt, NULL, write_func, write_opaque, val, options); } -void -JS_PrintValue (JSContext *ctx, JSPrintValueWrite *write_func, - void *write_opaque, JSValue val, - const JSPrintValueOptions *options) { +void JS_PrintValue (JSContext *ctx, JSPrintValueWrite *write_func, + void *write_opaque, JSValue val, + const JSPrintValueOptions *options) { JS_PrintValueInternal (ctx->rt, ctx, write_func, write_opaque, val, options); } -static void -js_dump_value_write (void *opaque, const char *buf, size_t len) { +static void js_dump_value_write (void *opaque, const char *buf, size_t len) { FILE *fo = opaque; fwrite (buf, 1, len, fo); } /* print_atom removed - atoms no longer used */ -static __maybe_unused void -JS_DumpValue (JSContext *ctx, const char *str, JSValue val) { +static __maybe_unused void JS_DumpValue (JSContext *ctx, const char *str, + JSValue val) { printf ("%s=", str); JS_PrintValue (ctx, js_dump_value_write, stdout, val, NULL); printf ("\n"); } -static __maybe_unused void -JS_DumpValueRT (JSRuntime *rt, const char *str, JSValue val) { +static __maybe_unused void JS_DumpValueRT (JSRuntime *rt, const char *str, + JSValue val) { printf ("%s=", str); JS_PrintValueRT (rt, js_dump_value_write, stdout, val, NULL); printf ("\n"); } -static __maybe_unused void -JS_DumpObjectHeader (JSRuntime *rt) { +static __maybe_unused void JS_DumpObjectHeader (JSRuntime *rt) { printf ("%14s %4s %4s %14s %s\n", "ADDRESS", "REFS", "SHRF", "PROTO", "CONTENT"); } /* for debug only: dump an object without side effect */ -static __maybe_unused void -JS_DumpObject (JSRuntime *rt, JSObject *p) { +static __maybe_unused void JS_DumpObject (JSRuntime *rt, JSObject *p) { JSPrintValueOptions options; JSRecord *rec = (JSRecord *)p; @@ -8009,8 +7734,8 @@ JS_DumpObject (JSRuntime *rt, JSObject *p) { printf ("\n"); } -static __maybe_unused void -JS_DumpGCObject (JSRuntime *rt, JSGCObjectHeader *p) { +static __maybe_unused void JS_DumpGCObject (JSRuntime *rt, + JSGCObjectHeader *p) { if (p->gc_obj_type == JS_GC_OBJ_TYPE_JS_OBJECT) { JS_DumpObject (rt, (JSObject *)p); } else { @@ -8043,13 +7768,11 @@ JS_DumpGCObject (JSRuntime *rt, JSGCObjectHeader *p) { } /* return -1 if exception (proxy case) or TRUE/FALSE */ -int -JS_IsArray (JSContext *ctx, JSValue val) { +int JS_IsArray (JSContext *ctx, JSValue val) { return JS_VALUE_IS_INTRINSIC_ARRAY (val); } -static double -js_pow (double a, double b) { +static double js_pow (double a, double b) { if (unlikely (!isfinite (b)) && fabs (a) == 1) { /* not compatible with IEEE 754 */ return NAN; @@ -8116,14 +7839,13 @@ js_unary_arith_slow (JSContext *ctx, JSValue *sp, OPCodeEnum op) { return 0; } -static __exception int -js_post_inc_slow (JSContext *ctx, JSValue *sp, OPCodeEnum op) { +static __exception int js_post_inc_slow (JSContext *ctx, JSValue *sp, + OPCodeEnum op) { sp[0] = JS_DupValue (ctx, sp[-1]); return js_unary_arith_slow (ctx, sp + 1, op - OP_post_dec + OP_dec); } -static no_inline int -js_not_slow (JSContext *ctx, JSValue *sp) { +static no_inline int js_not_slow (JSContext *ctx, JSValue *sp) { JSValue op1; op1 = sp[-1]; @@ -8252,13 +7974,12 @@ exception: return -1; } -static inline BOOL -tag_is_string (uint32_t tag) { +static inline BOOL tag_is_string (uint32_t tag) { return tag == JS_TAG_STRING || tag == JS_TAG_STRING_IMM; } -static no_inline int -js_relational_slow (JSContext *ctx, JSValue *sp, OPCodeEnum op) { +static no_inline int js_relational_slow (JSContext *ctx, JSValue *sp, + OPCodeEnum op) { JSValue op1 = sp[-2], op2 = sp[-1]; uint32_t tag1 = JS_VALUE_GET_NORM_TAG (op1); uint32_t tag2 = JS_VALUE_GET_NORM_TAG (op2); @@ -8332,15 +8053,13 @@ exception: return -1; } -static BOOL -tag_is_number (uint32_t tag) { +static BOOL tag_is_number (uint32_t tag) { return (tag == JS_TAG_INT || tag == JS_TAG_FLOAT64); } /* XXX: Should take JSValue arguments */ -static BOOL -js_strict_eq2 (JSContext *ctx, JSValue op1, JSValue op2, - JSStrictEqModeEnum eq_mode) { +static BOOL js_strict_eq2 (JSContext *ctx, JSValue op1, JSValue op2, + JSStrictEqModeEnum eq_mode) { BOOL res; int tag1, tag2; double d1, d2; @@ -8426,38 +8145,33 @@ done_no_free: return res; } -static BOOL -js_strict_eq (JSContext *ctx, JSValue op1, JSValue op2) { +static BOOL js_strict_eq (JSContext *ctx, JSValue op1, JSValue op2) { return js_strict_eq2 (ctx, JS_DupValue (ctx, op1), JS_DupValue (ctx, op2), JS_EQ_STRICT); } -BOOL -JS_StrictEq (JSContext *ctx, JSValue op1, JSValue op2) { +BOOL JS_StrictEq (JSContext *ctx, JSValue op1, JSValue op2) { return js_strict_eq (ctx, op1, op2); } -static BOOL -js_same_value (JSContext *ctx, JSValue op1, JSValue op2) { +static BOOL js_same_value (JSContext *ctx, JSValue op1, JSValue op2) { return js_strict_eq2 (ctx, JS_DupValue (ctx, op1), JS_DupValue (ctx, op2), JS_EQ_SAME_VALUE); } -BOOL -JS_SameValue (JSContext *ctx, JSValue op1, JSValue op2) { +BOOL JS_SameValue (JSContext *ctx, JSValue op1, JSValue op2) { return js_same_value (ctx, op1, op2); } -static no_inline int -js_strict_eq_slow (JSContext *ctx, JSValue *sp, BOOL is_neq) { +static no_inline int js_strict_eq_slow (JSContext *ctx, JSValue *sp, + BOOL is_neq) { BOOL res; res = js_strict_eq2 (ctx, sp[-2], sp[-1], JS_EQ_STRICT); sp[-2] = JS_NewBool (ctx, res ^ is_neq); return 0; } -static __exception int -js_operator_in (JSContext *ctx, JSValue *sp) { +static __exception int js_operator_in (JSContext *ctx, JSValue *sp) { JSValue op1, op2; int ret; @@ -8476,8 +8190,7 @@ js_operator_in (JSContext *ctx, JSValue *sp) { return 0; } -static __exception int -js_operator_delete (JSContext *ctx, JSValue *sp) { +static __exception int js_operator_delete (JSContext *ctx, JSValue *sp) { JSValue op1, op2; int ret; @@ -8495,9 +8208,8 @@ js_operator_delete (JSContext *ctx, JSValue *sp) { /* XXX: not 100% compatible, but mozilla seems to use a similar implementation to ensure that caller in non strict mode does not throw (ES5 compatibility) */ -static JSValue -js_throw_type_error (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_throw_type_error (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { return JS_ThrowTypeError (ctx, "invalid property access"); } @@ -8505,9 +8217,8 @@ js_throw_type_error (JSContext *ctx, JSValue this_val, int argc, #define ARGUMENT_VAR_OFFSET 0x20000000 /* Access an Array's internal JSValue array if available */ -static BOOL -js_get_fast_array (JSContext *ctx, JSValue obj, JSValue **arrpp, - uint32_t *countp) { +static BOOL js_get_fast_array (JSContext *ctx, JSValue obj, JSValue **arrpp, + uint32_t *countp) { /* Fast path for intrinsic arrays */ if (JS_VALUE_IS_INTRINSIC_ARRAY (obj)) { JSArray *arr = JS_VALUE_GET_ARRAY (obj); @@ -8518,10 +8229,9 @@ js_get_fast_array (JSContext *ctx, JSValue obj, JSValue **arrpp, return FALSE; } -static __exception int -JS_CopyDataProperties (JSContext *ctx, JSValue target, - JSValue source, JSValue excluded, - BOOL setprop) { +static __exception int JS_CopyDataProperties (JSContext *ctx, JSValue target, + JSValue source, JSValue excluded, + BOOL setprop) { JSValue *keys; JSValue val; uint32_t i, key_count; @@ -8530,8 +8240,7 @@ JS_CopyDataProperties (JSContext *ctx, JSValue target, if (JS_VALUE_GET_TAG (source) != JS_TAG_OBJECT) return 0; /* Get all string keys from source */ - if (JS_GetOwnPropertyNames (ctx, &keys, &key_count, source)) - return -1; + if (JS_GetOwnPropertyNames (ctx, &keys, &key_count, source)) return -1; for (i = 0; i < key_count; i++) { /* Check if key is excluded */ @@ -8571,13 +8280,12 @@ exception: } /* only valid inside C functions */ -static JSValue -JS_GetActiveFunction (JSContext *ctx) { +static JSValue JS_GetActiveFunction (JSContext *ctx) { return ctx->rt->current_stack_frame->cur_func; } -static JSVarRef * -get_var_ref (JSContext *ctx, JSStackFrame *sf, int var_idx, BOOL is_arg) { +static JSVarRef *get_var_ref (JSContext *ctx, JSStackFrame *sf, int var_idx, + BOOL is_arg) { JSVarRef *var_ref; struct list_head *el; JSValue *pvalue; @@ -8605,9 +8313,9 @@ get_var_ref (JSContext *ctx, JSStackFrame *sf, int var_idx, BOOL is_arg) { return var_ref; } -static JSValue -js_closure2 (JSContext *ctx, JSValue func_obj, JSFunctionBytecode *b, - JSVarRef **cur_var_refs, JSStackFrame *sf) { +static JSValue js_closure2 (JSContext *ctx, JSValue func_obj, + JSFunctionBytecode *b, JSVarRef **cur_var_refs, + JSStackFrame *sf) { JSFunction *f; JSVarRef **var_refs; int i; @@ -8640,9 +8348,8 @@ fail: return JS_EXCEPTION; } -static JSValue -js_closure (JSContext *ctx, JSValue bfunc, JSVarRef **cur_var_refs, - JSStackFrame *sf) { +static JSValue js_closure (JSContext *ctx, JSValue bfunc, + JSVarRef **cur_var_refs, JSStackFrame *sf) { JSFunctionBytecode *b; JSValue func_obj; JSFunction *f; @@ -8660,7 +8367,8 @@ js_closure (JSContext *ctx, JSValue bfunc, JSVarRef **cur_var_refs, } f = JS_VALUE_GET_FUNCTION (func_obj); /* Use bytecode func_name if valid, otherwise empty string */ - f->name = JS_IsString (b->func_name) ? JS_DupValue (ctx, b->func_name) : JS_KEY_empty; + f->name = JS_IsString (b->func_name) ? JS_DupValue (ctx, b->func_name) + : JS_KEY_empty; f->length = b->arg_count; /* arity = total parameter count */ return func_obj; fail: @@ -8669,8 +8377,7 @@ fail: return JS_EXCEPTION; } -static void -close_var_refs (JSRuntime *rt, JSStackFrame *sf) { +static void close_var_refs (JSRuntime *rt, JSStackFrame *sf) { struct list_head *el, *el1; JSVarRef *var_ref; @@ -8685,8 +8392,7 @@ close_var_refs (JSRuntime *rt, JSStackFrame *sf) { } } -static void -close_lexical_var (JSContext *ctx, JSStackFrame *sf, int var_idx) { +static void close_lexical_var (JSContext *ctx, JSStackFrame *sf, int var_idx) { JSValue *pvalue; struct list_head *el, *el1; JSVarRef *var_ref; @@ -8706,9 +8412,8 @@ close_lexical_var (JSContext *ctx, JSStackFrame *sf, int var_idx) { #define JS_CALL_FLAG_COPY_ARGV (1 << 1) -static JSValue -js_call_c_function (JSContext *ctx, JSValue func_obj, - JSValue this_obj, int argc, JSValue *argv) { +static JSValue js_call_c_function (JSContext *ctx, JSValue func_obj, + JSValue this_obj, int argc, JSValue *argv) { JSRuntime *rt = ctx->rt; JSCFunctionType func; JSFunction *f; @@ -8809,9 +8514,9 @@ js_call_c_function (JSContext *ctx, JSValue func_obj, return ret_val; } -static JSValue -js_call_bound_function (JSContext *ctx, JSValue func_obj, - JSValue this_obj, int argc, JSValue *argv) { +static JSValue js_call_bound_function (JSContext *ctx, JSValue func_obj, + JSValue this_obj, int argc, + JSValue *argv) { JSFunction *f; JSBoundFunction *bf; JSValue *arg_buf; @@ -8842,8 +8547,8 @@ typedef enum { /* argv[] is modified if (flags & JS_CALL_FLAG_COPY_ARGV) = 0. */ #ifdef DUMP_PROFILE /* Sampling profiler: try to take a sample */ -static void -profile_try_sample (JSRuntime *rt, JSFunctionBytecode *b, const uint8_t *pc) { +static void profile_try_sample (JSRuntime *rt, JSFunctionBytecode *b, + const uint8_t *pc) { struct timeval now; long elapsed_us; @@ -8865,9 +8570,8 @@ profile_try_sample (JSRuntime *rt, JSFunctionBytecode *b, const uint8_t *pc) { } /* Helper function to record a call site */ -static void -profile_record_call_site (JSRuntime *rt, JSFunctionBytecode *b, - uint32_t pc_offset) { +static void profile_record_call_site (JSRuntime *rt, JSFunctionBytecode *b, + uint32_t pc_offset) { uint32_t i; /* Check if we already have this callsite */ for (i = 0; i < b->call_site_count; i++) { @@ -8889,9 +8593,8 @@ profile_record_call_site (JSRuntime *rt, JSFunctionBytecode *b, } /* Helper function to record a property access site */ -static void -profile_record_prop_site (JSRuntime *rt, JSFunctionBytecode *b, - uint32_t pc_offset, JSAtom atom) { +static void profile_record_prop_site (JSRuntime *rt, JSFunctionBytecode *b, + uint32_t pc_offset, JSAtom atom) { uint32_t i; /* Check if we already have this prop site */ for (i = 0; i < b->prop_site_count; i++) { @@ -8913,9 +8616,9 @@ profile_record_prop_site (JSRuntime *rt, JSFunctionBytecode *b, } #endif -static JSValue -JS_CallInternal (JSContext *caller_ctx, JSValue func_obj, - JSValue this_obj, int argc, JSValue *argv, int flags) { +static JSValue JS_CallInternal (JSContext *caller_ctx, JSValue func_obj, + JSValue this_obj, int argc, JSValue *argv, + int flags) { JSRuntime *rt = caller_ctx->rt; JSContext *ctx; JSFunction *f; @@ -9087,8 +8790,7 @@ restart: var_refs, sf); if (unlikely (JS_IsException (sp[-1]))) goto exception; BREAK; - CASE (OP_push_empty_string) - : *sp++ = JS_KEY_empty; + CASE (OP_push_empty_string) : *sp++ = JS_KEY_empty; BREAK; #endif CASE (OP_null) : *sp++ = JS_NULL; @@ -10035,7 +9737,7 @@ restart: OP_get_field2 is only emitted when a call immediately follows. */ if (JS_IsFunction (obj)) { val = JS_DupValue (ctx, key); /* "name" as JSValue string */ - *sp++ = val; /* stack becomes [func, "name"] */ + *sp++ = val; /* stack becomes [func, "name"] */ } else if (JS_VALUE_GET_TAG (obj) == JS_TAG_OBJECT && js_gc_obj_type (obj) == JS_GC_OBJ_TYPE_RECORD) { /* Record property access - use JSValue key directly */ @@ -10155,9 +9857,7 @@ restart: } else { JS_FreeValue (ctx, sp[-1]); } - if (is_computed) { - JS_FreeValue (ctx, sp[-2]); - } + if (is_computed) { JS_FreeValue (ctx, sp[-2]); } sp -= 1 + is_computed; if (unlikely (ret < 0)) goto exception; } @@ -10224,18 +9924,14 @@ restart: sf->cur_pc = pc; /* Create key from the property name on stack */ key = sp[-1]; - if (JS_IsString (key)) { - key = js_key_from_string (ctx, key); - } + if (JS_IsString (key)) { key = js_key_from_string (ctx, key); } if (unlikely (JS_IsNull (sp[-2]))) { JS_ThrowReferenceErrorNotDefined (ctx, key); goto exception; } ret = JS_HasProperty (ctx, sp[-2], key); if (unlikely (ret <= 0)) { - if (ret < 0) { - goto exception; - } + if (ret < 0) { goto exception; } JS_ThrowReferenceErrorNotDefined (ctx, key); goto exception; } else { @@ -10270,18 +9966,14 @@ restart: sf->cur_pc = pc; /* Create key from the property name on stack */ key = sp[-2]; - if (JS_IsString (key)) { - key = js_key_from_string (ctx, key); - } + if (JS_IsString (key)) { key = js_key_from_string (ctx, key); } if (unlikely (JS_IsNull (sp[-3]))) { JS_ThrowReferenceErrorNotDefined (ctx, key); goto exception; } ret = JS_HasProperty (ctx, sp[-3], key); if (unlikely (ret <= 0)) { - if (unlikely (ret < 0)) { - goto exception; - } + if (unlikely (ret < 0)) { goto exception; } JS_ThrowReferenceErrorNotDefined (ctx, key); goto exception; } @@ -11008,16 +10700,14 @@ done: return ret_val; } -JSValue -JS_Call (JSContext *ctx, JSValue func_obj, JSValue this_obj, - int argc, JSValue *argv) { +JSValue JS_Call (JSContext *ctx, JSValue func_obj, JSValue this_obj, int argc, + JSValue *argv) { return JS_CallInternal (ctx, func_obj, this_obj, argc, (JSValue *)argv, JS_CALL_FLAG_COPY_ARGV); } -static JSValue -JS_CallFree (JSContext *ctx, JSValue func_obj, JSValue this_obj, int argc, - JSValue *argv) { +static JSValue JS_CallFree (JSContext *ctx, JSValue func_obj, JSValue this_obj, + int argc, JSValue *argv) { JSValue res = JS_CallInternal (ctx, func_obj, this_obj, argc, (JSValue *)argv, JS_CALL_FLAG_COPY_ARGV); JS_FreeValue (ctx, func_obj); @@ -11026,8 +10716,7 @@ JS_CallFree (JSContext *ctx, JSValue func_obj, JSValue this_obj, int argc, /* warning: the refcount of the context is not incremented. Return NULL in case of exception (case of revoked proxy only) */ -static JSContext * -JS_GetFunctionRealm (JSContext *ctx, JSValue func_obj) { +static JSContext *JS_GetFunctionRealm (JSContext *ctx, JSValue func_obj) { JSFunction *f; JSContext *realm; @@ -11164,10 +10853,10 @@ enum { typedef struct BlockEnv { struct BlockEnv *prev; JSValue label_name; /* JS_NULL if none */ - int label_break; /* -1 if none */ - int label_cont; /* -1 if none */ - int drop_count; /* number of stack elements to drop */ - int label_finally; /* -1 if none */ + int label_break; /* -1 if none */ + int label_cont; /* -1 if none */ + int drop_count; /* number of stack elements to drop */ + int label_finally; /* -1 if none */ int scope_level; uint8_t is_regular_stmt : 1; /* i.e. not a loop statement */ } BlockEnv; @@ -11250,7 +10939,7 @@ typedef struct JSFunctionDef { function */ BOOL in_function_body; JSParseFunctionEnum func_type : 8; - uint8_t js_mode; /* bitmap of JS_MODE_x */ + uint8_t js_mode; /* bitmap of JS_MODE_x */ JSValue func_name; /* JS_NULL if no name */ JSVarDef *vars; @@ -11313,8 +11002,8 @@ typedef struct JSFunctionDef { int line_number_last_pc; /* pc2line table */ - BOOL - strip_debug : 1; /* strip all debug info (implies strip_source = TRUE) */ + BOOL strip_debug + : 1; /* strip all debug info (implies strip_source = TRUE) */ BOOL strip_source : 1; /* strip only source code */ JSAtom filename; uint32_t source_pos; /* pointer in the eval() source */ @@ -11337,7 +11026,7 @@ typedef struct JSToken { JSValue val; } num; struct { - JSValue str; /* identifier as JSValue text */ + JSValue str; /* identifier as JSValue text */ BOOL has_escape; BOOL is_reserved; } ident; @@ -11403,8 +11092,7 @@ static const JSOpCode opcode_info[OP_COUNT + (OP_TEMP_END - OP_TEMP_START)] = { static __exception int next_token (JSParseState *s); -static void -free_token (JSParseState *s, JSToken *token) { +static void free_token (JSParseState *s, JSToken *token) { switch (token->val) { case TOK_NUMBER: JS_FreeValue (s->ctx, token->u.num.val); @@ -11428,8 +11116,8 @@ free_token (JSParseState *s, JSToken *token) { } } -static void __attribute ((unused)) -dump_token (JSParseState *s, const JSToken *token) { +static void __attribute ((unused)) dump_token (JSParseState *s, + const JSToken *token) { switch (token->val) { case TOK_NUMBER: { double d; @@ -11480,8 +11168,7 @@ dump_token (JSParseState *s, const JSToken *token) { /* return the zero based line and column number in the source. */ /* Note: we no longer support '\r' as line terminator */ -static int -get_line_col (int *pcol_num, const uint8_t *buf, size_t len) { +static int get_line_col (int *pcol_num, const uint8_t *buf, size_t len) { int line_num, col_num, c; size_t i; @@ -11500,8 +11187,8 @@ get_line_col (int *pcol_num, const uint8_t *buf, size_t len) { return line_num; } -static int -get_line_col_cached (GetLineColCache *s, int *pcol_num, const uint8_t *ptr) { +static int get_line_col_cached (GetLineColCache *s, int *pcol_num, + const uint8_t *ptr) { int line_num, col_num; if (ptr >= s->ptr) { line_num = get_line_col (&col_num, s->ptr, ptr - s->ptr); @@ -11536,9 +11223,8 @@ get_line_col_cached (GetLineColCache *s, int *pcol_num, const uint8_t *ptr) { } /* 'ptr' is the position of the error in the source */ -static int -js_parse_error_v (JSParseState *s, const uint8_t *ptr, const char *fmt, - va_list ap) { +static int js_parse_error_v (JSParseState *s, const uint8_t *ptr, + const char *fmt, va_list ap) { JSContext *ctx = s->ctx; int line_num, col_num; line_num = get_line_col (&col_num, s->buf_start, ptr - s->buf_start); @@ -11571,8 +11257,7 @@ js_parse_error (JSParseState *s, const char *fmt, ...) { return ret; } -static int -js_parse_expect (JSParseState *s, int tok) { +static int js_parse_expect (JSParseState *s, int tok) { if (s->token.val != tok) { /* XXX: dump token correctly in all cases */ return js_parse_error (s, "expecting '%c'", tok); @@ -11580,8 +11265,7 @@ js_parse_expect (JSParseState *s, int tok) { return next_token (s); } -static int -js_parse_expect_semi (JSParseState *s) { +static int js_parse_expect_semi (JSParseState *s) { if (s->token.val != ';') { /* automatic insertion of ';' */ if (s->token.val == TOK_EOF || s->token.val == '}' || s->got_lf) { @@ -11592,16 +11276,15 @@ js_parse_expect_semi (JSParseState *s) { return next_token (s); } -static int -js_parse_error_reserved_identifier (JSParseState *s) { +static int js_parse_error_reserved_identifier (JSParseState *s) { char buf1[ATOM_GET_STR_BUF_SIZE]; return js_parse_error ( s, "'%s' is a reserved identifier", JS_AtomGetStr (s->ctx, buf1, sizeof (buf1), s->token.u.ident.str)); } -static __exception int -js_parse_template_part (JSParseState *s, const uint8_t *p) { +static __exception int js_parse_template_part (JSParseState *s, + const uint8_t *p) { uint32_t c; StringBuffer b_s, *b = &b_s; JSValue str; @@ -11656,9 +11339,9 @@ fail: return -1; } -static __exception int -js_parse_string (JSParseState *s, int sep, BOOL do_throw, const uint8_t *p, - JSToken *token, const uint8_t **pp) { +static __exception int js_parse_string (JSParseState *s, int sep, + BOOL do_throw, const uint8_t *p, + JSToken *token, const uint8_t **pp) { int ret; uint32_t c; StringBuffer b_s, *b = &b_s; @@ -11778,14 +11461,12 @@ fail: return -1; } -static inline BOOL -token_is_pseudo_keyword (JSParseState *s, JSValue key) { +static inline BOOL token_is_pseudo_keyword (JSParseState *s, JSValue key) { return s->token.val == TOK_IDENT && js_key_equal (s->token.u.ident.str, key) && !s->token.u.ident.has_escape; } -static __exception int -js_parse_regexp (JSParseState *s) { +static __exception int js_parse_regexp (JSParseState *s) { const uint8_t *p; BOOL in_class; StringBuffer b_s, *b = &b_s; @@ -11881,8 +11562,8 @@ fail: return -1; } -static __exception int -ident_realloc (JSContext *ctx, char **pbuf, size_t *psize, char *static_buf) { +static __exception int ident_realloc (JSContext *ctx, char **pbuf, + size_t *psize, char *static_buf) { char *buf, *new_buf; size_t size, new_size; @@ -11961,11 +11642,10 @@ static const JSKeywordEntry js_keywords[] = { { "await", TOK_AWAIT, TRUE }, }; -#define JS_KEYWORD_COUNT (sizeof(js_keywords) / sizeof(js_keywords[0])) +#define JS_KEYWORD_COUNT (sizeof (js_keywords) / sizeof (js_keywords[0])) /* lookup keyword by JSValue string, return token or -1 if not found */ -static int -js_keyword_lookup (JSValue str, BOOL *is_strict_reserved) { +static int js_keyword_lookup (JSValue str, BOOL *is_strict_reserved) { char buf[16]; const char *cstr; size_t len; @@ -11994,8 +11674,7 @@ js_keyword_lookup (JSValue str, BOOL *is_strict_reserved) { } /* convert a TOK_IDENT to a keyword when needed */ -static void -update_token_ident (JSParseState *s) { +static void update_token_ident (JSParseState *s) { BOOL is_strict_reserved = FALSE; int token = js_keyword_lookup (s->token.u.ident.str, &is_strict_reserved); @@ -12012,8 +11691,7 @@ update_token_ident (JSParseState *s) { /* if the current token is an identifier or keyword, reparse it according to the current function type */ -static void -reparse_ident_token (JSParseState *s) { +static void reparse_ident_token (JSParseState *s) { if (s->token.val == TOK_IDENT || (s->token.val >= TOK_FIRST_KEYWORD && s->token.val <= TOK_LAST_KEYWORD)) { @@ -12024,9 +11702,8 @@ reparse_ident_token (JSParseState *s) { } /* 'c' is the first character. Return JS_NULL in case of error */ -static JSValue -parse_ident (JSParseState *s, const uint8_t **pp, BOOL *pident_has_escape, - int c) { +static JSValue parse_ident (JSParseState *s, const uint8_t **pp, + BOOL *pident_has_escape, int c) { const uint8_t *p, *p1; char ident_buf[128], *buf; size_t ident_size, ident_pos; @@ -12068,8 +11745,7 @@ done: return str; } -static __exception int -next_token (JSParseState *s) { +static __exception int next_token (JSParseState *s) { const uint8_t *p; int c; BOOL ident_has_escape; @@ -12499,8 +12175,7 @@ fail: /* 'c' is the first character. Return JS_NULL in case of error */ /* XXX: accept unicode identifiers as JSON5 ? */ -static JSValue -json_parse_ident (JSParseState *s, const uint8_t **pp, int c) { +static JSValue json_parse_ident (JSParseState *s, const uint8_t **pp, int c) { const uint8_t *p; char ident_buf[128], *buf; size_t ident_size, ident_pos; @@ -12530,8 +12205,7 @@ done: return str; } -static int -json_parse_string (JSParseState *s, const uint8_t **pp, int sep) { +static int json_parse_string (JSParseState *s, const uint8_t **pp, int sep) { const uint8_t *p, *p_next; int i; uint32_t c; @@ -12620,8 +12294,7 @@ fail: return -1; } -static int -json_parse_number (JSParseState *s, const uint8_t **pp) { +static int json_parse_number (JSParseState *s, const uint8_t **pp) { const uint8_t *p = *pp; const uint8_t *p_start = p; int radix; @@ -12701,8 +12374,7 @@ done: return 0; } -static __exception int -json_next_token (JSParseState *s) { +static __exception int json_next_token (JSParseState *s) { const uint8_t *p; int c; JSValue ident_str; @@ -12905,8 +12577,7 @@ fail: return -1; } -static int -match_identifier (const uint8_t *p, const char *s) { +static int match_identifier (const uint8_t *p, const char *s) { uint32_t c; while (*s) { if ((uint8_t)*s++ != *p++) return 0; @@ -12927,8 +12598,7 @@ match_identifier (const uint8_t *p, const char *s) { - TOK_IDENT is returned for other identifiers and keywords - otherwise the next character or unicode codepoint is returned. */ -static int -simple_next_token (const uint8_t **pp, BOOL no_line_terminator) { +static int simple_next_token (const uint8_t **pp, BOOL no_line_terminator) { const uint8_t *p; uint32_t c; @@ -13001,22 +12671,19 @@ simple_next_token (const uint8_t **pp, BOOL no_line_terminator) { } } -static int -peek_token (JSParseState *s, BOOL no_line_terminator) { +static int peek_token (JSParseState *s, BOOL no_line_terminator) { const uint8_t *p = s->buf_ptr; return simple_next_token (&p, no_line_terminator); } -static inline int -get_prev_opcode (JSFunctionDef *fd) { +static inline int get_prev_opcode (JSFunctionDef *fd) { if (fd->last_opcode_pos < 0 || dbuf_error (&fd->byte_code)) return OP_invalid; else return fd->byte_code.buf[fd->last_opcode_pos]; } -static BOOL -js_is_live_code (JSParseState *s) { +static BOOL js_is_live_code (JSParseState *s) { switch (get_prev_opcode (s->cur_func)) { case OP_tail_call: case OP_tail_call_method: @@ -13036,23 +12703,19 @@ js_is_live_code (JSParseState *s) { } } -static void -emit_u8 (JSParseState *s, uint8_t val) { +static void emit_u8 (JSParseState *s, uint8_t val) { dbuf_putc (&s->cur_func->byte_code, val); } -static void -emit_u16 (JSParseState *s, uint16_t val) { +static void emit_u16 (JSParseState *s, uint16_t val) { dbuf_put_u16 (&s->cur_func->byte_code, val); } -static void -emit_u32 (JSParseState *s, uint32_t val) { +static void emit_u32 (JSParseState *s, uint32_t val) { dbuf_put_u32 (&s->cur_func->byte_code, val); } -static void -emit_source_pos (JSParseState *s, const uint8_t *source_ptr) { +static void emit_source_pos (JSParseState *s, const uint8_t *source_ptr) { JSFunctionDef *fd = s->cur_func; DynBuf *bc = &fd->byte_code; @@ -13063,8 +12726,7 @@ emit_source_pos (JSParseState *s, const uint8_t *source_ptr) { } } -static void -emit_op (JSParseState *s, uint8_t val) { +static void emit_op (JSParseState *s, uint8_t val) { JSFunctionDef *fd = s->cur_func; DynBuf *bc = &fd->byte_code; @@ -13078,23 +12740,19 @@ static int cpool_add (JSParseState *s, JSValue val); /* Emit a key (JSValue) by adding to cpool and emitting the index. Used for variable opcodes (get_var, put_var, etc.) and property ops. */ -static int -emit_key (JSParseState *s, JSValue name) { +static int emit_key (JSParseState *s, JSValue name) { int idx = cpool_add (s, JS_DupValue (s->ctx, name)); if (idx < 0) return -1; emit_u32 (s, idx); return 0; } - /* Emit a property key for field access opcodes. */ -static int -emit_prop_key (JSParseState *s, JSValue key) { +static int emit_prop_key (JSParseState *s, JSValue key) { return emit_key (s, key); } -static int -update_label (JSFunctionDef *s, int label, int delta) { +static int update_label (JSFunctionDef *s, int label, int delta) { LabelSlot *ls; assert (label >= 0 && label < s->label_count); @@ -13104,8 +12762,7 @@ update_label (JSFunctionDef *s, int label, int delta) { return ls->ref_count; } -static int -new_label_fd (JSFunctionDef *fd) { +static int new_label_fd (JSFunctionDef *fd) { int label; LabelSlot *ls; @@ -13123,8 +12780,7 @@ new_label_fd (JSFunctionDef *fd) { return label; } -static int -new_label (JSParseState *s) { +static int new_label (JSParseState *s) { int label; label = new_label_fd (s->cur_func); if (unlikely (label < 0)) { dbuf_set_error (&s->cur_func->byte_code); } @@ -13132,16 +12788,14 @@ new_label (JSParseState *s) { } /* don't update the last opcode and don't emit line number info */ -static void -emit_label_raw (JSParseState *s, int label) { +static void emit_label_raw (JSParseState *s, int label) { emit_u8 (s, OP_label); emit_u32 (s, label); s->cur_func->label_slots[label].pos = s->cur_func->byte_code.size; } /* return the label ID offset */ -static int -emit_label (JSParseState *s, int label) { +static int emit_label (JSParseState *s, int label) { if (label >= 0) { emit_op (s, OP_label); emit_u32 (s, label); @@ -13153,8 +12807,7 @@ emit_label (JSParseState *s, int label) { } /* return label or -1 if dead code */ -static int -emit_goto (JSParseState *s, int opcode, int label) { +static int emit_goto (JSParseState *s, int opcode, int label) { if (js_is_live_code (s)) { if (label < 0) { label = new_label (s); @@ -13169,8 +12822,7 @@ emit_goto (JSParseState *s, int opcode, int label) { } /* return the constant pool index. 'val' is not duplicated. */ -static int -fd_cpool_add (JSContext *ctx, JSFunctionDef *fd, JSValue val) { +static int fd_cpool_add (JSContext *ctx, JSFunctionDef *fd, JSValue val) { if (js_resize_array (ctx, (void *)&fd->cpool, sizeof (fd->cpool[0]), &fd->cpool_size, fd->cpool_count + 1)) return -1; @@ -13179,13 +12831,11 @@ fd_cpool_add (JSContext *ctx, JSFunctionDef *fd, JSValue val) { } /* return the constant pool index. 'val' is not duplicated. */ -static int -cpool_add (JSParseState *s, JSValue val) { +static int cpool_add (JSParseState *s, JSValue val) { return fd_cpool_add (s->ctx, s->cur_func, val); } -static __exception int -emit_push_const (JSParseState *s, JSValue val) { +static __exception int emit_push_const (JSParseState *s, JSValue val) { int idx; idx = cpool_add (s, JS_DupValue (s->ctx, val)); if (idx < 0) return -1; @@ -13196,8 +12846,7 @@ emit_push_const (JSParseState *s, JSValue val) { /* return the variable index or -1 if not found, add ARGUMENT_VAR_OFFSET for argument variables */ -static int -find_arg (JSContext *ctx, JSFunctionDef *fd, JSAtom name) { +static int find_arg (JSContext *ctx, JSFunctionDef *fd, JSAtom name) { int i; for (i = fd->arg_count; i-- > 0;) { if (fd->args[i].var_name == name) return i | ARGUMENT_VAR_OFFSET; @@ -13205,8 +12854,7 @@ find_arg (JSContext *ctx, JSFunctionDef *fd, JSAtom name) { return -1; } -static int -find_var (JSContext *ctx, JSFunctionDef *fd, JSAtom name) { +static int find_var (JSContext *ctx, JSFunctionDef *fd, JSAtom name) { int i; for (i = fd->var_count; i-- > 0;) { if (fd->vars[i].var_name == name && fd->vars[i].scope_level == 0) return i; @@ -13216,9 +12864,8 @@ find_var (JSContext *ctx, JSFunctionDef *fd, JSAtom name) { /* return true if scope == parent_scope or if scope is a child of parent_scope */ -static BOOL -is_child_scope (JSContext *ctx, JSFunctionDef *fd, int scope, - int parent_scope) { +static BOOL is_child_scope (JSContext *ctx, JSFunctionDef *fd, int scope, + int parent_scope) { while (scope >= 0) { if (scope == parent_scope) return TRUE; scope = fd->scopes[scope].parent; @@ -13227,9 +12874,8 @@ is_child_scope (JSContext *ctx, JSFunctionDef *fd, int scope, } /* find a 'var' declaration in the same scope or a child scope */ -static int -find_var_in_child_scope (JSContext *ctx, JSFunctionDef *fd, JSAtom name, - int scope_level) { +static int find_var_in_child_scope (JSContext *ctx, JSFunctionDef *fd, + JSAtom name, int scope_level) { int i; for (i = 0; i < fd->var_count; i++) { JSVarDef *vd = &fd->vars[i]; @@ -13240,8 +12886,7 @@ find_var_in_child_scope (JSContext *ctx, JSFunctionDef *fd, JSAtom name, return -1; } -static JSGlobalVar * -find_global_var (JSFunctionDef *fd, JSValue name) { +static JSGlobalVar *find_global_var (JSFunctionDef *fd, JSValue name) { int i; for (i = 0; i < fd->global_var_count; i++) { JSGlobalVar *hf = &fd->global_vars[i]; @@ -13250,8 +12895,7 @@ find_global_var (JSFunctionDef *fd, JSValue name) { return NULL; } -static JSGlobalVar * -find_lexical_global_var (JSFunctionDef *fd, JSValue name) { +static JSGlobalVar *find_lexical_global_var (JSFunctionDef *fd, JSValue name) { JSGlobalVar *hf = find_global_var (fd, name); if (hf && hf->is_lexical) return hf; @@ -13259,9 +12903,8 @@ find_lexical_global_var (JSFunctionDef *fd, JSValue name) { return NULL; } -static int -find_lexical_decl (JSContext *ctx, JSFunctionDef *fd, JSValue name, - int scope_idx, BOOL check_catch_var) { +static int find_lexical_decl (JSContext *ctx, JSFunctionDef *fd, JSValue name, + int scope_idx, BOOL check_catch_var) { while (scope_idx >= 0) { JSVarDef *vd = &fd->vars[scope_idx]; if (js_key_equal (vd->var_name, name) @@ -13277,8 +12920,7 @@ find_lexical_decl (JSContext *ctx, JSFunctionDef *fd, JSValue name, return -1; } -static int -push_scope (JSParseState *s) { +static int push_scope (JSParseState *s) { if (s->cur_func) { JSFunctionDef *fd = s->cur_func; int scope = fd->scope_count; @@ -13313,8 +12955,7 @@ push_scope (JSParseState *s) { return 0; } -static int -get_first_lexical_var (JSFunctionDef *fd, int scope) { +static int get_first_lexical_var (JSFunctionDef *fd, int scope) { while (scope >= 0) { int scope_idx = fd->scopes[scope].first; if (scope_idx >= 0) return scope_idx; @@ -13323,8 +12964,7 @@ get_first_lexical_var (JSFunctionDef *fd, int scope) { return -1; } -static void -pop_scope (JSParseState *s) { +static void pop_scope (JSParseState *s) { if (s->cur_func) { /* disable scoped variables */ JSFunctionDef *fd = s->cur_func; @@ -13336,8 +12976,7 @@ pop_scope (JSParseState *s) { } } -static void -close_scopes (JSParseState *s, int scope, int scope_stop) { +static void close_scopes (JSParseState *s, int scope, int scope_stop) { while (scope > scope_stop) { emit_op (s, OP_leave_scope); emit_u16 (s, scope); @@ -13346,8 +12985,7 @@ close_scopes (JSParseState *s, int scope, int scope_stop) { } /* return the variable index or -1 if error */ -static int -add_var (JSContext *ctx, JSFunctionDef *fd, JSValue name) { +static int add_var (JSContext *ctx, JSFunctionDef *fd, JSValue name) { JSVarDef *vd; /* the local variable indexes are currently stored on 16 bits */ @@ -13365,9 +13003,8 @@ add_var (JSContext *ctx, JSFunctionDef *fd, JSValue name) { return fd->var_count - 1; } -static int -add_scope_var (JSContext *ctx, JSFunctionDef *fd, JSValue name, - JSVarKindEnum var_kind) { +static int add_scope_var (JSContext *ctx, JSFunctionDef *fd, JSValue name, + JSVarKindEnum var_kind) { int idx = add_var (ctx, fd, name); if (idx >= 0) { JSVarDef *vd = &fd->vars[idx]; @@ -13380,8 +13017,7 @@ add_scope_var (JSContext *ctx, JSFunctionDef *fd, JSValue name, return idx; } -static int -add_func_var (JSContext *ctx, JSFunctionDef *fd, JSValue name) { +static int add_func_var (JSContext *ctx, JSFunctionDef *fd, JSValue name) { int idx = fd->func_var_idx; if (idx < 0 && (idx = add_var (ctx, fd, name)) >= 0) { fd->func_var_idx = idx; @@ -13391,8 +13027,7 @@ add_func_var (JSContext *ctx, JSFunctionDef *fd, JSValue name) { return idx; } -static int -add_arg (JSContext *ctx, JSFunctionDef *fd, JSValue name) { +static int add_arg (JSContext *ctx, JSFunctionDef *fd, JSValue name) { JSVarDef *vd; /* the local variable indexes are currently stored on 16 bits */ @@ -13411,8 +13046,8 @@ add_arg (JSContext *ctx, JSFunctionDef *fd, JSValue name) { } /* add a global variable definition */ -static JSGlobalVar * -add_global_var (JSContext *ctx, JSFunctionDef *s, JSValue name) { +static JSGlobalVar *add_global_var (JSContext *ctx, JSFunctionDef *s, + JSValue name) { JSGlobalVar *hf; if (js_resize_array (ctx, (void **)&s->global_vars, @@ -13439,9 +13074,8 @@ typedef enum { JS_VAR_DEF_VAR, } JSVarDefEnum; -static int -define_var (JSParseState *s, JSFunctionDef *fd, JSValue name, - JSVarDefEnum var_def_type) { +static int define_var (JSParseState *s, JSFunctionDef *fd, JSValue name, + JSVarDefEnum var_def_type) { JSContext *ctx = s->ctx; JSVarDef *vd; int idx; @@ -13566,8 +13200,8 @@ static void push_break_entry (JSFunctionDef *fd, BlockEnv *be, int label_cont, int drop_count); static void pop_break_entry (JSFunctionDef *fd); -static __exception int -js_parse_template (JSParseState *s, int call, int *argc) { +static __exception int js_parse_template (JSParseState *s, int call, + int *argc) { JSContext *ctx = s->ctx; JSValue raw_array, template_object; JSToken cooked; @@ -13663,17 +13297,16 @@ done1: #define PROP_TYPE_IDENT 0 #define PROP_TYPE_VAR 1 -static BOOL -token_is_ident (int tok) { +static BOOL token_is_ident (int tok) { /* Accept keywords and reserved words as property names */ return (tok == TOK_IDENT || (tok >= TOK_FIRST_KEYWORD && tok <= TOK_LAST_KEYWORD)); } /* if the property is an expression, name = JS_NULL */ -static int __exception -js_parse_property_name (JSParseState *s, JSValue *pname, BOOL allow_method, - BOOL allow_var) { +static int __exception js_parse_property_name (JSParseState *s, JSValue *pname, + BOOL allow_method, + BOOL allow_var) { BOOL is_non_reserved_ident; JSValue name; int prop_type; @@ -13731,23 +13364,21 @@ typedef struct JSParsePos { const uint8_t *ptr; } JSParsePos; -static int -js_parse_get_pos (JSParseState *s, JSParsePos *sp) { +static int js_parse_get_pos (JSParseState *s, JSParsePos *sp) { sp->ptr = s->token.ptr; sp->got_lf = s->got_lf; return 0; } -static __exception int -js_parse_seek_token (JSParseState *s, const JSParsePos *sp) { +static __exception int js_parse_seek_token (JSParseState *s, + const JSParsePos *sp) { s->buf_ptr = sp->ptr; s->got_lf = sp->got_lf; return next_token (s); } /* return TRUE if a regexp literal is allowed after this token */ -static BOOL -is_regexp_allowed (int tok) { +static BOOL is_regexp_allowed (int tok) { switch (tok) { case TOK_NUMBER: case TOK_STRING: @@ -13771,8 +13402,7 @@ is_regexp_allowed (int tok) { #define SKIP_HAS_SEMI (1 << 0) #define SKIP_HAS_ASSIGNMENT (1 << 1) -static BOOL -has_lf_in_range (const uint8_t *p1, const uint8_t *p2) { +static BOOL has_lf_in_range (const uint8_t *p1, const uint8_t *p2) { const uint8_t *tmp; if (p1 > p2) { tmp = p1; @@ -13785,9 +13415,8 @@ has_lf_in_range (const uint8_t *p1, const uint8_t *p2) { /* XXX: improve speed with early bailout */ /* XXX: no longer works if regexps are present. Could use previous regexp parsing heuristics to handle most cases */ -static int -js_parse_skip_parens_token (JSParseState *s, int *pbits, - BOOL no_line_terminator) { +static int js_parse_skip_parens_token (JSParseState *s, int *pbits, + BOOL no_line_terminator) { char state[256]; size_t level = 0; JSParsePos pos; @@ -13888,8 +13517,7 @@ done: return tok; } -static void -set_object_name (JSParseState *s, JSValue name) { +static void set_object_name (JSParseState *s, JSValue name) { JSFunctionDef *fd = s->cur_func; int opcode; @@ -13913,8 +13541,7 @@ set_object_name (JSParseState *s, JSValue name) { } } -static void -set_object_name_computed (JSParseState *s) { +static void set_object_name_computed (JSParseState *s) { JSFunctionDef *fd = s->cur_func; int opcode; @@ -13934,8 +13561,7 @@ set_object_name_computed (JSParseState *s) { } } -static __exception int -js_parse_object_literal (JSParseState *s) { +static __exception int js_parse_object_literal (JSParseState *s) { JSValue name = JS_NULL; const uint8_t *start_ptr; int prop_type; @@ -13963,8 +13589,7 @@ js_parse_object_literal (JSParseState *s) { int op_flags; func_type = JS_PARSE_FUNC_METHOD; - if (js_parse_function_decl (s, func_type, JS_NULL, start_ptr)) - goto fail; + if (js_parse_function_decl (s, func_type, JS_NULL, start_ptr)) goto fail; if (JS_IsNull (name)) { emit_op (s, OP_define_method_computed); } else { @@ -14023,15 +13648,13 @@ js_new_function_def (JSContext *ctx, JSFunctionDef *parent, BOOL is_eval, GetLineColCache *get_line_col_cache); static void emit_return (JSParseState *s, BOOL hasval); -static __exception int -js_parse_left_hand_side_expr (JSParseState *s) { +static __exception int js_parse_left_hand_side_expr (JSParseState *s) { return js_parse_postfix_expr (s, PF_POSTFIX_CALL); } #define ARRAY_LITERAL_MAX 1024 -static __exception int -js_parse_array_literal (JSParseState *s) { +static __exception int js_parse_array_literal (JSParseState *s) { uint32_t idx = 0; if (next_token (s)) return -1; @@ -14058,8 +13681,7 @@ js_parse_array_literal (JSParseState *s) { } /* XXX: remove */ -static BOOL -has_with_scope (JSFunctionDef *s, int scope_level) { +static BOOL has_with_scope (JSFunctionDef *s, int scope_level) { /* check if scope chain contains a with statement */ while (s) { int scope_idx = s->scopes[scope_level].first; @@ -14076,9 +13698,9 @@ has_with_scope (JSFunctionDef *s, int scope_level) { return FALSE; } -static __exception int -get_lvalue (JSParseState *s, int *popcode, int *pscope, JSValue *pname, - int *plabel, int *pdepth, BOOL keep, int tok) { +static __exception int get_lvalue (JSParseState *s, int *popcode, int *pscope, + JSValue *pname, int *plabel, int *pdepth, + BOOL keep, int tok) { JSFunctionDef *fd; int opcode, scope, label, depth; JSValue name; @@ -14099,7 +13721,8 @@ get_lvalue (JSParseState *s, int *popcode, int *pscope, JSValue *pname, JS_FreeValue (s->ctx, name); return js_parse_error (s, "invalid lvalue in strict mode"); } - if (js_key_equal_str (name, "this") || js_key_equal_str (name, "new.target")) { + if (js_key_equal_str (name, "this") + || js_key_equal_str (name, "new.target")) { JS_FreeValue (s->ctx, name); goto invalid_lvalue; } @@ -14194,9 +13817,8 @@ typedef enum { /* name has a live reference. 'is_let' is only used with opcode = OP_scope_get_var which is never generated by get_lvalue(). */ -static void -put_lvalue (JSParseState *s, int opcode, int scope, JSValue name, int label, - PutLValueEnum special, BOOL is_let) { +static void put_lvalue (JSParseState *s, int opcode, int scope, JSValue name, + int label, PutLValueEnum special, BOOL is_let) { switch (opcode) { case OP_get_field: /* depth = 1 */ @@ -14270,23 +13892,20 @@ put_lvalue (JSParseState *s, int opcode, int scope, JSValue name, int label, } } -static __exception int -js_parse_expr_paren (JSParseState *s) { +static __exception int js_parse_expr_paren (JSParseState *s) { if (js_parse_expect (s, '(')) return -1; if (js_parse_expr (s)) return -1; if (js_parse_expect (s, ')')) return -1; return 0; } -static int -js_unsupported_keyword (JSParseState *s, JSAtom atom) { +static int js_unsupported_keyword (JSParseState *s, JSAtom atom) { char buf[ATOM_GET_STR_BUF_SIZE]; return js_parse_error (s, "unsupported keyword: %s", JS_AtomGetStr (s->ctx, buf, sizeof (buf), atom)); } -static __exception int -js_define_var (JSParseState *s, JSValue name, int tok) { +static __exception int js_define_var (JSParseState *s, JSValue name, int tok) { JSFunctionDef *fd = s->cur_func; JSVarDefEnum var_def_type; @@ -14313,8 +13932,7 @@ js_define_var (JSParseState *s, JSValue name, int tok) { return 0; } -static int -js_parse_check_duplicate_parameter (JSParseState *s, JSValue name) { +static int js_parse_check_duplicate_parameter (JSParseState *s, JSValue name) { /* Check for duplicate parameter names */ JSFunctionDef *fd = s->cur_func; int i; @@ -14331,8 +13949,8 @@ duplicate: s, "duplicate parameter names not allowed in this context"); } -static JSValue -js_parse_destructuring_var (JSParseState *s, int tok, int is_arg) { +static JSValue js_parse_destructuring_var (JSParseState *s, int tok, + int is_arg) { JSValue name; if (!(s->token.val == TOK_IDENT && !s->token.u.ident.is_reserved) @@ -14352,10 +13970,10 @@ fail: /* Return -1 if error, 0 if no initializer, 1 if an initializer is present at the top level. */ -static int -js_parse_destructuring_element (JSParseState *s, int tok, int is_arg, - int hasval, BOOL allow_initializer, - BOOL export_flag) { +static int js_parse_destructuring_element (JSParseState *s, int tok, + int is_arg, int hasval, + BOOL allow_initializer, + BOOL export_flag) { int label_parse, label_assign, label_done, label_lvalue, depth_lvalue; int start_addr, assign_addr; JSValue prop_name, var_name; @@ -14580,9 +14198,9 @@ typedef enum FuncCallType { FUNC_CALL_TEMPLATE, } FuncCallType; -static void -optional_chain_test (JSParseState *s, int *poptional_chaining_label, - int drop_count) { +static void optional_chain_test (JSParseState *s, + int *poptional_chaining_label, + int drop_count) { int label_next, i; if (*poptional_chaining_label < 0) *poptional_chaining_label = new_label (s); /* XXX: could be more efficient with a specific opcode */ @@ -14597,8 +14215,8 @@ optional_chain_test (JSParseState *s, int *poptional_chaining_label, } /* allowed parse_flags: PF_POSTFIX_CALL */ -static __exception int -js_parse_postfix_expr (JSParseState *s, int parse_flags) { +static __exception int js_parse_postfix_expr (JSParseState *s, + int parse_flags) { FuncCallType call_type; int optional_chaining_label; BOOL accept_lparen = (parse_flags & PF_POSTFIX_CALL) != 0; @@ -14665,8 +14283,7 @@ js_parse_postfix_expr (JSParseState *s, int parse_flags) { if (js_parse_expr_paren (s)) return -1; break; case TOK_FUNCTION: - if (js_parse_function_decl (s, JS_PARSE_FUNC_EXPR, JS_NULL, - s->token.ptr)) + if (js_parse_function_decl (s, JS_PARSE_FUNC_EXPR, JS_NULL, s->token.ptr)) return -1; break; case TOK_NULL: @@ -14930,8 +14547,7 @@ js_parse_postfix_expr (JSParseState *s, int parse_flags) { return 0; } -static __exception int -js_parse_delete (JSParseState *s) { +static __exception int js_parse_delete (JSParseState *s) { JSFunctionDef *fd = s->cur_func; int opcode; @@ -14990,7 +14606,8 @@ js_parse_delete (JSParseState *s) { /* 'delete this': this is not a reference */ uint32_t idx = get_u32 (fd->byte_code.buf + fd->last_opcode_pos + 1); JSValue name = fd->cpool[idx]; - if (js_key_equal (name, JS_KEY_this) || js_key_equal_str (name, "new.target")) + if (js_key_equal (name, JS_KEY_this) + || js_key_equal_str (name, "new.target")) goto ret_true; return js_parse_error (s, @@ -15006,8 +14623,7 @@ js_parse_delete (JSParseState *s) { } /* allowed parse_flags: PF_POW_ALLOWED, PF_POW_FORBIDDEN */ -static __exception int -js_parse_unary (JSParseState *s, int parse_flags) { +static __exception int js_parse_unary (JSParseState *s, int parse_flags) { int op; const uint8_t *op_token_ptr; @@ -15099,8 +14715,8 @@ js_parse_unary (JSParseState *s, int parse_flags) { } /* allowed parse_flags: PF_IN_ACCEPTED */ -static __exception int -js_parse_expr_binary (JSParseState *s, int level, int parse_flags) { +static __exception int js_parse_expr_binary (JSParseState *s, int level, + int parse_flags) { int op, opcode; const uint8_t *op_token_ptr; @@ -15231,8 +14847,8 @@ js_parse_expr_binary (JSParseState *s, int level, int parse_flags) { } /* allowed parse_flags: PF_IN_ACCEPTED */ -static __exception int -js_parse_logical_and_or (JSParseState *s, int op, int parse_flags) { +static __exception int js_parse_logical_and_or (JSParseState *s, int op, + int parse_flags) { int label1; if (op == TOK_LAND) { @@ -15266,8 +14882,8 @@ js_parse_logical_and_or (JSParseState *s, int op, int parse_flags) { return 0; } -static __exception int -js_parse_coalesce_expr (JSParseState *s, int parse_flags) { +static __exception int js_parse_coalesce_expr (JSParseState *s, + int parse_flags) { int label1; if (js_parse_logical_and_or (s, TOK_LOR, parse_flags)) return -1; @@ -15290,8 +14906,7 @@ js_parse_coalesce_expr (JSParseState *s, int parse_flags) { } /* allowed parse_flags: PF_IN_ACCEPTED */ -static __exception int -js_parse_cond_expr (JSParseState *s, int parse_flags) { +static __exception int js_parse_cond_expr (JSParseState *s, int parse_flags) { int label1, label2; if (js_parse_coalesce_expr (s, parse_flags)) return -1; @@ -15314,8 +14929,8 @@ js_parse_cond_expr (JSParseState *s, int parse_flags) { } /* allowed parse_flags: PF_IN_ACCEPTED */ -static __exception int -js_parse_assign_expr2 (JSParseState *s, int parse_flags) { +static __exception int js_parse_assign_expr2 (JSParseState *s, + int parse_flags) { int opcode, op, scope, skip_bits; JSValue name0 = JS_NULL; JSValue name; @@ -15424,14 +15039,12 @@ next: return 0; } -static __exception int -js_parse_assign_expr (JSParseState *s) { +static __exception int js_parse_assign_expr (JSParseState *s) { return js_parse_assign_expr2 (s, PF_IN_ACCEPTED); } /* allowed parse_flags: PF_IN_ACCEPTED */ -static __exception int -js_parse_expr2 (JSParseState *s, int parse_flags) { +static __exception int js_parse_expr2 (JSParseState *s, int parse_flags) { BOOL comma = FALSE; for (;;) { if (js_parse_assign_expr2 (s, parse_flags)) return -1; @@ -15451,14 +15064,13 @@ js_parse_expr2 (JSParseState *s, int parse_flags) { return 0; } -static __exception int -js_parse_expr (JSParseState *s) { +static __exception int js_parse_expr (JSParseState *s) { return js_parse_expr2 (s, PF_IN_ACCEPTED); } -static void -push_break_entry (JSFunctionDef *fd, BlockEnv *be, JSValue label_name, - int label_break, int label_cont, int drop_count) { +static void push_break_entry (JSFunctionDef *fd, BlockEnv *be, + JSValue label_name, int label_break, + int label_cont, int drop_count) { be->prev = fd->top_break; fd->top_break = be; be->label_name = label_name; @@ -15470,15 +15082,14 @@ push_break_entry (JSFunctionDef *fd, BlockEnv *be, JSValue label_name, be->is_regular_stmt = FALSE; } -static void -pop_break_entry (JSFunctionDef *fd) { +static void pop_break_entry (JSFunctionDef *fd) { BlockEnv *be; be = fd->top_break; fd->top_break = be->prev; } -static __exception int -emit_break (JSParseState *s, JSValue name, int is_cont) { +static __exception int emit_break (JSParseState *s, JSValue name, + int is_cont) { BlockEnv *top; int i, scope_level; @@ -15520,8 +15131,7 @@ emit_break (JSParseState *s, JSValue name, int is_cont) { } /* execute the finally blocks before return */ -static void -emit_return (JSParseState *s, BOOL hasval) { +static void emit_return (JSParseState *s, BOOL hasval) { BlockEnv *top; top = s->cur_func->top_break; @@ -15556,13 +15166,11 @@ emit_return (JSParseState *s, BOOL hasval) { static __exception int js_parse_statement_or_decl (JSParseState *s, int decl_mask); -static __exception int -js_parse_statement (JSParseState *s) { +static __exception int js_parse_statement (JSParseState *s) { return js_parse_statement_or_decl (s, 0); } -static __exception int -js_parse_block (JSParseState *s) { +static __exception int js_parse_block (JSParseState *s) { if (js_parse_expect (s, '{')) return -1; if (s->token.val != '}') { push_scope (s); @@ -15577,8 +15185,8 @@ 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) { +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; @@ -15642,16 +15250,14 @@ var_error: } /* test if the current token is a label. Use simplistic look-ahead scanner */ -static BOOL -is_label (JSParseState *s) { +static BOOL is_label (JSParseState *s) { return (s->token.val == TOK_IDENT && !s->token.u.ident.is_reserved && peek_token (s, FALSE) == ':'); } /* test if the current token is a let keyword. Use simplistic look-ahead * scanner */ -static int -is_let (JSParseState *s, int decl_mask) { +static int is_let (JSParseState *s, int decl_mask) { int res = FALSE; const uint8_t *last_token_ptr; @@ -15691,13 +15297,11 @@ is_let (JSParseState *s, int decl_mask) { } /* for-in and for-of loops are not supported */ -static __exception int -js_parse_for_in_of (JSParseState *s, int label_name) { +static __exception int js_parse_for_in_of (JSParseState *s, int label_name) { return js_parse_error (s, "'for in' and 'for of' loops are not supported"); } -static void -set_eval_ret_undefined (JSParseState *s) { +static void set_eval_ret_undefined (JSParseState *s) { if (s->cur_func->eval_ret_idx >= 0) { emit_op (s, OP_null); emit_op (s, OP_put_loc); @@ -15705,8 +15309,8 @@ set_eval_ret_undefined (JSParseState *s) { } } -static __exception int -js_parse_statement_or_decl (JSParseState *s, int decl_mask) { +static __exception int js_parse_statement_or_decl (JSParseState *s, + int decl_mask) { JSContext *ctx = s->ctx; JSValue label_name; int tok; @@ -16258,8 +15862,7 @@ js_parse_statement_or_decl (JSParseState *s, int decl_mask) { goto fail; } parse_func_var: - if (js_parse_function_decl (s, JS_PARSE_FUNC_VAR, JS_NULL, - s->token.ptr)) + if (js_parse_function_decl (s, JS_PARSE_FUNC_VAR, JS_NULL, s->token.ptr)) goto fail; break; } @@ -16304,8 +15907,7 @@ static int add_closure_var (JSContext *ctx, JSFunctionDef *s, BOOL is_local, BOOL is_const, BOOL is_lexical, JSVarKindEnum var_kind); -static __exception int -js_parse_source_element (JSParseState *s) { +static __exception int js_parse_source_element (JSParseState *s) { if (s->token.val == TOK_FUNCTION || (token_is_pseudo_keyword (s, JS_KEY_async) && peek_token (s, TRUE) == TOK_FUNCTION)) { @@ -16376,9 +15978,8 @@ js_new_function_def (JSContext *ctx, JSFunctionDef *parent, BOOL is_eval, return fd; } -static void -free_bytecode_atoms (JSRuntime *rt, const uint8_t *bc_buf, int bc_len, - BOOL use_short_opcodes) { +static void free_bytecode_atoms (JSRuntime *rt, const uint8_t *bc_buf, + int bc_len, BOOL use_short_opcodes) { int pos, len, op; JSAtom atom; const JSOpCode *oi; @@ -16414,8 +16015,7 @@ free_bytecode_atoms (JSRuntime *rt, const uint8_t *bc_buf, int bc_len, } } -static void -js_free_function_def (JSContext *ctx, JSFunctionDef *fd) { +static void js_free_function_def (JSContext *ctx, JSFunctionDef *fd) { int i; struct list_head *el, *el1; @@ -16475,8 +16075,7 @@ js_free_function_def (JSContext *ctx, JSFunctionDef *fd) { } #ifdef DUMP_BYTECODE -static const char * -skip_lines (const char *p, int n) { +static const char *skip_lines (const char *p, int n) { while (n-- > 0 && *p) { while (*p && *p++ != '\n') continue; @@ -16484,8 +16083,7 @@ skip_lines (const char *p, int n) { return p; } -static void -print_lines (const char *source, int line, int line1) { +static void print_lines (const char *source, int line, int line1) { const char *s = source; const char *p = skip_lines (s, line); if (*p) { @@ -16500,13 +16098,14 @@ print_lines (const char *source, int line, int line1) { } } -static void -dump_byte_code (JSContext *ctx, int pass, const uint8_t *tab, int len, - const JSVarDef *args, int arg_count, const JSVarDef *vars, - int var_count, const JSClosureVar *closure_var, - int closure_var_count, const JSValue *cpool, - uint32_t cpool_count, const char *source, - const LabelSlot *label_slots, JSFunctionBytecode *b) { +static void dump_byte_code (JSContext *ctx, int pass, const uint8_t *tab, + int len, const JSVarDef *args, int arg_count, + const JSVarDef *vars, int var_count, + const JSClosureVar *closure_var, + int closure_var_count, const JSValue *cpool, + uint32_t cpool_count, const char *source, + const LabelSlot *label_slots, + JSFunctionBytecode *b) { const JSOpCode *oi; int pos, pos_next, op, size, idx, addr, line, line1, in_source, line_num; uint8_t *bits = js_mallocz (ctx, len * sizeof (*bits)); @@ -16761,8 +16360,8 @@ dump_byte_code (JSContext *ctx, int pass, const uint8_t *tab, int len, js_free (ctx, bits); } -static __maybe_unused void -dump_pc2line (JSContext *ctx, const uint8_t *buf, int len) { +static __maybe_unused void dump_pc2line (JSContext *ctx, const uint8_t *buf, + int len) { const uint8_t *p_end, *p; int pc, v, line_num, col_num, ret; unsigned int op; @@ -16815,8 +16414,8 @@ dump_pc2line (JSContext *ctx, const uint8_t *buf, int len) { fail:; } -static __maybe_unused void -js_dump_function_bytecode (JSContext *ctx, JSFunctionBytecode *b) { +static __maybe_unused void js_dump_function_bytecode (JSContext *ctx, + JSFunctionBytecode *b) { int i; char atom_buf[ATOM_GET_STR_BUF_SIZE]; const char *str; @@ -16889,10 +16488,10 @@ js_dump_function_bytecode (JSContext *ctx, JSFunctionBytecode *b) { } #endif -static int -add_closure_var (JSContext *ctx, JSFunctionDef *s, BOOL is_local, BOOL is_arg, - int var_idx, JSValue var_name, BOOL is_const, BOOL is_lexical, - JSVarKindEnum var_kind) { +static int add_closure_var (JSContext *ctx, JSFunctionDef *s, BOOL is_local, + BOOL is_arg, int var_idx, JSValue var_name, + BOOL is_const, BOOL is_lexical, + JSVarKindEnum var_kind) { JSClosureVar *cv; /* the closure variable indexes are currently stored on 16 bits */ @@ -16919,10 +16518,10 @@ add_closure_var (JSContext *ctx, JSFunctionDef *s, BOOL is_local, BOOL is_arg, /* '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' */ -static int -get_closure_var2 (JSContext *ctx, JSFunctionDef *s, JSFunctionDef *fd, - BOOL is_local, BOOL is_arg, int var_idx, JSValue var_name, - BOOL is_const, BOOL is_lexical, JSVarKindEnum var_kind) { +static int get_closure_var2 (JSContext *ctx, JSFunctionDef *s, + JSFunctionDef *fd, BOOL is_local, BOOL is_arg, + int var_idx, JSValue var_name, BOOL is_const, + BOOL is_lexical, JSVarKindEnum var_kind) { int i; if (fd != s->parent) { @@ -16941,34 +16540,31 @@ get_closure_var2 (JSContext *ctx, JSFunctionDef *s, JSFunctionDef *fd, is_const, is_lexical, var_kind); } -static int -get_closure_var (JSContext *ctx, JSFunctionDef *s, JSFunctionDef *fd, - BOOL is_arg, int var_idx, JSValue var_name, BOOL is_const, - BOOL is_lexical, JSVarKindEnum var_kind) { +static int get_closure_var (JSContext *ctx, JSFunctionDef *s, + JSFunctionDef *fd, BOOL is_arg, int var_idx, + JSValue var_name, BOOL is_const, BOOL is_lexical, + JSVarKindEnum var_kind) { return get_closure_var2 (ctx, s, fd, TRUE, is_arg, var_idx, var_name, is_const, is_lexical, var_kind); } -static BOOL -can_opt_put_ref_value (const uint8_t *bc_buf, int pos) { +static BOOL can_opt_put_ref_value (const uint8_t *bc_buf, int pos) { int opcode = bc_buf[pos]; return (bc_buf[pos + 1] == OP_put_ref_value && (opcode == OP_insert3 || opcode == OP_perm4 || opcode == OP_nop || opcode == OP_rot3l)); } -static BOOL -can_opt_put_global_ref_value (const uint8_t *bc_buf, int pos) { +static BOOL can_opt_put_global_ref_value (const uint8_t *bc_buf, int pos) { int opcode = bc_buf[pos]; return (bc_buf[pos + 1] == OP_put_ref_value && (opcode == OP_insert3 || opcode == OP_perm4 || opcode == OP_nop || opcode == OP_rot3l)); } -static int -optimize_scope_make_ref (JSContext *ctx, JSFunctionDef *s, DynBuf *bc, - uint8_t *bc_buf, LabelSlot *ls, int pos_next, - int get_op, int var_idx) { +static int optimize_scope_make_ref (JSContext *ctx, JSFunctionDef *s, + DynBuf *bc, uint8_t *bc_buf, LabelSlot *ls, + int pos_next, int get_op, int var_idx) { int label_pos, end_pos, pos; /* XXX: should optimize `loc(a) += expr` as `expr add_loc(a)` @@ -17007,10 +16603,10 @@ optimize_scope_make_ref (JSContext *ctx, JSFunctionDef *s, DynBuf *bc, return pos_next; } -static int -optimize_scope_make_global_ref (JSContext *ctx, JSFunctionDef *s, DynBuf *bc, - uint8_t *bc_buf, LabelSlot *ls, int pos_next, - JSValue var_name) { +static int optimize_scope_make_global_ref (JSContext *ctx, JSFunctionDef *s, + DynBuf *bc, uint8_t *bc_buf, + LabelSlot *ls, int pos_next, + JSValue var_name) { int label_pos, end_pos, pos, op; int cpool_idx = fd_cpool_add (ctx, s, JS_DupValue (ctx, var_name)); @@ -17063,13 +16659,12 @@ optimize_scope_make_global_ref (JSContext *ctx, JSFunctionDef *s, DynBuf *bc, return pos_next; } -static int -add_var_this (JSContext *ctx, JSFunctionDef *fd) { +static int add_var_this (JSContext *ctx, JSFunctionDef *fd) { return add_var (ctx, fd, JS_KEY_this); } -static int -resolve_pseudo_var (JSContext *ctx, JSFunctionDef *s, JSValue var_name) { +static int resolve_pseudo_var (JSContext *ctx, JSFunctionDef *s, + JSValue var_name) { int var_idx; if (!s->has_this_binding) return -1; @@ -17094,19 +16689,19 @@ resolve_pseudo_var (JSContext *ctx, JSFunctionDef *s, JSValue var_name) { /* test if 'var_name' is in the variable object on the stack. If is it the case, handle it and jump to 'label_done' */ -static void -var_object_test (JSContext *ctx, JSFunctionDef *s, JSValue var_name, int op, - DynBuf *bc, int *plabel_done, BOOL is_with) { +static void var_object_test (JSContext *ctx, JSFunctionDef *s, + JSValue var_name, int op, DynBuf *bc, + int *plabel_done, BOOL is_with) { int cpool_idx = fd_cpool_add (ctx, s, JS_DupValue (ctx, var_name)); dbuf_putc (bc, op); dbuf_put_u32 (bc, cpool_idx); } /* return the position of the next opcode */ -static int -resolve_scope_var (JSContext *ctx, JSFunctionDef *s, JSValue var_name, - int scope_level, int op, DynBuf *bc, uint8_t *bc_buf, - LabelSlot *ls, int pos_next) { +static int resolve_scope_var (JSContext *ctx, JSFunctionDef *s, + JSValue var_name, int scope_level, int op, + DynBuf *bc, uint8_t *bc_buf, LabelSlot *ls, + int pos_next) { int idx, var_idx, is_put; int label_done; JSFunctionDef *fd; @@ -17117,11 +16712,10 @@ resolve_scope_var (JSContext *ctx, JSFunctionDef *s, JSValue var_name, /* XXX: could be simpler to use a specific function to resolve the pseudo variables */ - is_pseudo_var - = (js_key_equal_str (var_name, "home_object") - || js_key_equal_str (var_name, "this_active_func") - || js_key_equal_str (var_name, "new_target") - || js_key_equal (var_name, JS_KEY_this)); + is_pseudo_var = (js_key_equal_str (var_name, "home_object") + || js_key_equal_str (var_name, "this_active_func") + || js_key_equal_str (var_name, "new_target") + || js_key_equal (var_name, JS_KEY_this)); /* resolve local scoped variables */ var_idx = -1; @@ -17151,7 +16745,8 @@ resolve_scope_var (JSContext *ctx, JSFunctionDef *s, JSValue var_name, if (var_idx < 0 && is_pseudo_var) var_idx = resolve_pseudo_var (ctx, s, var_name); - if (var_idx < 0 && s->is_func_expr && js_key_equal (var_name, s->func_name)) { + if (var_idx < 0 && s->is_func_expr + && js_key_equal (var_name, s->func_name)) { /* add a new variable with the function name */ var_idx = add_func_var (ctx, s, var_name); } @@ -17508,9 +17103,8 @@ done: return pos_next; } -static void -mark_eval_captured_variables (JSContext *ctx, JSFunctionDef *s, - int scope_level) { +static void mark_eval_captured_variables (JSContext *ctx, JSFunctionDef *s, + int scope_level) { int idx; JSVarDef *vd; @@ -17522,8 +17116,7 @@ mark_eval_captured_variables (JSContext *ctx, JSFunctionDef *s, } /* XXX: should handle the argument scope generically */ -static BOOL -is_var_in_arg_scope (const JSVarDef *vd) { +static BOOL is_var_in_arg_scope (const JSVarDef *vd) { return (js_key_equal_str (vd->var_name, "home_object") || js_key_equal_str (vd->var_name, "this_active_func") || js_key_equal_str (vd->var_name, "new_target") @@ -17532,8 +17125,7 @@ is_var_in_arg_scope (const JSVarDef *vd) { || vd->var_kind == JS_VAR_FUNCTION_NAME); } -static void -add_eval_variables (JSContext *ctx, JSFunctionDef *s) { +static void add_eval_variables (JSContext *ctx, JSFunctionDef *s) { JSFunctionDef *fd; JSVarDef *vd; int i, scope_level, scope_idx; @@ -17619,9 +17211,8 @@ add_eval_variables (JSContext *ctx, JSFunctionDef *s) { } } -static void -set_closure_from_var (JSContext *ctx, JSClosureVar *cv, JSVarDef *vd, - int var_idx) { +static void set_closure_from_var (JSContext *ctx, JSClosureVar *cv, + JSVarDef *vd, int var_idx) { cv->is_local = TRUE; cv->is_arg = FALSE; cv->is_const = vd->is_const; @@ -17633,9 +17224,9 @@ set_closure_from_var (JSContext *ctx, JSClosureVar *cv, JSVarDef *vd, /* for direct eval compilation: add references to the variables of the calling function */ -static __exception int -add_closure_variables (JSContext *ctx, JSFunctionDef *s, JSFunctionBytecode *b, - int scope_idx) { +static __exception int add_closure_variables (JSContext *ctx, JSFunctionDef *s, + JSFunctionBytecode *b, + int scope_idx) { int i, count; JSVarDef *vd; BOOL is_arg_scope; @@ -17719,8 +17310,7 @@ typedef struct CodeContext { #define M4(op1, op2, op3, op4) \ ((op1) | ((op2) << 8) | ((op3) << 16) | ((op4) << 24)) -static BOOL -code_match (CodeContext *s, int pos, ...) { +static BOOL code_match (CodeContext *s, int pos, ...) { const uint8_t *tab = s->bc_buf; int op, len, op1, line_num, pos_next; va_list ap; @@ -17833,9 +17423,8 @@ done: return ret; } -static void -instantiate_hoisted_definitions (JSContext *ctx, JSFunctionDef *s, - DynBuf *bc) { +static void instantiate_hoisted_definitions (JSContext *ctx, JSFunctionDef *s, + DynBuf *bc) { int i, idx; /* add the hoisted functions in arguments and local variables */ @@ -17875,7 +17464,8 @@ instantiate_hoisted_definitions (JSContext *ctx, JSFunctionDef *s, force_init = FALSE; break; } - if (js_key_equal_str (cv->var_name, "_var_") || js_key_equal_str (cv->var_name, "_arg_var_")) { + if (js_key_equal_str (cv->var_name, "_var_") + || js_key_equal_str (cv->var_name, "_arg_var_")) { dbuf_putc (bc, OP_get_var_ref); dbuf_put_u16 (bc, idx); has_closure = 1; @@ -17946,9 +17536,8 @@ instantiate_hoisted_definitions (JSContext *ctx, JSFunctionDef *s, s->global_var_size = 0; } -static int -skip_dead_code (JSFunctionDef *s, const uint8_t *bc_buf, int bc_len, int pos, - int *linep) { +static int skip_dead_code (JSFunctionDef *s, const uint8_t *bc_buf, int bc_len, + int pos, int *linep) { int op, len, label; for (; pos < bc_len; pos += len) { @@ -17991,8 +17580,7 @@ skip_dead_code (JSFunctionDef *s, const uint8_t *bc_buf, int bc_len, int pos, return pos; } -static int -get_label_pos (JSFunctionDef *s, int label) { +static int get_label_pos (JSFunctionDef *s, int label) { int i, pos; for (i = 0; i < 20; i++) { pos = s->label_slots[label].pos; @@ -18016,8 +17604,7 @@ get_label_pos (JSFunctionDef *s, int label) { /* convert global variable accesses to local variables or closure variables when necessary */ -static __exception int -resolve_variables (JSContext *ctx, JSFunctionDef *s) { +static __exception int resolve_variables (JSContext *ctx, JSFunctionDef *s) { int pos, pos_next, bc_len, op, len, i, idx, line_num; uint8_t *bc_buf; JSValue var_name; @@ -18053,7 +17640,8 @@ resolve_variables (JSContext *ctx, JSFunctionDef *s) { } goto next; } - if (js_key_equal_str (cv->var_name, "") || js_key_equal_str (cv->var_name, "")) + if (js_key_equal_str (cv->var_name, "") + || js_key_equal_str (cv->var_name, "")) goto next; } @@ -18352,8 +17940,8 @@ fail: } /* the pc2line table gives a source position for each PC value */ -static void -add_pc2line_info (JSFunctionDef *s, uint32_t pc, uint32_t source_pos) { +static void add_pc2line_info (JSFunctionDef *s, uint32_t pc, + uint32_t source_pos) { if (s->line_number_slots != NULL && s->line_number_count < s->line_number_size && pc >= s->line_number_last_pc && source_pos != s->line_number_last) { @@ -18371,8 +17959,7 @@ add_pc2line_info (JSFunctionDef *s, uint32_t pc, uint32_t source_pos) { bytes. Alternatively, get_line_col_cached() could be issued in emit_source_pos() so that the deltas are more likely to be small. */ -static void -compute_pc2line_info (JSFunctionDef *s) { +static void compute_pc2line_info (JSFunctionDef *s) { if (!s->strip_debug) { int last_line_num, last_col_num; uint32_t last_pc = 0; @@ -18420,8 +18007,8 @@ compute_pc2line_info (JSFunctionDef *s) { } } -static RelocEntry * -add_reloc (JSContext *ctx, LabelSlot *ls, uint32_t addr, int size) { +static RelocEntry *add_reloc (JSContext *ctx, LabelSlot *ls, uint32_t addr, + int size) { RelocEntry *re; re = js_malloc (ctx, sizeof (*re)); if (!re) return NULL; @@ -18432,8 +18019,7 @@ add_reloc (JSContext *ctx, LabelSlot *ls, uint32_t addr, int size) { return re; } -static BOOL -code_has_label (CodeContext *s, int pos, int label) { +static BOOL code_has_label (CodeContext *s, int pos, int label) { while (pos < s->bc_len) { int op = s->bc_buf[pos]; if (op == OP_line_num) { @@ -18458,8 +18044,8 @@ code_has_label (CodeContext *s, int pos, int label) { /* return the target label, following the OP_goto jumps the first opcode at destination is stored in *pop */ -static int -find_jump_target (JSFunctionDef *s, int label0, int *pop, int *pline) { +static int find_jump_target (JSFunctionDef *s, int label0, int *pop, + int *pline) { int i, pos, op, label; label = label0; @@ -18510,8 +18096,7 @@ done: return label; } -static void -push_short_int (DynBuf *bc_out, int val) { +static void push_short_int (DynBuf *bc_out, int val) { #if SHORT_OPCODES if (val >= -1 && val <= 7) { dbuf_putc (bc_out, OP_push_0 + val); @@ -18532,8 +18117,7 @@ push_short_int (DynBuf *bc_out, int val) { dbuf_put_u32 (bc_out, val); } -static void -put_short_code (DynBuf *bc_out, int op, int idx) { +static void put_short_code (DynBuf *bc_out, int op, int idx) { #if SHORT_OPCODES if (idx < 4) { switch (op) { @@ -18591,8 +18175,7 @@ put_short_code (DynBuf *bc_out, int op, int idx) { } /* peephole optimizations and resolve goto/labels */ -static __exception int -resolve_labels (JSContext *ctx, JSFunctionDef *s) { +static __exception int resolve_labels (JSContext *ctx, JSFunctionDef *s) { int pos, pos_next, bc_len, op, op1, len, i, line_num; const uint8_t *bc_buf; DynBuf bc_out; @@ -18986,8 +18569,7 @@ resolve_labels (JSContext *ctx, JSFunctionDef *s) { if (code_match (&cc, pos_next, M3 (OP_get_loc, OP_get_arg, OP_get_var_ref), -1, OP_put_array_el, -1) - || code_match (&cc, pos_next, - M2 (OP_push_i32, OP_push_const), + || code_match (&cc, pos_next, M2 (OP_push_i32, OP_push_const), OP_put_array_el, -1) || code_match (&cc, pos_next, M4 (OP_null, OP_null, OP_push_true, OP_push_false), @@ -19306,9 +18888,8 @@ typedef struct StackSizeState { } StackSizeState; /* 'op' is only used for error indication */ -static __exception int -ss_check (JSContext *ctx, StackSizeState *s, int pos, int op, int stack_len, - int catch_pos) { +static __exception int ss_check (JSContext *ctx, StackSizeState *s, int pos, + int op, int stack_len, int catch_pos) { if ((unsigned)pos >= s->bc_len) { JS_ThrowInternalError (ctx, "bytecode buffer overflow (op=%d, pc=%d)", op, pos); @@ -19348,8 +18929,8 @@ ss_check (JSContext *ctx, StackSizeState *s, int pos, int op, int stack_len, return 0; } -static __exception int -compute_stack_size (JSContext *ctx, JSFunctionDef *fd, int *pstack_size) { +static __exception int compute_stack_size (JSContext *ctx, JSFunctionDef *fd, + int *pstack_size) { StackSizeState s_s, *s = &s_s; int i, diff, n_pop, pos_next, stack_len, pos, op, catch_pos, catch_level; const JSOpCode *oi; @@ -19510,8 +19091,7 @@ fail: /* create a function object from a function definition. The function definition is freed. All the child functions are also created. It must be done this way to resolve all the variables. */ -static JSValue -js_create_function (JSContext *ctx, JSFunctionDef *fd) { +static JSValue js_create_function (JSContext *ctx, JSFunctionDef *fd) { JSValue func_obj; JSFunctionBytecode *b; struct list_head *el, *el1; @@ -19727,8 +19307,7 @@ fail: /* IC helper functions removed - shapes no longer used */ -static void -free_function_bytecode (JSRuntime *rt, JSFunctionBytecode *b) { +static void free_function_bytecode (JSRuntime *rt, JSFunctionBytecode *b) { int i; free_bytecode_atoms (rt, b->byte_code_buf, b->byte_code_len, TRUE); @@ -19770,8 +19349,7 @@ free_function_bytecode (JSRuntime *rt, JSFunctionBytecode *b) { } } -static __exception int -js_parse_directives (JSParseState *s) { +static __exception int js_parse_directives (JSParseState *s) { char str[20]; JSParsePos pos; BOOL has_semi; @@ -19838,16 +19416,14 @@ js_parse_directives (JSParseState *s) { } /* return TRUE if the keyword is forbidden only in strict mode */ -static BOOL -is_strict_future_keyword (JSValue name) { +static BOOL is_strict_future_keyword (JSValue name) { BOOL is_strict_reserved = FALSE; int token = js_keyword_lookup (name, &is_strict_reserved); return (token >= 0 && is_strict_reserved); } -static int -js_parse_function_check_names (JSParseState *s, JSFunctionDef *fd, - JSValue func_name) { +static int js_parse_function_check_names (JSParseState *s, JSFunctionDef *fd, + JSValue func_name) { JSValue name; int i, idx; @@ -19855,7 +19431,8 @@ js_parse_function_check_names (JSParseState *s, JSFunctionDef *fd, return js_parse_error (s, "\"use strict\" not allowed in function with " "default or destructuring parameter"); } - if (js_key_equal (func_name, JS_KEY_eval) || is_strict_future_keyword (func_name)) { + if (js_key_equal (func_name, JS_KEY_eval) + || is_strict_future_keyword (func_name)) { return js_parse_error (s, "invalid function name in strict code"); } for (idx = 0; idx < fd->arg_count; idx++) { @@ -19875,7 +19452,8 @@ js_parse_function_check_names (JSParseState *s, JSFunctionDef *fd, /* Check if argument name duplicates a destructuring parameter */ /* XXX: should have a flag for such variables */ for (i = 0; i < fd->var_count; i++) { - if (js_key_equal (fd->vars[i].var_name, name) && fd->vars[i].scope_level == 0) + if (js_key_equal (fd->vars[i].var_name, name) + && fd->vars[i].scope_level == 0) goto duplicate; } } @@ -19889,10 +19467,11 @@ duplicate: /* func_name must be JS_NULL for JS_PARSE_FUNC_STATEMENT and JS_PARSE_FUNC_EXPR, JS_PARSE_FUNC_ARROW and JS_PARSE_FUNC_VAR */ -static __exception int -js_parse_function_decl2 (JSParseState *s, JSParseFunctionEnum func_type, - JSValue func_name, const uint8_t *ptr, - JSFunctionDef **pfd) { +static __exception int js_parse_function_decl2 (JSParseState *s, + JSParseFunctionEnum func_type, + JSValue func_name, + const uint8_t *ptr, + JSFunctionDef **pfd) { JSContext *ctx = s->ctx; JSFunctionDef *fd = s->cur_func; BOOL is_expr; @@ -20240,7 +19819,8 @@ done: } } else { if (!s->cur_func->is_global_var) { - int var_idx = define_var (s, s->cur_func, func_name_val, JS_VAR_DEF_VAR); + int var_idx + = define_var (s, s->cur_func, func_name_val, JS_VAR_DEF_VAR); if (var_idx < 0) goto fail; /* the variable will be assigned at the top of the function */ @@ -20271,14 +19851,14 @@ fail: return -1; } -static __exception int -js_parse_function_decl (JSParseState *s, JSParseFunctionEnum func_type, - JSValue func_name, const uint8_t *ptr) { +static __exception int js_parse_function_decl (JSParseState *s, + JSParseFunctionEnum func_type, + JSValue func_name, + const uint8_t *ptr) { return js_parse_function_decl2 (s, func_type, func_name, ptr, NULL); } -static __exception int -js_parse_program (JSParseState *s) { +static __exception int js_parse_program (JSParseState *s) { JSFunctionDef *fd = s->cur_func; int idx; @@ -20304,9 +19884,8 @@ js_parse_program (JSParseState *s) { return 0; } -static void -js_parse_init (JSContext *ctx, JSParseState *s, const char *input, - size_t input_len, const char *filename) { +static void js_parse_init (JSContext *ctx, JSParseState *s, const char *input, + size_t input_len, const char *filename) { memset (s, 0, sizeof (*s)); s->ctx = ctx; s->filename = filename; @@ -20321,10 +19900,9 @@ js_parse_init (JSContext *ctx, JSParseState *s, const char *input, s->get_line_col_cache.col_num = 0; } -static JSValue -JS_EvalFunctionInternal (JSContext *ctx, JSValue fun_obj, - JSValue this_obj, JSVarRef **var_refs, - JSStackFrame *sf) { +static JSValue JS_EvalFunctionInternal (JSContext *ctx, JSValue fun_obj, + JSValue this_obj, JSVarRef **var_refs, + JSStackFrame *sf) { JSValue ret_val; uint32_t tag; @@ -20339,16 +19917,15 @@ JS_EvalFunctionInternal (JSContext *ctx, JSValue fun_obj, return ret_val; } -JSValue -JS_EvalFunction (JSContext *ctx, JSValue fun_obj) { +JSValue JS_EvalFunction (JSContext *ctx, JSValue fun_obj) { return JS_EvalFunctionInternal (ctx, fun_obj, ctx->global_obj, NULL, NULL); } /* 'input' must be zero terminated i.e. input[input_len] = '\0'. */ -static JSValue -__JS_EvalInternal (JSContext *ctx, JSValue this_obj, const char *input, - size_t input_len, const char *filename, int flags, - int scope_idx) { +static JSValue __JS_EvalInternal (JSContext *ctx, JSValue this_obj, + const char *input, size_t input_len, + const char *filename, int flags, + int scope_idx) { JSParseState s1, *s = &s1; int err, js_mode, eval_type; JSValue fun_obj, ret_val; @@ -20414,10 +19991,10 @@ fail1: } /* the indirection is needed to make 'eval' optional */ -static JSValue -JS_EvalInternal (JSContext *ctx, JSValue this_obj, const char *input, - size_t input_len, const char *filename, int flags, - int scope_idx) { +static JSValue JS_EvalInternal (JSContext *ctx, JSValue this_obj, + const char *input, size_t input_len, + const char *filename, int flags, + int scope_idx) { BOOL backtrace_barrier = ((flags & JS_EVAL_FLAG_BACKTRACE_BARRIER) != 0); int saved_js_mode = 0; JSValue ret; @@ -20436,9 +20013,8 @@ JS_EvalInternal (JSContext *ctx, JSValue this_obj, const char *input, return ret; } -static JSValue -JS_EvalObject (JSContext *ctx, JSValue this_obj, JSValue val, - int flags, int scope_idx) { +static JSValue JS_EvalObject (JSContext *ctx, JSValue this_obj, JSValue val, + int flags, int scope_idx) { JSValue ret; const char *str; size_t len; @@ -20451,9 +20027,8 @@ JS_EvalObject (JSContext *ctx, JSValue this_obj, JSValue val, return ret; } -JSValue -JS_EvalThis (JSContext *ctx, JSValue this_obj, const char *input, - size_t input_len, const char *filename, int eval_flags) { +JSValue JS_EvalThis (JSContext *ctx, JSValue this_obj, const char *input, + size_t input_len, const char *filename, int eval_flags) { int eval_type = eval_flags & JS_EVAL_TYPE_MASK; JSValue ret; @@ -20463,9 +20038,8 @@ JS_EvalThis (JSContext *ctx, JSValue this_obj, const char *input, return ret; } -JSValue -JS_Eval (JSContext *ctx, const char *input, size_t input_len, - const char *filename, int eval_flags) { +JSValue JS_Eval (JSContext *ctx, const char *input, size_t input_len, + const char *filename, int eval_flags) { return JS_EvalThis (ctx, ctx->global_obj, input, input_len, filename, eval_flags); } @@ -20487,19 +20061,16 @@ typedef struct { uint32_t hash_size; } JSObjectList; -static void -js_object_list_init (JSObjectList *s) { +static void js_object_list_init (JSObjectList *s) { memset (s, 0, sizeof (*s)); } -static uint32_t -js_object_list_get_hash (JSObject *p, uint32_t hash_size) { +static uint32_t js_object_list_get_hash (JSObject *p, uint32_t hash_size) { return ((uintptr_t)p * 3163) & (hash_size - 1); } -static int -js_object_list_resize_hash (JSContext *ctx, JSObjectList *s, - uint32_t new_hash_size) { +static int js_object_list_resize_hash (JSContext *ctx, JSObjectList *s, + uint32_t new_hash_size) { JSObjectListEntry *e; uint32_t i, h, *new_hash_table; @@ -20523,8 +20094,8 @@ js_object_list_resize_hash (JSContext *ctx, JSObjectList *s, /* the reference count of 'obj' is not modified. Return 0 if OK, -1 if memory error */ -static int -js_object_list_add (JSContext *ctx, JSObjectList *s, JSObject *obj) { +static int js_object_list_add (JSContext *ctx, JSObjectList *s, + JSObject *obj) { JSObjectListEntry *e; uint32_t h, new_hash_size; @@ -20546,8 +20117,8 @@ js_object_list_add (JSContext *ctx, JSObjectList *s, JSObject *obj) { } /* return -1 if not present or the object index */ -static int -js_object_list_find (JSContext *ctx, JSObjectList *s, JSObject *obj) { +static int js_object_list_find (JSContext *ctx, JSObjectList *s, + JSObject *obj) { JSObjectListEntry *e; uint32_t h, p; @@ -20563,8 +20134,7 @@ js_object_list_find (JSContext *ctx, JSObjectList *s, JSObject *obj) { return -1; } -static void -js_object_list_end (JSContext *ctx, JSObjectList *s) { +static void js_object_list_end (JSContext *ctx, JSObjectList *s) { js_free (ctx, s->object_tab); js_free (ctx, s->hash_table); } @@ -20621,8 +20191,7 @@ static const char *const bc_tag_str[] = { }; #endif -static inline BOOL -is_be (void) { +static inline BOOL is_be (void) { union { uint16_t a; uint8_t b; @@ -20630,47 +20199,39 @@ is_be (void) { return u.b; } -static void -bc_put_u8 (BCWriterState *s, uint8_t v) { +static void bc_put_u8 (BCWriterState *s, uint8_t v) { dbuf_putc (&s->dbuf, v); } -static void -bc_put_u16 (BCWriterState *s, uint16_t v) { +static void bc_put_u16 (BCWriterState *s, uint16_t v) { if (is_be ()) v = bswap16 (v); dbuf_put_u16 (&s->dbuf, v); } -static __maybe_unused void -bc_put_u32 (BCWriterState *s, uint32_t v) { +static __maybe_unused void bc_put_u32 (BCWriterState *s, uint32_t v) { if (is_be ()) v = bswap32 (v); dbuf_put_u32 (&s->dbuf, v); } -static void -bc_put_u64 (BCWriterState *s, uint64_t v) { +static void bc_put_u64 (BCWriterState *s, uint64_t v) { if (is_be ()) v = bswap64 (v); dbuf_put (&s->dbuf, (uint8_t *)&v, sizeof (v)); } -static void -bc_put_leb128 (BCWriterState *s, uint32_t v) { +static void bc_put_leb128 (BCWriterState *s, uint32_t v) { dbuf_put_leb128 (&s->dbuf, v); } -static void -bc_put_sleb128 (BCWriterState *s, int32_t v) { +static void bc_put_sleb128 (BCWriterState *s, int32_t v) { dbuf_put_sleb128 (&s->dbuf, v); } -static void -bc_set_flags (uint32_t *pflags, int *pidx, uint32_t val, int n) { +static void bc_set_flags (uint32_t *pflags, int *pidx, uint32_t val, int n) { *pflags = *pflags | (val << *pidx); *pidx += n; } -static int -bc_atom_to_idx (BCWriterState *s, uint32_t *pres, JSAtom atom) { +static int bc_atom_to_idx (BCWriterState *s, uint32_t *pres, JSAtom atom) { uint32_t v; if (atom < s->first_atom) { @@ -20709,8 +20270,7 @@ fail: return -1; } -static int -bc_put_atom (BCWriterState *s, JSAtom atom) { +static int bc_put_atom (BCWriterState *s, JSAtom atom) { uint32_t v; if (bc_atom_to_idx (s, &v, atom)) return -1; @@ -20720,8 +20280,7 @@ bc_put_atom (BCWriterState *s, JSAtom atom) { } /* Write a JSValue key (text) to bytecode stream */ -static int -bc_put_key (BCWriterState *s, JSValue key) { +static int bc_put_key (BCWriterState *s, JSValue key) { /* Handle immediate ASCII strings */ if (MIST_IsImmediateASCII (key)) { int len = MIST_GetImmediateASCIILen (key); @@ -20746,10 +20305,14 @@ bc_put_key (BCWriterState *s, JSValue key) { size_t utf8_size = 0; for (uint32_t i = 0; i < len; i++) { uint32_t c = string_get (p, i); - if (c < 0x80) utf8_size += 1; - else if (c < 0x800) utf8_size += 2; - else if (c < 0x10000) utf8_size += 3; - else utf8_size += 4; + if (c < 0x80) + utf8_size += 1; + else if (c < 0x800) + utf8_size += 2; + else if (c < 0x10000) + utf8_size += 3; + else + utf8_size += 4; } bc_put_leb128 (s, (uint32_t)utf8_size); for (uint32_t i = 0; i < len; i++) { @@ -20773,8 +20336,7 @@ bc_put_key (BCWriterState *s, JSValue key) { return 0; } -static void -bc_byte_swap (uint8_t *bc_buf, int bc_len) { +static void bc_byte_swap (uint8_t *bc_buf, int bc_len) { int pos, len, op, fmt; pos = 0; @@ -20829,9 +20391,8 @@ bc_byte_swap (uint8_t *bc_buf, int bc_len) { } } -static int -JS_WriteFunctionBytecode (BCWriterState *s, const uint8_t *bc_buf1, - int bc_len) { +static int JS_WriteFunctionBytecode (BCWriterState *s, const uint8_t *bc_buf1, + int bc_len) { int pos, len, op; JSAtom atom; uint8_t *bc_buf; @@ -20878,8 +20439,7 @@ fail: return -1; } -static void -JS_WriteString (BCWriterState *s, JSString *p) { +static void JS_WriteString (BCWriterState *s, JSString *p) { int i; /* UTF-32: write length, then each character as 32-bit value */ bc_put_leb128 (s, (uint32_t)p->len); @@ -20891,8 +20451,7 @@ JS_WriteString (BCWriterState *s, JSString *p) { static int JS_WriteObjectRec (BCWriterState *s, JSValue obj); -static int -JS_WriteFunctionTag (BCWriterState *s, JSValue obj) { +static int JS_WriteFunctionTag (BCWriterState *s, JSValue obj) { JSFunctionBytecode *b = JS_VALUE_GET_PTR (obj); uint32_t flags; int idx, i; @@ -20973,8 +20532,7 @@ fail: return -1; } -static int -JS_WriteObjectTag (BCWriterState *s, JSValue obj) { +static int JS_WriteObjectTag (BCWriterState *s, JSValue obj) { JSRecord *rec = (JSRecord *)JS_VALUE_GET_OBJ (obj); uint32_t mask = (uint32_t)objhdr_cap56 (rec->mist_hdr); uint32_t i, prop_count; @@ -21004,8 +20562,7 @@ fail: return -1; } -static int -JS_WriteObjectRec (BCWriterState *s, JSValue obj) { +static int JS_WriteObjectRec (BCWriterState *s, JSValue obj) { uint32_t tag; if (js_check_stack_overflow (s->ctx->rt, 0)) { @@ -21106,8 +20663,7 @@ fail: } /* create the atom table */ -static int -JS_WriteObjectAtoms (BCWriterState *s) { +static int JS_WriteObjectAtoms (BCWriterState *s) { JSRuntime *rt = s->ctx->rt; DynBuf dbuf1; int i, atoms_size; @@ -21136,9 +20692,9 @@ fail: return -1; } -uint8_t * -JS_WriteObject2 (JSContext *ctx, size_t *psize, JSValue obj, int flags, - uint8_t ***psab_tab, size_t *psab_tab_len) { +uint8_t *JS_WriteObject2 (JSContext *ctx, size_t *psize, JSValue obj, + int flags, uint8_t ***psab_tab, + size_t *psab_tab_len) { BCWriterState ss, *s = &ss; memset (s, 0, sizeof (*s)); @@ -21174,8 +20730,8 @@ fail: return NULL; } -uint8_t * -JS_WriteObject (JSContext *ctx, size_t *psize, JSValue obj, int flags) { +uint8_t *JS_WriteObject (JSContext *ctx, size_t *psize, JSValue obj, + int flags) { return JS_WriteObject2 (ctx, psize, obj, flags, NULL, NULL); } @@ -21232,16 +20788,14 @@ bc_read_trace (BCReaderState *s, const char *fmt, ...) { #define bc_read_trace(...) #endif -static int -bc_read_error_end (BCReaderState *s) { +static int bc_read_error_end (BCReaderState *s) { if (!s->error_state) { JS_ThrowSyntaxError (s->ctx, "read after the end of the buffer"); } return s->error_state = -1; } -static int -bc_get_u8 (BCReaderState *s, uint8_t *pval) { +static int bc_get_u8 (BCReaderState *s, uint8_t *pval) { if (unlikely (s->buf_end - s->ptr < 1)) { *pval = 0; /* avoid warning */ return bc_read_error_end (s); @@ -21250,8 +20804,7 @@ bc_get_u8 (BCReaderState *s, uint8_t *pval) { return 0; } -static int -bc_get_u16 (BCReaderState *s, uint16_t *pval) { +static int bc_get_u16 (BCReaderState *s, uint16_t *pval) { uint16_t v; if (unlikely (s->buf_end - s->ptr < 2)) { *pval = 0; /* avoid warning */ @@ -21264,8 +20817,7 @@ bc_get_u16 (BCReaderState *s, uint16_t *pval) { return 0; } -static __maybe_unused int -bc_get_u32 (BCReaderState *s, uint32_t *pval) { +static __maybe_unused int bc_get_u32 (BCReaderState *s, uint32_t *pval) { uint32_t v; if (unlikely (s->buf_end - s->ptr < 4)) { *pval = 0; /* avoid warning */ @@ -21278,8 +20830,7 @@ bc_get_u32 (BCReaderState *s, uint32_t *pval) { return 0; } -static int -bc_get_u64 (BCReaderState *s, uint64_t *pval) { +static int bc_get_u64 (BCReaderState *s, uint64_t *pval) { uint64_t v; if (unlikely (s->buf_end - s->ptr < 8)) { *pval = 0; /* avoid warning */ @@ -21292,8 +20843,7 @@ bc_get_u64 (BCReaderState *s, uint64_t *pval) { return 0; } -static int -bc_get_leb128 (BCReaderState *s, uint32_t *pval) { +static int bc_get_leb128 (BCReaderState *s, uint32_t *pval) { int ret; ret = get_leb128 (pval, s->ptr, s->buf_end); if (unlikely (ret < 0)) return bc_read_error_end (s); @@ -21301,8 +20851,7 @@ bc_get_leb128 (BCReaderState *s, uint32_t *pval) { return 0; } -static int -bc_get_sleb128 (BCReaderState *s, int32_t *pval) { +static int bc_get_sleb128 (BCReaderState *s, int32_t *pval) { int ret; ret = get_sleb128 (pval, s->ptr, s->buf_end); if (unlikely (ret < 0)) return bc_read_error_end (s); @@ -21311,13 +20860,11 @@ bc_get_sleb128 (BCReaderState *s, int32_t *pval) { } /* XXX: used to read an `int` with a positive value */ -static int -bc_get_leb128_int (BCReaderState *s, int *pval) { +static int bc_get_leb128_int (BCReaderState *s, int *pval) { return bc_get_leb128 (s, (uint32_t *)pval); } -static int -bc_get_leb128_u16 (BCReaderState *s, uint16_t *pval) { +static int bc_get_leb128_u16 (BCReaderState *s, uint16_t *pval) { uint32_t val; if (bc_get_leb128 (s, &val)) { *pval = 0; @@ -21327,8 +20874,7 @@ bc_get_leb128_u16 (BCReaderState *s, uint16_t *pval) { return 0; } -static int -bc_get_buf (BCReaderState *s, uint8_t *buf, uint32_t buf_len) { +static int bc_get_buf (BCReaderState *s, uint8_t *buf, uint32_t buf_len) { if (buf_len != 0) { if (unlikely (!buf || s->buf_end - s->ptr < buf_len)) return bc_read_error_end (s); @@ -21338,8 +20884,7 @@ bc_get_buf (BCReaderState *s, uint8_t *buf, uint32_t buf_len) { return 0; } -static int -bc_idx_to_atom (BCReaderState *s, JSAtom *patom, uint32_t idx) { +static int bc_idx_to_atom (BCReaderState *s, JSAtom *patom, uint32_t idx) { JSAtom atom; if (idx < s->first_atom) { @@ -21358,8 +20903,7 @@ bc_idx_to_atom (BCReaderState *s, JSAtom *patom, uint32_t idx) { return 0; } -static int -bc_get_atom (BCReaderState *s, JSAtom *patom) { +static int bc_get_atom (BCReaderState *s, JSAtom *patom) { uint32_t v; if (bc_get_leb128 (s, &v)) return -1; if (v & 1) { @@ -21372,8 +20916,7 @@ bc_get_atom (BCReaderState *s, JSAtom *patom) { } /* Read a JSValue key (text) from bytecode stream */ -static int -bc_get_key (BCReaderState *s, JSValue *pkey) { +static int bc_get_key (BCReaderState *s, JSValue *pkey) { uint32_t len; if (bc_get_leb128 (s, &len)) return -1; if (len == 0) { @@ -21393,8 +20936,7 @@ bc_get_key (BCReaderState *s, JSValue *pkey) { return JS_IsNull (*pkey) ? -1 : 0; } -static JSString * -JS_ReadString (BCReaderState *s) { +static JSString *JS_ReadString (BCReaderState *s) { uint32_t len; size_t size; JSString *p; @@ -21430,8 +20972,7 @@ JS_ReadString (BCReaderState *s) { return p; } -static uint32_t -bc_get_flags (uint32_t flags, int *pidx, int n) { +static uint32_t bc_get_flags (uint32_t flags, int *pidx, int n) { uint32_t val; /* XXX: this does not work for n == 32 */ val = (flags >> *pidx) & ((1U << n) - 1); @@ -21439,9 +20980,8 @@ bc_get_flags (uint32_t flags, int *pidx, int n) { return val; } -static int -JS_ReadFunctionBytecode (BCReaderState *s, JSFunctionBytecode *b, - int byte_code_offset, uint32_t bc_len) { +static int JS_ReadFunctionBytecode (BCReaderState *s, JSFunctionBytecode *b, + int byte_code_offset, uint32_t bc_len) { uint8_t *bc_buf; int pos, len, op; JSAtom atom; @@ -21504,8 +21044,7 @@ JS_ReadFunctionBytecode (BCReaderState *s, JSFunctionBytecode *b, static JSValue JS_ReadObjectRec (BCReaderState *s); -static int -BC_add_object_ref1 (BCReaderState *s, JSObject *p) { +static int BC_add_object_ref1 (BCReaderState *s, JSObject *p) { if (s->allow_reference) { if (js_resize_array (s->ctx, (void *)&s->objects, sizeof (s->objects[0]), &s->objects_size, s->objects_count + 1)) @@ -21515,13 +21054,11 @@ BC_add_object_ref1 (BCReaderState *s, JSObject *p) { return 0; } -static int -BC_add_object_ref (BCReaderState *s, JSValue obj) { +static int BC_add_object_ref (BCReaderState *s, JSValue obj) { return BC_add_object_ref1 (s, JS_VALUE_GET_OBJ (obj)); } -static JSValue -JS_ReadFunctionTag (BCReaderState *s) { +static JSValue JS_ReadFunctionTag (BCReaderState *s) { JSContext *ctx = s->ctx; JSFunctionBytecode bc, *b; JSValue obj = JS_NULL; @@ -21545,8 +21082,7 @@ JS_ReadFunctionTag (BCReaderState *s) { bc.read_only_bytecode = s->is_rom_data; if (bc_get_u8 (s, &v8)) goto fail; bc.js_mode = v8; - if (bc_get_key (s, &bc.func_name)) - goto fail; + if (bc_get_key (s, &bc.func_name)) goto fail; if (bc_get_leb128_u16 (s, &bc.arg_count)) goto fail; if (bc_get_leb128_u16 (s, &bc.var_count)) goto fail; if (bc_get_leb128_u16 (s, &bc.defined_arg_count)) goto fail; @@ -21694,8 +21230,7 @@ fail: return JS_EXCEPTION; } -static JSValue -JS_ReadObjectTag (BCReaderState *s) { +static JSValue JS_ReadObjectTag (BCReaderState *s) { JSContext *ctx = s->ctx; JSValue obj; uint32_t prop_count, i; @@ -21728,8 +21263,7 @@ fail: return JS_EXCEPTION; } -static JSValue -JS_ReadArray (BCReaderState *s, int tag) { +static JSValue JS_ReadArray (BCReaderState *s, int tag) { JSContext *ctx = s->ctx; JSValue obj; uint32_t len, i; @@ -21771,8 +21305,7 @@ fail: return JS_EXCEPTION; } -static JSValue -JS_ReadObjectValue (BCReaderState *s) { +static JSValue JS_ReadObjectValue (BCReaderState *s) { JSContext *ctx = s->ctx; JSValue val, obj = JS_NULL; @@ -21789,8 +21322,7 @@ fail: return JS_EXCEPTION; } -static JSValue -JS_ReadObjectRec (BCReaderState *s) { +static JSValue JS_ReadObjectRec (BCReaderState *s) { JSContext *ctx = s->ctx; uint8_t tag; JSValue obj = JS_NULL; @@ -21862,8 +21394,7 @@ JS_ReadObjectRec (BCReaderState *s) { return obj; } -static int -JS_ReadObjectAtoms (BCReaderState *s) { +static int JS_ReadObjectAtoms (BCReaderState *s) { uint8_t v8; JSString *p; int i; @@ -21897,8 +21428,7 @@ JS_ReadObjectAtoms (BCReaderState *s) { return 0; } -static void -bc_reader_free (BCReaderState *s) { +static void bc_reader_free (BCReaderState *s) { int i; if (s->idx_to_atom) { for (i = 0; i < s->idx_to_atom_count; i++) { @@ -21909,8 +21439,8 @@ bc_reader_free (BCReaderState *s) { js_free (s->ctx, s->objects); } -JSValue -JS_ReadObject (JSContext *ctx, const uint8_t *buf, size_t buf_len, int flags) { +JSValue JS_ReadObject (JSContext *ctx, const uint8_t *buf, size_t buf_len, + int flags) { BCReaderState ss, *s = &ss; JSValue obj; @@ -21942,28 +21472,25 @@ JS_ReadObject (JSContext *ctx, const uint8_t *buf, size_t buf_len, int flags) { /*******************************************************************/ /* runtime functions & objects */ -static int -check_function (JSContext *ctx, JSValue obj) { +static int check_function (JSContext *ctx, JSValue obj) { if (likely (JS_IsFunction (obj))) return 0; JS_ThrowTypeError (ctx, "not a function"); return -1; } -static int -check_exception_free (JSContext *ctx, JSValue obj) { +static int check_exception_free (JSContext *ctx, JSValue obj) { JS_FreeValue (ctx, obj); return JS_IsException (obj); } -static JSValue -find_key (JSContext *ctx, const char *name) { +static JSValue find_key (JSContext *ctx, const char *name) { /* Create an interned JSValue key from C string */ return js_key_new (ctx, name); } -static int -JS_InstantiateFunctionListItem (JSContext *ctx, JSValue obj, JSValue key, - const JSCFunctionListEntry *e) { +static int JS_InstantiateFunctionListItem (JSContext *ctx, JSValue obj, + JSValue key, + const JSCFunctionListEntry *e) { JSValue val; int prop_flags = e->prop_flags; @@ -22016,9 +21543,8 @@ JS_InstantiateFunctionListItem (JSContext *ctx, JSValue obj, JSValue key, return 0; } -int -JS_SetPropertyFunctionList (JSContext *ctx, JSValue obj, - const JSCFunctionListEntry *tab, int len) { +int JS_SetPropertyFunctionList (JSContext *ctx, JSValue obj, + const JSCFunctionListEntry *tab, int len) { int i, ret; for (i = 0; i < len; i++) { @@ -22034,8 +21560,7 @@ JS_SetPropertyFunctionList (JSContext *ctx, JSValue obj, /* Object class */ -static JSValue -JS_ToObject (JSContext *ctx, JSValue val) { +static JSValue JS_ToObject (JSContext *ctx, JSValue val) { int tag = JS_VALUE_GET_NORM_TAG (val); switch (tag) { @@ -22048,16 +21573,15 @@ JS_ToObject (JSContext *ctx, JSValue val) { } } -static JSValue -JS_ToObjectFree (JSContext *ctx, JSValue val) { +static JSValue JS_ToObjectFree (JSContext *ctx, JSValue val) { JSValue obj = JS_ToObject (ctx, val); JS_FreeValue (ctx, val); return obj; } // TODO: This needs to only return text atoms -static JSValue -JS_GetOwnPropertyNames2 (JSContext *ctx, JSValue obj1, int flags) { +static JSValue JS_GetOwnPropertyNames2 (JSContext *ctx, JSValue obj1, + int flags) { JSValue obj, r, val, key, value; JSObject *p; JSPropertyEnum *atoms; @@ -22095,14 +21619,13 @@ done: /* Function class */ -static JSValue -js_function_proto (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_function_proto (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { return JS_NULL; } -static __exception int -js_get_length32 (JSContext *ctx, uint32_t *pres, JSValue obj) { +static __exception int js_get_length32 (JSContext *ctx, uint32_t *pres, + JSValue obj) { int tag = JS_VALUE_GET_TAG (obj); /* Fast path for intrinsic arrays */ @@ -22139,8 +21662,8 @@ js_get_length32 (JSContext *ctx, uint32_t *pres, JSValue obj) { return JS_ToUint32Free (ctx, pres, len_val); } -static __exception int -js_get_length64 (JSContext *ctx, int64_t *pres, JSValue obj) { +static __exception int js_get_length64 (JSContext *ctx, int64_t *pres, + JSValue obj) { /* Fast path for intrinsic arrays */ if (JS_VALUE_IS_INTRINSIC_ARRAY (obj)) { JSArray *arr = JS_VALUE_GET_ARRAY (obj); @@ -22156,13 +21679,11 @@ js_get_length64 (JSContext *ctx, int64_t *pres, JSValue obj) { return JS_ToLengthFree (ctx, pres, len_val); } -int -JS_GetLength (JSContext *ctx, JSValue obj, int64_t *pres) { +int JS_GetLength (JSContext *ctx, JSValue obj, int64_t *pres) { return js_get_length64 (ctx, pres, obj); } -static void -free_arg_list (JSContext *ctx, JSValue *tab, uint32_t len) { +static void free_arg_list (JSContext *ctx, JSValue *tab, uint32_t len) { uint32_t i; for (i = 0; i < len; i++) { JS_FreeValue (ctx, tab[i]); @@ -22171,8 +21692,8 @@ free_arg_list (JSContext *ctx, JSValue *tab, uint32_t len) { } /* XXX: should use ValueArray */ -static JSValue * -build_arg_list (JSContext *ctx, uint32_t *plen, JSValue array_arg) { +static JSValue *build_arg_list (JSContext *ctx, uint32_t *plen, + JSValue array_arg) { uint32_t len, i; JSValue *tab; @@ -22200,9 +21721,8 @@ build_arg_list (JSContext *ctx, uint32_t *plen, JSValue array_arg) { } /* magic value: 0 = normal apply, 2 = Reflect.apply */ -static JSValue -js_function_apply (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv, int magic) { +static JSValue js_function_apply (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv, int magic) { JSValue this_arg, array_arg; uint32_t len; JSValue *tab, ret; @@ -22229,9 +21749,8 @@ js_function_apply (JSContext *ctx, JSValue this_val, int argc, } /* Error class */ -static JSValue -js_error_constructor (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv, int magic) { +static JSValue js_error_constructor (JSContext *ctx, JSValue this_val, + int argc, JSValue *argv, int magic) { JSValue obj, msg; JSValue message, options, proto; int arg_index; @@ -22300,9 +21819,8 @@ exception: return JS_EXCEPTION; } -static JSValue -js_error_toString (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_error_toString (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { printf ("E TO STR\n"); JSValue name, msg; @@ -22328,9 +21846,8 @@ js_error_toString (JSContext *ctx, JSValue this_val, int argc, return JS_ConcatString (ctx, name, msg); } -static JSValue -js_array_includes (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_array_includes (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { JSValue found = js_cell_array_find (ctx, this_val, argc, argv); if (JS_IsException (found)) return JS_EXCEPTION; @@ -22338,8 +21855,7 @@ js_array_includes (JSContext *ctx, JSValue this_val, int argc, return JS_NewBool (ctx, TRUE); } -static int -string_cmp (JSString *p1, JSString *p2, int x1, int x2, int len) { +static int string_cmp (JSString *p1, JSString *p2, int x1, int x2, int len) { int i, c1, c2; for (i = 0; i < len; i++) { if ((c1 = string_get (p1, x1 + i)) != (c2 = string_get (p2, x2 + i))) @@ -22353,8 +21869,7 @@ static int js_is_regexp (JSContext *ctx, JSValue obj); /* RegExp */ -static void -js_regexp_finalizer (JSRuntime *rt, JSValue val) { +static void js_regexp_finalizer (JSRuntime *rt, JSValue val) { JSObject *p = JS_VALUE_GET_OBJ (val); JSRegExp *re = &p->u.regexp; JS_FreeValueRT (rt, JS_MKPTR (JS_TAG_STRING, re->bytecode)); @@ -22362,8 +21877,8 @@ js_regexp_finalizer (JSRuntime *rt, JSValue val) { } /* create a string containing the RegExp bytecode */ -static JSValue -js_compile_regexp (JSContext *ctx, JSValue pattern, JSValue flags) { +static JSValue js_compile_regexp (JSContext *ctx, JSValue pattern, + JSValue flags) { const char *str; int re_flags, mask; uint8_t *re_bytecode_buf; @@ -22442,8 +21957,8 @@ js_compile_regexp (JSContext *ctx, JSValue pattern, JSValue flags) { /* create a RegExp object from a string containing the RegExp bytecode and the source pattern */ -static JSValue -js_regexp_constructor_internal (JSContext *ctx, JSValue pattern, JSValue bc) { +static JSValue js_regexp_constructor_internal (JSContext *ctx, JSValue pattern, + JSValue bc) { JSValue obj; JSObject *p; JSRegExp *re; @@ -22473,8 +21988,8 @@ js_regexp_constructor_internal (JSContext *ctx, JSValue pattern, JSValue bc) { return obj; } -static JSRegExp * -js_get_regexp (JSContext *ctx, JSValue obj, BOOL throw_error) { +static JSRegExp *js_get_regexp (JSContext *ctx, JSValue obj, + BOOL throw_error) { if (JS_VALUE_GET_TAG (obj) == JS_TAG_OBJECT) { JSObject *p = JS_VALUE_GET_OBJ (obj); if (p->class_id == JS_CLASS_REGEXP) return &p->u.regexp; @@ -22484,8 +21999,7 @@ js_get_regexp (JSContext *ctx, JSValue obj, BOOL throw_error) { } /* return < 0 if exception or TRUE/FALSE */ -static int -js_is_regexp (JSContext *ctx, JSValue obj) { +static int js_is_regexp (JSContext *ctx, JSValue obj) { JSValue m; if (!JS_IsObject (obj)) return FALSE; @@ -22495,9 +22009,8 @@ js_is_regexp (JSContext *ctx, JSValue obj) { return js_get_regexp (ctx, obj, FALSE) != NULL; } -static JSValue -js_regexp_constructor (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_regexp_constructor (JSContext *ctx, JSValue this_val, + int argc, JSValue *argv) { JSValue pattern, flags, bc, val; JSValue pat, flags1; JSRegExp *re; @@ -22557,9 +22070,8 @@ fail: return JS_EXCEPTION; } -static JSValue -js_regexp_compile (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_regexp_compile (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { JSRegExp *re1, *re; JSValue pattern1, flags1; JSValue bc, pattern; @@ -22601,9 +22113,8 @@ fail: return JS_EXCEPTION; } -static JSValue -js_regexp_toString (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_regexp_toString (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { JSValue pattern, flags; StringBuffer b_s, *b = &b_s; @@ -22623,22 +22134,19 @@ fail: return JS_EXCEPTION; } -int -lre_check_stack_overflow (void *opaque, size_t alloca_size) { +int lre_check_stack_overflow (void *opaque, size_t alloca_size) { JSContext *ctx = opaque; return js_check_stack_overflow (ctx->rt, alloca_size); } -int -lre_check_timeout (void *opaque) { +int lre_check_timeout (void *opaque) { JSContext *ctx = opaque; JSRuntime *rt = ctx->rt; return (rt->interrupt_handler && rt->interrupt_handler (rt, rt->interrupt_opaque)); } -void * -lre_realloc (void *opaque, void *ptr, size_t size) { +void *lre_realloc (void *opaque, void *ptr, size_t size) { JSContext *ctx = opaque; /* No JS exception is raised here */ return js_realloc_rt (ctx->rt, ptr, size); @@ -22647,8 +22155,8 @@ lre_realloc (void *opaque, void *ptr, size_t size) { /* Convert UTF-32 JSString to UTF-16 buffer for regex engine. Returns allocated uint16_t buffer that must be freed by caller. Sets *out_len to number of uint16 code units. */ -static uint16_t * -js_string_to_utf16 (JSContext *ctx, JSString *str, int *out_len) { +static uint16_t *js_string_to_utf16 (JSContext *ctx, JSString *str, + int *out_len) { int len = str->len; /* Worst case: each UTF-32 char becomes 2 UTF-16 surrogates */ uint16_t *buf = js_malloc (ctx, len * 2 * sizeof (uint16_t)); @@ -22670,9 +22178,8 @@ js_string_to_utf16 (JSContext *ctx, JSString *str, int *out_len) { return buf; } -static JSValue -js_regexp_exec (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_regexp_exec (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { JSRegExp *re = js_get_regexp (ctx, this_val, TRUE); JSString *str; JSValue ret, str_val, res, val, groups, captures_arr, match0; @@ -22729,7 +22236,7 @@ js_regexp_exec (JSContext *ctx, JSValue this_val, int argc, if (rc >= 0) { if (rc == 2 || (re_flags & (LRE_FLAG_GLOBAL | LRE_FLAG_STICKY))) { if (JS_SetPropertyStr (ctx, this_val, "lastIndex", - JS_NewInt32 (ctx, 0)) + JS_NewInt32 (ctx, 0)) < 0) goto fail; } @@ -22745,7 +22252,7 @@ js_regexp_exec (JSContext *ctx, JSValue this_val, int argc, if (re_flags & (LRE_FLAG_GLOBAL | LRE_FLAG_STICKY)) { if (JS_SetPropertyStr (ctx, this_val, "lastIndex", - JS_NewInt32 (ctx, (capture[1] - str_buf) >> shift)) + JS_NewInt32 (ctx, (capture[1] - str_buf) >> shift)) < 0) goto fail; } @@ -22858,8 +22365,8 @@ fail: } /* delete portions of a string that match a given regex */ -static JSValue -JS_RegExpDelete (JSContext *ctx, JSValue this_val, JSValue arg) { +static JSValue JS_RegExpDelete (JSContext *ctx, JSValue this_val, + JSValue arg) { JSRegExp *re = js_get_regexp (ctx, this_val, TRUE); JSString *str; JSValue str_val, val; @@ -22904,13 +22411,13 @@ JS_RegExpDelete (JSContext *ctx, JSValue this_val, JSValue arg) { for (;;) { if (last_index > utf16_len) break; - ret = lre_exec (capture, re_bytecode, str_buf, last_index, utf16_len, shift, - ctx); + ret = lre_exec (capture, re_bytecode, str_buf, last_index, utf16_len, + shift, ctx); if (ret != 1) { if (ret >= 0) { if (ret == 2 || (re_flags & (LRE_FLAG_GLOBAL | LRE_FLAG_STICKY))) { if (JS_SetPropertyStr (ctx, this_val, "lastIndex", - JS_NewInt32 (ctx, 0)) + JS_NewInt32 (ctx, 0)) < 0) goto fail; } @@ -22933,7 +22440,7 @@ JS_RegExpDelete (JSContext *ctx, JSValue this_val, JSValue arg) { next_src_pos = end; if (!(re_flags & LRE_FLAG_GLOBAL)) { if (JS_SetPropertyStr (ctx, this_val, "lastIndex", - JS_NewInt32 (ctx, end)) + JS_NewInt32 (ctx, end)) < 0) goto fail; break; @@ -22967,8 +22474,7 @@ fail: return JS_EXCEPTION; } -static JSValue -JS_RegExpExec (JSContext *ctx, JSValue r, JSValue s) { +static JSValue JS_RegExpExec (JSContext *ctx, JSValue r, JSValue s) { JSValue method, ret; method = JS_GetProperty (ctx, r, JS_KEY_exec); @@ -22987,8 +22493,7 @@ JS_RegExpExec (JSContext *ctx, JSValue r, JSValue s) { return js_regexp_exec (ctx, r, 1, &s); } -static int -js_is_standard_regexp (JSContext *ctx, JSValue rx) { +static int js_is_standard_regexp (JSContext *ctx, JSValue rx) { JSValue val; int res; @@ -23013,13 +22518,11 @@ static const JSCFunctionListEntry js_regexp_proto_funcs[] = { JS_CFUNC_DEF ("toString", 0, js_regexp_toString), }; -void -JS_AddIntrinsicRegExpCompiler (JSContext *ctx) { +void JS_AddIntrinsicRegExpCompiler (JSContext *ctx) { ctx->compile_regexp = js_compile_regexp; } -void -JS_AddIntrinsicRegExp (JSContext *ctx) { +void JS_AddIntrinsicRegExp (JSContext *ctx) { JSValue obj; JS_AddIntrinsicRegExpCompiler (ctx); @@ -23036,8 +22539,7 @@ JS_AddIntrinsicRegExp (JSContext *ctx) { /* JSON */ -static int -json_parse_expect (JSParseState *s, int tok) { +static int json_parse_expect (JSParseState *s, int tok) { if (s->token.val != tok) { /* XXX: dump token correctly in all cases */ return js_parse_error (s, "expecting '%c'", tok); @@ -23045,8 +22547,7 @@ json_parse_expect (JSParseState *s, int tok) { return json_next_token (s); } -static JSValue -json_parse_value (JSParseState *s) { +static JSValue json_parse_value (JSParseState *s) { JSContext *ctx = s->ctx; JSValue val = JS_NULL; int ret; @@ -23129,7 +22630,8 @@ json_parse_value (JSParseState *s) { /* Note: json5 identifier handling is ambiguous e.g. is '{ NaN: 1 }' a valid JSON5 production ? */ val = JS_NewFloat64 (s->ctx, NAN); - } else if (js_key_equal_str (s->token.u.ident.str, "Infinity") && s->ext_json) { + } else if (js_key_equal_str (s->token.u.ident.str, "Infinity") + && s->ext_json) { val = JS_NewFloat64 (s->ctx, INFINITY); } else { goto def_token; @@ -23152,9 +22654,8 @@ fail: return JS_EXCEPTION; } -JSValue -JS_ParseJSON2 (JSContext *ctx, const char *buf, size_t buf_len, - const char *filename, int flags) { +JSValue JS_ParseJSON2 (JSContext *ctx, const char *buf, size_t buf_len, + const char *filename, int flags) { JSParseState s1, *s = &s1; JSValue val = JS_NULL; @@ -23173,15 +22674,13 @@ fail: return JS_EXCEPTION; } -JSValue -JS_ParseJSON (JSContext *ctx, const char *buf, size_t buf_len, - const char *filename) { +JSValue JS_ParseJSON (JSContext *ctx, const char *buf, size_t buf_len, + const char *filename) { return JS_ParseJSON2 (ctx, buf, buf_len, filename, 0); } -static JSValue -internalize_json_property (JSContext *ctx, JSValue holder, JSValue name, - JSValue reviver) { +static JSValue internalize_json_property (JSContext *ctx, JSValue holder, + JSValue name, JSValue reviver) { JSValue val, new_el, res; JSValue args[2]; int ret, is_array; @@ -23207,9 +22706,7 @@ internalize_json_property (JSContext *ctx, JSValue holder, JSValue name, /* For arrays, use integer index as key */ prop = JS_NewInt32 (ctx, i); new_el = internalize_json_property (ctx, val, prop, reviver); - if (JS_IsException (new_el)) { - goto fail; - } + if (JS_IsException (new_el)) { goto fail; } if (JS_IsNull (new_el)) { ret = JS_DeleteProperty (ctx, val, prop); } else { @@ -23230,9 +22727,8 @@ fail: return JS_EXCEPTION; } -static JSValue -js_json_parse (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_json_parse (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { JSValue obj, root; JSValue reviver; const char *str; @@ -23269,16 +22765,14 @@ typedef struct JSONStringifyContext { StringBuffer *b; } JSONStringifyContext; -static JSValue -JS_ToQuotedStringFree (JSContext *ctx, JSValue val) { +static JSValue JS_ToQuotedStringFree (JSContext *ctx, JSValue val) { JSValue r = JS_ToQuotedString (ctx, val); JS_FreeValue (ctx, val); return r; } -static JSValue -js_json_check (JSContext *ctx, JSONStringifyContext *jsc, JSValue holder, - JSValue val, JSValue key) { +static JSValue js_json_check (JSContext *ctx, JSONStringifyContext *jsc, + JSValue holder, JSValue val, JSValue key) { JSValue v; JSValue args[2]; @@ -23329,9 +22823,8 @@ exception: return JS_EXCEPTION; } -static int -js_json_to_str (JSContext *ctx, JSONStringifyContext *jsc, JSValue holder, - JSValue val, JSValue indent) { +static int js_json_to_str (JSContext *ctx, JSONStringifyContext *jsc, + JSValue holder, JSValue val, JSValue indent) { JSValue indent1, sep, sep1, tab, v, prop; JSObject *p; int64_t i, len; @@ -23475,9 +22968,8 @@ exception: return -1; } -JSValue -JS_JSONStringify (JSContext *ctx, JSValue obj, JSValue replacer, - JSValue space0) { +JSValue JS_JSONStringify (JSContext *ctx, JSValue obj, JSValue replacer, + JSValue space0) { StringBuffer b_s; JSONStringifyContext jsc_s, *jsc = &jsc_s; JSValue val, v, space, ret, wrapper; @@ -23580,9 +23072,8 @@ done: return ret; } -static JSValue -js_json_stringify (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_json_stringify (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { // stringify(val, replacer, space) return JS_JSONStringify (ctx, argv[0], argv[1], argv[2]); } @@ -23597,8 +23088,7 @@ static const JSCFunctionListEntry js_json_obj[] = { JS_OBJECT_DEF ("JSON", js_json_funcs, countof (js_json_funcs), 0), }; -void -JS_AddIntrinsicJSON (JSContext *ctx) { +void JS_AddIntrinsicJSON (JSContext *ctx) { /* add JSON as autoinit object */ JS_SetPropertyFunctionList (ctx, ctx->global_obj, js_json_obj, countof (js_json_obj)); @@ -23624,9 +23114,8 @@ JS_AddIntrinsicJSON (JSContext *ctx) { */ /* number(val, format) - convert to number */ -static JSValue -js_cell_number (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_number (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_NULL; JSValue val = argv[0]; @@ -23807,27 +23296,24 @@ js_cell_number (JSContext *ctx, JSValue this_val, int argc, } /* number.whole(n) - truncate to integer */ -static JSValue -js_cell_number_whole (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_number_whole (JSContext *ctx, JSValue this_val, + int argc, JSValue *argv) { double d; if (JS_ToFloat64 (ctx, &d, argv[0])) return JS_NULL; return JS_NewFloat64 (ctx, trunc (d)); } /* number.fraction(n) - get fractional part */ -static JSValue -js_cell_number_fraction (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_number_fraction (JSContext *ctx, JSValue this_val, + int argc, JSValue *argv) { double d; if (JS_ToFloat64 (ctx, &d, argv[0])) return JS_NULL; return JS_NewFloat64 (ctx, d - trunc (d)); } /* number.floor(n, place) - floor with optional decimal place */ -static JSValue -js_cell_number_floor (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_number_floor (JSContext *ctx, JSValue this_val, + int argc, JSValue *argv) { double d; if (JS_ToFloat64 (ctx, &d, argv[0])) return JS_NULL; if (argc < 2 || JS_IsNull (argv[1])) { @@ -23841,9 +23327,8 @@ js_cell_number_floor (JSContext *ctx, JSValue this_val, int argc, } /* number.ceiling(n, place) - ceiling with optional decimal place */ -static JSValue -js_cell_number_ceiling (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_number_ceiling (JSContext *ctx, JSValue this_val, + int argc, JSValue *argv) { double d; if (JS_ToFloat64 (ctx, &d, argv[0])) return JS_NULL; if (argc < 2 || JS_IsNull (argv[1])) { @@ -23857,9 +23342,8 @@ js_cell_number_ceiling (JSContext *ctx, JSValue this_val, int argc, } /* number.abs(n) - absolute value */ -static JSValue -js_cell_number_abs (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_number_abs (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_NULL; int tag = JS_VALUE_GET_TAG (argv[0]); if (tag != JS_TAG_INT && tag != JS_TAG_FLOAT64) return JS_NULL; @@ -23869,9 +23353,8 @@ js_cell_number_abs (JSContext *ctx, JSValue this_val, int argc, } /* number.round(n, place) - round with optional decimal place */ -static JSValue -js_cell_number_round (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_number_round (JSContext *ctx, JSValue this_val, + int argc, JSValue *argv) { double d; if (JS_ToFloat64 (ctx, &d, argv[0])) return JS_NULL; if (argc < 2 || JS_IsNull (argv[1])) { @@ -23885,9 +23368,8 @@ js_cell_number_round (JSContext *ctx, JSValue this_val, int argc, } /* number.sign(n) - return sign (-1, 0, 1) */ -static JSValue -js_cell_number_sign (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_number_sign (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { double d; if (JS_ToFloat64 (ctx, &d, argv[0])) return JS_NULL; if (d < 0) return JS_NewInt32 (ctx, -1); @@ -23896,9 +23378,8 @@ js_cell_number_sign (JSContext *ctx, JSValue this_val, int argc, } /* number.trunc(n, place) - truncate with optional decimal place */ -static JSValue -js_cell_number_trunc (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_number_trunc (JSContext *ctx, JSValue this_val, + int argc, JSValue *argv) { double d; if (JS_ToFloat64 (ctx, &d, argv[0])) return JS_NULL; if (argc < 2 || JS_IsNull (argv[1])) { @@ -23912,9 +23393,8 @@ js_cell_number_trunc (JSContext *ctx, JSValue this_val, int argc, } /* number.min(...vals) - minimum value */ -static JSValue -js_cell_number_min (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_number_min (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc == 0) return JS_NULL; double result; if (JS_ToFloat64 (ctx, &result, argv[0])) return JS_NULL; @@ -23927,9 +23407,8 @@ js_cell_number_min (JSContext *ctx, JSValue this_val, int argc, } /* number.max(...vals) - maximum value */ -static JSValue -js_cell_number_max (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_number_max (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc == 0) return JS_NULL; double result; if (JS_ToFloat64 (ctx, &result, argv[0])) return JS_NULL; @@ -23942,9 +23421,8 @@ js_cell_number_max (JSContext *ctx, JSValue this_val, int argc, } /* number.remainder(dividend, divisor) - remainder after division */ -static JSValue -js_cell_number_remainder (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_number_remainder (JSContext *ctx, JSValue this_val, + int argc, JSValue *argv) { if (argc < 2) return JS_NULL; double dividend, divisor; if (JS_ToFloat64 (ctx, ÷nd, argv[0])) return JS_NULL; @@ -23960,8 +23438,8 @@ js_cell_number_remainder (JSContext *ctx, JSValue this_val, int argc, */ /* Helper: convert number to string with radix */ -static JSValue -js_cell_number_to_radix_string (JSContext *ctx, double num, int radix) { +static JSValue js_cell_number_to_radix_string (JSContext *ctx, double num, + int radix) { if (radix < 2 || radix > 36) return JS_NULL; /* For base 10, handle floating point properly */ @@ -24013,8 +23491,7 @@ js_cell_number_to_radix_string (JSContext *ctx, double num, int radix) { } /* Helper: add separator every n digits from right */ -static char * -add_separator (JSContext *ctx, const char *str, char sep, int n) { +static char *add_separator (JSContext *ctx, const char *str, char sep, int n) { if (n <= 0) { char *result = js_malloc (ctx, strlen (str) + 1); if (result) strcpy (result, str); @@ -24058,8 +23535,8 @@ add_separator (JSContext *ctx, const char *str, char sep, int n) { } /* Helper: format number with format string */ -static JSValue -js_cell_format_number (JSContext *ctx, double num, const char *format) { +static JSValue js_cell_format_number (JSContext *ctx, double num, + const char *format) { int separation = 0; char style = '\0'; int places = 0; @@ -24258,9 +23735,8 @@ js_cell_format_number (JSContext *ctx, double num, const char *format) { static blob *js_get_blob (JSContext *ctx, JSValue val); /* modulo(dividend, divisor) - result has sign of divisor */ -static JSValue -js_cell_modulo (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_modulo (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 2) return JS_NULL; double dividend, divisor; @@ -24283,9 +23759,8 @@ js_cell_modulo (JSContext *ctx, JSValue this_val, int argc, } /* not(bool) - negate a boolean value */ -static JSValue -js_cell_not (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_not (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_NULL; if (!JS_IsBool (argv[0])) return JS_NULL; @@ -24294,9 +23769,8 @@ js_cell_not (JSContext *ctx, JSValue this_val, int argc, } /* neg(number) - negate a number */ -static JSValue -js_cell_neg (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_neg (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_NULL; double num; @@ -24308,9 +23782,8 @@ js_cell_neg (JSContext *ctx, JSValue this_val, int argc, } /* character(value) - get character from text or codepoint */ -static JSValue -js_cell_character (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_character (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_NewString (ctx, ""); JSValue arg = argv[0]; @@ -24321,7 +23794,8 @@ js_cell_character (JSContext *ctx, JSValue this_val, int argc, JSString *p = JS_VALUE_GET_STRING (arg); if (p->len == 0) return JS_NewString (ctx, ""); - /* UTF-32: each element is a full code point, no surrogate handling needed */ + /* UTF-32: each element is a full code point, no surrogate handling needed + */ return js_sub_string (ctx, p, 0, 1); } @@ -24376,9 +23850,8 @@ js_cell_character (JSContext *ctx, JSValue this_val, int argc, } /* text(arg, format) - main text function */ -static JSValue -js_cell_text (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_text (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_NULL; JSValue arg = argv[0]; @@ -24643,9 +24116,8 @@ js_cell_text (JSContext *ctx, JSValue this_val, int argc, } /* text.lower(str) - convert to lowercase */ -static JSValue -js_cell_text_lower (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_text_lower (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_NULL; if (!JS_VALUE_IS_TEXT (argv[0])) return JS_NULL; @@ -24666,9 +24138,8 @@ js_cell_text_lower (JSContext *ctx, JSValue this_val, int argc, } /* text.upper(str) - convert to uppercase */ -static JSValue -js_cell_text_upper (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_text_upper (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_NULL; if (!JS_VALUE_IS_TEXT (argv[0])) return JS_NULL; @@ -24689,9 +24160,8 @@ js_cell_text_upper (JSContext *ctx, JSValue this_val, int argc, } /* text.trim(str, reject) - trim whitespace or custom characters */ -static JSValue -js_cell_text_trim (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_text_trim (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_NULL; int tag = JS_VALUE_GET_TAG (argv[0]); if (tag != JS_TAG_STRING && tag != JS_TAG_STRING_IMM) return JS_NULL; @@ -24751,9 +24221,8 @@ js_cell_text_trim (JSContext *ctx, JSValue this_val, int argc, } /* text.codepoint(str) - get first codepoint */ -static JSValue -js_cell_text_codepoint (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_text_codepoint (JSContext *ctx, JSValue this_val, + int argc, JSValue *argv) { if (argc < 1) return JS_NULL; int tag = JS_VALUE_GET_TAG (argv[0]); if (tag != JS_TAG_STRING && tag != JS_TAG_STRING_IMM) return JS_NULL; @@ -24783,8 +24252,8 @@ js_cell_text_codepoint (JSContext *ctx, JSValue this_val, int argc, /* Helpers (C, not C++). Put these above js_cell_text_replace in the same C * file. */ -static int -sb_concat_value_to_string_free (JSContext *ctx, StringBuffer *b, JSValue v) { +static int sb_concat_value_to_string_free (JSContext *ctx, StringBuffer *b, + JSValue v) { JSValue s = JS_ToString (ctx, v); JS_FreeValue (ctx, v); if (JS_IsException (s)) return -1; @@ -24801,9 +24270,8 @@ sb_concat_value_to_string_free (JSContext *ctx, StringBuffer *b, JSValue v) { * free it via args cleanup), otherwise it will free match_val before * returning. */ -static JSValue -make_replacement (JSContext *ctx, int argc, JSValue *argv, int found, - JSValue match_val) { +static JSValue make_replacement (JSContext *ctx, int argc, JSValue *argv, + int found, JSValue match_val) { JSValue rep; if (argc > 2 && JS_IsFunction (argv[2])) { @@ -24822,8 +24290,7 @@ make_replacement (JSContext *ctx, int argc, JSValue *argv, int found, return JS_KEY_empty; } -static int -JS_IsRegExp (JSContext *ctx, JSValue v) { +static int JS_IsRegExp (JSContext *ctx, JSValue v) { if (!JS_IsObject (v)) return 0; JSValue exec = JS_GetPropertyStr (ctx, v, "exec"); @@ -24849,9 +24316,8 @@ JS_IsRegExp (JSContext *ctx, JSValue v) { * limit even if replacement returns null. */ -static JSValue -js_cell_text_replace (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_text_replace (JSContext *ctx, JSValue this_val, + int argc, JSValue *argv) { if (argc < 2) return JS_NULL; int tag_text = JS_VALUE_GET_TAG (argv[0]); @@ -25097,9 +24563,8 @@ fail_rx: } /* text.search(str, target, from) - find substring or regex match */ -static JSValue -js_cell_text_search (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_text_search (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 2) return JS_NULL; int tag1 = JS_VALUE_GET_TAG (argv[0]); @@ -25177,8 +24642,7 @@ js_cell_text_search (JSContext *ctx, JSValue this_val, int argc, JSValue sub_str = js_sub_string (ctx, p, from, len); if (JS_IsException (sub_str)) goto fail_rx_search; - JSValue exec_res - = JS_Invoke (ctx, rx, JS_KEY_exec, 1, (JSValue *)&sub_str); + JSValue exec_res = JS_Invoke (ctx, rx, JS_KEY_exec, 1, (JSValue *)&sub_str); JS_FreeValue (ctx, sub_str); if (JS_IsException (exec_res)) goto fail_rx_search; @@ -25222,13 +24686,12 @@ fail_rx_search: /* str removed - arg not owned */ return JS_EXCEPTION; } -static inline uint32_t -js_str_get (JSString *s, int idx) { +static inline uint32_t js_str_get (JSString *s, int idx) { return string_get (s, idx); } -static int -js_str_find_range (JSString *hay, int from, int to, JSString *needle) { +static int js_str_find_range (JSString *hay, int from, int to, + JSString *needle) { int nlen = (int)needle->len; int hlen = (int)hay->len; @@ -25255,9 +24718,8 @@ js_str_find_range (JSString *hay, int from, int to, JSString *needle) { - literal pattern: [match] - regexp pattern: [full_match, cap1, cap2, ...] */ -static JSValue -js_cell_text_extract (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_text_extract (JSContext *ctx, JSValue this_val, + int argc, JSValue *argv) { if (argc < 2) return JS_NULL; int tag_text = JS_VALUE_GET_TAG (argv[0]); @@ -25414,9 +24876,8 @@ js_cell_text_extract (JSContext *ctx, JSValue this_val, int argc, */ /* array(arg, arg2, arg3, arg4) - main array function */ -static JSValue -js_cell_array (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_array (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_NULL; JSValue arg = argv[0]; @@ -25880,9 +25341,8 @@ js_cell_array (JSContext *ctx, JSValue this_val, int argc, } /* array.reduce(arr, fn, initial, reverse) */ -static JSValue -js_cell_array_reduce (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_array_reduce (JSContext *ctx, JSValue this_val, + int argc, JSValue *argv) { if (argc < 2) return JS_NULL; if (!JS_IsArray (ctx, argv[0])) return JS_NULL; if (!JS_IsFunction (argv[1])) return JS_NULL; @@ -25948,9 +25408,8 @@ js_cell_array_reduce (JSContext *ctx, JSValue this_val, int argc, } /* array.for(arr, fn, reverse, exit) */ -static JSValue -js_cell_array_for (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_array_for (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 2) return JS_NULL; if (!JS_IsArray (ctx, argv[0])) return JS_NULL; if (!JS_IsFunction (argv[1])) return JS_NULL; @@ -26017,9 +25476,8 @@ js_cell_array_for (JSContext *ctx, JSValue this_val, int argc, } /* array.find(arr, fn, reverse, from) */ -static JSValue -js_cell_array_find (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_array_find (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 2) return JS_NULL; if (!JS_IsArray (ctx, argv[0])) return JS_NULL; @@ -26117,9 +25575,8 @@ js_cell_array_find (JSContext *ctx, JSValue this_val, int argc, } /* array.filter(arr, fn) */ -static JSValue -js_cell_array_filter (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_array_filter (JSContext *ctx, JSValue this_val, + int argc, JSValue *argv) { if (argc < 2) return JS_NULL; if (!JS_IsArray (ctx, argv[0])) return JS_NULL; if (!JS_IsFunction (argv[1])) return JS_NULL; @@ -26207,9 +25664,8 @@ js_cell_array_filter (JSContext *ctx, JSValue this_val, int argc, } /* array.sort(arr, select) */ -static JSValue -js_cell_array_sort (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_array_sort (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_NULL; if (!JS_IsArray (ctx, argv[0])) return JS_NULL; @@ -26260,8 +25716,8 @@ js_cell_array_sort (JSContext *ctx, JSValue this_val, int argc, } else { key = JS_GetPropertyInt64 (ctx, items[i], idx); } - } else if (JS_VALUE_GET_TAG (argv[1]) == JS_TAG_STRING || - JS_VALUE_GET_TAG (argv[1]) == JS_TAG_STRING_IMM) { + } else if (JS_VALUE_GET_TAG (argv[1]) == JS_TAG_STRING + || JS_VALUE_GET_TAG (argv[1]) == JS_TAG_STRING_IMM) { JSValue prop_key = js_key_from_string (ctx, argv[1]); key = JS_GetProperty (ctx, items[i], prop_key); } else if (key_arr) { @@ -26382,9 +25838,8 @@ js_cell_array_sort (JSContext *ctx, JSValue this_val, int argc, */ /* object(arg, arg2) - main object function */ -static JSValue -js_cell_object (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_object (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_NULL; JSValue arg = argv[0]; @@ -26406,14 +25861,16 @@ js_cell_object (JSContext *ctx, JSValue this_val, int argc, for (uint32_t i = 0; i < len; i++) { JSValue val = JS_GetProperty (ctx, arg, keys[i]); if (JS_IsException (val)) { - for (uint32_t j = 0; j < len; j++) JS_FreeValue (ctx, keys[j]); + for (uint32_t j = 0; j < len; j++) + JS_FreeValue (ctx, keys[j]); js_free (ctx, keys); JS_FreeValue (ctx, result); return JS_EXCEPTION; } JS_SetProperty (ctx, result, keys[i], val); } - for (uint32_t i = 0; i < len; i++) JS_FreeValue (ctx, keys[i]); + for (uint32_t i = 0; i < len; i++) + JS_FreeValue (ctx, keys[i]); js_free (ctx, keys); return result; } @@ -26433,14 +25890,16 @@ js_cell_object (JSContext *ctx, JSValue this_val, int argc, for (uint32_t i = 0; i < len; i++) { JSValue val = JS_GetProperty (ctx, arg, keys[i]); if (JS_IsException (val)) { - for (uint32_t j = 0; j < len; j++) JS_FreeValue (ctx, keys[j]); + for (uint32_t j = 0; j < len; j++) + JS_FreeValue (ctx, keys[j]); js_free (ctx, keys); JS_FreeValue (ctx, result); return JS_EXCEPTION; } JS_SetProperty (ctx, result, keys[i], val); } - for (uint32_t i = 0; i < len; i++) JS_FreeValue (ctx, keys[i]); + for (uint32_t i = 0; i < len; i++) + JS_FreeValue (ctx, keys[i]); js_free (ctx, keys); /* Copy from second object */ @@ -26451,14 +25910,16 @@ js_cell_object (JSContext *ctx, JSValue this_val, int argc, for (uint32_t i = 0; i < len; i++) { JSValue val = JS_GetProperty (ctx, argv[1], keys[i]); if (JS_IsException (val)) { - for (uint32_t j = 0; j < len; j++) JS_FreeValue (ctx, keys[j]); + for (uint32_t j = 0; j < len; j++) + JS_FreeValue (ctx, keys[j]); js_free (ctx, keys); JS_FreeValue (ctx, result); return JS_EXCEPTION; } JS_SetProperty (ctx, result, keys[i], val); } - for (uint32_t i = 0; i < len; i++) JS_FreeValue (ctx, keys[i]); + for (uint32_t i = 0; i < len; i++) + JS_FreeValue (ctx, keys[i]); js_free (ctx, keys); return result; } @@ -26539,9 +26000,8 @@ js_cell_object (JSContext *ctx, JSValue this_val, int argc, */ /* fn.apply(func, args) - arity is enforced in JS_CallInternal */ -static JSValue -js_cell_fn_apply (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_fn_apply (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_NULL; if (!JS_IsFunction (argv[0])) return JS_DupValue (ctx, argv[0]); @@ -26585,8 +26045,7 @@ js_cell_fn_apply (JSContext *ctx, JSValue this_val, int argc, */ /* Helper to check if JSValue is a blob */ -static blob * -js_get_blob (JSContext *ctx, JSValue val) { +static blob *js_get_blob (JSContext *ctx, JSValue val) { if (JS_VALUE_GET_TAG (val) != JS_TAG_OBJECT) return NULL; JSObject *p = JS_VALUE_GET_OBJ (val); if (p->class_id != JS_CLASS_BLOB) return NULL; @@ -26594,8 +26053,7 @@ js_get_blob (JSContext *ctx, JSValue val) { } /* Helper to create a new blob JSValue */ -static JSValue -js_new_blob (JSContext *ctx, blob *b) { +static JSValue js_new_blob (JSContext *ctx, blob *b) { JSValue obj = JS_NewObjectClass (ctx, JS_CLASS_BLOB); if (JS_IsException (obj)) { blob_destroy (b); @@ -26606,16 +26064,14 @@ js_new_blob (JSContext *ctx, blob *b) { } /* Blob finalizer */ -static void -js_blob_finalizer (JSRuntime *rt, JSValue val) { +static void js_blob_finalizer (JSRuntime *rt, JSValue val) { blob *b = JS_GetOpaque (val, JS_CLASS_BLOB); if (b) blob_destroy (b); } /* blob() constructor */ -static JSValue -js_blob_constructor (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_blob_constructor (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { blob *bd = NULL; /* blob() - empty blob */ @@ -26720,9 +26176,8 @@ js_blob_constructor (JSContext *ctx, JSValue this_val, int argc, } /* blob.write_bit(logical) */ -static JSValue -js_blob_write_bit (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_blob_write_bit (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_ThrowTypeError (ctx, "write_bit(logical) requires 1 argument"); blob *bd = js_get_blob (ctx, this_val); @@ -26747,9 +26202,8 @@ js_blob_write_bit (JSContext *ctx, JSValue this_val, int argc, } /* blob.write_blob(second_blob) */ -static JSValue -js_blob_write_blob (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_blob_write_blob (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_ThrowTypeError (ctx, "write_blob(second_blob) requires 1 argument"); @@ -26767,9 +26221,8 @@ js_blob_write_blob (JSContext *ctx, JSValue this_val, int argc, } /* blob.write_number(number) - write dec64 */ -static JSValue -js_blob_write_number (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_blob_write_number (JSContext *ctx, JSValue this_val, + int argc, JSValue *argv) { if (argc < 1) return JS_ThrowTypeError (ctx, "write_number(number) requires 1 argument"); blob *bd = js_get_blob (ctx, this_val); @@ -26787,9 +26240,8 @@ js_blob_write_number (JSContext *ctx, JSValue this_val, int argc, } /* blob.write_fit(value, len) */ -static JSValue -js_blob_write_fit (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_blob_write_fit (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 2) return JS_ThrowTypeError (ctx, "write_fit(value, len) requires 2 arguments"); @@ -26811,9 +26263,8 @@ js_blob_write_fit (JSContext *ctx, JSValue this_val, int argc, } /* blob.write_text(text) */ -static JSValue -js_blob_write_text (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_blob_write_text (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_ThrowTypeError (ctx, "write_text(text) requires 1 argument"); @@ -26834,9 +26285,8 @@ js_blob_write_text (JSContext *ctx, JSValue this_val, int argc, } /* blob.write_pad(block_size) */ -static JSValue -js_blob_write_pad (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_blob_write_pad (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_ThrowTypeError (ctx, "write_pad(block_size) requires 1 argument"); @@ -26854,9 +26304,8 @@ js_blob_write_pad (JSContext *ctx, JSValue this_val, int argc, } /* blob.w16(value) - write 16-bit value */ -static JSValue -js_blob_w16 (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_blob_w16 (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_ThrowTypeError (ctx, "w16(value) requires 1 argument"); @@ -26874,9 +26323,8 @@ js_blob_w16 (JSContext *ctx, JSValue this_val, int argc, } /* blob.w32(value) - write 32-bit value */ -static JSValue -js_blob_w32 (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_blob_w32 (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_ThrowTypeError (ctx, "w32(value) requires 1 argument"); @@ -26893,8 +26341,7 @@ js_blob_w32 (JSContext *ctx, JSValue this_val, int argc, } /* blob.wf(value) - write float */ -static JSValue -js_blob_wf (JSContext *ctx, JSValue this_val, JSValue arg0) { +static JSValue js_blob_wf (JSContext *ctx, JSValue this_val, JSValue arg0) { if (JS_IsNull (arg0)) return JS_ThrowTypeError (ctx, "wf(value) requires 1 argument"); @@ -26913,9 +26360,8 @@ js_blob_wf (JSContext *ctx, JSValue this_val, JSValue arg0) { } /* blob.read_logical(from) */ -static JSValue -js_blob_read_logical (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_blob_read_logical (JSContext *ctx, JSValue this_val, + int argc, JSValue *argv) { if (argc < 1) return JS_ThrowTypeError (ctx, "read_logical(from) requires 1 argument"); blob *bd = js_get_blob (ctx, this_val); @@ -26934,9 +26380,8 @@ js_blob_read_logical (JSContext *ctx, JSValue this_val, int argc, } /* blob.read_blob(from, to) */ -static JSValue -js_blob_read_blob (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_blob_read_blob (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { blob *bd = js_get_blob (ctx, this_val); if (!bd) return JS_ThrowTypeError (ctx, "read_blob: not called on a blob"); @@ -26962,9 +26407,8 @@ js_blob_read_blob (JSContext *ctx, JSValue this_val, int argc, } /* blob.read_number(from) */ -static JSValue -js_blob_read_number (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_blob_read_number (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_ThrowTypeError (ctx, "read_number(from) requires 1 argument"); blob *bd = js_get_blob (ctx, this_val); @@ -26988,9 +26432,8 @@ js_blob_read_number (JSContext *ctx, JSValue this_val, int argc, } /* blob.read_fit(from, len) */ -static JSValue -js_blob_read_fit (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_blob_read_fit (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 2) return JS_ThrowTypeError (ctx, "read_fit(from, len) requires 2 arguments"); @@ -27018,9 +26461,8 @@ js_blob_read_fit (JSContext *ctx, JSValue this_val, int argc, } /* blob.read_text(from) */ -static JSValue -js_blob_read_text (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_blob_read_text (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { blob *bd = js_get_blob (ctx, this_val); if (!bd) return JS_ThrowTypeError (ctx, "read_text: not called on a blob"); @@ -27046,9 +26488,8 @@ js_blob_read_text (JSContext *ctx, JSValue this_val, int argc, } /* blob.pad?(from, block_size) */ -static JSValue -js_blob_pad_q (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_blob_pad_q (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 2) return JS_ThrowTypeError (ctx, "pad?(from, block_size) requires 2 arguments"); @@ -27094,14 +26535,12 @@ static const JSCFunctionListEntry js_blob_proto_funcs[] = { /* Initialize blob - called during context setup (but we do it in * JS_AddIntrinsicBaseObjects now) */ -JSValue -js_blob_use (JSContext *js) { +JSValue js_blob_use (JSContext *js) { return JS_GetPropertyStr (js, js->global_obj, "blob"); } /* Create a new blob from raw data, stone it, and return as JSValue */ -JSValue -js_new_blob_stoned_copy (JSContext *js, void *data, size_t bytes) { +JSValue js_new_blob_stoned_copy (JSContext *js, void *data, size_t bytes) { blob *b = blob_new (bytes * 8); if (!b) return JS_ThrowOutOfMemory (js); memcpy (b->data, data, bytes); @@ -27111,8 +26550,7 @@ js_new_blob_stoned_copy (JSContext *js, void *data, size_t bytes) { } /* Get raw data pointer from a blob (must be stone) - returns byte count */ -void * -js_get_blob_data (JSContext *js, size_t *size, JSValue v) { +void *js_get_blob_data (JSContext *js, size_t *size, JSValue v) { blob *b = js_get_blob (js, v); *size = (b->length + 7) / 8; if (!b) { @@ -27138,8 +26576,7 @@ js_get_blob_data (JSContext *js, size_t *size, JSValue v) { } /* Get raw data pointer from a blob (must be stone) - returns bit count */ -void * -js_get_blob_data_bits (JSContext *js, size_t *bits, JSValue v) { +void *js_get_blob_data_bits (JSContext *js, size_t *bits, JSValue v) { blob *b = js_get_blob (js, v); if (!b) { JS_ThrowReferenceError (js, "get_blob_data_bits: not called on a blob"); @@ -27172,8 +26609,7 @@ js_get_blob_data_bits (JSContext *js, size_t *bits, JSValue v) { } /* Check if a value is a blob */ -int -js_is_blob (JSContext *js, JSValue v) { +int js_is_blob (JSContext *js, JSValue v) { return js_get_blob (js, v) != NULL; } @@ -27183,9 +26619,8 @@ js_is_blob (JSContext *js, JSValue v) { */ /* stone(object) - deep freeze an object */ -static JSValue -js_cell_stone (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_stone (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_NULL; JSValue obj = argv[0]; @@ -27216,9 +26651,8 @@ js_cell_stone (JSContext *ctx, JSValue this_val, int argc, * ============================================================================ */ -static JSValue -js_cell_reverse (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_reverse (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_NULL; JSValue value = argv[0]; @@ -27253,9 +26687,8 @@ js_cell_reverse (JSContext *ctx, JSValue this_val, int argc, * ============================================================================ */ -static JSValue -js_cell_pop (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_pop (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_NULL; JSValue obj = argv[0]; @@ -27272,13 +26705,11 @@ js_cell_pop (JSContext *ctx, JSValue this_val, int argc, return last; } -JSValue -JS_Stone (JSContext *ctx, JSValue this_val) { +JSValue JS_Stone (JSContext *ctx, JSValue this_val) { return js_cell_stone (ctx, this_val, 1, &this_val); } -int -JS_ArrayPush (JSContext *ctx, JSValue obj, JSValue val) { +int JS_ArrayPush (JSContext *ctx, JSValue obj, JSValue val) { if (!JS_IsArray (ctx, obj)) { JS_ThrowTypeError (ctx, "not an array"); return -1; @@ -27293,16 +26724,14 @@ JS_ArrayPush (JSContext *ctx, JSValue obj, JSValue val) { return 0; } -JSValue -JS_ArrayPop (JSContext *ctx, JSValue obj) { +JSValue JS_ArrayPop (JSContext *ctx, JSValue obj) { if (!JS_IsArray (ctx, obj)) return JS_ThrowTypeError (ctx, "not an array"); return js_cell_pop (ctx, JS_NULL, 1, &obj); } -static JSValue -js_cell_push (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_push (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_NULL; JSValue obj = argv[0]; @@ -27317,9 +26746,8 @@ js_cell_push (JSContext *ctx, JSValue this_val, int argc, return JS_NULL; } -static JSValue -js_cell_proto (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_proto (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_NULL; JSValue obj = argv[0]; @@ -27350,9 +26778,8 @@ js_cell_proto (JSContext *ctx, JSValue this_val, int argc, return proto; } -static JSValue -js_cell_meme (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_meme (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { JSValue proto = JS_NULL; if (argc > 0 && !JS_IsNull (argv[0])) proto = argv[0]; @@ -27424,9 +26851,8 @@ js_cell_meme (JSContext *ctx, JSValue this_val, int argc, * ============================================================================ */ -static JSValue -js_cell_splat (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_splat (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_NULL; JSValue obj = argv[0]; @@ -27517,9 +26943,8 @@ js_cell_splat (JSContext *ctx, JSValue this_val, int argc, * ============================================================================ */ -static JSValue -js_cell_length (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_length (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_NULL; JSValue val = argv[0]; @@ -27576,9 +27001,8 @@ js_cell_length (JSContext *ctx, JSValue this_val, int argc, */ /* call(func, this_val, args_array) */ -static JSValue -js_cell_call (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_call (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_ThrowTypeError (ctx, "call requires a function argument"); @@ -27610,25 +27034,22 @@ js_cell_call (JSContext *ctx, JSValue this_val, int argc, */ /* is_array(val) */ -static JSValue -js_cell_is_array (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_is_array (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_FALSE; return JS_NewBool (ctx, JS_IsArray (ctx, argv[0])); } /* is_blob(val) */ -static JSValue -js_cell_is_blob (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_is_blob (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_FALSE; return JS_NewBool (ctx, js_get_blob (ctx, argv[0]) != NULL); } /* is_data(val) - check if object is a plain object (data record) */ -static JSValue -js_cell_is_data (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_is_data (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_FALSE; JSValue val = argv[0]; if (!JS_IsObject (val)) return JS_FALSE; @@ -27640,25 +27061,22 @@ js_cell_is_data (JSContext *ctx, JSValue this_val, int argc, } /* is_function(val) */ -static JSValue -js_cell_is_function (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_is_function (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_FALSE; return JS_NewBool (ctx, JS_IsFunction (argv[0])); } /* is_logical(val) - check if value is a boolean (true or false) */ -static JSValue -js_cell_is_logical (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_is_logical (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_FALSE; return JS_NewBool (ctx, JS_VALUE_GET_TAG (argv[0]) == JS_TAG_BOOL); } /* is_integer(val) */ -static JSValue -js_cell_is_integer (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_is_integer (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_FALSE; JSValue val = argv[0]; int tag = JS_VALUE_GET_TAG (val); @@ -27671,25 +27089,22 @@ js_cell_is_integer (JSContext *ctx, JSValue this_val, int argc, } /* is_null(val) */ -static JSValue -js_cell_is_null (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_is_null (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_FALSE; return JS_NewBool (ctx, JS_IsNull (argv[0])); } /* is_number(val) */ -static JSValue -js_cell_is_number (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_is_number (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_FALSE; return JS_NewBool (ctx, JS_IsNumber (argv[0])); } /* is_object(val) - true for non-array, non-null objects */ -static JSValue -js_cell_is_object (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_is_object (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_FALSE; JSValue val = argv[0]; if (!JS_IsObject (val)) return JS_FALSE; @@ -27698,9 +27113,8 @@ js_cell_is_object (JSContext *ctx, JSValue this_val, int argc, } /* is_stone(val) - check if value is immutable */ -static JSValue -js_cell_is_stone (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_is_stone (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_FALSE; JSValue obj = argv[0]; @@ -27723,25 +27137,22 @@ js_cell_is_stone (JSContext *ctx, JSValue this_val, int argc, return JS_NewBool (ctx, true); } -int -JS_IsStone (JSContext *ctx, JSValue this_val) { +int JS_IsStone (JSContext *ctx, JSValue this_val) { JSValue is = js_cell_is_stone (ctx, this_val, 1, &this_val); return JS_VALUE_GET_BOOL (is); } /* is_text(val) */ -static JSValue -js_cell_is_text (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_is_text (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_FALSE; int tag = JS_VALUE_GET_TAG (argv[0]); return JS_NewBool (ctx, tag == JS_TAG_STRING || tag == JS_TAG_STRING_IMM); } /* is_proto(val, master) - check if val has master in prototype chain */ -static JSValue -js_cell_is_proto (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_is_proto (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 2) return JS_FALSE; JSValue val = argv[0]; JSValue master = argv[1]; @@ -27786,8 +27197,7 @@ js_cell_is_proto (JSContext *ctx, JSValue this_val, int argc, /* eval */ -void -JS_AddIntrinsicEval (JSContext *ctx) { +void JS_AddIntrinsicEval (JSContext *ctx) { ctx->eval_internal = __JS_EvalInternal; } @@ -27798,8 +27208,7 @@ static const char *const native_error_name[JS_NATIVE_ERROR_COUNT] = { /* Minimum amount of objects to be able to compile code and display error messages. No JSAtom should be allocated by this function. */ -static void -JS_AddIntrinsicBasicObjects (JSContext *ctx) { +static void JS_AddIntrinsicBasicObjects (JSContext *ctx) { JSValue proto; int i; @@ -27816,14 +27225,12 @@ JS_AddIntrinsicBasicObjects (JSContext *ctx) { proto = JS_NewObjectProto (ctx, ctx->class_proto[JS_CLASS_ERROR]); JS_SetPropertyInternal (ctx, proto, JS_KEY_name, JS_NewAtomString (ctx, native_error_name[i])); - JS_SetPropertyInternal (ctx, proto, JS_KEY_message, - JS_KEY_empty); + JS_SetPropertyInternal (ctx, proto, JS_KEY_message, JS_KEY_empty); ctx->native_error_proto[i] = proto; } } -void -JS_AddIntrinsicBaseObjects (JSContext *ctx) { +void JS_AddIntrinsicBaseObjects (JSContext *ctx) { int i; JSValue obj, number_obj; JSValue obj1; @@ -28046,9 +27453,8 @@ JS_AddIntrinsicBaseObjects (JSContext *ctx) { #define STRLEN(s) (sizeof (s) / sizeof (s[0])) #define CSTR "" -static inline void -atom_to_buf (JSContext *ctx, JSAtom atom, char *dst, int cap, - const char *fallback) { +static inline void atom_to_buf (JSContext *ctx, JSAtom atom, char *dst, + int cap, const char *fallback) { if (atom == JS_ATOM_NULL) { strncpy (dst, fallback, cap); dst[cap - 1] = 0; @@ -28061,8 +27467,7 @@ atom_to_buf (JSContext *ctx, JSAtom atom, char *dst, int cap, } } -void -js_debug_info (JSContext *js, JSValue fn, js_debug *dbg) { +void js_debug_info (JSContext *js, JSValue fn, js_debug *dbg) { *dbg = (js_debug){ 0 }; if (!JS_IsFunction (fn)) return; @@ -28104,15 +27509,13 @@ js_debug_info (JSContext *js, JSValue fn, js_debug *dbg) { } } -void -js_debug_sethook (JSContext *ctx, js_hook hook, int type, void *user) { +void js_debug_sethook (JSContext *ctx, js_hook hook, int type, void *user) { ctx->trace_hook = hook; ctx->trace_type = type; ctx->trace_data = user; } -uint32_t -js_debugger_stack_depth (JSContext *ctx) { +uint32_t js_debugger_stack_depth (JSContext *ctx) { uint32_t stack_index = 0; JSStackFrame *sf = ctx->rt->current_stack_frame; while (sf != NULL) { @@ -28122,8 +27525,7 @@ js_debugger_stack_depth (JSContext *ctx) { return stack_index; } -JSValue -js_debugger_backtrace_fns (JSContext *ctx, const uint8_t *cur_pc) { +JSValue js_debugger_backtrace_fns (JSContext *ctx, const uint8_t *cur_pc) { JSValue ret = JS_NewArray (ctx); JSStackFrame *sf; uint32_t stack_index = 0; @@ -28135,8 +27537,7 @@ js_debugger_backtrace_fns (JSContext *ctx, const uint8_t *cur_pc) { return ret; } -JSValue -js_debugger_build_backtrace (JSContext *ctx, const uint8_t *cur_pc) { +JSValue js_debugger_build_backtrace (JSContext *ctx, const uint8_t *cur_pc) { JSStackFrame *sf; const char *func_name_str; JSFunction *f; @@ -28191,8 +27592,7 @@ js_debugger_build_backtrace (JSContext *ctx, const uint8_t *cur_pc) { return ret; } -JSValue -js_debugger_fn_info (JSContext *ctx, JSValue fn) { +JSValue js_debugger_fn_info (JSContext *ctx, JSValue fn) { JSValue ret = JS_NewObject (ctx); if (!js_is_bytecode_function (fn)) goto done; @@ -28306,8 +27706,7 @@ static const char *opcode_names[] = { #undef FMT }; -JSValue -js_debugger_fn_bytecode (JSContext *ctx, JSValue fn) { +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); @@ -28650,8 +28049,7 @@ js_debugger_fn_bytecode (JSContext *ctx, JSValue fn) { return ret; } -JSValue -js_debugger_local_variables (JSContext *ctx, int stack_index) { +JSValue js_debugger_local_variables (JSContext *ctx, int stack_index) { JSValue ret = JS_NewObject (ctx); JSStackFrame *sf; @@ -28700,9 +28098,8 @@ done: return ret; } -void -js_debugger_set_closure_variable (JSContext *ctx, JSValue fn, JSValue var_name, - JSValue val) { +void js_debugger_set_closure_variable (JSContext *ctx, JSValue fn, + JSValue var_name, JSValue val) { if (!js_is_bytecode_function (fn)) return; JSFunction *f = JS_VALUE_GET_FUNCTION (fn); @@ -28731,8 +28128,7 @@ js_debugger_set_closure_variable (JSContext *ctx, JSValue fn, JSValue var_name, JS_FreeCString (ctx, name_str); } -JSValue -js_debugger_closure_variables (JSContext *ctx, JSValue fn) { +JSValue js_debugger_closure_variables (JSContext *ctx, JSValue fn) { JSValue ret = JS_NewObject (ctx); if (!js_is_bytecode_function (fn)) goto done; @@ -28756,8 +28152,7 @@ done: return ret; } -void * -js_debugger_val_address (JSContext *ctx, JSValue val) { +void *js_debugger_val_address (JSContext *ctx, JSValue val) { return JS_VALUE_GET_PTR (val); } @@ -28767,9 +28162,8 @@ js_debugger_val_address (JSContext *ctx, JSValue val) { * ============================================================================ */ -static JSValue -js_cell_json_encode (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_json_encode (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_ThrowTypeError (ctx, "json.encode requires at least 1 argument"); @@ -28780,9 +28174,8 @@ js_cell_json_encode (JSContext *ctx, JSValue this_val, int argc, return result; } -static JSValue -js_cell_json_decode (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_cell_json_decode (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { if (argc < 1) return JS_ThrowTypeError (ctx, "json.decode requires at least 1 argument"); @@ -28810,8 +28203,7 @@ js_cell_json_decode (JSContext *ctx, JSValue this_val, int argc, JSValue holder = wrapper; JSValue key = JS_KEY_empty; - JSValue args[2] - = { key, JS_GetProperty (ctx, holder, key) }; + JSValue args[2] = { key, JS_GetProperty (ctx, holder, key) }; JSValue final = JS_Call (ctx, argv[1], holder, 2, args); JS_FreeValue (ctx, args[1]); JS_FreeValue (ctx, wrapper); @@ -28826,17 +28218,15 @@ static const JSCFunctionListEntry js_cell_json_funcs[] = { JS_CFUNC_DEF ("decode", 1, js_cell_json_decode), }; -JSValue -js_json_use (JSContext *ctx) { +JSValue js_json_use (JSContext *ctx) { JSValue obj = JS_NewObject (ctx); JS_SetPropertyFunctionList (ctx, obj, js_cell_json_funcs, countof (js_cell_json_funcs)); return obj; } -static JSValue -js_math_e (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_math_e (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { double power = 1.0; if (argc > 0 && !JS_IsNull (argv[0])) { if (JS_ToFloat64 (ctx, &power, argv[0]) < 0) return JS_EXCEPTION; @@ -28850,81 +28240,71 @@ js_math_e (JSContext *ctx, JSValue this_val, int argc, * ============================================================================ */ -static JSValue -js_math_rad_arc_cosine (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_math_rad_arc_cosine (JSContext *ctx, JSValue this_val, + int argc, JSValue *argv) { double x; if (JS_ToFloat64 (ctx, &x, argv[0]) < 0) return JS_EXCEPTION; return JS_NewFloat64 (ctx, acos (x)); } -static JSValue -js_math_rad_arc_sine (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_math_rad_arc_sine (JSContext *ctx, JSValue this_val, + int argc, JSValue *argv) { double x; if (JS_ToFloat64 (ctx, &x, argv[0]) < 0) return JS_EXCEPTION; return JS_NewFloat64 (ctx, asin (x)); } -static JSValue -js_math_rad_arc_tangent (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_math_rad_arc_tangent (JSContext *ctx, JSValue this_val, + int argc, JSValue *argv) { double x; if (JS_ToFloat64 (ctx, &x, argv[0]) < 0) return JS_EXCEPTION; return JS_NewFloat64 (ctx, atan (x)); } -static JSValue -js_math_rad_cosine (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_math_rad_cosine (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { double x; if (JS_ToFloat64 (ctx, &x, argv[0]) < 0) return JS_EXCEPTION; return JS_NewFloat64 (ctx, cos (x)); } -static JSValue -js_math_rad_sine (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_math_rad_sine (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { double x; if (JS_ToFloat64 (ctx, &x, argv[0]) < 0) return JS_EXCEPTION; return JS_NewFloat64 (ctx, sin (x)); } -static JSValue -js_math_rad_tangent (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_math_rad_tangent (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { double x; if (JS_ToFloat64 (ctx, &x, argv[0]) < 0) return JS_EXCEPTION; return JS_NewFloat64 (ctx, tan (x)); } -static JSValue -js_math_ln (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_math_ln (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { double x; if (JS_ToFloat64 (ctx, &x, argv[0]) < 0) return JS_EXCEPTION; return JS_NewFloat64 (ctx, log (x)); } -static JSValue -js_math_log10 (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_math_log10 (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { double x; if (JS_ToFloat64 (ctx, &x, argv[0]) < 0) return JS_EXCEPTION; return JS_NewFloat64 (ctx, log10 (x)); } -static JSValue -js_math_log2 (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_math_log2 (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { double x; if (JS_ToFloat64 (ctx, &x, argv[0]) < 0) return JS_EXCEPTION; return JS_NewFloat64 (ctx, log2 (x)); } -static JSValue -js_math_power (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_math_power (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { double x, y; if (argc < 2) return JS_NULL; if (JS_ToFloat64 (ctx, &x, argv[0]) < 0) return JS_EXCEPTION; @@ -28932,9 +28312,8 @@ js_math_power (JSContext *ctx, JSValue this_val, int argc, return JS_NewFloat64 (ctx, pow (x, y)); } -static JSValue -js_math_root (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_math_root (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { double x, n; if (argc < 2) return JS_NULL; if (JS_ToFloat64 (ctx, &x, argv[0]) < 0) return JS_EXCEPTION; @@ -28942,9 +28321,8 @@ js_math_root (JSContext *ctx, JSValue this_val, int argc, return JS_NewFloat64 (ctx, pow (x, 1.0 / n)); } -static JSValue -js_math_sqrt (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_math_sqrt (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { double x; if (JS_ToFloat64 (ctx, &x, argv[0]) < 0) return JS_EXCEPTION; return JS_NewFloat64 (ctx, sqrt (x)); @@ -28965,8 +28343,7 @@ static const JSCFunctionListEntry js_math_radians_funcs[] JS_CFUNC_DEF ("sqrt", 1, js_math_sqrt), JS_CFUNC_DEF ("e", 1, js_math_e) }; -JSValue -js_math_radians_use (JSContext *ctx) { +JSValue js_math_radians_use (JSContext *ctx) { JSValue obj = JS_NewObject (ctx); JS_SetPropertyFunctionList (ctx, obj, js_math_radians_funcs, countof (js_math_radians_funcs)); @@ -28982,49 +28359,43 @@ js_math_radians_use (JSContext *ctx) { #define DEG2RAD (3.14159265358979323846264338327950288419716939937510 / 180.0) #define RAD2DEG (180.0 / 3.14159265358979323846264338327950288419716939937510) -static JSValue -js_math_deg_arc_cosine (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_math_deg_arc_cosine (JSContext *ctx, JSValue this_val, + int argc, JSValue *argv) { double x; if (JS_ToFloat64 (ctx, &x, argv[0]) < 0) return JS_EXCEPTION; return JS_NewFloat64 (ctx, acos (x) * RAD2DEG); } -static JSValue -js_math_deg_arc_sine (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_math_deg_arc_sine (JSContext *ctx, JSValue this_val, + int argc, JSValue *argv) { double x; if (JS_ToFloat64 (ctx, &x, argv[0]) < 0) return JS_EXCEPTION; return JS_NewFloat64 (ctx, asin (x) * RAD2DEG); } -static JSValue -js_math_deg_arc_tangent (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_math_deg_arc_tangent (JSContext *ctx, JSValue this_val, + int argc, JSValue *argv) { double x; if (JS_ToFloat64 (ctx, &x, argv[0]) < 0) return JS_EXCEPTION; return JS_NewFloat64 (ctx, atan (x) * RAD2DEG); } -static JSValue -js_math_deg_cosine (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_math_deg_cosine (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { double x; if (JS_ToFloat64 (ctx, &x, argv[0]) < 0) return JS_EXCEPTION; return JS_NewFloat64 (ctx, cos (x * DEG2RAD)); } -static JSValue -js_math_deg_sine (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_math_deg_sine (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { double x; if (JS_ToFloat64 (ctx, &x, argv[0]) < 0) return JS_EXCEPTION; return JS_NewFloat64 (ctx, sin (x * DEG2RAD)); } -static JSValue -js_math_deg_tangent (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_math_deg_tangent (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { double x; if (JS_ToFloat64 (ctx, &x, argv[0]) < 0) return JS_EXCEPTION; return JS_NewFloat64 (ctx, tan (x * DEG2RAD)); @@ -29045,8 +28416,7 @@ static const JSCFunctionListEntry js_math_degrees_funcs[] JS_CFUNC_DEF ("sqrt", 1, js_math_sqrt), JS_CFUNC_DEF ("e", 1, js_math_e) }; -JSValue -js_math_degrees_use (JSContext *ctx) { +JSValue js_math_degrees_use (JSContext *ctx) { JSValue obj = JS_NewObject (ctx); JS_SetPropertyFunctionList (ctx, obj, js_math_degrees_funcs, countof (js_math_degrees_funcs)); @@ -29061,49 +28431,43 @@ js_math_degrees_use (JSContext *ctx) { #define TWOPI (2.0 * 3.14159265358979323846264338327950288419716939937510) -static JSValue -js_math_cyc_arc_cosine (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_math_cyc_arc_cosine (JSContext *ctx, JSValue this_val, + int argc, JSValue *argv) { double x; if (JS_ToFloat64 (ctx, &x, argv[0]) < 0) return JS_EXCEPTION; return JS_NewFloat64 (ctx, acos (x) / TWOPI); } -static JSValue -js_math_cyc_arc_sine (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_math_cyc_arc_sine (JSContext *ctx, JSValue this_val, + int argc, JSValue *argv) { double x; if (JS_ToFloat64 (ctx, &x, argv[0]) < 0) return JS_EXCEPTION; return JS_NewFloat64 (ctx, asin (x) / TWOPI); } -static JSValue -js_math_cyc_arc_tangent (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_math_cyc_arc_tangent (JSContext *ctx, JSValue this_val, + int argc, JSValue *argv) { double x; if (JS_ToFloat64 (ctx, &x, argv[0]) < 0) return JS_EXCEPTION; return JS_NewFloat64 (ctx, atan (x) / TWOPI); } -static JSValue -js_math_cyc_cosine (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_math_cyc_cosine (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { double x; if (JS_ToFloat64 (ctx, &x, argv[0]) < 0) return JS_EXCEPTION; return JS_NewFloat64 (ctx, cos (x * TWOPI)); } -static JSValue -js_math_cyc_sine (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_math_cyc_sine (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { double x; if (JS_ToFloat64 (ctx, &x, argv[0]) < 0) return JS_EXCEPTION; return JS_NewFloat64 (ctx, sin (x * TWOPI)); } -static JSValue -js_math_cyc_tangent (JSContext *ctx, JSValue this_val, int argc, - JSValue *argv) { +static JSValue js_math_cyc_tangent (JSContext *ctx, JSValue this_val, int argc, + JSValue *argv) { double x; if (JS_ToFloat64 (ctx, &x, argv[0]) < 0) return JS_EXCEPTION; return JS_NewFloat64 (ctx, tan (x * TWOPI)); @@ -29124,15 +28488,11 @@ static const JSCFunctionListEntry js_math_cycles_funcs[] JS_CFUNC_DEF ("sqrt", 1, js_math_sqrt), JS_CFUNC_DEF ("e", 1, js_math_e) }; -JSValue -js_math_cycles_use (JSContext *ctx) { +JSValue js_math_cycles_use (JSContext *ctx) { JSValue obj = JS_NewObject (ctx); JS_SetPropertyFunctionList (ctx, obj, js_math_cycles_funcs, countof (js_math_cycles_funcs)); return obj; } -JSContext * -JS_GetContext (JSRuntime *rt) { - return rt->js; -} +JSContext *JS_GetContext (JSRuntime *rt) { return rt->js; }