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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/bindings/js/core.cc ('k') | mojo/bindings/js/handle.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_BINDINGS_JS_HANDLE_H_ 5 #ifndef MOJO_BINDINGS_JS_HANDLE_H_
6 #define MOJO_BINDINGS_JS_HANDLE_H_ 6 #define MOJO_BINDINGS_JS_HANDLE_H_
7 7
8 #include "gin/converter.h" 8 #include "gin/converter.h"
9 #include "gin/handle.h" 9 #include "gin/handle.h"
10 #include "gin/wrappable.h" 10 #include "gin/wrappable.h"
(...skipping 27 matching lines...) Expand all
38 // there's no way to prevent against accidental use. 38 // there's no way to prevent against accidental use.
39 // TODO(mpcomplete): define converters for all Handle subtypes. 39 // TODO(mpcomplete): define converters for all Handle subtypes.
40 template<> 40 template<>
41 struct Converter<mojo::Handle> { 41 struct Converter<mojo::Handle> {
42 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, 42 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
43 const mojo::Handle& val); 43 const mojo::Handle& val);
44 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, 44 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
45 mojo::Handle* out); 45 mojo::Handle* out);
46 }; 46 };
47 47
48 // We need to specialize the normal gin::Handle converter in order to handle
49 // converting |null| to a wrapper for an empty mojo::Handle.
50 template<>
51 struct Converter<gin::Handle<gin::HandleWrapper> > {
52 static v8::Handle<v8::Value> ToV8(
53 v8::Isolate* isolate, const gin::Handle<gin::HandleWrapper>& val) {
54 return val.ToV8();
55 }
56
57 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
58 gin::Handle<gin::HandleWrapper>* out) {
59 if (val->IsNull()) {
60 *out = HandleWrapper::Create(isolate, MOJO_HANDLE_INVALID);
61 return true;
62 }
63
64 gin::HandleWrapper* object = NULL;
65 if (!Converter<gin::HandleWrapper*>::FromV8(isolate, val, &object)) {
66 return false;
67 }
68 *out = gin::Handle<gin::HandleWrapper>(val, object);
69 return true;
70 }
71 };
72
48 } // namespace gin 73 } // namespace gin
49 74
50 #endif // MOJO_BINDINGS_JS_HANDLE_H_ 75 #endif // MOJO_BINDINGS_JS_HANDLE_H_
OLDNEW
« 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