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

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

Issue 278093003: Break dependency on core from generated mojom.js files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Specialize Converter<gin::Handle<gin::HandleWrapper> > Created 6 years, 7 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
« no previous file with comments | « mojo/bindings/js/core.cc ('k') | mojo/bindings/js/handle.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/bindings/js/handle.h
diff --git a/mojo/bindings/js/handle.h b/mojo/bindings/js/handle.h
index ad03f87501a5a8a7bab1e6fd3ba219fbf1b3b021..35202b07ea674240bdc4b81c6702f718f8b9d696 100644
--- a/mojo/bindings/js/handle.h
+++ b/mojo/bindings/js/handle.h
@@ -45,6 +45,31 @@ struct Converter<mojo::Handle> {
mojo::Handle* out);
};
+// We need to specialize the normal gin::Handle converter in order to handle
+// converting |null| to a wrapper for an empty mojo::Handle.
+template<>
+struct Converter<gin::Handle<gin::HandleWrapper> > {
+ static v8::Handle<v8::Value> ToV8(
+ v8::Isolate* isolate, const gin::Handle<gin::HandleWrapper>& val) {
+ return val.ToV8();
+ }
+
+ static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
+ gin::Handle<gin::HandleWrapper>* out) {
+ if (val->IsNull()) {
+ *out = HandleWrapper::Create(isolate, MOJO_HANDLE_INVALID);
+ return true;
+ }
+
+ gin::HandleWrapper* object = NULL;
+ if (!Converter<gin::HandleWrapper*>::FromV8(isolate, val, &object)) {
+ return false;
+ }
+ *out = gin::Handle<gin::HandleWrapper>(val, object);
+ return true;
+ }
+};
+
} // namespace gin
#endif // MOJO_BINDINGS_JS_HANDLE_H_
« no previous file with comments | « mojo/bindings/js/core.cc ('k') | mojo/bindings/js/handle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698