diff options
author | Trevor Norris <trev.norris@gmail.com> | 2013-10-29 12:49:53 -0700 |
---|---|---|
committer | Trevor Norris <trev.norris@gmail.com> | 2013-10-29 15:09:44 -0700 |
commit | 60a3e695cb6ff09f81de4195368535fdb11e2da9 (patch) | |
tree | 1e39179a155cc98ce9cca734e300d32d8cc07f5b | |
parent | 93f75a86bf6c87aa897312740aab61282b0eff1d (diff) | |
download | node-new-60a3e695cb6ff09f81de4195368535fdb11e2da9.tar.gz |
src: don't use WeakObject::Unwrap
Switch out to use UnwrapObject from util.h.
-rw-r--r-- | src/node_contextify.cc | 2 | ||||
-rw-r--r-- | src/node_crypto.cc | 90 | ||||
-rw-r--r-- | src/node_crypto.h | 2 | ||||
-rw-r--r-- | src/node_http_parser.cc | 10 | ||||
-rw-r--r-- | src/node_stat_watcher.cc | 6 | ||||
-rw-r--r-- | src/node_zlib.cc | 12 | ||||
-rw-r--r-- | src/tls_wrap.cc | 6 | ||||
-rw-r--r-- | src/weak-object-inl.h | 15 | ||||
-rw-r--r-- | src/weak-object.h | 5 |
9 files changed, 68 insertions, 80 deletions
diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 1c7484fb63..1b3ef355c4 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -575,7 +575,7 @@ class ContextifyScript : public WeakObject { } ContextifyScript* wrapped_script = - WeakObject::Unwrap<ContextifyScript>(args.This()); + UnwrapObject<ContextifyScript>(args.This()); Local<Script> script = PersistentToLocal(node_isolate, wrapped_script->script_); diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 6f1d232436..af00b70563 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -245,7 +245,7 @@ void SecureContext::New(const FunctionCallbackInfo<Value>& args) { void SecureContext::Init(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - SecureContext* sc = WeakObject::Unwrap<SecureContext>(args.This()); + SecureContext* sc = UnwrapObject<SecureContext>(args.This()); OPENSSL_CONST SSL_METHOD *method = SSLv23_method(); @@ -371,7 +371,7 @@ static X509* LoadX509(Handle<Value> v) { void SecureContext::SetKey(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - SecureContext* sc = WeakObject::Unwrap<SecureContext>(args.This()); + SecureContext* sc = UnwrapObject<SecureContext>(args.This()); unsigned int len = args.Length(); if (len != 1 && len != 2) { @@ -477,7 +477,7 @@ int SSL_CTX_use_certificate_chain(SSL_CTX *ctx, BIO *in) { void SecureContext::SetCert(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - SecureContext* sc = WeakObject::Unwrap<SecureContext>(args.This()); + SecureContext* sc = UnwrapObject<SecureContext>(args.This()); if (args.Length() != 1) { return ThrowTypeError("Bad parameter"); @@ -505,7 +505,7 @@ void SecureContext::AddCACert(const FunctionCallbackInfo<Value>& args) { bool newCAStore = false; HandleScope scope(node_isolate); - SecureContext* sc = WeakObject::Unwrap<SecureContext>(args.This()); + SecureContext* sc = UnwrapObject<SecureContext>(args.This()); if (args.Length() != 1) { return ThrowTypeError("Bad parameter"); @@ -534,7 +534,7 @@ void SecureContext::AddCACert(const FunctionCallbackInfo<Value>& args) { void SecureContext::AddCRL(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - SecureContext* sc = WeakObject::Unwrap<SecureContext>(args.This()); + SecureContext* sc = UnwrapObject<SecureContext>(args.This()); if (args.Length() != 1) { return ThrowTypeError("Bad parameter"); @@ -566,7 +566,7 @@ void SecureContext::AddCRL(const FunctionCallbackInfo<Value>& args) { void SecureContext::AddRootCerts(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - SecureContext* sc = WeakObject::Unwrap<SecureContext>(args.This()); + SecureContext* sc = UnwrapObject<SecureContext>(args.This()); assert(sc->ca_store_ == NULL); @@ -603,7 +603,7 @@ void SecureContext::AddRootCerts(const FunctionCallbackInfo<Value>& args) { void SecureContext::SetCiphers(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - SecureContext* sc = WeakObject::Unwrap<SecureContext>(args.This()); + SecureContext* sc = UnwrapObject<SecureContext>(args.This()); if (args.Length() != 1 || !args[0]->IsString()) { return ThrowTypeError("Bad parameter"); @@ -617,7 +617,7 @@ void SecureContext::SetCiphers(const FunctionCallbackInfo<Value>& args) { void SecureContext::SetOptions(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - SecureContext* sc = WeakObject::Unwrap<SecureContext>(args.This()); + SecureContext* sc = UnwrapObject<SecureContext>(args.This()); if (args.Length() != 1 || !args[0]->IntegerValue()) { return ThrowTypeError("Bad parameter"); @@ -631,7 +631,7 @@ void SecureContext::SetSessionIdContext( const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - SecureContext* sc = WeakObject::Unwrap<SecureContext>(args.This()); + SecureContext* sc = UnwrapObject<SecureContext>(args.This()); if (args.Length() != 1 || !args[0]->IsString()) { return ThrowTypeError("Bad parameter"); @@ -668,7 +668,7 @@ void SecureContext::SetSessionIdContext( void SecureContext::SetSessionTimeout(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - SecureContext* sc = WeakObject::Unwrap<SecureContext>(args.This()); + SecureContext* sc = UnwrapObject<SecureContext>(args.This()); if (args.Length() != 1 || !args[0]->IsInt32()) { return ThrowTypeError("Bad parameter"); @@ -681,7 +681,7 @@ void SecureContext::SetSessionTimeout(const FunctionCallbackInfo<Value>& args) { void SecureContext::Close(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - SecureContext* sc = WeakObject::Unwrap<SecureContext>(args.This()); + SecureContext* sc = UnwrapObject<SecureContext>(args.This()); sc->FreeCTXMem(); } @@ -698,7 +698,7 @@ void SecureContext::LoadPKCS12(const FunctionCallbackInfo<Value>& args) { char* pass = NULL; bool ret = false; - SecureContext* sc = WeakObject::Unwrap<SecureContext>(args.This()); + SecureContext* sc = UnwrapObject<SecureContext>(args.This()); if (args.Length() < 1) { return ThrowTypeError("Bad parameter"); @@ -1654,7 +1654,7 @@ int Connection::SelectSNIContextCallback_(SSL *s, int *ad, void* arg) { env->secure_context_constructor_template(); if (secure_context_constructor_template->HasInstance(ret)) { conn->sniContext_.Reset(node_isolate, ret); - SecureContext* sc = WeakObject::Unwrap<SecureContext>(ret.As<Object>()); + SecureContext* sc = UnwrapObject<SecureContext>(ret.As<Object>()); SSL_set_SSL_CTX(s, sc->ctx_); } else { return SSL_TLSEXT_ERR_NOACK; @@ -1673,7 +1673,7 @@ void Connection::New(const FunctionCallbackInfo<Value>& args) { return ThrowError("First argument must be a crypto module Credentials"); } - SecureContext* sc = WeakObject::Unwrap<SecureContext>(args[0]->ToObject()); + SecureContext* sc = UnwrapObject<SecureContext>(args[0]->ToObject()); Environment* env = sc->env(); bool is_server = args[1]->BooleanValue(); @@ -2135,7 +2135,7 @@ void CipherBase::Init(const char* cipher_type, void CipherBase::Init(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - CipherBase* cipher = WeakObject::Unwrap<CipherBase>(args.This()); + CipherBase* cipher = UnwrapObject<CipherBase>(args.This()); if (args.Length() < 2 || !(args[0]->IsString() && Buffer::HasInstance(args[1]))) { @@ -2187,7 +2187,7 @@ void CipherBase::InitIv(const char* cipher_type, void CipherBase::InitIv(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - CipherBase* cipher = WeakObject::Unwrap<CipherBase>(args.This()); + CipherBase* cipher = UnwrapObject<CipherBase>(args.This()); if (args.Length() < 3 || !args[0]->IsString()) { return ThrowError("Must give cipher-type, key, and iv as argument"); @@ -2225,7 +2225,7 @@ void CipherBase::Update(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args.GetIsolate()); HandleScope handle_scope(args.GetIsolate()); - CipherBase* cipher = WeakObject::Unwrap<CipherBase>(args.This()); + CipherBase* cipher = UnwrapObject<CipherBase>(args.This()); ASSERT_IS_STRING_OR_BUFFER(args[0]); @@ -2272,7 +2272,7 @@ bool CipherBase::SetAutoPadding(bool auto_padding) { void CipherBase::SetAutoPadding(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - CipherBase* cipher = WeakObject::Unwrap<CipherBase>(args.This()); + CipherBase* cipher = UnwrapObject<CipherBase>(args.This()); cipher->SetAutoPadding(args.Length() < 1 || args[0]->BooleanValue()); } @@ -2294,7 +2294,7 @@ void CipherBase::Final(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args.GetIsolate()); HandleScope handle_scope(args.GetIsolate()); - CipherBase* cipher = WeakObject::Unwrap<CipherBase>(args.This()); + CipherBase* cipher = UnwrapObject<CipherBase>(args.This()); unsigned char* out_value = NULL; int out_len = -1; @@ -2354,7 +2354,7 @@ void Hmac::HmacInit(const char* hash_type, const char* key, int key_len) { void Hmac::HmacInit(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - Hmac* hmac = WeakObject::Unwrap<Hmac>(args.This()); + Hmac* hmac = UnwrapObject<Hmac>(args.This()); if (args.Length() < 2 || !args[0]->IsString()) { return ThrowError("Must give hashtype string, key as arguments"); @@ -2380,7 +2380,7 @@ bool Hmac::HmacUpdate(const char* data, int len) { void Hmac::HmacUpdate(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - Hmac* hmac = WeakObject::Unwrap<Hmac>(args.This()); + Hmac* hmac = UnwrapObject<Hmac>(args.This()); ASSERT_IS_STRING_OR_BUFFER(args[0]); @@ -2422,7 +2422,7 @@ bool Hmac::HmacDigest(unsigned char** md_value, unsigned int* md_len) { void Hmac::HmacDigest(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - Hmac* hmac = WeakObject::Unwrap<Hmac>(args.This()); + Hmac* hmac = UnwrapObject<Hmac>(args.This()); enum encoding encoding = BUFFER; if (args.Length() >= 1) { @@ -2496,7 +2496,7 @@ bool Hash::HashUpdate(const char* data, int len) { void Hash::HashUpdate(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - Hash* hash = WeakObject::Unwrap<Hash>(args.This()); + Hash* hash = UnwrapObject<Hash>(args.This()); ASSERT_IS_STRING_OR_BUFFER(args[0]); @@ -2527,7 +2527,7 @@ void Hash::HashUpdate(const FunctionCallbackInfo<Value>& args) { void Hash::HashDigest(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - Hash* hash = WeakObject::Unwrap<Hash>(args.This()); + Hash* hash = UnwrapObject<Hash>(args.This()); if (!hash->initialised_) { return ThrowError("Not initialized"); @@ -2586,7 +2586,7 @@ void Sign::SignInit(const char* sign_type) { void Sign::SignInit(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - Sign* sign = WeakObject::Unwrap<Sign>(args.This()); + Sign* sign = UnwrapObject<Sign>(args.This()); if (args.Length() == 0 || !args[0]->IsString()) { return ThrowError("Must give signtype string as argument"); @@ -2608,7 +2608,7 @@ bool Sign::SignUpdate(const char* data, int len) { void Sign::SignUpdate(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - Sign* sign = WeakObject::Unwrap<Sign>(args.This()); + Sign* sign = UnwrapObject<Sign>(args.This()); ASSERT_IS_STRING_OR_BUFFER(args[0]); @@ -2694,7 +2694,7 @@ bool Sign::SignFinal(const char* key_pem, void Sign::SignFinal(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - Sign* sign = WeakObject::Unwrap<Sign>(args.This()); + Sign* sign = UnwrapObject<Sign>(args.This()); unsigned char* md_value; unsigned int md_len; @@ -2768,7 +2768,7 @@ void Verify::VerifyInit(const char* verify_type) { void Verify::VerifyInit(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - Verify* verify = WeakObject::Unwrap<Verify>(args.This()); + Verify* verify = UnwrapObject<Verify>(args.This()); if (args.Length() == 0 || !args[0]->IsString()) { return ThrowError("Must give verifytype string as argument"); @@ -2790,7 +2790,7 @@ bool Verify::VerifyUpdate(const char* data, int len) { void Verify::VerifyUpdate(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - Verify* verify = WeakObject::Unwrap<Verify>(args.This()); + Verify* verify = UnwrapObject<Verify>(args.This()); ASSERT_IS_STRING_OR_BUFFER(args[0]); @@ -2903,7 +2903,7 @@ bool Verify::VerifyFinal(const char* key_pem, void Verify::VerifyFinal(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - Verify* verify = WeakObject::Unwrap<Verify>(args.This()); + Verify* verify = UnwrapObject<Verify>(args.This()); ASSERT_IS_BUFFER(args[0]); char* kbuf = Buffer::Data(args[0]); @@ -3056,8 +3056,7 @@ void DiffieHellman::New(const FunctionCallbackInfo<Value>& args) { void DiffieHellman::GenerateKeys(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - DiffieHellman* diffieHellman = - WeakObject::Unwrap<DiffieHellman>(args.This()); + DiffieHellman* diffieHellman = UnwrapObject<DiffieHellman>(args.This()); if (!diffieHellman->initialised_) { return ThrowError("Not initialized"); @@ -3080,8 +3079,7 @@ void DiffieHellman::GenerateKeys(const FunctionCallbackInfo<Value>& args) { void DiffieHellman::GetPrime(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - DiffieHellman* diffieHellman = - WeakObject::Unwrap<DiffieHellman>(args.This()); + DiffieHellman* diffieHellman = UnwrapObject<DiffieHellman>(args.This()); if (!diffieHellman->initialised_) { return ThrowError("Not initialized"); @@ -3099,8 +3097,7 @@ void DiffieHellman::GetPrime(const FunctionCallbackInfo<Value>& args) { void DiffieHellman::GetGenerator(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - DiffieHellman* diffieHellman = - WeakObject::Unwrap<DiffieHellman>(args.This()); + DiffieHellman* diffieHellman = UnwrapObject<DiffieHellman>(args.This()); if (!diffieHellman->initialised_) { return ThrowError("Not initialized"); @@ -3118,8 +3115,7 @@ void DiffieHellman::GetGenerator(const FunctionCallbackInfo<Value>& args) { void DiffieHellman::GetPublicKey(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - DiffieHellman* diffieHellman = - WeakObject::Unwrap<DiffieHellman>(args.This()); + DiffieHellman* diffieHellman = UnwrapObject<DiffieHellman>(args.This()); if (!diffieHellman->initialised_) { return ThrowError("Not initialized"); @@ -3142,8 +3138,7 @@ void DiffieHellman::GetPublicKey(const FunctionCallbackInfo<Value>& args) { void DiffieHellman::GetPrivateKey(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - DiffieHellman* diffieHellman = - WeakObject::Unwrap<DiffieHellman>(args.This()); + DiffieHellman* diffieHellman = UnwrapObject<DiffieHellman>(args.This()); if (!diffieHellman->initialised_) { return ThrowError("Not initialized"); @@ -3166,8 +3161,7 @@ void DiffieHellman::GetPrivateKey(const FunctionCallbackInfo<Value>& args) { void DiffieHellman::ComputeSecret(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - DiffieHellman* diffieHellman = - WeakObject::Unwrap<DiffieHellman>(args.This()); + DiffieHellman* diffieHellman = UnwrapObject<DiffieHellman>(args.This()); if (!diffieHellman->initialised_) { return ThrowError("Not initialized"); @@ -3238,8 +3232,7 @@ void DiffieHellman::ComputeSecret(const FunctionCallbackInfo<Value>& args) { void DiffieHellman::SetPublicKey(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - DiffieHellman* diffieHellman = - WeakObject::Unwrap<DiffieHellman>(args.This()); + DiffieHellman* diffieHellman = UnwrapObject<DiffieHellman>(args.This()); if (!diffieHellman->initialised_) { return ThrowError("Not initialized"); @@ -3259,8 +3252,7 @@ void DiffieHellman::SetPublicKey(const FunctionCallbackInfo<Value>& args) { void DiffieHellman::SetPrivateKey(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - DiffieHellman* diffieHellman = - WeakObject::Unwrap<DiffieHellman>(args.This()); + DiffieHellman* diffieHellman = UnwrapObject<DiffieHellman>(args.This()); if (!diffieHellman->initialised_) { return ThrowError("Not initialized"); @@ -3705,7 +3697,7 @@ bool Certificate::VerifySpkac(const char* data, unsigned int len) { void Certificate::VerifySpkac(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - Certificate* certificate = WeakObject::Unwrap<Certificate>(args.This()); + Certificate* certificate = UnwrapObject<Certificate>(args.This()); bool i = false; if (args.Length() < 1) @@ -3770,7 +3762,7 @@ const char* Certificate::ExportPublicKey(const char* data, int len) { void Certificate::ExportPublicKey(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - Certificate* certificate = WeakObject::Unwrap<Certificate>(args.This()); + Certificate* certificate = UnwrapObject<Certificate>(args.This()); if (args.Length() < 1) return ThrowTypeError("Missing argument"); @@ -3813,7 +3805,7 @@ const char* Certificate::ExportChallenge(const char* data, int len) { void Certificate::ExportChallenge(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - Certificate* crt = WeakObject::Unwrap<Certificate>(args.This()); + Certificate* crt = UnwrapObject<Certificate>(args.This()); if (args.Length() < 1) return ThrowTypeError("Missing argument"); diff --git a/src/node_crypto.h b/src/node_crypto.h index 770528ec1a..414261effe 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -275,7 +275,7 @@ class Connection : public SSLWrap<Connection>, public WeakObject { void SetShutdownFlags(); static Connection* Unwrap(v8::Local<v8::Object> object) { - Connection* conn = WeakObject::Unwrap<Connection>(object); + Connection* conn = UnwrapObject<Connection>(object); conn->ClearError(); return conn; } diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index d6b0090756..0f5d58d507 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -25,6 +25,8 @@ #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" @@ -362,7 +364,7 @@ class Parser : public WeakObject { static void Execute(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - Parser* parser = WeakObject::Unwrap<Parser>(args.This()); + Parser* parser = UnwrapObject<Parser>(args.This()); assert(parser->current_buffer_.IsEmpty()); assert(parser->current_buffer_len_ == 0); assert(parser->current_buffer_data_ == NULL); @@ -417,7 +419,7 @@ class Parser : public WeakObject { static void Finish(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - Parser* parser = WeakObject::Unwrap<Parser>(args.This()); + Parser* parser = UnwrapObject<Parser>(args.This()); assert(parser->current_buffer_.IsEmpty()); parser->got_exception_ = false; @@ -451,7 +453,7 @@ class Parser : public WeakObject { static_cast<http_parser_type>(args[0]->Int32Value()); assert(type == HTTP_REQUEST || type == HTTP_RESPONSE); - Parser* parser = WeakObject::Unwrap<Parser>(args.This()); + Parser* parser = UnwrapObject<Parser>(args.This()); // Should always be called from the same context. assert(env == parser->env()); parser->Init(type); @@ -462,7 +464,7 @@ class Parser : public WeakObject { static void Pause(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args.GetIsolate()); HandleScope handle_scope(args.GetIsolate()); - Parser* parser = WeakObject::Unwrap<Parser>(args.This()); + Parser* parser = UnwrapObject<Parser>(args.This()); // Should always be called from the same context. assert(env == parser->env()); http_parser_pause(&parser->parser_, should_pause); diff --git a/src/node_stat_watcher.cc b/src/node_stat_watcher.cc index 3468cc38ad..a9f41e6d50 100644 --- a/src/node_stat_watcher.cc +++ b/src/node_stat_watcher.cc @@ -22,6 +22,8 @@ #include "node_stat_watcher.h" #include "env.h" #include "env-inl.h" +#include "util.h" +#include "util-inl.h" #include "weak-object.h" #include "weak-object-inl.h" @@ -112,7 +114,7 @@ void StatWatcher::Start(const FunctionCallbackInfo<Value>& args) { assert(args.Length() == 3); HandleScope scope(node_isolate); - StatWatcher* wrap = WeakObject::Unwrap<StatWatcher>(args.This()); + StatWatcher* wrap = UnwrapObject<StatWatcher>(args.This()); String::Utf8Value path(args[0]); const bool persistent = args[1]->BooleanValue(); const uint32_t interval = args[2]->Uint32Value(); @@ -125,7 +127,7 @@ void StatWatcher::Start(const FunctionCallbackInfo<Value>& args) { void StatWatcher::Stop(const FunctionCallbackInfo<Value>& args) { - StatWatcher* wrap = WeakObject::Unwrap<StatWatcher>(args.This()); + StatWatcher* wrap = UnwrapObject<StatWatcher>(args.This()); Environment* env = wrap->env(); Context::Scope context_scope(env->context()); HandleScope handle_scope(env->isolate()); diff --git a/src/node_zlib.cc b/src/node_zlib.cc index ac3a296c0b..4d4bd994f2 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -24,6 +24,8 @@ #include "env.h" #include "env-inl.h" +#include "util.h" +#include "util-inl.h" #include "weak-object.h" #include "weak-object-inl.h" @@ -122,7 +124,7 @@ class ZCtx : public WeakObject { static void Close(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - ZCtx* ctx = WeakObject::Unwrap<ZCtx>(args.This()); + ZCtx* ctx = UnwrapObject<ZCtx>(args.This()); ctx->Close(); } @@ -132,7 +134,7 @@ class ZCtx : public WeakObject { HandleScope scope(node_isolate); assert(args.Length() == 7); - ZCtx* ctx = WeakObject::Unwrap<ZCtx>(args.This()); + ZCtx* ctx = UnwrapObject<ZCtx>(args.This()); assert(ctx->init_done_ && "write before init"); assert(ctx->mode_ != NONE && "already finalized"); @@ -341,7 +343,7 @@ class ZCtx : public WeakObject { assert((args.Length() == 4 || args.Length() == 5) && "init(windowBits, level, memLevel, strategy, [dictionary])"); - ZCtx* ctx = WeakObject::Unwrap<ZCtx>(args.This()); + ZCtx* ctx = UnwrapObject<ZCtx>(args.This()); int windowBits = args[0]->Uint32Value(); assert((windowBits >= 8 && windowBits <= 15) && "invalid windowBits"); @@ -380,7 +382,7 @@ class ZCtx : public WeakObject { assert(args.Length() == 2 && "params(level, strategy)"); - ZCtx* ctx = WeakObject::Unwrap<ZCtx>(args.This()); + ZCtx* ctx = UnwrapObject<ZCtx>(args.This()); Params(ctx, args[0]->Int32Value(), args[1]->Int32Value()); } @@ -388,7 +390,7 @@ class ZCtx : public WeakObject { static void Reset(const FunctionCallbackInfo<Value> &args) { HandleScope scope(node_isolate); - ZCtx* ctx = WeakObject::Unwrap<ZCtx>(args.This()); + ZCtx* ctx = UnwrapObject<ZCtx>(args.This()); Reset(ctx); SetDictionary(ctx); diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index 3b22ce50b1..6976e251bd 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -60,7 +60,7 @@ TLSCallbacks::TLSCallbacks(Environment* env, Kind kind, Handle<Object> sc, StreamWrapCallbacks* old) - : SSLWrap<TLSCallbacks>(env, WeakObject::Unwrap<SecureContext>(sc), kind), + : SSLWrap<TLSCallbacks>(env, UnwrapObject<SecureContext>(sc), kind), StreamWrapCallbacks(old), enc_in_(NULL), enc_out_(NULL), @@ -72,7 +72,7 @@ TLSCallbacks::TLSCallbacks(Environment* env, shutdown_(false) { // Persist SecureContext - sc_ = WeakObject::Unwrap<SecureContext>(sc); + sc_ = UnwrapObject<SecureContext>(sc); sc_handle_.Reset(node_isolate, sc); Local<Object> object = env->tls_wrap_constructor_function()->NewInstance(); @@ -694,7 +694,7 @@ int TLSCallbacks::SelectSNIContextCallback(SSL* s, int* ad, void* arg) { p->sni_context_.Dispose(); p->sni_context_.Reset(node_isolate, ctx); - SecureContext* sc = WeakObject::Unwrap<SecureContext>(ctx.As<Object>()); + SecureContext* sc = UnwrapObject<SecureContext>(ctx.As<Object>()); SSL_set_SSL_CTX(s, sc->ctx_); } diff --git a/src/weak-object-inl.h b/src/weak-object-inl.h index 0d293a437d..47233e2dad 100644 --- a/src/weak-object-inl.h +++ b/src/weak-object-inl.h @@ -23,13 +23,17 @@ #define SRC_WEAK_OBJECT_INL_H_ #include "weak-object.h" +#include "util.h" +#include "util-inl.h" namespace node { WeakObject::WeakObject(v8::Isolate* isolate, v8::Local<v8::Object> object) : weak_object_(isolate, object) { weak_object_.MarkIndependent(); - object->SetAlignedPointerInInternalField(kInternalFieldIndex, this); + + // The pointer is resolved as void*. + WrapObject<WeakObject>(object, this); MakeWeak(); } @@ -48,15 +52,6 @@ void WeakObject::ClearWeak() { weak_object_.ClearWeak(); } -template <typename TypeName> -TypeName* WeakObject::Unwrap(v8::Local<v8::Object> object) { - // Cast to WeakObject* before casting to TypeName* avoids issues with classes - // that have multiple base classes. - void* p = object->GetAlignedPointerFromInternalField(kInternalFieldIndex); - WeakObject* w = static_cast<WeakObject*>(p); - return static_cast<TypeName*>(w); -} - void WeakObject::WeakCallback(v8::Isolate* isolate, v8::Persistent<v8::Object>* persistent, WeakObject* self) { diff --git a/src/weak-object.h b/src/weak-object.h index b42332eb71..39bf35fa76 100644 --- a/src/weak-object.h +++ b/src/weak-object.h @@ -28,10 +28,6 @@ namespace node { class WeakObject { public: - // FIXME(bnoordhuis) These methods are public only because the code base - // plays fast and loose with encapsulation. - template <typename TypeName> - inline static TypeName* Unwrap(v8::Local<v8::Object> object); // Returns the wrapped object. Illegal to call in your destructor. inline v8::Local<v8::Object> weak_object(v8::Isolate* isolate) const; protected: @@ -45,7 +41,6 @@ class WeakObject { inline static void WeakCallback(v8::Isolate* isolate, v8::Persistent<v8::Object>* persistent, WeakObject* self); - static const int kInternalFieldIndex = 0; v8::Persistent<v8::Object> weak_object_; }; |