LibWeb/IDL: Respect type of IDL constants

Previously we ignored the type and cast the value to i32 and then put
it into a JS::Value.
This commit is contained in:
Luke Wilde 2022-06-02 20:30:27 +01:00 committed by Linus Groh
parent 98f354cec4
commit 29b0277a71
Notes: sideshowbarker 2024-07-17 10:16:48 +09:00

View File

@ -2824,10 +2824,11 @@ void @constructor_class@::initialize(JS::GlobalObject& global_object)
for (auto& constant : interface.constants) {
auto constant_generator = generator.fork();
constant_generator.set("constant.name", constant.name);
constant_generator.set("constant.value", constant.value);
generate_wrap_statement(constant_generator, constant.value, constant.type, interface, String::formatted("auto constant_{}_value =", constant.name));
constant_generator.append(R"~~~(
define_direct_property("@constant.name@", JS::Value((i32)@constant.value@), JS::Attribute::Enumerable);
define_direct_property("@constant.name@", constant_@constant.name@_value, JS::Attribute::Enumerable);
)~~~");
}
@ -3092,10 +3093,11 @@ void @prototype_class@::initialize(JS::GlobalObject& global_object)
auto constant_generator = generator.fork();
constant_generator.set("constant.name", constant.name);
constant_generator.set("constant.value", constant.value);
generate_wrap_statement(constant_generator, constant.value, constant.type, interface, String::formatted("auto constant_{}_value =", constant.name));
constant_generator.append(R"~~~(
define_direct_property("@constant.name@", JS::Value((i32)@constant.value@), JS::Attribute::Enumerable);
define_direct_property("@constant.name@", constant_@constant.name@_value, JS::Attribute::Enumerable);
)~~~");
}