• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../../common');
4const skipMessage = 'intensive toString tests due to memory confinements';
5if (!common.enoughTestMem)
6  common.skip(skipMessage);
7
8const binding = require(`./build/${common.buildType}/binding`);
9const assert = require('assert');
10
11// v8 fails silently if string length > v8::String::kMaxLength
12// v8::String::kMaxLength defined in v8.h
13const kStringMaxLength = require('buffer').constants.MAX_STRING_LENGTH;
14
15let buf;
16try {
17  buf = Buffer.allocUnsafe(kStringMaxLength);
18} catch (e) {
19  // If the exception is not due to memory confinement then rethrow it.
20  if (e.message !== 'Array buffer allocation failed') throw (e);
21  common.skip(skipMessage);
22}
23
24// Ensure we have enough memory available for future allocations to succeed.
25if (!binding.ensureAllocation(2 * kStringMaxLength))
26  common.skip(skipMessage);
27
28const maxString = buf.toString('latin1');
29assert.strictEqual(maxString.length, kStringMaxLength);
30