summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/grow/grow-same-size.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/grow/grow-same-size.js')
-rw-r--r--js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/grow/grow-same-size.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/grow/grow-same-size.js b/js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/grow/grow-same-size.js
new file mode 100644
index 0000000000..9148d630a5
--- /dev/null
+++ b/js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/grow/grow-same-size.js
@@ -0,0 +1,50 @@
+// |reftest| skip -- resizable-arraybuffer is not supported
+// 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-sharedarraybuffer.prototype.grow
+description: >
+ Behavior when attempting to grow a growable array buffer to its current size
+info: |
+ SharedArrayBuffer.prototype.grow ( newLength )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
+ 3. If IsSharedArrayBuffer(O) is false throw a TypeError exception.
+ 4. Let newByteLength be ? ToIntegerOrInfinity(newLength).
+ 5. Let hostHandled be ? HostGrowSharedArrayBuffer(O, newByteLength).
+ 6. If hostHandled is handled, return undefined.
+ [...]
+features: [SharedArrayBuffer, resizable-arraybuffer]
+---*/
+
+var sab = new SharedArrayBuffer(4, {maxByteLength: 5});
+var result;
+
+// If the host chooses to throw as allowed by the specification, the observed
+// behavior will be identical to the case where
+// `SharedArrayBuffer.prototype.grow` has not been implemented. The following
+// assertion prevents this test from passing in runtimes which have not
+// implemented the method.
+assert.sameValue(typeof sab.grow, 'function');
+
+try {
+ result = ab.grow(4);
+} catch (_) {}
+
+// One of the following three conditions must be met:
+//
+// - HostGrowSharedArrayBuffer returns an abrupt completion
+// - HostGrowSharedArrayBuffer handles the grow operation, and the `grow`
+// method returns early
+// - HostGrowSharedArrayBuffer does not handle the grow operation, and the
+// `grow` method executes its final steps
+//
+// All three conditions have the same effect on the value of `result`.
+assert.sameValue(result, undefined, 'normal completion value');
+
+// Neither the length nor the contents of the SharedArrayBuffer are guaranteed
+// by the host-defined abstract operation, so they are not asserted in this
+// test.
+
+reportCompare(0, 0);