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: 6ee834532d
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
54c87f37f4
commit
2d72a9543c
@ -76,8 +76,8 @@ class JSGraph : public EmbedderGraph {
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddEdge(Node* from, Node* to) override {
|
void AddEdge(Node* from, Node* to, const char* name = nullptr) override {
|
||||||
edges_[from].insert(to);
|
edges_[from].insert(std::make_pair(name, to));
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeLocal<Array> CreateObject() const {
|
MaybeLocal<Array> CreateObject() const {
|
||||||
@ -92,6 +92,7 @@ class JSGraph : public EmbedderGraph {
|
|||||||
Local<String> size_string = FIXED_ONE_BYTE_STRING(isolate_, "size");
|
Local<String> size_string = FIXED_ONE_BYTE_STRING(isolate_, "size");
|
||||||
Local<String> value_string = FIXED_ONE_BYTE_STRING(isolate_, "value");
|
Local<String> value_string = FIXED_ONE_BYTE_STRING(isolate_, "value");
|
||||||
Local<String> wraps_string = FIXED_ONE_BYTE_STRING(isolate_, "wraps");
|
Local<String> wraps_string = FIXED_ONE_BYTE_STRING(isolate_, "wraps");
|
||||||
|
Local<String> to_string = FIXED_ONE_BYTE_STRING(isolate_, "to");
|
||||||
|
|
||||||
for (const std::unique_ptr<Node>& n : nodes_)
|
for (const std::unique_ptr<Node>& n : nodes_)
|
||||||
info_objects[n.get()] = Object::New(isolate_);
|
info_objects[n.get()] = Object::New(isolate_);
|
||||||
@ -141,10 +142,23 @@ class JSGraph : public EmbedderGraph {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (Node* target : edge_info.second) {
|
size_t j = 0;
|
||||||
if (edges.As<Array>()->Set(context,
|
for (const auto& edge : edge_info.second) {
|
||||||
i++,
|
Local<Object> to_object = info_objects[edge.second];
|
||||||
info_objects[target]).IsNothing()) {
|
Local<Object> edge_info = Object::New(isolate_);
|
||||||
|
Local<Value> edge_name_value;
|
||||||
|
const char* edge_name = edge.first;
|
||||||
|
if (edge_name != nullptr &&
|
||||||
|
!String::NewFromUtf8(
|
||||||
|
isolate_, edge_name, v8::NewStringType::kNormal)
|
||||||
|
.ToLocal(&edge_name_value)) {
|
||||||
|
return MaybeLocal<Array>();
|
||||||
|
} else {
|
||||||
|
edge_name_value = Number::New(isolate_, j++);
|
||||||
|
}
|
||||||
|
if (edge_info->Set(context, name_string, edge_name_value).IsNothing() ||
|
||||||
|
edge_info->Set(context, to_string, to_object).IsNothing() ||
|
||||||
|
edges.As<Array>()->Set(context, i++, edge_info).IsNothing()) {
|
||||||
return MaybeLocal<Array>();
|
return MaybeLocal<Array>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -158,7 +172,7 @@ class JSGraph : public EmbedderGraph {
|
|||||||
std::unordered_set<std::unique_ptr<Node>> nodes_;
|
std::unordered_set<std::unique_ptr<Node>> nodes_;
|
||||||
std::unordered_set<JSGraphJSNode*, JSGraphJSNode::Hash, JSGraphJSNode::Equal>
|
std::unordered_set<JSGraphJSNode*, JSGraphJSNode::Hash, JSGraphJSNode::Equal>
|
||||||
engine_nodes_;
|
engine_nodes_;
|
||||||
std::unordered_map<Node*, std::unordered_set<Node*>> edges_;
|
std::unordered_map<Node*, std::set<std::pair<const char*, Node*>>> edges_;
|
||||||
};
|
};
|
||||||
|
|
||||||
void BuildEmbedderGraph(const FunctionCallbackInfo<Value>& args) {
|
void BuildEmbedderGraph(const FunctionCallbackInfo<Value>& args) {
|
||||||
|
@ -47,10 +47,14 @@ class State {
|
|||||||
else
|
else
|
||||||
assert.strictEqual(graph.length, expected.length);
|
assert.strictEqual(graph.length, expected.length);
|
||||||
for (const expectedNode of expected) {
|
for (const expectedNode of expected) {
|
||||||
if (expectedNode.edges) {
|
if (expectedNode.children) {
|
||||||
for (const expectedChild of expectedNode.children) {
|
for (const expectedChild of expectedNode.children) {
|
||||||
const check = typeof expectedChild === 'function' ?
|
const check = (edge) => {
|
||||||
expectedChild : (node) => {
|
// TODO(joyeecheung): check the edge names
|
||||||
|
const node = edge.to;
|
||||||
|
if (typeof expectedChild === 'function') {
|
||||||
|
return expectedChild(node);
|
||||||
|
}
|
||||||
return node.name === expectedChild.name ||
|
return node.name === expectedChild.name ||
|
||||||
(node.value &&
|
(node.value &&
|
||||||
node.value.constructor &&
|
node.value.constructor &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user