allocation-limit.js 988 B

12345678910111213141516171819202122232425262728293031
  1. // Copyright (C) 2015 André Bargull. All rights reserved.
  2. // This code is governed by the BSD license found in the LICENSE file.
  3. /*---
  4. esid: sec-arraybuffer-length
  5. description: >
  6. Throws a RangeError if requested Data Block is too large.
  7. info: |
  8. ArrayBuffer( length )
  9. ...
  10. 6. Return AllocateArrayBuffer(NewTarget, byteLength).
  11. 6.2.6.1 CreateByteDataBlock(size)
  12. ...
  13. 2. Let db be a new Data Block value consisting of size bytes. If it is
  14. impossible to create such a Data Block, throw a RangeError exception.
  15. ...
  16. ---*/
  17. assert.throws(RangeError, function() {
  18. // Allocating 7 PiB should fail with a RangeError.
  19. // Math.pow(1024, 5) = 1125899906842624
  20. new ArrayBuffer(7 * 1125899906842624);
  21. }, "`length` parameter is 7 PiB");
  22. assert.throws(RangeError, function() {
  23. // Allocating almost 8 PiB should fail with a RangeError.
  24. // Math.pow(2, 53) = 9007199254740992
  25. new ArrayBuffer(9007199254740992 - 1);
  26. }, "`length` parameter is Math.pow(2, 53) - 1");