fix issue #4930, by only calling offset() after checking vals.length