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

Unified Diff: gin/wrappable.h

Issue 79203004: [Gin] Add a mechanism for wrapping C++ object (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Disallow copy and assign 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
« no previous file with comments | « gin/gin.gyp ('k') | gin/wrappable.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gin/wrappable.h
diff --git a/gin/wrappable.h b/gin/wrappable.h
new file mode 100644
index 0000000000000000000000000000000000000000..66c23891d73e1f14568e892e81548cc34d418322
--- /dev/null
+++ b/gin/wrappable.h
@@ -0,0 +1,60 @@
+// 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.
+
+#ifndef GIN_WRAPPABLE_H_
+#define GIN_WRAPPABLE_H_
+
+#include "base/memory/ref_counted.h"
+#include "gin/converter.h"
+#include "gin/public/wrapper_info.h"
+
+namespace gin {
+
+class Wrappable : public base::RefCounted<Wrappable> {
+ public:
+ virtual WrapperInfo* GetWrapperInfo() = 0;
+
+ protected:
+ Wrappable();
+ virtual ~Wrappable();
+
+ private:
+ friend class base::RefCounted<Wrappable>;
+ friend struct Converter<Wrappable*>;
+
+ static void WeakCallback(
+ const v8::WeakCallbackData<v8::Object, Wrappable>& data);
+ v8::Handle<v8::Object> CreateWrapper(v8::Isolate* isolate);
+
+ v8::Persistent<v8::Object> wrapper_; // Weak
+
+ DISALLOW_COPY_AND_ASSIGN(Wrappable);
+};
+
+template<>
+struct Converter<Wrappable*> {
+ static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
+ Wrappable* val);
+ static bool FromV8(v8::Handle<v8::Value> val,
+ Wrappable** out);
+};
+
+template<typename T>
+struct WrappableConverter {
+ static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, T* val) {
+ return Converter<Wrappable*>::ToV8(isolate, val);
+ }
+ static bool FromV8(v8::Handle<v8::Value> val, T** out) {
+ Wrappable* wrappable = 0;
+ if (!Converter<Wrappable*>::FromV8(val, &wrappable)
+ || wrappable->GetWrapperInfo() != &T::kWrapperInfo)
+ return false;
+ *out = static_cast<T*>(wrappable);
+ return true;
+ }
+};
+
+} // namespace gin
+
+#endif // GIN_WRAPPABLE_H_
« no previous file with comments | « gin/gin.gyp ('k') | gin/wrappable.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698