MCPcopy Create free account
hub / github.com/mozilla/rhino / flat

Method flat

rhino/src/main/java/org/mozilla/javascript/NativeArray.java:1866–1890  ·  view source on GitHub ↗
(Context cx, VarScope scope, Scriptable source, double depth)

Source from the content-addressed store, hash-verified

1864 }
1865
1866 private static Scriptable flat(Context cx, VarScope scope, Scriptable source, double depth) {
1867 long length = getLengthProperty(cx, source);
1868
1869 Scriptable result;
1870 result = ArrayLikeAbstractOperations.arraySpeciesCreate(cx, scope, source, 0);
1871 long j = 0;
1872 for (long i = 0; i < length; i++) {
1873 Object elem = getRawElem(source, i);
1874 if (elem == Scriptable.NOT_FOUND) {
1875 continue;
1876 }
1877 if (depth >= 1 && js_isArray(elem)) {
1878 Scriptable arr = flat(cx, scope, (Scriptable) elem, depth - 1);
1879 long arrLength = getLengthProperty(cx, arr);
1880 for (long k = 0; k < arrLength; k++) {
1881 Object temp = getRawElem(arr, k);
1882 defineElemOrThrow(cx, result, j++, temp);
1883 }
1884 } else {
1885 defineElemOrThrow(cx, result, j++, elem);
1886 }
1887 }
1888 setLengthProperty(cx, result, j);
1889 return result;
1890 }
1891
1892 private static Object js_flatMap(
1893 Context cx, JSFunction f, Object nt, VarScope s, Object thisObj, Object[] args) {

Callers 2

js_flatMethod · 0.95
array-flat.jsFile · 0.80

Calls 6

getLengthPropertyMethod · 0.95
arraySpeciesCreateMethod · 0.95
js_isArrayMethod · 0.95
defineElemOrThrowMethod · 0.95
setLengthPropertyMethod · 0.95
getRawElemMethod · 0.80

Tested by

no test coverage detected