Replies: 1 comment 3 replies
|
To me, I think there's a certain amount of "Doctor, it hurts when I do this", "Then don't do that" going on here. Mixing context managers and explicit state control is always going to be a bit of a mess, and if people do this, they should expect hilarity. If the HTML Canvas spec says it's a no-op, then I feel like we need to honour that. I could maybe go as far as a warning, since that could be suppressed; but the real fix here is "balance your state saves", and document that you shouldn't mix context managers with explicit save/restore. I guess one option (conceptually - I haven't thought through how it would work in practice) would be to only allow manual restores of a manual save - that is, the explicit The output of the two |
Uh oh!
There was an error while loading. Please reload this page.
The MDN docs for
restore()say:So if called at the root, without a prior call to
save(), it should just be a no-op. But I've been considering if we ought to throw an error — or at least a warning — when it happens inside a substate. Because this puts things in very strange territory:Allowing this breaks the contract of all of a state's drawing actions being run within that state; that first fill is effectively outside of the state that contains it. It also — and this is the reason I thought of it in the first place — makes it significantly harder to accurately query context attributes. I realized we're not testing this case, and the code as-is won't be able to figure it out. I'm not sure it's worth the twisted logic to get it right — but whether that means raising a warning telling the user this when they call the erroneous
restore, or raising an exception to entirely disallow it, I'm not sure. I'd appreciate your thoughts if you have any, @freakboy3742 and/or @corranwebster.All reactions