|
2 | 2 |
|
3 | 3 | require('../common');
|
4 | 4 | const assert = require('assert');
|
5 |
| -const os = require('os'); |
6 | 5 | const SIZE = 28;
|
7 | 6 |
|
8 | 7 | const buf1 = Buffer.allocUnsafe(SIZE);
|
9 | 8 | const buf2 = Buffer.allocUnsafe(SIZE);
|
10 | 9 |
|
11 |
| - |
12 | 10 | // Default encoding
|
13 | 11 | testBufs('abc');
|
14 | 12 | testBufs('\u0222aa');
|
@@ -112,8 +110,7 @@ testBufs('\u0222aa', 8, 1, 'ucs2');
|
112 | 110 | testBufs('a\u0234b\u0235c\u0236', 4, -1, 'ucs2');
|
113 | 111 | testBufs('a\u0234b\u0235c\u0236', 4, 1, 'ucs2');
|
114 | 112 | testBufs('a\u0234b\u0235c\u0236', 12, 1, 'ucs2');
|
115 |
| -assert.strictEqual(Buffer.allocUnsafe(1).fill('\u0222', 'ucs2')[0], |
116 |
| - os.endianness() === 'LE' ? 0x22 : 0x02); |
| 113 | +assert.strictEqual(Buffer.allocUnsafe(1).fill('\u0222', 'ucs2')[0], 0x22); |
117 | 114 |
|
118 | 115 |
|
119 | 116 | // HEX
|
@@ -259,15 +256,6 @@ function writeToFill(string, offset, end, encoding) {
|
259 | 256 | }
|
260 | 257 | } while (offset < buf2.length);
|
261 | 258 |
|
262 |
| - // Correction for UCS2 operations. |
263 |
| - if (os.endianness() === 'BE' && encoding === 'ucs2') { |
264 |
| - for (var i = 0; i < buf2.length; i += 2) { |
265 |
| - var tmp = buf2[i]; |
266 |
| - buf2[i] = buf2[i + 1]; |
267 |
| - buf2[i + 1] = tmp; |
268 |
| - } |
269 |
| - } |
270 |
| - |
271 | 259 | return buf2;
|
272 | 260 | }
|
273 | 261 |
|
@@ -406,3 +394,12 @@ assert.throws(() => {
|
406 | 394 | });
|
407 | 395 | buf.fill('');
|
408 | 396 | }, /^RangeError: out of range index$/);
|
| 397 | + |
| 398 | + |
| 399 | +assert.deepStrictEqual( |
| 400 | + Buffer.allocUnsafeSlow(16).fill('ab', 'utf16le'), |
| 401 | + Buffer.from('61006200610062006100620061006200', 'hex')); |
| 402 | + |
| 403 | +assert.deepStrictEqual( |
| 404 | + Buffer.allocUnsafeSlow(15).fill('ab', 'utf16le'), |
| 405 | + Buffer.from('610062006100620061006200610062', 'hex')); |
0 commit comments