options-maxbytelength-object.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (C) 2021 the V8 project authors. All rights reserved.
  2. // This code is governed by the BSD license found in the LICENSE file.
  3. /*---
  4. esid: sec-arraybuffer-constructor
  5. description: |
  6. Invoked with an options object whose `maxByteLength` property cannot be
  7. coerced to a primitive value
  8. info: |
  9. ArrayBuffer( length [ , options ] )
  10. 1. If NewTarget is undefined, throw a TypeError exception.
  11. 2. Let byteLength be ? ToIndex(length).
  12. 3. Let requestedMaxByteLength be ? GetArrayBufferMaxByteLengthOption(options).
  13. [...]
  14. 1.1.5 GetArrayBufferMaxByteLengthOption ( options )
  15. 1. If Type(options) is not Object, return empty.
  16. 2. Let maxByteLength be ? Get(options, "maxByteLength").
  17. 3. If maxByteLength is undefined, return empty.
  18. 4. Return ? ToIndex(maxByteLength).
  19. features: [resizable-arraybuffer]
  20. ---*/
  21. var log = [];
  22. var options = {
  23. maxByteLength: {
  24. toString: function() {
  25. log.push('toString');
  26. return {};
  27. },
  28. valueOf: function() {
  29. log.push('valueOf');
  30. return {};
  31. }
  32. }
  33. };
  34. assert.throws(TypeError, function() {
  35. new ArrayBuffer(0, options);
  36. });
  37. assert.sameValue(log.length, 2);
  38. assert.sameValue(log[0], 'valueOf');
  39. assert.sameValue(log[1], 'toString');