Skip to content

Commit

Permalink
fix(ios): removing eventlistener multiple times ourCallbackCount shou…
Browse files Browse the repository at this point in the history
…ld not be in negative value (#12339)

Fixes TIMOB-28267
  • Loading branch information
vijaysingh-axway committed Dec 16, 2020
1 parent aa9c9b4 commit 798bd54
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -800,10 +800,10 @@ - (void)removeEventListener:(NSArray *)args

//TODO: You know, we can probably nip this in the bud and do this at a lower level,
//Or make this less onerous.
int ourCallbackCount = 0;

pthread_rwlock_wrlock(&listenerLock);
ourCallbackCount = [[listeners objectForKey:type] intValue] - 1;
int ourCallbackCount = [[listeners objectForKey:type] intValue];
ourCallbackCount = MAX(0, ourCallbackCount - 1);
[listeners setObject:NUMINT(ourCallbackCount) forKey:type];
pthread_rwlock_unlock(&listenerLock);

Expand Down
18 changes: 18 additions & 0 deletions tests/Resources/ti.ui.window.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1125,4 +1125,22 @@ describe('Titanium.UI.Window', function () {
// ios took 1ms repeatedly
// so 1 second should be enough time.
});

it('TIMOB-28267 On removing event listener multiple times and adding once afterward, event should be fired', finish => {
const win = Ti.UI.createWindow({
backgroundColor: '#0000ff'
});

win.addEventListener('open', openListener);
win.removeEventListener('open', openListener);
win.removeEventListener('open', openListener);
win.removeEventListener('open', openListener);
win.addEventListener('open', openListener);

function openListener () {
win.removeEventListener('open', openListener);
finish();
}
win.open();
});
});

0 comments on commit 798bd54

Please sign in to comment.