Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Unified Diff: gin/per_context_data.cc

Issue 62333018: Implement Asynchronous Module Definition API for Mojo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moar testing Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: gin/per_context_data.cc
diff --git a/gin/per_context_data.cc b/gin/per_context_data.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8f6261ac4a395868c46fe5f53740b243a18e758a
--- /dev/null
+++ b/gin/per_context_data.cc
@@ -0,0 +1,49 @@
+// Copyright 2013 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 "gin/per_context_data.h"
+
+#include <assert.h>
+#include "gin/wrapper_info.h"
+
+namespace gin {
+
+ContextSupplement::ContextSupplement() {
+}
+
+ContextSupplement::~ContextSupplement() {
+}
+
+PerContextData::PerContextData(v8::Handle<v8::Context> context) {
+ context->SetAlignedPointerInEmbedderData(kEncodedValueIndex, this);
+}
+
+PerContextData::~PerContextData() {
+ assert(supplements_.empty());
+}
+
+void PerContextData::Detach(v8::Handle<v8::Context> context) {
+ assert(From(context) == this);
+ context->SetAlignedPointerInEmbedderData(kEncodedValueIndex, NULL);
+
+ SuplementVector supplements;
+ supplements.swap(supplements_);
+
+ for (SuplementVector::iterator it = supplements.begin();
+ it != supplements.end(); ++it) {
+ (*it)->Detach(context);
+ delete *it;
+ }
+}
+
+PerContextData* PerContextData::From(v8::Handle<v8::Context> context) {
+ return static_cast<PerContextData*>(
+ context->GetAlignedPointerFromEmbedderData(kEncodedValueIndex));
+}
+
+void PerContextData::AddSupplement(ContextSupplement* supplement) {
+ supplements_.push_back(supplement);
+}
+
+} // namespace gin

Powered by Google App Engine
This is Rietveld 408576698