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.

use enum for map/set ctx

+30 -23
+30 -23
src/modules/collections.c
··· 689 689 double size; 690 690 } set_record_t; 691 691 692 - typedef ant_value_t (*set_key_cb)( 692 + typedef enum { 693 + SET_KEY_CONTINUE, 694 + SET_KEY_STOP, 695 + } set_key_status_t; 696 + 697 + typedef set_key_status_t (*set_key_cb)( 693 698 ant_t *js, 694 699 ant_value_t value, 695 - void *ctx, 696 - bool *stop 700 + ant_value_t *result, 701 + void *ctx 697 702 ); 698 703 699 704 static ant_value_t get_set_record(ant_t *js, ant_value_t value, const char *method, set_record_t *out) { ··· 770 775 ant_value_t value = js_getprop_fallback(js, next, "value"); 771 776 if (is_err(value)) return value; 772 777 773 - bool stop = false; 774 - ant_value_t result = cb(js, value, ctx, &stop); 778 + ant_value_t result = js_mkundef(); 779 + set_key_status_t status = cb(js, value, &result, ctx); 780 + 775 781 if (is_err(result)) { 776 782 ant_value_t close_result = set_record_close_keys_iterator(js, iterator); 777 783 return is_err(close_result) ? close_result : result; 778 784 } 779 - if (stop) { 785 + 786 + if (status == SET_KEY_STOP) { 780 787 ant_value_t close_result = set_record_close_keys_iterator(js, iterator); 781 788 return is_err(close_result) ? close_result : js_mkundef(); 782 789 } ··· 788 795 set_entry_t **out_set; 789 796 } set_build_ctx_t; 790 797 791 - static ant_value_t set_add_key_cb(ant_t *js, ant_value_t value, void *ctx, bool *stop) { 798 + static set_key_status_t set_add_key_cb(ant_t *js, ant_value_t value, ant_value_t *result, void *ctx) { 792 799 set_build_ctx_t *build = (set_build_ctx_t *)ctx; 793 800 if (!set_result_add(js, build->out, build->out_set, value)) 794 - return js_mkerr(js, "out of memory"); 795 - return js_mkundef(); 801 + *result = js_mkerr(js, "out of memory"); 802 + return SET_KEY_CONTINUE; 796 803 } 797 804 798 805 static ant_value_t set_union(ant_t *js, ant_value_t *args, int nargs) { ··· 823 830 set_entry_t **this_set; 824 831 } set_compare_build_ctx_t; 825 832 826 - static ant_value_t set_intersection_key_cb(ant_t *js, ant_value_t value, void *ctx, bool *stop) { 833 + static set_key_status_t set_intersection_key_cb(ant_t *js, ant_value_t value, ant_value_t *result, void *ctx) { 827 834 set_compare_build_ctx_t *build = (set_compare_build_ctx_t *)ctx; 828 835 if ( 829 836 set_find_entry(js, build->this_set, value) && 830 837 !set_result_add(js, build->out, build->out_set, value) 831 - ) return js_mkerr(js, "out of memory"); 832 - return js_mkundef(); 838 + ) *result = js_mkerr(js, "out of memory"); 839 + return SET_KEY_CONTINUE; 833 840 } 834 841 835 842 static ant_value_t set_intersection(ant_t *js, ant_value_t *args, int nargs) { ··· 878 885 return js_mkundef(); 879 886 } 880 887 881 - static ant_value_t set_delete_key_cb(ant_t *js, ant_value_t value, void *ctx, bool *stop) { 888 + static set_key_status_t set_delete_key_cb(ant_t *js, ant_value_t value, ant_value_t *result, void *ctx) { 882 889 set_build_ctx_t *build = (set_build_ctx_t *)ctx; 883 890 set_result_delete(js, build->out_set, value); 884 - return js_mkundef(); 891 + return SET_KEY_CONTINUE; 885 892 } 886 893 887 894 static ant_value_t set_difference(ant_t *js, ant_value_t *args, int nargs) { ··· 923 930 set_entry_t **this_set; 924 931 } set_symdiff_ctx_t; 925 932 926 - static ant_value_t set_symmetric_difference_key_cb(ant_t *js, ant_value_t value, void *ctx, bool *stop) { 933 + static set_key_status_t set_symmetric_difference_key_cb(ant_t *js, ant_value_t value, ant_value_t *result, void *ctx) { 927 934 set_symdiff_ctx_t *build = (set_symdiff_ctx_t *)ctx; 928 935 if (set_find_entry(js, build->this_set, value)) { 929 936 set_result_delete(js, build->out_set, value); 930 937 } else if (!set_find_entry(js, build->out_set, value)) 931 - if (!set_result_add(js, build->out, build->out_set, value)) return js_mkerr(js, "out of memory"); 932 - return js_mkundef(); 938 + if (!set_result_add(js, build->out, build->out_set, value)) *result = js_mkerr(js, "out of memory"); 939 + return SET_KEY_CONTINUE; 933 940 } 934 941 935 942 static ant_value_t set_symmetricDifference(ant_t *js, ant_value_t *args, int nargs) { ··· 980 987 bool result; 981 988 } set_predicate_ctx_t; 982 989 983 - static ant_value_t set_superset_key_cb(ant_t *js, ant_value_t value, void *ctx, bool *stop) { 990 + static set_key_status_t set_superset_key_cb(ant_t *js, ant_value_t value, ant_value_t *result, void *ctx) { 984 991 set_predicate_ctx_t *pred = (set_predicate_ctx_t *)ctx; 985 992 if (!set_find_entry(js, pred->this_set, value)) { 986 993 pred->result = false; 987 - *stop = true; 994 + return SET_KEY_STOP; 988 995 } 989 - return js_mkundef(); 996 + return SET_KEY_CONTINUE; 990 997 } 991 998 992 999 static ant_value_t set_isSupersetOf(ant_t *js, ant_value_t *args, int nargs) { ··· 1005 1012 return js_bool(pred.result); 1006 1013 } 1007 1014 1008 - static ant_value_t set_disjoint_key_cb(ant_t *js, ant_value_t value, void *ctx, bool *stop) { 1015 + static set_key_status_t set_disjoint_key_cb(ant_t *js, ant_value_t value, ant_value_t *result, void *ctx) { 1009 1016 set_predicate_ctx_t *pred = (set_predicate_ctx_t *)ctx; 1010 1017 if (set_find_entry(js, pred->this_set, value)) { 1011 1018 pred->result = false; 1012 - *stop = true; 1019 + return SET_KEY_STOP; 1013 1020 } 1014 - return js_mkundef(); 1021 + return SET_KEY_CONTINUE; 1015 1022 } 1016 1023 1017 1024 static ant_value_t set_isDisjointFrom(ant_t *js, ant_value_t *args, int nargs) {