web-streams-polyfill 3.1.0 → 3.2.1

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.0
2
+ * web-streams-polyfill v3.2.1
3
3
  */
4
4
  /// <reference lib="es2015.symbol" />
5
5
  const SymbolPolyfill = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol' ?
@@ -1206,6 +1206,9 @@ function ReadableByteStreamControllerEnqueue(controller, chunk) {
1206
1206
  ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
1207
1207
  }
1208
1208
  else {
1209
+ if (controller._pendingPullIntos.length > 0) {
1210
+ ReadableByteStreamControllerShiftPendingPullInto(controller);
1211
+ }
1209
1212
  const transferredView = new Uint8Array(transferredBuffer, byteOffset, byteLength);
1210
1213
  ReadableStreamFulfillReadRequest(stream, transferredView, false);
1211
1214
  }
@@ -1291,8 +1294,9 @@ function ReadableByteStreamControllerRespondWithNewView(controller, view) {
1291
1294
  if (firstDescriptor.bytesFilled + view.byteLength > firstDescriptor.byteLength) {
1292
1295
  throw new RangeError('The region specified by view is larger than byobRequest');
1293
1296
  }
1297
+ const viewByteLength = view.byteLength;
1294
1298
  firstDescriptor.buffer = TransferArrayBuffer(view.buffer);
1295
- ReadableByteStreamControllerRespondInternal(controller, view.byteLength);
1299
+ ReadableByteStreamControllerRespondInternal(controller, viewByteLength);
1296
1300
  }
1297
1301
  function SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize) {
1298
1302
  controller._controlledReadableByteStream = stream;
@@ -2219,6 +2223,10 @@ class WritableStreamDefaultController {
2219
2223
  }
2220
2224
  /**
2221
2225
  * The reason which was passed to `WritableStream.abort(reason)` when the stream was aborted.
2226
+ *
2227
+ * @deprecated
2228
+ * This property has been removed from the specification, see https://github.com/whatwg/streams/pull/1177.
2229
+ * Use {@link WritableStreamDefaultController.signal}'s `reason` instead.
2222
2230
  */
2223
2231
  get abortReason() {
2224
2232
  if (!IsWritableStreamDefaultController(this)) {
@@ -2272,6 +2280,8 @@ class WritableStreamDefaultController {
2272
2280
  }
2273
2281
  }
2274
2282
  Object.defineProperties(WritableStreamDefaultController.prototype, {
2283
+ abortReason: { enumerable: true },
2284
+ signal: { enumerable: true },
2275
2285
  error: { enumerable: true }
2276
2286
  });
2277
2287
  if (typeof SymbolPolyfill.toStringTag === 'symbol') {
@@ -3013,6 +3023,7 @@ function ReadableStreamTee(stream, cloneForBranch2) {
3013
3023
  function ReadableStreamDefaultTee(stream, cloneForBranch2) {
3014
3024
  const reader = AcquireReadableStreamDefaultReader(stream);
3015
3025
  let reading = false;
3026
+ let readAgain = false;
3016
3027
  let canceled1 = false;
3017
3028
  let canceled2 = false;
3018
3029
  let reason1;
@@ -3025,6 +3036,7 @@ function ReadableStreamDefaultTee(stream, cloneForBranch2) {
3025
3036
  });
3026
3037
  function pullAlgorithm() {
3027
3038
  if (reading) {
3039
+ readAgain = true;
3028
3040
  return promiseResolvedWith(undefined);
3029
3041
  }
3030
3042
  reading = true;
@@ -3034,7 +3046,7 @@ function ReadableStreamDefaultTee(stream, cloneForBranch2) {
3034
3046
  // reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
3035
3047
  // successful synchronously-available reads get ahead of asynchronously-available errors.
3036
3048
  queueMicrotask(() => {
3037
- reading = false;
3049
+ readAgain = false;
3038
3050
  const chunk1 = chunk;
3039
3051
  const chunk2 = chunk;
3040
3052
  // There is no way to access the cloning code right now in the reference implementation.
@@ -3048,6 +3060,10 @@ function ReadableStreamDefaultTee(stream, cloneForBranch2) {
3048
3060
  if (!canceled2) {
3049
3061
  ReadableStreamDefaultControllerEnqueue(branch2._readableStreamController, chunk2);
3050
3062
  }
3063
+ reading = false;
3064
+ if (readAgain) {
3065
+ pullAlgorithm();
3066
+ }
3051
3067
  });
3052
3068
  },
3053
3069
  _closeSteps: () => {
@@ -3106,6 +3122,8 @@ function ReadableStreamDefaultTee(stream, cloneForBranch2) {
3106
3122
  function ReadableByteStreamTee(stream) {
3107
3123
  let reader = AcquireReadableStreamDefaultReader(stream);
3108
3124
  let reading = false;
3125
+ let readAgainForBranch1 = false;
3126
+ let readAgainForBranch2 = false;
3109
3127
  let canceled1 = false;
3110
3128
  let canceled2 = false;
3111
3129
  let reason1;
@@ -3140,7 +3158,8 @@ function ReadableByteStreamTee(stream) {
3140
3158
  // reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
3141
3159
  // successful synchronously-available reads get ahead of asynchronously-available errors.
3142
3160
  queueMicrotask(() => {
3143
- reading = false;
3161
+ readAgainForBranch1 = false;
3162
+ readAgainForBranch2 = false;
3144
3163
  const chunk1 = chunk;
3145
3164
  let chunk2 = chunk;
3146
3165
  if (!canceled1 && !canceled2) {
@@ -3160,6 +3179,13 @@ function ReadableByteStreamTee(stream) {
3160
3179
  if (!canceled2) {
3161
3180
  ReadableByteStreamControllerEnqueue(branch2._readableStreamController, chunk2);
3162
3181
  }
3182
+ reading = false;
3183
+ if (readAgainForBranch1) {
3184
+ pull1Algorithm();
3185
+ }
3186
+ else if (readAgainForBranch2) {
3187
+ pull2Algorithm();
3188
+ }
3163
3189
  });
3164
3190
  },
3165
3191
  _closeSteps: () => {
@@ -3200,7 +3226,8 @@ function ReadableByteStreamTee(stream) {
3200
3226
  // reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
3201
3227
  // successful synchronously-available reads get ahead of asynchronously-available errors.
3202
3228
  queueMicrotask(() => {
3203
- reading = false;
3229
+ readAgainForBranch1 = false;
3230
+ readAgainForBranch2 = false;
3204
3231
  const byobCanceled = forBranch2 ? canceled2 : canceled1;
3205
3232
  const otherCanceled = forBranch2 ? canceled1 : canceled2;
3206
3233
  if (!otherCanceled) {
@@ -3222,6 +3249,13 @@ function ReadableByteStreamTee(stream) {
3222
3249
  else if (!byobCanceled) {
3223
3250
  ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
3224
3251
  }
3252
+ reading = false;
3253
+ if (readAgainForBranch1) {
3254
+ pull1Algorithm();
3255
+ }
3256
+ else if (readAgainForBranch2) {
3257
+ pull2Algorithm();
3258
+ }
3225
3259
  });
3226
3260
  },
3227
3261
  _closeSteps: chunk => {
@@ -3254,6 +3288,7 @@ function ReadableByteStreamTee(stream) {
3254
3288
  }
3255
3289
  function pull1Algorithm() {
3256
3290
  if (reading) {
3291
+ readAgainForBranch1 = true;
3257
3292
  return promiseResolvedWith(undefined);
3258
3293
  }
3259
3294
  reading = true;
@@ -3268,6 +3303,7 @@ function ReadableByteStreamTee(stream) {
3268
3303
  }
3269
3304
  function pull2Algorithm() {
3270
3305
  if (reading) {
3306
+ readAgainForBranch2 = true;
3271
3307
  return promiseResolvedWith(undefined);
3272
3308
  }
3273
3309
  reading = true;
@@ -3671,10 +3707,16 @@ function convertQueuingStrategyInit(init, context) {
3671
3707
  const byteLengthSizeFunction = (chunk) => {
3672
3708
  return chunk.byteLength;
3673
3709
  };
3674
- Object.defineProperty(byteLengthSizeFunction, 'name', {
3675
- value: 'size',
3676
- configurable: true
3677
- });
3710
+ try {
3711
+ Object.defineProperty(byteLengthSizeFunction, 'name', {
3712
+ value: 'size',
3713
+ configurable: true
3714
+ });
3715
+ }
3716
+ catch (_a) {
3717
+ // This property is non-configurable in older browsers, so ignore if this throws.
3718
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name#browser_compatibility
3719
+ }
3678
3720
  /**
3679
3721
  * A queuing strategy that counts the number of bytes in each chunk.
3680
3722
  *
@@ -3733,10 +3775,16 @@ function IsByteLengthQueuingStrategy(x) {
3733
3775
  const countSizeFunction = () => {
3734
3776
  return 1;
3735
3777
  };
3736
- Object.defineProperty(countSizeFunction, 'name', {
3737
- value: 'size',
3738
- configurable: true
3739
- });
3778
+ try {
3779
+ Object.defineProperty(countSizeFunction, 'name', {
3780
+ value: 'size',
3781
+ configurable: true
3782
+ });
3783
+ }
3784
+ catch (_a) {
3785
+ // This property is non-configurable in older browsers, so ignore if this throws.
3786
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name#browser_compatibility
3787
+ }
3740
3788
  /**
3741
3789
  * A queuing strategy that counts the number of chunks.
3742
3790
  *