summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-same-size-zero-implicit.js
blob: cd78beba50a184a1e4016d4ea670540627f6d7cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- resizable-arraybuffer is not enabled unconditionally, requires shell-options
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-arraybuffer.prototype.resize
description: >
  Behavior when attempting to reset the size of a resizable array buffer to zero explicitly
info: |
  ArrayBuffer.prototype.resize ( newLength )

  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
  3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
  4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
  5. Let newByteLength be ? ToIntegerOrInfinity(newLength).
  6. If newByteLength < 0 or newByteLength > O.[[ArrayBufferMaxByteLength]],
     throw a RangeError exception.
  7. Let hostHandled be ? HostResizeArrayBuffer(O, newByteLength).
  [...]

  HostResizeArrayBuffer ( buffer, newByteLength )

  The implementation of HostResizeArrayBuffer must conform to the following
  requirements:

  - The abstract operation does not detach buffer.
  - The abstract operation may complete normally or abruptly.
  - If the abstract operation completes normally with handled,
    buffer.[[ArrayBufferByteLength]] is newByteLength.
  - The return value is either handled or unhandled.
features: [resizable-arraybuffer]
---*/

var ab = new ArrayBuffer(0, {maxByteLength: 0});
var caught = false;
var result;

// If the host chooses to throw as allowed by the specification, the observed
// behavior will be identical to the case where `ArrayBuffer.prototype.resize`
// has not been implemented. The following assertion prevents this test from
// passing in runtimes which have not implemented the method.
assert.sameValue(typeof ab.resize, 'function');

try {
  result = ab.resize();
} catch (_) {
  caught = true;
}

try {
  ab.slice();
} catch (_) {
  throw new Test262Error('The ArrayBuffer under test was detached');
}

// One of the following three conditions must be met:
//
// - HostResizeArrayBuffer returns an abrupt completion
// - HostResizeArrayBuffer handles the resize operation and conforms to the
//   invarient regarding [[ArrayBufferByteLength]]
// - HostResizeArrayBuffer does not handle the resize operation, and the
//   `resize` method updates [[ArrayBufferByteLength]]
//
// The final two conditions are indistinguishable.
assert(caught || ab.byteLength === 0, 'byteLength');

// One of the following three conditions must be met:
//
// - HostResizeArrayBuffer returns an abrupt completion
// - HostResizeArrayBuffer handles the resize operation, and the `resize`
//   method returns early
// - HostResizeArrayBuffer does not handle the resize operation, and the
//   `resize` method executes its final steps
//
// All three conditions have the same effect on the value of `result`.
assert.sameValue(result, undefined, 'normal completion value');

// The contents of the ArrayBuffer are not guaranteed by the host-defined
// abstract operation, so they are not asserted in this test.

reportCompare(0, 0);