mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
Signed-off-by: LiviaMedeiros <livia@cirno.name> PR-URL: https://github.com/nodejs/node/pull/67461 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
49 lines
1.0 KiB
JavaScript
49 lines
1.0 KiB
JavaScript
'use strict';
|
|
|
|
require('../common');
|
|
const assert = require('assert');
|
|
const { isAscii, Buffer } = require('buffer');
|
|
|
|
const encoder = new TextEncoder();
|
|
|
|
assert.strictEqual(isAscii(encoder.encode('hello')), true);
|
|
assert.strictEqual(isAscii(encoder.encode('ğ')), false);
|
|
assert.strictEqual(isAscii(Buffer.from([])), true);
|
|
|
|
[
|
|
undefined,
|
|
'', 'hello',
|
|
false, true,
|
|
0, 1,
|
|
0n, 1n,
|
|
Symbol(),
|
|
() => {},
|
|
{}, [], null,
|
|
].forEach((input) => {
|
|
assert.throws(
|
|
() => { isAscii(input); },
|
|
{
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
},
|
|
);
|
|
});
|
|
|
|
{
|
|
// Detached array buffers and views are treated as empty.
|
|
const arrayBuffer = new ArrayBuffer(1);
|
|
const typedArray = new Uint8Array(arrayBuffer);
|
|
typedArray[0] = 0xff;
|
|
const inputs = [
|
|
arrayBuffer,
|
|
typedArray,
|
|
Buffer.from(arrayBuffer),
|
|
];
|
|
for (const input of inputs) {
|
|
assert.strictEqual(isAscii(input), false);
|
|
}
|
|
structuredClone(arrayBuffer, { transfer: [arrayBuffer] });
|
|
for (const input of inputs) {
|
|
assert.strictEqual(isAscii(input), true);
|
|
}
|
|
}
|