2015-10-12 11:53:31 +08:00
|
|
|
'use strict';
|
|
|
|
|
2016-04-05 00:09:52 +08:00
|
|
|
const common = require('../../common');
|
2016-05-12 03:34:52 +08:00
|
|
|
const skipMessage = 'intensive toString tests due to memory confinements';
|
2017-07-01 07:29:09 +08:00
|
|
|
if (!common.enoughTestMem)
|
2016-05-12 03:34:52 +08:00
|
|
|
common.skip(skipMessage);
|
2017-07-01 07:29:09 +08:00
|
|
|
|
|
|
|
const binding = require(`./build/${common.buildType}/binding`);
|
|
|
|
const assert = require('assert');
|
2015-11-07 01:51:48 +08:00
|
|
|
|
2015-10-12 11:53:31 +08:00
|
|
|
// v8 fails silently if string length > v8::String::kMaxLength
|
|
|
|
// v8::String::kMaxLength defined in v8.h
|
|
|
|
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
|
|
|
|
|
2017-01-08 21:19:00 +08:00
|
|
|
let buf;
|
2015-10-12 11:53:31 +08:00
|
|
|
try {
|
2017-01-08 21:19:00 +08:00
|
|
|
buf = Buffer.allocUnsafe(kStringMaxLength + 1);
|
2016-01-14 04:42:45 +08:00
|
|
|
} catch (e) {
|
2015-11-07 01:51:48 +08:00
|
|
|
// If the exception is not due to memory confinement then rethrow it.
|
2016-01-21 01:58:07 +08:00
|
|
|
if (e.message !== 'Array buffer allocation failed') throw (e);
|
2016-05-12 03:34:52 +08:00
|
|
|
common.skip(skipMessage);
|
2015-10-12 11:53:31 +08:00
|
|
|
}
|
|
|
|
|
2016-04-05 00:09:52 +08:00
|
|
|
// Ensure we have enough memory available for future allocations to succeed.
|
2017-07-01 07:29:09 +08:00
|
|
|
if (!binding.ensureAllocation(2 * kStringMaxLength))
|
2016-05-12 03:34:52 +08:00
|
|
|
common.skip(skipMessage);
|
2016-04-05 00:09:52 +08:00
|
|
|
|
2015-10-12 11:53:31 +08:00
|
|
|
assert.throws(function() {
|
|
|
|
buf.toString('hex');
|
2015-11-10 07:10:49 +08:00
|
|
|
}, /"toString\(\)" failed/);
|