test262/implementation-contributed/javascriptcore/stress/array-join-on-strings-need-overflow-checks.js
test262-automation e9a5a7f918 [javascriptcore-test262-automation] changes from git@github.com:WebKit/webkit.git at sha 949e26452cfa153a7f4afe593da97e2fe9e1b706 on Tue Jul 03 2018 14:35:15 GMT-0400 (Eastern Daylight Time) (#1620)
* [javascriptcore-test262-automation] changes from git@github.com:WebKit/webkit.git at sha 949e26452cfa153a7f4afe593da97e2fe9e1b706 on Tue Jul 03 2018 14:35:15 GMT-0400 (Eastern Daylight Time)
2018-07-03 15:59:58 -04:00

34 lines
779 B
JavaScript

function assert(x, y) {
if (x != y)
throw(" Expect: " + y + ", actual: " + x);
}
s1 = "";
for (var k = 0; k < 2000; ++k)
s1 += "z";
var expectedLength = 2000;
assert(s1.length, 2000);
s2 = 'x';
expectedLength = 1;
assert(s2.length, expectedLength);
for (var i = 0; i < 22; ++i) {
expectedLength += expectedLength;
s2 += s2;
assert(s2.length, expectedLength);
}
var caughtException;
try {
expectedLength = ((s1.length - 1) * s2.length) + 1;
result = Array.prototype.join.apply(s1, [s2]);
assert(result.length, expectedLength);
} catch (e) {
caughtException = e;
}
if (!caughtException)
throw("Array.prototype.join should have thrown an exception when string length overflows");
assert(caughtException, "Error: Out of memory");