cbor-x 1.5.2 → 1.5.4
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/decode.js +12 -1
- package/dist/decode-no-eval.cjs +12 -1
- package/dist/decode-no-eval.cjs.map +1 -1
- package/dist/index-no-eval.cjs +21 -3
- package/dist/index-no-eval.cjs.map +1 -1
- package/dist/index-no-eval.min.js +1 -1
- package/dist/index-no-eval.min.js.map +1 -1
- package/dist/index.js +20 -3
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/node.cjs +20 -3
- package/dist/node.cjs.map +1 -1
- package/encode.js +9 -2
- package/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -34,6 +34,16 @@
|
|
|
34
34
|
mapsAsObjects: true
|
|
35
35
|
};
|
|
36
36
|
let sequentialMode = false;
|
|
37
|
+
let inlineObjectReadThreshold = 2;
|
|
38
|
+
// no-eval build
|
|
39
|
+
try {
|
|
40
|
+
new Function('');
|
|
41
|
+
} catch(error) {
|
|
42
|
+
// if eval variants are not supported, do not create inline object readers ever
|
|
43
|
+
inlineObjectReadThreshold = Infinity;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
37
47
|
|
|
38
48
|
class Decoder {
|
|
39
49
|
constructor(options) {
|
|
@@ -464,7 +474,7 @@
|
|
|
464
474
|
return compiledReader(read) // with the right length, so we use it
|
|
465
475
|
compiledReader = compiledReader.next; // see if there is another reader with the right length
|
|
466
476
|
}
|
|
467
|
-
if (this.slowReads++ >=
|
|
477
|
+
if (this.slowReads++ >= inlineObjectReadThreshold) { // create a fast compiled reader
|
|
468
478
|
let array = this.length == length ? this : this.slice(0, length);
|
|
469
479
|
compiledReader = currentDecoder.keyMap
|
|
470
480
|
? new Function('r', 'return {' + array.map(k => currentDecoder.decodeKey(k)).map(k => validName.test(k) ? safeKey(k) + ':r()' : ('[' + JSON.stringify(k) + ']:r()')).join(',') + '}')
|
|
@@ -1092,7 +1102,7 @@
|
|
|
1092
1102
|
textEncoder = new TextEncoder();
|
|
1093
1103
|
} catch (error) {}
|
|
1094
1104
|
let extensions, extensionClasses;
|
|
1095
|
-
const Buffer$1 = globalThis.Buffer;
|
|
1105
|
+
const Buffer$1 = typeof globalThis === 'object' && globalThis.Buffer;
|
|
1096
1106
|
const hasNodeBuffer = typeof Buffer$1 !== 'undefined';
|
|
1097
1107
|
const ByteArrayAllocate = hasNodeBuffer ? Buffer$1.allocUnsafeSlow : Uint8Array;
|
|
1098
1108
|
const ByteArray = hasNodeBuffer ? Buffer$1 : Uint8Array;
|
|
@@ -1643,6 +1653,13 @@
|
|
|
1643
1653
|
error.iteratorNotHandled = true;
|
|
1644
1654
|
throw error;
|
|
1645
1655
|
}
|
|
1656
|
+
if (this.useToJSON && value.toJSON) {
|
|
1657
|
+
const json = value.toJSON();
|
|
1658
|
+
// if for some reason value.toJSON returns itself it'll loop forever
|
|
1659
|
+
if (json !== value)
|
|
1660
|
+
return encode(json)
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1646
1663
|
// no extension found, write as object
|
|
1647
1664
|
writeObject(value, !value.hasOwnProperty); // if it doesn't have hasOwnProperty, don't do hasOwnProperty checks
|
|
1648
1665
|
}
|
|
@@ -1696,7 +1713,7 @@
|
|
|
1696
1713
|
}
|
|
1697
1714
|
if (encoder.keyMap) {
|
|
1698
1715
|
for (let i = 0; i < length; i++) {
|
|
1699
|
-
encode(encodeKey(keys[i]));
|
|
1716
|
+
encode(encoder.encodeKey(keys[i]));
|
|
1700
1717
|
encode(vals[i]);
|
|
1701
1718
|
}
|
|
1702
1719
|
} else {
|