oboe.js icon indicating copy to clipboard operation
oboe.js copied to clipboard

length of undefined error during parsing

Open sserdyuk opened this issue 3 years ago • 0 comments

I have stumbled on this issue today. It has something to do with one specific file that triggers that branch in the logic. Other files seem to work just fine. For this reason I am not able to present a sandbox with an example. Luckily, the problem is very easy to see. It is in the checkBufferLength method of the clarinet.js file. If the conditions is right and the emitError('Max buffer length exceeded: textNode') code is executed, the emitError method resets the textNode value and the following line maxActual = Math.max(maxActual, textNode.length) fails with an error.

The most obvious solution would be to simply swap these two lines around.

function checkBufferLength () {
    var maxActual = 0

    if (textNode !== undefined && textNode.length > MAX_BUFFER_LENGTH) {
      emitError('Max buffer length exceeded: textNode')
      maxActual = Math.max(maxActual, textNode.length)
    }
    if (numberNode.length > MAX_BUFFER_LENGTH) {
      emitError('Max buffer length exceeded: numberNode')
      maxActual = Math.max(maxActual, numberNode.length)
    }

    bufferCheckPosition = (MAX_BUFFER_LENGTH - maxActual) +
      position
  }

https://github.com/jimhigson/oboe.js/blob/52d150dd78b20205bd26d63c807ac170c03f0f64/dist/oboe-browser.js#L2381-L2384

sserdyuk avatar Sep 14 '21 02:09 sserdyuk