diff --git a/transcrypt/modules/org/transcrypt/__core__.js b/transcrypt/modules/org/transcrypt/__core__.js index 74901958..6f4350c9 100644 --- a/transcrypt/modules/org/transcrypt/__core__.js +++ b/transcrypt/modules/org/transcrypt/__core__.js @@ -113,23 +113,28 @@ export function __init__ (module) { export function __get__ (aThis, func, quotedFuncName) {// Param aThis is thing before the dot, if it's there if (aThis) { if (aThis.hasOwnProperty ('__class__') || typeof aThis == 'string' || aThis instanceof String) { // Object before the dot + var bound = function () { // Return bound function, code duplication for efficiency if no memoizing + var args = [] .slice.apply (arguments); // So multilayer search prototype, apply __get__, call curry func that calls func + return func.apply (null, [aThis.__proxy__ ? aThis.__proxy__ : aThis] .concat (args)); + }; + if (quotedFuncName) { // Memoize call since fcall is on, by installing bound function in instance + Object.defineProperty (bound, "name", {value:quotedFuncName}) + // copy addintional attributes + for(var n in func) { + bound[n] = func[n]; + } + bound.__repr__ = function() { + return "method {} of {}".format(quotedFuncName, repr(aThis)); }; + Object.defineProperty (aThis, quotedFuncName, { // Will override the non-own property, next time it will be called directly - value: function () { // So next time just call curry function that calls function - var args = [] .slice.apply (arguments); - return func.apply (null, [aThis] .concat (args)); - }, + value: bound, writable: true, enumerable: true, configurable: true }); } - var bound = function () { // Return bound function, code duplication for efficiency if no memoizing - var args = [] .slice.apply (arguments); // So multilayer search prototype, apply __get__, call curry func that calls func - return func.apply (null, [aThis.__proxy__ ? aThis.__proxy__ : aThis] .concat (args)); - }; - bound.__org__ = func - return bound + return bound; } else { // Class before the dot return func; // Return static method diff --git a/transcrypt/modules/org/transcrypt/compiler.py b/transcrypt/modules/org/transcrypt/compiler.py index 50af5e3f..82e6b6a4 100644 --- a/transcrypt/modules/org/transcrypt/compiler.py +++ b/transcrypt/modules/org/transcrypt/compiler.py @@ -2638,6 +2638,7 @@ def pushPropertyAccessor(functionName): isClassMethod = False isStaticMethod = False isProperty = False + keep_name = False getter = '__get__' if node.decorator_list: @@ -2693,6 +2694,7 @@ def pushPropertyAccessor(functionName): self.emit ('{}: ', self.filterId (nodeName)) else: self.emit ('get {} () {{return {} (this, ', self.filterId (nodeName), getter) + keep_name = True elif isGlobal: if type (node.parentNode) == ast.Module and not nodeName in self.allOwnNames: self.emit ('export ') @@ -2725,7 +2727,8 @@ def pushPropertyAccessor(functionName): if isStaticMethod: self.emit ('get {} () {{return {}function', self.filterId (nodeName), 'async ' if anAsync else '') else: - self.emit ('get {} () {{return {} (this, {}function', self.filterId (nodeName), getter, 'async ' if anAsync else '') + keep_name = True + self.emit ('get {} () {{return {} (this, ({}function', self.filterId (nodeName), getter, 'async ' if anAsync else '') elif isGlobal: if type (node.parentNode) == ast.Module and not nodeName in self.allOwnNames: self.emit ('export ') @@ -2768,6 +2771,11 @@ def pushPropertyAccessor(functionName): if decorate: self.emit (')' * decoratorsUsed) + if keep_name: + self.emit (', "{}"', self.filterId (nodeName)) + + elif keep_name: + self.emit ('), "{}"', self.filterId (nodeName)) if isMethod: if not jsCall: