mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
refactor: introduce primordials for web/streams (#11251)
This commit is contained in:
parent
c4cc353d59
commit
3ee0c36453
3 changed files with 109 additions and 86 deletions
|
@ -170,6 +170,9 @@
|
||||||
// Create copy of isNaN
|
// Create copy of isNaN
|
||||||
primordials[isNaN.name] = isNaN;
|
primordials[isNaN.name] = isNaN;
|
||||||
|
|
||||||
|
// Create copy of queueMicrotask
|
||||||
|
primordials["queueMicrotask"] = queueMicrotask;
|
||||||
|
|
||||||
// Create copies of URI handling functions
|
// Create copies of URI handling functions
|
||||||
[
|
[
|
||||||
decodeURI,
|
decodeURI,
|
||||||
|
|
1
core/internal.d.ts
vendored
1
core/internal.d.ts
vendored
|
@ -632,6 +632,7 @@ declare namespace __bootstrap {
|
||||||
export const ObjectPrototypeToLocaleString: UncurryThis<
|
export const ObjectPrototypeToLocaleString: UncurryThis<
|
||||||
typeof Object.prototype.toLocaleString
|
typeof Object.prototype.toLocaleString
|
||||||
>;
|
>;
|
||||||
|
export const queueMicrotask: typeof globalThis.queueMicrotask;
|
||||||
export const RangeError: typeof globalThis.RangeError;
|
export const RangeError: typeof globalThis.RangeError;
|
||||||
export const RangeErrorLength: typeof RangeError.length;
|
export const RangeErrorLength: typeof RangeError.length;
|
||||||
export const RangeErrorName: typeof RangeError.name;
|
export const RangeErrorName: typeof RangeError.name;
|
||||||
|
|
|
@ -9,6 +9,33 @@
|
||||||
|
|
||||||
((window) => {
|
((window) => {
|
||||||
const webidl = window.__bootstrap.webidl;
|
const webidl = window.__bootstrap.webidl;
|
||||||
|
// TODO(lucacasonato): get AbortSignal from __bootstrap.
|
||||||
|
const {
|
||||||
|
ArrayPrototypeMap,
|
||||||
|
ArrayPrototypePush,
|
||||||
|
ArrayPrototypeShift,
|
||||||
|
Error,
|
||||||
|
NumberIsInteger,
|
||||||
|
NumberIsNaN,
|
||||||
|
ObjectCreate,
|
||||||
|
ObjectDefineProperties,
|
||||||
|
ObjectDefineProperty,
|
||||||
|
ObjectGetPrototypeOf,
|
||||||
|
ObjectSetPrototypeOf,
|
||||||
|
Promise,
|
||||||
|
PromiseAll,
|
||||||
|
PromisePrototypeThen,
|
||||||
|
PromiseReject,
|
||||||
|
queueMicrotask,
|
||||||
|
RangeError,
|
||||||
|
SymbolAsyncIterator,
|
||||||
|
TypeError,
|
||||||
|
Uint8Array,
|
||||||
|
WeakMap,
|
||||||
|
WeakMapPrototypeGet,
|
||||||
|
WeakMapPrototypeHas,
|
||||||
|
WeakMapPrototypeSet,
|
||||||
|
} = globalThis.__bootstrap.primordials;
|
||||||
const { DOMException } = window.__bootstrap.domException;
|
const { DOMException } = window.__bootstrap.domException;
|
||||||
|
|
||||||
class AssertionError extends Error {
|
class AssertionError extends Error {
|
||||||
|
@ -78,29 +105,13 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const originalPromise = Promise;
|
|
||||||
const originalPromiseThen = Promise.prototype.then;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @template T
|
|
||||||
* @template TResult1
|
|
||||||
* @template TResult2
|
|
||||||
* @param {Promise<T>} promise
|
|
||||||
* @param {(value: T) => TResult1 | PromiseLike<TResult1>} onFulfilled
|
|
||||||
* @param {(reason: any) => TResult2 | PromiseLike<TResult2>=} onRejected
|
|
||||||
* @returns {Promise<TResult1 | TResult2>}
|
|
||||||
*/
|
|
||||||
function performPromiseThen(promise, onFulfilled, onRejected) {
|
|
||||||
return originalPromiseThen.call(promise, onFulfilled, onRejected);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @template T
|
* @template T
|
||||||
* @param {T | PromiseLike<T>} value
|
* @param {T | PromiseLike<T>} value
|
||||||
* @returns {Promise<T>}
|
* @returns {Promise<T>}
|
||||||
*/
|
*/
|
||||||
function resolvePromiseWith(value) {
|
function resolvePromiseWith(value) {
|
||||||
return new originalPromise((resolve) => resolve(value));
|
return new Promise((resolve) => resolve(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @param {any} e */
|
/** @param {any} e */
|
||||||
|
@ -114,7 +125,7 @@
|
||||||
|
|
||||||
/** @param {Promise<any>} promise */
|
/** @param {Promise<any>} promise */
|
||||||
function setPromiseIsHandledToTrue(promise) {
|
function setPromiseIsHandledToTrue(promise) {
|
||||||
performPromiseThen(promise, undefined, rethrowAssertionErrorRejection);
|
PromisePrototypeThen(promise, undefined, rethrowAssertionErrorRejection);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -127,7 +138,7 @@
|
||||||
* @returns {Promise<TResult1 | TResult2>}
|
* @returns {Promise<TResult1 | TResult2>}
|
||||||
*/
|
*/
|
||||||
function transformPromiseWith(promise, fulfillmentHandler, rejectionHandler) {
|
function transformPromiseWith(promise, fulfillmentHandler, rejectionHandler) {
|
||||||
return performPromiseThen(promise, fulfillmentHandler, rejectionHandler);
|
return PromisePrototypeThen(promise, fulfillmentHandler, rejectionHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -162,8 +173,8 @@
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
function uponPromise(promise, onFulfilled, onRejected) {
|
function uponPromise(promise, onFulfilled, onRejected) {
|
||||||
performPromiseThen(
|
PromisePrototypeThen(
|
||||||
performPromiseThen(promise, onFulfilled, onRejected),
|
PromisePrototypeThen(promise, onFulfilled, onRejected),
|
||||||
undefined,
|
undefined,
|
||||||
rethrowAssertionErrorRejection,
|
rethrowAssertionErrorRejection,
|
||||||
);
|
);
|
||||||
|
@ -335,7 +346,7 @@
|
||||||
function dequeueValue(container) {
|
function dequeueValue(container) {
|
||||||
assert(_queue in container && _queueTotalSize in container);
|
assert(_queue in container && _queueTotalSize in container);
|
||||||
assert(container[_queue].length);
|
assert(container[_queue].length);
|
||||||
const valueWithSize = container[_queue].shift();
|
const valueWithSize = ArrayPrototypeShift(container[_queue]);
|
||||||
container[_queueTotalSize] -= valueWithSize.size;
|
container[_queueTotalSize] -= valueWithSize.size;
|
||||||
if (container[_queueTotalSize] < 0) {
|
if (container[_queueTotalSize] < 0) {
|
||||||
container[_queueTotalSize] = 0;
|
container[_queueTotalSize] = 0;
|
||||||
|
@ -358,7 +369,7 @@
|
||||||
if (size === Infinity) {
|
if (size === Infinity) {
|
||||||
throw RangeError("chunk size is invalid");
|
throw RangeError("chunk size is invalid");
|
||||||
}
|
}
|
||||||
container[_queue].push({ value, size });
|
ArrayPrototypePush(container[_queue], { value, size });
|
||||||
container[_queueTotalSize] += size;
|
container[_queueTotalSize] += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,7 +382,7 @@
|
||||||
return defaultHWM;
|
return defaultHWM;
|
||||||
}
|
}
|
||||||
const highWaterMark = strategy.highWaterMark;
|
const highWaterMark = strategy.highWaterMark;
|
||||||
if (Number.isNaN(highWaterMark) || highWaterMark < 0) {
|
if (NumberIsNaN(highWaterMark) || highWaterMark < 0) {
|
||||||
throw RangeError(
|
throw RangeError(
|
||||||
`Expected highWaterMark to be a positive number or Infinity, got "${highWaterMark}".`,
|
`Expected highWaterMark to be a positive number or Infinity, got "${highWaterMark}".`,
|
||||||
);
|
);
|
||||||
|
@ -492,7 +503,7 @@
|
||||||
if (typeof v !== "number") {
|
if (typeof v !== "number") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (Number.isNaN(v)) {
|
if (NumberIsNaN(v)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (v < 0) {
|
if (v < 0) {
|
||||||
|
@ -589,7 +600,8 @@
|
||||||
/** @type {Promise<void>} */
|
/** @type {Promise<void>} */
|
||||||
const pullPromise = controller[_pullAlgorithm](controller);
|
const pullPromise = controller[_pullAlgorithm](controller);
|
||||||
setPromiseIsHandledToTrue(
|
setPromiseIsHandledToTrue(
|
||||||
pullPromise.then(
|
PromisePrototypeThen(
|
||||||
|
pullPromise,
|
||||||
() => {
|
() => {
|
||||||
controller[_pulling] = false;
|
controller[_pulling] = false;
|
||||||
if (controller[_pullAgain]) {
|
if (controller[_pullAgain]) {
|
||||||
|
@ -707,7 +719,7 @@
|
||||||
byteOffset,
|
byteOffset,
|
||||||
byteLength,
|
byteLength,
|
||||||
) {
|
) {
|
||||||
controller[_queue].push({ buffer, byteOffset, byteLength });
|
ArrayPrototypePush(controller[_queue], { buffer, byteOffset, byteLength });
|
||||||
controller[_queueTotalSize] += byteLength;
|
controller[_queueTotalSize] += byteLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -787,7 +799,7 @@
|
||||||
function readableStreamAddReadRequest(stream, readRequest) {
|
function readableStreamAddReadRequest(stream, readRequest) {
|
||||||
assert(isReadableStreamDefaultReader(stream[_reader]));
|
assert(isReadableStreamDefaultReader(stream[_reader]));
|
||||||
assert(stream[_state] === "readable");
|
assert(stream[_state] === "readable");
|
||||||
stream[_reader][_readRequests].push(readRequest);
|
ArrayPrototypePush(stream[_reader][_readRequests], readRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -802,12 +814,12 @@
|
||||||
return resolvePromiseWith(undefined);
|
return resolvePromiseWith(undefined);
|
||||||
}
|
}
|
||||||
if (stream[_state] === "errored") {
|
if (stream[_state] === "errored") {
|
||||||
return Promise.reject(stream[_storedError]);
|
return PromiseReject(stream[_storedError]);
|
||||||
}
|
}
|
||||||
readableStreamClose(stream);
|
readableStreamClose(stream);
|
||||||
/** @type {Promise<void>} */
|
/** @type {Promise<void>} */
|
||||||
const sourceCancelPromise = stream[_controller][_cancelSteps](reason);
|
const sourceCancelPromise = stream[_controller][_cancelSteps](reason);
|
||||||
return sourceCancelPromise.then(() => undefined);
|
return PromisePrototypeThen(sourceCancelPromise, () => undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1064,7 +1076,7 @@
|
||||||
const reader = stream[_reader];
|
const reader = stream[_reader];
|
||||||
assert(reader[_readRequests].length);
|
assert(reader[_readRequests].length);
|
||||||
/** @type {ReadRequest<R>} */
|
/** @type {ReadRequest<R>} */
|
||||||
const readRequest = reader[_readRequests].shift();
|
const readRequest = ArrayPrototypeShift(reader[_readRequests]);
|
||||||
if (done) {
|
if (done) {
|
||||||
readRequest.closeSteps();
|
readRequest.closeSteps();
|
||||||
} else {
|
} else {
|
||||||
|
@ -1138,7 +1150,7 @@
|
||||||
/** @type {Array<() => Promise<void>>} */
|
/** @type {Array<() => Promise<void>>} */
|
||||||
const actions = [];
|
const actions = [];
|
||||||
if (preventAbort === false) {
|
if (preventAbort === false) {
|
||||||
actions.push(() => {
|
ArrayPrototypePush(actions, () => {
|
||||||
if (dest[_state] === "writable") {
|
if (dest[_state] === "writable") {
|
||||||
return writableStreamAbort(dest, error);
|
return writableStreamAbort(dest, error);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1147,7 +1159,7 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (preventCancel === false) {
|
if (preventCancel === false) {
|
||||||
actions.push(() => {
|
ArrayPrototypePush(actions, () => {
|
||||||
if (source[_state] === "readable") {
|
if (source[_state] === "readable") {
|
||||||
return readableStreamCancel(source, error);
|
return readableStreamCancel(source, error);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1156,7 +1168,7 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
shutdownWithAction(
|
shutdownWithAction(
|
||||||
() => Promise.all(actions.map((action) => action())),
|
() => PromiseAll(ArrayPrototypeMap(actions, (action) => action())),
|
||||||
true,
|
true,
|
||||||
error,
|
error,
|
||||||
);
|
);
|
||||||
|
@ -1166,6 +1178,7 @@
|
||||||
abortAlgorithm();
|
abortAlgorithm();
|
||||||
return promise.promise;
|
return promise.promise;
|
||||||
}
|
}
|
||||||
|
// TODO(lucacasonato): use the internal API to listen for abort.
|
||||||
signal.addEventListener("abort", abortAlgorithm);
|
signal.addEventListener("abort", abortAlgorithm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1370,6 +1383,7 @@
|
||||||
readableStreamReaderGenericRelease(reader);
|
readableStreamReaderGenericRelease(reader);
|
||||||
|
|
||||||
if (signal !== undefined) {
|
if (signal !== undefined) {
|
||||||
|
// TODO(lucacasonato): use the internal API to remove the listener.
|
||||||
signal.removeEventListener("abort", abortAlgorithm);
|
signal.removeEventListener("abort", abortAlgorithm);
|
||||||
}
|
}
|
||||||
if (isError) {
|
if (isError) {
|
||||||
|
@ -1478,6 +1492,8 @@
|
||||||
const value1 = value;
|
const value1 = value;
|
||||||
const value2 = value;
|
const value2 = value;
|
||||||
|
|
||||||
|
// TODO(lucacasonato): respect clonedForBranch2.
|
||||||
|
|
||||||
if (canceled1 === false) {
|
if (canceled1 === false) {
|
||||||
readableStreamDefaultControllerEnqueue(
|
readableStreamDefaultControllerEnqueue(
|
||||||
/** @type {ReadableStreamDefaultController<any>} */ (branch1[
|
/** @type {ReadableStreamDefaultController<any>} */ (branch1[
|
||||||
|
@ -1578,7 +1594,9 @@
|
||||||
]),
|
]),
|
||||||
r,
|
r,
|
||||||
);
|
);
|
||||||
cancelPromise.resolve(undefined);
|
if (canceled1 === false || canceled2 === false) {
|
||||||
|
cancelPromise.resolve(undefined);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return [branch1, branch2];
|
return [branch1, branch2];
|
||||||
|
@ -1604,7 +1622,7 @@
|
||||||
) {
|
) {
|
||||||
assert(stream[_controller] === undefined);
|
assert(stream[_controller] === undefined);
|
||||||
if (autoAllocateChunkSize !== undefined) {
|
if (autoAllocateChunkSize !== undefined) {
|
||||||
assert(Number.isInteger(autoAllocateChunkSize));
|
assert(NumberIsInteger(autoAllocateChunkSize));
|
||||||
assert(autoAllocateChunkSize >= 0);
|
assert(autoAllocateChunkSize >= 0);
|
||||||
}
|
}
|
||||||
controller[_stream] = stream;
|
controller[_stream] = stream;
|
||||||
|
@ -1621,7 +1639,8 @@
|
||||||
const startResult = startAlgorithm();
|
const startResult = startAlgorithm();
|
||||||
const startPromise = resolvePromiseWith(startResult);
|
const startPromise = resolvePromiseWith(startResult);
|
||||||
setPromiseIsHandledToTrue(
|
setPromiseIsHandledToTrue(
|
||||||
startPromise.then(
|
PromisePrototypeThen(
|
||||||
|
startPromise,
|
||||||
() => {
|
() => {
|
||||||
controller[_started] = true;
|
controller[_started] = true;
|
||||||
assert(controller[_pulling] === false);
|
assert(controller[_pulling] === false);
|
||||||
|
@ -1877,7 +1896,7 @@
|
||||||
try {
|
try {
|
||||||
transformStreamDefaultControllerEnqueue(controller, chunk);
|
transformStreamDefaultControllerEnqueue(controller, chunk);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return Promise.reject(e);
|
return PromiseReject(e);
|
||||||
}
|
}
|
||||||
return resolvePromiseWith(undefined);
|
return resolvePromiseWith(undefined);
|
||||||
};
|
};
|
||||||
|
@ -2333,7 +2352,7 @@
|
||||||
assert(stream[_state] === "writable");
|
assert(stream[_state] === "writable");
|
||||||
/** @type {Deferred<void>} */
|
/** @type {Deferred<void>} */
|
||||||
const deferred = new Deferred();
|
const deferred = new Deferred();
|
||||||
stream[_writeRequests].push(deferred);
|
ArrayPrototypePush(stream[_writeRequests], deferred);
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2344,7 +2363,7 @@
|
||||||
function writableStreamClose(stream) {
|
function writableStreamClose(stream) {
|
||||||
const state = stream[_state];
|
const state = stream[_state];
|
||||||
if (state === "closed" || state === "errored") {
|
if (state === "closed" || state === "errored") {
|
||||||
return Promise.reject(
|
return PromiseReject(
|
||||||
new TypeError("Writable stream is closed or errored."),
|
new TypeError("Writable stream is closed or errored."),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -2599,7 +2618,7 @@
|
||||||
return resolvePromiseWith(undefined);
|
return resolvePromiseWith(undefined);
|
||||||
}
|
}
|
||||||
if (state === "errored") {
|
if (state === "errored") {
|
||||||
return Promise.reject(stream[_storedError]);
|
return PromiseReject(stream[_storedError]);
|
||||||
}
|
}
|
||||||
assert(state === "writable" || state === "erroring");
|
assert(state === "writable" || state === "erroring");
|
||||||
return writableStreamDefaultWriterClose(writer);
|
return writableStreamDefaultWriterClose(writer);
|
||||||
|
@ -2690,21 +2709,21 @@
|
||||||
chunk,
|
chunk,
|
||||||
);
|
);
|
||||||
if (stream !== writer[_stream]) {
|
if (stream !== writer[_stream]) {
|
||||||
return Promise.reject(new TypeError("Writer's stream is unexpected."));
|
return PromiseReject(new TypeError("Writer's stream is unexpected."));
|
||||||
}
|
}
|
||||||
const state = stream[_state];
|
const state = stream[_state];
|
||||||
if (state === "errored") {
|
if (state === "errored") {
|
||||||
return Promise.reject(stream[_storedError]);
|
return PromiseReject(stream[_storedError]);
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
writableStreamCloseQueuedOrInFlight(stream) === true || state === "closed"
|
writableStreamCloseQueuedOrInFlight(stream) === true || state === "closed"
|
||||||
) {
|
) {
|
||||||
return Promise.reject(
|
return PromiseReject(
|
||||||
new TypeError("The stream is closing or is closed."),
|
new TypeError("The stream is closing or is closed."),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (state === "erroring") {
|
if (state === "erroring") {
|
||||||
return Promise.reject(stream[_storedError]);
|
return PromiseReject(stream[_storedError]);
|
||||||
}
|
}
|
||||||
assert(state === "writable");
|
assert(state === "writable");
|
||||||
const promise = writableStreamAddWriteRequest(stream);
|
const promise = writableStreamAddWriteRequest(stream);
|
||||||
|
@ -2899,8 +2918,8 @@
|
||||||
* @returns {IteratorResult<T>}
|
* @returns {IteratorResult<T>}
|
||||||
*/
|
*/
|
||||||
function createIteratorResult(value, done) {
|
function createIteratorResult(value, done) {
|
||||||
const result = Object.create(null);
|
const result = ObjectCreate(null);
|
||||||
Object.defineProperties(result, {
|
ObjectDefineProperties(result, {
|
||||||
value: { value, writable: true, enumerable: true, configurable: true },
|
value: { value, writable: true, enumerable: true, configurable: true },
|
||||||
done: {
|
done: {
|
||||||
value: done,
|
value: done,
|
||||||
|
@ -2913,18 +2932,18 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {AsyncIterator<unknown, unknown>} */
|
/** @type {AsyncIterator<unknown, unknown>} */
|
||||||
const asyncIteratorPrototype = Object.getPrototypeOf(
|
const asyncIteratorPrototype = ObjectGetPrototypeOf(
|
||||||
Object.getPrototypeOf(async function* () {}).prototype,
|
ObjectGetPrototypeOf(async function* () {}).prototype,
|
||||||
);
|
);
|
||||||
|
|
||||||
/** @type {AsyncIterator<unknown>} */
|
/** @type {AsyncIterator<unknown>} */
|
||||||
const readableStreamAsyncIteratorPrototype = Object.setPrototypeOf({
|
const readableStreamAsyncIteratorPrototype = ObjectSetPrototypeOf({
|
||||||
/** @returns {Promise<IteratorResult<unknown>>} */
|
/** @returns {Promise<IteratorResult<unknown>>} */
|
||||||
next() {
|
next() {
|
||||||
/** @type {ReadableStreamDefaultReader} */
|
/** @type {ReadableStreamDefaultReader} */
|
||||||
const reader = this[_reader];
|
const reader = this[_reader];
|
||||||
if (reader[_stream] === undefined) {
|
if (reader[_stream] === undefined) {
|
||||||
return Promise.reject(
|
return PromiseReject(
|
||||||
new TypeError(
|
new TypeError(
|
||||||
"Cannot get the next iteration result once the reader has been released.",
|
"Cannot get the next iteration result once the reader has been released.",
|
||||||
),
|
),
|
||||||
|
@ -2995,7 +3014,7 @@
|
||||||
get size() {
|
get size() {
|
||||||
webidl.assertBranded(this, ByteLengthQueuingStrategy);
|
webidl.assertBranded(this, ByteLengthQueuingStrategy);
|
||||||
initializeByteLengthSizeFunction(this[_globalObject]);
|
initializeByteLengthSizeFunction(this[_globalObject]);
|
||||||
return byteSizeFunctionWeakMap.get(this[_globalObject]);
|
return WeakMapPrototypeGet(byteSizeFunctionWeakMap, this[_globalObject]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Symbol.for("Deno.customInspect")](inspect) {
|
[Symbol.for("Deno.customInspect")](inspect) {
|
||||||
|
@ -3015,11 +3034,11 @@
|
||||||
const byteSizeFunctionWeakMap = new WeakMap();
|
const byteSizeFunctionWeakMap = new WeakMap();
|
||||||
|
|
||||||
function initializeByteLengthSizeFunction(globalObject) {
|
function initializeByteLengthSizeFunction(globalObject) {
|
||||||
if (byteSizeFunctionWeakMap.has(globalObject)) {
|
if (WeakMapPrototypeHas(byteSizeFunctionWeakMap, globalObject)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const size = (chunk) => chunk.byteLength;
|
const size = (chunk) => chunk.byteLength;
|
||||||
byteSizeFunctionWeakMap.set(globalObject, size);
|
WeakMapPrototypeSet(byteSizeFunctionWeakMap, globalObject, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
class CountQueuingStrategy {
|
class CountQueuingStrategy {
|
||||||
|
@ -3046,7 +3065,7 @@
|
||||||
get size() {
|
get size() {
|
||||||
webidl.assertBranded(this, CountQueuingStrategy);
|
webidl.assertBranded(this, CountQueuingStrategy);
|
||||||
initializeCountSizeFunction(this[_globalObject]);
|
initializeCountSizeFunction(this[_globalObject]);
|
||||||
return countSizeFunctionWeakMap.get(this[_globalObject]);
|
return WeakMapPrototypeGet(countSizeFunctionWeakMap, this[_globalObject]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Symbol.for("Deno.customInspect")](inspect) {
|
[Symbol.for("Deno.customInspect")](inspect) {
|
||||||
|
@ -3067,11 +3086,11 @@
|
||||||
|
|
||||||
/** @param {typeof globalThis} globalObject */
|
/** @param {typeof globalThis} globalObject */
|
||||||
function initializeCountSizeFunction(globalObject) {
|
function initializeCountSizeFunction(globalObject) {
|
||||||
if (countSizeFunctionWeakMap.has(globalObject)) {
|
if (WeakMapPrototypeHas(countSizeFunctionWeakMap, globalObject)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const size = () => 1;
|
const size = () => 1;
|
||||||
countSizeFunctionWeakMap.set(globalObject, size);
|
WeakMapPrototypeSet(countSizeFunctionWeakMap, globalObject, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @template R */
|
/** @template R */
|
||||||
|
@ -3159,10 +3178,10 @@
|
||||||
reason = webidl.converters.any(reason);
|
reason = webidl.converters.any(reason);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return Promise.reject(err);
|
return PromiseReject(err);
|
||||||
}
|
}
|
||||||
if (isReadableStreamLocked(this)) {
|
if (isReadableStreamLocked(this)) {
|
||||||
return Promise.reject(
|
return PromiseReject(
|
||||||
new TypeError("Cannot cancel a locked ReadableStream."),
|
new TypeError("Cannot cancel a locked ReadableStream."),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3175,7 +3194,7 @@
|
||||||
* @returns {AsyncIterableIterator<R>}
|
* @returns {AsyncIterableIterator<R>}
|
||||||
*/
|
*/
|
||||||
getIterator(options = {}) {
|
getIterator(options = {}) {
|
||||||
return this[Symbol.asyncIterator](options);
|
return this[SymbolAsyncIterator](options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3254,16 +3273,16 @@
|
||||||
context: "Argument 2",
|
context: "Argument 2",
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return Promise.reject(err);
|
return PromiseReject(err);
|
||||||
}
|
}
|
||||||
const { preventClose, preventAbort, preventCancel, signal } = options;
|
const { preventClose, preventAbort, preventCancel, signal } = options;
|
||||||
if (isReadableStreamLocked(this)) {
|
if (isReadableStreamLocked(this)) {
|
||||||
return Promise.reject(
|
return PromiseReject(
|
||||||
new TypeError("ReadableStream is already locked."),
|
new TypeError("ReadableStream is already locked."),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (isWritableStreamLocked(destination)) {
|
if (isWritableStreamLocked(destination)) {
|
||||||
return Promise.reject(
|
return PromiseReject(
|
||||||
new TypeError("destination WritableStream is already locked."),
|
new TypeError("destination WritableStream is already locked."),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3296,7 +3315,7 @@
|
||||||
context: "Argument 1",
|
context: "Argument 1",
|
||||||
});
|
});
|
||||||
/** @type {AsyncIterableIterator<R>} */
|
/** @type {AsyncIterableIterator<R>} */
|
||||||
const iterator = Object.create(readableStreamAsyncIteratorPrototype);
|
const iterator = ObjectCreate(readableStreamAsyncIteratorPrototype);
|
||||||
const reader = acquireReadableStreamDefaultReader(this);
|
const reader = acquireReadableStreamDefaultReader(this);
|
||||||
iterator[_reader] = reader;
|
iterator[_reader] = reader;
|
||||||
iterator[_preventCancel] = options.preventCancel;
|
iterator[_preventCancel] = options.preventCancel;
|
||||||
|
@ -3313,9 +3332,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(lucacasonato): should be moved to webidl crate
|
// TODO(lucacasonato): should be moved to webidl crate
|
||||||
ReadableStream.prototype[Symbol.asyncIterator] =
|
ReadableStream.prototype[SymbolAsyncIterator] =
|
||||||
ReadableStream.prototype.values;
|
ReadableStream.prototype.values;
|
||||||
Object.defineProperty(ReadableStream.prototype, Symbol.asyncIterator, {
|
ObjectDefineProperty(ReadableStream.prototype, SymbolAsyncIterator, {
|
||||||
writable: true,
|
writable: true,
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
configurable: true,
|
configurable: true,
|
||||||
|
@ -3353,10 +3372,10 @@
|
||||||
try {
|
try {
|
||||||
webidl.assertBranded(this, ReadableStreamDefaultReader);
|
webidl.assertBranded(this, ReadableStreamDefaultReader);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return Promise.reject(err);
|
return PromiseReject(err);
|
||||||
}
|
}
|
||||||
if (this[_stream] === undefined) {
|
if (this[_stream] === undefined) {
|
||||||
return Promise.reject(
|
return PromiseReject(
|
||||||
new TypeError("Reader has no associated stream."),
|
new TypeError("Reader has no associated stream."),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3396,7 +3415,7 @@
|
||||||
try {
|
try {
|
||||||
webidl.assertBranded(this, ReadableStreamDefaultReader);
|
webidl.assertBranded(this, ReadableStreamDefaultReader);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return Promise.reject(err);
|
return PromiseReject(err);
|
||||||
}
|
}
|
||||||
return this[_closedPromise].promise;
|
return this[_closedPromise].promise;
|
||||||
}
|
}
|
||||||
|
@ -3412,11 +3431,11 @@
|
||||||
reason = webidl.converters.any(reason);
|
reason = webidl.converters.any(reason);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return Promise.reject(err);
|
return PromiseReject(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this[_stream] === undefined) {
|
if (this[_stream] === undefined) {
|
||||||
return Promise.reject(
|
return PromiseReject(
|
||||||
new TypeError("Reader has no associated stream."),
|
new TypeError("Reader has no associated stream."),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3573,7 +3592,7 @@
|
||||||
assert(readableStreamHasDefaultReader(stream));
|
assert(readableStreamHasDefaultReader(stream));
|
||||||
if (this[_queueTotalSize] > 0) {
|
if (this[_queueTotalSize] > 0) {
|
||||||
assert(readableStreamGetNumReadRequests(stream) === 0);
|
assert(readableStreamGetNumReadRequests(stream) === 0);
|
||||||
const entry = this[_queue].shift();
|
const entry = ArrayPrototypeShift(this[_queue]);
|
||||||
this[_queueTotalSize] -= entry.byteLength;
|
this[_queueTotalSize] -= entry.byteLength;
|
||||||
readableByteStreamControllerHandleQueueDrain(this);
|
readableByteStreamControllerHandleQueueDrain(this);
|
||||||
const view = new Uint8Array(
|
const view = new Uint8Array(
|
||||||
|
@ -3978,13 +3997,13 @@
|
||||||
try {
|
try {
|
||||||
webidl.assertBranded(this, WritableStream);
|
webidl.assertBranded(this, WritableStream);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return Promise.reject(err);
|
return PromiseReject(err);
|
||||||
}
|
}
|
||||||
if (reason !== undefined) {
|
if (reason !== undefined) {
|
||||||
reason = webidl.converters.any(reason);
|
reason = webidl.converters.any(reason);
|
||||||
}
|
}
|
||||||
if (isWritableStreamLocked(this)) {
|
if (isWritableStreamLocked(this)) {
|
||||||
return Promise.reject(
|
return PromiseReject(
|
||||||
new TypeError(
|
new TypeError(
|
||||||
"The writable stream is locked, therefore cannot be aborted.",
|
"The writable stream is locked, therefore cannot be aborted.",
|
||||||
),
|
),
|
||||||
|
@ -3998,17 +4017,17 @@
|
||||||
try {
|
try {
|
||||||
webidl.assertBranded(this, WritableStream);
|
webidl.assertBranded(this, WritableStream);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return Promise.reject(err);
|
return PromiseReject(err);
|
||||||
}
|
}
|
||||||
if (isWritableStreamLocked(this)) {
|
if (isWritableStreamLocked(this)) {
|
||||||
return Promise.reject(
|
return PromiseReject(
|
||||||
new TypeError(
|
new TypeError(
|
||||||
"The writable stream is locked, therefore cannot be closed.",
|
"The writable stream is locked, therefore cannot be closed.",
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (writableStreamCloseQueuedOrInFlight(this) === true) {
|
if (writableStreamCloseQueuedOrInFlight(this) === true) {
|
||||||
return Promise.reject(
|
return PromiseReject(
|
||||||
new TypeError("The writable stream is already closing."),
|
new TypeError("The writable stream is already closing."),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -4062,7 +4081,7 @@
|
||||||
try {
|
try {
|
||||||
webidl.assertBranded(this, WritableStreamDefaultWriter);
|
webidl.assertBranded(this, WritableStreamDefaultWriter);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return Promise.reject(err);
|
return PromiseReject(err);
|
||||||
}
|
}
|
||||||
return this[_closedPromise].promise;
|
return this[_closedPromise].promise;
|
||||||
}
|
}
|
||||||
|
@ -4083,7 +4102,7 @@
|
||||||
try {
|
try {
|
||||||
webidl.assertBranded(this, WritableStreamDefaultWriter);
|
webidl.assertBranded(this, WritableStreamDefaultWriter);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return Promise.reject(err);
|
return PromiseReject(err);
|
||||||
}
|
}
|
||||||
return this[_readyPromise].promise;
|
return this[_readyPromise].promise;
|
||||||
}
|
}
|
||||||
|
@ -4096,13 +4115,13 @@
|
||||||
try {
|
try {
|
||||||
webidl.assertBranded(this, WritableStreamDefaultWriter);
|
webidl.assertBranded(this, WritableStreamDefaultWriter);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return Promise.reject(err);
|
return PromiseReject(err);
|
||||||
}
|
}
|
||||||
if (reason !== undefined) {
|
if (reason !== undefined) {
|
||||||
reason = webidl.converters.any(reason);
|
reason = webidl.converters.any(reason);
|
||||||
}
|
}
|
||||||
if (this[_stream] === undefined) {
|
if (this[_stream] === undefined) {
|
||||||
return Promise.reject(
|
return PromiseReject(
|
||||||
new TypeError("A writable stream is not associated with the writer."),
|
new TypeError("A writable stream is not associated with the writer."),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -4114,16 +4133,16 @@
|
||||||
try {
|
try {
|
||||||
webidl.assertBranded(this, WritableStreamDefaultWriter);
|
webidl.assertBranded(this, WritableStreamDefaultWriter);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return Promise.reject(err);
|
return PromiseReject(err);
|
||||||
}
|
}
|
||||||
const stream = this[_stream];
|
const stream = this[_stream];
|
||||||
if (stream === undefined) {
|
if (stream === undefined) {
|
||||||
return Promise.reject(
|
return PromiseReject(
|
||||||
new TypeError("A writable stream is not associated with the writer."),
|
new TypeError("A writable stream is not associated with the writer."),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (writableStreamCloseQueuedOrInFlight(stream) === true) {
|
if (writableStreamCloseQueuedOrInFlight(stream) === true) {
|
||||||
return Promise.reject(
|
return PromiseReject(
|
||||||
new TypeError("The associated stream is already closing."),
|
new TypeError("The associated stream is already closing."),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -4152,10 +4171,10 @@
|
||||||
chunk = webidl.converters.any(chunk);
|
chunk = webidl.converters.any(chunk);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return Promise.reject(err);
|
return PromiseReject(err);
|
||||||
}
|
}
|
||||||
if (this[_stream] === undefined) {
|
if (this[_stream] === undefined) {
|
||||||
return Promise.reject(
|
return PromiseReject(
|
||||||
new TypeError("A writable stream is not associate with the writer."),
|
new TypeError("A writable stream is not associate with the writer."),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue