mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.1 KiB
59 lines
1.1 KiB
/*
|
|
* 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
|
|
===*/
|
|
|
|
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);
|
|
}
|
|
|