From a3eb5137da768577a8e38cbf6526379788d5daa7 Mon Sep 17 00:00:00 2001 From: jjrv Date: Wed, 26 Oct 2016 14:00:33 +0300 Subject: [PATCH] Fix possible multiple inheritance issues and clean up. --- include/nbind/BindClass.h | 2 -- src/v8/Binding.cc | 18 ++++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/include/nbind/BindClass.h b/include/nbind/BindClass.h index 36ff9a5..8c8bd81 100644 --- a/include/nbind/BindClass.h +++ b/include/nbind/BindClass.h @@ -245,8 +245,6 @@ void BindWrapper :: testInstance(v8::Local arg) { } } -void *upcastStep(BindClassBase &src, BindClassBase &dst, void *ptr); - template Bound *BindWrapperBase :: upcast() { BindClassBase &src = getClass(); diff --git a/src/v8/Binding.cc b/src/v8/Binding.cc index d8fb7ec..066cd89 100644 --- a/src/v8/Binding.cc +++ b/src/v8/Binding.cc @@ -97,7 +97,11 @@ const char *NBindID :: toString() { typedef BaseSignature :: SignatureType SignatureType; -static void registerMethods(BindClassBase &bindClass, Local constructorTemplate) { +static void registerMethods( + BindClassBase &bindClass, + Local constructorTemplate, + bool staticOnly +) { Local proto = constructorTemplate->PrototypeTemplate(); char *nameBuf = nullptr; @@ -130,6 +134,8 @@ static void registerMethods(BindClassBase &bindClass, Local co continue; } + if(staticOnly && signature->getType() != SignatureType :: func) continue; + param = new SignatureParam(); switch(signature->getType()) { @@ -204,17 +210,14 @@ static void registerSuperMethods( // Mark this class visited. visitTbl.insert(&bindClass); - // If not just marking visits, include contents in class constructor template. - if(firstSuper >= 0) registerMethods(bindClass, constructorTemplate); - signed int superNum = 0; signed int nextFirst; for(auto &spec : bindClass.getSuperClassList()) { if(superNum++ < firstSuper || firstSuper < 0) { - // Contents of the initial first superclass and all of its + // Non-static contents of the initial first superclass and all of its // superclasses have already been inherited through the prototype - // chain. Just mark them visited recursively. + // chain. Mark them visited recursively and inherit static methods. nextFirst = -1; } else { // Complete contents of all other superclasses must be included @@ -224,6 +227,9 @@ static void registerSuperMethods( registerSuperMethods(spec.superClass, nextFirst, constructorTemplate, visitTbl); } + + // Include (possibly only static) contents in class constructor template. + registerMethods(bindClass, constructorTemplate, firstSuper < 0); } static void nop(const Nan::FunctionCallbackInfo &args) {