function initializeWritableStream(underlyingSink, strategy)
{
"use strict";
if (underlyingSink === @undefined)
underlyingSink = { };
if (strategy === @undefined)
strategy = { };
if (!@isObject(underlyingSink))
@throwTypeError("WritableStream constructor takes an object as first argument");
if ("type" in underlyingSink)
@throwRangeError("Invalid type is specified");
const sizeAlgorithm = @extractSizeAlgorithm(strategy);
const highWaterMark = @extractHighWaterMark(strategy, 1);
const underlyingSinkDict = { };
if ("start" in underlyingSink) {
underlyingSinkDict["start"] = underlyingSink["start"];
if (typeof underlyingSinkDict["start"] !== "function")
@throwTypeError("underlyingSink.start should be a function");
}
if ("write" in underlyingSink) {
underlyingSinkDict["write"] = underlyingSink["write"];
if (typeof underlyingSinkDict["write"] !== "function")
@throwTypeError("underlyingSink.write should be a function");
}
if ("close" in underlyingSink) {
underlyingSinkDict["close"] = underlyingSink["close"];
if (typeof underlyingSinkDict["close"] !== "function")
@throwTypeError("underlyingSink.close should be a function");
}
if ("abort" in underlyingSink) {
underlyingSinkDict["abort"] = underlyingSink["abort"];
if (typeof underlyingSinkDict["abort"] !== "function")
@throwTypeError("underlyingSink.abort should be a function");
}
@putByIdDirectPrivate(this, "state", "writable");
@putByIdDirectPrivate(this, "storedError", @undefined);
@putByIdDirectPrivate(this, "writer", @undefined);
@putByIdDirectPrivate(this, "controller", @undefined);
@putByIdDirectPrivate(this, "inFlightWriteRequest", @undefined);
@putByIdDirectPrivate(this, "closeRequest", @undefined);
@putByIdDirectPrivate(this, "inFlightCloseRequest", @undefined);
@putByIdDirectPrivate(this, "pendingAbortRequest", @undefined);
@putByIdDirectPrivate(this, "writeRequests", []);
@putByIdDirectPrivate(this, "backpressure", false);
@putByIdDirectPrivate(this, "underlyingSink", underlyingSink);
@setUpWritableStreamDefaultControllerFromUnderlyingSink(this, underlyingSink, underlyingSinkDict, highWaterMark, sizeAlgorithm)
return this;
}
@getter
function locked()
{
"use strict";
if (!@isWritableStream(this))
throw @makeThisTypeError("WritableStream", "locked");
return @isWritableStreamLocked(this);
}
function abort(reason)
{
"use strict";
if (!@isWritableStream(this))
return @Promise.@reject(@makeThisTypeError("WritableStream", "abort"));
if (@isWritableStreamLocked(this))
return @Promise.@reject(@makeTypeError("WritableStream.abort method can only be used on non locked WritableStream"));
return @writableStreamAbort(this, reason);
}
function close()
{
"use strict";
if (!@isWritableStream(this))
return @Promise.@reject(@makeThisTypeError("WritableStream", "close"));
if (@isWritableStreamLocked(this))
return @Promise.@reject(@makeTypeError("WritableStream.close method can only be used on non locked WritableStream"));
if (@writableStreamCloseQueuedOrInFlight(this))
return @Promise.@reject(@makeTypeError("WritableStream.close method can only be used on a being close WritableStream"));
return @writableStreamClose(this);
}
function getWriter()
{
"use strict";
if (!@isWritableStream(this))
throw @makeThisTypeError("WritableStream", "getWriter");
return @acquireWritableStreamDefaultWriter(this);
}