0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-at-max.js
Trevor Norris 54cc7212df buffer: introduce latin1 encoding term
When node began using the OneByte API (f150d56) it also switched to
officially supporting ISO-8859-1. Though at the time no new encoding
string was introduced.

Introduce the new encoding string 'latin1' to be more explicit. The
previous 'binary' and documented as an alias to 'latin1'.  While many
tests have switched to use 'latin1', there are still plenty that do both
'binary' and 'latin1' checks side-by-side to ensure there is no
regression.

PR-URL: https://github.com/nodejs/node/pull/7111
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-06-07 13:51:14 -06:00

34 lines
975 B
JavaScript

'use strict';
const common = require('../../common');
const binding = require('./build/Release/binding');
const assert = require('assert');
// v8 fails silently if string length > v8::String::kMaxLength
// v8::String::kMaxLength defined in v8.h
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
const skipMessage = 'intensive toString tests due to memory confinements';
if (!common.enoughTestMem) {
common.skip(skipMessage);
return;
}
try {
var buf = Buffer.allocUnsafe(kStringMaxLength);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);
common.skip(skipMessage);
return;
}
// Ensure we have enough memory available for future allocations to succeed.
if (!binding.ensureAllocation(2 * kStringMaxLength)) {
common.skip(skipMessage);
return;
}
const maxString = buf.toString('latin1');
assert.equal(maxString.length, kStringMaxLength);