Socket
Socket
Sign inDemoInstall

bson

Package Overview
Dependencies
0
Maintainers
8
Versions
161
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.0.0-alpha.0 to 6.0.0-alpha.1

2

package.json

@@ -17,3 +17,3 @@ {

"types": "bson.d.ts",
"version": "6.0.0-alpha.0",
"version": "6.0.0-alpha.1",
"author": {

@@ -20,0 +20,0 @@ "name": "The MongoDB NodeJS Team",

@@ -65,3 +65,3 @@ import type { Document } from './bson';

const codeJson = this.toJSON();
return `new Code("${String(codeJson.code)}"${
return `new Code(${JSON.stringify(String(codeJson.code))}${
codeJson.scope != null ? `, ${JSON.stringify(codeJson.scope)}` : ''

@@ -68,0 +68,0 @@ })`;

@@ -163,2 +163,3 @@ import { BSONValue } from './bson_value';

let isNegative = false;
let sawSign = false;
let sawRadix = false;

@@ -184,4 +185,2 @@ let foundNonZero = false;

let digitsInsert = 0;
// The index of the first non-zero digit
let firstDigit = 0;
// The index of the last digit

@@ -192,4 +191,2 @@ let lastDigit = 0;

let exponent = 0;
// loop index over array
let i = 0;
// The high 17 digits of the significand

@@ -247,2 +244,3 @@ let significandHigh = new Long(0, 0);

if (representation[index] === '+' || representation[index] === '-') {
sawSign = true;
isNegative = representation[index++] === '-';

@@ -270,3 +268,3 @@ }

if (nDigitsStored < 34) {
if (nDigitsStored < MAX_DIGITS) {
if (representation[index] !== '0' || foundNonZero) {

@@ -315,7 +313,3 @@ if (!foundNonZero) {

// Find first non-zero digit in digits
firstDigit = 0;
if (!nDigitsStored) {
firstDigit = 0;
lastDigit = 0;
digits[0] = 0;

@@ -329,3 +323,7 @@ nDigits = 1;

if (significantDigits !== 1) {
while (digits[firstNonZero + significantDigits - 1] === 0) {
while (
representation[
firstNonZero + significantDigits - 1 + Number(sawSign) + Number(sawRadix)
] === '0'
) {
significantDigits = significantDigits - 1;

@@ -341,3 +339,3 @@ }

// Overflow prevention
if (exponent <= radixPosition && radixPosition - exponent > 1 << 14) {
if (exponent <= radixPosition && radixPosition > exponent + (1 << 14)) {
exponent = EXPONENT_MIN;

@@ -352,7 +350,5 @@ } else {

lastDigit = lastDigit + 1;
if (lastDigit - firstDigit > MAX_DIGITS) {
if (lastDigit >= MAX_DIGITS) {
// Check if we have a zero then just hard clamp, otherwise fail
const digitsString = digits.join('');
if (digitsString.match(/^0+$/)) {
if (significantDigits === 0) {
exponent = EXPONENT_MAX;

@@ -369,12 +365,24 @@ break;

// Shift last digit. can only do this if < significant digits than # stored.
if (lastDigit === 0 && significantDigits < nDigitsStored) {
exponent = EXPONENT_MIN;
significantDigits = 0;
break;
if (lastDigit === 0) {
if (significantDigits === 0) {
exponent = EXPONENT_MIN;
break;
}
invalidErr(representation, 'exponent underflow');
}
if (nDigitsStored < nDigits) {
if (
representation[nDigits - 1 + Number(sawSign) + Number(sawRadix)] !== '0' &&
significantDigits !== 0
) {
invalidErr(representation, 'inexact rounding');
}
// adjust to match digits not stored
nDigits = nDigits - 1;
} else {
if (digits[lastDigit] !== 0) {
invalidErr(representation, 'inexact rounding');
}
// adjust to round

@@ -387,8 +395,2 @@ lastDigit = lastDigit - 1;

} else {
// Check if we have a zero then just hard clamp, otherwise fail
const digitsString = digits.join('');
if (digitsString.match(/^0+$/)) {
exponent = EXPONENT_MAX;
break;
}
invalidErr(representation, 'overflow');

@@ -400,5 +402,3 @@ }

// We've normalized the exponent, but might still need to round.
if (lastDigit - firstDigit + 1 < significantDigits) {
let endOfString = nDigitsRead;
if (lastDigit + 1 < significantDigits) {
// If we have seen a radix point, 'string' is 1 longer than we have

@@ -409,45 +409,13 @@ // documented with ndigits_read, so inc the position of the first nonzero

firstNonZero = firstNonZero + 1;
endOfString = endOfString + 1;
}
// if negative, we need to increment again to account for - sign at start.
if (isNegative) {
// if saw sign, we need to increment again to account for - or + sign at start.
if (sawSign) {
firstNonZero = firstNonZero + 1;
endOfString = endOfString + 1;
}
const roundDigit = parseInt(representation[firstNonZero + lastDigit + 1], 10);
let roundBit = 0;
if (roundDigit >= 5) {
roundBit = 1;
if (roundDigit === 5) {
roundBit = digits[lastDigit] % 2 === 1 ? 1 : 0;
for (i = firstNonZero + lastDigit + 2; i < endOfString; i++) {
if (parseInt(representation[i], 10)) {
roundBit = 1;
break;
}
}
}
if (roundDigit !== 0) {
invalidErr(representation, 'inexact rounding');
}
if (roundBit) {
let dIdx = lastDigit;
for (; dIdx >= 0; dIdx--) {
if (++digits[dIdx] > 9) {
digits[dIdx] = 0;
// overflowed most significant digit
if (dIdx === 0) {
if (exponent < EXPONENT_MAX) {
exponent = exponent + 1;
digits[dIdx] = 1;
} else {
return new Decimal128(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER);
}
}
}
}
}
}

@@ -465,4 +433,4 @@

significandLow = Long.fromNumber(0);
} else if (lastDigit - firstDigit < 17) {
let dIdx = firstDigit;
} else if (lastDigit < 17) {
let dIdx = 0;
significandLow = Long.fromNumber(digits[dIdx++]);

@@ -476,3 +444,3 @@ significandHigh = new Long(0, 0);

} else {
let dIdx = firstDigit;
let dIdx = 0;
significandHigh = Long.fromNumber(digits[dIdx++]);

@@ -479,0 +447,0 @@

@@ -37,3 +37,3 @@ import { BSONValue } from './bson_value';

inspect(): string {
return `new BSONSymbol("${this.value}")`;
return `new BSONSymbol(${JSON.stringify(this.value)})`;
}

@@ -40,0 +40,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc