Debian Codegraph @

js/src/tests/test262/built-ins/DataView/custom-proto-access-resizes-buffer-valid-by-offset.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-dataview-buffer-byteoffset-bytelength
5 description: >
6 The view's offset may equal the underlying buffer's byte length if it is
7 modified during retrieval of the NewTarget's prototype.
8 features: [resizable-arraybuffer]
9 ---*/
10
11 // If the host chooses to throw as allowed by the specification, the observed
12 // behavior will be identical to the case where `ArrayBuffer.prototype.resize`
13 // has not been implemented. The following assertion prevents this test from
14 // passing in runtimes which have not implemented the method.
15 assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function');
16
17 var buffer = new ArrayBuffer(3, {maxByteLength: 3});
18 var expectedByteLength;
19
20 var newTarget = function() {}.bind(null);
21 Object.defineProperty(newTarget, 'prototype', {
22 get: function() {
23 try {
24 buffer.resize(2);
25 expectedByteLength = 0;
26 } catch (error) {
27 expectedByteLength = 1;
28 }
29 }
30 });
31
32 var result = Reflect.construct(DataView, [buffer, 2], newTarget);
33
34 assert.sameValue(result.constructor, DataView);
35 assert.sameValue(result.byteLength, expectedByteLength);
36
37 reportCompare(0, 0);