TooTallNate / ref

Turn Buffer instances into "pointers"
http://tootallnate.github.com/ref
453 stars 141 forks source link

Avoid problems when required twice #76

Closed vbfox closed 6 years ago

vbfox commented 7 years ago

It's possible due to test runners like jest playing with the node runtime object.

The native module can't be required twice but the javascript one can. As the javascript one return a mutated version of the native one it create problems :

exports._writePointer = exports.writePointer

exports.writePointer = function writePointer (buf, offset, ptr) {
  debug('writing pointer to buffer', buf, offset, ptr)
  exports._writePointer(buf, offset, ptr)
  exports._attach(buf, ptr)
}

After 2+ executions of this code writePointer would call itself and produce a stack overflow exception.

Additional info