From 233d08cd6ea5c9336e299de09378a44e6c7afb48 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Fri, 24 Apr 2026 15:23:25 +0200 Subject: [PATCH 01/17] ci: generate a .deb package on tag --- .github/workflows/release.yml | 69 +++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 62f75198..0a5e7d89 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -201,3 +201,72 @@ jobs: artifacts: pkg/lightpanda-${{ env.PKGVER }}-${{ env.PKGREL }}-${{ env.ARCH }}.pkg.tar.zst tag: ${{ env.RELEASE }} makeLatest: true + + package-debian: + if: github.ref_type == 'tag' + strategy: + fail-fast: false + matrix: + include: + - arch: x86_64 + deb_arch: amd64 + - arch: aarch64 + deb_arch: arm64 + + env: + ARCH: ${{ matrix.arch }} + DEB_ARCH: ${{ matrix.deb_arch }} + OS: linux + + needs: build-linux + runs-on: ubuntu-22.04 + container: debian:stable-slim + timeout-minutes: 10 + + steps: + - uses: actions/checkout@v6 + + - name: Install packaging deps + run: | + apt-get update + apt-get install -y --no-install-recommends dpkg-dev + + - name: Download linux binary + uses: actions/download-artifact@v4 + with: + name: lightpanda-${{ env.ARCH }}-${{ env.OS }} + path: . + + - name: Build Debian package + run: | + RAW_VERSION="${{ env.RELEASE }}" + PKGVER="${RAW_VERSION#v}" + echo "PKGVER=${PKGVER}" >> "$GITHUB_ENV" + + ROOT="lightpanda_${PKGVER}_${DEB_ARCH}" + mkdir -p "$ROOT/DEBIAN" "$ROOT/usr/bin" "$ROOT/usr/share/doc/lightpanda" + + install -m755 "lightpanda-${ARCH}-${OS}" "$ROOT/usr/bin/lightpanda" + install -m644 LICENSE "$ROOT/usr/share/doc/lightpanda/copyright" + + cat > "$ROOT/DEBIAN/control" <= 2.35) + Maintainer: Lightpanda + Homepage: https://lightpanda.io + Description: Lightpanda, headless browser built for AI and automation + EOF + + dpkg-deb --build --root-owner-group "$ROOT" + + - name: Upload Debian package to release + uses: ncipollo/release-action@v1 + with: + allowUpdates: true + artifacts: lightpanda_${{ env.PKGVER }}_${{ env.DEB_ARCH }}.deb + tag: ${{ env.RELEASE }} + makeLatest: true From 8ba960ecbc93be401feae632f76d98faae6aa12b Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Fri, 24 Apr 2026 21:29:41 +0800 Subject: [PATCH 02/17] window.open Adds limited support for window.open. This leverages the new page container and behaves similarly to an iframe. There are many things not implemented, but the most significant are: 1- target=window_name or target=_blank don't work (but this could be added pretty easily I think) 2- Windows (which are is just a Frame) are shutdown when the Page is shutdown. They would need to be owned by the Session (rather than the Page), but I'm not really confident in that right now. 3- No CDP testing. There are maybe CDP-specific messages we need to emit (or maybe messages that we shouldn't emit). As-is, this should help with common cases where: 1. window.open is called but doesn't matter (won't give a JS error) 2. window.open is short-lived, or, more specifically, lives only for the duration of the page that opened it (e.g. a login popup). 3. WPT tests! (because most of these fit in #2). --- src/browser/Frame.zig | 67 ++++++++++++- src/browser/Page.zig | 23 +++++ src/browser/Session.zig | 46 +++++++++ src/browser/tests/window/open.html | 109 ++++++++++++++++++++ src/browser/webapi/Window.zig | 155 ++++++++++++++++++++++++++++- 5 files changed, 396 insertions(+), 4 deletions(-) create mode 100644 src/browser/tests/window/open.html diff --git a/src/browser/Frame.zig b/src/browser/Frame.zig index dedb522e..bb23a452 100644 --- a/src/browser/Frame.zig +++ b/src/browser/Frame.zig @@ -532,6 +532,8 @@ pub fn navigate(self: *Frame, request_url: [:0]const u8, opts: NavigateOpts) !vo self.origin = try URL.getOrigin(self.arena, request_url[5.. :0]); } else if (self.parent) |parent| { self.origin = parent.origin; + } else if (self.window._opener) |opener| { + self.origin = opener._frame.origin; } else { self.origin = null; } @@ -1289,6 +1291,69 @@ pub fn iframeAddedCallback(self: *Frame, iframe: *IFrame) !void { } } +const OpenPopupOpts = struct { + url: []const u8, + name: []const u8, + opener: ?*Window, +}; + +// Create a new top-level browsing context as a sibling of the root frame. +// The popup shares the Page's arena, factory, and identity map, but has no +// parent and is not attached to the frame tree — it lives in page.popups. +pub fn openPopup(self: *Frame, opts: OpenPopupOpts) !*Frame { + const page = self._page; + const session = self._session; + + const resolved_url: [:0]const u8 = blk: { + if (opts.url.len == 0) { + break :blk "about:blank"; + } + if (std.mem.eql(u8, opts.url, "about:blank")) { + break :blk "about:blank"; + } + const frame_base = base_blk: { + var frame = self; + while (true) { + const maybe_base = frame.base(); + if (!std.mem.eql(u8, maybe_base, "about:blank")) { + break :base_blk maybe_base; + } + frame = frame.parent orelse break :base_blk ""; + } + }; + break :blk try URL.resolve(self.call_arena, frame_base, opts.url, .{ .always_dupe = true, .encoding = self.charset }); + }; + + const popup = try page.frame_arena.create(Frame); + errdefer page.frame_arena.destroy(popup); + + const frame_id = session.nextFrameId(); + try Frame.init(popup, frame_id, page, null); + errdefer popup.deinit(true); + + popup.window._opener = opts.opener; + if (opts.name.len > 0 and + !std.ascii.eqlIgnoreCase(opts.name, "_blank") and + !std.ascii.eqlIgnoreCase(opts.name, "_self") and + !std.ascii.eqlIgnoreCase(opts.name, "_parent") and + !std.ascii.eqlIgnoreCase(opts.name, "_top")) + { + popup.window._name = try page.frame_arena.dupe(u8, opts.name); + } + + const popup_index = page.popups.items.len; + try page.popups.append(page.frame_arena, popup); + // not impossible that navigate adds popups, so remove by index + errdefer _ = page.popups.swapRemove(popup_index); + + popup.navigate(resolved_url, .{ .reason = .script }) catch |err| { + log.warn(.frame, "popup navigate failure", .{ .url = resolved_url, .err = err }); + return err; + }; + + return popup; +} + pub fn domChanged(self: *Frame) void { self.version += 1; @@ -3390,7 +3455,7 @@ pub const QueuedNavigation = struct { /// to the appropriateFrame to navigate. /// Returns null if the target is "_blank" (which would open a new window/tab). /// Note: Callers should handle empty target separately (for owner document resolution). -fn resolveTargetFrame(self: *Frame, target_name: []const u8) ?*Frame { +pub fn resolveTargetFrame(self: *Frame, target_name: []const u8) ?*Frame { if (std.ascii.eqlIgnoreCase(target_name, "_self")) { return self; } diff --git a/src/browser/Page.zig b/src/browser/Page.zig index af58f34a..929cd07c 100644 --- a/src/browser/Page.zig +++ b/src/browser/Page.zig @@ -88,6 +88,14 @@ queued_queued_navigation: std.ArrayList(*Frame) = .empty, // The root Frame of this Page. Non-optional — a Page always has a root frame. frame: Frame, +// Popup Frames opened by window.open. They are top-level browsing contexts +// (parent == null, no iframe element) but share this Page's factory, arena, +// and identity map. +// Their lifetime is bound to the Page: on Page.deinit they +// are torn down. TODO: this is far from correct. An new window shouldn't be tied +// to the original page like this. +popups: std.ArrayList(*Frame) = .empty, + // Initialize a Page and its root Frame. pub fn init(self: *Page, session: *Session, frame_id: u32) !void { const frame_arena = try session.arena_pool.acquire(.large, "Page.frame_arena"); @@ -107,6 +115,11 @@ pub fn init(self: *Page, session: *Session, frame_id: u32) !void { // Tear down the Page and its root Frame. Equivalent to the old // Session.removePage + Session.resetFrameResources. pub fn deinit(self: *Page, abort_http: bool) void { + for (self.popups.items) |popup| { + popup.deinit(abort_http); + } + self.popups = .empty; + self.frame.deinit(abort_http); const session = self.session; @@ -217,6 +230,16 @@ pub fn findFrameByFrameId(self: *Page, frame_id: u32) ?*Frame { return findFrameBy(&self.frame, "_frame_id", frame_id); } +// Returns the popup Frame registered under `name`, or null. +pub fn findPopupByName(self: *Page, name: []const u8) ?*Frame { + for (self.popups.items) |popup| { + if (std.mem.eql(u8, popup.window._name, name)) { + return popup; + } + } + return null; +} + pub fn findFrameByLoaderId(self: *Page, loader_id: u32) ?*Frame { return findFrameBy(&self.frame, "_loader_id", loader_id); } diff --git a/src/browser/Session.zig b/src/browser/Session.zig index 17f2e221..421b9b25 100644 --- a/src/browser/Session.zig +++ b/src/browser/Session.zig @@ -281,6 +281,13 @@ pub fn processQueuedNavigation(self: *Session) !void { } fn processFrameNavigation(self: *Session, frame: *Frame, qn: *QueuedNavigation) !void { + // Popups live on the Page as top-level browsing contexts without a + // parent or iframe element. Their re-navigation path is simpler than + // iframes — no parent bookkeeping to patch. + if (frame.parent == null and frame.iframe == null) { + return self.processPopupNavigation(frame, qn); + } + lp.assert(frame.parent != null, "root queued navigation", .{}); const iframe = frame.iframe.?; @@ -331,6 +338,45 @@ fn processFrameNavigation(self: *Session, frame: *Frame, qn: *QueuedNavigation) }; } +// Re-navigates a popup Frame in place. The Frame pointer stays stable +// (scripts in the opener may hold a cached Window ref — though the Window +// object inside is replaced, matching how iframes behave on navigation). +fn processPopupNavigation(self: *Session, frame: *Frame, qn: *QueuedNavigation) !void { + frame._queued_navigation = null; + defer self.releaseArena(qn.arena); + + // Preserve popup identity fields. _name lives in the Page arena and + // survives Frame.deinit; _opener is just a pointer. + const saved_name = frame.window._name; + const saved_opener = frame.window._opener; + const frame_id = frame._frame_id; + const page = self.currentPage().?; + + frame.deinit(true); + frame.* = undefined; + + errdefer { + // If re-init fails, drop from popups so we don't leave a corpse. + for (page.popups.items, 0..) |p, i| { + if (p == frame) { + _ = page.popups.swapRemove(i); + break; + } + } + } + + try Frame.init(frame, frame_id, page, null); + errdefer frame.deinit(true); + + frame.window._name = saved_name; + frame.window._opener = saved_opener; + + frame.navigate(qn.url, qn.opts) catch |err| { + log.err(.browser, "queued popup navigation error", .{ .err = err }); + return err; + }; +} + fn processRootQueuedNavigation(self: *Session) !void { const current_frame = &self.page.?.frame; const frame_id = current_frame._frame_id; diff --git a/src/browser/tests/window/open.html b/src/browser/tests/window/open.html new file mode 100644 index 00000000..4bc0b72d --- /dev/null +++ b/src/browser/tests/window/open.html @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/browser/webapi/Window.zig b/src/browser/webapi/Window.zig index 31efb8ff..e02ba550 100644 --- a/src/browser/webapi/Window.zig +++ b/src/browser/webapi/Window.zig @@ -95,6 +95,18 @@ _scroll_pos: struct { // A cross origin wrapper for this window _cross_origin_wrapper: CrossOriginWindow, +// The Window that called window.open to create this one. Null for the root +// window, for noopener popups, and cleared if the opener is torn down while +// we're still alive. Only valid if `!_opener.?._closed`. +_opener: ?*Window = null, + +// True after our Frame has been deinit'd by window.close. Many things on the +// window become invalid once this is true. +_closed: bool = false, + +// Popup name (owned by page.arena) +_name: []const u8 = "", + pub fn asEventTarget(self: *Window) *EventTarget { return self._proto; } @@ -111,6 +123,25 @@ pub fn getWindow(self: *Window) *Window { return self; } +pub fn getOpener(self: *Window, frame: *Frame) ?Access { + const opener = self._opener orelse return null; + if (opener._closed) return null; + return Access.init(frame.window, opener); +} + +pub fn getClosed(self: *const Window) bool { + return self._closed; +} + +pub fn getName(self: *const Window) []const u8 { + return self._name; +} + +pub fn setName(self: *Window, name: []const u8, frame: *Frame) !void { + // Store in the Page's frame arena so the slice outlives any call_arena. + self._name = try frame.arena.dupe(u8, name); +} + pub fn getTop(self: *Window, frame: *Frame) Access { var p = self._frame; while (p.parent) |parent| { @@ -424,6 +455,108 @@ pub fn getComputedStyle(_: *const Window, element: *Element, pseudo_element: ?[] return CSSStyleProperties.init(element, true, frame); } +// window.open(url?, target?, features?) — v1 scope: +// * Always creates a new popup Frame on the Page (sibling to the root). +// * Honors `noopener` / `noreferrer` tokens in `features` (opener=null, +// return value=null). Geometry (width, height, ...) ignored. +// * `target` values `_self` / `_parent` / `_top` navigate the current frame. +// Any other value is treated as a popup name; reusing a live name +// navigates the existing popup instead of spawning a new one. +// * `url` empty or missing opens about:blank. +pub fn open(self: *Window, url_: ?[]const u8, target_: ?[]const u8, features_: ?[]const u8, frame: *Frame) !?Access { + const raw_url = url_ orelse ""; + const target = target_ orelse ""; + const features = features_ orelse ""; + + const no_opener = hasFeatureToken(features, "noopener") or hasFeatureToken(features, "noreferrer"); + + // _self / _parent / _top navigate the current browsing context. + if (std.ascii.eqlIgnoreCase(target, "_self") or + std.ascii.eqlIgnoreCase(target, "_parent") or + std.ascii.eqlIgnoreCase(target, "_top")) + { + const nav_target = frame.resolveTargetFrame(target) orelse frame; + const nav_url = if (raw_url.len == 0) "about:blank" else raw_url; + try frame.scheduleNavigation(nav_url, .{ + .reason = .script, + .kind = .{ .push = null }, + }, .{ .script = nav_target }); + + if (no_opener) { + return null; + } + + return Access.init(frame.window, nav_target.window); + } + + const page = frame._page; + + // Name-based reuse: if a popup with this name already exists, reuse it. + // `_blank` is reserved and never reuses. + const is_named = target.len > 0 and !std.ascii.eqlIgnoreCase(target, "_blank"); + if (is_named) { + if (page.findPopupByName(target)) |existing| { + if (raw_url.len > 0) { + try existing.scheduleNavigation(raw_url, .{ + .reason = .script, + .kind = .{ .push = null }, + }, .{ .script = existing }); + } + if (no_opener) { + return null; + } + return Access.init(frame.window, existing.window); + } + } + + // Spawn a new popup Frame as a sibling of the root. + const popup = try frame.openPopup(.{ + .url = raw_url, + .name = target, + .opener = if (no_opener) null else self, + }); + + if (no_opener) { + return null; + } + return Access.init(frame.window, popup.window); +} + +pub fn close(self: *Window) void { + if (self._closed) { + return; + } + + // Per spec, close() is only honored on script-opened windows. That + // maps exactly to membership in page.popups. + const frame = self._frame; + const page = frame._page; + + var popup_index: usize = 0; + while (popup_index < page.popups.items.len) : (popup_index += 1) { + if (page.popups.items[popup_index] == frame) { + break; + } + } else return; + + self._closed = true; + + // Any live Window holding us as its opener must drop the reference — + // our Frame is about to go away, and a stale _frame deref on their + // side would crash. + for (page.popups.items) |popup| { + if (popup.window._opener == self) { + popup.window._opener = null; + } + } + if (page.frame.window._opener == self) { + page.frame.window._opener = null; + } + + _ = page.popups.swapRemove(popup_index); + frame.deinit(true); +} + pub fn postMessage(self: *Window, message: js.Value.Temp, target_origin: ?[]const u8, frame: *Frame) !void { // For now, we ignore targetOrigin checking and just dispatch the message // In a full implementation, we would validate the origin @@ -833,6 +966,20 @@ fn getFunctionFromSetter(setter_: ?FunctionSetter) ?js.Function.Global { }; } +// Checks whether a window.open features string contains a token, matched +// case-insensitively on whole-token boundaries (comma or whitespace separated). +// The features syntax is legacy and loose; the only tokens we interpret are +// noopener and noreferrer. +fn hasFeatureToken(features: []const u8, token: []const u8) bool { + var it = std.mem.tokenizeAny(u8, features, " \t\r\n,"); + while (it.next()) |raw| { + // Trim a trailing =value if present — we only need the key. + const key = if (std.mem.indexOfScalarPos(u8, raw, 0, '=')) |eq| raw[0..eq] else raw; + if (std.ascii.eqlIgnoreCase(key, token)) return true; + } + return false; +} + pub const JsApi = struct { pub const bridge = js.Bridge(Window); @@ -912,9 +1059,11 @@ pub const JsApi = struct { pub const innerHeight = bridge.property(1080, .{ .template = false }); pub const devicePixelRatio = bridge.property(1, .{ .template = false }); - // This should return a window-like object in specific conditions. Would be - // pretty complicated to properly support I think. - pub const opener = bridge.property(null, .{ .template = false }); + pub const opener = bridge.accessor(Window.getOpener, null, .{}); + pub const closed = bridge.accessor(Window.getClosed, null, .{}); + pub const name = bridge.accessor(Window.getName, Window.setName, .{}); + pub const open = bridge.function(Window.open, .{}); + pub const close = bridge.function(Window.close, .{}); pub const alert = bridge.function(struct { fn alert(_: *const Window, message: ?[]const u8, frame: *Frame) void { From 876712730869f7bd21c9ffd5cb719580e40b2944 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Fri, 24 Apr 2026 15:37:02 +0200 Subject: [PATCH 03/17] ci: split package release into sub files --- .github/workflows/package-archlinux.yml | 79 ++++++++++++++ .github/workflows/package-debian.yml | 78 ++++++++++++++ .github/workflows/release.yml | 133 +----------------------- 3 files changed, 159 insertions(+), 131 deletions(-) create mode 100644 .github/workflows/package-archlinux.yml create mode 100644 .github/workflows/package-debian.yml diff --git a/.github/workflows/package-archlinux.yml b/.github/workflows/package-archlinux.yml new file mode 100644 index 00000000..dba6d2d0 --- /dev/null +++ b/.github/workflows/package-archlinux.yml @@ -0,0 +1,79 @@ +name: package archlinux + +on: + workflow_call: + +permissions: + contents: write + +env: + RELEASE: ${{ github.ref_type == 'tag' && github.ref_name || 'nightly' }} + +jobs: + package: + strategy: + fail-fast: false + matrix: + arch: [x86_64, aarch64] + + env: + ARCH: ${{ matrix.arch }} + OS: linux + + runs-on: ubuntu-22.04 + container: archlinux:latest + timeout-minutes: 10 + + steps: + - uses: actions/checkout@v6 + + - name: Install packaging deps + run: pacman -Syu --noconfirm --needed base-devel sudo + + - name: Download linux binary + uses: actions/download-artifact@v4 + with: + name: lightpanda-${{ env.ARCH }}-${{ env.OS }} + path: . + + - name: Build Arch package + run: | + useradd -m builder + echo "builder ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers + + RAW_VERSION="${{ env.RELEASE }}" + PKGVER="${RAW_VERSION#v}" + PKGREL="1" + echo "PKGVER=${PKGVER}" >> "$GITHUB_ENV" + echo "PKGREL=${PKGREL}" >> "$GITHUB_ENV" + + mkdir -p pkg + cp lightpanda-${{ env.ARCH }}-${{ env.OS }} pkg/ + cp LICENSE pkg/ + + cat > pkg/PKGBUILD <> "$GITHUB_ENV" + + ROOT="lightpanda_${PKGVER}_${DEB_ARCH}" + mkdir -p "$ROOT/DEBIAN" "$ROOT/usr/bin" "$ROOT/usr/share/doc/lightpanda" + + install -m755 "lightpanda-${ARCH}-${OS}" "$ROOT/usr/bin/lightpanda" + install -m644 LICENSE "$ROOT/usr/share/doc/lightpanda/copyright" + + cat > "$ROOT/DEBIAN/control" <= 2.35) + Maintainer: Lightpanda + Homepage: https://lightpanda.io + Description: Lightpanda, headless browser built for AI and automation + EOF + + dpkg-deb --build --root-owner-group "$ROOT" + + - name: Upload Debian package to release + uses: ncipollo/release-action@v1 + with: + allowUpdates: true + artifacts: lightpanda_${{ env.PKGVER }}_${{ env.DEB_ARCH }}.deb + tag: ${{ env.RELEASE }} + makeLatest: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0a5e7d89..11e4b87e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -134,139 +134,10 @@ jobs: package-archlinux: if: github.ref_type == 'tag' - strategy: - fail-fast: false - matrix: - arch: [x86_64, aarch64] - - env: - ARCH: ${{ matrix.arch }} - OS: linux - needs: build-linux - runs-on: ubuntu-22.04 - container: archlinux:latest - timeout-minutes: 10 - - steps: - - uses: actions/checkout@v6 - - - name: Install packaging deps - run: pacman -Syu --noconfirm --needed base-devel sudo - - - name: Download linux binary - uses: actions/download-artifact@v4 - with: - name: lightpanda-${{ env.ARCH }}-${{ env.OS }} - path: . - - - name: Build Arch package - run: | - useradd -m builder - echo "builder ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers - - RAW_VERSION="${{ env.RELEASE }}" - PKGVER="${RAW_VERSION#v}" - PKGREL="1" - echo "PKGVER=${PKGVER}" >> "$GITHUB_ENV" - echo "PKGREL=${PKGREL}" >> "$GITHUB_ENV" - - mkdir -p pkg - cp lightpanda-${{ env.ARCH }}-${{ env.OS }} pkg/ - cp LICENSE pkg/ - - cat > pkg/PKGBUILD <> "$GITHUB_ENV" - - ROOT="lightpanda_${PKGVER}_${DEB_ARCH}" - mkdir -p "$ROOT/DEBIAN" "$ROOT/usr/bin" "$ROOT/usr/share/doc/lightpanda" - - install -m755 "lightpanda-${ARCH}-${OS}" "$ROOT/usr/bin/lightpanda" - install -m644 LICENSE "$ROOT/usr/share/doc/lightpanda/copyright" - - cat > "$ROOT/DEBIAN/control" <= 2.35) - Maintainer: Lightpanda - Homepage: https://lightpanda.io - Description: Lightpanda, headless browser built for AI and automation - EOF - - dpkg-deb --build --root-owner-group "$ROOT" - - - name: Upload Debian package to release - uses: ncipollo/release-action@v1 - with: - allowUpdates: true - artifacts: lightpanda_${{ env.PKGVER }}_${{ env.DEB_ARCH }}.deb - tag: ${{ env.RELEASE }} - makeLatest: true + uses: ./.github/workflows/package-debian.yml From 1df011bb2b52254dc6c720bec526c26561b456ba Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Tue, 28 Apr 2026 15:13:33 +0800 Subject: [PATCH 04/17] Improve correctness of generateKey error Previously, the only error generateKey would throw as SyntaxError. This commit adds validation to the input so that the correct error can be returned. This helps a couple thousands of WPT tests to pass, e.g. /WebCryptoAPI/generateKey/failures_AES-CBC.https.any.html Goes from 210 / 775 to 775/775. This does not add more crypto capabilities / algos, just validation of the provided parameters. --- src/browser/tests/crypto.html | 129 ++++++++++++++++++++++++ src/browser/webapi/DOMException.zig | 12 ++- src/browser/webapi/SubtleCrypto.zig | 100 +++++++++++++++--- src/browser/webapi/crypto/AES.zig | 70 +++++++++++++ src/browser/webapi/crypto/EC.zig | 66 ++++++++++++ src/browser/webapi/crypto/HMAC.zig | 32 +++--- src/browser/webapi/crypto/RSA.zig | 85 ++++++++++++++++ src/browser/webapi/crypto/algorithm.zig | 25 ++++- 8 files changed, 484 insertions(+), 35 deletions(-) create mode 100644 src/browser/webapi/crypto/AES.zig create mode 100644 src/browser/webapi/crypto/EC.zig create mode 100644 src/browser/webapi/crypto/RSA.zig diff --git a/src/browser/tests/crypto.html b/src/browser/tests/crypto.html index c584cd84..59d6522e 100644 --- a/src/browser/tests/crypto.html +++ b/src/browser/tests/crypto.html @@ -120,6 +120,135 @@ }); + + + + + + + + + + + + + + + + diff --git a/src/browser/webapi/Node.zig b/src/browser/webapi/Node.zig index 1c69fae4..b1e40062 100644 --- a/src/browser/webapi/Node.zig +++ b/src/browser/webapi/Node.zig @@ -763,6 +763,7 @@ const CloneError = error{ NotImplemented, InvalidCharacterError, CloneError, + Idna, IFrameLoadError, TooManyContexts, LinkLoadError, diff --git a/src/sys/idna.zig b/src/sys/idna.zig new file mode 100644 index 00000000..368928e5 --- /dev/null +++ b/src/sys/idna.zig @@ -0,0 +1,76 @@ +// Copyright (C) 2023-2026 Lightpanda (Selecy SAS) +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +const std = @import("std"); + +const c = @cImport({ + @cInclude("idn2.h"); +}); + +const Allocator = std.mem.Allocator; +pub const Error = error{Idna} || Allocator.Error; + +/// True if `host` contains any non-ASCII byte and therefore needs IDNA +/// processing. Pure-ASCII hostnames are returned unchanged by `toAscii`, +/// so callers can use this as a fast path to skip the C call entirely. +pub fn needsAscii(host: []const u8) bool { + for (host) |byte| { + if (byte >= 0x80) { + return true; + } + } + return false; +} + +/// Convert a UTF-8 hostname to its ASCII (Punycode) form per UTS#46 +/// IDNA 2008 with non-transitional processing — the algorithm WHATWG URL +/// invokes as "domain to ASCII". Returns an allocator-owned slice. +pub fn toAscii(allocator: Allocator, host: []const u8) Error![]u8 { + const host_z = try allocator.dupeZ(u8, host); + defer allocator.free(host_z); + + var out_ptr: [*c]u8 = undefined; + const flags: c_int = c.IDN2_NFC_INPUT | c.IDN2_NONTRANSITIONAL; + const rc = c.idn2_to_ascii_8z(host_z.ptr, &out_ptr, flags); + if (rc != c.IDN2_OK) { + return error.Idna; + } + defer c.idn2_free(out_ptr); + + return try allocator.dupe(u8, std.mem.span(@as([*:0]const u8, @ptrCast(out_ptr)))); +} + +const testing = @import("../testing.zig"); + +test "idna: ASCII passthrough" { + try testing.expectEqual(false, needsAscii("example.com")); + const out = try toAscii(testing.allocator, "example.com"); + defer testing.allocator.free(out); + try testing.expectString("example.com", out); +} + +test "idna: non-ASCII to punycode" { + try testing.expectEqual(true, needsAscii("räksmörgås.se")); + const out = try toAscii(testing.allocator, "räksmörgås.se"); + defer testing.allocator.free(out); + try testing.expectString("xn--rksmrgs-5wao1o.se", out); +} + +test "idna: German sharp s with non-transitional processing" { + // UTS#46 non-transitional preserves ß rather than mapping to ss. + const out = try toAscii(testing.allocator, "faß.de"); + defer testing.allocator.free(out); + try testing.expectString("xn--fa-hia.de", out); +} diff --git a/vendor/libidn2/config.h b/vendor/libidn2/config.h new file mode 100644 index 00000000..5ff0d577 --- /dev/null +++ b/vendor/libidn2/config.h @@ -0,0 +1,1907 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Witness that has been included. */ +#define _GL_CONFIG_H_INCLUDED 1 + + +/* Define to the number of bits in type 'ptrdiff_t'. */ +/* #undef BITSIZEOF_PTRDIFF_T */ + +/* Define to the number of bits in type 'sig_atomic_t'. */ +/* #undef BITSIZEOF_SIG_ATOMIC_T */ + +/* Define to the number of bits in type 'size_t'. */ +/* #undef BITSIZEOF_SIZE_T */ + +/* Define to the number of bits in type 'wchar_t'. */ +/* #undef BITSIZEOF_WCHAR_T */ + +/* Define to the number of bits in type 'wint_t'. */ +/* #undef BITSIZEOF_WINT_T */ + +/* Define to 1 if using 'alloca.c'. */ +/* #undef C_ALLOCA */ + +/* Define to 1 if // is a file system root distinct from /. */ +/* #undef DOUBLE_SLASH_IS_DISTINCT_ROOT */ + +/* Define to 1 if translation of program messages to the user's native + language is requested. */ +/* #undef ENABLE_NLS */ + +/* Define this to 1 if F_DUPFD behavior does not match POSIX */ +/* #undef FCNTL_DUPFD_BUGGY */ + +/* Define to a C preprocessor expression that evaluates to 1 or 0, depending + whether the gnulib module close shall be considered present. */ +#define GNULIB_CLOSE 1 + +/* Define to a C preprocessor expression that evaluates to 1 or 0, depending + whether the gnulib module fscanf shall be considered present. */ +#define GNULIB_FSCANF 1 + +/* Define to a C preprocessor expression that evaluates to 1 or 0, depending + whether the gnulib module fstat shall be considered present. */ +#define GNULIB_FSTAT 1 + +/* Define to the directory where to find the localizations of the translation + domain 'gnulib', as a C string. */ +#define GNULIB_LOCALEDIR "/usr/local/share/locale" + +/* Define to a C preprocessor expression that evaluates to 1 or 0, depending + whether the gnulib module msvc-nothrow shall be considered present. */ +#define GNULIB_MSVC_NOTHROW 1 + +/* Disable VLA usage in gettext.h. */ +#define GNULIB_NO_VLA 1 + +/* Define to 1 if printf and friends should be labeled with attribute + "__gnu_printf__" instead of "__printf__" */ +/* #undef GNULIB_PRINTF_ATTRIBUTE_FLAVOR_GNU */ + +/* Define to a C preprocessor expression that evaluates to 1 or 0, depending + whether the gnulib module scanf shall be considered present. */ +#define GNULIB_SCANF 1 + +/* Define to a C preprocessor expression that evaluates to 1 or 0, depending + whether the gnulib module stat shall be considered present. */ +#define GNULIB_STAT 1 + +/* Define to a C preprocessor expression that evaluates to 1 or 0, depending + whether the gnulib module strerror shall be considered present. */ +#define GNULIB_STRERROR 1 + +/* Define to 1 when the gnulib module cloexec should be tested. */ +#define GNULIB_TEST_CLOEXEC 1 + +/* Define to 1 when the gnulib module close should be tested. */ +#define GNULIB_TEST_CLOSE 1 + +/* Define to 1 when the gnulib module dup2 should be tested. */ +#define GNULIB_TEST_DUP2 1 + +/* Define to 1 when the gnulib module fcntl should be tested. */ +#define GNULIB_TEST_FCNTL 1 + +/* Define to 1 when the gnulib module fgetc should be tested. */ +#define GNULIB_TEST_FGETC 1 + +/* Define to 1 when the gnulib module fgets should be tested. */ +#define GNULIB_TEST_FGETS 1 + +/* Define to 1 when the gnulib module fprintf should be tested. */ +#define GNULIB_TEST_FPRINTF 1 + +/* Define to 1 when the gnulib module fputc should be tested. */ +#define GNULIB_TEST_FPUTC 1 + +/* Define to 1 when the gnulib module fputs should be tested. */ +#define GNULIB_TEST_FPUTS 1 + +/* Define to 1 when the gnulib module fread should be tested. */ +#define GNULIB_TEST_FREAD 1 + +/* Define to 1 when the gnulib module free-posix should be tested. */ +#define GNULIB_TEST_FREE_POSIX 1 + +/* Define to 1 when the gnulib module fscanf should be tested. */ +#define GNULIB_TEST_FSCANF 1 + +/* Define to 1 when the gnulib module fstat should be tested. */ +#define GNULIB_TEST_FSTAT 1 + +/* Define to 1 when the gnulib module fwrite should be tested. */ +#define GNULIB_TEST_FWRITE 1 + +/* Define to 1 when the gnulib module getc should be tested. */ +#define GNULIB_TEST_GETC 1 + +/* Define to 1 when the gnulib module getchar should be tested. */ +#define GNULIB_TEST_GETCHAR 1 + +/* Define to 1 when the gnulib module getdelim should be tested. */ +#define GNULIB_TEST_GETDELIM 1 + +/* Define to 1 when the gnulib module getdtablesize should be tested. */ +#define GNULIB_TEST_GETDTABLESIZE 1 + +/* Define to 1 when the gnulib module getline should be tested. */ +#define GNULIB_TEST_GETLINE 1 + +/* Define to 1 when the gnulib module getopt-posix should be tested. */ +#define GNULIB_TEST_GETOPT_POSIX 1 + +/* Define to 1 when the gnulib module getprogname should be tested. */ +#define GNULIB_TEST_GETPROGNAME 1 + +/* Define to 1 when the gnulib module open should be tested. */ +#define GNULIB_TEST_OPEN 1 + +/* Define to 1 when the gnulib module printf should be tested. */ +#define GNULIB_TEST_PRINTF 1 + +/* Define to 1 when the gnulib module putc should be tested. */ +#define GNULIB_TEST_PUTC 1 + +/* Define to 1 when the gnulib module putchar should be tested. */ +#define GNULIB_TEST_PUTCHAR 1 + +/* Define to 1 when the gnulib module puts should be tested. */ +#define GNULIB_TEST_PUTS 1 + +/* Define to 1 when the gnulib module rawmemchr should be tested. */ +#define GNULIB_TEST_RAWMEMCHR 1 + +/* Define to 1 when the gnulib module scanf should be tested. */ +#define GNULIB_TEST_SCANF 1 + +/* Define to 1 when the gnulib module stat should be tested. */ +#define GNULIB_TEST_STAT 1 + +/* Define to 1 when the gnulib module strchrnul should be tested. */ +#define GNULIB_TEST_STRCHRNUL 1 + +/* Define to 1 when the gnulib module strerror should be tested. */ +#define GNULIB_TEST_STRERROR 1 + +/* Define to 1 when the gnulib module strverscmp should be tested. */ +#define GNULIB_TEST_STRVERSCMP 1 + +/* Define to 1 when the gnulib module uninorm/u32-normalize should be tested. + */ +#define GNULIB_TEST_UNINORM_U32_NORMALIZE 1 + +/* Define to 1 when the gnulib module vfprintf should be tested. */ +#define GNULIB_TEST_VFPRINTF 1 + +/* Define to 1 when the gnulib module vprintf should be tested. */ +#define GNULIB_TEST_VPRINTF 1 + +/* Define to a C preprocessor expression that evaluates to 1 or 0, depending + whether the gnulib module unistr/u32-mbtouc-unsafe shall be considered + present. */ +#define GNULIB_UNISTR_U32_MBTOUC_UNSAFE 1 + +/* Define to a C preprocessor expression that evaluates to 1 or 0, depending + whether the gnulib module unistr/u32-uctomb shall be considered present. */ +#define GNULIB_UNISTR_U32_UCTOMB 1 + +/* Define to a C preprocessor expression that evaluates to 1 or 0, depending + whether the gnulib module unistr/u8-mbtouc shall be considered present. */ +#define GNULIB_UNISTR_U8_MBTOUC 1 + +/* Define to a C preprocessor expression that evaluates to 1 or 0, depending + whether the gnulib module unistr/u8-mbtoucr shall be considered present. */ +#define GNULIB_UNISTR_U8_MBTOUCR 1 + +/* Define to a C preprocessor expression that evaluates to 1 or 0, depending + whether the gnulib module unistr/u8-mbtouc-unsafe shall be considered + present. */ +#define GNULIB_UNISTR_U8_MBTOUC_UNSAFE 1 + +/* Define to a C preprocessor expression that evaluates to 1 or 0, depending + whether the gnulib module unistr/u8-uctomb shall be considered present. */ +#define GNULIB_UNISTR_U8_UCTOMB 1 + +/* Define to 1 if you have 'alloca' after including , a header that + may be supplied by this distribution. */ +#define HAVE_ALLOCA 1 + +/* Define to 1 if works. */ +#define HAVE_ALLOCA_H 1 + +/* Define to 1 if you have the Mac OS X function CFLocaleCopyCurrent in the + CoreFoundation framework. */ +#define HAVE_CFLOCALECOPYCURRENT 1 + +/* Define to 1 if you have the Mac OS X function CFPreferencesCopyAppValue in + the CoreFoundation framework. */ +#define HAVE_CFPREFERENCESCOPYAPPVALUE 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_CRTDEFS_H */ + +/* Define to 1 if bool, true and false work as per C2023. */ +/* #undef HAVE_C_BOOL */ + +/* Define to 1 if the static_assert keyword works. */ +/* #undef HAVE_C_STATIC_ASSERT */ + +/* Define to 1 if C supports variable-length arrays. */ +#define HAVE_C_VARARRAYS 1 + +/* Define if the GNU dcgettext() function is already present or preinstalled. + */ +/* #undef HAVE_DCGETTEXT */ + +/* Define to 1 if you have the declaration of `ecvt', and to 0 if you don't. + */ +#define HAVE_DECL_ECVT 1 + +/* Define to 1 if you have the declaration of `execvpe', and to 0 if you + don't. */ +#define HAVE_DECL_EXECVPE 0 + +/* Define to 1 if you have the declaration of `fcloseall', and to 0 if you + don't. */ +#define HAVE_DECL_FCLOSEALL 0 + +/* Define to 1 if you have the declaration of `fcvt', and to 0 if you don't. + */ +#define HAVE_DECL_FCVT 1 + +/* Define to 1 if you have the declaration of `gcvt', and to 0 if you don't. + */ +#define HAVE_DECL_GCVT 1 + +/* Define to 1 if you have the declaration of `getc_unlocked', and to 0 if you + don't. */ +#define HAVE_DECL_GETC_UNLOCKED 1 + +/* Define to 1 if you have the declaration of `getdelim', and to 0 if you + don't. */ +#define HAVE_DECL_GETDELIM 1 + +/* Define to 1 if you have the declaration of `getdtablesize', and to 0 if you + don't. */ +#define HAVE_DECL_GETDTABLESIZE 1 + +/* Define to 1 if you have the declaration of `getline', and to 0 if you + don't. */ +#define HAVE_DECL_GETLINE 1 + +/* Define to 1 if you have the declaration of `getw', and to 0 if you don't. + */ +#define HAVE_DECL_GETW 1 + +/* Define to 1 if you have the declaration of `program_invocation_name', and + to 0 if you don't. */ +#define HAVE_DECL_PROGRAM_INVOCATION_NAME 0 + +/* Define to 1 if you have the declaration of `program_invocation_short_name', + and to 0 if you don't. */ +#define HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME 0 + +/* Define to 1 if you have the declaration of `putw', and to 0 if you don't. + */ +#define HAVE_DECL_PUTW 1 + +/* Define to 1 if you have the declaration of `strerror_r', and to 0 if you + don't. */ +#define HAVE_DECL_STRERROR_R 1 + +/* Define to 1 if you have the declaration of `wcsdup', and to 0 if you don't. + */ +#define HAVE_DECL_WCSDUP 1 + +/* Define to 1 if you have the declaration of `__argv', and to 0 if you don't. + */ +/* #undef HAVE_DECL___ARGV */ + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the `error' function. */ +/* #undef HAVE_ERROR */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_ERROR_H */ + +/* Define to 1 if you have the `fcntl' function. */ +#define HAVE_FCNTL 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_FEATURES_H */ + +/* Define to 1 if you have the `flockfile' function. */ +#define HAVE_FLOCKFILE 1 + +/* Define if the 'free' function is guaranteed to preserve errno. */ +/* #undef HAVE_FREE_POSIX */ + +/* Define to 1 if you have the `funlockfile' function. */ +#define HAVE_FUNLOCKFILE 1 + +/* Define to 1 if you have the `getdelim' function. */ +#define HAVE_GETDELIM 1 + +/* Define to 1 if you have the `getdtablesize' function. */ +#define HAVE_GETDTABLESIZE 1 + +/* Define to 1 if you have the `getexecname' function. */ +/* #undef HAVE_GETEXECNAME */ + +/* Define to 1 if you have the `getline' function. */ +#define HAVE_GETLINE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_GETOPT_H 1 + +/* Define to 1 if you have the `getopt_long_only' function. */ +#define HAVE_GETOPT_LONG_ONLY 1 + +/* Define to 1 if you have the `getprogname' function. */ +#define HAVE_GETPROGNAME 1 + +/* Define if the GNU gettext() function is already present or preinstalled. */ +/* #undef HAVE_GETTEXT */ + +/* Define if you have the iconv() function and it works. */ +/* #undef HAVE_ICONV */ + +/* Define to 1 if you have the header file. */ +#define HAVE_ICONV_H 1 + +/* Define to 1 if the compiler supports one of the keywords 'inline', + '__inline__', '__inline' and effectively inlines functions marked as such. + */ +#define HAVE_INLINE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define if you have and nl_langinfo(CODESET). */ +#define HAVE_LANGINFO_CODESET 1 + +/* Define if you have the libunistring library. */ +/* #undef HAVE_LIBUNISTRING */ + +/* Define to 1 if you have the header file. */ +#define HAVE_LIMITS_H 1 + +/* Define to 1 if the system has the type 'long long int'. */ +#define HAVE_LONG_LONG_INT 1 + +/* Define to 1 if you have the `lstat' function. */ +#define HAVE_LSTAT 1 + +/* Define to 1 if malloc (0) returns nonnull. */ +#define HAVE_MALLOC_0_NONNULL 1 + +/* Define if malloc, realloc, and calloc set errno on allocation failure. */ +#define HAVE_MALLOC_POSIX 1 + +/* Define to 1 if malloc-like functions do not allocate objects larger than + PTRDIFF_MAX bytes. */ +#define HAVE_MALLOC_PTRDIFF 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_MINIX_CONFIG_H */ + +/* Define to 1 on MSVC platforms that have the "invalid parameter handler" + concept. */ +/* #undef HAVE_MSVC_INVALID_PARAMETER_HANDLER */ + +/* Define to 1 if you have the `rawmemchr' function. */ +/* #undef HAVE_RAWMEMCHR */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SDKDDKVER_H */ + +/* Define to 1 if you have the `setdtablesize' function. */ +/* #undef HAVE_SETDTABLESIZE */ + +/* Define to 1 if 'sig_atomic_t' is a signed integer type. */ +/* #undef HAVE_SIGNED_SIG_ATOMIC_T */ + +/* Define to 1 if 'wchar_t' is a signed integer type. */ +/* #undef HAVE_SIGNED_WCHAR_T */ + +/* Define to 1 if 'wint_t' is a signed integer type. */ +/* #undef HAVE_SIGNED_WINT_T */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDBOOL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDCKDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDIO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the `strchrnul' function. */ +#define HAVE_STRCHRNUL 1 + +/* Define if you have `strerror_r'. */ +#define HAVE_STRERROR_R 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if `st_atimensec' is a member of `struct stat'. */ +/* #undef HAVE_STRUCT_STAT_ST_ATIMENSEC */ + +/* Define to 1 if `st_atimespec.tv_nsec' is a member of `struct stat'. */ +#define HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC 1 + +/* Define to 1 if `st_atim.st__tim.tv_nsec' is a member of `struct stat'. */ +/* #undef HAVE_STRUCT_STAT_ST_ATIM_ST__TIM_TV_NSEC */ + +/* Define to 1 if `st_atim.tv_nsec' is a member of `struct stat'. */ +/* #undef HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC */ + +/* Define to 1 if `st_birthtimensec' is a member of `struct stat'. */ +/* #undef HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC */ + +/* Define to 1 if `st_birthtimespec.tv_nsec' is a member of `struct stat'. */ +#define HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC 1 + +/* Define to 1 if `st_birthtim.tv_nsec' is a member of `struct stat'. */ +/* #undef HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC */ + +/* Define to 1 if you have the `strverscmp' function. */ +/* #undef HAVE_STRVERSCMP */ + +/* Define to 1 if you have the `symlink' function. */ +#define HAVE_SYMLINK 1 + +/* The toolchain supports aliases and .symver. */ +/* #undef HAVE_SYMVER_ALIAS_SUPPORT */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_BITYPES_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_INTTYPES_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SOCKET_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_UNISTRING_WOE32DLL_H */ + +/* Define to 1 if the system has the type 'unsigned long long int'. */ +#define HAVE_UNSIGNED_LONG_LONG_INT 1 + +/* Define if you have a global __progname variable */ +/* #undef HAVE_VAR___PROGNAME */ + +/* Define to 1 or 0, depending whether the compiler supports simple visibility + declarations. */ +#define HAVE_VISIBILITY 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_WCHAR_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_WINSOCK2_H */ + +/* Define if you have the 'wint_t' type. */ +#define HAVE_WINT_T 1 + +/* Define to 1 if O_NOATIME works. */ +#define HAVE_WORKING_O_NOATIME 1 + +/* Define to 1 if O_NOFOLLOW works. */ +#define HAVE_WORKING_O_NOFOLLOW 1 + +/* Define to 1 if you have the `_set_invalid_parameter_handler' function. */ +/* #undef HAVE__SET_INVALID_PARAMETER_HANDLER */ + +/* Define to 1 if ctype.h defines __header_inline. */ +#define HAVE___HEADER_INLINE 1 + +/* Please see the Gnulib manual for how to use these macros. + + Suppress extern inline with HP-UX cc, as it appears to be broken; see + . + + Suppress extern inline with Sun C in standards-conformance mode, as it + mishandles inline functions that call each other. E.g., for 'inline void f + (void) { } inline void g (void) { f (); }', c99 incorrectly complains + 'reference to static identifier "f" in extern inline function'. + This bug was observed with Oracle Developer Studio 12.6 + (Sun C 5.15 SunOS_sparc 2017/05/30). + + Suppress extern inline (with or without __attribute__ ((__gnu_inline__))) + on configurations that mistakenly use 'static inline' to implement + functions or macros in standard C headers like . For example, + if isdigit is mistakenly implemented via a static inline function, + a program containing an extern inline function that calls isdigit + may not work since the C standard prohibits extern inline functions + from calling static functions (ISO C 99 section 6.7.4.(3). + This bug is known to occur on: + + OS X 10.8 and earlier; see: + https://lists.gnu.org/r/bug-gnulib/2012-12/msg00023.html + + DragonFly; see + http://muscles.dragonflybsd.org/bulk/clang-master-potential/20141111_102002/logs/ah-tty-0.3.12.log + + FreeBSD; see: + https://lists.gnu.org/r/bug-gnulib/2014-07/msg00104.html + + OS X 10.9 has a macro __header_inline indicating the bug is fixed for C and + for clang but remains for g++; see . + Assume DragonFly and FreeBSD will be similar. + + GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99 + inline semantics, unless -fgnu89-inline is used. It defines a macro + __GNUC_STDC_INLINE__ to indicate this situation or a macro + __GNUC_GNU_INLINE__ to indicate the opposite situation. + GCC 4.2 with -std=c99 or -std=gnu99 implements the GNU C inline + semantics but warns, unless -fgnu89-inline is used: + warning: C99 inline functions are not supported; using GNU89 + warning: to disable this warning use -fgnu89-inline or the gnu_inline function attribute + It defines a macro __GNUC_GNU_INLINE__ to indicate this situation. + */ +#if (((defined __APPLE__ && defined __MACH__) \ + || defined __DragonFly__ || defined __FreeBSD__) \ + && (defined HAVE___HEADER_INLINE \ + ? (defined __cplusplus && defined __GNUC_STDC_INLINE__ \ + && ! defined __clang__) \ + : ((! defined _DONT_USE_CTYPE_INLINE_ \ + && (defined __GNUC__ || defined __cplusplus)) \ + || (defined _FORTIFY_SOURCE && 0 < _FORTIFY_SOURCE \ + && defined __GNUC__ && ! defined __cplusplus)))) +# define _GL_EXTERN_INLINE_STDHEADER_BUG +#endif +#if ((__GNUC__ \ + ? (defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__ \ + && !defined __PCC__) \ + : (199901L <= __STDC_VERSION__ \ + && !defined __HP_cc \ + && !defined __PGI \ + && !(defined __SUNPRO_C && __STDC__))) \ + && !defined _GL_EXTERN_INLINE_STDHEADER_BUG) +# define _GL_INLINE inline +# define _GL_EXTERN_INLINE extern inline +# define _GL_EXTERN_INLINE_IN_USE +#elif (2 < __GNUC__ + (7 <= __GNUC_MINOR__) && !defined __STRICT_ANSI__ \ + && !defined __PCC__ \ + && !defined _GL_EXTERN_INLINE_STDHEADER_BUG) +# if defined __GNUC_GNU_INLINE__ && __GNUC_GNU_INLINE__ + /* __gnu_inline__ suppresses a GCC 4.2 diagnostic. */ +# define _GL_INLINE extern inline __attribute__ ((__gnu_inline__)) +# else +# define _GL_INLINE extern inline +# endif +# define _GL_EXTERN_INLINE extern +# define _GL_EXTERN_INLINE_IN_USE +#else +# define _GL_INLINE _GL_UNUSED static +# define _GL_EXTERN_INLINE _GL_UNUSED static +#endif + +/* In GCC 4.6 (inclusive) to 5.1 (exclusive), + suppress bogus "no previous prototype for 'FOO'" + and "no previous declaration for 'FOO'" diagnostics, + when FOO is an inline function in the header; see + and + . */ +#if __GNUC__ == 4 && 6 <= __GNUC_MINOR__ +# if defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__ +# define _GL_INLINE_HEADER_CONST_PRAGMA +# else +# define _GL_INLINE_HEADER_CONST_PRAGMA \ + _Pragma ("GCC diagnostic ignored \"-Wsuggest-attribute=const\"") +# endif +# define _GL_INLINE_HEADER_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wmissing-prototypes\"") \ + _Pragma ("GCC diagnostic ignored \"-Wmissing-declarations\"") \ + _GL_INLINE_HEADER_CONST_PRAGMA +# define _GL_INLINE_HEADER_END \ + _Pragma ("GCC diagnostic pop") +#else +# define _GL_INLINE_HEADER_BEGIN +# define _GL_INLINE_HEADER_END +#endif + +/* Define to 1 if the compiler supports the keyword '__inline'. */ +#define HAVE___INLINE 1 + +/* Define as const if the declaration of iconv() needs const. */ +#define ICONV_CONST + +/* Define to a symbolic name denoting the flavor of iconv_open() + implementation. */ +/* #undef ICONV_FLAVOR */ + +/* Define to the sub-directory where libtool stores uninstalled libraries. */ +#define LT_OBJDIR ".libs/" + +/* Use GNU style printf and scanf. */ +#ifndef __USE_MINGW_ANSI_STDIO +# define __USE_MINGW_ANSI_STDIO 1 +#endif + + +/* Define to 1 on musl libc. */ +/* #undef MUSL_LIBC */ + +/* Define to 1 if open() fails to recognize a trailing slash. */ +/* #undef OPEN_TRAILING_SLASH_BUG */ + +/* Name of package */ +#define PACKAGE "libidn2" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "help-libidn@gnu.org" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "Libidn2" + +/* String identifying the packager of this software */ +/* #undef PACKAGE_PACKAGER */ + +/* Packager info for bug reports (URL/e-mail/...) */ +/* #undef PACKAGE_PACKAGER_BUG_REPORTS */ + +/* Packager-specific version information */ +/* #undef PACKAGE_PACKAGER_VERSION */ + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "Libidn2 2.3.8" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "libidn2" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "https://www.gnu.org/software/libidn/#libidn2" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "2.3.8" + +/* Define to the type that is the result of default argument promotions of + type mode_t. */ +#define PROMOTED_MODE_T int + +/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type + 'ptrdiff_t'. */ +/* #undef PTRDIFF_T_SUFFIX */ + +/* Define to 1 if stat needs help when passed a file name with a trailing + slash */ +/* #undef REPLACE_FUNC_STAT_FILE */ + +/* Define to 1 if strerror(0) does not return a message implying success. */ +#define REPLACE_STRERROR_0 1 + +/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type + 'sig_atomic_t'. */ +/* #undef SIG_ATOMIC_T_SUFFIX */ + +/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type + 'size_t'. */ +/* #undef SIZE_T_SUFFIX */ + +/* If using the C implementation of alloca, define if you know the + direction of stack growth for your system; otherwise it will be + automatically deduced at runtime. + STACK_DIRECTION > 0 => grows toward higher addresses + STACK_DIRECTION < 0 => grows toward lower addresses + STACK_DIRECTION = 0 => direction of growth unknown */ +/* #undef STACK_DIRECTION */ + +/* Define to 1 if the `S_IS*' macros in do not work properly. */ +/* #undef STAT_MACROS_BROKEN */ + +/* Define to 1 if all of the C90 standard headers exist (not just the ones + required in a freestanding environment). This macro is provided for + backward compatibility; new code need not use it. */ +#define STDC_HEADERS 1 + +/* Define to 1 if strerror_r returns char *. */ +/* #undef STRERROR_R_CHAR_P */ + +/* Define to 1 if the type of the st_atim member of a struct stat is struct + timespec. */ +/* #undef TYPEOF_STRUCT_STAT_ST_ATIM_IS_STRUCT_TIMESPEC */ + +/* Define to enable the declarations of ISO C 23 Annex K types and functions. */ +#if !(defined __STDC_WANT_LIB_EXT1__ && __STDC_WANT_LIB_EXT1__) +#undef/**/__STDC_WANT_LIB_EXT1__ +#define __STDC_WANT_LIB_EXT1__ 1 +#endif + + +/* Enable extensions on AIX 3, Interix. */ +#ifndef _ALL_SOURCE +# define _ALL_SOURCE 1 +#endif +/* Enable general extensions on macOS. */ +#ifndef _DARWIN_C_SOURCE +# define _DARWIN_C_SOURCE 1 +#endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# define __EXTENSIONS__ 1 +#endif +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif +/* Enable X/Open compliant socket functions that do not require linking + with -lxnet on HP-UX 11.11. */ +#ifndef _HPUX_ALT_XOPEN_SOCKET_API +# define _HPUX_ALT_XOPEN_SOCKET_API 1 +#endif +/* Identify the host operating system as Minix. + This macro does not affect the system headers' behavior. + A future release of Autoconf may stop defining this macro. */ +#ifndef _MINIX +/* # undef _MINIX */ +#endif +/* Enable general extensions on NetBSD. + Enable NetBSD compatibility extensions on Minix. */ +#ifndef _NETBSD_SOURCE +# define _NETBSD_SOURCE 1 +#endif +/* Enable OpenBSD compatibility extensions on NetBSD. + Oddly enough, this does nothing on OpenBSD. */ +#ifndef _OPENBSD_SOURCE +# define _OPENBSD_SOURCE 1 +#endif +/* Define to 1 if needed for POSIX-compatible behavior. */ +#ifndef _POSIX_SOURCE +/* # undef _POSIX_SOURCE */ +#endif +/* Define to 2 if needed for POSIX-compatible behavior. */ +#ifndef _POSIX_1_SOURCE +/* # undef _POSIX_1_SOURCE */ +#endif +/* Enable POSIX-compatible threading on Solaris. */ +#ifndef _POSIX_PTHREAD_SEMANTICS +# define _POSIX_PTHREAD_SEMANTICS 1 +#endif +/* Enable extensions specified by ISO/IEC TS 18661-5:2014. */ +#ifndef __STDC_WANT_IEC_60559_ATTRIBS_EXT__ +# define __STDC_WANT_IEC_60559_ATTRIBS_EXT__ 1 +#endif +/* Enable extensions specified by ISO/IEC TS 18661-1:2014. */ +#ifndef __STDC_WANT_IEC_60559_BFP_EXT__ +# define __STDC_WANT_IEC_60559_BFP_EXT__ 1 +#endif +/* Enable extensions specified by ISO/IEC TS 18661-2:2015. */ +#ifndef __STDC_WANT_IEC_60559_DFP_EXT__ +# define __STDC_WANT_IEC_60559_DFP_EXT__ 1 +#endif +/* Enable extensions specified by C23 Annex F. */ +#ifndef __STDC_WANT_IEC_60559_EXT__ +# define __STDC_WANT_IEC_60559_EXT__ 1 +#endif +/* Enable extensions specified by ISO/IEC TS 18661-4:2015. */ +#ifndef __STDC_WANT_IEC_60559_FUNCS_EXT__ +# define __STDC_WANT_IEC_60559_FUNCS_EXT__ 1 +#endif +/* Enable extensions specified by C23 Annex H and ISO/IEC TS 18661-3:2015. */ +#ifndef __STDC_WANT_IEC_60559_TYPES_EXT__ +# define __STDC_WANT_IEC_60559_TYPES_EXT__ 1 +#endif +/* Enable extensions specified by ISO/IEC TR 24731-2:2010. */ +#ifndef __STDC_WANT_LIB_EXT2__ +# define __STDC_WANT_LIB_EXT2__ 1 +#endif +/* Enable extensions specified by ISO/IEC 24747:2009. */ +#ifndef __STDC_WANT_MATH_SPEC_FUNCS__ +# define __STDC_WANT_MATH_SPEC_FUNCS__ 1 +#endif +/* Enable extensions on HP NonStop. */ +#ifndef _TANDEM_SOURCE +# define _TANDEM_SOURCE 1 +#endif +/* Enable X/Open extensions. Define to 500 only if necessary + to make mbstate_t available. */ +#ifndef _XOPEN_SOURCE +/* # undef _XOPEN_SOURCE */ +#endif + + +/* Version number of package */ +#define VERSION "2.3.8" + +/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type + 'wchar_t'. */ +/* #undef WCHAR_T_SUFFIX */ + +/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type + 'wint_t'. */ +/* #undef WINT_T_SUFFIX */ + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ + +/* True if the compiler says it groks GNU C version MAJOR.MINOR. + Except that + - clang groks GNU C 4.2, even on Windows, where it does not define + __GNUC__. + - The OpenMandriva-modified clang compiler pretends that it groks + GNU C version 13.1, but it doesn't: It does not support + __attribute__ ((__malloc__ (f, i))), nor does it support + __attribute__ ((__warning__ (message))) on a function redeclaration. + - Users can make clang lie as well, through the -fgnuc-version option. */ +#if defined __GNUC__ && defined __GNUC_MINOR__ && !defined __clang__ +# define _GL_GNUC_PREREQ(major, minor) \ + ((major) < __GNUC__ + ((minor) <= __GNUC_MINOR__)) +#elif defined __clang__ + /* clang really only groks GNU C 4.2. */ +# define _GL_GNUC_PREREQ(major, minor) \ + ((major) < 4 + ((minor) <= 2)) +#else +# define _GL_GNUC_PREREQ(major, minor) 0 +#endif + + +/* Define to enable the declarations of ISO C 11 types and functions. */ +/* #undef _ISOC11_SOURCE */ + +/* Define to 1 on platforms where this makes off_t a 64-bit type. */ +/* #undef _LARGE_FILES */ + +/* Define so that AIX headers are more compatible with GNU/Linux. */ +#define _LINUX_SOURCE_COMPAT 1 + +/* The _Noreturn keyword of C11. */ +#ifndef _Noreturn +# if (defined __cplusplus \ + && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \ + || (defined _MSC_VER && 1900 <= _MSC_VER)) \ + && 0) + /* [[noreturn]] is not practically usable, because with it the syntax + extern _Noreturn void func (...); + would not be valid; such a declaration would only be valid with 'extern' + and '_Noreturn' swapped, or without the 'extern' keyword. However, some + AIX system header files and several gnulib header files use precisely + this syntax with 'extern'. */ +# define _Noreturn [[noreturn]] +# elif (defined __clang__ && __clang_major__ < 16 \ + && defined _GL_WORK_AROUND_LLVM_BUG_59792) + /* Compile with -D_GL_WORK_AROUND_LLVM_BUG_59792 to work around + that rare LLVM bug, though you may get many false-alarm warnings. */ +# define _Noreturn +# elif ((!defined __cplusplus || defined __clang__) \ + && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \ + || (!defined __STRICT_ANSI__ \ + && (_GL_GNUC_PREREQ (4, 7) \ + || (defined __apple_build_version__ \ + ? 6000000 <= __apple_build_version__ \ + : 3 < __clang_major__ + (5 <= __clang_minor__)))))) + /* _Noreturn works as-is. */ +# elif _GL_GNUC_PREREQ (2, 8) || defined __clang__ || 0x5110 <= __SUNPRO_C +# define _Noreturn __attribute__ ((__noreturn__)) +# elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0) +# define _Noreturn __declspec (noreturn) +# else +# define _Noreturn +# endif +#endif + + +/* Number of bits in time_t, on hosts where this is settable. */ +/* #undef _TIME_BITS */ + +/* For standard stat data types on VMS. */ +#define _USE_STD_STAT 1 + +/* Define to rpl_ if the getopt replacement functions and variables should be + used. */ +#define __GETOPT_PREFIX rpl_ + +/* Define to 1 on platforms where this makes time_t a 64-bit type. */ +/* #undef __MINGW_USE_VC2005_COMPAT */ + +/* Define to 1 if the system predates C++11. */ +/* #undef __STDC_CONSTANT_MACROS */ + +/* Define to 1 if the system predates C++11. */ +/* #undef __STDC_LIMIT_MACROS */ + +/* Define to 1 if C does not support variable-length arrays, and if the + compiler does not already define this. */ +/* #undef __STDC_NO_VLA__ */ + +/* The _GL_ASYNC_SAFE marker should be attached to functions that are + signal handlers (for signals other than SIGABRT, SIGPIPE) or can be + invoked from such signal handlers. Such functions have some restrictions: + * All functions that it calls should be marked _GL_ASYNC_SAFE as well, + or should be listed as async-signal-safe in POSIX + + section 2.4.3. Note that malloc(), sprintf(), and fwrite(), in + particular, are NOT async-signal-safe. + * All memory locations (variables and struct fields) that these functions + access must be marked 'volatile'. This holds for both read and write + accesses. Otherwise the compiler might optimize away stores to and + reads from such locations that occur in the program, depending on its + data flow analysis. For example, when the program contains a loop + that is intended to inspect a variable set from within a signal handler + while (!signal_occurred) + ; + the compiler is allowed to transform this into an endless loop if the + variable 'signal_occurred' is not declared 'volatile'. + Additionally, recall that: + * A signal handler should not modify errno (except if it is a handler + for a fatal signal and ends by raising the same signal again, thus + provoking the termination of the process). If it invokes a function + that may clobber errno, it needs to save and restore the value of + errno. */ +#define _GL_ASYNC_SAFE + + +/* Attributes. */ +/* Define _GL_HAS_ATTRIBUTE only once, because on FreeBSD, with gcc < 5, if + gets included once again after , __has_attribute(x) + expands to 0 always, and redefining _GL_HAS_ATTRIBUTE would turn off all + attributes. */ +#ifndef _GL_HAS_ATTRIBUTE +# if (defined __has_attribute \ + && (!defined __clang_minor__ \ + || (defined __apple_build_version__ \ + ? 7000000 <= __apple_build_version__ \ + : 5 <= __clang_major__))) +# define _GL_HAS_ATTRIBUTE(attr) __has_attribute (__##attr##__) +# else +# define _GL_HAS_ATTRIBUTE(attr) _GL_ATTR_##attr +# define _GL_ATTR_alloc_size _GL_GNUC_PREREQ (4, 3) +# define _GL_ATTR_always_inline _GL_GNUC_PREREQ (3, 2) +# define _GL_ATTR_artificial _GL_GNUC_PREREQ (4, 3) +# define _GL_ATTR_cold _GL_GNUC_PREREQ (4, 3) +# define _GL_ATTR_const _GL_GNUC_PREREQ (2, 95) +# define _GL_ATTR_deprecated _GL_GNUC_PREREQ (3, 1) +# define _GL_ATTR_diagnose_if 0 +# define _GL_ATTR_error _GL_GNUC_PREREQ (4, 3) +# define _GL_ATTR_externally_visible _GL_GNUC_PREREQ (4, 1) +# define _GL_ATTR_fallthrough _GL_GNUC_PREREQ (7, 0) +# define _GL_ATTR_format _GL_GNUC_PREREQ (2, 7) +# define _GL_ATTR_leaf _GL_GNUC_PREREQ (4, 6) +# define _GL_ATTR_malloc _GL_GNUC_PREREQ (3, 0) +# ifdef _ICC +# define _GL_ATTR_may_alias 0 +# else +# define _GL_ATTR_may_alias _GL_GNUC_PREREQ (3, 3) +# endif +# define _GL_ATTR_noinline _GL_GNUC_PREREQ (3, 1) +# define _GL_ATTR_nonnull _GL_GNUC_PREREQ (3, 3) +# define _GL_ATTR_nonstring _GL_GNUC_PREREQ (8, 0) +# define _GL_ATTR_nothrow _GL_GNUC_PREREQ (3, 3) +# define _GL_ATTR_packed _GL_GNUC_PREREQ (2, 7) +# define _GL_ATTR_pure _GL_GNUC_PREREQ (2, 96) +# define _GL_ATTR_reproducible 0 /* not yet supported, as of GCC 14 */ +# define _GL_ATTR_returns_nonnull _GL_GNUC_PREREQ (4, 9) +# define _GL_ATTR_sentinel _GL_GNUC_PREREQ (4, 0) +# define _GL_ATTR_unsequenced 0 /* not yet supported, as of GCC 14 */ +# define _GL_ATTR_unused _GL_GNUC_PREREQ (2, 7) +# define _GL_ATTR_warn_unused_result _GL_GNUC_PREREQ (3, 4) +# endif +#endif + +/* Use __has_c_attribute if available. However, do not use with + pre-C23 GCC, which can issue false positives if -Wpedantic. */ +#if (defined __has_c_attribute \ + && ! (_GL_GNUC_PREREQ (4, 6) \ + && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) <= 201710)) +# define _GL_HAVE___HAS_C_ATTRIBUTE 1 +#else +# define _GL_HAVE___HAS_C_ATTRIBUTE 0 +#endif + +/* Attributes in bracket syntax [[...]] vs. attributes in __attribute__((...)) + syntax, in function declarations. There are two problems here. + (Last tested with gcc/g++ 14 and clang/clang++ 18.) + + 1) We want that the _GL_ATTRIBUTE_* can be cumulated on the same declaration + in any order. + =========================== foo.c = foo.cc =========================== + __attribute__ ((__deprecated__)) [[__nodiscard__]] int bar1 (int); + [[__nodiscard__]] __attribute__ ((__deprecated__)) int bar2 (int); + ====================================================================== + This gives a syntax error + - in C mode with gcc + , and + - in C++ mode with clang++ version < 16, and + - in C++ mode, inside extern "C" {}, still in newer clang++ versions + . + */ +/* Define if, in a function declaration, the attributes in bracket syntax + [[...]] must come before the attributes in __attribute__((...)) syntax. + If this is defined, it is best to avoid the bracket syntax, so that the + various _GL_ATTRIBUTE_* can be cumulated on the same declaration in any + order. */ +#ifdef __cplusplus +# if defined __clang__ +# define _GL_BRACKET_BEFORE_ATTRIBUTE 1 +# endif +#else +# if defined __GNUC__ && !defined __clang__ +# define _GL_BRACKET_BEFORE_ATTRIBUTE 1 +# endif +#endif +/* + 2) We want that the _GL_ATTRIBUTE_* can be placed in a declaration + - without 'extern', in C as well as in C++, + - with 'extern', in C, + - with 'extern "C"', in C++ + in the same position. That is, we don't want to be forced to use a + macro which arranges for the attribute to come before 'extern' in + one case and after 'extern' in the other case, because such a macro + would make the source code of .h files pretty ugly. + =========================== foo.c = foo.cc =========================== + #ifdef __cplusplus + # define CC "C" + #else + # define CC + #endif + + #define ND [[__nodiscard__]] + #define WUR __attribute__((__warn_unused_result__)) + + #ifdef __cplusplus + extern "C" { + #endif + // gcc clang g++ clang++ + + ND int foo (int); + int ND foo (int); // warn error warn error + int foo ND (int); + int foo (int) ND; // warn error warn error + + WUR int foo (int); + int WUR foo (int); + int fo1 WUR (int); // error error error error + int foo (int) WUR; + + #ifdef __cplusplus + } + #endif + + // gcc clang g++ clang++ + + ND extern CC int foo (int); // error error + extern CC ND int foo (int); // error error + extern CC int ND foo (int); // warn error warn error + extern CC int foo ND (int); + extern CC int foo (int) ND; // warn error warn error + + WUR extern CC int foo (int); // warn + extern CC WUR int foo (int); + extern CC int WUR foo (int); + extern CC int foo WUR (int); // error error error error + extern CC int foo (int) WUR; + + ND EXTERN_C_FUNC int foo (int); // error error + EXTERN_C_FUNC ND int foo (int); + EXTERN_C_FUNC int ND foo (int); // warn error warn error + EXTERN_C_FUNC int foo ND (int); + EXTERN_C_FUNC int foo (int) ND; // warn error warn error + + WUR EXTERN_C_FUNC int foo (int); // warn + EXTERN_C_FUNC WUR int foo (int); + EXTERN_C_FUNC int WUR foo (int); + EXTERN_C_FUNC int fo2 WUR (int); // error error error error + EXTERN_C_FUNC int foo (int) WUR; + ====================================================================== + So, if we insist on using the 'extern' keyword ('extern CC' idiom): + * If _GL_ATTRIBUTE_* expands to bracket syntax [[...]] + in both C and C++, there is one available position: + - between the function name and the parameter list. + * If _GL_ATTRIBUTE_* expands to __attribute__((...)) syntax + in both C and C++, there are several available positions: + - before the return type, + - between return type and function name, + - at the end of the declaration. + * If _GL_ATTRIBUTE_* expands to bracket syntax [[...]] in C and to + __attribute__((...)) syntax in C++, there is no available position: + it would need to come before 'extern' in C but after 'extern "C"' + in C++. + * If _GL_ATTRIBUTE_* expands to __attribute__((...)) syntax in C and + to bracket syntax [[...]] in C++, there is one available position: + - before the return type. + Whereas, if we use the 'EXTERN_C_FUNC' idiom, which conditionally + omits the 'extern' keyword: + * If _GL_ATTRIBUTE_* expands to bracket syntax [[...]] + in both C and C++, there are two available positions: + - before the return type, + - between the function name and the parameter list. + * If _GL_ATTRIBUTE_* expands to __attribute__((...)) syntax + in both C and C++, there are several available positions: + - before the return type, + - between return type and function name, + - at the end of the declaration. + * If _GL_ATTRIBUTE_* expands to bracket syntax [[...]] in C and to + __attribute__((...)) syntax in C++, there is one available position: + - before the return type. + * If _GL_ATTRIBUTE_* expands to __attribute__((...)) syntax in C and + to bracket syntax [[...]] in C++, there is one available position: + - before the return type. + The best choice is therefore to use the 'EXTERN_C_FUNC' idiom and + put the attributes before the return type. This works regardless + to what the _GL_ATTRIBUTE_* macros expand. + */ + +/* Attributes in bracket syntax [[...]] vs. attributes in __attribute__((...)) + syntax, in static/inline function definitions. + + There are similar constraints as for function declarations. However, here, + we cannot omit the storage-class specifier. Therefore, the following rule + applies: + * The macros + _GL_ATTRIBUTE_CONST + _GL_ATTRIBUTE_DEPRECATED + _GL_ATTRIBUTE_MAYBE_UNUSED + _GL_ATTRIBUTE_NODISCARD + _GL_ATTRIBUTE_PURE + _GL_ATTRIBUTE_REPRODUCIBLE + _GL_ATTRIBUTE_UNSEQUENCED + which may expand to bracket syntax [[...]], must come first, before the + storage-class specifier. + * Other _GL_ATTRIBUTE_* macros, that expand to __attribute__((...)) syntax, + are better placed between the storage-class specifier and the return + type. + */ + +/* Attributes in bracket syntax [[...]] vs. attributes in __attribute__((...)) + syntax, in variable declarations. + + At which position can they be placed? + (Last tested with gcc/g++ 14 and clang/clang++ 18.) + + =========================== foo.c = foo.cc =========================== + #ifdef __cplusplus + # define CC "C" + #else + # define CC + #endif + + #define BD [[__deprecated__]] + #define AD __attribute__ ((__deprecated__)) + + // gcc clang g++ clang++ + + BD extern CC int var; // error error + extern CC BD int var; // error error + extern CC int BD var; // warn error warn error + extern CC int var BD; + + AD extern CC int var; // warn + extern CC AD int var; + extern CC int AD var; + extern CC int var AD; + + BD extern CC int z[]; // error error + extern CC BD int z[]; // error error + extern CC int BD z[]; // warn error warn error + extern CC int z1 BD []; + extern CC int z[] BD; // warn error error + + AD extern CC int z[]; // warn + extern CC AD int z[]; + extern CC int AD z[]; + extern CC int z2 AD []; // error error error error + extern CC int z[] AD; + ====================================================================== + + * For non-array variables, the only good position is after the variable name, + that is, at the end of the declaration. + * For array variables, you will need to distinguish C and C++: + - In C, before the 'extern' keyword. + - In C++, between the 'extern "C"' and the variable's type. + */ + +/* _GL_ATTRIBUTE_ALLOC_SIZE ((N)) declares that the Nth argument of the function + is the size of the returned memory block. + _GL_ATTRIBUTE_ALLOC_SIZE ((M, N)) declares that the Mth argument multiplied + by the Nth argument of the function is the size of the returned memory block. + */ +/* Applies to: functions, pointer to functions, function types. */ +#ifndef _GL_ATTRIBUTE_ALLOC_SIZE +# if _GL_HAS_ATTRIBUTE (alloc_size) +# define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args)) +# else +# define _GL_ATTRIBUTE_ALLOC_SIZE(args) +# endif +#endif + +/* _GL_ATTRIBUTE_ALWAYS_INLINE tells that the compiler should always inline the + function and report an error if it cannot do so. */ +/* Applies to: functions. */ +#ifndef _GL_ATTRIBUTE_ALWAYS_INLINE +# if _GL_HAS_ATTRIBUTE (always_inline) +# define _GL_ATTRIBUTE_ALWAYS_INLINE __attribute__ ((__always_inline__)) +# else +# define _GL_ATTRIBUTE_ALWAYS_INLINE +# endif +#endif + +/* _GL_ATTRIBUTE_ARTIFICIAL declares that the function is not important to show + in stack traces when debugging. The compiler should omit the function from + stack traces. */ +/* Applies to: functions. */ +#ifndef _GL_ATTRIBUTE_ARTIFICIAL +# if _GL_HAS_ATTRIBUTE (artificial) +# define _GL_ATTRIBUTE_ARTIFICIAL __attribute__ ((__artificial__)) +# else +# define _GL_ATTRIBUTE_ARTIFICIAL +# endif +#endif + +/* _GL_ATTRIBUTE_COLD declares that the function is rarely executed. */ +/* Applies to: functions. */ +/* Avoid __attribute__ ((cold)) on MinGW; see thread starting at + . + Also, Oracle Studio 12.6 requires 'cold' not '__cold__'. */ +#ifndef _GL_ATTRIBUTE_COLD +# if _GL_HAS_ATTRIBUTE (cold) && !defined __MINGW32__ +# ifndef __SUNPRO_C +# define _GL_ATTRIBUTE_COLD __attribute__ ((__cold__)) +# else +# define _GL_ATTRIBUTE_COLD __attribute__ ((cold)) +# endif +# else +# define _GL_ATTRIBUTE_COLD +# endif +#endif + +/* _GL_ATTRIBUTE_CONST declares: + It is OK for a compiler to move calls to the function and to omit + calls to the function if another call has the same arguments or the + result is not used. + This attribute is safe for a function that neither depends on + nor affects state, and always returns exactly once - + e.g., does not raise an exception, call longjmp, or loop forever. + (This attribute is stricter than _GL_ATTRIBUTE_PURE because the + function cannot observe state. It is stricter than + _GL_ATTRIBUTE_UNSEQUENCED because the function must return exactly + once and cannot depend on state addressed by its arguments.) */ +/* Applies to: functions. */ +#ifndef _GL_ATTRIBUTE_CONST +# if _GL_HAS_ATTRIBUTE (const) +# define _GL_ATTRIBUTE_CONST __attribute__ ((__const__)) +# else +# define _GL_ATTRIBUTE_CONST _GL_ATTRIBUTE_UNSEQUENCED +# endif +#endif + +/* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers + that can be freed by passing them as the Ith argument to the + function F. + _GL_ATTRIBUTE_DEALLOC_FREE declares that the function returns pointers that + can be freed via 'free'; it can be used only after declaring 'free'. */ +/* Applies to: functions. Cannot be used on inline functions. */ +#ifndef _GL_ATTRIBUTE_DEALLOC +# if _GL_GNUC_PREREQ (11, 0) +# define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i))) +# else +# define _GL_ATTRIBUTE_DEALLOC(f, i) +# endif +#endif +/* If gnulib's or has already defined this macro, continue + to use this earlier definition, since may not have been included + yet. */ +#ifndef _GL_ATTRIBUTE_DEALLOC_FREE +# if defined __cplusplus && defined __GNUC__ && !defined __clang__ +/* Work around GCC bug */ +# define _GL_ATTRIBUTE_DEALLOC_FREE \ + _GL_ATTRIBUTE_DEALLOC ((void (*) (void *)) free, 1) +# else +# define _GL_ATTRIBUTE_DEALLOC_FREE \ + _GL_ATTRIBUTE_DEALLOC (free, 1) +# endif +#endif + +/* _GL_ATTRIBUTE_DEPRECATED: Declares that an entity is deprecated. + The compiler may warn if the entity is used. */ +/* Applies to: + - function, variable, + - struct, union, struct/union member, + - enumeration, enumeration item, + - typedef, + in C++ also: namespace, class, template specialization. */ +#ifndef _GL_ATTRIBUTE_DEPRECATED +# ifndef _GL_BRACKET_BEFORE_ATTRIBUTE +# if _GL_HAVE___HAS_C_ATTRIBUTE +# if __has_c_attribute (__deprecated__) +# define _GL_ATTRIBUTE_DEPRECATED [[__deprecated__]] +# endif +# endif +# endif +# if !defined _GL_ATTRIBUTE_DEPRECATED && _GL_HAS_ATTRIBUTE (deprecated) +# define _GL_ATTRIBUTE_DEPRECATED __attribute__ ((__deprecated__)) +# endif +# ifndef _GL_ATTRIBUTE_DEPRECATED +# define _GL_ATTRIBUTE_DEPRECATED +# endif +#endif + +/* _GL_ATTRIBUTE_ERROR(msg) requests an error if a function is called and + the function call is not optimized away. + _GL_ATTRIBUTE_WARNING(msg) requests a warning if a function is called and + the function call is not optimized away. */ +/* Applies to: functions. */ +#if !(defined _GL_ATTRIBUTE_ERROR && defined _GL_ATTRIBUTE_WARNING) +# if _GL_HAS_ATTRIBUTE (error) +# define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__error__ (msg))) +# define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__warning__ (msg))) +# elif _GL_HAS_ATTRIBUTE (diagnose_if) +# define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__diagnose_if__ (1, msg, "error"))) +# define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__diagnose_if__ (1, msg, "warning"))) +# else +# define _GL_ATTRIBUTE_ERROR(msg) +# define _GL_ATTRIBUTE_WARNING(msg) +# endif +#endif + +/* _GL_ATTRIBUTE_EXTERNALLY_VISIBLE declares that the entity should remain + visible to debuggers etc., even with '-fwhole-program'. */ +/* Applies to: functions, variables. */ +#ifndef _GL_ATTRIBUTE_EXTERNALLY_VISIBLE +# if _GL_HAS_ATTRIBUTE (externally_visible) +# define _GL_ATTRIBUTE_EXTERNALLY_VISIBLE __attribute__ ((externally_visible)) +# else +# define _GL_ATTRIBUTE_EXTERNALLY_VISIBLE +# endif +#endif + +/* _GL_ATTRIBUTE_FALLTHROUGH declares that it is not a programming mistake if + the control flow falls through to the immediately following 'case' or + 'default' label. The compiler should not warn in this case. */ +/* Applies to: Empty statement (;), inside a 'switch' statement. */ +/* Always expands to something. */ +#ifndef _GL_ATTRIBUTE_FALLTHROUGH +# if _GL_HAVE___HAS_C_ATTRIBUTE +# if __has_c_attribute (__fallthrough__) +# define _GL_ATTRIBUTE_FALLTHROUGH [[__fallthrough__]] +# endif +# endif +# if !defined _GL_ATTRIBUTE_FALLTHROUGH && _GL_HAS_ATTRIBUTE (fallthrough) +# define _GL_ATTRIBUTE_FALLTHROUGH __attribute__ ((__fallthrough__)) +# endif +# ifndef _GL_ATTRIBUTE_FALLTHROUGH +# define _GL_ATTRIBUTE_FALLTHROUGH ((void) 0) +# endif +#endif + +/* _GL_ATTRIBUTE_FORMAT ((ARCHETYPE, STRING-INDEX, FIRST-TO-CHECK)) + declares that the STRING-INDEXth function argument is a format string of + style ARCHETYPE, which is one of: + printf, gnu_printf + scanf, gnu_scanf, + strftime, gnu_strftime, + strfmon, + or the same thing prefixed and suffixed with '__'. + If FIRST-TO-CHECK is not 0, arguments starting at FIRST-TO_CHECK + are suitable for the format string. */ +/* Applies to: functions. */ +#ifndef _GL_ATTRIBUTE_FORMAT +# if _GL_HAS_ATTRIBUTE (format) +# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec)) +# else +# define _GL_ATTRIBUTE_FORMAT(spec) +# endif +#endif + +/* _GL_ATTRIBUTE_LEAF declares that if the function is called from some other + compilation unit, it executes code from that unit only by return or by + exception handling. This declaration lets the compiler optimize that unit + more aggressively. */ +/* Applies to: functions. */ +#ifndef _GL_ATTRIBUTE_LEAF +# if _GL_HAS_ATTRIBUTE (leaf) +# define _GL_ATTRIBUTE_LEAF __attribute__ ((__leaf__)) +# else +# define _GL_ATTRIBUTE_LEAF +# endif +#endif + +/* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly + allocated memory. */ +/* Applies to: functions. */ +#ifndef _GL_ATTRIBUTE_MALLOC +# if _GL_HAS_ATTRIBUTE (malloc) +# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__)) +# else +# define _GL_ATTRIBUTE_MALLOC +# endif +#endif + +/* _GL_ATTRIBUTE_MAY_ALIAS declares that pointers to the type may point to the + same storage as pointers to other types. Thus this declaration disables + strict aliasing optimization. */ +/* Applies to: types. */ +/* Oracle Studio 12.6 mishandles may_alias despite __has_attribute OK. */ +#ifndef _GL_ATTRIBUTE_MAY_ALIAS +# if _GL_HAS_ATTRIBUTE (may_alias) && !defined __SUNPRO_C +# define _GL_ATTRIBUTE_MAY_ALIAS __attribute__ ((__may_alias__)) +# else +# define _GL_ATTRIBUTE_MAY_ALIAS +# endif +#endif + +/* _GL_ATTRIBUTE_MAYBE_UNUSED declares that it is not a programming mistake if + the entity is not used. The compiler should not warn if the entity is not + used. */ +/* Applies to: + - function, variable, + - struct, union, struct/union member, + - enumeration, enumeration item, + - typedef, + in C++ also: class. */ +/* In C++ and C23, this is spelled [[__maybe_unused__]]. + GCC's syntax is __attribute__ ((__unused__)). + clang supports both syntaxes. Except that with clang ≥ 6, < 10, in C++ mode, + __has_c_attribute (__maybe_unused__) yields true but the use of + [[__maybe_unused__]] nevertheless produces a warning. */ +#ifndef _GL_ATTRIBUTE_MAYBE_UNUSED +# ifndef _GL_BRACKET_BEFORE_ATTRIBUTE +# if defined __clang__ && defined __cplusplus +# if !defined __apple_build_version__ && __clang_major__ >= 10 +# define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]] +# endif +# elif _GL_HAVE___HAS_C_ATTRIBUTE +# if __has_c_attribute (__maybe_unused__) +# define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]] +# endif +# endif +# endif +# ifndef _GL_ATTRIBUTE_MAYBE_UNUSED +# define _GL_ATTRIBUTE_MAYBE_UNUSED _GL_ATTRIBUTE_UNUSED +# endif +#endif +/* Alternative spelling of this macro, for convenience and for + compatibility with glibc/include/libc-symbols.h. */ +#define _GL_UNUSED _GL_ATTRIBUTE_MAYBE_UNUSED +/* Earlier spellings of this macro. */ +#define _UNUSED_PARAMETER_ _GL_ATTRIBUTE_MAYBE_UNUSED + +/* _GL_ATTRIBUTE_NODISCARD declares that the caller of the function should not + discard the return value. The compiler may warn if the caller does not use + the return value, unless the caller uses something like ignore_value. */ +/* Applies to: function, enumeration, class. */ +#ifndef _GL_ATTRIBUTE_NODISCARD +# ifndef _GL_BRACKET_BEFORE_ATTRIBUTE +# if defined __clang__ && defined __cplusplus + /* With clang up to 15.0.6 (at least), in C++ mode, [[__nodiscard__]] produces + a warning. + The 1000 below means a yet unknown threshold. When clang++ version X + starts supporting [[__nodiscard__]] without warning about it, you can + replace the 1000 with X. */ +# if __clang_major__ >= 1000 +# define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]] +# endif +# elif _GL_HAVE___HAS_C_ATTRIBUTE +# if __has_c_attribute (__nodiscard__) +# define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]] +# endif +# endif +# endif +# if !defined _GL_ATTRIBUTE_NODISCARD && _GL_HAS_ATTRIBUTE (warn_unused_result) +# define _GL_ATTRIBUTE_NODISCARD __attribute__ ((__warn_unused_result__)) +# endif +# ifndef _GL_ATTRIBUTE_NODISCARD +# define _GL_ATTRIBUTE_NODISCARD +# endif +#endif + +/* _GL_ATTRIBUTE_NOINLINE tells that the compiler should not inline the + function. */ +/* Applies to: functions. */ +#ifndef _GL_ATTRIBUTE_NOINLINE +# if _GL_HAS_ATTRIBUTE (noinline) +# define _GL_ATTRIBUTE_NOINLINE __attribute__ ((__noinline__)) +# else +# define _GL_ATTRIBUTE_NOINLINE +# endif +#endif + +/* _GL_ATTRIBUTE_NONNULL ((N1, N2,...)) declares that the arguments N1, N2,... + must not be NULL. + _GL_ATTRIBUTE_NONNULL () declares that all pointer arguments must not be + null. */ +/* Applies to: functions. */ +#ifndef _GL_ATTRIBUTE_NONNULL +# if _GL_HAS_ATTRIBUTE (nonnull) +# define _GL_ATTRIBUTE_NONNULL(args) __attribute__ ((__nonnull__ args)) +# else +# define _GL_ATTRIBUTE_NONNULL(args) +# endif +#endif + +/* _GL_ATTRIBUTE_NONSTRING declares that the contents of a character array is + not meant to be NUL-terminated. */ +/* Applies to: struct/union members and variables that are arrays of element + type '[[un]signed] char'. */ +#ifndef _GL_ATTRIBUTE_NONSTRING +# if _GL_HAS_ATTRIBUTE (nonstring) +# define _GL_ATTRIBUTE_NONSTRING __attribute__ ((__nonstring__)) +# else +# define _GL_ATTRIBUTE_NONSTRING +# endif +#endif + +/* There is no _GL_ATTRIBUTE_NORETURN; use _Noreturn instead. */ + +/* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions. + */ +/* Applies to: functions. */ +/* After a function's parameter list, this attribute must come first, before + other attributes. */ +#ifndef _GL_ATTRIBUTE_NOTHROW +# if defined __cplusplus +# if _GL_GNUC_PREREQ (2, 8) || __clang_major__ >= 4 +# if __cplusplus >= 201103L +# define _GL_ATTRIBUTE_NOTHROW noexcept (true) +# else +# define _GL_ATTRIBUTE_NOTHROW throw () +# endif +# else +# define _GL_ATTRIBUTE_NOTHROW +# endif +# else +# if _GL_HAS_ATTRIBUTE (nothrow) +# define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__)) +# else +# define _GL_ATTRIBUTE_NOTHROW +# endif +# endif +#endif + +/* _GL_ATTRIBUTE_PACKED declares: + For struct members: The member has the smallest possible alignment. + For struct, union, class: All members have the smallest possible alignment, + minimizing the memory required. */ +/* Applies to: struct members, struct, union, + in C++ also: class. */ +#ifndef _GL_ATTRIBUTE_PACKED +/* Oracle Studio 12.6 miscompiles code with __attribute__ ((__packed__)) despite + __has_attribute OK. */ +# if _GL_HAS_ATTRIBUTE (packed) && !defined __SUNPRO_C +# define _GL_ATTRIBUTE_PACKED __attribute__ ((__packed__)) +# else +# define _GL_ATTRIBUTE_PACKED +# endif +#endif + +/* _GL_ATTRIBUTE_PURE declares: + It is OK for a compiler to move calls to the function and to omit + calls to the function if another call has the same arguments or the + result is not used, and if observable state is the same. + This attribute is safe for a function that does not affect observable state + and always returns exactly once. + (This attribute is looser than _GL_ATTRIBUTE_CONST because the function + can depend on observable state. It is stricter than + _GL_ATTRIBUTE_REPRODUCIBLE because the function must return exactly + once and cannot affect state addressed by its arguments.) */ +/* Applies to: functions. */ +#ifndef _GL_ATTRIBUTE_PURE +# if _GL_HAS_ATTRIBUTE (pure) +# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) +# else +# define _GL_ATTRIBUTE_PURE _GL_ATTRIBUTE_REPRODUCIBLE +# endif +#endif + +/* _GL_ATTRIBUTE_REPRODUCIBLE declares: + It is OK for a compiler to move calls to the function and to omit duplicate + calls to the function with the same arguments, so long as the state + addressed by its arguments is the same and is updated in time for + the rest of the program. + This attribute is safe for a function that is effectless and idempotent; see + ISO C 23 § 6.7.12.7 for a definition of these terms. + (This attribute is looser than _GL_ATTRIBUTE_UNSEQUENCED because + the function need not be stateless and idempotent. It is looser + than _GL_ATTRIBUTE_PURE because the function need not return + exactly once and can affect state addressed by its arguments.) + See also and + . + ATTENTION! Efforts are underway to change the meaning of this attribute. + See . */ +/* Applies to: functions, pointer to functions, function types. */ +#ifndef _GL_ATTRIBUTE_REPRODUCIBLE +/* This may be revisited when gcc and clang support [[reproducible]] or possibly + __attribute__ ((__reproducible__)). */ +# ifndef _GL_BRACKET_BEFORE_ATTRIBUTE +# if _GL_HAS_ATTRIBUTE (reproducible) +# define _GL_ATTRIBUTE_REPRODUCIBLE [[reproducible]] +# endif +# endif +# ifndef _GL_ATTRIBUTE_REPRODUCIBLE +# define _GL_ATTRIBUTE_REPRODUCIBLE +# endif +#endif + +/* _GL_ATTRIBUTE_RETURNS_NONNULL declares that the function's return value is + a non-NULL pointer. */ +/* Applies to: functions. */ +#ifndef _GL_ATTRIBUTE_RETURNS_NONNULL +# if _GL_HAS_ATTRIBUTE (returns_nonnull) +# define _GL_ATTRIBUTE_RETURNS_NONNULL __attribute__ ((__returns_nonnull__)) +# else +# define _GL_ATTRIBUTE_RETURNS_NONNULL +# endif +#endif + +/* _GL_ATTRIBUTE_SENTINEL(pos) declares that the variadic function expects a + trailing NULL argument. + _GL_ATTRIBUTE_SENTINEL () - The last argument is NULL (requires C99). + _GL_ATTRIBUTE_SENTINEL ((N)) - The (N+1)st argument from the end is NULL. */ +/* Applies to: functions. */ +#ifndef _GL_ATTRIBUTE_SENTINEL +# if _GL_HAS_ATTRIBUTE (sentinel) +# define _GL_ATTRIBUTE_SENTINEL(pos) __attribute__ ((__sentinel__ pos)) +# else +# define _GL_ATTRIBUTE_SENTINEL(pos) +# endif +#endif + +/* _GL_ATTRIBUTE_UNSEQUENCED declares: + It is OK for a compiler to move calls to the function and to omit duplicate + calls to the function with the same arguments, so long as the state + addressed by its arguments is the same. + This attribute is safe for a function that is effectless, idempotent, + stateless, and independent; see ISO C 23 § 6.7.12.7 for a definition of + these terms. + (This attribute is stricter than _GL_ATTRIBUTE_REPRODUCIBLE because + the function must be stateless and independent. It is looser than + _GL_ATTRIBUTE_CONST because the function need not return exactly + once and can depend on state addressed by its arguments.) + See also and + . + ATTENTION! Efforts are underway to change the meaning of this attribute. + See . */ +/* Applies to: functions, pointer to functions, function types. */ +#ifndef _GL_ATTRIBUTE_UNSEQUENCED +/* This may be revisited when gcc and clang support [[unsequenced]] or possibly + __attribute__ ((__unsequenced__)). */ +# ifndef _GL_BRACKET_BEFORE_ATTRIBUTE +# if _GL_HAS_ATTRIBUTE (unsequenced) +# define _GL_ATTRIBUTE_UNSEQUENCED [[unsequenced]] +# endif +# endif +# ifndef _GL_ATTRIBUTE_UNSEQUENCED +# define _GL_ATTRIBUTE_UNSEQUENCED +# endif +#endif + +/* A helper macro. Don't use it directly. */ +#ifndef _GL_ATTRIBUTE_UNUSED +# if _GL_HAS_ATTRIBUTE (unused) +# define _GL_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) +# else +# define _GL_ATTRIBUTE_UNUSED +# endif +#endif + + +/* _GL_UNUSED_LABEL; declares that it is not a programming mistake if the + immediately preceding label is not used. The compiler should not warn + if the label is not used. */ +/* Applies to: label (both in C and C++). */ +/* Note that g++ < 4.5 does not support the '__attribute__ ((__unused__)) ;' + syntax. But clang does. */ +#ifndef _GL_UNUSED_LABEL +# if !(defined __cplusplus && !_GL_GNUC_PREREQ (4, 5)) || defined __clang__ +# define _GL_UNUSED_LABEL _GL_ATTRIBUTE_UNUSED +# else +# define _GL_UNUSED_LABEL +# endif +#endif + +/* The following attributes enable detection of multithread-safety problems + and resource leaks at compile-time, by clang ≥ 15, when the warning option + -Wthread-safety is enabled. For usage, see + . */ +#ifndef _GL_ATTRIBUTE_CAPABILITY_TYPE +# if __clang_major__ >= 15 +# define _GL_ATTRIBUTE_CAPABILITY_TYPE(concept) \ + __attribute__ ((__capability__ (concept))) +# else +# define _GL_ATTRIBUTE_CAPABILITY_TYPE(concept) +# endif +#endif +#ifndef _GL_ATTRIBUTE_ACQUIRE_CAPABILITY +# if __clang_major__ >= 15 +# define _GL_ATTRIBUTE_ACQUIRE_CAPABILITY(resource) \ + __attribute__ ((__acquire_capability__ (resource))) +# else +# define _GL_ATTRIBUTE_ACQUIRE_CAPABILITY(resource) +# endif +#endif +#ifndef _GL_ATTRIBUTE_RELEASE_CAPABILITY +# if __clang_major__ >= 15 +# define _GL_ATTRIBUTE_RELEASE_CAPABILITY(resource) \ + __attribute__ ((__release_capability__ (resource))) +# else +# define _GL_ATTRIBUTE_RELEASE_CAPABILITY(resource) +# endif +#endif + + +/* In C++, there is the concept of "language linkage", that encompasses + name mangling and function calling conventions. + The following macros start and end a block of "C" linkage. */ +#ifdef __cplusplus +# define _GL_BEGIN_C_LINKAGE extern "C" { +# define _GL_END_C_LINKAGE } +#else +# define _GL_BEGIN_C_LINKAGE +# define _GL_END_C_LINKAGE +#endif + + +/* A replacement for va_copy, if needed. */ +#define gl_va_copy(a,b) ((a) = (b)) + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +/* #undef inline */ +#endif + +/* Work around a bug in Apple GCC 4.0.1 build 5465: In C99 mode, it supports + the ISO C 99 semantics of 'extern inline' (unlike the GNU C semantics of + earlier versions), but does not display it by setting __GNUC_STDC_INLINE__. + __APPLE__ && __MACH__ test for Mac OS X. + __APPLE_CC__ tests for the Apple compiler and its version. + __STDC_VERSION__ tests for the C99 mode. */ +#if defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && !defined __cplusplus && __STDC_VERSION__ >= 199901L && !defined __GNUC_STDC_INLINE__ +# define __GNUC_STDC_INLINE__ 1 +#endif + +/* _GL_CMP (n1, n2) performs a three-valued comparison on n1 vs. n2, where + n1 and n2 are expressions without side effects, that evaluate to real + numbers (excluding NaN). + It returns + 1 if n1 > n2 + 0 if n1 == n2 + -1 if n1 < n2 + The naïve code (n1 > n2 ? 1 : n1 < n2 ? -1 : 0) produces a conditional + jump with nearly all GCC versions up to GCC 10. + This variant (n1 < n2 ? -1 : n1 > n2) produces a conditional with many + GCC versions up to GCC 9. + The better code (n1 > n2) - (n1 < n2) from Hacker's Delight § 2-9 + avoids conditional jumps in all GCC versions >= 3.4. */ +#define _GL_CMP(n1, n2) (((n1) > (n2)) - ((n1) < (n2))) + + +/* Define to `int' if does not define. */ +/* #undef mode_t */ + +/* Define to the type of st_nlink in struct stat, or a supertype. */ +/* #undef nlink_t */ + +/* Define as a signed integer type capable of holding a process identifier. */ +/* #undef pid_t */ + +/* Define to the equivalent of the C99 'restrict' keyword, or to + nothing if this is not supported. Do not define if restrict is + supported only directly. */ +#define restrict __restrict__ +/* Work around a bug in older versions of Sun C++, which did not + #define __restrict__ or support _Restrict or __restrict__ + even though the corresponding Sun C compiler ended up with + "#define restrict _Restrict" or "#define restrict __restrict__" + in the previous line. This workaround can be removed once + we assume Oracle Developer Studio 12.5 (2016) or later. */ +#if defined __SUNPRO_CC && !defined __RESTRICT && !defined __restrict__ +# define _Restrict +# define __restrict__ +#endif + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ + +/* Define as a signed type of the same size as size_t. */ +/* #undef ssize_t */ + + + /* This definition is a duplicate of the one in unitypes.h. + It is here so that we can cope with an older version of unitypes.h + that does not contain this definition and that is pre-installed among + the public header files. */ + # if defined __restrict \ + || 2 < __GNUC__ + (95 <= __GNUC_MINOR__) \ + || __clang_major__ >= 3 + # define _UC_RESTRICT __restrict + # elif 199901L <= __STDC_VERSION__ || defined restrict + # define _UC_RESTRICT restrict + # else + # define _UC_RESTRICT + # endif + + +/* Define as a macro for copying va_list variables. */ +/* #undef va_copy */ + +#if !(defined __cplusplus \ + ? 1 \ + : (defined __clang__ \ + ? __STDC_VERSION__ >= 202000L && __clang_major__ >= 15 \ + : (defined __GNUC__ \ + ? __STDC_VERSION__ >= 202000L && __GNUC__ >= 13 \ + : defined HAVE_C_BOOL))) +# if !defined __cplusplus && !defined __bool_true_false_are_defined +# if HAVE_STDBOOL_H +# include +# else +# if defined __SUNPRO_C +# error " is not usable with this configuration. To make it usable, add -D_STDC_C99= to $CC." +# else +# error " does not exist on this platform. Use gnulib module 'stdbool-c99' instead of gnulib module 'stdbool'." +# endif +# endif +# endif +# if !true +# define true (!false) +# endif +#endif + +#if (!(defined __clang__ \ + ? (defined __cplusplus \ + ? __cplusplus >= 201703L \ + : __STDC_VERSION__ >= 202000L && __clang_major__ >= 16 \ + && !defined __sun) \ + : (defined __GNUC__ \ + ? (defined __cplusplus \ + ? __cplusplus >= 201103L && __GNUG__ >= 6 \ + : __STDC_VERSION__ >= 202000L && __GNUC__ >= 13 \ + && !defined __sun) \ + : defined HAVE_C_STATIC_ASSERT)) \ + && !defined assert \ + && (!defined __cplusplus \ + || (__cpp_static_assert < 201411 \ + && __GNUG__ < 6 && __clang_major__ < 6))) + #include + #undef/**/assert + #ifdef __sgi + #undef/**/__ASSERT_H__ + #endif + /* Solaris 11.4 defines static_assert as a macro with 2 arguments. + We need it also to be invocable with a single argument. + Haiku 2022 does not define static_assert at all. */ + #if (__STDC_VERSION__ - 0 >= 201112L) && !defined __cplusplus + #undef/**/static_assert + #define static_assert _Static_assert + #endif +#endif + +/* lightpanda: macOS's does not declare strverscmp (a glibc + extension). gnulib normally declares it via its replacement + shim, which we don't pull in. lib/strverscmp.c provides the definition. */ +#ifndef _LIBIDN2_LP_DECLS +#define _LIBIDN2_LP_DECLS +extern int strverscmp(const char *, const char *); +#endif From 8181f0a1ddf68b76e7b5aec870b490a7cc17b759 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Tue, 28 Apr 2026 22:48:33 +0800 Subject: [PATCH 06/17] try to fix build --- build.zig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build.zig b/build.zig index e57315cb..9ef2f28d 100644 --- a/build.zig +++ b/build.zig @@ -344,6 +344,10 @@ fn linkCurl(b: *Build, mod: *Build.Module, is_tsan: bool) !void { const libidn2 = buildLibidn2(b, target, mod.optimize.?, is_tsan); curl.root_module.linkLibrary(libidn2); + // Also expose libidn2 to the consuming module so src/sys/idna.zig's + // @cImport of resolves. Without this, lightpanda_module only + // sees idn2.h transitively if a system libidn2 happens to be installed. + mod.linkLibrary(libidn2); switch (target.result.os.tag) { .macos => { From 7c6f2a2a8c80fe8b9c649f24365ad98e000e9817 Mon Sep 17 00:00:00 2001 From: Navid EMAD Date: Wed, 29 Apr 2026 01:53:17 +0200 Subject: [PATCH 07/17] forms: normalize CR/LF to CRLF in form-data set encoding Per the HTML form-data set encoding algorithm, every U+000A (LF) not preceded by U+000D (CR) and every U+000D (CR) not followed by U+000A (LF) in an entry's name or value is replaced with the two-byte sequence CR+LF before percent-encoding. Without this pass, a textarea API value containing LF (per the textarea wrapping transformation) submits as raw %0A on the wire instead of the spec-required %0D%0A. The normalization is gated on URLEncodeMode == .form so URLSearchParams (.query) still follows the URL standard's serializer, which doesn't normalize. Same pass covers names + values for both the POST application/x-www-form-urlencoded body and the GET query-string path (both go through the same encoder before URL.concatQueryString). Closes #2307 --- src/browser/webapi/KeyValueList.zig | 120 +++++++++++++++++++++++++++- 1 file changed, 118 insertions(+), 2 deletions(-) diff --git a/src/browser/webapi/KeyValueList.zig b/src/browser/webapi/KeyValueList.zig index cb4e7c50..ca1e5016 100644 --- a/src/browser/webapi/KeyValueList.zig +++ b/src/browser/webapi/KeyValueList.zig @@ -259,7 +259,12 @@ fn urlEncodeValueUtf8(value: []const u8, comptime mode: URLEncodeMode, writer: * return writer.writeAll(value); } - for (value) |b| { + var i: usize = 0; + while (i < value.len) : (i += 1) { + const b = value[i]; + if (comptime mode == .form) { + if (try writeFormLineEnd(value, &i, b, writer)) continue; + } if (urlEncodeUnreserved(b, mode)) { try writer.writeByte(b); } else if (b == ' ') { @@ -272,7 +277,12 @@ fn urlEncodeValueUtf8(value: []const u8, comptime mode: URLEncodeMode, writer: * /// Percent-encode a legacy-encoded value - must also encode & and ; to preserve NCRs. fn urlEncodeValueLegacy(value: []const u8, comptime mode: URLEncodeMode, writer: *std.Io.Writer) !void { - for (value) |b| { + var i: usize = 0; + while (i < value.len) : (i += 1) { + const b = value[i]; + if (comptime mode == .form) { + if (try writeFormLineEnd(value, &i, b, writer)) continue; + } if (urlEncodeUnreserved(b, mode)) { try writer.writeByte(b); } else if (b == ' ') { @@ -286,6 +296,25 @@ fn urlEncodeValueLegacy(value: []const u8, comptime mode: URLEncodeMode, writer: } } +// HTML form-data set encoding algorithm: every U+000D (CR) not followed by +// U+000A (LF), and every U+000A (LF) not preceded by U+000D (CR), is replaced +// with the two-byte sequence CR+LF before percent-encoding. Returns true (and +// emits "%0D%0A") when `b` is CR or LF; on CR, advances the caller's index +// past a following LF so existing CRLF pairs aren't doubled. +// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#url-encoded-form-data +fn writeFormLineEnd(value: []const u8, i: *usize, b: u8, writer: *std.Io.Writer) !bool { + if (b == '\r') { + try writer.writeAll("%0D%0A"); + if (i.* + 1 < value.len and value[i.* + 1] == '\n') i.* += 1; + return true; + } + if (b == '\n') { + try writer.writeAll("%0D%0A"); + return true; + } + return false; +} + fn urlEncodeShouldEscape(value: []const u8, comptime mode: URLEncodeMode) bool { for (value) |b| { if (!urlEncodeUnreserved(b, mode)) { @@ -409,3 +438,90 @@ test "KeyValueList: urlEncode Big5 unmappable character" { // 炣 percent-encoded is %26%2328835%3B try testing.expectString("q=%26%2328835%3B", buf.written()); } + +// HTML form-data set encoding algorithm: line endings in entry names and values +// are normalized to CRLF — every stray LF (not preceded by CR) and every stray +// CR (not followed by LF) is replaced with CR+LF before percent-encoding. The +// normalization applies only to .form mode; URLSearchParams (.query) follows +// the URL standard's serializer, which doesn't normalize. +// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#url-encoded-form-data +test "KeyValueList: urlEncode .form normalizes stray LF to CRLF" { + const allocator = testing.arena_allocator; + var list = KeyValueList.init(); + try list.append(allocator, "msg", "line1\nline2\nline3"); + + var buf = std.Io.Writer.Allocating.init(allocator); + try list.urlEncode(.form, null, "UTF-8", &buf.writer); + + try testing.expectString("msg=line1%0D%0Aline2%0D%0Aline3", buf.written()); +} + +test "KeyValueList: urlEncode .form normalizes stray CR to CRLF" { + const allocator = testing.arena_allocator; + var list = KeyValueList.init(); + try list.append(allocator, "msg", "line1\rline2"); + + var buf = std.Io.Writer.Allocating.init(allocator); + try list.urlEncode(.form, null, "UTF-8", &buf.writer); + + try testing.expectString("msg=line1%0D%0Aline2", buf.written()); +} + +test "KeyValueList: urlEncode .form preserves existing CRLF" { + const allocator = testing.arena_allocator; + var list = KeyValueList.init(); + try list.append(allocator, "msg", "line1\r\nline2"); + + var buf = std.Io.Writer.Allocating.init(allocator); + try list.urlEncode(.form, null, "UTF-8", &buf.writer); + + try testing.expectString("msg=line1%0D%0Aline2", buf.written()); +} + +test "KeyValueList: urlEncode .form handles mixed line endings" { + const allocator = testing.arena_allocator; + var list = KeyValueList.init(); + // CR LF, then bare LF, then bare CR -> three CRLF sequences. + try list.append(allocator, "msg", "a\r\nb\nc\rd"); + + var buf = std.Io.Writer.Allocating.init(allocator); + try list.urlEncode(.form, null, "UTF-8", &buf.writer); + + try testing.expectString("msg=a%0D%0Ab%0D%0Ac%0D%0Ad", buf.written()); +} + +test "KeyValueList: urlEncode .form normalizes line endings in entry names" { + const allocator = testing.arena_allocator; + var list = KeyValueList.init(); + try list.append(allocator, "n\nm", "v"); + + var buf = std.Io.Writer.Allocating.init(allocator); + try list.urlEncode(.form, null, "UTF-8", &buf.writer); + + try testing.expectString("n%0D%0Am=v", buf.written()); +} + +test "KeyValueList: urlEncode .form normalizes legacy charsets too" { + const allocator = testing.arena_allocator; + var list = KeyValueList.init(); + try list.append(allocator, "msg", "a\nb"); + + var buf = std.Io.Writer.Allocating.init(allocator); + try list.urlEncode(.form, allocator, "GBK", &buf.writer); + + try testing.expectString("msg=a%0D%0Ab", buf.written()); +} + +test "KeyValueList: urlEncode .query does NOT normalize line endings" { + // URL standard's application/x-www-form-urlencoded serializer (used by + // URLSearchParams) does not perform CRLF normalization — only the HTML + // form-data set encoding wrapper does. https://url.spec.whatwg.org/#concept-urlencoded-serializer + const allocator = testing.arena_allocator; + var list = KeyValueList.init(); + try list.append(allocator, "msg", "a\nb\rc"); + + var buf = std.Io.Writer.Allocating.init(allocator); + try list.urlEncode(.query, null, "UTF-8", &buf.writer); + + try testing.expectString("msg=a%0Ab%0Dc", buf.written()); +} From b3756032587a3df9d0080ddf368773c5f7010ac8 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Wed, 29 Apr 2026 18:59:35 +0800 Subject: [PATCH 08/17] On Window.close, remove any queued navigation --- src/browser/webapi/Window.zig | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/browser/webapi/Window.zig b/src/browser/webapi/Window.zig index 807816bf..d67b174b 100644 --- a/src/browser/webapi/Window.zig +++ b/src/browser/webapi/Window.zig @@ -555,6 +555,19 @@ pub fn close(self: *Window) void { } _ = page.popups.swapRemove(popup_index); + + // Drop any pending queued navigation for this frame. Frame.deinit will + // release the QueuedNavigation arena, but the entry in page.queued_navigation + // would otherwise have processQueuedNavigation re-deinit the popup. + if (frame._queued_navigation != null) { + for (page.queued_navigation.items, 0..) |f, i| { + if (f == frame) { + _ = page.queued_navigation.swapRemove(i); + break; + } + } + } + frame.deinit(true); } From 7c40d2fb983f77923dc60d8116902a9c47c4c0ba Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Tue, 28 Apr 2026 08:51:39 +0800 Subject: [PATCH 09/17] FormData File support Move FormData from using KeyValueList to using its own List(Entry), where entry's value is a union over a String or File. Preparatory stuff for input type=file support. --- src/browser/webapi/KeyValueList.zig | 5 + src/browser/webapi/net/FormData.zig | 171 ++++++++++++++++----- src/browser/webapi/net/URLSearchParams.zig | 2 +- 3 files changed, 142 insertions(+), 36 deletions(-) diff --git a/src/browser/webapi/KeyValueList.zig b/src/browser/webapi/KeyValueList.zig index ca1e5016..b8e32234 100644 --- a/src/browser/webapi/KeyValueList.zig +++ b/src/browser/webapi/KeyValueList.zig @@ -206,6 +206,11 @@ fn urlEncodeEntry(entry: Entry, comptime mode: URLEncodeMode, allocator_: ?Alloc try urlEncodeValue(entry.value.str(), mode, allocator_, charset, writer); } +// Exposed so FormData (which keeps its own entry list) can reuse the charset/NCR-aware encoder. +pub fn urlEncodeFormValue(value: []const u8, allocator_: ?Allocator, charset: []const u8, writer: *std.Io.Writer) !void { + return urlEncodeValue(value, .form, allocator_, charset, writer); +} + fn urlEncodeValue(value: []const u8, comptime mode: URLEncodeMode, allocator_: ?Allocator, charset: []const u8, writer: *std.Io.Writer) !void { // For UTF-8, do standard percent encoding if (std.mem.eql(u8, charset, "UTF-8")) { diff --git a/src/browser/webapi/net/FormData.zig b/src/browser/webapi/net/FormData.zig index cd8584da..1cbe80f5 100644 --- a/src/browser/webapi/net/FormData.zig +++ b/src/browser/webapi/net/FormData.zig @@ -23,22 +23,41 @@ const js = @import("../../js/js.zig"); const Frame = @import("../../Frame.zig"); const Form = @import("../element/html/Form.zig"); const Element = @import("../Element.zig"); +const File = @import("../File.zig"); const KeyValueList = @import("../KeyValueList.zig"); const log = lp.log; +const String = lp.String; const Execution = js.Execution; const Allocator = std.mem.Allocator; const FormData = @This(); _arena: Allocator, -_list: KeyValueList, +_entries: std.ArrayList(Entry), + +pub const Entry = struct { + name: String, + value: Value, + + const Value = union(enum) { + file: *File, + string: String, + + fn asString(self: *const Value) []const u8 { + return switch (self.*) { + .string => |*s| s.str(), + .file => unreachable, // nothing currently creates this type of value + }; + } + }; +}; pub fn init(form_: ?*Form, submitter: ?*Element, exec: *const Execution) !*FormData { const form = form_ orelse { return try exec._factory.create(FormData{ ._arena = exec.arena, - ._list = KeyValueList.init(), + ._entries = .empty, }); }; @@ -49,7 +68,7 @@ pub fn init(form_: ?*Form, submitter: ?*Element, exec: *const Execution) !*FormD const form_data = try exec._factory.create(FormData{ ._arena = exec.arena, - ._list = try collectForm(frame.arena, form, submitter, frame), + ._entries = try collectForm(frame.arena, form, submitter, frame), }); const form_data_event = try (@import("../event/FormDataEvent.zig")).initTrusted( @@ -62,47 +81,78 @@ pub fn init(form_: ?*Form, submitter: ?*Element, exec: *const Execution) !*FormD return form_data; } -pub fn get(self: *const FormData, name: []const u8) ?[]const u8 { - return self._list.get(name); +pub fn get(self: *const FormData, name: String) ?[]const u8 { + for (self._entries.items) |*entry| { + if (entry.name.eql(name)) { + return entry.value.asString(); + } + } + return null; } -pub fn getAll(self: *const FormData, name: []const u8, exec: *const Execution) ![]const []const u8 { - return self._list.getAll(exec.call_arena, name); +pub fn getAll(self: *const FormData, name: String, exec: *const Execution) ![]const []const u8 { + var arr: std.ArrayList([]const u8) = .empty; + for (self._entries.items) |*entry| { + if (entry.name.eql(name)) { + try arr.append(exec.call_arena, entry.value.asString()); + } + } + return arr.items; } -pub fn has(self: *const FormData, name: []const u8) bool { - return self._list.has(name); +pub fn has(self: *const FormData, name: String) bool { + for (self._entries.items) |*entry| { + if (entry.name.eql(name)) { + return true; + } + } + return false; } -pub fn set(self: *FormData, name: []const u8, value: []const u8) !void { - return self._list.set(self._arena, name, value); +pub fn set(self: *FormData, name: String, value: []const u8) !void { + self.deleteByName(name); + return self.append(name.str(), value); } pub fn append(self: *FormData, name: []const u8, value: []const u8) !void { - return self._list.append(self._arena, name, value); + try self._entries.append(self._arena, .{ + .name = try String.init(self._arena, name, .{}), + .value = .{ .string = try String.init(self._arena, value, .{}) }, + }); } -pub fn delete(self: *FormData, name: []const u8) void { - self._list.delete(name, null); +pub fn delete(self: *FormData, name: String) void { + self.deleteByName(name); } -pub fn keys(self: *FormData, exec: *const js.Execution) !*KeyValueList.KeyIterator { - return KeyValueList.KeyIterator.init(.{ .list = self, .kv = &self._list }, exec); +fn deleteByName(self: *FormData, name: String) void { + var i: usize = 0; + while (i < self._entries.items.len) { + if (self._entries.items[i].name.eql(name)) { + _ = self._entries.swapRemove(i); + continue; + } + i += 1; + } } -pub fn values(self: *FormData, exec: *const js.Execution) !*KeyValueList.ValueIterator { - return KeyValueList.ValueIterator.init(.{ .list = self, .kv = &self._list }, exec); +pub fn keys(self: *FormData, exec: *const js.Execution) !*KeyIterator { + return KeyIterator.init(.{ .fd = self, .list = self }, exec); } -pub fn entries(self: *FormData, exec: *const js.Execution) !*KeyValueList.EntryIterator { - return KeyValueList.EntryIterator.init(.{ .list = self, .kv = &self._list }, exec); +pub fn values(self: *FormData, exec: *const js.Execution) !*ValueIterator { + return ValueIterator.init(.{ .fd = self, .list = self }, exec); +} + +pub fn entries(self: *FormData, exec: *const js.Execution) !*EntryIterator { + return EntryIterator.init(.{ .fd = self, .list = self }, exec); } pub fn forEach(self: *FormData, cb_: js.Function, js_this_: ?js.Object) !void { const cb = if (js_this_) |js_this| try cb_.withThis(js_this) else cb_; - for (self._list._entries.items) |entry| { - cb.call(void, .{ entry.value.str(), entry.name.str(), self }) catch |err| { + for (self._entries.items) |*entry| { + cb.call(void, .{ entry.value.asString(), entry.name.str(), self }) catch |err| { // this is a non-JS error log.warn(.js, "FormData.forEach", .{ .err = err }); }; @@ -117,11 +167,11 @@ pub const WriteOpts = struct { pub fn write(self: *const FormData, opts: WriteOpts, writer: *std.Io.Writer) !void { const enctype = opts.enctype orelse { - return self._list.urlEncode(.form, opts.allocator, opts.charset, writer); + return self.urlEncode(opts, writer); }; if (std.ascii.eqlIgnoreCase(enctype, "application/x-www-form-urlencoded")) { - return self._list.urlEncode(.form, opts.allocator, opts.charset, writer); + return self.urlEncode(opts, writer); } log.warn(.not_implemented, "FormData.encoding", .{ @@ -129,27 +179,71 @@ pub fn write(self: *const FormData, opts: WriteOpts, writer: *std.Io.Writer) !vo }); } +fn urlEncode(self: *const FormData, opts: WriteOpts, writer: *std.Io.Writer) !void { + const items = self._entries.items; + if (items.len == 0) return; + + try urlEncodeEntry(&items[0], opts, writer); + for (items[1..]) |*entry| { + try writer.writeByte('&'); + try urlEncodeEntry(entry, opts, writer); + } +} + +fn urlEncodeEntry(entry: *const Entry, opts: WriteOpts, writer: *std.Io.Writer) !void { + try KeyValueList.urlEncodeFormValue(entry.name.str(), opts.allocator, opts.charset, writer); + try writer.writeByte('='); + try KeyValueList.urlEncodeFormValue(entry.value.asString(), opts.allocator, opts.charset, writer); +} + +// Used by URLSearchParams to ingest a FormData; file entries collapse via Value.asString. +pub fn toKeyValueList(self: *const FormData, arena: Allocator) !KeyValueList { + var list: KeyValueList = .empty; + try list.ensureTotalCapacity(arena, self._entries.items.len); + for (self._entries.items) |*entry| { + try list.appendAssumeCapacity(arena, entry.name.str(), entry.value.asString()); + } + return list; +} + pub const Iterator = struct { index: u32 = 0, - list: *const FormData, + fd: *FormData, - const Entry = struct { []const u8, []const u8 }; + // See KeyValueList.Iterator.list — required by the GenericIterator wrapper. + list: *anyopaque, - pub fn next(self: *Iterator, _: *Frame) !?Iterator.Entry { + pub const Entry = struct { []const u8, []const u8 }; + + pub fn next(self: *Iterator, _: *const Execution) ?Iterator.Entry { const index = self.index; - const items = self.list._list.items(); + const items = self.fd._entries.items; if (index >= items.len) { return null; } self.index = index + 1; const e = &items[index]; - return .{ e.name.str(), e.value.str() }; + return .{ e.name.str(), e.value.asString() }; } }; -fn collectForm(arena: Allocator, form_: ?*Form, submitter_: ?*Element, frame: *Frame) !KeyValueList { - var list: KeyValueList = .empty; +const GenericIterator = @import("../collections/iterator.zig").Entry; +pub const KeyIterator = GenericIterator(Iterator, "0"); +pub const ValueIterator = GenericIterator(Iterator, "1"); +pub const EntryIterator = GenericIterator(Iterator, null); + +pub fn registerTypes() []const type { + return &.{ + FormData, + KeyIterator, + ValueIterator, + EntryIterator, + }; +} + +fn collectForm(arena: Allocator, form_: ?*Form, submitter_: ?*Element, frame: *Frame) !std.ArrayList(Entry) { + var list: std.ArrayList(Entry) = .empty; const form = form_ orelse return list; var elements = try form.getElements(frame); @@ -170,8 +264,8 @@ fn collectForm(arena: Allocator, form_: ?*Form, submitter_: ?*Element, frame: *F const name = element.getAttributeSafe(comptime .wrap("name")); const x_key = if (name) |n| try std.fmt.allocPrint(arena, "{s}.x", .{n}) else "x"; const y_key = if (name) |n| try std.fmt.allocPrint(arena, "{s}.y", .{n}) else "y"; - try list.append(arena, x_key, "0"); - try list.append(arena, y_key, "0"); + try appendString(&list, arena, x_key, "0"); + try appendString(&list, arena, y_key, "0"); continue; } } @@ -206,7 +300,7 @@ fn collectForm(arena: Allocator, form_: ?*Form, submitter_: ?*Element, frame: *F var options = try select.getSelectedOptions(frame); while (options.next()) |option| { - try list.append(arena, name, option.as(Form.Select.Option).getValue(frame)); + try appendString(&list, arena, name, option.as(Form.Select.Option).getValue(frame)); } continue; } @@ -224,11 +318,18 @@ fn collectForm(arena: Allocator, form_: ?*Form, submitter_: ?*Element, frame: *F } continue; }; - try list.append(arena, name, value); + try appendString(&list, arena, name, value); } return list; } +fn appendString(list: *std.ArrayList(Entry), arena: Allocator, name: []const u8, value: []const u8) !void { + try list.append(arena, .{ + .name = try String.init(arena, name, .{}), + .value = .{ .string = try String.init(arena, value, .{}) }, + }); +} + pub const JsApi = struct { pub const bridge = js.Bridge(FormData); diff --git a/src/browser/webapi/net/URLSearchParams.zig b/src/browser/webapi/net/URLSearchParams.zig index bd75df46..747a8114 100644 --- a/src/browser/webapi/net/URLSearchParams.zig +++ b/src/browser/webapi/net/URLSearchParams.zig @@ -46,7 +46,7 @@ pub fn init(opts_: ?InitOpts, exec: *const Execution) !*URLSearchParams { const opts = opts_ orelse break :blk .empty; switch (opts) { .query_string => |qs| break :blk try paramsFromString(arena, qs, exec.buf), - .form_data => |fd| break :blk try KeyValueList.copy(arena, fd._list), + .form_data => |fd| break :blk try fd.toKeyValueList(arena), .value => |js_val| { // Order matters here; Array is also an Object. if (js_val.isArray()) { From f7c3ccaf85979088244129d1c9ec6af0319b0b8a Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Tue, 28 Apr 2026 09:19:23 +0800 Subject: [PATCH 10/17] initial (file-free) multi-part form encoding --- src/browser/Frame.zig | 42 +++++++--- src/browser/webapi/net/FormData.zig | 126 +++++++++++++++++++++++++--- 2 files changed, 146 insertions(+), 22 deletions(-) diff --git a/src/browser/Frame.zig b/src/browser/Frame.zig index 6f6a67ce..983aaded 100644 --- a/src/browser/Frame.zig +++ b/src/browser/Frame.zig @@ -3861,12 +3861,19 @@ pub fn submitForm(self: *Frame, submitter_: ?*Element, form_: ?*Element.Html.For // button, its formaction/formmethod/formenctype attributes override the // form's corresponding attributes (matching how formtarget is honored above). // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-form-submit - const enctype = blk: { + const enctype_attr = blk: { if (submitter_) |s| { if (s.getAttributeSafe(comptime .wrap("formenctype"))) |fe| break :blk fe; } break :blk form_element.getAttributeSafe(comptime .wrap("enctype")); }; + const method = blk: { + if (submitter_) |s| { + if (s.getAttributeSafe(comptime .wrap("formmethod"))) |fm| break :blk fm; + } + break :blk form_element.getAttributeSafe(comptime .wrap("method")) orelse ""; + }; + const is_post = std.ascii.eqlIgnoreCase(method, "post"); // Get charset from accept-charset attribute or fall back to document charset const charset: []const u8 = blk: { @@ -3880,15 +3887,26 @@ pub fn submitForm(self: *Frame, submitter_: ?*Element, form_: ?*Element.Html.For break :blk self.charset; }; - var buf = std.Io.Writer.Allocating.init(arena); - try form_data.write(.{ .enctype = enctype, .charset = charset, .allocator = arena }, &buf.writer); - - const method = blk: { - if (submitter_) |s| { - if (s.getAttributeSafe(comptime .wrap("formmethod"))) |fm| break :blk fm; + var boundary_buf: [36]u8 = undefined; + // GET ignores enctype per HTML spec; only resolve the union for POST. + const encoding: FormData.EncType = blk: { + if (is_post) { + if (enctype_attr) |attr| { + if (std.ascii.eqlIgnoreCase(attr, "multipart/form-data")) { + @import("../id.zig").uuidv4(&boundary_buf); + break :blk .{ .formdata = &boundary_buf }; + } + if (!std.ascii.eqlIgnoreCase(attr, "application/x-www-form-urlencoded")) { + log.warn(.not_implemented, "FormData.encoding", .{ .encoding = attr }); + } + } } - break :blk form_element.getAttributeSafe(comptime .wrap("method")) orelse ""; + break :blk .urlencode; }; + + var buf = std.Io.Writer.Allocating.init(arena); + try form_data.write(.{ .encoding = encoding, .charset = charset, .allocator = arena }, &buf.writer); + var action = blk: { if (submitter_) |s| { if (s.getAttributeSafe(comptime .wrap("formaction"))) |fa| break :blk fa; @@ -3900,11 +3918,13 @@ pub fn submitForm(self: *Frame, submitter_: ?*Element, form_: ?*Element.Html.For .reason = .form, .kind = .{ .push = null }, }; - if (std.ascii.eqlIgnoreCase(method, "post")) { + if (is_post) { opts.method = .POST; opts.body = buf.written(); - // form_data.write currently only supports this encoding, so we know this has to be the content type - opts.header = "Content-Type: application/x-www-form-urlencoded"; + opts.header = switch (encoding) { + .urlencode => "Content-Type: application/x-www-form-urlencoded", + .formdata => |b| try std.fmt.allocPrintSentinel(arena, "Content-Type: multipart/form-data; boundary={s}", .{b}, 0), + }; } else { action = try URL.concatQueryString(arena, action, buf.written()); } diff --git a/src/browser/webapi/net/FormData.zig b/src/browser/webapi/net/FormData.zig index 1cbe80f5..fb4f49f3 100644 --- a/src/browser/webapi/net/FormData.zig +++ b/src/browser/webapi/net/FormData.zig @@ -159,24 +159,23 @@ pub fn forEach(self: *FormData, cb_: js.Function, js_this_: ?js.Object) !void { } } +pub const EncType = union(enum) { + urlencode, + // Boundary delimiter; caller owns the bytes (must outlive the write). + formdata: []const u8, +}; + pub const WriteOpts = struct { - enctype: ?[]const u8 = null, + encoding: EncType = .urlencode, charset: []const u8 = "UTF-8", allocator: ?std.mem.Allocator = null, }; pub fn write(self: *const FormData, opts: WriteOpts, writer: *std.Io.Writer) !void { - const enctype = opts.enctype orelse { - return self.urlEncode(opts, writer); - }; - - if (std.ascii.eqlIgnoreCase(enctype, "application/x-www-form-urlencoded")) { - return self.urlEncode(opts, writer); + switch (opts.encoding) { + .urlencode => return self.urlEncode(opts, writer), + .formdata => |boundary| return self.multipartEncode(boundary, writer), } - - log.warn(.not_implemented, "FormData.encoding", .{ - .encoding = enctype, - }); } fn urlEncode(self: *const FormData, opts: WriteOpts, writer: *std.Io.Writer) !void { @@ -196,6 +195,42 @@ fn urlEncodeEntry(entry: *const Entry, opts: WriteOpts, writer: *std.Io.Writer) try KeyValueList.urlEncodeFormValue(entry.value.asString(), opts.allocator, opts.charset, writer); } +fn multipartEncode(self: *const FormData, boundary: []const u8, writer: *std.Io.Writer) !void { + for (self._entries.items) |*entry| { + try multipartEncodeEntry(entry, boundary, writer); + } + try writer.print("--{s}--\r\n", .{boundary}); +} + +fn multipartEncodeEntry(entry: *const Entry, boundary: []const u8, writer: *std.Io.Writer) !void { + try writer.print("--{s}\r\n", .{boundary}); + const value_ptr = &entry.value; + switch (value_ptr.*) { + .string => |*s| { + try writer.writeAll("Content-Disposition: form-data; name=\""); + try writeMultipartName(writer, entry.name.str()); + try writer.writeAll("\"\r\n\r\n"); + try writer.writeAll(s.str()); + try writer.writeAll("\r\n"); + }, + // File entries need a real payload (filename + bytes + Content-Type) — not yet wired. + .file => log.warn(.not_implemented, "FormData.multipart.file", .{}), + } +} + +// Per RFC 7578 §4.2, Content-Disposition names are quoted-string form; +// CR/LF/" must be escaped. +fn writeMultipartName(writer: *std.Io.Writer, name: []const u8) !void { + for (name) |c| { + switch (c) { + '"' => try writer.writeAll("%22"), + '\r' => try writer.writeAll("%0D"), + '\n' => try writer.writeAll("%0A"), + else => try writer.writeByte(c), + } + } +} + // Used by URLSearchParams to ingest a FormData; file entries collapse via Value.asString. pub fn toKeyValueList(self: *const FormData, arena: Allocator) !KeyValueList { var list: KeyValueList = .empty; @@ -357,3 +392,72 @@ const testing = @import("../../../testing.zig"); test "WebApi: FormData" { try testing.htmlRunner("net/form_data.html", .{}); } + +test "FormData: multipart write" { + const allocator = testing.arena_allocator; + + var fd = FormData{ + ._arena = allocator, + ._entries = .empty, + }; + try fd.append("name", "John"); + try fd.append("note", "two\r\nlines"); + + var buf = std.Io.Writer.Allocating.init(allocator); + try fd.write(.{ + .encoding = .{ .formdata = "BOUNDARY" }, + .allocator = allocator, + }, &buf.writer); + + try testing.expectString( + "--BOUNDARY\r\n" ++ + "Content-Disposition: form-data; name=\"name\"\r\n\r\n" ++ + "John\r\n" ++ + "--BOUNDARY\r\n" ++ + "Content-Disposition: form-data; name=\"note\"\r\n\r\n" ++ + "two\r\nlines\r\n" ++ + "--BOUNDARY--\r\n", + buf.written(), + ); +} + +test "FormData: multipart escapes name CR/LF/quote" { + const allocator = testing.arena_allocator; + + var fd = FormData{ + ._arena = allocator, + ._entries = .empty, + }; + try fd.append("a\"b\r\nc", "v"); + + var buf = std.Io.Writer.Allocating.init(allocator); + try fd.write(.{ + .encoding = .{ .formdata = "B" }, + .allocator = allocator, + }, &buf.writer); + + try testing.expectString( + "--B\r\n" ++ + "Content-Disposition: form-data; name=\"a%22b%0D%0Ac\"\r\n\r\n" ++ + "v\r\n" ++ + "--B--\r\n", + buf.written(), + ); +} + +test "FormData: multipart empty body" { + const allocator = testing.arena_allocator; + + var fd = FormData{ + ._arena = allocator, + ._entries = .empty, + }; + + var buf = std.Io.Writer.Allocating.init(allocator); + try fd.write(.{ + .encoding = .{ .formdata = "B" }, + .allocator = allocator, + }, &buf.writer); + + try testing.expectString("--B--\r\n", buf.written()); +} From 91f5988fe57efec4050ad9af6acbc9bbe2071d36 Mon Sep 17 00:00:00 2001 From: Nikolay Govorov Date: Wed, 29 Apr 2026 13:33:10 +0100 Subject: [PATCH 11/17] Fix segfault on Frame deinit --- src/browser/Session.zig | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/browser/Session.zig b/src/browser/Session.zig index 17f2e221..651d97b6 100644 --- a/src/browser/Session.zig +++ b/src/browser/Session.zig @@ -133,9 +133,15 @@ pub fn createPage(self: *Session) !*Frame { } pub fn removePage(self: *Session) void { + lp.assert(self.page != null, "Session.removePage - page is null", .{}); + if (self.page.?.frame._script_manager.is_evaluating) { + // Reentrant teardown from a CDP message drained inside syncRequest; + // Session.deinit reclaims the page when the connection closes. + return; + } + // Inform CDP the frame is going to be removed, allowing other worlds to remove themselves before the main one self.notification.dispatch(.frame_remove, .{}); - lp.assert(self.page != null, "Session.removePage - page is null", .{}); self.page.?.deinit(false); self.page = null; From 71af1706581deca4e5839737a29f1c70a58602d0 Mon Sep 17 00:00:00 2001 From: Navid EMAD Date: Wed, 29 Apr 2026 15:01:18 +0200 Subject: [PATCH 12/17] cdp: fall back to dialog defaultText when LP.handleJavaScriptDialog promptText is null MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a CDP client pre-arms `LP.handleJavaScriptDialog {accept: true}` with no `promptText` and the page subsequently calls `window.prompt(message, defaultText)`, Lightpanda discarded the dialog's `defaultText` argument and returned `""`. Chrome's behavior is to surface `defaultText` as the prompt's return value — that's the natural "user accepted without typing anything" outcome per the HTML simple-dialog algorithm. The fix is one line in `Window.zig`'s `prompt` JS binding: keep the second argument named (`default_text` instead of `_`) and use it as the fallback. Pre-armed `promptText` still wins when the client supplies it; `accept = false` still returns null regardless. When neither `promptText` nor `defaultText` is provided, the binding still returns `""` per the CDP spec. Adds four new assertions to the existing `cdp.lp` integration test covering the matrix: defaultText fallback (no promptText), promptText overrides defaultText, accept=false ignores defaultText, and the existing no-defaultText case continues to return `""`. --- src/browser/webapi/Window.zig | 9 ++++++--- src/cdp/domains/lp.zig | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/browser/webapi/Window.zig b/src/browser/webapi/Window.zig index d67b174b..0945dc7f 100644 --- a/src/browser/webapi/Window.zig +++ b/src/browser/webapi/Window.zig @@ -1105,7 +1105,7 @@ pub const JsApi = struct { } }.confirm, .{}); pub const prompt = bridge.function(struct { - fn prompt(_: *const Window, message: ?[]const u8, _: ?[]const u8, frame: *Frame) ?[]const u8 { + fn prompt(_: *const Window, message: ?[]const u8, default_text: ?[]const u8, frame: *Frame) ?[]const u8 { var response: Notification.DialogResponse = .{}; frame._session.notification.dispatch(.javascript_dialog_opening, &.{ .url = frame.url, @@ -1114,9 +1114,12 @@ pub const JsApi = struct { .response = &response, }); if (!response.accept) return null; - // promptText omitted with accept=true is "" per CDP spec + // Pre-armed promptText wins when present. Otherwise fall back to + // the dialog's defaultText (second arg to window.prompt) — Chrome's + // accept-without-typing behavior. If both are absent, return "" + // per CDP spec // (https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-handleJavaScriptDialog). - return response.prompt_text orelse ""; + return response.prompt_text orelse default_text orelse ""; } }.prompt, .{}); diff --git a/src/cdp/domains/lp.zig b/src/cdp/domains/lp.zig index 95a04133..2b042c99 100644 --- a/src/cdp/domains/lp.zig +++ b/src/cdp/domains/lp.zig @@ -569,7 +569,7 @@ test "cdp.lp: handleJavaScriptDialog controls confirm/prompt/alert return values const p_text_str = try p_text.toStringSlice(); try testing.expectEqualSlices(u8, "hello", p_text_str); - // ---- prompt: accept=true without promptText returns "" per CDP spec ---- + // ---- prompt: accept=true without promptText AND no dialog defaultText returns "" ---- try ctx.processMessage(.{ .id = 4, .method = "LP.handleJavaScriptDialog", .params = .{ .accept = true } }); try ctx.expectSentResult(null, .{ .id = 4 }); @@ -577,10 +577,35 @@ test "cdp.lp: handleJavaScriptDialog controls confirm/prompt/alert return values const p_empty_str = try p_empty.toStringSlice(); try testing.expectEqualSlices(u8, "", p_empty_str); - // ---- prompt: accept=false makes prompt() return null ---- - try ctx.processMessage(.{ .id = 5, .method = "LP.handleJavaScriptDialog", .params = .{ .accept = false } }); + // ---- prompt: accept=true without promptText falls back to dialog defaultText ---- + // Mirrors Chrome's accept-without-typing behavior: with no client-supplied + // promptText, the prompt's return value is the second arg to window.prompt. + try ctx.processMessage(.{ .id = 5, .method = "LP.handleJavaScriptDialog", .params = .{ .accept = true } }); try ctx.expectSentResult(null, .{ .id = 5 }); + const p_default_text = try ls.local.exec("prompt('name?', 'John Smith')", null); + const p_default_text_str = try p_default_text.toStringSlice(); + try testing.expectEqualSlices(u8, "John Smith", p_default_text_str); + + // ---- prompt: pre-armed promptText overrides the dialog defaultText ---- + try ctx.processMessage(.{ .id = 6, .method = "LP.handleJavaScriptDialog", .params = .{ .accept = true, .promptText = "typed" } }); + try ctx.expectSentResult(null, .{ .id = 6 }); + + const p_override = try ls.local.exec("prompt('name?', 'John Smith')", null); + const p_override_str = try p_override.toStringSlice(); + try testing.expectEqualSlices(u8, "typed", p_override_str); + + // ---- prompt: accept=false returns null regardless of dialog defaultText ---- + try ctx.processMessage(.{ .id = 7, .method = "LP.handleJavaScriptDialog", .params = .{ .accept = false } }); + try ctx.expectSentResult(null, .{ .id = 7 }); + + const p_dismiss_with_default = try ls.local.exec("prompt('cancel?', 'John Smith')", null); + try testing.expect(p_dismiss_with_default.isNull()); + + // ---- prompt: accept=false makes prompt() return null ---- + try ctx.processMessage(.{ .id = 8, .method = "LP.handleJavaScriptDialog", .params = .{ .accept = false } }); + try ctx.expectSentResult(null, .{ .id = 8 }); + const p_dismiss = try ls.local.exec("prompt('cancel?')", null); try testing.expect(p_dismiss.isNull()); @@ -589,8 +614,8 @@ test "cdp.lp: handleJavaScriptDialog controls confirm/prompt/alert return values try testing.expect(p_default.isNull()); // ---- alert: dispatches the event but has no return value to override ---- - try ctx.processMessage(.{ .id = 6, .method = "LP.handleJavaScriptDialog", .params = .{ .accept = true } }); - try ctx.expectSentResult(null, .{ .id = 6 }); + try ctx.processMessage(.{ .id = 9, .method = "LP.handleJavaScriptDialog", .params = .{ .accept = true } }); + try ctx.expectSentResult(null, .{ .id = 9 }); _ = try ls.local.exec("alert('important')", null); try ctx.expectSentEvent("Page.javascriptDialogOpening", .{ .message = "important", From 31e0e7c81adb129b1d6eb0be2f7a9c517ef3cddc Mon Sep 17 00:00:00 2001 From: Navid EMAD Date: Wed, 29 Apr 2026 15:24:42 +0200 Subject: [PATCH 13/17] dom: run label activation behavior on click MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `Frame.handleClick` had no `.label` arm, so clicking an `HTMLLabelElement` fired the click event but never dispatched the synthetic click activation on the labeled control. Per HTML §4.10.4 "The label element", a label's activation behavior is to run the synthetic click activation steps on the labeled control; without it `cb.checked` stays unchanged when the click target is a `