Skip to content

[cssom] Should insertRule() return or throw a syntax error? #9234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cdoublev opened this issue Aug 24, 2023 · 1 comment · Fixed by #9272
Closed

[cssom] Should insertRule() return or throw a syntax error? #9234

cdoublev opened this issue Aug 24, 2023 · 1 comment · Fixed by #9272

Comments

@cdoublev
Copy link
Collaborator

https://drafts.csswg.org/cssom-1/#dom-cssstylesheet-insertrule

  1. Let parsed rule be the return value of invoking parse a rule with rule.
  2. If parsed rule is a syntax error, return parsed rule.

All mainstream browsers do not return a syntax error but throws a SyntaxError DOMException when the result of parse a rule is a syntax error:

try {
  document.styleSheets[0].insertRule(' ')
} catch (error) {
  error.name // SyntaxError
  error // DOMException: Failed to execute 'insertRule' on 'CSSStyleSheet': Failed to parse the rule ' '.
}

Furthermore, the Web IDL definition does not allow to return syntax error:

  unsigned long insertRule(CSSOMString rule, optional unsigned long index = 0);

Should the current procedure be updated to this interopable behavior?

@cdoublev cdoublev added the cssom-1 Current Work label Aug 24, 2023
@tabatkins
Copy link
Member

Yeah, that's just an incoherent line. The "syntax error" isn't an reifiable object in any way, just a spec concept to indicate that the parsing failed. It should indeed explicitly throw a SyntaxError DOMException.

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

Successfully merging a pull request may close this issue.

2 participants