Added safe to-JS serializer.