11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_cirequire('../common'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst { SlowBuffer } = require('buffer'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst msg = { 81cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_VALUE', 91cb0ef41Sopenharmony_ci name: 'RangeError', 101cb0ef41Sopenharmony_ci message: /^The argument 'size' is invalid\. Received [^"]*$/ 111cb0ef41Sopenharmony_ci}; 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci// Test that negative Buffer length inputs throw errors. 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciassert.throws(() => Buffer(-Buffer.poolSize), msg); 161cb0ef41Sopenharmony_ciassert.throws(() => Buffer(-100), msg); 171cb0ef41Sopenharmony_ciassert.throws(() => Buffer(-1), msg); 181cb0ef41Sopenharmony_ciassert.throws(() => Buffer(NaN), msg); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ciassert.throws(() => Buffer.alloc(-Buffer.poolSize), msg); 211cb0ef41Sopenharmony_ciassert.throws(() => Buffer.alloc(-100), msg); 221cb0ef41Sopenharmony_ciassert.throws(() => Buffer.alloc(-1), msg); 231cb0ef41Sopenharmony_ciassert.throws(() => Buffer.alloc(NaN), msg); 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ciassert.throws(() => Buffer.allocUnsafe(-Buffer.poolSize), msg); 261cb0ef41Sopenharmony_ciassert.throws(() => Buffer.allocUnsafe(-100), msg); 271cb0ef41Sopenharmony_ciassert.throws(() => Buffer.allocUnsafe(-1), msg); 281cb0ef41Sopenharmony_ciassert.throws(() => Buffer.allocUnsafe(NaN), msg); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ciassert.throws(() => Buffer.allocUnsafeSlow(-Buffer.poolSize), msg); 311cb0ef41Sopenharmony_ciassert.throws(() => Buffer.allocUnsafeSlow(-100), msg); 321cb0ef41Sopenharmony_ciassert.throws(() => Buffer.allocUnsafeSlow(-1), msg); 331cb0ef41Sopenharmony_ciassert.throws(() => Buffer.allocUnsafeSlow(NaN), msg); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ciassert.throws(() => SlowBuffer(-Buffer.poolSize), msg); 361cb0ef41Sopenharmony_ciassert.throws(() => SlowBuffer(-100), msg); 371cb0ef41Sopenharmony_ciassert.throws(() => SlowBuffer(-1), msg); 381cb0ef41Sopenharmony_ciassert.throws(() => SlowBuffer(NaN), msg); 39