Commit Graph

530 Commits

Author SHA1 Message Date
Shannon Booth
bb0f244667 LibWeb: Remove ShadowRealm HTML integration 2026-04-05 13:57:58 +02:00
Shannon Booth
85765ccb5c LibWeb: Factor newTarget prototype setup into WebIDL helper 2026-04-05 02:09:39 +02:00
Shannon Booth
b05c56cbb6 LibWeb/Bindings: Fix LegacyUnenumerableNamedProperties enumerability
The boolean was mistakenly reversed.
2026-04-03 18:33:45 +02:00
Shannon Booth
379461e047 LibWeb: Make global prototype chains immutable
Per https://webidl.spec.whatwg.org/#interface-prototype-object any
global platform object should reject prototype changes (besides
from ShadowRealmGlobalScope), and interface prototype objects on
global prototype chains must be immutable.

We already handled parts of this on the globals themselves, but not
the full chain.

Also align some spec comments to the latest WebIDL spec.
2026-04-03 18:33:45 +02:00
Psychpsyo
f4a86c8466 LibWeb: Implement enough of WebXR for xrSession_end test to pass 2026-04-03 13:14:33 +02:00
Timothy Flynn
2e2a99a379 LibWeb: Add a stub for the Cache interface
The Cache and CacheStorage interfaces are quite intertwined. A Cache
object can only be created through CacheStorage, so the Cache interface
cannot be tested on its own. So adding just this stub will allow
implementing the CacheStorage interfaces that create Cache objects. We
can then implement the Cache interface piecemeal.
2026-04-03 11:04:12 +02:00
Zaggy1024
a54a86c024 Meta: Treat MediaSource as a platform object
This allows URL.createObjectURL(new MediaSource()) to succeed.
2026-04-01 02:54:22 -05:00
Sam Atkins
ed6a5f25a0 LibWeb: Implement scoped custom element registries 2026-03-27 19:49:55 +00:00
Sam Atkins
ecbd846272 LibWeb/DOM: Implement DocumentOrShadowRoot.customElementRegistry
Step towards scoped custom element registries.
2026-03-27 19:49:55 +00:00
Jonathan Gamble
793a4eeb8e Meta: Support nullable BufferSource as Optional in IDL generator
This IDL change is needed for webaudio's WaveShaperNode, where a
null BufferSource for a curve attribute results in a zero-length buffer.

WebGL also has a nullable BufferSource arg in bufferData(...). But
there, a null data/srcData value returns GL_INVALID_VALUE.
2026-03-27 00:03:39 +01:00
Luke Wilde
cfd795f907 LibWeb+IDLGenerators: Support nullable union types 2026-03-25 13:18:15 +00:00
Shannon Booth
3a95df60f9 LibWeb/Bindings: Deduplicate cpp type name normalization
This was copy and pasted twice.
2026-03-19 22:14:26 +01:00
Shannon Booth
0803ace948 LibWeb/Bindings: Factor out function for generating dictionary to cpp 2026-03-19 22:14:26 +01:00
Shannon Booth
f04e7d88d5 LibWeb/Bindings: Add a forward declaration of generate_to_cpp
generate_to_cpp is called recursively, such as when generating
dictionary values. To support factoring this (massive) function
into functions, add a forward declaration.
2026-03-19 22:14:26 +01:00
Shannon Booth
92f4fc2cb9 LibWeb/Bindings: Don't use parameter type in may_be_null checks
Whether a converted value may be null should only depend on the presence
and value of an optional default, not the nullability of the type being
passed in.
2026-03-19 22:14:26 +01:00
Shannon Booth
71ba774083 LibWeb/Bindings: Don’t set @@unscopables in unforgeable attribute setup
[Unscopable] members should only affect the interface prototype’s
@@unscopables object. The bindings generator was also creating an empty
@@unscopables object in define_unforgeable_attributes(), installing it
as an own property on instances.
2026-03-19 20:44:36 +01:00
Shannon Booth
19af2bebc7 LibWeb/Bindings: Implement LegacyLenientThis extended attribute 2026-03-14 00:08:20 +01:00
Shannon Booth
604b79403c LibWeb/Bindings: Add early returns to attribute setter codegen
Previously we avoided early returns and used `else if` chains instead,
since returning early could prevent other required code generation
steps from running. This structure diverged from the specification and
makes implementing [LegacyLenientThis] more difficult.

Now that attribute setter logic has been moved into its own function,
the necessary code generation can run independently, allowing us to
use early returns where appropriate.

No functional impact.
2026-03-14 00:08:20 +01:00
Shannon Booth
4b92e0f0c2 LibWeb/Bindings: Factor out attribute setter code generation
No functional impact.
2026-03-14 00:08:20 +01:00
Shannon Booth
dcce7e63c6 LibWeb/Bindings: Remove redundant HTML::Window check in impl_from
This is covered by the @fully_qualified_name@ type check just below,
WindowProxy is the only special case that we need to handle at the
IDL layer. Also split this into two separate functions while we
are at it, as this function as-is is performing a few different
specification steps all at once.
2026-03-14 00:08:20 +01:00
Jelle Raaijmakers
fb353a64c1 LibWeb: Detect promise-returning IDL callbacks correctly
The code generator checked is_object() to detect Promise return types,
but Promise<T> is a ParameterizedType, so the check always failed and
caused crashes in WebContent in throwing callback functions.
2026-03-12 10:38:43 +01:00
Shannon Booth
e555edd770 LibWeb/Bindings: Implement callback interface object bindings
Generate correct bindings for callback interfaces: only create an
interface object when the interface declares constants, and set up
the prototype correctly.

This also lets us tidy up some IDL for these callback interfaces.
2026-03-11 21:16:44 +01:00
Shannon Booth
6a2540213a LibWeb/Bindings: Use implemented names for imported IDL headers
The bindings generator derived imported interface headers from the IDL
file name. That only works when the IDL name, implemented C++ type, and
header basename all match.

Interfaces with [ImplementedAs] break that assumption, since the
generated bindings need to include the implementation header rather than
the header implied by the IDL file name.

This fixes a compile error in a future commit where EventListener
callback interface is split into its own IDL file with an
ImplementedAs of IDLEventListener.
2026-03-11 21:16:44 +01:00
Jonathan Gamble
938ca3dbad Meta: Fix optional dictionary wrapping in IDL generator
Handle Optional<T> and Optional<Variant<...>> correctly when wrapping
dictionary members, and make ComputedEffectTiming.localTime optional
to distinguish absence from null.
2026-03-10 22:49:19 +01:00
Jelle Raaijmakers
703bef336a Meta/IDLGenerators: Do not call resolve_overload() if possible
For overload sets of size 1, we don't need to call into
`resolve_overload()` preventing many heap allocations. This effectively
removed EffectiveOverloadSet / resolve_overload from profiles for me on
slither.io.
2026-02-27 11:42:38 -05:00
Jelle Raaijmakers
0d262ac558 Meta/IDLGenerators: Make use of as_if<T> for union type checks 2026-02-27 11:42:38 -05:00
Luke Wilde
09e00677eb IDLGenerators: Support Experimental extended attribute on IDL attributes 2026-02-24 17:08:48 +01:00
Luke Wilde
79de597f8a IDLGenerator: Implement LegacyLenientSetter 2026-02-23 18:44:26 +00:00
Ben Wiederhake
b765a3a261 LibWeb: Remove unused header in IDLGenerators 2026-02-23 12:15:23 +01:00
Ben Wiederhake
dab83d35d1 AK: Remove unused include from ByteString 2026-02-17 12:38:51 +00:00
Callum Law
3f8da74e63 LibIDL+Meta: Add support for WebIDL maplike declarations on interfaces
Currently we only support string keys and numeric sequence values.

This is heavily based on the implementation of `setlike`.
2026-02-17 12:25:27 +00:00
Shannon Booth
bc93ba4530 LibWeb/Bindings: Implement [SecureContext] extended attribute
Unfortunately this is a bit of a pain to test as it is surprisingly
difficult to create a non secure context in our test harness.
This is because both file scheme URLs and localhost are considered
secure contexts.

To test this, add a very specific internals setter to change the
top level origin of the environment for the current realm.
2026-02-14 20:22:40 +01:00
Niccolo Antonelli Dziri
94ca0dcbef IDLGenerators: Translate boolean? silent = null to Optional<bool>
It was prevously translating it to just `bool` instead of
`Optional<bool>`.

Required elements in dictionary (such as in Notification.idl
for the NotificationAction) were treated as Optional<T> like the other
non-required elements. Now it's just the type without the Optional.

Co-authored-by: Zaggy1024 <gregory.bertilson@gmail.com>
2026-02-13 16:47:42 +00:00
Shannon Booth
39976bb4b8 LibWeb/Bindings: Use DefineDataPropertyOrThrow in Replaceable setter 2026-02-07 11:49:36 +01:00
Shannon Booth
1d3e48cce8 LibWeb/Bindings: Use JS Get for [PutForwards] attribute setter
Previously we were invoking the c++ getter, which is clearly not
correct.
2026-02-06 19:23:30 +01:00
Shannon Booth
c71d6d3b20 LibWeb/Bindings: Do not throw on [PutForwards] attribute setter 2026-02-06 19:23:30 +01:00
Shannon Booth
932a20423f LibWeb/Bindings: Treat missing attribute setter argument as undefined
Fold attribute setter handling into the shared [Replaceable] and
[PutForwards] paths, aligning the implementation more closely with the
WebIDL specification.

This change unfortunately introduces a regression in a WebAssembly
JS API test that expects attribute setters to throw when invoked
with no arguments (rather than treating the missing argument as
undefined). The exact specification text that mandates this
behavior for the WASM API is unclear to me.

The new behaviour seems like it would be more compatible in the
general case by not throwing an exception for all of the other
cases, so this commit accepts this as a regression until the
reasoning for needing to throw can be determined.
2026-02-06 19:23:30 +01:00
Shannon Booth
aa6b9ed318 LibWeb/Bindings: Treat no args as undefined for Replaceable/PutForwards 2026-02-06 19:23:30 +01:00
Shannon Booth
a5bbe4e44d LibWeb/Bindings: Add spec comments for PutForwards and Replaceable
No functional change intended, this is just intending to make it
obvious where the previous implementation was not following the
specification.
2026-02-06 19:23:30 +01:00
Andreas Kling
74a80b7bfc LibJS: Mark JS::Cell::initialize() as MUST_UPCALL
Intermediate classes in the initialize() chain set up prototypes and
define properties. Forgetting to call Base::initialize() in any
override would silently skip that setup.
2026-02-06 13:50:54 +01:00
Andreas Kling
706eb0018c LibGC+LibWeb: Mark two GC::Cell functions as MUST_UPCALL
Let's make sure that subclasses always call their base class when
overriding these virtuals:

- void finalize()
- void visit_edges(Visitor&)
2026-02-06 13:50:54 +01:00
Psychpsyo
617b8cb247 LibWeb: Implement the very basics of XRSession 2026-02-04 15:08:37 +01:00
Timothy Flynn
34466eeb2d IDLGenerators: Do not generate a plain type for default nullable values
Commit 1b8e81cd6f added a check to prevent
assigning a default value when the default value itself is null. But we
had previously generated an uninitialized type, expecting it to become
defaulted later on. So we would have generated code such as:

    bool value;

    if (!property.is_null() && !property.is_undefined())
        value = property.to_boolean();

    options.value = value;

This is undefined behavior.

We know use the same default value check to ensure we generate Optional
types instead. So the above `value` initializer becomes:

    Optional<bool> value;
2026-02-02 18:01:08 +01:00
Jonathan Gamble
4e48ba36bd LibWeb: Better handling of union types in IDL code generation
First check if a string is a member of the enum before attempting
numeric conversion. This generates correct code for fields like:

AudioContextOptions {
  latencyHint: AudioContextLatencyCategory | double;
}
2026-01-26 18:46:39 +01:00
Reimar
26181f2958 LibWeb: Implement External interface 2026-01-22 14:56:46 +01:00
Jelle Raaijmakers
e8cbddbeb8 Meta/IDLGenerators: Clean up is_platform_object()
Any type ending in "Event" or "Element" does not need to be added to the
manually curated list of platform objects in is_platform_object().
Additionally, "WindowProxy" was already part of that list, so no need to
check for it separately. No functional changes.
2026-01-20 07:28:32 -05:00
Jelle Raaijmakers
99923eac8d LibWeb: Add stubbed Speech API 2026-01-20 06:51:04 -05:00
Psychpsyo
52781cc2fd LibWeb: Add WebXR's XRSystem 2026-01-11 00:01:24 +01:00
Shannon Booth
f67c15b2ff LibWeb/Bindings: Ensure identity for [LegacyUnforgeable] attributes
The WebIDL spec requires that attributes marked [LegacyUnforgeable]
share the same getter and setter function objects across all instances
within the same Realm.

Previously, we were creating new JS::NativeFunction wrappers during
every instance initialization, which caused identity checks to fail.
This change moves these functions into Bindings::Intrinsics so they
are created once per Realm and reused.
2026-01-08 12:57:17 +01:00
Andreas Kling
2ac363dcba LibGC: Only call finalize() on types that override finalize()
This dramatically cuts down on time spent in the GC's finalizer pass,
since most types don't override finalize().
2026-01-07 20:51:17 +01:00