Files
node/test/common/heap.js
T
Joyee Cheung 2d72a9543c src: implement the new EmbedderGraph::AddEdge()
The signature of EmbedderGraph::AddEdge() has been changed so
the current implementation of JSGraph no longer compiles.
This patch updates the implementation accordingly.

PR-URL: https://github.com/nodejs/node/pull/22106
Refs: https://github.com/v8/v8/commit/6ee834532d6f924f6057584085fa79b4777c396a
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
2018-08-19 00:52:42 +08:00

85 lines
2.6 KiB
JavaScript

/* eslint-disable node-core/required-modules */
'use strict';
const assert = require('assert');
const util = require('util');
let internalTestHeap;
try {
internalTestHeap = require('internal/test/heap');
} catch (e) {
console.log('using `test/common/heap.js` requires `--expose-internals`');
throw e;
}
const { createJSHeapDump, buildEmbedderGraph } = internalTestHeap;
class State {
constructor() {
this.snapshot = createJSHeapDump();
this.embedderGraph = buildEmbedderGraph();
}
validateSnapshotNodes(name, expected, { loose = false } = {}) {
const snapshot = this.snapshot.filter(
(node) => node.name === 'Node / ' + name && node.type !== 'string');
if (loose)
assert(snapshot.length >= expected.length);
else
assert.strictEqual(snapshot.length, expected.length);
for (const expectedNode of expected) {
if (expectedNode.children) {
for (const expectedChild of expectedNode.children) {
const check = typeof expectedChild === 'function' ?
expectedChild :
(node) => [expectedChild.name, 'Node / ' + expectedChild.name]
.includes(node.name);
assert(snapshot.some((node) => {
return node.outgoingEdges.map((edge) => edge.toNode).some(check);
}), `expected to find child ${util.inspect(expectedChild)} ` +
`in ${util.inspect(snapshot)}`);
}
}
}
const graph = this.embedderGraph.filter((node) => node.name === name);
if (loose)
assert(graph.length >= expected.length);
else
assert.strictEqual(graph.length, expected.length);
for (const expectedNode of expected) {
if (expectedNode.children) {
for (const expectedChild of expectedNode.children) {
const check = (edge) => {
// TODO(joyeecheung): check the edge names
const node = edge.to;
if (typeof expectedChild === 'function') {
return expectedChild(node);
}
return node.name === expectedChild.name ||
(node.value &&
node.value.constructor &&
node.value.constructor.name === expectedChild.name);
};
assert(graph.some((node) => node.edges.some(check)),
`expected to find child ${util.inspect(expectedChild)} ` +
`in ${util.inspect(snapshot)}`);
}
}
}
}
}
function recordState() {
return new State();
}
function validateSnapshotNodes(...args) {
return recordState().validateSnapshotNodes(...args);
}
module.exports = {
recordState,
validateSnapshotNodes
};