File tree Expand file tree Collapse file tree 4 files changed +38
-1
lines changed Expand file tree Collapse file tree 4 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -131,8 +131,10 @@ tasks:
131131 - func : fetch source
132132 vars :
133133 NODE_LTS_VERSION : 16
134+ NPM_VERSION : 9
134135 - func : install dependencies
135136 vars :
137+ NODE_LTS_VERSION : 16
136138 NPM_VERSION : 9
137139 - func : run tests
138140 vars :
@@ -143,6 +145,7 @@ tasks:
143145 - func : fetch source
144146 vars :
145147 NODE_LTS_VERSION : 18
148+ NPM_VERSION : 10
146149 - func : install dependencies
147150 - func : run tests
148151 vars :
@@ -246,6 +249,7 @@ tasks:
246249 vars :
247250 # This needs to stay pinned at Node v18.16.0 for consistency across perf runs.
248251 NODE_LTS_VERSION : v18.16.0
252+ NPM_VERSION : 9
249253 - func : install dependencies
250254 vars :
251255 NPM_VERSION : 9
@@ -262,6 +266,7 @@ tasks:
262266 vars :
263267 # This needs to stay pinned at Node v18.16.0 for consistency across perf runs.
264268 NODE_LTS_VERSION : v18.16.0
269+ NPM_VERSION : 9
265270 - func : install dependencies
266271 vars :
267272 NPM_VERSION : 9
@@ -275,6 +280,7 @@ tasks:
275280 vars :
276281 # This needs to stay pinned at Node v18.16.0 for consistency across perf runs.
277282 NODE_LTS_VERSION : v18.16.0
283+ NPM_VERSION : 9
278284 - func : install dependencies
279285 vars :
280286 NPM_VERSION : 9
Original file line number Diff line number Diff line change @@ -33,12 +33,14 @@ cat <<EOT > expansion.yml
3333CURRENT_VERSION: "$CURRENT_VERSION "
3434PROJECT_DIRECTORY: "$PROJECT_DIRECTORY "
3535NODE_LTS_VERSION: "$NODE_LTS_VERSION "
36+ NPM_VERSION: "$NPM_VERSION "
3637DRIVERS_TOOLS: "$DRIVERS_TOOLS "
3738PREPARE_SHELL: |
3839 set -o errexit
3940 set -o xtrace
4041 export PROJECT_DIRECTORY="$PROJECT_DIRECTORY "
4142 export NODE_LTS_VERSION="$NODE_LTS_VERSION "
43+ export NPM_VERSION="$NPM_VERSION "
4244 export DRIVERS_TOOLS="$DRIVERS_TOOLS "
4345EOT
4446# See what we've done
Original file line number Diff line number Diff line change 11import { Binary } from '../binary' ;
22import type { Document } from '../bson' ;
3- import { BSONVersionError } from '../error' ;
3+ import { BSONError , BSONVersionError } from '../error' ;
44import * as constants from '../constants' ;
55import { ByteUtils } from '../utils/byte_utils' ;
66import { isAnyArrayBuffer , isDate , isRegExp } from './utils' ;
@@ -205,6 +205,13 @@ function calculateElement(
205205 1
206206 ) ;
207207 }
208+ return 0 ;
209+ case 'bigint' :
210+ return ( name != null ? ByteUtils . utf8ByteLength ( name ) + 1 : 0 ) + ( 8 + 1 ) ;
211+ case 'symbol' :
212+ return 0 ;
213+ default :
214+ throw new BSONError ( `Unrecognized JS type: ${ typeof value } ` ) ;
208215 }
209216
210217 return 0 ;
Original file line number Diff line number Diff line change @@ -24,4 +24,26 @@ describe('calculateSize()', () => {
2424 } )
2525 ) . to . throw ( BSONVersionError , / U n s u p p o r t e d B S O N v e r s i o n / i) ;
2626 } ) ;
27+
28+ describe ( 'when given a bigint value with a single character key' , function ( ) {
29+ beforeEach ( function ( ) {
30+ if ( BSON . __noBigInt__ ) {
31+ this . currentTest ?. skip ( ) ;
32+ }
33+ } ) ;
34+
35+ it ( 'returns 8 bytes (+4 bytes for document size + 1 type byte + 1 byte for "a" + 2 null terminators)' , function ( ) {
36+ const doc = { a : BigInt ( 1 ) } ;
37+ expect ( BSON . calculateObjectSize ( doc ) ) . to . equal ( 8 + 4 + 1 + 1 + 1 + 1 ) ;
38+ expect ( BSON . calculateObjectSize ( doc ) ) . to . equal ( BSON . serialize ( doc ) . byteLength ) ;
39+ } ) ;
40+ } ) ;
41+
42+ describe ( 'when given a symbol value with a single character key' , function ( ) {
43+ it ( 'returns 0 bytes (+4 bytes for document size + 1 null terminator)' , function ( ) {
44+ const doc = { a : Symbol ( ) } ;
45+ expect ( BSON . calculateObjectSize ( doc ) ) . to . equal ( 4 + 1 ) ;
46+ expect ( BSON . calculateObjectSize ( doc ) ) . to . equal ( BSON . serialize ( doc ) . byteLength ) ;
47+ } ) ;
48+ } ) ;
2749} ) ;
You can’t perform that action at this time.
0 commit comments