Browse Source

basic testcase for string overflows (now check Array.prototype.join(), internally duk_concat())

pull/1/head
Sami Vaarala 11 years ago
parent
commit
9780a9fc9c
  1. 61
      ecmascript-testcases/test-misc-strings-overflows.js

61
ecmascript-testcases/test-misc-strings-overflows.js

@ -0,0 +1,61 @@
/*
* String overflow tests.
*
* Strings overflow at 4G bytes (at the latest) even on 64-bit platforms,
* at least for the moment. Most string concat operations now use duk_concat()
* internally, which is exercised fully by Array.prototype.join().
*/
/*===
1048576
===*/
var oneMeg = 'x';
var i;
for (i = 0; i < 20; i++) {
oneMeg += oneMeg;
}
print(oneMeg.length);
/*===
RangeError
RangeError
RangeError
===*/
function arrayJoinSepOverflow() {
/* The internal helper first computes total size of separators, so see
* that the overflow check for that works.
*/
var test = [];
var i;
for (i = 0; i < 4097; i++) {
test[i] = '';
}
test.join(oneMeg); /* 4096 seps * 1M = 2**32 -> overflow */
print('still here');
}
function arrayJoinResultOverflow() {
var test = [];
var i;
for (i = 0; i < 4097; i++) {
test[i] = oneMeg;
}
test.join('');
print('still here');
}
try {
arrayJoinSepOverflow();
} catch (e) {
print(e.name);
}
try {
arrayJoinResultOverflow();
} catch (e) {
print(e.name);
}
Loading…
Cancel
Save