Skip to content

Commit fc50bbf

Browse files
JacksonTianMyles Borins
authored and
Myles Borins
committed
tools: enable no-proto rule for linter
Enable `no-proto` in `.eslintrc`. Use `Object.setPrototypeOf()` and `Object.getPrototypeOf()` instead of. PR-URL: #5140 Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 8727d7a commit fc50bbf

File tree

6 files changed

+12
-9
lines changed

6 files changed

+12
-9
lines changed

.eslintrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ ecmaFeatures:
1717
rules:
1818
# Possible Errors
1919
# list: https://github.com/eslint/eslint/tree/master/docs/rules#possible-errors
20+
## Disallow Use of __proto__
21+
no-proto: 2
2022
## disallow control characters in regular expressions
2123
no-control-regex: 2
2224
## check debugger sentence

test/common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ exports.hasIPv6 = Object.keys(ifaces).some(function(name) {
190190

191191
function protoCtrChain(o) {
192192
var result = [];
193-
for (; o; o = o.__proto__) { result.push(o.constructor); }
193+
for (; o; o = Object.getPrototypeOf(o)) { result.push(o.constructor); }
194194
return result.join();
195195
}
196196

test/parallel/test-buffer-arraybuffer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ assert.equal(dv.getFloat64(8, true), 3.1415);
4040

4141
assert.throws(function() {
4242
function AB() { }
43-
AB.__proto__ = ArrayBuffer;
44-
AB.prototype.__proto__ = ArrayBuffer.prototype;
43+
Object.setPrototypeOf(AB, ArrayBuffer);
44+
Object.setPrototypeOf(AB.prototype, ArrayBuffer.prototype);
4545
new Buffer(new AB());
4646
}, TypeError);
4747

test/parallel/test-buffer-fakes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const assert = require('assert');
55
const Buffer = require('buffer').Buffer;
66

77
function FakeBuffer() { }
8-
FakeBuffer.__proto__ = Buffer;
9-
FakeBuffer.prototype.__proto__ = Buffer.prototype;
8+
Object.setPrototypeOf(FakeBuffer, Buffer);
9+
Object.setPrototypeOf(FakeBuffer.prototype, Buffer.prototype);
1010

1111
const fb = new FakeBuffer();
1212

test/parallel/test-buffer-inheritance.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ const vals = [new T(4), T(4)];
2424

2525
vals.forEach(function(t) {
2626
assert.equal(t.constructor, T);
27-
assert.equal(t.__proto__, T.prototype);
28-
assert.equal(t.__proto__.__proto__, Buffer.prototype);
27+
assert.equal(Object.getPrototypeOf(t), T.prototype);
28+
assert.equal(Object.getPrototypeOf(Object.getPrototypeOf(t)),
29+
Buffer.prototype);
2930

3031
t.fill(5);
3132
let cntr = 0;

test/parallel/test-child-process-env.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ var spawn = require('child_process').spawn;
77
var env = {
88
'HELLO': 'WORLD'
99
};
10-
env.__proto__ = {
10+
Object.setPrototypeOf(env, {
1111
'FOO': 'BAR'
12-
};
12+
});
1313

1414
var child;
1515
if (common.isWindows) {

0 commit comments

Comments
 (0)