dns: Use object without protoype for map

Currently we use `{}` for the `lookup` function to find the relevant
resolver to the dns.resolve function. It is preferable to use an
object without a Object.prototype, currently for example you can do
something like:

```js
dns.resolve("google.com", "toString", console.log);
```

And get `[Object undefined]` logged and the callback would never be
called. This is unexpected and strange behavior in my opinion.
In addition, if someone adds a property to `Object.prototype` might
also create unexpected results.

This pull request fixes it, with it an appropriate error is thrown.

PR-URL: https://github.com/nodejs/node/pull/5843
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Benjamin Gruenbaum authored and James M Snell committed 2016-03-22 11:13:03 -07:00
1 parent 4985c3411f
commit c9c387fdac
2 files changed
+6 -1

No files matched your search

+1 -1
View File
@@ -243,7 +243,7 @@ function resolver(bindingName) {
}
var resolveMap = {};
var resolveMap = Object.create(null);
exports.resolve4 = resolveMap.A = resolver('queryA');
exports.resolve6 = resolveMap.AAAA = resolver('queryAaaa');
exports.resolveCname = resolveMap.CNAME = resolver('queryCname');
+5
View File
@@ -27,6 +27,11 @@ assert.throws(function() {
dns.resolve('www.google.com', 'HI');
}, /Unknown type/);
// Try calling resolve with an unsupported type that's an object key
assert.throws(function() {
dns.resolve('www.google.com', 'toString');
}, /Unknown type/);
// Windows doesn't usually have an entry for localhost 127.0.0.1 in
// C:\Windows\System32\drivers\etc\hosts
// so we disable this test on Windows.