web-streams-polyfill 3.3.1 → 3.3.3

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.
package/dist/ponyfill.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * web-streams-polyfill v3.3.1
3
+ * web-streams-polyfill v3.3.3
4
4
  * Copyright 2024 Mattias Buelens, Diwank Singh Tomer and other contributors.
5
5
  * This code is released under the MIT license.
6
6
  * SPDX-License-Identifier: MIT
@@ -641,22 +641,137 @@
641
641
  return new TypeError("ReadableStreamDefaultReader.prototype.".concat(name, " can only be used on a ReadableStreamDefaultReader"));
642
642
  }
643
643
 
644
- /// <reference lib="es2018.asynciterable" />
645
- var _a;
646
- var AsyncIteratorPrototype;
647
- if (typeof SymbolPolyfill.asyncIterator === 'symbol') {
648
- // We're running inside a ES2018+ environment, but we're compiling to an older syntax.
649
- // We cannot access %AsyncIteratorPrototype% without non-ES2018 syntax, but we can re-create it.
650
- AsyncIteratorPrototype = (_a = {},
651
- // 25.1.3.1 %AsyncIteratorPrototype% [ @@asyncIterator ] ( )
652
- // https://tc39.github.io/ecma262/#sec-asynciteratorprototype-asynciterator
653
- _a[SymbolPolyfill.asyncIterator] = function () {
654
- return this;
655
- },
644
+ var _a$1, _b, _c;
645
+ function CreateArrayFromList(elements) {
646
+ // We use arrays to represent lists, so this is basically a no-op.
647
+ // Do a slice though just in case we happen to depend on the unique-ness.
648
+ return elements.slice();
649
+ }
650
+ function CopyDataBlockBytes(dest, destOffset, src, srcOffset, n) {
651
+ new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset);
652
+ }
653
+ var TransferArrayBuffer = function (O) {
654
+ if (typeof O.transfer === 'function') {
655
+ TransferArrayBuffer = function (buffer) { return buffer.transfer(); };
656
+ }
657
+ else if (typeof structuredClone === 'function') {
658
+ TransferArrayBuffer = function (buffer) { return structuredClone(buffer, { transfer: [buffer] }); };
659
+ }
660
+ else {
661
+ // Not implemented correctly
662
+ TransferArrayBuffer = function (buffer) { return buffer; };
663
+ }
664
+ return TransferArrayBuffer(O);
665
+ };
666
+ var IsDetachedBuffer = function (O) {
667
+ if (typeof O.detached === 'boolean') {
668
+ IsDetachedBuffer = function (buffer) { return buffer.detached; };
669
+ }
670
+ else {
671
+ // Not implemented correctly
672
+ IsDetachedBuffer = function (buffer) { return buffer.byteLength === 0; };
673
+ }
674
+ return IsDetachedBuffer(O);
675
+ };
676
+ function ArrayBufferSlice(buffer, begin, end) {
677
+ // ArrayBuffer.prototype.slice is not available on IE10
678
+ // https://www.caniuse.com/mdn-javascript_builtins_arraybuffer_slice
679
+ if (buffer.slice) {
680
+ return buffer.slice(begin, end);
681
+ }
682
+ var length = end - begin;
683
+ var slice = new ArrayBuffer(length);
684
+ CopyDataBlockBytes(slice, 0, buffer, begin, length);
685
+ return slice;
686
+ }
687
+ function GetMethod(receiver, prop) {
688
+ var func = receiver[prop];
689
+ if (func === undefined || func === null) {
690
+ return undefined;
691
+ }
692
+ if (typeof func !== 'function') {
693
+ throw new TypeError("".concat(String(prop), " is not a function"));
694
+ }
695
+ return func;
696
+ }
697
+ function CreateAsyncFromSyncIterator(syncIteratorRecord) {
698
+ // Instead of re-implementing CreateAsyncFromSyncIterator and %AsyncFromSyncIteratorPrototype%,
699
+ // we use yield* inside an async generator function to achieve the same result.
700
+ var _a;
701
+ // Wrap the sync iterator inside a sync iterable, so we can use it with yield*.
702
+ var syncIterable = (_a = {},
703
+ _a[SymbolPolyfill.iterator] = function () { return syncIteratorRecord.iterator; },
656
704
  _a);
657
- Object.defineProperty(AsyncIteratorPrototype, SymbolPolyfill.asyncIterator, { enumerable: false });
705
+ // Create an async generator function and immediately invoke it.
706
+ var asyncIterator = (function () {
707
+ return __asyncGenerator(this, arguments, function () {
708
+ return __generator(this, function (_a) {
709
+ switch (_a.label) {
710
+ case 0: return [5 /*yield**/, __values(__asyncDelegator(__asyncValues(syncIterable)))];
711
+ case 1: return [4 /*yield*/, __await.apply(void 0, [_a.sent()])];
712
+ case 2: return [4 /*yield*/, __await.apply(void 0, [_a.sent()])];
713
+ case 3: return [2 /*return*/, _a.sent()];
714
+ }
715
+ });
716
+ });
717
+ }());
718
+ // Return as an async iterator record.
719
+ var nextMethod = asyncIterator.next;
720
+ return { iterator: asyncIterator, nextMethod: nextMethod, done: false };
721
+ }
722
+ // Aligns with core-js/modules/es.symbol.async-iterator.js
723
+ var SymbolAsyncIterator = (_c = (_a$1 = SymbolPolyfill.asyncIterator) !== null && _a$1 !== void 0 ? _a$1 : (_b = SymbolPolyfill.for) === null || _b === void 0 ? void 0 : _b.call(SymbolPolyfill, 'Symbol.asyncIterator')) !== null && _c !== void 0 ? _c : '@@asyncIterator';
724
+ function GetIterator(obj, hint, method) {
725
+ if (hint === void 0) { hint = 'sync'; }
726
+ if (method === undefined) {
727
+ if (hint === 'async') {
728
+ method = GetMethod(obj, SymbolAsyncIterator);
729
+ if (method === undefined) {
730
+ var syncMethod = GetMethod(obj, SymbolPolyfill.iterator);
731
+ var syncIteratorRecord = GetIterator(obj, 'sync', syncMethod);
732
+ return CreateAsyncFromSyncIterator(syncIteratorRecord);
733
+ }
734
+ }
735
+ else {
736
+ method = GetMethod(obj, SymbolPolyfill.iterator);
737
+ }
738
+ }
739
+ if (method === undefined) {
740
+ throw new TypeError('The object is not iterable');
741
+ }
742
+ var iterator = reflectCall(method, obj, []);
743
+ if (!typeIsObject(iterator)) {
744
+ throw new TypeError('The iterator method must return an object');
745
+ }
746
+ var nextMethod = iterator.next;
747
+ return { iterator: iterator, nextMethod: nextMethod, done: false };
748
+ }
749
+ function IteratorNext(iteratorRecord) {
750
+ var result = reflectCall(iteratorRecord.nextMethod, iteratorRecord.iterator, []);
751
+ if (!typeIsObject(result)) {
752
+ throw new TypeError('The iterator.next() method must return an object');
753
+ }
754
+ return result;
755
+ }
756
+ function IteratorComplete(iterResult) {
757
+ return Boolean(iterResult.done);
758
+ }
759
+ function IteratorValue(iterResult) {
760
+ return iterResult.value;
658
761
  }
659
762
 
763
+ /// <reference lib="es2018.asynciterable" />
764
+ var _a;
765
+ // We cannot access %AsyncIteratorPrototype% without non-ES2018 syntax, but we can re-create it.
766
+ var AsyncIteratorPrototype = (_a = {},
767
+ // 25.1.3.1 %AsyncIteratorPrototype% [ @@asyncIterator ] ( )
768
+ // https://tc39.github.io/ecma262/#sec-asynciteratorprototype-asynciterator
769
+ _a[SymbolAsyncIterator] = function () {
770
+ return this;
771
+ },
772
+ _a);
773
+ Object.defineProperty(AsyncIteratorPrototype, SymbolAsyncIterator, { enumerable: false });
774
+
660
775
  /// <reference lib="es2018.asynciterable" />
661
776
  var ReadableStreamAsyncIteratorImpl = /** @class */ (function () {
662
777
  function ReadableStreamAsyncIteratorImpl(reader, preventCancel) {
@@ -745,9 +860,7 @@
745
860
  return this._asyncIteratorImpl.return(value);
746
861
  }
747
862
  };
748
- if (AsyncIteratorPrototype !== undefined) {
749
- Object.setPrototypeOf(ReadableStreamAsyncIteratorPrototype, AsyncIteratorPrototype);
750
- }
863
+ Object.setPrototypeOf(ReadableStreamAsyncIteratorPrototype, AsyncIteratorPrototype);
751
864
  // Abstract operations for the ReadableStream.
752
865
  function AcquireReadableStreamAsyncIterator(stream, preventCancel) {
753
866
  var reader = AcquireReadableStreamDefaultReader(stream);
@@ -784,122 +897,6 @@
784
897
  return x !== x;
785
898
  };
786
899
 
787
- function CreateArrayFromList(elements) {
788
- // We use arrays to represent lists, so this is basically a no-op.
789
- // Do a slice though just in case we happen to depend on the unique-ness.
790
- return elements.slice();
791
- }
792
- function CopyDataBlockBytes(dest, destOffset, src, srcOffset, n) {
793
- new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset);
794
- }
795
- var TransferArrayBuffer = function (O) {
796
- if (typeof O.transfer === 'function') {
797
- TransferArrayBuffer = function (buffer) { return buffer.transfer(); };
798
- }
799
- else if (typeof structuredClone === 'function') {
800
- TransferArrayBuffer = function (buffer) { return structuredClone(buffer, { transfer: [buffer] }); };
801
- }
802
- else {
803
- // Not implemented correctly
804
- TransferArrayBuffer = function (buffer) { return buffer; };
805
- }
806
- return TransferArrayBuffer(O);
807
- };
808
- var IsDetachedBuffer = function (O) {
809
- if (typeof O.detached === 'boolean') {
810
- IsDetachedBuffer = function (buffer) { return buffer.detached; };
811
- }
812
- else {
813
- // Not implemented correctly
814
- IsDetachedBuffer = function (buffer) { return buffer.byteLength === 0; };
815
- }
816
- return IsDetachedBuffer(O);
817
- };
818
- function ArrayBufferSlice(buffer, begin, end) {
819
- // ArrayBuffer.prototype.slice is not available on IE10
820
- // https://www.caniuse.com/mdn-javascript_builtins_arraybuffer_slice
821
- if (buffer.slice) {
822
- return buffer.slice(begin, end);
823
- }
824
- var length = end - begin;
825
- var slice = new ArrayBuffer(length);
826
- CopyDataBlockBytes(slice, 0, buffer, begin, length);
827
- return slice;
828
- }
829
- function GetMethod(receiver, prop) {
830
- var func = receiver[prop];
831
- if (func === undefined || func === null) {
832
- return undefined;
833
- }
834
- if (typeof func !== 'function') {
835
- throw new TypeError("".concat(String(prop), " is not a function"));
836
- }
837
- return func;
838
- }
839
- function CreateAsyncFromSyncIterator(syncIteratorRecord) {
840
- // Instead of re-implementing CreateAsyncFromSyncIterator and %AsyncFromSyncIteratorPrototype%,
841
- // we use yield* inside an async generator function to achieve the same result.
842
- var _a;
843
- // Wrap the sync iterator inside a sync iterable, so we can use it with yield*.
844
- var syncIterable = (_a = {},
845
- _a[SymbolPolyfill.iterator] = function () { return syncIteratorRecord.iterator; },
846
- _a);
847
- // Create an async generator function and immediately invoke it.
848
- var asyncIterator = (function () {
849
- return __asyncGenerator(this, arguments, function () {
850
- return __generator(this, function (_a) {
851
- switch (_a.label) {
852
- case 0: return [5 /*yield**/, __values(__asyncDelegator(__asyncValues(syncIterable)))];
853
- case 1: return [4 /*yield*/, __await.apply(void 0, [_a.sent()])];
854
- case 2: return [4 /*yield*/, __await.apply(void 0, [_a.sent()])];
855
- case 3: return [2 /*return*/, _a.sent()];
856
- }
857
- });
858
- });
859
- }());
860
- // Return as an async iterator record.
861
- var nextMethod = asyncIterator.next;
862
- return { iterator: asyncIterator, nextMethod: nextMethod, done: false };
863
- }
864
- function GetIterator(obj, hint, method) {
865
- if (hint === void 0) { hint = 'sync'; }
866
- if (method === undefined) {
867
- if (hint === 'async') {
868
- method = GetMethod(obj, SymbolPolyfill.asyncIterator);
869
- if (method === undefined) {
870
- var syncMethod = GetMethod(obj, SymbolPolyfill.iterator);
871
- var syncIteratorRecord = GetIterator(obj, 'sync', syncMethod);
872
- return CreateAsyncFromSyncIterator(syncIteratorRecord);
873
- }
874
- }
875
- else {
876
- method = GetMethod(obj, SymbolPolyfill.iterator);
877
- }
878
- }
879
- if (method === undefined) {
880
- throw new TypeError('The object is not iterable');
881
- }
882
- var iterator = reflectCall(method, obj, []);
883
- if (!typeIsObject(iterator)) {
884
- throw new TypeError('The iterator method must return an object');
885
- }
886
- var nextMethod = iterator.next;
887
- return { iterator: iterator, nextMethod: nextMethod, done: false };
888
- }
889
- function IteratorNext(iteratorRecord) {
890
- var result = reflectCall(iteratorRecord.nextMethod, iteratorRecord.iterator, []);
891
- if (!typeIsObject(result)) {
892
- throw new TypeError('The iterator.next() method must return an object');
893
- }
894
- return result;
895
- }
896
- function IteratorComplete(iterResult) {
897
- return Boolean(iterResult.done);
898
- }
899
- function IteratorValue(iterResult) {
900
- return iterResult.value;
901
- }
902
-
903
900
  function IsNonNegativeNumber(v) {
904
901
  if (typeof v !== 'number') {
905
902
  return false;
@@ -4183,6 +4180,10 @@
4183
4180
  var options = convertIteratorOptions(rawOptions, 'First parameter');
4184
4181
  return AcquireReadableStreamAsyncIterator(this, options.preventCancel);
4185
4182
  };
4183
+ ReadableStream.prototype[SymbolAsyncIterator] = function (options) {
4184
+ // Stub implementation, overridden below
4185
+ return this.values(options);
4186
+ };
4186
4187
  /**
4187
4188
  * Creates a new ReadableStream wrapping the provided iterable or async iterable.
4188
4189
  *
@@ -4219,13 +4220,11 @@
4219
4220
  configurable: true
4220
4221
  });
4221
4222
  }
4222
- if (typeof SymbolPolyfill.asyncIterator === 'symbol') {
4223
- Object.defineProperty(ReadableStream.prototype, SymbolPolyfill.asyncIterator, {
4224
- value: ReadableStream.prototype.values,
4225
- writable: true,
4226
- configurable: true
4227
- });
4228
- }
4223
+ Object.defineProperty(ReadableStream.prototype, SymbolAsyncIterator, {
4224
+ value: ReadableStream.prototype.values,
4225
+ writable: true,
4226
+ configurable: true
4227
+ });
4229
4228
  // Abstract operations for the ReadableStream.
4230
4229
  // Throws if and only if startAlgorithm throws.
4231
4230
  function CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm) {