11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_cirequire('../common'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst { isAscii, Buffer } = require('buffer'); 61cb0ef41Sopenharmony_ciconst { TextEncoder } = require('util'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst encoder = new TextEncoder(); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciassert.strictEqual(isAscii(encoder.encode('hello')), true); 111cb0ef41Sopenharmony_ciassert.strictEqual(isAscii(encoder.encode('ğ')), false); 121cb0ef41Sopenharmony_ciassert.strictEqual(isAscii(Buffer.from([])), true); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci[ 151cb0ef41Sopenharmony_ci undefined, 161cb0ef41Sopenharmony_ci '', 'hello', 171cb0ef41Sopenharmony_ci false, true, 181cb0ef41Sopenharmony_ci 0, 1, 191cb0ef41Sopenharmony_ci 0n, 1n, 201cb0ef41Sopenharmony_ci Symbol(), 211cb0ef41Sopenharmony_ci () => {}, 221cb0ef41Sopenharmony_ci {}, [], null, 231cb0ef41Sopenharmony_ci].forEach((input) => { 241cb0ef41Sopenharmony_ci assert.throws( 251cb0ef41Sopenharmony_ci () => { isAscii(input); }, 261cb0ef41Sopenharmony_ci { 271cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 281cb0ef41Sopenharmony_ci }, 291cb0ef41Sopenharmony_ci ); 301cb0ef41Sopenharmony_ci}); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci{ 331cb0ef41Sopenharmony_ci // Test with detached array buffers 341cb0ef41Sopenharmony_ci const arrayBuffer = new ArrayBuffer(1024); 351cb0ef41Sopenharmony_ci structuredClone(arrayBuffer, { transfer: [arrayBuffer] }); 361cb0ef41Sopenharmony_ci assert.throws( 371cb0ef41Sopenharmony_ci () => { isAscii(arrayBuffer); }, 381cb0ef41Sopenharmony_ci { 391cb0ef41Sopenharmony_ci code: 'ERR_INVALID_STATE' 401cb0ef41Sopenharmony_ci } 411cb0ef41Sopenharmony_ci ); 421cb0ef41Sopenharmony_ci} 43