Fixed bug for prunning with JS code

Added the case in traverse method for prunning based on an arbitrary Javascript code.