Problem is in de splice call "len":
remove () {
self._hookAspects[method][pointcut].splice(len - 1, 1)
Len was stored when inserting the hook in the array. However due to the removal of the first hook, the second hook became first in the list. Therefore it will not get removed.
Simple node example showing the issue:
n=[]
[]
n.push(1) -> add first hook
1 -> internally stored len
n.push(2) -> add second hook
2 -> internally stored len
n --> self._hookAspects[method][pointcut]
[ 1, 2 ]
n.splice(0,1) --> len-1, 1
[ 1 ] -> 1 is removed
n
[ 2 ]
n.splice(1,1) --> len-1, 1
[] -> nothing is removed
n -> second hook still in the list...
[ 2 ]
Actually the fun start when adding and removing hooks in various orders then one hook actually removed the wrong hook! which is causing me to not use remove any longer, only use replace! which is a safe workaround if it works for your application.
To repoduce:
Problem is in de splice call "len": remove () { self._hookAspects[method][pointcut].splice(len - 1, 1)
Len was stored when inserting the hook in the array. However due to the removal of the first hook, the second hook became first in the list. Therefore it will not get removed.
Simple node example showing the issue:
Actually the fun start when adding and removing hooks in various orders then one hook actually removed the wrong hook! which is causing me to not use remove any longer, only use replace! which is a safe workaround if it works for your application.