JS backend: support for reflection

This commit is contained in:
Michael Nedzelsky
2014-07-22 16:11:37 +04:00
parent c42a9840de
commit cc98664832
6 changed files with 286 additions and 12 deletions
@@ -294,7 +294,60 @@ var Kotlin = {};
}
};
// TODO Store callable references for members in class
Kotlin.getCallableRefForMemberFunction = function (klass, memberName) {
return function () {
return this[memberName].apply(this, arguments);
};
};
// TODO Store callable references for extension functions in class
// extFun expected receiver as the first argument
Kotlin.getCallableRefForExtensionFunction = function (extFun) {
return function () {
var args = [this];
Array.prototype.push.apply(args, arguments);
return extFun.apply(null, args);
};
};
Kotlin.getCallableRefForConstructor = function (klass) {
return function () {
var obj = Object.create(klass.prototype);
klass.apply(obj, arguments);
return obj;
};
};
Kotlin.getCallableRefForTopLevelProperty = function(packageName, name, isVar) {
var obj = {};
obj.name = name;
obj.get = function() { return packageName[name]; };
if (isVar) {
obj.set_za3rmp$ = function(value) { packageName[name] = value; };
}
return obj;
};
Kotlin.getCallableRefForMemberProperty = function(name, isVar) {
var obj = {};
obj.name = name;
obj.get_za3rmp$ = function(receiver) { return receiver[name]; };
if (isVar) {
obj.set_wn2jw4$ = function(receiver, value) { receiver[name] = value; };
}
return obj;
};
Kotlin.getCallableRefForExtensionProperty = function(name, getFun, setFun) {
var obj = {};
obj.name = name;
obj.get_za3rmp$ = getFun;
if (setFun !== undefined) {
obj.set_wn2jw4$ = setFun;
}
return obj;
};
////////////////////////////////// packages & modules //////////////////////////////
Kotlin.modules = {};