msgpackr 1.7.0-beta1 → 1.7.1
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 +23 -12
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +54 -54
- package/dist/index.min.js.map +1 -1
- package/dist/node.cjs +78 -40
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +106 -40
- package/dist/test.js.map +1 -1
- package/index.d.ts +62 -14
- package/pack.d.ts +1 -9
- package/pack.js +9 -9
- package/package.json +8 -3
- package/struct.js +55 -28
- package/unpack.d.ts +2 -53
- package/unpack.js +14 -6
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 && currentStructures.restoreStructures)
|
|
191
192
|
restoreStructures();
|
|
192
193
|
currentStructures = null;
|
|
193
194
|
src = null;
|
|
@@ -202,7 +203,7 @@
|
|
|
202
203
|
// else more to read, but we are reading sequentially, so don't clear source yet
|
|
203
204
|
return result
|
|
204
205
|
} catch(error) {
|
|
205
|
-
if (currentStructures
|
|
206
|
+
if (currentStructures && currentStructures.restoreStructures)
|
|
206
207
|
restoreStructures();
|
|
207
208
|
clearSource();
|
|
208
209
|
if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position > srcEnd) {
|
|
@@ -242,7 +243,10 @@
|
|
|
242
243
|
if (currentUnpackr.mapsAsObjects) {
|
|
243
244
|
let object = {};
|
|
244
245
|
for (let i = 0; i < token; i++) {
|
|
245
|
-
|
|
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
|
-
|
|
599
|
+
let key = readKey();
|
|
600
|
+
if (key === '__proto__')
|
|
601
|
+
key = '__proto_';
|
|
602
|
+
object[key] = read();
|
|
594
603
|
}
|
|
595
604
|
return object
|
|
596
605
|
} else {
|
|
@@ -1177,12 +1186,11 @@
|
|
|
1177
1186
|
writeStruct(value);
|
|
1178
1187
|
else
|
|
1179
1188
|
pack(value);
|
|
1180
|
-
if (bundledStrings$1) {
|
|
1181
|
-
writeBundles(start, pack);
|
|
1182
|
-
}
|
|
1183
|
-
packr.offset = position$1; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
|
|
1184
1189
|
if (referenceMap && referenceMap.idsToInsert) {
|
|
1185
|
-
|
|
1190
|
+
let incrementPosition = referenceMap.idsToInsert.length * 6;
|
|
1191
|
+
if (bundledStrings$1)
|
|
1192
|
+
writeBundles(start, pack, incrementPosition);
|
|
1193
|
+
position$1 += incrementPosition;
|
|
1186
1194
|
if (position$1 > safeEnd)
|
|
1187
1195
|
makeRoom(position$1);
|
|
1188
1196
|
packr.offset = position$1;
|
|
@@ -1190,6 +1198,9 @@
|
|
|
1190
1198
|
referenceMap = null;
|
|
1191
1199
|
return serialized
|
|
1192
1200
|
}
|
|
1201
|
+
if (bundledStrings$1)
|
|
1202
|
+
writeBundles(start, pack, 0);
|
|
1203
|
+
packr.offset = position$1; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
|
|
1193
1204
|
if (encodeOptions & REUSE_BUFFER_MODE) {
|
|
1194
1205
|
target.start = start;
|
|
1195
1206
|
target.end = position$1;
|
|
@@ -1957,9 +1968,9 @@
|
|
|
1957
1968
|
return serialized
|
|
1958
1969
|
}
|
|
1959
1970
|
|
|
1960
|
-
function writeBundles(start, pack) {
|
|
1971
|
+
function writeBundles(start, pack, incrementPosition) {
|
|
1961
1972
|
if (bundledStrings$1.length > 0) {
|
|
1962
|
-
targetView.setUint32(bundledStrings$1.position + start, position$1 - bundledStrings$1.position - start);
|
|
1973
|
+
targetView.setUint32(bundledStrings$1.position + start, position$1 + incrementPosition - bundledStrings$1.position - start);
|
|
1963
1974
|
let writeStrings = bundledStrings$1;
|
|
1964
1975
|
bundledStrings$1 = null;
|
|
1965
1976
|
pack(writeStrings[0]);
|