aboutsummaryrefslogtreecommitdiff
path: root/src/base-object.h
diff options
context:
space:
mode:
authorTrevor Norris <trev.norris@gmail.com>2013-11-04 10:49:55 -0800
committerTrevor Norris <trev.norris@gmail.com>2013-11-12 13:38:31 -0800
commitd120d92bfef0b5012e76c636335fee80e9c1e4a9 (patch)
tree277864e238d78271c82b3e77c8f3e8c850c35bd9 /src/base-object.h
parent6cea16f2c9ec0666708e924fa93c664ddb000b5c (diff)
downloadandroid-node-v8-d120d92bfef0b5012e76c636335fee80e9c1e4a9.tar.gz
android-node-v8-d120d92bfef0b5012e76c636335fee80e9c1e4a9.tar.bz2
android-node-v8-d120d92bfef0b5012e76c636335fee80e9c1e4a9.zip
base-object: add BaseObject
BaseObject is a class that just handles the Persistent handle attached to the class instance. This also removed WeakObject. Reordering the inheritance chain helps prevent unneeded calls on instances that don't call MakeCallback.
Diffstat (limited to 'src/base-object.h')
-rw-r--r--src/base-object.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/base-object.h b/src/base-object.h
new file mode 100644
index 0000000000..8b3f6da594
--- /dev/null
+++ b/src/base-object.h
@@ -0,0 +1,61 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+#ifndef SRC_BASE_OBJECT_H_
+#define SRC_BASE_OBJECT_H_
+
+#include "env.h"
+#include "v8.h"
+
+namespace node {
+
+class BaseObject {
+ public:
+ BaseObject(Environment* env, v8::Local<v8::Object> handle);
+ ~BaseObject();
+
+ // Returns the wrapped object. Illegal to call in your destructor.
+ inline v8::Local<v8::Object> object();
+
+ // Parent class is responsible to Dispose.
+ inline v8::Persistent<v8::Object>& persistent();
+
+ inline Environment* env() const;
+
+ template <typename Type>
+ inline void MakeWeak(Type* ptr);
+
+ inline void ClearWeak();
+
+ private:
+ BaseObject();
+
+ template <typename Type>
+ static inline void WeakCallback(
+ const v8::WeakCallbackData<v8::Object, Type>& data);
+
+ v8::Persistent<v8::Object> handle_;
+ Environment* env_;
+};
+
+} // namespace node
+
+#endif // SRC_BASE_OBJECT_H_