File tree 4 files changed +38
-1
lines changed
4 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -131,8 +131,10 @@ tasks:
131
131
- func : fetch source
132
132
vars :
133
133
NODE_LTS_VERSION : 16
134
+ NPM_VERSION : 9
134
135
- func : install dependencies
135
136
vars :
137
+ NODE_LTS_VERSION : 16
136
138
NPM_VERSION : 9
137
139
- func : run tests
138
140
vars :
@@ -143,6 +145,7 @@ tasks:
143
145
- func : fetch source
144
146
vars :
145
147
NODE_LTS_VERSION : 18
148
+ NPM_VERSION : 10
146
149
- func : install dependencies
147
150
- func : run tests
148
151
vars :
@@ -246,6 +249,7 @@ tasks:
246
249
vars :
247
250
# This needs to stay pinned at Node v18.16.0 for consistency across perf runs.
248
251
NODE_LTS_VERSION : v18.16.0
252
+ NPM_VERSION : 9
249
253
- func : install dependencies
250
254
vars :
251
255
NPM_VERSION : 9
@@ -262,6 +266,7 @@ tasks:
262
266
vars :
263
267
# This needs to stay pinned at Node v18.16.0 for consistency across perf runs.
264
268
NODE_LTS_VERSION : v18.16.0
269
+ NPM_VERSION : 9
265
270
- func : install dependencies
266
271
vars :
267
272
NPM_VERSION : 9
@@ -275,6 +280,7 @@ tasks:
275
280
vars :
276
281
# This needs to stay pinned at Node v18.16.0 for consistency across perf runs.
277
282
NODE_LTS_VERSION : v18.16.0
283
+ NPM_VERSION : 9
278
284
- func : install dependencies
279
285
vars :
280
286
NPM_VERSION : 9
Original file line number Diff line number Diff line change @@ -33,12 +33,14 @@ cat <<EOT > expansion.yml
33
33
CURRENT_VERSION: "$CURRENT_VERSION "
34
34
PROJECT_DIRECTORY: "$PROJECT_DIRECTORY "
35
35
NODE_LTS_VERSION: "$NODE_LTS_VERSION "
36
+ NPM_VERSION: "$NPM_VERSION "
36
37
DRIVERS_TOOLS: "$DRIVERS_TOOLS "
37
38
PREPARE_SHELL: |
38
39
set -o errexit
39
40
set -o xtrace
40
41
export PROJECT_DIRECTORY="$PROJECT_DIRECTORY "
41
42
export NODE_LTS_VERSION="$NODE_LTS_VERSION "
43
+ export NPM_VERSION="$NPM_VERSION "
42
44
export DRIVERS_TOOLS="$DRIVERS_TOOLS "
43
45
EOT
44
46
# See what we've done
Original file line number Diff line number Diff line change 1
1
import { Binary } from '../binary' ;
2
2
import type { Document } from '../bson' ;
3
- import { BSONVersionError } from '../error' ;
3
+ import { BSONError , BSONVersionError } from '../error' ;
4
4
import * as constants from '../constants' ;
5
5
import { ByteUtils } from '../utils/byte_utils' ;
6
6
import { isAnyArrayBuffer , isDate , isRegExp } from './utils' ;
@@ -205,6 +205,13 @@ function calculateElement(
205
205
1
206
206
) ;
207
207
}
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 } ` ) ;
208
215
}
209
216
210
217
return 0 ;
Original file line number Diff line number Diff line change @@ -24,4 +24,26 @@ describe('calculateSize()', () => {
24
24
} )
25
25
) . 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) ;
26
26
} ) ;
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
+ } ) ;
27
49
} ) ;
You can’t perform that action at this time.
0 commit comments