Debian Codegraph @

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

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