Merge pull request #4202 from lightpanda-io/css-setFloat-undefined

webapi: Apply LegacyNullToEmptyString to setFloat
This commit is contained in:
Karl Seguin authored and GitHub committed 2026-10-27 07:02:32 +08:00
commit 33dbdb5783
2 files changed
+14 -2

No files matched your search

@@ -60,6 +60,16 @@
div.style.setProperty('float', 'right');
testing.expectEqual('right', div.style.cssFloat);
// undefined stringifies to "undefined", it doesn't clear the declaration
// (Chrome rejects the invalid value and keeps 'right'; we don't validate yet)
div.style.cssFloat = undefined;
testing.expectEqual(false, div.style.cssFloat === '');
// [LegacyNullToEmptyString]: null removes it
div.style.cssFloat = null;
testing.expectEqual('', div.style.cssFloat);
testing.expectEqual('', div.style.cssText);
}
</script>
@@ -485,11 +485,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);
}
}