| 1202 | |
| 1203 | |
| 1204 | def test_map_self_pymethod(): |
| 1205 | items = ['Four', 'Three', 'One'] |
| 1206 | |
| 1207 | class Counter: |
| 1208 | def __init__(self): |
| 1209 | self.count = 0 |
| 1210 | |
| 1211 | def increment(self, element, index, array): |
| 1212 | self.count += 1 |
| 1213 | |
| 1214 | obj = Counter() |
| 1215 | assert obj.count == 0 |
| 1216 | result = pm.eval(""" |
| 1217 | (arr, increment, result) => { |
| 1218 | let jsObj = {count: 0} |
| 1219 | arr.map(increment, jsObj); |
| 1220 | return jsObj.count; |
| 1221 | } |
| 1222 | """)(items, obj.increment) |
| 1223 | assert obj.count == 0 |
| 1224 | assert result == 3 |
| 1225 | |
| 1226 | |
| 1227 | def test_map_self_pyfunction(): |