////////////////////////////////////////////////////////////////////////////// // // Checks for requests for oversize arrays (more than MaxArrayPayloadBytes), // where MaxArrayPayloadBytes == 1,987,654,321.
const MaxArrayPayloadBytes = 1987654321;
function maxNumElementsForSize(bytes, elemSize) {
let n = bytes;
n = bytes & ~0b111; // round down to nearest multiple of gc::CellAlignSize
n -= getBuildConfiguration()['pointer-byte-size']; // subtract size of data header
n = Math.floor(n / elemSize); // divide by elemSize and round down return n;
}
// // Test code for maxNumElementsForSize // for (const bytes of [32, 33, 112]) { // for (const size of [1, 2, 4, 8, 16]) { // print(bytes, size, "->", maxNumElementsForSize(bytes, size)); // } // } // throw "see above";
const tests = [[1, test1], [2, test2], [4, test4], [8, test8]]; if (wasmSimdEnabled()) {
tests.push([16, test16]);
} for (const [size, test] of tests) { for (const doMasm of [false, true]) { if (doMasm) { // Prime the alloc site with a successful allocation so we hit masm from here on out
test(0);
}
// Test boundaries of implementation limit const maxNumElements = maxNumElementsForSize(MaxArrayPayloadBytes, size);
test(maxNumElements);
assertErrorMessage(() => test(maxNumElements + 1), WebAssembly.RuntimeError, /too many array elements/);
// Test around signed overflow boundary for (let i = -16; i <= 16; i++) {
assertErrorMessage(
() => test(maxNumElementsForSize(Math.pow(2, 31) + i, size)),
WebAssembly.RuntimeError,
/too many array elements/,
);
}
// Test around unsigned overflow boundary for (let i = -16; i <= -1; i++) {
assertErrorMessage(() => test(i), WebAssembly.RuntimeError, /too many array elements/);
}
}
}
}
const tests = [[1, test1], [2, test2], [4, test4], [8, test8]]; if (wasmSimdEnabled()) {
tests.push([16, test16]);
} for (const [size, test] of tests) { for (const doMasm of [false, true]) { if (doMasm) { // Prime the alloc site with a successful allocation so we hit masm from here on out
test(0);
}
// Test boundaries of implementation limit const maxNumElements = maxNumElementsForSize(MaxArrayPayloadBytes, size);
test(maxNumElements);
assertErrorMessage(() => test(maxNumElements + 1), WebAssembly.RuntimeError, /too many array elements/);
// Test around signed overflow boundary for (let i = -16; i <= 16; i++) {
assertErrorMessage(
() => test(maxNumElementsForSize(Math.pow(2, 31) + i, size)),
WebAssembly.RuntimeError,
/too many array elements/,
);
}
// Test around unsigned overflow boundary for (let i = -16; i <= -1; i++) {
assertErrorMessage(() => test(i), WebAssembly.RuntimeError, /too many array elements/);
}
}
}
}
// array.new_data // Impossible to test because the max data segment length is 1GB // (1,073,741,824 bytes) (MaxDataSegmentLengthPages * PageSize), which is less // than MaxArrayPayloadBytes.
// array.new_element // Similarly, impossible to test because an element segment can contain at // most 10,000,000 (MaxElemSegmentLength) entries.
Messung V0.5
¤ Dauer der Verarbeitung: 0.39 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.