File tree Expand file tree Collapse file tree 2 files changed +18
-18
lines changed Expand file tree Collapse file tree 2 files changed +18
-18
lines changed Original file line number Diff line number Diff line change @@ -9,13 +9,16 @@ const {
9
9
kMaxLength,
10
10
} = require ( 'buffer' ) ;
11
11
12
+ < << << << HEAD
12
13
// Verify the maximum Uint8Array size. There is no concrete limit by spec. The
13
14
// internal limits should be updated if this fails.
14
15
assert . throws (
15
16
( ) => new Uint8Array ( kMaxLength + 1 ) ,
16
17
{ message : `Invalid typed array length: ${ kMaxLength + 1 } ` } ,
17
18
) ;
18
19
20
+ = === ===
21
+ >>> >>> > b3e1523f34 ( Adapt tests for increased TypedArray sizes ( #161 ) )
19
22
const b = Buffer . allocUnsafe ( 1024 ) ;
20
23
assert . strictEqual ( b . length , 1024 ) ;
21
24
Original file line number Diff line number Diff line change @@ -18,26 +18,23 @@ const {
18
18
} ,
19
19
} = require ( 'buffer' ) ;
20
20
21
- const len = MAX_STRING_LENGTH + 1 ;
22
- const message = {
23
- code : 'ERR_STRING_TOO_LONG' ,
24
- name : 'Error' ,
25
- } ;
26
-
27
- function test ( getBuffer ) {
28
- let buf ;
21
+ // Find the maximum supported buffer length.
22
+ let limit = 1 << 31 ; // 2GB
23
+ while ( true ) {
29
24
try {
30
- buf = getBuffer ( ) ;
25
+ Buffer ( limit ) ;
26
+ limit *= 2 ;
31
27
} catch ( e ) {
32
- // If the buffer allocation fails, we skip the test.
33
- if ( e . code === 'ERR_MEMORY_ALLOCATION_FAILED' || / A r r a y b u f f e r a l l o c a t i o n f a i l e d / . test ( e . message ) ) {
34
- return ;
35
- }
28
+ break ;
36
29
}
37
- assert . throws ( ( ) => { buf . toString ( 'utf8' ) ; } , message ) ;
38
30
}
39
31
40
- test ( ( ) => Buffer ( len ) ) ;
41
- test ( ( ) => Buffer . alloc ( len ) ) ;
42
- test ( ( ) => Buffer . allocUnsafe ( len ) ) ;
43
- test ( ( ) => Buffer . allocUnsafeSlow ( len ) ) ;
32
+ const message = {
33
+ code : 'ERR_STRING_TOO_LONG' ,
34
+ name : 'Error' ,
35
+ } ;
36
+ assert . throws ( ( ) => Buffer ( limit ) . toString ( 'utf8' ) , message ) ;
37
+ assert . throws ( ( ) => SlowBuffer ( limit ) . toString ( 'utf8' ) , message ) ;
38
+ assert . throws ( ( ) => Buffer . alloc ( limit ) . toString ( 'utf8' ) , message ) ;
39
+ assert . throws ( ( ) => Buffer . allocUnsafe ( limit ) . toString ( 'utf8' ) , message ) ;
40
+ assert . throws ( ( ) => Buffer . allocUnsafeSlow ( limit ) . toString ( 'utf8' ) , message ) ;
You can’t perform that action at this time.
0 commit comments