Proposal: Stop using Object.freeze/Object.seal on most of our Javascript Objects

Richard Newman rnewman at
Mon Nov 20 16:00:09 UTC 2017

> Are there alternative ways we could achieve the same without the (or with
> low) complexity/overhead?

If I'm understanding correctly what you're trying to do, the typical
suggestion here is to not use global singletons. That way you don't need to
dig into the guts of a globally visible object in order to test it; you can
pass your own part-mocked Object instance into whatever mechanism is trying
to call ``.

In your `foo`/`bar` case, you'd pass a `MockObject` to `bar`, and verify
that `` was called. We do this all the time in codebases that
use less dynamic languages (e.g., Fennec and Firefox for iOS).

This doesn't help you to test existing singleton-based JS code… but then,
if that code is already using Object.freeze, then you already can't, and
you'll be having to change _something_.

I mostly agree with Nicolas's sentiment; poking at the guts of code outside
your own module (or even in your own module!) isn't really a kind of
software development that I feel we should encourage. If we find that
gut-poking is the only good way to write tests for a component, then I
would rather we revisit the design of the component instead of making it
mutable. Refactoring for testability is A-OK in my book.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the firefox-dev mailing list