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 brand helpers

+41 -49
+1 -1
examples/results.txt
··· 1234 1234 compat-table/es2019/misc.Function-toString.computed-names.js: failed 1235 1235 compat-table/es2019/misc.Function-toString.native-code.js: failed 1236 1236 compat-table/es2019/misc.Function-toString.unicode-escapes.js: failed 1237 - compat-table/es2019/misc.JSON-stringify-well-formed.js: TypeError: JSON.stringify() failed: write error 1237 + compat-table/es2019/misc.JSON-stringify-well-formed.js: OK 1238 1238 compat-table/es2019/misc.JSON-superset.line-separator.js: OK 1239 1239 compat-table/es2019/misc.JSON-superset.paragraph-separator.js: OK 1240 1240 compat-table/es2019/misc.optional-catch-binding.await.js: OK
+10
include/internal.h
··· 375 375 return vtype(value) == T_STR && ((vdata(value) & 1ULL) != 0); 376 376 } 377 377 378 + static inline int js_brand_id(ant_value_t obj) { 379 + if (!is_object_type(obj)) return BRAND_NONE; 380 + ant_value_t brand = js_get_slot(obj, SLOT_BRAND); 381 + return vtype(brand) == T_NUM ? (int)js_getnum(brand) : BRAND_NONE; 382 + } 383 + 384 + static inline bool js_check_brand(ant_value_t obj, int brand) { 385 + return js_brand_id(obj) == brand; 386 + } 387 + 378 388 static inline ant_value_t js_make_ctor(ant_t *js, ant_cfunc_t fn, ant_value_t proto, const char *name, size_t nlen) { 379 389 ant_value_t obj = js_mkobj(js); 380 390 js_set_slot(obj, SLOT_CFUNC, js_mkfun(fn));
+1 -3
src/modules/blob.c
··· 21 21 ant_value_t g_file_proto = 0; 22 22 23 23 bool blob_is_blob(ant_t *js, ant_value_t obj) { 24 - ant_value_t brand = js_get_slot(obj, SLOT_BRAND); 25 - if (vtype(brand) != T_NUM) return false; 26 - int id = (int)js_getnum(brand); 24 + int id = js_brand_id(obj); 27 25 return id == BRAND_BLOB || id == BRAND_FILE; 28 26 } 29 27
+1 -2
src/modules/buffer.c
··· 35 35 static ant_value_t g_typedarray_iter_proto = 0; 36 36 37 37 bool buffer_is_dataview(ant_value_t obj) { 38 - ant_value_t brand = js_get_slot(obj, SLOT_BRAND); 39 - return vtype(brand) == T_NUM && (int)js_getnum(brand) == BRAND_DATAVIEW; 38 + return js_check_brand(obj, BRAND_DATAVIEW); 40 39 } 41 40 42 41 bool buffer_source_get_bytes(ant_t *js, ant_value_t value, const uint8_t **out, size_t *len) {
+1 -2
src/modules/formdata.c
··· 31 31 static fd_data_t *get_fd_data(ant_value_t obj); 32 32 33 33 bool formdata_is_formdata(ant_t *js, ant_value_t obj) { 34 - ant_value_t brand = js_get_slot(obj, SLOT_BRAND); 35 - return vtype(brand) == T_NUM && (int)js_getnum(brand) == BRAND_FORMDATA; 34 + return js_check_brand(obj, BRAND_FORMDATA); 36 35 } 37 36 38 37 bool formdata_is_empty(ant_value_t fd) {
+1 -2
src/modules/headers.c
··· 76 76 } 77 77 78 78 bool headers_is_headers(ant_value_t obj) { 79 - ant_value_t brand = js_get_slot(obj, SLOT_BRAND); 80 - return vtype(brand) == T_NUM && (int)js_getnum(brand) == BRAND_HEADERS; 79 + return js_check_brand(obj, BRAND_HEADERS); 81 80 } 82 81 83 82 static bool is_token_char(unsigned char c) {
+1 -2
src/modules/url.c
··· 33 33 } 34 34 35 35 bool usp_is_urlsearchparams(ant_t *js, ant_value_t obj) { 36 - ant_value_t brand = js_get_slot(obj, SLOT_BRAND); 37 - return vtype(brand) == T_NUM && (int)js_getnum(brand) == BRAND_URLSEARCHPARAMS; 36 + return js_check_brand(obj, BRAND_URLSEARCHPARAMS); 38 37 } 39 38 40 39 void url_state_clear(url_state_t *s) {
+3 -12
src/streams/readable.c
··· 18 18 ant_value_t g_controller_proto; 19 19 20 20 bool rs_is_stream(ant_value_t obj) { 21 - if (!is_object_type(obj)) return false; 22 - ant_value_t brand = js_get_slot(obj, SLOT_BRAND); 23 - return vtype(brand) == T_NUM 24 - && (int)js_getnum(brand) == BRAND_READABLE_STREAM 21 + return js_check_brand(obj, BRAND_READABLE_STREAM) 25 22 && rs_get_stream(obj) != NULL; 26 23 } 27 24 28 25 bool rs_is_reader(ant_value_t obj) { 29 - if (!is_object_type(obj)) return false; 30 - ant_value_t brand = js_get_slot(obj, SLOT_BRAND); 31 - return vtype(brand) == T_NUM 32 - && (int)js_getnum(brand) == BRAND_READABLE_STREAM_READER 26 + return js_check_brand(obj, BRAND_READABLE_STREAM_READER) 33 27 && vtype(js_get_slot(obj, SLOT_RS_CLOSED)) == T_PROMISE 34 28 && vtype(js_get_slot(obj, SLOT_BUFFER)) == T_ARR; 35 29 } 36 30 37 31 bool rs_is_controller(ant_value_t obj) { 38 - if (!is_object_type(obj)) return false; 39 - ant_value_t brand = js_get_slot(obj, SLOT_BRAND); 40 - return vtype(brand) == T_NUM 41 - && (int)js_getnum(brand) == BRAND_READABLE_STREAM_CONTROLLER 32 + return js_check_brand(obj, BRAND_READABLE_STREAM_CONTROLLER) 42 33 && rs_get_controller(obj) != NULL 43 34 && rs_is_stream(js_get_slot(obj, SLOT_ENTRIES)); 44 35 }
+19 -13
src/streams/transform.c
··· 17 17 ant_value_t g_ts_proto; 18 18 ant_value_t g_ts_ctrl_proto; 19 19 20 - bool ts_is_controller(ant_value_t obj) { 21 - if (!is_object_type(obj)) return false; 22 - ant_value_t brand = js_get_slot(obj, SLOT_BRAND); 23 - if (vtype(brand) != T_NUM || (int)js_getnum(brand) != BRAND_TRANSFORM_STREAM_CONTROLLER) 24 - return false; 20 + static inline bool ts_has_stream_shape(ant_value_t obj) { 21 + return vtype(js_get_slot(obj, SLOT_DATA)) == T_NUM 22 + && rs_is_stream(js_get_slot(obj, SLOT_ENTRIES)) 23 + && ws_is_stream(js_get_slot(obj, SLOT_CTOR)); 24 + } 25 + 26 + static inline bool ts_has_controller_shape(ant_value_t obj) { 25 27 ant_value_t ts_obj = js_get_slot(obj, SLOT_DATA); 26 28 return is_object_type(ts_obj) 27 - && ts_is_stream(ts_obj) 29 + && js_check_brand(ts_obj, BRAND_TRANSFORM_STREAM) 30 + && vtype(js_get_slot(ts_obj, SLOT_DATA)) == T_NUM 28 31 && js_get_slot(ts_obj, SLOT_DEFAULT) == obj; 29 32 } 30 33 34 + bool ts_is_controller(ant_value_t obj) { 35 + return js_check_brand(obj, BRAND_TRANSFORM_STREAM_CONTROLLER) 36 + && ts_has_controller_shape(obj); 37 + } 38 + 31 39 bool ts_is_stream(ant_value_t obj) { 32 - return is_object_type(obj) 33 - && vtype(js_get_slot(obj, SLOT_BRAND)) == T_NUM 34 - && (int)js_getnum(js_get_slot(obj, SLOT_BRAND)) == BRAND_TRANSFORM_STREAM 35 - && vtype(js_get_slot(obj, SLOT_DATA)) == T_NUM 36 - && rs_is_stream(js_get_slot(obj, SLOT_ENTRIES)) 37 - && ws_is_stream(js_get_slot(obj, SLOT_CTOR)) 38 - && ts_is_controller(js_get_slot(obj, SLOT_DEFAULT)); 40 + ant_value_t ctrl_obj = js_get_slot(obj, SLOT_DEFAULT); 41 + return js_check_brand(obj, BRAND_TRANSFORM_STREAM) 42 + && ts_has_stream_shape(obj) 43 + && js_check_brand(ctrl_obj, BRAND_TRANSFORM_STREAM_CONTROLLER) 44 + && ts_has_controller_shape(ctrl_obj); 39 45 } 40 46 41 47 ant_value_t ts_stream_readable(ant_value_t ts_obj) {
+3 -12
src/streams/writable.c
··· 19 19 static ant_value_t g_close_sentinel; 20 20 21 21 bool ws_is_stream(ant_value_t obj) { 22 - if (!is_object_type(obj)) return false; 23 - ant_value_t brand = js_get_slot(obj, SLOT_BRAND); 24 - return vtype(brand) == T_NUM 25 - && (int)js_getnum(brand) == BRAND_WRITABLE_STREAM 22 + return js_check_brand(obj, BRAND_WRITABLE_STREAM) 26 23 && ws_get_stream(obj) != NULL; 27 24 } 28 25 29 26 bool ws_is_writer(ant_value_t obj) { 30 - if (!is_object_type(obj)) return false; 31 - ant_value_t brand = js_get_slot(obj, SLOT_BRAND); 32 - return vtype(brand) == T_NUM 33 - && (int)js_getnum(brand) == BRAND_WRITABLE_STREAM_WRITER 27 + return js_check_brand(obj, BRAND_WRITABLE_STREAM_WRITER) 34 28 && vtype(js_get_slot(obj, SLOT_RS_CLOSED)) == T_PROMISE 35 29 && vtype(js_get_slot(obj, SLOT_WS_READY)) == T_PROMISE; 36 30 } 37 31 38 32 bool ws_is_controller(ant_value_t obj) { 39 - if (!is_object_type(obj)) return false; 40 - ant_value_t brand = js_get_slot(obj, SLOT_BRAND); 41 - return vtype(brand) == T_NUM 42 - && (int)js_getnum(brand) == BRAND_WRITABLE_STREAM_CONTROLLER 33 + return js_check_brand(obj, BRAND_WRITABLE_STREAM_CONTROLLER) 43 34 && ws_get_controller(obj) != NULL 44 35 && ws_is_stream(js_get_slot(obj, SLOT_ENTRIES)); 45 36 }