diff --git a/ecmascript-testcases/test-dev-array-rep-trick.js b/ecmascript-testcases/test-dev-array-rep-trick.js new file mode 100644 index 00000000..f260e2ec --- /dev/null +++ b/ecmascript-testcases/test-dev-array-rep-trick.js @@ -0,0 +1,37 @@ +/*=== +10 x +10 y +100000 x +100000 y +===*/ + +/* String repeat can be implemented with an array join. */ + +function dump(x) { + var ch = '?' + if (x.length > 0) { + ch = x.charAt(0); + for (var i = 0; i < x.length; i++) { + if (x.charAt(i) !== ch) { + throw new Error('error in string'); + } + } + } + print(x.length, ch); +} + +try { + dump(Array.prototype.join.call({ length: 10 + 1 }, 'x')); + var arr = []; arr.length = 10 + 1; + dump(arr.join('y')); +} catch (e) { + print(e); +} + +try { + dump(Array.prototype.join.call({ length: 100000 + 1 }, 'x')); + var arr = []; arr.length = 100000 + 1; + dump(arr.join('y')); +} catch (e) { + print(e); +}