Commit 945fa918 authored by Xavier Guimard's avatar Xavier Guimard

Update upstream source from tag 'upstream/3.1.10+_3.1.9'

Update to upstream version '3.1.10+~3.1.9'
with Debian dir 867100ac53acd7d3038c9d23ad0748e621f704b4
parents 357336be 6df78e12
......@@ -2,6 +2,37 @@
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
<a name="3.1.10"></a>
## [3.1.10](https://github.com/mongodb/node-mongodb-native/compare/v3.1.9...v3.1.10) (2018-11-16)
### Bug Fixes
* **auth:** remember to default to admin database ([c7dec28](https://github.com/mongodb/node-mongodb-native/commit/c7dec28))
### Features
* **core:** update to mongodb-core v3.1.9 ([bd3355b](https://github.com/mongodb/node-mongodb-native/commit/bd3355b))
<a name="3.1.9"></a>
## [3.1.9](https://github.com/mongodb/node-mongodb-native/compare/v3.1.8...v3.1.9) (2018-11-06)
### Bug Fixes
* **db:** move db constants to other file to avoid circular ref ([#1858](https://github.com/mongodb/node-mongodb-native/issues/1858)) ([239036f](https://github.com/mongodb/node-mongodb-native/commit/239036f))
* **estimated-document-count:** support options other than maxTimeMs ([36c3c7d](https://github.com/mongodb/node-mongodb-native/commit/36c3c7d))
### Features
* **core:** update to mongodb-core v3.1.8 ([80d7c79](https://github.com/mongodb/node-mongodb-native/commit/80d7c79))
<a name="3.1.8"></a>
## [3.1.8](https://github.com/mongodb/node-mongodb-native/compare/v3.1.7...v3.1.8) (2018-10-10)
......
......@@ -211,7 +211,7 @@ The application should print **Connected successfully to server** to the console
### Insert a Document
Add to **app.js** the following function which uses the **insertMany**
method to add three documents to the **documents** collection.
method to add three documents to the **documents** collection.
```js
const insertDocuments = function(db, callback) {
......@@ -354,7 +354,7 @@ const updateDocument = function(db, callback) {
assert.equal(1, result.result.n);
console.log("Updated the document with the field a equal to 2");
callback(result);
});
});
}
```
......@@ -399,7 +399,7 @@ const removeDocument = function(db, callback) {
assert.equal(1, result.result.n);
console.log("Removed the document with the field a equal to 3");
callback(result);
});
});
}
```
......@@ -484,3 +484,10 @@ For more detailed information, see the [tutorials](docs/reference/content/tutori
* [MongoDB Documentation](http://mongodb.org)
* [Read about Schemas](http://learnmongodbthehardway.com)
* [Star us on GitHub](https://github.com/mongodb/node-mongodb-native)
## License
[Apache 2.0](LICENSE.md)
© 2009-2012 Christian Amor Kvalheim
© 2012-present MongoDB [Contributors](CONTRIBUTORS.md)
<a name="3.0.2"></a>
## [3.0.2](https://github.com/mongodb/js-bson/compare/v3.0.1...v3.0.2) (2018-07-13)
<a name="1.1.0"></a>
# [1.1.0](https://github.com/mongodb/js-bson/compare/v1.0.9...v1.1.0) (2018-08-13)
### Bug Fixes
* **revert:** Reverting v3.0.1 ([efb0720](https://github.com/mongodb/js-bson/commit/efb0720))
* **serializer:** do not use checkKeys for $clusterTime ([573e141](https://github.com/mongodb/js-bson/commit/573e141))
<a name="3.0.0"></a>
# [3.0.0](https://github.com/mongodb/js-bson/compare/v2.0.8...v3.0.0) (2018-06-13)
### Features
* **ObjectID:** use FNV-1a hash for objectId ([4f545b1](https://github.com/mongodb/js-bson/commit/4f545b1))
* **rollup:** initial commit of rollup-generated bundle ([474b8f7](https://github.com/mongodb/js-bson/commit/474b8f7))
* **rollup:** switch from webpack to rollup for bundling ([98068fa](https://github.com/mongodb/js-bson/commit/98068fa))
<a name="2.0.8"></a>
## [2.0.8](https://github.com/mongodb/js-bson/compare/v2.0.7...v2.0.8) (2018-06-06)
### Bug Fixes
* **readme:** clarify documentation about deserialize methods ([e311056](https://github.com/mongodb/js-bson/commit/e311056))
* **serialization:** normalize function stringification ([21eb0b0](https://github.com/mongodb/js-bson/commit/21eb0b0))
<a name="2.0.7"></a>
## [2.0.7](https://github.com/mongodb/js-bson/compare/v2.0.6...v2.0.7) (2018-05-31)
### Bug Fixes
* **binary:** add type checking for buffer ([cbfb25d](https://github.com/mongodb/js-bson/commit/cbfb25d))
<a name="2.0.6"></a>
## [2.0.6](https://github.com/mongodb/js-bson/compare/v2.0.5...v2.0.6) (2018-04-27)
<a name="1.0.9"></a>
## [1.0.9](https://github.com/mongodb/js-bson/compare/v1.0.8...v1.0.9) (2018-06-07)
### Bug Fixes
* **deserializeStream:** allow multiple documents to be deserialized ([6fc5984](https://github.com/mongodb/js-bson/commit/6fc5984)), closes [#244](https://github.com/mongodb/js-bson/issues/244)
* **serializer:** remove use of `const` ([5feb12f](https://github.com/mongodb/js-bson/commit/5feb12f))
<a name="2.0.5"></a>
## [2.0.5](https://github.com/mongodb/js-bson/compare/v2.0.4...v2.0.5) (2018-04-06)
<a name="1.0.7"></a>
## [1.0.7](https://github.com/mongodb/js-bson/compare/v1.0.6...v1.0.7) (2018-06-06)
### Bug Fixes
* **regexp:** properly construct new BSONRegExp when constructor called without new ([#242](https://github.com/mongodb/js-bson/issues/242)) ([93ae799](https://github.com/mongodb/js-bson/commit/93ae799))
* **binary:** add type checking for buffer ([26b05b5](https://github.com/mongodb/js-bson/commit/26b05b5))
* **bson:** fix custom inspect property ([080323b](https://github.com/mongodb/js-bson/commit/080323b))
* **readme:** clarify documentation about deserialize methods ([20f764c](https://github.com/mongodb/js-bson/commit/20f764c))
* **serialization:** normalize function stringification ([1320c10](https://github.com/mongodb/js-bson/commit/1320c10))
<a name="2.0.4"></a>
## [2.0.4](https://github.com/mongodb/js-bson/compare/v2.0.3...v2.0.4) (2018-03-12)
<a name="2.0.3"></a>
## [2.0.3](https://github.com/mongodb/js-bson/compare/v2.0.2...v2.0.3) (2018-03-12)
### Features
* **serialization:** support arbitrary sizes for the internal serialization buffer ([a6bd45c](https://github.com/mongodb/js-bson/commit/a6bd45c))
<a name="2.0.2"></a>
## [2.0.2](https://github.com/mongodb/js-bson/compare/v2.0.1...v2.0.2) (2018-03-02)
### Bug Fixes
* make sure all functions are named consistently ([6df9022](https://github.com/mongodb/js-bson/commit/6df9022))
<a name="2.0.1"></a>
## [2.0.1](https://github.com/mongodb/js-bson/compare/v2.0.0...v2.0.1) (2018-02-28)
### Bug Fixes
* **serializer:** ensure RegExp options are alphabetically sorted ([d60659d](https://github.com/mongodb/js-bson/commit/d60659d))
<a name="1.0.6"></a>
## [1.0.6](https://github.com/mongodb/js-bson/compare/v1.0.5...v1.0.6) (2018-03-12)
### Features
* **db-ref:** support passing a namespace into a DBRef ctor ([604831b](https://github.com/mongodb/js-bson/commit/604831b))
* **serialization:** support arbitrary sizes for the internal serialization buffer ([abe97bc](https://github.com/mongodb/js-bson/commit/abe97bc))
<a name="2.0.0"></a>
# 2.0.0 (2018-02-26)
<a name="1.0.5"></a>
## 1.0.5 (2018-02-26)
### Bug Fixes
* **browser:** fixing browser property in package.json ([095fba9](https://github.com/mongodb/js-bson/commit/095fba9))
* **dbref:** only upgrade objects with allowed $keys to DBRefs ([98eb9e2](https://github.com/mongodb/js-bson/commit/98eb9e2))
* **decimal128:** add basic guard against REDOS attacks ([511ecc4](https://github.com/mongodb/js-bson/commit/511ecc4))
* **Decimal128:** update toString and fromString methods to correctly handle the case of too many significant digits ([25ed43e](https://github.com/mongodb/js-bson/commit/25ed43e))
* **decimal128:** add basic guard against REDOS attacks ([bd61c45](https://github.com/mongodb/js-bson/commit/bd61c45))
* **objectid:** if pid is 1, use random value ([e188ae6](https://github.com/mongodb/js-bson/commit/e188ae6))
* **serializeWithBufferAndIndex:** write documents to start of intermediate buffer ([b4e4ac5](https://github.com/mongodb/js-bson/commit/b4e4ac5))
......
......@@ -2,7 +2,7 @@
BSON is short for Bin­ary JSON and is the bin­ary-en­coded seri­al­iz­a­tion of JSON-like doc­u­ments. You can learn more about it in [the specification](http://bsonspec.org).
This browser version of the BSON parser is compiled using [rollup](https://rollupjs.org/) and the current version is pre-compiled in the `dist` directory.
This browser version of the BSON parser is compiled using [webpack](https://webpack.js.org/) and the current version is pre-compiled in the `browser_build` directory.
This is the default BSON parser, however, there is a C++ Node.js addon version as well that does not support the browser. It can be found at [mongod-js/bson-ext](https://github.com/mongodb-js/bson-ext).
......@@ -18,7 +18,7 @@ npm run build
A simple example of how to use BSON in the browser:
```html
<script src="./dist/bson.js"></script>
<script src="./browser_build/bson.js"></script>
<script>
function start() {
......@@ -68,7 +68,9 @@ console.log('doc_2:', doc_2)
### BSON types
For all BSON types documentation, please refer to the documentation for the [MongoDB Node.js driver](https://github.com/mongodb/node-mongodb-native).
For all BSON types documentation, please refer to the following sources:
* [MongoDB BSON Type Reference](https://docs.mongodb.com/manual/reference/bson-types/)
* [BSON Spec](https://bsonspec.org/)
### BSON serialization and deserialiation
......
......@@ -7,7 +7,7 @@
"parser"
],
"author": "Christian Amor Kvalheim <christkv@gmail.com>",
"main": "./dist/bson.js",
"main": "./browser_build/bson.js",
"license": "Apache-2.0",
"moduleType": [
"globals",
......
This diff is collapsed.
{ "name" : "bson"
, "description" : "A bson parser for node.js and the browser"
, "main": "../"
, "directories" : { "lib" : "../lib/bson" }
, "engines" : { "node" : ">=0.6.0" }
, "licenses" : [ { "type" : "Apache License, Version 2.0"
, "url" : "http://www.apache.org/licenses/LICENSE-2.0" } ]
}
This diff is collapsed.
'use strict';
/**
* Module dependencies.
* @ignore
......@@ -62,7 +60,7 @@ function Binary(buffer, subType) {
) {
this.buffer = writeStringToArray(buffer);
} else {
throw new TypeError('only String, Buffer, Uint8Array or Array accepted');
throw new Error('only String, Buffer, Uint8Array or Array accepted');
}
} else {
this.buffer = buffer;
......@@ -90,9 +88,9 @@ function Binary(buffer, subType) {
Binary.prototype.put = function put(byte_value) {
// If it's a string and a has more than one character throw an error
if (byte_value['length'] != null && typeof byte_value !== 'number' && byte_value.length !== 1)
throw new TypeError('only accepts single character String, Uint8Array or Array');
throw new Error('only accepts single character String, Uint8Array or Array');
if ((typeof byte_value !== 'number' && byte_value < 0) || byte_value > 255)
throw new TypeError('only accepts number in a valid unsigned byte range 0-255');
throw new Error('only accepts number in a valid unsigned byte range 0-255');
// Decode the byte value once
var decoded_byte = null;
......
......@@ -53,7 +53,7 @@ BSON.prototype.serialize = function serialize(object, options) {
typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true;
var minInternalBufferSize =
typeof options.minInternalBufferSize === 'number' ? options.minInternalBufferSize : MAXSIZE;
// Resize the internal serialization buffer if needed
if (buffer.length < minInternalBufferSize) {
buffer = new Buffer(minInternalBufferSize);
......@@ -102,18 +102,17 @@ BSON.prototype.serializeWithBufferAndIndex = function(object, finalBuffer, optio
// Attempt to serialize
var serializationIndex = serializer(
buffer,
finalBuffer,
object,
checkKeys,
0,
startIndex || 0,
0,
serializeFunctions,
ignoreUndefined
);
buffer.copy(finalBuffer, startIndex, 0, serializationIndex);
// Return the index
return startIndex + serializationIndex - 1;
return serializationIndex - 1;
};
/**
......@@ -128,7 +127,6 @@ BSON.prototype.serializeWithBufferAndIndex = function(object, finalBuffer, optio
* @param {Object} [options.promoteValues=false] when deserializing will promote BSON values to their Node.js closest equivalent types.
* @param {Object} [options.fieldsAsRaw=null] allow to specify if there what fields we wish to return as unserialized raw buffer.
* @param {Object} [options.bsonRegExp=false] return BSON regular expressions as BSONRegExp instances.
* @param {boolean} [options.allowObjectSmallerThanBufferSize=false] allows the buffer to be larger than the parsed BSON object
* @return {Object} returns the deserialized Javascript Object.
* @api public
*/
......@@ -184,7 +182,7 @@ BSON.prototype.deserializeStream = function(
docStartIndex,
options
) {
options = Object.assign({ allowObjectSmallerThanBufferSize: true }, options);
options = options != null ? options : {};
var index = startIndex;
// Loop over all documents
for (var i = 0; i < numberOfDocuments; i++) {
......@@ -192,7 +190,7 @@ BSON.prototype.deserializeStream = function(
var size =
data[index] | (data[index + 1] << 8) | (data[index + 2] << 16) | (data[index + 3] << 24);
// Update options with index
options.index = index;
options['index'] = index;
// Parse the document at this point
documents[docStartIndex + i] = this.deserialize(data, options);
// Adjust index by the document size
......
'use strict';
/**
* A class representation of the BSON Code type.
*
......@@ -8,12 +6,12 @@
* @param {Object} [scope] an optional scope for the function.
* @return {Code}
*/
function Code(code, scope) {
var Code = function Code(code, scope) {
if (!(this instanceof Code)) return new Code(code, scope);
this._bsontype = 'Code';
this.code = code;
this.scope = scope;
}
};
/**
* @ignore
......
'use strict';
/**
* A class representation of the BSON DBRef type.
*
* @class
* @param {string} collection the collection name.
* @param {string} namespace the collection name.
* @param {ObjectID} oid the reference ObjectID.
* @param {string} [db] optional db name, if omitted the reference is local to the current db.
* @return {DBRef}
*/
function DBRef(collection, oid, db, fields) {
if (!(this instanceof DBRef)) return new DBRef(collection, oid, db, fields);
// check if namespace has been provided
var parts = collection.split('.');
if (parts.length === 2) {
db = parts.shift();
collection = parts.shift();
}
function DBRef(namespace, oid, db) {
if (!(this instanceof DBRef)) return new DBRef(namespace, oid, db);
this._bsontype = 'DBRef';
this.collection = collection;
this.namespace = namespace;
this.oid = oid;
this.db = db;
this.fields = fields || {};
}
/**
......@@ -30,14 +21,11 @@ function DBRef(collection, oid, db, fields) {
* @api private
*/
DBRef.prototype.toJSON = function() {
var o = {
$ref: this.collection,
$id: this.oid
return {
$ref: this.namespace,
$id: this.oid,
$db: this.db == null ? '' : this.db
};
if (this.db != null) o.$db = this.db;
o = Object.assign(o, this.fields);
return o;
};
module.exports = DBRef;
......
'use strict';
let Long = require('./long');
var Long = require('./long');
var PARSE_STRING_REGEXP = /^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/;
var PARSE_INF_REGEXP = /^(\+|-)?(Infinity|inf)$/i;
......@@ -79,12 +79,13 @@ var isDigit = function(value) {
var divideu128 = function(value) {
var DIVISOR = Long.fromNumber(1000 * 1000 * 1000);
var _rem = Long.fromNumber(0);
var i = 0;
if (!value.parts[0] && !value.parts[1] && !value.parts[2] && !value.parts[3]) {
return { quotient: value, rem: _rem };
}
for (let i = 0; i <= 3; i++) {
for (i = 0; i <= 3; i++) {
// Adjust remainder to match value of next dividend
_rem = _rem.shiftLeft(32);
// Add the divided to _rem
......@@ -141,9 +142,34 @@ var lessThan = function(left, right) {
return false;
};
var invalidErr = function(string, message) {
throw new TypeError('"${string}" not a valid Decimal128 string - ' + message);
};
// var longtoHex = function(value) {
// var buffer = new Buffer(8);
// var index = 0;
// // Encode the low 64 bits of the decimal
// // Encode low bits
// buffer[index++] = value.low_ & 0xff;
// buffer[index++] = (value.low_ >> 8) & 0xff;
// buffer[index++] = (value.low_ >> 16) & 0xff;
// buffer[index++] = (value.low_ >> 24) & 0xff;
// // Encode high bits
// buffer[index++] = value.high_ & 0xff;
// buffer[index++] = (value.high_ >> 8) & 0xff;
// buffer[index++] = (value.high_ >> 16) & 0xff;
// buffer[index++] = (value.high_ >> 24) & 0xff;
// return buffer.reverse().toString('hex');
// };
// var int32toHex = function(value) {
// var buffer = new Buffer(4);
// var index = 0;
// // Encode the low 64 bits of the decimal
// // Encode low bits
// buffer[index++] = value & 0xff;
// buffer[index++] = (value >> 8) & 0xff;
// buffer[index++] = (value >> 16) & 0xff;
// buffer[index++] = (value >> 24) & 0xff;
// return buffer.reverse().toString('hex');
// };
/**
* A class representation of the BSON Decimal128 type.
......@@ -152,10 +178,10 @@ var invalidErr = function(string, message) {
* @param {Buffer} bytes a buffer containing the raw Decimal128 bytes.
* @return {Double}
*/
function Decimal128(bytes) {
var Decimal128 = function(bytes) {
this._bsontype = 'Decimal128';
this.bytes = bytes;
}
};
/**
* Create a Decimal128 instance from a string representation
......@@ -206,11 +232,14 @@ Decimal128.fromString = function(string) {
// Read index
var index = 0;
// Trim the string
string = string.trim();
// Naively prevent against REDOS attacks.
// TODO: implementing a custom parsing for this, or refactoring the regex would yield
// further gains.
if (string.length >= 7000) {
throw new TypeError('' + string + ' not a valid Decimal128 string');
throw new Error('' + string + ' not a valid Decimal128 string');
}
// Results
......@@ -220,30 +249,12 @@ Decimal128.fromString = function(string) {
// Validate the string
if ((!stringMatch && !infMatch && !nanMatch) || string.length === 0) {
throw new TypeError('' + string + ' not a valid Decimal128 string');
throw new Error('' + string + ' not a valid Decimal128 string');
}
if (stringMatch) {
// full_match = stringMatch[0]
// sign = stringMatch[1]
var unsignedNumber = stringMatch[2];
// stringMatch[3] is undefined if a whole number (ex "1", 12")
// but defined if a number w/ decimal in it (ex "1.0, 12.2")
var e = stringMatch[4];
var expSign = stringMatch[5];
var expNumber = stringMatch[6];
// they provided e, but didn't give an exponent number. for ex "1e"
if (e && expNumber === undefined) invalidErr(string, 'missing exponent power');
// they provided e, but didn't give a number before it. for ex "e1"
if (e && unsignedNumber === undefined) invalidErr(string, 'missing exponent base');
if (e === undefined && (expSign || expNumber)) {
invalidErr(string, 'missing e before exponent');
}
// Check if we have an illegal exponent format
if (stringMatch && stringMatch[4] && stringMatch[2] === undefined) {
throw new Error('' + string + ' not a valid Decimal128 string');
}
// Get the negative or positive sign
......@@ -263,7 +274,9 @@ Decimal128.fromString = function(string) {
// Read all the digits
while (isDigit(string[index]) || string[index] === '.') {
if (string[index] === '.') {
if (sawRadix) invalidErr(string, 'contains multiple periods');
if (sawRadix) {
return new Decimal128(new Buffer(NAN_BUFFER));
}
sawRadix = true;
index = index + 1;
......@@ -284,14 +297,21 @@ Decimal128.fromString = function(string) {
}
}
if (foundNonZero) nDigits = nDigits + 1;
if (sawRadix) radixPosition = radixPosition + 1;
if (foundNonZero) {
nDigits = nDigits + 1;
}
if (sawRadix) {
radixPosition = radixPosition + 1;
}
nDigitsRead = nDigitsRead + 1;
index = index + 1;
}
if (sawRadix && !nDigitsRead) throw new TypeError('' + string + ' not a valid Decimal128 string');
if (sawRadix && !nDigitsRead) {
throw new Error('' + string + ' not a valid Decimal128 string');
}
// Read exponent if exists
if (string[index] === 'e' || string[index] === 'E') {
......@@ -299,7 +319,9 @@ Decimal128.fromString = function(string) {
var match = string.substr(++index).match(EXPONENT_REGEX);
// No digits read
if (!match || !match[2]) return new Decimal128(new Buffer(NAN_BUFFER));
if (!match || !match[2]) {
return new Decimal128(new Buffer(NAN_BUFFER));
}
// Get exponent
exponent = parseInt(match[0], 10);
......@@ -309,7 +331,9 @@ Decimal128.fromString = function(string) {
}
// Return not a number
if (string[index]) return new Decimal128(new Buffer(NAN_BUFFER));
if (string[index]) {
return new Decimal128(new Buffer(NAN_BUFFER));
}
// Done reading input
// Find first non-zero digit in digits
......@@ -325,7 +349,8 @@ Decimal128.fromString = function(string) {
} else {
lastDigit = nDigitsStored - 1;
significantDigits = nDigits;
if (significantDigits !== 1) {
if (exponent !== 0 && significantDigits !== 1) {
while (string[firstNonZero + significantDigits - 1] === '0') {
significantDigits = significantDigits - 1;
}
......@@ -354,15 +379,17 @@ Decimal128.fromString = function(string) {
if (digitsString.match(/^0+$/)) {
exponent = EXPONENT_MAX;
break;
} else {
return new Decimal128(new Buffer(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER));
}
invalidErr(string, 'overflow');
}
exponent = exponent - 1;
}
while (exponent < EXPONENT_MIN || nDigitsStored < nDigits) {
// Shift last digit. can only do this if < significant digits than # stored.
if (lastDigit === 0 && significantDigits < nDigitsStored) {
// Shift last digit
if (lastDigit === 0) {
exponent = EXPONENT_MIN;
significantDigits = 0;
break;
......@@ -384,25 +411,21 @@ Decimal128.fromString = function(string) {
if (digitsString.match(/^0+$/)) {
exponent = EXPONENT_MAX;
break;
} else {
return new Decimal128(new Buffer(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER));
}
invalidErr(string, 'overflow');
}
}
// Round
// We've normalized the exponent, but might still need to round.
if (lastDigit - firstDigit + 1 < significantDigits) {
if (lastDigit - firstDigit + 1 < significantDigits && string[significantDigits] !== '0') {
var endOfString = nDigitsRead;
// If we have seen a radix point, 'string' is 1 longer than we have
// documented with ndigits_read, so inc the position of the first nonzero
// digit and the position that digits are read to.
if (sawRadix) {
firstNonZero = firstNonZero + 1;
endOfString = endOfString + 1;
}
// if negative, we need to increment again to account for - sign at start.
if (isNegative) {
if (sawRadix && exponent === EXPONENT_MIN) {
firstNonZero = firstNonZero + 1;
endOfString = endOfString + 1;
}
......@@ -412,8 +435,10 @@ Decimal128.fromString = function(string) {
if (roundDigit >= 5) {
roundBit = 1;
if (roundDigit === 5) {
roundBit = digits[lastDigit] % 2 === 1;
for (i = firstNonZero + lastDigit + 2; i < endOfString; i++) {
if (parseInt(string[i], 10)) {
roundBit = 1;
......@@ -441,6 +466,8 @@ Decimal128.fromString = function(string) {
);
}
}
} else {
break;
}
}
}
......@@ -607,6 +634,7 @@ Decimal128.prototype.toString = function() {
// temporary storage for significand decoding
var significand128 = { parts: new Array(4) };
// indexing variables
i;
var j, k;
// Output string
......@@ -728,19 +756,9 @@ Decimal128.prototype.toString = function() {
// has trailing zeros. However, we *cannot* output these trailing zeros,
// because doing so would change the precision of the value, and would
// change stored data if the string converted number is round tripped.
if (scientific_exponent >= 34 || scientific_exponent <= -7 || exponent > 0) {
// Scientific format
// if there are too many significant digits, we should just be treating numbers
// as + or - 0 and using the non-scientific exponent (this is for the "invalid
// representation should be treated as 0/-0" spec cases in decimal128-1.json)
if (significand_digits > 34) {
string.push(0);
if (exponent > 0) string.push('E+' + exponent);
else if (exponent < 0) string.push('E' + exponent);
return string.join('');
}
string.push(significand[index++]);
significand_digits = significand_digits - 1;
......
'use strict';
/**
* A class representation of the BSON Double type.
*
......
'use strict';
// Copyright (c) 2008, Fair Oaks Labs, Inc.
// All rights reserved.
//
......@@ -112,27 +111,11 @@ var writeIEEE754 = function(buffer, value, offset, endian, mLen, nBytes) {
}
}
if (isNaN(value)) m = 0;
while (mLen >= 8) {
buffer[offset + i] = m & 0xff;
i += d;
m /= 256;
mLen -= 8;
}
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8);
e = (e << mLen) | m;