mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-05 22:52:22 +02:00
LibWeb: Initialize IDL any values without default value to undefined
Previously this would generate the following code:
JS::Value foo_value;
if (!foo.is_undefined())
foo_value = foo;
Which is dangerous as we're passing an empty value around, which could
be exposed to user code again. This is fine with "= null", for which it
also generates:
else
foo_value = JS::js_null();
So, in summary: a value of type `any`, not `required`, with no default
value and no initializer from user code will now default to undefined
instead of an empty value.
This commit is contained in:
Notes:
sideshowbarker
2024-07-18 02:49:17 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/7afd215e955 Pull-request: https://github.com/SerenityOS/serenity/pull/10437 Reviewed-by: https://github.com/awesomekling ✅
@@ -1079,7 +1079,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
||||
)~~~");
|
||||
} else {
|
||||
scoped_generator.append(R"~~~(
|
||||
JS::Value @cpp_name@;
|
||||
JS::Value @cpp_name@ = JS::js_undefined();
|
||||
if (!@js_name@@js_suffix@.is_undefined())
|
||||
@cpp_name@ = @js_name@@js_suffix@;
|
||||
)~~~");
|
||||
|
||||
Reference in New Issue
Block a user