Skip to content

[cssom-1] Expected error type when trying to insert an invalid rule in a grouping rule #14537

Open

Description

@cdoublev

If you try to insert @top-left or @annotation (valid only in @page or @font-feature-values) in a style sheet or a grouping rule (e.g. @media), Chrome and Firefox throw a SyntaxError. I do no think there is a related WPT test for this.

But if you try to insert @namespace or @import (valid only at the top-level) in a grouping rule, they throw a HierarchyRequestError. There is this WPT test for this.

I also note that if you try to insert any other rule than a page margin rule in @page (which is a grouping rule), Chrome throws a SyntaxError while Firefox throws a HierarchyRequestError.

At first glance, HierarchyRequestError seems well-suited when trying to insert @import, @namespace, or @layer, following some other rules. Based on the underlying algorithms for .insertRule(), a SyntaxError must be thrown when the result from parse a rule is a "syntax error". The parsing algorithms defined in CSS Syntax have become context-sensitive since the introduction of nested style rules. Therefore, they should now identify these rules as a syntax error, assuming the context is defined by any ancestor or sibling rule (or the style sheet). And HierarchyRequestError can no longer be thrown.

Could all of this be clarified?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    cssom-1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions