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.

clean up proto ctor

+34 -15
+34 -15
src/ant.c
··· 9986 9986 return js_mkundef(); 9987 9987 } 9988 9988 9989 + static inline bool is_same_heap_value(ant_value_t a, ant_value_t b) { 9990 + return vtype(a) == vtype(b) && vdata(a) == vdata(b); 9991 + } 9992 + 9993 + static inline bool is_constructor_value(ant_value_t value) { 9994 + return vtype(value) == T_FUNC || vtype(value) == T_CFUNC; 9995 + } 9996 + 9997 + static void promise_init_derived_promise( 9998 + ant_t *js, 9999 + ant_value_t next_p, 10000 + ant_value_t parent_p, 10001 + ant_value_t species_ctor, 10002 + ant_value_t promise_ctor 10003 + ) { 10004 + ant_value_t next_obj = js_as_obj(next_p); 10005 + 10006 + if (is_constructor_value(species_ctor) && !is_same_heap_value(species_ctor, promise_ctor)) { 10007 + ant_value_t species_proto = js_get(js, species_ctor, "prototype"); 10008 + if (is_object_type(species_proto)) js_set_proto_init(next_obj, species_proto); 10009 + set_slot(next_obj, SLOT_CTOR, species_ctor); 10010 + return; 10011 + } 10012 + 10013 + ant_value_t parent_obj = js_as_obj(parent_p); 10014 + ant_value_t parent_proto = get_slot(parent_obj, SLOT_PROTO); 10015 + if (vtype(parent_proto) == T_OBJ) js_set_proto_init(next_obj, parent_proto); 10016 + 10017 + ant_value_t parent_ctor = get_slot(parent_obj, SLOT_CTOR); 10018 + if (is_constructor_value(parent_ctor)) set_slot(next_obj, SLOT_CTOR, parent_ctor); 10019 + } 10020 + 9989 10021 static ant_value_t builtin_promise_then(ant_t *js, ant_value_t *args, int nargs) { 9990 10022 ant_value_t p = js->this_val; 9991 10023 if (vtype(p) != T_PROMISE) return js_mkerr(js, "not a promise"); ··· 10026 10058 10027 10059 ant_value_t nextP = js_mkpromise(js); 10028 10060 GC_ROOT_PIN(js, nextP); 10029 - if ((vtype(species_ctor) == T_FUNC || vtype(species_ctor) == T_CFUNC) 10030 - && !(vtype(species_ctor) == vtype(promise_ctor) 10031 - && vdata(species_ctor) == vdata(promise_ctor))) { 10032 - ant_value_t species_proto = js_get(js, species_ctor, "prototype"); 10033 - if (is_object_type(species_proto)) 10034 - js_set_proto_init(js_as_obj(nextP), species_proto); 10035 - set_slot(js_as_obj(nextP), SLOT_CTOR, species_ctor); 10036 - } else { 10037 - ant_value_t p_proto = get_slot(js_as_obj(p), SLOT_PROTO); 10038 - if (vtype(p_proto) == T_OBJ) { 10039 - js_set_proto_init(js_as_obj(nextP), p_proto); 10040 - ant_value_t p_ctor = get_slot(js_as_obj(p), SLOT_CTOR); 10041 - if (vtype(p_ctor) == T_FUNC) set_slot(js_as_obj(nextP), SLOT_CTOR, p_ctor); 10042 - } 10043 - } 10061 + promise_init_derived_promise(js, nextP, p, species_ctor, promise_ctor); 10044 10062 10045 10063 ant_value_t onFulfilled = nargs > 0 ? args[0] : js_mkundef(); 10046 10064 ant_value_t onRejected = nargs > 1 ? args[1] : js_mkundef(); 10065 + 10047 10066 GC_ROOT_PIN(js, onFulfilled); 10048 10067 GC_ROOT_PIN(js, onRejected); 10049 10068