Fix context leaks when using Context.update().

Context.update() implies a push(), which some of our code wasn't
accounting for, resulting in leaked state This mainly impacted
extensions, though datagrids were also doing this (not resulting in
leaks, but rather slightly slowing down rendering).

We now construct a Context as late as possible, instead of creating one
early and operating on it, and pop() when necessary.

Reviewed at https://reviews.reviewboard.org/r/5763/