| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2312b0b commit 60d5f6b
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -618,6 +618,9 @@ void Fill(const FunctionCallbackInfo<Value>& args) { | |||
| 618 | 618 | ||
| 619 | 619 | } else if (enc == UCS2) { | |
| 620 | 620 | node::TwoByteValue str(env->isolate(), args[1]); | |
| 621 | + if (IsBigEndian()) | ||
| 622 | + SwapBytes16(reinterpret_cast<char*>(&str[0]), str_length); | ||
| 623 | + | ||
| 621 | 624 | memcpy(ts_obj_data + start, *str, MIN(str_length, fill_length)); | |
| 622 | 625 | ||
| 623 | 626 | } else { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,13 +2,11 @@ | |||
| 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')); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments