mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
css: throw IndexSizeError in deleteRule and insertRule
This commit is contained in:
@@ -436,6 +436,15 @@
|
||||
|
||||
sheet.deleteRule(0);
|
||||
testing.expectEqual(0, sheet.cssRules.length);
|
||||
|
||||
let caught = false;
|
||||
try {
|
||||
sheet.deleteRule(5);
|
||||
} catch (e) {
|
||||
caught = true;
|
||||
testing.expectEqual('IndexSizeError', e.name);
|
||||
}
|
||||
testing.expectTrue(caught);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -24,14 +24,14 @@ pub fn item(self: *const CSSRuleList, index: usize) ?*CSSRule {
|
||||
|
||||
pub fn insert(self: *CSSRuleList, index: u32, rule: *CSSRule, page: *Page) !void {
|
||||
if (index > self._rules.items.len) {
|
||||
return error.IndexSizeError; // Or standard DOMException mapped error
|
||||
return error.IndexSizeError;
|
||||
}
|
||||
try self._rules.insert(page.arena, index, rule);
|
||||
}
|
||||
|
||||
pub fn remove(self: *CSSRuleList, index: u32) void {
|
||||
pub fn remove(self: *CSSRuleList, index: u32) !void {
|
||||
if (index >= self._rules.items.len) {
|
||||
return; // Ignore or throw? Standard says IndexSizeError DOMException, but we might just no-op or return an error depending on the caller.
|
||||
return error.IndexSizeError;
|
||||
}
|
||||
_ = self._rules.orderedRemove(index);
|
||||
}
|
||||
|
||||
@@ -193,7 +193,6 @@ pub fn setCssText(self: *CSSStyleDeclaration, text: []const u8, page: *Page) !vo
|
||||
while (it.next()) |declaration| {
|
||||
try self.setPropertyImpl(declaration.name, declaration.value, declaration.important, page);
|
||||
}
|
||||
|
||||
try self.syncStyleAttribute(page);
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ pub fn insertRule(self: *CSSStyleSheet, rule: []const u8, index: u32, page: *Pag
|
||||
|
||||
pub fn deleteRule(self: *CSSStyleSheet, index: u32, page: *Page) !void {
|
||||
const rules = try self.getCssRules(page);
|
||||
rules.remove(index);
|
||||
try rules.remove(index);
|
||||
}
|
||||
|
||||
pub fn replace(self: *CSSStyleSheet, text: []const u8, page: *Page) !js.Promise {
|
||||
@@ -116,8 +116,8 @@ pub const JsApi = struct {
|
||||
pub const disabled = bridge.accessor(CSSStyleSheet.getDisabled, CSSStyleSheet.setDisabled, .{});
|
||||
pub const cssRules = bridge.accessor(CSSStyleSheet.getCssRules, null, .{});
|
||||
pub const ownerRule = bridge.accessor(CSSStyleSheet.getOwnerRule, null, .{});
|
||||
pub const insertRule = bridge.function(CSSStyleSheet.insertRule, .{});
|
||||
pub const deleteRule = bridge.function(CSSStyleSheet.deleteRule, .{});
|
||||
pub const insertRule = bridge.function(CSSStyleSheet.insertRule, .{ .dom_exception = true });
|
||||
pub const deleteRule = bridge.function(CSSStyleSheet.deleteRule, .{ .dom_exception = true });
|
||||
pub const replace = bridge.function(CSSStyleSheet.replace, .{});
|
||||
pub const replaceSync = bridge.function(CSSStyleSheet.replaceSync, .{});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user