@@ -77,7 +77,14 @@ class JSGraph : public EmbedderGraph {
77
77
}
78
78
79
79
void AddEdge (Node* from, Node* to) override {
80
- edges_[from].insert (to);
80
+ edges_[from].insert (std::make_pair (nullptr , to));
81
+ }
82
+
83
+ // For ABI compatibility, we did not backport the virtual function
84
+ // AddEdge() with the name as last argument back to v10.x.
85
+ // This is only here to reduce the amount of churn.
86
+ void AddEdge (Node* from, Node* to, const char * name = nullptr ) {
87
+ edges_[from].insert (std::make_pair (name, to));
81
88
}
82
89
83
90
MaybeLocal<Array> CreateObject () const {
@@ -92,6 +99,7 @@ class JSGraph : public EmbedderGraph {
92
99
Local<String> size_string = FIXED_ONE_BYTE_STRING (isolate_, " size" );
93
100
Local<String> value_string = FIXED_ONE_BYTE_STRING (isolate_, " value" );
94
101
Local<String> wraps_string = FIXED_ONE_BYTE_STRING (isolate_, " wraps" );
102
+ Local<String> to_string = FIXED_ONE_BYTE_STRING (isolate_, " to" );
95
103
96
104
for (const std::unique_ptr<Node>& n : nodes_)
97
105
info_objects[n.get ()] = Object::New (isolate_);
@@ -141,10 +149,23 @@ class JSGraph : public EmbedderGraph {
141
149
}
142
150
143
151
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 ()) {
152
+ size_t j = 0 ;
153
+ for (const auto & edge : edge_info.second ) {
154
+ Local<Object> to_object = info_objects[edge.second ];
155
+ Local<Object> edge_info = Object::New (isolate_);
156
+ Local<Value> edge_name_value;
157
+ const char * edge_name = edge.first ;
158
+ if (edge_name != nullptr &&
159
+ !String::NewFromUtf8 (
160
+ isolate_, edge_name, v8::NewStringType::kNormal )
161
+ .ToLocal (&edge_name_value)) {
162
+ return MaybeLocal<Array>();
163
+ } else {
164
+ edge_name_value = Number::New (isolate_, j++);
165
+ }
166
+ if (edge_info->Set (context, name_string, edge_name_value).IsNothing () ||
167
+ edge_info->Set (context, to_string, to_object).IsNothing () ||
168
+ edges.As <Array>()->Set (context, i++, edge_info).IsNothing ()) {
148
169
return MaybeLocal<Array>();
149
170
}
150
171
}
@@ -158,7 +179,7 @@ class JSGraph : public EmbedderGraph {
158
179
std::unordered_set<std::unique_ptr<Node>> nodes_;
159
180
std::unordered_set<JSGraphJSNode*, JSGraphJSNode::Hash, JSGraphJSNode::Equal>
160
181
engine_nodes_;
161
- std::unordered_map<Node*, std::unordered_set< Node*>> edges_;
182
+ std::unordered_map<Node*, std::set<std::pair< const char *, Node*> >> edges_;
162
183
};
163
184
164
185
void BuildEmbedderGraph (const FunctionCallbackInfo<Value>& args) {
0 commit comments