Skip to content

Commit a34354d

Browse files
committed
Autotest added for call chaining on proxies
1 parent 8aea2c1 commit a34354d

File tree

3 files changed

+64
-277
lines changed

3 files changed

+64
-277
lines changed

transcrypt/development/automated_tests/transcrypt/proxies/__init__.py

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,65 @@ class D (B, C):
8080
d.q = 9
8181
d.r = 10
8282
d.s = 11
83-
autoTester.check (d.p, d.q, d.r, d.s)
83+
autoTester.check (d.p, d.q, d.r, d.s)
84+
85+
# Issue 587, code as utilized by pjbonestro
86+
87+
autoTester.check ("Issue 587")
88+
89+
class Element():
90+
def __init__(self):
91+
self.message = "Goodbye"
92+
93+
def sayBye(self):
94+
autoTester.check (self.message)
95+
96+
class Wrapper():
97+
def __init__ (self, element):
98+
self.element = element
99+
100+
def __setattr__ (self, name, value):
101+
""" set attribute on element if it already has the attribute """
102+
if name != "element" and hasattr(self.element, name):
103+
setattr(self.element, name, value)
104+
else:
105+
self.__dict__[name] = value
106+
107+
def __getattr__ (self, name):
108+
""" get attribute from element if this object doesn't have the attribute """
109+
result = getattr(self.element, name)
110+
# if result is a function, bind self.element to it
111+
if hasattr(result, 'call') and hasattr(result, 'bind'):
112+
result = result.bind(self.element)
113+
return result
114+
115+
def sayHello(self):
116+
autoTester.check("Hello")
117+
return self
118+
119+
120+
e = Element()
121+
w = Wrapper(e)
122+
123+
#
124+
# Usage
125+
#
126+
127+
e.sayBye()
128+
w.sayBye() # call functions on e, using w
129+
130+
# and method chaining should work:
131+
w.sayHello().sayBye()
132+
133+
w.message = "Bye" # set attributes on e, using w
134+
135+
e.sayBye()
136+
w.sayBye() # call functions on e, using w
137+
138+
# and method chaining should work:
139+
w.sayHello().sayBye()
140+
141+
autoTester.check ("End issue 587")
142+
143+
# End of issue 587
144+

transcrypt/modules/org/transcrypt/BROKEN__core__.js

Lines changed: 0 additions & 274 deletions
This file was deleted.

transcrypt/modules/org/transcrypt/__core__.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export function __get__ (aThis, func, quotedFuncName) {// Param aThis is thing b
117117
Object.defineProperty (aThis, quotedFuncName, { // Will override the non-own property, next time it will be called directly
118118
value: function () { // So next time just call curry function that calls function
119119
var args = [] .slice.apply (arguments);
120-
return func.apply (null, [aThis.__proxy__ ? aThis.__proxy__ : aThis] .concat (args));
120+
return func.apply (null, [aThis] .concat (args));
121121
},
122122
writable: true,
123123
enumerable: true,
@@ -126,7 +126,7 @@ export function __get__ (aThis, func, quotedFuncName) {// Param aThis is thing b
126126
}
127127
return function () { // Return bound function, code duplication for efficiency if no memoizing
128128
var args = [] .slice.apply (arguments); // So multilayer search prototype, apply __get__, call curry func that calls func
129-
return func.apply (null, [aThis] .concat (args));
129+
return func.apply (null, [aThis.__proxy__ ? aThis.__proxy__ : aThis] .concat (args));
130130
};
131131
}
132132
else { // Class before the dot

0 commit comments

Comments
 (0)