Commit graph

1244 commits

Author SHA1 Message Date
Andreas Kling
0dd6b32a1b LibWeb/Bindings: Share more interface constructors
Split the generator decision for shared prototype and constructor
objects. Interfaces with custom prototype behavior can still use the
shared InterfaceConstructor when the constructor object itself has no
custom GC cell state.

Teach Intrinsics how to register a shared constructor for an existing
custom prototype object, and keep LegacyFactoryFunction aliases wired up
when the primary interface objects are shared.
2026-05-09 15:33:00 +02:00
Andreas Kling
02f504f3ce LibWeb/Bindings: Share simple generated interface objects
Many generated Web IDL prototype and constructor objects have no
per-interface storage and no custom virtual behavior. They only differ
by metadata such as their exposed name, parent interface, constructor
hook, and generated initialization functions.

Add shared InterfacePrototypeObject and InterfaceConstructor classes for
these simple interfaces. The generators now emit per-interface metadata
and static helper functions instead of distinct GC::Cell subclasses when
the interface does not need special object behavior.

This avoids creating separate type-isolated GC allocators for hundreds
of otherwise empty prototype and constructor classes, while preserving
constructors, unforgeable attributes, IDL conversions, and immutable
prototypes in the global prototype chain.
2026-05-09 14:36:18 +02:00
Shannon Booth
08b77d0465 LibWeb/Bindings: Generate named JS-to-IDL conversion helpers
Generate per-type bindings helpers for converting JS values to IDL
dictionary and enum values.

This makes the generated API line up better with the spec's
"converted to an IDL value" wording and gives us some functions to
use for future cleanup of manual IDL conversion code.
2026-05-09 10:49:49 +02:00
Shannon Booth
2446594a32 LibWeb/Bindings: Split source and bindings include dependency collection
Split include dependency collection into source header and generated
bindings header paths to prepare for dictionary and enum conversion
being split from being generated where they are used by an interface.
2026-05-09 10:49:49 +02:00
Shannon Booth
5adfd1c43a LibWeb/Bindings: Generate struct definitions from IDL dictionaries
Previously we were inconsistent by generating code for enum definitions
but not generating code for dictionaries. With future changes to the
IDL generator to expose helpers to convert to and from IDL values
this produced circular depdendencies. To solve this problem, also
generate the dictionary definitions in bindings headers.
2026-05-09 10:49:49 +02:00
Shannon Booth
7ad946c669 LibWeb/Bindings: Generate enum bindings in their owning IDL headers
Change the bindings generator to emit enum definitions into the
Bindings/<Thing>.h file owned by the IDL that defines them, including
support IDLs that do not have a top-level interface or namespace.

Allow enum-only modules to generate bindings headers and make generated
bindings code include those owner headers when another IDL depends on
their enums.

This allows us to replace the hand made NavigationType.h header with
one generated by bindings.
2026-05-09 10:49:49 +02:00
Shannon Booth
dc238476e6 Meta: Generate bindings files for all LibWeb IDLs
Teach LibWeb codegen to emit a generated bindings header and
implementation for every IDL in the CMake inputs, including support only
IDLs.

For IDLs that do not yet produce bindings content, keep generation going
through IDLGenerators and emit empty placeholder files. This prepares
per-IDL generated definitions without changing the overall generation
flow.
2026-05-09 10:49:49 +02:00
Shannon Booth
132daf35be LibWeb/Bindings: Use Vector for sequences of GC::Root
Generate plain Vector storage for IDL sequences whose element type is
already wrapped in GC::Root, instead of using GC::RootVector.
2026-05-03 10:56:45 +02:00
Shannon Booth
538727884e LibWeb/Bindings: Ignore nullability in idl_type_name_to_cpp_type()
Make idl_type_name_to_cpp_type() return the same base C++ type for
nullable and non-nullable IDL types. Nullability is handled by the
surrounding codegen logic, and this helper does not have enough
context to decide storage/wrapping semantics on its own.
2026-05-03 10:56:45 +02:00
Shannon Booth
268e5f1ba8 LibIDL: Resolve partial dictionary members during context resolution
Instead of during code generation.
2026-05-03 10:56:45 +02:00
Sam Atkins
f242bee7f3 Meta: Replace GenerateNamedCharacterReferences with a python generator
This is a direct conversion, and produces the same output.
2026-04-29 17:28:09 +01:00
Sam Atkins
7a7b838ed5 Meta: Replace GenerateAriaRoles with a python generator
This is a direct conversion, and produces the same output.
2026-04-29 17:28:09 +01:00
Shannon Booth
6cd7425a4b Meta: Port GenerateWindowOrWorkerInterfaces to Python
This replaces the C++ GenerateWindowOrWorkerInterfaces generator with a
python3 port.

The generator uses the new python WebIDL parser and writes directly to a
TextIO instance instead of porting SourceGenerator.

For validation, the python generator was diffed against the existing C++
generator over the full LibWeb IDL input set. The generated output is
behaviorally identical, and the only changes are whitespace changes
(all improvements).
2026-04-29 12:24:00 +01:00
Shannon Booth
7beac55210 LibWeb/Bindings: Pass exact typed array types through WebIDL bindings
Generate exact JS buffer types for exact IDL buffer arguments instead
of widening them to BufferSource or ArrayBufferView.

This fixes cases like TextEncoder.encodeInto(), whose IDL requires
a Uint8Array destination. Previously the generated binding accepted
any BufferSource, so DataView, other typed arrays, and
ArrayBuffer-backed values were let through. With exact conversion,
those are rejected at the binding layer as expected.
2026-04-26 17:50:58 +02:00
Sam Atkins
2ed3868012 Meta: Replace GenerateCSSPropertyID with a python generator
We don't match the C++ output byte-for-byte here, because the key
iteration order is different. So I've taken the opportunity to tidy up
some whitespace too.
2026-04-25 12:02:49 +02:00
Sam Atkins
3580e2506c Meta: Replace GenerateCSSStyleProperties with a python generator 2026-04-25 12:02:49 +02:00
Sam Atkins
d3d124b1d8 Meta: Replace GenerateCSSNumericFactoryMethods with a python generator
Adds a new `invoke_py_idl_generator` CMake helper for python scripts
that also produce an IDL file.
2026-04-25 12:02:49 +02:00
Sam Atkins
399341c3de Meta: Replace GenerateCSSPseudoElement with a python generator 2026-04-25 12:02:49 +02:00
Sam Atkins
353846fe79 Meta: Replace GenerateCSSMathFunctions with a python generator 2026-04-25 12:02:49 +02:00
Sam Atkins
143f1bc34d Meta: Replace GenerateCSSDescriptors with a python generator 2026-04-25 12:02:49 +02:00
Sam Atkins
5fbf6f6801 Meta: Replace GenerateCSSUnits with a python generator 2026-04-25 12:02:49 +02:00
Sam Atkins
f2ead8b520 Meta: Replace GenerateCSSMediaFeatureID with a python generator 2026-04-25 12:02:49 +02:00
Sam Atkins
91022151d6 Meta: Replace GenerateCSSPseudoClass with a python generator 2026-04-25 12:02:49 +02:00
Sam Atkins
f7898d2c8b Meta: Replace GenerateCSSTransformFunctions with a python generator 2026-04-25 12:02:49 +02:00
Sam Atkins
f9dc467cae Meta: Replace GenerateCSSKeyword with a python generator 2026-04-25 12:02:49 +02:00
Sam Atkins
f6a3ff388b Meta: Replace GenerateCSSEnvironmentVariable with a python generator 2026-04-25 12:02:49 +02:00
Sam Atkins
4de5f3056b Meta: Replace GenerateCSSEnums with a python generator 2026-04-25 12:02:49 +02:00
Shannon Booth
cc6e048bd6 LibWeb+LibIDL: Remove support for #import directives during parsing
These no longer serve any purpose now that we run the IDLGenerator
on all of these files at once.
2026-04-24 20:08:29 +02:00
Shannon Booth
ba741994dd LibIDL: Resolve parsed interfaces post parsing
Move partial interface, partial namespace, mixin, typedef, and overload
finalization into a context-wide post-parse resolve step.

This lets BindingsGenerator parse all declared IDL files first and then
finalize the shared IDL context before generating bindings.
2026-04-24 20:08:29 +02:00
Shannon Booth
a153732a64 LibWeb: Parse support IDL files when generating bindings
Teach the bindings build to pass support IDL files alongside the regular
binding IDLs so BindingsGenerator parses the full declared IDL set into
a shared context.

Keep idl_files.cmake as the source of truth for parsed support IDLs, and
let Interface::will_generate_code() decide which parsed interfaces emit
generated bindings.
2026-04-24 20:08:29 +02:00
Shannon Booth
0e55b0f87e LibWeb/Bindings: Derive includes from IDL references
Stop using imported modules to decide which binding headers to include.
Instead, collect dependencies from referenced interfaces, dictionaries,
enumerations, callbacks, and nested IDL types in the parsed context.
2026-04-24 20:08:29 +02:00
Shannon Booth
535b8f5b9b LibWeb/Bindings: Qualify generated C++ type names
Derive C++ namespaces from each IDL module's location and use those
qualified names when generating binding code.

Also Teach dictionaries their owning IDL module path so dictionary C++
types can be qualified the same way as interfaces. This removes the need
for the generated `using namespace Web::*` hack and the hard-coded
namespace list.

Also fix DOMURL.idl to refer to the IDL interface name `URL`, not the
C++ implementation name `DOMURL`.
2026-04-24 20:08:29 +02:00
Shannon Booth
4178ec0af4 LibWeb/WebGL: Remove Extensions interface
No other third layer folder in LibWeb has its own namespace which
makes this a special case for the IDLGenerator when determining
namespaces. Instead of adding a special case, simply remove the
namespace.
2026-04-24 20:08:29 +02:00
Shannon Booth
83427086fa LibWeb/Bindings: Use IDL context to determine 'is platform object' 2026-04-24 20:08:29 +02:00
Shannon Booth
83f4e03045 LibWeb/Bindings: Batch BindingsGenerator over all IDL files
Teach BindingsGenerator to parse and generate bindings for the full
LibWeb IDL set in one invocation, and collapse the CMake bindings
rules from one custom command per IDL file to a single batched codegen
step.

This has the downsides of:
 * Any single IDL change now reruns the whole bindings generator
 * Per-IDL parallelism at the custom-command level is lost

However, I still feel that this is a worthy trade off as:
 * Generated files are written with write_if_changed(), so rebuilds
   of generated files should not be significantly impacted.
 * It is not a common task to be modifying IDL files
 * Most importantly, giving the IDL generator full knowledge of _all_
   IDL will allow for some simplifications of the bindings generator as
   it has knowledge of all types.
2026-04-24 20:08:29 +02:00
Shannon Booth
bd4ef4b95a LibIDL: Resolve JSON interface types via context
Use the shared IDL context when checking whether a type is a JSON type
instead of walking imported modules from the current interface. This
removes another dependency on explicit #import directives when resolving
interface inheritance for toJSON.
2026-04-23 22:12:13 +02:00
Shannon Booth
e8c221bed4 LibWeb/Bindings: Resolve inherited interfaces via IDL context
When creating an inheritance stack, look up parent interfaces from the
parsed IDL context instead of the current interface's imported modules.
This removes a dependency on explicit #import directives during bindings
generation.
2026-04-23 22:12:13 +02:00
Shannon Booth
5a97dba495 LibWeb: Model Function as a callback type
Import WebIDL/Function.idl where TimerHandler uses Function, and let the
bindings generator handle it through the normal callback-function path.

This removes the special C++ mapping for Function and makes TimerHandler
use GC::Root<CallbackType>, matching the generated binding type when IDL
files are parsed together.
2026-04-23 07:07:49 +02:00
Shannon Booth
04b3537b8f LibWeb/Bindings: Use qualified namespace for WindowProxy in code gen
Rather than relying on the hacky using namespace defintions.
2026-04-23 07:07:49 +02:00
Shannon Booth
f25bfd747a LibIDL: Make parser return modules instead of interfaces
Change the IDL parser entry point to a static factory returning an
IDL::Module. Modules now own the parsed file identity and import graph,
with an optional reference to the file's real interface when one exists.

This is a step towards running the IDL generator on files without
an interface defined.
2026-04-23 07:07:49 +02:00
Callum Law
aa9f2ed83f LibWeb: Rename AcceptedTypeRange to NumericRange
This name wasn't very clear, also updates associated type and variable
names.
2026-04-22 14:24:12 +01:00
Callum Law
8a7332b7b9 LibWeb: Add OpacityValueStyleValue
This allows us to avoid the ugly hack in
`property_accepted_type_ranges()`.

This also updates the `ValueType` to be `opacity-value` rather than
`opacity` to match the spec.
2026-04-22 14:24:12 +01:00
Shannon Booth
25254d5a20 LibWeb/Bindings: Move parsed IDL entities into Context
Start making IDL::Context represent the shared IDL world used during
code generation.

Move globally visible parsed IDL such as dictionaries, enums,
typedefs, callbacks, mixins, and partial declarations out of individual
Interface objects and into Context.

The main goal of this change is a step towards invoking the IDL
generator on every IDL file at once, rather than per interface.

In the meantime as standalone improvements, this lets code generation
resolve imported IDL types through the shared Context without copying
imported declarations onto each Interface. It also makes duplicate
local declarations unnecessary for imported shared types, since an
interface can reference an enum or dictionary owned by another
parsed IDL module without re-emitting it itself.
2026-04-22 13:26:01 +02:00
Shannon Booth
442a0e2e64 LibIDL+LibWeb: Move IDL interface dump into LibIDL 2026-04-22 13:26:01 +02:00
Shannon Booth
db41fde06a LibWeb/Bindings: Factor write_if_changed into standalone function 2026-04-22 13:26:01 +02:00
Shannon Booth
31a4093c86 LibWeb/Bindings: Factor out function for generating depfiles 2026-04-22 13:26:01 +02:00
Shannon Booth
0ec82fac38 LibWeb/Bindings: Convert file paths over to ByteString 2026-04-22 13:26:01 +02:00
Jonathan Gamble
baefb51902 LibWeb: Add Media Capture and Stream APIs 2026-04-21 16:40:46 -05:00
Shannon Booth
fd44da6829 LibWeb/Bindings: Emit one bindings header and cpp per IDL
Previously, the LibWeb bindings generator would output multiple per
interface files like Prototype/Constructor/Namespace/GlobalMixin
depending on the contents of that IDL file.

This complicates the build system as it means that it does not know
what files will be generated without knowledge of the contents of that
IDL file.

Instead, for each IDL file only generate a single Bindings/<IDLFile>.h
and Bindings/<IDLFile>.cpp.
2026-04-21 07:36:13 +02:00
Shannon Booth
f8288a14cc LibWeb/BindingsGenerator: Simplify weird dictionary member assignment
Remove the special case assignment path for string dictionary members.
The old logic was using the outer dictionary conversion’s optional and
optional_default_value state to decide how to assign an individual
member, which was very confusing and not correct.

This was probably needed on earlier buggier versions of the IDL
generator working around the wrong problem.
2026-04-17 20:48:30 +01:00