aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-08-04 00:09:16 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2018-08-19 00:52:42 +0800
commit2d72a9543c15be57c3b4a383f0c80d09245eb9ba (patch)
tree42b02c6161e4ca41832206de2815755e441ed6d7 /src
parent54c87f37f44742588d0f8e0a778444e0890d7842 (diff)
downloadandroid-node-v8-2d72a9543c15be57c3b4a383f0c80d09245eb9ba.tar.gz
android-node-v8-2d72a9543c15be57c3b4a383f0c80d09245eb9ba.tar.bz2
android-node-v8-2d72a9543c15be57c3b4a383f0c80d09245eb9ba.zip
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>
Diffstat (limited to 'src')
-rw-r--r--src/heap_utils.cc28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/heap_utils.cc b/src/heap_utils.cc
index 2d339c580f..668dff3451 100644
--- a/src/heap_utils.cc
+++ b/src/heap_utils.cc
@@ -76,8 +76,8 @@ class JSGraph : public EmbedderGraph {
return n;
}
- void AddEdge(Node* from, Node* to) override {
- edges_[from].insert(to);
+ void AddEdge(Node* from, Node* to, const char* name = nullptr) override {
+ edges_[from].insert(std::make_pair(name, to));
}
MaybeLocal<Array> CreateObject() const {
@@ -92,6 +92,7 @@ class JSGraph : public EmbedderGraph {
Local<String> size_string = FIXED_ONE_BYTE_STRING(isolate_, "size");
Local<String> value_string = FIXED_ONE_BYTE_STRING(isolate_, "value");
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_)
info_objects[n.get()] = Object::New(isolate_);
@@ -141,10 +142,23 @@ class JSGraph : public EmbedderGraph {
}
size_t i = 0;
- for (Node* target : edge_info.second) {
- if (edges.As<Array>()->Set(context,
- i++,
- info_objects[target]).IsNothing()) {
+ size_t j = 0;
+ for (const auto& edge : edge_info.second) {
+ Local<Object> to_object = info_objects[edge.second];
+ 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>();
}
}
@@ -158,7 +172,7 @@ class JSGraph : public EmbedderGraph {
std::unordered_set<std::unique_ptr<Node>> nodes_;
std::unordered_set<JSGraphJSNode*, JSGraphJSNode::Hash, JSGraphJSNode::Equal>
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) {