Skip to content

Commit

Permalink
Fix possible multiple inheritance issues and clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
jjrv committed Oct 26, 2016
1 parent a7dcc68 commit a3eb513
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 0 additions & 2 deletions include/nbind/BindClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,6 @@ void BindWrapper<Bound> :: testInstance(v8::Local<v8::Object> arg) {
}
}

void *upcastStep(BindClassBase &src, BindClassBase &dst, void *ptr);

template <class Bound>
Bound *BindWrapperBase :: upcast() {
BindClassBase &src = getClass();
Expand Down
18 changes: 12 additions & 6 deletions src/v8/Binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ const char *NBindID :: toString() {

typedef BaseSignature :: SignatureType SignatureType;

static void registerMethods(BindClassBase &bindClass, Local<FunctionTemplate> constructorTemplate) {
static void registerMethods(
BindClassBase &bindClass,
Local<FunctionTemplate> constructorTemplate,
bool staticOnly
) {
Local<ObjectTemplate> proto = constructorTemplate->PrototypeTemplate();
char *nameBuf = nullptr;

Expand Down Expand Up @@ -130,6 +134,8 @@ static void registerMethods(BindClassBase &bindClass, Local<FunctionTemplate> co
continue;
}

if(staticOnly && signature->getType() != SignatureType :: func) continue;

param = new SignatureParam();

switch(signature->getType()) {
Expand Down Expand Up @@ -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
Expand All @@ -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<v8::Value> &args) {
Expand Down

0 comments on commit a3eb513

Please sign in to comment.