Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions ext/web/mod.js
Original file line number Diff line number Diff line change
@@ -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;
24 changes: 24 additions & 0 deletions ext/web/streams.js
Original file line number Diff line number Diff line change
@@ -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;
}
}