-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
Expand file tree
/
Copy pathtest-whatwg-encoding-encodeinto-large.js
More file actions
41 lines (33 loc) · 1.11 KB
/
test-whatwg-encoding-encodeinto-large.js
File metadata and controls
41 lines (33 loc) · 1.11 KB
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
'use strict';
const common = require('../common');
common.skipIf32Bits();
const assert = require('assert');
const encoder = new TextEncoder();
const source = 'a\xFF\u6211\u{1D452}';
const expected = encoder.encode(source);
const size = 2 ** 31 + expected.length;
const offset = expected.length - 1;
let dest;
try {
dest = new Uint8Array(size);
} catch (e) {
if (e.code === 'ERR_MEMORY_ALLOCATION_FAILED' ||
/Array buffer allocation failed/.test(e.message)) {
common.skip('insufficient space for Uint8Array allocation');
}
throw e;
}
const large = encoder.encodeInto(source, dest.subarray(offset));
assert.deepStrictEqual(large, {
read: source.length,
written: expected.length,
});
assert.deepStrictEqual(dest.slice(offset, offset + expected.length), expected);
const bounded = encoder.encodeInto(source,
dest.subarray(offset,
offset + expected.length));
assert.deepStrictEqual(bounded, {
read: source.length,
written: expected.length,
});
assert.deepStrictEqual(dest.slice(offset, offset + expected.length), expected);