diff options
author | Mike Samuel <mikesamuel@gmail.com> | 2018-11-28 13:06:46 -0500 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2018-11-30 23:31:52 -0800 |
commit | 0d2311820d50e29b83eb9f885d961f9b43dfd165 (patch) | |
tree | 292c2fb3033c10e3715f8376e0cb8b0746a9e023 /node.gypi | |
parent | 76faccccbb51bb477a88ebfa3fa2a8254da37696 (diff) | |
download | android-node-v8-0d2311820d50e29b83eb9f885d961f9b43dfd165.tar.gz android-node-v8-0d2311820d50e29b83eb9f885d961f9b43dfd165.tar.bz2 android-node-v8-0d2311820d50e29b83eb9f885d961f9b43dfd165.zip |
url: use SafeSet to filter known special protocols
Avoids a maintenance hazard when reviewers assume that
`hostlessProtocol` and `slashedProtocol` are disjoint.
The following may be counter-intuitive:
```js
// These objects seem to have no keys in common
const hostlessProtocol = { 'javascript': true };
const slashedProtocol = { 'http': true };
// A reasonable reviewer may assumes bothTrue is never truthy
function bothTrue(lowerProto) {
return hostlessProtocol[lowerProto] && slashedProtocol[lowerProto];
}
// But
console.log(Boolean(bothTrue('constructor'))); // true
```
This change uses SafeSet instead of plain-old objects.
----
Rejected alternative:
We could have used object with a `null` prototype as lookup tables
so that `lowerProto` is never treated as a key into `Object.prototype`.
```js
const hostlessProtocol = { __proto__: null, 'javascript': true };
const slashedProtocol = { __proto__: null, 'http': true };
function bothTrue(lowerProto) {
return hostlessProtocol[lowerProto] && slashedProtocol[lowerProto];
}
console.log(Boolean(bothTrue('constructor'))); // false
```
PR-URL: https://github.com/nodejs/node/pull/24703
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'node.gypi')
0 files changed, 0 insertions, 0 deletions