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.
38 lines
1.0 KiB
38 lines
1.0 KiB
9 years ago
|
'use strict';
|
||
9 years ago
|
// Flags: --expose-gc
|
||
9 years ago
|
|
||
9 years ago
|
const common = require('../common');
|
||
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;
|
||
|
}
|
||
|
assert(typeof gc === 'function', 'Run this test with --expose-gc');
|
||
|
|
||
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 = new Buffer(kStringMaxLength + 1);
|
||
|
// Try to allocate memory first then force gc so future allocations succeed.
|
||
|
new Buffer(2 * kStringMaxLength);
|
||
|
gc();
|
||
9 years ago
|
} catch(e) {
|
||
9 years ago
|
// If the exception is not due to memory confinement then rethrow it.
|
||
|
if (e.message !== 'Invalid array buffer length') throw (e);
|
||
|
console.log(skipMessage);
|
||
9 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
assert.throws(function() {
|
||
|
buf.toString();
|
||
9 years ago
|
}, /"toString\(\)" failed|Invalid array buffer length/);
|
||
9 years ago
|
|
||
|
assert.throws(function() {
|
||
|
buf.toString('utf8');
|
||
9 years ago
|
}, /"toString\(\)" failed/);
|