@@ -1701,3 +1701,50 @@ class Source {
1701
1701
assert . deepStrictEqual ( value , new Uint8Array ( [ 1 , 1 , 1 ] ) ) ;
1702
1702
} ) ) ;
1703
1703
}
1704
+
1705
+ // Initial Pull Delay
1706
+ {
1707
+ const stream = new ReadableStream ( {
1708
+ start ( controller ) {
1709
+ controller . enqueue ( 'data' ) ;
1710
+ controller . close ( ) ;
1711
+ }
1712
+ } ) ;
1713
+
1714
+ const iterator = stream . values ( ) ;
1715
+
1716
+ let microtaskCompleted = false ;
1717
+ Promise . resolve ( ) . then ( ( ) => { microtaskCompleted = true ; } ) ;
1718
+
1719
+ iterator . next ( ) . then ( common . mustCall ( ( { done, value } ) => {
1720
+ assert . strictEqual ( done , false ) ;
1721
+ assert . strictEqual ( value , 'data' ) ;
1722
+ assert . strictEqual ( microtaskCompleted , true ) ;
1723
+ } ) ) ;
1724
+ }
1725
+
1726
+ // Avoiding Prototype Pollution
1727
+ {
1728
+ const stream = new ReadableStream ( {
1729
+ start ( controller ) {
1730
+ controller . enqueue ( 'data' ) ;
1731
+ controller . close ( ) ;
1732
+ }
1733
+ } ) ;
1734
+
1735
+ const iterator = stream . values ( ) ;
1736
+
1737
+ // Modify Promise.prototype.then to simulate prototype pollution
1738
+ const originalThen = Promise . prototype . then ;
1739
+ Promise . prototype . then = function ( onFulfilled , onRejected ) {
1740
+ return originalThen . call ( this , onFulfilled , onRejected ) ;
1741
+ } ;
1742
+
1743
+ iterator . next ( ) . then ( common . mustCall ( ( { done, value } ) => {
1744
+ assert . strictEqual ( done , false ) ;
1745
+ assert . strictEqual ( value , 'data' ) ;
1746
+
1747
+ // Restore original then method
1748
+ Promise . prototype . then = originalThen ;
1749
+ } ) ) ;
1750
+ }
0 commit comments