Debian Codegraph @

js/src/tests/test262/built-ins/ArrayBuffer/options-maxbytelength-object.js

raw
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
11 1. If NewTarget is undefined, throw a TypeError exception.
12 2. Let byteLength be ? ToIndex(length).
13 3. Let requestedMaxByteLength be ? GetArrayBufferMaxByteLengthOption(options).
14 [...]
15
16 1.1.5 GetArrayBufferMaxByteLengthOption ( options )
17
18 1. If Type(options) is not Object, return empty.
19 2. Let maxByteLength be ? Get(options, "maxByteLength").
20 3. If maxByteLength is undefined, return empty.
21 4. Return ? ToIndex(maxByteLength).
22 features: [resizable-arraybuffer]
23 ---*/
24
25 var log = [];
26 var options = {
27 maxByteLength: {
28 toString: function() {
29 log.push('toString');
30 return {};
31 },
32 valueOf: function() {
33 log.push('valueOf');
34 return {};
35 }
36 }
37 };
38
39 assert.throws(TypeError, function() {
40 new ArrayBuffer(0, options);
41 });
42
43 assert.sameValue(log.length, 2);
44 assert.sameValue(log[0], 'valueOf');
45 assert.sameValue(log[1], 'toString');
46
47 reportCompare(0, 0);