Skip to content

Commit 198cec4

Browse files
Lubrsiawesomekling
authored andcommitted
LibWeb: Allow null for optional, nullable, no default value union types
For these types, it would previously only accept `undefined` for the `null` state. Fixes GET requests in the Turbo library always failing: https://github.com/hotwired/turbo/blob/9e057f284a60a9597446b258d562cebd55be71d7/src/http/fetch_request.js#L219-L220 https://github.com/hotwired/turbo/blob/9e057f284a60a9597446b258d562cebd55be71d7/src/http/fetch_request.js#L51-L64 This was found on https://www.fangamer.com/.
1 parent 16662ab commit 198cec4

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1586,9 +1586,10 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
15861586
)~~~");
15871587
} else {
15881588
if (!optional_default_value.has_value()) {
1589+
union_generator.set("nullish_or_undefined", union_type.is_nullable() ? "nullish" : "undefined");
15891590
union_generator.append(R"~~~(
15901591
Optional<@union_type@> @cpp_name@;
1591-
if (!@js_name@@js_suffix@.is_undefined())
1592+
if (!@js_name@@js_suffix@.is_@nullish_or_undefined@())
15921593
@cpp_name@ = TRY(@js_name@@js_suffix@_to_variant(@js_name@@js_suffix@));
15931594
)~~~");
15941595
} else {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Successfully created GET request with body set to null
2+
Successfully created HEAD request with body set to null
3+
Successfully started GET fetch with body set to null
4+
Successfully started HEAD fetch with body set to null
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
<script src="../include.js"></script>
3+
<script>
4+
asyncTest(async (done) => {
5+
try {
6+
const dataUrl = "data:,hello";
7+
new Request(dataUrl, { method: "GET", body: null });
8+
println("Successfully created GET request with body set to null");
9+
new Request(dataUrl, { method: "HEAD", body: null });
10+
println("Successfully created HEAD request with body set to null");
11+
await fetch(dataUrl, { method: "GET", body: null });
12+
println("Successfully started GET fetch with body set to null");
13+
await fetch(dataUrl, { method: "HEAD", body: null });
14+
println("Successfully started HEAD fetch with body set to null");
15+
} catch (e) {
16+
println(`Unexpected throw: ${e}`);
17+
}
18+
19+
done();
20+
});
21+
</script>

0 commit comments

Comments
 (0)