async-validator
async-validator copied to clipboard
RangeError: Maximum call stack size exceeded (爆栈问题)
http://2ality.com/2014/04/call-stack-size.html
v8 max call stack in chrome is 1W+ , our validate series length is 370 ,so the asyncSerialArray and func call stack is over 1W+, so the Maximum call stack size occur.
but the asyncSerialArray may be written with tail recursive.
function asyncSerialArray(arr, func, callback) {
var index = 0
var arrLength = arr.length
return function next(errors) {
if (errors && errors.length) {
callback(errors)
return
}
var original = index
index = index + 1
if (original < arrLength) {
func(arr[original], next)
} else {
callback([])
}
}
}
maybe i can provide pr for this ?
put an setTimeout function can solve the problem. Maybe the library should consider this situation?
加个setTimeout果然解决了