 hasOwnProperty = v8.uncurryThis(global.Object.hasOwnProperty);
const getPrototypeOf = global.Object.getPrototypeOf.bind(global.Object);
const getOwnPropertyDescriptor =
global.Object.getOwnPropertyDescriptor.bind(global.Object);
const thenPromise = v8.uncurryThis(Promise.prototype.then);
const JSON_parse = global.JSON.parse.bind(global.JSON);
const JSON_stringify = global.JSON.stringify.bind(global.JSON);
function hasOwnPropertyNoThrow(x, property) {
return Boolean(x) && hasOwnProperty(x, property);
}
function streamInternalError() {
throw new RangeError('Stream API Internal Error');
}
function createPromise() {
const p = v8.createPromise();
p[_isSettled] = false;
return p;
}
function rejectPromise(p, reason) {
if (!v8.isPromise(p)) {
streamInternalError();
}
if (p[_isSettled] !== false) {
return;
}
p[_isSettled] = true;
v8.rejectPromise(p, reason);
}
function createRejectedPromise(reason) {
const p = createPromise();
rejectPromise(p, reason);
return p;
}
function resolvePromise(p, value) {
if (!v8.isPromise(p)) {
streamInternalError();
}
if (p[_isSettled] !== false) {
return;
}
p[_isSettled] = true;
v8.resolvePromise(p, value);
}
function createResolvedPromise(value) {
if (v8.isPromise(value)) {
return value;
}
const p = createPromise();
resolvePromise(p, value);
return p;
}
function markPromiseAsHandled(p) {
if (!v8.isPromise(p)) {
streamInternalError();
}
v8.markPromiseAsHandled(p);
}
function promiseState(p) {
if (!v8.isPromise(p)) {
streamInternalError();
}
return v8.promiseState(p);
}
function DequeueValue(container) {
const pair = container[_queue].shift();
container[_queueTotalSize] -= pair.size;
if (container[_queueTotalSize] < 0) {
container[_queueTotalSize] = 0;
}
return pair.value;
}
function EnqueueValueWithSize(container, value, size) {
size = Number(size);
if (!IsFiniteNonNegativeNumber(size)) {
throw new RangeError(binding.streamErrors.invalidSize);
}
container[_queue].push({value, size});
container[_queueTotalSize] += size;
}
function PeekQueueValue(container) {
const pair = container[_queue].peek();
return pair.value;
}
function ResetQueue(container) {
container[_queue] = new binding.SimpleQueue();
container[_queueTotalSize] = 0;
}
function IsFiniteNonNegativeNumber(v) {
return Number_isFinite(v) && v >= 0;
}
function ValidateAndNormalizeHighWaterMark(highWaterMark) {
highWaterMark = Number(highWaterMark);
if (Number_isNaN(highWaterMark)) {
throw new RangeError(binding.streamErrors.invalidHWM);
}
if (highWaterMark < 0) {
throw new RangeError(binding.streamErrors.invalidHWM);
}
return highWaterMark;
}
function MakeSizeAlgorithmFromSizeFunction(size) {
if (size === undefined) {
return () => 1;
}
if (typeof size !== 'function') {
throw new TypeError(binding.streamErrors.sizeNotAFunction);
}
return size;
}
const callFunction = v8.uncurryThis(global.Function.prototype.call);
const errTmplMustBeFunctionOrUndefined = name =>
`${name} must be a function or undefined`;
const Function_bind = v8.uncurryThis(global.Function.prototype.bind);
function resolveMethod(O, P, nameForError) {
const method = O[P];
if (typeof method !== 'function' && typeof method !== 'undefined') {
throw new TypeError(errTmplMustBeFunctionOrUndefined(nameForError));
}
return method;
}
function CreateAlgorithmFromUnderlyingMethod(
underlyingObject, methodName, algoArgCount, methodNameForError) {
const method =
resolveMethod(underlyingObject, methodName, methodNameForError);
if (method === undefined) {
return () => createResolvedPromise();
}
if (algoArgCount === 0) {
return Function_bind(PromiseCall0, undefined, method, underlyingObject);
}
return Function_bind(PromiseCall1, undefined, method, underlyingObject);
}
function CreateAlgorithmFromUnderlyingMethodPassingController(
underlyingObject, methodName, algoArgCount, controller,
methodNameForError) {
const method =
resolveMethod(underlyingObject, methodName, methodNameForError);
if (method === undefined) {
return () => createResolvedPromise();
}
if (algoArgCount === 0) {
return Function_bind(
PromiseCall1, undefined, method, underlyingObject, controller);
}
return arg => PromiseCall2(method, underlyingObject, arg, controller);
}
function CallOrNoop1(O, P, arg0, nameForError) {
const method = resolveMethod(O, P, nameForError);
if (method === undefined) {
return undefined;
}
return callFunction(method, O, arg0);
}
function PromiseCall0(F, V) {
try {
return createResolvedPromise(callFunction(F, V));
} catch (e) {
return createRejectedPromise(e);
}
}
function PromiseCall1(F, V, arg0) {
try {
return createResolvedPromise(callFunction(F, V, arg0));
} catch (e) {
return createRejectedPromise(e);
}
}
function PromiseCall2(F, V, arg0, arg1) {
try {
return createResolvedPromise(callFunction(F, V, arg0, arg1));
} catch (e) {
return createRejectedPromise(e);
}
}
const kPull = 1;
const kCancel = 2;
const kChunk = 3;
const kClose = 4;
const kAbort = 5;
const kError = 6;
function isATypeError(object) {
return object !== null && getPrototypeOf(object) === TypeError_prototype;
}
function isADOMException(object) {
try {
callFunction(binding.DOMException_name_get, object);
return true;
} catch (e) {
return false;
}
}
function packReason(reason) {
switch (typeof reason) {
case 'string':
case 'number':
case 'boolean':
return {encoder: 'json', string: JSON_stringify(reason)};
case 'object':
try {
if (isATypeError(reason)) {
let message;
const descriptor = getOwnPropertyDescriptor(reason, 'message');
if (descriptor) {
message = descriptor.value;
if (typeof message !== 'string') {
message = undefined;
}
}
return {encoder: 'typeerror', string: message};
}
if (isADOMException(reason)) {
const message =
callFunction(binding.DOMException_message_get, reason);
const name = callFunction(binding.DOMException_name_get, reason);
return {
encoder: 'domexception',
string: JSON_stringify({message, name})
};
}
return {encoder: 'json', string: JSON_stringify(reason)};
} catch (e) {
return {encoder: 'typeerror', string: 'Cannot transfer message'};
}
default:
return {encoder: 'undefined', string: undefined};
}
}
function unpackReason(packedReason) {
const {encoder, string} = packedReason;
switch (encoder) {
case 'json':
return JSON_parse(string);
case 'typeerror':
return new TypeError(string);
case 'domexception':
const {message, name} = JSON_parse(string);
return new binding.DOMException(message, name);
case 'undefined':
return undefined;
}
}
function CreateCrossRealmTransformWritable(port) {
let backpressurePromise = createPromise();
callFunction(binding.EventTarget_addEventListener, port, 'message', evt => {
const {type, value} = callFunction(binding.MessageEvent_data_get, evt);
switch (type) {
case kPull:
resolvePromise(backpressurePromise);
backpressurePromise = undefined;
break;
case kCancel:
case kError:
binding.WritableStreamDefaultControllerErrorIfNeeded(
controller, unpackReason(value));
if (backpressurePromise !== undefined) {
resolvePromise(backpressurePromise);
backpressurePromise = undefined;
}
break;
}
});
callFunction(
binding.EventTarget_addEventListener, port, 'messageerror', () => {
const error = new binding.DOMException('chunk could not be cloned',
'DataCloneError');
callFunction(binding.MessagePort_postMessage, port,
{type: kError, value: packReason(error)});
callFunction(binding.MessagePort_close, port);
binding.WritableStreamDefaultControllerErrorIfNeeded(controller,
error);
});
callFunction(binding.MessagePort_start, port);
function doWrite(chunk) {
backpressurePromise = createPromise();
try {
callFunction(
binding.MessagePort_postMessage, port,
{type: kChunk, value: chunk});
} catch (e) {
callFunction(
binding.MessagePort_postMessage, port,
{type: kError, value: packReason(e)});
callFunction(binding.MessagePort_close, port);
throw e;
}
}
const stream = binding.CreateWritableStream(
() => undefined,
chunk => {
if (!backpressurePromise) {
return PromiseCall1(doWrite, null, chunk);
}
return thenPromise(backpressurePromise, () => doWrite(chunk));
},
() => {
callFunction(
binding.MessagePort_postMessage, port,
{type: kClose, value: undefined});
callFunction(binding.MessagePort_close, port);
return createResolvedPromise();
},
reason => {
callFunction(
binding.MessagePort_postMessage, port,
{type: kAbort, value: packReason(reason)});
callFunction(binding.MessagePort_close, port);
return createResolvedPromise();
});
const controller = binding.getWritableStreamController(stream);
return stream;
}
function CreateCrossRealmTransformReadable(port) {
let backpressurePromise = createPromise();
let finished = false;
callFunction(binding.EventTarget_addEventListener, port, 'message', evt => {
const {type, value} = callFunction(binding.MessageEvent_data_get, evt);
if (finished) {
return;
}
switch (type) {
case kChunk:
binding.ReadableStreamDefaultControllerEnqueue(controller, value);
resolvePromise(backpressurePromise);
backpressurePromise = createPromise();
break;
case kClose:
finished = true;
binding.ReadableStreamDefaultControllerClose(controller);
callFunction(binding.MessagePort_close, port);
break;
case kAbort:
case kError:
finished = true;
binding.ReadableStreamDefaultControllerError(
controller, unpackReason(value));
callFunction(binding.MessagePort_close, port);
break;
}
});
callFunction(
binding.EventTarget_addEventListener, port, 'messageerror', () => {
const error = new binding.DOMException('chunk could not be cloned',
'DataCloneError');
callFunction(binding.MessagePort_postMessage, port,
{type: kError, value: packReason(error)});
callFunction(binding.MessagePort_close, port);
binding.ReadableStreamDefaultControllerError(controller, error);
});
callFunction(binding.MessagePort_start, port);
const stream = binding.CreateReadableStream(
() => undefined,
() => {
callFunction(
binding.MessagePort_postMessage, port,
{type: kPull, value: undefined});
return backpressurePromise;
},
reason => {
finished = true;
callFunction(
binding.MessagePort_postMessage, port,
{type: kCancel, value: packReason(reason)});
callFunction(binding.MessagePort_close, port);
return createResolvedPromise();
},
0);
const controller = binding.getReadableStreamController(stream);
return stream;
}
binding.streamOperations = {
_queue,
_queueTotalSize,
createPromise,
createRejectedPromise,
createResolvedPromise,
hasOwnPropertyNoThrow,
rejectPromise,
resolvePromise,
markPromiseAsHandled,
promiseState,
CreateAlgorithmFromUnderlyingMethod,
CreateAlgorithmFromUnderlyingMethodPassingController,
CreateCrossRealmTransformWritable,
CreateCrossRealmTransformReadable,
DequeueValue,
EnqueueValueWithSize,
PeekQueueValue,
ResetQueue,
ValidateAndNormalizeHighWaterMark,
MakeSizeAlgorithmFromSizeFunction,
CallOrNoop1,
PromiseCall2
};
});
4CommonStrings	
(function(global, binding, v8) {
'use strict';
binding.streamErrors = {
cannotTransferLockedStream: 'Cannot transfer a locked stream',
cannotTransferContext: 'Cannot transfer from this context',
illegalInvocation: 'Illegal invocation',
illegalConstructor: 'Illegal constructor',
invalidType: 'Invalid type is specified',
invalidSize: 'The return value of a queuing strategy\'s size function ' +
'must be a finite, non-NaN, non-negative number',
sizeNotAFunction: 'A queuing strategy\'s size property must be a function',
invalidHWM:
'A queueing strategy\'s highWaterMark property must be a nonnegative, ' +
'non-NaN number',
};
});
,SimpleQueue