I would add bv->IsFunction() and proto->IsObject() sanity checks here.