Bug 1885337 - Part 3: Import tests from test262 PR. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / prs / 3994 / built-ins / Uint8Array / prototype / setFromHex / target-size.js
blobd73fa1749d2579cf7fa4118ba10b6d45208e1f22
1 // |reftest| shell-option(--enable-uint8array-base64) skip-if(!Uint8Array.fromBase64||!xulRuntime.shell) -- uint8array-base64 is not enabled unconditionally, requires shell-options
2 // Copyright (C) 2024 Kevin Gibbons. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4 /*---
5 esid: sec-uint8array.prototype.setfromhex
6 description: Uint8Array.prototype.setFromHex behavior when target buffer is small
7 includes: [compareArray.js]
8 features: [uint8array-base64, TypedArray]
9 ---*/
11 // buffer too small
12 var target = new Uint8Array([255, 255]);
13 var result = target.setFromHex('aabbcc');
14 assert.sameValue(result.read, 4);
15 assert.sameValue(result.written, 2);
16 assert.compareArray(target, [170, 187]);
18 // buffer exact
19 var target = new Uint8Array([255, 255, 255]);
20 var result = target.setFromHex('aabbcc');
21 assert.sameValue(result.read, 6);
22 assert.sameValue(result.written, 3);
23 assert.compareArray(target, [170, 187, 204]);
25 // buffer too large
26 var target = new Uint8Array([255, 255, 255, 255]);
27 var result = target.setFromHex('aabbcc');
28 assert.sameValue(result.read, 6);
29 assert.sameValue(result.written, 3);
30 assert.compareArray(target, [170, 187, 204, 255]);
32 reportCompare(0, 0);