bson 6.10.2 → 6.10.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/lib/bson.mjs CHANGED
@@ -48,7 +48,7 @@ function getStylizeFunction(options) {
48
48
  const BSON_MAJOR_VERSION = 6;
49
49
  const BSON_VERSION_SYMBOL = Symbol.for('@@mdb.bson.version');
50
50
  const BSON_INT32_MAX = 0x7fffffff;
51
- const BSON_INT32_MIN = -0x80000000;
51
+ const BSON_INT32_MIN = -2147483648;
52
52
  const BSON_INT64_MAX = Math.pow(2, 63) - 1;
53
53
  const BSON_INT64_MIN = -Math.pow(2, 63);
54
54
  const JS_INT_MAX = Math.pow(2, 53);
@@ -482,9 +482,15 @@ const NumberUtils = {
482
482
  source[offset] * 16777216);
483
483
  },
484
484
  getBigInt64LE(source, offset) {
485
- const lo = NumberUtils.getUint32LE(source, offset);
486
- const hi = NumberUtils.getUint32LE(source, offset + 4);
487
- return (BigInt(hi) << BigInt(32)) + BigInt(lo);
485
+ const hi = BigInt(source[offset + 4] +
486
+ source[offset + 5] * 256 +
487
+ source[offset + 6] * 65536 +
488
+ (source[offset + 7] << 24));
489
+ const lo = BigInt(source[offset] +
490
+ source[offset + 1] * 256 +
491
+ source[offset + 2] * 65536 +
492
+ source[offset + 3] * 16777216);
493
+ return (hi << BigInt(32)) + lo;
488
494
  },
489
495
  getFloat64LE: isBigEndian
490
496
  ? (source, offset) => {
@@ -1185,7 +1191,7 @@ class Long extends BSONValue {
1185
1191
  return Long.MAX_UNSIGNED_VALUE;
1186
1192
  }
1187
1193
  else {
1188
- if (value <= -TWO_PWR_63_DBL)
1194
+ if (value <= -9223372036854776e3)
1189
1195
  return Long.MIN_VALUE;
1190
1196
  if (value + 1 >= TWO_PWR_63_DBL)
1191
1197
  return Long.MAX_VALUE;
@@ -1344,7 +1350,7 @@ class Long extends BSONValue {
1344
1350
  throw new BSONError('division by zero');
1345
1351
  if (wasm) {
1346
1352
  if (!this.unsigned &&
1347
- this.high === -0x80000000 &&
1353
+ this.high === -2147483648 &&
1348
1354
  divisor.low === -1 &&
1349
1355
  divisor.high === -1) {
1350
1356
  return this;
@@ -3099,9 +3105,8 @@ function deserializeObject(buffer, index, options, isArray = false) {
3099
3105
  throw new BSONError('corrupt bson message');
3100
3106
  const object = isArray ? [] : {};
3101
3107
  let arrayIndex = 0;
3102
- const done = false;
3103
3108
  let isPossibleDBRef = isArray ? false : null;
3104
- while (!done) {
3109
+ while (true) {
3105
3110
  const elementType = buffer[index++];
3106
3111
  if (elementType === 0)
3107
3112
  break;
@@ -3849,8 +3854,8 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
3849
3854
  done = !!entry.done;
3850
3855
  if (done)
3851
3856
  continue;
3852
- const key = entry.value[0];
3853
- let value = entry.value[1];
3857
+ const key = entry.value ? entry.value[0] : undefined;
3858
+ let value = entry.value ? entry.value[1] : undefined;
3854
3859
  if (typeof value?.toBSON === 'function') {
3855
3860
  value = value.toBSON();
3856
3861
  }