@slicemachine/adapter-next 0.0.3 → 0.0.4
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/SliceSimulator.cjs +14 -41
- package/dist/SliceSimulator.cjs.map +1 -1
- package/dist/SliceSimulator.js +11 -36
- package/dist/SliceSimulator.js.map +1 -1
- package/dist/_virtual/_commonjsHelpers.cjs +5 -0
- package/dist/_virtual/_commonjsHelpers.cjs.map +1 -0
- package/dist/_virtual/_commonjsHelpers.js +5 -0
- package/dist/_virtual/_commonjsHelpers.js.map +1 -0
- package/dist/_virtual/ponyfill.es2018.cjs +5 -0
- package/dist/_virtual/ponyfill.es2018.cjs.map +1 -0
- package/dist/_virtual/ponyfill.es2018.js +5 -0
- package/dist/_virtual/ponyfill.es2018.js.map +1 -0
- package/dist/constants.cjs +5 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +5 -0
- package/dist/constants.js.map +1 -0
- package/dist/hooks/customType-asset-delete.cjs +3 -5
- package/dist/hooks/customType-asset-delete.cjs.map +1 -1
- package/dist/hooks/customType-asset-delete.js.map +1 -1
- package/dist/hooks/customType-asset-read.cjs +3 -5
- package/dist/hooks/customType-asset-read.cjs.map +1 -1
- package/dist/hooks/customType-asset-read.js.map +1 -1
- package/dist/hooks/customType-asset-update.cjs +4 -6
- package/dist/hooks/customType-asset-update.cjs.map +1 -1
- package/dist/hooks/customType-asset-update.js.map +1 -1
- package/dist/hooks/customType-create.cjs +4 -6
- package/dist/hooks/customType-create.cjs.map +1 -1
- package/dist/hooks/customType-create.js.map +1 -1
- package/dist/hooks/customType-delete.cjs +3 -5
- package/dist/hooks/customType-delete.cjs.map +1 -1
- package/dist/hooks/customType-delete.js.map +1 -1
- package/dist/hooks/customType-read.cjs +1 -1
- package/dist/hooks/customType-read.cjs.map +1 -1
- package/dist/hooks/customType-read.js.map +1 -1
- package/dist/hooks/customType-rename.cjs +1 -1
- package/dist/hooks/customType-rename.cjs.map +1 -1
- package/dist/hooks/customType-rename.js.map +1 -1
- package/dist/hooks/customType-update.cjs +1 -1
- package/dist/hooks/customType-update.cjs.map +1 -1
- package/dist/hooks/customType-update.js.map +1 -1
- package/dist/hooks/customTypeLibrary-read.cjs +4 -6
- package/dist/hooks/customTypeLibrary-read.cjs.map +1 -1
- package/dist/hooks/customTypeLibrary-read.js.map +1 -1
- package/dist/hooks/slice-asset-delete.cjs +3 -5
- package/dist/hooks/slice-asset-delete.cjs.map +1 -1
- package/dist/hooks/slice-asset-delete.js.map +1 -1
- package/dist/hooks/slice-asset-read.cjs +3 -5
- package/dist/hooks/slice-asset-read.cjs.map +1 -1
- package/dist/hooks/slice-asset-read.js.map +1 -1
- package/dist/hooks/slice-asset-update.cjs +4 -6
- package/dist/hooks/slice-asset-update.cjs.map +1 -1
- package/dist/hooks/slice-asset-update.js.map +1 -1
- package/dist/hooks/slice-create.cjs +7 -9
- package/dist/hooks/slice-create.cjs.map +1 -1
- package/dist/hooks/slice-create.js +3 -3
- package/dist/hooks/slice-create.js.map +1 -1
- package/dist/hooks/slice-delete.cjs +3 -5
- package/dist/hooks/slice-delete.cjs.map +1 -1
- package/dist/hooks/slice-delete.js.map +1 -1
- package/dist/hooks/slice-read.cjs +4 -6
- package/dist/hooks/slice-read.cjs.map +1 -1
- package/dist/hooks/slice-read.js.map +1 -1
- package/dist/hooks/slice-rename.cjs +3 -5
- package/dist/hooks/slice-rename.cjs.map +1 -1
- package/dist/hooks/slice-rename.js.map +1 -1
- package/dist/hooks/slice-update.cjs +1 -1
- package/dist/hooks/slice-update.cjs.map +1 -1
- package/dist/hooks/slice-update.js.map +1 -1
- package/dist/hooks/sliceLibrary-read.cjs +4 -6
- package/dist/hooks/sliceLibrary-read.cjs.map +1 -1
- package/dist/hooks/sliceLibrary-read.js.map +1 -1
- package/dist/hooks/sliceSimulator-setup-read.cjs +31 -94
- package/dist/hooks/sliceSimulator-setup-read.cjs.map +1 -1
- package/dist/hooks/sliceSimulator-setup-read.js +31 -75
- package/dist/hooks/sliceSimulator-setup-read.js.map +1 -1
- package/dist/hooks/snippet-read.cjs +33 -18
- package/dist/hooks/snippet-read.cjs.map +1 -1
- package/dist/hooks/snippet-read.js +30 -13
- package/dist/hooks/snippet-read.js.map +1 -1
- package/dist/index.cjs +0 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/getJSOrTSXFileExtension.cjs +1 -1
- package/dist/lib/getJSOrTSXFileExtension.cjs.map +1 -1
- package/dist/lib/getJSOrTSXFileExtension.js.map +1 -1
- package/dist/lib/isSharedSliceModel.cjs +3 -5
- package/dist/lib/isSharedSliceModel.cjs.map +1 -1
- package/dist/lib/isSharedSliceModel.js.map +1 -1
- package/dist/lib/pascalCase.cjs +1 -1
- package/dist/lib/pascalCase.cjs.map +1 -1
- package/dist/lib/pascalCase.js.map +1 -1
- package/dist/lib/readJSONFile.cjs +3 -5
- package/dist/lib/readJSONFile.cjs.map +1 -1
- package/dist/lib/readJSONFile.js.map +1 -1
- package/dist/lib/rejectIfNecessary.cjs +1 -1
- package/dist/lib/rejectIfNecessary.cjs.map +1 -1
- package/dist/lib/rejectIfNecessary.js.map +1 -1
- package/dist/lib/updateSliceModelFile.cjs +3 -5
- package/dist/lib/updateSliceModelFile.cjs.map +1 -1
- package/dist/lib/updateSliceModelFile.js.map +1 -1
- package/dist/lib/upsertGlobalContentTypes.cjs +8 -6
- package/dist/lib/upsertGlobalContentTypes.cjs.map +1 -1
- package/dist/lib/upsertGlobalContentTypes.js +4 -0
- package/dist/lib/upsertGlobalContentTypes.js.map +1 -1
- package/dist/lib/upsertSliceLibraryIndexFile.cjs +9 -8
- package/dist/lib/upsertSliceLibraryIndexFile.cjs.map +1 -1
- package/dist/lib/upsertSliceLibraryIndexFile.js +6 -3
- package/dist/lib/upsertSliceLibraryIndexFile.js.map +1 -1
- package/dist/node_modules/data-uri-to-buffer/dist/index.cjs +41 -0
- package/dist/node_modules/data-uri-to-buffer/dist/index.cjs.map +1 -0
- package/dist/node_modules/data-uri-to-buffer/dist/index.js +41 -0
- package/dist/node_modules/data-uri-to-buffer/dist/index.js.map +1 -0
- package/dist/node_modules/fetch-blob/file.cjs +55 -0
- package/dist/node_modules/fetch-blob/file.cjs.map +1 -0
- package/dist/node_modules/fetch-blob/file.js +55 -0
- package/dist/node_modules/fetch-blob/file.js.map +1 -0
- package/dist/node_modules/fetch-blob/index.cjs +176 -0
- package/dist/node_modules/fetch-blob/index.cjs.map +1 -0
- package/dist/node_modules/fetch-blob/index.js +176 -0
- package/dist/node_modules/fetch-blob/index.js.map +1 -0
- package/dist/node_modules/fetch-blob/streams.cjs +43 -0
- package/dist/node_modules/fetch-blob/streams.cjs.map +1 -0
- package/dist/node_modules/fetch-blob/streams.js +42 -0
- package/dist/node_modules/fetch-blob/streams.js.map +1 -0
- package/dist/node_modules/formdata-polyfill/esm.min.cjs +115 -0
- package/dist/node_modules/formdata-polyfill/esm.min.cjs.map +1 -0
- package/dist/node_modules/formdata-polyfill/esm.min.js +115 -0
- package/dist/node_modules/formdata-polyfill/esm.min.js.map +1 -0
- package/dist/node_modules/node-domexception/index.cjs +10 -0
- package/dist/node_modules/node-domexception/index.cjs.map +1 -0
- package/dist/node_modules/node-domexception/index.js +9 -0
- package/dist/node_modules/node-domexception/index.js.map +1 -0
- package/dist/node_modules/node-fetch/src/body.cjs +237 -0
- package/dist/node_modules/node-fetch/src/body.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/body.js +237 -0
- package/dist/node_modules/node-fetch/src/body.js.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/abort-error.cjs +10 -0
- package/dist/node_modules/node-fetch/src/errors/abort-error.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/abort-error.js +10 -0
- package/dist/node_modules/node-fetch/src/errors/abort-error.js.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/base.cjs +17 -0
- package/dist/node_modules/node-fetch/src/errors/base.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/base.js +17 -0
- package/dist/node_modules/node-fetch/src/errors/base.js.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/fetch-error.cjs +14 -0
- package/dist/node_modules/node-fetch/src/errors/fetch-error.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/fetch-error.js +14 -0
- package/dist/node_modules/node-fetch/src/errors/fetch-error.js.map +1 -0
- package/dist/node_modules/node-fetch/src/headers.cjs +173 -0
- package/dist/node_modules/node-fetch/src/headers.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/headers.js +173 -0
- package/dist/node_modules/node-fetch/src/headers.js.map +1 -0
- package/dist/node_modules/node-fetch/src/index.cjs +292 -0
- package/dist/node_modules/node-fetch/src/index.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/index.js +298 -0
- package/dist/node_modules/node-fetch/src/index.js.map +1 -0
- package/dist/node_modules/node-fetch/src/request.cjs +193 -0
- package/dist/node_modules/node-fetch/src/request.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/request.js +193 -0
- package/dist/node_modules/node-fetch/src/request.js.map +1 -0
- package/dist/node_modules/node-fetch/src/response.cjs +110 -0
- package/dist/node_modules/node-fetch/src/response.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/response.js +110 -0
- package/dist/node_modules/node-fetch/src/response.js.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/get-search.cjs +12 -0
- package/dist/node_modules/node-fetch/src/utils/get-search.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/get-search.js +12 -0
- package/dist/node_modules/node-fetch/src/utils/get-search.js.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/is-redirect.cjs +8 -0
- package/dist/node_modules/node-fetch/src/utils/is-redirect.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/is-redirect.js +8 -0
- package/dist/node_modules/node-fetch/src/utils/is-redirect.js.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/is.cjs +28 -0
- package/dist/node_modules/node-fetch/src/utils/is.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/is.js +28 -0
- package/dist/node_modules/node-fetch/src/utils/is.js.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/multipart-parser.cjs +350 -0
- package/dist/node_modules/node-fetch/src/utils/multipart-parser.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/multipart-parser.js +350 -0
- package/dist/node_modules/node-fetch/src/utils/multipart-parser.js.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/referrer.cjs +149 -0
- package/dist/node_modules/node-fetch/src/utils/referrer.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/referrer.js +149 -0
- package/dist/node_modules/node-fetch/src/utils/referrer.js.map +1 -0
- package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs +3599 -0
- package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs.map +1 -0
- package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.js +3599 -0
- package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.js.map +1 -0
- package/dist/package.json.cjs +5 -0
- package/dist/package.json.cjs.map +1 -0
- package/dist/{package.js → package.json.js} +1 -1
- package/dist/package.json.js.map +1 -0
- package/dist/plugin.cjs +2 -2
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.js +1 -1
- package/dist/plugin.js.map +1 -1
- package/package.json +28 -13
- package/src/constants.ts +5 -0
- package/src/hooks/slice-create.ts +3 -3
- package/src/hooks/sliceSimulator-setup-read.ts +37 -76
- package/src/hooks/snippet-read.ts +42 -22
- package/src/index.ts +0 -6
- package/src/lib/upsertGlobalContentTypes.ts +3 -0
- package/src/lib/upsertSliceLibraryIndexFile.ts +11 -6
- package/dist/package.cjs +0 -5
- package/dist/package.cjs.map +0 -1
- package/dist/package.js.map +0 -1
|
@@ -0,0 +1,3599 @@
|
|
|
1
|
+
import { commonjsGlobal } from "../../../_virtual/_commonjsHelpers.js";
|
|
2
|
+
import { p as ponyfill_es2018 } from "../../../_virtual/ponyfill.es2018.js";
|
|
3
|
+
var hasRequiredPonyfill_es2018;
|
|
4
|
+
function requirePonyfill_es2018() {
|
|
5
|
+
if (hasRequiredPonyfill_es2018)
|
|
6
|
+
return ponyfill_es2018.exports;
|
|
7
|
+
hasRequiredPonyfill_es2018 = 1;
|
|
8
|
+
(function(module, exports) {
|
|
9
|
+
(function(global, factory) {
|
|
10
|
+
factory(exports);
|
|
11
|
+
})(commonjsGlobal, function(exports2) {
|
|
12
|
+
const SymbolPolyfill = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? Symbol : (description) => `Symbol(${description})`;
|
|
13
|
+
function noop() {
|
|
14
|
+
return void 0;
|
|
15
|
+
}
|
|
16
|
+
function getGlobals() {
|
|
17
|
+
if (typeof self !== "undefined") {
|
|
18
|
+
return self;
|
|
19
|
+
} else if (typeof window !== "undefined") {
|
|
20
|
+
return window;
|
|
21
|
+
} else if (typeof commonjsGlobal !== "undefined") {
|
|
22
|
+
return commonjsGlobal;
|
|
23
|
+
}
|
|
24
|
+
return void 0;
|
|
25
|
+
}
|
|
26
|
+
const globals = getGlobals();
|
|
27
|
+
function typeIsObject(x) {
|
|
28
|
+
return typeof x === "object" && x !== null || typeof x === "function";
|
|
29
|
+
}
|
|
30
|
+
const rethrowAssertionErrorRejection = noop;
|
|
31
|
+
const originalPromise = Promise;
|
|
32
|
+
const originalPromiseThen = Promise.prototype.then;
|
|
33
|
+
const originalPromiseResolve = Promise.resolve.bind(originalPromise);
|
|
34
|
+
const originalPromiseReject = Promise.reject.bind(originalPromise);
|
|
35
|
+
function newPromise(executor) {
|
|
36
|
+
return new originalPromise(executor);
|
|
37
|
+
}
|
|
38
|
+
function promiseResolvedWith(value) {
|
|
39
|
+
return originalPromiseResolve(value);
|
|
40
|
+
}
|
|
41
|
+
function promiseRejectedWith(reason) {
|
|
42
|
+
return originalPromiseReject(reason);
|
|
43
|
+
}
|
|
44
|
+
function PerformPromiseThen(promise, onFulfilled, onRejected) {
|
|
45
|
+
return originalPromiseThen.call(promise, onFulfilled, onRejected);
|
|
46
|
+
}
|
|
47
|
+
function uponPromise(promise, onFulfilled, onRejected) {
|
|
48
|
+
PerformPromiseThen(PerformPromiseThen(promise, onFulfilled, onRejected), void 0, rethrowAssertionErrorRejection);
|
|
49
|
+
}
|
|
50
|
+
function uponFulfillment(promise, onFulfilled) {
|
|
51
|
+
uponPromise(promise, onFulfilled);
|
|
52
|
+
}
|
|
53
|
+
function uponRejection(promise, onRejected) {
|
|
54
|
+
uponPromise(promise, void 0, onRejected);
|
|
55
|
+
}
|
|
56
|
+
function transformPromiseWith(promise, fulfillmentHandler, rejectionHandler) {
|
|
57
|
+
return PerformPromiseThen(promise, fulfillmentHandler, rejectionHandler);
|
|
58
|
+
}
|
|
59
|
+
function setPromiseIsHandledToTrue(promise) {
|
|
60
|
+
PerformPromiseThen(promise, void 0, rethrowAssertionErrorRejection);
|
|
61
|
+
}
|
|
62
|
+
const queueMicrotask = (() => {
|
|
63
|
+
const globalQueueMicrotask = globals && globals.queueMicrotask;
|
|
64
|
+
if (typeof globalQueueMicrotask === "function") {
|
|
65
|
+
return globalQueueMicrotask;
|
|
66
|
+
}
|
|
67
|
+
const resolvedPromise = promiseResolvedWith(void 0);
|
|
68
|
+
return (fn) => PerformPromiseThen(resolvedPromise, fn);
|
|
69
|
+
})();
|
|
70
|
+
function reflectCall(F, V, args) {
|
|
71
|
+
if (typeof F !== "function") {
|
|
72
|
+
throw new TypeError("Argument is not a function");
|
|
73
|
+
}
|
|
74
|
+
return Function.prototype.apply.call(F, V, args);
|
|
75
|
+
}
|
|
76
|
+
function promiseCall(F, V, args) {
|
|
77
|
+
try {
|
|
78
|
+
return promiseResolvedWith(reflectCall(F, V, args));
|
|
79
|
+
} catch (value) {
|
|
80
|
+
return promiseRejectedWith(value);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const QUEUE_MAX_ARRAY_SIZE = 16384;
|
|
84
|
+
class SimpleQueue {
|
|
85
|
+
constructor() {
|
|
86
|
+
this._cursor = 0;
|
|
87
|
+
this._size = 0;
|
|
88
|
+
this._front = {
|
|
89
|
+
_elements: [],
|
|
90
|
+
_next: void 0
|
|
91
|
+
};
|
|
92
|
+
this._back = this._front;
|
|
93
|
+
this._cursor = 0;
|
|
94
|
+
this._size = 0;
|
|
95
|
+
}
|
|
96
|
+
get length() {
|
|
97
|
+
return this._size;
|
|
98
|
+
}
|
|
99
|
+
push(element) {
|
|
100
|
+
const oldBack = this._back;
|
|
101
|
+
let newBack = oldBack;
|
|
102
|
+
if (oldBack._elements.length === QUEUE_MAX_ARRAY_SIZE - 1) {
|
|
103
|
+
newBack = {
|
|
104
|
+
_elements: [],
|
|
105
|
+
_next: void 0
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
oldBack._elements.push(element);
|
|
109
|
+
if (newBack !== oldBack) {
|
|
110
|
+
this._back = newBack;
|
|
111
|
+
oldBack._next = newBack;
|
|
112
|
+
}
|
|
113
|
+
++this._size;
|
|
114
|
+
}
|
|
115
|
+
shift() {
|
|
116
|
+
const oldFront = this._front;
|
|
117
|
+
let newFront = oldFront;
|
|
118
|
+
const oldCursor = this._cursor;
|
|
119
|
+
let newCursor = oldCursor + 1;
|
|
120
|
+
const elements = oldFront._elements;
|
|
121
|
+
const element = elements[oldCursor];
|
|
122
|
+
if (newCursor === QUEUE_MAX_ARRAY_SIZE) {
|
|
123
|
+
newFront = oldFront._next;
|
|
124
|
+
newCursor = 0;
|
|
125
|
+
}
|
|
126
|
+
--this._size;
|
|
127
|
+
this._cursor = newCursor;
|
|
128
|
+
if (oldFront !== newFront) {
|
|
129
|
+
this._front = newFront;
|
|
130
|
+
}
|
|
131
|
+
elements[oldCursor] = void 0;
|
|
132
|
+
return element;
|
|
133
|
+
}
|
|
134
|
+
forEach(callback) {
|
|
135
|
+
let i = this._cursor;
|
|
136
|
+
let node = this._front;
|
|
137
|
+
let elements = node._elements;
|
|
138
|
+
while (i !== elements.length || node._next !== void 0) {
|
|
139
|
+
if (i === elements.length) {
|
|
140
|
+
node = node._next;
|
|
141
|
+
elements = node._elements;
|
|
142
|
+
i = 0;
|
|
143
|
+
if (elements.length === 0) {
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
callback(elements[i]);
|
|
148
|
+
++i;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
peek() {
|
|
152
|
+
const front = this._front;
|
|
153
|
+
const cursor = this._cursor;
|
|
154
|
+
return front._elements[cursor];
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function ReadableStreamReaderGenericInitialize(reader, stream) {
|
|
158
|
+
reader._ownerReadableStream = stream;
|
|
159
|
+
stream._reader = reader;
|
|
160
|
+
if (stream._state === "readable") {
|
|
161
|
+
defaultReaderClosedPromiseInitialize(reader);
|
|
162
|
+
} else if (stream._state === "closed") {
|
|
163
|
+
defaultReaderClosedPromiseInitializeAsResolved(reader);
|
|
164
|
+
} else {
|
|
165
|
+
defaultReaderClosedPromiseInitializeAsRejected(reader, stream._storedError);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function ReadableStreamReaderGenericCancel(reader, reason) {
|
|
169
|
+
const stream = reader._ownerReadableStream;
|
|
170
|
+
return ReadableStreamCancel(stream, reason);
|
|
171
|
+
}
|
|
172
|
+
function ReadableStreamReaderGenericRelease(reader) {
|
|
173
|
+
if (reader._ownerReadableStream._state === "readable") {
|
|
174
|
+
defaultReaderClosedPromiseReject(reader, new TypeError(`Reader was released and can no longer be used to monitor the stream's closedness`));
|
|
175
|
+
} else {
|
|
176
|
+
defaultReaderClosedPromiseResetToRejected(reader, new TypeError(`Reader was released and can no longer be used to monitor the stream's closedness`));
|
|
177
|
+
}
|
|
178
|
+
reader._ownerReadableStream._reader = void 0;
|
|
179
|
+
reader._ownerReadableStream = void 0;
|
|
180
|
+
}
|
|
181
|
+
function readerLockException(name) {
|
|
182
|
+
return new TypeError("Cannot " + name + " a stream using a released reader");
|
|
183
|
+
}
|
|
184
|
+
function defaultReaderClosedPromiseInitialize(reader) {
|
|
185
|
+
reader._closedPromise = newPromise((resolve, reject) => {
|
|
186
|
+
reader._closedPromise_resolve = resolve;
|
|
187
|
+
reader._closedPromise_reject = reject;
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
function defaultReaderClosedPromiseInitializeAsRejected(reader, reason) {
|
|
191
|
+
defaultReaderClosedPromiseInitialize(reader);
|
|
192
|
+
defaultReaderClosedPromiseReject(reader, reason);
|
|
193
|
+
}
|
|
194
|
+
function defaultReaderClosedPromiseInitializeAsResolved(reader) {
|
|
195
|
+
defaultReaderClosedPromiseInitialize(reader);
|
|
196
|
+
defaultReaderClosedPromiseResolve(reader);
|
|
197
|
+
}
|
|
198
|
+
function defaultReaderClosedPromiseReject(reader, reason) {
|
|
199
|
+
if (reader._closedPromise_reject === void 0) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
setPromiseIsHandledToTrue(reader._closedPromise);
|
|
203
|
+
reader._closedPromise_reject(reason);
|
|
204
|
+
reader._closedPromise_resolve = void 0;
|
|
205
|
+
reader._closedPromise_reject = void 0;
|
|
206
|
+
}
|
|
207
|
+
function defaultReaderClosedPromiseResetToRejected(reader, reason) {
|
|
208
|
+
defaultReaderClosedPromiseInitializeAsRejected(reader, reason);
|
|
209
|
+
}
|
|
210
|
+
function defaultReaderClosedPromiseResolve(reader) {
|
|
211
|
+
if (reader._closedPromise_resolve === void 0) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
reader._closedPromise_resolve(void 0);
|
|
215
|
+
reader._closedPromise_resolve = void 0;
|
|
216
|
+
reader._closedPromise_reject = void 0;
|
|
217
|
+
}
|
|
218
|
+
const AbortSteps = SymbolPolyfill("[[AbortSteps]]");
|
|
219
|
+
const ErrorSteps = SymbolPolyfill("[[ErrorSteps]]");
|
|
220
|
+
const CancelSteps = SymbolPolyfill("[[CancelSteps]]");
|
|
221
|
+
const PullSteps = SymbolPolyfill("[[PullSteps]]");
|
|
222
|
+
const NumberIsFinite = Number.isFinite || function(x) {
|
|
223
|
+
return typeof x === "number" && isFinite(x);
|
|
224
|
+
};
|
|
225
|
+
const MathTrunc = Math.trunc || function(v) {
|
|
226
|
+
return v < 0 ? Math.ceil(v) : Math.floor(v);
|
|
227
|
+
};
|
|
228
|
+
function isDictionary(x) {
|
|
229
|
+
return typeof x === "object" || typeof x === "function";
|
|
230
|
+
}
|
|
231
|
+
function assertDictionary(obj, context) {
|
|
232
|
+
if (obj !== void 0 && !isDictionary(obj)) {
|
|
233
|
+
throw new TypeError(`${context} is not an object.`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function assertFunction(x, context) {
|
|
237
|
+
if (typeof x !== "function") {
|
|
238
|
+
throw new TypeError(`${context} is not a function.`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function isObject(x) {
|
|
242
|
+
return typeof x === "object" && x !== null || typeof x === "function";
|
|
243
|
+
}
|
|
244
|
+
function assertObject(x, context) {
|
|
245
|
+
if (!isObject(x)) {
|
|
246
|
+
throw new TypeError(`${context} is not an object.`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
function assertRequiredArgument(x, position, context) {
|
|
250
|
+
if (x === void 0) {
|
|
251
|
+
throw new TypeError(`Parameter ${position} is required in '${context}'.`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
function assertRequiredField(x, field, context) {
|
|
255
|
+
if (x === void 0) {
|
|
256
|
+
throw new TypeError(`${field} is required in '${context}'.`);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function convertUnrestrictedDouble(value) {
|
|
260
|
+
return Number(value);
|
|
261
|
+
}
|
|
262
|
+
function censorNegativeZero(x) {
|
|
263
|
+
return x === 0 ? 0 : x;
|
|
264
|
+
}
|
|
265
|
+
function integerPart(x) {
|
|
266
|
+
return censorNegativeZero(MathTrunc(x));
|
|
267
|
+
}
|
|
268
|
+
function convertUnsignedLongLongWithEnforceRange(value, context) {
|
|
269
|
+
const lowerBound = 0;
|
|
270
|
+
const upperBound = Number.MAX_SAFE_INTEGER;
|
|
271
|
+
let x = Number(value);
|
|
272
|
+
x = censorNegativeZero(x);
|
|
273
|
+
if (!NumberIsFinite(x)) {
|
|
274
|
+
throw new TypeError(`${context} is not a finite number`);
|
|
275
|
+
}
|
|
276
|
+
x = integerPart(x);
|
|
277
|
+
if (x < lowerBound || x > upperBound) {
|
|
278
|
+
throw new TypeError(`${context} is outside the accepted range of ${lowerBound} to ${upperBound}, inclusive`);
|
|
279
|
+
}
|
|
280
|
+
if (!NumberIsFinite(x) || x === 0) {
|
|
281
|
+
return 0;
|
|
282
|
+
}
|
|
283
|
+
return x;
|
|
284
|
+
}
|
|
285
|
+
function assertReadableStream(x, context) {
|
|
286
|
+
if (!IsReadableStream(x)) {
|
|
287
|
+
throw new TypeError(`${context} is not a ReadableStream.`);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
function AcquireReadableStreamDefaultReader(stream) {
|
|
291
|
+
return new ReadableStreamDefaultReader(stream);
|
|
292
|
+
}
|
|
293
|
+
function ReadableStreamAddReadRequest(stream, readRequest) {
|
|
294
|
+
stream._reader._readRequests.push(readRequest);
|
|
295
|
+
}
|
|
296
|
+
function ReadableStreamFulfillReadRequest(stream, chunk, done) {
|
|
297
|
+
const reader = stream._reader;
|
|
298
|
+
const readRequest = reader._readRequests.shift();
|
|
299
|
+
if (done) {
|
|
300
|
+
readRequest._closeSteps();
|
|
301
|
+
} else {
|
|
302
|
+
readRequest._chunkSteps(chunk);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
function ReadableStreamGetNumReadRequests(stream) {
|
|
306
|
+
return stream._reader._readRequests.length;
|
|
307
|
+
}
|
|
308
|
+
function ReadableStreamHasDefaultReader(stream) {
|
|
309
|
+
const reader = stream._reader;
|
|
310
|
+
if (reader === void 0) {
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
if (!IsReadableStreamDefaultReader(reader)) {
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
318
|
+
class ReadableStreamDefaultReader {
|
|
319
|
+
constructor(stream) {
|
|
320
|
+
assertRequiredArgument(stream, 1, "ReadableStreamDefaultReader");
|
|
321
|
+
assertReadableStream(stream, "First parameter");
|
|
322
|
+
if (IsReadableStreamLocked(stream)) {
|
|
323
|
+
throw new TypeError("This stream has already been locked for exclusive reading by another reader");
|
|
324
|
+
}
|
|
325
|
+
ReadableStreamReaderGenericInitialize(this, stream);
|
|
326
|
+
this._readRequests = new SimpleQueue();
|
|
327
|
+
}
|
|
328
|
+
get closed() {
|
|
329
|
+
if (!IsReadableStreamDefaultReader(this)) {
|
|
330
|
+
return promiseRejectedWith(defaultReaderBrandCheckException("closed"));
|
|
331
|
+
}
|
|
332
|
+
return this._closedPromise;
|
|
333
|
+
}
|
|
334
|
+
cancel(reason = void 0) {
|
|
335
|
+
if (!IsReadableStreamDefaultReader(this)) {
|
|
336
|
+
return promiseRejectedWith(defaultReaderBrandCheckException("cancel"));
|
|
337
|
+
}
|
|
338
|
+
if (this._ownerReadableStream === void 0) {
|
|
339
|
+
return promiseRejectedWith(readerLockException("cancel"));
|
|
340
|
+
}
|
|
341
|
+
return ReadableStreamReaderGenericCancel(this, reason);
|
|
342
|
+
}
|
|
343
|
+
read() {
|
|
344
|
+
if (!IsReadableStreamDefaultReader(this)) {
|
|
345
|
+
return promiseRejectedWith(defaultReaderBrandCheckException("read"));
|
|
346
|
+
}
|
|
347
|
+
if (this._ownerReadableStream === void 0) {
|
|
348
|
+
return promiseRejectedWith(readerLockException("read from"));
|
|
349
|
+
}
|
|
350
|
+
let resolvePromise;
|
|
351
|
+
let rejectPromise;
|
|
352
|
+
const promise = newPromise((resolve, reject) => {
|
|
353
|
+
resolvePromise = resolve;
|
|
354
|
+
rejectPromise = reject;
|
|
355
|
+
});
|
|
356
|
+
const readRequest = {
|
|
357
|
+
_chunkSteps: (chunk) => resolvePromise({ value: chunk, done: false }),
|
|
358
|
+
_closeSteps: () => resolvePromise({ value: void 0, done: true }),
|
|
359
|
+
_errorSteps: (e) => rejectPromise(e)
|
|
360
|
+
};
|
|
361
|
+
ReadableStreamDefaultReaderRead(this, readRequest);
|
|
362
|
+
return promise;
|
|
363
|
+
}
|
|
364
|
+
releaseLock() {
|
|
365
|
+
if (!IsReadableStreamDefaultReader(this)) {
|
|
366
|
+
throw defaultReaderBrandCheckException("releaseLock");
|
|
367
|
+
}
|
|
368
|
+
if (this._ownerReadableStream === void 0) {
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
if (this._readRequests.length > 0) {
|
|
372
|
+
throw new TypeError("Tried to release a reader lock when that reader has pending read() calls un-settled");
|
|
373
|
+
}
|
|
374
|
+
ReadableStreamReaderGenericRelease(this);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
Object.defineProperties(ReadableStreamDefaultReader.prototype, {
|
|
378
|
+
cancel: { enumerable: true },
|
|
379
|
+
read: { enumerable: true },
|
|
380
|
+
releaseLock: { enumerable: true },
|
|
381
|
+
closed: { enumerable: true }
|
|
382
|
+
});
|
|
383
|
+
if (typeof SymbolPolyfill.toStringTag === "symbol") {
|
|
384
|
+
Object.defineProperty(ReadableStreamDefaultReader.prototype, SymbolPolyfill.toStringTag, {
|
|
385
|
+
value: "ReadableStreamDefaultReader",
|
|
386
|
+
configurable: true
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
function IsReadableStreamDefaultReader(x) {
|
|
390
|
+
if (!typeIsObject(x)) {
|
|
391
|
+
return false;
|
|
392
|
+
}
|
|
393
|
+
if (!Object.prototype.hasOwnProperty.call(x, "_readRequests")) {
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
return x instanceof ReadableStreamDefaultReader;
|
|
397
|
+
}
|
|
398
|
+
function ReadableStreamDefaultReaderRead(reader, readRequest) {
|
|
399
|
+
const stream = reader._ownerReadableStream;
|
|
400
|
+
stream._disturbed = true;
|
|
401
|
+
if (stream._state === "closed") {
|
|
402
|
+
readRequest._closeSteps();
|
|
403
|
+
} else if (stream._state === "errored") {
|
|
404
|
+
readRequest._errorSteps(stream._storedError);
|
|
405
|
+
} else {
|
|
406
|
+
stream._readableStreamController[PullSteps](readRequest);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
function defaultReaderBrandCheckException(name) {
|
|
410
|
+
return new TypeError(`ReadableStreamDefaultReader.prototype.${name} can only be used on a ReadableStreamDefaultReader`);
|
|
411
|
+
}
|
|
412
|
+
const AsyncIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf(async function* () {
|
|
413
|
+
}).prototype);
|
|
414
|
+
class ReadableStreamAsyncIteratorImpl {
|
|
415
|
+
constructor(reader, preventCancel) {
|
|
416
|
+
this._ongoingPromise = void 0;
|
|
417
|
+
this._isFinished = false;
|
|
418
|
+
this._reader = reader;
|
|
419
|
+
this._preventCancel = preventCancel;
|
|
420
|
+
}
|
|
421
|
+
next() {
|
|
422
|
+
const nextSteps = () => this._nextSteps();
|
|
423
|
+
this._ongoingPromise = this._ongoingPromise ? transformPromiseWith(this._ongoingPromise, nextSteps, nextSteps) : nextSteps();
|
|
424
|
+
return this._ongoingPromise;
|
|
425
|
+
}
|
|
426
|
+
return(value) {
|
|
427
|
+
const returnSteps = () => this._returnSteps(value);
|
|
428
|
+
return this._ongoingPromise ? transformPromiseWith(this._ongoingPromise, returnSteps, returnSteps) : returnSteps();
|
|
429
|
+
}
|
|
430
|
+
_nextSteps() {
|
|
431
|
+
if (this._isFinished) {
|
|
432
|
+
return Promise.resolve({ value: void 0, done: true });
|
|
433
|
+
}
|
|
434
|
+
const reader = this._reader;
|
|
435
|
+
if (reader._ownerReadableStream === void 0) {
|
|
436
|
+
return promiseRejectedWith(readerLockException("iterate"));
|
|
437
|
+
}
|
|
438
|
+
let resolvePromise;
|
|
439
|
+
let rejectPromise;
|
|
440
|
+
const promise = newPromise((resolve, reject) => {
|
|
441
|
+
resolvePromise = resolve;
|
|
442
|
+
rejectPromise = reject;
|
|
443
|
+
});
|
|
444
|
+
const readRequest = {
|
|
445
|
+
_chunkSteps: (chunk) => {
|
|
446
|
+
this._ongoingPromise = void 0;
|
|
447
|
+
queueMicrotask(() => resolvePromise({ value: chunk, done: false }));
|
|
448
|
+
},
|
|
449
|
+
_closeSteps: () => {
|
|
450
|
+
this._ongoingPromise = void 0;
|
|
451
|
+
this._isFinished = true;
|
|
452
|
+
ReadableStreamReaderGenericRelease(reader);
|
|
453
|
+
resolvePromise({ value: void 0, done: true });
|
|
454
|
+
},
|
|
455
|
+
_errorSteps: (reason) => {
|
|
456
|
+
this._ongoingPromise = void 0;
|
|
457
|
+
this._isFinished = true;
|
|
458
|
+
ReadableStreamReaderGenericRelease(reader);
|
|
459
|
+
rejectPromise(reason);
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
ReadableStreamDefaultReaderRead(reader, readRequest);
|
|
463
|
+
return promise;
|
|
464
|
+
}
|
|
465
|
+
_returnSteps(value) {
|
|
466
|
+
if (this._isFinished) {
|
|
467
|
+
return Promise.resolve({ value, done: true });
|
|
468
|
+
}
|
|
469
|
+
this._isFinished = true;
|
|
470
|
+
const reader = this._reader;
|
|
471
|
+
if (reader._ownerReadableStream === void 0) {
|
|
472
|
+
return promiseRejectedWith(readerLockException("finish iterating"));
|
|
473
|
+
}
|
|
474
|
+
if (!this._preventCancel) {
|
|
475
|
+
const result = ReadableStreamReaderGenericCancel(reader, value);
|
|
476
|
+
ReadableStreamReaderGenericRelease(reader);
|
|
477
|
+
return transformPromiseWith(result, () => ({ value, done: true }));
|
|
478
|
+
}
|
|
479
|
+
ReadableStreamReaderGenericRelease(reader);
|
|
480
|
+
return promiseResolvedWith({ value, done: true });
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
const ReadableStreamAsyncIteratorPrototype = {
|
|
484
|
+
next() {
|
|
485
|
+
if (!IsReadableStreamAsyncIterator(this)) {
|
|
486
|
+
return promiseRejectedWith(streamAsyncIteratorBrandCheckException("next"));
|
|
487
|
+
}
|
|
488
|
+
return this._asyncIteratorImpl.next();
|
|
489
|
+
},
|
|
490
|
+
return(value) {
|
|
491
|
+
if (!IsReadableStreamAsyncIterator(this)) {
|
|
492
|
+
return promiseRejectedWith(streamAsyncIteratorBrandCheckException("return"));
|
|
493
|
+
}
|
|
494
|
+
return this._asyncIteratorImpl.return(value);
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
if (AsyncIteratorPrototype !== void 0) {
|
|
498
|
+
Object.setPrototypeOf(ReadableStreamAsyncIteratorPrototype, AsyncIteratorPrototype);
|
|
499
|
+
}
|
|
500
|
+
function AcquireReadableStreamAsyncIterator(stream, preventCancel) {
|
|
501
|
+
const reader = AcquireReadableStreamDefaultReader(stream);
|
|
502
|
+
const impl = new ReadableStreamAsyncIteratorImpl(reader, preventCancel);
|
|
503
|
+
const iterator = Object.create(ReadableStreamAsyncIteratorPrototype);
|
|
504
|
+
iterator._asyncIteratorImpl = impl;
|
|
505
|
+
return iterator;
|
|
506
|
+
}
|
|
507
|
+
function IsReadableStreamAsyncIterator(x) {
|
|
508
|
+
if (!typeIsObject(x)) {
|
|
509
|
+
return false;
|
|
510
|
+
}
|
|
511
|
+
if (!Object.prototype.hasOwnProperty.call(x, "_asyncIteratorImpl")) {
|
|
512
|
+
return false;
|
|
513
|
+
}
|
|
514
|
+
try {
|
|
515
|
+
return x._asyncIteratorImpl instanceof ReadableStreamAsyncIteratorImpl;
|
|
516
|
+
} catch (_a) {
|
|
517
|
+
return false;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
function streamAsyncIteratorBrandCheckException(name) {
|
|
521
|
+
return new TypeError(`ReadableStreamAsyncIterator.${name} can only be used on a ReadableSteamAsyncIterator`);
|
|
522
|
+
}
|
|
523
|
+
const NumberIsNaN = Number.isNaN || function(x) {
|
|
524
|
+
return x !== x;
|
|
525
|
+
};
|
|
526
|
+
function CreateArrayFromList(elements) {
|
|
527
|
+
return elements.slice();
|
|
528
|
+
}
|
|
529
|
+
function CopyDataBlockBytes(dest, destOffset, src, srcOffset, n) {
|
|
530
|
+
new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset);
|
|
531
|
+
}
|
|
532
|
+
function TransferArrayBuffer(O) {
|
|
533
|
+
return O;
|
|
534
|
+
}
|
|
535
|
+
function IsDetachedBuffer(O) {
|
|
536
|
+
return false;
|
|
537
|
+
}
|
|
538
|
+
function ArrayBufferSlice(buffer, begin, end) {
|
|
539
|
+
if (buffer.slice) {
|
|
540
|
+
return buffer.slice(begin, end);
|
|
541
|
+
}
|
|
542
|
+
const length = end - begin;
|
|
543
|
+
const slice = new ArrayBuffer(length);
|
|
544
|
+
CopyDataBlockBytes(slice, 0, buffer, begin, length);
|
|
545
|
+
return slice;
|
|
546
|
+
}
|
|
547
|
+
function IsNonNegativeNumber(v) {
|
|
548
|
+
if (typeof v !== "number") {
|
|
549
|
+
return false;
|
|
550
|
+
}
|
|
551
|
+
if (NumberIsNaN(v)) {
|
|
552
|
+
return false;
|
|
553
|
+
}
|
|
554
|
+
if (v < 0) {
|
|
555
|
+
return false;
|
|
556
|
+
}
|
|
557
|
+
return true;
|
|
558
|
+
}
|
|
559
|
+
function CloneAsUint8Array(O) {
|
|
560
|
+
const buffer = ArrayBufferSlice(O.buffer, O.byteOffset, O.byteOffset + O.byteLength);
|
|
561
|
+
return new Uint8Array(buffer);
|
|
562
|
+
}
|
|
563
|
+
function DequeueValue(container) {
|
|
564
|
+
const pair = container._queue.shift();
|
|
565
|
+
container._queueTotalSize -= pair.size;
|
|
566
|
+
if (container._queueTotalSize < 0) {
|
|
567
|
+
container._queueTotalSize = 0;
|
|
568
|
+
}
|
|
569
|
+
return pair.value;
|
|
570
|
+
}
|
|
571
|
+
function EnqueueValueWithSize(container, value, size) {
|
|
572
|
+
if (!IsNonNegativeNumber(size) || size === Infinity) {
|
|
573
|
+
throw new RangeError("Size must be a finite, non-NaN, non-negative number.");
|
|
574
|
+
}
|
|
575
|
+
container._queue.push({ value, size });
|
|
576
|
+
container._queueTotalSize += size;
|
|
577
|
+
}
|
|
578
|
+
function PeekQueueValue(container) {
|
|
579
|
+
const pair = container._queue.peek();
|
|
580
|
+
return pair.value;
|
|
581
|
+
}
|
|
582
|
+
function ResetQueue(container) {
|
|
583
|
+
container._queue = new SimpleQueue();
|
|
584
|
+
container._queueTotalSize = 0;
|
|
585
|
+
}
|
|
586
|
+
class ReadableStreamBYOBRequest {
|
|
587
|
+
constructor() {
|
|
588
|
+
throw new TypeError("Illegal constructor");
|
|
589
|
+
}
|
|
590
|
+
get view() {
|
|
591
|
+
if (!IsReadableStreamBYOBRequest(this)) {
|
|
592
|
+
throw byobRequestBrandCheckException("view");
|
|
593
|
+
}
|
|
594
|
+
return this._view;
|
|
595
|
+
}
|
|
596
|
+
respond(bytesWritten) {
|
|
597
|
+
if (!IsReadableStreamBYOBRequest(this)) {
|
|
598
|
+
throw byobRequestBrandCheckException("respond");
|
|
599
|
+
}
|
|
600
|
+
assertRequiredArgument(bytesWritten, 1, "respond");
|
|
601
|
+
bytesWritten = convertUnsignedLongLongWithEnforceRange(bytesWritten, "First parameter");
|
|
602
|
+
if (this._associatedReadableByteStreamController === void 0) {
|
|
603
|
+
throw new TypeError("This BYOB request has been invalidated");
|
|
604
|
+
}
|
|
605
|
+
if (IsDetachedBuffer(this._view.buffer))
|
|
606
|
+
;
|
|
607
|
+
ReadableByteStreamControllerRespond(this._associatedReadableByteStreamController, bytesWritten);
|
|
608
|
+
}
|
|
609
|
+
respondWithNewView(view) {
|
|
610
|
+
if (!IsReadableStreamBYOBRequest(this)) {
|
|
611
|
+
throw byobRequestBrandCheckException("respondWithNewView");
|
|
612
|
+
}
|
|
613
|
+
assertRequiredArgument(view, 1, "respondWithNewView");
|
|
614
|
+
if (!ArrayBuffer.isView(view)) {
|
|
615
|
+
throw new TypeError("You can only respond with array buffer views");
|
|
616
|
+
}
|
|
617
|
+
if (this._associatedReadableByteStreamController === void 0) {
|
|
618
|
+
throw new TypeError("This BYOB request has been invalidated");
|
|
619
|
+
}
|
|
620
|
+
if (IsDetachedBuffer(view.buffer))
|
|
621
|
+
;
|
|
622
|
+
ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
Object.defineProperties(ReadableStreamBYOBRequest.prototype, {
|
|
626
|
+
respond: { enumerable: true },
|
|
627
|
+
respondWithNewView: { enumerable: true },
|
|
628
|
+
view: { enumerable: true }
|
|
629
|
+
});
|
|
630
|
+
if (typeof SymbolPolyfill.toStringTag === "symbol") {
|
|
631
|
+
Object.defineProperty(ReadableStreamBYOBRequest.prototype, SymbolPolyfill.toStringTag, {
|
|
632
|
+
value: "ReadableStreamBYOBRequest",
|
|
633
|
+
configurable: true
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
class ReadableByteStreamController {
|
|
637
|
+
constructor() {
|
|
638
|
+
throw new TypeError("Illegal constructor");
|
|
639
|
+
}
|
|
640
|
+
get byobRequest() {
|
|
641
|
+
if (!IsReadableByteStreamController(this)) {
|
|
642
|
+
throw byteStreamControllerBrandCheckException("byobRequest");
|
|
643
|
+
}
|
|
644
|
+
return ReadableByteStreamControllerGetBYOBRequest(this);
|
|
645
|
+
}
|
|
646
|
+
get desiredSize() {
|
|
647
|
+
if (!IsReadableByteStreamController(this)) {
|
|
648
|
+
throw byteStreamControllerBrandCheckException("desiredSize");
|
|
649
|
+
}
|
|
650
|
+
return ReadableByteStreamControllerGetDesiredSize(this);
|
|
651
|
+
}
|
|
652
|
+
close() {
|
|
653
|
+
if (!IsReadableByteStreamController(this)) {
|
|
654
|
+
throw byteStreamControllerBrandCheckException("close");
|
|
655
|
+
}
|
|
656
|
+
if (this._closeRequested) {
|
|
657
|
+
throw new TypeError("The stream has already been closed; do not close it again!");
|
|
658
|
+
}
|
|
659
|
+
const state = this._controlledReadableByteStream._state;
|
|
660
|
+
if (state !== "readable") {
|
|
661
|
+
throw new TypeError(`The stream (in ${state} state) is not in the readable state and cannot be closed`);
|
|
662
|
+
}
|
|
663
|
+
ReadableByteStreamControllerClose(this);
|
|
664
|
+
}
|
|
665
|
+
enqueue(chunk) {
|
|
666
|
+
if (!IsReadableByteStreamController(this)) {
|
|
667
|
+
throw byteStreamControllerBrandCheckException("enqueue");
|
|
668
|
+
}
|
|
669
|
+
assertRequiredArgument(chunk, 1, "enqueue");
|
|
670
|
+
if (!ArrayBuffer.isView(chunk)) {
|
|
671
|
+
throw new TypeError("chunk must be an array buffer view");
|
|
672
|
+
}
|
|
673
|
+
if (chunk.byteLength === 0) {
|
|
674
|
+
throw new TypeError("chunk must have non-zero byteLength");
|
|
675
|
+
}
|
|
676
|
+
if (chunk.buffer.byteLength === 0) {
|
|
677
|
+
throw new TypeError(`chunk's buffer must have non-zero byteLength`);
|
|
678
|
+
}
|
|
679
|
+
if (this._closeRequested) {
|
|
680
|
+
throw new TypeError("stream is closed or draining");
|
|
681
|
+
}
|
|
682
|
+
const state = this._controlledReadableByteStream._state;
|
|
683
|
+
if (state !== "readable") {
|
|
684
|
+
throw new TypeError(`The stream (in ${state} state) is not in the readable state and cannot be enqueued to`);
|
|
685
|
+
}
|
|
686
|
+
ReadableByteStreamControllerEnqueue(this, chunk);
|
|
687
|
+
}
|
|
688
|
+
error(e = void 0) {
|
|
689
|
+
if (!IsReadableByteStreamController(this)) {
|
|
690
|
+
throw byteStreamControllerBrandCheckException("error");
|
|
691
|
+
}
|
|
692
|
+
ReadableByteStreamControllerError(this, e);
|
|
693
|
+
}
|
|
694
|
+
[CancelSteps](reason) {
|
|
695
|
+
ReadableByteStreamControllerClearPendingPullIntos(this);
|
|
696
|
+
ResetQueue(this);
|
|
697
|
+
const result = this._cancelAlgorithm(reason);
|
|
698
|
+
ReadableByteStreamControllerClearAlgorithms(this);
|
|
699
|
+
return result;
|
|
700
|
+
}
|
|
701
|
+
[PullSteps](readRequest) {
|
|
702
|
+
const stream = this._controlledReadableByteStream;
|
|
703
|
+
if (this._queueTotalSize > 0) {
|
|
704
|
+
const entry = this._queue.shift();
|
|
705
|
+
this._queueTotalSize -= entry.byteLength;
|
|
706
|
+
ReadableByteStreamControllerHandleQueueDrain(this);
|
|
707
|
+
const view = new Uint8Array(entry.buffer, entry.byteOffset, entry.byteLength);
|
|
708
|
+
readRequest._chunkSteps(view);
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
const autoAllocateChunkSize = this._autoAllocateChunkSize;
|
|
712
|
+
if (autoAllocateChunkSize !== void 0) {
|
|
713
|
+
let buffer;
|
|
714
|
+
try {
|
|
715
|
+
buffer = new ArrayBuffer(autoAllocateChunkSize);
|
|
716
|
+
} catch (bufferE) {
|
|
717
|
+
readRequest._errorSteps(bufferE);
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
const pullIntoDescriptor = {
|
|
721
|
+
buffer,
|
|
722
|
+
bufferByteLength: autoAllocateChunkSize,
|
|
723
|
+
byteOffset: 0,
|
|
724
|
+
byteLength: autoAllocateChunkSize,
|
|
725
|
+
bytesFilled: 0,
|
|
726
|
+
elementSize: 1,
|
|
727
|
+
viewConstructor: Uint8Array,
|
|
728
|
+
readerType: "default"
|
|
729
|
+
};
|
|
730
|
+
this._pendingPullIntos.push(pullIntoDescriptor);
|
|
731
|
+
}
|
|
732
|
+
ReadableStreamAddReadRequest(stream, readRequest);
|
|
733
|
+
ReadableByteStreamControllerCallPullIfNeeded(this);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
Object.defineProperties(ReadableByteStreamController.prototype, {
|
|
737
|
+
close: { enumerable: true },
|
|
738
|
+
enqueue: { enumerable: true },
|
|
739
|
+
error: { enumerable: true },
|
|
740
|
+
byobRequest: { enumerable: true },
|
|
741
|
+
desiredSize: { enumerable: true }
|
|
742
|
+
});
|
|
743
|
+
if (typeof SymbolPolyfill.toStringTag === "symbol") {
|
|
744
|
+
Object.defineProperty(ReadableByteStreamController.prototype, SymbolPolyfill.toStringTag, {
|
|
745
|
+
value: "ReadableByteStreamController",
|
|
746
|
+
configurable: true
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
function IsReadableByteStreamController(x) {
|
|
750
|
+
if (!typeIsObject(x)) {
|
|
751
|
+
return false;
|
|
752
|
+
}
|
|
753
|
+
if (!Object.prototype.hasOwnProperty.call(x, "_controlledReadableByteStream")) {
|
|
754
|
+
return false;
|
|
755
|
+
}
|
|
756
|
+
return x instanceof ReadableByteStreamController;
|
|
757
|
+
}
|
|
758
|
+
function IsReadableStreamBYOBRequest(x) {
|
|
759
|
+
if (!typeIsObject(x)) {
|
|
760
|
+
return false;
|
|
761
|
+
}
|
|
762
|
+
if (!Object.prototype.hasOwnProperty.call(x, "_associatedReadableByteStreamController")) {
|
|
763
|
+
return false;
|
|
764
|
+
}
|
|
765
|
+
return x instanceof ReadableStreamBYOBRequest;
|
|
766
|
+
}
|
|
767
|
+
function ReadableByteStreamControllerCallPullIfNeeded(controller) {
|
|
768
|
+
const shouldPull = ReadableByteStreamControllerShouldCallPull(controller);
|
|
769
|
+
if (!shouldPull) {
|
|
770
|
+
return;
|
|
771
|
+
}
|
|
772
|
+
if (controller._pulling) {
|
|
773
|
+
controller._pullAgain = true;
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
controller._pulling = true;
|
|
777
|
+
const pullPromise = controller._pullAlgorithm();
|
|
778
|
+
uponPromise(pullPromise, () => {
|
|
779
|
+
controller._pulling = false;
|
|
780
|
+
if (controller._pullAgain) {
|
|
781
|
+
controller._pullAgain = false;
|
|
782
|
+
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
783
|
+
}
|
|
784
|
+
}, (e) => {
|
|
785
|
+
ReadableByteStreamControllerError(controller, e);
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
function ReadableByteStreamControllerClearPendingPullIntos(controller) {
|
|
789
|
+
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
790
|
+
controller._pendingPullIntos = new SimpleQueue();
|
|
791
|
+
}
|
|
792
|
+
function ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor) {
|
|
793
|
+
let done = false;
|
|
794
|
+
if (stream._state === "closed") {
|
|
795
|
+
done = true;
|
|
796
|
+
}
|
|
797
|
+
const filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor);
|
|
798
|
+
if (pullIntoDescriptor.readerType === "default") {
|
|
799
|
+
ReadableStreamFulfillReadRequest(stream, filledView, done);
|
|
800
|
+
} else {
|
|
801
|
+
ReadableStreamFulfillReadIntoRequest(stream, filledView, done);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
function ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor) {
|
|
805
|
+
const bytesFilled = pullIntoDescriptor.bytesFilled;
|
|
806
|
+
const elementSize = pullIntoDescriptor.elementSize;
|
|
807
|
+
return new pullIntoDescriptor.viewConstructor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, bytesFilled / elementSize);
|
|
808
|
+
}
|
|
809
|
+
function ReadableByteStreamControllerEnqueueChunkToQueue(controller, buffer, byteOffset, byteLength) {
|
|
810
|
+
controller._queue.push({ buffer, byteOffset, byteLength });
|
|
811
|
+
controller._queueTotalSize += byteLength;
|
|
812
|
+
}
|
|
813
|
+
function ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) {
|
|
814
|
+
const elementSize = pullIntoDescriptor.elementSize;
|
|
815
|
+
const currentAlignedBytes = pullIntoDescriptor.bytesFilled - pullIntoDescriptor.bytesFilled % elementSize;
|
|
816
|
+
const maxBytesToCopy = Math.min(controller._queueTotalSize, pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled);
|
|
817
|
+
const maxBytesFilled = pullIntoDescriptor.bytesFilled + maxBytesToCopy;
|
|
818
|
+
const maxAlignedBytes = maxBytesFilled - maxBytesFilled % elementSize;
|
|
819
|
+
let totalBytesToCopyRemaining = maxBytesToCopy;
|
|
820
|
+
let ready = false;
|
|
821
|
+
if (maxAlignedBytes > currentAlignedBytes) {
|
|
822
|
+
totalBytesToCopyRemaining = maxAlignedBytes - pullIntoDescriptor.bytesFilled;
|
|
823
|
+
ready = true;
|
|
824
|
+
}
|
|
825
|
+
const queue = controller._queue;
|
|
826
|
+
while (totalBytesToCopyRemaining > 0) {
|
|
827
|
+
const headOfQueue = queue.peek();
|
|
828
|
+
const bytesToCopy = Math.min(totalBytesToCopyRemaining, headOfQueue.byteLength);
|
|
829
|
+
const destStart = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;
|
|
830
|
+
CopyDataBlockBytes(pullIntoDescriptor.buffer, destStart, headOfQueue.buffer, headOfQueue.byteOffset, bytesToCopy);
|
|
831
|
+
if (headOfQueue.byteLength === bytesToCopy) {
|
|
832
|
+
queue.shift();
|
|
833
|
+
} else {
|
|
834
|
+
headOfQueue.byteOffset += bytesToCopy;
|
|
835
|
+
headOfQueue.byteLength -= bytesToCopy;
|
|
836
|
+
}
|
|
837
|
+
controller._queueTotalSize -= bytesToCopy;
|
|
838
|
+
ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesToCopy, pullIntoDescriptor);
|
|
839
|
+
totalBytesToCopyRemaining -= bytesToCopy;
|
|
840
|
+
}
|
|
841
|
+
return ready;
|
|
842
|
+
}
|
|
843
|
+
function ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, size, pullIntoDescriptor) {
|
|
844
|
+
pullIntoDescriptor.bytesFilled += size;
|
|
845
|
+
}
|
|
846
|
+
function ReadableByteStreamControllerHandleQueueDrain(controller) {
|
|
847
|
+
if (controller._queueTotalSize === 0 && controller._closeRequested) {
|
|
848
|
+
ReadableByteStreamControllerClearAlgorithms(controller);
|
|
849
|
+
ReadableStreamClose(controller._controlledReadableByteStream);
|
|
850
|
+
} else {
|
|
851
|
+
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
function ReadableByteStreamControllerInvalidateBYOBRequest(controller) {
|
|
855
|
+
if (controller._byobRequest === null) {
|
|
856
|
+
return;
|
|
857
|
+
}
|
|
858
|
+
controller._byobRequest._associatedReadableByteStreamController = void 0;
|
|
859
|
+
controller._byobRequest._view = null;
|
|
860
|
+
controller._byobRequest = null;
|
|
861
|
+
}
|
|
862
|
+
function ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller) {
|
|
863
|
+
while (controller._pendingPullIntos.length > 0) {
|
|
864
|
+
if (controller._queueTotalSize === 0) {
|
|
865
|
+
return;
|
|
866
|
+
}
|
|
867
|
+
const pullIntoDescriptor = controller._pendingPullIntos.peek();
|
|
868
|
+
if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor)) {
|
|
869
|
+
ReadableByteStreamControllerShiftPendingPullInto(controller);
|
|
870
|
+
ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableByteStream, pullIntoDescriptor);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
function ReadableByteStreamControllerPullInto(controller, view, readIntoRequest) {
|
|
875
|
+
const stream = controller._controlledReadableByteStream;
|
|
876
|
+
let elementSize = 1;
|
|
877
|
+
if (view.constructor !== DataView) {
|
|
878
|
+
elementSize = view.constructor.BYTES_PER_ELEMENT;
|
|
879
|
+
}
|
|
880
|
+
const ctor = view.constructor;
|
|
881
|
+
const buffer = TransferArrayBuffer(view.buffer);
|
|
882
|
+
const pullIntoDescriptor = {
|
|
883
|
+
buffer,
|
|
884
|
+
bufferByteLength: buffer.byteLength,
|
|
885
|
+
byteOffset: view.byteOffset,
|
|
886
|
+
byteLength: view.byteLength,
|
|
887
|
+
bytesFilled: 0,
|
|
888
|
+
elementSize,
|
|
889
|
+
viewConstructor: ctor,
|
|
890
|
+
readerType: "byob"
|
|
891
|
+
};
|
|
892
|
+
if (controller._pendingPullIntos.length > 0) {
|
|
893
|
+
controller._pendingPullIntos.push(pullIntoDescriptor);
|
|
894
|
+
ReadableStreamAddReadIntoRequest(stream, readIntoRequest);
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
if (stream._state === "closed") {
|
|
898
|
+
const emptyView = new ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, 0);
|
|
899
|
+
readIntoRequest._closeSteps(emptyView);
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
if (controller._queueTotalSize > 0) {
|
|
903
|
+
if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor)) {
|
|
904
|
+
const filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor);
|
|
905
|
+
ReadableByteStreamControllerHandleQueueDrain(controller);
|
|
906
|
+
readIntoRequest._chunkSteps(filledView);
|
|
907
|
+
return;
|
|
908
|
+
}
|
|
909
|
+
if (controller._closeRequested) {
|
|
910
|
+
const e = new TypeError("Insufficient bytes to fill elements in the given buffer");
|
|
911
|
+
ReadableByteStreamControllerError(controller, e);
|
|
912
|
+
readIntoRequest._errorSteps(e);
|
|
913
|
+
return;
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
controller._pendingPullIntos.push(pullIntoDescriptor);
|
|
917
|
+
ReadableStreamAddReadIntoRequest(stream, readIntoRequest);
|
|
918
|
+
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
919
|
+
}
|
|
920
|
+
function ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor) {
|
|
921
|
+
const stream = controller._controlledReadableByteStream;
|
|
922
|
+
if (ReadableStreamHasBYOBReader(stream)) {
|
|
923
|
+
while (ReadableStreamGetNumReadIntoRequests(stream) > 0) {
|
|
924
|
+
const pullIntoDescriptor = ReadableByteStreamControllerShiftPendingPullInto(controller);
|
|
925
|
+
ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor);
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
function ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor) {
|
|
930
|
+
ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesWritten, pullIntoDescriptor);
|
|
931
|
+
if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize) {
|
|
932
|
+
return;
|
|
933
|
+
}
|
|
934
|
+
ReadableByteStreamControllerShiftPendingPullInto(controller);
|
|
935
|
+
const remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize;
|
|
936
|
+
if (remainderSize > 0) {
|
|
937
|
+
const end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;
|
|
938
|
+
const remainder = ArrayBufferSlice(pullIntoDescriptor.buffer, end - remainderSize, end);
|
|
939
|
+
ReadableByteStreamControllerEnqueueChunkToQueue(controller, remainder, 0, remainder.byteLength);
|
|
940
|
+
}
|
|
941
|
+
pullIntoDescriptor.bytesFilled -= remainderSize;
|
|
942
|
+
ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableByteStream, pullIntoDescriptor);
|
|
943
|
+
ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);
|
|
944
|
+
}
|
|
945
|
+
function ReadableByteStreamControllerRespondInternal(controller, bytesWritten) {
|
|
946
|
+
const firstDescriptor = controller._pendingPullIntos.peek();
|
|
947
|
+
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
948
|
+
const state = controller._controlledReadableByteStream._state;
|
|
949
|
+
if (state === "closed") {
|
|
950
|
+
ReadableByteStreamControllerRespondInClosedState(controller);
|
|
951
|
+
} else {
|
|
952
|
+
ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor);
|
|
953
|
+
}
|
|
954
|
+
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
955
|
+
}
|
|
956
|
+
function ReadableByteStreamControllerShiftPendingPullInto(controller) {
|
|
957
|
+
const descriptor = controller._pendingPullIntos.shift();
|
|
958
|
+
return descriptor;
|
|
959
|
+
}
|
|
960
|
+
function ReadableByteStreamControllerShouldCallPull(controller) {
|
|
961
|
+
const stream = controller._controlledReadableByteStream;
|
|
962
|
+
if (stream._state !== "readable") {
|
|
963
|
+
return false;
|
|
964
|
+
}
|
|
965
|
+
if (controller._closeRequested) {
|
|
966
|
+
return false;
|
|
967
|
+
}
|
|
968
|
+
if (!controller._started) {
|
|
969
|
+
return false;
|
|
970
|
+
}
|
|
971
|
+
if (ReadableStreamHasDefaultReader(stream) && ReadableStreamGetNumReadRequests(stream) > 0) {
|
|
972
|
+
return true;
|
|
973
|
+
}
|
|
974
|
+
if (ReadableStreamHasBYOBReader(stream) && ReadableStreamGetNumReadIntoRequests(stream) > 0) {
|
|
975
|
+
return true;
|
|
976
|
+
}
|
|
977
|
+
const desiredSize = ReadableByteStreamControllerGetDesiredSize(controller);
|
|
978
|
+
if (desiredSize > 0) {
|
|
979
|
+
return true;
|
|
980
|
+
}
|
|
981
|
+
return false;
|
|
982
|
+
}
|
|
983
|
+
function ReadableByteStreamControllerClearAlgorithms(controller) {
|
|
984
|
+
controller._pullAlgorithm = void 0;
|
|
985
|
+
controller._cancelAlgorithm = void 0;
|
|
986
|
+
}
|
|
987
|
+
function ReadableByteStreamControllerClose(controller) {
|
|
988
|
+
const stream = controller._controlledReadableByteStream;
|
|
989
|
+
if (controller._closeRequested || stream._state !== "readable") {
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
if (controller._queueTotalSize > 0) {
|
|
993
|
+
controller._closeRequested = true;
|
|
994
|
+
return;
|
|
995
|
+
}
|
|
996
|
+
if (controller._pendingPullIntos.length > 0) {
|
|
997
|
+
const firstPendingPullInto = controller._pendingPullIntos.peek();
|
|
998
|
+
if (firstPendingPullInto.bytesFilled > 0) {
|
|
999
|
+
const e = new TypeError("Insufficient bytes to fill elements in the given buffer");
|
|
1000
|
+
ReadableByteStreamControllerError(controller, e);
|
|
1001
|
+
throw e;
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
ReadableByteStreamControllerClearAlgorithms(controller);
|
|
1005
|
+
ReadableStreamClose(stream);
|
|
1006
|
+
}
|
|
1007
|
+
function ReadableByteStreamControllerEnqueue(controller, chunk) {
|
|
1008
|
+
const stream = controller._controlledReadableByteStream;
|
|
1009
|
+
if (controller._closeRequested || stream._state !== "readable") {
|
|
1010
|
+
return;
|
|
1011
|
+
}
|
|
1012
|
+
const buffer = chunk.buffer;
|
|
1013
|
+
const byteOffset = chunk.byteOffset;
|
|
1014
|
+
const byteLength = chunk.byteLength;
|
|
1015
|
+
const transferredBuffer = TransferArrayBuffer(buffer);
|
|
1016
|
+
if (controller._pendingPullIntos.length > 0) {
|
|
1017
|
+
const firstPendingPullInto = controller._pendingPullIntos.peek();
|
|
1018
|
+
if (IsDetachedBuffer(firstPendingPullInto.buffer))
|
|
1019
|
+
;
|
|
1020
|
+
firstPendingPullInto.buffer = TransferArrayBuffer(firstPendingPullInto.buffer);
|
|
1021
|
+
}
|
|
1022
|
+
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
1023
|
+
if (ReadableStreamHasDefaultReader(stream)) {
|
|
1024
|
+
if (ReadableStreamGetNumReadRequests(stream) === 0) {
|
|
1025
|
+
ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
|
|
1026
|
+
} else {
|
|
1027
|
+
if (controller._pendingPullIntos.length > 0) {
|
|
1028
|
+
ReadableByteStreamControllerShiftPendingPullInto(controller);
|
|
1029
|
+
}
|
|
1030
|
+
const transferredView = new Uint8Array(transferredBuffer, byteOffset, byteLength);
|
|
1031
|
+
ReadableStreamFulfillReadRequest(stream, transferredView, false);
|
|
1032
|
+
}
|
|
1033
|
+
} else if (ReadableStreamHasBYOBReader(stream)) {
|
|
1034
|
+
ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
|
|
1035
|
+
ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);
|
|
1036
|
+
} else {
|
|
1037
|
+
ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
|
|
1038
|
+
}
|
|
1039
|
+
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
1040
|
+
}
|
|
1041
|
+
function ReadableByteStreamControllerError(controller, e) {
|
|
1042
|
+
const stream = controller._controlledReadableByteStream;
|
|
1043
|
+
if (stream._state !== "readable") {
|
|
1044
|
+
return;
|
|
1045
|
+
}
|
|
1046
|
+
ReadableByteStreamControllerClearPendingPullIntos(controller);
|
|
1047
|
+
ResetQueue(controller);
|
|
1048
|
+
ReadableByteStreamControllerClearAlgorithms(controller);
|
|
1049
|
+
ReadableStreamError(stream, e);
|
|
1050
|
+
}
|
|
1051
|
+
function ReadableByteStreamControllerGetBYOBRequest(controller) {
|
|
1052
|
+
if (controller._byobRequest === null && controller._pendingPullIntos.length > 0) {
|
|
1053
|
+
const firstDescriptor = controller._pendingPullIntos.peek();
|
|
1054
|
+
const view = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled);
|
|
1055
|
+
const byobRequest = Object.create(ReadableStreamBYOBRequest.prototype);
|
|
1056
|
+
SetUpReadableStreamBYOBRequest(byobRequest, controller, view);
|
|
1057
|
+
controller._byobRequest = byobRequest;
|
|
1058
|
+
}
|
|
1059
|
+
return controller._byobRequest;
|
|
1060
|
+
}
|
|
1061
|
+
function ReadableByteStreamControllerGetDesiredSize(controller) {
|
|
1062
|
+
const state = controller._controlledReadableByteStream._state;
|
|
1063
|
+
if (state === "errored") {
|
|
1064
|
+
return null;
|
|
1065
|
+
}
|
|
1066
|
+
if (state === "closed") {
|
|
1067
|
+
return 0;
|
|
1068
|
+
}
|
|
1069
|
+
return controller._strategyHWM - controller._queueTotalSize;
|
|
1070
|
+
}
|
|
1071
|
+
function ReadableByteStreamControllerRespond(controller, bytesWritten) {
|
|
1072
|
+
const firstDescriptor = controller._pendingPullIntos.peek();
|
|
1073
|
+
const state = controller._controlledReadableByteStream._state;
|
|
1074
|
+
if (state === "closed") {
|
|
1075
|
+
if (bytesWritten !== 0) {
|
|
1076
|
+
throw new TypeError("bytesWritten must be 0 when calling respond() on a closed stream");
|
|
1077
|
+
}
|
|
1078
|
+
} else {
|
|
1079
|
+
if (bytesWritten === 0) {
|
|
1080
|
+
throw new TypeError("bytesWritten must be greater than 0 when calling respond() on a readable stream");
|
|
1081
|
+
}
|
|
1082
|
+
if (firstDescriptor.bytesFilled + bytesWritten > firstDescriptor.byteLength) {
|
|
1083
|
+
throw new RangeError("bytesWritten out of range");
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer);
|
|
1087
|
+
ReadableByteStreamControllerRespondInternal(controller, bytesWritten);
|
|
1088
|
+
}
|
|
1089
|
+
function ReadableByteStreamControllerRespondWithNewView(controller, view) {
|
|
1090
|
+
const firstDescriptor = controller._pendingPullIntos.peek();
|
|
1091
|
+
const state = controller._controlledReadableByteStream._state;
|
|
1092
|
+
if (state === "closed") {
|
|
1093
|
+
if (view.byteLength !== 0) {
|
|
1094
|
+
throw new TypeError("The view's length must be 0 when calling respondWithNewView() on a closed stream");
|
|
1095
|
+
}
|
|
1096
|
+
} else {
|
|
1097
|
+
if (view.byteLength === 0) {
|
|
1098
|
+
throw new TypeError("The view's length must be greater than 0 when calling respondWithNewView() on a readable stream");
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) {
|
|
1102
|
+
throw new RangeError("The region specified by view does not match byobRequest");
|
|
1103
|
+
}
|
|
1104
|
+
if (firstDescriptor.bufferByteLength !== view.buffer.byteLength) {
|
|
1105
|
+
throw new RangeError("The buffer of view has different capacity than byobRequest");
|
|
1106
|
+
}
|
|
1107
|
+
if (firstDescriptor.bytesFilled + view.byteLength > firstDescriptor.byteLength) {
|
|
1108
|
+
throw new RangeError("The region specified by view is larger than byobRequest");
|
|
1109
|
+
}
|
|
1110
|
+
const viewByteLength = view.byteLength;
|
|
1111
|
+
firstDescriptor.buffer = TransferArrayBuffer(view.buffer);
|
|
1112
|
+
ReadableByteStreamControllerRespondInternal(controller, viewByteLength);
|
|
1113
|
+
}
|
|
1114
|
+
function SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize) {
|
|
1115
|
+
controller._controlledReadableByteStream = stream;
|
|
1116
|
+
controller._pullAgain = false;
|
|
1117
|
+
controller._pulling = false;
|
|
1118
|
+
controller._byobRequest = null;
|
|
1119
|
+
controller._queue = controller._queueTotalSize = void 0;
|
|
1120
|
+
ResetQueue(controller);
|
|
1121
|
+
controller._closeRequested = false;
|
|
1122
|
+
controller._started = false;
|
|
1123
|
+
controller._strategyHWM = highWaterMark;
|
|
1124
|
+
controller._pullAlgorithm = pullAlgorithm;
|
|
1125
|
+
controller._cancelAlgorithm = cancelAlgorithm;
|
|
1126
|
+
controller._autoAllocateChunkSize = autoAllocateChunkSize;
|
|
1127
|
+
controller._pendingPullIntos = new SimpleQueue();
|
|
1128
|
+
stream._readableStreamController = controller;
|
|
1129
|
+
const startResult = startAlgorithm();
|
|
1130
|
+
uponPromise(promiseResolvedWith(startResult), () => {
|
|
1131
|
+
controller._started = true;
|
|
1132
|
+
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
1133
|
+
}, (r) => {
|
|
1134
|
+
ReadableByteStreamControllerError(controller, r);
|
|
1135
|
+
});
|
|
1136
|
+
}
|
|
1137
|
+
function SetUpReadableByteStreamControllerFromUnderlyingSource(stream, underlyingByteSource, highWaterMark) {
|
|
1138
|
+
const controller = Object.create(ReadableByteStreamController.prototype);
|
|
1139
|
+
let startAlgorithm = () => void 0;
|
|
1140
|
+
let pullAlgorithm = () => promiseResolvedWith(void 0);
|
|
1141
|
+
let cancelAlgorithm = () => promiseResolvedWith(void 0);
|
|
1142
|
+
if (underlyingByteSource.start !== void 0) {
|
|
1143
|
+
startAlgorithm = () => underlyingByteSource.start(controller);
|
|
1144
|
+
}
|
|
1145
|
+
if (underlyingByteSource.pull !== void 0) {
|
|
1146
|
+
pullAlgorithm = () => underlyingByteSource.pull(controller);
|
|
1147
|
+
}
|
|
1148
|
+
if (underlyingByteSource.cancel !== void 0) {
|
|
1149
|
+
cancelAlgorithm = (reason) => underlyingByteSource.cancel(reason);
|
|
1150
|
+
}
|
|
1151
|
+
const autoAllocateChunkSize = underlyingByteSource.autoAllocateChunkSize;
|
|
1152
|
+
if (autoAllocateChunkSize === 0) {
|
|
1153
|
+
throw new TypeError("autoAllocateChunkSize must be greater than 0");
|
|
1154
|
+
}
|
|
1155
|
+
SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize);
|
|
1156
|
+
}
|
|
1157
|
+
function SetUpReadableStreamBYOBRequest(request, controller, view) {
|
|
1158
|
+
request._associatedReadableByteStreamController = controller;
|
|
1159
|
+
request._view = view;
|
|
1160
|
+
}
|
|
1161
|
+
function byobRequestBrandCheckException(name) {
|
|
1162
|
+
return new TypeError(`ReadableStreamBYOBRequest.prototype.${name} can only be used on a ReadableStreamBYOBRequest`);
|
|
1163
|
+
}
|
|
1164
|
+
function byteStreamControllerBrandCheckException(name) {
|
|
1165
|
+
return new TypeError(`ReadableByteStreamController.prototype.${name} can only be used on a ReadableByteStreamController`);
|
|
1166
|
+
}
|
|
1167
|
+
function AcquireReadableStreamBYOBReader(stream) {
|
|
1168
|
+
return new ReadableStreamBYOBReader(stream);
|
|
1169
|
+
}
|
|
1170
|
+
function ReadableStreamAddReadIntoRequest(stream, readIntoRequest) {
|
|
1171
|
+
stream._reader._readIntoRequests.push(readIntoRequest);
|
|
1172
|
+
}
|
|
1173
|
+
function ReadableStreamFulfillReadIntoRequest(stream, chunk, done) {
|
|
1174
|
+
const reader = stream._reader;
|
|
1175
|
+
const readIntoRequest = reader._readIntoRequests.shift();
|
|
1176
|
+
if (done) {
|
|
1177
|
+
readIntoRequest._closeSteps(chunk);
|
|
1178
|
+
} else {
|
|
1179
|
+
readIntoRequest._chunkSteps(chunk);
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
function ReadableStreamGetNumReadIntoRequests(stream) {
|
|
1183
|
+
return stream._reader._readIntoRequests.length;
|
|
1184
|
+
}
|
|
1185
|
+
function ReadableStreamHasBYOBReader(stream) {
|
|
1186
|
+
const reader = stream._reader;
|
|
1187
|
+
if (reader === void 0) {
|
|
1188
|
+
return false;
|
|
1189
|
+
}
|
|
1190
|
+
if (!IsReadableStreamBYOBReader(reader)) {
|
|
1191
|
+
return false;
|
|
1192
|
+
}
|
|
1193
|
+
return true;
|
|
1194
|
+
}
|
|
1195
|
+
class ReadableStreamBYOBReader {
|
|
1196
|
+
constructor(stream) {
|
|
1197
|
+
assertRequiredArgument(stream, 1, "ReadableStreamBYOBReader");
|
|
1198
|
+
assertReadableStream(stream, "First parameter");
|
|
1199
|
+
if (IsReadableStreamLocked(stream)) {
|
|
1200
|
+
throw new TypeError("This stream has already been locked for exclusive reading by another reader");
|
|
1201
|
+
}
|
|
1202
|
+
if (!IsReadableByteStreamController(stream._readableStreamController)) {
|
|
1203
|
+
throw new TypeError("Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte source");
|
|
1204
|
+
}
|
|
1205
|
+
ReadableStreamReaderGenericInitialize(this, stream);
|
|
1206
|
+
this._readIntoRequests = new SimpleQueue();
|
|
1207
|
+
}
|
|
1208
|
+
get closed() {
|
|
1209
|
+
if (!IsReadableStreamBYOBReader(this)) {
|
|
1210
|
+
return promiseRejectedWith(byobReaderBrandCheckException("closed"));
|
|
1211
|
+
}
|
|
1212
|
+
return this._closedPromise;
|
|
1213
|
+
}
|
|
1214
|
+
cancel(reason = void 0) {
|
|
1215
|
+
if (!IsReadableStreamBYOBReader(this)) {
|
|
1216
|
+
return promiseRejectedWith(byobReaderBrandCheckException("cancel"));
|
|
1217
|
+
}
|
|
1218
|
+
if (this._ownerReadableStream === void 0) {
|
|
1219
|
+
return promiseRejectedWith(readerLockException("cancel"));
|
|
1220
|
+
}
|
|
1221
|
+
return ReadableStreamReaderGenericCancel(this, reason);
|
|
1222
|
+
}
|
|
1223
|
+
read(view) {
|
|
1224
|
+
if (!IsReadableStreamBYOBReader(this)) {
|
|
1225
|
+
return promiseRejectedWith(byobReaderBrandCheckException("read"));
|
|
1226
|
+
}
|
|
1227
|
+
if (!ArrayBuffer.isView(view)) {
|
|
1228
|
+
return promiseRejectedWith(new TypeError("view must be an array buffer view"));
|
|
1229
|
+
}
|
|
1230
|
+
if (view.byteLength === 0) {
|
|
1231
|
+
return promiseRejectedWith(new TypeError("view must have non-zero byteLength"));
|
|
1232
|
+
}
|
|
1233
|
+
if (view.buffer.byteLength === 0) {
|
|
1234
|
+
return promiseRejectedWith(new TypeError(`view's buffer must have non-zero byteLength`));
|
|
1235
|
+
}
|
|
1236
|
+
if (IsDetachedBuffer(view.buffer))
|
|
1237
|
+
;
|
|
1238
|
+
if (this._ownerReadableStream === void 0) {
|
|
1239
|
+
return promiseRejectedWith(readerLockException("read from"));
|
|
1240
|
+
}
|
|
1241
|
+
let resolvePromise;
|
|
1242
|
+
let rejectPromise;
|
|
1243
|
+
const promise = newPromise((resolve, reject) => {
|
|
1244
|
+
resolvePromise = resolve;
|
|
1245
|
+
rejectPromise = reject;
|
|
1246
|
+
});
|
|
1247
|
+
const readIntoRequest = {
|
|
1248
|
+
_chunkSteps: (chunk) => resolvePromise({ value: chunk, done: false }),
|
|
1249
|
+
_closeSteps: (chunk) => resolvePromise({ value: chunk, done: true }),
|
|
1250
|
+
_errorSteps: (e) => rejectPromise(e)
|
|
1251
|
+
};
|
|
1252
|
+
ReadableStreamBYOBReaderRead(this, view, readIntoRequest);
|
|
1253
|
+
return promise;
|
|
1254
|
+
}
|
|
1255
|
+
releaseLock() {
|
|
1256
|
+
if (!IsReadableStreamBYOBReader(this)) {
|
|
1257
|
+
throw byobReaderBrandCheckException("releaseLock");
|
|
1258
|
+
}
|
|
1259
|
+
if (this._ownerReadableStream === void 0) {
|
|
1260
|
+
return;
|
|
1261
|
+
}
|
|
1262
|
+
if (this._readIntoRequests.length > 0) {
|
|
1263
|
+
throw new TypeError("Tried to release a reader lock when that reader has pending read() calls un-settled");
|
|
1264
|
+
}
|
|
1265
|
+
ReadableStreamReaderGenericRelease(this);
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
Object.defineProperties(ReadableStreamBYOBReader.prototype, {
|
|
1269
|
+
cancel: { enumerable: true },
|
|
1270
|
+
read: { enumerable: true },
|
|
1271
|
+
releaseLock: { enumerable: true },
|
|
1272
|
+
closed: { enumerable: true }
|
|
1273
|
+
});
|
|
1274
|
+
if (typeof SymbolPolyfill.toStringTag === "symbol") {
|
|
1275
|
+
Object.defineProperty(ReadableStreamBYOBReader.prototype, SymbolPolyfill.toStringTag, {
|
|
1276
|
+
value: "ReadableStreamBYOBReader",
|
|
1277
|
+
configurable: true
|
|
1278
|
+
});
|
|
1279
|
+
}
|
|
1280
|
+
function IsReadableStreamBYOBReader(x) {
|
|
1281
|
+
if (!typeIsObject(x)) {
|
|
1282
|
+
return false;
|
|
1283
|
+
}
|
|
1284
|
+
if (!Object.prototype.hasOwnProperty.call(x, "_readIntoRequests")) {
|
|
1285
|
+
return false;
|
|
1286
|
+
}
|
|
1287
|
+
return x instanceof ReadableStreamBYOBReader;
|
|
1288
|
+
}
|
|
1289
|
+
function ReadableStreamBYOBReaderRead(reader, view, readIntoRequest) {
|
|
1290
|
+
const stream = reader._ownerReadableStream;
|
|
1291
|
+
stream._disturbed = true;
|
|
1292
|
+
if (stream._state === "errored") {
|
|
1293
|
+
readIntoRequest._errorSteps(stream._storedError);
|
|
1294
|
+
} else {
|
|
1295
|
+
ReadableByteStreamControllerPullInto(stream._readableStreamController, view, readIntoRequest);
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
function byobReaderBrandCheckException(name) {
|
|
1299
|
+
return new TypeError(`ReadableStreamBYOBReader.prototype.${name} can only be used on a ReadableStreamBYOBReader`);
|
|
1300
|
+
}
|
|
1301
|
+
function ExtractHighWaterMark(strategy, defaultHWM) {
|
|
1302
|
+
const { highWaterMark } = strategy;
|
|
1303
|
+
if (highWaterMark === void 0) {
|
|
1304
|
+
return defaultHWM;
|
|
1305
|
+
}
|
|
1306
|
+
if (NumberIsNaN(highWaterMark) || highWaterMark < 0) {
|
|
1307
|
+
throw new RangeError("Invalid highWaterMark");
|
|
1308
|
+
}
|
|
1309
|
+
return highWaterMark;
|
|
1310
|
+
}
|
|
1311
|
+
function ExtractSizeAlgorithm(strategy) {
|
|
1312
|
+
const { size } = strategy;
|
|
1313
|
+
if (!size) {
|
|
1314
|
+
return () => 1;
|
|
1315
|
+
}
|
|
1316
|
+
return size;
|
|
1317
|
+
}
|
|
1318
|
+
function convertQueuingStrategy(init, context) {
|
|
1319
|
+
assertDictionary(init, context);
|
|
1320
|
+
const highWaterMark = init === null || init === void 0 ? void 0 : init.highWaterMark;
|
|
1321
|
+
const size = init === null || init === void 0 ? void 0 : init.size;
|
|
1322
|
+
return {
|
|
1323
|
+
highWaterMark: highWaterMark === void 0 ? void 0 : convertUnrestrictedDouble(highWaterMark),
|
|
1324
|
+
size: size === void 0 ? void 0 : convertQueuingStrategySize(size, `${context} has member 'size' that`)
|
|
1325
|
+
};
|
|
1326
|
+
}
|
|
1327
|
+
function convertQueuingStrategySize(fn, context) {
|
|
1328
|
+
assertFunction(fn, context);
|
|
1329
|
+
return (chunk) => convertUnrestrictedDouble(fn(chunk));
|
|
1330
|
+
}
|
|
1331
|
+
function convertUnderlyingSink(original, context) {
|
|
1332
|
+
assertDictionary(original, context);
|
|
1333
|
+
const abort = original === null || original === void 0 ? void 0 : original.abort;
|
|
1334
|
+
const close = original === null || original === void 0 ? void 0 : original.close;
|
|
1335
|
+
const start = original === null || original === void 0 ? void 0 : original.start;
|
|
1336
|
+
const type = original === null || original === void 0 ? void 0 : original.type;
|
|
1337
|
+
const write = original === null || original === void 0 ? void 0 : original.write;
|
|
1338
|
+
return {
|
|
1339
|
+
abort: abort === void 0 ? void 0 : convertUnderlyingSinkAbortCallback(abort, original, `${context} has member 'abort' that`),
|
|
1340
|
+
close: close === void 0 ? void 0 : convertUnderlyingSinkCloseCallback(close, original, `${context} has member 'close' that`),
|
|
1341
|
+
start: start === void 0 ? void 0 : convertUnderlyingSinkStartCallback(start, original, `${context} has member 'start' that`),
|
|
1342
|
+
write: write === void 0 ? void 0 : convertUnderlyingSinkWriteCallback(write, original, `${context} has member 'write' that`),
|
|
1343
|
+
type
|
|
1344
|
+
};
|
|
1345
|
+
}
|
|
1346
|
+
function convertUnderlyingSinkAbortCallback(fn, original, context) {
|
|
1347
|
+
assertFunction(fn, context);
|
|
1348
|
+
return (reason) => promiseCall(fn, original, [reason]);
|
|
1349
|
+
}
|
|
1350
|
+
function convertUnderlyingSinkCloseCallback(fn, original, context) {
|
|
1351
|
+
assertFunction(fn, context);
|
|
1352
|
+
return () => promiseCall(fn, original, []);
|
|
1353
|
+
}
|
|
1354
|
+
function convertUnderlyingSinkStartCallback(fn, original, context) {
|
|
1355
|
+
assertFunction(fn, context);
|
|
1356
|
+
return (controller) => reflectCall(fn, original, [controller]);
|
|
1357
|
+
}
|
|
1358
|
+
function convertUnderlyingSinkWriteCallback(fn, original, context) {
|
|
1359
|
+
assertFunction(fn, context);
|
|
1360
|
+
return (chunk, controller) => promiseCall(fn, original, [chunk, controller]);
|
|
1361
|
+
}
|
|
1362
|
+
function assertWritableStream(x, context) {
|
|
1363
|
+
if (!IsWritableStream(x)) {
|
|
1364
|
+
throw new TypeError(`${context} is not a WritableStream.`);
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
function isAbortSignal(value) {
|
|
1368
|
+
if (typeof value !== "object" || value === null) {
|
|
1369
|
+
return false;
|
|
1370
|
+
}
|
|
1371
|
+
try {
|
|
1372
|
+
return typeof value.aborted === "boolean";
|
|
1373
|
+
} catch (_a) {
|
|
1374
|
+
return false;
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
const supportsAbortController = typeof AbortController === "function";
|
|
1378
|
+
function createAbortController() {
|
|
1379
|
+
if (supportsAbortController) {
|
|
1380
|
+
return new AbortController();
|
|
1381
|
+
}
|
|
1382
|
+
return void 0;
|
|
1383
|
+
}
|
|
1384
|
+
class WritableStream {
|
|
1385
|
+
constructor(rawUnderlyingSink = {}, rawStrategy = {}) {
|
|
1386
|
+
if (rawUnderlyingSink === void 0) {
|
|
1387
|
+
rawUnderlyingSink = null;
|
|
1388
|
+
} else {
|
|
1389
|
+
assertObject(rawUnderlyingSink, "First parameter");
|
|
1390
|
+
}
|
|
1391
|
+
const strategy = convertQueuingStrategy(rawStrategy, "Second parameter");
|
|
1392
|
+
const underlyingSink = convertUnderlyingSink(rawUnderlyingSink, "First parameter");
|
|
1393
|
+
InitializeWritableStream(this);
|
|
1394
|
+
const type = underlyingSink.type;
|
|
1395
|
+
if (type !== void 0) {
|
|
1396
|
+
throw new RangeError("Invalid type is specified");
|
|
1397
|
+
}
|
|
1398
|
+
const sizeAlgorithm = ExtractSizeAlgorithm(strategy);
|
|
1399
|
+
const highWaterMark = ExtractHighWaterMark(strategy, 1);
|
|
1400
|
+
SetUpWritableStreamDefaultControllerFromUnderlyingSink(this, underlyingSink, highWaterMark, sizeAlgorithm);
|
|
1401
|
+
}
|
|
1402
|
+
get locked() {
|
|
1403
|
+
if (!IsWritableStream(this)) {
|
|
1404
|
+
throw streamBrandCheckException$2("locked");
|
|
1405
|
+
}
|
|
1406
|
+
return IsWritableStreamLocked(this);
|
|
1407
|
+
}
|
|
1408
|
+
abort(reason = void 0) {
|
|
1409
|
+
if (!IsWritableStream(this)) {
|
|
1410
|
+
return promiseRejectedWith(streamBrandCheckException$2("abort"));
|
|
1411
|
+
}
|
|
1412
|
+
if (IsWritableStreamLocked(this)) {
|
|
1413
|
+
return promiseRejectedWith(new TypeError("Cannot abort a stream that already has a writer"));
|
|
1414
|
+
}
|
|
1415
|
+
return WritableStreamAbort(this, reason);
|
|
1416
|
+
}
|
|
1417
|
+
close() {
|
|
1418
|
+
if (!IsWritableStream(this)) {
|
|
1419
|
+
return promiseRejectedWith(streamBrandCheckException$2("close"));
|
|
1420
|
+
}
|
|
1421
|
+
if (IsWritableStreamLocked(this)) {
|
|
1422
|
+
return promiseRejectedWith(new TypeError("Cannot close a stream that already has a writer"));
|
|
1423
|
+
}
|
|
1424
|
+
if (WritableStreamCloseQueuedOrInFlight(this)) {
|
|
1425
|
+
return promiseRejectedWith(new TypeError("Cannot close an already-closing stream"));
|
|
1426
|
+
}
|
|
1427
|
+
return WritableStreamClose(this);
|
|
1428
|
+
}
|
|
1429
|
+
getWriter() {
|
|
1430
|
+
if (!IsWritableStream(this)) {
|
|
1431
|
+
throw streamBrandCheckException$2("getWriter");
|
|
1432
|
+
}
|
|
1433
|
+
return AcquireWritableStreamDefaultWriter(this);
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
Object.defineProperties(WritableStream.prototype, {
|
|
1437
|
+
abort: { enumerable: true },
|
|
1438
|
+
close: { enumerable: true },
|
|
1439
|
+
getWriter: { enumerable: true },
|
|
1440
|
+
locked: { enumerable: true }
|
|
1441
|
+
});
|
|
1442
|
+
if (typeof SymbolPolyfill.toStringTag === "symbol") {
|
|
1443
|
+
Object.defineProperty(WritableStream.prototype, SymbolPolyfill.toStringTag, {
|
|
1444
|
+
value: "WritableStream",
|
|
1445
|
+
configurable: true
|
|
1446
|
+
});
|
|
1447
|
+
}
|
|
1448
|
+
function AcquireWritableStreamDefaultWriter(stream) {
|
|
1449
|
+
return new WritableStreamDefaultWriter(stream);
|
|
1450
|
+
}
|
|
1451
|
+
function CreateWritableStream(startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark = 1, sizeAlgorithm = () => 1) {
|
|
1452
|
+
const stream = Object.create(WritableStream.prototype);
|
|
1453
|
+
InitializeWritableStream(stream);
|
|
1454
|
+
const controller = Object.create(WritableStreamDefaultController.prototype);
|
|
1455
|
+
SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm);
|
|
1456
|
+
return stream;
|
|
1457
|
+
}
|
|
1458
|
+
function InitializeWritableStream(stream) {
|
|
1459
|
+
stream._state = "writable";
|
|
1460
|
+
stream._storedError = void 0;
|
|
1461
|
+
stream._writer = void 0;
|
|
1462
|
+
stream._writableStreamController = void 0;
|
|
1463
|
+
stream._writeRequests = new SimpleQueue();
|
|
1464
|
+
stream._inFlightWriteRequest = void 0;
|
|
1465
|
+
stream._closeRequest = void 0;
|
|
1466
|
+
stream._inFlightCloseRequest = void 0;
|
|
1467
|
+
stream._pendingAbortRequest = void 0;
|
|
1468
|
+
stream._backpressure = false;
|
|
1469
|
+
}
|
|
1470
|
+
function IsWritableStream(x) {
|
|
1471
|
+
if (!typeIsObject(x)) {
|
|
1472
|
+
return false;
|
|
1473
|
+
}
|
|
1474
|
+
if (!Object.prototype.hasOwnProperty.call(x, "_writableStreamController")) {
|
|
1475
|
+
return false;
|
|
1476
|
+
}
|
|
1477
|
+
return x instanceof WritableStream;
|
|
1478
|
+
}
|
|
1479
|
+
function IsWritableStreamLocked(stream) {
|
|
1480
|
+
if (stream._writer === void 0) {
|
|
1481
|
+
return false;
|
|
1482
|
+
}
|
|
1483
|
+
return true;
|
|
1484
|
+
}
|
|
1485
|
+
function WritableStreamAbort(stream, reason) {
|
|
1486
|
+
var _a;
|
|
1487
|
+
if (stream._state === "closed" || stream._state === "errored") {
|
|
1488
|
+
return promiseResolvedWith(void 0);
|
|
1489
|
+
}
|
|
1490
|
+
stream._writableStreamController._abortReason = reason;
|
|
1491
|
+
(_a = stream._writableStreamController._abortController) === null || _a === void 0 ? void 0 : _a.abort();
|
|
1492
|
+
const state = stream._state;
|
|
1493
|
+
if (state === "closed" || state === "errored") {
|
|
1494
|
+
return promiseResolvedWith(void 0);
|
|
1495
|
+
}
|
|
1496
|
+
if (stream._pendingAbortRequest !== void 0) {
|
|
1497
|
+
return stream._pendingAbortRequest._promise;
|
|
1498
|
+
}
|
|
1499
|
+
let wasAlreadyErroring = false;
|
|
1500
|
+
if (state === "erroring") {
|
|
1501
|
+
wasAlreadyErroring = true;
|
|
1502
|
+
reason = void 0;
|
|
1503
|
+
}
|
|
1504
|
+
const promise = newPromise((resolve, reject) => {
|
|
1505
|
+
stream._pendingAbortRequest = {
|
|
1506
|
+
_promise: void 0,
|
|
1507
|
+
_resolve: resolve,
|
|
1508
|
+
_reject: reject,
|
|
1509
|
+
_reason: reason,
|
|
1510
|
+
_wasAlreadyErroring: wasAlreadyErroring
|
|
1511
|
+
};
|
|
1512
|
+
});
|
|
1513
|
+
stream._pendingAbortRequest._promise = promise;
|
|
1514
|
+
if (!wasAlreadyErroring) {
|
|
1515
|
+
WritableStreamStartErroring(stream, reason);
|
|
1516
|
+
}
|
|
1517
|
+
return promise;
|
|
1518
|
+
}
|
|
1519
|
+
function WritableStreamClose(stream) {
|
|
1520
|
+
const state = stream._state;
|
|
1521
|
+
if (state === "closed" || state === "errored") {
|
|
1522
|
+
return promiseRejectedWith(new TypeError(`The stream (in ${state} state) is not in the writable state and cannot be closed`));
|
|
1523
|
+
}
|
|
1524
|
+
const promise = newPromise((resolve, reject) => {
|
|
1525
|
+
const closeRequest = {
|
|
1526
|
+
_resolve: resolve,
|
|
1527
|
+
_reject: reject
|
|
1528
|
+
};
|
|
1529
|
+
stream._closeRequest = closeRequest;
|
|
1530
|
+
});
|
|
1531
|
+
const writer = stream._writer;
|
|
1532
|
+
if (writer !== void 0 && stream._backpressure && state === "writable") {
|
|
1533
|
+
defaultWriterReadyPromiseResolve(writer);
|
|
1534
|
+
}
|
|
1535
|
+
WritableStreamDefaultControllerClose(stream._writableStreamController);
|
|
1536
|
+
return promise;
|
|
1537
|
+
}
|
|
1538
|
+
function WritableStreamAddWriteRequest(stream) {
|
|
1539
|
+
const promise = newPromise((resolve, reject) => {
|
|
1540
|
+
const writeRequest = {
|
|
1541
|
+
_resolve: resolve,
|
|
1542
|
+
_reject: reject
|
|
1543
|
+
};
|
|
1544
|
+
stream._writeRequests.push(writeRequest);
|
|
1545
|
+
});
|
|
1546
|
+
return promise;
|
|
1547
|
+
}
|
|
1548
|
+
function WritableStreamDealWithRejection(stream, error) {
|
|
1549
|
+
const state = stream._state;
|
|
1550
|
+
if (state === "writable") {
|
|
1551
|
+
WritableStreamStartErroring(stream, error);
|
|
1552
|
+
return;
|
|
1553
|
+
}
|
|
1554
|
+
WritableStreamFinishErroring(stream);
|
|
1555
|
+
}
|
|
1556
|
+
function WritableStreamStartErroring(stream, reason) {
|
|
1557
|
+
const controller = stream._writableStreamController;
|
|
1558
|
+
stream._state = "erroring";
|
|
1559
|
+
stream._storedError = reason;
|
|
1560
|
+
const writer = stream._writer;
|
|
1561
|
+
if (writer !== void 0) {
|
|
1562
|
+
WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, reason);
|
|
1563
|
+
}
|
|
1564
|
+
if (!WritableStreamHasOperationMarkedInFlight(stream) && controller._started) {
|
|
1565
|
+
WritableStreamFinishErroring(stream);
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
function WritableStreamFinishErroring(stream) {
|
|
1569
|
+
stream._state = "errored";
|
|
1570
|
+
stream._writableStreamController[ErrorSteps]();
|
|
1571
|
+
const storedError = stream._storedError;
|
|
1572
|
+
stream._writeRequests.forEach((writeRequest) => {
|
|
1573
|
+
writeRequest._reject(storedError);
|
|
1574
|
+
});
|
|
1575
|
+
stream._writeRequests = new SimpleQueue();
|
|
1576
|
+
if (stream._pendingAbortRequest === void 0) {
|
|
1577
|
+
WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
|
|
1578
|
+
return;
|
|
1579
|
+
}
|
|
1580
|
+
const abortRequest = stream._pendingAbortRequest;
|
|
1581
|
+
stream._pendingAbortRequest = void 0;
|
|
1582
|
+
if (abortRequest._wasAlreadyErroring) {
|
|
1583
|
+
abortRequest._reject(storedError);
|
|
1584
|
+
WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
|
|
1585
|
+
return;
|
|
1586
|
+
}
|
|
1587
|
+
const promise = stream._writableStreamController[AbortSteps](abortRequest._reason);
|
|
1588
|
+
uponPromise(promise, () => {
|
|
1589
|
+
abortRequest._resolve();
|
|
1590
|
+
WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
|
|
1591
|
+
}, (reason) => {
|
|
1592
|
+
abortRequest._reject(reason);
|
|
1593
|
+
WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
|
|
1594
|
+
});
|
|
1595
|
+
}
|
|
1596
|
+
function WritableStreamFinishInFlightWrite(stream) {
|
|
1597
|
+
stream._inFlightWriteRequest._resolve(void 0);
|
|
1598
|
+
stream._inFlightWriteRequest = void 0;
|
|
1599
|
+
}
|
|
1600
|
+
function WritableStreamFinishInFlightWriteWithError(stream, error) {
|
|
1601
|
+
stream._inFlightWriteRequest._reject(error);
|
|
1602
|
+
stream._inFlightWriteRequest = void 0;
|
|
1603
|
+
WritableStreamDealWithRejection(stream, error);
|
|
1604
|
+
}
|
|
1605
|
+
function WritableStreamFinishInFlightClose(stream) {
|
|
1606
|
+
stream._inFlightCloseRequest._resolve(void 0);
|
|
1607
|
+
stream._inFlightCloseRequest = void 0;
|
|
1608
|
+
const state = stream._state;
|
|
1609
|
+
if (state === "erroring") {
|
|
1610
|
+
stream._storedError = void 0;
|
|
1611
|
+
if (stream._pendingAbortRequest !== void 0) {
|
|
1612
|
+
stream._pendingAbortRequest._resolve();
|
|
1613
|
+
stream._pendingAbortRequest = void 0;
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
stream._state = "closed";
|
|
1617
|
+
const writer = stream._writer;
|
|
1618
|
+
if (writer !== void 0) {
|
|
1619
|
+
defaultWriterClosedPromiseResolve(writer);
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
function WritableStreamFinishInFlightCloseWithError(stream, error) {
|
|
1623
|
+
stream._inFlightCloseRequest._reject(error);
|
|
1624
|
+
stream._inFlightCloseRequest = void 0;
|
|
1625
|
+
if (stream._pendingAbortRequest !== void 0) {
|
|
1626
|
+
stream._pendingAbortRequest._reject(error);
|
|
1627
|
+
stream._pendingAbortRequest = void 0;
|
|
1628
|
+
}
|
|
1629
|
+
WritableStreamDealWithRejection(stream, error);
|
|
1630
|
+
}
|
|
1631
|
+
function WritableStreamCloseQueuedOrInFlight(stream) {
|
|
1632
|
+
if (stream._closeRequest === void 0 && stream._inFlightCloseRequest === void 0) {
|
|
1633
|
+
return false;
|
|
1634
|
+
}
|
|
1635
|
+
return true;
|
|
1636
|
+
}
|
|
1637
|
+
function WritableStreamHasOperationMarkedInFlight(stream) {
|
|
1638
|
+
if (stream._inFlightWriteRequest === void 0 && stream._inFlightCloseRequest === void 0) {
|
|
1639
|
+
return false;
|
|
1640
|
+
}
|
|
1641
|
+
return true;
|
|
1642
|
+
}
|
|
1643
|
+
function WritableStreamMarkCloseRequestInFlight(stream) {
|
|
1644
|
+
stream._inFlightCloseRequest = stream._closeRequest;
|
|
1645
|
+
stream._closeRequest = void 0;
|
|
1646
|
+
}
|
|
1647
|
+
function WritableStreamMarkFirstWriteRequestInFlight(stream) {
|
|
1648
|
+
stream._inFlightWriteRequest = stream._writeRequests.shift();
|
|
1649
|
+
}
|
|
1650
|
+
function WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream) {
|
|
1651
|
+
if (stream._closeRequest !== void 0) {
|
|
1652
|
+
stream._closeRequest._reject(stream._storedError);
|
|
1653
|
+
stream._closeRequest = void 0;
|
|
1654
|
+
}
|
|
1655
|
+
const writer = stream._writer;
|
|
1656
|
+
if (writer !== void 0) {
|
|
1657
|
+
defaultWriterClosedPromiseReject(writer, stream._storedError);
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
function WritableStreamUpdateBackpressure(stream, backpressure) {
|
|
1661
|
+
const writer = stream._writer;
|
|
1662
|
+
if (writer !== void 0 && backpressure !== stream._backpressure) {
|
|
1663
|
+
if (backpressure) {
|
|
1664
|
+
defaultWriterReadyPromiseReset(writer);
|
|
1665
|
+
} else {
|
|
1666
|
+
defaultWriterReadyPromiseResolve(writer);
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
stream._backpressure = backpressure;
|
|
1670
|
+
}
|
|
1671
|
+
class WritableStreamDefaultWriter {
|
|
1672
|
+
constructor(stream) {
|
|
1673
|
+
assertRequiredArgument(stream, 1, "WritableStreamDefaultWriter");
|
|
1674
|
+
assertWritableStream(stream, "First parameter");
|
|
1675
|
+
if (IsWritableStreamLocked(stream)) {
|
|
1676
|
+
throw new TypeError("This stream has already been locked for exclusive writing by another writer");
|
|
1677
|
+
}
|
|
1678
|
+
this._ownerWritableStream = stream;
|
|
1679
|
+
stream._writer = this;
|
|
1680
|
+
const state = stream._state;
|
|
1681
|
+
if (state === "writable") {
|
|
1682
|
+
if (!WritableStreamCloseQueuedOrInFlight(stream) && stream._backpressure) {
|
|
1683
|
+
defaultWriterReadyPromiseInitialize(this);
|
|
1684
|
+
} else {
|
|
1685
|
+
defaultWriterReadyPromiseInitializeAsResolved(this);
|
|
1686
|
+
}
|
|
1687
|
+
defaultWriterClosedPromiseInitialize(this);
|
|
1688
|
+
} else if (state === "erroring") {
|
|
1689
|
+
defaultWriterReadyPromiseInitializeAsRejected(this, stream._storedError);
|
|
1690
|
+
defaultWriterClosedPromiseInitialize(this);
|
|
1691
|
+
} else if (state === "closed") {
|
|
1692
|
+
defaultWriterReadyPromiseInitializeAsResolved(this);
|
|
1693
|
+
defaultWriterClosedPromiseInitializeAsResolved(this);
|
|
1694
|
+
} else {
|
|
1695
|
+
const storedError = stream._storedError;
|
|
1696
|
+
defaultWriterReadyPromiseInitializeAsRejected(this, storedError);
|
|
1697
|
+
defaultWriterClosedPromiseInitializeAsRejected(this, storedError);
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
get closed() {
|
|
1701
|
+
if (!IsWritableStreamDefaultWriter(this)) {
|
|
1702
|
+
return promiseRejectedWith(defaultWriterBrandCheckException("closed"));
|
|
1703
|
+
}
|
|
1704
|
+
return this._closedPromise;
|
|
1705
|
+
}
|
|
1706
|
+
get desiredSize() {
|
|
1707
|
+
if (!IsWritableStreamDefaultWriter(this)) {
|
|
1708
|
+
throw defaultWriterBrandCheckException("desiredSize");
|
|
1709
|
+
}
|
|
1710
|
+
if (this._ownerWritableStream === void 0) {
|
|
1711
|
+
throw defaultWriterLockException("desiredSize");
|
|
1712
|
+
}
|
|
1713
|
+
return WritableStreamDefaultWriterGetDesiredSize(this);
|
|
1714
|
+
}
|
|
1715
|
+
get ready() {
|
|
1716
|
+
if (!IsWritableStreamDefaultWriter(this)) {
|
|
1717
|
+
return promiseRejectedWith(defaultWriterBrandCheckException("ready"));
|
|
1718
|
+
}
|
|
1719
|
+
return this._readyPromise;
|
|
1720
|
+
}
|
|
1721
|
+
abort(reason = void 0) {
|
|
1722
|
+
if (!IsWritableStreamDefaultWriter(this)) {
|
|
1723
|
+
return promiseRejectedWith(defaultWriterBrandCheckException("abort"));
|
|
1724
|
+
}
|
|
1725
|
+
if (this._ownerWritableStream === void 0) {
|
|
1726
|
+
return promiseRejectedWith(defaultWriterLockException("abort"));
|
|
1727
|
+
}
|
|
1728
|
+
return WritableStreamDefaultWriterAbort(this, reason);
|
|
1729
|
+
}
|
|
1730
|
+
close() {
|
|
1731
|
+
if (!IsWritableStreamDefaultWriter(this)) {
|
|
1732
|
+
return promiseRejectedWith(defaultWriterBrandCheckException("close"));
|
|
1733
|
+
}
|
|
1734
|
+
const stream = this._ownerWritableStream;
|
|
1735
|
+
if (stream === void 0) {
|
|
1736
|
+
return promiseRejectedWith(defaultWriterLockException("close"));
|
|
1737
|
+
}
|
|
1738
|
+
if (WritableStreamCloseQueuedOrInFlight(stream)) {
|
|
1739
|
+
return promiseRejectedWith(new TypeError("Cannot close an already-closing stream"));
|
|
1740
|
+
}
|
|
1741
|
+
return WritableStreamDefaultWriterClose(this);
|
|
1742
|
+
}
|
|
1743
|
+
releaseLock() {
|
|
1744
|
+
if (!IsWritableStreamDefaultWriter(this)) {
|
|
1745
|
+
throw defaultWriterBrandCheckException("releaseLock");
|
|
1746
|
+
}
|
|
1747
|
+
const stream = this._ownerWritableStream;
|
|
1748
|
+
if (stream === void 0) {
|
|
1749
|
+
return;
|
|
1750
|
+
}
|
|
1751
|
+
WritableStreamDefaultWriterRelease(this);
|
|
1752
|
+
}
|
|
1753
|
+
write(chunk = void 0) {
|
|
1754
|
+
if (!IsWritableStreamDefaultWriter(this)) {
|
|
1755
|
+
return promiseRejectedWith(defaultWriterBrandCheckException("write"));
|
|
1756
|
+
}
|
|
1757
|
+
if (this._ownerWritableStream === void 0) {
|
|
1758
|
+
return promiseRejectedWith(defaultWriterLockException("write to"));
|
|
1759
|
+
}
|
|
1760
|
+
return WritableStreamDefaultWriterWrite(this, chunk);
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
Object.defineProperties(WritableStreamDefaultWriter.prototype, {
|
|
1764
|
+
abort: { enumerable: true },
|
|
1765
|
+
close: { enumerable: true },
|
|
1766
|
+
releaseLock: { enumerable: true },
|
|
1767
|
+
write: { enumerable: true },
|
|
1768
|
+
closed: { enumerable: true },
|
|
1769
|
+
desiredSize: { enumerable: true },
|
|
1770
|
+
ready: { enumerable: true }
|
|
1771
|
+
});
|
|
1772
|
+
if (typeof SymbolPolyfill.toStringTag === "symbol") {
|
|
1773
|
+
Object.defineProperty(WritableStreamDefaultWriter.prototype, SymbolPolyfill.toStringTag, {
|
|
1774
|
+
value: "WritableStreamDefaultWriter",
|
|
1775
|
+
configurable: true
|
|
1776
|
+
});
|
|
1777
|
+
}
|
|
1778
|
+
function IsWritableStreamDefaultWriter(x) {
|
|
1779
|
+
if (!typeIsObject(x)) {
|
|
1780
|
+
return false;
|
|
1781
|
+
}
|
|
1782
|
+
if (!Object.prototype.hasOwnProperty.call(x, "_ownerWritableStream")) {
|
|
1783
|
+
return false;
|
|
1784
|
+
}
|
|
1785
|
+
return x instanceof WritableStreamDefaultWriter;
|
|
1786
|
+
}
|
|
1787
|
+
function WritableStreamDefaultWriterAbort(writer, reason) {
|
|
1788
|
+
const stream = writer._ownerWritableStream;
|
|
1789
|
+
return WritableStreamAbort(stream, reason);
|
|
1790
|
+
}
|
|
1791
|
+
function WritableStreamDefaultWriterClose(writer) {
|
|
1792
|
+
const stream = writer._ownerWritableStream;
|
|
1793
|
+
return WritableStreamClose(stream);
|
|
1794
|
+
}
|
|
1795
|
+
function WritableStreamDefaultWriterCloseWithErrorPropagation(writer) {
|
|
1796
|
+
const stream = writer._ownerWritableStream;
|
|
1797
|
+
const state = stream._state;
|
|
1798
|
+
if (WritableStreamCloseQueuedOrInFlight(stream) || state === "closed") {
|
|
1799
|
+
return promiseResolvedWith(void 0);
|
|
1800
|
+
}
|
|
1801
|
+
if (state === "errored") {
|
|
1802
|
+
return promiseRejectedWith(stream._storedError);
|
|
1803
|
+
}
|
|
1804
|
+
return WritableStreamDefaultWriterClose(writer);
|
|
1805
|
+
}
|
|
1806
|
+
function WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, error) {
|
|
1807
|
+
if (writer._closedPromiseState === "pending") {
|
|
1808
|
+
defaultWriterClosedPromiseReject(writer, error);
|
|
1809
|
+
} else {
|
|
1810
|
+
defaultWriterClosedPromiseResetToRejected(writer, error);
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
function WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, error) {
|
|
1814
|
+
if (writer._readyPromiseState === "pending") {
|
|
1815
|
+
defaultWriterReadyPromiseReject(writer, error);
|
|
1816
|
+
} else {
|
|
1817
|
+
defaultWriterReadyPromiseResetToRejected(writer, error);
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
function WritableStreamDefaultWriterGetDesiredSize(writer) {
|
|
1821
|
+
const stream = writer._ownerWritableStream;
|
|
1822
|
+
const state = stream._state;
|
|
1823
|
+
if (state === "errored" || state === "erroring") {
|
|
1824
|
+
return null;
|
|
1825
|
+
}
|
|
1826
|
+
if (state === "closed") {
|
|
1827
|
+
return 0;
|
|
1828
|
+
}
|
|
1829
|
+
return WritableStreamDefaultControllerGetDesiredSize(stream._writableStreamController);
|
|
1830
|
+
}
|
|
1831
|
+
function WritableStreamDefaultWriterRelease(writer) {
|
|
1832
|
+
const stream = writer._ownerWritableStream;
|
|
1833
|
+
const releasedError = new TypeError(`Writer was released and can no longer be used to monitor the stream's closedness`);
|
|
1834
|
+
WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, releasedError);
|
|
1835
|
+
WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, releasedError);
|
|
1836
|
+
stream._writer = void 0;
|
|
1837
|
+
writer._ownerWritableStream = void 0;
|
|
1838
|
+
}
|
|
1839
|
+
function WritableStreamDefaultWriterWrite(writer, chunk) {
|
|
1840
|
+
const stream = writer._ownerWritableStream;
|
|
1841
|
+
const controller = stream._writableStreamController;
|
|
1842
|
+
const chunkSize = WritableStreamDefaultControllerGetChunkSize(controller, chunk);
|
|
1843
|
+
if (stream !== writer._ownerWritableStream) {
|
|
1844
|
+
return promiseRejectedWith(defaultWriterLockException("write to"));
|
|
1845
|
+
}
|
|
1846
|
+
const state = stream._state;
|
|
1847
|
+
if (state === "errored") {
|
|
1848
|
+
return promiseRejectedWith(stream._storedError);
|
|
1849
|
+
}
|
|
1850
|
+
if (WritableStreamCloseQueuedOrInFlight(stream) || state === "closed") {
|
|
1851
|
+
return promiseRejectedWith(new TypeError("The stream is closing or closed and cannot be written to"));
|
|
1852
|
+
}
|
|
1853
|
+
if (state === "erroring") {
|
|
1854
|
+
return promiseRejectedWith(stream._storedError);
|
|
1855
|
+
}
|
|
1856
|
+
const promise = WritableStreamAddWriteRequest(stream);
|
|
1857
|
+
WritableStreamDefaultControllerWrite(controller, chunk, chunkSize);
|
|
1858
|
+
return promise;
|
|
1859
|
+
}
|
|
1860
|
+
const closeSentinel = {};
|
|
1861
|
+
class WritableStreamDefaultController {
|
|
1862
|
+
constructor() {
|
|
1863
|
+
throw new TypeError("Illegal constructor");
|
|
1864
|
+
}
|
|
1865
|
+
get abortReason() {
|
|
1866
|
+
if (!IsWritableStreamDefaultController(this)) {
|
|
1867
|
+
throw defaultControllerBrandCheckException$2("abortReason");
|
|
1868
|
+
}
|
|
1869
|
+
return this._abortReason;
|
|
1870
|
+
}
|
|
1871
|
+
get signal() {
|
|
1872
|
+
if (!IsWritableStreamDefaultController(this)) {
|
|
1873
|
+
throw defaultControllerBrandCheckException$2("signal");
|
|
1874
|
+
}
|
|
1875
|
+
if (this._abortController === void 0) {
|
|
1876
|
+
throw new TypeError("WritableStreamDefaultController.prototype.signal is not supported");
|
|
1877
|
+
}
|
|
1878
|
+
return this._abortController.signal;
|
|
1879
|
+
}
|
|
1880
|
+
error(e = void 0) {
|
|
1881
|
+
if (!IsWritableStreamDefaultController(this)) {
|
|
1882
|
+
throw defaultControllerBrandCheckException$2("error");
|
|
1883
|
+
}
|
|
1884
|
+
const state = this._controlledWritableStream._state;
|
|
1885
|
+
if (state !== "writable") {
|
|
1886
|
+
return;
|
|
1887
|
+
}
|
|
1888
|
+
WritableStreamDefaultControllerError(this, e);
|
|
1889
|
+
}
|
|
1890
|
+
[AbortSteps](reason) {
|
|
1891
|
+
const result = this._abortAlgorithm(reason);
|
|
1892
|
+
WritableStreamDefaultControllerClearAlgorithms(this);
|
|
1893
|
+
return result;
|
|
1894
|
+
}
|
|
1895
|
+
[ErrorSteps]() {
|
|
1896
|
+
ResetQueue(this);
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
Object.defineProperties(WritableStreamDefaultController.prototype, {
|
|
1900
|
+
abortReason: { enumerable: true },
|
|
1901
|
+
signal: { enumerable: true },
|
|
1902
|
+
error: { enumerable: true }
|
|
1903
|
+
});
|
|
1904
|
+
if (typeof SymbolPolyfill.toStringTag === "symbol") {
|
|
1905
|
+
Object.defineProperty(WritableStreamDefaultController.prototype, SymbolPolyfill.toStringTag, {
|
|
1906
|
+
value: "WritableStreamDefaultController",
|
|
1907
|
+
configurable: true
|
|
1908
|
+
});
|
|
1909
|
+
}
|
|
1910
|
+
function IsWritableStreamDefaultController(x) {
|
|
1911
|
+
if (!typeIsObject(x)) {
|
|
1912
|
+
return false;
|
|
1913
|
+
}
|
|
1914
|
+
if (!Object.prototype.hasOwnProperty.call(x, "_controlledWritableStream")) {
|
|
1915
|
+
return false;
|
|
1916
|
+
}
|
|
1917
|
+
return x instanceof WritableStreamDefaultController;
|
|
1918
|
+
}
|
|
1919
|
+
function SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm) {
|
|
1920
|
+
controller._controlledWritableStream = stream;
|
|
1921
|
+
stream._writableStreamController = controller;
|
|
1922
|
+
controller._queue = void 0;
|
|
1923
|
+
controller._queueTotalSize = void 0;
|
|
1924
|
+
ResetQueue(controller);
|
|
1925
|
+
controller._abortReason = void 0;
|
|
1926
|
+
controller._abortController = createAbortController();
|
|
1927
|
+
controller._started = false;
|
|
1928
|
+
controller._strategySizeAlgorithm = sizeAlgorithm;
|
|
1929
|
+
controller._strategyHWM = highWaterMark;
|
|
1930
|
+
controller._writeAlgorithm = writeAlgorithm;
|
|
1931
|
+
controller._closeAlgorithm = closeAlgorithm;
|
|
1932
|
+
controller._abortAlgorithm = abortAlgorithm;
|
|
1933
|
+
const backpressure = WritableStreamDefaultControllerGetBackpressure(controller);
|
|
1934
|
+
WritableStreamUpdateBackpressure(stream, backpressure);
|
|
1935
|
+
const startResult = startAlgorithm();
|
|
1936
|
+
const startPromise = promiseResolvedWith(startResult);
|
|
1937
|
+
uponPromise(startPromise, () => {
|
|
1938
|
+
controller._started = true;
|
|
1939
|
+
WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
|
|
1940
|
+
}, (r) => {
|
|
1941
|
+
controller._started = true;
|
|
1942
|
+
WritableStreamDealWithRejection(stream, r);
|
|
1943
|
+
});
|
|
1944
|
+
}
|
|
1945
|
+
function SetUpWritableStreamDefaultControllerFromUnderlyingSink(stream, underlyingSink, highWaterMark, sizeAlgorithm) {
|
|
1946
|
+
const controller = Object.create(WritableStreamDefaultController.prototype);
|
|
1947
|
+
let startAlgorithm = () => void 0;
|
|
1948
|
+
let writeAlgorithm = () => promiseResolvedWith(void 0);
|
|
1949
|
+
let closeAlgorithm = () => promiseResolvedWith(void 0);
|
|
1950
|
+
let abortAlgorithm = () => promiseResolvedWith(void 0);
|
|
1951
|
+
if (underlyingSink.start !== void 0) {
|
|
1952
|
+
startAlgorithm = () => underlyingSink.start(controller);
|
|
1953
|
+
}
|
|
1954
|
+
if (underlyingSink.write !== void 0) {
|
|
1955
|
+
writeAlgorithm = (chunk) => underlyingSink.write(chunk, controller);
|
|
1956
|
+
}
|
|
1957
|
+
if (underlyingSink.close !== void 0) {
|
|
1958
|
+
closeAlgorithm = () => underlyingSink.close();
|
|
1959
|
+
}
|
|
1960
|
+
if (underlyingSink.abort !== void 0) {
|
|
1961
|
+
abortAlgorithm = (reason) => underlyingSink.abort(reason);
|
|
1962
|
+
}
|
|
1963
|
+
SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm);
|
|
1964
|
+
}
|
|
1965
|
+
function WritableStreamDefaultControllerClearAlgorithms(controller) {
|
|
1966
|
+
controller._writeAlgorithm = void 0;
|
|
1967
|
+
controller._closeAlgorithm = void 0;
|
|
1968
|
+
controller._abortAlgorithm = void 0;
|
|
1969
|
+
controller._strategySizeAlgorithm = void 0;
|
|
1970
|
+
}
|
|
1971
|
+
function WritableStreamDefaultControllerClose(controller) {
|
|
1972
|
+
EnqueueValueWithSize(controller, closeSentinel, 0);
|
|
1973
|
+
WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
|
|
1974
|
+
}
|
|
1975
|
+
function WritableStreamDefaultControllerGetChunkSize(controller, chunk) {
|
|
1976
|
+
try {
|
|
1977
|
+
return controller._strategySizeAlgorithm(chunk);
|
|
1978
|
+
} catch (chunkSizeE) {
|
|
1979
|
+
WritableStreamDefaultControllerErrorIfNeeded(controller, chunkSizeE);
|
|
1980
|
+
return 1;
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
function WritableStreamDefaultControllerGetDesiredSize(controller) {
|
|
1984
|
+
return controller._strategyHWM - controller._queueTotalSize;
|
|
1985
|
+
}
|
|
1986
|
+
function WritableStreamDefaultControllerWrite(controller, chunk, chunkSize) {
|
|
1987
|
+
try {
|
|
1988
|
+
EnqueueValueWithSize(controller, chunk, chunkSize);
|
|
1989
|
+
} catch (enqueueE) {
|
|
1990
|
+
WritableStreamDefaultControllerErrorIfNeeded(controller, enqueueE);
|
|
1991
|
+
return;
|
|
1992
|
+
}
|
|
1993
|
+
const stream = controller._controlledWritableStream;
|
|
1994
|
+
if (!WritableStreamCloseQueuedOrInFlight(stream) && stream._state === "writable") {
|
|
1995
|
+
const backpressure = WritableStreamDefaultControllerGetBackpressure(controller);
|
|
1996
|
+
WritableStreamUpdateBackpressure(stream, backpressure);
|
|
1997
|
+
}
|
|
1998
|
+
WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
|
|
1999
|
+
}
|
|
2000
|
+
function WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller) {
|
|
2001
|
+
const stream = controller._controlledWritableStream;
|
|
2002
|
+
if (!controller._started) {
|
|
2003
|
+
return;
|
|
2004
|
+
}
|
|
2005
|
+
if (stream._inFlightWriteRequest !== void 0) {
|
|
2006
|
+
return;
|
|
2007
|
+
}
|
|
2008
|
+
const state = stream._state;
|
|
2009
|
+
if (state === "erroring") {
|
|
2010
|
+
WritableStreamFinishErroring(stream);
|
|
2011
|
+
return;
|
|
2012
|
+
}
|
|
2013
|
+
if (controller._queue.length === 0) {
|
|
2014
|
+
return;
|
|
2015
|
+
}
|
|
2016
|
+
const value = PeekQueueValue(controller);
|
|
2017
|
+
if (value === closeSentinel) {
|
|
2018
|
+
WritableStreamDefaultControllerProcessClose(controller);
|
|
2019
|
+
} else {
|
|
2020
|
+
WritableStreamDefaultControllerProcessWrite(controller, value);
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
function WritableStreamDefaultControllerErrorIfNeeded(controller, error) {
|
|
2024
|
+
if (controller._controlledWritableStream._state === "writable") {
|
|
2025
|
+
WritableStreamDefaultControllerError(controller, error);
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
function WritableStreamDefaultControllerProcessClose(controller) {
|
|
2029
|
+
const stream = controller._controlledWritableStream;
|
|
2030
|
+
WritableStreamMarkCloseRequestInFlight(stream);
|
|
2031
|
+
DequeueValue(controller);
|
|
2032
|
+
const sinkClosePromise = controller._closeAlgorithm();
|
|
2033
|
+
WritableStreamDefaultControllerClearAlgorithms(controller);
|
|
2034
|
+
uponPromise(sinkClosePromise, () => {
|
|
2035
|
+
WritableStreamFinishInFlightClose(stream);
|
|
2036
|
+
}, (reason) => {
|
|
2037
|
+
WritableStreamFinishInFlightCloseWithError(stream, reason);
|
|
2038
|
+
});
|
|
2039
|
+
}
|
|
2040
|
+
function WritableStreamDefaultControllerProcessWrite(controller, chunk) {
|
|
2041
|
+
const stream = controller._controlledWritableStream;
|
|
2042
|
+
WritableStreamMarkFirstWriteRequestInFlight(stream);
|
|
2043
|
+
const sinkWritePromise = controller._writeAlgorithm(chunk);
|
|
2044
|
+
uponPromise(sinkWritePromise, () => {
|
|
2045
|
+
WritableStreamFinishInFlightWrite(stream);
|
|
2046
|
+
const state = stream._state;
|
|
2047
|
+
DequeueValue(controller);
|
|
2048
|
+
if (!WritableStreamCloseQueuedOrInFlight(stream) && state === "writable") {
|
|
2049
|
+
const backpressure = WritableStreamDefaultControllerGetBackpressure(controller);
|
|
2050
|
+
WritableStreamUpdateBackpressure(stream, backpressure);
|
|
2051
|
+
}
|
|
2052
|
+
WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
|
|
2053
|
+
}, (reason) => {
|
|
2054
|
+
if (stream._state === "writable") {
|
|
2055
|
+
WritableStreamDefaultControllerClearAlgorithms(controller);
|
|
2056
|
+
}
|
|
2057
|
+
WritableStreamFinishInFlightWriteWithError(stream, reason);
|
|
2058
|
+
});
|
|
2059
|
+
}
|
|
2060
|
+
function WritableStreamDefaultControllerGetBackpressure(controller) {
|
|
2061
|
+
const desiredSize = WritableStreamDefaultControllerGetDesiredSize(controller);
|
|
2062
|
+
return desiredSize <= 0;
|
|
2063
|
+
}
|
|
2064
|
+
function WritableStreamDefaultControllerError(controller, error) {
|
|
2065
|
+
const stream = controller._controlledWritableStream;
|
|
2066
|
+
WritableStreamDefaultControllerClearAlgorithms(controller);
|
|
2067
|
+
WritableStreamStartErroring(stream, error);
|
|
2068
|
+
}
|
|
2069
|
+
function streamBrandCheckException$2(name) {
|
|
2070
|
+
return new TypeError(`WritableStream.prototype.${name} can only be used on a WritableStream`);
|
|
2071
|
+
}
|
|
2072
|
+
function defaultControllerBrandCheckException$2(name) {
|
|
2073
|
+
return new TypeError(`WritableStreamDefaultController.prototype.${name} can only be used on a WritableStreamDefaultController`);
|
|
2074
|
+
}
|
|
2075
|
+
function defaultWriterBrandCheckException(name) {
|
|
2076
|
+
return new TypeError(`WritableStreamDefaultWriter.prototype.${name} can only be used on a WritableStreamDefaultWriter`);
|
|
2077
|
+
}
|
|
2078
|
+
function defaultWriterLockException(name) {
|
|
2079
|
+
return new TypeError("Cannot " + name + " a stream using a released writer");
|
|
2080
|
+
}
|
|
2081
|
+
function defaultWriterClosedPromiseInitialize(writer) {
|
|
2082
|
+
writer._closedPromise = newPromise((resolve, reject) => {
|
|
2083
|
+
writer._closedPromise_resolve = resolve;
|
|
2084
|
+
writer._closedPromise_reject = reject;
|
|
2085
|
+
writer._closedPromiseState = "pending";
|
|
2086
|
+
});
|
|
2087
|
+
}
|
|
2088
|
+
function defaultWriterClosedPromiseInitializeAsRejected(writer, reason) {
|
|
2089
|
+
defaultWriterClosedPromiseInitialize(writer);
|
|
2090
|
+
defaultWriterClosedPromiseReject(writer, reason);
|
|
2091
|
+
}
|
|
2092
|
+
function defaultWriterClosedPromiseInitializeAsResolved(writer) {
|
|
2093
|
+
defaultWriterClosedPromiseInitialize(writer);
|
|
2094
|
+
defaultWriterClosedPromiseResolve(writer);
|
|
2095
|
+
}
|
|
2096
|
+
function defaultWriterClosedPromiseReject(writer, reason) {
|
|
2097
|
+
if (writer._closedPromise_reject === void 0) {
|
|
2098
|
+
return;
|
|
2099
|
+
}
|
|
2100
|
+
setPromiseIsHandledToTrue(writer._closedPromise);
|
|
2101
|
+
writer._closedPromise_reject(reason);
|
|
2102
|
+
writer._closedPromise_resolve = void 0;
|
|
2103
|
+
writer._closedPromise_reject = void 0;
|
|
2104
|
+
writer._closedPromiseState = "rejected";
|
|
2105
|
+
}
|
|
2106
|
+
function defaultWriterClosedPromiseResetToRejected(writer, reason) {
|
|
2107
|
+
defaultWriterClosedPromiseInitializeAsRejected(writer, reason);
|
|
2108
|
+
}
|
|
2109
|
+
function defaultWriterClosedPromiseResolve(writer) {
|
|
2110
|
+
if (writer._closedPromise_resolve === void 0) {
|
|
2111
|
+
return;
|
|
2112
|
+
}
|
|
2113
|
+
writer._closedPromise_resolve(void 0);
|
|
2114
|
+
writer._closedPromise_resolve = void 0;
|
|
2115
|
+
writer._closedPromise_reject = void 0;
|
|
2116
|
+
writer._closedPromiseState = "resolved";
|
|
2117
|
+
}
|
|
2118
|
+
function defaultWriterReadyPromiseInitialize(writer) {
|
|
2119
|
+
writer._readyPromise = newPromise((resolve, reject) => {
|
|
2120
|
+
writer._readyPromise_resolve = resolve;
|
|
2121
|
+
writer._readyPromise_reject = reject;
|
|
2122
|
+
});
|
|
2123
|
+
writer._readyPromiseState = "pending";
|
|
2124
|
+
}
|
|
2125
|
+
function defaultWriterReadyPromiseInitializeAsRejected(writer, reason) {
|
|
2126
|
+
defaultWriterReadyPromiseInitialize(writer);
|
|
2127
|
+
defaultWriterReadyPromiseReject(writer, reason);
|
|
2128
|
+
}
|
|
2129
|
+
function defaultWriterReadyPromiseInitializeAsResolved(writer) {
|
|
2130
|
+
defaultWriterReadyPromiseInitialize(writer);
|
|
2131
|
+
defaultWriterReadyPromiseResolve(writer);
|
|
2132
|
+
}
|
|
2133
|
+
function defaultWriterReadyPromiseReject(writer, reason) {
|
|
2134
|
+
if (writer._readyPromise_reject === void 0) {
|
|
2135
|
+
return;
|
|
2136
|
+
}
|
|
2137
|
+
setPromiseIsHandledToTrue(writer._readyPromise);
|
|
2138
|
+
writer._readyPromise_reject(reason);
|
|
2139
|
+
writer._readyPromise_resolve = void 0;
|
|
2140
|
+
writer._readyPromise_reject = void 0;
|
|
2141
|
+
writer._readyPromiseState = "rejected";
|
|
2142
|
+
}
|
|
2143
|
+
function defaultWriterReadyPromiseReset(writer) {
|
|
2144
|
+
defaultWriterReadyPromiseInitialize(writer);
|
|
2145
|
+
}
|
|
2146
|
+
function defaultWriterReadyPromiseResetToRejected(writer, reason) {
|
|
2147
|
+
defaultWriterReadyPromiseInitializeAsRejected(writer, reason);
|
|
2148
|
+
}
|
|
2149
|
+
function defaultWriterReadyPromiseResolve(writer) {
|
|
2150
|
+
if (writer._readyPromise_resolve === void 0) {
|
|
2151
|
+
return;
|
|
2152
|
+
}
|
|
2153
|
+
writer._readyPromise_resolve(void 0);
|
|
2154
|
+
writer._readyPromise_resolve = void 0;
|
|
2155
|
+
writer._readyPromise_reject = void 0;
|
|
2156
|
+
writer._readyPromiseState = "fulfilled";
|
|
2157
|
+
}
|
|
2158
|
+
const NativeDOMException = typeof DOMException !== "undefined" ? DOMException : void 0;
|
|
2159
|
+
function isDOMExceptionConstructor(ctor) {
|
|
2160
|
+
if (!(typeof ctor === "function" || typeof ctor === "object")) {
|
|
2161
|
+
return false;
|
|
2162
|
+
}
|
|
2163
|
+
try {
|
|
2164
|
+
new ctor();
|
|
2165
|
+
return true;
|
|
2166
|
+
} catch (_a) {
|
|
2167
|
+
return false;
|
|
2168
|
+
}
|
|
2169
|
+
}
|
|
2170
|
+
function createDOMExceptionPolyfill() {
|
|
2171
|
+
const ctor = function DOMException2(message, name) {
|
|
2172
|
+
this.message = message || "";
|
|
2173
|
+
this.name = name || "Error";
|
|
2174
|
+
if (Error.captureStackTrace) {
|
|
2175
|
+
Error.captureStackTrace(this, this.constructor);
|
|
2176
|
+
}
|
|
2177
|
+
};
|
|
2178
|
+
ctor.prototype = Object.create(Error.prototype);
|
|
2179
|
+
Object.defineProperty(ctor.prototype, "constructor", { value: ctor, writable: true, configurable: true });
|
|
2180
|
+
return ctor;
|
|
2181
|
+
}
|
|
2182
|
+
const DOMException$1 = isDOMExceptionConstructor(NativeDOMException) ? NativeDOMException : createDOMExceptionPolyfill();
|
|
2183
|
+
function ReadableStreamPipeTo(source, dest, preventClose, preventAbort, preventCancel, signal) {
|
|
2184
|
+
const reader = AcquireReadableStreamDefaultReader(source);
|
|
2185
|
+
const writer = AcquireWritableStreamDefaultWriter(dest);
|
|
2186
|
+
source._disturbed = true;
|
|
2187
|
+
let shuttingDown = false;
|
|
2188
|
+
let currentWrite = promiseResolvedWith(void 0);
|
|
2189
|
+
return newPromise((resolve, reject) => {
|
|
2190
|
+
let abortAlgorithm;
|
|
2191
|
+
if (signal !== void 0) {
|
|
2192
|
+
abortAlgorithm = () => {
|
|
2193
|
+
const error = new DOMException$1("Aborted", "AbortError");
|
|
2194
|
+
const actions = [];
|
|
2195
|
+
if (!preventAbort) {
|
|
2196
|
+
actions.push(() => {
|
|
2197
|
+
if (dest._state === "writable") {
|
|
2198
|
+
return WritableStreamAbort(dest, error);
|
|
2199
|
+
}
|
|
2200
|
+
return promiseResolvedWith(void 0);
|
|
2201
|
+
});
|
|
2202
|
+
}
|
|
2203
|
+
if (!preventCancel) {
|
|
2204
|
+
actions.push(() => {
|
|
2205
|
+
if (source._state === "readable") {
|
|
2206
|
+
return ReadableStreamCancel(source, error);
|
|
2207
|
+
}
|
|
2208
|
+
return promiseResolvedWith(void 0);
|
|
2209
|
+
});
|
|
2210
|
+
}
|
|
2211
|
+
shutdownWithAction(() => Promise.all(actions.map((action) => action())), true, error);
|
|
2212
|
+
};
|
|
2213
|
+
if (signal.aborted) {
|
|
2214
|
+
abortAlgorithm();
|
|
2215
|
+
return;
|
|
2216
|
+
}
|
|
2217
|
+
signal.addEventListener("abort", abortAlgorithm);
|
|
2218
|
+
}
|
|
2219
|
+
function pipeLoop() {
|
|
2220
|
+
return newPromise((resolveLoop, rejectLoop) => {
|
|
2221
|
+
function next(done) {
|
|
2222
|
+
if (done) {
|
|
2223
|
+
resolveLoop();
|
|
2224
|
+
} else {
|
|
2225
|
+
PerformPromiseThen(pipeStep(), next, rejectLoop);
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
next(false);
|
|
2229
|
+
});
|
|
2230
|
+
}
|
|
2231
|
+
function pipeStep() {
|
|
2232
|
+
if (shuttingDown) {
|
|
2233
|
+
return promiseResolvedWith(true);
|
|
2234
|
+
}
|
|
2235
|
+
return PerformPromiseThen(writer._readyPromise, () => {
|
|
2236
|
+
return newPromise((resolveRead, rejectRead) => {
|
|
2237
|
+
ReadableStreamDefaultReaderRead(reader, {
|
|
2238
|
+
_chunkSteps: (chunk) => {
|
|
2239
|
+
currentWrite = PerformPromiseThen(WritableStreamDefaultWriterWrite(writer, chunk), void 0, noop);
|
|
2240
|
+
resolveRead(false);
|
|
2241
|
+
},
|
|
2242
|
+
_closeSteps: () => resolveRead(true),
|
|
2243
|
+
_errorSteps: rejectRead
|
|
2244
|
+
});
|
|
2245
|
+
});
|
|
2246
|
+
});
|
|
2247
|
+
}
|
|
2248
|
+
isOrBecomesErrored(source, reader._closedPromise, (storedError) => {
|
|
2249
|
+
if (!preventAbort) {
|
|
2250
|
+
shutdownWithAction(() => WritableStreamAbort(dest, storedError), true, storedError);
|
|
2251
|
+
} else {
|
|
2252
|
+
shutdown(true, storedError);
|
|
2253
|
+
}
|
|
2254
|
+
});
|
|
2255
|
+
isOrBecomesErrored(dest, writer._closedPromise, (storedError) => {
|
|
2256
|
+
if (!preventCancel) {
|
|
2257
|
+
shutdownWithAction(() => ReadableStreamCancel(source, storedError), true, storedError);
|
|
2258
|
+
} else {
|
|
2259
|
+
shutdown(true, storedError);
|
|
2260
|
+
}
|
|
2261
|
+
});
|
|
2262
|
+
isOrBecomesClosed(source, reader._closedPromise, () => {
|
|
2263
|
+
if (!preventClose) {
|
|
2264
|
+
shutdownWithAction(() => WritableStreamDefaultWriterCloseWithErrorPropagation(writer));
|
|
2265
|
+
} else {
|
|
2266
|
+
shutdown();
|
|
2267
|
+
}
|
|
2268
|
+
});
|
|
2269
|
+
if (WritableStreamCloseQueuedOrInFlight(dest) || dest._state === "closed") {
|
|
2270
|
+
const destClosed = new TypeError("the destination writable stream closed before all data could be piped to it");
|
|
2271
|
+
if (!preventCancel) {
|
|
2272
|
+
shutdownWithAction(() => ReadableStreamCancel(source, destClosed), true, destClosed);
|
|
2273
|
+
} else {
|
|
2274
|
+
shutdown(true, destClosed);
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2277
|
+
setPromiseIsHandledToTrue(pipeLoop());
|
|
2278
|
+
function waitForWritesToFinish() {
|
|
2279
|
+
const oldCurrentWrite = currentWrite;
|
|
2280
|
+
return PerformPromiseThen(currentWrite, () => oldCurrentWrite !== currentWrite ? waitForWritesToFinish() : void 0);
|
|
2281
|
+
}
|
|
2282
|
+
function isOrBecomesErrored(stream, promise, action) {
|
|
2283
|
+
if (stream._state === "errored") {
|
|
2284
|
+
action(stream._storedError);
|
|
2285
|
+
} else {
|
|
2286
|
+
uponRejection(promise, action);
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
function isOrBecomesClosed(stream, promise, action) {
|
|
2290
|
+
if (stream._state === "closed") {
|
|
2291
|
+
action();
|
|
2292
|
+
} else {
|
|
2293
|
+
uponFulfillment(promise, action);
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2296
|
+
function shutdownWithAction(action, originalIsError, originalError) {
|
|
2297
|
+
if (shuttingDown) {
|
|
2298
|
+
return;
|
|
2299
|
+
}
|
|
2300
|
+
shuttingDown = true;
|
|
2301
|
+
if (dest._state === "writable" && !WritableStreamCloseQueuedOrInFlight(dest)) {
|
|
2302
|
+
uponFulfillment(waitForWritesToFinish(), doTheRest);
|
|
2303
|
+
} else {
|
|
2304
|
+
doTheRest();
|
|
2305
|
+
}
|
|
2306
|
+
function doTheRest() {
|
|
2307
|
+
uponPromise(action(), () => finalize(originalIsError, originalError), (newError) => finalize(true, newError));
|
|
2308
|
+
}
|
|
2309
|
+
}
|
|
2310
|
+
function shutdown(isError, error) {
|
|
2311
|
+
if (shuttingDown) {
|
|
2312
|
+
return;
|
|
2313
|
+
}
|
|
2314
|
+
shuttingDown = true;
|
|
2315
|
+
if (dest._state === "writable" && !WritableStreamCloseQueuedOrInFlight(dest)) {
|
|
2316
|
+
uponFulfillment(waitForWritesToFinish(), () => finalize(isError, error));
|
|
2317
|
+
} else {
|
|
2318
|
+
finalize(isError, error);
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
function finalize(isError, error) {
|
|
2322
|
+
WritableStreamDefaultWriterRelease(writer);
|
|
2323
|
+
ReadableStreamReaderGenericRelease(reader);
|
|
2324
|
+
if (signal !== void 0) {
|
|
2325
|
+
signal.removeEventListener("abort", abortAlgorithm);
|
|
2326
|
+
}
|
|
2327
|
+
if (isError) {
|
|
2328
|
+
reject(error);
|
|
2329
|
+
} else {
|
|
2330
|
+
resolve(void 0);
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
});
|
|
2334
|
+
}
|
|
2335
|
+
class ReadableStreamDefaultController {
|
|
2336
|
+
constructor() {
|
|
2337
|
+
throw new TypeError("Illegal constructor");
|
|
2338
|
+
}
|
|
2339
|
+
get desiredSize() {
|
|
2340
|
+
if (!IsReadableStreamDefaultController(this)) {
|
|
2341
|
+
throw defaultControllerBrandCheckException$1("desiredSize");
|
|
2342
|
+
}
|
|
2343
|
+
return ReadableStreamDefaultControllerGetDesiredSize(this);
|
|
2344
|
+
}
|
|
2345
|
+
close() {
|
|
2346
|
+
if (!IsReadableStreamDefaultController(this)) {
|
|
2347
|
+
throw defaultControllerBrandCheckException$1("close");
|
|
2348
|
+
}
|
|
2349
|
+
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(this)) {
|
|
2350
|
+
throw new TypeError("The stream is not in a state that permits close");
|
|
2351
|
+
}
|
|
2352
|
+
ReadableStreamDefaultControllerClose(this);
|
|
2353
|
+
}
|
|
2354
|
+
enqueue(chunk = void 0) {
|
|
2355
|
+
if (!IsReadableStreamDefaultController(this)) {
|
|
2356
|
+
throw defaultControllerBrandCheckException$1("enqueue");
|
|
2357
|
+
}
|
|
2358
|
+
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(this)) {
|
|
2359
|
+
throw new TypeError("The stream is not in a state that permits enqueue");
|
|
2360
|
+
}
|
|
2361
|
+
return ReadableStreamDefaultControllerEnqueue(this, chunk);
|
|
2362
|
+
}
|
|
2363
|
+
error(e = void 0) {
|
|
2364
|
+
if (!IsReadableStreamDefaultController(this)) {
|
|
2365
|
+
throw defaultControllerBrandCheckException$1("error");
|
|
2366
|
+
}
|
|
2367
|
+
ReadableStreamDefaultControllerError(this, e);
|
|
2368
|
+
}
|
|
2369
|
+
[CancelSteps](reason) {
|
|
2370
|
+
ResetQueue(this);
|
|
2371
|
+
const result = this._cancelAlgorithm(reason);
|
|
2372
|
+
ReadableStreamDefaultControllerClearAlgorithms(this);
|
|
2373
|
+
return result;
|
|
2374
|
+
}
|
|
2375
|
+
[PullSteps](readRequest) {
|
|
2376
|
+
const stream = this._controlledReadableStream;
|
|
2377
|
+
if (this._queue.length > 0) {
|
|
2378
|
+
const chunk = DequeueValue(this);
|
|
2379
|
+
if (this._closeRequested && this._queue.length === 0) {
|
|
2380
|
+
ReadableStreamDefaultControllerClearAlgorithms(this);
|
|
2381
|
+
ReadableStreamClose(stream);
|
|
2382
|
+
} else {
|
|
2383
|
+
ReadableStreamDefaultControllerCallPullIfNeeded(this);
|
|
2384
|
+
}
|
|
2385
|
+
readRequest._chunkSteps(chunk);
|
|
2386
|
+
} else {
|
|
2387
|
+
ReadableStreamAddReadRequest(stream, readRequest);
|
|
2388
|
+
ReadableStreamDefaultControllerCallPullIfNeeded(this);
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2392
|
+
Object.defineProperties(ReadableStreamDefaultController.prototype, {
|
|
2393
|
+
close: { enumerable: true },
|
|
2394
|
+
enqueue: { enumerable: true },
|
|
2395
|
+
error: { enumerable: true },
|
|
2396
|
+
desiredSize: { enumerable: true }
|
|
2397
|
+
});
|
|
2398
|
+
if (typeof SymbolPolyfill.toStringTag === "symbol") {
|
|
2399
|
+
Object.defineProperty(ReadableStreamDefaultController.prototype, SymbolPolyfill.toStringTag, {
|
|
2400
|
+
value: "ReadableStreamDefaultController",
|
|
2401
|
+
configurable: true
|
|
2402
|
+
});
|
|
2403
|
+
}
|
|
2404
|
+
function IsReadableStreamDefaultController(x) {
|
|
2405
|
+
if (!typeIsObject(x)) {
|
|
2406
|
+
return false;
|
|
2407
|
+
}
|
|
2408
|
+
if (!Object.prototype.hasOwnProperty.call(x, "_controlledReadableStream")) {
|
|
2409
|
+
return false;
|
|
2410
|
+
}
|
|
2411
|
+
return x instanceof ReadableStreamDefaultController;
|
|
2412
|
+
}
|
|
2413
|
+
function ReadableStreamDefaultControllerCallPullIfNeeded(controller) {
|
|
2414
|
+
const shouldPull = ReadableStreamDefaultControllerShouldCallPull(controller);
|
|
2415
|
+
if (!shouldPull) {
|
|
2416
|
+
return;
|
|
2417
|
+
}
|
|
2418
|
+
if (controller._pulling) {
|
|
2419
|
+
controller._pullAgain = true;
|
|
2420
|
+
return;
|
|
2421
|
+
}
|
|
2422
|
+
controller._pulling = true;
|
|
2423
|
+
const pullPromise = controller._pullAlgorithm();
|
|
2424
|
+
uponPromise(pullPromise, () => {
|
|
2425
|
+
controller._pulling = false;
|
|
2426
|
+
if (controller._pullAgain) {
|
|
2427
|
+
controller._pullAgain = false;
|
|
2428
|
+
ReadableStreamDefaultControllerCallPullIfNeeded(controller);
|
|
2429
|
+
}
|
|
2430
|
+
}, (e) => {
|
|
2431
|
+
ReadableStreamDefaultControllerError(controller, e);
|
|
2432
|
+
});
|
|
2433
|
+
}
|
|
2434
|
+
function ReadableStreamDefaultControllerShouldCallPull(controller) {
|
|
2435
|
+
const stream = controller._controlledReadableStream;
|
|
2436
|
+
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(controller)) {
|
|
2437
|
+
return false;
|
|
2438
|
+
}
|
|
2439
|
+
if (!controller._started) {
|
|
2440
|
+
return false;
|
|
2441
|
+
}
|
|
2442
|
+
if (IsReadableStreamLocked(stream) && ReadableStreamGetNumReadRequests(stream) > 0) {
|
|
2443
|
+
return true;
|
|
2444
|
+
}
|
|
2445
|
+
const desiredSize = ReadableStreamDefaultControllerGetDesiredSize(controller);
|
|
2446
|
+
if (desiredSize > 0) {
|
|
2447
|
+
return true;
|
|
2448
|
+
}
|
|
2449
|
+
return false;
|
|
2450
|
+
}
|
|
2451
|
+
function ReadableStreamDefaultControllerClearAlgorithms(controller) {
|
|
2452
|
+
controller._pullAlgorithm = void 0;
|
|
2453
|
+
controller._cancelAlgorithm = void 0;
|
|
2454
|
+
controller._strategySizeAlgorithm = void 0;
|
|
2455
|
+
}
|
|
2456
|
+
function ReadableStreamDefaultControllerClose(controller) {
|
|
2457
|
+
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(controller)) {
|
|
2458
|
+
return;
|
|
2459
|
+
}
|
|
2460
|
+
const stream = controller._controlledReadableStream;
|
|
2461
|
+
controller._closeRequested = true;
|
|
2462
|
+
if (controller._queue.length === 0) {
|
|
2463
|
+
ReadableStreamDefaultControllerClearAlgorithms(controller);
|
|
2464
|
+
ReadableStreamClose(stream);
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
function ReadableStreamDefaultControllerEnqueue(controller, chunk) {
|
|
2468
|
+
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(controller)) {
|
|
2469
|
+
return;
|
|
2470
|
+
}
|
|
2471
|
+
const stream = controller._controlledReadableStream;
|
|
2472
|
+
if (IsReadableStreamLocked(stream) && ReadableStreamGetNumReadRequests(stream) > 0) {
|
|
2473
|
+
ReadableStreamFulfillReadRequest(stream, chunk, false);
|
|
2474
|
+
} else {
|
|
2475
|
+
let chunkSize;
|
|
2476
|
+
try {
|
|
2477
|
+
chunkSize = controller._strategySizeAlgorithm(chunk);
|
|
2478
|
+
} catch (chunkSizeE) {
|
|
2479
|
+
ReadableStreamDefaultControllerError(controller, chunkSizeE);
|
|
2480
|
+
throw chunkSizeE;
|
|
2481
|
+
}
|
|
2482
|
+
try {
|
|
2483
|
+
EnqueueValueWithSize(controller, chunk, chunkSize);
|
|
2484
|
+
} catch (enqueueE) {
|
|
2485
|
+
ReadableStreamDefaultControllerError(controller, enqueueE);
|
|
2486
|
+
throw enqueueE;
|
|
2487
|
+
}
|
|
2488
|
+
}
|
|
2489
|
+
ReadableStreamDefaultControllerCallPullIfNeeded(controller);
|
|
2490
|
+
}
|
|
2491
|
+
function ReadableStreamDefaultControllerError(controller, e) {
|
|
2492
|
+
const stream = controller._controlledReadableStream;
|
|
2493
|
+
if (stream._state !== "readable") {
|
|
2494
|
+
return;
|
|
2495
|
+
}
|
|
2496
|
+
ResetQueue(controller);
|
|
2497
|
+
ReadableStreamDefaultControllerClearAlgorithms(controller);
|
|
2498
|
+
ReadableStreamError(stream, e);
|
|
2499
|
+
}
|
|
2500
|
+
function ReadableStreamDefaultControllerGetDesiredSize(controller) {
|
|
2501
|
+
const state = controller._controlledReadableStream._state;
|
|
2502
|
+
if (state === "errored") {
|
|
2503
|
+
return null;
|
|
2504
|
+
}
|
|
2505
|
+
if (state === "closed") {
|
|
2506
|
+
return 0;
|
|
2507
|
+
}
|
|
2508
|
+
return controller._strategyHWM - controller._queueTotalSize;
|
|
2509
|
+
}
|
|
2510
|
+
function ReadableStreamDefaultControllerHasBackpressure(controller) {
|
|
2511
|
+
if (ReadableStreamDefaultControllerShouldCallPull(controller)) {
|
|
2512
|
+
return false;
|
|
2513
|
+
}
|
|
2514
|
+
return true;
|
|
2515
|
+
}
|
|
2516
|
+
function ReadableStreamDefaultControllerCanCloseOrEnqueue(controller) {
|
|
2517
|
+
const state = controller._controlledReadableStream._state;
|
|
2518
|
+
if (!controller._closeRequested && state === "readable") {
|
|
2519
|
+
return true;
|
|
2520
|
+
}
|
|
2521
|
+
return false;
|
|
2522
|
+
}
|
|
2523
|
+
function SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm) {
|
|
2524
|
+
controller._controlledReadableStream = stream;
|
|
2525
|
+
controller._queue = void 0;
|
|
2526
|
+
controller._queueTotalSize = void 0;
|
|
2527
|
+
ResetQueue(controller);
|
|
2528
|
+
controller._started = false;
|
|
2529
|
+
controller._closeRequested = false;
|
|
2530
|
+
controller._pullAgain = false;
|
|
2531
|
+
controller._pulling = false;
|
|
2532
|
+
controller._strategySizeAlgorithm = sizeAlgorithm;
|
|
2533
|
+
controller._strategyHWM = highWaterMark;
|
|
2534
|
+
controller._pullAlgorithm = pullAlgorithm;
|
|
2535
|
+
controller._cancelAlgorithm = cancelAlgorithm;
|
|
2536
|
+
stream._readableStreamController = controller;
|
|
2537
|
+
const startResult = startAlgorithm();
|
|
2538
|
+
uponPromise(promiseResolvedWith(startResult), () => {
|
|
2539
|
+
controller._started = true;
|
|
2540
|
+
ReadableStreamDefaultControllerCallPullIfNeeded(controller);
|
|
2541
|
+
}, (r) => {
|
|
2542
|
+
ReadableStreamDefaultControllerError(controller, r);
|
|
2543
|
+
});
|
|
2544
|
+
}
|
|
2545
|
+
function SetUpReadableStreamDefaultControllerFromUnderlyingSource(stream, underlyingSource, highWaterMark, sizeAlgorithm) {
|
|
2546
|
+
const controller = Object.create(ReadableStreamDefaultController.prototype);
|
|
2547
|
+
let startAlgorithm = () => void 0;
|
|
2548
|
+
let pullAlgorithm = () => promiseResolvedWith(void 0);
|
|
2549
|
+
let cancelAlgorithm = () => promiseResolvedWith(void 0);
|
|
2550
|
+
if (underlyingSource.start !== void 0) {
|
|
2551
|
+
startAlgorithm = () => underlyingSource.start(controller);
|
|
2552
|
+
}
|
|
2553
|
+
if (underlyingSource.pull !== void 0) {
|
|
2554
|
+
pullAlgorithm = () => underlyingSource.pull(controller);
|
|
2555
|
+
}
|
|
2556
|
+
if (underlyingSource.cancel !== void 0) {
|
|
2557
|
+
cancelAlgorithm = (reason) => underlyingSource.cancel(reason);
|
|
2558
|
+
}
|
|
2559
|
+
SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm);
|
|
2560
|
+
}
|
|
2561
|
+
function defaultControllerBrandCheckException$1(name) {
|
|
2562
|
+
return new TypeError(`ReadableStreamDefaultController.prototype.${name} can only be used on a ReadableStreamDefaultController`);
|
|
2563
|
+
}
|
|
2564
|
+
function ReadableStreamTee(stream, cloneForBranch2) {
|
|
2565
|
+
if (IsReadableByteStreamController(stream._readableStreamController)) {
|
|
2566
|
+
return ReadableByteStreamTee(stream);
|
|
2567
|
+
}
|
|
2568
|
+
return ReadableStreamDefaultTee(stream);
|
|
2569
|
+
}
|
|
2570
|
+
function ReadableStreamDefaultTee(stream, cloneForBranch2) {
|
|
2571
|
+
const reader = AcquireReadableStreamDefaultReader(stream);
|
|
2572
|
+
let reading = false;
|
|
2573
|
+
let readAgain = false;
|
|
2574
|
+
let canceled1 = false;
|
|
2575
|
+
let canceled2 = false;
|
|
2576
|
+
let reason1;
|
|
2577
|
+
let reason2;
|
|
2578
|
+
let branch1;
|
|
2579
|
+
let branch2;
|
|
2580
|
+
let resolveCancelPromise;
|
|
2581
|
+
const cancelPromise = newPromise((resolve) => {
|
|
2582
|
+
resolveCancelPromise = resolve;
|
|
2583
|
+
});
|
|
2584
|
+
function pullAlgorithm() {
|
|
2585
|
+
if (reading) {
|
|
2586
|
+
readAgain = true;
|
|
2587
|
+
return promiseResolvedWith(void 0);
|
|
2588
|
+
}
|
|
2589
|
+
reading = true;
|
|
2590
|
+
const readRequest = {
|
|
2591
|
+
_chunkSteps: (chunk) => {
|
|
2592
|
+
queueMicrotask(() => {
|
|
2593
|
+
readAgain = false;
|
|
2594
|
+
const chunk1 = chunk;
|
|
2595
|
+
const chunk2 = chunk;
|
|
2596
|
+
if (!canceled1) {
|
|
2597
|
+
ReadableStreamDefaultControllerEnqueue(branch1._readableStreamController, chunk1);
|
|
2598
|
+
}
|
|
2599
|
+
if (!canceled2) {
|
|
2600
|
+
ReadableStreamDefaultControllerEnqueue(branch2._readableStreamController, chunk2);
|
|
2601
|
+
}
|
|
2602
|
+
reading = false;
|
|
2603
|
+
if (readAgain) {
|
|
2604
|
+
pullAlgorithm();
|
|
2605
|
+
}
|
|
2606
|
+
});
|
|
2607
|
+
},
|
|
2608
|
+
_closeSteps: () => {
|
|
2609
|
+
reading = false;
|
|
2610
|
+
if (!canceled1) {
|
|
2611
|
+
ReadableStreamDefaultControllerClose(branch1._readableStreamController);
|
|
2612
|
+
}
|
|
2613
|
+
if (!canceled2) {
|
|
2614
|
+
ReadableStreamDefaultControllerClose(branch2._readableStreamController);
|
|
2615
|
+
}
|
|
2616
|
+
if (!canceled1 || !canceled2) {
|
|
2617
|
+
resolveCancelPromise(void 0);
|
|
2618
|
+
}
|
|
2619
|
+
},
|
|
2620
|
+
_errorSteps: () => {
|
|
2621
|
+
reading = false;
|
|
2622
|
+
}
|
|
2623
|
+
};
|
|
2624
|
+
ReadableStreamDefaultReaderRead(reader, readRequest);
|
|
2625
|
+
return promiseResolvedWith(void 0);
|
|
2626
|
+
}
|
|
2627
|
+
function cancel1Algorithm(reason) {
|
|
2628
|
+
canceled1 = true;
|
|
2629
|
+
reason1 = reason;
|
|
2630
|
+
if (canceled2) {
|
|
2631
|
+
const compositeReason = CreateArrayFromList([reason1, reason2]);
|
|
2632
|
+
const cancelResult = ReadableStreamCancel(stream, compositeReason);
|
|
2633
|
+
resolveCancelPromise(cancelResult);
|
|
2634
|
+
}
|
|
2635
|
+
return cancelPromise;
|
|
2636
|
+
}
|
|
2637
|
+
function cancel2Algorithm(reason) {
|
|
2638
|
+
canceled2 = true;
|
|
2639
|
+
reason2 = reason;
|
|
2640
|
+
if (canceled1) {
|
|
2641
|
+
const compositeReason = CreateArrayFromList([reason1, reason2]);
|
|
2642
|
+
const cancelResult = ReadableStreamCancel(stream, compositeReason);
|
|
2643
|
+
resolveCancelPromise(cancelResult);
|
|
2644
|
+
}
|
|
2645
|
+
return cancelPromise;
|
|
2646
|
+
}
|
|
2647
|
+
function startAlgorithm() {
|
|
2648
|
+
}
|
|
2649
|
+
branch1 = CreateReadableStream(startAlgorithm, pullAlgorithm, cancel1Algorithm);
|
|
2650
|
+
branch2 = CreateReadableStream(startAlgorithm, pullAlgorithm, cancel2Algorithm);
|
|
2651
|
+
uponRejection(reader._closedPromise, (r) => {
|
|
2652
|
+
ReadableStreamDefaultControllerError(branch1._readableStreamController, r);
|
|
2653
|
+
ReadableStreamDefaultControllerError(branch2._readableStreamController, r);
|
|
2654
|
+
if (!canceled1 || !canceled2) {
|
|
2655
|
+
resolveCancelPromise(void 0);
|
|
2656
|
+
}
|
|
2657
|
+
});
|
|
2658
|
+
return [branch1, branch2];
|
|
2659
|
+
}
|
|
2660
|
+
function ReadableByteStreamTee(stream) {
|
|
2661
|
+
let reader = AcquireReadableStreamDefaultReader(stream);
|
|
2662
|
+
let reading = false;
|
|
2663
|
+
let readAgainForBranch1 = false;
|
|
2664
|
+
let readAgainForBranch2 = false;
|
|
2665
|
+
let canceled1 = false;
|
|
2666
|
+
let canceled2 = false;
|
|
2667
|
+
let reason1;
|
|
2668
|
+
let reason2;
|
|
2669
|
+
let branch1;
|
|
2670
|
+
let branch2;
|
|
2671
|
+
let resolveCancelPromise;
|
|
2672
|
+
const cancelPromise = newPromise((resolve) => {
|
|
2673
|
+
resolveCancelPromise = resolve;
|
|
2674
|
+
});
|
|
2675
|
+
function forwardReaderError(thisReader) {
|
|
2676
|
+
uponRejection(thisReader._closedPromise, (r) => {
|
|
2677
|
+
if (thisReader !== reader) {
|
|
2678
|
+
return;
|
|
2679
|
+
}
|
|
2680
|
+
ReadableByteStreamControllerError(branch1._readableStreamController, r);
|
|
2681
|
+
ReadableByteStreamControllerError(branch2._readableStreamController, r);
|
|
2682
|
+
if (!canceled1 || !canceled2) {
|
|
2683
|
+
resolveCancelPromise(void 0);
|
|
2684
|
+
}
|
|
2685
|
+
});
|
|
2686
|
+
}
|
|
2687
|
+
function pullWithDefaultReader() {
|
|
2688
|
+
if (IsReadableStreamBYOBReader(reader)) {
|
|
2689
|
+
ReadableStreamReaderGenericRelease(reader);
|
|
2690
|
+
reader = AcquireReadableStreamDefaultReader(stream);
|
|
2691
|
+
forwardReaderError(reader);
|
|
2692
|
+
}
|
|
2693
|
+
const readRequest = {
|
|
2694
|
+
_chunkSteps: (chunk) => {
|
|
2695
|
+
queueMicrotask(() => {
|
|
2696
|
+
readAgainForBranch1 = false;
|
|
2697
|
+
readAgainForBranch2 = false;
|
|
2698
|
+
const chunk1 = chunk;
|
|
2699
|
+
let chunk2 = chunk;
|
|
2700
|
+
if (!canceled1 && !canceled2) {
|
|
2701
|
+
try {
|
|
2702
|
+
chunk2 = CloneAsUint8Array(chunk);
|
|
2703
|
+
} catch (cloneE) {
|
|
2704
|
+
ReadableByteStreamControllerError(branch1._readableStreamController, cloneE);
|
|
2705
|
+
ReadableByteStreamControllerError(branch2._readableStreamController, cloneE);
|
|
2706
|
+
resolveCancelPromise(ReadableStreamCancel(stream, cloneE));
|
|
2707
|
+
return;
|
|
2708
|
+
}
|
|
2709
|
+
}
|
|
2710
|
+
if (!canceled1) {
|
|
2711
|
+
ReadableByteStreamControllerEnqueue(branch1._readableStreamController, chunk1);
|
|
2712
|
+
}
|
|
2713
|
+
if (!canceled2) {
|
|
2714
|
+
ReadableByteStreamControllerEnqueue(branch2._readableStreamController, chunk2);
|
|
2715
|
+
}
|
|
2716
|
+
reading = false;
|
|
2717
|
+
if (readAgainForBranch1) {
|
|
2718
|
+
pull1Algorithm();
|
|
2719
|
+
} else if (readAgainForBranch2) {
|
|
2720
|
+
pull2Algorithm();
|
|
2721
|
+
}
|
|
2722
|
+
});
|
|
2723
|
+
},
|
|
2724
|
+
_closeSteps: () => {
|
|
2725
|
+
reading = false;
|
|
2726
|
+
if (!canceled1) {
|
|
2727
|
+
ReadableByteStreamControllerClose(branch1._readableStreamController);
|
|
2728
|
+
}
|
|
2729
|
+
if (!canceled2) {
|
|
2730
|
+
ReadableByteStreamControllerClose(branch2._readableStreamController);
|
|
2731
|
+
}
|
|
2732
|
+
if (branch1._readableStreamController._pendingPullIntos.length > 0) {
|
|
2733
|
+
ReadableByteStreamControllerRespond(branch1._readableStreamController, 0);
|
|
2734
|
+
}
|
|
2735
|
+
if (branch2._readableStreamController._pendingPullIntos.length > 0) {
|
|
2736
|
+
ReadableByteStreamControllerRespond(branch2._readableStreamController, 0);
|
|
2737
|
+
}
|
|
2738
|
+
if (!canceled1 || !canceled2) {
|
|
2739
|
+
resolveCancelPromise(void 0);
|
|
2740
|
+
}
|
|
2741
|
+
},
|
|
2742
|
+
_errorSteps: () => {
|
|
2743
|
+
reading = false;
|
|
2744
|
+
}
|
|
2745
|
+
};
|
|
2746
|
+
ReadableStreamDefaultReaderRead(reader, readRequest);
|
|
2747
|
+
}
|
|
2748
|
+
function pullWithBYOBReader(view, forBranch2) {
|
|
2749
|
+
if (IsReadableStreamDefaultReader(reader)) {
|
|
2750
|
+
ReadableStreamReaderGenericRelease(reader);
|
|
2751
|
+
reader = AcquireReadableStreamBYOBReader(stream);
|
|
2752
|
+
forwardReaderError(reader);
|
|
2753
|
+
}
|
|
2754
|
+
const byobBranch = forBranch2 ? branch2 : branch1;
|
|
2755
|
+
const otherBranch = forBranch2 ? branch1 : branch2;
|
|
2756
|
+
const readIntoRequest = {
|
|
2757
|
+
_chunkSteps: (chunk) => {
|
|
2758
|
+
queueMicrotask(() => {
|
|
2759
|
+
readAgainForBranch1 = false;
|
|
2760
|
+
readAgainForBranch2 = false;
|
|
2761
|
+
const byobCanceled = forBranch2 ? canceled2 : canceled1;
|
|
2762
|
+
const otherCanceled = forBranch2 ? canceled1 : canceled2;
|
|
2763
|
+
if (!otherCanceled) {
|
|
2764
|
+
let clonedChunk;
|
|
2765
|
+
try {
|
|
2766
|
+
clonedChunk = CloneAsUint8Array(chunk);
|
|
2767
|
+
} catch (cloneE) {
|
|
2768
|
+
ReadableByteStreamControllerError(byobBranch._readableStreamController, cloneE);
|
|
2769
|
+
ReadableByteStreamControllerError(otherBranch._readableStreamController, cloneE);
|
|
2770
|
+
resolveCancelPromise(ReadableStreamCancel(stream, cloneE));
|
|
2771
|
+
return;
|
|
2772
|
+
}
|
|
2773
|
+
if (!byobCanceled) {
|
|
2774
|
+
ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
|
|
2775
|
+
}
|
|
2776
|
+
ReadableByteStreamControllerEnqueue(otherBranch._readableStreamController, clonedChunk);
|
|
2777
|
+
} else if (!byobCanceled) {
|
|
2778
|
+
ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
|
|
2779
|
+
}
|
|
2780
|
+
reading = false;
|
|
2781
|
+
if (readAgainForBranch1) {
|
|
2782
|
+
pull1Algorithm();
|
|
2783
|
+
} else if (readAgainForBranch2) {
|
|
2784
|
+
pull2Algorithm();
|
|
2785
|
+
}
|
|
2786
|
+
});
|
|
2787
|
+
},
|
|
2788
|
+
_closeSteps: (chunk) => {
|
|
2789
|
+
reading = false;
|
|
2790
|
+
const byobCanceled = forBranch2 ? canceled2 : canceled1;
|
|
2791
|
+
const otherCanceled = forBranch2 ? canceled1 : canceled2;
|
|
2792
|
+
if (!byobCanceled) {
|
|
2793
|
+
ReadableByteStreamControllerClose(byobBranch._readableStreamController);
|
|
2794
|
+
}
|
|
2795
|
+
if (!otherCanceled) {
|
|
2796
|
+
ReadableByteStreamControllerClose(otherBranch._readableStreamController);
|
|
2797
|
+
}
|
|
2798
|
+
if (chunk !== void 0) {
|
|
2799
|
+
if (!byobCanceled) {
|
|
2800
|
+
ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
|
|
2801
|
+
}
|
|
2802
|
+
if (!otherCanceled && otherBranch._readableStreamController._pendingPullIntos.length > 0) {
|
|
2803
|
+
ReadableByteStreamControllerRespond(otherBranch._readableStreamController, 0);
|
|
2804
|
+
}
|
|
2805
|
+
}
|
|
2806
|
+
if (!byobCanceled || !otherCanceled) {
|
|
2807
|
+
resolveCancelPromise(void 0);
|
|
2808
|
+
}
|
|
2809
|
+
},
|
|
2810
|
+
_errorSteps: () => {
|
|
2811
|
+
reading = false;
|
|
2812
|
+
}
|
|
2813
|
+
};
|
|
2814
|
+
ReadableStreamBYOBReaderRead(reader, view, readIntoRequest);
|
|
2815
|
+
}
|
|
2816
|
+
function pull1Algorithm() {
|
|
2817
|
+
if (reading) {
|
|
2818
|
+
readAgainForBranch1 = true;
|
|
2819
|
+
return promiseResolvedWith(void 0);
|
|
2820
|
+
}
|
|
2821
|
+
reading = true;
|
|
2822
|
+
const byobRequest = ReadableByteStreamControllerGetBYOBRequest(branch1._readableStreamController);
|
|
2823
|
+
if (byobRequest === null) {
|
|
2824
|
+
pullWithDefaultReader();
|
|
2825
|
+
} else {
|
|
2826
|
+
pullWithBYOBReader(byobRequest._view, false);
|
|
2827
|
+
}
|
|
2828
|
+
return promiseResolvedWith(void 0);
|
|
2829
|
+
}
|
|
2830
|
+
function pull2Algorithm() {
|
|
2831
|
+
if (reading) {
|
|
2832
|
+
readAgainForBranch2 = true;
|
|
2833
|
+
return promiseResolvedWith(void 0);
|
|
2834
|
+
}
|
|
2835
|
+
reading = true;
|
|
2836
|
+
const byobRequest = ReadableByteStreamControllerGetBYOBRequest(branch2._readableStreamController);
|
|
2837
|
+
if (byobRequest === null) {
|
|
2838
|
+
pullWithDefaultReader();
|
|
2839
|
+
} else {
|
|
2840
|
+
pullWithBYOBReader(byobRequest._view, true);
|
|
2841
|
+
}
|
|
2842
|
+
return promiseResolvedWith(void 0);
|
|
2843
|
+
}
|
|
2844
|
+
function cancel1Algorithm(reason) {
|
|
2845
|
+
canceled1 = true;
|
|
2846
|
+
reason1 = reason;
|
|
2847
|
+
if (canceled2) {
|
|
2848
|
+
const compositeReason = CreateArrayFromList([reason1, reason2]);
|
|
2849
|
+
const cancelResult = ReadableStreamCancel(stream, compositeReason);
|
|
2850
|
+
resolveCancelPromise(cancelResult);
|
|
2851
|
+
}
|
|
2852
|
+
return cancelPromise;
|
|
2853
|
+
}
|
|
2854
|
+
function cancel2Algorithm(reason) {
|
|
2855
|
+
canceled2 = true;
|
|
2856
|
+
reason2 = reason;
|
|
2857
|
+
if (canceled1) {
|
|
2858
|
+
const compositeReason = CreateArrayFromList([reason1, reason2]);
|
|
2859
|
+
const cancelResult = ReadableStreamCancel(stream, compositeReason);
|
|
2860
|
+
resolveCancelPromise(cancelResult);
|
|
2861
|
+
}
|
|
2862
|
+
return cancelPromise;
|
|
2863
|
+
}
|
|
2864
|
+
function startAlgorithm() {
|
|
2865
|
+
return;
|
|
2866
|
+
}
|
|
2867
|
+
branch1 = CreateReadableByteStream(startAlgorithm, pull1Algorithm, cancel1Algorithm);
|
|
2868
|
+
branch2 = CreateReadableByteStream(startAlgorithm, pull2Algorithm, cancel2Algorithm);
|
|
2869
|
+
forwardReaderError(reader);
|
|
2870
|
+
return [branch1, branch2];
|
|
2871
|
+
}
|
|
2872
|
+
function convertUnderlyingDefaultOrByteSource(source, context) {
|
|
2873
|
+
assertDictionary(source, context);
|
|
2874
|
+
const original = source;
|
|
2875
|
+
const autoAllocateChunkSize = original === null || original === void 0 ? void 0 : original.autoAllocateChunkSize;
|
|
2876
|
+
const cancel = original === null || original === void 0 ? void 0 : original.cancel;
|
|
2877
|
+
const pull = original === null || original === void 0 ? void 0 : original.pull;
|
|
2878
|
+
const start = original === null || original === void 0 ? void 0 : original.start;
|
|
2879
|
+
const type = original === null || original === void 0 ? void 0 : original.type;
|
|
2880
|
+
return {
|
|
2881
|
+
autoAllocateChunkSize: autoAllocateChunkSize === void 0 ? void 0 : convertUnsignedLongLongWithEnforceRange(autoAllocateChunkSize, `${context} has member 'autoAllocateChunkSize' that`),
|
|
2882
|
+
cancel: cancel === void 0 ? void 0 : convertUnderlyingSourceCancelCallback(cancel, original, `${context} has member 'cancel' that`),
|
|
2883
|
+
pull: pull === void 0 ? void 0 : convertUnderlyingSourcePullCallback(pull, original, `${context} has member 'pull' that`),
|
|
2884
|
+
start: start === void 0 ? void 0 : convertUnderlyingSourceStartCallback(start, original, `${context} has member 'start' that`),
|
|
2885
|
+
type: type === void 0 ? void 0 : convertReadableStreamType(type, `${context} has member 'type' that`)
|
|
2886
|
+
};
|
|
2887
|
+
}
|
|
2888
|
+
function convertUnderlyingSourceCancelCallback(fn, original, context) {
|
|
2889
|
+
assertFunction(fn, context);
|
|
2890
|
+
return (reason) => promiseCall(fn, original, [reason]);
|
|
2891
|
+
}
|
|
2892
|
+
function convertUnderlyingSourcePullCallback(fn, original, context) {
|
|
2893
|
+
assertFunction(fn, context);
|
|
2894
|
+
return (controller) => promiseCall(fn, original, [controller]);
|
|
2895
|
+
}
|
|
2896
|
+
function convertUnderlyingSourceStartCallback(fn, original, context) {
|
|
2897
|
+
assertFunction(fn, context);
|
|
2898
|
+
return (controller) => reflectCall(fn, original, [controller]);
|
|
2899
|
+
}
|
|
2900
|
+
function convertReadableStreamType(type, context) {
|
|
2901
|
+
type = `${type}`;
|
|
2902
|
+
if (type !== "bytes") {
|
|
2903
|
+
throw new TypeError(`${context} '${type}' is not a valid enumeration value for ReadableStreamType`);
|
|
2904
|
+
}
|
|
2905
|
+
return type;
|
|
2906
|
+
}
|
|
2907
|
+
function convertReaderOptions(options, context) {
|
|
2908
|
+
assertDictionary(options, context);
|
|
2909
|
+
const mode = options === null || options === void 0 ? void 0 : options.mode;
|
|
2910
|
+
return {
|
|
2911
|
+
mode: mode === void 0 ? void 0 : convertReadableStreamReaderMode(mode, `${context} has member 'mode' that`)
|
|
2912
|
+
};
|
|
2913
|
+
}
|
|
2914
|
+
function convertReadableStreamReaderMode(mode, context) {
|
|
2915
|
+
mode = `${mode}`;
|
|
2916
|
+
if (mode !== "byob") {
|
|
2917
|
+
throw new TypeError(`${context} '${mode}' is not a valid enumeration value for ReadableStreamReaderMode`);
|
|
2918
|
+
}
|
|
2919
|
+
return mode;
|
|
2920
|
+
}
|
|
2921
|
+
function convertIteratorOptions(options, context) {
|
|
2922
|
+
assertDictionary(options, context);
|
|
2923
|
+
const preventCancel = options === null || options === void 0 ? void 0 : options.preventCancel;
|
|
2924
|
+
return { preventCancel: Boolean(preventCancel) };
|
|
2925
|
+
}
|
|
2926
|
+
function convertPipeOptions(options, context) {
|
|
2927
|
+
assertDictionary(options, context);
|
|
2928
|
+
const preventAbort = options === null || options === void 0 ? void 0 : options.preventAbort;
|
|
2929
|
+
const preventCancel = options === null || options === void 0 ? void 0 : options.preventCancel;
|
|
2930
|
+
const preventClose = options === null || options === void 0 ? void 0 : options.preventClose;
|
|
2931
|
+
const signal = options === null || options === void 0 ? void 0 : options.signal;
|
|
2932
|
+
if (signal !== void 0) {
|
|
2933
|
+
assertAbortSignal(signal, `${context} has member 'signal' that`);
|
|
2934
|
+
}
|
|
2935
|
+
return {
|
|
2936
|
+
preventAbort: Boolean(preventAbort),
|
|
2937
|
+
preventCancel: Boolean(preventCancel),
|
|
2938
|
+
preventClose: Boolean(preventClose),
|
|
2939
|
+
signal
|
|
2940
|
+
};
|
|
2941
|
+
}
|
|
2942
|
+
function assertAbortSignal(signal, context) {
|
|
2943
|
+
if (!isAbortSignal(signal)) {
|
|
2944
|
+
throw new TypeError(`${context} is not an AbortSignal.`);
|
|
2945
|
+
}
|
|
2946
|
+
}
|
|
2947
|
+
function convertReadableWritablePair(pair, context) {
|
|
2948
|
+
assertDictionary(pair, context);
|
|
2949
|
+
const readable = pair === null || pair === void 0 ? void 0 : pair.readable;
|
|
2950
|
+
assertRequiredField(readable, "readable", "ReadableWritablePair");
|
|
2951
|
+
assertReadableStream(readable, `${context} has member 'readable' that`);
|
|
2952
|
+
const writable = pair === null || pair === void 0 ? void 0 : pair.writable;
|
|
2953
|
+
assertRequiredField(writable, "writable", "ReadableWritablePair");
|
|
2954
|
+
assertWritableStream(writable, `${context} has member 'writable' that`);
|
|
2955
|
+
return { readable, writable };
|
|
2956
|
+
}
|
|
2957
|
+
class ReadableStream {
|
|
2958
|
+
constructor(rawUnderlyingSource = {}, rawStrategy = {}) {
|
|
2959
|
+
if (rawUnderlyingSource === void 0) {
|
|
2960
|
+
rawUnderlyingSource = null;
|
|
2961
|
+
} else {
|
|
2962
|
+
assertObject(rawUnderlyingSource, "First parameter");
|
|
2963
|
+
}
|
|
2964
|
+
const strategy = convertQueuingStrategy(rawStrategy, "Second parameter");
|
|
2965
|
+
const underlyingSource = convertUnderlyingDefaultOrByteSource(rawUnderlyingSource, "First parameter");
|
|
2966
|
+
InitializeReadableStream(this);
|
|
2967
|
+
if (underlyingSource.type === "bytes") {
|
|
2968
|
+
if (strategy.size !== void 0) {
|
|
2969
|
+
throw new RangeError("The strategy for a byte stream cannot have a size function");
|
|
2970
|
+
}
|
|
2971
|
+
const highWaterMark = ExtractHighWaterMark(strategy, 0);
|
|
2972
|
+
SetUpReadableByteStreamControllerFromUnderlyingSource(this, underlyingSource, highWaterMark);
|
|
2973
|
+
} else {
|
|
2974
|
+
const sizeAlgorithm = ExtractSizeAlgorithm(strategy);
|
|
2975
|
+
const highWaterMark = ExtractHighWaterMark(strategy, 1);
|
|
2976
|
+
SetUpReadableStreamDefaultControllerFromUnderlyingSource(this, underlyingSource, highWaterMark, sizeAlgorithm);
|
|
2977
|
+
}
|
|
2978
|
+
}
|
|
2979
|
+
get locked() {
|
|
2980
|
+
if (!IsReadableStream(this)) {
|
|
2981
|
+
throw streamBrandCheckException$1("locked");
|
|
2982
|
+
}
|
|
2983
|
+
return IsReadableStreamLocked(this);
|
|
2984
|
+
}
|
|
2985
|
+
cancel(reason = void 0) {
|
|
2986
|
+
if (!IsReadableStream(this)) {
|
|
2987
|
+
return promiseRejectedWith(streamBrandCheckException$1("cancel"));
|
|
2988
|
+
}
|
|
2989
|
+
if (IsReadableStreamLocked(this)) {
|
|
2990
|
+
return promiseRejectedWith(new TypeError("Cannot cancel a stream that already has a reader"));
|
|
2991
|
+
}
|
|
2992
|
+
return ReadableStreamCancel(this, reason);
|
|
2993
|
+
}
|
|
2994
|
+
getReader(rawOptions = void 0) {
|
|
2995
|
+
if (!IsReadableStream(this)) {
|
|
2996
|
+
throw streamBrandCheckException$1("getReader");
|
|
2997
|
+
}
|
|
2998
|
+
const options = convertReaderOptions(rawOptions, "First parameter");
|
|
2999
|
+
if (options.mode === void 0) {
|
|
3000
|
+
return AcquireReadableStreamDefaultReader(this);
|
|
3001
|
+
}
|
|
3002
|
+
return AcquireReadableStreamBYOBReader(this);
|
|
3003
|
+
}
|
|
3004
|
+
pipeThrough(rawTransform, rawOptions = {}) {
|
|
3005
|
+
if (!IsReadableStream(this)) {
|
|
3006
|
+
throw streamBrandCheckException$1("pipeThrough");
|
|
3007
|
+
}
|
|
3008
|
+
assertRequiredArgument(rawTransform, 1, "pipeThrough");
|
|
3009
|
+
const transform = convertReadableWritablePair(rawTransform, "First parameter");
|
|
3010
|
+
const options = convertPipeOptions(rawOptions, "Second parameter");
|
|
3011
|
+
if (IsReadableStreamLocked(this)) {
|
|
3012
|
+
throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked ReadableStream");
|
|
3013
|
+
}
|
|
3014
|
+
if (IsWritableStreamLocked(transform.writable)) {
|
|
3015
|
+
throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked WritableStream");
|
|
3016
|
+
}
|
|
3017
|
+
const promise = ReadableStreamPipeTo(this, transform.writable, options.preventClose, options.preventAbort, options.preventCancel, options.signal);
|
|
3018
|
+
setPromiseIsHandledToTrue(promise);
|
|
3019
|
+
return transform.readable;
|
|
3020
|
+
}
|
|
3021
|
+
pipeTo(destination, rawOptions = {}) {
|
|
3022
|
+
if (!IsReadableStream(this)) {
|
|
3023
|
+
return promiseRejectedWith(streamBrandCheckException$1("pipeTo"));
|
|
3024
|
+
}
|
|
3025
|
+
if (destination === void 0) {
|
|
3026
|
+
return promiseRejectedWith(`Parameter 1 is required in 'pipeTo'.`);
|
|
3027
|
+
}
|
|
3028
|
+
if (!IsWritableStream(destination)) {
|
|
3029
|
+
return promiseRejectedWith(new TypeError(`ReadableStream.prototype.pipeTo's first argument must be a WritableStream`));
|
|
3030
|
+
}
|
|
3031
|
+
let options;
|
|
3032
|
+
try {
|
|
3033
|
+
options = convertPipeOptions(rawOptions, "Second parameter");
|
|
3034
|
+
} catch (e) {
|
|
3035
|
+
return promiseRejectedWith(e);
|
|
3036
|
+
}
|
|
3037
|
+
if (IsReadableStreamLocked(this)) {
|
|
3038
|
+
return promiseRejectedWith(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream"));
|
|
3039
|
+
}
|
|
3040
|
+
if (IsWritableStreamLocked(destination)) {
|
|
3041
|
+
return promiseRejectedWith(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream"));
|
|
3042
|
+
}
|
|
3043
|
+
return ReadableStreamPipeTo(this, destination, options.preventClose, options.preventAbort, options.preventCancel, options.signal);
|
|
3044
|
+
}
|
|
3045
|
+
tee() {
|
|
3046
|
+
if (!IsReadableStream(this)) {
|
|
3047
|
+
throw streamBrandCheckException$1("tee");
|
|
3048
|
+
}
|
|
3049
|
+
const branches = ReadableStreamTee(this);
|
|
3050
|
+
return CreateArrayFromList(branches);
|
|
3051
|
+
}
|
|
3052
|
+
values(rawOptions = void 0) {
|
|
3053
|
+
if (!IsReadableStream(this)) {
|
|
3054
|
+
throw streamBrandCheckException$1("values");
|
|
3055
|
+
}
|
|
3056
|
+
const options = convertIteratorOptions(rawOptions, "First parameter");
|
|
3057
|
+
return AcquireReadableStreamAsyncIterator(this, options.preventCancel);
|
|
3058
|
+
}
|
|
3059
|
+
}
|
|
3060
|
+
Object.defineProperties(ReadableStream.prototype, {
|
|
3061
|
+
cancel: { enumerable: true },
|
|
3062
|
+
getReader: { enumerable: true },
|
|
3063
|
+
pipeThrough: { enumerable: true },
|
|
3064
|
+
pipeTo: { enumerable: true },
|
|
3065
|
+
tee: { enumerable: true },
|
|
3066
|
+
values: { enumerable: true },
|
|
3067
|
+
locked: { enumerable: true }
|
|
3068
|
+
});
|
|
3069
|
+
if (typeof SymbolPolyfill.toStringTag === "symbol") {
|
|
3070
|
+
Object.defineProperty(ReadableStream.prototype, SymbolPolyfill.toStringTag, {
|
|
3071
|
+
value: "ReadableStream",
|
|
3072
|
+
configurable: true
|
|
3073
|
+
});
|
|
3074
|
+
}
|
|
3075
|
+
if (typeof SymbolPolyfill.asyncIterator === "symbol") {
|
|
3076
|
+
Object.defineProperty(ReadableStream.prototype, SymbolPolyfill.asyncIterator, {
|
|
3077
|
+
value: ReadableStream.prototype.values,
|
|
3078
|
+
writable: true,
|
|
3079
|
+
configurable: true
|
|
3080
|
+
});
|
|
3081
|
+
}
|
|
3082
|
+
function CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark = 1, sizeAlgorithm = () => 1) {
|
|
3083
|
+
const stream = Object.create(ReadableStream.prototype);
|
|
3084
|
+
InitializeReadableStream(stream);
|
|
3085
|
+
const controller = Object.create(ReadableStreamDefaultController.prototype);
|
|
3086
|
+
SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm);
|
|
3087
|
+
return stream;
|
|
3088
|
+
}
|
|
3089
|
+
function CreateReadableByteStream(startAlgorithm, pullAlgorithm, cancelAlgorithm) {
|
|
3090
|
+
const stream = Object.create(ReadableStream.prototype);
|
|
3091
|
+
InitializeReadableStream(stream);
|
|
3092
|
+
const controller = Object.create(ReadableByteStreamController.prototype);
|
|
3093
|
+
SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, 0, void 0);
|
|
3094
|
+
return stream;
|
|
3095
|
+
}
|
|
3096
|
+
function InitializeReadableStream(stream) {
|
|
3097
|
+
stream._state = "readable";
|
|
3098
|
+
stream._reader = void 0;
|
|
3099
|
+
stream._storedError = void 0;
|
|
3100
|
+
stream._disturbed = false;
|
|
3101
|
+
}
|
|
3102
|
+
function IsReadableStream(x) {
|
|
3103
|
+
if (!typeIsObject(x)) {
|
|
3104
|
+
return false;
|
|
3105
|
+
}
|
|
3106
|
+
if (!Object.prototype.hasOwnProperty.call(x, "_readableStreamController")) {
|
|
3107
|
+
return false;
|
|
3108
|
+
}
|
|
3109
|
+
return x instanceof ReadableStream;
|
|
3110
|
+
}
|
|
3111
|
+
function IsReadableStreamLocked(stream) {
|
|
3112
|
+
if (stream._reader === void 0) {
|
|
3113
|
+
return false;
|
|
3114
|
+
}
|
|
3115
|
+
return true;
|
|
3116
|
+
}
|
|
3117
|
+
function ReadableStreamCancel(stream, reason) {
|
|
3118
|
+
stream._disturbed = true;
|
|
3119
|
+
if (stream._state === "closed") {
|
|
3120
|
+
return promiseResolvedWith(void 0);
|
|
3121
|
+
}
|
|
3122
|
+
if (stream._state === "errored") {
|
|
3123
|
+
return promiseRejectedWith(stream._storedError);
|
|
3124
|
+
}
|
|
3125
|
+
ReadableStreamClose(stream);
|
|
3126
|
+
const reader = stream._reader;
|
|
3127
|
+
if (reader !== void 0 && IsReadableStreamBYOBReader(reader)) {
|
|
3128
|
+
reader._readIntoRequests.forEach((readIntoRequest) => {
|
|
3129
|
+
readIntoRequest._closeSteps(void 0);
|
|
3130
|
+
});
|
|
3131
|
+
reader._readIntoRequests = new SimpleQueue();
|
|
3132
|
+
}
|
|
3133
|
+
const sourceCancelPromise = stream._readableStreamController[CancelSteps](reason);
|
|
3134
|
+
return transformPromiseWith(sourceCancelPromise, noop);
|
|
3135
|
+
}
|
|
3136
|
+
function ReadableStreamClose(stream) {
|
|
3137
|
+
stream._state = "closed";
|
|
3138
|
+
const reader = stream._reader;
|
|
3139
|
+
if (reader === void 0) {
|
|
3140
|
+
return;
|
|
3141
|
+
}
|
|
3142
|
+
defaultReaderClosedPromiseResolve(reader);
|
|
3143
|
+
if (IsReadableStreamDefaultReader(reader)) {
|
|
3144
|
+
reader._readRequests.forEach((readRequest) => {
|
|
3145
|
+
readRequest._closeSteps();
|
|
3146
|
+
});
|
|
3147
|
+
reader._readRequests = new SimpleQueue();
|
|
3148
|
+
}
|
|
3149
|
+
}
|
|
3150
|
+
function ReadableStreamError(stream, e) {
|
|
3151
|
+
stream._state = "errored";
|
|
3152
|
+
stream._storedError = e;
|
|
3153
|
+
const reader = stream._reader;
|
|
3154
|
+
if (reader === void 0) {
|
|
3155
|
+
return;
|
|
3156
|
+
}
|
|
3157
|
+
defaultReaderClosedPromiseReject(reader, e);
|
|
3158
|
+
if (IsReadableStreamDefaultReader(reader)) {
|
|
3159
|
+
reader._readRequests.forEach((readRequest) => {
|
|
3160
|
+
readRequest._errorSteps(e);
|
|
3161
|
+
});
|
|
3162
|
+
reader._readRequests = new SimpleQueue();
|
|
3163
|
+
} else {
|
|
3164
|
+
reader._readIntoRequests.forEach((readIntoRequest) => {
|
|
3165
|
+
readIntoRequest._errorSteps(e);
|
|
3166
|
+
});
|
|
3167
|
+
reader._readIntoRequests = new SimpleQueue();
|
|
3168
|
+
}
|
|
3169
|
+
}
|
|
3170
|
+
function streamBrandCheckException$1(name) {
|
|
3171
|
+
return new TypeError(`ReadableStream.prototype.${name} can only be used on a ReadableStream`);
|
|
3172
|
+
}
|
|
3173
|
+
function convertQueuingStrategyInit(init, context) {
|
|
3174
|
+
assertDictionary(init, context);
|
|
3175
|
+
const highWaterMark = init === null || init === void 0 ? void 0 : init.highWaterMark;
|
|
3176
|
+
assertRequiredField(highWaterMark, "highWaterMark", "QueuingStrategyInit");
|
|
3177
|
+
return {
|
|
3178
|
+
highWaterMark: convertUnrestrictedDouble(highWaterMark)
|
|
3179
|
+
};
|
|
3180
|
+
}
|
|
3181
|
+
const byteLengthSizeFunction = (chunk) => {
|
|
3182
|
+
return chunk.byteLength;
|
|
3183
|
+
};
|
|
3184
|
+
try {
|
|
3185
|
+
Object.defineProperty(byteLengthSizeFunction, "name", {
|
|
3186
|
+
value: "size",
|
|
3187
|
+
configurable: true
|
|
3188
|
+
});
|
|
3189
|
+
} catch (_a) {
|
|
3190
|
+
}
|
|
3191
|
+
class ByteLengthQueuingStrategy {
|
|
3192
|
+
constructor(options) {
|
|
3193
|
+
assertRequiredArgument(options, 1, "ByteLengthQueuingStrategy");
|
|
3194
|
+
options = convertQueuingStrategyInit(options, "First parameter");
|
|
3195
|
+
this._byteLengthQueuingStrategyHighWaterMark = options.highWaterMark;
|
|
3196
|
+
}
|
|
3197
|
+
get highWaterMark() {
|
|
3198
|
+
if (!IsByteLengthQueuingStrategy(this)) {
|
|
3199
|
+
throw byteLengthBrandCheckException("highWaterMark");
|
|
3200
|
+
}
|
|
3201
|
+
return this._byteLengthQueuingStrategyHighWaterMark;
|
|
3202
|
+
}
|
|
3203
|
+
get size() {
|
|
3204
|
+
if (!IsByteLengthQueuingStrategy(this)) {
|
|
3205
|
+
throw byteLengthBrandCheckException("size");
|
|
3206
|
+
}
|
|
3207
|
+
return byteLengthSizeFunction;
|
|
3208
|
+
}
|
|
3209
|
+
}
|
|
3210
|
+
Object.defineProperties(ByteLengthQueuingStrategy.prototype, {
|
|
3211
|
+
highWaterMark: { enumerable: true },
|
|
3212
|
+
size: { enumerable: true }
|
|
3213
|
+
});
|
|
3214
|
+
if (typeof SymbolPolyfill.toStringTag === "symbol") {
|
|
3215
|
+
Object.defineProperty(ByteLengthQueuingStrategy.prototype, SymbolPolyfill.toStringTag, {
|
|
3216
|
+
value: "ByteLengthQueuingStrategy",
|
|
3217
|
+
configurable: true
|
|
3218
|
+
});
|
|
3219
|
+
}
|
|
3220
|
+
function byteLengthBrandCheckException(name) {
|
|
3221
|
+
return new TypeError(`ByteLengthQueuingStrategy.prototype.${name} can only be used on a ByteLengthQueuingStrategy`);
|
|
3222
|
+
}
|
|
3223
|
+
function IsByteLengthQueuingStrategy(x) {
|
|
3224
|
+
if (!typeIsObject(x)) {
|
|
3225
|
+
return false;
|
|
3226
|
+
}
|
|
3227
|
+
if (!Object.prototype.hasOwnProperty.call(x, "_byteLengthQueuingStrategyHighWaterMark")) {
|
|
3228
|
+
return false;
|
|
3229
|
+
}
|
|
3230
|
+
return x instanceof ByteLengthQueuingStrategy;
|
|
3231
|
+
}
|
|
3232
|
+
const countSizeFunction = () => {
|
|
3233
|
+
return 1;
|
|
3234
|
+
};
|
|
3235
|
+
try {
|
|
3236
|
+
Object.defineProperty(countSizeFunction, "name", {
|
|
3237
|
+
value: "size",
|
|
3238
|
+
configurable: true
|
|
3239
|
+
});
|
|
3240
|
+
} catch (_a) {
|
|
3241
|
+
}
|
|
3242
|
+
class CountQueuingStrategy {
|
|
3243
|
+
constructor(options) {
|
|
3244
|
+
assertRequiredArgument(options, 1, "CountQueuingStrategy");
|
|
3245
|
+
options = convertQueuingStrategyInit(options, "First parameter");
|
|
3246
|
+
this._countQueuingStrategyHighWaterMark = options.highWaterMark;
|
|
3247
|
+
}
|
|
3248
|
+
get highWaterMark() {
|
|
3249
|
+
if (!IsCountQueuingStrategy(this)) {
|
|
3250
|
+
throw countBrandCheckException("highWaterMark");
|
|
3251
|
+
}
|
|
3252
|
+
return this._countQueuingStrategyHighWaterMark;
|
|
3253
|
+
}
|
|
3254
|
+
get size() {
|
|
3255
|
+
if (!IsCountQueuingStrategy(this)) {
|
|
3256
|
+
throw countBrandCheckException("size");
|
|
3257
|
+
}
|
|
3258
|
+
return countSizeFunction;
|
|
3259
|
+
}
|
|
3260
|
+
}
|
|
3261
|
+
Object.defineProperties(CountQueuingStrategy.prototype, {
|
|
3262
|
+
highWaterMark: { enumerable: true },
|
|
3263
|
+
size: { enumerable: true }
|
|
3264
|
+
});
|
|
3265
|
+
if (typeof SymbolPolyfill.toStringTag === "symbol") {
|
|
3266
|
+
Object.defineProperty(CountQueuingStrategy.prototype, SymbolPolyfill.toStringTag, {
|
|
3267
|
+
value: "CountQueuingStrategy",
|
|
3268
|
+
configurable: true
|
|
3269
|
+
});
|
|
3270
|
+
}
|
|
3271
|
+
function countBrandCheckException(name) {
|
|
3272
|
+
return new TypeError(`CountQueuingStrategy.prototype.${name} can only be used on a CountQueuingStrategy`);
|
|
3273
|
+
}
|
|
3274
|
+
function IsCountQueuingStrategy(x) {
|
|
3275
|
+
if (!typeIsObject(x)) {
|
|
3276
|
+
return false;
|
|
3277
|
+
}
|
|
3278
|
+
if (!Object.prototype.hasOwnProperty.call(x, "_countQueuingStrategyHighWaterMark")) {
|
|
3279
|
+
return false;
|
|
3280
|
+
}
|
|
3281
|
+
return x instanceof CountQueuingStrategy;
|
|
3282
|
+
}
|
|
3283
|
+
function convertTransformer(original, context) {
|
|
3284
|
+
assertDictionary(original, context);
|
|
3285
|
+
const flush = original === null || original === void 0 ? void 0 : original.flush;
|
|
3286
|
+
const readableType = original === null || original === void 0 ? void 0 : original.readableType;
|
|
3287
|
+
const start = original === null || original === void 0 ? void 0 : original.start;
|
|
3288
|
+
const transform = original === null || original === void 0 ? void 0 : original.transform;
|
|
3289
|
+
const writableType = original === null || original === void 0 ? void 0 : original.writableType;
|
|
3290
|
+
return {
|
|
3291
|
+
flush: flush === void 0 ? void 0 : convertTransformerFlushCallback(flush, original, `${context} has member 'flush' that`),
|
|
3292
|
+
readableType,
|
|
3293
|
+
start: start === void 0 ? void 0 : convertTransformerStartCallback(start, original, `${context} has member 'start' that`),
|
|
3294
|
+
transform: transform === void 0 ? void 0 : convertTransformerTransformCallback(transform, original, `${context} has member 'transform' that`),
|
|
3295
|
+
writableType
|
|
3296
|
+
};
|
|
3297
|
+
}
|
|
3298
|
+
function convertTransformerFlushCallback(fn, original, context) {
|
|
3299
|
+
assertFunction(fn, context);
|
|
3300
|
+
return (controller) => promiseCall(fn, original, [controller]);
|
|
3301
|
+
}
|
|
3302
|
+
function convertTransformerStartCallback(fn, original, context) {
|
|
3303
|
+
assertFunction(fn, context);
|
|
3304
|
+
return (controller) => reflectCall(fn, original, [controller]);
|
|
3305
|
+
}
|
|
3306
|
+
function convertTransformerTransformCallback(fn, original, context) {
|
|
3307
|
+
assertFunction(fn, context);
|
|
3308
|
+
return (chunk, controller) => promiseCall(fn, original, [chunk, controller]);
|
|
3309
|
+
}
|
|
3310
|
+
class TransformStream {
|
|
3311
|
+
constructor(rawTransformer = {}, rawWritableStrategy = {}, rawReadableStrategy = {}) {
|
|
3312
|
+
if (rawTransformer === void 0) {
|
|
3313
|
+
rawTransformer = null;
|
|
3314
|
+
}
|
|
3315
|
+
const writableStrategy = convertQueuingStrategy(rawWritableStrategy, "Second parameter");
|
|
3316
|
+
const readableStrategy = convertQueuingStrategy(rawReadableStrategy, "Third parameter");
|
|
3317
|
+
const transformer = convertTransformer(rawTransformer, "First parameter");
|
|
3318
|
+
if (transformer.readableType !== void 0) {
|
|
3319
|
+
throw new RangeError("Invalid readableType specified");
|
|
3320
|
+
}
|
|
3321
|
+
if (transformer.writableType !== void 0) {
|
|
3322
|
+
throw new RangeError("Invalid writableType specified");
|
|
3323
|
+
}
|
|
3324
|
+
const readableHighWaterMark = ExtractHighWaterMark(readableStrategy, 0);
|
|
3325
|
+
const readableSizeAlgorithm = ExtractSizeAlgorithm(readableStrategy);
|
|
3326
|
+
const writableHighWaterMark = ExtractHighWaterMark(writableStrategy, 1);
|
|
3327
|
+
const writableSizeAlgorithm = ExtractSizeAlgorithm(writableStrategy);
|
|
3328
|
+
let startPromise_resolve;
|
|
3329
|
+
const startPromise = newPromise((resolve) => {
|
|
3330
|
+
startPromise_resolve = resolve;
|
|
3331
|
+
});
|
|
3332
|
+
InitializeTransformStream(this, startPromise, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, readableSizeAlgorithm);
|
|
3333
|
+
SetUpTransformStreamDefaultControllerFromTransformer(this, transformer);
|
|
3334
|
+
if (transformer.start !== void 0) {
|
|
3335
|
+
startPromise_resolve(transformer.start(this._transformStreamController));
|
|
3336
|
+
} else {
|
|
3337
|
+
startPromise_resolve(void 0);
|
|
3338
|
+
}
|
|
3339
|
+
}
|
|
3340
|
+
get readable() {
|
|
3341
|
+
if (!IsTransformStream(this)) {
|
|
3342
|
+
throw streamBrandCheckException("readable");
|
|
3343
|
+
}
|
|
3344
|
+
return this._readable;
|
|
3345
|
+
}
|
|
3346
|
+
get writable() {
|
|
3347
|
+
if (!IsTransformStream(this)) {
|
|
3348
|
+
throw streamBrandCheckException("writable");
|
|
3349
|
+
}
|
|
3350
|
+
return this._writable;
|
|
3351
|
+
}
|
|
3352
|
+
}
|
|
3353
|
+
Object.defineProperties(TransformStream.prototype, {
|
|
3354
|
+
readable: { enumerable: true },
|
|
3355
|
+
writable: { enumerable: true }
|
|
3356
|
+
});
|
|
3357
|
+
if (typeof SymbolPolyfill.toStringTag === "symbol") {
|
|
3358
|
+
Object.defineProperty(TransformStream.prototype, SymbolPolyfill.toStringTag, {
|
|
3359
|
+
value: "TransformStream",
|
|
3360
|
+
configurable: true
|
|
3361
|
+
});
|
|
3362
|
+
}
|
|
3363
|
+
function InitializeTransformStream(stream, startPromise, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, readableSizeAlgorithm) {
|
|
3364
|
+
function startAlgorithm() {
|
|
3365
|
+
return startPromise;
|
|
3366
|
+
}
|
|
3367
|
+
function writeAlgorithm(chunk) {
|
|
3368
|
+
return TransformStreamDefaultSinkWriteAlgorithm(stream, chunk);
|
|
3369
|
+
}
|
|
3370
|
+
function abortAlgorithm(reason) {
|
|
3371
|
+
return TransformStreamDefaultSinkAbortAlgorithm(stream, reason);
|
|
3372
|
+
}
|
|
3373
|
+
function closeAlgorithm() {
|
|
3374
|
+
return TransformStreamDefaultSinkCloseAlgorithm(stream);
|
|
3375
|
+
}
|
|
3376
|
+
stream._writable = CreateWritableStream(startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, writableHighWaterMark, writableSizeAlgorithm);
|
|
3377
|
+
function pullAlgorithm() {
|
|
3378
|
+
return TransformStreamDefaultSourcePullAlgorithm(stream);
|
|
3379
|
+
}
|
|
3380
|
+
function cancelAlgorithm(reason) {
|
|
3381
|
+
TransformStreamErrorWritableAndUnblockWrite(stream, reason);
|
|
3382
|
+
return promiseResolvedWith(void 0);
|
|
3383
|
+
}
|
|
3384
|
+
stream._readable = CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, readableHighWaterMark, readableSizeAlgorithm);
|
|
3385
|
+
stream._backpressure = void 0;
|
|
3386
|
+
stream._backpressureChangePromise = void 0;
|
|
3387
|
+
stream._backpressureChangePromise_resolve = void 0;
|
|
3388
|
+
TransformStreamSetBackpressure(stream, true);
|
|
3389
|
+
stream._transformStreamController = void 0;
|
|
3390
|
+
}
|
|
3391
|
+
function IsTransformStream(x) {
|
|
3392
|
+
if (!typeIsObject(x)) {
|
|
3393
|
+
return false;
|
|
3394
|
+
}
|
|
3395
|
+
if (!Object.prototype.hasOwnProperty.call(x, "_transformStreamController")) {
|
|
3396
|
+
return false;
|
|
3397
|
+
}
|
|
3398
|
+
return x instanceof TransformStream;
|
|
3399
|
+
}
|
|
3400
|
+
function TransformStreamError(stream, e) {
|
|
3401
|
+
ReadableStreamDefaultControllerError(stream._readable._readableStreamController, e);
|
|
3402
|
+
TransformStreamErrorWritableAndUnblockWrite(stream, e);
|
|
3403
|
+
}
|
|
3404
|
+
function TransformStreamErrorWritableAndUnblockWrite(stream, e) {
|
|
3405
|
+
TransformStreamDefaultControllerClearAlgorithms(stream._transformStreamController);
|
|
3406
|
+
WritableStreamDefaultControllerErrorIfNeeded(stream._writable._writableStreamController, e);
|
|
3407
|
+
if (stream._backpressure) {
|
|
3408
|
+
TransformStreamSetBackpressure(stream, false);
|
|
3409
|
+
}
|
|
3410
|
+
}
|
|
3411
|
+
function TransformStreamSetBackpressure(stream, backpressure) {
|
|
3412
|
+
if (stream._backpressureChangePromise !== void 0) {
|
|
3413
|
+
stream._backpressureChangePromise_resolve();
|
|
3414
|
+
}
|
|
3415
|
+
stream._backpressureChangePromise = newPromise((resolve) => {
|
|
3416
|
+
stream._backpressureChangePromise_resolve = resolve;
|
|
3417
|
+
});
|
|
3418
|
+
stream._backpressure = backpressure;
|
|
3419
|
+
}
|
|
3420
|
+
class TransformStreamDefaultController {
|
|
3421
|
+
constructor() {
|
|
3422
|
+
throw new TypeError("Illegal constructor");
|
|
3423
|
+
}
|
|
3424
|
+
get desiredSize() {
|
|
3425
|
+
if (!IsTransformStreamDefaultController(this)) {
|
|
3426
|
+
throw defaultControllerBrandCheckException("desiredSize");
|
|
3427
|
+
}
|
|
3428
|
+
const readableController = this._controlledTransformStream._readable._readableStreamController;
|
|
3429
|
+
return ReadableStreamDefaultControllerGetDesiredSize(readableController);
|
|
3430
|
+
}
|
|
3431
|
+
enqueue(chunk = void 0) {
|
|
3432
|
+
if (!IsTransformStreamDefaultController(this)) {
|
|
3433
|
+
throw defaultControllerBrandCheckException("enqueue");
|
|
3434
|
+
}
|
|
3435
|
+
TransformStreamDefaultControllerEnqueue(this, chunk);
|
|
3436
|
+
}
|
|
3437
|
+
error(reason = void 0) {
|
|
3438
|
+
if (!IsTransformStreamDefaultController(this)) {
|
|
3439
|
+
throw defaultControllerBrandCheckException("error");
|
|
3440
|
+
}
|
|
3441
|
+
TransformStreamDefaultControllerError(this, reason);
|
|
3442
|
+
}
|
|
3443
|
+
terminate() {
|
|
3444
|
+
if (!IsTransformStreamDefaultController(this)) {
|
|
3445
|
+
throw defaultControllerBrandCheckException("terminate");
|
|
3446
|
+
}
|
|
3447
|
+
TransformStreamDefaultControllerTerminate(this);
|
|
3448
|
+
}
|
|
3449
|
+
}
|
|
3450
|
+
Object.defineProperties(TransformStreamDefaultController.prototype, {
|
|
3451
|
+
enqueue: { enumerable: true },
|
|
3452
|
+
error: { enumerable: true },
|
|
3453
|
+
terminate: { enumerable: true },
|
|
3454
|
+
desiredSize: { enumerable: true }
|
|
3455
|
+
});
|
|
3456
|
+
if (typeof SymbolPolyfill.toStringTag === "symbol") {
|
|
3457
|
+
Object.defineProperty(TransformStreamDefaultController.prototype, SymbolPolyfill.toStringTag, {
|
|
3458
|
+
value: "TransformStreamDefaultController",
|
|
3459
|
+
configurable: true
|
|
3460
|
+
});
|
|
3461
|
+
}
|
|
3462
|
+
function IsTransformStreamDefaultController(x) {
|
|
3463
|
+
if (!typeIsObject(x)) {
|
|
3464
|
+
return false;
|
|
3465
|
+
}
|
|
3466
|
+
if (!Object.prototype.hasOwnProperty.call(x, "_controlledTransformStream")) {
|
|
3467
|
+
return false;
|
|
3468
|
+
}
|
|
3469
|
+
return x instanceof TransformStreamDefaultController;
|
|
3470
|
+
}
|
|
3471
|
+
function SetUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm) {
|
|
3472
|
+
controller._controlledTransformStream = stream;
|
|
3473
|
+
stream._transformStreamController = controller;
|
|
3474
|
+
controller._transformAlgorithm = transformAlgorithm;
|
|
3475
|
+
controller._flushAlgorithm = flushAlgorithm;
|
|
3476
|
+
}
|
|
3477
|
+
function SetUpTransformStreamDefaultControllerFromTransformer(stream, transformer) {
|
|
3478
|
+
const controller = Object.create(TransformStreamDefaultController.prototype);
|
|
3479
|
+
let transformAlgorithm = (chunk) => {
|
|
3480
|
+
try {
|
|
3481
|
+
TransformStreamDefaultControllerEnqueue(controller, chunk);
|
|
3482
|
+
return promiseResolvedWith(void 0);
|
|
3483
|
+
} catch (transformResultE) {
|
|
3484
|
+
return promiseRejectedWith(transformResultE);
|
|
3485
|
+
}
|
|
3486
|
+
};
|
|
3487
|
+
let flushAlgorithm = () => promiseResolvedWith(void 0);
|
|
3488
|
+
if (transformer.transform !== void 0) {
|
|
3489
|
+
transformAlgorithm = (chunk) => transformer.transform(chunk, controller);
|
|
3490
|
+
}
|
|
3491
|
+
if (transformer.flush !== void 0) {
|
|
3492
|
+
flushAlgorithm = () => transformer.flush(controller);
|
|
3493
|
+
}
|
|
3494
|
+
SetUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm);
|
|
3495
|
+
}
|
|
3496
|
+
function TransformStreamDefaultControllerClearAlgorithms(controller) {
|
|
3497
|
+
controller._transformAlgorithm = void 0;
|
|
3498
|
+
controller._flushAlgorithm = void 0;
|
|
3499
|
+
}
|
|
3500
|
+
function TransformStreamDefaultControllerEnqueue(controller, chunk) {
|
|
3501
|
+
const stream = controller._controlledTransformStream;
|
|
3502
|
+
const readableController = stream._readable._readableStreamController;
|
|
3503
|
+
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(readableController)) {
|
|
3504
|
+
throw new TypeError("Readable side is not in a state that permits enqueue");
|
|
3505
|
+
}
|
|
3506
|
+
try {
|
|
3507
|
+
ReadableStreamDefaultControllerEnqueue(readableController, chunk);
|
|
3508
|
+
} catch (e) {
|
|
3509
|
+
TransformStreamErrorWritableAndUnblockWrite(stream, e);
|
|
3510
|
+
throw stream._readable._storedError;
|
|
3511
|
+
}
|
|
3512
|
+
const backpressure = ReadableStreamDefaultControllerHasBackpressure(readableController);
|
|
3513
|
+
if (backpressure !== stream._backpressure) {
|
|
3514
|
+
TransformStreamSetBackpressure(stream, true);
|
|
3515
|
+
}
|
|
3516
|
+
}
|
|
3517
|
+
function TransformStreamDefaultControllerError(controller, e) {
|
|
3518
|
+
TransformStreamError(controller._controlledTransformStream, e);
|
|
3519
|
+
}
|
|
3520
|
+
function TransformStreamDefaultControllerPerformTransform(controller, chunk) {
|
|
3521
|
+
const transformPromise = controller._transformAlgorithm(chunk);
|
|
3522
|
+
return transformPromiseWith(transformPromise, void 0, (r) => {
|
|
3523
|
+
TransformStreamError(controller._controlledTransformStream, r);
|
|
3524
|
+
throw r;
|
|
3525
|
+
});
|
|
3526
|
+
}
|
|
3527
|
+
function TransformStreamDefaultControllerTerminate(controller) {
|
|
3528
|
+
const stream = controller._controlledTransformStream;
|
|
3529
|
+
const readableController = stream._readable._readableStreamController;
|
|
3530
|
+
ReadableStreamDefaultControllerClose(readableController);
|
|
3531
|
+
const error = new TypeError("TransformStream terminated");
|
|
3532
|
+
TransformStreamErrorWritableAndUnblockWrite(stream, error);
|
|
3533
|
+
}
|
|
3534
|
+
function TransformStreamDefaultSinkWriteAlgorithm(stream, chunk) {
|
|
3535
|
+
const controller = stream._transformStreamController;
|
|
3536
|
+
if (stream._backpressure) {
|
|
3537
|
+
const backpressureChangePromise = stream._backpressureChangePromise;
|
|
3538
|
+
return transformPromiseWith(backpressureChangePromise, () => {
|
|
3539
|
+
const writable = stream._writable;
|
|
3540
|
+
const state = writable._state;
|
|
3541
|
+
if (state === "erroring") {
|
|
3542
|
+
throw writable._storedError;
|
|
3543
|
+
}
|
|
3544
|
+
return TransformStreamDefaultControllerPerformTransform(controller, chunk);
|
|
3545
|
+
});
|
|
3546
|
+
}
|
|
3547
|
+
return TransformStreamDefaultControllerPerformTransform(controller, chunk);
|
|
3548
|
+
}
|
|
3549
|
+
function TransformStreamDefaultSinkAbortAlgorithm(stream, reason) {
|
|
3550
|
+
TransformStreamError(stream, reason);
|
|
3551
|
+
return promiseResolvedWith(void 0);
|
|
3552
|
+
}
|
|
3553
|
+
function TransformStreamDefaultSinkCloseAlgorithm(stream) {
|
|
3554
|
+
const readable = stream._readable;
|
|
3555
|
+
const controller = stream._transformStreamController;
|
|
3556
|
+
const flushPromise = controller._flushAlgorithm();
|
|
3557
|
+
TransformStreamDefaultControllerClearAlgorithms(controller);
|
|
3558
|
+
return transformPromiseWith(flushPromise, () => {
|
|
3559
|
+
if (readable._state === "errored") {
|
|
3560
|
+
throw readable._storedError;
|
|
3561
|
+
}
|
|
3562
|
+
ReadableStreamDefaultControllerClose(readable._readableStreamController);
|
|
3563
|
+
}, (r) => {
|
|
3564
|
+
TransformStreamError(stream, r);
|
|
3565
|
+
throw readable._storedError;
|
|
3566
|
+
});
|
|
3567
|
+
}
|
|
3568
|
+
function TransformStreamDefaultSourcePullAlgorithm(stream) {
|
|
3569
|
+
TransformStreamSetBackpressure(stream, false);
|
|
3570
|
+
return stream._backpressureChangePromise;
|
|
3571
|
+
}
|
|
3572
|
+
function defaultControllerBrandCheckException(name) {
|
|
3573
|
+
return new TypeError(`TransformStreamDefaultController.prototype.${name} can only be used on a TransformStreamDefaultController`);
|
|
3574
|
+
}
|
|
3575
|
+
function streamBrandCheckException(name) {
|
|
3576
|
+
return new TypeError(`TransformStream.prototype.${name} can only be used on a TransformStream`);
|
|
3577
|
+
}
|
|
3578
|
+
exports2.ByteLengthQueuingStrategy = ByteLengthQueuingStrategy;
|
|
3579
|
+
exports2.CountQueuingStrategy = CountQueuingStrategy;
|
|
3580
|
+
exports2.ReadableByteStreamController = ReadableByteStreamController;
|
|
3581
|
+
exports2.ReadableStream = ReadableStream;
|
|
3582
|
+
exports2.ReadableStreamBYOBReader = ReadableStreamBYOBReader;
|
|
3583
|
+
exports2.ReadableStreamBYOBRequest = ReadableStreamBYOBRequest;
|
|
3584
|
+
exports2.ReadableStreamDefaultController = ReadableStreamDefaultController;
|
|
3585
|
+
exports2.ReadableStreamDefaultReader = ReadableStreamDefaultReader;
|
|
3586
|
+
exports2.TransformStream = TransformStream;
|
|
3587
|
+
exports2.TransformStreamDefaultController = TransformStreamDefaultController;
|
|
3588
|
+
exports2.WritableStream = WritableStream;
|
|
3589
|
+
exports2.WritableStreamDefaultController = WritableStreamDefaultController;
|
|
3590
|
+
exports2.WritableStreamDefaultWriter = WritableStreamDefaultWriter;
|
|
3591
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3592
|
+
});
|
|
3593
|
+
})(ponyfill_es2018, ponyfill_es2018.exports);
|
|
3594
|
+
return ponyfill_es2018.exports;
|
|
3595
|
+
}
|
|
3596
|
+
export {
|
|
3597
|
+
requirePonyfill_es2018 as __require
|
|
3598
|
+
};
|
|
3599
|
+
//# sourceMappingURL=ponyfill.es2018.js.map
|