TextDecoderStream.js [plain text]
function initializeTextDecoderStream()
{
"use strict";
const label = arguments.length >= 1 ? arguments[0] : "utf-8";
const options = arguments.length >= 2 ? arguments[1] : { };
const startAlgorithm = () => {
return @Promise.@resolve();
};
const transformAlgorithm = (chunk) => {
const decoder = @getByIdDirectPrivate(this, "textDecoderStreamDecoder");
let buffer;
try {
buffer = decoder.@decode(chunk);
} catch (e) {
return @Promise.@reject(e);
}
if (buffer) {
const transformStream = @getByIdDirectPrivate(this, "textDecoderStreamTransform");
const controller = @getByIdDirectPrivate(transformStream, "controller");
@transformStreamDefaultControllerEnqueue(controller, buffer);
}
return @Promise.@resolve();
};
const flushAlgorithm = () => {
const decoder = @getByIdDirectPrivate(this, "textDecoderStreamDecoder");
let buffer;
try {
buffer = decoder.@flush();
} catch (e) {
return @Promise.@reject(e);
}
if (buffer) {
const transformStream = @getByIdDirectPrivate(this, "textDecoderStreamTransform");
const controller = @getByIdDirectPrivate(transformStream, "controller");
@transformStreamDefaultControllerEnqueue(controller, buffer);
}
return @Promise.@resolve();
};
const transform = @createTransformStream(startAlgorithm, transformAlgorithm, flushAlgorithm);
@putByIdDirectPrivate(this, "textDecoderStreamTransform", transform);
const fatal = !!options.fatal;
const ignoreBOM = !!options.ignoreBOM;
const decoder = new @TextDecoderStreamDecoder(label, fatal, ignoreBOM);
@putByIdDirectPrivate(this, "fatal", fatal);
@putByIdDirectPrivate(this, "ignoreBOM", ignoreBOM);
@putByIdDirectPrivate(this, "encoding", decoder.@encoding());
@putByIdDirectPrivate(this, "textDecoderStreamDecoder", decoder);
return this;
}
@getter
function encoding()
{
"use strict";
if (!@getByIdDirectPrivate(this, "textDecoderStreamTransform"))
throw @makeThisTypeError("TextDecoderStream", "encoding");
return @getByIdDirectPrivate(this, "encoding");
}
@getter
function fatal()
{
"use strict";
if (!@getByIdDirectPrivate(this, "textDecoderStreamTransform"))
throw @makeThisTypeError("TextDecoderStream", "fatal");
return @getByIdDirectPrivate(this, "fatal");
}
@getter
function ignoreBOM()
{
"use strict";
if (!@getByIdDirectPrivate(this, "textDecoderStreamTransform"))
throw @makeThisTypeError("TextDecoderStream", "ignoreBOM");
return @getByIdDirectPrivate(this, "ignoreBOM");
}
@getter
function readable()
{
"use strict";
const transform = @getByIdDirectPrivate(this, "textDecoderStreamTransform");
if (!transform)
throw @makeThisTypeError("TextDecoderStream", "readable");
return @getByIdDirectPrivate(transform, "readable");
}
@getter
function writable()
{
"use strict";
const transform = @getByIdDirectPrivate(this, "textDecoderStreamTransform");
if (!transform)
throw @makeThisTypeError("TextDecoderStream", "writable");
return @getByIdDirectPrivate(transform, "writable");
}