@@ -77,7 +77,14 @@ class JSGraph : public EmbedderGraph {
7777 }
7878
7979 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));
8188 }
8289
8390 MaybeLocal<Array> CreateObject () const {
@@ -92,6 +99,7 @@ class JSGraph : public EmbedderGraph {
9299 Local<String> size_string = FIXED_ONE_BYTE_STRING (isolate_, " size" );
93100 Local<String> value_string = FIXED_ONE_BYTE_STRING (isolate_, " value" );
94101 Local<String> wraps_string = FIXED_ONE_BYTE_STRING (isolate_, " wraps" );
102+ Local<String> to_string = FIXED_ONE_BYTE_STRING (isolate_, " to" );
95103
96104 for (const std::unique_ptr<Node>& n : nodes_)
97105 info_objects[n.get ()] = Object::New (isolate_);
@@ -141,10 +149,23 @@ class JSGraph : public EmbedderGraph {
141149 }
142150
143151 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 ()) {
148169 return MaybeLocal<Array>();
149170 }
150171 }
@@ -158,7 +179,7 @@ class JSGraph : public EmbedderGraph {
158179 std::unordered_set<std::unique_ptr<Node>> nodes_;
159180 std::unordered_set<JSGraphJSNode*, JSGraphJSNode::Hash, JSGraphJSNode::Equal>
160181 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_;
162183};
163184
164185void BuildEmbedderGraph (const FunctionCallbackInfo<Value>& args) {
0 commit comments