OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS 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 ENTD_JS_OBJECT_WRAPPER_H_ | 5 #ifndef ENTD_JS_OBJECT_WRAPPER_H_ |
6 #define ENTD_JS_OBJECT_WRAPPER_H_ | 6 #define ENTD_JS_OBJECT_WRAPPER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <v8.h> | 9 #include <v8.h> |
10 #include <base/basictypes.h> | 10 #include <base/basictypes.h> |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 static v8::Handle<v8::FunctionTemplate> GetTemplate() { | 63 static v8::Handle<v8::FunctionTemplate> GetTemplate() { |
64 return ManageTemplate(true); | 64 return ManageTemplate(true); |
65 } | 65 } |
66 | 66 |
67 // Call ManageTemplate() with 'false' to destroy the template | 67 // Call ManageTemplate() with 'false' to destroy the template |
68 static void CleanupTemplate() { | 68 static void CleanupTemplate() { |
69 ManageTemplate(false); | 69 ManageTemplate(false); |
70 } | 70 } |
71 | 71 |
72 // Accessors | 72 // Accessors |
73 v8::Handle<v8::Object> obj() { return obj_; } | 73 v8::Handle<v8::Object> obj() const { return obj_; } |
74 | 74 |
75 private: | 75 private: |
76 | 76 |
77 // ManageTemplate handles construction and destruction of a | 77 // ManageTemplate handles construction and destruction of a |
78 // singleton function template instance. | 78 // singleton function template instance. |
79 // | 79 // |
80 // If build is true, construct the template object if necessary, otherwise | 80 // If build is true, construct the template object if necessary, otherwise |
81 // dispose of the template if it exists. | 81 // dispose of the template if it exists. |
82 // | 82 // |
83 // Returns the function template handle (undefined if build is false) | 83 // Returns the function template handle (undefined if build is false) |
84 static v8::Handle<v8::FunctionTemplate> ManageTemplate(bool build); | 84 static v8::Handle<v8::FunctionTemplate> ManageTemplate(bool build); |
85 | 85 |
86 // Override this to bind methods or data to the template. e.g.: | 86 // Override this to bind methods or data to the template. e.g.: |
87 // tmpl_obj->Set(String::New("bar"), FunctionTemplate::New(dispatch_Bar)); | 87 // tmpl_obj->Set(String::New("bar"), FunctionTemplate::New(dispatch_Bar)); |
88 static void SetTemplateBindings(v8::Handle<v8::ObjectTemplate> tmpl_obj) {} | 88 static void SetTemplateBindings(v8::Handle<v8::ObjectTemplate> tmpl_obj) {} |
89 | 89 |
90 // V8 Object bound to this C++ instance | 90 // V8 Object bound to this C++ instance |
91 v8::Persistent<v8::Object> obj_; | 91 v8::Persistent<v8::Object> obj_; |
92 }; | 92 }; |
93 | 93 |
94 #include "entd/js_object_wrapper-inl.h" | 94 #include "entd/js_object_wrapper-inl.h" |
95 | 95 |
96 } // namespace entd | 96 } // namespace entd |
97 | 97 |
98 #endif // ENTD_JS_OBJECT_WRAPPER_ | 98 #endif // ENTD_JS_OBJECT_WRAPPER_ |
OLD | NEW |