ladybird/Meta/Generators/libweb_bindings/constants.py
Shannon Booth dba62aefc0 LibWeb/Bindings: Port IDL bindings generator to Python
Replace the Lagom C++ bindings generator invocation with the new Python
generator under Meta/Generators/libweb_bindings.

Fold the exposed-interface generation into the same generator entry
point, and keep generated overload metadata using the existing LibIDL
types for now.
2026-06-08 01:11:40 +02:00

35 lines
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Copyright (c) 2026-present, the Ladybird developers.
#
# SPDX-License-Identifier: BSD-2-Clause
from typing import TextIO
from Generators.libweb_bindings.context import GenerationContext
from Generators.libweb_bindings.includes import GeneratedIncludes
from Generators.libweb_bindings.to_js_value import to_javascript_value
from Utils.webidl_parser import Interface
def define_the_constants(
out: TextIO,
context: GenerationContext,
includes: GeneratedIncludes,
interface: Interface,
) -> None:
if not interface.constants:
return
includes.add("LibJS/Runtime/PropertyDescriptor.h")
out.write("\n")
# 1. For each constant const that is a member of definition:
for constant in interface.constants:
out.write(
f""" // 1. FIXME: If const is not exposed in realm, then continue.
// 2. Let value be the result of converting consts IDL value to a JavaScript value.
// 3. Let desc be the PropertyDescriptor{{[[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false, [[Value]]: value}}.
// 4. Let id be consts identifier.
// 5. Perform ! DefinePropertyOrThrow(target, id, desc).
object.define_direct_property("{constant.name}"_utf16_fly_string, {to_javascript_value(constant.type, constant.value, includes, context)}, JS::Attribute::Enumerable);
"""
)