Skip to content

buffer: make byteLength throw on invalid input

Checklist
  • make -j8 test (UNIX), or vcbuild test nosign (Windows) passes
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)
  • buffer
Description of change

This makes buffer.byteLength() throw if the first argument passed to it is not a Buffer/TypedArray/etc. or string, instead of converting the value to string and calculating the length of that string.

If other values are being passed, IMHO that could signal a programming error. For example, if an undefined value is passed in, I would not expect to get 'undefined'.length returned. If undefined is passed in, it probably means I have a bug in my code somewhere where a variable isn't being set (properly).

CI: https://ci.nodejs.org/job/node-test-pull-request/4404/ CITGM: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/403/

Merge request reports

Loading