MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

display async functions properly in io

+37 -8
+26 -8
src/ant.c
··· 2059 2059 return true; 2060 2060 } 2061 2061 2062 + struct func_format { 2063 + const char *prefix; 2064 + size_t prefix_len; 2065 + const char *anon; 2066 + size_t anon_len; 2067 + }; 2068 + 2069 + static const struct func_format formats[] = { 2070 + [0] = { "[Function: ", 11, "[Function (anonymous)]", 22 }, 2071 + [1] = { "[AsyncFunction: ", 16, "[AsyncFunction (anonymous)]", 27 }, 2072 + }; 2073 + 2062 2074 static size_t strfunc(struct js *js, jsval_t value, char *buf, size_t len) { 2063 2075 jsoff_t name_len = 0; 2064 2076 const char *name = get_func_name(js, value, &name_len); 2077 + 2065 2078 jsval_t func_obj = mkval(T_OBJ, vdata(value)); 2066 2079 jsval_t code_slot = get_slot(js, func_obj, SLOT_CODE); 2067 2080 jsval_t builtin_slot = get_slot(js, func_obj, SLOT_BUILTIN); 2081 + jsval_t async_slot = get_slot(js, func_obj, SLOT_ASYNC); 2082 + 2083 + bool is_async = is_true(async_slot); 2084 + const struct func_format *fmt = &formats[is_async]; 2085 + 2068 2086 if (vtype(builtin_slot) == T_NUM) { 2069 2087 if (name && name_len > 0) { 2070 - size_t n = cpy(buf, len, "[Function: ", 11); 2088 + size_t n = cpy(buf, len, fmt->prefix, fmt->prefix_len); 2071 2089 n += cpy(buf + n, len - n, name, name_len); 2072 2090 n += cpy(buf + n, len - n, "]", 1); 2073 2091 return n; ··· 2079 2097 jsval_t cfunc_slot = get_slot(js, func_obj, SLOT_CFUNC); 2080 2098 if (vtype(cfunc_slot) == T_CFUNC) { 2081 2099 if (name && name_len > 0) { 2082 - size_t n = cpy(buf, len, "[Function: ", 11); 2100 + size_t n = cpy(buf, len, fmt->prefix, fmt->prefix_len); 2083 2101 n += cpy(buf + n, len - n, name, name_len); 2084 2102 n += cpy(buf + n, len - n, "]", 1); 2085 2103 return n; ··· 2087 2105 return cpy(buf, len, "[native code]", 13); 2088 2106 } 2089 2107 if (name && name_len > 0) { 2090 - size_t n = cpy(buf, len, "[Function: ", 11); 2108 + size_t n = cpy(buf, len, fmt->prefix, fmt->prefix_len); 2091 2109 n += cpy(buf + n, len - n, name, name_len); 2092 2110 n += cpy(buf + n, len - n, "]", 1); 2093 2111 return n; 2094 2112 } 2095 - return cpy(buf, len, "[Function (anonymous)]", 22); 2113 + return cpy(buf, len, fmt->anon, fmt->anon_len); 2096 2114 } 2097 2115 jsval_t code_val = code_slot; 2098 2116 2099 2117 if (vtype(code_val) != T_STR) { 2100 2118 if (name && name_len > 0) { 2101 - size_t n = cpy(buf, len, "[Function: ", 11); 2119 + size_t n = cpy(buf, len, fmt->prefix, fmt->prefix_len); 2102 2120 n += cpy(buf + n, len - n, name, name_len); 2103 2121 n += cpy(buf + n, len - n, "]", 1); 2104 2122 return n; 2105 2123 } 2106 - return cpy(buf, len, "[Function (anonymous)]", 22); 2124 + return cpy(buf, len, fmt->anon, fmt->anon_len); 2107 2125 } 2108 2126 2109 2127 if (name && name_len > 0) { 2110 - size_t n = cpy(buf, len, "[Function: ", 11); 2128 + size_t n = cpy(buf, len, fmt->prefix, fmt->prefix_len); 2111 2129 n += cpy(buf + n, len - n, name, name_len); 2112 2130 n += cpy(buf + n, len - n, "]", 1); 2113 2131 return n; 2114 2132 } 2115 - return cpy(buf, len, "[Function (anonymous)]", 22); 2133 + return cpy(buf, len, fmt->anon, fmt->anon_len); 2116 2134 } 2117 2135 2118 2136 static void get_line_col(const char *code, jsoff_t pos, int *line, int *col) {
+11
src/modules/io.c
··· 160 160 161 161 lbrack: 162 162 switch (p[1]) { 163 + case 'A': if (memcmp(p + 2, "syncFunction", 7) == 0) { EMIT_UNTIL(']', JSON_FUNC) } break; 163 164 case 'F': if (memcmp(p + 2, "unction", 7) == 0) { EMIT_UNTIL(']', JSON_FUNC) } break; 164 165 case 'n': if (memcmp(p + 2, "ative code]", 11) == 0) { EMIT_UNTIL(']', JSON_FUNC) } break; 165 166 case 'C': if (memcmp(p + 2, "ircular", 7) == 0) { EMIT_UNTIL(']', JSON_REF) } break; ··· 201 202 202 203 lt: 203 204 if (memcmp(p, "<ref", 4) == 0) { EMIT_UNTIL('>', JSON_REF) } 205 + if (memcmp(p, "<pen", 4) == 0) { EMIT_UNTIL('>', JSON_REF) } 206 + if (memcmp(p, "<rej", 4) == 0) { EMIT_UNTIL('>', JSON_REF) } 204 207 io_puts(JSON_BRACE, stream); io_putc(*p++, stream); io_puts(ANSI_RESET, stream); 205 208 goto next; 206 209 ··· 215 218 while (*p && *p != ']') io_putc(*p++, stream); 216 219 if (*p == ']') io_putc(*p++, stream); 217 220 io_puts(ANSI_RESET, stream); 221 + goto next; 222 + } 223 + 224 + if (memcmp(p, "Promise { ", 10) == 0) { 225 + io_puts(JSON_FUNC, stream); io_puts("Promise", stream); 226 + io_puts(JSON_BRACE, stream); io_puts(" { ", stream); 227 + p += 10; 228 + 218 229 goto next; 219 230 } 220 231