phantomjs2: fix evaluation and refactor
The error was due to the fact that with-introduced bindings have lower
priority and we do have `darwin` in scope already.
Fixes #12350. Closes #12351. (A slightly different fix.
I chose this to lower the risk of people re-introducing the mistake.)