Skip to content

Implement input type=file support (FileList, input.files/value, DOM.setFileInputFiles)#2635

Merged
karlseguin merged 2 commits into
lightpanda-io:mainfrom
Ar-maan05:feat-implement-file-api
Jun 5, 2026
Merged

Implement input type=file support (FileList, input.files/value, DOM.setFileInputFiles)#2635
karlseguin merged 2 commits into
lightpanda-io:mainfrom
Ar-maan05:feat-implement-file-api

Conversation

@Ar-maan05

Copy link
Copy Markdown
Contributor

What

Implements <input type=file> support, building on the W3C Blob/File API in the first commit.

  • FileList now backs a real []*File (was a zero-size stub): length and item(i) work.
  • input.files returns a live, identity-stable FileList for type=file, and null for every other input type (per the IDL).
  • input.value returns the spec C:\fakepath\<name> string for file inputs; setting it to anything but "" throws.
  • Required file inputs report valueMissing only when empty (was a hardcoded always-empty TODO).
  • CDP DOM.setFileInputFiles loads files from disk into a file input, sniffs MIME by extension, and fires input + change: the upload entry point for WebDriver/automation.

Memory ownership

File/Blob own a reference-counted pooled arena, normally released when V8 finalizes the JS wrapper. Files set via CDP may never be read from JS, so the owning Frame now tracks each input's FileList, acquireRefs the files it holds, and releases them at teardown, mirroring how URL.createObjectURL blobs are managed. Without this they leak an arena (caught by the test runner's leak detector). A scoped errdefer also frees partially-created files if one path in a multi-file set fails to load.

Not in scope

  • multipart/form-data encoding of files on form submit
  • drag-and-drop / DataTransfer

Tests

  • element/html/input_file.html: files identity/length/item, null for non-file inputs, value getter/setter.
  • cdp.dom: setFileInputFiles: happy path, non-input node, missing node id, and partial-failure (no-leak) path.
  • make test green; zig fmt --check clean.

Closes #2175

…tFiles

  Populate FileList with real File objects and expose them on
  HTMLInputElement:
  - input.files returns a live, identity-stable FileList for type=file
    (null for other input types)
  - input.value returns the spec "C:\fakepath\<name>" string
  - required file inputs report value-missing only when empty

  Implement CDP DOM.setFileInputFiles: load files from disk into a file
  input (MIME sniffed by extension) and fire input + change events.

  File backing arenas are reference counted via their Blob proto, so the
  owning Frame now acquires/releases them and frees any still held at
  teardown, preventing an ArenaPool leak for CDP-set files never read
  from JS. A scoped errdefer frees partially-created files when one path
  in a multi-file set fails to load.
@Ar-maan05
Ar-maan05 force-pushed the feat-implement-file-api branch from 6932a13 to 7524a75 Compare June 4, 2026 10:32
@Ar-maan05

Copy link
Copy Markdown
Contributor Author

Friendly ping! Resolved all merge conflicts. Let me know if any changes are needed.

Small formatting tweaks
@karlseguin
karlseguin merged commit 0e12790 into lightpanda-io:main Jun 5, 2026
21 of 23 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 5, 2026
@karlseguin

Copy link
Copy Markdown
Collaborator

Thank you.

@Ar-maan05
Ar-maan05 deleted the feat-implement-file-api branch June 5, 2026 03:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement input type=file support

2 participants