msgpackr 1.7.0-beta1 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -177,6 +177,7 @@
177
177
  let result;
178
178
  if (currentUnpackr.randomAccessStructure && src[position] < 0x40 && src[position] >= 0x20 && readStruct) {
179
179
  result = readStruct(src, position, srcEnd, currentUnpackr);
180
+ src = null; // dispose of this so that recursive unpack calls don't save state
180
181
  if (!(options && options.lazy) && result)
181
182
  result = result.toJSON();
182
183
  position = srcEnd;
@@ -187,7 +188,7 @@
187
188
 
188
189
  if (position == srcEnd) {
189
190
  // finished reading this source, cleanup references
190
- if (currentStructures.restoreStructures)
191
+ if (currentStructures?.restoreStructures)
191
192
  restoreStructures();
192
193
  currentStructures = null;
193
194
  src = null;
@@ -242,7 +243,10 @@
242
243
  if (currentUnpackr.mapsAsObjects) {
243
244
  let object = {};
244
245
  for (let i = 0; i < token; i++) {
245
- object[readKey()] = read();
246
+ let key = readKey();
247
+ if (key === '__proto__')
248
+ key = '__proto_';
249
+ object[key] = read();
246
250
  }
247
251
  return object
248
252
  } else {
@@ -471,7 +475,7 @@
471
475
  // This initial function is quick to instantiate, but runs slower. After several iterations pay the cost to build the faster function
472
476
  if (readObject.count++ > inlineObjectReadThreshold) {
473
477
  let readObject = structure.read = (new Function('r', 'return function(){return ' + (currentUnpackr.freezeData ? 'Object.freeze' : '') +
474
- '({' + structure.map(key => validName.test(key) ? key + ':r()' : ('[' + JSON.stringify(key) + ']:r()')).join(',') + '})}'))(read);
478
+ '({' + structure.map(key => key === '__proto__' ? '__proto_:r()' : validName.test(key) ? key + ':r()' : ('[' + JSON.stringify(key) + ']:r()')).join(',') + '})}'))(read);
475
479
  if (structure.highByte === 0)
476
480
  structure.read = createSecondByteReader(firstId, structure.read);
477
481
  return readObject() // second byte is already read, if there is one so immediately read object
@@ -479,6 +483,8 @@
479
483
  let object = {};
480
484
  for (let i = 0, l = structure.length; i < l; i++) {
481
485
  let key = structure[i];
486
+ if (key === '__proto__')
487
+ key = '__proto_';
482
488
  object[key] = read();
483
489
  }
484
490
  if (currentUnpackr.freezeData)
@@ -590,7 +596,10 @@
590
596
  if (currentUnpackr.mapsAsObjects) {
591
597
  let object = {};
592
598
  for (let i = 0; i < length; i++) {
593
- object[readKey()] = read();
599
+ let key = readKey();
600
+ if (key === '__proto__')
601
+ key = '__proto_';
602
+ object[key] = read();
594
603
  }
595
604
  return object
596
605
  } else {