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.

regexp abstract exec

+41 -19
+41 -19
src/modules/regex.c
··· 1021 1021 return result; 1022 1022 } 1023 1023 1024 - static ant_value_t regexp_exec_abstract(ant_t *js, ant_value_t rx, ant_value_t str) { 1025 - ant_value_t exec_fn = js_get(js, rx, "exec"); 1026 - if (is_err(exec_fn)) return exec_fn; 1027 - 1024 + static ant_value_t regexp_exec_with_exec_fn(ant_t *js, ant_value_t rx, ant_value_t str, ant_value_t exec_fn) { 1028 1025 if (vtype(exec_fn) == T_FUNC || vtype(exec_fn) == T_CFUNC) { 1029 1026 ant_value_t call_args[1] = { str }; 1030 1027 ant_value_t result = sv_vm_call(js->vm, js, exec_fn, rx, call_args, 1, NULL, false); ··· 1041 1038 js->this_val = saved; 1042 1039 1043 1040 return result; 1041 + } 1042 + 1043 + static ant_value_t regexp_exec_abstract(ant_t *js, ant_value_t rx, ant_value_t str) { 1044 + ant_value_t exec_fn = js_get(js, rx, "exec"); 1045 + if (is_err(exec_fn)) return exec_fn; 1046 + return regexp_exec_with_exec_fn(js, rx, str, exec_fn); 1044 1047 } 1045 1048 1046 1049 bool regexp_exec_truthy_try_fast( ··· 1076 1079 ant_value_t result; 1077 1080 if (vtype(exec_fn) == T_CFUNC && js_as_cfunc(exec_fn) == builtin_regexp_exec) { 1078 1081 result = regexp_exec_internal(js, regexp, str_arg, true); 1079 - } else { 1080 - result = regexp_exec_abstract(js, regexp, str_arg); 1081 - } 1082 + } else result = regexp_exec_with_exec_fn(js, regexp, str_arg, exec_fn); 1083 + 1082 1084 if (is_err(result)) return result; 1083 1085 return mkval(T_BOOL, vtype(result) != T_NULL ? 1 : 0); 1084 1086 } 1085 1087 1086 1088 static ant_value_t builtin_regexp_flags_getter(ant_t *js, ant_value_t *args, int nargs) { 1087 - (void)args; (void)nargs; 1088 1089 ant_value_t rx = js->this_val; 1089 1090 if (!is_object_type(rx)) 1090 1091 return js_mkerr_typed(js, JS_ERR_TYPE, "RegExp.prototype.flags called on non-object"); 1092 + 1093 + char buf[16]; int n = 0; 1094 + ant_value_t v = js_getprop_fallback(js, rx, "hasIndices"); 1095 + 1096 + if (is_err(v)) return v; 1097 + if (js_truthy(js, v)) buf[n++] = 'd'; 1091 1098 1092 - char buf[16]; 1093 - int n = 0; 1094 - uint8_t mask = regexp_flags_mask(js, rx); 1099 + v = js_getprop_fallback(js, rx, "global"); 1100 + if (is_err(v)) return v; 1101 + if (js_truthy(js, v)) buf[n++] = 'g'; 1095 1102 1096 - if (mask & REGEXP_FLAG_HAS_INDICES) buf[n++] = 'd'; 1097 - if (mask & REGEXP_FLAG_GLOBAL) buf[n++] = 'g'; 1098 - if (mask & REGEXP_FLAG_IGNORE_CASE) buf[n++] = 'i'; 1099 - if (mask & REGEXP_FLAG_MULTILINE) buf[n++] = 'm'; 1100 - if (mask & REGEXP_FLAG_DOTALL) buf[n++] = 's'; 1101 - if (mask & REGEXP_FLAG_UNICODE) buf[n++] = 'u'; 1102 - if (mask & REGEXP_FLAG_UNICODE_SET) buf[n++] = 'v'; 1103 - if (mask & REGEXP_FLAG_STICKY) buf[n++] = 'y'; 1103 + v = js_getprop_fallback(js, rx, "ignoreCase"); 1104 + if (is_err(v)) return v; 1105 + if (js_truthy(js, v)) buf[n++] = 'i'; 1106 + 1107 + v = js_getprop_fallback(js, rx, "multiline"); 1108 + if (is_err(v)) return v; 1109 + if (js_truthy(js, v)) buf[n++] = 'm'; 1110 + 1111 + v = js_getprop_fallback(js, rx, "dotAll"); 1112 + if (is_err(v)) return v; 1113 + if (js_truthy(js, v)) buf[n++] = 's'; 1114 + 1115 + v = js_getprop_fallback(js, rx, "unicode"); 1116 + if (is_err(v)) return v; 1117 + if (js_truthy(js, v)) buf[n++] = 'u'; 1118 + 1119 + v = js_getprop_fallback(js, rx, "unicodeSets"); 1120 + if (is_err(v)) return v; 1121 + if (js_truthy(js, v)) buf[n++] = 'v'; 1122 + 1123 + v = js_getprop_fallback(js, rx, "sticky"); 1124 + if (is_err(v)) return v; 1125 + if (js_truthy(js, v)) buf[n++] = 'y'; 1104 1126 1105 1127 return js_mkstr(js, buf, n); 1106 1128 }