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

Unified Diff: mojo/bindings/js/handle.h

Issue 214183003: Change mojo JS bindings to expose a handle object, which is Closed when garbage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rm.extra.gc Created 6 years, 9 months 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: mojo/bindings/js/handle.h
diff --git a/mojo/bindings/js/handle.h b/mojo/bindings/js/handle.h
index 3cd4cf572f9585475dc30e64937216b34a00330a..ad03f87501a5a8a7bab1e6fd3ba219fbf1b3b021 100644
--- a/mojo/bindings/js/handle.h
+++ b/mojo/bindings/js/handle.h
@@ -6,10 +6,37 @@
#define MOJO_BINDINGS_JS_HANDLE_H_
#include "gin/converter.h"
+#include "gin/handle.h"
+#include "gin/wrappable.h"
#include "mojo/public/cpp/system/core.h"
namespace gin {
+// Wrapper for mojo Handles exposed to JavaScript. This ensures the Handle
+// is Closed when its JS object is garbage collected.
+class HandleWrapper : public gin::Wrappable<HandleWrapper> {
+ public:
+ static gin::WrapperInfo kWrapperInfo;
+
+ static gin::Handle<HandleWrapper> Create(v8::Isolate* isolate,
+ MojoHandle handle) {
+ return gin::CreateHandle(isolate, new HandleWrapper(handle));
+ }
+
+ mojo::Handle get() const { return handle_.get(); }
+ mojo::Handle release() { return handle_.release(); }
+ void Close() { handle_.reset(); }
+
+ protected:
+ HandleWrapper(MojoHandle handle);
+ virtual ~HandleWrapper();
+ mojo::ScopedHandle handle_;
+};
+
+// Note: It's important to use this converter rather than the one for
+// MojoHandle, since that will do a simple int32 conversion. It's unfortunate
+// there's no way to prevent against accidental use.
+// TODO(mpcomplete): define converters for all Handle subtypes.
template<>
struct Converter<mojo::Handle> {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,

Powered by Google App Engine
This is Rietveld 408576698