Skip to content

Lightpanda: the headless browser designed for AI and automation

webapi: Blob / File conformance

Karl Seguinb70f7a325e48
diff --git a/src/browser/js/Local.zig b/src/browser/js/Local.zig
index 0d65665c2..76d8d2d36 100644
--- a/src/browser/js/Local.zig
+++ b/src/browser/js/Local.zig
@@ -819,6 +819,15 @@ fn jsValueToStruct(self: *const Local, comptime T: type, js_val: js.Value) !?T {
string.String => try js_val.toSSO(false),
string.Global => try js_val.toSSO(true),
else => {
+ comptime {
+ // Structs generated by Event.inheritOptions read inherited
+ // members first (per Web IDL); each level is validated at
+ // generation and the result carries the zero-bit marker.
+ if (!@hasField(T, dictionary_group_marker)) {
+ assertDictionaryFieldOrder(T);
+ }
+ }
+
if (!js_val.isObject()) {
return null;
}
@@ -828,10 +837,22 @@ fn jsValueToStruct(self: *const Local, comptime T: type, js_val: js.Value) !?T {
var value: T = undefined;
inline for (@typeInfo(T).@"struct".fields) |field| {
+ if (comptime std.mem.eql(u8, field.name, dictionary_group_marker)) {
+ continue;
+ }
const name = field.name;
const key = isolate.initStringHandle(name);
if (js_obj.has(key)) {
- @field(value, name) = try self.jsValueToZig(field.type, try js_obj.get(key));
+ const member = try js_obj.get(key);
+ const default_for_undefined = comptime field.defaultValue();
+ @field(value, name) = blk: {
+ if (comptime default_for_undefined) |dflt| {
+ if (member.isUndefined()) {
+ break :blk dflt;
+ }
+ }
+ break :blk try self.jsValueToZig(field.type, member);
+ };
} else if (@typeInfo(field.type) == .optional) {
@field(value, name) = null;
} else {
@@ -845,6 +866,22 @@ fn jsValueToStruct(self: *const Local, comptime T: type, js_val: js.Value) !?T {
};
}
+// Marks a struct generated by Event.inheritOptions: inherited members come first
+pub const dictionary_group_marker = "js_grouped_dictionary";
+
+// Dictionary members must be read in lexicographic order of name. Getters must
+// fire in a predictable order. Could probably comptime this to work
+// automatically, but it's a lot easier just to check it and ask for a manual fix.
+pub fn assertDictionaryFieldOrder(comptime T: type) void {
+ const fields = @typeInfo(T).@"struct".fields;
+ var i: usize = 1;
+ while (i < fields.len) : (i += 1) {
+ if (std.mem.order(u8, fields[i - 1].name, fields[i].name) == .gt) {
+ @compileError("dictionary fields must be declared in lexicographic order: " ++ @typeName(T));
+ }
+ }
+}
+
fn jsValueToTypedArray(comptime T: type, js_val: js.Value) !?[]T {
var force_u8 = false;
var array_buffer: ?*const v8.ArrayBuffer = null;
diff --git a/src/browser/js/Object.zig b/src/browser/js/Object.zig
index f0102fc3c..b5f7436bf 100644
--- a/src/browser/js/Object.zig
+++ b/src/browser/js/Object.zig
@@ -50,6 +50,14 @@ pub fn get(self: Object, key: anytype) !js.Value {
};
}
+pub fn getSymbol(self: Object, symbol: *const v8.Symbol) !js.Value {
+ const handle = v8.v8__Object__Get(self.handle, self.local.handle, @ptrCast(symbol)) orelse return error.JsException;
+ return .{
+ .handle = handle,
+ .local = self.local,
+ };
+}
+
pub fn set(self: Object, key: anytype, value: anytype, comptime opts: js.Caller.CallOpts) !bool {
const ctx = self.local.ctx;
diff --git a/src/browser/js/Value.zig b/src/browser/js/Value.zig
index 5dcac824d..1d17cebd5 100644
--- a/src/browser/js/Value.zig
+++ b/src/browser/js/Value.zig
@@ -685,6 +685,49 @@ pub fn format(self: Value, writer: *std.Io.Writer) !void {
return js_str.format(writer);
}
+// The JS iteration protocol (@@iterator)
+pub fn iterator(self: Value) !?Iterator {
+ if (!self.isObject()) {
+ return null;
+ }
+ const source = self.toObject();
+
+ const method = try source.getSymbol(v8.v8__Symbol__GetIterator(self.local.isolate.handle).?);
+ if (method.isNullOrUndefined()) {
+ return null;
+ }
+ if (!method.isFunction()) {
+ return error.TypeError;
+ }
+ const iterator_fn: js.Function = .{ .local = self.local, .handle = @ptrCast(method.handle) };
+
+ const iterator_value = try iterator_fn.callWithThisRethrow(Value, source, .{});
+ if (!iterator_value.isObject()) {
+ return error.TypeError;
+ }
+ const iterator_object = iterator_value.toObject();
+ const next_fn = (try iterator_object.getFunction("next")) orelse return error.TypeError;
+
+ return .{ .object = iterator_object, .next_fn = next_fn };
+}
+
+pub const Iterator = struct {
+ object: js.Object,
+ next_fn: js.Function,
+ pub fn next(self: *const Iterator) !?Value {
+ const step = try self.next_fn.callWithThisRethrow(Value, self.object, .{});
+ if (!step.isObject()) {
+ return error.TypeError;
+ }
+
+ const step_object = step.toObject();
+ if ((try step_object.get("done")).toBool()) {
+ return null;
+ }
+ return try step_object.get("value");
+ }
+};
+
// Copyable handle to our v8::Global wrapper so that releasing a copy resets
// the underlying v8::Global
pub const Global = struct {
diff --git a/src/browser/tests/blob.html b/src/browser/tests/blob.html
index d6faf15f8..fbfb3d901 100644
--- a/src/browser/tests/blob.html
+++ b/src/browser/tests/blob.html
@@ -191,25 +191,25 @@
testing.expectEqual("application/json", blob.type);
}
- // MIME is parsed and re-serialized: optional whitespace dropped, essence
- // and parameter names lowercased, but parameter values preserved as-is.
+ // The type is never parsed as a MIME type: it is only lowercased, so
+ // whitespace and parameters survive verbatim.
{
const blob = new Blob([], { type: "text/html; charset=UTF-8" });
- testing.expectEqual("text/html;charset=UTF-8", blob.type);
+ testing.expectEqual("text/html; charset=utf-8", blob.type);
}
- // A string that fails to parse as a MIME type yields the empty string.
+ // A string that isn't a MIME type at all is still kept.
{
const blob = new Blob([], { type: "invalid" });
- testing.expectEqual("", blob.type);
+ testing.expectEqual("invalid", blob.type);
}
{
const blob = new Blob([], { type: "/" });
- testing.expectEqual("", blob.type);
+ testing.expectEqual("/", blob.type);
}
- // Non-ASCII characters cause empty string (not HTTP token code points)
+ // Anything outside U+0020..U+007E empties the type
{
const blob = new Blob([], { type: "ý/x" });
testing.expectEqual("", blob.type);
@@ -265,8 +265,7 @@
testing.expectEqual("lasymphoniedeséclairs", sliceAllText);
testing.expectEqual(2, sliceCustom.size);
- // "custom" is not a valid MIME type (no "/"), so the type is empty.
- testing.expectEqual("", sliceCustom.type);
+ testing.expectEqual("custom", sliceCustom.type);
testing.expectEqual("ai", sliceCustomText);
testing.expectEqual(8, sliceTail.size);
diff --git a/src/browser/webapi/Blob.zig b/src/browser/webapi/Blob.zig
index 16c7ca50a..751c0d127 100644
--- a/src/browser/webapi/Blob.zig
+++ b/src/browser/webapi/Blob.zig
@@ -22,8 +22,6 @@ const lp = @import("lightpanda");
const js = @import("../js/js.zig");
const Page = @import("../Page.zig");
-const Mime = @import("../Mime.zig");
-
const Writer = std.Io.Writer;
const Execution = js.Execution;
@@ -69,17 +67,21 @@ pub fn urlBelongsToOrigin(url: []const u8, origin_: ?[]const u8) bool {
}
const InitOptions = struct {
- /// MIME type.
- type: []const u8 = "",
/// How to handle line endings (CR and LF).
/// `transparent` means do nothing, `native` expects CRLF (\r\n) on Windows.
endings: []const u8 = "transparent",
+ /// MIME type.
+ type: []const u8 = "",
};
/// Creates a new Blob from JS values with optional MIME validation.
/// This is the JS Constructor
-pub fn init(parts_: ?[]const js.Value, opts_: ?InitOptions, exec: *const Execution) !*Blob {
- const blob = try buildValue(parts_, opts_ orelse .{}, exec);
+pub fn init(parts_: ?js.Value, opts_: ?js.Value, exec: *const Execution) !*Blob {
+ const parts = if (parts_) |p| try collectParts(p, exec) else null;
+ const blob = try buildValue(parts, blk: {
+ const o = opts_ orelse break :blk .{};
+ break :blk (try o.toZig(?InitOptions)) orelse .{};
+ }, exec);
errdefer blob._arena.release();
const self = try blob._arena.create(Blob);
@@ -89,16 +91,37 @@ pub fn init(parts_: ?[]const js.Value, opts_: ?InitOptions, exec: *const Executi
return self;
}
-pub fn buildValue(parts_: ?[]const js.Value, opts: InitOptions, exec: *const Execution) !Blob {
+pub fn collectParts(value: js.Value, exec: *const Execution) !?[]const []const u8 {
+ if (value.isUndefined()) {
+ return null;
+ }
+ const it = (try value.iterator()) orelse return error.TypeError;
+
+ var parts: std.ArrayList([]const u8) = .empty;
+ while (try it.next()) |part| {
+ try parts.append(exec.call_arena, try part.toStringSmart());
+ }
+ return parts.items;
+}
+
+pub fn buildValue(parts_: ?[]const []const u8, opts: InitOptions, exec: *const Execution) !Blob {
+ const use_native_endings = blk: {
+ if (std.mem.eql(u8, opts.endings, "native")) {
+ break :blk true;
+ }
+ if (std.mem.eql(u8, opts.endings, "transparent")) {
+ break :blk false;
+ }
+ return error.TypeError;
+ };
+
const data, const arena = blk: {
const parts = parts_ orelse {
break :blk .{ "", try exec.getPinnedArena(.tiny, "Blob") };
};
var len: usize = 0;
- const slices = try exec.call_arena.alloc([]const u8, parts.len);
- for (parts, slices) |js_val, *s| {
- s.* = try js_val.toStringSmart();
- len += s.len;
+ for (parts) |part| {
+ len += part.len;
}
// +256, ~struct overhead, mime dupe, ...
const arena = try exec.getPinnedArena(len + 256, "blob");
@@ -106,15 +129,13 @@ pub fn buildValue(parts_: ?[]const js.Value, opts: InitOptions, exec: *const Exe
const buf = try arena.alloc(u8, len);
var w: Writer = .fixed(buf);
- const use_native_endings = std.mem.eql(u8, opts.endings, "native");
-
- for (slices) |part| {
+ for (parts) |part| {
try writePartWithEndings(part, use_native_endings, &w);
}
break :blk .{ w.buffered(), arena };
};
- const mime = try Mime.serialize(arena.allocator(), opts.type);
+ const mime = try normalizeType(arena.allocator(), opts.type);
return .{
._rc = .{},
@@ -131,10 +152,23 @@ pub fn buildValueFromBytes(arena: *lp.Arena, data: []const u8, content_type: []c
._arena = arena,
._type = .generic,
._slice = try arena.dupe(u8, data),
- ._mime = try Mime.serialize(arena.allocator(), content_type),
+ ._mime = try normalizeType(arena.allocator(), content_type),
};
}
+// Blob's type is NOT a MIME Type. Far less strict.
+fn normalizeType(arena: std.mem.Allocator, input: []const u8) ![]const u8 {
+ if (input.len == 0) {
+ return "";
+ }
+ for (input) |c| {
+ if (c < 0x20 or c > 0x7E) {
+ return "";
+ }
+ }
+ return std.ascii.allocLowerString(arena, input);
+}
+
/// Creates a new Blob from raw byte slices (for internal Zig use).
pub fn initFromBytes(data: []const u8, content_type: []const u8, exec: *const Execution) !*Blob {
const arena = try exec.getPinnedArena(data.len + content_type.len + 256, "Blob");
@@ -304,6 +338,10 @@ pub fn stream(self: *const Blob, exec: *Execution) !*ReadableStream {
return ReadableStream.initWithData(self._slice, exec);
}
+pub fn textStream(self: *const Blob, exec: *const Execution) !*ReadableStream {
+ return ReadableStream.initWithText(self._slice, exec);
+}
+
/// Returns a Promise that resolves with a string containing
/// the contents of the blob, interpreted as UTF-8.
pub fn text(self: *const Blob, exec: *Execution) !js.Promise {
@@ -322,31 +360,52 @@ pub fn bytes(self: *const Blob, exec: *Execution) !js.Promise {
/// from a subset of the blob on which it's called.
pub fn slice(
self: *const Blob,
- start_: ?i32,
- end_: ?i32,
- content_type_: ?[]const u8,
+ start_: ?f64,
+ end_: ?f64,
+ content_type_: ?js.NullableString,
exec: *const Execution,
) !*Blob {
const data = self._slice;
+ const size: i64 = @intCast(data.len);
- const start = blk: {
- const requested_start = start_ orelse break :blk 0;
- if (requested_start < 0) {
- break :blk data.len -| @abs(requested_start);
- }
- break :blk @min(data.len, @as(u31, @intCast(requested_start)));
+ const relative_start: i64 = blk: {
+ const requested = clampLongLong(start_ orelse break :blk 0);
+ break :blk if (requested < 0) @max(size + requested, 0) else @min(requested, size);
};
- const end: usize = blk: {
- const requested_end = end_ orelse break :blk data.len;
- if (requested_end < 0) {
- break :blk @max(start, data.len -| @abs(requested_end));
- }
-
- break :blk @min(data.len, @max(start, @as(u31, @intCast(requested_end))));
+ const relative_end: i64 = blk: {
+ const requested = clampLongLong(end_ orelse break :blk size);
+ break :blk if (requested < 0) @max(size + requested, 0) else @min(requested, size);
};
- return Blob.initFromBytes(data[start..end], content_type_ orelse "", exec);
+ const start: usize = @intCast(relative_start);
+ const span: usize = @intCast(@max(relative_end - relative_start, 0));
+
+ const content_type = if (content_type_) |c| c.value else "";
+ return Blob.initFromBytes(data[start..][0..span], content_type, exec);
+}
+
+// NaN -> 0
+// .5 rounds to even,
+fn clampLongLong(value: f64) i64 {
+ if (std.math.isNan(value)) {
+ return 0;
+ }
+
+ const min = -9223372036854775808.0;
+ const max = 9223372036854775807.0;
+ if (value <= min) {
+ return std.math.minInt(i64);
+ }
+ if (value >= max) {
+ return std.math.maxInt(i64);
+ }
+
+ var rounded = @round(value);
+ if (@abs(value - @trunc(value)) == 0.5 and @mod(rounded, 2) != 0) {
+ rounded -= std.math.sign(value);
+ }
+ return @intFromFloat(rounded);
}
/// Returns the size of the Blob in bytes.
@@ -375,6 +434,7 @@ pub const JsApi = struct {
pub const size = bridge.accessor(Blob.getSize, null, .{});
pub const @"type" = bridge.accessor(Blob.getType, null, .{});
pub const stream = bridge.function(Blob.stream, .{});
+ pub const textStream = bridge.function(Blob.textStream, .{});
pub const arrayBuffer = bridge.function(Blob.arrayBuffer, .{});
};
diff --git a/src/browser/webapi/DOMMatrixReadOnly.zig b/src/browser/webapi/DOMMatrixReadOnly.zig
index 4b8e8d972..ccdbd9a9a 100644
--- a/src/browser/webapi/DOMMatrixReadOnly.zig
+++ b/src/browser/webapi/DOMMatrixReadOnly.zig
@@ -127,6 +127,7 @@ pub const DOMMatrixInit = struct {
d: ?f64 = null,
e: ?f64 = null,
f: ?f64 = null,
+ is2D: ?bool = null,
m11: ?f64 = null,
m12: ?f64 = null,
m13: ?f64 = null,
@@ -143,7 +144,6 @@ pub const DOMMatrixInit = struct {
m42: ?f64 = null,
m43: ?f64 = null,
m44: ?f64 = null,
- is2D: ?bool = null,
};
// Implements "validate and fixup a DOMMatrixInit dictionary".
diff --git a/src/browser/webapi/DOMPointReadOnly.zig b/src/browser/webapi/DOMPointReadOnly.zig
index f8ecd2606..f61ee08e9 100644
--- a/src/browser/webapi/DOMPointReadOnly.zig
+++ b/src/browser/webapi/DOMPointReadOnly.zig
@@ -59,10 +59,10 @@ pub const Type = union(enum) {
};
pub const DOMPointInit = struct {
+ w: f64 = 1,
x: f64 = 0,
y: f64 = 0,
z: f64 = 0,
- w: f64 = 1,
};
pub fn init(x_: ?f64, y_: ?f64, z_: ?f64, w_: ?f64, exec: *const js.Execution) !*DOMPointReadOnly {
diff --git a/src/browser/webapi/DOMRectReadOnly.zig b/src/browser/webapi/DOMRectReadOnly.zig
index 49ee7e54e..5729e4e43 100644
--- a/src/browser/webapi/DOMRectReadOnly.zig
+++ b/src/browser/webapi/DOMRectReadOnly.zig
@@ -39,10 +39,10 @@ pub const Type = union(enum) {
};
pub const Data = struct {
+ height: f64 = 0,
+ width: f64 = 0,
x: f64 = 0,
y: f64 = 0,
- width: f64 = 0,
- height: f64 = 0,
};
pub fn init(x_: ?f64, y_: ?f64, width_: ?f64, height_: ?f64, exec: *const js.Execution) !*DOMRectReadOnly {
diff --git a/src/browser/webapi/Element.zig b/src/browser/webapi/Element.zig
index 5eab95796..da4e3451c 100644
--- a/src/browser/webapi/Element.zig
+++ b/src/browser/webapi/Element.zig
@@ -1316,8 +1316,8 @@ pub fn checkVisibilityCached(self: *Element, cache: ?*VisibilityCache, frame: *F
const CheckVisibilityOpts = struct {
checkOpacity: bool = false,
- opacityProperty: bool = false,
checkVisibilityCSS: bool = false,
+ opacityProperty: bool = false,
visibilityProperty: bool = false,
};
pub fn checkVisibility(self: *Element, opts_: ?CheckVisibilityOpts, frame: *Frame) bool {
@@ -1871,9 +1871,9 @@ const ScrollToOpts = union(enum) {
opts: Opts,
const Opts = struct {
- top: ?i32 = null,
- left: ?i32 = null,
behavior: []const u8 = "",
+ left: ?i32 = null,
+ top: ?i32 = null,
};
};
@@ -2452,11 +2452,11 @@ pub const JsApi = struct {
pub const insertAdjacentText = bridge.function(Element.insertAdjacentText, .{ .ce_reactions = true });
const ShadowRootInit = struct {
- mode: String,
- delegatesFocus: bool = false,
- slotAssignment: ?String = null,
clonable: bool = false,
+ delegatesFocus: bool = false,
+ mode: String,
serializable: bool = false,
+ slotAssignment: ?String = null,
};
fn _attachShadow(self: *Element, init: ShadowRootInit, frame: *Frame) !*ShadowRoot {
const mode: ShadowRoot.Mode = blk: {
diff --git a/src/browser/webapi/Event.zig b/src/browser/webapi/Event.zig
index c62730864..3641a8fae 100644
--- a/src/browser/webapi/Event.zig
+++ b/src/browser/webapi/Event.zig
@@ -395,6 +395,11 @@ pub fn populateFromOptions(self: *Event, opts: anytype) void {
}
pub fn inheritOptions(comptime T: type, comptime additions: anytype) type {
+ // Web IDL reads inherited dictionaries least-derived first, each level's
+ // own members in lexicographic order — which the concatenation below plus
+ // this per-level check produce.
+ js.Local.assertDictionaryFieldOrder(additions);
+
var all_fields: []const std.builtin.Type.StructField = &.{};
if (@hasField(T, "_proto")) {
@@ -405,7 +410,11 @@ pub fn inheritOptions(comptime T: type, comptime additions: anytype) type {
const ProtoType = @typeInfo(field.type).pointer.child;
if (@hasDecl(ProtoType, "Options")) {
const parent_options = @typeInfo(ProtoType.Options);
- all_fields = all_fields ++ parent_options.@"struct".fields;
+ for (parent_options.@"struct".fields) |f| {
+ if (!std.mem.eql(u8, f.name, js.Local.dictionary_group_marker)) {
+ all_fields = all_fields ++ &[_]std.builtin.Type.StructField{f};
+ }
+ }
}
}
}
@@ -414,14 +423,18 @@ pub fn inheritOptions(comptime T: type, comptime additions: anytype) type {
const additions_info = @typeInfo(additions);
all_fields = all_fields ++ additions_info.@"struct".fields;
- var names: [all_fields.len][:0]const u8 = undefined;
- var types: [all_fields.len]type = undefined;
- var attrs: [all_fields.len]std.builtin.Type.StructField.Attributes = undefined;
+ const marker_default: void = {};
+ var names: [all_fields.len + 1][:0]const u8 = undefined;
+ var types: [all_fields.len + 1]type = undefined;
+ var attrs: [all_fields.len + 1]std.builtin.Type.StructField.Attributes = undefined;
for (all_fields, 0..) |f, i| {
names[i] = f.name;
types[i] = f.type;
attrs[i] = .{ .@"comptime" = f.is_comptime, .@"align" = f.alignment, .default_value_ptr = f.default_value_ptr };
}
+ names[all_fields.len] = js.Local.dictionary_group_marker;
+ types[all_fields.len] = void;
+ attrs[all_fields.len] = .{ .default_value_ptr = @ptrCast(&marker_default) };
return @Struct(.auto, null, &names, &types, &attrs);
}
diff --git a/src/browser/webapi/EventTarget.zig b/src/browser/webapi/EventTarget.zig
index 99403becd..5f0d83e93 100644
--- a/src/browser/webapi/EventTarget.zig
+++ b/src/browser/webapi/EventTarget.zig
@@ -190,8 +190,8 @@ const AddEventListenerOptions = union(enum) {
// passive is optional so that an absent (or undefined) member falls back
// to the type- and target-dependent default passive value.
const Options = struct {
- once: bool = false,
capture: bool = false,
+ once: bool = false,
passive: ?bool = null,
signal: ?js.Value = null,
};
diff --git a/src/browser/webapi/File.zig b/src/browser/webapi/File.zig
index 8155a807b..75bee9624 100644
--- a/src/browser/webapi/File.zig
+++ b/src/browser/webapi/File.zig
@@ -33,19 +33,26 @@ _name: []const u8,
_last_modified: i64,
pub const InitOptions = struct {
- type: []const u8 = "",
endings: []const u8 = "transparent",
lastModified: ?i64 = null,
+ type: []const u8 = "",
};
pub fn init(
- parts_: ?[]const js.Value,
- name: []const u8,
- opts_: ?InitOptions,
+ parts_: js.Value,
+ name_: js.Value,
+ opts_: ?js.Value,
exec: *js.Execution,
) !*File {
- const opts = opts_ orelse InitOptions{};
- const blob = try Blob.buildValue(parts_, .{
+ const parts = try Blob.collectParts(parts_, exec) orelse return error.TypeError;
+ const name = try name_.toStringSlice();
+
+ const opts: InitOptions = blk: {
+ const value = opts_ orelse break :blk .{};
+ break :blk (try value.toZig(?InitOptions)) orelse .{};
+ };
+
+ const blob = try Blob.buildValue(parts, .{
.type = opts.type,
.endings = opts.endings,
}, exec);
diff --git a/src/browser/webapi/ModelContext.zig b/src/browser/webapi/ModelContext.zig
index edae42ab6..47a6d7e53 100644
--- a/src/browser/webapi/ModelContext.zig
+++ b/src/browser/webapi/ModelContext.zig
@@ -36,12 +36,12 @@ _tools: std.ArrayList(*Tool) = .empty,
pub const init: ModelContext = .{};
pub const Annotations = struct {
- readOnlyHint: bool = false,
- untrustedContentHint: bool = false,
// Not in the W3C spec yet. The CDP `WebMCP.Annotation` type has an
// `autosubmit` field; storing it here means the CDP follow-up won't have
// to re-shape this struct.
autoSubmitHint: bool = false,
+ readOnlyHint: bool = false,
+ untrustedContentHint: bool = false,
};
pub const Tool = struct {
@@ -60,12 +60,12 @@ pub const Tool = struct {
};
const ToolDict = struct {
- name: []const u8,
- title: ?[]const u8 = null,
+ annotations: ?Annotations = null,
description: []const u8,
- inputSchema: ?js.Object.Global = null,
execute: js.Function.Global,
- annotations: ?Annotations = null,
+ inputSchema: ?js.Object.Global = null,
+ name: []const u8,
+ title: ?[]const u8 = null,
};
const RegisterToolOptions = struct {
diff --git a/src/browser/webapi/MutationObserver.zig b/src/browser/webapi/MutationObserver.zig
index 6c193eece..da4fed5f3 100644
--- a/src/browser/webapi/MutationObserver.zig
+++ b/src/browser/webapi/MutationObserver.zig
@@ -64,13 +64,13 @@ const ResolvedOptions = struct {
};
pub const ObserveOptions = struct {
- attributes: ?bool = null,
+ attributeFilter: ?[]const []const u8 = null,
attributeOldValue: ?bool = null,
- childList: bool = false,
+ attributes: ?bool = null,
characterData: ?bool = null,
characterDataOldValue: ?bool = null,
+ childList: bool = false,
subtree: bool = false,
- attributeFilter: ?[]const []const u8 = null,
};
pub fn init(callback: js.Function.Global, frame: *Frame) !*MutationObserver {
diff --git a/src/browser/webapi/Notification.zig b/src/browser/webapi/Notification.zig
index d719bfed8..7ea7c6dfe 100644
--- a/src/browser/webapi/Notification.zig
+++ b/src/browser/webapi/Notification.zig
@@ -45,16 +45,16 @@ _require_interaction: bool = false,
_renotify: bool = false,
const Options = struct {
+ badge: ?[]const u8 = null,
body: ?[]const u8 = null,
+ dir: ?[]const u8 = null,
icon: ?[]const u8 = null,
image: ?[]const u8 = null,
- badge: ?[]const u8 = null,
- tag: ?[]const u8 = null,
lang: ?[]const u8 = null,
- dir: ?[]const u8 = null,
- silent: ?bool = null,
- requireInteraction: ?bool = null,
renotify: ?bool = null,
+ requireInteraction: ?bool = null,
+ silent: ?bool = null,
+ tag: ?[]const u8 = null,
};
pub fn init(title: []const u8, options_: ?Options, exec: *const Execution) !*Notification {
diff --git a/src/browser/webapi/Performance.zig b/src/browser/webapi/Performance.zig
index e21ae4c11..946f8f5b2 100644
--- a/src/browser/webapi/Performance.zig
+++ b/src/browser/webapi/Performance.zig
@@ -527,9 +527,9 @@ pub const Measure = struct {
const Options = struct {
detail: ?js.Value = null,
- start: ?TimestampOrMark,
- end: ?TimestampOrMark,
duration: ?f64 = null,
+ end: ?TimestampOrMark,
+ start: ?TimestampOrMark,
const TimestampOrMark = union(enum) {
timestamp: f64,
diff --git a/src/browser/webapi/Scheduler.zig b/src/browser/webapi/Scheduler.zig
index 9dc4c035f..6b862bf78 100644
--- a/src/browser/webapi/Scheduler.zig
+++ b/src/browser/webapi/Scheduler.zig
@@ -49,8 +49,8 @@ const TaskState = struct {
};
const PostTaskOptions = struct {
- priority: ?Priority = null,
delay: ?u32 = null,
+ priority: ?Priority = null,
signal: ?*AbortSignal = null,
};
diff --git a/src/browser/webapi/StaticRange.zig b/src/browser/webapi/StaticRange.zig
index 518ad847a..e3cfa2115 100644
--- a/src/browser/webapi/StaticRange.zig
+++ b/src/browser/webapi/StaticRange.zig
@@ -35,10 +35,10 @@ _proto: *AbstractRange,
// All members are required. The fields are non-optional with no default, so the
// argument decoder rejects a missing or null member with a TypeError.
pub const StaticRangeInit = struct {
- startContainer: *Node,
- startOffset: u32,
endContainer: *Node,
endOffset: u32,
+ startContainer: *Node,
+ startOffset: u32,
};
pub fn init(opts: StaticRangeInit, frame: *Frame) !*StaticRange {
diff --git a/src/browser/webapi/URLPattern.zig b/src/browser/webapi/URLPattern.zig
index 11bb079d7..bb3b59421 100644
--- a/src/browser/webapi/URLPattern.zig
+++ b/src/browser/webapi/URLPattern.zig
@@ -54,15 +54,15 @@ const component_names = [_][]const u8{
};
pub const Init = struct {
- protocol: ?[]const u8 = null,
- username: ?[]const u8 = null,
- password: ?[]const u8 = null,
+ baseURL: ?[]const u8 = null,
+ hash: ?[]const u8 = null,
hostname: ?[]const u8 = null,
- port: ?[]const u8 = null,
+ password: ?[]const u8 = null,
pathname: ?[]const u8 = null,
+ port: ?[]const u8 = null,
+ protocol: ?[]const u8 = null,
search: ?[]const u8 = null,
- hash: ?[]const u8 = null,
- baseURL: ?[]const u8 = null,
+ username: ?[]const u8 = null,
};
const Input = union(enum) {
diff --git a/src/browser/webapi/Window.zig b/src/browser/webapi/Window.zig
index 14ccb86f2..002c793e2 100644
--- a/src/browser/webapi/Window.zig
+++ b/src/browser/webapi/Window.zig
@@ -927,9 +927,9 @@ const ScrollToOpts = union(enum) {
opts: Opts,
const Opts = struct {
- top: i32,
- left: i32,
behavior: []const u8 = "",
+ left: i32,
+ top: i32,
};
};
pub fn scrollTo(self: *Window, opts: ScrollToOpts, y: ?i32, frame: *Frame) !void {
diff --git a/src/browser/webapi/crypto/algorithm.zig b/src/browser/webapi/crypto/algorithm.zig
index 8eb9404ef..440a34065 100644
--- a/src/browser/webapi/crypto/algorithm.zig
+++ b/src/browser/webapi/crypto/algorithm.zig
@@ -45,21 +45,21 @@ pub const Init = union(enum) {
/// https://developer.mozilla.org/en-US/docs/Web/API/RsaHashedKeyGenParams
pub const RsaHashedKeyGen = struct {
- name: []const u8,
- /// This should be at least 2048.
- /// Some organizations are now recommending that it should be 4096.
- modulusLength: u32,
- publicExponent: js.TypedArray(u8),
hash: union(enum) {
string: []const u8,
object: struct { name: []const u8 },
},
+ /// This should be at least 2048.
+ /// Some organizations are now recommending that it should be 4096.
+ modulusLength: u32,
+ name: []const u8,
+ publicExponent: js.TypedArray(u8),
};
/// https://developer.mozilla.org/en-US/docs/Web/API/AesKeyGenParams
pub const AesKeyGen = struct {
- name: []const u8,
length: u32,
+ name: []const u8,
};
/// https://developer.mozilla.org/en-US/docs/Web/API/EcKeyGenParams
@@ -70,8 +70,6 @@ pub const Init = union(enum) {
/// https://developer.mozilla.org/en-US/docs/Web/API/HmacKeyGenParams
pub const HmacKeyGen = struct {
- /// Always HMAC.
- name: []const u8,
/// Its also possible to pass this in an object.
hash: union(enum) {
string: []const u8,
@@ -79,6 +77,8 @@ pub const Init = union(enum) {
},
/// If omitted, default is the block size of the chosen hash function.
length: ?usize,
+ /// Always HMAC.
+ name: []const u8,
};
/// Alias.
pub const HmacImport = HmacKeyGen;
@@ -112,17 +112,17 @@ pub const Derive = union(enum) {
};
pub const Pbkdf2Params = struct {
- name: []const u8,
hash: Hash,
- salt: js.TypedArray(u8),
iterations: u32,
+ name: []const u8,
+ salt: js.TypedArray(u8),
};
pub const HkdfParams = struct {
- name: []const u8,
hash: Hash,
- salt: js.TypedArray(u8),
info: js.TypedArray(u8),
+ name: []const u8,
+ salt: js.TypedArray(u8),
};
};
@@ -130,8 +130,8 @@ pub const Derive = union(enum) {
/// produce. HMAC carries a hash; AES carries a length. Probed in that order so
/// the more specific shapes win.
pub const DerivedKey = union(enum) {
- hmac: struct { name: []const u8, hash: Derive.Hash, length: ?u32 = null },
- keyed: struct { name: []const u8, length: u32 },
+ hmac: struct { hash: Derive.Hash, length: ?u32 = null, name: []const u8 },
+ keyed: struct { length: u32, name: []const u8 },
object: struct { name: []const u8 },
name: []const u8,
};
@@ -141,12 +141,12 @@ pub const DerivedKey = union(enum) {
/// JS value coerces to a string).
pub const Import = union(enum) {
hmac: struct {
- name: []const u8,
hash: union(enum) {
string: []const u8,
object: struct { name: []const u8 },
},
length: ?u32 = null,
+ name: []const u8,
},
ec: struct { name: []const u8, namedCurve: []const u8 },
object: struct { name: []const u8 },
@@ -181,12 +181,12 @@ pub const KeyData = union(enum) {
/// `kty` and `k`; `d` marks an asymmetric private key. The rest are accepted
/// for forward-compatibility.
pub const Jwk = struct {
- kty: []const u8,
- k: ?[]const u8 = null,
- d: ?[]const u8 = null,
alg: ?[]const u8 = null,
- use: ?[]const u8 = null,
+ d: ?[]const u8 = null,
ext: ?bool = null,
+ k: ?[]const u8 = null,
+ kty: []const u8,
+ use: ?[]const u8 = null,
};
};
@@ -195,11 +195,11 @@ pub const KeyData = union(enum) {
/// is the fallback form.
pub const Encrypt = union(enum) {
params: struct {
- name: []const u8,
- iv: ?js.TypedArray(u8) = null,
+ additionalData: ?js.TypedArray(u8) = null,
counter: ?js.TypedArray(u8) = null,
+ iv: ?js.TypedArray(u8) = null,
length: ?u32 = null,
- additionalData: ?js.TypedArray(u8) = null,
+ name: []const u8,
tagLength: ?u32 = null,
},
name: []const u8,
diff --git a/src/browser/webapi/event/DeviceOrientationEvent.zig b/src/browser/webapi/event/DeviceOrientationEvent.zig
index 8cf291946..3e4616937 100644
--- a/src/browser/webapi/event/DeviceOrientationEvent.zig
+++ b/src/browser/webapi/event/DeviceOrientationEvent.zig
@@ -37,10 +37,10 @@ _gamma: ?f64 = null,
_absolute: bool = false,
const DeviceOrientationEventOptions = struct {
+ absolute: bool = false,
alpha: ?f64 = null,
beta: ?f64 = null,
gamma: ?f64 = null,
- absolute: bool = false,
};
const Options = Event.inheritOptions(DeviceOrientationEvent, DeviceOrientationEventOptions);
diff --git a/src/browser/webapi/event/ErrorEvent.zig b/src/browser/webapi/event/ErrorEvent.zig
index 1a840b300..a9065cd57 100644
--- a/src/browser/webapi/event/ErrorEvent.zig
+++ b/src/browser/webapi/event/ErrorEvent.zig
@@ -40,11 +40,11 @@ _error: ?js.Value.Global = null,
_arena: Allocator,
pub const ErrorEventOptions = struct {
- message: ?[]const u8 = null,
- filename: ?[]const u8 = null,
- lineno: u32 = 0,
colno: u32 = 0,
@"error": ?js.Value.Global = null,
+ filename: ?[]const u8 = null,
+ lineno: u32 = 0,
+ message: ?[]const u8 = null,
};
const Options = Event.inheritOptions(ErrorEvent, ErrorEventOptions);
diff --git a/src/browser/webapi/event/HashChangeEvent.zig b/src/browser/webapi/event/HashChangeEvent.zig
index b308948d1..aa43c5ba6 100644
--- a/src/browser/webapi/event/HashChangeEvent.zig
+++ b/src/browser/webapi/event/HashChangeEvent.zig
@@ -35,8 +35,8 @@ _old_url: []const u8,
_new_url: []const u8,
const HashChangeEventOptions = struct {
- oldURL: []const u8 = "",
newURL: []const u8 = "",
+ oldURL: []const u8 = "",
};
const Options = Event.inheritOptions(HashChangeEvent, HashChangeEventOptions);
diff --git a/src/browser/webapi/event/KeyboardEvent.zig b/src/browser/webapi/event/KeyboardEvent.zig
index 50bbe5bf8..d167bfd5f 100644
--- a/src/browser/webapi/event/KeyboardEvent.zig
+++ b/src/browser/webapi/event/KeyboardEvent.zig
@@ -276,17 +276,17 @@ pub const Location = enum(i32) {
};
pub const KeyboardEventOptions = struct {
- key: []const u8 = "",
+ altKey: bool = false,
+ charCode: u32 = 0,
code: ?[]const u8 = null,
+ ctrlKey: bool = false,
+ isComposing: bool = false,
+ key: []const u8 = "",
+ keyCode: u32 = 0,
location: u32 = 0,
+ metaKey: bool = false,
repeat: bool = false,
- isComposing: bool = false,
- ctrlKey: bool = false,
shiftKey: bool = false,
- altKey: bool = false,
- metaKey: bool = false,
- charCode: u32 = 0,
- keyCode: u32 = 0,
};
const Options = Event.inheritOptions(
diff --git a/src/browser/webapi/event/MessageEvent.zig b/src/browser/webapi/event/MessageEvent.zig
index fdfbdb6c0..01a4e5334 100644
--- a/src/browser/webapi/event/MessageEvent.zig
+++ b/src/browser/webapi/event/MessageEvent.zig
@@ -46,10 +46,10 @@ pub const Source = union(enum) {
const MessageEventOptions = struct {
data: ?Data = null,
- origin: ?[]const u8 = null,
lastEventId: ?[]const u8 = null,
- source: ?Source = null,
+ origin: ?[]const u8 = null,
ports: []const *MessagePort = &.{},
+ source: ?Source = null,
};
pub const Data = union(enum) {
diff --git a/src/browser/webapi/event/MouseEvent.zig b/src/browser/webapi/event/MouseEvent.zig
index b7da253b8..4269de93c 100644
--- a/src/browser/webapi/event/MouseEvent.zig
+++ b/src/browser/webapi/event/MouseEvent.zig
@@ -68,17 +68,17 @@ _screen_y: f64,
_shift_key: bool,
pub const MouseEventOptions = struct {
- screenX: f64 = 0.0,
- screenY: f64 = 0.0,
+ altKey: bool = false,
+ button: i32 = 0,
+ buttons: u16 = 0,
clientX: f64 = 0.0,
clientY: f64 = 0.0,
ctrlKey: bool = false,
- shiftKey: bool = false,
- altKey: bool = false,
metaKey: bool = false,
- button: i32 = 0,
- buttons: u16 = 0,
relatedTarget: ?*EventTarget = null,
+ screenX: f64 = 0.0,
+ screenY: f64 = 0.0,
+ shiftKey: bool = false,
};
pub const Options = Event.inheritOptions(
diff --git a/src/browser/webapi/event/PointerEvent.zig b/src/browser/webapi/event/PointerEvent.zig
index 9a35ee1a8..807c1f99f 100644
--- a/src/browser/webapi/event/PointerEvent.zig
+++ b/src/browser/webapi/event/PointerEvent.zig
@@ -68,18 +68,18 @@ _azimuth_angle: f64,
_is_primary: bool,
pub const PointerEventOptions = struct {
+ altitudeAngle: f64 = std.math.pi / 2.0,
+ azimuthAngle: f64 = 0.0,
+ height: f64 = 1.0,
+ isPrimary: bool = false,
pointerId: i32 = 0,
pointerType: []const u8 = "",
- width: f64 = 1.0,
- height: f64 = 1.0,
pressure: f64 = 0.0,
tangentialPressure: f64 = 0.0,
tiltX: i32 = 0,
tiltY: i32 = 0,
twist: i32 = 0,
- altitudeAngle: f64 = std.math.pi / 2.0,
- azimuthAngle: f64 = 0.0,
- isPrimary: bool = false,
+ width: f64 = 1.0,
};
const Options = Event.inheritOptions(
diff --git a/src/browser/webapi/event/ProgressEvent.zig b/src/browser/webapi/event/ProgressEvent.zig
index f051ba936..c8de7a563 100644
--- a/src/browser/webapi/event/ProgressEvent.zig
+++ b/src/browser/webapi/event/ProgressEvent.zig
@@ -32,9 +32,9 @@ _loaded: usize = 0,
_length_computable: bool = false,
const ProgressEventOptions = struct {
- total: usize = 0,
- loaded: usize = 0,
lengthComputable: bool = false,
+ loaded: usize = 0,
+ total: usize = 0,
};
const Options = Event.inheritOptions(ProgressEvent, ProgressEventOptions);
diff --git a/src/browser/webapi/event/PromiseRejectionEvent.zig b/src/browser/webapi/event/PromiseRejectionEvent.zig
index de6f856b4..fba5bf706 100644
--- a/src/browser/webapi/event/PromiseRejectionEvent.zig
+++ b/src/browser/webapi/event/PromiseRejectionEvent.zig
@@ -33,8 +33,8 @@ _reason: ?js.Value.Global = null,
_promise: ?js.Promise.Global = null,
const PromiseRejectionEventOptions = struct {
- reason: ?js.Value.Global = null,
promise: ?js.Promise.Global = null,
+ reason: ?js.Value.Global = null,
};
const Options = Event.inheritOptions(PromiseRejectionEvent, PromiseRejectionEventOptions);
diff --git a/src/browser/webapi/event/StorageEvent.zig b/src/browser/webapi/event/StorageEvent.zig
index c25f8084c..4b5461233 100644
--- a/src/browser/webapi/event/StorageEvent.zig
+++ b/src/browser/webapi/event/StorageEvent.zig
@@ -38,8 +38,8 @@ _url: []const u8 = "",
const StorageEventOptions = struct {
key: ?[]const u8 = null,
- oldValue: ?[]const u8 = null,
newValue: ?[]const u8 = null,
+ oldValue: ?[]const u8 = null,
url: []const u8 = "",
};
diff --git a/src/browser/webapi/event/ToggleEvent.zig b/src/browser/webapi/event/ToggleEvent.zig
index b04c67653..10aee4299 100644
--- a/src/browser/webapi/event/ToggleEvent.zig
+++ b/src/browser/webapi/event/ToggleEvent.zig
@@ -37,8 +37,8 @@ _new_state: []const u8 = "",
_source: ?*HtmlElement = null,
const ToggleEventOptions = struct {
- oldState: []const u8 = "",
newState: []const u8 = "",
+ oldState: []const u8 = "",
source: ?*HtmlElement = null,
};
diff --git a/src/browser/webapi/event/TouchEvent.zig b/src/browser/webapi/event/TouchEvent.zig
index 5ce6b8c74..64c39d1aa 100644
--- a/src/browser/webapi/event/TouchEvent.zig
+++ b/src/browser/webapi/event/TouchEvent.zig
@@ -40,8 +40,8 @@ _shift_key: bool = false,
pub const TouchEventOptions = struct {
altKey: bool = false,
- metaKey: bool = false,
ctrlKey: bool = false,
+ metaKey: bool = false,
shiftKey: bool = false,
};
diff --git a/src/browser/webapi/event/WheelEvent.zig b/src/browser/webapi/event/WheelEvent.zig
index a17e7094b..74133a958 100644
--- a/src/browser/webapi/event/WheelEvent.zig
+++ b/src/browser/webapi/event/WheelEvent.zig
@@ -41,10 +41,10 @@ pub const DOM_DELTA_LINE: u32 = 0x01;
pub const DOM_DELTA_PAGE: u32 = 0x02;
pub const WheelEventOptions = struct {
+ deltaMode: u32 = 0,
deltaX: f64 = 0.0,
deltaY: f64 = 0.0,
deltaZ: f64 = 0.0,
- deltaMode: u32 = 0,
};
pub const Options = Event.inheritOptions(
diff --git a/src/browser/webapi/navigation/Navigation.zig b/src/browser/webapi/navigation/Navigation.zig
index b188032f6..6dc58660a 100644
--- a/src/browser/webapi/navigation/Navigation.zig
+++ b/src/browser/webapi/navigation/Navigation.zig
@@ -296,9 +296,9 @@ pub fn replaceEntry(
}
const NavigateOptions = struct {
- state: ?js.Value = null,
- info: ?js.Value = null,
history: ?[]const u8 = null,
+ info: ?js.Value = null,
+ state: ?js.Value = null,
};
pub fn navigateInner(
@@ -415,8 +415,8 @@ pub fn navigate(self: *Navigation, _url: [:0]const u8, _opts: ?NavigateOptions,
}
pub const ReloadOptions = struct {
- state: ?js.Value = null,
info: ?js.Value = null,
+ state: ?js.Value = null,
};
pub fn reload(self: *Navigation, _opts: ?ReloadOptions, frame: *Frame) !NavigationReturn {
diff --git a/src/browser/webapi/net/Request.zig b/src/browser/webapi/net/Request.zig
index fa249d497..18e8d1ff3 100644
--- a/src/browser/webapi/net/Request.zig
+++ b/src/browser/webapi/net/Request.zig
@@ -55,14 +55,14 @@ pub const Input = union(enum) {
};
pub const InitOpts = struct {
- method: ?[]const u8 = null,
- headers: ?Headers.InitOpts = null,
body: ?BodyInit = null,
cache: Cache = .default,
credentials: Credentials = .@"same-origin",
+ headers: ?Headers.InitOpts = null,
+ method: ?[]const u8 = null,
+ priority: ?[]const u8 = null,
redirect: Redirect = .follow,
signal: ?*AbortSignal = null,
- priority: ?[]const u8 = null,
};
const Priority = enum { high, low, auto };
diff --git a/src/browser/webapi/net/Response.zig b/src/browser/webapi/net/Response.zig
index 31a7bf92a..79ff5f936 100644
--- a/src/browser/webapi/net/Response.zig
+++ b/src/browser/webapi/net/Response.zig
@@ -66,8 +66,8 @@ const Body = union(enum) {
};
const InitOpts = struct {
- status: u16 = 200,
headers: ?Headers.InitOpts = null,
+ status: u16 = 200,
statusText: ?[]const u8 = null,
};
diff --git a/src/browser/webapi/storage/CookieStore.zig b/src/browser/webapi/storage/CookieStore.zig
index 62451e734..4a8e3ac3e 100644
--- a/src/browser/webapi/storage/CookieStore.zig
+++ b/src/browser/webapi/storage/CookieStore.zig
@@ -213,14 +213,14 @@ const GetInput = union(enum) {
// https://developer.mozilla.org/en-US/docs/Web/API/CookieStore/set
const CookieInit = struct {
- name: []const u8,
- value: []const u8,
+ domain: ?[]const u8 = null,
expires: ?f64 = null,
maxAge: ?f64 = null,
- domain: ?[]const u8 = null,
+ name: []const u8,
+ partitioned: bool = false,
path: []const u8 = "/",
sameSite: SameSite = .strict,
- partitioned: bool = false,
+ value: []const u8,
};
const SetInput = union(enum) {
@@ -230,10 +230,10 @@ const SetInput = union(enum) {
// https://developer.mozilla.org/en-US/docs/Web/API/CookieStore/delete
const DeleteOptions = struct {
- name: []const u8,
domain: ?[]const u8 = null,
- path: []const u8 = "/",
+ name: []const u8,
partitioned: bool = false,
+ path: []const u8 = "/",
};
const DeleteInput = union(enum) {
@@ -595,17 +595,17 @@ pub const JsApi = struct {
// NOTE: Per spec, name and value are the only valid fields. All other fields
// are experimental. Chrome exposes them all, so we do too.
pub const CookieListItem = struct {
+ domain: ?String = null,
+ expires: ?f64 = null,
name: String,
+ partitioned: bool = false,
+ path: String = String.wrap("/"),
+ sameSite: []const u8 = "strict",
+ secure: bool = false,
// Optional because a deletion change-event reports the removed cookie with
// `value` omitted (serialized as undefined via the `deleted` accessor's
// null_as_undefined). For get/getAll and `changed` items it is always set.
value: ?String = null,
- domain: ?String = null,
- path: String = String.wrap("/"),
- expires: ?f64 = null,
- secure: bool = false,
- sameSite: []const u8 = "strict",
- partitioned: bool = false,
};
const testing = @import("../../../testing.zig");
diff --git a/src/browser/webapi/storage/idb/IDBDatabase.zig b/src/browser/webapi/storage/idb/IDBDatabase.zig
index c2f2237ce..7f736e227 100644
--- a/src/browser/webapi/storage/idb/IDBDatabase.zig
+++ b/src/browser/webapi/storage/idb/IDBDatabase.zig
@@ -63,8 +63,8 @@ pub fn asEventTarget(self: *IDBDatabase) *EventTarget {
}
const CreateObjectStoreOptions = struct {
- keyPath: ?Key.KeyPath = null,
autoIncrement: bool = false,
+ keyPath: ?Key.KeyPath = null,
};
// Only callable while the upgrade transaction is live and active, hence the checks
diff --git a/src/browser/webapi/storage/idb/IDBObjectStore.zig b/src/browser/webapi/storage/idb/IDBObjectStore.zig
index f9554f53f..aec0747c6 100644
--- a/src/browser/webapi/storage/idb/IDBObjectStore.zig
+++ b/src/browser/webapi/storage/idb/IDBObjectStore.zig
@@ -476,8 +476,8 @@ fn addIndexEntries(self: *IDBObjectStore, local: *const js.Local, arena: Allocat
}
const CreateIndexOptions = struct {
- unique: bool = false,
multiEntry: bool = false,
+ unique: bool = false,
};
// Only callable during an upgrade (versionchange transaction).
diff --git a/src/browser/webapi/storage/idb/IDBVersionChangeEvent.zig b/src/browser/webapi/storage/idb/IDBVersionChangeEvent.zig
index 1dddc0363..56796b548 100644
--- a/src/browser/webapi/storage/idb/IDBVersionChangeEvent.zig
+++ b/src/browser/webapi/storage/idb/IDBVersionChangeEvent.zig
@@ -34,8 +34,8 @@ _old_version: u64,
_new_version: ?u64,
const IDBVersionChangeEventOptions = struct {
- oldVersion: u64 = 0,
newVersion: ?u64 = null,
+ oldVersion: u64 = 0,
};
const Options = Event.inheritOptions(IDBVersionChangeEvent, IDBVersionChangeEventOptions);
diff --git a/src/browser/webapi/streams/ReadableStream.zig b/src/browser/webapi/streams/ReadableStream.zig
index 11276d79a..353afd4cb 100644
--- a/src/browser/webapi/streams/ReadableStream.zig
+++ b/src/browser/webapi/streams/ReadableStream.zig
@@ -55,15 +55,15 @@ _cancel: ?Cancel = null,
_collected: bool = false,
const UnderlyingSource = struct {
- start: ?js.Function = null,
- pull: ?js.Function.Global = null,
cancel: ?js.Function.Global = null,
+ pull: ?js.Function.Global = null,
+ start: ?js.Function = null,
type: ?[]const u8 = null,
};
const QueueingStrategy = struct {
- size: ?js.Function = null,
highWaterMark: u32 = 1,
+ size: ?js.Function = null,
};
pub fn init(src_: ?UnderlyingSource, strategy_: ?QueueingStrategy, exec: *const Execution) !*ReadableStream {
@@ -109,6 +109,17 @@ pub fn initWithData(data: []const u8, exec: *const Execution) !*ReadableStream {
return stream;
}
+pub fn initWithText(text: []const u8, exec: *const Execution) !*ReadableStream {
+ const stream = try init(null, null, exec);
+
+ if (text.len > 0) {
+ try stream._controller.enqueue(.{ .string = text });
+ }
+ try stream._controller.close();
+
+ return stream;
+}
+
pub fn getReader(self: *ReadableStream, exec: *const Execution) !*ReadableStreamDefaultReader {
if (self.getLocked()) {
return error.ReaderLocked;
@@ -281,8 +292,8 @@ pub fn cancel(self: *ReadableStream, reason: ?[]const u8, exec: *const Execution
/// pipeThrough(transform) — pipes this readable stream through a transform stream,
/// returning the readable side. `transform` is a JS object with `readable` and `writable` properties.
const PipeTransform = struct {
- writable: *WritableStream,
readable: *ReadableStream,
+ writable: *WritableStream,
};
pub fn pipeThrough(self: *ReadableStream, transform: PipeTransform, exec: *const Execution) !*ReadableStream {
diff --git a/src/browser/webapi/streams/TransformStream.zig b/src/browser/webapi/streams/TransformStream.zig
index d807b2f59..2bdb65d6c 100644
--- a/src/browser/webapi/streams/TransformStream.zig
+++ b/src/browser/webapi/streams/TransformStream.zig
@@ -35,9 +35,9 @@ _writable: *WritableStream,
_controller: *TransformStreamDefaultController,
const Transformer = struct {
+ flush: ?js.Function.Global = null,
start: ?js.Function = null,
transform: ?js.Function.Global = null,
- flush: ?js.Function.Global = null,
};
pub fn init(transformer_: ?Transformer, exec: *const Execution) !*TransformStream {
diff --git a/src/browser/webapi/streams/WritableStream.zig b/src/browser/webapi/streams/WritableStream.zig
index ddf3da7ee..4b8df652c 100644
--- a/src/browser/webapi/streams/WritableStream.zig
+++ b/src/browser/webapi/streams/WritableStream.zig
@@ -41,11 +41,11 @@ _close_fn: ?js.Function.Global,
_transform_stream: ?*TransformStream,
const UnderlyingSink = struct {
- start: ?js.Function = null,
- write: ?js.Function.Global = null,
- close: ?js.Function.Global = null,
abort: ?js.Function.Global = null,
+ close: ?js.Function.Global = null,
+ start: ?js.Function = null,
type: ?[]const u8 = null,
+ write: ?js.Function.Global = null,
};
pub fn init(sink_: ?UnderlyingSink, exec: *const Execution) !*WritableStream {
diff --git a/src/network/HttpClient.zig b/src/network/HttpClient.zig
index ec8808806..b6d1abb5e 100644
--- a/src/network/HttpClient.zig
+++ b/src/network/HttpClient.zig
@@ -3277,11 +3277,17 @@ const Synthetic = struct {
content_type = parsed.content_type;
body = parsed.body;
} else {
+ // Fetch: a blob: request with any other method is a network error.
+ if (transfer.req.method != .GET) {
+ return error.BlobMethodNotAllowed;
+ }
+
const owner = transfer.owner orelse return error.BlobNotFound;
- if (!Owner.Blob.urlBelongsToOrigin(url, owner.origin.*)) {
+ const key = url[0 .. std.mem.indexOfScalar(u8, url, '#') orelse url.len];
+ if (!Owner.Blob.urlBelongsToOrigin(key, owner.origin.*)) {
return error.BlobNotFound;
}
- const blob = (owner.blob_urls.get(url) orelse return error.BlobNotFound).blob;
+ const blob = (owner.blob_urls.get(key) orelse return error.BlobNotFound).blob;
// blob can be removed by the time we run, dupe it.
content_type = try arena.dupe(u8, blob._mime);
body = try arena.dupe(u8, blob._slice);