File tree 3 files changed +26
-6
lines changed
3 files changed +26
-6
lines changed Original file line number Diff line number Diff line change 6
6
MathMin,
7
7
ObjectDefineProperties,
8
8
ObjectDefineProperty,
9
+ ObjectSetPrototypeOf,
9
10
PromiseReject,
10
11
ReflectConstruct,
11
12
RegExpPrototypeExec,
@@ -403,13 +404,23 @@ function ClonedBlob() {
403
404
}
404
405
ClonedBlob . prototype [ kDeserialize ] = ( ) => { } ;
405
406
407
+ function TransferrableBlob ( handle , length , type = '' ) {
408
+ markTransferMode ( this , true , false ) ;
409
+ this [ kHandle ] = handle ;
410
+ this [ kType ] = type ;
411
+ this [ kLength ] = length ;
412
+ }
413
+
414
+ ObjectSetPrototypeOf ( TransferrableBlob . prototype , Blob . prototype ) ;
415
+ ObjectSetPrototypeOf ( TransferrableBlob , Blob ) ;
416
+
406
417
function createBlob ( handle , length , type = '' ) {
407
- return ReflectConstruct ( function ( ) {
408
- markTransferMode ( this , true , false ) ;
409
- this [ kHandle ] = handle ;
410
- this [ kType ] = type ;
411
- this [ kLength ] = length ;
412
- } , [ ] , Blob ) ;
418
+ const transferredBlob = new TransferrableBlob ( handle , length , type ) ;
419
+
420
+ // Fix issues like: https://github.com/nodejs/node/pull/49730#discussion_r1331720053
421
+ transferredBlob . constructor = Blob ;
422
+
423
+ return transferredBlob ;
413
424
}
414
425
415
426
ObjectDefineProperty ( Blob . prototype , SymbolToStringTag , {
Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ const assert = require('assert');
24
24
const id = URL . createObjectURL ( blob ) ;
25
25
assert . strictEqual ( typeof id , 'string' ) ;
26
26
const otherBlob = resolveObjectURL ( id ) ;
27
+ assert . ok ( otherBlob instanceof Blob ) ;
28
+ assert . strictEqual ( otherBlob . constructor , Blob ) ;
27
29
assert . strictEqual ( otherBlob . size , 5 ) ;
28
30
assert . strictEqual (
29
31
Buffer . from ( await otherBlob . arrayBuffer ( ) ) . toString ( ) ,
Original file line number Diff line number Diff line change @@ -473,3 +473,10 @@ assert.throws(() => new Blob({}), {
473
473
474
474
await new Blob ( chunks ) . arrayBuffer ( ) ;
475
475
} ) ( ) . then ( common . mustCall ( ) ) ;
476
+
477
+ {
478
+ const blob = new Blob ( [ 'hello' ] ) ;
479
+
480
+ assert . ok ( blob . slice ( 0 , 1 ) . constructor === Blob ) ;
481
+ assert . ok ( blob . slice ( 0 , 1 ) instanceof Blob ) ;
482
+ }
You can’t perform that action at this time.
0 commit comments