mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
9 years ago
|
'use strict';
|
||
|
|
||
9 years ago
|
const common = require('../../common');
|
||
|
const binding = require('./build/Release/binding');
|
||
9 years ago
|
const assert = require('assert');
|
||
|
|
||
9 years ago
|
const skipMessage =
|
||
|
'1..0 # Skipped: intensive toString tests due to memory confinements';
|
||
|
if (!common.enoughTestMem) {
|
||
|
console.log(skipMessage);
|
||
|
return;
|
||
|
}
|
||
|
|
||
9 years ago
|
// v8 fails silently if string length > v8::String::kMaxLength
|
||
|
// v8::String::kMaxLength defined in v8.h
|
||
|
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
|
||
|
|
||
|
try {
|
||
9 years ago
|
var buf = Buffer.allocUnsafe(kStringMaxLength + 1);
|
||
9 years ago
|
} catch (e) {
|
||
9 years ago
|
// If the exception is not due to memory confinement then rethrow it.
|
||
9 years ago
|
if (e.message !== 'Array buffer allocation failed') throw (e);
|
||
9 years ago
|
console.log(skipMessage);
|
||
9 years ago
|
return;
|
||
|
}
|
||
|
|
||
9 years ago
|
// Ensure we have enough memory available for future allocations to succeed.
|
||
|
if (!binding.ensureAllocation(2 * kStringMaxLength)) {
|
||
|
console.log(skipMessage);
|
||
|
return;
|
||
|
}
|
||
|
|
||
9 years ago
|
assert.throws(function() {
|
||
|
buf.toString();
|
||
9 years ago
|
}, /"toString\(\)" failed|Array buffer allocation failed/);
|
||
9 years ago
|
|
||
|
assert.throws(function() {
|
||
|
buf.toString('utf8');
|
||
9 years ago
|
}, /"toString\(\)" failed/);
|