web-streams-polyfill 3.1.1 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * web-streams-polyfill v3.1.1
2
+ * web-streams-polyfill v3.2.0
3
3
  */
4
4
  /// <reference lib="es2015.symbol" />
5
5
  const SymbolPolyfill = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol' ?
@@ -1195,6 +1195,9 @@ function ReadableByteStreamControllerEnqueue(controller, chunk) {
1195
1195
  ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
1196
1196
  }
1197
1197
  else {
1198
+ if (controller._pendingPullIntos.length > 0) {
1199
+ ReadableByteStreamControllerShiftPendingPullInto(controller);
1200
+ }
1198
1201
  const transferredView = new Uint8Array(transferredBuffer, byteOffset, byteLength);
1199
1202
  ReadableStreamFulfillReadRequest(stream, transferredView, false);
1200
1203
  }
@@ -1280,8 +1283,9 @@ function ReadableByteStreamControllerRespondWithNewView(controller, view) {
1280
1283
  if (firstDescriptor.bytesFilled + view.byteLength > firstDescriptor.byteLength) {
1281
1284
  throw new RangeError('The region specified by view is larger than byobRequest');
1282
1285
  }
1286
+ const viewByteLength = view.byteLength;
1283
1287
  firstDescriptor.buffer = TransferArrayBuffer(view.buffer);
1284
- ReadableByteStreamControllerRespondInternal(controller, view.byteLength);
1288
+ ReadableByteStreamControllerRespondInternal(controller, viewByteLength);
1285
1289
  }
1286
1290
  function SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize) {
1287
1291
  controller._controlledReadableByteStream = stream;
@@ -2208,6 +2212,10 @@ class WritableStreamDefaultController {
2208
2212
  }
2209
2213
  /**
2210
2214
  * The reason which was passed to `WritableStream.abort(reason)` when the stream was aborted.
2215
+ *
2216
+ * @deprecated
2217
+ * This property has been removed from the specification, see https://github.com/whatwg/streams/pull/1177.
2218
+ * Use {@link WritableStreamDefaultController.signal}'s `reason` instead.
2211
2219
  */
2212
2220
  get abortReason() {
2213
2221
  if (!IsWritableStreamDefaultController(this)) {
@@ -2261,6 +2269,8 @@ class WritableStreamDefaultController {
2261
2269
  }
2262
2270
  }
2263
2271
  Object.defineProperties(WritableStreamDefaultController.prototype, {
2272
+ abortReason: { enumerable: true },
2273
+ signal: { enumerable: true },
2264
2274
  error: { enumerable: true }
2265
2275
  });
2266
2276
  if (typeof SymbolPolyfill.toStringTag === 'symbol') {
@@ -3002,6 +3012,7 @@ function ReadableStreamTee(stream, cloneForBranch2) {
3002
3012
  function ReadableStreamDefaultTee(stream, cloneForBranch2) {
3003
3013
  const reader = AcquireReadableStreamDefaultReader(stream);
3004
3014
  let reading = false;
3015
+ let readAgain = false;
3005
3016
  let canceled1 = false;
3006
3017
  let canceled2 = false;
3007
3018
  let reason1;
@@ -3014,6 +3025,7 @@ function ReadableStreamDefaultTee(stream, cloneForBranch2) {
3014
3025
  });
3015
3026
  function pullAlgorithm() {
3016
3027
  if (reading) {
3028
+ readAgain = true;
3017
3029
  return promiseResolvedWith(undefined);
3018
3030
  }
3019
3031
  reading = true;
@@ -3023,7 +3035,7 @@ function ReadableStreamDefaultTee(stream, cloneForBranch2) {
3023
3035
  // reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
3024
3036
  // successful synchronously-available reads get ahead of asynchronously-available errors.
3025
3037
  queueMicrotask(() => {
3026
- reading = false;
3038
+ readAgain = false;
3027
3039
  const chunk1 = chunk;
3028
3040
  const chunk2 = chunk;
3029
3041
  // There is no way to access the cloning code right now in the reference implementation.
@@ -3037,6 +3049,10 @@ function ReadableStreamDefaultTee(stream, cloneForBranch2) {
3037
3049
  if (!canceled2) {
3038
3050
  ReadableStreamDefaultControllerEnqueue(branch2._readableStreamController, chunk2);
3039
3051
  }
3052
+ reading = false;
3053
+ if (readAgain) {
3054
+ pullAlgorithm();
3055
+ }
3040
3056
  });
3041
3057
  },
3042
3058
  _closeSteps: () => {
@@ -3095,6 +3111,8 @@ function ReadableStreamDefaultTee(stream, cloneForBranch2) {
3095
3111
  function ReadableByteStreamTee(stream) {
3096
3112
  let reader = AcquireReadableStreamDefaultReader(stream);
3097
3113
  let reading = false;
3114
+ let readAgainForBranch1 = false;
3115
+ let readAgainForBranch2 = false;
3098
3116
  let canceled1 = false;
3099
3117
  let canceled2 = false;
3100
3118
  let reason1;
@@ -3129,7 +3147,8 @@ function ReadableByteStreamTee(stream) {
3129
3147
  // reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
3130
3148
  // successful synchronously-available reads get ahead of asynchronously-available errors.
3131
3149
  queueMicrotask(() => {
3132
- reading = false;
3150
+ readAgainForBranch1 = false;
3151
+ readAgainForBranch2 = false;
3133
3152
  const chunk1 = chunk;
3134
3153
  let chunk2 = chunk;
3135
3154
  if (!canceled1 && !canceled2) {
@@ -3149,6 +3168,13 @@ function ReadableByteStreamTee(stream) {
3149
3168
  if (!canceled2) {
3150
3169
  ReadableByteStreamControllerEnqueue(branch2._readableStreamController, chunk2);
3151
3170
  }
3171
+ reading = false;
3172
+ if (readAgainForBranch1) {
3173
+ pull1Algorithm();
3174
+ }
3175
+ else if (readAgainForBranch2) {
3176
+ pull2Algorithm();
3177
+ }
3152
3178
  });
3153
3179
  },
3154
3180
  _closeSteps: () => {
@@ -3189,7 +3215,8 @@ function ReadableByteStreamTee(stream) {
3189
3215
  // reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
3190
3216
  // successful synchronously-available reads get ahead of asynchronously-available errors.
3191
3217
  queueMicrotask(() => {
3192
- reading = false;
3218
+ readAgainForBranch1 = false;
3219
+ readAgainForBranch2 = false;
3193
3220
  const byobCanceled = forBranch2 ? canceled2 : canceled1;
3194
3221
  const otherCanceled = forBranch2 ? canceled1 : canceled2;
3195
3222
  if (!otherCanceled) {
@@ -3211,6 +3238,13 @@ function ReadableByteStreamTee(stream) {
3211
3238
  else if (!byobCanceled) {
3212
3239
  ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
3213
3240
  }
3241
+ reading = false;
3242
+ if (readAgainForBranch1) {
3243
+ pull1Algorithm();
3244
+ }
3245
+ else if (readAgainForBranch2) {
3246
+ pull2Algorithm();
3247
+ }
3214
3248
  });
3215
3249
  },
3216
3250
  _closeSteps: chunk => {
@@ -3243,6 +3277,7 @@ function ReadableByteStreamTee(stream) {
3243
3277
  }
3244
3278
  function pull1Algorithm() {
3245
3279
  if (reading) {
3280
+ readAgainForBranch1 = true;
3246
3281
  return promiseResolvedWith(undefined);
3247
3282
  }
3248
3283
  reading = true;
@@ -3257,6 +3292,7 @@ function ReadableByteStreamTee(stream) {
3257
3292
  }
3258
3293
  function pull2Algorithm() {
3259
3294
  if (reading) {
3295
+ readAgainForBranch2 = true;
3260
3296
  return promiseResolvedWith(undefined);
3261
3297
  }
3262
3298
  reading = true;