Skip to content

Lightpanda: the headless browser designed for AI and automation

webapi: Apply LegacyNullToEmptyString to setFloat

Karl Seguin8954f272aab8
diff --git a/src/browser/tests/element/css_style_properties.html b/src/browser/tests/element/css_style_properties.html
index e2ce4e3b8..e3c57777f 100644
--- a/src/browser/tests/element/css_style_properties.html
+++ b/src/browser/tests/element/css_style_properties.html
@@ -60,6 +60,15 @@
div.style.setProperty('float', 'right');
testing.expectEqual('right', div.style.cssFloat);
+
+ // undefined stringifies to "undefined", an invalid value: the declaration stays
+ div.style.cssFloat = undefined;
+ testing.expectEqual('right', div.style.cssFloat);
+
+ // [LegacyNullToEmptyString]: null removes it
+ div.style.cssFloat = null;
+ testing.expectEqual('', div.style.cssFloat);
+ testing.expectEqual('', div.style.cssText);
}
</script>
diff --git a/src/browser/webapi/css/CSSStyleDeclaration.zig b/src/browser/webapi/css/CSSStyleDeclaration.zig
index 3eec441c8..f1a99cdc0 100644
--- a/src/browser/webapi/css/CSSStyleDeclaration.zig
+++ b/src/browser/webapi/css/CSSStyleDeclaration.zig
@@ -450,11 +450,13 @@ fn getFloat(self: *const CSSStyleDeclaration, frame: *Frame) []const u8 {
return self.getPropertyValue("float", frame);
}
-fn setFloat(self: *CSSStyleDeclaration, value_: ?[]const u8, frame: *Frame) !void {
+fn setFloat(self: *CSSStyleDeclaration, value: js.Value, frame: *Frame) !void {
if (self._is_computed) {
return error.NoModificationAllowed;
}
- if (try self.setPropertyImpl("float", value_ orelse "", false, frame)) {
+ // `[LegacyNullToEmptyString] CSSOMString`: null becomes "", undefined becomes "undefined".
+ const str = if (value.isNull()) "" else try value.toZig([]const u8);
+ if (try self.setPropertyImpl("float", str, false, frame)) {
try self.syncStyleAttribute(frame);
}
}