mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
storage: maintain Lookup size correctly
This commit is contained in:
@@ -88,3 +88,12 @@
|
||||
localStorage.clear();
|
||||
testing.expectEqual(0, localStorage.length)
|
||||
</script>
|
||||
|
||||
<script id="localstorage_limits">
|
||||
localStorage.clear();
|
||||
for (i = 0; i < 5; i++) {
|
||||
const v = "v".repeat(1024 * 1024);
|
||||
localStorage.setItem(v, v);
|
||||
}
|
||||
testing.expectError("QuotaExceededError", () => localStorage.setItem("last", "v"));
|
||||
</script>
|
||||
|
||||
@@ -86,11 +86,15 @@ pub const Lookup = struct {
|
||||
|
||||
pub fn removeItem(self: *Lookup, key_: ?[]const u8) void {
|
||||
const k = key_ orelse return;
|
||||
if (self._data.get(k)) |value| {
|
||||
self._size -= value.len;
|
||||
_ = self._data.remove(k);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clear(self: *Lookup) void {
|
||||
self._data.clearRetainingCapacity();
|
||||
self._size = 0;
|
||||
}
|
||||
|
||||
pub fn key(self: *const Lookup, index: u32) ?[]const u8 {
|
||||
|
||||
Reference in New Issue
Block a user