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
Should we use FrozenArray instead of StyleSheetList for adoptedStyleSheets? #36
Comments
Yeah. I think this is probably the right path. The only drawback is consistency. For web developers (as opposed to implementers/spec authors) the lack of consistency would be observable in the following ways: document.styleSheets instanceof StyleSheetList; // true
document.adoptedStyleSheets instanceof StyleSheetList; // false
document.styleSheets.item(0); // works, although [0] does too
document.adoptedStyleSheets.item(0); // does not work; use [0] instead I think these are not very bad, so FrozenArray is probably better. |
I'm not sure I understand; FrozenArray is fixed-length and readonly, so you can't use array assignment and other stuff on it. |
If the attribute is not read-only, you can use array assignment on it. See Web IDL spec. Not sure what "other stuff" StyleSheetList has that FrozenArray does not. |
That... doesn't appear to be true, or if it is, WebIDL is at least severely misleading on this point. 2.13.32 says:
3.2.26, in the "create a frozen array" algorithm, freezes the constructed array:
Am I totally misreading this, or missing a part somewhere else that contradicts these lines and makes the array modifiable?
Because it's frozen, |
Attribute definitions are separate from type definitions. You can have an immutable value held by a mutable attribute. (This is similar to how you can store an immutable value in a let binding, and then still reassign the binding to point to another value.) When you assign to such an attribute it creates a new frozen array using the algorithm you referred to and starts returning that. StyleSheetList doesn't have .push() either. |
Yes, you can replace the whole
Right, that would have gotten added, as appending newly-created sheets to the list is the whole point of |
I guess I don't know what "array assignment" means if it doesn't mean "assigning an array" |
Assigning to an array, like |
If we do add If there's no way to prevent that then that means we can't add the function, so I think the FrozenArray approach is better here since you can just assign a normal array, instead of making another object that doesn't really do anything. |
Yeah, we should stick with FrozenArray for now. I discussed this with @domenic, and we might want to upgrade it into an array-like later, but that should be consistent with FrozenArray for now. (Changing will just mean that some things that throw would start working instead, I think.) |
Cool, let me update the spec and explainer and close this soon. |
Spec update is merged at #40. |
If we do, we don't need to introduce a constructor for
StyleSheetList
, and can use array assignment and other functions directly onadoptedStyleSheets
.cc @domenic who pointed this out.
The text was updated successfully, but these errors were encountered: