ES2015+ library methods (startsWith, flat, replaceAll, globalThis)
medium
Unlike ES2015 syntax, newer library methods parse fine on an old engine and fail only at runtime with a TypeError for the request that reaches them. The branch then behaves like a script failure.
Why it matters
host.endsWith(".corp.example") is valid ES5 syntax, so an engine without the method loads
the file and only throws TypeError: host.endsWith is not a function when the line executes.
That is harder to notice than a parse error: the PAC works in Chrome and in a quick test,
and fails on another engine for exactly the hosts that reach the branch.
Engines differ in which methods they have. In the lab on Windows 11 (2026-10-11) Windows had
the ES2015 to ES2017 methods includes and padStart, the entries method of Object, and
Map and Set, but not the newer flat, replaceAll, at, the fromEntries method of
Object or globalThis; a call to one of these throws on every Windows program. Older
engines such as pactester 1.4 lack the ES2015 methods as well. ES5 equivalents exist for all
of them (indexOf, slice, substring, shExpMatch, dnsDomainIs, a plain loop).
How to fix
Use dnsDomainIs/shExpMatch for suffix and prefix tests and indexOf for membership; avoid Map/Set/Promise in PAC files.
Examples
Bad
var direct = ["intranet.corp.example", "wiki.corp.example"];
function FindProxyForURL(url, host) {
if (direct.includes(host) || host.endsWith(".lab.example")) {
return "DIRECT";
}
return "PROXY proxy.corp.example:8080";
}
Open bad example in checkerGood
var direct = ["intranet.corp.example", "wiki.corp.example"];
function FindProxyForURL(url, host) {
if (direct.indexOf(host) >= 0 || dnsDomainIs(host, ".lab.example")) {
return "DIRECT";
}
return "PROXY proxy.corp.example:8080";
}
Open good example in checkerEngine behaviour
| Engine | Behaviour | Source |
|---|---|---|
| winhttp | Present: Array includes, String padStart, Object.entries, Map, Set, Promise, Symbol, Proxy, Reflect. Missing (undefined, so a call throws): Array flat, Object.fromEntries, String replaceAll, Array at, globalThis. | lab, verified 2026-10-11 |
Related rules
- ES2015 to ES2017 syntax (let, const, arrow functions, template literals) PAC-K001
- Evaluation throws an exception PAC-E006