2015-10-08 13:56:34 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
2016-04-05 22:22:42 -07:00
|
|
|
const common = require('../../common');
|
2017-07-01 02:29:09 +03:00
|
|
|
const skipMessage = 'intensive toString tests due to memory confinements';
|
|
|
|
|
if (!common.enoughTestMem)
|
|
|
|
|
common.skip(skipMessage);
|
|
|
|
|
|
2016-09-28 20:14:23 +02:00
|
|
|
const binding = require(`./build/${common.buildType}/binding`);
|
2015-10-08 13:56:34 -07:00
|
|
|
const assert = require('assert');
|
|
|
|
|
|
|
|
|
|
// v8 fails silently if string length > v8::String::kMaxLength
|
|
|
|
|
// v8::String::kMaxLength defined in v8.h
|
2019-01-01 20:51:06 -08:00
|
|
|
const kStringMaxLength = require('buffer').constants.MAX_STRING_LENGTH;
|
2015-10-08 13:56:34 -07:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
let buf;
|
2015-10-08 13:56:34 -07:00
|
|
|
try {
|
2017-01-08 13:19:00 +00:00
|
|
|
buf = Buffer.allocUnsafe(kStringMaxLength);
|
2016-01-13 21:42:45 +01:00
|
|
|
} catch (e) {
|
2015-11-06 12:51:48 -05:00
|
|
|
// If the exception is not due to memory confinement then rethrow it.
|
2016-01-20 09:58:07 -08:00
|
|
|
if (e.message !== 'Array buffer allocation failed') throw (e);
|
2016-05-11 15:34:52 -04:00
|
|
|
common.skip(skipMessage);
|
2015-10-08 13:56:34 -07:00
|
|
|
}
|
|
|
|
|
|
2016-04-05 22:22:42 -07:00
|
|
|
// Ensure we have enough memory available for future allocations to succeed.
|
2017-07-01 02:29:09 +03:00
|
|
|
if (!binding.ensureAllocation(2 * kStringMaxLength))
|
2016-05-11 15:34:52 -04:00
|
|
|
common.skip(skipMessage);
|
2016-04-05 22:22:42 -07:00
|
|
|
|
2016-06-02 10:55:36 -06:00
|
|
|
const maxString = buf.toString('latin1');
|
2016-11-29 12:33:28 -06:00
|
|
|
assert.strictEqual(maxString.length, kStringMaxLength);
|