(target, source *Object, sourceLen, start, depth int64, mapperFunction func(FunctionCall) Value, thisArg Value)
| 1203 | } |
| 1204 | |
| 1205 | func (r *Runtime) flattenIntoArray(target, source *Object, sourceLen, start, depth int64, mapperFunction func(FunctionCall) Value, thisArg Value) int64 { |
| 1206 | targetIndex, sourceIndex := start, int64(0) |
| 1207 | for sourceIndex < sourceLen { |
| 1208 | p := intToValue(sourceIndex) |
| 1209 | if source.hasProperty(p.toString()) { |
| 1210 | element := nilSafe(source.get(p, source)) |
| 1211 | if mapperFunction != nil { |
| 1212 | element = mapperFunction(FunctionCall{ |
| 1213 | This: thisArg, |
| 1214 | Arguments: []Value{element, p, source}, |
| 1215 | }) |
| 1216 | } |
| 1217 | var elementArray *Object |
| 1218 | if depth > 0 { |
| 1219 | if elementObj, ok := element.(*Object); ok && isArray(elementObj) { |
| 1220 | elementArray = elementObj |
| 1221 | } |
| 1222 | } |
| 1223 | if elementArray != nil { |
| 1224 | elementLen := toLength(elementArray.self.getStr("length", nil)) |
| 1225 | targetIndex = r.flattenIntoArray(target, elementArray, elementLen, targetIndex, depth-1, nil, nil) |
| 1226 | } else { |
| 1227 | if targetIndex >= maxInt-1 { |
| 1228 | panic(r.NewTypeError("Invalid array length")) |
| 1229 | } |
| 1230 | createDataPropertyOrThrow(target, intToValue(targetIndex), element) |
| 1231 | targetIndex++ |
| 1232 | } |
| 1233 | } |
| 1234 | sourceIndex++ |
| 1235 | } |
| 1236 | return targetIndex |
| 1237 | } |
| 1238 | |
| 1239 | func (r *Runtime) arrayproto_flatMap(call FunctionCall) Value { |
| 1240 | o := call.This.ToObject(r) |
no test coverage detected