cloudcommerce 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/ecomplus-stores/monocard/functions/ssr/package.json +0 -2
- package/ecomplus-stores/tia-sonia/functions/ssr/package.json +0 -2
- package/package.json +6 -6
- package/packages/api/package.json +1 -1
- package/packages/apps/correios/package.json +2 -2
- package/packages/apps/custom-payment/package.json +1 -1
- package/packages/apps/custom-shipping/package.json +1 -1
- package/packages/apps/datafrete/package.json +2 -2
- package/packages/apps/discounts/package.json +1 -1
- package/packages/apps/emails/package.json +1 -1
- package/packages/apps/fb-conversions/package.json +1 -1
- package/packages/apps/frenet/package.json +2 -2
- package/packages/apps/galaxpay/package.json +2 -2
- package/packages/apps/google-analytics/package.json +2 -2
- package/packages/apps/infinitepay/package.json +2 -2
- package/packages/apps/jadlog/package.json +2 -2
- package/packages/apps/loyalty-points/package.json +1 -1
- package/packages/apps/melhor-envio/CHANGELOG.md +1 -0
- package/packages/apps/melhor-envio/README.md +1 -0
- package/packages/apps/melhor-envio/events.js +1 -0
- package/packages/apps/melhor-envio/lib/functions-lib/database.d.ts +18 -0
- package/packages/apps/melhor-envio/lib/functions-lib/database.js +115 -0
- package/packages/apps/melhor-envio/lib/functions-lib/database.js.map +1 -0
- package/packages/apps/melhor-envio/lib/functions-lib/events-to-melhor-envio.d.ts +7 -0
- package/packages/apps/melhor-envio/lib/functions-lib/events-to-melhor-envio.js +112 -0
- package/packages/apps/melhor-envio/lib/functions-lib/events-to-melhor-envio.js.map +1 -0
- package/packages/apps/melhor-envio/lib/functions-lib/new-label.d.ts +42 -0
- package/packages/apps/melhor-envio/lib/functions-lib/new-label.js +185 -0
- package/packages/apps/melhor-envio/lib/functions-lib/new-label.js.map +1 -0
- package/packages/apps/melhor-envio/lib/functions-lib/order-is-valid.d.ts +5 -0
- package/packages/apps/melhor-envio/lib/functions-lib/order-is-valid.js +40 -0
- package/packages/apps/melhor-envio/lib/functions-lib/order-is-valid.js.map +1 -0
- package/packages/apps/melhor-envio/lib/functions-lib/tracking-codes.d.ts +2 -0
- package/packages/apps/melhor-envio/lib/functions-lib/tracking-codes.js +164 -0
- package/packages/apps/melhor-envio/lib/functions-lib/tracking-codes.js.map +1 -0
- package/packages/apps/melhor-envio/lib/index.d.ts +1 -0
- package/packages/apps/melhor-envio/lib/index.js +2 -0
- package/packages/apps/melhor-envio/lib/index.js.map +1 -0
- package/packages/apps/melhor-envio/lib/melhor-envio-events.d.ts +6 -0
- package/packages/apps/melhor-envio/lib/melhor-envio-events.js +17 -0
- package/packages/apps/melhor-envio/lib/melhor-envio-events.js.map +1 -0
- package/packages/apps/melhor-envio/lib/melhor-envio.d.ts +2 -0
- package/packages/apps/melhor-envio/lib/melhor-envio.js +6 -0
- package/packages/apps/melhor-envio/lib/melhor-envio.js.map +1 -0
- package/packages/apps/melhor-envio/lib-mjs/calculate-melhor-envio.mjs +341 -0
- package/packages/apps/melhor-envio/lib-mjs/functions/client-melhor-envio.mjs +14 -0
- package/packages/apps/melhor-envio/lib-mjs/functions/error-handling.mjs +62 -0
- package/packages/apps/melhor-envio/lib-mjs/functions/new-shipment.mjs +119 -0
- package/packages/apps/melhor-envio/package.json +36 -0
- package/packages/apps/melhor-envio/src/functions-lib/database.ts +140 -0
- package/packages/apps/melhor-envio/src/functions-lib/events-to-melhor-envio.ts +137 -0
- package/packages/apps/melhor-envio/src/functions-lib/new-label.ts +214 -0
- package/packages/apps/melhor-envio/src/functions-lib/order-is-valid.ts +51 -0
- package/packages/apps/melhor-envio/src/functions-lib/tracking-codes.ts +191 -0
- package/packages/apps/melhor-envio/src/index.ts +1 -0
- package/packages/apps/melhor-envio/src/melhor-envio-events.ts +24 -0
- package/packages/apps/melhor-envio/src/melhor-envio.ts +7 -0
- package/packages/apps/melhor-envio/tsconfig.json +6 -0
- package/packages/apps/mercadopago/package.json +2 -2
- package/packages/apps/pagarme/package.json +2 -2
- package/packages/apps/paghiper/package.json +3 -3
- package/packages/apps/pix/package.json +2 -2
- package/packages/apps/tiny-erp/package.json +2 -2
- package/packages/cli/package.json +1 -1
- package/packages/config/package.json +1 -1
- package/packages/emails/package.json +3 -3
- package/packages/events/lib/firebase.js +2 -0
- package/packages/events/lib/firebase.js.map +1 -1
- package/packages/events/package.json +2 -1
- package/packages/events/src/firebase.ts +2 -0
- package/packages/firebase/lib/config.d.ts +4 -0
- package/packages/firebase/lib/config.js +7 -0
- package/packages/firebase/lib/config.js.map +1 -1
- package/packages/firebase/package.json +2 -2
- package/packages/firebase/src/config.ts +8 -0
- package/packages/i18n/lib/en_us/i19buyTogether.txt +1 -0
- package/packages/i18n/lib/en_us/i19buyTogetherWith.txt +1 -0
- package/packages/i18n/lib/en_us/i19report.txt +1 -0
- package/packages/i18n/lib/en_us/i19toggleMenu.txt +1 -0
- package/packages/i18n/lib/en_us/i19uponRequest.txt +1 -0
- package/packages/i18n/lib/en_us/i19usedPoints.txt +1 -0
- package/packages/i18n/lib/en_us.d.ts +6 -0
- package/packages/i18n/lib/en_us.js +6 -0
- package/packages/i18n/lib/en_us.js.map +1 -1
- package/packages/i18n/lib/pt_br/i19buyTogether.txt +1 -0
- package/packages/i18n/lib/pt_br/i19buyTogetherWith.txt +1 -0
- package/packages/i18n/lib/pt_br/i19report.txt +1 -0
- package/packages/i18n/lib/pt_br/i19toggleMenu.txt +1 -0
- package/packages/i18n/lib/pt_br/i19uponRequest.txt +1 -0
- package/packages/i18n/lib/pt_br/i19usedPoints.txt +1 -0
- package/packages/i18n/lib/pt_br.d.ts +6 -0
- package/packages/i18n/lib/pt_br.js +6 -0
- package/packages/i18n/lib/pt_br.js.map +1 -1
- package/packages/i18n/package.json +1 -1
- package/packages/i18n/src/en_us.ts +6 -0
- package/packages/i18n/src/pt_br.ts +6 -0
- package/packages/modules/lib/firebase/call-app-module.js +5 -0
- package/packages/modules/lib/firebase/call-app-module.js.map +1 -1
- package/packages/modules/package.json +3 -2
- package/packages/modules/src/firebase/call-app-module.ts +5 -0
- package/packages/passport/package.json +1 -1
- package/packages/ssr/package.json +3 -4
- package/packages/storefront/.eslintrc.cjs +1 -1
- package/packages/storefront/astro.config.mjs +8 -1
- package/packages/storefront/dist/client/_astro/PitchBar.209c6645.js +1 -0
- package/packages/storefront/dist/client/_astro/Prices.6fbcb5ac.js +1 -0
- package/packages/storefront/dist/client/_astro/Prices.vue_vue_type_script_setup_true_lang.44f23680.js +1 -0
- package/packages/storefront/dist/client/_astro/ProductCard.ee5eee91.js +1 -0
- package/packages/storefront/dist/client/_astro/ShopHeader.b801c785.js +1 -0
- package/packages/storefront/dist/client/_astro/_...slug_.32968ccf.css +1 -0
- package/packages/storefront/dist/client/_astro/client.5a46cc02.js +1 -0
- package/packages/storefront/dist/client/_astro/index.844a4059.js +1 -0
- package/packages/storefront/dist/client/_astro/{modules-info.dde776b4.js → modules-info.d9373e21.js} +1 -1
- package/packages/storefront/dist/client/_astro/runtime-core.esm-bundler.f04cee62.js +1 -0
- package/packages/storefront/dist/client/_astro/runtime-dom.esm-bundler.00313542.js +1 -0
- package/packages/storefront/dist/client/_astro/server.60de185d.css +1 -0
- package/packages/storefront/dist/client/_astro/use-component-variant.58788b6e.js +1 -0
- package/packages/storefront/dist/client/fallback/index.html +13 -7
- package/packages/storefront/dist/client/sw.js +1 -1
- package/packages/storefront/dist/server/chunks/pages/{all.c27193d6.mjs → all.23de4e5c.mjs} +444 -186
- package/packages/storefront/dist/server/chunks/{prerender.89f63027.mjs → prerender.f40361a3.mjs} +0 -0
- package/packages/storefront/dist/server/entry.mjs +39 -4452
- package/packages/storefront/package.json +4 -5
- package/packages/storefront/src/lib/assets/base.css +16 -11
- package/packages/storefront/src/lib/components/Carousel.vue +52 -82
- package/packages/storefront/src/lib/components/Drawer.vue +103 -0
- package/packages/storefront/src/lib/components/PitchBar.vue +16 -11
- package/packages/storefront/src/lib/components/Prices.vue +5 -5
- package/packages/storefront/src/lib/components/ShopHeader.vue +82 -0
- package/packages/storefront/src/lib/components/StickyHeader.vue +71 -43
- package/packages/storefront/src/lib/components/globals/Fade.vue +10 -14
- package/packages/storefront/src/lib/composables/use-component-variant.ts +6 -2
- package/packages/storefront/src/lib/composables/use-prices.ts +4 -2
- package/packages/storefront/src/lib/layouts/BaseBody.astro +1 -0
- package/packages/storefront/src/lib/layouts/PagesHeader.astro +28 -13
- package/packages/storefront/tailwind.config.cjs +4 -0
- package/packages/storefront/uno.config.cjs +1 -1
- package/packages/types/package.json +1 -1
- package/packages/storefront/dist/client/_astro/PitchBar.f3579a5b.js +0 -1
- package/packages/storefront/dist/client/_astro/Prices.8e5cead5.js +0 -1
- package/packages/storefront/dist/client/_astro/Prices.vue_vue_type_script_setup_true_lang.b8cbeb54.js +0 -1
- package/packages/storefront/dist/client/_astro/ProductCard.6d8b6d86.js +0 -1
- package/packages/storefront/dist/client/_astro/StickyHeader.7b0f3963.js +0 -1
- package/packages/storefront/dist/client/_astro/_...slug_.97285eba.css +0 -1
- package/packages/storefront/dist/client/_astro/client.3e777d4c.js +0 -1
- package/packages/storefront/dist/client/_astro/runtime-core.esm-bundler.7cf33881.js +0 -1
- package/packages/storefront/dist/client/_astro/runtime-dom.esm-bundler.1a4c7407.js +0 -1
- package/packages/storefront/dist/client/_astro/server.4d9646d8.css +0 -1
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { performance } from 'node:perf_hooks';
|
|
2
|
+
import { ReadableStream, ByteLengthQueuingStrategy, CountQueuingStrategy, ReadableByteStreamController, ReadableStreamBYOBReader, ReadableStreamBYOBRequest, ReadableStreamDefaultController, ReadableStreamDefaultReader, TransformStream, WritableStream, WritableStreamDefaultController, WritableStreamDefaultWriter } from 'node:stream/web';
|
|
3
|
+
import * as undici from 'undici';
|
|
2
4
|
import { setTimeout as setTimeout$1, clearTimeout as clearTimeout$1 } from 'node:timers';
|
|
3
|
-
import { bootstrap } from 'global-agent';
|
|
4
|
-
import nodeFetch, { Headers, Request, Response } from 'node-fetch';
|
|
5
|
-
import Stream from 'node:stream';
|
|
6
5
|
import { N as NodeApp, g as server_default, h as deserializeManifest } from './chunks/astro.89bd9221.mjs';
|
|
7
6
|
import { Readable } from 'stream';
|
|
8
7
|
import https from 'https';
|
|
@@ -14,8 +13,8 @@ import send from 'send';
|
|
|
14
13
|
import { defineComponent, computed, unref, useSSRContext, mergeProps, h as h$2, createSSRApp } from 'vue';
|
|
15
14
|
import { ssrRenderSlotInner, ssrRenderAttrs, ssrRenderSlot, renderToString } from 'vue/server-renderer';
|
|
16
15
|
import { i18n, formatMoney } from '@ecomplus/utils';
|
|
17
|
-
/* empty css */import { _ as _page0, a as _page1, b as _page3, c as _page4, d as _page5 } from './chunks/pages/all.
|
|
18
|
-
import { _ as _page2 } from './chunks/prerender.
|
|
16
|
+
/* empty css */import { _ as _page0, a as _page1, b as _page3, c as _page4, d as _page5 } from './chunks/pages/all.23de4e5c.mjs';
|
|
17
|
+
import { _ as _page2 } from './chunks/prerender.f40361a3.mjs';
|
|
19
18
|
import 'path-to-regexp';
|
|
20
19
|
import 'tls';
|
|
21
20
|
import 'mime';
|
|
@@ -32,27 +31,19 @@ import 'http-cache-semantics';
|
|
|
32
31
|
import 'node:os';
|
|
33
32
|
import 'image-size';
|
|
34
33
|
import 'magic-string';
|
|
34
|
+
import 'node:stream';
|
|
35
35
|
import '@cloudcommerce/api';
|
|
36
36
|
/* empty css */import 'node:events';
|
|
37
37
|
import 'node:fs';
|
|
38
38
|
import '@cloudcommerce/config';
|
|
39
|
-
/* empty css */import '
|
|
40
|
-
import '@vueuse/core';
|
|
39
|
+
/* empty css */import '@vueuse/core';
|
|
41
40
|
|
|
42
41
|
/** Returns the function bound to the given object. */
|
|
43
42
|
const __function_bind = Function.bind.bind(Function.call);
|
|
44
|
-
/** Returns the function called with the specified values. */
|
|
45
|
-
Function.call.bind(Function.call);
|
|
46
|
-
/** Returns whether an object has a property with the specified name. */
|
|
47
|
-
const __object_hasOwnProperty = Function.call.bind(Object.prototype.hasOwnProperty);
|
|
48
|
-
/** Returns a string representation of an object. */
|
|
49
|
-
Function.call.bind(Object.prototype.toString);
|
|
50
43
|
/** Returns whether the object prototype exists in another object. */
|
|
51
44
|
const __object_isPrototypeOf = Function.call.bind(Object.prototype.isPrototypeOf);
|
|
52
45
|
/** Current high resolution millisecond timestamp. */
|
|
53
46
|
const __performance_now = performance.now;
|
|
54
|
-
/** Returns the string escaped for use inside regular expressions. */
|
|
55
|
-
const __string_escapeRegExp = (value) => value.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
56
47
|
// @ts-ignore
|
|
57
48
|
const INTERNALS = new WeakMap();
|
|
58
49
|
const internalsOf = (target, className, propName) => {
|
|
@@ -62,20 +53,6 @@ const internalsOf = (target, className, propName) => {
|
|
|
62
53
|
return internals;
|
|
63
54
|
};
|
|
64
55
|
const allowStringTag = (value) => (value.prototype[Symbol.toStringTag] = value.name);
|
|
65
|
-
/** Returns any kind of path as a posix path. */
|
|
66
|
-
const pathToPosix = (pathname) => String(pathname == null ? '' : pathname)
|
|
67
|
-
.replace(
|
|
68
|
-
// convert slashes
|
|
69
|
-
/\\+/g, '/')
|
|
70
|
-
.replace(
|
|
71
|
-
// prefix a slash to drive letters
|
|
72
|
-
/^(?=[A-Za-z]:\/)/, '/')
|
|
73
|
-
.replace(
|
|
74
|
-
// encode path characters
|
|
75
|
-
/%/g, '%25')
|
|
76
|
-
.replace(/\n/g, '%0A')
|
|
77
|
-
.replace(/\r/g, '%0D')
|
|
78
|
-
.replace(/\t/g, '%09');
|
|
79
56
|
|
|
80
57
|
class DOMException extends Error {
|
|
81
58
|
constructor(message = '', name = 'Error') {
|
|
@@ -210,7 +187,7 @@ const CanceledInPassiveListener = new Warning("W05", "Unable to preventDefault i
|
|
|
210
187
|
const EventListenerWasDuplicated = new Warning("W06", "An event listener wasn't added because it has been added already: %o, %o");
|
|
211
188
|
const OptionWasIgnored = new Warning("W07", "The %o option value was abandoned because the event listener wasn't added as duplicated.");
|
|
212
189
|
const InvalidEventListener = new Warning("W08", "The 'callback' argument must be a function or an object that has 'handleEvent' method: %o");
|
|
213
|
-
|
|
190
|
+
new Warning("W09", "Event attribute handler must be a function: %o");
|
|
214
191
|
|
|
215
192
|
/*eslint-disable class-methods-use-this */
|
|
216
193
|
/**
|
|
@@ -1049,4243 +1026,6 @@ for (let i = 0; i < keys$1$1.length; ++i) {
|
|
|
1049
1026
|
}
|
|
1050
1027
|
Object.defineProperty(EventTarget.prototype, keys$1$1[i], { enumerable: true });
|
|
1051
1028
|
}
|
|
1052
|
-
// Ensure `eventTarget instanceof window.EventTarget` is `true`.
|
|
1053
|
-
|
|
1054
|
-
/**
|
|
1055
|
-
* Get the current value of a given event attribute.
|
|
1056
|
-
* @param target The `EventTarget` object to get.
|
|
1057
|
-
* @param type The event type.
|
|
1058
|
-
*/
|
|
1059
|
-
function getEventAttributeValue(target, type) {
|
|
1060
|
-
var _a, _b;
|
|
1061
|
-
const listMap = $$2(target, "target");
|
|
1062
|
-
return (_b = (_a = listMap[type]) === null || _a === void 0 ? void 0 : _a.attrCallback) !== null && _b !== void 0 ? _b : null;
|
|
1063
|
-
}
|
|
1064
|
-
/**
|
|
1065
|
-
* Set an event listener to a given event attribute.
|
|
1066
|
-
* @param target The `EventTarget` object to set.
|
|
1067
|
-
* @param type The event type.
|
|
1068
|
-
* @param callback The event listener.
|
|
1069
|
-
*/
|
|
1070
|
-
function setEventAttributeValue(target, type, callback) {
|
|
1071
|
-
if (callback != null && typeof callback !== "function") {
|
|
1072
|
-
InvalidAttributeHandler.warn(callback);
|
|
1073
|
-
}
|
|
1074
|
-
if (typeof callback === "function" ||
|
|
1075
|
-
(typeof callback === "object" && callback !== null)) {
|
|
1076
|
-
upsertEventAttributeListener(target, type, callback);
|
|
1077
|
-
}
|
|
1078
|
-
else {
|
|
1079
|
-
removeEventAttributeListener(target, type);
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
//------------------------------------------------------------------------------
|
|
1083
|
-
// Helpers
|
|
1084
|
-
//------------------------------------------------------------------------------
|
|
1085
|
-
/**
|
|
1086
|
-
* Update or insert the given event attribute handler.
|
|
1087
|
-
* @param target The `EventTarget` object to set.
|
|
1088
|
-
* @param type The event type.
|
|
1089
|
-
* @param callback The event listener.
|
|
1090
|
-
*/
|
|
1091
|
-
function upsertEventAttributeListener(target, type, callback) {
|
|
1092
|
-
const list = ensureListenerList($$2(target, "target"), String(type));
|
|
1093
|
-
list.attrCallback = callback;
|
|
1094
|
-
if (list.attrListener == null) {
|
|
1095
|
-
list.attrListener = addListener(list, defineEventAttributeCallback(list), false, false, false, undefined);
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1098
|
-
/**
|
|
1099
|
-
* Remove the given event attribute handler.
|
|
1100
|
-
* @param target The `EventTarget` object to remove.
|
|
1101
|
-
* @param type The event type.
|
|
1102
|
-
* @param callback The event listener.
|
|
1103
|
-
*/
|
|
1104
|
-
function removeEventAttributeListener(target, type) {
|
|
1105
|
-
const listMap = $$2(target, "target");
|
|
1106
|
-
const list = listMap[String(type)];
|
|
1107
|
-
if (list && list.attrListener) {
|
|
1108
|
-
removeListener(list, list.attrListener.callback, false);
|
|
1109
|
-
list.attrCallback = list.attrListener = undefined;
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
1112
|
-
/**
|
|
1113
|
-
* Define the callback function for the given listener list object.
|
|
1114
|
-
* It calls `attrCallback` property if the property value is a function.
|
|
1115
|
-
* @param list The `ListenerList` object.
|
|
1116
|
-
*/
|
|
1117
|
-
function defineEventAttributeCallback(list) {
|
|
1118
|
-
return function (event) {
|
|
1119
|
-
const callback = list.attrCallback;
|
|
1120
|
-
if (typeof callback === "function") {
|
|
1121
|
-
callback.call(this, event);
|
|
1122
|
-
}
|
|
1123
|
-
};
|
|
1124
|
-
}
|
|
1125
|
-
/**
|
|
1126
|
-
* Define an event attribute.
|
|
1127
|
-
* @param target The `EventTarget` object to define an event attribute.
|
|
1128
|
-
* @param type The event type to define.
|
|
1129
|
-
* @param _eventClass Unused, but to infer `Event` class type.
|
|
1130
|
-
* @deprecated Use `getEventAttributeValue`/`setEventAttributeValue` pair on your derived class instead because of static analysis friendly.
|
|
1131
|
-
*/
|
|
1132
|
-
function defineEventAttribute(target, type, _eventClass) {
|
|
1133
|
-
Object.defineProperty(target, `on${type}`, {
|
|
1134
|
-
get() {
|
|
1135
|
-
return getEventAttributeValue(this, type);
|
|
1136
|
-
},
|
|
1137
|
-
set(value) {
|
|
1138
|
-
setEventAttributeValue(this, type, value);
|
|
1139
|
-
},
|
|
1140
|
-
configurable: true,
|
|
1141
|
-
enumerable: true,
|
|
1142
|
-
});
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
|
-
/**
|
|
1146
|
-
* @author Toru Nagashima <https://github.com/mysticatea>
|
|
1147
|
-
* See LICENSE file in root directory for full license.
|
|
1148
|
-
*/
|
|
1149
|
-
|
|
1150
|
-
/**
|
|
1151
|
-
* The signal class.
|
|
1152
|
-
* @see https://dom.spec.whatwg.org/#abortsignal
|
|
1153
|
-
*/
|
|
1154
|
-
class AbortSignal extends EventTarget {
|
|
1155
|
-
/**
|
|
1156
|
-
* AbortSignal cannot be constructed directly.
|
|
1157
|
-
*/
|
|
1158
|
-
constructor() {
|
|
1159
|
-
super();
|
|
1160
|
-
throw new TypeError("AbortSignal cannot be constructed directly");
|
|
1161
|
-
}
|
|
1162
|
-
/**
|
|
1163
|
-
* Returns `true` if this `AbortSignal`'s `AbortController` has signaled to abort, and `false` otherwise.
|
|
1164
|
-
*/
|
|
1165
|
-
get aborted() {
|
|
1166
|
-
const aborted = abortedFlags.get(this);
|
|
1167
|
-
if (typeof aborted !== "boolean") {
|
|
1168
|
-
throw new TypeError(`Expected 'this' to be an 'AbortSignal' object, but got ${this === null ? "null" : typeof this}`);
|
|
1169
|
-
}
|
|
1170
|
-
return aborted;
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
defineEventAttribute(AbortSignal.prototype, "abort");
|
|
1174
|
-
/**
|
|
1175
|
-
* Create an AbortSignal object.
|
|
1176
|
-
*/
|
|
1177
|
-
function createAbortSignal() {
|
|
1178
|
-
const signal = Object.create(AbortSignal.prototype);
|
|
1179
|
-
EventTarget.call(signal);
|
|
1180
|
-
abortedFlags.set(signal, false);
|
|
1181
|
-
return signal;
|
|
1182
|
-
}
|
|
1183
|
-
/**
|
|
1184
|
-
* Abort a given signal.
|
|
1185
|
-
*/
|
|
1186
|
-
function abortSignal(signal) {
|
|
1187
|
-
if (abortedFlags.get(signal) !== false) {
|
|
1188
|
-
return;
|
|
1189
|
-
}
|
|
1190
|
-
abortedFlags.set(signal, true);
|
|
1191
|
-
signal.dispatchEvent({ type: "abort" });
|
|
1192
|
-
}
|
|
1193
|
-
/**
|
|
1194
|
-
* Aborted flag for each instances.
|
|
1195
|
-
*/
|
|
1196
|
-
const abortedFlags = new WeakMap();
|
|
1197
|
-
// Properties should be enumerable.
|
|
1198
|
-
Object.defineProperties(AbortSignal.prototype, {
|
|
1199
|
-
aborted: { enumerable: true },
|
|
1200
|
-
});
|
|
1201
|
-
// `toString()` should return `"[object AbortSignal]"`
|
|
1202
|
-
if (typeof Symbol === "function" && typeof Symbol.toStringTag === "symbol") {
|
|
1203
|
-
Object.defineProperty(AbortSignal.prototype, Symbol.toStringTag, {
|
|
1204
|
-
configurable: true,
|
|
1205
|
-
value: "AbortSignal",
|
|
1206
|
-
});
|
|
1207
|
-
}
|
|
1208
|
-
|
|
1209
|
-
/**
|
|
1210
|
-
* The AbortController.
|
|
1211
|
-
* @see https://dom.spec.whatwg.org/#abortcontroller
|
|
1212
|
-
*/
|
|
1213
|
-
class AbortController {
|
|
1214
|
-
/**
|
|
1215
|
-
* Initialize this controller.
|
|
1216
|
-
*/
|
|
1217
|
-
constructor() {
|
|
1218
|
-
signals.set(this, createAbortSignal());
|
|
1219
|
-
}
|
|
1220
|
-
/**
|
|
1221
|
-
* Returns the `AbortSignal` object associated with this object.
|
|
1222
|
-
*/
|
|
1223
|
-
get signal() {
|
|
1224
|
-
return getSignal(this);
|
|
1225
|
-
}
|
|
1226
|
-
/**
|
|
1227
|
-
* Abort and signal to any observers that the associated activity is to be aborted.
|
|
1228
|
-
*/
|
|
1229
|
-
abort() {
|
|
1230
|
-
abortSignal(getSignal(this));
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1233
|
-
/**
|
|
1234
|
-
* Associated signals.
|
|
1235
|
-
*/
|
|
1236
|
-
const signals = new WeakMap();
|
|
1237
|
-
/**
|
|
1238
|
-
* Get the associated signal of a given controller.
|
|
1239
|
-
*/
|
|
1240
|
-
function getSignal(controller) {
|
|
1241
|
-
const signal = signals.get(controller);
|
|
1242
|
-
if (signal == null) {
|
|
1243
|
-
throw new TypeError(`Expected 'this' to be an 'AbortController' object, but got ${controller === null ? "null" : typeof controller}`);
|
|
1244
|
-
}
|
|
1245
|
-
return signal;
|
|
1246
|
-
}
|
|
1247
|
-
// Properties should be enumerable.
|
|
1248
|
-
Object.defineProperties(AbortController.prototype, {
|
|
1249
|
-
signal: { enumerable: true },
|
|
1250
|
-
abort: { enumerable: true },
|
|
1251
|
-
});
|
|
1252
|
-
if (typeof Symbol === "function" && typeof Symbol.toStringTag === "symbol") {
|
|
1253
|
-
Object.defineProperty(AbortController.prototype, Symbol.toStringTag, {
|
|
1254
|
-
configurable: true,
|
|
1255
|
-
value: "AbortController",
|
|
1256
|
-
});
|
|
1257
|
-
}
|
|
1258
|
-
|
|
1259
|
-
/**
|
|
1260
|
-
* web-streams-polyfill v3.2.1
|
|
1261
|
-
*/
|
|
1262
|
-
/// <reference lib="es2015.symbol" />
|
|
1263
|
-
const SymbolPolyfill = Symbol;
|
|
1264
|
-
|
|
1265
|
-
/// <reference lib="dom" />
|
|
1266
|
-
function noop() {
|
|
1267
|
-
return undefined;
|
|
1268
|
-
}
|
|
1269
|
-
|
|
1270
|
-
function typeIsObject(x) {
|
|
1271
|
-
return (typeof x === 'object' && x !== null) || typeof x === 'function';
|
|
1272
|
-
}
|
|
1273
|
-
const rethrowAssertionErrorRejection = noop;
|
|
1274
|
-
|
|
1275
|
-
const originalPromise = Promise;
|
|
1276
|
-
const originalPromiseThen = Promise.prototype.then;
|
|
1277
|
-
const originalPromiseResolve = Promise.resolve.bind(originalPromise);
|
|
1278
|
-
const originalPromiseReject = Promise.reject.bind(originalPromise);
|
|
1279
|
-
function newPromise(executor) {
|
|
1280
|
-
return new originalPromise(executor);
|
|
1281
|
-
}
|
|
1282
|
-
function promiseResolvedWith(value) {
|
|
1283
|
-
return originalPromiseResolve(value);
|
|
1284
|
-
}
|
|
1285
|
-
function promiseRejectedWith(reason) {
|
|
1286
|
-
return originalPromiseReject(reason);
|
|
1287
|
-
}
|
|
1288
|
-
function PerformPromiseThen(promise, onFulfilled, onRejected) {
|
|
1289
|
-
// There doesn't appear to be any way to correctly emulate the behaviour from JavaScript, so this is just an
|
|
1290
|
-
// approximation.
|
|
1291
|
-
return originalPromiseThen.call(promise, onFulfilled, onRejected);
|
|
1292
|
-
}
|
|
1293
|
-
function uponPromise(promise, onFulfilled, onRejected) {
|
|
1294
|
-
PerformPromiseThen(PerformPromiseThen(promise, onFulfilled, onRejected), undefined, rethrowAssertionErrorRejection);
|
|
1295
|
-
}
|
|
1296
|
-
function uponFulfillment(promise, onFulfilled) {
|
|
1297
|
-
uponPromise(promise, onFulfilled);
|
|
1298
|
-
}
|
|
1299
|
-
function uponRejection(promise, onRejected) {
|
|
1300
|
-
uponPromise(promise, undefined, onRejected);
|
|
1301
|
-
}
|
|
1302
|
-
function transformPromiseWith(promise, fulfillmentHandler, rejectionHandler) {
|
|
1303
|
-
return PerformPromiseThen(promise, fulfillmentHandler, rejectionHandler);
|
|
1304
|
-
}
|
|
1305
|
-
function setPromiseIsHandledToTrue(promise) {
|
|
1306
|
-
PerformPromiseThen(promise, undefined, rethrowAssertionErrorRejection);
|
|
1307
|
-
}
|
|
1308
|
-
function reflectCall(F, V, args) {
|
|
1309
|
-
if (typeof F !== 'function') {
|
|
1310
|
-
throw new TypeError('Argument is not a function');
|
|
1311
|
-
}
|
|
1312
|
-
return Function.prototype.apply.call(F, V, args);
|
|
1313
|
-
}
|
|
1314
|
-
function promiseCall(F, V, args) {
|
|
1315
|
-
try {
|
|
1316
|
-
return promiseResolvedWith(reflectCall(F, V, args));
|
|
1317
|
-
}
|
|
1318
|
-
catch (value) {
|
|
1319
|
-
return promiseRejectedWith(value);
|
|
1320
|
-
}
|
|
1321
|
-
}
|
|
1322
|
-
|
|
1323
|
-
// Original from Chromium
|
|
1324
|
-
// https://chromium.googlesource.com/chromium/src/+/0aee4434a4dba42a42abaea9bfbc0cd196a63bc1/third_party/blink/renderer/core/streams/SimpleQueue.js
|
|
1325
|
-
const QUEUE_MAX_ARRAY_SIZE = 16384;
|
|
1326
|
-
/**
|
|
1327
|
-
* Simple queue structure.
|
|
1328
|
-
*
|
|
1329
|
-
* Avoids scalability issues with using a packed array directly by using
|
|
1330
|
-
* multiple arrays in a linked list and keeping the array size bounded.
|
|
1331
|
-
*/
|
|
1332
|
-
class SimpleQueue {
|
|
1333
|
-
constructor() {
|
|
1334
|
-
this._cursor = 0;
|
|
1335
|
-
this._size = 0;
|
|
1336
|
-
// _front and _back are always defined.
|
|
1337
|
-
this._front = {
|
|
1338
|
-
_elements: [],
|
|
1339
|
-
_next: undefined
|
|
1340
|
-
};
|
|
1341
|
-
this._back = this._front;
|
|
1342
|
-
// The cursor is used to avoid calling Array.shift().
|
|
1343
|
-
// It contains the index of the front element of the array inside the
|
|
1344
|
-
// front-most node. It is always in the range [0, QUEUE_MAX_ARRAY_SIZE).
|
|
1345
|
-
this._cursor = 0;
|
|
1346
|
-
// When there is only one node, size === elements.length - cursor.
|
|
1347
|
-
this._size = 0;
|
|
1348
|
-
}
|
|
1349
|
-
get length() {
|
|
1350
|
-
return this._size;
|
|
1351
|
-
}
|
|
1352
|
-
// For exception safety, this method is structured in order:
|
|
1353
|
-
// 1. Read state
|
|
1354
|
-
// 2. Calculate required state mutations
|
|
1355
|
-
// 3. Perform state mutations
|
|
1356
|
-
push(element) {
|
|
1357
|
-
const oldBack = this._back;
|
|
1358
|
-
let newBack = oldBack;
|
|
1359
|
-
if (oldBack._elements.length === QUEUE_MAX_ARRAY_SIZE - 1) {
|
|
1360
|
-
newBack = {
|
|
1361
|
-
_elements: [],
|
|
1362
|
-
_next: undefined
|
|
1363
|
-
};
|
|
1364
|
-
}
|
|
1365
|
-
// push() is the mutation most likely to throw an exception, so it
|
|
1366
|
-
// goes first.
|
|
1367
|
-
oldBack._elements.push(element);
|
|
1368
|
-
if (newBack !== oldBack) {
|
|
1369
|
-
this._back = newBack;
|
|
1370
|
-
oldBack._next = newBack;
|
|
1371
|
-
}
|
|
1372
|
-
++this._size;
|
|
1373
|
-
}
|
|
1374
|
-
// Like push(), shift() follows the read -> calculate -> mutate pattern for
|
|
1375
|
-
// exception safety.
|
|
1376
|
-
shift() { // must not be called on an empty queue
|
|
1377
|
-
const oldFront = this._front;
|
|
1378
|
-
let newFront = oldFront;
|
|
1379
|
-
const oldCursor = this._cursor;
|
|
1380
|
-
let newCursor = oldCursor + 1;
|
|
1381
|
-
const elements = oldFront._elements;
|
|
1382
|
-
const element = elements[oldCursor];
|
|
1383
|
-
if (newCursor === QUEUE_MAX_ARRAY_SIZE) {
|
|
1384
|
-
newFront = oldFront._next;
|
|
1385
|
-
newCursor = 0;
|
|
1386
|
-
}
|
|
1387
|
-
// No mutations before this point.
|
|
1388
|
-
--this._size;
|
|
1389
|
-
this._cursor = newCursor;
|
|
1390
|
-
if (oldFront !== newFront) {
|
|
1391
|
-
this._front = newFront;
|
|
1392
|
-
}
|
|
1393
|
-
// Permit shifted element to be garbage collected.
|
|
1394
|
-
elements[oldCursor] = undefined;
|
|
1395
|
-
return element;
|
|
1396
|
-
}
|
|
1397
|
-
// The tricky thing about forEach() is that it can be called
|
|
1398
|
-
// re-entrantly. The queue may be mutated inside the callback. It is easy to
|
|
1399
|
-
// see that push() within the callback has no negative effects since the end
|
|
1400
|
-
// of the queue is checked for on every iteration. If shift() is called
|
|
1401
|
-
// repeatedly within the callback then the next iteration may return an
|
|
1402
|
-
// element that has been removed. In this case the callback will be called
|
|
1403
|
-
// with undefined values until we either "catch up" with elements that still
|
|
1404
|
-
// exist or reach the back of the queue.
|
|
1405
|
-
forEach(callback) {
|
|
1406
|
-
let i = this._cursor;
|
|
1407
|
-
let node = this._front;
|
|
1408
|
-
let elements = node._elements;
|
|
1409
|
-
while (i !== elements.length || node._next !== undefined) {
|
|
1410
|
-
if (i === elements.length) {
|
|
1411
|
-
node = node._next;
|
|
1412
|
-
elements = node._elements;
|
|
1413
|
-
i = 0;
|
|
1414
|
-
if (elements.length === 0) {
|
|
1415
|
-
break;
|
|
1416
|
-
}
|
|
1417
|
-
}
|
|
1418
|
-
callback(elements[i]);
|
|
1419
|
-
++i;
|
|
1420
|
-
}
|
|
1421
|
-
}
|
|
1422
|
-
// Return the element that would be returned if shift() was called now,
|
|
1423
|
-
// without modifying the queue.
|
|
1424
|
-
peek() { // must not be called on an empty queue
|
|
1425
|
-
const front = this._front;
|
|
1426
|
-
const cursor = this._cursor;
|
|
1427
|
-
return front._elements[cursor];
|
|
1428
|
-
}
|
|
1429
|
-
}
|
|
1430
|
-
|
|
1431
|
-
function ReadableStreamReaderGenericInitialize(reader, stream) {
|
|
1432
|
-
reader._ownerReadableStream = stream;
|
|
1433
|
-
stream._reader = reader;
|
|
1434
|
-
if (stream._state === 'readable') {
|
|
1435
|
-
defaultReaderClosedPromiseInitialize(reader);
|
|
1436
|
-
}
|
|
1437
|
-
else if (stream._state === 'closed') {
|
|
1438
|
-
defaultReaderClosedPromiseInitializeAsResolved(reader);
|
|
1439
|
-
}
|
|
1440
|
-
else {
|
|
1441
|
-
defaultReaderClosedPromiseInitializeAsRejected(reader, stream._storedError);
|
|
1442
|
-
}
|
|
1443
|
-
}
|
|
1444
|
-
// A client of ReadableStreamDefaultReader and ReadableStreamBYOBReader may use these functions directly to bypass state
|
|
1445
|
-
// check.
|
|
1446
|
-
function ReadableStreamReaderGenericCancel(reader, reason) {
|
|
1447
|
-
const stream = reader._ownerReadableStream;
|
|
1448
|
-
return ReadableStreamCancel(stream, reason);
|
|
1449
|
-
}
|
|
1450
|
-
function ReadableStreamReaderGenericRelease(reader) {
|
|
1451
|
-
if (reader._ownerReadableStream._state === 'readable') {
|
|
1452
|
-
defaultReaderClosedPromiseReject(reader, new TypeError(`Reader was released and can no longer be used to monitor the stream's closedness`));
|
|
1453
|
-
}
|
|
1454
|
-
else {
|
|
1455
|
-
defaultReaderClosedPromiseResetToRejected(reader, new TypeError(`Reader was released and can no longer be used to monitor the stream's closedness`));
|
|
1456
|
-
}
|
|
1457
|
-
reader._ownerReadableStream._reader = undefined;
|
|
1458
|
-
reader._ownerReadableStream = undefined;
|
|
1459
|
-
}
|
|
1460
|
-
// Helper functions for the readers.
|
|
1461
|
-
function readerLockException(name) {
|
|
1462
|
-
return new TypeError('Cannot ' + name + ' a stream using a released reader');
|
|
1463
|
-
}
|
|
1464
|
-
// Helper functions for the ReadableStreamDefaultReader.
|
|
1465
|
-
function defaultReaderClosedPromiseInitialize(reader) {
|
|
1466
|
-
reader._closedPromise = newPromise((resolve, reject) => {
|
|
1467
|
-
reader._closedPromise_resolve = resolve;
|
|
1468
|
-
reader._closedPromise_reject = reject;
|
|
1469
|
-
});
|
|
1470
|
-
}
|
|
1471
|
-
function defaultReaderClosedPromiseInitializeAsRejected(reader, reason) {
|
|
1472
|
-
defaultReaderClosedPromiseInitialize(reader);
|
|
1473
|
-
defaultReaderClosedPromiseReject(reader, reason);
|
|
1474
|
-
}
|
|
1475
|
-
function defaultReaderClosedPromiseInitializeAsResolved(reader) {
|
|
1476
|
-
defaultReaderClosedPromiseInitialize(reader);
|
|
1477
|
-
defaultReaderClosedPromiseResolve(reader);
|
|
1478
|
-
}
|
|
1479
|
-
function defaultReaderClosedPromiseReject(reader, reason) {
|
|
1480
|
-
if (reader._closedPromise_reject === undefined) {
|
|
1481
|
-
return;
|
|
1482
|
-
}
|
|
1483
|
-
setPromiseIsHandledToTrue(reader._closedPromise);
|
|
1484
|
-
reader._closedPromise_reject(reason);
|
|
1485
|
-
reader._closedPromise_resolve = undefined;
|
|
1486
|
-
reader._closedPromise_reject = undefined;
|
|
1487
|
-
}
|
|
1488
|
-
function defaultReaderClosedPromiseResetToRejected(reader, reason) {
|
|
1489
|
-
defaultReaderClosedPromiseInitializeAsRejected(reader, reason);
|
|
1490
|
-
}
|
|
1491
|
-
function defaultReaderClosedPromiseResolve(reader) {
|
|
1492
|
-
if (reader._closedPromise_resolve === undefined) {
|
|
1493
|
-
return;
|
|
1494
|
-
}
|
|
1495
|
-
reader._closedPromise_resolve(undefined);
|
|
1496
|
-
reader._closedPromise_resolve = undefined;
|
|
1497
|
-
reader._closedPromise_reject = undefined;
|
|
1498
|
-
}
|
|
1499
|
-
|
|
1500
|
-
const AbortSteps = SymbolPolyfill('[[AbortSteps]]');
|
|
1501
|
-
const ErrorSteps = SymbolPolyfill('[[ErrorSteps]]');
|
|
1502
|
-
const CancelSteps = SymbolPolyfill('[[CancelSteps]]');
|
|
1503
|
-
const PullSteps = SymbolPolyfill('[[PullSteps]]');
|
|
1504
|
-
|
|
1505
|
-
/// <reference lib="es2015.core" />
|
|
1506
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite#Polyfill
|
|
1507
|
-
const NumberIsFinite = Number.isFinite || function (x) {
|
|
1508
|
-
return typeof x === 'number' && isFinite(x);
|
|
1509
|
-
};
|
|
1510
|
-
|
|
1511
|
-
/// <reference lib="es2015.core" />
|
|
1512
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc#Polyfill
|
|
1513
|
-
const MathTrunc = Math.trunc || function (v) {
|
|
1514
|
-
return v < 0 ? Math.ceil(v) : Math.floor(v);
|
|
1515
|
-
};
|
|
1516
|
-
|
|
1517
|
-
// https://heycam.github.io/webidl/#idl-dictionaries
|
|
1518
|
-
function isDictionary(x) {
|
|
1519
|
-
return typeof x === 'object' || typeof x === 'function';
|
|
1520
|
-
}
|
|
1521
|
-
function assertDictionary(obj, context) {
|
|
1522
|
-
if (obj !== undefined && !isDictionary(obj)) {
|
|
1523
|
-
throw new TypeError(`${context} is not an object.`);
|
|
1524
|
-
}
|
|
1525
|
-
}
|
|
1526
|
-
// https://heycam.github.io/webidl/#idl-callback-functions
|
|
1527
|
-
function assertFunction(x, context) {
|
|
1528
|
-
if (typeof x !== 'function') {
|
|
1529
|
-
throw new TypeError(`${context} is not a function.`);
|
|
1530
|
-
}
|
|
1531
|
-
}
|
|
1532
|
-
// https://heycam.github.io/webidl/#idl-object
|
|
1533
|
-
function isObject(x) {
|
|
1534
|
-
return (typeof x === 'object' && x !== null) || typeof x === 'function';
|
|
1535
|
-
}
|
|
1536
|
-
function assertObject(x, context) {
|
|
1537
|
-
if (!isObject(x)) {
|
|
1538
|
-
throw new TypeError(`${context} is not an object.`);
|
|
1539
|
-
}
|
|
1540
|
-
}
|
|
1541
|
-
function assertRequiredArgument(x, position, context) {
|
|
1542
|
-
if (x === undefined) {
|
|
1543
|
-
throw new TypeError(`Parameter ${position} is required in '${context}'.`);
|
|
1544
|
-
}
|
|
1545
|
-
}
|
|
1546
|
-
function assertRequiredField(x, field, context) {
|
|
1547
|
-
if (x === undefined) {
|
|
1548
|
-
throw new TypeError(`${field} is required in '${context}'.`);
|
|
1549
|
-
}
|
|
1550
|
-
}
|
|
1551
|
-
// https://heycam.github.io/webidl/#idl-unrestricted-double
|
|
1552
|
-
function convertUnrestrictedDouble(value) {
|
|
1553
|
-
return Number(value);
|
|
1554
|
-
}
|
|
1555
|
-
function censorNegativeZero(x) {
|
|
1556
|
-
return x === 0 ? 0 : x;
|
|
1557
|
-
}
|
|
1558
|
-
function integerPart(x) {
|
|
1559
|
-
return censorNegativeZero(MathTrunc(x));
|
|
1560
|
-
}
|
|
1561
|
-
// https://heycam.github.io/webidl/#idl-unsigned-long-long
|
|
1562
|
-
function convertUnsignedLongLongWithEnforceRange(value, context) {
|
|
1563
|
-
const lowerBound = 0;
|
|
1564
|
-
const upperBound = Number.MAX_SAFE_INTEGER;
|
|
1565
|
-
let x = Number(value);
|
|
1566
|
-
x = censorNegativeZero(x);
|
|
1567
|
-
if (!NumberIsFinite(x)) {
|
|
1568
|
-
throw new TypeError(`${context} is not a finite number`);
|
|
1569
|
-
}
|
|
1570
|
-
x = integerPart(x);
|
|
1571
|
-
if (x < lowerBound || x > upperBound) {
|
|
1572
|
-
throw new TypeError(`${context} is outside the accepted range of ${lowerBound} to ${upperBound}, inclusive`);
|
|
1573
|
-
}
|
|
1574
|
-
if (!NumberIsFinite(x) || x === 0) {
|
|
1575
|
-
return 0;
|
|
1576
|
-
}
|
|
1577
|
-
// TODO Use BigInt if supported?
|
|
1578
|
-
// let xBigInt = BigInt(integerPart(x));
|
|
1579
|
-
// xBigInt = BigInt.asUintN(64, xBigInt);
|
|
1580
|
-
// return Number(xBigInt);
|
|
1581
|
-
return x;
|
|
1582
|
-
}
|
|
1583
|
-
|
|
1584
|
-
function assertReadableStream(x, context) {
|
|
1585
|
-
if (!IsReadableStream(x)) {
|
|
1586
|
-
throw new TypeError(`${context} is not a ReadableStream.`);
|
|
1587
|
-
}
|
|
1588
|
-
}
|
|
1589
|
-
|
|
1590
|
-
// Abstract operations for the ReadableStream.
|
|
1591
|
-
function AcquireReadableStreamDefaultReader(stream) {
|
|
1592
|
-
return new ReadableStreamDefaultReader(stream);
|
|
1593
|
-
}
|
|
1594
|
-
// ReadableStream API exposed for controllers.
|
|
1595
|
-
function ReadableStreamAddReadRequest(stream, readRequest) {
|
|
1596
|
-
stream._reader._readRequests.push(readRequest);
|
|
1597
|
-
}
|
|
1598
|
-
function ReadableStreamFulfillReadRequest(stream, chunk, done) {
|
|
1599
|
-
const reader = stream._reader;
|
|
1600
|
-
const readRequest = reader._readRequests.shift();
|
|
1601
|
-
if (done) {
|
|
1602
|
-
readRequest._closeSteps();
|
|
1603
|
-
}
|
|
1604
|
-
else {
|
|
1605
|
-
readRequest._chunkSteps(chunk);
|
|
1606
|
-
}
|
|
1607
|
-
}
|
|
1608
|
-
function ReadableStreamGetNumReadRequests(stream) {
|
|
1609
|
-
return stream._reader._readRequests.length;
|
|
1610
|
-
}
|
|
1611
|
-
function ReadableStreamHasDefaultReader(stream) {
|
|
1612
|
-
const reader = stream._reader;
|
|
1613
|
-
if (reader === undefined) {
|
|
1614
|
-
return false;
|
|
1615
|
-
}
|
|
1616
|
-
if (!IsReadableStreamDefaultReader(reader)) {
|
|
1617
|
-
return false;
|
|
1618
|
-
}
|
|
1619
|
-
return true;
|
|
1620
|
-
}
|
|
1621
|
-
/**
|
|
1622
|
-
* A default reader vended by a {@link ReadableStream}.
|
|
1623
|
-
*
|
|
1624
|
-
* @public
|
|
1625
|
-
*/
|
|
1626
|
-
class ReadableStreamDefaultReader {
|
|
1627
|
-
constructor(stream) {
|
|
1628
|
-
assertRequiredArgument(stream, 1, 'ReadableStreamDefaultReader');
|
|
1629
|
-
assertReadableStream(stream, 'First parameter');
|
|
1630
|
-
if (IsReadableStreamLocked(stream)) {
|
|
1631
|
-
throw new TypeError('This stream has already been locked for exclusive reading by another reader');
|
|
1632
|
-
}
|
|
1633
|
-
ReadableStreamReaderGenericInitialize(this, stream);
|
|
1634
|
-
this._readRequests = new SimpleQueue();
|
|
1635
|
-
}
|
|
1636
|
-
/**
|
|
1637
|
-
* Returns a promise that will be fulfilled when the stream becomes closed,
|
|
1638
|
-
* or rejected if the stream ever errors or the reader's lock is released before the stream finishes closing.
|
|
1639
|
-
*/
|
|
1640
|
-
get closed() {
|
|
1641
|
-
if (!IsReadableStreamDefaultReader(this)) {
|
|
1642
|
-
return promiseRejectedWith(defaultReaderBrandCheckException('closed'));
|
|
1643
|
-
}
|
|
1644
|
-
return this._closedPromise;
|
|
1645
|
-
}
|
|
1646
|
-
/**
|
|
1647
|
-
* If the reader is active, behaves the same as {@link ReadableStream.cancel | stream.cancel(reason)}.
|
|
1648
|
-
*/
|
|
1649
|
-
cancel(reason = undefined) {
|
|
1650
|
-
if (!IsReadableStreamDefaultReader(this)) {
|
|
1651
|
-
return promiseRejectedWith(defaultReaderBrandCheckException('cancel'));
|
|
1652
|
-
}
|
|
1653
|
-
if (this._ownerReadableStream === undefined) {
|
|
1654
|
-
return promiseRejectedWith(readerLockException('cancel'));
|
|
1655
|
-
}
|
|
1656
|
-
return ReadableStreamReaderGenericCancel(this, reason);
|
|
1657
|
-
}
|
|
1658
|
-
/**
|
|
1659
|
-
* Returns a promise that allows access to the next chunk from the stream's internal queue, if available.
|
|
1660
|
-
*
|
|
1661
|
-
* If reading a chunk causes the queue to become empty, more data will be pulled from the underlying source.
|
|
1662
|
-
*/
|
|
1663
|
-
read() {
|
|
1664
|
-
if (!IsReadableStreamDefaultReader(this)) {
|
|
1665
|
-
return promiseRejectedWith(defaultReaderBrandCheckException('read'));
|
|
1666
|
-
}
|
|
1667
|
-
if (this._ownerReadableStream === undefined) {
|
|
1668
|
-
return promiseRejectedWith(readerLockException('read from'));
|
|
1669
|
-
}
|
|
1670
|
-
let resolvePromise;
|
|
1671
|
-
let rejectPromise;
|
|
1672
|
-
const promise = newPromise((resolve, reject) => {
|
|
1673
|
-
resolvePromise = resolve;
|
|
1674
|
-
rejectPromise = reject;
|
|
1675
|
-
});
|
|
1676
|
-
const readRequest = {
|
|
1677
|
-
_chunkSteps: chunk => resolvePromise({ value: chunk, done: false }),
|
|
1678
|
-
_closeSteps: () => resolvePromise({ value: undefined, done: true }),
|
|
1679
|
-
_errorSteps: e => rejectPromise(e)
|
|
1680
|
-
};
|
|
1681
|
-
ReadableStreamDefaultReaderRead(this, readRequest);
|
|
1682
|
-
return promise;
|
|
1683
|
-
}
|
|
1684
|
-
/**
|
|
1685
|
-
* Releases the reader's lock on the corresponding stream. After the lock is released, the reader is no longer active.
|
|
1686
|
-
* If the associated stream is errored when the lock is released, the reader will appear errored in the same way
|
|
1687
|
-
* from now on; otherwise, the reader will appear closed.
|
|
1688
|
-
*
|
|
1689
|
-
* A reader's lock cannot be released while it still has a pending read request, i.e., if a promise returned by
|
|
1690
|
-
* the reader's {@link ReadableStreamDefaultReader.read | read()} method has not yet been settled. Attempting to
|
|
1691
|
-
* do so will throw a `TypeError` and leave the reader locked to the stream.
|
|
1692
|
-
*/
|
|
1693
|
-
releaseLock() {
|
|
1694
|
-
if (!IsReadableStreamDefaultReader(this)) {
|
|
1695
|
-
throw defaultReaderBrandCheckException('releaseLock');
|
|
1696
|
-
}
|
|
1697
|
-
if (this._ownerReadableStream === undefined) {
|
|
1698
|
-
return;
|
|
1699
|
-
}
|
|
1700
|
-
if (this._readRequests.length > 0) {
|
|
1701
|
-
throw new TypeError('Tried to release a reader lock when that reader has pending read() calls un-settled');
|
|
1702
|
-
}
|
|
1703
|
-
ReadableStreamReaderGenericRelease(this);
|
|
1704
|
-
}
|
|
1705
|
-
}
|
|
1706
|
-
Object.defineProperties(ReadableStreamDefaultReader.prototype, {
|
|
1707
|
-
cancel: { enumerable: true },
|
|
1708
|
-
read: { enumerable: true },
|
|
1709
|
-
releaseLock: { enumerable: true },
|
|
1710
|
-
closed: { enumerable: true }
|
|
1711
|
-
});
|
|
1712
|
-
// Abstract operations for the readers.
|
|
1713
|
-
function IsReadableStreamDefaultReader(x) {
|
|
1714
|
-
if (!typeIsObject(x)) {
|
|
1715
|
-
return false;
|
|
1716
|
-
}
|
|
1717
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_readRequests')) {
|
|
1718
|
-
return false;
|
|
1719
|
-
}
|
|
1720
|
-
return x instanceof ReadableStreamDefaultReader;
|
|
1721
|
-
}
|
|
1722
|
-
function ReadableStreamDefaultReaderRead(reader, readRequest) {
|
|
1723
|
-
const stream = reader._ownerReadableStream;
|
|
1724
|
-
stream._disturbed = true;
|
|
1725
|
-
if (stream._state === 'closed') {
|
|
1726
|
-
readRequest._closeSteps();
|
|
1727
|
-
}
|
|
1728
|
-
else if (stream._state === 'errored') {
|
|
1729
|
-
readRequest._errorSteps(stream._storedError);
|
|
1730
|
-
}
|
|
1731
|
-
else {
|
|
1732
|
-
stream._readableStreamController[PullSteps](readRequest);
|
|
1733
|
-
}
|
|
1734
|
-
}
|
|
1735
|
-
// Helper functions for the ReadableStreamDefaultReader.
|
|
1736
|
-
function defaultReaderBrandCheckException(name) {
|
|
1737
|
-
return new TypeError(`ReadableStreamDefaultReader.prototype.${name} can only be used on a ReadableStreamDefaultReader`);
|
|
1738
|
-
}
|
|
1739
|
-
|
|
1740
|
-
/// <reference lib="es2018.asynciterable" />
|
|
1741
|
-
class ReadableStreamAsyncIteratorImpl {
|
|
1742
|
-
constructor(reader, preventCancel) {
|
|
1743
|
-
this._ongoingPromise = undefined;
|
|
1744
|
-
this._isFinished = false;
|
|
1745
|
-
this._reader = reader;
|
|
1746
|
-
this._preventCancel = preventCancel;
|
|
1747
|
-
}
|
|
1748
|
-
next() {
|
|
1749
|
-
const nextSteps = () => this._nextSteps();
|
|
1750
|
-
this._ongoingPromise = this._ongoingPromise ?
|
|
1751
|
-
transformPromiseWith(this._ongoingPromise, nextSteps, nextSteps) :
|
|
1752
|
-
nextSteps();
|
|
1753
|
-
return this._ongoingPromise;
|
|
1754
|
-
}
|
|
1755
|
-
return(value) {
|
|
1756
|
-
const returnSteps = () => this._returnSteps(value);
|
|
1757
|
-
return this._ongoingPromise ?
|
|
1758
|
-
transformPromiseWith(this._ongoingPromise, returnSteps, returnSteps) :
|
|
1759
|
-
returnSteps();
|
|
1760
|
-
}
|
|
1761
|
-
_nextSteps() {
|
|
1762
|
-
if (this._isFinished) {
|
|
1763
|
-
return Promise.resolve({ value: undefined, done: true });
|
|
1764
|
-
}
|
|
1765
|
-
const reader = this._reader;
|
|
1766
|
-
if (reader._ownerReadableStream === undefined) {
|
|
1767
|
-
return promiseRejectedWith(readerLockException('iterate'));
|
|
1768
|
-
}
|
|
1769
|
-
let resolvePromise;
|
|
1770
|
-
let rejectPromise;
|
|
1771
|
-
const promise = newPromise((resolve, reject) => {
|
|
1772
|
-
resolvePromise = resolve;
|
|
1773
|
-
rejectPromise = reject;
|
|
1774
|
-
});
|
|
1775
|
-
const readRequest = {
|
|
1776
|
-
_chunkSteps: chunk => {
|
|
1777
|
-
this._ongoingPromise = undefined;
|
|
1778
|
-
// This needs to be delayed by one microtask, otherwise we stop pulling too early which breaks a test.
|
|
1779
|
-
// FIXME Is this a bug in the specification, or in the test?
|
|
1780
|
-
queueMicrotask(() => resolvePromise({ value: chunk, done: false }));
|
|
1781
|
-
},
|
|
1782
|
-
_closeSteps: () => {
|
|
1783
|
-
this._ongoingPromise = undefined;
|
|
1784
|
-
this._isFinished = true;
|
|
1785
|
-
ReadableStreamReaderGenericRelease(reader);
|
|
1786
|
-
resolvePromise({ value: undefined, done: true });
|
|
1787
|
-
},
|
|
1788
|
-
_errorSteps: reason => {
|
|
1789
|
-
this._ongoingPromise = undefined;
|
|
1790
|
-
this._isFinished = true;
|
|
1791
|
-
ReadableStreamReaderGenericRelease(reader);
|
|
1792
|
-
rejectPromise(reason);
|
|
1793
|
-
}
|
|
1794
|
-
};
|
|
1795
|
-
ReadableStreamDefaultReaderRead(reader, readRequest);
|
|
1796
|
-
return promise;
|
|
1797
|
-
}
|
|
1798
|
-
_returnSteps(value) {
|
|
1799
|
-
if (this._isFinished) {
|
|
1800
|
-
return Promise.resolve({ value, done: true });
|
|
1801
|
-
}
|
|
1802
|
-
this._isFinished = true;
|
|
1803
|
-
const reader = this._reader;
|
|
1804
|
-
if (reader._ownerReadableStream === undefined) {
|
|
1805
|
-
return promiseRejectedWith(readerLockException('finish iterating'));
|
|
1806
|
-
}
|
|
1807
|
-
if (!this._preventCancel) {
|
|
1808
|
-
const result = ReadableStreamReaderGenericCancel(reader, value);
|
|
1809
|
-
ReadableStreamReaderGenericRelease(reader);
|
|
1810
|
-
return transformPromiseWith(result, () => ({ value, done: true }));
|
|
1811
|
-
}
|
|
1812
|
-
ReadableStreamReaderGenericRelease(reader);
|
|
1813
|
-
return promiseResolvedWith({ value, done: true });
|
|
1814
|
-
}
|
|
1815
|
-
}
|
|
1816
|
-
const ReadableStreamAsyncIteratorPrototype = {
|
|
1817
|
-
next() {
|
|
1818
|
-
if (!IsReadableStreamAsyncIterator(this)) {
|
|
1819
|
-
return promiseRejectedWith(streamAsyncIteratorBrandCheckException('next'));
|
|
1820
|
-
}
|
|
1821
|
-
return this._asyncIteratorImpl.next();
|
|
1822
|
-
},
|
|
1823
|
-
return(value) {
|
|
1824
|
-
if (!IsReadableStreamAsyncIterator(this)) {
|
|
1825
|
-
return promiseRejectedWith(streamAsyncIteratorBrandCheckException('return'));
|
|
1826
|
-
}
|
|
1827
|
-
return this._asyncIteratorImpl.return(value);
|
|
1828
|
-
}
|
|
1829
|
-
};
|
|
1830
|
-
// Abstract operations for the ReadableStream.
|
|
1831
|
-
function AcquireReadableStreamAsyncIterator(stream, preventCancel) {
|
|
1832
|
-
const reader = AcquireReadableStreamDefaultReader(stream);
|
|
1833
|
-
const impl = new ReadableStreamAsyncIteratorImpl(reader, preventCancel);
|
|
1834
|
-
const iterator = Object.create(ReadableStreamAsyncIteratorPrototype);
|
|
1835
|
-
iterator._asyncIteratorImpl = impl;
|
|
1836
|
-
return iterator;
|
|
1837
|
-
}
|
|
1838
|
-
function IsReadableStreamAsyncIterator(x) {
|
|
1839
|
-
if (!typeIsObject(x)) {
|
|
1840
|
-
return false;
|
|
1841
|
-
}
|
|
1842
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_asyncIteratorImpl')) {
|
|
1843
|
-
return false;
|
|
1844
|
-
}
|
|
1845
|
-
try {
|
|
1846
|
-
// noinspection SuspiciousTypeOfGuard
|
|
1847
|
-
return x._asyncIteratorImpl instanceof
|
|
1848
|
-
ReadableStreamAsyncIteratorImpl;
|
|
1849
|
-
}
|
|
1850
|
-
catch (_a) {
|
|
1851
|
-
return false;
|
|
1852
|
-
}
|
|
1853
|
-
}
|
|
1854
|
-
// Helper functions for the ReadableStream.
|
|
1855
|
-
function streamAsyncIteratorBrandCheckException(name) {
|
|
1856
|
-
return new TypeError(`ReadableStreamAsyncIterator.${name} can only be used on a ReadableSteamAsyncIterator`);
|
|
1857
|
-
}
|
|
1858
|
-
|
|
1859
|
-
/// <reference lib="es2015.core" />
|
|
1860
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN#Polyfill
|
|
1861
|
-
const NumberIsNaN = Number.isNaN || function (x) {
|
|
1862
|
-
// eslint-disable-next-line no-self-compare
|
|
1863
|
-
return x !== x;
|
|
1864
|
-
};
|
|
1865
|
-
|
|
1866
|
-
function CreateArrayFromList(elements) {
|
|
1867
|
-
// We use arrays to represent lists, so this is basically a no-op.
|
|
1868
|
-
// Do a slice though just in case we happen to depend on the unique-ness.
|
|
1869
|
-
return elements.slice();
|
|
1870
|
-
}
|
|
1871
|
-
function CopyDataBlockBytes(dest, destOffset, src, srcOffset, n) {
|
|
1872
|
-
new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset);
|
|
1873
|
-
}
|
|
1874
|
-
// Not implemented correctly
|
|
1875
|
-
function TransferArrayBuffer(O) {
|
|
1876
|
-
return O;
|
|
1877
|
-
}
|
|
1878
|
-
// Not implemented correctly
|
|
1879
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1880
|
-
function IsDetachedBuffer(O) {
|
|
1881
|
-
return false;
|
|
1882
|
-
}
|
|
1883
|
-
function ArrayBufferSlice(buffer, begin, end) {
|
|
1884
|
-
// ArrayBuffer.prototype.slice is not available on IE10
|
|
1885
|
-
// https://www.caniuse.com/mdn-javascript_builtins_arraybuffer_slice
|
|
1886
|
-
if (buffer.slice) {
|
|
1887
|
-
return buffer.slice(begin, end);
|
|
1888
|
-
}
|
|
1889
|
-
const length = end - begin;
|
|
1890
|
-
const slice = new ArrayBuffer(length);
|
|
1891
|
-
CopyDataBlockBytes(slice, 0, buffer, begin, length);
|
|
1892
|
-
return slice;
|
|
1893
|
-
}
|
|
1894
|
-
|
|
1895
|
-
function IsNonNegativeNumber(v) {
|
|
1896
|
-
if (typeof v !== 'number') {
|
|
1897
|
-
return false;
|
|
1898
|
-
}
|
|
1899
|
-
if (NumberIsNaN(v)) {
|
|
1900
|
-
return false;
|
|
1901
|
-
}
|
|
1902
|
-
if (v < 0) {
|
|
1903
|
-
return false;
|
|
1904
|
-
}
|
|
1905
|
-
return true;
|
|
1906
|
-
}
|
|
1907
|
-
function CloneAsUint8Array(O) {
|
|
1908
|
-
const buffer = ArrayBufferSlice(O.buffer, O.byteOffset, O.byteOffset + O.byteLength);
|
|
1909
|
-
return new Uint8Array(buffer);
|
|
1910
|
-
}
|
|
1911
|
-
|
|
1912
|
-
function DequeueValue(container) {
|
|
1913
|
-
const pair = container._queue.shift();
|
|
1914
|
-
container._queueTotalSize -= pair.size;
|
|
1915
|
-
if (container._queueTotalSize < 0) {
|
|
1916
|
-
container._queueTotalSize = 0;
|
|
1917
|
-
}
|
|
1918
|
-
return pair.value;
|
|
1919
|
-
}
|
|
1920
|
-
function EnqueueValueWithSize(container, value, size) {
|
|
1921
|
-
if (!IsNonNegativeNumber(size) || size === Infinity) {
|
|
1922
|
-
throw new RangeError('Size must be a finite, non-NaN, non-negative number.');
|
|
1923
|
-
}
|
|
1924
|
-
container._queue.push({ value, size });
|
|
1925
|
-
container._queueTotalSize += size;
|
|
1926
|
-
}
|
|
1927
|
-
function PeekQueueValue(container) {
|
|
1928
|
-
const pair = container._queue.peek();
|
|
1929
|
-
return pair.value;
|
|
1930
|
-
}
|
|
1931
|
-
function ResetQueue(container) {
|
|
1932
|
-
container._queue = new SimpleQueue();
|
|
1933
|
-
container._queueTotalSize = 0;
|
|
1934
|
-
}
|
|
1935
|
-
|
|
1936
|
-
/**
|
|
1937
|
-
* A pull-into request in a {@link ReadableByteStreamController}.
|
|
1938
|
-
*
|
|
1939
|
-
* @public
|
|
1940
|
-
*/
|
|
1941
|
-
class ReadableStreamBYOBRequest {
|
|
1942
|
-
constructor() {
|
|
1943
|
-
throw new TypeError('Illegal constructor');
|
|
1944
|
-
}
|
|
1945
|
-
/**
|
|
1946
|
-
* Returns the view for writing in to, or `null` if the BYOB request has already been responded to.
|
|
1947
|
-
*/
|
|
1948
|
-
get view() {
|
|
1949
|
-
if (!IsReadableStreamBYOBRequest(this)) {
|
|
1950
|
-
throw byobRequestBrandCheckException('view');
|
|
1951
|
-
}
|
|
1952
|
-
return this._view;
|
|
1953
|
-
}
|
|
1954
|
-
respond(bytesWritten) {
|
|
1955
|
-
if (!IsReadableStreamBYOBRequest(this)) {
|
|
1956
|
-
throw byobRequestBrandCheckException('respond');
|
|
1957
|
-
}
|
|
1958
|
-
assertRequiredArgument(bytesWritten, 1, 'respond');
|
|
1959
|
-
bytesWritten = convertUnsignedLongLongWithEnforceRange(bytesWritten, 'First parameter');
|
|
1960
|
-
if (this._associatedReadableByteStreamController === undefined) {
|
|
1961
|
-
throw new TypeError('This BYOB request has been invalidated');
|
|
1962
|
-
}
|
|
1963
|
-
if (IsDetachedBuffer(this._view.buffer)) ;
|
|
1964
|
-
ReadableByteStreamControllerRespond(this._associatedReadableByteStreamController, bytesWritten);
|
|
1965
|
-
}
|
|
1966
|
-
respondWithNewView(view) {
|
|
1967
|
-
if (!IsReadableStreamBYOBRequest(this)) {
|
|
1968
|
-
throw byobRequestBrandCheckException('respondWithNewView');
|
|
1969
|
-
}
|
|
1970
|
-
assertRequiredArgument(view, 1, 'respondWithNewView');
|
|
1971
|
-
if (!ArrayBuffer.isView(view)) {
|
|
1972
|
-
throw new TypeError('You can only respond with array buffer views');
|
|
1973
|
-
}
|
|
1974
|
-
if (this._associatedReadableByteStreamController === undefined) {
|
|
1975
|
-
throw new TypeError('This BYOB request has been invalidated');
|
|
1976
|
-
}
|
|
1977
|
-
if (IsDetachedBuffer(view.buffer)) ;
|
|
1978
|
-
ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view);
|
|
1979
|
-
}
|
|
1980
|
-
}
|
|
1981
|
-
Object.defineProperties(ReadableStreamBYOBRequest.prototype, {
|
|
1982
|
-
respond: { enumerable: true },
|
|
1983
|
-
respondWithNewView: { enumerable: true },
|
|
1984
|
-
view: { enumerable: true }
|
|
1985
|
-
});
|
|
1986
|
-
/**
|
|
1987
|
-
* Allows control of a {@link ReadableStream | readable byte stream}'s state and internal queue.
|
|
1988
|
-
*
|
|
1989
|
-
* @public
|
|
1990
|
-
*/
|
|
1991
|
-
class ReadableByteStreamController {
|
|
1992
|
-
constructor() {
|
|
1993
|
-
throw new TypeError('Illegal constructor');
|
|
1994
|
-
}
|
|
1995
|
-
/**
|
|
1996
|
-
* Returns the current BYOB pull request, or `null` if there isn't one.
|
|
1997
|
-
*/
|
|
1998
|
-
get byobRequest() {
|
|
1999
|
-
if (!IsReadableByteStreamController(this)) {
|
|
2000
|
-
throw byteStreamControllerBrandCheckException('byobRequest');
|
|
2001
|
-
}
|
|
2002
|
-
return ReadableByteStreamControllerGetBYOBRequest(this);
|
|
2003
|
-
}
|
|
2004
|
-
/**
|
|
2005
|
-
* Returns the desired size to fill the controlled stream's internal queue. It can be negative, if the queue is
|
|
2006
|
-
* over-full. An underlying byte source ought to use this information to determine when and how to apply backpressure.
|
|
2007
|
-
*/
|
|
2008
|
-
get desiredSize() {
|
|
2009
|
-
if (!IsReadableByteStreamController(this)) {
|
|
2010
|
-
throw byteStreamControllerBrandCheckException('desiredSize');
|
|
2011
|
-
}
|
|
2012
|
-
return ReadableByteStreamControllerGetDesiredSize(this);
|
|
2013
|
-
}
|
|
2014
|
-
/**
|
|
2015
|
-
* Closes the controlled readable stream. Consumers will still be able to read any previously-enqueued chunks from
|
|
2016
|
-
* the stream, but once those are read, the stream will become closed.
|
|
2017
|
-
*/
|
|
2018
|
-
close() {
|
|
2019
|
-
if (!IsReadableByteStreamController(this)) {
|
|
2020
|
-
throw byteStreamControllerBrandCheckException('close');
|
|
2021
|
-
}
|
|
2022
|
-
if (this._closeRequested) {
|
|
2023
|
-
throw new TypeError('The stream has already been closed; do not close it again!');
|
|
2024
|
-
}
|
|
2025
|
-
const state = this._controlledReadableByteStream._state;
|
|
2026
|
-
if (state !== 'readable') {
|
|
2027
|
-
throw new TypeError(`The stream (in ${state} state) is not in the readable state and cannot be closed`);
|
|
2028
|
-
}
|
|
2029
|
-
ReadableByteStreamControllerClose(this);
|
|
2030
|
-
}
|
|
2031
|
-
enqueue(chunk) {
|
|
2032
|
-
if (!IsReadableByteStreamController(this)) {
|
|
2033
|
-
throw byteStreamControllerBrandCheckException('enqueue');
|
|
2034
|
-
}
|
|
2035
|
-
assertRequiredArgument(chunk, 1, 'enqueue');
|
|
2036
|
-
if (!ArrayBuffer.isView(chunk)) {
|
|
2037
|
-
throw new TypeError('chunk must be an array buffer view');
|
|
2038
|
-
}
|
|
2039
|
-
if (chunk.byteLength === 0) {
|
|
2040
|
-
throw new TypeError('chunk must have non-zero byteLength');
|
|
2041
|
-
}
|
|
2042
|
-
if (chunk.buffer.byteLength === 0) {
|
|
2043
|
-
throw new TypeError(`chunk's buffer must have non-zero byteLength`);
|
|
2044
|
-
}
|
|
2045
|
-
if (this._closeRequested) {
|
|
2046
|
-
throw new TypeError('stream is closed or draining');
|
|
2047
|
-
}
|
|
2048
|
-
const state = this._controlledReadableByteStream._state;
|
|
2049
|
-
if (state !== 'readable') {
|
|
2050
|
-
throw new TypeError(`The stream (in ${state} state) is not in the readable state and cannot be enqueued to`);
|
|
2051
|
-
}
|
|
2052
|
-
ReadableByteStreamControllerEnqueue(this, chunk);
|
|
2053
|
-
}
|
|
2054
|
-
/**
|
|
2055
|
-
* Errors the controlled readable stream, making all future interactions with it fail with the given error `e`.
|
|
2056
|
-
*/
|
|
2057
|
-
error(e = undefined) {
|
|
2058
|
-
if (!IsReadableByteStreamController(this)) {
|
|
2059
|
-
throw byteStreamControllerBrandCheckException('error');
|
|
2060
|
-
}
|
|
2061
|
-
ReadableByteStreamControllerError(this, e);
|
|
2062
|
-
}
|
|
2063
|
-
/** @internal */
|
|
2064
|
-
[CancelSteps](reason) {
|
|
2065
|
-
ReadableByteStreamControllerClearPendingPullIntos(this);
|
|
2066
|
-
ResetQueue(this);
|
|
2067
|
-
const result = this._cancelAlgorithm(reason);
|
|
2068
|
-
ReadableByteStreamControllerClearAlgorithms(this);
|
|
2069
|
-
return result;
|
|
2070
|
-
}
|
|
2071
|
-
/** @internal */
|
|
2072
|
-
[PullSteps](readRequest) {
|
|
2073
|
-
const stream = this._controlledReadableByteStream;
|
|
2074
|
-
if (this._queueTotalSize > 0) {
|
|
2075
|
-
const entry = this._queue.shift();
|
|
2076
|
-
this._queueTotalSize -= entry.byteLength;
|
|
2077
|
-
ReadableByteStreamControllerHandleQueueDrain(this);
|
|
2078
|
-
const view = new Uint8Array(entry.buffer, entry.byteOffset, entry.byteLength);
|
|
2079
|
-
readRequest._chunkSteps(view);
|
|
2080
|
-
return;
|
|
2081
|
-
}
|
|
2082
|
-
const autoAllocateChunkSize = this._autoAllocateChunkSize;
|
|
2083
|
-
if (autoAllocateChunkSize !== undefined) {
|
|
2084
|
-
let buffer;
|
|
2085
|
-
try {
|
|
2086
|
-
buffer = new ArrayBuffer(autoAllocateChunkSize);
|
|
2087
|
-
}
|
|
2088
|
-
catch (bufferE) {
|
|
2089
|
-
readRequest._errorSteps(bufferE);
|
|
2090
|
-
return;
|
|
2091
|
-
}
|
|
2092
|
-
const pullIntoDescriptor = {
|
|
2093
|
-
buffer,
|
|
2094
|
-
bufferByteLength: autoAllocateChunkSize,
|
|
2095
|
-
byteOffset: 0,
|
|
2096
|
-
byteLength: autoAllocateChunkSize,
|
|
2097
|
-
bytesFilled: 0,
|
|
2098
|
-
elementSize: 1,
|
|
2099
|
-
viewConstructor: Uint8Array,
|
|
2100
|
-
readerType: 'default'
|
|
2101
|
-
};
|
|
2102
|
-
this._pendingPullIntos.push(pullIntoDescriptor);
|
|
2103
|
-
}
|
|
2104
|
-
ReadableStreamAddReadRequest(stream, readRequest);
|
|
2105
|
-
ReadableByteStreamControllerCallPullIfNeeded(this);
|
|
2106
|
-
}
|
|
2107
|
-
}
|
|
2108
|
-
Object.defineProperties(ReadableByteStreamController.prototype, {
|
|
2109
|
-
close: { enumerable: true },
|
|
2110
|
-
enqueue: { enumerable: true },
|
|
2111
|
-
error: { enumerable: true },
|
|
2112
|
-
byobRequest: { enumerable: true },
|
|
2113
|
-
desiredSize: { enumerable: true }
|
|
2114
|
-
});
|
|
2115
|
-
// Abstract operations for the ReadableByteStreamController.
|
|
2116
|
-
function IsReadableByteStreamController(x) {
|
|
2117
|
-
if (!typeIsObject(x)) {
|
|
2118
|
-
return false;
|
|
2119
|
-
}
|
|
2120
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_controlledReadableByteStream')) {
|
|
2121
|
-
return false;
|
|
2122
|
-
}
|
|
2123
|
-
return x instanceof ReadableByteStreamController;
|
|
2124
|
-
}
|
|
2125
|
-
function IsReadableStreamBYOBRequest(x) {
|
|
2126
|
-
if (!typeIsObject(x)) {
|
|
2127
|
-
return false;
|
|
2128
|
-
}
|
|
2129
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_associatedReadableByteStreamController')) {
|
|
2130
|
-
return false;
|
|
2131
|
-
}
|
|
2132
|
-
return x instanceof ReadableStreamBYOBRequest;
|
|
2133
|
-
}
|
|
2134
|
-
function ReadableByteStreamControllerCallPullIfNeeded(controller) {
|
|
2135
|
-
const shouldPull = ReadableByteStreamControllerShouldCallPull(controller);
|
|
2136
|
-
if (!shouldPull) {
|
|
2137
|
-
return;
|
|
2138
|
-
}
|
|
2139
|
-
if (controller._pulling) {
|
|
2140
|
-
controller._pullAgain = true;
|
|
2141
|
-
return;
|
|
2142
|
-
}
|
|
2143
|
-
controller._pulling = true;
|
|
2144
|
-
// TODO: Test controller argument
|
|
2145
|
-
const pullPromise = controller._pullAlgorithm();
|
|
2146
|
-
uponPromise(pullPromise, () => {
|
|
2147
|
-
controller._pulling = false;
|
|
2148
|
-
if (controller._pullAgain) {
|
|
2149
|
-
controller._pullAgain = false;
|
|
2150
|
-
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
2151
|
-
}
|
|
2152
|
-
}, e => {
|
|
2153
|
-
ReadableByteStreamControllerError(controller, e);
|
|
2154
|
-
});
|
|
2155
|
-
}
|
|
2156
|
-
function ReadableByteStreamControllerClearPendingPullIntos(controller) {
|
|
2157
|
-
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
2158
|
-
controller._pendingPullIntos = new SimpleQueue();
|
|
2159
|
-
}
|
|
2160
|
-
function ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor) {
|
|
2161
|
-
let done = false;
|
|
2162
|
-
if (stream._state === 'closed') {
|
|
2163
|
-
done = true;
|
|
2164
|
-
}
|
|
2165
|
-
const filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor);
|
|
2166
|
-
if (pullIntoDescriptor.readerType === 'default') {
|
|
2167
|
-
ReadableStreamFulfillReadRequest(stream, filledView, done);
|
|
2168
|
-
}
|
|
2169
|
-
else {
|
|
2170
|
-
ReadableStreamFulfillReadIntoRequest(stream, filledView, done);
|
|
2171
|
-
}
|
|
2172
|
-
}
|
|
2173
|
-
function ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor) {
|
|
2174
|
-
const bytesFilled = pullIntoDescriptor.bytesFilled;
|
|
2175
|
-
const elementSize = pullIntoDescriptor.elementSize;
|
|
2176
|
-
return new pullIntoDescriptor.viewConstructor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, bytesFilled / elementSize);
|
|
2177
|
-
}
|
|
2178
|
-
function ReadableByteStreamControllerEnqueueChunkToQueue(controller, buffer, byteOffset, byteLength) {
|
|
2179
|
-
controller._queue.push({ buffer, byteOffset, byteLength });
|
|
2180
|
-
controller._queueTotalSize += byteLength;
|
|
2181
|
-
}
|
|
2182
|
-
function ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) {
|
|
2183
|
-
const elementSize = pullIntoDescriptor.elementSize;
|
|
2184
|
-
const currentAlignedBytes = pullIntoDescriptor.bytesFilled - pullIntoDescriptor.bytesFilled % elementSize;
|
|
2185
|
-
const maxBytesToCopy = Math.min(controller._queueTotalSize, pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled);
|
|
2186
|
-
const maxBytesFilled = pullIntoDescriptor.bytesFilled + maxBytesToCopy;
|
|
2187
|
-
const maxAlignedBytes = maxBytesFilled - maxBytesFilled % elementSize;
|
|
2188
|
-
let totalBytesToCopyRemaining = maxBytesToCopy;
|
|
2189
|
-
let ready = false;
|
|
2190
|
-
if (maxAlignedBytes > currentAlignedBytes) {
|
|
2191
|
-
totalBytesToCopyRemaining = maxAlignedBytes - pullIntoDescriptor.bytesFilled;
|
|
2192
|
-
ready = true;
|
|
2193
|
-
}
|
|
2194
|
-
const queue = controller._queue;
|
|
2195
|
-
while (totalBytesToCopyRemaining > 0) {
|
|
2196
|
-
const headOfQueue = queue.peek();
|
|
2197
|
-
const bytesToCopy = Math.min(totalBytesToCopyRemaining, headOfQueue.byteLength);
|
|
2198
|
-
const destStart = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;
|
|
2199
|
-
CopyDataBlockBytes(pullIntoDescriptor.buffer, destStart, headOfQueue.buffer, headOfQueue.byteOffset, bytesToCopy);
|
|
2200
|
-
if (headOfQueue.byteLength === bytesToCopy) {
|
|
2201
|
-
queue.shift();
|
|
2202
|
-
}
|
|
2203
|
-
else {
|
|
2204
|
-
headOfQueue.byteOffset += bytesToCopy;
|
|
2205
|
-
headOfQueue.byteLength -= bytesToCopy;
|
|
2206
|
-
}
|
|
2207
|
-
controller._queueTotalSize -= bytesToCopy;
|
|
2208
|
-
ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesToCopy, pullIntoDescriptor);
|
|
2209
|
-
totalBytesToCopyRemaining -= bytesToCopy;
|
|
2210
|
-
}
|
|
2211
|
-
return ready;
|
|
2212
|
-
}
|
|
2213
|
-
function ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, size, pullIntoDescriptor) {
|
|
2214
|
-
pullIntoDescriptor.bytesFilled += size;
|
|
2215
|
-
}
|
|
2216
|
-
function ReadableByteStreamControllerHandleQueueDrain(controller) {
|
|
2217
|
-
if (controller._queueTotalSize === 0 && controller._closeRequested) {
|
|
2218
|
-
ReadableByteStreamControllerClearAlgorithms(controller);
|
|
2219
|
-
ReadableStreamClose(controller._controlledReadableByteStream);
|
|
2220
|
-
}
|
|
2221
|
-
else {
|
|
2222
|
-
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
2223
|
-
}
|
|
2224
|
-
}
|
|
2225
|
-
function ReadableByteStreamControllerInvalidateBYOBRequest(controller) {
|
|
2226
|
-
if (controller._byobRequest === null) {
|
|
2227
|
-
return;
|
|
2228
|
-
}
|
|
2229
|
-
controller._byobRequest._associatedReadableByteStreamController = undefined;
|
|
2230
|
-
controller._byobRequest._view = null;
|
|
2231
|
-
controller._byobRequest = null;
|
|
2232
|
-
}
|
|
2233
|
-
function ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller) {
|
|
2234
|
-
while (controller._pendingPullIntos.length > 0) {
|
|
2235
|
-
if (controller._queueTotalSize === 0) {
|
|
2236
|
-
return;
|
|
2237
|
-
}
|
|
2238
|
-
const pullIntoDescriptor = controller._pendingPullIntos.peek();
|
|
2239
|
-
if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor)) {
|
|
2240
|
-
ReadableByteStreamControllerShiftPendingPullInto(controller);
|
|
2241
|
-
ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableByteStream, pullIntoDescriptor);
|
|
2242
|
-
}
|
|
2243
|
-
}
|
|
2244
|
-
}
|
|
2245
|
-
function ReadableByteStreamControllerPullInto(controller, view, readIntoRequest) {
|
|
2246
|
-
const stream = controller._controlledReadableByteStream;
|
|
2247
|
-
let elementSize = 1;
|
|
2248
|
-
if (view.constructor !== DataView) {
|
|
2249
|
-
elementSize = view.constructor.BYTES_PER_ELEMENT;
|
|
2250
|
-
}
|
|
2251
|
-
const ctor = view.constructor;
|
|
2252
|
-
// try {
|
|
2253
|
-
const buffer = TransferArrayBuffer(view.buffer);
|
|
2254
|
-
// } catch (e) {
|
|
2255
|
-
// readIntoRequest._errorSteps(e);
|
|
2256
|
-
// return;
|
|
2257
|
-
// }
|
|
2258
|
-
const pullIntoDescriptor = {
|
|
2259
|
-
buffer,
|
|
2260
|
-
bufferByteLength: buffer.byteLength,
|
|
2261
|
-
byteOffset: view.byteOffset,
|
|
2262
|
-
byteLength: view.byteLength,
|
|
2263
|
-
bytesFilled: 0,
|
|
2264
|
-
elementSize,
|
|
2265
|
-
viewConstructor: ctor,
|
|
2266
|
-
readerType: 'byob'
|
|
2267
|
-
};
|
|
2268
|
-
if (controller._pendingPullIntos.length > 0) {
|
|
2269
|
-
controller._pendingPullIntos.push(pullIntoDescriptor);
|
|
2270
|
-
// No ReadableByteStreamControllerCallPullIfNeeded() call since:
|
|
2271
|
-
// - No change happens on desiredSize
|
|
2272
|
-
// - The source has already been notified of that there's at least 1 pending read(view)
|
|
2273
|
-
ReadableStreamAddReadIntoRequest(stream, readIntoRequest);
|
|
2274
|
-
return;
|
|
2275
|
-
}
|
|
2276
|
-
if (stream._state === 'closed') {
|
|
2277
|
-
const emptyView = new ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, 0);
|
|
2278
|
-
readIntoRequest._closeSteps(emptyView);
|
|
2279
|
-
return;
|
|
2280
|
-
}
|
|
2281
|
-
if (controller._queueTotalSize > 0) {
|
|
2282
|
-
if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor)) {
|
|
2283
|
-
const filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor);
|
|
2284
|
-
ReadableByteStreamControllerHandleQueueDrain(controller);
|
|
2285
|
-
readIntoRequest._chunkSteps(filledView);
|
|
2286
|
-
return;
|
|
2287
|
-
}
|
|
2288
|
-
if (controller._closeRequested) {
|
|
2289
|
-
const e = new TypeError('Insufficient bytes to fill elements in the given buffer');
|
|
2290
|
-
ReadableByteStreamControllerError(controller, e);
|
|
2291
|
-
readIntoRequest._errorSteps(e);
|
|
2292
|
-
return;
|
|
2293
|
-
}
|
|
2294
|
-
}
|
|
2295
|
-
controller._pendingPullIntos.push(pullIntoDescriptor);
|
|
2296
|
-
ReadableStreamAddReadIntoRequest(stream, readIntoRequest);
|
|
2297
|
-
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
2298
|
-
}
|
|
2299
|
-
function ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor) {
|
|
2300
|
-
const stream = controller._controlledReadableByteStream;
|
|
2301
|
-
if (ReadableStreamHasBYOBReader(stream)) {
|
|
2302
|
-
while (ReadableStreamGetNumReadIntoRequests(stream) > 0) {
|
|
2303
|
-
const pullIntoDescriptor = ReadableByteStreamControllerShiftPendingPullInto(controller);
|
|
2304
|
-
ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor);
|
|
2305
|
-
}
|
|
2306
|
-
}
|
|
2307
|
-
}
|
|
2308
|
-
function ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor) {
|
|
2309
|
-
ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesWritten, pullIntoDescriptor);
|
|
2310
|
-
if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize) {
|
|
2311
|
-
return;
|
|
2312
|
-
}
|
|
2313
|
-
ReadableByteStreamControllerShiftPendingPullInto(controller);
|
|
2314
|
-
const remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize;
|
|
2315
|
-
if (remainderSize > 0) {
|
|
2316
|
-
const end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;
|
|
2317
|
-
const remainder = ArrayBufferSlice(pullIntoDescriptor.buffer, end - remainderSize, end);
|
|
2318
|
-
ReadableByteStreamControllerEnqueueChunkToQueue(controller, remainder, 0, remainder.byteLength);
|
|
2319
|
-
}
|
|
2320
|
-
pullIntoDescriptor.bytesFilled -= remainderSize;
|
|
2321
|
-
ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableByteStream, pullIntoDescriptor);
|
|
2322
|
-
ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);
|
|
2323
|
-
}
|
|
2324
|
-
function ReadableByteStreamControllerRespondInternal(controller, bytesWritten) {
|
|
2325
|
-
const firstDescriptor = controller._pendingPullIntos.peek();
|
|
2326
|
-
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
2327
|
-
const state = controller._controlledReadableByteStream._state;
|
|
2328
|
-
if (state === 'closed') {
|
|
2329
|
-
ReadableByteStreamControllerRespondInClosedState(controller);
|
|
2330
|
-
}
|
|
2331
|
-
else {
|
|
2332
|
-
ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor);
|
|
2333
|
-
}
|
|
2334
|
-
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
2335
|
-
}
|
|
2336
|
-
function ReadableByteStreamControllerShiftPendingPullInto(controller) {
|
|
2337
|
-
const descriptor = controller._pendingPullIntos.shift();
|
|
2338
|
-
return descriptor;
|
|
2339
|
-
}
|
|
2340
|
-
function ReadableByteStreamControllerShouldCallPull(controller) {
|
|
2341
|
-
const stream = controller._controlledReadableByteStream;
|
|
2342
|
-
if (stream._state !== 'readable') {
|
|
2343
|
-
return false;
|
|
2344
|
-
}
|
|
2345
|
-
if (controller._closeRequested) {
|
|
2346
|
-
return false;
|
|
2347
|
-
}
|
|
2348
|
-
if (!controller._started) {
|
|
2349
|
-
return false;
|
|
2350
|
-
}
|
|
2351
|
-
if (ReadableStreamHasDefaultReader(stream) && ReadableStreamGetNumReadRequests(stream) > 0) {
|
|
2352
|
-
return true;
|
|
2353
|
-
}
|
|
2354
|
-
if (ReadableStreamHasBYOBReader(stream) && ReadableStreamGetNumReadIntoRequests(stream) > 0) {
|
|
2355
|
-
return true;
|
|
2356
|
-
}
|
|
2357
|
-
const desiredSize = ReadableByteStreamControllerGetDesiredSize(controller);
|
|
2358
|
-
if (desiredSize > 0) {
|
|
2359
|
-
return true;
|
|
2360
|
-
}
|
|
2361
|
-
return false;
|
|
2362
|
-
}
|
|
2363
|
-
function ReadableByteStreamControllerClearAlgorithms(controller) {
|
|
2364
|
-
controller._pullAlgorithm = undefined;
|
|
2365
|
-
controller._cancelAlgorithm = undefined;
|
|
2366
|
-
}
|
|
2367
|
-
// A client of ReadableByteStreamController may use these functions directly to bypass state check.
|
|
2368
|
-
function ReadableByteStreamControllerClose(controller) {
|
|
2369
|
-
const stream = controller._controlledReadableByteStream;
|
|
2370
|
-
if (controller._closeRequested || stream._state !== 'readable') {
|
|
2371
|
-
return;
|
|
2372
|
-
}
|
|
2373
|
-
if (controller._queueTotalSize > 0) {
|
|
2374
|
-
controller._closeRequested = true;
|
|
2375
|
-
return;
|
|
2376
|
-
}
|
|
2377
|
-
if (controller._pendingPullIntos.length > 0) {
|
|
2378
|
-
const firstPendingPullInto = controller._pendingPullIntos.peek();
|
|
2379
|
-
if (firstPendingPullInto.bytesFilled > 0) {
|
|
2380
|
-
const e = new TypeError('Insufficient bytes to fill elements in the given buffer');
|
|
2381
|
-
ReadableByteStreamControllerError(controller, e);
|
|
2382
|
-
throw e;
|
|
2383
|
-
}
|
|
2384
|
-
}
|
|
2385
|
-
ReadableByteStreamControllerClearAlgorithms(controller);
|
|
2386
|
-
ReadableStreamClose(stream);
|
|
2387
|
-
}
|
|
2388
|
-
function ReadableByteStreamControllerEnqueue(controller, chunk) {
|
|
2389
|
-
const stream = controller._controlledReadableByteStream;
|
|
2390
|
-
if (controller._closeRequested || stream._state !== 'readable') {
|
|
2391
|
-
return;
|
|
2392
|
-
}
|
|
2393
|
-
const buffer = chunk.buffer;
|
|
2394
|
-
const byteOffset = chunk.byteOffset;
|
|
2395
|
-
const byteLength = chunk.byteLength;
|
|
2396
|
-
const transferredBuffer = TransferArrayBuffer(buffer);
|
|
2397
|
-
if (controller._pendingPullIntos.length > 0) {
|
|
2398
|
-
const firstPendingPullInto = controller._pendingPullIntos.peek();
|
|
2399
|
-
if (IsDetachedBuffer(firstPendingPullInto.buffer)) ;
|
|
2400
|
-
firstPendingPullInto.buffer = TransferArrayBuffer(firstPendingPullInto.buffer);
|
|
2401
|
-
}
|
|
2402
|
-
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
2403
|
-
if (ReadableStreamHasDefaultReader(stream)) {
|
|
2404
|
-
if (ReadableStreamGetNumReadRequests(stream) === 0) {
|
|
2405
|
-
ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
|
|
2406
|
-
}
|
|
2407
|
-
else {
|
|
2408
|
-
if (controller._pendingPullIntos.length > 0) {
|
|
2409
|
-
ReadableByteStreamControllerShiftPendingPullInto(controller);
|
|
2410
|
-
}
|
|
2411
|
-
const transferredView = new Uint8Array(transferredBuffer, byteOffset, byteLength);
|
|
2412
|
-
ReadableStreamFulfillReadRequest(stream, transferredView, false);
|
|
2413
|
-
}
|
|
2414
|
-
}
|
|
2415
|
-
else if (ReadableStreamHasBYOBReader(stream)) {
|
|
2416
|
-
// TODO: Ideally in this branch detaching should happen only if the buffer is not consumed fully.
|
|
2417
|
-
ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
|
|
2418
|
-
ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);
|
|
2419
|
-
}
|
|
2420
|
-
else {
|
|
2421
|
-
ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
|
|
2422
|
-
}
|
|
2423
|
-
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
2424
|
-
}
|
|
2425
|
-
function ReadableByteStreamControllerError(controller, e) {
|
|
2426
|
-
const stream = controller._controlledReadableByteStream;
|
|
2427
|
-
if (stream._state !== 'readable') {
|
|
2428
|
-
return;
|
|
2429
|
-
}
|
|
2430
|
-
ReadableByteStreamControllerClearPendingPullIntos(controller);
|
|
2431
|
-
ResetQueue(controller);
|
|
2432
|
-
ReadableByteStreamControllerClearAlgorithms(controller);
|
|
2433
|
-
ReadableStreamError(stream, e);
|
|
2434
|
-
}
|
|
2435
|
-
function ReadableByteStreamControllerGetBYOBRequest(controller) {
|
|
2436
|
-
if (controller._byobRequest === null && controller._pendingPullIntos.length > 0) {
|
|
2437
|
-
const firstDescriptor = controller._pendingPullIntos.peek();
|
|
2438
|
-
const view = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled);
|
|
2439
|
-
const byobRequest = Object.create(ReadableStreamBYOBRequest.prototype);
|
|
2440
|
-
SetUpReadableStreamBYOBRequest(byobRequest, controller, view);
|
|
2441
|
-
controller._byobRequest = byobRequest;
|
|
2442
|
-
}
|
|
2443
|
-
return controller._byobRequest;
|
|
2444
|
-
}
|
|
2445
|
-
function ReadableByteStreamControllerGetDesiredSize(controller) {
|
|
2446
|
-
const state = controller._controlledReadableByteStream._state;
|
|
2447
|
-
if (state === 'errored') {
|
|
2448
|
-
return null;
|
|
2449
|
-
}
|
|
2450
|
-
if (state === 'closed') {
|
|
2451
|
-
return 0;
|
|
2452
|
-
}
|
|
2453
|
-
return controller._strategyHWM - controller._queueTotalSize;
|
|
2454
|
-
}
|
|
2455
|
-
function ReadableByteStreamControllerRespond(controller, bytesWritten) {
|
|
2456
|
-
const firstDescriptor = controller._pendingPullIntos.peek();
|
|
2457
|
-
const state = controller._controlledReadableByteStream._state;
|
|
2458
|
-
if (state === 'closed') {
|
|
2459
|
-
if (bytesWritten !== 0) {
|
|
2460
|
-
throw new TypeError('bytesWritten must be 0 when calling respond() on a closed stream');
|
|
2461
|
-
}
|
|
2462
|
-
}
|
|
2463
|
-
else {
|
|
2464
|
-
if (bytesWritten === 0) {
|
|
2465
|
-
throw new TypeError('bytesWritten must be greater than 0 when calling respond() on a readable stream');
|
|
2466
|
-
}
|
|
2467
|
-
if (firstDescriptor.bytesFilled + bytesWritten > firstDescriptor.byteLength) {
|
|
2468
|
-
throw new RangeError('bytesWritten out of range');
|
|
2469
|
-
}
|
|
2470
|
-
}
|
|
2471
|
-
firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer);
|
|
2472
|
-
ReadableByteStreamControllerRespondInternal(controller, bytesWritten);
|
|
2473
|
-
}
|
|
2474
|
-
function ReadableByteStreamControllerRespondWithNewView(controller, view) {
|
|
2475
|
-
const firstDescriptor = controller._pendingPullIntos.peek();
|
|
2476
|
-
const state = controller._controlledReadableByteStream._state;
|
|
2477
|
-
if (state === 'closed') {
|
|
2478
|
-
if (view.byteLength !== 0) {
|
|
2479
|
-
throw new TypeError('The view\'s length must be 0 when calling respondWithNewView() on a closed stream');
|
|
2480
|
-
}
|
|
2481
|
-
}
|
|
2482
|
-
else {
|
|
2483
|
-
if (view.byteLength === 0) {
|
|
2484
|
-
throw new TypeError('The view\'s length must be greater than 0 when calling respondWithNewView() on a readable stream');
|
|
2485
|
-
}
|
|
2486
|
-
}
|
|
2487
|
-
if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) {
|
|
2488
|
-
throw new RangeError('The region specified by view does not match byobRequest');
|
|
2489
|
-
}
|
|
2490
|
-
if (firstDescriptor.bufferByteLength !== view.buffer.byteLength) {
|
|
2491
|
-
throw new RangeError('The buffer of view has different capacity than byobRequest');
|
|
2492
|
-
}
|
|
2493
|
-
if (firstDescriptor.bytesFilled + view.byteLength > firstDescriptor.byteLength) {
|
|
2494
|
-
throw new RangeError('The region specified by view is larger than byobRequest');
|
|
2495
|
-
}
|
|
2496
|
-
const viewByteLength = view.byteLength;
|
|
2497
|
-
firstDescriptor.buffer = TransferArrayBuffer(view.buffer);
|
|
2498
|
-
ReadableByteStreamControllerRespondInternal(controller, viewByteLength);
|
|
2499
|
-
}
|
|
2500
|
-
function SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize) {
|
|
2501
|
-
controller._controlledReadableByteStream = stream;
|
|
2502
|
-
controller._pullAgain = false;
|
|
2503
|
-
controller._pulling = false;
|
|
2504
|
-
controller._byobRequest = null;
|
|
2505
|
-
// Need to set the slots so that the assert doesn't fire. In the spec the slots already exist implicitly.
|
|
2506
|
-
controller._queue = controller._queueTotalSize = undefined;
|
|
2507
|
-
ResetQueue(controller);
|
|
2508
|
-
controller._closeRequested = false;
|
|
2509
|
-
controller._started = false;
|
|
2510
|
-
controller._strategyHWM = highWaterMark;
|
|
2511
|
-
controller._pullAlgorithm = pullAlgorithm;
|
|
2512
|
-
controller._cancelAlgorithm = cancelAlgorithm;
|
|
2513
|
-
controller._autoAllocateChunkSize = autoAllocateChunkSize;
|
|
2514
|
-
controller._pendingPullIntos = new SimpleQueue();
|
|
2515
|
-
stream._readableStreamController = controller;
|
|
2516
|
-
const startResult = startAlgorithm();
|
|
2517
|
-
uponPromise(promiseResolvedWith(startResult), () => {
|
|
2518
|
-
controller._started = true;
|
|
2519
|
-
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
2520
|
-
}, r => {
|
|
2521
|
-
ReadableByteStreamControllerError(controller, r);
|
|
2522
|
-
});
|
|
2523
|
-
}
|
|
2524
|
-
function SetUpReadableByteStreamControllerFromUnderlyingSource(stream, underlyingByteSource, highWaterMark) {
|
|
2525
|
-
const controller = Object.create(ReadableByteStreamController.prototype);
|
|
2526
|
-
let startAlgorithm = () => undefined;
|
|
2527
|
-
let pullAlgorithm = () => promiseResolvedWith(undefined);
|
|
2528
|
-
let cancelAlgorithm = () => promiseResolvedWith(undefined);
|
|
2529
|
-
if (underlyingByteSource.start !== undefined) {
|
|
2530
|
-
startAlgorithm = () => underlyingByteSource.start(controller);
|
|
2531
|
-
}
|
|
2532
|
-
if (underlyingByteSource.pull !== undefined) {
|
|
2533
|
-
pullAlgorithm = () => underlyingByteSource.pull(controller);
|
|
2534
|
-
}
|
|
2535
|
-
if (underlyingByteSource.cancel !== undefined) {
|
|
2536
|
-
cancelAlgorithm = reason => underlyingByteSource.cancel(reason);
|
|
2537
|
-
}
|
|
2538
|
-
const autoAllocateChunkSize = underlyingByteSource.autoAllocateChunkSize;
|
|
2539
|
-
if (autoAllocateChunkSize === 0) {
|
|
2540
|
-
throw new TypeError('autoAllocateChunkSize must be greater than 0');
|
|
2541
|
-
}
|
|
2542
|
-
SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize);
|
|
2543
|
-
}
|
|
2544
|
-
function SetUpReadableStreamBYOBRequest(request, controller, view) {
|
|
2545
|
-
request._associatedReadableByteStreamController = controller;
|
|
2546
|
-
request._view = view;
|
|
2547
|
-
}
|
|
2548
|
-
// Helper functions for the ReadableStreamBYOBRequest.
|
|
2549
|
-
function byobRequestBrandCheckException(name) {
|
|
2550
|
-
return new TypeError(`ReadableStreamBYOBRequest.prototype.${name} can only be used on a ReadableStreamBYOBRequest`);
|
|
2551
|
-
}
|
|
2552
|
-
// Helper functions for the ReadableByteStreamController.
|
|
2553
|
-
function byteStreamControllerBrandCheckException(name) {
|
|
2554
|
-
return new TypeError(`ReadableByteStreamController.prototype.${name} can only be used on a ReadableByteStreamController`);
|
|
2555
|
-
}
|
|
2556
|
-
|
|
2557
|
-
// Abstract operations for the ReadableStream.
|
|
2558
|
-
function AcquireReadableStreamBYOBReader(stream) {
|
|
2559
|
-
return new ReadableStreamBYOBReader(stream);
|
|
2560
|
-
}
|
|
2561
|
-
// ReadableStream API exposed for controllers.
|
|
2562
|
-
function ReadableStreamAddReadIntoRequest(stream, readIntoRequest) {
|
|
2563
|
-
stream._reader._readIntoRequests.push(readIntoRequest);
|
|
2564
|
-
}
|
|
2565
|
-
function ReadableStreamFulfillReadIntoRequest(stream, chunk, done) {
|
|
2566
|
-
const reader = stream._reader;
|
|
2567
|
-
const readIntoRequest = reader._readIntoRequests.shift();
|
|
2568
|
-
if (done) {
|
|
2569
|
-
readIntoRequest._closeSteps(chunk);
|
|
2570
|
-
}
|
|
2571
|
-
else {
|
|
2572
|
-
readIntoRequest._chunkSteps(chunk);
|
|
2573
|
-
}
|
|
2574
|
-
}
|
|
2575
|
-
function ReadableStreamGetNumReadIntoRequests(stream) {
|
|
2576
|
-
return stream._reader._readIntoRequests.length;
|
|
2577
|
-
}
|
|
2578
|
-
function ReadableStreamHasBYOBReader(stream) {
|
|
2579
|
-
const reader = stream._reader;
|
|
2580
|
-
if (reader === undefined) {
|
|
2581
|
-
return false;
|
|
2582
|
-
}
|
|
2583
|
-
if (!IsReadableStreamBYOBReader(reader)) {
|
|
2584
|
-
return false;
|
|
2585
|
-
}
|
|
2586
|
-
return true;
|
|
2587
|
-
}
|
|
2588
|
-
/**
|
|
2589
|
-
* A BYOB reader vended by a {@link ReadableStream}.
|
|
2590
|
-
*
|
|
2591
|
-
* @public
|
|
2592
|
-
*/
|
|
2593
|
-
class ReadableStreamBYOBReader {
|
|
2594
|
-
constructor(stream) {
|
|
2595
|
-
assertRequiredArgument(stream, 1, 'ReadableStreamBYOBReader');
|
|
2596
|
-
assertReadableStream(stream, 'First parameter');
|
|
2597
|
-
if (IsReadableStreamLocked(stream)) {
|
|
2598
|
-
throw new TypeError('This stream has already been locked for exclusive reading by another reader');
|
|
2599
|
-
}
|
|
2600
|
-
if (!IsReadableByteStreamController(stream._readableStreamController)) {
|
|
2601
|
-
throw new TypeError('Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte ' +
|
|
2602
|
-
'source');
|
|
2603
|
-
}
|
|
2604
|
-
ReadableStreamReaderGenericInitialize(this, stream);
|
|
2605
|
-
this._readIntoRequests = new SimpleQueue();
|
|
2606
|
-
}
|
|
2607
|
-
/**
|
|
2608
|
-
* Returns a promise that will be fulfilled when the stream becomes closed, or rejected if the stream ever errors or
|
|
2609
|
-
* the reader's lock is released before the stream finishes closing.
|
|
2610
|
-
*/
|
|
2611
|
-
get closed() {
|
|
2612
|
-
if (!IsReadableStreamBYOBReader(this)) {
|
|
2613
|
-
return promiseRejectedWith(byobReaderBrandCheckException('closed'));
|
|
2614
|
-
}
|
|
2615
|
-
return this._closedPromise;
|
|
2616
|
-
}
|
|
2617
|
-
/**
|
|
2618
|
-
* If the reader is active, behaves the same as {@link ReadableStream.cancel | stream.cancel(reason)}.
|
|
2619
|
-
*/
|
|
2620
|
-
cancel(reason = undefined) {
|
|
2621
|
-
if (!IsReadableStreamBYOBReader(this)) {
|
|
2622
|
-
return promiseRejectedWith(byobReaderBrandCheckException('cancel'));
|
|
2623
|
-
}
|
|
2624
|
-
if (this._ownerReadableStream === undefined) {
|
|
2625
|
-
return promiseRejectedWith(readerLockException('cancel'));
|
|
2626
|
-
}
|
|
2627
|
-
return ReadableStreamReaderGenericCancel(this, reason);
|
|
2628
|
-
}
|
|
2629
|
-
/**
|
|
2630
|
-
* Attempts to reads bytes into view, and returns a promise resolved with the result.
|
|
2631
|
-
*
|
|
2632
|
-
* If reading a chunk causes the queue to become empty, more data will be pulled from the underlying source.
|
|
2633
|
-
*/
|
|
2634
|
-
read(view) {
|
|
2635
|
-
if (!IsReadableStreamBYOBReader(this)) {
|
|
2636
|
-
return promiseRejectedWith(byobReaderBrandCheckException('read'));
|
|
2637
|
-
}
|
|
2638
|
-
if (!ArrayBuffer.isView(view)) {
|
|
2639
|
-
return promiseRejectedWith(new TypeError('view must be an array buffer view'));
|
|
2640
|
-
}
|
|
2641
|
-
if (view.byteLength === 0) {
|
|
2642
|
-
return promiseRejectedWith(new TypeError('view must have non-zero byteLength'));
|
|
2643
|
-
}
|
|
2644
|
-
if (view.buffer.byteLength === 0) {
|
|
2645
|
-
return promiseRejectedWith(new TypeError(`view's buffer must have non-zero byteLength`));
|
|
2646
|
-
}
|
|
2647
|
-
if (IsDetachedBuffer(view.buffer)) ;
|
|
2648
|
-
if (this._ownerReadableStream === undefined) {
|
|
2649
|
-
return promiseRejectedWith(readerLockException('read from'));
|
|
2650
|
-
}
|
|
2651
|
-
let resolvePromise;
|
|
2652
|
-
let rejectPromise;
|
|
2653
|
-
const promise = newPromise((resolve, reject) => {
|
|
2654
|
-
resolvePromise = resolve;
|
|
2655
|
-
rejectPromise = reject;
|
|
2656
|
-
});
|
|
2657
|
-
const readIntoRequest = {
|
|
2658
|
-
_chunkSteps: chunk => resolvePromise({ value: chunk, done: false }),
|
|
2659
|
-
_closeSteps: chunk => resolvePromise({ value: chunk, done: true }),
|
|
2660
|
-
_errorSteps: e => rejectPromise(e)
|
|
2661
|
-
};
|
|
2662
|
-
ReadableStreamBYOBReaderRead(this, view, readIntoRequest);
|
|
2663
|
-
return promise;
|
|
2664
|
-
}
|
|
2665
|
-
/**
|
|
2666
|
-
* Releases the reader's lock on the corresponding stream. After the lock is released, the reader is no longer active.
|
|
2667
|
-
* If the associated stream is errored when the lock is released, the reader will appear errored in the same way
|
|
2668
|
-
* from now on; otherwise, the reader will appear closed.
|
|
2669
|
-
*
|
|
2670
|
-
* A reader's lock cannot be released while it still has a pending read request, i.e., if a promise returned by
|
|
2671
|
-
* the reader's {@link ReadableStreamBYOBReader.read | read()} method has not yet been settled. Attempting to
|
|
2672
|
-
* do so will throw a `TypeError` and leave the reader locked to the stream.
|
|
2673
|
-
*/
|
|
2674
|
-
releaseLock() {
|
|
2675
|
-
if (!IsReadableStreamBYOBReader(this)) {
|
|
2676
|
-
throw byobReaderBrandCheckException('releaseLock');
|
|
2677
|
-
}
|
|
2678
|
-
if (this._ownerReadableStream === undefined) {
|
|
2679
|
-
return;
|
|
2680
|
-
}
|
|
2681
|
-
if (this._readIntoRequests.length > 0) {
|
|
2682
|
-
throw new TypeError('Tried to release a reader lock when that reader has pending read() calls un-settled');
|
|
2683
|
-
}
|
|
2684
|
-
ReadableStreamReaderGenericRelease(this);
|
|
2685
|
-
}
|
|
2686
|
-
}
|
|
2687
|
-
Object.defineProperties(ReadableStreamBYOBReader.prototype, {
|
|
2688
|
-
cancel: { enumerable: true },
|
|
2689
|
-
read: { enumerable: true },
|
|
2690
|
-
releaseLock: { enumerable: true },
|
|
2691
|
-
closed: { enumerable: true }
|
|
2692
|
-
});
|
|
2693
|
-
// Abstract operations for the readers.
|
|
2694
|
-
function IsReadableStreamBYOBReader(x) {
|
|
2695
|
-
if (!typeIsObject(x)) {
|
|
2696
|
-
return false;
|
|
2697
|
-
}
|
|
2698
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_readIntoRequests')) {
|
|
2699
|
-
return false;
|
|
2700
|
-
}
|
|
2701
|
-
return x instanceof ReadableStreamBYOBReader;
|
|
2702
|
-
}
|
|
2703
|
-
function ReadableStreamBYOBReaderRead(reader, view, readIntoRequest) {
|
|
2704
|
-
const stream = reader._ownerReadableStream;
|
|
2705
|
-
stream._disturbed = true;
|
|
2706
|
-
if (stream._state === 'errored') {
|
|
2707
|
-
readIntoRequest._errorSteps(stream._storedError);
|
|
2708
|
-
}
|
|
2709
|
-
else {
|
|
2710
|
-
ReadableByteStreamControllerPullInto(stream._readableStreamController, view, readIntoRequest);
|
|
2711
|
-
}
|
|
2712
|
-
}
|
|
2713
|
-
// Helper functions for the ReadableStreamBYOBReader.
|
|
2714
|
-
function byobReaderBrandCheckException(name) {
|
|
2715
|
-
return new TypeError(`ReadableStreamBYOBReader.prototype.${name} can only be used on a ReadableStreamBYOBReader`);
|
|
2716
|
-
}
|
|
2717
|
-
|
|
2718
|
-
function ExtractHighWaterMark(strategy, defaultHWM) {
|
|
2719
|
-
const { highWaterMark } = strategy;
|
|
2720
|
-
if (highWaterMark === undefined) {
|
|
2721
|
-
return defaultHWM;
|
|
2722
|
-
}
|
|
2723
|
-
if (NumberIsNaN(highWaterMark) || highWaterMark < 0) {
|
|
2724
|
-
throw new RangeError('Invalid highWaterMark');
|
|
2725
|
-
}
|
|
2726
|
-
return highWaterMark;
|
|
2727
|
-
}
|
|
2728
|
-
function ExtractSizeAlgorithm(strategy) {
|
|
2729
|
-
const { size } = strategy;
|
|
2730
|
-
if (!size) {
|
|
2731
|
-
return () => 1;
|
|
2732
|
-
}
|
|
2733
|
-
return size;
|
|
2734
|
-
}
|
|
2735
|
-
|
|
2736
|
-
function convertQueuingStrategy(init, context) {
|
|
2737
|
-
assertDictionary(init, context);
|
|
2738
|
-
const highWaterMark = init === null || init === void 0 ? void 0 : init.highWaterMark;
|
|
2739
|
-
const size = init === null || init === void 0 ? void 0 : init.size;
|
|
2740
|
-
return {
|
|
2741
|
-
highWaterMark: highWaterMark === undefined ? undefined : convertUnrestrictedDouble(highWaterMark),
|
|
2742
|
-
size: size === undefined ? undefined : convertQueuingStrategySize(size, `${context} has member 'size' that`)
|
|
2743
|
-
};
|
|
2744
|
-
}
|
|
2745
|
-
function convertQueuingStrategySize(fn, context) {
|
|
2746
|
-
assertFunction(fn, context);
|
|
2747
|
-
return chunk => convertUnrestrictedDouble(fn(chunk));
|
|
2748
|
-
}
|
|
2749
|
-
|
|
2750
|
-
function convertUnderlyingSink(original, context) {
|
|
2751
|
-
assertDictionary(original, context);
|
|
2752
|
-
const abort = original === null || original === void 0 ? void 0 : original.abort;
|
|
2753
|
-
const close = original === null || original === void 0 ? void 0 : original.close;
|
|
2754
|
-
const start = original === null || original === void 0 ? void 0 : original.start;
|
|
2755
|
-
const type = original === null || original === void 0 ? void 0 : original.type;
|
|
2756
|
-
const write = original === null || original === void 0 ? void 0 : original.write;
|
|
2757
|
-
return {
|
|
2758
|
-
abort: abort === undefined ?
|
|
2759
|
-
undefined :
|
|
2760
|
-
convertUnderlyingSinkAbortCallback(abort, original, `${context} has member 'abort' that`),
|
|
2761
|
-
close: close === undefined ?
|
|
2762
|
-
undefined :
|
|
2763
|
-
convertUnderlyingSinkCloseCallback(close, original, `${context} has member 'close' that`),
|
|
2764
|
-
start: start === undefined ?
|
|
2765
|
-
undefined :
|
|
2766
|
-
convertUnderlyingSinkStartCallback(start, original, `${context} has member 'start' that`),
|
|
2767
|
-
write: write === undefined ?
|
|
2768
|
-
undefined :
|
|
2769
|
-
convertUnderlyingSinkWriteCallback(write, original, `${context} has member 'write' that`),
|
|
2770
|
-
type
|
|
2771
|
-
};
|
|
2772
|
-
}
|
|
2773
|
-
function convertUnderlyingSinkAbortCallback(fn, original, context) {
|
|
2774
|
-
assertFunction(fn, context);
|
|
2775
|
-
return (reason) => promiseCall(fn, original, [reason]);
|
|
2776
|
-
}
|
|
2777
|
-
function convertUnderlyingSinkCloseCallback(fn, original, context) {
|
|
2778
|
-
assertFunction(fn, context);
|
|
2779
|
-
return () => promiseCall(fn, original, []);
|
|
2780
|
-
}
|
|
2781
|
-
function convertUnderlyingSinkStartCallback(fn, original, context) {
|
|
2782
|
-
assertFunction(fn, context);
|
|
2783
|
-
return (controller) => reflectCall(fn, original, [controller]);
|
|
2784
|
-
}
|
|
2785
|
-
function convertUnderlyingSinkWriteCallback(fn, original, context) {
|
|
2786
|
-
assertFunction(fn, context);
|
|
2787
|
-
return (chunk, controller) => promiseCall(fn, original, [chunk, controller]);
|
|
2788
|
-
}
|
|
2789
|
-
|
|
2790
|
-
function assertWritableStream(x, context) {
|
|
2791
|
-
if (!IsWritableStream(x)) {
|
|
2792
|
-
throw new TypeError(`${context} is not a WritableStream.`);
|
|
2793
|
-
}
|
|
2794
|
-
}
|
|
2795
|
-
|
|
2796
|
-
function isAbortSignal(value) {
|
|
2797
|
-
if (typeof value !== 'object' || value === null) {
|
|
2798
|
-
return false;
|
|
2799
|
-
}
|
|
2800
|
-
try {
|
|
2801
|
-
return typeof value.aborted === 'boolean';
|
|
2802
|
-
}
|
|
2803
|
-
catch (_a) {
|
|
2804
|
-
// AbortSignal.prototype.aborted throws if its brand check fails
|
|
2805
|
-
return false;
|
|
2806
|
-
}
|
|
2807
|
-
}
|
|
2808
|
-
|
|
2809
|
-
/**
|
|
2810
|
-
* A writable stream represents a destination for data, into which you can write.
|
|
2811
|
-
*
|
|
2812
|
-
* @public
|
|
2813
|
-
*/
|
|
2814
|
-
class WritableStream {
|
|
2815
|
-
constructor(rawUnderlyingSink = {}, rawStrategy = {}) {
|
|
2816
|
-
if (rawUnderlyingSink === undefined) {
|
|
2817
|
-
rawUnderlyingSink = null;
|
|
2818
|
-
}
|
|
2819
|
-
else {
|
|
2820
|
-
assertObject(rawUnderlyingSink, 'First parameter');
|
|
2821
|
-
}
|
|
2822
|
-
const strategy = convertQueuingStrategy(rawStrategy, 'Second parameter');
|
|
2823
|
-
const underlyingSink = convertUnderlyingSink(rawUnderlyingSink, 'First parameter');
|
|
2824
|
-
InitializeWritableStream(this);
|
|
2825
|
-
const type = underlyingSink.type;
|
|
2826
|
-
if (type !== undefined) {
|
|
2827
|
-
throw new RangeError('Invalid type is specified');
|
|
2828
|
-
}
|
|
2829
|
-
const sizeAlgorithm = ExtractSizeAlgorithm(strategy);
|
|
2830
|
-
const highWaterMark = ExtractHighWaterMark(strategy, 1);
|
|
2831
|
-
SetUpWritableStreamDefaultControllerFromUnderlyingSink(this, underlyingSink, highWaterMark, sizeAlgorithm);
|
|
2832
|
-
}
|
|
2833
|
-
/**
|
|
2834
|
-
* Returns whether or not the writable stream is locked to a writer.
|
|
2835
|
-
*/
|
|
2836
|
-
get locked() {
|
|
2837
|
-
if (!IsWritableStream(this)) {
|
|
2838
|
-
throw streamBrandCheckException$2('locked');
|
|
2839
|
-
}
|
|
2840
|
-
return IsWritableStreamLocked(this);
|
|
2841
|
-
}
|
|
2842
|
-
/**
|
|
2843
|
-
* Aborts the stream, signaling that the producer can no longer successfully write to the stream and it is to be
|
|
2844
|
-
* immediately moved to an errored state, with any queued-up writes discarded. This will also execute any abort
|
|
2845
|
-
* mechanism of the underlying sink.
|
|
2846
|
-
*
|
|
2847
|
-
* The returned promise will fulfill if the stream shuts down successfully, or reject if the underlying sink signaled
|
|
2848
|
-
* that there was an error doing so. Additionally, it will reject with a `TypeError` (without attempting to cancel
|
|
2849
|
-
* the stream) if the stream is currently locked.
|
|
2850
|
-
*/
|
|
2851
|
-
abort(reason = undefined) {
|
|
2852
|
-
if (!IsWritableStream(this)) {
|
|
2853
|
-
return promiseRejectedWith(streamBrandCheckException$2('abort'));
|
|
2854
|
-
}
|
|
2855
|
-
if (IsWritableStreamLocked(this)) {
|
|
2856
|
-
return promiseRejectedWith(new TypeError('Cannot abort a stream that already has a writer'));
|
|
2857
|
-
}
|
|
2858
|
-
return WritableStreamAbort(this, reason);
|
|
2859
|
-
}
|
|
2860
|
-
/**
|
|
2861
|
-
* Closes the stream. The underlying sink will finish processing any previously-written chunks, before invoking its
|
|
2862
|
-
* close behavior. During this time any further attempts to write will fail (without erroring the stream).
|
|
2863
|
-
*
|
|
2864
|
-
* The method returns a promise that will fulfill if all remaining chunks are successfully written and the stream
|
|
2865
|
-
* successfully closes, or rejects if an error is encountered during this process. Additionally, it will reject with
|
|
2866
|
-
* a `TypeError` (without attempting to cancel the stream) if the stream is currently locked.
|
|
2867
|
-
*/
|
|
2868
|
-
close() {
|
|
2869
|
-
if (!IsWritableStream(this)) {
|
|
2870
|
-
return promiseRejectedWith(streamBrandCheckException$2('close'));
|
|
2871
|
-
}
|
|
2872
|
-
if (IsWritableStreamLocked(this)) {
|
|
2873
|
-
return promiseRejectedWith(new TypeError('Cannot close a stream that already has a writer'));
|
|
2874
|
-
}
|
|
2875
|
-
if (WritableStreamCloseQueuedOrInFlight(this)) {
|
|
2876
|
-
return promiseRejectedWith(new TypeError('Cannot close an already-closing stream'));
|
|
2877
|
-
}
|
|
2878
|
-
return WritableStreamClose(this);
|
|
2879
|
-
}
|
|
2880
|
-
/**
|
|
2881
|
-
* Creates a {@link WritableStreamDefaultWriter | writer} and locks the stream to the new writer. While the stream
|
|
2882
|
-
* is locked, no other writer can be acquired until this one is released.
|
|
2883
|
-
*
|
|
2884
|
-
* This functionality is especially useful for creating abstractions that desire the ability to write to a stream
|
|
2885
|
-
* without interruption or interleaving. By getting a writer for the stream, you can ensure nobody else can write at
|
|
2886
|
-
* the same time, which would cause the resulting written data to be unpredictable and probably useless.
|
|
2887
|
-
*/
|
|
2888
|
-
getWriter() {
|
|
2889
|
-
if (!IsWritableStream(this)) {
|
|
2890
|
-
throw streamBrandCheckException$2('getWriter');
|
|
2891
|
-
}
|
|
2892
|
-
return AcquireWritableStreamDefaultWriter(this);
|
|
2893
|
-
}
|
|
2894
|
-
}
|
|
2895
|
-
Object.defineProperties(WritableStream.prototype, {
|
|
2896
|
-
abort: { enumerable: true },
|
|
2897
|
-
close: { enumerable: true },
|
|
2898
|
-
getWriter: { enumerable: true },
|
|
2899
|
-
locked: { enumerable: true }
|
|
2900
|
-
});
|
|
2901
|
-
// Abstract operations for the WritableStream.
|
|
2902
|
-
function AcquireWritableStreamDefaultWriter(stream) {
|
|
2903
|
-
return new WritableStreamDefaultWriter(stream);
|
|
2904
|
-
}
|
|
2905
|
-
// Throws if and only if startAlgorithm throws.
|
|
2906
|
-
function CreateWritableStream(startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark = 1, sizeAlgorithm = () => 1) {
|
|
2907
|
-
const stream = Object.create(WritableStream.prototype);
|
|
2908
|
-
InitializeWritableStream(stream);
|
|
2909
|
-
const controller = Object.create(WritableStreamDefaultController.prototype);
|
|
2910
|
-
SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm);
|
|
2911
|
-
return stream;
|
|
2912
|
-
}
|
|
2913
|
-
function InitializeWritableStream(stream) {
|
|
2914
|
-
stream._state = 'writable';
|
|
2915
|
-
// The error that will be reported by new method calls once the state becomes errored. Only set when [[state]] is
|
|
2916
|
-
// 'erroring' or 'errored'. May be set to an undefined value.
|
|
2917
|
-
stream._storedError = undefined;
|
|
2918
|
-
stream._writer = undefined;
|
|
2919
|
-
// Initialize to undefined first because the constructor of the controller checks this
|
|
2920
|
-
// variable to validate the caller.
|
|
2921
|
-
stream._writableStreamController = undefined;
|
|
2922
|
-
// This queue is placed here instead of the writer class in order to allow for passing a writer to the next data
|
|
2923
|
-
// producer without waiting for the queued writes to finish.
|
|
2924
|
-
stream._writeRequests = new SimpleQueue();
|
|
2925
|
-
// Write requests are removed from _writeRequests when write() is called on the underlying sink. This prevents
|
|
2926
|
-
// them from being erroneously rejected on error. If a write() call is in-flight, the request is stored here.
|
|
2927
|
-
stream._inFlightWriteRequest = undefined;
|
|
2928
|
-
// The promise that was returned from writer.close(). Stored here because it may be fulfilled after the writer
|
|
2929
|
-
// has been detached.
|
|
2930
|
-
stream._closeRequest = undefined;
|
|
2931
|
-
// Close request is removed from _closeRequest when close() is called on the underlying sink. This prevents it
|
|
2932
|
-
// from being erroneously rejected on error. If a close() call is in-flight, the request is stored here.
|
|
2933
|
-
stream._inFlightCloseRequest = undefined;
|
|
2934
|
-
// The promise that was returned from writer.abort(). This may also be fulfilled after the writer has detached.
|
|
2935
|
-
stream._pendingAbortRequest = undefined;
|
|
2936
|
-
// The backpressure signal set by the controller.
|
|
2937
|
-
stream._backpressure = false;
|
|
2938
|
-
}
|
|
2939
|
-
function IsWritableStream(x) {
|
|
2940
|
-
if (!typeIsObject(x)) {
|
|
2941
|
-
return false;
|
|
2942
|
-
}
|
|
2943
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_writableStreamController')) {
|
|
2944
|
-
return false;
|
|
2945
|
-
}
|
|
2946
|
-
return x instanceof WritableStream;
|
|
2947
|
-
}
|
|
2948
|
-
function IsWritableStreamLocked(stream) {
|
|
2949
|
-
if (stream._writer === undefined) {
|
|
2950
|
-
return false;
|
|
2951
|
-
}
|
|
2952
|
-
return true;
|
|
2953
|
-
}
|
|
2954
|
-
function WritableStreamAbort(stream, reason) {
|
|
2955
|
-
var _a;
|
|
2956
|
-
if (stream._state === 'closed' || stream._state === 'errored') {
|
|
2957
|
-
return promiseResolvedWith(undefined);
|
|
2958
|
-
}
|
|
2959
|
-
stream._writableStreamController._abortReason = reason;
|
|
2960
|
-
(_a = stream._writableStreamController._abortController) === null || _a === void 0 ? void 0 : _a.abort();
|
|
2961
|
-
// TypeScript narrows the type of `stream._state` down to 'writable' | 'erroring',
|
|
2962
|
-
// but it doesn't know that signaling abort runs author code that might have changed the state.
|
|
2963
|
-
// Widen the type again by casting to WritableStreamState.
|
|
2964
|
-
const state = stream._state;
|
|
2965
|
-
if (state === 'closed' || state === 'errored') {
|
|
2966
|
-
return promiseResolvedWith(undefined);
|
|
2967
|
-
}
|
|
2968
|
-
if (stream._pendingAbortRequest !== undefined) {
|
|
2969
|
-
return stream._pendingAbortRequest._promise;
|
|
2970
|
-
}
|
|
2971
|
-
let wasAlreadyErroring = false;
|
|
2972
|
-
if (state === 'erroring') {
|
|
2973
|
-
wasAlreadyErroring = true;
|
|
2974
|
-
// reason will not be used, so don't keep a reference to it.
|
|
2975
|
-
reason = undefined;
|
|
2976
|
-
}
|
|
2977
|
-
const promise = newPromise((resolve, reject) => {
|
|
2978
|
-
stream._pendingAbortRequest = {
|
|
2979
|
-
_promise: undefined,
|
|
2980
|
-
_resolve: resolve,
|
|
2981
|
-
_reject: reject,
|
|
2982
|
-
_reason: reason,
|
|
2983
|
-
_wasAlreadyErroring: wasAlreadyErroring
|
|
2984
|
-
};
|
|
2985
|
-
});
|
|
2986
|
-
stream._pendingAbortRequest._promise = promise;
|
|
2987
|
-
if (!wasAlreadyErroring) {
|
|
2988
|
-
WritableStreamStartErroring(stream, reason);
|
|
2989
|
-
}
|
|
2990
|
-
return promise;
|
|
2991
|
-
}
|
|
2992
|
-
function WritableStreamClose(stream) {
|
|
2993
|
-
const state = stream._state;
|
|
2994
|
-
if (state === 'closed' || state === 'errored') {
|
|
2995
|
-
return promiseRejectedWith(new TypeError(`The stream (in ${state} state) is not in the writable state and cannot be closed`));
|
|
2996
|
-
}
|
|
2997
|
-
const promise = newPromise((resolve, reject) => {
|
|
2998
|
-
const closeRequest = {
|
|
2999
|
-
_resolve: resolve,
|
|
3000
|
-
_reject: reject
|
|
3001
|
-
};
|
|
3002
|
-
stream._closeRequest = closeRequest;
|
|
3003
|
-
});
|
|
3004
|
-
const writer = stream._writer;
|
|
3005
|
-
if (writer !== undefined && stream._backpressure && state === 'writable') {
|
|
3006
|
-
defaultWriterReadyPromiseResolve(writer);
|
|
3007
|
-
}
|
|
3008
|
-
WritableStreamDefaultControllerClose(stream._writableStreamController);
|
|
3009
|
-
return promise;
|
|
3010
|
-
}
|
|
3011
|
-
// WritableStream API exposed for controllers.
|
|
3012
|
-
function WritableStreamAddWriteRequest(stream) {
|
|
3013
|
-
const promise = newPromise((resolve, reject) => {
|
|
3014
|
-
const writeRequest = {
|
|
3015
|
-
_resolve: resolve,
|
|
3016
|
-
_reject: reject
|
|
3017
|
-
};
|
|
3018
|
-
stream._writeRequests.push(writeRequest);
|
|
3019
|
-
});
|
|
3020
|
-
return promise;
|
|
3021
|
-
}
|
|
3022
|
-
function WritableStreamDealWithRejection(stream, error) {
|
|
3023
|
-
const state = stream._state;
|
|
3024
|
-
if (state === 'writable') {
|
|
3025
|
-
WritableStreamStartErroring(stream, error);
|
|
3026
|
-
return;
|
|
3027
|
-
}
|
|
3028
|
-
WritableStreamFinishErroring(stream);
|
|
3029
|
-
}
|
|
3030
|
-
function WritableStreamStartErroring(stream, reason) {
|
|
3031
|
-
const controller = stream._writableStreamController;
|
|
3032
|
-
stream._state = 'erroring';
|
|
3033
|
-
stream._storedError = reason;
|
|
3034
|
-
const writer = stream._writer;
|
|
3035
|
-
if (writer !== undefined) {
|
|
3036
|
-
WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, reason);
|
|
3037
|
-
}
|
|
3038
|
-
if (!WritableStreamHasOperationMarkedInFlight(stream) && controller._started) {
|
|
3039
|
-
WritableStreamFinishErroring(stream);
|
|
3040
|
-
}
|
|
3041
|
-
}
|
|
3042
|
-
function WritableStreamFinishErroring(stream) {
|
|
3043
|
-
stream._state = 'errored';
|
|
3044
|
-
stream._writableStreamController[ErrorSteps]();
|
|
3045
|
-
const storedError = stream._storedError;
|
|
3046
|
-
stream._writeRequests.forEach(writeRequest => {
|
|
3047
|
-
writeRequest._reject(storedError);
|
|
3048
|
-
});
|
|
3049
|
-
stream._writeRequests = new SimpleQueue();
|
|
3050
|
-
if (stream._pendingAbortRequest === undefined) {
|
|
3051
|
-
WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
|
|
3052
|
-
return;
|
|
3053
|
-
}
|
|
3054
|
-
const abortRequest = stream._pendingAbortRequest;
|
|
3055
|
-
stream._pendingAbortRequest = undefined;
|
|
3056
|
-
if (abortRequest._wasAlreadyErroring) {
|
|
3057
|
-
abortRequest._reject(storedError);
|
|
3058
|
-
WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
|
|
3059
|
-
return;
|
|
3060
|
-
}
|
|
3061
|
-
const promise = stream._writableStreamController[AbortSteps](abortRequest._reason);
|
|
3062
|
-
uponPromise(promise, () => {
|
|
3063
|
-
abortRequest._resolve();
|
|
3064
|
-
WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
|
|
3065
|
-
}, (reason) => {
|
|
3066
|
-
abortRequest._reject(reason);
|
|
3067
|
-
WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
|
|
3068
|
-
});
|
|
3069
|
-
}
|
|
3070
|
-
function WritableStreamFinishInFlightWrite(stream) {
|
|
3071
|
-
stream._inFlightWriteRequest._resolve(undefined);
|
|
3072
|
-
stream._inFlightWriteRequest = undefined;
|
|
3073
|
-
}
|
|
3074
|
-
function WritableStreamFinishInFlightWriteWithError(stream, error) {
|
|
3075
|
-
stream._inFlightWriteRequest._reject(error);
|
|
3076
|
-
stream._inFlightWriteRequest = undefined;
|
|
3077
|
-
WritableStreamDealWithRejection(stream, error);
|
|
3078
|
-
}
|
|
3079
|
-
function WritableStreamFinishInFlightClose(stream) {
|
|
3080
|
-
stream._inFlightCloseRequest._resolve(undefined);
|
|
3081
|
-
stream._inFlightCloseRequest = undefined;
|
|
3082
|
-
const state = stream._state;
|
|
3083
|
-
if (state === 'erroring') {
|
|
3084
|
-
// The error was too late to do anything, so it is ignored.
|
|
3085
|
-
stream._storedError = undefined;
|
|
3086
|
-
if (stream._pendingAbortRequest !== undefined) {
|
|
3087
|
-
stream._pendingAbortRequest._resolve();
|
|
3088
|
-
stream._pendingAbortRequest = undefined;
|
|
3089
|
-
}
|
|
3090
|
-
}
|
|
3091
|
-
stream._state = 'closed';
|
|
3092
|
-
const writer = stream._writer;
|
|
3093
|
-
if (writer !== undefined) {
|
|
3094
|
-
defaultWriterClosedPromiseResolve(writer);
|
|
3095
|
-
}
|
|
3096
|
-
}
|
|
3097
|
-
function WritableStreamFinishInFlightCloseWithError(stream, error) {
|
|
3098
|
-
stream._inFlightCloseRequest._reject(error);
|
|
3099
|
-
stream._inFlightCloseRequest = undefined;
|
|
3100
|
-
// Never execute sink abort() after sink close().
|
|
3101
|
-
if (stream._pendingAbortRequest !== undefined) {
|
|
3102
|
-
stream._pendingAbortRequest._reject(error);
|
|
3103
|
-
stream._pendingAbortRequest = undefined;
|
|
3104
|
-
}
|
|
3105
|
-
WritableStreamDealWithRejection(stream, error);
|
|
3106
|
-
}
|
|
3107
|
-
// TODO(ricea): Fix alphabetical order.
|
|
3108
|
-
function WritableStreamCloseQueuedOrInFlight(stream) {
|
|
3109
|
-
if (stream._closeRequest === undefined && stream._inFlightCloseRequest === undefined) {
|
|
3110
|
-
return false;
|
|
3111
|
-
}
|
|
3112
|
-
return true;
|
|
3113
|
-
}
|
|
3114
|
-
function WritableStreamHasOperationMarkedInFlight(stream) {
|
|
3115
|
-
if (stream._inFlightWriteRequest === undefined && stream._inFlightCloseRequest === undefined) {
|
|
3116
|
-
return false;
|
|
3117
|
-
}
|
|
3118
|
-
return true;
|
|
3119
|
-
}
|
|
3120
|
-
function WritableStreamMarkCloseRequestInFlight(stream) {
|
|
3121
|
-
stream._inFlightCloseRequest = stream._closeRequest;
|
|
3122
|
-
stream._closeRequest = undefined;
|
|
3123
|
-
}
|
|
3124
|
-
function WritableStreamMarkFirstWriteRequestInFlight(stream) {
|
|
3125
|
-
stream._inFlightWriteRequest = stream._writeRequests.shift();
|
|
3126
|
-
}
|
|
3127
|
-
function WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream) {
|
|
3128
|
-
if (stream._closeRequest !== undefined) {
|
|
3129
|
-
stream._closeRequest._reject(stream._storedError);
|
|
3130
|
-
stream._closeRequest = undefined;
|
|
3131
|
-
}
|
|
3132
|
-
const writer = stream._writer;
|
|
3133
|
-
if (writer !== undefined) {
|
|
3134
|
-
defaultWriterClosedPromiseReject(writer, stream._storedError);
|
|
3135
|
-
}
|
|
3136
|
-
}
|
|
3137
|
-
function WritableStreamUpdateBackpressure(stream, backpressure) {
|
|
3138
|
-
const writer = stream._writer;
|
|
3139
|
-
if (writer !== undefined && backpressure !== stream._backpressure) {
|
|
3140
|
-
if (backpressure) {
|
|
3141
|
-
defaultWriterReadyPromiseReset(writer);
|
|
3142
|
-
}
|
|
3143
|
-
else {
|
|
3144
|
-
defaultWriterReadyPromiseResolve(writer);
|
|
3145
|
-
}
|
|
3146
|
-
}
|
|
3147
|
-
stream._backpressure = backpressure;
|
|
3148
|
-
}
|
|
3149
|
-
/**
|
|
3150
|
-
* A default writer vended by a {@link WritableStream}.
|
|
3151
|
-
*
|
|
3152
|
-
* @public
|
|
3153
|
-
*/
|
|
3154
|
-
class WritableStreamDefaultWriter {
|
|
3155
|
-
constructor(stream) {
|
|
3156
|
-
assertRequiredArgument(stream, 1, 'WritableStreamDefaultWriter');
|
|
3157
|
-
assertWritableStream(stream, 'First parameter');
|
|
3158
|
-
if (IsWritableStreamLocked(stream)) {
|
|
3159
|
-
throw new TypeError('This stream has already been locked for exclusive writing by another writer');
|
|
3160
|
-
}
|
|
3161
|
-
this._ownerWritableStream = stream;
|
|
3162
|
-
stream._writer = this;
|
|
3163
|
-
const state = stream._state;
|
|
3164
|
-
if (state === 'writable') {
|
|
3165
|
-
if (!WritableStreamCloseQueuedOrInFlight(stream) && stream._backpressure) {
|
|
3166
|
-
defaultWriterReadyPromiseInitialize(this);
|
|
3167
|
-
}
|
|
3168
|
-
else {
|
|
3169
|
-
defaultWriterReadyPromiseInitializeAsResolved(this);
|
|
3170
|
-
}
|
|
3171
|
-
defaultWriterClosedPromiseInitialize(this);
|
|
3172
|
-
}
|
|
3173
|
-
else if (state === 'erroring') {
|
|
3174
|
-
defaultWriterReadyPromiseInitializeAsRejected(this, stream._storedError);
|
|
3175
|
-
defaultWriterClosedPromiseInitialize(this);
|
|
3176
|
-
}
|
|
3177
|
-
else if (state === 'closed') {
|
|
3178
|
-
defaultWriterReadyPromiseInitializeAsResolved(this);
|
|
3179
|
-
defaultWriterClosedPromiseInitializeAsResolved(this);
|
|
3180
|
-
}
|
|
3181
|
-
else {
|
|
3182
|
-
const storedError = stream._storedError;
|
|
3183
|
-
defaultWriterReadyPromiseInitializeAsRejected(this, storedError);
|
|
3184
|
-
defaultWriterClosedPromiseInitializeAsRejected(this, storedError);
|
|
3185
|
-
}
|
|
3186
|
-
}
|
|
3187
|
-
/**
|
|
3188
|
-
* Returns a promise that will be fulfilled when the stream becomes closed, or rejected if the stream ever errors or
|
|
3189
|
-
* the writer’s lock is released before the stream finishes closing.
|
|
3190
|
-
*/
|
|
3191
|
-
get closed() {
|
|
3192
|
-
if (!IsWritableStreamDefaultWriter(this)) {
|
|
3193
|
-
return promiseRejectedWith(defaultWriterBrandCheckException('closed'));
|
|
3194
|
-
}
|
|
3195
|
-
return this._closedPromise;
|
|
3196
|
-
}
|
|
3197
|
-
/**
|
|
3198
|
-
* Returns the desired size to fill the stream’s internal queue. It can be negative, if the queue is over-full.
|
|
3199
|
-
* A producer can use this information to determine the right amount of data to write.
|
|
3200
|
-
*
|
|
3201
|
-
* It will be `null` if the stream cannot be successfully written to (due to either being errored, or having an abort
|
|
3202
|
-
* queued up). It will return zero if the stream is closed. And the getter will throw an exception if invoked when
|
|
3203
|
-
* the writer’s lock is released.
|
|
3204
|
-
*/
|
|
3205
|
-
get desiredSize() {
|
|
3206
|
-
if (!IsWritableStreamDefaultWriter(this)) {
|
|
3207
|
-
throw defaultWriterBrandCheckException('desiredSize');
|
|
3208
|
-
}
|
|
3209
|
-
if (this._ownerWritableStream === undefined) {
|
|
3210
|
-
throw defaultWriterLockException('desiredSize');
|
|
3211
|
-
}
|
|
3212
|
-
return WritableStreamDefaultWriterGetDesiredSize(this);
|
|
3213
|
-
}
|
|
3214
|
-
/**
|
|
3215
|
-
* Returns a promise that will be fulfilled when the desired size to fill the stream’s internal queue transitions
|
|
3216
|
-
* from non-positive to positive, signaling that it is no longer applying backpressure. Once the desired size dips
|
|
3217
|
-
* back to zero or below, the getter will return a new promise that stays pending until the next transition.
|
|
3218
|
-
*
|
|
3219
|
-
* If the stream becomes errored or aborted, or the writer’s lock is released, the returned promise will become
|
|
3220
|
-
* rejected.
|
|
3221
|
-
*/
|
|
3222
|
-
get ready() {
|
|
3223
|
-
if (!IsWritableStreamDefaultWriter(this)) {
|
|
3224
|
-
return promiseRejectedWith(defaultWriterBrandCheckException('ready'));
|
|
3225
|
-
}
|
|
3226
|
-
return this._readyPromise;
|
|
3227
|
-
}
|
|
3228
|
-
/**
|
|
3229
|
-
* If the reader is active, behaves the same as {@link WritableStream.abort | stream.abort(reason)}.
|
|
3230
|
-
*/
|
|
3231
|
-
abort(reason = undefined) {
|
|
3232
|
-
if (!IsWritableStreamDefaultWriter(this)) {
|
|
3233
|
-
return promiseRejectedWith(defaultWriterBrandCheckException('abort'));
|
|
3234
|
-
}
|
|
3235
|
-
if (this._ownerWritableStream === undefined) {
|
|
3236
|
-
return promiseRejectedWith(defaultWriterLockException('abort'));
|
|
3237
|
-
}
|
|
3238
|
-
return WritableStreamDefaultWriterAbort(this, reason);
|
|
3239
|
-
}
|
|
3240
|
-
/**
|
|
3241
|
-
* If the reader is active, behaves the same as {@link WritableStream.close | stream.close()}.
|
|
3242
|
-
*/
|
|
3243
|
-
close() {
|
|
3244
|
-
if (!IsWritableStreamDefaultWriter(this)) {
|
|
3245
|
-
return promiseRejectedWith(defaultWriterBrandCheckException('close'));
|
|
3246
|
-
}
|
|
3247
|
-
const stream = this._ownerWritableStream;
|
|
3248
|
-
if (stream === undefined) {
|
|
3249
|
-
return promiseRejectedWith(defaultWriterLockException('close'));
|
|
3250
|
-
}
|
|
3251
|
-
if (WritableStreamCloseQueuedOrInFlight(stream)) {
|
|
3252
|
-
return promiseRejectedWith(new TypeError('Cannot close an already-closing stream'));
|
|
3253
|
-
}
|
|
3254
|
-
return WritableStreamDefaultWriterClose(this);
|
|
3255
|
-
}
|
|
3256
|
-
/**
|
|
3257
|
-
* Releases the writer’s lock on the corresponding stream. After the lock is released, the writer is no longer active.
|
|
3258
|
-
* If the associated stream is errored when the lock is released, the writer will appear errored in the same way from
|
|
3259
|
-
* now on; otherwise, the writer will appear closed.
|
|
3260
|
-
*
|
|
3261
|
-
* Note that the lock can still be released even if some ongoing writes have not yet finished (i.e. even if the
|
|
3262
|
-
* promises returned from previous calls to {@link WritableStreamDefaultWriter.write | write()} have not yet settled).
|
|
3263
|
-
* It’s not necessary to hold the lock on the writer for the duration of the write; the lock instead simply prevents
|
|
3264
|
-
* other producers from writing in an interleaved manner.
|
|
3265
|
-
*/
|
|
3266
|
-
releaseLock() {
|
|
3267
|
-
if (!IsWritableStreamDefaultWriter(this)) {
|
|
3268
|
-
throw defaultWriterBrandCheckException('releaseLock');
|
|
3269
|
-
}
|
|
3270
|
-
const stream = this._ownerWritableStream;
|
|
3271
|
-
if (stream === undefined) {
|
|
3272
|
-
return;
|
|
3273
|
-
}
|
|
3274
|
-
WritableStreamDefaultWriterRelease(this);
|
|
3275
|
-
}
|
|
3276
|
-
write(chunk = undefined) {
|
|
3277
|
-
if (!IsWritableStreamDefaultWriter(this)) {
|
|
3278
|
-
return promiseRejectedWith(defaultWriterBrandCheckException('write'));
|
|
3279
|
-
}
|
|
3280
|
-
if (this._ownerWritableStream === undefined) {
|
|
3281
|
-
return promiseRejectedWith(defaultWriterLockException('write to'));
|
|
3282
|
-
}
|
|
3283
|
-
return WritableStreamDefaultWriterWrite(this, chunk);
|
|
3284
|
-
}
|
|
3285
|
-
}
|
|
3286
|
-
Object.defineProperties(WritableStreamDefaultWriter.prototype, {
|
|
3287
|
-
abort: { enumerable: true },
|
|
3288
|
-
close: { enumerable: true },
|
|
3289
|
-
releaseLock: { enumerable: true },
|
|
3290
|
-
write: { enumerable: true },
|
|
3291
|
-
closed: { enumerable: true },
|
|
3292
|
-
desiredSize: { enumerable: true },
|
|
3293
|
-
ready: { enumerable: true }
|
|
3294
|
-
});
|
|
3295
|
-
// Abstract operations for the WritableStreamDefaultWriter.
|
|
3296
|
-
function IsWritableStreamDefaultWriter(x) {
|
|
3297
|
-
if (!typeIsObject(x)) {
|
|
3298
|
-
return false;
|
|
3299
|
-
}
|
|
3300
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_ownerWritableStream')) {
|
|
3301
|
-
return false;
|
|
3302
|
-
}
|
|
3303
|
-
return x instanceof WritableStreamDefaultWriter;
|
|
3304
|
-
}
|
|
3305
|
-
// A client of WritableStreamDefaultWriter may use these functions directly to bypass state check.
|
|
3306
|
-
function WritableStreamDefaultWriterAbort(writer, reason) {
|
|
3307
|
-
const stream = writer._ownerWritableStream;
|
|
3308
|
-
return WritableStreamAbort(stream, reason);
|
|
3309
|
-
}
|
|
3310
|
-
function WritableStreamDefaultWriterClose(writer) {
|
|
3311
|
-
const stream = writer._ownerWritableStream;
|
|
3312
|
-
return WritableStreamClose(stream);
|
|
3313
|
-
}
|
|
3314
|
-
function WritableStreamDefaultWriterCloseWithErrorPropagation(writer) {
|
|
3315
|
-
const stream = writer._ownerWritableStream;
|
|
3316
|
-
const state = stream._state;
|
|
3317
|
-
if (WritableStreamCloseQueuedOrInFlight(stream) || state === 'closed') {
|
|
3318
|
-
return promiseResolvedWith(undefined);
|
|
3319
|
-
}
|
|
3320
|
-
if (state === 'errored') {
|
|
3321
|
-
return promiseRejectedWith(stream._storedError);
|
|
3322
|
-
}
|
|
3323
|
-
return WritableStreamDefaultWriterClose(writer);
|
|
3324
|
-
}
|
|
3325
|
-
function WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, error) {
|
|
3326
|
-
if (writer._closedPromiseState === 'pending') {
|
|
3327
|
-
defaultWriterClosedPromiseReject(writer, error);
|
|
3328
|
-
}
|
|
3329
|
-
else {
|
|
3330
|
-
defaultWriterClosedPromiseResetToRejected(writer, error);
|
|
3331
|
-
}
|
|
3332
|
-
}
|
|
3333
|
-
function WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, error) {
|
|
3334
|
-
if (writer._readyPromiseState === 'pending') {
|
|
3335
|
-
defaultWriterReadyPromiseReject(writer, error);
|
|
3336
|
-
}
|
|
3337
|
-
else {
|
|
3338
|
-
defaultWriterReadyPromiseResetToRejected(writer, error);
|
|
3339
|
-
}
|
|
3340
|
-
}
|
|
3341
|
-
function WritableStreamDefaultWriterGetDesiredSize(writer) {
|
|
3342
|
-
const stream = writer._ownerWritableStream;
|
|
3343
|
-
const state = stream._state;
|
|
3344
|
-
if (state === 'errored' || state === 'erroring') {
|
|
3345
|
-
return null;
|
|
3346
|
-
}
|
|
3347
|
-
if (state === 'closed') {
|
|
3348
|
-
return 0;
|
|
3349
|
-
}
|
|
3350
|
-
return WritableStreamDefaultControllerGetDesiredSize(stream._writableStreamController);
|
|
3351
|
-
}
|
|
3352
|
-
function WritableStreamDefaultWriterRelease(writer) {
|
|
3353
|
-
const stream = writer._ownerWritableStream;
|
|
3354
|
-
const releasedError = new TypeError(`Writer was released and can no longer be used to monitor the stream's closedness`);
|
|
3355
|
-
WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, releasedError);
|
|
3356
|
-
// The state transitions to "errored" before the sink abort() method runs, but the writer.closed promise is not
|
|
3357
|
-
// rejected until afterwards. This means that simply testing state will not work.
|
|
3358
|
-
WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, releasedError);
|
|
3359
|
-
stream._writer = undefined;
|
|
3360
|
-
writer._ownerWritableStream = undefined;
|
|
3361
|
-
}
|
|
3362
|
-
function WritableStreamDefaultWriterWrite(writer, chunk) {
|
|
3363
|
-
const stream = writer._ownerWritableStream;
|
|
3364
|
-
const controller = stream._writableStreamController;
|
|
3365
|
-
const chunkSize = WritableStreamDefaultControllerGetChunkSize(controller, chunk);
|
|
3366
|
-
if (stream !== writer._ownerWritableStream) {
|
|
3367
|
-
return promiseRejectedWith(defaultWriterLockException('write to'));
|
|
3368
|
-
}
|
|
3369
|
-
const state = stream._state;
|
|
3370
|
-
if (state === 'errored') {
|
|
3371
|
-
return promiseRejectedWith(stream._storedError);
|
|
3372
|
-
}
|
|
3373
|
-
if (WritableStreamCloseQueuedOrInFlight(stream) || state === 'closed') {
|
|
3374
|
-
return promiseRejectedWith(new TypeError('The stream is closing or closed and cannot be written to'));
|
|
3375
|
-
}
|
|
3376
|
-
if (state === 'erroring') {
|
|
3377
|
-
return promiseRejectedWith(stream._storedError);
|
|
3378
|
-
}
|
|
3379
|
-
const promise = WritableStreamAddWriteRequest(stream);
|
|
3380
|
-
WritableStreamDefaultControllerWrite(controller, chunk, chunkSize);
|
|
3381
|
-
return promise;
|
|
3382
|
-
}
|
|
3383
|
-
const closeSentinel = {};
|
|
3384
|
-
/**
|
|
3385
|
-
* Allows control of a {@link WritableStream | writable stream}'s state and internal queue.
|
|
3386
|
-
*
|
|
3387
|
-
* @public
|
|
3388
|
-
*/
|
|
3389
|
-
class WritableStreamDefaultController {
|
|
3390
|
-
constructor() {
|
|
3391
|
-
throw new TypeError('Illegal constructor');
|
|
3392
|
-
}
|
|
3393
|
-
/**
|
|
3394
|
-
* The reason which was passed to `WritableStream.abort(reason)` when the stream was aborted.
|
|
3395
|
-
*
|
|
3396
|
-
* @deprecated
|
|
3397
|
-
* This property has been removed from the specification, see https://github.com/whatwg/streams/pull/1177.
|
|
3398
|
-
* Use {@link WritableStreamDefaultController.signal}'s `reason` instead.
|
|
3399
|
-
*/
|
|
3400
|
-
get abortReason() {
|
|
3401
|
-
if (!IsWritableStreamDefaultController(this)) {
|
|
3402
|
-
throw defaultControllerBrandCheckException$2('abortReason');
|
|
3403
|
-
}
|
|
3404
|
-
return this._abortReason;
|
|
3405
|
-
}
|
|
3406
|
-
/**
|
|
3407
|
-
* An `AbortSignal` that can be used to abort the pending write or close operation when the stream is aborted.
|
|
3408
|
-
*/
|
|
3409
|
-
get signal() {
|
|
3410
|
-
if (!IsWritableStreamDefaultController(this)) {
|
|
3411
|
-
throw defaultControllerBrandCheckException$2('signal');
|
|
3412
|
-
}
|
|
3413
|
-
if (this._abortController === undefined) {
|
|
3414
|
-
// Older browsers or older Node versions may not support `AbortController` or `AbortSignal`.
|
|
3415
|
-
// We don't want to bundle and ship an `AbortController` polyfill together with our polyfill,
|
|
3416
|
-
// so instead we only implement support for `signal` if we find a global `AbortController` constructor.
|
|
3417
|
-
throw new TypeError('WritableStreamDefaultController.prototype.signal is not supported');
|
|
3418
|
-
}
|
|
3419
|
-
return this._abortController.signal;
|
|
3420
|
-
}
|
|
3421
|
-
/**
|
|
3422
|
-
* Closes the controlled writable stream, making all future interactions with it fail with the given error `e`.
|
|
3423
|
-
*
|
|
3424
|
-
* This method is rarely used, since usually it suffices to return a rejected promise from one of the underlying
|
|
3425
|
-
* sink's methods. However, it can be useful for suddenly shutting down a stream in response to an event outside the
|
|
3426
|
-
* normal lifecycle of interactions with the underlying sink.
|
|
3427
|
-
*/
|
|
3428
|
-
error(e = undefined) {
|
|
3429
|
-
if (!IsWritableStreamDefaultController(this)) {
|
|
3430
|
-
throw defaultControllerBrandCheckException$2('error');
|
|
3431
|
-
}
|
|
3432
|
-
const state = this._controlledWritableStream._state;
|
|
3433
|
-
if (state !== 'writable') {
|
|
3434
|
-
// The stream is closed, errored or will be soon. The sink can't do anything useful if it gets an error here, so
|
|
3435
|
-
// just treat it as a no-op.
|
|
3436
|
-
return;
|
|
3437
|
-
}
|
|
3438
|
-
WritableStreamDefaultControllerError(this, e);
|
|
3439
|
-
}
|
|
3440
|
-
/** @internal */
|
|
3441
|
-
[AbortSteps](reason) {
|
|
3442
|
-
const result = this._abortAlgorithm(reason);
|
|
3443
|
-
WritableStreamDefaultControllerClearAlgorithms(this);
|
|
3444
|
-
return result;
|
|
3445
|
-
}
|
|
3446
|
-
/** @internal */
|
|
3447
|
-
[ErrorSteps]() {
|
|
3448
|
-
ResetQueue(this);
|
|
3449
|
-
}
|
|
3450
|
-
}
|
|
3451
|
-
Object.defineProperties(WritableStreamDefaultController.prototype, {
|
|
3452
|
-
abortReason: { enumerable: true },
|
|
3453
|
-
signal: { enumerable: true },
|
|
3454
|
-
error: { enumerable: true }
|
|
3455
|
-
});
|
|
3456
|
-
// Abstract operations implementing interface required by the WritableStream.
|
|
3457
|
-
function IsWritableStreamDefaultController(x) {
|
|
3458
|
-
if (!typeIsObject(x)) {
|
|
3459
|
-
return false;
|
|
3460
|
-
}
|
|
3461
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_controlledWritableStream')) {
|
|
3462
|
-
return false;
|
|
3463
|
-
}
|
|
3464
|
-
return x instanceof WritableStreamDefaultController;
|
|
3465
|
-
}
|
|
3466
|
-
function SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm) {
|
|
3467
|
-
controller._controlledWritableStream = stream;
|
|
3468
|
-
stream._writableStreamController = controller;
|
|
3469
|
-
// Need to set the slots so that the assert doesn't fire. In the spec the slots already exist implicitly.
|
|
3470
|
-
controller._queue = undefined;
|
|
3471
|
-
controller._queueTotalSize = undefined;
|
|
3472
|
-
ResetQueue(controller);
|
|
3473
|
-
controller._abortReason = undefined;
|
|
3474
|
-
controller._abortController = new AbortController();
|
|
3475
|
-
controller._started = false;
|
|
3476
|
-
controller._strategySizeAlgorithm = sizeAlgorithm;
|
|
3477
|
-
controller._strategyHWM = highWaterMark;
|
|
3478
|
-
controller._writeAlgorithm = writeAlgorithm;
|
|
3479
|
-
controller._closeAlgorithm = closeAlgorithm;
|
|
3480
|
-
controller._abortAlgorithm = abortAlgorithm;
|
|
3481
|
-
const backpressure = WritableStreamDefaultControllerGetBackpressure(controller);
|
|
3482
|
-
WritableStreamUpdateBackpressure(stream, backpressure);
|
|
3483
|
-
const startResult = startAlgorithm();
|
|
3484
|
-
const startPromise = promiseResolvedWith(startResult);
|
|
3485
|
-
uponPromise(startPromise, () => {
|
|
3486
|
-
controller._started = true;
|
|
3487
|
-
WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
|
|
3488
|
-
}, r => {
|
|
3489
|
-
controller._started = true;
|
|
3490
|
-
WritableStreamDealWithRejection(stream, r);
|
|
3491
|
-
});
|
|
3492
|
-
}
|
|
3493
|
-
function SetUpWritableStreamDefaultControllerFromUnderlyingSink(stream, underlyingSink, highWaterMark, sizeAlgorithm) {
|
|
3494
|
-
const controller = Object.create(WritableStreamDefaultController.prototype);
|
|
3495
|
-
let startAlgorithm = () => undefined;
|
|
3496
|
-
let writeAlgorithm = () => promiseResolvedWith(undefined);
|
|
3497
|
-
let closeAlgorithm = () => promiseResolvedWith(undefined);
|
|
3498
|
-
let abortAlgorithm = () => promiseResolvedWith(undefined);
|
|
3499
|
-
if (underlyingSink.start !== undefined) {
|
|
3500
|
-
startAlgorithm = () => underlyingSink.start(controller);
|
|
3501
|
-
}
|
|
3502
|
-
if (underlyingSink.write !== undefined) {
|
|
3503
|
-
writeAlgorithm = chunk => underlyingSink.write(chunk, controller);
|
|
3504
|
-
}
|
|
3505
|
-
if (underlyingSink.close !== undefined) {
|
|
3506
|
-
closeAlgorithm = () => underlyingSink.close();
|
|
3507
|
-
}
|
|
3508
|
-
if (underlyingSink.abort !== undefined) {
|
|
3509
|
-
abortAlgorithm = reason => underlyingSink.abort(reason);
|
|
3510
|
-
}
|
|
3511
|
-
SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm);
|
|
3512
|
-
}
|
|
3513
|
-
// ClearAlgorithms may be called twice. Erroring the same stream in multiple ways will often result in redundant calls.
|
|
3514
|
-
function WritableStreamDefaultControllerClearAlgorithms(controller) {
|
|
3515
|
-
controller._writeAlgorithm = undefined;
|
|
3516
|
-
controller._closeAlgorithm = undefined;
|
|
3517
|
-
controller._abortAlgorithm = undefined;
|
|
3518
|
-
controller._strategySizeAlgorithm = undefined;
|
|
3519
|
-
}
|
|
3520
|
-
function WritableStreamDefaultControllerClose(controller) {
|
|
3521
|
-
EnqueueValueWithSize(controller, closeSentinel, 0);
|
|
3522
|
-
WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
|
|
3523
|
-
}
|
|
3524
|
-
function WritableStreamDefaultControllerGetChunkSize(controller, chunk) {
|
|
3525
|
-
try {
|
|
3526
|
-
return controller._strategySizeAlgorithm(chunk);
|
|
3527
|
-
}
|
|
3528
|
-
catch (chunkSizeE) {
|
|
3529
|
-
WritableStreamDefaultControllerErrorIfNeeded(controller, chunkSizeE);
|
|
3530
|
-
return 1;
|
|
3531
|
-
}
|
|
3532
|
-
}
|
|
3533
|
-
function WritableStreamDefaultControllerGetDesiredSize(controller) {
|
|
3534
|
-
return controller._strategyHWM - controller._queueTotalSize;
|
|
3535
|
-
}
|
|
3536
|
-
function WritableStreamDefaultControllerWrite(controller, chunk, chunkSize) {
|
|
3537
|
-
try {
|
|
3538
|
-
EnqueueValueWithSize(controller, chunk, chunkSize);
|
|
3539
|
-
}
|
|
3540
|
-
catch (enqueueE) {
|
|
3541
|
-
WritableStreamDefaultControllerErrorIfNeeded(controller, enqueueE);
|
|
3542
|
-
return;
|
|
3543
|
-
}
|
|
3544
|
-
const stream = controller._controlledWritableStream;
|
|
3545
|
-
if (!WritableStreamCloseQueuedOrInFlight(stream) && stream._state === 'writable') {
|
|
3546
|
-
const backpressure = WritableStreamDefaultControllerGetBackpressure(controller);
|
|
3547
|
-
WritableStreamUpdateBackpressure(stream, backpressure);
|
|
3548
|
-
}
|
|
3549
|
-
WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
|
|
3550
|
-
}
|
|
3551
|
-
// Abstract operations for the WritableStreamDefaultController.
|
|
3552
|
-
function WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller) {
|
|
3553
|
-
const stream = controller._controlledWritableStream;
|
|
3554
|
-
if (!controller._started) {
|
|
3555
|
-
return;
|
|
3556
|
-
}
|
|
3557
|
-
if (stream._inFlightWriteRequest !== undefined) {
|
|
3558
|
-
return;
|
|
3559
|
-
}
|
|
3560
|
-
const state = stream._state;
|
|
3561
|
-
if (state === 'erroring') {
|
|
3562
|
-
WritableStreamFinishErroring(stream);
|
|
3563
|
-
return;
|
|
3564
|
-
}
|
|
3565
|
-
if (controller._queue.length === 0) {
|
|
3566
|
-
return;
|
|
3567
|
-
}
|
|
3568
|
-
const value = PeekQueueValue(controller);
|
|
3569
|
-
if (value === closeSentinel) {
|
|
3570
|
-
WritableStreamDefaultControllerProcessClose(controller);
|
|
3571
|
-
}
|
|
3572
|
-
else {
|
|
3573
|
-
WritableStreamDefaultControllerProcessWrite(controller, value);
|
|
3574
|
-
}
|
|
3575
|
-
}
|
|
3576
|
-
function WritableStreamDefaultControllerErrorIfNeeded(controller, error) {
|
|
3577
|
-
if (controller._controlledWritableStream._state === 'writable') {
|
|
3578
|
-
WritableStreamDefaultControllerError(controller, error);
|
|
3579
|
-
}
|
|
3580
|
-
}
|
|
3581
|
-
function WritableStreamDefaultControllerProcessClose(controller) {
|
|
3582
|
-
const stream = controller._controlledWritableStream;
|
|
3583
|
-
WritableStreamMarkCloseRequestInFlight(stream);
|
|
3584
|
-
DequeueValue(controller);
|
|
3585
|
-
const sinkClosePromise = controller._closeAlgorithm();
|
|
3586
|
-
WritableStreamDefaultControllerClearAlgorithms(controller);
|
|
3587
|
-
uponPromise(sinkClosePromise, () => {
|
|
3588
|
-
WritableStreamFinishInFlightClose(stream);
|
|
3589
|
-
}, reason => {
|
|
3590
|
-
WritableStreamFinishInFlightCloseWithError(stream, reason);
|
|
3591
|
-
});
|
|
3592
|
-
}
|
|
3593
|
-
function WritableStreamDefaultControllerProcessWrite(controller, chunk) {
|
|
3594
|
-
const stream = controller._controlledWritableStream;
|
|
3595
|
-
WritableStreamMarkFirstWriteRequestInFlight(stream);
|
|
3596
|
-
const sinkWritePromise = controller._writeAlgorithm(chunk);
|
|
3597
|
-
uponPromise(sinkWritePromise, () => {
|
|
3598
|
-
WritableStreamFinishInFlightWrite(stream);
|
|
3599
|
-
const state = stream._state;
|
|
3600
|
-
DequeueValue(controller);
|
|
3601
|
-
if (!WritableStreamCloseQueuedOrInFlight(stream) && state === 'writable') {
|
|
3602
|
-
const backpressure = WritableStreamDefaultControllerGetBackpressure(controller);
|
|
3603
|
-
WritableStreamUpdateBackpressure(stream, backpressure);
|
|
3604
|
-
}
|
|
3605
|
-
WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
|
|
3606
|
-
}, reason => {
|
|
3607
|
-
if (stream._state === 'writable') {
|
|
3608
|
-
WritableStreamDefaultControllerClearAlgorithms(controller);
|
|
3609
|
-
}
|
|
3610
|
-
WritableStreamFinishInFlightWriteWithError(stream, reason);
|
|
3611
|
-
});
|
|
3612
|
-
}
|
|
3613
|
-
function WritableStreamDefaultControllerGetBackpressure(controller) {
|
|
3614
|
-
const desiredSize = WritableStreamDefaultControllerGetDesiredSize(controller);
|
|
3615
|
-
return desiredSize <= 0;
|
|
3616
|
-
}
|
|
3617
|
-
// A client of WritableStreamDefaultController may use these functions directly to bypass state check.
|
|
3618
|
-
function WritableStreamDefaultControllerError(controller, error) {
|
|
3619
|
-
const stream = controller._controlledWritableStream;
|
|
3620
|
-
WritableStreamDefaultControllerClearAlgorithms(controller);
|
|
3621
|
-
WritableStreamStartErroring(stream, error);
|
|
3622
|
-
}
|
|
3623
|
-
// Helper functions for the WritableStream.
|
|
3624
|
-
function streamBrandCheckException$2(name) {
|
|
3625
|
-
return new TypeError(`WritableStream.prototype.${name} can only be used on a WritableStream`);
|
|
3626
|
-
}
|
|
3627
|
-
// Helper functions for the WritableStreamDefaultController.
|
|
3628
|
-
function defaultControllerBrandCheckException$2(name) {
|
|
3629
|
-
return new TypeError(`WritableStreamDefaultController.prototype.${name} can only be used on a WritableStreamDefaultController`);
|
|
3630
|
-
}
|
|
3631
|
-
// Helper functions for the WritableStreamDefaultWriter.
|
|
3632
|
-
function defaultWriterBrandCheckException(name) {
|
|
3633
|
-
return new TypeError(`WritableStreamDefaultWriter.prototype.${name} can only be used on a WritableStreamDefaultWriter`);
|
|
3634
|
-
}
|
|
3635
|
-
function defaultWriterLockException(name) {
|
|
3636
|
-
return new TypeError('Cannot ' + name + ' a stream using a released writer');
|
|
3637
|
-
}
|
|
3638
|
-
function defaultWriterClosedPromiseInitialize(writer) {
|
|
3639
|
-
writer._closedPromise = newPromise((resolve, reject) => {
|
|
3640
|
-
writer._closedPromise_resolve = resolve;
|
|
3641
|
-
writer._closedPromise_reject = reject;
|
|
3642
|
-
writer._closedPromiseState = 'pending';
|
|
3643
|
-
});
|
|
3644
|
-
}
|
|
3645
|
-
function defaultWriterClosedPromiseInitializeAsRejected(writer, reason) {
|
|
3646
|
-
defaultWriterClosedPromiseInitialize(writer);
|
|
3647
|
-
defaultWriterClosedPromiseReject(writer, reason);
|
|
3648
|
-
}
|
|
3649
|
-
function defaultWriterClosedPromiseInitializeAsResolved(writer) {
|
|
3650
|
-
defaultWriterClosedPromiseInitialize(writer);
|
|
3651
|
-
defaultWriterClosedPromiseResolve(writer);
|
|
3652
|
-
}
|
|
3653
|
-
function defaultWriterClosedPromiseReject(writer, reason) {
|
|
3654
|
-
if (writer._closedPromise_reject === undefined) {
|
|
3655
|
-
return;
|
|
3656
|
-
}
|
|
3657
|
-
setPromiseIsHandledToTrue(writer._closedPromise);
|
|
3658
|
-
writer._closedPromise_reject(reason);
|
|
3659
|
-
writer._closedPromise_resolve = undefined;
|
|
3660
|
-
writer._closedPromise_reject = undefined;
|
|
3661
|
-
writer._closedPromiseState = 'rejected';
|
|
3662
|
-
}
|
|
3663
|
-
function defaultWriterClosedPromiseResetToRejected(writer, reason) {
|
|
3664
|
-
defaultWriterClosedPromiseInitializeAsRejected(writer, reason);
|
|
3665
|
-
}
|
|
3666
|
-
function defaultWriterClosedPromiseResolve(writer) {
|
|
3667
|
-
if (writer._closedPromise_resolve === undefined) {
|
|
3668
|
-
return;
|
|
3669
|
-
}
|
|
3670
|
-
writer._closedPromise_resolve(undefined);
|
|
3671
|
-
writer._closedPromise_resolve = undefined;
|
|
3672
|
-
writer._closedPromise_reject = undefined;
|
|
3673
|
-
writer._closedPromiseState = 'resolved';
|
|
3674
|
-
}
|
|
3675
|
-
function defaultWriterReadyPromiseInitialize(writer) {
|
|
3676
|
-
writer._readyPromise = newPromise((resolve, reject) => {
|
|
3677
|
-
writer._readyPromise_resolve = resolve;
|
|
3678
|
-
writer._readyPromise_reject = reject;
|
|
3679
|
-
});
|
|
3680
|
-
writer._readyPromiseState = 'pending';
|
|
3681
|
-
}
|
|
3682
|
-
function defaultWriterReadyPromiseInitializeAsRejected(writer, reason) {
|
|
3683
|
-
defaultWriterReadyPromiseInitialize(writer);
|
|
3684
|
-
defaultWriterReadyPromiseReject(writer, reason);
|
|
3685
|
-
}
|
|
3686
|
-
function defaultWriterReadyPromiseInitializeAsResolved(writer) {
|
|
3687
|
-
defaultWriterReadyPromiseInitialize(writer);
|
|
3688
|
-
defaultWriterReadyPromiseResolve(writer);
|
|
3689
|
-
}
|
|
3690
|
-
function defaultWriterReadyPromiseReject(writer, reason) {
|
|
3691
|
-
if (writer._readyPromise_reject === undefined) {
|
|
3692
|
-
return;
|
|
3693
|
-
}
|
|
3694
|
-
setPromiseIsHandledToTrue(writer._readyPromise);
|
|
3695
|
-
writer._readyPromise_reject(reason);
|
|
3696
|
-
writer._readyPromise_resolve = undefined;
|
|
3697
|
-
writer._readyPromise_reject = undefined;
|
|
3698
|
-
writer._readyPromiseState = 'rejected';
|
|
3699
|
-
}
|
|
3700
|
-
function defaultWriterReadyPromiseReset(writer) {
|
|
3701
|
-
defaultWriterReadyPromiseInitialize(writer);
|
|
3702
|
-
}
|
|
3703
|
-
function defaultWriterReadyPromiseResetToRejected(writer, reason) {
|
|
3704
|
-
defaultWriterReadyPromiseInitializeAsRejected(writer, reason);
|
|
3705
|
-
}
|
|
3706
|
-
function defaultWriterReadyPromiseResolve(writer) {
|
|
3707
|
-
if (writer._readyPromise_resolve === undefined) {
|
|
3708
|
-
return;
|
|
3709
|
-
}
|
|
3710
|
-
writer._readyPromise_resolve(undefined);
|
|
3711
|
-
writer._readyPromise_resolve = undefined;
|
|
3712
|
-
writer._readyPromise_reject = undefined;
|
|
3713
|
-
writer._readyPromiseState = 'fulfilled';
|
|
3714
|
-
}
|
|
3715
|
-
// eslint-disable-next-line no-redeclarelet DOMException$1=DOMException
|
|
3716
|
-
|
|
3717
|
-
function ReadableStreamPipeTo(source, dest, preventClose, preventAbort, preventCancel, signal) {
|
|
3718
|
-
const reader = AcquireReadableStreamDefaultReader(source);
|
|
3719
|
-
const writer = AcquireWritableStreamDefaultWriter(dest);
|
|
3720
|
-
source._disturbed = true;
|
|
3721
|
-
let shuttingDown = false;
|
|
3722
|
-
// This is used to keep track of the spec's requirement that we wait for ongoing writes during shutdown.
|
|
3723
|
-
let currentWrite = promiseResolvedWith(undefined);
|
|
3724
|
-
return newPromise((resolve, reject) => {
|
|
3725
|
-
let abortAlgorithm;
|
|
3726
|
-
if (signal !== undefined) {
|
|
3727
|
-
abortAlgorithm = () => {
|
|
3728
|
-
const error =new DOMException('Aborted', 'AbortError');
|
|
3729
|
-
const actions = [];
|
|
3730
|
-
if (!preventAbort) {
|
|
3731
|
-
actions.push(() => {
|
|
3732
|
-
if (dest._state === 'writable') {
|
|
3733
|
-
return WritableStreamAbort(dest, error);
|
|
3734
|
-
}
|
|
3735
|
-
return promiseResolvedWith(undefined);
|
|
3736
|
-
});
|
|
3737
|
-
}
|
|
3738
|
-
if (!preventCancel) {
|
|
3739
|
-
actions.push(() => {
|
|
3740
|
-
if (source._state === 'readable') {
|
|
3741
|
-
return ReadableStreamCancel(source, error);
|
|
3742
|
-
}
|
|
3743
|
-
return promiseResolvedWith(undefined);
|
|
3744
|
-
});
|
|
3745
|
-
}
|
|
3746
|
-
shutdownWithAction(() => Promise.all(actions.map(action => action())), true, error);
|
|
3747
|
-
};
|
|
3748
|
-
if (signal.aborted) {
|
|
3749
|
-
abortAlgorithm();
|
|
3750
|
-
return;
|
|
3751
|
-
}
|
|
3752
|
-
signal.addEventListener('abort', abortAlgorithm);
|
|
3753
|
-
}
|
|
3754
|
-
// Using reader and writer, read all chunks from this and write them to dest
|
|
3755
|
-
// - Backpressure must be enforced
|
|
3756
|
-
// - Shutdown must stop all activity
|
|
3757
|
-
function pipeLoop() {
|
|
3758
|
-
return newPromise((resolveLoop, rejectLoop) => {
|
|
3759
|
-
function next(done) {
|
|
3760
|
-
if (done) {
|
|
3761
|
-
resolveLoop();
|
|
3762
|
-
}
|
|
3763
|
-
else {
|
|
3764
|
-
// Use `PerformPromiseThen` instead of `uponPromise` to avoid
|
|
3765
|
-
// adding unnecessary `.catch(rethrowAssertionErrorRejection)` handlers
|
|
3766
|
-
PerformPromiseThen(pipeStep(), next, rejectLoop);
|
|
3767
|
-
}
|
|
3768
|
-
}
|
|
3769
|
-
next(false);
|
|
3770
|
-
});
|
|
3771
|
-
}
|
|
3772
|
-
function pipeStep() {
|
|
3773
|
-
if (shuttingDown) {
|
|
3774
|
-
return promiseResolvedWith(true);
|
|
3775
|
-
}
|
|
3776
|
-
return PerformPromiseThen(writer._readyPromise, () => {
|
|
3777
|
-
return newPromise((resolveRead, rejectRead) => {
|
|
3778
|
-
ReadableStreamDefaultReaderRead(reader, {
|
|
3779
|
-
_chunkSteps: chunk => {
|
|
3780
|
-
currentWrite = PerformPromiseThen(WritableStreamDefaultWriterWrite(writer, chunk), undefined, noop);
|
|
3781
|
-
resolveRead(false);
|
|
3782
|
-
},
|
|
3783
|
-
_closeSteps: () => resolveRead(true),
|
|
3784
|
-
_errorSteps: rejectRead
|
|
3785
|
-
});
|
|
3786
|
-
});
|
|
3787
|
-
});
|
|
3788
|
-
}
|
|
3789
|
-
// Errors must be propagated forward
|
|
3790
|
-
isOrBecomesErrored(source, reader._closedPromise, storedError => {
|
|
3791
|
-
if (!preventAbort) {
|
|
3792
|
-
shutdownWithAction(() => WritableStreamAbort(dest, storedError), true, storedError);
|
|
3793
|
-
}
|
|
3794
|
-
else {
|
|
3795
|
-
shutdown(true, storedError);
|
|
3796
|
-
}
|
|
3797
|
-
});
|
|
3798
|
-
// Errors must be propagated backward
|
|
3799
|
-
isOrBecomesErrored(dest, writer._closedPromise, storedError => {
|
|
3800
|
-
if (!preventCancel) {
|
|
3801
|
-
shutdownWithAction(() => ReadableStreamCancel(source, storedError), true, storedError);
|
|
3802
|
-
}
|
|
3803
|
-
else {
|
|
3804
|
-
shutdown(true, storedError);
|
|
3805
|
-
}
|
|
3806
|
-
});
|
|
3807
|
-
// Closing must be propagated forward
|
|
3808
|
-
isOrBecomesClosed(source, reader._closedPromise, () => {
|
|
3809
|
-
if (!preventClose) {
|
|
3810
|
-
shutdownWithAction(() => WritableStreamDefaultWriterCloseWithErrorPropagation(writer));
|
|
3811
|
-
}
|
|
3812
|
-
else {
|
|
3813
|
-
shutdown();
|
|
3814
|
-
}
|
|
3815
|
-
});
|
|
3816
|
-
// Closing must be propagated backward
|
|
3817
|
-
if (WritableStreamCloseQueuedOrInFlight(dest) || dest._state === 'closed') {
|
|
3818
|
-
const destClosed = new TypeError('the destination writable stream closed before all data could be piped to it');
|
|
3819
|
-
if (!preventCancel) {
|
|
3820
|
-
shutdownWithAction(() => ReadableStreamCancel(source, destClosed), true, destClosed);
|
|
3821
|
-
}
|
|
3822
|
-
else {
|
|
3823
|
-
shutdown(true, destClosed);
|
|
3824
|
-
}
|
|
3825
|
-
}
|
|
3826
|
-
setPromiseIsHandledToTrue(pipeLoop());
|
|
3827
|
-
function waitForWritesToFinish() {
|
|
3828
|
-
// Another write may have started while we were waiting on this currentWrite, so we have to be sure to wait
|
|
3829
|
-
// for that too.
|
|
3830
|
-
const oldCurrentWrite = currentWrite;
|
|
3831
|
-
return PerformPromiseThen(currentWrite, () => oldCurrentWrite !== currentWrite ? waitForWritesToFinish() : undefined);
|
|
3832
|
-
}
|
|
3833
|
-
function isOrBecomesErrored(stream, promise, action) {
|
|
3834
|
-
if (stream._state === 'errored') {
|
|
3835
|
-
action(stream._storedError);
|
|
3836
|
-
}
|
|
3837
|
-
else {
|
|
3838
|
-
uponRejection(promise, action);
|
|
3839
|
-
}
|
|
3840
|
-
}
|
|
3841
|
-
function isOrBecomesClosed(stream, promise, action) {
|
|
3842
|
-
if (stream._state === 'closed') {
|
|
3843
|
-
action();
|
|
3844
|
-
}
|
|
3845
|
-
else {
|
|
3846
|
-
uponFulfillment(promise, action);
|
|
3847
|
-
}
|
|
3848
|
-
}
|
|
3849
|
-
function shutdownWithAction(action, originalIsError, originalError) {
|
|
3850
|
-
if (shuttingDown) {
|
|
3851
|
-
return;
|
|
3852
|
-
}
|
|
3853
|
-
shuttingDown = true;
|
|
3854
|
-
if (dest._state === 'writable' && !WritableStreamCloseQueuedOrInFlight(dest)) {
|
|
3855
|
-
uponFulfillment(waitForWritesToFinish(), doTheRest);
|
|
3856
|
-
}
|
|
3857
|
-
else {
|
|
3858
|
-
doTheRest();
|
|
3859
|
-
}
|
|
3860
|
-
function doTheRest() {
|
|
3861
|
-
uponPromise(action(), () => finalize(originalIsError, originalError), newError => finalize(true, newError));
|
|
3862
|
-
}
|
|
3863
|
-
}
|
|
3864
|
-
function shutdown(isError, error) {
|
|
3865
|
-
if (shuttingDown) {
|
|
3866
|
-
return;
|
|
3867
|
-
}
|
|
3868
|
-
shuttingDown = true;
|
|
3869
|
-
if (dest._state === 'writable' && !WritableStreamCloseQueuedOrInFlight(dest)) {
|
|
3870
|
-
uponFulfillment(waitForWritesToFinish(), () => finalize(isError, error));
|
|
3871
|
-
}
|
|
3872
|
-
else {
|
|
3873
|
-
finalize(isError, error);
|
|
3874
|
-
}
|
|
3875
|
-
}
|
|
3876
|
-
function finalize(isError, error) {
|
|
3877
|
-
WritableStreamDefaultWriterRelease(writer);
|
|
3878
|
-
ReadableStreamReaderGenericRelease(reader);
|
|
3879
|
-
if (signal !== undefined) {
|
|
3880
|
-
signal.removeEventListener('abort', abortAlgorithm);
|
|
3881
|
-
}
|
|
3882
|
-
if (isError) {
|
|
3883
|
-
reject(error);
|
|
3884
|
-
}
|
|
3885
|
-
else {
|
|
3886
|
-
resolve(undefined);
|
|
3887
|
-
}
|
|
3888
|
-
}
|
|
3889
|
-
});
|
|
3890
|
-
}
|
|
3891
|
-
|
|
3892
|
-
/**
|
|
3893
|
-
* Allows control of a {@link ReadableStream | readable stream}'s state and internal queue.
|
|
3894
|
-
*
|
|
3895
|
-
* @public
|
|
3896
|
-
*/
|
|
3897
|
-
class ReadableStreamDefaultController {
|
|
3898
|
-
constructor() {
|
|
3899
|
-
throw new TypeError('Illegal constructor');
|
|
3900
|
-
}
|
|
3901
|
-
/**
|
|
3902
|
-
* Returns the desired size to fill the controlled stream's internal queue. It can be negative, if the queue is
|
|
3903
|
-
* over-full. An underlying source ought to use this information to determine when and how to apply backpressure.
|
|
3904
|
-
*/
|
|
3905
|
-
get desiredSize() {
|
|
3906
|
-
if (!IsReadableStreamDefaultController(this)) {
|
|
3907
|
-
throw defaultControllerBrandCheckException$1('desiredSize');
|
|
3908
|
-
}
|
|
3909
|
-
return ReadableStreamDefaultControllerGetDesiredSize(this);
|
|
3910
|
-
}
|
|
3911
|
-
/**
|
|
3912
|
-
* Closes the controlled readable stream. Consumers will still be able to read any previously-enqueued chunks from
|
|
3913
|
-
* the stream, but once those are read, the stream will become closed.
|
|
3914
|
-
*/
|
|
3915
|
-
close() {
|
|
3916
|
-
if (!IsReadableStreamDefaultController(this)) {
|
|
3917
|
-
throw defaultControllerBrandCheckException$1('close');
|
|
3918
|
-
}
|
|
3919
|
-
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(this)) {
|
|
3920
|
-
throw new TypeError('The stream is not in a state that permits close');
|
|
3921
|
-
}
|
|
3922
|
-
ReadableStreamDefaultControllerClose(this);
|
|
3923
|
-
}
|
|
3924
|
-
enqueue(chunk = undefined) {
|
|
3925
|
-
if (!IsReadableStreamDefaultController(this)) {
|
|
3926
|
-
throw defaultControllerBrandCheckException$1('enqueue');
|
|
3927
|
-
}
|
|
3928
|
-
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(this)) {
|
|
3929
|
-
throw new TypeError('The stream is not in a state that permits enqueue');
|
|
3930
|
-
}
|
|
3931
|
-
return ReadableStreamDefaultControllerEnqueue(this, chunk);
|
|
3932
|
-
}
|
|
3933
|
-
/**
|
|
3934
|
-
* Errors the controlled readable stream, making all future interactions with it fail with the given error `e`.
|
|
3935
|
-
*/
|
|
3936
|
-
error(e = undefined) {
|
|
3937
|
-
if (!IsReadableStreamDefaultController(this)) {
|
|
3938
|
-
throw defaultControllerBrandCheckException$1('error');
|
|
3939
|
-
}
|
|
3940
|
-
ReadableStreamDefaultControllerError(this, e);
|
|
3941
|
-
}
|
|
3942
|
-
/** @internal */
|
|
3943
|
-
[CancelSteps](reason) {
|
|
3944
|
-
ResetQueue(this);
|
|
3945
|
-
const result = this._cancelAlgorithm(reason);
|
|
3946
|
-
ReadableStreamDefaultControllerClearAlgorithms(this);
|
|
3947
|
-
return result;
|
|
3948
|
-
}
|
|
3949
|
-
/** @internal */
|
|
3950
|
-
[PullSteps](readRequest) {
|
|
3951
|
-
const stream = this._controlledReadableStream;
|
|
3952
|
-
if (this._queue.length > 0) {
|
|
3953
|
-
const chunk = DequeueValue(this);
|
|
3954
|
-
if (this._closeRequested && this._queue.length === 0) {
|
|
3955
|
-
ReadableStreamDefaultControllerClearAlgorithms(this);
|
|
3956
|
-
ReadableStreamClose(stream);
|
|
3957
|
-
}
|
|
3958
|
-
else {
|
|
3959
|
-
ReadableStreamDefaultControllerCallPullIfNeeded(this);
|
|
3960
|
-
}
|
|
3961
|
-
readRequest._chunkSteps(chunk);
|
|
3962
|
-
}
|
|
3963
|
-
else {
|
|
3964
|
-
ReadableStreamAddReadRequest(stream, readRequest);
|
|
3965
|
-
ReadableStreamDefaultControllerCallPullIfNeeded(this);
|
|
3966
|
-
}
|
|
3967
|
-
}
|
|
3968
|
-
}
|
|
3969
|
-
Object.defineProperties(ReadableStreamDefaultController.prototype, {
|
|
3970
|
-
close: { enumerable: true },
|
|
3971
|
-
enqueue: { enumerable: true },
|
|
3972
|
-
error: { enumerable: true },
|
|
3973
|
-
desiredSize: { enumerable: true }
|
|
3974
|
-
});
|
|
3975
|
-
// Abstract operations for the ReadableStreamDefaultController.
|
|
3976
|
-
function IsReadableStreamDefaultController(x) {
|
|
3977
|
-
if (!typeIsObject(x)) {
|
|
3978
|
-
return false;
|
|
3979
|
-
}
|
|
3980
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_controlledReadableStream')) {
|
|
3981
|
-
return false;
|
|
3982
|
-
}
|
|
3983
|
-
return x instanceof ReadableStreamDefaultController;
|
|
3984
|
-
}
|
|
3985
|
-
function ReadableStreamDefaultControllerCallPullIfNeeded(controller) {
|
|
3986
|
-
const shouldPull = ReadableStreamDefaultControllerShouldCallPull(controller);
|
|
3987
|
-
if (!shouldPull) {
|
|
3988
|
-
return;
|
|
3989
|
-
}
|
|
3990
|
-
if (controller._pulling) {
|
|
3991
|
-
controller._pullAgain = true;
|
|
3992
|
-
return;
|
|
3993
|
-
}
|
|
3994
|
-
controller._pulling = true;
|
|
3995
|
-
const pullPromise = controller._pullAlgorithm();
|
|
3996
|
-
uponPromise(pullPromise, () => {
|
|
3997
|
-
controller._pulling = false;
|
|
3998
|
-
if (controller._pullAgain) {
|
|
3999
|
-
controller._pullAgain = false;
|
|
4000
|
-
ReadableStreamDefaultControllerCallPullIfNeeded(controller);
|
|
4001
|
-
}
|
|
4002
|
-
}, e => {
|
|
4003
|
-
ReadableStreamDefaultControllerError(controller, e);
|
|
4004
|
-
});
|
|
4005
|
-
}
|
|
4006
|
-
function ReadableStreamDefaultControllerShouldCallPull(controller) {
|
|
4007
|
-
const stream = controller._controlledReadableStream;
|
|
4008
|
-
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(controller)) {
|
|
4009
|
-
return false;
|
|
4010
|
-
}
|
|
4011
|
-
if (!controller._started) {
|
|
4012
|
-
return false;
|
|
4013
|
-
}
|
|
4014
|
-
if (IsReadableStreamLocked(stream) && ReadableStreamGetNumReadRequests(stream) > 0) {
|
|
4015
|
-
return true;
|
|
4016
|
-
}
|
|
4017
|
-
const desiredSize = ReadableStreamDefaultControllerGetDesiredSize(controller);
|
|
4018
|
-
if (desiredSize > 0) {
|
|
4019
|
-
return true;
|
|
4020
|
-
}
|
|
4021
|
-
return false;
|
|
4022
|
-
}
|
|
4023
|
-
function ReadableStreamDefaultControllerClearAlgorithms(controller) {
|
|
4024
|
-
controller._pullAlgorithm = undefined;
|
|
4025
|
-
controller._cancelAlgorithm = undefined;
|
|
4026
|
-
controller._strategySizeAlgorithm = undefined;
|
|
4027
|
-
}
|
|
4028
|
-
// A client of ReadableStreamDefaultController may use these functions directly to bypass state check.
|
|
4029
|
-
function ReadableStreamDefaultControllerClose(controller) {
|
|
4030
|
-
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(controller)) {
|
|
4031
|
-
return;
|
|
4032
|
-
}
|
|
4033
|
-
const stream = controller._controlledReadableStream;
|
|
4034
|
-
controller._closeRequested = true;
|
|
4035
|
-
if (controller._queue.length === 0) {
|
|
4036
|
-
ReadableStreamDefaultControllerClearAlgorithms(controller);
|
|
4037
|
-
ReadableStreamClose(stream);
|
|
4038
|
-
}
|
|
4039
|
-
}
|
|
4040
|
-
function ReadableStreamDefaultControllerEnqueue(controller, chunk) {
|
|
4041
|
-
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(controller)) {
|
|
4042
|
-
return;
|
|
4043
|
-
}
|
|
4044
|
-
const stream = controller._controlledReadableStream;
|
|
4045
|
-
if (IsReadableStreamLocked(stream) && ReadableStreamGetNumReadRequests(stream) > 0) {
|
|
4046
|
-
ReadableStreamFulfillReadRequest(stream, chunk, false);
|
|
4047
|
-
}
|
|
4048
|
-
else {
|
|
4049
|
-
let chunkSize;
|
|
4050
|
-
try {
|
|
4051
|
-
chunkSize = controller._strategySizeAlgorithm(chunk);
|
|
4052
|
-
}
|
|
4053
|
-
catch (chunkSizeE) {
|
|
4054
|
-
ReadableStreamDefaultControllerError(controller, chunkSizeE);
|
|
4055
|
-
throw chunkSizeE;
|
|
4056
|
-
}
|
|
4057
|
-
try {
|
|
4058
|
-
EnqueueValueWithSize(controller, chunk, chunkSize);
|
|
4059
|
-
}
|
|
4060
|
-
catch (enqueueE) {
|
|
4061
|
-
ReadableStreamDefaultControllerError(controller, enqueueE);
|
|
4062
|
-
throw enqueueE;
|
|
4063
|
-
}
|
|
4064
|
-
}
|
|
4065
|
-
ReadableStreamDefaultControllerCallPullIfNeeded(controller);
|
|
4066
|
-
}
|
|
4067
|
-
function ReadableStreamDefaultControllerError(controller, e) {
|
|
4068
|
-
const stream = controller._controlledReadableStream;
|
|
4069
|
-
if (stream._state !== 'readable') {
|
|
4070
|
-
return;
|
|
4071
|
-
}
|
|
4072
|
-
ResetQueue(controller);
|
|
4073
|
-
ReadableStreamDefaultControllerClearAlgorithms(controller);
|
|
4074
|
-
ReadableStreamError(stream, e);
|
|
4075
|
-
}
|
|
4076
|
-
function ReadableStreamDefaultControllerGetDesiredSize(controller) {
|
|
4077
|
-
const state = controller._controlledReadableStream._state;
|
|
4078
|
-
if (state === 'errored') {
|
|
4079
|
-
return null;
|
|
4080
|
-
}
|
|
4081
|
-
if (state === 'closed') {
|
|
4082
|
-
return 0;
|
|
4083
|
-
}
|
|
4084
|
-
return controller._strategyHWM - controller._queueTotalSize;
|
|
4085
|
-
}
|
|
4086
|
-
// This is used in the implementation of TransformStream.
|
|
4087
|
-
function ReadableStreamDefaultControllerHasBackpressure(controller) {
|
|
4088
|
-
if (ReadableStreamDefaultControllerShouldCallPull(controller)) {
|
|
4089
|
-
return false;
|
|
4090
|
-
}
|
|
4091
|
-
return true;
|
|
4092
|
-
}
|
|
4093
|
-
function ReadableStreamDefaultControllerCanCloseOrEnqueue(controller) {
|
|
4094
|
-
const state = controller._controlledReadableStream._state;
|
|
4095
|
-
if (!controller._closeRequested && state === 'readable') {
|
|
4096
|
-
return true;
|
|
4097
|
-
}
|
|
4098
|
-
return false;
|
|
4099
|
-
}
|
|
4100
|
-
function SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm) {
|
|
4101
|
-
controller._controlledReadableStream = stream;
|
|
4102
|
-
controller._queue = undefined;
|
|
4103
|
-
controller._queueTotalSize = undefined;
|
|
4104
|
-
ResetQueue(controller);
|
|
4105
|
-
controller._started = false;
|
|
4106
|
-
controller._closeRequested = false;
|
|
4107
|
-
controller._pullAgain = false;
|
|
4108
|
-
controller._pulling = false;
|
|
4109
|
-
controller._strategySizeAlgorithm = sizeAlgorithm;
|
|
4110
|
-
controller._strategyHWM = highWaterMark;
|
|
4111
|
-
controller._pullAlgorithm = pullAlgorithm;
|
|
4112
|
-
controller._cancelAlgorithm = cancelAlgorithm;
|
|
4113
|
-
stream._readableStreamController = controller;
|
|
4114
|
-
const startResult = startAlgorithm();
|
|
4115
|
-
uponPromise(promiseResolvedWith(startResult), () => {
|
|
4116
|
-
controller._started = true;
|
|
4117
|
-
ReadableStreamDefaultControllerCallPullIfNeeded(controller);
|
|
4118
|
-
}, r => {
|
|
4119
|
-
ReadableStreamDefaultControllerError(controller, r);
|
|
4120
|
-
});
|
|
4121
|
-
}
|
|
4122
|
-
function SetUpReadableStreamDefaultControllerFromUnderlyingSource(stream, underlyingSource, highWaterMark, sizeAlgorithm) {
|
|
4123
|
-
const controller = Object.create(ReadableStreamDefaultController.prototype);
|
|
4124
|
-
let startAlgorithm = () => undefined;
|
|
4125
|
-
let pullAlgorithm = () => promiseResolvedWith(undefined);
|
|
4126
|
-
let cancelAlgorithm = () => promiseResolvedWith(undefined);
|
|
4127
|
-
if (underlyingSource.start !== undefined) {
|
|
4128
|
-
startAlgorithm = () => underlyingSource.start(controller);
|
|
4129
|
-
}
|
|
4130
|
-
if (underlyingSource.pull !== undefined) {
|
|
4131
|
-
pullAlgorithm = () => underlyingSource.pull(controller);
|
|
4132
|
-
}
|
|
4133
|
-
if (underlyingSource.cancel !== undefined) {
|
|
4134
|
-
cancelAlgorithm = reason => underlyingSource.cancel(reason);
|
|
4135
|
-
}
|
|
4136
|
-
SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm);
|
|
4137
|
-
}
|
|
4138
|
-
// Helper functions for the ReadableStreamDefaultController.
|
|
4139
|
-
function defaultControllerBrandCheckException$1(name) {
|
|
4140
|
-
return new TypeError(`ReadableStreamDefaultController.prototype.${name} can only be used on a ReadableStreamDefaultController`);
|
|
4141
|
-
}
|
|
4142
|
-
|
|
4143
|
-
function ReadableStreamTee(stream, cloneForBranch2) {
|
|
4144
|
-
if (IsReadableByteStreamController(stream._readableStreamController)) {
|
|
4145
|
-
return ReadableByteStreamTee(stream);
|
|
4146
|
-
}
|
|
4147
|
-
return ReadableStreamDefaultTee(stream);
|
|
4148
|
-
}
|
|
4149
|
-
function ReadableStreamDefaultTee(stream, cloneForBranch2) {
|
|
4150
|
-
const reader = AcquireReadableStreamDefaultReader(stream);
|
|
4151
|
-
let reading = false;
|
|
4152
|
-
let readAgain = false;
|
|
4153
|
-
let canceled1 = false;
|
|
4154
|
-
let canceled2 = false;
|
|
4155
|
-
let reason1;
|
|
4156
|
-
let reason2;
|
|
4157
|
-
let branch1;
|
|
4158
|
-
let branch2;
|
|
4159
|
-
let resolveCancelPromise;
|
|
4160
|
-
const cancelPromise = newPromise(resolve => {
|
|
4161
|
-
resolveCancelPromise = resolve;
|
|
4162
|
-
});
|
|
4163
|
-
function pullAlgorithm() {
|
|
4164
|
-
if (reading) {
|
|
4165
|
-
readAgain = true;
|
|
4166
|
-
return promiseResolvedWith(undefined);
|
|
4167
|
-
}
|
|
4168
|
-
reading = true;
|
|
4169
|
-
const readRequest = {
|
|
4170
|
-
_chunkSteps: chunk => {
|
|
4171
|
-
// This needs to be delayed a microtask because it takes at least a microtask to detect errors (using
|
|
4172
|
-
// reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
|
|
4173
|
-
// successful synchronously-available reads get ahead of asynchronously-available errors.
|
|
4174
|
-
queueMicrotask(() => {
|
|
4175
|
-
readAgain = false;
|
|
4176
|
-
const chunk1 = chunk;
|
|
4177
|
-
const chunk2 = chunk;
|
|
4178
|
-
// There is no way to access the cloning code right now in the reference implementation.
|
|
4179
|
-
// If we add one then we'll need an implementation for serializable objects.
|
|
4180
|
-
// if (!canceled2 && cloneForBranch2) {
|
|
4181
|
-
// chunk2 = StructuredDeserialize(StructuredSerialize(chunk2));
|
|
4182
|
-
// }
|
|
4183
|
-
if (!canceled1) {
|
|
4184
|
-
ReadableStreamDefaultControllerEnqueue(branch1._readableStreamController, chunk1);
|
|
4185
|
-
}
|
|
4186
|
-
if (!canceled2) {
|
|
4187
|
-
ReadableStreamDefaultControllerEnqueue(branch2._readableStreamController, chunk2);
|
|
4188
|
-
}
|
|
4189
|
-
reading = false;
|
|
4190
|
-
if (readAgain) {
|
|
4191
|
-
pullAlgorithm();
|
|
4192
|
-
}
|
|
4193
|
-
});
|
|
4194
|
-
},
|
|
4195
|
-
_closeSteps: () => {
|
|
4196
|
-
reading = false;
|
|
4197
|
-
if (!canceled1) {
|
|
4198
|
-
ReadableStreamDefaultControllerClose(branch1._readableStreamController);
|
|
4199
|
-
}
|
|
4200
|
-
if (!canceled2) {
|
|
4201
|
-
ReadableStreamDefaultControllerClose(branch2._readableStreamController);
|
|
4202
|
-
}
|
|
4203
|
-
if (!canceled1 || !canceled2) {
|
|
4204
|
-
resolveCancelPromise(undefined);
|
|
4205
|
-
}
|
|
4206
|
-
},
|
|
4207
|
-
_errorSteps: () => {
|
|
4208
|
-
reading = false;
|
|
4209
|
-
}
|
|
4210
|
-
};
|
|
4211
|
-
ReadableStreamDefaultReaderRead(reader, readRequest);
|
|
4212
|
-
return promiseResolvedWith(undefined);
|
|
4213
|
-
}
|
|
4214
|
-
function cancel1Algorithm(reason) {
|
|
4215
|
-
canceled1 = true;
|
|
4216
|
-
reason1 = reason;
|
|
4217
|
-
if (canceled2) {
|
|
4218
|
-
const compositeReason = CreateArrayFromList([reason1, reason2]);
|
|
4219
|
-
const cancelResult = ReadableStreamCancel(stream, compositeReason);
|
|
4220
|
-
resolveCancelPromise(cancelResult);
|
|
4221
|
-
}
|
|
4222
|
-
return cancelPromise;
|
|
4223
|
-
}
|
|
4224
|
-
function cancel2Algorithm(reason) {
|
|
4225
|
-
canceled2 = true;
|
|
4226
|
-
reason2 = reason;
|
|
4227
|
-
if (canceled1) {
|
|
4228
|
-
const compositeReason = CreateArrayFromList([reason1, reason2]);
|
|
4229
|
-
const cancelResult = ReadableStreamCancel(stream, compositeReason);
|
|
4230
|
-
resolveCancelPromise(cancelResult);
|
|
4231
|
-
}
|
|
4232
|
-
return cancelPromise;
|
|
4233
|
-
}
|
|
4234
|
-
function startAlgorithm() {
|
|
4235
|
-
// do nothing
|
|
4236
|
-
}
|
|
4237
|
-
branch1 = CreateReadableStream(startAlgorithm, pullAlgorithm, cancel1Algorithm);
|
|
4238
|
-
branch2 = CreateReadableStream(startAlgorithm, pullAlgorithm, cancel2Algorithm);
|
|
4239
|
-
uponRejection(reader._closedPromise, (r) => {
|
|
4240
|
-
ReadableStreamDefaultControllerError(branch1._readableStreamController, r);
|
|
4241
|
-
ReadableStreamDefaultControllerError(branch2._readableStreamController, r);
|
|
4242
|
-
if (!canceled1 || !canceled2) {
|
|
4243
|
-
resolveCancelPromise(undefined);
|
|
4244
|
-
}
|
|
4245
|
-
});
|
|
4246
|
-
return [branch1, branch2];
|
|
4247
|
-
}
|
|
4248
|
-
function ReadableByteStreamTee(stream) {
|
|
4249
|
-
let reader = AcquireReadableStreamDefaultReader(stream);
|
|
4250
|
-
let reading = false;
|
|
4251
|
-
let readAgainForBranch1 = false;
|
|
4252
|
-
let readAgainForBranch2 = false;
|
|
4253
|
-
let canceled1 = false;
|
|
4254
|
-
let canceled2 = false;
|
|
4255
|
-
let reason1;
|
|
4256
|
-
let reason2;
|
|
4257
|
-
let branch1;
|
|
4258
|
-
let branch2;
|
|
4259
|
-
let resolveCancelPromise;
|
|
4260
|
-
const cancelPromise = newPromise(resolve => {
|
|
4261
|
-
resolveCancelPromise = resolve;
|
|
4262
|
-
});
|
|
4263
|
-
function forwardReaderError(thisReader) {
|
|
4264
|
-
uponRejection(thisReader._closedPromise, r => {
|
|
4265
|
-
if (thisReader !== reader) {
|
|
4266
|
-
return;
|
|
4267
|
-
}
|
|
4268
|
-
ReadableByteStreamControllerError(branch1._readableStreamController, r);
|
|
4269
|
-
ReadableByteStreamControllerError(branch2._readableStreamController, r);
|
|
4270
|
-
if (!canceled1 || !canceled2) {
|
|
4271
|
-
resolveCancelPromise(undefined);
|
|
4272
|
-
}
|
|
4273
|
-
});
|
|
4274
|
-
}
|
|
4275
|
-
function pullWithDefaultReader() {
|
|
4276
|
-
if (IsReadableStreamBYOBReader(reader)) {
|
|
4277
|
-
ReadableStreamReaderGenericRelease(reader);
|
|
4278
|
-
reader = AcquireReadableStreamDefaultReader(stream);
|
|
4279
|
-
forwardReaderError(reader);
|
|
4280
|
-
}
|
|
4281
|
-
const readRequest = {
|
|
4282
|
-
_chunkSteps: chunk => {
|
|
4283
|
-
// This needs to be delayed a microtask because it takes at least a microtask to detect errors (using
|
|
4284
|
-
// reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
|
|
4285
|
-
// successful synchronously-available reads get ahead of asynchronously-available errors.
|
|
4286
|
-
queueMicrotask(() => {
|
|
4287
|
-
readAgainForBranch1 = false;
|
|
4288
|
-
readAgainForBranch2 = false;
|
|
4289
|
-
const chunk1 = chunk;
|
|
4290
|
-
let chunk2 = chunk;
|
|
4291
|
-
if (!canceled1 && !canceled2) {
|
|
4292
|
-
try {
|
|
4293
|
-
chunk2 = CloneAsUint8Array(chunk);
|
|
4294
|
-
}
|
|
4295
|
-
catch (cloneE) {
|
|
4296
|
-
ReadableByteStreamControllerError(branch1._readableStreamController, cloneE);
|
|
4297
|
-
ReadableByteStreamControllerError(branch2._readableStreamController, cloneE);
|
|
4298
|
-
resolveCancelPromise(ReadableStreamCancel(stream, cloneE));
|
|
4299
|
-
return;
|
|
4300
|
-
}
|
|
4301
|
-
}
|
|
4302
|
-
if (!canceled1) {
|
|
4303
|
-
ReadableByteStreamControllerEnqueue(branch1._readableStreamController, chunk1);
|
|
4304
|
-
}
|
|
4305
|
-
if (!canceled2) {
|
|
4306
|
-
ReadableByteStreamControllerEnqueue(branch2._readableStreamController, chunk2);
|
|
4307
|
-
}
|
|
4308
|
-
reading = false;
|
|
4309
|
-
if (readAgainForBranch1) {
|
|
4310
|
-
pull1Algorithm();
|
|
4311
|
-
}
|
|
4312
|
-
else if (readAgainForBranch2) {
|
|
4313
|
-
pull2Algorithm();
|
|
4314
|
-
}
|
|
4315
|
-
});
|
|
4316
|
-
},
|
|
4317
|
-
_closeSteps: () => {
|
|
4318
|
-
reading = false;
|
|
4319
|
-
if (!canceled1) {
|
|
4320
|
-
ReadableByteStreamControllerClose(branch1._readableStreamController);
|
|
4321
|
-
}
|
|
4322
|
-
if (!canceled2) {
|
|
4323
|
-
ReadableByteStreamControllerClose(branch2._readableStreamController);
|
|
4324
|
-
}
|
|
4325
|
-
if (branch1._readableStreamController._pendingPullIntos.length > 0) {
|
|
4326
|
-
ReadableByteStreamControllerRespond(branch1._readableStreamController, 0);
|
|
4327
|
-
}
|
|
4328
|
-
if (branch2._readableStreamController._pendingPullIntos.length > 0) {
|
|
4329
|
-
ReadableByteStreamControllerRespond(branch2._readableStreamController, 0);
|
|
4330
|
-
}
|
|
4331
|
-
if (!canceled1 || !canceled2) {
|
|
4332
|
-
resolveCancelPromise(undefined);
|
|
4333
|
-
}
|
|
4334
|
-
},
|
|
4335
|
-
_errorSteps: () => {
|
|
4336
|
-
reading = false;
|
|
4337
|
-
}
|
|
4338
|
-
};
|
|
4339
|
-
ReadableStreamDefaultReaderRead(reader, readRequest);
|
|
4340
|
-
}
|
|
4341
|
-
function pullWithBYOBReader(view, forBranch2) {
|
|
4342
|
-
if (IsReadableStreamDefaultReader(reader)) {
|
|
4343
|
-
ReadableStreamReaderGenericRelease(reader);
|
|
4344
|
-
reader = AcquireReadableStreamBYOBReader(stream);
|
|
4345
|
-
forwardReaderError(reader);
|
|
4346
|
-
}
|
|
4347
|
-
const byobBranch = forBranch2 ? branch2 : branch1;
|
|
4348
|
-
const otherBranch = forBranch2 ? branch1 : branch2;
|
|
4349
|
-
const readIntoRequest = {
|
|
4350
|
-
_chunkSteps: chunk => {
|
|
4351
|
-
// This needs to be delayed a microtask because it takes at least a microtask to detect errors (using
|
|
4352
|
-
// reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
|
|
4353
|
-
// successful synchronously-available reads get ahead of asynchronously-available errors.
|
|
4354
|
-
queueMicrotask(() => {
|
|
4355
|
-
readAgainForBranch1 = false;
|
|
4356
|
-
readAgainForBranch2 = false;
|
|
4357
|
-
const byobCanceled = forBranch2 ? canceled2 : canceled1;
|
|
4358
|
-
const otherCanceled = forBranch2 ? canceled1 : canceled2;
|
|
4359
|
-
if (!otherCanceled) {
|
|
4360
|
-
let clonedChunk;
|
|
4361
|
-
try {
|
|
4362
|
-
clonedChunk = CloneAsUint8Array(chunk);
|
|
4363
|
-
}
|
|
4364
|
-
catch (cloneE) {
|
|
4365
|
-
ReadableByteStreamControllerError(byobBranch._readableStreamController, cloneE);
|
|
4366
|
-
ReadableByteStreamControllerError(otherBranch._readableStreamController, cloneE);
|
|
4367
|
-
resolveCancelPromise(ReadableStreamCancel(stream, cloneE));
|
|
4368
|
-
return;
|
|
4369
|
-
}
|
|
4370
|
-
if (!byobCanceled) {
|
|
4371
|
-
ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
|
|
4372
|
-
}
|
|
4373
|
-
ReadableByteStreamControllerEnqueue(otherBranch._readableStreamController, clonedChunk);
|
|
4374
|
-
}
|
|
4375
|
-
else if (!byobCanceled) {
|
|
4376
|
-
ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
|
|
4377
|
-
}
|
|
4378
|
-
reading = false;
|
|
4379
|
-
if (readAgainForBranch1) {
|
|
4380
|
-
pull1Algorithm();
|
|
4381
|
-
}
|
|
4382
|
-
else if (readAgainForBranch2) {
|
|
4383
|
-
pull2Algorithm();
|
|
4384
|
-
}
|
|
4385
|
-
});
|
|
4386
|
-
},
|
|
4387
|
-
_closeSteps: chunk => {
|
|
4388
|
-
reading = false;
|
|
4389
|
-
const byobCanceled = forBranch2 ? canceled2 : canceled1;
|
|
4390
|
-
const otherCanceled = forBranch2 ? canceled1 : canceled2;
|
|
4391
|
-
if (!byobCanceled) {
|
|
4392
|
-
ReadableByteStreamControllerClose(byobBranch._readableStreamController);
|
|
4393
|
-
}
|
|
4394
|
-
if (!otherCanceled) {
|
|
4395
|
-
ReadableByteStreamControllerClose(otherBranch._readableStreamController);
|
|
4396
|
-
}
|
|
4397
|
-
if (chunk !== undefined) {
|
|
4398
|
-
if (!byobCanceled) {
|
|
4399
|
-
ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
|
|
4400
|
-
}
|
|
4401
|
-
if (!otherCanceled && otherBranch._readableStreamController._pendingPullIntos.length > 0) {
|
|
4402
|
-
ReadableByteStreamControllerRespond(otherBranch._readableStreamController, 0);
|
|
4403
|
-
}
|
|
4404
|
-
}
|
|
4405
|
-
if (!byobCanceled || !otherCanceled) {
|
|
4406
|
-
resolveCancelPromise(undefined);
|
|
4407
|
-
}
|
|
4408
|
-
},
|
|
4409
|
-
_errorSteps: () => {
|
|
4410
|
-
reading = false;
|
|
4411
|
-
}
|
|
4412
|
-
};
|
|
4413
|
-
ReadableStreamBYOBReaderRead(reader, view, readIntoRequest);
|
|
4414
|
-
}
|
|
4415
|
-
function pull1Algorithm() {
|
|
4416
|
-
if (reading) {
|
|
4417
|
-
readAgainForBranch1 = true;
|
|
4418
|
-
return promiseResolvedWith(undefined);
|
|
4419
|
-
}
|
|
4420
|
-
reading = true;
|
|
4421
|
-
const byobRequest = ReadableByteStreamControllerGetBYOBRequest(branch1._readableStreamController);
|
|
4422
|
-
if (byobRequest === null) {
|
|
4423
|
-
pullWithDefaultReader();
|
|
4424
|
-
}
|
|
4425
|
-
else {
|
|
4426
|
-
pullWithBYOBReader(byobRequest._view, false);
|
|
4427
|
-
}
|
|
4428
|
-
return promiseResolvedWith(undefined);
|
|
4429
|
-
}
|
|
4430
|
-
function pull2Algorithm() {
|
|
4431
|
-
if (reading) {
|
|
4432
|
-
readAgainForBranch2 = true;
|
|
4433
|
-
return promiseResolvedWith(undefined);
|
|
4434
|
-
}
|
|
4435
|
-
reading = true;
|
|
4436
|
-
const byobRequest = ReadableByteStreamControllerGetBYOBRequest(branch2._readableStreamController);
|
|
4437
|
-
if (byobRequest === null) {
|
|
4438
|
-
pullWithDefaultReader();
|
|
4439
|
-
}
|
|
4440
|
-
else {
|
|
4441
|
-
pullWithBYOBReader(byobRequest._view, true);
|
|
4442
|
-
}
|
|
4443
|
-
return promiseResolvedWith(undefined);
|
|
4444
|
-
}
|
|
4445
|
-
function cancel1Algorithm(reason) {
|
|
4446
|
-
canceled1 = true;
|
|
4447
|
-
reason1 = reason;
|
|
4448
|
-
if (canceled2) {
|
|
4449
|
-
const compositeReason = CreateArrayFromList([reason1, reason2]);
|
|
4450
|
-
const cancelResult = ReadableStreamCancel(stream, compositeReason);
|
|
4451
|
-
resolveCancelPromise(cancelResult);
|
|
4452
|
-
}
|
|
4453
|
-
return cancelPromise;
|
|
4454
|
-
}
|
|
4455
|
-
function cancel2Algorithm(reason) {
|
|
4456
|
-
canceled2 = true;
|
|
4457
|
-
reason2 = reason;
|
|
4458
|
-
if (canceled1) {
|
|
4459
|
-
const compositeReason = CreateArrayFromList([reason1, reason2]);
|
|
4460
|
-
const cancelResult = ReadableStreamCancel(stream, compositeReason);
|
|
4461
|
-
resolveCancelPromise(cancelResult);
|
|
4462
|
-
}
|
|
4463
|
-
return cancelPromise;
|
|
4464
|
-
}
|
|
4465
|
-
function startAlgorithm() {
|
|
4466
|
-
return;
|
|
4467
|
-
}
|
|
4468
|
-
branch1 = CreateReadableByteStream(startAlgorithm, pull1Algorithm, cancel1Algorithm);
|
|
4469
|
-
branch2 = CreateReadableByteStream(startAlgorithm, pull2Algorithm, cancel2Algorithm);
|
|
4470
|
-
forwardReaderError(reader);
|
|
4471
|
-
return [branch1, branch2];
|
|
4472
|
-
}
|
|
4473
|
-
|
|
4474
|
-
function convertUnderlyingDefaultOrByteSource(source, context) {
|
|
4475
|
-
assertDictionary(source, context);
|
|
4476
|
-
const original = source;
|
|
4477
|
-
const autoAllocateChunkSize = original === null || original === void 0 ? void 0 : original.autoAllocateChunkSize;
|
|
4478
|
-
const cancel = original === null || original === void 0 ? void 0 : original.cancel;
|
|
4479
|
-
const pull = original === null || original === void 0 ? void 0 : original.pull;
|
|
4480
|
-
const start = original === null || original === void 0 ? void 0 : original.start;
|
|
4481
|
-
const type = original === null || original === void 0 ? void 0 : original.type;
|
|
4482
|
-
return {
|
|
4483
|
-
autoAllocateChunkSize: autoAllocateChunkSize === undefined ?
|
|
4484
|
-
undefined :
|
|
4485
|
-
convertUnsignedLongLongWithEnforceRange(autoAllocateChunkSize, `${context} has member 'autoAllocateChunkSize' that`),
|
|
4486
|
-
cancel: cancel === undefined ?
|
|
4487
|
-
undefined :
|
|
4488
|
-
convertUnderlyingSourceCancelCallback(cancel, original, `${context} has member 'cancel' that`),
|
|
4489
|
-
pull: pull === undefined ?
|
|
4490
|
-
undefined :
|
|
4491
|
-
convertUnderlyingSourcePullCallback(pull, original, `${context} has member 'pull' that`),
|
|
4492
|
-
start: start === undefined ?
|
|
4493
|
-
undefined :
|
|
4494
|
-
convertUnderlyingSourceStartCallback(start, original, `${context} has member 'start' that`),
|
|
4495
|
-
type: type === undefined ? undefined : convertReadableStreamType(type, `${context} has member 'type' that`)
|
|
4496
|
-
};
|
|
4497
|
-
}
|
|
4498
|
-
function convertUnderlyingSourceCancelCallback(fn, original, context) {
|
|
4499
|
-
assertFunction(fn, context);
|
|
4500
|
-
return (reason) => promiseCall(fn, original, [reason]);
|
|
4501
|
-
}
|
|
4502
|
-
function convertUnderlyingSourcePullCallback(fn, original, context) {
|
|
4503
|
-
assertFunction(fn, context);
|
|
4504
|
-
return (controller) => promiseCall(fn, original, [controller]);
|
|
4505
|
-
}
|
|
4506
|
-
function convertUnderlyingSourceStartCallback(fn, original, context) {
|
|
4507
|
-
assertFunction(fn, context);
|
|
4508
|
-
return (controller) => reflectCall(fn, original, [controller]);
|
|
4509
|
-
}
|
|
4510
|
-
function convertReadableStreamType(type, context) {
|
|
4511
|
-
type = `${type}`;
|
|
4512
|
-
if (type !== 'bytes') {
|
|
4513
|
-
throw new TypeError(`${context} '${type}' is not a valid enumeration value for ReadableStreamType`);
|
|
4514
|
-
}
|
|
4515
|
-
return type;
|
|
4516
|
-
}
|
|
4517
|
-
|
|
4518
|
-
function convertReaderOptions(options, context) {
|
|
4519
|
-
assertDictionary(options, context);
|
|
4520
|
-
const mode = options === null || options === void 0 ? void 0 : options.mode;
|
|
4521
|
-
return {
|
|
4522
|
-
mode: mode === undefined ? undefined : convertReadableStreamReaderMode(mode, `${context} has member 'mode' that`)
|
|
4523
|
-
};
|
|
4524
|
-
}
|
|
4525
|
-
function convertReadableStreamReaderMode(mode, context) {
|
|
4526
|
-
mode = `${mode}`;
|
|
4527
|
-
if (mode !== 'byob') {
|
|
4528
|
-
throw new TypeError(`${context} '${mode}' is not a valid enumeration value for ReadableStreamReaderMode`);
|
|
4529
|
-
}
|
|
4530
|
-
return mode;
|
|
4531
|
-
}
|
|
4532
|
-
|
|
4533
|
-
function convertIteratorOptions(options, context) {
|
|
4534
|
-
assertDictionary(options, context);
|
|
4535
|
-
const preventCancel = options === null || options === void 0 ? void 0 : options.preventCancel;
|
|
4536
|
-
return { preventCancel: Boolean(preventCancel) };
|
|
4537
|
-
}
|
|
4538
|
-
|
|
4539
|
-
function convertPipeOptions(options, context) {
|
|
4540
|
-
assertDictionary(options, context);
|
|
4541
|
-
const preventAbort = options === null || options === void 0 ? void 0 : options.preventAbort;
|
|
4542
|
-
const preventCancel = options === null || options === void 0 ? void 0 : options.preventCancel;
|
|
4543
|
-
const preventClose = options === null || options === void 0 ? void 0 : options.preventClose;
|
|
4544
|
-
const signal = options === null || options === void 0 ? void 0 : options.signal;
|
|
4545
|
-
if (signal !== undefined) {
|
|
4546
|
-
assertAbortSignal(signal, `${context} has member 'signal' that`);
|
|
4547
|
-
}
|
|
4548
|
-
return {
|
|
4549
|
-
preventAbort: Boolean(preventAbort),
|
|
4550
|
-
preventCancel: Boolean(preventCancel),
|
|
4551
|
-
preventClose: Boolean(preventClose),
|
|
4552
|
-
signal
|
|
4553
|
-
};
|
|
4554
|
-
}
|
|
4555
|
-
function assertAbortSignal(signal, context) {
|
|
4556
|
-
if (!isAbortSignal(signal)) {
|
|
4557
|
-
throw new TypeError(`${context} is not an AbortSignal.`);
|
|
4558
|
-
}
|
|
4559
|
-
}
|
|
4560
|
-
|
|
4561
|
-
function convertReadableWritablePair(pair, context) {
|
|
4562
|
-
assertDictionary(pair, context);
|
|
4563
|
-
const readable = pair === null || pair === void 0 ? void 0 : pair.readable;
|
|
4564
|
-
assertRequiredField(readable, 'readable', 'ReadableWritablePair');
|
|
4565
|
-
assertReadableStream(readable, `${context} has member 'readable' that`);
|
|
4566
|
-
const writable = pair === null || pair === void 0 ? void 0 : pair.writable;
|
|
4567
|
-
assertRequiredField(writable, 'writable', 'ReadableWritablePair');
|
|
4568
|
-
assertWritableStream(writable, `${context} has member 'writable' that`);
|
|
4569
|
-
return { readable, writable };
|
|
4570
|
-
}
|
|
4571
|
-
|
|
4572
|
-
/**
|
|
4573
|
-
* A readable stream represents a source of data, from which you can read.
|
|
4574
|
-
*
|
|
4575
|
-
* @public
|
|
4576
|
-
*/
|
|
4577
|
-
class ReadableStream {
|
|
4578
|
-
constructor(rawUnderlyingSource = {}, rawStrategy = {}) {
|
|
4579
|
-
if (rawUnderlyingSource === undefined) {
|
|
4580
|
-
rawUnderlyingSource = null;
|
|
4581
|
-
}
|
|
4582
|
-
else {
|
|
4583
|
-
assertObject(rawUnderlyingSource, 'First parameter');
|
|
4584
|
-
}
|
|
4585
|
-
const strategy = convertQueuingStrategy(rawStrategy, 'Second parameter');
|
|
4586
|
-
const underlyingSource = convertUnderlyingDefaultOrByteSource(rawUnderlyingSource, 'First parameter');
|
|
4587
|
-
InitializeReadableStream(this);
|
|
4588
|
-
if (underlyingSource.type === 'bytes') {
|
|
4589
|
-
if (strategy.size !== undefined) {
|
|
4590
|
-
throw new RangeError('The strategy for a byte stream cannot have a size function');
|
|
4591
|
-
}
|
|
4592
|
-
const highWaterMark = ExtractHighWaterMark(strategy, 0);
|
|
4593
|
-
SetUpReadableByteStreamControllerFromUnderlyingSource(this, underlyingSource, highWaterMark);
|
|
4594
|
-
}
|
|
4595
|
-
else {
|
|
4596
|
-
const sizeAlgorithm = ExtractSizeAlgorithm(strategy);
|
|
4597
|
-
const highWaterMark = ExtractHighWaterMark(strategy, 1);
|
|
4598
|
-
SetUpReadableStreamDefaultControllerFromUnderlyingSource(this, underlyingSource, highWaterMark, sizeAlgorithm);
|
|
4599
|
-
}
|
|
4600
|
-
}
|
|
4601
|
-
/**
|
|
4602
|
-
* Whether or not the readable stream is locked to a {@link ReadableStreamDefaultReader | reader}.
|
|
4603
|
-
*/
|
|
4604
|
-
get locked() {
|
|
4605
|
-
if (!IsReadableStream(this)) {
|
|
4606
|
-
throw streamBrandCheckException$1('locked');
|
|
4607
|
-
}
|
|
4608
|
-
return IsReadableStreamLocked(this);
|
|
4609
|
-
}
|
|
4610
|
-
/**
|
|
4611
|
-
* Cancels the stream, signaling a loss of interest in the stream by a consumer.
|
|
4612
|
-
*
|
|
4613
|
-
* The supplied `reason` argument will be given to the underlying source's {@link UnderlyingSource.cancel | cancel()}
|
|
4614
|
-
* method, which might or might not use it.
|
|
4615
|
-
*/
|
|
4616
|
-
cancel(reason = undefined) {
|
|
4617
|
-
if (!IsReadableStream(this)) {
|
|
4618
|
-
return promiseRejectedWith(streamBrandCheckException$1('cancel'));
|
|
4619
|
-
}
|
|
4620
|
-
if (IsReadableStreamLocked(this)) {
|
|
4621
|
-
return promiseRejectedWith(new TypeError('Cannot cancel a stream that already has a reader'));
|
|
4622
|
-
}
|
|
4623
|
-
return ReadableStreamCancel(this, reason);
|
|
4624
|
-
}
|
|
4625
|
-
getReader(rawOptions = undefined) {
|
|
4626
|
-
if (!IsReadableStream(this)) {
|
|
4627
|
-
throw streamBrandCheckException$1('getReader');
|
|
4628
|
-
}
|
|
4629
|
-
const options = convertReaderOptions(rawOptions, 'First parameter');
|
|
4630
|
-
if (options.mode === undefined) {
|
|
4631
|
-
return AcquireReadableStreamDefaultReader(this);
|
|
4632
|
-
}
|
|
4633
|
-
return AcquireReadableStreamBYOBReader(this);
|
|
4634
|
-
}
|
|
4635
|
-
pipeThrough(rawTransform, rawOptions = {}) {
|
|
4636
|
-
if (!IsReadableStream(this)) {
|
|
4637
|
-
throw streamBrandCheckException$1('pipeThrough');
|
|
4638
|
-
}
|
|
4639
|
-
assertRequiredArgument(rawTransform, 1, 'pipeThrough');
|
|
4640
|
-
const transform = convertReadableWritablePair(rawTransform, 'First parameter');
|
|
4641
|
-
const options = convertPipeOptions(rawOptions, 'Second parameter');
|
|
4642
|
-
if (IsReadableStreamLocked(this)) {
|
|
4643
|
-
throw new TypeError('ReadableStream.prototype.pipeThrough cannot be used on a locked ReadableStream');
|
|
4644
|
-
}
|
|
4645
|
-
if (IsWritableStreamLocked(transform.writable)) {
|
|
4646
|
-
throw new TypeError('ReadableStream.prototype.pipeThrough cannot be used on a locked WritableStream');
|
|
4647
|
-
}
|
|
4648
|
-
const promise = ReadableStreamPipeTo(this, transform.writable, options.preventClose, options.preventAbort, options.preventCancel, options.signal);
|
|
4649
|
-
setPromiseIsHandledToTrue(promise);
|
|
4650
|
-
return transform.readable;
|
|
4651
|
-
}
|
|
4652
|
-
pipeTo(destination, rawOptions = {}) {
|
|
4653
|
-
if (!IsReadableStream(this)) {
|
|
4654
|
-
return promiseRejectedWith(streamBrandCheckException$1('pipeTo'));
|
|
4655
|
-
}
|
|
4656
|
-
if (destination === undefined) {
|
|
4657
|
-
return promiseRejectedWith(`Parameter 1 is required in 'pipeTo'.`);
|
|
4658
|
-
}
|
|
4659
|
-
if (!IsWritableStream(destination)) {
|
|
4660
|
-
return promiseRejectedWith(new TypeError(`ReadableStream.prototype.pipeTo's first argument must be a WritableStream`));
|
|
4661
|
-
}
|
|
4662
|
-
let options;
|
|
4663
|
-
try {
|
|
4664
|
-
options = convertPipeOptions(rawOptions, 'Second parameter');
|
|
4665
|
-
}
|
|
4666
|
-
catch (e) {
|
|
4667
|
-
return promiseRejectedWith(e);
|
|
4668
|
-
}
|
|
4669
|
-
if (IsReadableStreamLocked(this)) {
|
|
4670
|
-
return promiseRejectedWith(new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream'));
|
|
4671
|
-
}
|
|
4672
|
-
if (IsWritableStreamLocked(destination)) {
|
|
4673
|
-
return promiseRejectedWith(new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream'));
|
|
4674
|
-
}
|
|
4675
|
-
return ReadableStreamPipeTo(this, destination, options.preventClose, options.preventAbort, options.preventCancel, options.signal);
|
|
4676
|
-
}
|
|
4677
|
-
/**
|
|
4678
|
-
* Tees this readable stream, returning a two-element array containing the two resulting branches as
|
|
4679
|
-
* new {@link ReadableStream} instances.
|
|
4680
|
-
*
|
|
4681
|
-
* Teeing a stream will lock it, preventing any other consumer from acquiring a reader.
|
|
4682
|
-
* To cancel the stream, cancel both of the resulting branches; a composite cancellation reason will then be
|
|
4683
|
-
* propagated to the stream's underlying source.
|
|
4684
|
-
*
|
|
4685
|
-
* Note that the chunks seen in each branch will be the same object. If the chunks are not immutable,
|
|
4686
|
-
* this could allow interference between the two branches.
|
|
4687
|
-
*/
|
|
4688
|
-
tee() {
|
|
4689
|
-
if (!IsReadableStream(this)) {
|
|
4690
|
-
throw streamBrandCheckException$1('tee');
|
|
4691
|
-
}
|
|
4692
|
-
const branches = ReadableStreamTee(this);
|
|
4693
|
-
return CreateArrayFromList(branches);
|
|
4694
|
-
}
|
|
4695
|
-
values(rawOptions = undefined) {
|
|
4696
|
-
if (!IsReadableStream(this)) {
|
|
4697
|
-
throw streamBrandCheckException$1('values');
|
|
4698
|
-
}
|
|
4699
|
-
const options = convertIteratorOptions(rawOptions, 'First parameter');
|
|
4700
|
-
return AcquireReadableStreamAsyncIterator(this, options.preventCancel);
|
|
4701
|
-
}
|
|
4702
|
-
}
|
|
4703
|
-
Object.defineProperties(ReadableStream.prototype, {
|
|
4704
|
-
cancel: { enumerable: true },
|
|
4705
|
-
getReader: { enumerable: true },
|
|
4706
|
-
pipeThrough: { enumerable: true },
|
|
4707
|
-
pipeTo: { enumerable: true },
|
|
4708
|
-
tee: { enumerable: true },
|
|
4709
|
-
values: { enumerable: true },
|
|
4710
|
-
locked: { enumerable: true }
|
|
4711
|
-
});
|
|
4712
|
-
// Abstract operations for the ReadableStream.
|
|
4713
|
-
// Throws if and only if startAlgorithm throws.
|
|
4714
|
-
function CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark = 1, sizeAlgorithm = () => 1) {
|
|
4715
|
-
const stream = Object.create(ReadableStream.prototype);
|
|
4716
|
-
InitializeReadableStream(stream);
|
|
4717
|
-
const controller = Object.create(ReadableStreamDefaultController.prototype);
|
|
4718
|
-
SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm);
|
|
4719
|
-
return stream;
|
|
4720
|
-
}
|
|
4721
|
-
// Throws if and only if startAlgorithm throws.
|
|
4722
|
-
function CreateReadableByteStream(startAlgorithm, pullAlgorithm, cancelAlgorithm) {
|
|
4723
|
-
const stream = Object.create(ReadableStream.prototype);
|
|
4724
|
-
InitializeReadableStream(stream);
|
|
4725
|
-
const controller = Object.create(ReadableByteStreamController.prototype);
|
|
4726
|
-
SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, 0, undefined);
|
|
4727
|
-
return stream;
|
|
4728
|
-
}
|
|
4729
|
-
function InitializeReadableStream(stream) {
|
|
4730
|
-
stream._state = 'readable';
|
|
4731
|
-
stream._reader = undefined;
|
|
4732
|
-
stream._storedError = undefined;
|
|
4733
|
-
stream._disturbed = false;
|
|
4734
|
-
}
|
|
4735
|
-
function IsReadableStream(x) {
|
|
4736
|
-
if (!typeIsObject(x)) {
|
|
4737
|
-
return false;
|
|
4738
|
-
}
|
|
4739
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_readableStreamController')) {
|
|
4740
|
-
return false;
|
|
4741
|
-
}
|
|
4742
|
-
return x instanceof ReadableStream;
|
|
4743
|
-
}
|
|
4744
|
-
function IsReadableStreamLocked(stream) {
|
|
4745
|
-
if (stream._reader === undefined) {
|
|
4746
|
-
return false;
|
|
4747
|
-
}
|
|
4748
|
-
return true;
|
|
4749
|
-
}
|
|
4750
|
-
// ReadableStream API exposed for controllers.
|
|
4751
|
-
function ReadableStreamCancel(stream, reason) {
|
|
4752
|
-
stream._disturbed = true;
|
|
4753
|
-
if (stream._state === 'closed') {
|
|
4754
|
-
return promiseResolvedWith(undefined);
|
|
4755
|
-
}
|
|
4756
|
-
if (stream._state === 'errored') {
|
|
4757
|
-
return promiseRejectedWith(stream._storedError);
|
|
4758
|
-
}
|
|
4759
|
-
ReadableStreamClose(stream);
|
|
4760
|
-
const reader = stream._reader;
|
|
4761
|
-
if (reader !== undefined && IsReadableStreamBYOBReader(reader)) {
|
|
4762
|
-
reader._readIntoRequests.forEach(readIntoRequest => {
|
|
4763
|
-
readIntoRequest._closeSteps(undefined);
|
|
4764
|
-
});
|
|
4765
|
-
reader._readIntoRequests = new SimpleQueue();
|
|
4766
|
-
}
|
|
4767
|
-
const sourceCancelPromise = stream._readableStreamController[CancelSteps](reason);
|
|
4768
|
-
return transformPromiseWith(sourceCancelPromise, noop);
|
|
4769
|
-
}
|
|
4770
|
-
function ReadableStreamClose(stream) {
|
|
4771
|
-
stream._state = 'closed';
|
|
4772
|
-
const reader = stream._reader;
|
|
4773
|
-
if (reader === undefined) {
|
|
4774
|
-
return;
|
|
4775
|
-
}
|
|
4776
|
-
defaultReaderClosedPromiseResolve(reader);
|
|
4777
|
-
if (IsReadableStreamDefaultReader(reader)) {
|
|
4778
|
-
reader._readRequests.forEach(readRequest => {
|
|
4779
|
-
readRequest._closeSteps();
|
|
4780
|
-
});
|
|
4781
|
-
reader._readRequests = new SimpleQueue();
|
|
4782
|
-
}
|
|
4783
|
-
}
|
|
4784
|
-
function ReadableStreamError(stream, e) {
|
|
4785
|
-
stream._state = 'errored';
|
|
4786
|
-
stream._storedError = e;
|
|
4787
|
-
const reader = stream._reader;
|
|
4788
|
-
if (reader === undefined) {
|
|
4789
|
-
return;
|
|
4790
|
-
}
|
|
4791
|
-
defaultReaderClosedPromiseReject(reader, e);
|
|
4792
|
-
if (IsReadableStreamDefaultReader(reader)) {
|
|
4793
|
-
reader._readRequests.forEach(readRequest => {
|
|
4794
|
-
readRequest._errorSteps(e);
|
|
4795
|
-
});
|
|
4796
|
-
reader._readRequests = new SimpleQueue();
|
|
4797
|
-
}
|
|
4798
|
-
else {
|
|
4799
|
-
reader._readIntoRequests.forEach(readIntoRequest => {
|
|
4800
|
-
readIntoRequest._errorSteps(e);
|
|
4801
|
-
});
|
|
4802
|
-
reader._readIntoRequests = new SimpleQueue();
|
|
4803
|
-
}
|
|
4804
|
-
}
|
|
4805
|
-
// Helper functions for the ReadableStream.
|
|
4806
|
-
function streamBrandCheckException$1(name) {
|
|
4807
|
-
return new TypeError(`ReadableStream.prototype.${name} can only be used on a ReadableStream`);
|
|
4808
|
-
}
|
|
4809
|
-
|
|
4810
|
-
function convertQueuingStrategyInit(init, context) {
|
|
4811
|
-
assertDictionary(init, context);
|
|
4812
|
-
const highWaterMark = init === null || init === void 0 ? void 0 : init.highWaterMark;
|
|
4813
|
-
assertRequiredField(highWaterMark, 'highWaterMark', 'QueuingStrategyInit');
|
|
4814
|
-
return {
|
|
4815
|
-
highWaterMark: convertUnrestrictedDouble(highWaterMark)
|
|
4816
|
-
};
|
|
4817
|
-
}
|
|
4818
|
-
|
|
4819
|
-
// The size function must not have a prototype property nor be a constructor
|
|
4820
|
-
const byteLengthSizeFunction = (chunk) => {
|
|
4821
|
-
return chunk.byteLength;
|
|
4822
|
-
};
|
|
4823
|
-
try {
|
|
4824
|
-
Object.defineProperty(byteLengthSizeFunction, 'name', {
|
|
4825
|
-
value: 'size',
|
|
4826
|
-
configurable: true
|
|
4827
|
-
});
|
|
4828
|
-
}
|
|
4829
|
-
catch (_a) {
|
|
4830
|
-
// This property is non-configurable in older browsers, so ignore if this throws.
|
|
4831
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name#browser_compatibility
|
|
4832
|
-
}
|
|
4833
|
-
/**
|
|
4834
|
-
* A queuing strategy that counts the number of bytes in each chunk.
|
|
4835
|
-
*
|
|
4836
|
-
* @public
|
|
4837
|
-
*/
|
|
4838
|
-
class ByteLengthQueuingStrategy {
|
|
4839
|
-
constructor(options) {
|
|
4840
|
-
assertRequiredArgument(options, 1, 'ByteLengthQueuingStrategy');
|
|
4841
|
-
options = convertQueuingStrategyInit(options, 'First parameter');
|
|
4842
|
-
this._byteLengthQueuingStrategyHighWaterMark = options.highWaterMark;
|
|
4843
|
-
}
|
|
4844
|
-
/**
|
|
4845
|
-
* Returns the high water mark provided to the constructor.
|
|
4846
|
-
*/
|
|
4847
|
-
get highWaterMark() {
|
|
4848
|
-
if (!IsByteLengthQueuingStrategy(this)) {
|
|
4849
|
-
throw byteLengthBrandCheckException('highWaterMark');
|
|
4850
|
-
}
|
|
4851
|
-
return this._byteLengthQueuingStrategyHighWaterMark;
|
|
4852
|
-
}
|
|
4853
|
-
/**
|
|
4854
|
-
* Measures the size of `chunk` by returning the value of its `byteLength` property.
|
|
4855
|
-
*/
|
|
4856
|
-
get size() {
|
|
4857
|
-
if (!IsByteLengthQueuingStrategy(this)) {
|
|
4858
|
-
throw byteLengthBrandCheckException('size');
|
|
4859
|
-
}
|
|
4860
|
-
return byteLengthSizeFunction;
|
|
4861
|
-
}
|
|
4862
|
-
}
|
|
4863
|
-
Object.defineProperties(ByteLengthQueuingStrategy.prototype, {
|
|
4864
|
-
highWaterMark: { enumerable: true },
|
|
4865
|
-
size: { enumerable: true }
|
|
4866
|
-
});
|
|
4867
|
-
// Helper functions for the ByteLengthQueuingStrategy.
|
|
4868
|
-
function byteLengthBrandCheckException(name) {
|
|
4869
|
-
return new TypeError(`ByteLengthQueuingStrategy.prototype.${name} can only be used on a ByteLengthQueuingStrategy`);
|
|
4870
|
-
}
|
|
4871
|
-
function IsByteLengthQueuingStrategy(x) {
|
|
4872
|
-
if (!typeIsObject(x)) {
|
|
4873
|
-
return false;
|
|
4874
|
-
}
|
|
4875
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_byteLengthQueuingStrategyHighWaterMark')) {
|
|
4876
|
-
return false;
|
|
4877
|
-
}
|
|
4878
|
-
return x instanceof ByteLengthQueuingStrategy;
|
|
4879
|
-
}
|
|
4880
|
-
|
|
4881
|
-
// The size function must not have a prototype property nor be a constructor
|
|
4882
|
-
const countSizeFunction = () => {
|
|
4883
|
-
return 1;
|
|
4884
|
-
};
|
|
4885
|
-
try {
|
|
4886
|
-
Object.defineProperty(countSizeFunction, 'name', {
|
|
4887
|
-
value: 'size',
|
|
4888
|
-
configurable: true
|
|
4889
|
-
});
|
|
4890
|
-
}
|
|
4891
|
-
catch (_a) {
|
|
4892
|
-
// This property is non-configurable in older browsers, so ignore if this throws.
|
|
4893
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name#browser_compatibility
|
|
4894
|
-
}
|
|
4895
|
-
/**
|
|
4896
|
-
* A queuing strategy that counts the number of chunks.
|
|
4897
|
-
*
|
|
4898
|
-
* @public
|
|
4899
|
-
*/
|
|
4900
|
-
class CountQueuingStrategy {
|
|
4901
|
-
constructor(options) {
|
|
4902
|
-
assertRequiredArgument(options, 1, 'CountQueuingStrategy');
|
|
4903
|
-
options = convertQueuingStrategyInit(options, 'First parameter');
|
|
4904
|
-
this._countQueuingStrategyHighWaterMark = options.highWaterMark;
|
|
4905
|
-
}
|
|
4906
|
-
/**
|
|
4907
|
-
* Returns the high water mark provided to the constructor.
|
|
4908
|
-
*/
|
|
4909
|
-
get highWaterMark() {
|
|
4910
|
-
if (!IsCountQueuingStrategy(this)) {
|
|
4911
|
-
throw countBrandCheckException('highWaterMark');
|
|
4912
|
-
}
|
|
4913
|
-
return this._countQueuingStrategyHighWaterMark;
|
|
4914
|
-
}
|
|
4915
|
-
/**
|
|
4916
|
-
* Measures the size of `chunk` by always returning 1.
|
|
4917
|
-
* This ensures that the total queue size is a count of the number of chunks in the queue.
|
|
4918
|
-
*/
|
|
4919
|
-
get size() {
|
|
4920
|
-
if (!IsCountQueuingStrategy(this)) {
|
|
4921
|
-
throw countBrandCheckException('size');
|
|
4922
|
-
}
|
|
4923
|
-
return countSizeFunction;
|
|
4924
|
-
}
|
|
4925
|
-
}
|
|
4926
|
-
Object.defineProperties(CountQueuingStrategy.prototype, {
|
|
4927
|
-
highWaterMark: { enumerable: true },
|
|
4928
|
-
size: { enumerable: true }
|
|
4929
|
-
});
|
|
4930
|
-
// Helper functions for the CountQueuingStrategy.
|
|
4931
|
-
function countBrandCheckException(name) {
|
|
4932
|
-
return new TypeError(`CountQueuingStrategy.prototype.${name} can only be used on a CountQueuingStrategy`);
|
|
4933
|
-
}
|
|
4934
|
-
function IsCountQueuingStrategy(x) {
|
|
4935
|
-
if (!typeIsObject(x)) {
|
|
4936
|
-
return false;
|
|
4937
|
-
}
|
|
4938
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_countQueuingStrategyHighWaterMark')) {
|
|
4939
|
-
return false;
|
|
4940
|
-
}
|
|
4941
|
-
return x instanceof CountQueuingStrategy;
|
|
4942
|
-
}
|
|
4943
|
-
|
|
4944
|
-
function convertTransformer(original, context) {
|
|
4945
|
-
assertDictionary(original, context);
|
|
4946
|
-
const flush = original === null || original === void 0 ? void 0 : original.flush;
|
|
4947
|
-
const readableType = original === null || original === void 0 ? void 0 : original.readableType;
|
|
4948
|
-
const start = original === null || original === void 0 ? void 0 : original.start;
|
|
4949
|
-
const transform = original === null || original === void 0 ? void 0 : original.transform;
|
|
4950
|
-
const writableType = original === null || original === void 0 ? void 0 : original.writableType;
|
|
4951
|
-
return {
|
|
4952
|
-
flush: flush === undefined ?
|
|
4953
|
-
undefined :
|
|
4954
|
-
convertTransformerFlushCallback(flush, original, `${context} has member 'flush' that`),
|
|
4955
|
-
readableType,
|
|
4956
|
-
start: start === undefined ?
|
|
4957
|
-
undefined :
|
|
4958
|
-
convertTransformerStartCallback(start, original, `${context} has member 'start' that`),
|
|
4959
|
-
transform: transform === undefined ?
|
|
4960
|
-
undefined :
|
|
4961
|
-
convertTransformerTransformCallback(transform, original, `${context} has member 'transform' that`),
|
|
4962
|
-
writableType
|
|
4963
|
-
};
|
|
4964
|
-
}
|
|
4965
|
-
function convertTransformerFlushCallback(fn, original, context) {
|
|
4966
|
-
assertFunction(fn, context);
|
|
4967
|
-
return (controller) => promiseCall(fn, original, [controller]);
|
|
4968
|
-
}
|
|
4969
|
-
function convertTransformerStartCallback(fn, original, context) {
|
|
4970
|
-
assertFunction(fn, context);
|
|
4971
|
-
return (controller) => reflectCall(fn, original, [controller]);
|
|
4972
|
-
}
|
|
4973
|
-
function convertTransformerTransformCallback(fn, original, context) {
|
|
4974
|
-
assertFunction(fn, context);
|
|
4975
|
-
return (chunk, controller) => promiseCall(fn, original, [chunk, controller]);
|
|
4976
|
-
}
|
|
4977
|
-
|
|
4978
|
-
// Class TransformStream
|
|
4979
|
-
/**
|
|
4980
|
-
* A transform stream consists of a pair of streams: a {@link WritableStream | writable stream},
|
|
4981
|
-
* known as its writable side, and a {@link ReadableStream | readable stream}, known as its readable side.
|
|
4982
|
-
* In a manner specific to the transform stream in question, writes to the writable side result in new data being
|
|
4983
|
-
* made available for reading from the readable side.
|
|
4984
|
-
*
|
|
4985
|
-
* @public
|
|
4986
|
-
*/
|
|
4987
|
-
class TransformStream {
|
|
4988
|
-
constructor(rawTransformer = {}, rawWritableStrategy = {}, rawReadableStrategy = {}) {
|
|
4989
|
-
if (rawTransformer === undefined) {
|
|
4990
|
-
rawTransformer = null;
|
|
4991
|
-
}
|
|
4992
|
-
const writableStrategy = convertQueuingStrategy(rawWritableStrategy, 'Second parameter');
|
|
4993
|
-
const readableStrategy = convertQueuingStrategy(rawReadableStrategy, 'Third parameter');
|
|
4994
|
-
const transformer = convertTransformer(rawTransformer, 'First parameter');
|
|
4995
|
-
if (transformer.readableType !== undefined) {
|
|
4996
|
-
throw new RangeError('Invalid readableType specified');
|
|
4997
|
-
}
|
|
4998
|
-
if (transformer.writableType !== undefined) {
|
|
4999
|
-
throw new RangeError('Invalid writableType specified');
|
|
5000
|
-
}
|
|
5001
|
-
const readableHighWaterMark = ExtractHighWaterMark(readableStrategy, 0);
|
|
5002
|
-
const readableSizeAlgorithm = ExtractSizeAlgorithm(readableStrategy);
|
|
5003
|
-
const writableHighWaterMark = ExtractHighWaterMark(writableStrategy, 1);
|
|
5004
|
-
const writableSizeAlgorithm = ExtractSizeAlgorithm(writableStrategy);
|
|
5005
|
-
let startPromise_resolve;
|
|
5006
|
-
const startPromise = newPromise(resolve => {
|
|
5007
|
-
startPromise_resolve = resolve;
|
|
5008
|
-
});
|
|
5009
|
-
InitializeTransformStream(this, startPromise, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, readableSizeAlgorithm);
|
|
5010
|
-
SetUpTransformStreamDefaultControllerFromTransformer(this, transformer);
|
|
5011
|
-
if (transformer.start !== undefined) {
|
|
5012
|
-
startPromise_resolve(transformer.start(this._transformStreamController));
|
|
5013
|
-
}
|
|
5014
|
-
else {
|
|
5015
|
-
startPromise_resolve(undefined);
|
|
5016
|
-
}
|
|
5017
|
-
}
|
|
5018
|
-
/**
|
|
5019
|
-
* The readable side of the transform stream.
|
|
5020
|
-
*/
|
|
5021
|
-
get readable() {
|
|
5022
|
-
if (!IsTransformStream(this)) {
|
|
5023
|
-
throw streamBrandCheckException('readable');
|
|
5024
|
-
}
|
|
5025
|
-
return this._readable;
|
|
5026
|
-
}
|
|
5027
|
-
/**
|
|
5028
|
-
* The writable side of the transform stream.
|
|
5029
|
-
*/
|
|
5030
|
-
get writable() {
|
|
5031
|
-
if (!IsTransformStream(this)) {
|
|
5032
|
-
throw streamBrandCheckException('writable');
|
|
5033
|
-
}
|
|
5034
|
-
return this._writable;
|
|
5035
|
-
}
|
|
5036
|
-
}
|
|
5037
|
-
Object.defineProperties(TransformStream.prototype, {
|
|
5038
|
-
readable: { enumerable: true },
|
|
5039
|
-
writable: { enumerable: true }
|
|
5040
|
-
});
|
|
5041
|
-
function InitializeTransformStream(stream, startPromise, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, readableSizeAlgorithm) {
|
|
5042
|
-
function startAlgorithm() {
|
|
5043
|
-
return startPromise;
|
|
5044
|
-
}
|
|
5045
|
-
function writeAlgorithm(chunk) {
|
|
5046
|
-
return TransformStreamDefaultSinkWriteAlgorithm(stream, chunk);
|
|
5047
|
-
}
|
|
5048
|
-
function abortAlgorithm(reason) {
|
|
5049
|
-
return TransformStreamDefaultSinkAbortAlgorithm(stream, reason);
|
|
5050
|
-
}
|
|
5051
|
-
function closeAlgorithm() {
|
|
5052
|
-
return TransformStreamDefaultSinkCloseAlgorithm(stream);
|
|
5053
|
-
}
|
|
5054
|
-
stream._writable = CreateWritableStream(startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, writableHighWaterMark, writableSizeAlgorithm);
|
|
5055
|
-
function pullAlgorithm() {
|
|
5056
|
-
return TransformStreamDefaultSourcePullAlgorithm(stream);
|
|
5057
|
-
}
|
|
5058
|
-
function cancelAlgorithm(reason) {
|
|
5059
|
-
TransformStreamErrorWritableAndUnblockWrite(stream, reason);
|
|
5060
|
-
return promiseResolvedWith(undefined);
|
|
5061
|
-
}
|
|
5062
|
-
stream._readable = CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, readableHighWaterMark, readableSizeAlgorithm);
|
|
5063
|
-
// The [[backpressure]] slot is set to undefined so that it can be initialised by TransformStreamSetBackpressure.
|
|
5064
|
-
stream._backpressure = undefined;
|
|
5065
|
-
stream._backpressureChangePromise = undefined;
|
|
5066
|
-
stream._backpressureChangePromise_resolve = undefined;
|
|
5067
|
-
TransformStreamSetBackpressure(stream, true);
|
|
5068
|
-
stream._transformStreamController = undefined;
|
|
5069
|
-
}
|
|
5070
|
-
function IsTransformStream(x) {
|
|
5071
|
-
if (!typeIsObject(x)) {
|
|
5072
|
-
return false;
|
|
5073
|
-
}
|
|
5074
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_transformStreamController')) {
|
|
5075
|
-
return false;
|
|
5076
|
-
}
|
|
5077
|
-
return x instanceof TransformStream;
|
|
5078
|
-
}
|
|
5079
|
-
// This is a no-op if both sides are already errored.
|
|
5080
|
-
function TransformStreamError(stream, e) {
|
|
5081
|
-
ReadableStreamDefaultControllerError(stream._readable._readableStreamController, e);
|
|
5082
|
-
TransformStreamErrorWritableAndUnblockWrite(stream, e);
|
|
5083
|
-
}
|
|
5084
|
-
function TransformStreamErrorWritableAndUnblockWrite(stream, e) {
|
|
5085
|
-
TransformStreamDefaultControllerClearAlgorithms(stream._transformStreamController);
|
|
5086
|
-
WritableStreamDefaultControllerErrorIfNeeded(stream._writable._writableStreamController, e);
|
|
5087
|
-
if (stream._backpressure) {
|
|
5088
|
-
// Pretend that pull() was called to permit any pending write() calls to complete. TransformStreamSetBackpressure()
|
|
5089
|
-
// cannot be called from enqueue() or pull() once the ReadableStream is errored, so this will will be the final time
|
|
5090
|
-
// _backpressure is set.
|
|
5091
|
-
TransformStreamSetBackpressure(stream, false);
|
|
5092
|
-
}
|
|
5093
|
-
}
|
|
5094
|
-
function TransformStreamSetBackpressure(stream, backpressure) {
|
|
5095
|
-
// Passes also when called during construction.
|
|
5096
|
-
if (stream._backpressureChangePromise !== undefined) {
|
|
5097
|
-
stream._backpressureChangePromise_resolve();
|
|
5098
|
-
}
|
|
5099
|
-
stream._backpressureChangePromise = newPromise(resolve => {
|
|
5100
|
-
stream._backpressureChangePromise_resolve = resolve;
|
|
5101
|
-
});
|
|
5102
|
-
stream._backpressure = backpressure;
|
|
5103
|
-
}
|
|
5104
|
-
// Class TransformStreamDefaultController
|
|
5105
|
-
/**
|
|
5106
|
-
* Allows control of the {@link ReadableStream} and {@link WritableStream} of the associated {@link TransformStream}.
|
|
5107
|
-
*
|
|
5108
|
-
* @public
|
|
5109
|
-
*/
|
|
5110
|
-
class TransformStreamDefaultController {
|
|
5111
|
-
constructor() {
|
|
5112
|
-
throw new TypeError('Illegal constructor');
|
|
5113
|
-
}
|
|
5114
|
-
/**
|
|
5115
|
-
* Returns the desired size to fill the readable side’s internal queue. It can be negative, if the queue is over-full.
|
|
5116
|
-
*/
|
|
5117
|
-
get desiredSize() {
|
|
5118
|
-
if (!IsTransformStreamDefaultController(this)) {
|
|
5119
|
-
throw defaultControllerBrandCheckException('desiredSize');
|
|
5120
|
-
}
|
|
5121
|
-
const readableController = this._controlledTransformStream._readable._readableStreamController;
|
|
5122
|
-
return ReadableStreamDefaultControllerGetDesiredSize(readableController);
|
|
5123
|
-
}
|
|
5124
|
-
enqueue(chunk = undefined) {
|
|
5125
|
-
if (!IsTransformStreamDefaultController(this)) {
|
|
5126
|
-
throw defaultControllerBrandCheckException('enqueue');
|
|
5127
|
-
}
|
|
5128
|
-
TransformStreamDefaultControllerEnqueue(this, chunk);
|
|
5129
|
-
}
|
|
5130
|
-
/**
|
|
5131
|
-
* Errors both the readable side and the writable side of the controlled transform stream, making all future
|
|
5132
|
-
* interactions with it fail with the given error `e`. Any chunks queued for transformation will be discarded.
|
|
5133
|
-
*/
|
|
5134
|
-
error(reason = undefined) {
|
|
5135
|
-
if (!IsTransformStreamDefaultController(this)) {
|
|
5136
|
-
throw defaultControllerBrandCheckException('error');
|
|
5137
|
-
}
|
|
5138
|
-
TransformStreamDefaultControllerError(this, reason);
|
|
5139
|
-
}
|
|
5140
|
-
/**
|
|
5141
|
-
* Closes the readable side and errors the writable side of the controlled transform stream. This is useful when the
|
|
5142
|
-
* transformer only needs to consume a portion of the chunks written to the writable side.
|
|
5143
|
-
*/
|
|
5144
|
-
terminate() {
|
|
5145
|
-
if (!IsTransformStreamDefaultController(this)) {
|
|
5146
|
-
throw defaultControllerBrandCheckException('terminate');
|
|
5147
|
-
}
|
|
5148
|
-
TransformStreamDefaultControllerTerminate(this);
|
|
5149
|
-
}
|
|
5150
|
-
}
|
|
5151
|
-
Object.defineProperties(TransformStreamDefaultController.prototype, {
|
|
5152
|
-
enqueue: { enumerable: true },
|
|
5153
|
-
error: { enumerable: true },
|
|
5154
|
-
terminate: { enumerable: true },
|
|
5155
|
-
desiredSize: { enumerable: true }
|
|
5156
|
-
});
|
|
5157
|
-
// Transform Stream Default Controller Abstract Operations
|
|
5158
|
-
function IsTransformStreamDefaultController(x) {
|
|
5159
|
-
if (!typeIsObject(x)) {
|
|
5160
|
-
return false;
|
|
5161
|
-
}
|
|
5162
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_controlledTransformStream')) {
|
|
5163
|
-
return false;
|
|
5164
|
-
}
|
|
5165
|
-
return x instanceof TransformStreamDefaultController;
|
|
5166
|
-
}
|
|
5167
|
-
function SetUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm) {
|
|
5168
|
-
controller._controlledTransformStream = stream;
|
|
5169
|
-
stream._transformStreamController = controller;
|
|
5170
|
-
controller._transformAlgorithm = transformAlgorithm;
|
|
5171
|
-
controller._flushAlgorithm = flushAlgorithm;
|
|
5172
|
-
}
|
|
5173
|
-
function SetUpTransformStreamDefaultControllerFromTransformer(stream, transformer) {
|
|
5174
|
-
const controller = Object.create(TransformStreamDefaultController.prototype);
|
|
5175
|
-
let transformAlgorithm = (chunk) => {
|
|
5176
|
-
try {
|
|
5177
|
-
TransformStreamDefaultControllerEnqueue(controller, chunk);
|
|
5178
|
-
return promiseResolvedWith(undefined);
|
|
5179
|
-
}
|
|
5180
|
-
catch (transformResultE) {
|
|
5181
|
-
return promiseRejectedWith(transformResultE);
|
|
5182
|
-
}
|
|
5183
|
-
};
|
|
5184
|
-
let flushAlgorithm = () => promiseResolvedWith(undefined);
|
|
5185
|
-
if (transformer.transform !== undefined) {
|
|
5186
|
-
transformAlgorithm = chunk => transformer.transform(chunk, controller);
|
|
5187
|
-
}
|
|
5188
|
-
if (transformer.flush !== undefined) {
|
|
5189
|
-
flushAlgorithm = () => transformer.flush(controller);
|
|
5190
|
-
}
|
|
5191
|
-
SetUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm);
|
|
5192
|
-
}
|
|
5193
|
-
function TransformStreamDefaultControllerClearAlgorithms(controller) {
|
|
5194
|
-
controller._transformAlgorithm = undefined;
|
|
5195
|
-
controller._flushAlgorithm = undefined;
|
|
5196
|
-
}
|
|
5197
|
-
function TransformStreamDefaultControllerEnqueue(controller, chunk) {
|
|
5198
|
-
const stream = controller._controlledTransformStream;
|
|
5199
|
-
const readableController = stream._readable._readableStreamController;
|
|
5200
|
-
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(readableController)) {
|
|
5201
|
-
throw new TypeError('Readable side is not in a state that permits enqueue');
|
|
5202
|
-
}
|
|
5203
|
-
// We throttle transform invocations based on the backpressure of the ReadableStream, but we still
|
|
5204
|
-
// accept TransformStreamDefaultControllerEnqueue() calls.
|
|
5205
|
-
try {
|
|
5206
|
-
ReadableStreamDefaultControllerEnqueue(readableController, chunk);
|
|
5207
|
-
}
|
|
5208
|
-
catch (e) {
|
|
5209
|
-
// This happens when readableStrategy.size() throws.
|
|
5210
|
-
TransformStreamErrorWritableAndUnblockWrite(stream, e);
|
|
5211
|
-
throw stream._readable._storedError;
|
|
5212
|
-
}
|
|
5213
|
-
const backpressure = ReadableStreamDefaultControllerHasBackpressure(readableController);
|
|
5214
|
-
if (backpressure !== stream._backpressure) {
|
|
5215
|
-
TransformStreamSetBackpressure(stream, true);
|
|
5216
|
-
}
|
|
5217
|
-
}
|
|
5218
|
-
function TransformStreamDefaultControllerError(controller, e) {
|
|
5219
|
-
TransformStreamError(controller._controlledTransformStream, e);
|
|
5220
|
-
}
|
|
5221
|
-
function TransformStreamDefaultControllerPerformTransform(controller, chunk) {
|
|
5222
|
-
const transformPromise = controller._transformAlgorithm(chunk);
|
|
5223
|
-
return transformPromiseWith(transformPromise, undefined, r => {
|
|
5224
|
-
TransformStreamError(controller._controlledTransformStream, r);
|
|
5225
|
-
throw r;
|
|
5226
|
-
});
|
|
5227
|
-
}
|
|
5228
|
-
function TransformStreamDefaultControllerTerminate(controller) {
|
|
5229
|
-
const stream = controller._controlledTransformStream;
|
|
5230
|
-
const readableController = stream._readable._readableStreamController;
|
|
5231
|
-
ReadableStreamDefaultControllerClose(readableController);
|
|
5232
|
-
const error = new TypeError('TransformStream terminated');
|
|
5233
|
-
TransformStreamErrorWritableAndUnblockWrite(stream, error);
|
|
5234
|
-
}
|
|
5235
|
-
// TransformStreamDefaultSink Algorithms
|
|
5236
|
-
function TransformStreamDefaultSinkWriteAlgorithm(stream, chunk) {
|
|
5237
|
-
const controller = stream._transformStreamController;
|
|
5238
|
-
if (stream._backpressure) {
|
|
5239
|
-
const backpressureChangePromise = stream._backpressureChangePromise;
|
|
5240
|
-
return transformPromiseWith(backpressureChangePromise, () => {
|
|
5241
|
-
const writable = stream._writable;
|
|
5242
|
-
const state = writable._state;
|
|
5243
|
-
if (state === 'erroring') {
|
|
5244
|
-
throw writable._storedError;
|
|
5245
|
-
}
|
|
5246
|
-
return TransformStreamDefaultControllerPerformTransform(controller, chunk);
|
|
5247
|
-
});
|
|
5248
|
-
}
|
|
5249
|
-
return TransformStreamDefaultControllerPerformTransform(controller, chunk);
|
|
5250
|
-
}
|
|
5251
|
-
function TransformStreamDefaultSinkAbortAlgorithm(stream, reason) {
|
|
5252
|
-
// abort() is not called synchronously, so it is possible for abort() to be called when the stream is already
|
|
5253
|
-
// errored.
|
|
5254
|
-
TransformStreamError(stream, reason);
|
|
5255
|
-
return promiseResolvedWith(undefined);
|
|
5256
|
-
}
|
|
5257
|
-
function TransformStreamDefaultSinkCloseAlgorithm(stream) {
|
|
5258
|
-
// stream._readable cannot change after construction, so caching it across a call to user code is safe.
|
|
5259
|
-
const readable = stream._readable;
|
|
5260
|
-
const controller = stream._transformStreamController;
|
|
5261
|
-
const flushPromise = controller._flushAlgorithm();
|
|
5262
|
-
TransformStreamDefaultControllerClearAlgorithms(controller);
|
|
5263
|
-
// Return a promise that is fulfilled with undefined on success.
|
|
5264
|
-
return transformPromiseWith(flushPromise, () => {
|
|
5265
|
-
if (readable._state === 'errored') {
|
|
5266
|
-
throw readable._storedError;
|
|
5267
|
-
}
|
|
5268
|
-
ReadableStreamDefaultControllerClose(readable._readableStreamController);
|
|
5269
|
-
}, r => {
|
|
5270
|
-
TransformStreamError(stream, r);
|
|
5271
|
-
throw readable._storedError;
|
|
5272
|
-
});
|
|
5273
|
-
}
|
|
5274
|
-
// TransformStreamDefaultSource Algorithms
|
|
5275
|
-
function TransformStreamDefaultSourcePullAlgorithm(stream) {
|
|
5276
|
-
// Invariant. Enforced by the promises returned by start() and pull().
|
|
5277
|
-
TransformStreamSetBackpressure(stream, false);
|
|
5278
|
-
// Prevent the next pull() call until there is backpressure.
|
|
5279
|
-
return stream._backpressureChangePromise;
|
|
5280
|
-
}
|
|
5281
|
-
// Helper functions for the TransformStreamDefaultController.
|
|
5282
|
-
function defaultControllerBrandCheckException(name) {
|
|
5283
|
-
return new TypeError(`TransformStreamDefaultController.prototype.${name} can only be used on a TransformStreamDefaultController`);
|
|
5284
|
-
}
|
|
5285
|
-
// Helper functions for the TransformStream.
|
|
5286
|
-
function streamBrandCheckException(name) {
|
|
5287
|
-
return new TypeError(`TransformStream.prototype.${name} can only be used on a TransformStream`);
|
|
5288
|
-
}
|
|
5289
1029
|
|
|
5290
1030
|
/* c8 ignore start */
|
|
5291
1031
|
// 64 KiB (same size chrome slice theirs blob into Uint8array's)
|
|
@@ -5560,9 +1300,9 @@ Object.defineProperties(_Blob.prototype, {
|
|
|
5560
1300
|
});
|
|
5561
1301
|
|
|
5562
1302
|
/** @type {typeof globalThis.Blob} */
|
|
5563
|
-
const Blob = _Blob;
|
|
1303
|
+
const Blob$1 = _Blob;
|
|
5564
1304
|
|
|
5565
|
-
const _File = class File extends Blob {
|
|
1305
|
+
const _File = class File extends Blob$1 {
|
|
5566
1306
|
#lastModified = 0
|
|
5567
1307
|
#name = ''
|
|
5568
1308
|
|
|
@@ -5601,19 +1341,19 @@ const _File = class File extends Blob {
|
|
|
5601
1341
|
}
|
|
5602
1342
|
|
|
5603
1343
|
static [Symbol.hasInstance] (object) {
|
|
5604
|
-
return !!object && object instanceof Blob &&
|
|
1344
|
+
return !!object && object instanceof Blob$1 &&
|
|
5605
1345
|
/^(File)$/.test(object[Symbol.toStringTag])
|
|
5606
1346
|
}
|
|
5607
1347
|
};
|
|
5608
1348
|
|
|
5609
1349
|
/** @type {typeof globalThis.File} */// @ts-ignore
|
|
5610
|
-
const File = _File;
|
|
1350
|
+
const File$1 = _File;
|
|
5611
1351
|
|
|
5612
1352
|
/*! formdata-polyfill. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */
|
|
5613
1353
|
|
|
5614
1354
|
var {toStringTag:t$1,iterator:i$1,hasInstance:h$1}=Symbol,
|
|
5615
1355
|
m$1='append,set,get,getAll,delete,keys,values,entries,forEach,constructor'.split(','),
|
|
5616
|
-
f$1=(a,b,c)=>(a+='',/^(Blob|File)$/.test(b && b[t$1])?[(c=c!==void 0?c+'':b[t$1]=='File'?b.name:'blob',a),b.name!==c||b[t$1]=='blob'?new File([b],c,b):b]:[a,b+'']),
|
|
1356
|
+
f$1=(a,b,c)=>(a+='',/^(Blob|File)$/.test(b && b[t$1])?[(c=c!==void 0?c+'':b[t$1]=='File'?b.name:'blob',a),b.name!==c||b[t$1]=='blob'?new File$1([b],c,b):b]:[a,b+'']),
|
|
5617
1357
|
x$1=(n, a, e)=>{if(a.length<e){throw new TypeError(`Failed to execute '${n}' on 'FormData': ${e} arguments required, but only ${a.length} present.`)}};
|
|
5618
1358
|
|
|
5619
1359
|
/** @type {typeof globalThis.FormData} */
|
|
@@ -5660,13 +1400,6 @@ function cancelAnimationFrame(requestId) {
|
|
|
5660
1400
|
}
|
|
5661
1401
|
}
|
|
5662
1402
|
|
|
5663
|
-
function atob(data) {
|
|
5664
|
-
return Buffer.from(data, 'base64').toString('binary');
|
|
5665
|
-
}
|
|
5666
|
-
function btoa(data) {
|
|
5667
|
-
return Buffer.from(data, 'binary').toString('base64');
|
|
5668
|
-
}
|
|
5669
|
-
|
|
5670
1403
|
class Node extends EventTarget {
|
|
5671
1404
|
append(...nodesOrDOMStrings) {
|
|
5672
1405
|
}
|
|
@@ -5819,51 +1552,6 @@ class CustomEvent extends Event {
|
|
|
5819
1552
|
}
|
|
5820
1553
|
allowStringTag(CustomEvent);
|
|
5821
1554
|
|
|
5822
|
-
bootstrap({
|
|
5823
|
-
environmentVariableNamespace: '',
|
|
5824
|
-
});
|
|
5825
|
-
const fetch = {
|
|
5826
|
-
fetch(resource, init) {
|
|
5827
|
-
const resourceURL = new URL(__object_isPrototypeOf(Request.prototype, resource)
|
|
5828
|
-
? resource.url
|
|
5829
|
-
: pathToPosix(resource), typeof Object(globalThis.process).cwd === 'function'
|
|
5830
|
-
? 'file:' + pathToPosix(process.cwd()) + '/'
|
|
5831
|
-
: 'file:');
|
|
5832
|
-
if (resourceURL.protocol.toLowerCase() === 'file:') {
|
|
5833
|
-
return import('node:fs').then((fs) => {
|
|
5834
|
-
try {
|
|
5835
|
-
const stats = fs.statSync(resourceURL);
|
|
5836
|
-
const body = fs.createReadStream(resourceURL);
|
|
5837
|
-
return new Response(body, {
|
|
5838
|
-
status: 200,
|
|
5839
|
-
statusText: '',
|
|
5840
|
-
headers: {
|
|
5841
|
-
'content-length': String(stats.size),
|
|
5842
|
-
date: new Date().toUTCString(),
|
|
5843
|
-
'last-modified': new Date(stats.mtimeMs).toUTCString(),
|
|
5844
|
-
},
|
|
5845
|
-
});
|
|
5846
|
-
}
|
|
5847
|
-
catch (error) {
|
|
5848
|
-
const body = new Stream.Readable();
|
|
5849
|
-
body._read = () => { };
|
|
5850
|
-
body.push(null);
|
|
5851
|
-
return new Response(body, {
|
|
5852
|
-
status: 404,
|
|
5853
|
-
statusText: '',
|
|
5854
|
-
headers: {
|
|
5855
|
-
date: new Date().toUTCString(),
|
|
5856
|
-
},
|
|
5857
|
-
});
|
|
5858
|
-
}
|
|
5859
|
-
});
|
|
5860
|
-
}
|
|
5861
|
-
else {
|
|
5862
|
-
return nodeFetch(resource, init);
|
|
5863
|
-
}
|
|
5864
|
-
},
|
|
5865
|
-
}.fetch;
|
|
5866
|
-
|
|
5867
1555
|
const INTERNAL$1 = { tick: 0, pool: new Map() };
|
|
5868
1556
|
function requestIdleCallback(callback) {
|
|
5869
1557
|
if (!INTERNAL$1.pool.size) {
|
|
@@ -6865,93 +2553,12 @@ function alert(...messages) {
|
|
|
6865
2553
|
console.log(...messages);
|
|
6866
2554
|
}
|
|
6867
2555
|
|
|
6868
|
-
|
|
6869
|
-
|
|
6870
|
-
|
|
6871
|
-
|
|
6872
|
-
|
|
6873
|
-
const
|
|
6874
|
-
if (exclude.has('Object') || exclude.has('object') || exclude.has('hasOwn'))
|
|
6875
|
-
return;
|
|
6876
|
-
const Class = target.Object || globalThis.Object;
|
|
6877
|
-
Object.defineProperty(Class, 'hasOwn', {
|
|
6878
|
-
value: hasOwn,
|
|
6879
|
-
writable: true,
|
|
6880
|
-
enumerable: false,
|
|
6881
|
-
configurable: true,
|
|
6882
|
-
});
|
|
6883
|
-
};
|
|
6884
|
-
|
|
6885
|
-
const any = {
|
|
6886
|
-
async any(iterable) {
|
|
6887
|
-
return Promise.all([...iterable].map((promise) => {
|
|
6888
|
-
return new Promise((resolve, reject) => Promise.resolve(promise).then(reject, resolve));
|
|
6889
|
-
})).then((errors) => Promise.reject(errors), (value) => Promise.resolve(value));
|
|
6890
|
-
},
|
|
6891
|
-
}.any;
|
|
6892
|
-
const initPromise = (target, exclude) => {
|
|
6893
|
-
if (exclude.has('Promise') || exclude.has('any'))
|
|
6894
|
-
return;
|
|
6895
|
-
const Class = target.Promise || globalThis.Promise;
|
|
6896
|
-
if (!Class.any)
|
|
6897
|
-
Object.defineProperty(Class, 'any', {
|
|
6898
|
-
value: any,
|
|
6899
|
-
writable: true,
|
|
6900
|
-
enumerable: false,
|
|
6901
|
-
configurable: true,
|
|
6902
|
-
});
|
|
6903
|
-
};
|
|
6904
|
-
|
|
6905
|
-
const at = {
|
|
6906
|
-
at(index) {
|
|
6907
|
-
index = Math.trunc(index) || 0;
|
|
6908
|
-
if (index < 0)
|
|
6909
|
-
index += this.length;
|
|
6910
|
-
if (index < 0 || index >= this.length)
|
|
6911
|
-
return undefined;
|
|
6912
|
-
return this[index];
|
|
6913
|
-
},
|
|
6914
|
-
}.at;
|
|
6915
|
-
const initRelativeIndexingMethod = (target, exclude) => {
|
|
6916
|
-
if (exclude.has('at'))
|
|
6917
|
-
return;
|
|
6918
|
-
const Classes = [];
|
|
6919
|
-
if (!exclude.has('TypedArray'))
|
|
6920
|
-
Classes.push(Object.getPrototypeOf(target.Int8Array || globalThis.Int8Array));
|
|
6921
|
-
if (!exclude.has('Array'))
|
|
6922
|
-
Classes.push(target.Array || globalThis.Array);
|
|
6923
|
-
if (!exclude.has('String'))
|
|
6924
|
-
Classes.push(target.String || globalThis.String);
|
|
6925
|
-
for (const Class of Classes) {
|
|
6926
|
-
if (!Class.prototype.at)
|
|
6927
|
-
Object.defineProperty(Class.prototype, 'at', {
|
|
6928
|
-
value: at,
|
|
6929
|
-
writable: true,
|
|
6930
|
-
enumerable: false,
|
|
6931
|
-
configurable: true,
|
|
6932
|
-
});
|
|
6933
|
-
}
|
|
6934
|
-
};
|
|
6935
|
-
|
|
6936
|
-
const replaceAll = {
|
|
6937
|
-
replaceAll(searchValue, replaceValue) {
|
|
6938
|
-
return __object_isPrototypeOf(RegExp.prototype, searchValue)
|
|
6939
|
-
? this.replace(searchValue, replaceValue)
|
|
6940
|
-
: this.replace(new RegExp(__string_escapeRegExp(searchValue), 'g'), replaceValue);
|
|
6941
|
-
},
|
|
6942
|
-
}.replaceAll;
|
|
6943
|
-
const initString = (target, exclude) => {
|
|
6944
|
-
if (exclude.has('String') || exclude.has('replaceAll'))
|
|
6945
|
-
return;
|
|
6946
|
-
const Class = target.String || globalThis.String;
|
|
6947
|
-
if (!Class.prototype.replaceAll)
|
|
6948
|
-
Object.defineProperty(Class.prototype, 'replaceAll', {
|
|
6949
|
-
value: replaceAll,
|
|
6950
|
-
writable: true,
|
|
6951
|
-
enumerable: false,
|
|
6952
|
-
configurable: true,
|
|
6953
|
-
});
|
|
6954
|
-
};
|
|
2556
|
+
// @ts-check
|
|
2557
|
+
const fetch = undici.fetch;
|
|
2558
|
+
const Headers = undici.Headers;
|
|
2559
|
+
const Response = undici.Response;
|
|
2560
|
+
const Request = undici.Request;
|
|
2561
|
+
const File = undici.File;
|
|
6955
2562
|
|
|
6956
2563
|
const exclusionsForHTMLElement = [
|
|
6957
2564
|
'CustomElementsRegistry',
|
|
@@ -6983,7 +2590,6 @@ const exclusionsForNode = [
|
|
|
6983
2590
|
...exclusionsForElement,
|
|
6984
2591
|
];
|
|
6985
2592
|
const exclusionsForEventTarget = [
|
|
6986
|
-
'AbortSignal',
|
|
6987
2593
|
'Event',
|
|
6988
2594
|
'CustomEvent',
|
|
6989
2595
|
'EventTarget',
|
|
@@ -6993,7 +2599,6 @@ const exclusionsForEventTarget = [
|
|
|
6993
2599
|
...exclusionsForNode,
|
|
6994
2600
|
];
|
|
6995
2601
|
const exclusionsForEvent = [
|
|
6996
|
-
'AbortSignal',
|
|
6997
2602
|
'Event',
|
|
6998
2603
|
'CustomEvent',
|
|
6999
2604
|
'EventTarget',
|
|
@@ -7003,7 +2608,6 @@ const exclusionsForEvent = [
|
|
|
7003
2608
|
...exclusionsForNode,
|
|
7004
2609
|
];
|
|
7005
2610
|
const exclusions = {
|
|
7006
|
-
'Blob+': ['Blob', 'File'],
|
|
7007
2611
|
'Document+': exclusionsForDocument,
|
|
7008
2612
|
'Element+': exclusionsForElement,
|
|
7009
2613
|
'Event+': exclusionsForEvent,
|
|
@@ -7013,14 +2617,13 @@ const exclusions = {
|
|
|
7013
2617
|
'StyleSheet+': ['StyleSheet', 'CSSStyleSheet'],
|
|
7014
2618
|
};
|
|
7015
2619
|
|
|
7016
|
-
const
|
|
2620
|
+
const inheritance = {
|
|
7017
2621
|
CSSStyleSheet: 'StyleSheet',
|
|
7018
2622
|
CustomEvent: 'Event',
|
|
7019
2623
|
DOMException: 'Error',
|
|
7020
2624
|
Document: 'Node',
|
|
7021
2625
|
DocumentFragment: 'Node',
|
|
7022
2626
|
Element: 'Node',
|
|
7023
|
-
File: 'Blob',
|
|
7024
2627
|
HTMLDocument: 'Document',
|
|
7025
2628
|
HTMLElement: 'Element',
|
|
7026
2629
|
HTMLBodyElement: 'HTMLElement',
|
|
@@ -7043,9 +2646,6 @@ const inheritence = {
|
|
|
7043
2646
|
|
|
7044
2647
|
const polyfill = (target, options) => {
|
|
7045
2648
|
const webAPIs = {
|
|
7046
|
-
AbortController,
|
|
7047
|
-
AbortSignal,
|
|
7048
|
-
Blob,
|
|
7049
2649
|
ByteLengthQueuingStrategy,
|
|
7050
2650
|
CanvasRenderingContext2D,
|
|
7051
2651
|
CharacterData,
|
|
@@ -7105,8 +2705,6 @@ const polyfill = (target, options) => {
|
|
|
7105
2705
|
WritableStreamDefaultWriter,
|
|
7106
2706
|
Window,
|
|
7107
2707
|
alert,
|
|
7108
|
-
atob,
|
|
7109
|
-
btoa,
|
|
7110
2708
|
cancelAnimationFrame,
|
|
7111
2709
|
cancelIdleCallback,
|
|
7112
2710
|
clearTimeout,
|
|
@@ -7152,17 +2750,17 @@ const polyfill = (target, options) => {
|
|
|
7152
2750
|
if (excludeOptions.has(name))
|
|
7153
2751
|
continue;
|
|
7154
2752
|
// skip WebAPIs that do not extend other WebAPIs
|
|
7155
|
-
if (!Object.hasOwnProperty.call(
|
|
2753
|
+
if (!Object.hasOwnProperty.call(inheritance, name))
|
|
7156
2754
|
continue;
|
|
7157
2755
|
const Class = target[name];
|
|
7158
|
-
const Super = target[
|
|
2756
|
+
const Super = target[inheritance[name]];
|
|
7159
2757
|
// skip WebAPIs that are not available
|
|
7160
2758
|
if (!Class || !Super)
|
|
7161
2759
|
continue;
|
|
7162
2760
|
// skip WebAPIs that are already inherited correctly
|
|
7163
2761
|
if (Object.getPrototypeOf(Class.prototype) === Super.prototype)
|
|
7164
2762
|
continue;
|
|
7165
|
-
// define WebAPIs
|
|
2763
|
+
// define WebAPIs inheritance
|
|
7166
2764
|
Object.setPrototypeOf(Class.prototype, Super.prototype);
|
|
7167
2765
|
}
|
|
7168
2766
|
if (!excludeOptions.has('HTMLDocument') &&
|
|
@@ -7172,12 +2770,8 @@ const polyfill = (target, options) => {
|
|
|
7172
2770
|
initCustomElementRegistry(target, excludeOptions);
|
|
7173
2771
|
}
|
|
7174
2772
|
}
|
|
7175
|
-
initObject(target, excludeOptions);
|
|
7176
2773
|
initMediaQueryList(target, excludeOptions);
|
|
7177
|
-
initPromise(target, excludeOptions);
|
|
7178
|
-
initRelativeIndexingMethod(target, excludeOptions);
|
|
7179
2774
|
initStorage(target, excludeOptions);
|
|
7180
|
-
initString(target, excludeOptions);
|
|
7181
2775
|
initWindow(target, excludeOptions);
|
|
7182
2776
|
return target;
|
|
7183
2777
|
};
|
|
@@ -7186,11 +2780,7 @@ polyfill.internals = (target, name) => {
|
|
|
7186
2780
|
CustomElementRegistry: initCustomElementRegistry,
|
|
7187
2781
|
Document: initDocument,
|
|
7188
2782
|
MediaQueryList: initMediaQueryList,
|
|
7189
|
-
Object: initObject,
|
|
7190
|
-
Promise: initPromise,
|
|
7191
|
-
RelativeIndexingMethod: initRelativeIndexingMethod,
|
|
7192
2783
|
Storage: initStorage,
|
|
7193
|
-
String: initString,
|
|
7194
2784
|
Window: initWindow,
|
|
7195
2785
|
};
|
|
7196
2786
|
init[name](target, new Set());
|
|
@@ -7534,6 +3124,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
7534
3124
|
props: {
|
|
7535
3125
|
speed: { default: "default" },
|
|
7536
3126
|
slide: null,
|
|
3127
|
+
isFloating: { type: Boolean, default: false },
|
|
7537
3128
|
isLeaveTo: { type: Boolean, default: true },
|
|
7538
3129
|
isEnterFrom: { type: Boolean, default: true }
|
|
7539
3130
|
},
|
|
@@ -7577,45 +3168,41 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
7577
3168
|
return props.slide === "down" || props.slide === "up";
|
|
7578
3169
|
});
|
|
7579
3170
|
const height = computed(() => {
|
|
3171
|
+
if (props.isFloating)
|
|
3172
|
+
return null;
|
|
7580
3173
|
return isSlideY.value ? 0 : "auto";
|
|
7581
3174
|
});
|
|
7582
3175
|
const width = computed(() => {
|
|
3176
|
+
if (props.isFloating)
|
|
3177
|
+
return null;
|
|
7583
3178
|
return props.slide && !isSlideY.value ? 0 : "auto";
|
|
7584
3179
|
});
|
|
7585
3180
|
const enterFromHeight = computed(() => {
|
|
7586
3181
|
return props.isEnterFrom ? height.value : "auto";
|
|
7587
3182
|
});
|
|
7588
|
-
const leaveToHeight = computed(() => {
|
|
7589
|
-
return props.isLeaveTo ? height.value : "auto";
|
|
7590
|
-
});
|
|
7591
3183
|
const enterFromWidth = computed(() => {
|
|
7592
3184
|
return props.isEnterFrom ? width.value : "auto";
|
|
7593
3185
|
});
|
|
7594
|
-
const leaveToWidth = computed(() => {
|
|
7595
|
-
return props.isLeaveTo ? width.value : "auto";
|
|
7596
|
-
});
|
|
7597
3186
|
const willChange = computed(() => {
|
|
7598
3187
|
let properties = "opacity";
|
|
7599
3188
|
if (transform.value !== "none")
|
|
7600
3189
|
properties += ", transform";
|
|
7601
|
-
if (height.value
|
|
3190
|
+
if (height.value === 0)
|
|
7602
3191
|
properties += ", height";
|
|
7603
|
-
if (width.value
|
|
3192
|
+
if (width.value === 0)
|
|
7604
3193
|
properties += ", width";
|
|
7605
3194
|
return properties;
|
|
7606
3195
|
});
|
|
7607
3196
|
return (_ctx, _push, _parent, _attrs) => {
|
|
7608
3197
|
({ style: {
|
|
7609
|
-
"--
|
|
7610
|
-
"--
|
|
7611
|
-
"--
|
|
7612
|
-
"--
|
|
7613
|
-
"--
|
|
7614
|
-
"--
|
|
7615
|
-
"--
|
|
7616
|
-
"--
|
|
7617
|
-
"--5ef3e2f4": unref(leaveToHeight),
|
|
7618
|
-
"--7b2c0887": unref(leaveToWidth)
|
|
3198
|
+
"--68e3b484": unref(willChange),
|
|
3199
|
+
"--17a22876": unref(duration),
|
|
3200
|
+
"--bc2eb02a": unref(enterFromOpacity),
|
|
3201
|
+
"--da7ab968": unref(enterFromTransform),
|
|
3202
|
+
"--43026547": unref(enterFromHeight),
|
|
3203
|
+
"--6e5955a6": unref(enterFromWidth),
|
|
3204
|
+
"--6f10697b": unref(leaveToOpacity),
|
|
3205
|
+
"--95ff7e48": unref(leaveToTransform)
|
|
7619
3206
|
} });
|
|
7620
3207
|
ssrRenderSlotInner(_ctx.$slots, "default", {}, null, _push, _parent, null, true);
|
|
7621
3208
|
};
|
|
@@ -7636,7 +3223,7 @@ _sfc_main$1.setup = (props, ctx) => {
|
|
|
7636
3223
|
(ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("src/lib/components/globals/Fade.vue");
|
|
7637
3224
|
return _sfc_setup$1 ? _sfc_setup$1(props, ctx) : void 0;
|
|
7638
3225
|
};
|
|
7639
|
-
const Fade = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-
|
|
3226
|
+
const Fade = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-d3912920"]]);
|
|
7640
3227
|
|
|
7641
3228
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
7642
3229
|
__name: "ALink",
|
|
@@ -7734,7 +3321,7 @@ const _renderer1 = {
|
|
|
7734
3321
|
const pageMap = new Map([["../../node_modules/.pnpm/@astrojs+image@0.13.0_astro@2.0.2+sharp@0.31.3/node_modules/@astrojs/image/dist/endpoint.js", _page0],["src/pages/index.astro", _page1],["src/pages/fallback.astro", _page2],["src/pages/app/index.astro", _page3],["src/pages/app/account.astro", _page4],["src/pages/[...slug].astro", _page5],]);
|
|
7735
3322
|
const renderers = [Object.assign({"name":"astro:jsx","serverEntrypoint":"astro/jsx/server.js","jsxImportSource":"astro"}, { ssr: server_default }),Object.assign({"name":"@astrojs/vue","clientEntrypoint":"@astrojs/vue/client.js","serverEntrypoint":"@astrojs/vue/server.js"}, { ssr: _renderer1 }),];
|
|
7736
3323
|
|
|
7737
|
-
const _manifest = Object.assign(deserializeManifest({"adapterName":"@astrojs/node","routes":[{"file":"fallback/index.html","links":[],"scripts":[],"routeData":{"route":"/fallback","type":"page","pattern":"^\\/fallback\\/?$","segments":[[{"content":"fallback","dynamic":false,"spread":false}]],"params":[],"component":"src/pages/fallback.astro","pathname":"/fallback","_meta":{"trailingSlash":"ignore"}}},{"file":"","links":[],"scripts":[],"routeData":{"type":"endpoint","route":"/_image","pattern":"^\\/_image$","segments":[[{"content":"_image","dynamic":false,"spread":false}]],"params":[],"component":"../../node_modules/.pnpm/@astrojs+image@0.13.0_astro@2.0.2+sharp@0.31.3/node_modules/@astrojs/image/dist/endpoint.js","pathname":"/_image","_meta":{"trailingSlash":"ignore"}}},{"file":"","links":["_astro/_...slug_.
|
|
3324
|
+
const _manifest = Object.assign(deserializeManifest({"adapterName":"@astrojs/node","routes":[{"file":"fallback/index.html","links":[],"scripts":[],"routeData":{"route":"/fallback","type":"page","pattern":"^\\/fallback\\/?$","segments":[[{"content":"fallback","dynamic":false,"spread":false}]],"params":[],"component":"src/pages/fallback.astro","pathname":"/fallback","_meta":{"trailingSlash":"ignore"}}},{"file":"","links":[],"scripts":[],"routeData":{"type":"endpoint","route":"/_image","pattern":"^\\/_image$","segments":[[{"content":"_image","dynamic":false,"spread":false}]],"params":[],"component":"../../node_modules/.pnpm/@astrojs+image@0.13.0_astro@2.0.2+sharp@0.31.3/node_modules/@astrojs/image/dist/endpoint.js","pathname":"/_image","_meta":{"trailingSlash":"ignore"}}},{"file":"","links":["_astro/_...slug_.32968ccf.css","_astro/index.90df622b.css"],"scripts":[{"type":"external","value":"_astro/hoisted.6edd7364.js"}],"routeData":{"route":"/","type":"page","pattern":"^\\/$","segments":[],"params":[],"component":"src/pages/index.astro","pathname":"/","_meta":{"trailingSlash":"ignore"}}},{"file":"","links":[],"scripts":[],"routeData":{"route":"/app","type":"page","pattern":"^\\/app\\/?$","segments":[[{"content":"app","dynamic":false,"spread":false}]],"params":[],"component":"src/pages/app/index.astro","pathname":"/app","_meta":{"trailingSlash":"ignore"}}},{"file":"","links":[],"scripts":[],"routeData":{"route":"/app/account","type":"page","pattern":"^\\/app\\/account\\/?$","segments":[[{"content":"app","dynamic":false,"spread":false}],[{"content":"account","dynamic":false,"spread":false}]],"params":[],"component":"src/pages/app/account.astro","pathname":"/app/account","_meta":{"trailingSlash":"ignore"}}},{"file":"","links":["_astro/_...slug_.32968ccf.css"],"scripts":[{"type":"external","value":"_astro/hoisted.6edd7364.js"}],"routeData":{"route":"/[...slug]","type":"page","pattern":"^(?:\\/(.*?))?\\/?$","segments":[[{"content":"...slug","dynamic":true,"spread":true}]],"params":["...slug"],"component":"src/pages/[...slug].astro","_meta":{"trailingSlash":"ignore"}}}],"site":"https://ecom2-002.web.app","base":"/","markdown":{"drafts":false,"syntaxHighlight":"shiki","shikiConfig":{"langs":[],"theme":"github-dark","wrap":false},"remarkPlugins":[],"rehypePlugins":[],"remarkRehype":{},"gfm":true,"smartypants":true,"contentDir":"file:///home/leo/code/ecomplus/cloud-commerce/packages/storefront/src/content/"},"pageMap":null,"renderers":[],"entryModules":{"\u0000@astrojs-ssr-virtual-entry":"_@astrojs-ssr-virtual-entry.mjs","@@sf/components/Prices.vue":"_astro/Prices.6fbcb5ac.js","@@sf/components/PitchBar.vue":"_astro/PitchBar.209c6645.js","@@sf/components/ProductCard.vue":"_astro/ProductCard.ee5eee91.js","/astro/hoisted.js?q=0":"_astro/hoisted.6edd7364.js","/home/leo/code/ecomplus/cloud-commerce/node_modules/workbox-window/build/workbox-window.prod.es5.mjs":"_astro/workbox-window.prod.es5.295a6886.js","@astrojs/vue/client.js":"_astro/client.5a46cc02.js","@@sf/components/ShopHeader.vue":"_astro/ShopHeader.b801c785.js","astro:scripts/before-hydration.js":""},"assets":["/_astro/index.90df622b.css","/_astro/server.60de185d.css","/_astro/_...slug_.32968ccf.css","/manifest.webmanifest","/registerSW.js","/robots.txt","/sw.js","/workbox-e2ee76b5.js","/_astro/PitchBar.209c6645.js","/_astro/Prices.6fbcb5ac.js","/_astro/Prices.vue_vue_type_script_setup_true_lang.44f23680.js","/_astro/ProductCard.ee5eee91.js","/_astro/ShopHeader.b801c785.js","/_astro/client.5a46cc02.js","/_astro/ecom-utils.92f137f6.js","/_astro/hoisted.6edd7364.js","/_astro/index.844a4059.js","/_astro/modules-info.d9373e21.js","/_astro/runtime-core.esm-bundler.f04cee62.js","/_astro/runtime-dom.esm-bundler.00313542.js","/_astro/session-utm.72684b84.js","/_astro/use-component-variant.58788b6e.js","/_astro/workbox-window.prod.es5.295a6886.js","/admin/config.json","/assets/cms-preview.css","/assets/cms.css","/assets/cvv.png","/assets/img-placeholder.png","/assets/payments.png","/assets/ssl-safe.png","/img/icon.png","/img/large-icon.png","/img/uploads/banner1.png","/img/uploads/banner2.png","/img/uploads/banner2.webp","/img/uploads/favicon.png","/img/uploads/headless.png","/img/uploads/headphone.png","/img/uploads/headphone.webp","/img/uploads/icon.png","/img/uploads/large-icon.png","/img/uploads/logo.png","/img/uploads/logo.webp","/img/uploads/og-image.png","/img/uploads/passion.png","/img/uploads/passion.webp","/img/uploads/pwa-reliable.png","/img/uploads/rect8589.png","/img/uploads/rect859.png","/img/uploads/rect89.png","/img/uploads/rect89.webp","/img/uploads/ssl-safe.png","/assets/icons/bootstrap-icons/font/storefront-icons.woff2","/assets/icons/feather-icons/font/storefront-icons.woff2","/assets/icons/font-awesome/font/storefront-icons.woff2","/assets/icons/line-awesome/font/storefront-icons.woff2","/assets/icons/tabler-icons/font/storefront-icons.woff2","/fallback/index.html"]}), {
|
|
7738
3325
|
pageMap: pageMap,
|
|
7739
3326
|
renderers: renderers
|
|
7740
3327
|
});
|