Wouldn't it be better if the return is just a list of either the result (in the case that the value of a KV pair matches), or a reference to the result (in the case that the key of a KV pair matches)?
Actually it does mark visited objects to avoid cycles in its search. The default depth limit prevents it from taking too long on huge dom objects, but the choice of an arbitrary depth limit (of 5) does seem kind of gross. I'm open to suggestions for improvement.