Index: tonic/dart_gc_context.cc |
diff --git a/tonic/dart_gc_context.cc b/tonic/dart_gc_context.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2c53d0cbcbca86d9c1bf47224d1dc8503a724b77 |
--- /dev/null |
+++ b/tonic/dart_gc_context.cc |
@@ -0,0 +1,30 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include <utility> |
+ |
+#include "tonic/dart_gc_context.h" |
+ |
+namespace blink { |
+ |
+DartGCContext::DartGCContext() : builder_(Dart_NewWeakReferenceSetBuilder()) { |
+} |
+ |
+DartGCContext::~DartGCContext() { |
+} |
+ |
+Dart_WeakReferenceSet DartGCContext::AddToSetForRoot( |
+ const void* root, |
+ Dart_WeakPersistentHandle handle) { |
+ const auto& result = references_.insert(std::make_pair(root, nullptr)); |
+ if (!result.second) { |
+ // Already present. |
+ Dart_AppendToWeakReferenceSet(result.first->second, handle, handle); |
+ return result.first->second; |
+ } |
+ result.first->second = Dart_NewWeakReferenceSet(builder_, handle, handle); |
+ return result.first->second; |
+} |
+ |
+} // namespace blink |