lightweight tree traversal for javascript