1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 #include "gin/converter.h"
12 // You can use gin::Handle on the stack to retain a gin::Wrappable object.
13 // Currently we don't have a mechanism for retaining a gin::Wrappable object
14 // in the C++ heap because strong references from C++ to V8 can cause memory
19 Handle() : object_(NULL
) {}
21 Handle(v8::Handle
<v8::Value
> wrapper
, T
* object
)
26 bool IsEmpty() const { return !object_
; }
33 T
* operator->() const { return object_
; }
34 v8::Handle
<v8::Value
> ToV8() const { return wrapper_
; }
35 T
* get() const { return object_
; }
38 v8::Handle
<v8::Value
> wrapper_
;
43 struct Converter
<gin::Handle
<T
> > {
44 static v8::Handle
<v8::Value
> ToV8(v8::Isolate
* isolate
,
45 const gin::Handle
<T
>& val
) {
48 static bool FromV8(v8::Isolate
* isolate
, v8::Handle
<v8::Value
> val
,
49 gin::Handle
<T
>* out
) {
51 if (!Converter
<T
*>::FromV8(isolate
, val
, &object
)) {
54 *out
= gin::Handle
<T
>(val
, object
);
59 // This function is a convenient way to create a handle from a raw pointer
60 // without having to write out the type of the object explicitly.
62 gin::Handle
<T
> CreateHandle(v8::Isolate
* isolate
, T
* object
) {
63 return gin::Handle
<T
>(object
->GetWrapper(isolate
), object
);
68 #endif // GIN_HANDLE_H_