diff --git a/ext/lib.rs b/ext/lib.rs index 5a70d1c..b7231c5 100644 --- a/ext/lib.rs +++ b/ext/lib.rs @@ -45,6 +45,7 @@ pub mod extensions { "battery/mod.js", "web/mod.js", "web/events.js", + "web/streams.js", "web/encoding.js", "console/mod.js", "console/printer.js", diff --git a/ext/web/mod.js b/ext/web/mod.js index 3907b32..52a9be6 100644 --- a/ext/web/mod.js +++ b/ext/web/mod.js @@ -1,10 +1,21 @@ import { TextDecoder, TextEncoder } from "ext:bueno/web/encoding.js"; import { CustomEvent, Event, EventTarget } from "ext:bueno/web/events.js"; +import { + ByteLengthQueuingStrategy, + CountQueuingStrategy, +} from "ext:bueno/web/streams.js"; globalThis.navigator = {}; + +// Event API globalThis.Event = Event; globalThis.CustomEvent = CustomEvent; globalThis.EventTarget = EventTarget; +// Streams API +globalThis.ByteLengthQueuingStrategy = ByteLengthQueuingStrategy; +globalThis.CountQueuingStrategy = CountQueuingStrategy; + +// Text Encoding API globalThis.TextDecoder = TextDecoder; globalThis.TextEncoder = TextEncoder; diff --git a/ext/web/streams.js b/ext/web/streams.js new file mode 100644 index 0000000..57b7dfc --- /dev/null +++ b/ext/web/streams.js @@ -0,0 +1,24 @@ +// Ported from https://github.com/whatwg/streams/tree/main/reference-implementation + +export class ByteLengthQueuingStrategy { + constructor({ highWaterMark }) { + this.highWaterMark = highWaterMark; + } + + /** + * @param {Uint8Array} chunk + */ + size(chunk) { + return chunk.byteLength; + } +} + +export class CountQueuingStrategy { + constructor({ highWaterMark }) { + this.highWaterMark = highWaterMark; + } + + get size() { + return 1; + } +}