ClojureScript and RegExp.source

2015-04-02 / Site compat, Specs

The basic social contracts on the web is that browsers should strive to implement standards, sites should write their code according to standards, and the authors of the standards should take great care to write implementable specs.

Sometimes, more often than you might expect, a small detail in a new spec causes a compatibility problem. When this happens, either the spec or the affected websites must change. (If neither does, the problem is simply dumped on browser vendors who must decide whether they want to follow the spec or make websites work).

Yes, sometimes we do ask the web to change itself. It happens. Perhaps it even happens more and more often. (A related example: browsers are hardening their security and start disallowing more weak encryption methods - which means a significant number of sites using these old methods need to change.)

This raises several interesting questions: how do we even find the problem in the first place? How do we find as many affected sites as possible? How do we figure out the right people to talk to when we want a site fixed?

Mozilla’s bug 1138325 is a good example of this cycle. A minor change deep in the ECMAScript engine while it is updated to the new Edition 6 version of the spec caused a problem described as “Turning RegExp#source from an instance property into an accessor breaks ClojureScript apps”. This was fixed in the ClojureScript library rather quickly. However, the library is used on several sites - and if they don’t update, the issue will remain a problem. This might make it needlessly painful for all browsers trying to update to ECMAScript edition 6.

The ClojureScript project had a handy reference list listing users. Using a SlimerJS-based URL player I’ve been developing, injecting a little bit of code looking for the problematic JavaScript, I scanned through these URLs, 63 sites. Here’s an excerpt of this log:

Presumably ClojureScript http://jamesmacaulay.github.io/zelkova-todomvc/js/app.js
Broken ClojureScript seen! http://jamesmacaulay.github.io/zelkova-todomvc/js/app.js

Presumably ClojureScript http://www.8thlight.com/
Broken ClojureScript seen! http://www.8thlight.com/assets/eighthlight-200eb63b72445bdaca9c38e9e19f7b86.js

Now opening https://www.cognician.com/
Broken ClojureScript seen! https://s3.amazonaws.com/cognician-static/js/elf/elf.js

This approach found 11 sites with old ClojureScript. There are 7 sites with presumably updated versions (the word ‘clojure’ in source but the scrip does not contain hasOwnProperty(“source”). The remaining 45 sites had no ‘clojure’ in source. They might use ClojureScript on a non-front page part of the site, or internally. Scanning the public parts of sites won’t find everything (ebay.com listed as a user is particularly intriguing).

Next step is to contact the sites and ask them to upgrade. I’ve opened bugs on webcompat.com to track this work. With some luck, the next browser engine that tries to implement ES6 might not run into this particular problem.