| 1016 | |
| 1017 | |
| 1018 | def test_forEach_self_pymethod(): |
| 1019 | items = ['Four', 'Three', 'One'] |
| 1020 | |
| 1021 | class Counter: |
| 1022 | def __init__(self): |
| 1023 | self.count = 0 |
| 1024 | |
| 1025 | def increment(self, element, index, array): |
| 1026 | self.count += 1 |
| 1027 | |
| 1028 | obj = Counter() |
| 1029 | assert obj.count == 0 |
| 1030 | result = pm.eval(""" |
| 1031 | (arr, increment, result) => { |
| 1032 | let jsObj = {count: 0} |
| 1033 | arr.forEach(increment, jsObj); |
| 1034 | return jsObj.count; |
| 1035 | } |
| 1036 | """)(items, obj.increment) |
| 1037 | assert obj.count == 0 |
| 1038 | assert result == 3 |
| 1039 | |
| 1040 | |
| 1041 | def test_forEach_self_pyfunction(): |