From: Ben Noordhuis Date: Fri, 6 Sep 2013 18:59:27 +0000 (+0200) Subject: src: fix multi-base class ObjectWrap::Unwrap() X-Git-Tag: v0.11.8~83 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b89b97ddedc5b659e5592917d4789a31723ceca3;p=platform%2Fupstream%2Fnodejs.git src: fix multi-base class ObjectWrap::Unwrap() Fix pointer unwrapping when T is a class with more than one base class. Before this commit, the wrapped void* pointer was cast directly to T* without going through ObjectWrap* first, possibly leading to a class instance pointer that points to the wrong vtable. This change required some cleanup in various files; some classes used private rather than public inheritance, others didn't derive from ObjectWrap at all... Fixes #6188. --- diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 132fa91..da63655 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -212,8 +212,8 @@ class ContextifyContext { const PropertyCallbackInfo& args) { HandleScope scope(node_isolate); - Local data = args.Data()->ToObject(); - ContextifyContext* ctx = ObjectWrap::Unwrap(data); + ContextifyContext* ctx = NULL; + NODE_UNWRAP(args.Data().As(), ContextifyContext, ctx); Local sandbox = PersistentToLocal(node_isolate, ctx->sandbox_); Local rv = sandbox->GetRealNamedProperty(property); @@ -236,8 +236,8 @@ class ContextifyContext { const PropertyCallbackInfo& args) { HandleScope scope(node_isolate); - Local data = args.Data()->ToObject(); - ContextifyContext* ctx = ObjectWrap::Unwrap(data); + ContextifyContext* ctx = NULL; + NODE_UNWRAP(args.Data().As(), ContextifyContext, ctx); PersistentToLocal(node_isolate, ctx->sandbox_)->Set(property, value); } @@ -248,8 +248,8 @@ class ContextifyContext { const PropertyCallbackInfo& args) { HandleScope scope(node_isolate); - Local data = args.Data()->ToObject(); - ContextifyContext* ctx = ObjectWrap::Unwrap(data); + ContextifyContext* ctx = NULL; + NODE_UNWRAP(args.Data().As(), ContextifyContext, ctx); Local sandbox = PersistentToLocal(node_isolate, ctx->sandbox_); Local proxy_global = PersistentToLocal(node_isolate, @@ -269,8 +269,8 @@ class ContextifyContext { const PropertyCallbackInfo& args) { HandleScope scope(node_isolate); - Local data = args.Data()->ToObject(); - ContextifyContext* ctx = ObjectWrap::Unwrap(data); + ContextifyContext* ctx = NULL; + NODE_UNWRAP(args.Data().As(), ContextifyContext, ctx); bool success = PersistentToLocal(node_isolate, ctx->sandbox_)->Delete(property); @@ -286,15 +286,15 @@ class ContextifyContext { const PropertyCallbackInfo& args) { HandleScope scope(node_isolate); - Local data = args.Data()->ToObject(); - ContextifyContext* ctx = ObjectWrap::Unwrap(data); + ContextifyContext* ctx = NULL; + NODE_UNWRAP(args.Data().As(), ContextifyContext, ctx); Local sandbox = PersistentToLocal(node_isolate, ctx->sandbox_); args.GetReturnValue().Set(sandbox->GetPropertyNames()); } }; -class ContextifyScript : ObjectWrap { +class ContextifyScript : public ObjectWrap { private: Persistent