File tree 2 files changed +23
-1
lines changed
2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const common = require ( '../common.js' ) ;
4
+ const { createHash } = require ( 'crypto' ) ;
5
+ const assert = require ( 'assert' ) ;
6
+
7
+ const bench = common . createBenchmark ( main , {
8
+ n : [ 1e5 ] ,
9
+ } ) ;
10
+
11
+ function main ( { n } ) {
12
+ const array = [ ] ;
13
+ for ( let i = 0 ; i < n ; ++ i ) {
14
+ array . push ( null ) ;
15
+ }
16
+ bench . start ( ) ;
17
+ for ( let i = 0 ; i < n ; ++ i ) {
18
+ array [ i ] = createHash ( 'sha1' ) ;
19
+ }
20
+ bench . end ( n ) ;
21
+ assert . strictEqual ( typeof array [ n - 1 ] , 'object' ) ;
22
+ }
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ const kState = Symbol('kState');
57
57
const kFinalized = Symbol ( 'kFinalized' ) ;
58
58
59
59
function Hash ( algorithm , options ) {
60
- if ( ! ( this instanceof Hash ) )
60
+ if ( ! new . target )
61
61
return new Hash ( algorithm , options ) ;
62
62
if ( ! ( algorithm instanceof _Hash ) )
63
63
validateString ( algorithm , 'algorithm' ) ;
You can’t perform that action at this time.
0 commit comments