mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
42 lines
1.4 KiB
JavaScript
42 lines
1.4 KiB
JavaScript
|
// Copyright (c) 2014, StrongLoop Inc.
|
||
|
//
|
||
|
// Permission to use, copy, modify, and/or distribute this software for any
|
||
|
// purpose with or without fee is hereby granted, provided that the above
|
||
|
// copyright notice and this permission notice appear in all copies.
|
||
|
//
|
||
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||
|
|
||
|
'use strict';
|
||
|
|
||
|
var EventEmitter = require('events');
|
||
|
var v8binding = process.binding('v8');
|
||
|
|
||
|
var v8 = module.exports = new EventEmitter();
|
||
|
v8.getHeapStatistics = v8binding.getHeapStatistics;
|
||
|
v8.setFlagsFromString = v8binding.setFlagsFromString;
|
||
|
|
||
|
|
||
|
function emitGC(before, after) {
|
||
|
v8.emit('gc', before, after);
|
||
|
}
|
||
|
|
||
|
|
||
|
v8.on('newListener', function(name) {
|
||
|
if (name === 'gc' && EventEmitter.listenerCount(this, name) === 0) {
|
||
|
v8binding.startGarbageCollectionTracking(emitGC);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
|
||
|
v8.on('removeListener', function(name) {
|
||
|
if (name === 'gc' && EventEmitter.listenerCount(this, name) === 0) {
|
||
|
v8binding.stopGarbageCollectionTracking();
|
||
|
}
|
||
|
});
|