Skip to content

Commit 421a918

Browse files
committed
Fix high water mark bug when providing an array and add tests
1 parent 39e3e49 commit 421a918

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

lib/node_modules/@stdlib/array/pool/lib/factory.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ function factory( options ) {
203203
arr = arguments[ 0 ];
204204
len = arr.length;
205205
out = typedarray( ctor, len, dtype );
206+
if ( out === null ) {
207+
return out;
208+
}
206209
for ( i = 0; i < len; i++ ) {
207210
out[ i ] = arr[ i ];
208211
}

lib/node_modules/@stdlib/array/pool/test/test.factory.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,15 @@ tape( 'the function supports specifying a high water mark which limits the total
17991799
arr2 = typedarraypool.calloc( 1e6, 'float64' );
18001800
t.strictEqual( arr2, null, 'returns expected value' );
18011801

1802+
arr2 = typedarraypool( new Float64Array( 20 ), 'float64' );
1803+
t.strictEqual( arr2, null, 'returns expected value' );
1804+
1805+
arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' );
1806+
t.strictEqual( arr2, null, 'returns expected value' );
1807+
1808+
arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' );
1809+
t.strictEqual( arr2, null, 'returns expected value' );
1810+
18021811
typedarraypool.free( arr1 );
18031812

18041813
arr2 = typedarraypool( 1e6, 'float64' );
@@ -1810,6 +1819,15 @@ tape( 'the function supports specifying a high water mark which limits the total
18101819
arr2 = typedarraypool.calloc( 1e6, 'float64' );
18111820
t.strictEqual( arr2, null, 'returns expected value' );
18121821

1822+
arr2 = typedarraypool( new Float64Array( 20 ), 'float64' );
1823+
t.strictEqual( arr2, null, 'returns expected value' );
1824+
1825+
arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' );
1826+
t.strictEqual( arr2, null, 'returns expected value' );
1827+
1828+
arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' );
1829+
t.strictEqual( arr2, null, 'returns expected value' );
1830+
18131831
arr2 = typedarraypool( 8, 'float64' );
18141832
t.strictEqual( arr2.length, 8, 'returns expected value' );
18151833
t.strictEqual( arr2.byteLength, 64, 'returns expected value' );

0 commit comments

Comments
 (0)