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

Source: https://findproxyforurl.net/rules/es2015-builtins/ · last updated 2026-10-11

Rule PAC-K010 (`es2015-builtins`), severity medium, category: 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.

## Bad

```js
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";
}
```

## Good

```js
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";
}
```

## Engine behaviour

- 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. (source: lab, verified 2026-10-11)
