镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

exact URL origin-length boundary #312

Closed

Description

@chrisbbreuer

Parent: #140
Tracked by: #134, #163, #164

Symbols (URL cluster sub-slice 3 — origin length)

Symbol Home (packages/runtime/src/jsc/URL.zig @ 7ed99c02) Bun C++ (upstream/src/jsc/bindings/BunString.cpp)
URL__originLength :167 — extern fn URL__originLength(latin1_slice: [*]const u8, len: usize) u32; (declared, un-wrapped: originFromSlice is omitted pending strings.firstNonASCII) :569 — WTF::String from the latin-1 slice, WTF::URL, invalid → 0, else url.pathStart()

Both pinned profiles declare the identical zig-side signature (latin1_slice: [*]const u8, len: usize) u32 (the C++ size_t return narrows to u32).

Last standalone URL-cluster symbol; after this slice only the DOMURL object-creation group (BunString__toURL/toJSDOMURL + WebCore__DOMURL__cast_/href_/pathname_/fileSystemPath) remains in the cluster.

Acceptance criteria

  • Parse the latin-1 slice through the allocator-first urlParse with no base; empty/invalid (scheme-less) input returns 0, matching Bun's validity guard.
  • pathStart is computed from the parsed parts so it exactly mirrors urlSerialize's prefix emission: scheme: plus, when a host component is present, // + userinfo (user[:pw]@, emitted only when non-empty) + host + (:port when set), plus the /. sentinel for a non-opaque path that begins with //. This is the byte offset where the path begins in the canonical serialization — i.e. url.origin.length for tuple origins, and the scheme/authority prefix length otherwise.
  • The latin-1 slice is widened to WTF-8 before parsing (WTF 8-bit string semantics); non-ASCII bytes follow the parser's existing rules. A null slice returns 0 (zig-js sentinel where Bun dereferences unconditionally).
  • Compiled runtime fixture covers: http with userinfo+port, default-port elision, file: (empty authority present), opaque-path (mailto:), the //-led non-opaque sentinel case, invalid input → 0, null → 0; results cross-checked against new URL(...).origin.length where the JS getter exists (http/https) and against the serialized prefix elsewhere. Fixture symbol count 313 → 314.
  • Home inventory 311/431, Bun inventory 304/421; bun-private-abi-audit + c-api-audit green; full zig build test zero new failures (worktree baseline-vs-candidate against the same pinned base).

Design constraints

  • No new parser machinery: reuse urlParse + the parts layout; the prefix-length arithmetic must not duplicate serialization logic beyond reading the same component fields.
  • Context-free: no realm, no exception channel — pure bytes in, length out.

Activity

  1. chrisbbreuer commented on Jul 19, 2026

    @chrisbbreuer
    MemberAuthor

    Evidence — landed on main as runtime a95eb6fd + docs a44593a7.

    Implementation: URL__originLength in src/c_api.zig widens the latin-1 slice to WTF-8 (privateLatin1ToWTF8, WTF 8-bit string semantics), parses with no base through the allocator-first urlParse, and returns the pathStart offset computed from the parsed parts so it mirrors urlSerialize's prefix emission exactly — scheme: plus, with a host present, // + non-empty userinfo (user[:pw]@) + host + (:port when set), plus the /. sentinel for a non-opaque //-led path. Empty/invalid input and a null slice return 0. Context-free: no realm, no exception channel.

    Validation:

    • Compiled runtime fixture 313 → 314/314: fixed-offset cases (userinfo+port http://user:pw@example.com:8080 → 31, default-port elision → 18, file: empty-authority → 7, opaque mailto: → 7), JS-derived parity pathStart === href.length - pathname.length for the non-special hierarchical (foo://host:9/p) and /.-sentinel (foo:////p) cases, origin.length getter parity for https, and invalid/empty/null → 0.
    • bun-private-abi-audit: implemented-private 304/421 (pending 117). c-api-audit: 320 private profile exports, 117/117 public complete.
    • Worktree A/B at base bcf9b0fd (isolated from unrelated uncommitted wasm work in the shared checkout): baseline 1152 passed / 3 failed vs candidate 1152 passed / 3 failed — identical failure sets (the three known pre-existing: gc slab size, wasm.decode malformed, wasm.validate GC canonical recursive type identity). Zero new failures.

    Inventories refreshed: Home 311/431 implemented (120 pending), Bun 304/421 (117 pending). Docs boundary evidence published in docs/abi/README.md. Only the DOMURL object-creation group remains in the URL cluster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions