PAC-K010 · es2015-builtins

ES2015+ library methods (startsWith, flat, replaceAll, globalThis)

medium · Compatibility across engines

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 checker

Good

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 checker

Engine behaviour

EngineBehaviourSource
winhttpPresent: 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

Source: code = read in the engine's source, doc = vendor documentation, lab = observed in a lab run, expert = practitioner knowledge, not yet verified.

Related rules

References

Last updated: