Reconstruct code after git merge issue.

This commit is contained in:
Bill Welden 2013-01-18 13:04:57 -08:00 коммит произвёл Jukka Jylänki
Родитель 93b8504747
Коммит e5a50ea590
1 изменённых файлов: 45 добавлений и 81 удалений

Просмотреть файл

@ -36,103 +36,67 @@ function _embind_repr(v) {
var typeRegistry = {}; var typeRegistry = {};
function resolveType(type) { function createInheritedFunctionOrProperty(name, type, nameInBaseClass, baseClassType) {
function createInheritedFunctionOrProperty(baseClassName, name, baseClassPrototype, baseClassType) { function upcastingWrapper(method) {
if (!type.Handle.prototype.hasOwnProperty(name)) { return function() {
var desc = Object.getOwnPropertyDescriptor(baseClassPrototype, baseClassName); var baseClassPtr = ___staticPointerCast(this.ptr, type.rawType, baseClassType.rawType);
if (desc) { // some names in the list may not be present in this particular base class if (baseClassPtr === this.ptr) {
if (baseClassPrototype.constructor.memberType[baseClassName] === 'field') { return method.apply(this, arguments);
var newDescriptor = { } else {
var handle = this.clone();
try {
handle.ptr = baseClassPtr;
return method.apply(handle, arguments);
} finally {
handle.delete();
}
}
};
}
var baseClassPrototype = baseClassType.Handle.prototype;
if (baseClassPrototype.constructor.memberType[nameInBaseClass] === 'field') {
var baseClassDescriptor = Object.getOwnPropertyDescriptor(baseClassPrototype, nameInBaseClass);
Object.defineProperty(type.Handle.prototype, name, {
enumerable: true, enumerable: true,
get: function() { get: upcastingWrapper(baseClassDescriptor.get),
var save = this.ptr; set: upcastingWrapper(baseClassDescriptor.set)
var baseClassPtr = ___staticPointerCast(this.ptr, type.rawType, baseClassType.rawType);
try {
this.ptr = baseClassPtr;
return desc.get();
} finally {
this.ptr = save; // todo: still not good, if the base class routine calls through the current handle
}
},
set: function(v) {
var save = this.ptr;
var baseClassPtr = ___staticPointerCast(this.ptr, type.rawType, baseClassType.rawType);
try {
this.ptr = baseClassPtr;
desc.set(v);
} finally {
this.ptr = save; // todo: still not good, if the base class routine calls through the current handle
}
}
};
Object.defineProperty(type.Handle.prototype, name, desc);
} else if (baseClassPrototype.constructor.memberType[baseClassName] === 'method') {
type.Handle.prototype[name] = createNamedFunction(name, function() {
var save = this.ptr;
var baseClassPtr = ___staticPointerCast(this.ptr, type.rawType, baseClassType.rawType);
try {
this.ptr = baseClassPtr;
return baseClassPrototype[baseClassName].apply(this, arguments);
} finally {
this.ptr = save; // todo: still not good, if the base class routine calls through the current handle
}
}); });
} else if (baseClassPrototype.constructor.memberType[nameInBaseClass] === 'method') {
var baseClassMethod = baseClassPrototype[nameInBaseClass];
type.Handle.prototype[name] = createNamedFunction(name, upcastingWrapper(baseClassMethod));
} }
} }
}
} function resolveType(type) {
if (!type.resolved) { if (!type.resolved) {
var i, j, rawBaseClassType, baseClassType, name, baseProto; var baseClassType, name, baseProto;
var names = []; var inheritedNames = {};
var addName = function(name) {
if (names.indexOf(name) < 0) {
names.push(name);
}
};
var qualifiedNames = {};
var addQualifiedName = function(name, qualifiedName) {
if (!(name in qualifiedNames)) {
qualifiedNames[name] = [];
}
if (qualifiedNames[name].indexOf(qualifiedName) < 0) {
qualifiedNames[name].push(qualifiedName);
}
};
var rawBaseClassTypes = Module.__getBaseClasses(type.rawType); var rawBaseClassTypes = Module.__getBaseClasses(type.rawType);
for (i = 0; i < rawBaseClassTypes.size(); i++) { for (var i = 0; i < rawBaseClassTypes.size(); i++) {
rawBaseClassType = rawBaseClassTypes.at(i); var rawBaseClassType = rawBaseClassTypes.at(i);
baseClassType = typeRegistry[rawBaseClassType]; baseClassType = typeRegistry[rawBaseClassType];
if (baseClassType) { if (baseClassType) {
resolveType(baseClassType); resolveType(baseClassType);
baseProto = baseClassType.Handle.prototype; baseProto = baseClassType.Handle.prototype;
for (name in baseProto) { for (name in baseProto) {
if (baseProto.hasOwnProperty(name) && baseClassType.Handle.memberType[name]) { if (baseProto.hasOwnProperty(name) && baseClassType.Handle.memberType[name]) {
if (names.indexOf(name) >= 0 || type.Handle.prototype.hasOwnProperty(name)) { if (!(name in inheritedNames)) {
addQualifiedName(name, baseClassType.name + "_" + name); inheritedNames[name] = [];
} }
addName(name); inheritedNames[name].push(baseClassType);
} }
} }
} }
} }
for (i = 0; i < rawBaseClassTypes.size(); i++) { for (name in inheritedNames) {
rawBaseClassType = rawBaseClassTypes.at(i); if (inheritedNames.hasOwnProperty(name)) {
baseClassType = typeRegistry[rawBaseClassType]; if (!type.Handle.prototype.hasOwnProperty(name) && inheritedNames[name].length === 1) {
if (baseClassType) { baseClassType = inheritedNames[name][0];
var proto = baseClassType.Handle.prototype; createInheritedFunctionOrProperty(name, type, name, baseClassType);
for (name in qualifiedNames) { } else {
if (qualifiedNames.hasOwnProperty(name)) { for (var j = 0; j < inheritedNames[name].length; j++) {
for (j = 0; j < qualifiedNames[name].length; j++) { baseClassType = inheritedNames[name][j];
if (qualifiedNames[name][j].indexOf(baseClassType.name + "_") === 0) { createInheritedFunctionOrProperty(baseClassType.name+"_"+name, type, name, baseClassType);
createInheritedFunctionOrProperty(name, qualifiedNames[name][j], proto, baseClassType);
}
}
}
}
for (j = 0; j < names.length; j++) {
name = names[j];
if (!(name in qualifiedNames)) {
createInheritedFunctionOrProperty(name, name, proto, baseClassType);
} }
} }
} }