@@ -76,8 +76,8 @@ class JSGraph : public EmbedderGraph {
76
76
return n;
77
77
}
78
78
79
- void AddEdge (Node* from, Node* to) override {
80
- edges_[from].insert (to );
79
+ void AddEdge (Node* from, Node* to, const char * name = nullptr ) override {
80
+ edges_[from].insert (std::make_pair (name, to) );
81
81
}
82
82
83
83
MaybeLocal<Array> CreateObject () const {
@@ -92,6 +92,7 @@ class JSGraph : public EmbedderGraph {
92
92
Local<String> size_string = FIXED_ONE_BYTE_STRING (isolate_, " size" );
93
93
Local<String> value_string = FIXED_ONE_BYTE_STRING (isolate_, " value" );
94
94
Local<String> wraps_string = FIXED_ONE_BYTE_STRING (isolate_, " wraps" );
95
+ Local<String> to_string = FIXED_ONE_BYTE_STRING (isolate_, " to" );
95
96
96
97
for (const std::unique_ptr<Node>& n : nodes_)
97
98
info_objects[n.get ()] = Object::New (isolate_);
@@ -141,10 +142,23 @@ class JSGraph : public EmbedderGraph {
141
142
}
142
143
143
144
size_t i = 0 ;
144
- for (Node* target : edge_info.second ) {
145
- if (edges.As <Array>()->Set (context,
146
- i++,
147
- info_objects[target]).IsNothing ()) {
145
+ size_t j = 0 ;
146
+ for (const auto & edge : edge_info.second ) {
147
+ Local<Object> to_object = info_objects[edge.second ];
148
+ Local<Object> edge_info = Object::New (isolate_);
149
+ Local<Value> edge_name_value;
150
+ const char * edge_name = edge.first ;
151
+ if (edge_name != nullptr &&
152
+ !String::NewFromUtf8 (
153
+ isolate_, edge_name, v8::NewStringType::kNormal )
154
+ .ToLocal (&edge_name_value)) {
155
+ return MaybeLocal<Array>();
156
+ } else {
157
+ edge_name_value = Number::New (isolate_, j++);
158
+ }
159
+ if (edge_info->Set (context, name_string, edge_name_value).IsNothing () ||
160
+ edge_info->Set (context, to_string, to_object).IsNothing () ||
161
+ edges.As <Array>()->Set (context, i++, edge_info).IsNothing ()) {
148
162
return MaybeLocal<Array>();
149
163
}
150
164
}
@@ -158,7 +172,7 @@ class JSGraph : public EmbedderGraph {
158
172
std::unordered_set<std::unique_ptr<Node>> nodes_;
159
173
std::unordered_set<JSGraphJSNode*, JSGraphJSNode::Hash, JSGraphJSNode::Equal>
160
174
engine_nodes_;
161
- std::unordered_map<Node*, std::unordered_set< Node*>> edges_;
175
+ std::unordered_map<Node*, std::set<std::pair< const char *, Node*> >> edges_;
162
176
};
163
177
164
178
void BuildEmbedderGraph (const FunctionCallbackInfo<Value>& args) {
0 commit comments