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