File tree Expand file tree Collapse file tree 2 files changed +34
-3
lines changed
Expand file tree Collapse file tree 2 files changed +34
-3
lines changed Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+ const common = require ( '../common.js' ) ;
3+ const { Blob } = require ( 'buffer' ) ;
4+
5+ const bench = common . createBenchmark ( main , {
6+ bytes : [ 0 , 8 , 128 ] ,
7+ n : [ 1e6 ] ,
8+ operation : [ 'text' , 'arrayBuffer' ]
9+ } ) ;
10+
11+ async function run ( n , bytes , operation ) {
12+ const buff = Buffer . allocUnsafe ( bytes ) ;
13+ const source = new Blob ( buff ) ;
14+ bench . start ( ) ;
15+ for ( let i = 0 ; i < n ; i ++ ) {
16+ switch ( operation ) {
17+ case 'text' :
18+ await source . text ( ) ;
19+ break ;
20+ case 'arrayBuffer' :
21+ await source . arrayBuffer ( ) ;
22+ break ;
23+ }
24+ }
25+ bench . end ( n ) ;
26+ }
27+
28+ function main ( conf ) {
29+ run ( conf . n , conf . bytes , conf . operation ) . catch ( console . log ) ;
30+ }
Original file line number Diff line number Diff line change 88 PromiseResolve,
99 PromiseReject,
1010 SafePromisePrototypeFinally,
11+ PromisePrototypeThen,
1112 ReflectConstruct,
1213 RegExpPrototypeExec,
1314 RegExpPrototypeSymbolReplace,
@@ -308,13 +309,13 @@ class Blob {
308309 /**
309310 * @returns {Promise<string> }
310311 */
311- async text ( ) {
312+ text ( ) {
312313 if ( ! isBlob ( this ) )
313- throw new ERR_INVALID_THIS ( 'Blob' ) ;
314+ return PromiseReject ( new ERR_INVALID_THIS ( 'Blob' ) ) ;
314315
315316 dec ??= new TextDecoder ( ) ;
316317
317- return dec . decode ( await this . arrayBuffer ( ) ) ;
318+ return PromisePrototypeThen ( this . arrayBuffer ( ) , ( value ) => dec . decode ( value ) ) ;
318319 }
319320
320321 /**
You can’t perform that action at this time.
0 commit comments