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 ...rest in js_call

+39
+39
src/ant.c
··· 3998 3998 js->flags = saved_flags; 3999 3999 int arg_idx = 0; 4000 4000 4001 + bool has_rest = false; 4002 + jsoff_t rest_param_start = 0, rest_param_len = 0; 4003 + 4001 4004 while (fnpos < fnlen) { 4002 4005 fnpos = skiptonext(fn, fnlen, fnpos); 4003 4006 if (fnpos < fnlen && fn[fnpos] == ')') break; 4007 + 4008 + bool is_rest = false; 4009 + if (fnpos + 3 < fnlen && fn[fnpos] == '.' && fn[fnpos + 1] == '.' && fn[fnpos + 2] == '.') { 4010 + is_rest = true; 4011 + has_rest = true; 4012 + fnpos += 3; 4013 + fnpos = skiptonext(fn, fnlen, fnpos); 4014 + } 4015 + 4004 4016 jsoff_t identlen = 0; 4005 4017 uint8_t tok = parseident(&fn[fnpos], fnlen - fnpos, &identlen); 4006 4018 if (tok != TOK_IDENTIFIER) break; 4019 + 4020 + if (is_rest) { 4021 + rest_param_start = fnpos; 4022 + rest_param_len = identlen; 4023 + fnpos = skiptonext(fn, fnlen, fnpos + identlen); 4024 + break; 4025 + } 4026 + 4007 4027 jsval_t v = arg_idx < nargs ? args[arg_idx] : js_mkundef(); 4008 4028 setprop(js, js->scope, js_mkstr(js, &fn[fnpos], identlen), v); 4009 4029 arg_idx++; 4010 4030 fnpos = skiptonext(fn, fnlen, fnpos + identlen); 4011 4031 if (fnpos < fnlen && fn[fnpos] == ',') fnpos++; 4032 + } 4033 + 4034 + if (has_rest && rest_param_len > 0) { 4035 + jsval_t rest_array = mkarr(js); 4036 + if (!is_err(rest_array)) { 4037 + jsoff_t idx = 0; 4038 + while (arg_idx < nargs) { 4039 + char idxstr[16]; 4040 + snprintf(idxstr, sizeof(idxstr), "%u", (unsigned) idx); 4041 + jsval_t key = js_mkstr(js, idxstr, strlen(idxstr)); 4042 + setprop(js, rest_array, key, args[arg_idx]); 4043 + idx++; 4044 + arg_idx++; 4045 + } 4046 + jsval_t len_key = js_mkstr(js, "length", 6); 4047 + setprop(js, rest_array, len_key, tov((double) idx)); 4048 + rest_array = mkval(T_ARR, vdata(rest_array)); 4049 + setprop(js, js->scope, js_mkstr(js, &fn[rest_param_start], rest_param_len), rest_array); 4050 + } 4012 4051 } 4013 4052 4014 4053 if (fnpos < fnlen && fn[fnpos] == ')') fnpos++;