Skip to main content

ServiceNow: Arrow Functions (and more) Everywhere!

Christopher Crockett

Did you know? Starting in the Washington release, ServiceNow's Rhino engine now natively supports JavaScript Arrow Functions!

Even as recently as Vancouver, Arrow Functions wouldn't have worked...

It works everywhere server-side code runs. Even in the Global scope without using the new "Turn on ECMAScript 2021 (ES12) mode" button.

Yet now they work! No special properties or scopes required.

How can this be??

Those of you following recent ServiceNow releases have probably already (correctly) intuited that this new development must be somehow related to the recent introduction of the new "ES12" JavaScript Mode. This is true... to an extent.

The "JavaScript Mode" setting available via Application configuration.

Internally, ServiceNow uses an ancient JavaScript engine known as Rhino. Rhino doesn't support most ES12 features, yet ServiceNow still somehow supports ES12... How is ServiceNow pulling off that magic trick? In short: Transpilation. Transpilers automatically convert modern code into legacy-compatible code – ServiceNow has a built-in auto-transpiler which automatically converts code wherever "ES12" mode has been enabled.

Babel is a popular transpiler. ServiceNow probably uses a different transpiler stack, though!

So, is that what's going on here? Did ServiceNow accidentally turn on their magic transpilation step everywhere and somehow never notice? Nope! That's definitely not the case because many other ES12 JavaScript features available remain unusable.

If this were transpilation, we'd expect other non-Rhino syntax to also work!

So... what's going on here, if not transpilation? The answer is actually rather simple: ServiceNow's version of Rhino has been upgraded to a newer release – first 1.7.12 in Washington, then 1.7.14 in Xanadu.

Up through Vancouver, we were (most likely) on version 1.7R5

We can prove this by checking if Array.prototype.includes is available. This is a newer Array method which only gained support starting in Rhino version 1.7.12.

Just how long have we all been waiting for this moment??

The proof is in the pudding. As you can see below: Rhino has gained native support for many new language features which were previously impossible!

array.indexOf('foo') !== -1 begone!

This long-overdue engine update can be chalked up to a happy side-effect of ServiceNow's ongoing work on the new "ES12" JavaScript transpilation mode:
More engine features => Less transpilation => Better performance & accuracy

What's The Catch?

The catch is that Rhino is still an old engine without full ES12 support. Even if some new features have become available, >50% of all modern JavaScript features are still unavailable to Rhino. In other words: most modern features are still locked behind transpilation (i.e. "ES12" mode), Rhino upgrade notwithstanding.

Unfortunately, Rhino is still an old engine with many missing features

How do I know what's newly available in my Instance?

Our research indicates two recent upgrades to the Rhino engine:

  • Washington: Rhino 1.7.12
  • Xanadu: Rhino 1.7.14

Consulting this table, search for any features which were red in 1.7R5 and now green in your instance's Rhino version (see directly above). Easy peasy!

Not so easy? Well, dear reader, this must be your lucky day because as a special gift just for you I've already compiled a list and snuck it in right below 😁