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.

add support for special objects in various modules

+17 -13
+1 -2
src/modules/buffer.c
··· 421 421 return create_typed_array_with_buffer(js, type, buffer, byte_offset, length, type_name, args[0]); 422 422 } 423 423 424 - int arg_type = vtype(args[0]); 425 - if (arg_type == T_OBJ) { 424 + if (is_special_object(args[0])) { 426 425 jsval_t len_val = js_get(js, args[0], "length"); 427 426 size_t length = 0; jsval_t *values = NULL; 428 427 bool is_iterable = false;
+3
src/modules/events.c
··· 42 42 43 43 if (vtype(slot) == T_UNDEF) { 44 44 EventType **events = ant_calloc(sizeof(EventType *)); 45 + if (!events) return NULL; 45 46 *events = NULL; 46 47 js_set_slot(js, this_obj, SLOT_DATA, ANT_PTR(events)); 47 48 return events; ··· 69 70 if (evt == NULL) { 70 71 size_t etlen = strlen(event_type); 71 72 evt = ant_calloc(sizeof(EventType) + etlen + 1); 73 + if (!evt) return NULL; 72 74 evt->event_type = (char *)(evt + 1); 73 75 memcpy(evt->event_type, event_type, etlen + 1); 74 76 evt->listener_count = 0; ··· 85 87 if (evt == NULL) { 86 88 size_t etlen = strlen(event_type); 87 89 evt = ant_calloc(sizeof(EventType) + etlen + 1); 90 + if (!evt) return NULL; 88 91 evt->event_type = (char *)(evt + 1); 89 92 memcpy(evt->event_type, event_type, etlen + 1); 90 93 evt->listener_count = 0;
+4 -2
src/modules/navigator.c
··· 169 169 170 170 if (vtype(result) == T_PROMISE) { 171 171 jsval_t then_fn = js_get(js, result, "then"); 172 + int fn_type = vtype(then_fn); 172 173 173 - if (vtype(then_fn) == T_FUNC) { 174 + if (fn_type == T_FUNC || fn_type == T_CFUNC) { 174 175 jsval_t name_str = js_mkstr(js, name, strlen(name)); 175 176 176 177 jsval_t on_resolve = js_mkfun(lock_then_handler); ··· 272 273 273 274 if (vtype(result) == T_PROMISE) { 274 275 jsval_t then_fn = js_get(js, result, "then"); 275 - if (vtype(then_fn) == T_FUNC) { 276 + int fn_type = vtype(then_fn); 277 + if (fn_type == T_FUNC || fn_type == T_CFUNC) { 276 278 jsval_t on_resolve = js_mkfun(lock_then_handler); 277 279 js_set(js, on_resolve, "_lockName", js_mkstr(js, "", 0)); 278 280 js_set(js, on_resolve, "_outerPromise", promise);
+3 -3
src/modules/os.c
··· 523 523 524 524 for (pCurrAddresses = pAddresses; pCurrAddresses; pCurrAddresses = pCurrAddresses->Next) { 525 525 jsval_t iface_arr = js_get(js, result, pCurrAddresses->AdapterName); 526 - if (vtype(iface_arr) != T_OBJ) { 526 + if (!is_special_object(iface_arr)) { 527 527 iface_arr = js_mkarr(js); 528 528 js_set(js, result, pCurrAddresses->AdapterName, iface_arr); 529 529 } ··· 701 701 format_mac_address(mac_str, sizeof(mac_str), mac_bytes); 702 702 703 703 jsval_t iface_arr = js_get(js, result, name); 704 - if (vtype(iface_arr) != T_OBJ) return; 704 + if (!is_special_object(iface_arr)) return; 705 705 706 706 jsval_t len_val = js_get(js, iface_arr, "length"); 707 707 int len = (vtype(len_val) == T_NUM) ? (int)js_getnum(len_val) : 0; ··· 729 729 if (family != AF_INET && family != AF_INET6) continue; 730 730 731 731 jsval_t iface_arr = js_get(js, result, ifa->ifa_name); 732 - if (vtype(iface_arr) != T_OBJ) { 732 + if (!is_special_object(iface_arr)) { 733 733 iface_arr = js_mkarr(js); 734 734 js_set(js, result, ifa->ifa_name, iface_arr); 735 735 }
+5 -5
src/modules/readline.c
··· 297 297 298 298 int prompt_len = (int)strlen(iface->prompt); 299 299 int end_cols = prompt_len + iface->line_len; 300 - int end_row = end_cols > 0 ? (end_cols - 1) / cols : 0; 300 + int end_row = end_cols > 0 ? end_cols / cols : 0; 301 301 int cursor_cols = prompt_len + iface->line_pos; 302 - int cursor_row = cursor_cols > 0 ? (cursor_cols - 1) / cols : 0; 303 - int cursor_col = cursor_cols > 0 ? (cursor_cols - 1) % cols : 0; 302 + int cursor_row = cursor_cols > 0 ? cursor_cols / cols : 0; 303 + int cursor_col = cursor_cols > 0 ? cursor_cols % cols : 0; 304 304 int up_rows = end_row - cursor_row; 305 305 306 306 if (up_rows > 0) { ··· 315 315 write_output(iface, move_buf); 316 316 } 317 317 318 - iface->last_render_rows = end_cols > 0 ? (end_cols - 1) / cols + 1 : 1; 318 + iface->last_render_rows = end_cols > 0 ? end_cols / cols + 1 : 1; 319 319 } 320 320 321 321 static rl_interface_t *find_interface_by_id(uint64_t id) { ··· 1120 1120 iface->completer = (vtype(completer_val) == T_FUNC) ? completer_val : js_mkundef(); 1121 1121 1122 1122 jsval_t history_val = js_get(js, options, "history"); 1123 - if (vtype(history_val) == T_OBJ) { 1123 + if (is_special_object(history_val)) { 1124 1124 jsval_t len_val = js_get(js, history_val, "length"); 1125 1125 int len = (vtype(len_val) == T_NUM) ? (int)js_getnum(len_val) : 0; 1126 1126
+1 -1
src/snapshot.c
··· 7 7 #include "snapshot_data.h" 8 8 9 9 jsval_t ant_load_snapshot(struct js *js) { 10 - if (!js) return js_mkerr(js, "invalid js runtime"); 10 + if (!js) return js_mkundef(); 11 11 jsval_t result = js_eval(js, (const char *)ant_snapshot_source, ant_snapshot_source_len); 12 12 13 13 if (vtype(result) == T_ERR) return result;