# headers to make for a more pleasant IDE experience
'src/async-wrap.h',
'src/async-wrap-inl.h',
+ 'src/base-object.h',
+ 'src/base-object-inl.h',
'src/env.h',
'src/env-inl.h',
'src/handle_wrap.h',
'src/tree.h',
'src/util.h',
'src/util-inl.h',
- 'src/weak-object.h',
- 'src/weak-object-inl.h',
'deps/http_parser/http_parser.h',
'<(SHARED_INTERMEDIATE_DIR)/node_natives.h',
# javascript files to make for an even more pleasant IDE experience
#define SRC_ASYNC_WRAP_INL_H_
#include "async-wrap.h"
+#include "base-object.h"
+#include "base-object-inl.h"
#include "env.h"
#include "env-inl.h"
#include "util.h"
#include "util-inl.h"
+
#include "v8.h"
#include <assert.h>
namespace node {
inline AsyncWrap::AsyncWrap(Environment* env, v8::Handle<v8::Object> object)
- : object_(env->isolate(), object),
- env_(env),
+ : BaseObject(env, object),
async_flags_(NO_OPTIONS) {
- assert(!object.IsEmpty());
-
if (!env->has_async_listeners())
return;
inline AsyncWrap::~AsyncWrap() {
- assert(persistent().IsEmpty());
}
}
-inline Environment* AsyncWrap::env() const {
- return env_;
-}
-
-
-inline v8::Local<v8::Object> AsyncWrap::object() {
- return PersistentToLocal(env()->isolate(), persistent());
-}
-
-
-inline v8::Persistent<v8::Object>& AsyncWrap::persistent() {
- return object_;
-}
-
-
inline v8::Handle<v8::Value> AsyncWrap::MakeCallback(
const v8::Handle<v8::Function> cb,
int argc,
#ifndef SRC_ASYNC_WRAP_H_
#define SRC_ASYNC_WRAP_H_
+#include "base-object.h"
#include "env.h"
#include "v8.h"
namespace node {
-class AsyncWrap {
+class AsyncWrap : public BaseObject {
public:
enum AsyncFlags {
NO_OPTIONS = 0,
inline bool has_async_queue();
- inline Environment* env() const;
-
- // 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();
-
// Only call these within a valid HandleScope.
inline v8::Handle<v8::Value> MakeCallback(const v8::Handle<v8::Function> cb,
int argc,
static inline void RemoveAsyncListener(
const v8::FunctionCallbackInfo<v8::Value>& args);
- v8::Persistent<v8::Object> object_;
- Environment* const env_;
uint32_t async_flags_;
};
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
-#ifndef SRC_WEAK_OBJECT_INL_H_
-#define SRC_WEAK_OBJECT_INL_H_
+#ifndef SRC_BASE_OBJECT_INL_H_
+#define SRC_BASE_OBJECT_INL_H_
-#include "weak-object.h"
-#include "async-wrap.h"
-#include "async-wrap-inl.h"
+#include "base-object.h"
#include "util.h"
#include "util-inl.h"
+#include "v8.h"
+
+#include <assert.h>
namespace node {
-WeakObject::WeakObject(Environment* env, v8::Local<v8::Object> object)
- : AsyncWrap(env, object) {
- persistent().MarkIndependent();
+inline BaseObject::BaseObject(Environment* env, v8::Local<v8::Object> handle)
+ : handle_(env->isolate(), handle),
+ env_(env) {
+ assert(!handle.IsEmpty());
+}
+
- // The pointer is resolved as void*.
- Wrap<WeakObject>(object, this);
- MakeWeak();
+inline BaseObject::~BaseObject() {
+ assert(handle_.IsEmpty());
}
-WeakObject::~WeakObject() {
+
+inline v8::Persistent<v8::Object>& BaseObject::persistent() {
+ return handle_;
}
-void WeakObject::MakeWeak() {
- persistent().MakeWeak(this, WeakCallback);
+
+inline v8::Local<v8::Object> BaseObject::object() {
+ return PersistentToLocal(env_->isolate(), handle_);
}
-void WeakObject::ClearWeak() {
- persistent().ClearWeak();
+
+inline Environment* BaseObject::env() const {
+ return env_;
}
-void WeakObject::WeakCallback(v8::Isolate* isolate,
- v8::Persistent<v8::Object>* persistent,
- WeakObject* self) {
- // Dispose now instead of in the destructor to avoid child classes that call
- // `delete this` in their destructor from blowing up.
- // Dispose the class member instead of the argument or else the IsEmpty()
- // check in ~AsyncWrap will fail.
- self->persistent().Dispose();
+
+template <typename Type>
+inline void BaseObject::WeakCallback(
+ const v8::WeakCallbackData<v8::Object, Type>& data) {
+ Type* self = data.GetParameter();
+ self->persistent().Reset();
delete self;
}
+
+template <typename Type>
+inline void BaseObject::MakeWeak(Type* ptr) {
+ v8::HandleScope scope(env_->isolate());
+ v8::Local<v8::Object> handle = object();
+ assert(handle->InternalFieldCount() > 0);
+ Wrap<Type>(handle, ptr);
+ handle_.MarkIndependent();
+ handle_.SetWeak<Type>(ptr, WeakCallback<Type>);
+}
+
+
+inline void BaseObject::ClearWeak() {
+ handle_.ClearWeak();
+}
+
} // namespace node
-#endif // SRC_WEAK_OBJECT_INL_H_
+#endif // SRC_BASE_OBJECT_INL_H_
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
-#ifndef SRC_WEAK_OBJECT_H_
-#define SRC_WEAK_OBJECT_H_
+#ifndef SRC_BASE_OBJECT_H_
+#define SRC_BASE_OBJECT_H_
-#include "async-wrap.h"
#include "env.h"
#include "v8.h"
namespace node {
-class WeakObject : public AsyncWrap {
- protected:
- // |object| should be an instance of a v8::ObjectTemplate that has at least
- // one internal field reserved with v8::ObjectTemplate::SetInternalFieldCount.
- inline WeakObject(Environment* env, v8::Local<v8::Object> object);
- virtual inline ~WeakObject();
- inline void MakeWeak();
+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:
- inline static void WeakCallback(v8::Isolate* isolate,
- v8::Persistent<v8::Object>* persistent,
- WeakObject* self);
+ 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_WEAK_OBJECT_H_
+#endif // SRC_BASE_OBJECT_H_
#include "node.h"
#include "node_internals.h"
#include "node_watchdog.h"
+#include "base-object.h"
+#include "base-object-inl.h"
#include "env.h"
#include "env-inl.h"
#include "util.h"
#include "util-inl.h"
-#include "weak-object.h"
-#include "weak-object-inl.h"
namespace node {
}
};
-class ContextifyScript : public WeakObject {
+class ContextifyScript : public BaseObject {
private:
Persistent<Script> script_;
ContextifyScript(Environment* env, Local<Object> object)
- : WeakObject(env, object) {
+ : BaseObject(env, object) {
+ MakeWeak<ContextifyScript>(this);
}
#include "node_crypto_groups.h"
#include "tls_wrap.h" // TLSCallbacks
+#include "async-wrap.h"
+#include "async-wrap-inl.h"
#include "env.h"
#include "env-inl.h"
#include "string_bytes.h"
#endif
#include "env.h"
-#include "weak-object.h"
-#include "weak-object-inl.h"
+#include "async-wrap.h"
+#include "async-wrap-inl.h"
+#include "base-object.h"
+#include "base-object-inl.h"
#include "v8.h"
// Forward declaration
class Connection;
-class SecureContext : public WeakObject {
+class SecureContext : public BaseObject {
public:
+ ~SecureContext() {
+ FreeCTXMem();
+ }
+
static void Initialize(Environment* env, v8::Handle<v8::Object> target);
X509_STORE* ca_store_;
static void SetTicketKeys(const v8::FunctionCallbackInfo<v8::Value>& args);
SecureContext(Environment* env, v8::Local<v8::Object> wrap)
- : WeakObject(env, wrap),
+ : BaseObject(env, wrap),
ca_store_(NULL),
ctx_(NULL) {
+ MakeWeak<SecureContext>(this);
}
void FreeCTXMem() {
assert(ca_store_ == NULL);
}
}
-
- ~SecureContext() {
- FreeCTXMem();
- }
};
template <class Base>
friend class SecureContext;
};
-class Connection : public SSLWrap<Connection>, public WeakObject {
+class Connection : public SSLWrap<Connection>, public AsyncWrap {
public:
+ ~Connection() {
+#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
+ sniObject_.Dispose();
+ sniContext_.Dispose();
+ servername_.Dispose();
+#endif
+ }
+
static void Initialize(Environment* env, v8::Handle<v8::Object> target);
#ifdef OPENSSL_NPN_NEGOTIATED
SecureContext* sc,
SSLWrap<Connection>::Kind kind)
: SSLWrap<Connection>(env, sc, kind),
- WeakObject(env, wrap),
+ AsyncWrap(env, wrap),
bio_read_(NULL),
bio_write_(NULL),
hello_offset_(0) {
+ MakeWeak<Connection>(this);
hello_parser_.Start(SSLWrap<Connection>::OnClientHello,
OnClientHelloParseEnd,
this);
enable_session_callbacks();
}
- ~Connection() {
-#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
- sniObject_.Dispose();
- sniContext_.Dispose();
- servername_.Dispose();
-#endif
- }
-
private:
static void SSLInfoCallback(const SSL *ssl, int where, int ret);
friend class SecureContext;
};
-class CipherBase : public WeakObject {
+class CipherBase : public BaseObject {
public:
+ ~CipherBase() {
+ if (!initialised_)
+ return;
+ EVP_CIPHER_CTX_cleanup(&ctx_);
+ }
+
static void Initialize(Environment* env, v8::Handle<v8::Object> target);
protected:
CipherBase(Environment* env,
v8::Local<v8::Object> wrap,
CipherKind kind)
- : WeakObject(env, wrap),
+ : BaseObject(env, wrap),
cipher_(NULL),
initialised_(false),
kind_(kind) {
- }
-
- ~CipherBase() {
- if (!initialised_)
- return;
- EVP_CIPHER_CTX_cleanup(&ctx_);
+ MakeWeak<CipherBase>(this);
}
private:
CipherKind kind_;
};
-class Hmac : public WeakObject {
+class Hmac : public BaseObject {
public:
+ ~Hmac() {
+ if (!initialised_)
+ return;
+ HMAC_CTX_cleanup(&ctx_);
+ }
+
static void Initialize(Environment* env, v8::Handle<v8::Object> target);
protected:
static void HmacDigest(const v8::FunctionCallbackInfo<v8::Value>& args);
Hmac(Environment* env, v8::Local<v8::Object> wrap)
- : WeakObject(env, wrap),
+ : BaseObject(env, wrap),
md_(NULL),
initialised_(false) {
- }
-
- ~Hmac() {
- if (!initialised_)
- return;
- HMAC_CTX_cleanup(&ctx_);
+ MakeWeak<Hmac>(this);
}
private:
bool initialised_;
};
-class Hash : public WeakObject {
+class Hash : public BaseObject {
public:
+ ~Hash() {
+ if (!initialised_)
+ return;
+ EVP_MD_CTX_cleanup(&mdctx_);
+ }
+
static void Initialize(Environment* env, v8::Handle<v8::Object> target);
bool HashInit(const char* hash_type);
static void HashDigest(const v8::FunctionCallbackInfo<v8::Value>& args);
Hash(Environment* env, v8::Local<v8::Object> wrap)
- : WeakObject(env, wrap),
+ : BaseObject(env, wrap),
md_(NULL),
initialised_(false) {
- }
-
- ~Hash() {
- if (!initialised_)
- return;
- EVP_MD_CTX_cleanup(&mdctx_);
+ MakeWeak<Hash>(this);
}
private:
bool initialised_;
};
-class Sign : public WeakObject {
+class Sign : public BaseObject {
public:
+ ~Sign() {
+ if (!initialised_)
+ return;
+ EVP_MD_CTX_cleanup(&mdctx_);
+ }
+
static void Initialize(Environment* env, v8::Handle<v8::Object> target);
void SignInit(const char* sign_type);
static void SignFinal(const v8::FunctionCallbackInfo<v8::Value>& args);
Sign(Environment* env, v8::Local<v8::Object> wrap)
- : WeakObject(env, wrap),
+ : BaseObject(env, wrap),
md_(NULL),
initialised_(false) {
- }
-
- ~Sign() {
- if (!initialised_)
- return;
- EVP_MD_CTX_cleanup(&mdctx_);
+ MakeWeak<Sign>(this);
}
private:
bool initialised_;
};
-class Verify : public WeakObject {
+class Verify : public BaseObject {
public:
+ ~Verify() {
+ if (!initialised_)
+ return;
+ EVP_MD_CTX_cleanup(&mdctx_);
+ }
+
static void Initialize(Environment* env, v8::Handle<v8::Object> target);
void VerifyInit(const char* verify_type);
static void VerifyFinal(const v8::FunctionCallbackInfo<v8::Value>& args);
Verify(Environment* env, v8::Local<v8::Object> wrap)
- : WeakObject(env, wrap),
+ : BaseObject(env, wrap),
md_(NULL),
initialised_(false) {
- }
-
- ~Verify() {
- if (!initialised_)
- return;
- EVP_MD_CTX_cleanup(&mdctx_);
+ MakeWeak<Verify>(this);
}
private:
bool initialised_;
};
-class DiffieHellman : public WeakObject {
+class DiffieHellman : public BaseObject {
public:
+ ~DiffieHellman() {
+ if (dh != NULL) {
+ DH_free(dh);
+ }
+ }
+
static void Initialize(Environment* env, v8::Handle<v8::Object> target);
bool Init(int primeLength);
static void SetPrivateKey(const v8::FunctionCallbackInfo<v8::Value>& args);
DiffieHellman(Environment* env, v8::Local<v8::Object> wrap)
- : WeakObject(env, wrap),
+ : BaseObject(env, wrap),
initialised_(false),
dh(NULL) {
- }
-
- ~DiffieHellman() {
- if (dh != NULL) {
- DH_free(dh);
- }
+ MakeWeak<DiffieHellman>(this);
}
private:
DH* dh;
};
-class Certificate : public WeakObject {
+class Certificate : public AsyncWrap {
public:
static void Initialize(v8::Handle<v8::Object> target);
static void ExportChallenge(const v8::FunctionCallbackInfo<v8::Value>& args);
Certificate(Environment* env, v8::Local<v8::Object> wrap)
- : WeakObject(env, wrap) {
+ : AsyncWrap(env, wrap) {
+ MakeWeak<Certificate>(this);
}
};
#include "node_buffer.h"
#include "node_http_parser.h"
+#include "base-object.h"
+#include "base-object-inl.h"
#include "env.h"
#include "env-inl.h"
#include "util.h"
#include "util-inl.h"
-#include "weak-object.h"
-#include "weak-object-inl.h"
#include "v8.h"
#include <stdlib.h> // free()
};
-class Parser : public WeakObject {
+class Parser : public BaseObject {
public:
Parser(Environment* env, Local<Object> wrap, enum http_parser_type type)
- : WeakObject(env, wrap),
+ : BaseObject(env, wrap),
current_buffer_len_(0),
current_buffer_data_(NULL) {
+ MakeWeak<Parser>(this);
Init(type);
}
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "node_stat_watcher.h"
+#include "async-wrap.h"
+#include "async-wrap-inl.h"
#include "env.h"
#include "env-inl.h"
#include "util.h"
#include "util-inl.h"
-#include "weak-object.h"
-#include "weak-object-inl.h"
#include <assert.h>
#include <string.h>
StatWatcher::StatWatcher(Environment* env, Local<Object> wrap)
- : WeakObject(env, wrap),
+ : AsyncWrap(env, wrap),
watcher_(new uv_fs_poll_t) {
+ MakeWeak<StatWatcher>(this);
uv_fs_poll_init(env->event_loop(), watcher_);
watcher_->data = static_cast<void*>(this);
}
if (!uv_is_active(reinterpret_cast<uv_handle_t*>(watcher_)))
return;
uv_fs_poll_stop(watcher_);
- MakeWeak();
+ MakeWeak<StatWatcher>(this);
}
#define SRC_NODE_STAT_WATCHER_H_
#include "node.h"
+#include "async-wrap.h"
#include "env.h"
-#include "weak-object.h"
#include "uv.h"
#include "v8.h"
namespace node {
-class StatWatcher : public WeakObject {
+class StatWatcher : public AsyncWrap {
public:
+ virtual ~StatWatcher();
+
static void Initialize(v8::Handle<v8::Object> target);
protected:
StatWatcher(Environment* env, v8::Local<v8::Object> wrap);
- virtual ~StatWatcher();
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Start(const v8::FunctionCallbackInfo<v8::Value>& args);
#include "node.h"
#include "node_buffer.h"
+#include "async-wrap.h"
+#include "async-wrap-inl.h"
#include "env.h"
#include "env-inl.h"
#include "util.h"
#include "util-inl.h"
-#include "weak-object.h"
-#include "weak-object-inl.h"
#include "v8.h"
#include "zlib.h"
/**
* Deflate/Inflate
*/
-class ZCtx : public WeakObject {
+class ZCtx : public AsyncWrap {
public:
ZCtx(Environment* env, Local<Object> wrap, node_zlib_mode mode)
- : WeakObject(env, wrap),
+ : AsyncWrap(env, wrap),
chunk_size_(0),
dictionary_(NULL),
dictionary_len_(0),
windowBits_(0),
write_in_progress_(false),
refs_(0) {
+ MakeWeak<ZCtx>(this);
}
void Unref() {
assert(refs_ > 0);
if (--refs_ == 0) {
- MakeWeak();
+ MakeWeak<ZCtx>(this);
}
}