cbor-x 1.5.1 → 1.5.3

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
@@ -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++ >= 3) { // create a fast compiled reader
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(',') + '}')
@@ -945,9 +955,11 @@
945
955
  }
946
956
  function registerTypedArray(TypedArray, tag) {
947
957
  let dvMethod = 'get' + TypedArray.name.slice(0, -5);
948
- if (typeof TypedArray !== 'function')
958
+ let bytesPerElement;
959
+ if (typeof TypedArray === 'function')
960
+ bytesPerElement = TypedArray.BYTES_PER_ELEMENT;
961
+ else
949
962
  TypedArray = null;
950
- let bytesPerElement = TypedArray.BYTES_PER_ELEMENT;
951
963
  for (let littleEndian = 0; littleEndian < 2; littleEndian++) {
952
964
  if (!littleEndian && bytesPerElement == 1)
953
965
  continue
@@ -1090,7 +1102,7 @@
1090
1102
  textEncoder = new TextEncoder();
1091
1103
  } catch (error) {}
1092
1104
  let extensions, extensionClasses;
1093
- const Buffer$1 = globalThis.Buffer;
1105
+ const Buffer$1 = typeof globalThis === 'object' && globalThis.Buffer;
1094
1106
  const hasNodeBuffer = typeof Buffer$1 !== 'undefined';
1095
1107
  const ByteArrayAllocate = hasNodeBuffer ? Buffer$1.allocUnsafeSlow : Uint8Array;
1096
1108
  const ByteArray = hasNodeBuffer ? Buffer$1 : Uint8Array;
@@ -1481,7 +1493,7 @@
1481
1493
  }
1482
1494
  position += length;
1483
1495
  } else if (type === 'number') {
1484
- if (value >>> 0 === value) {// positive integer, 32-bit or less
1496
+ if (!this.alwaysUseFloat && value >>> 0 === value) {// positive integer, 32-bit or less
1485
1497
  // positive uint
1486
1498
  if (value < 0x18) {
1487
1499
  target[position++] = value;
@@ -1497,7 +1509,7 @@
1497
1509
  targetView.setUint32(position, value);
1498
1510
  position += 4;
1499
1511
  }
1500
- } else if (value >> 0 === value) { // negative integer
1512
+ } else if (!this.alwaysUseFloat && value >> 0 === value) { // negative integer
1501
1513
  if (value >= -0x18) {
1502
1514
  target[position++] = 0x1f - value;
1503
1515
  } else if (value >= -0x100) {