tools: enable no-proto rule for linter
Enable `no-proto` in `.eslintrc`. Use `Object.setPrototypeOf()` and `Object.getPrototypeOf()` instead of. PR-URL: https://github.com/nodejs/node/pull/5140 Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
826844e27e
commit
cc195bf37b
@ -17,6 +17,8 @@ ecmaFeatures:
|
|||||||
rules:
|
rules:
|
||||||
# Possible Errors
|
# Possible Errors
|
||||||
# list: https://github.com/eslint/eslint/tree/master/docs/rules#possible-errors
|
# list: https://github.com/eslint/eslint/tree/master/docs/rules#possible-errors
|
||||||
|
## Disallow Use of __proto__
|
||||||
|
no-proto: 2
|
||||||
## disallow control characters in regular expressions
|
## disallow control characters in regular expressions
|
||||||
no-control-regex: 2
|
no-control-regex: 2
|
||||||
## check debugger sentence
|
## check debugger sentence
|
||||||
|
@ -190,7 +190,7 @@ exports.hasIPv6 = Object.keys(ifaces).some(function(name) {
|
|||||||
|
|
||||||
function protoCtrChain(o) {
|
function protoCtrChain(o) {
|
||||||
var result = [];
|
var result = [];
|
||||||
for (; o; o = o.__proto__) { result.push(o.constructor); }
|
for (; o; o = Object.getPrototypeOf(o)) { result.push(o.constructor); }
|
||||||
return result.join();
|
return result.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,8 +40,8 @@ assert.equal(dv.getFloat64(8, true), 3.1415);
|
|||||||
|
|
||||||
assert.throws(function() {
|
assert.throws(function() {
|
||||||
function AB() { }
|
function AB() { }
|
||||||
AB.__proto__ = ArrayBuffer;
|
Object.setPrototypeOf(AB, ArrayBuffer);
|
||||||
AB.prototype.__proto__ = ArrayBuffer.prototype;
|
Object.setPrototypeOf(AB.prototype, ArrayBuffer.prototype);
|
||||||
new Buffer(new AB());
|
new Buffer(new AB());
|
||||||
}, TypeError);
|
}, TypeError);
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@ const assert = require('assert');
|
|||||||
const Buffer = require('buffer').Buffer;
|
const Buffer = require('buffer').Buffer;
|
||||||
|
|
||||||
function FakeBuffer() { }
|
function FakeBuffer() { }
|
||||||
FakeBuffer.__proto__ = Buffer;
|
Object.setPrototypeOf(FakeBuffer, Buffer);
|
||||||
FakeBuffer.prototype.__proto__ = Buffer.prototype;
|
Object.setPrototypeOf(FakeBuffer.prototype, Buffer.prototype);
|
||||||
|
|
||||||
const fb = new FakeBuffer();
|
const fb = new FakeBuffer();
|
||||||
|
|
||||||
|
@ -24,8 +24,9 @@ const vals = [new T(4), T(4)];
|
|||||||
|
|
||||||
vals.forEach(function(t) {
|
vals.forEach(function(t) {
|
||||||
assert.equal(t.constructor, T);
|
assert.equal(t.constructor, T);
|
||||||
assert.equal(t.__proto__, T.prototype);
|
assert.equal(Object.getPrototypeOf(t), T.prototype);
|
||||||
assert.equal(t.__proto__.__proto__, Buffer.prototype);
|
assert.equal(Object.getPrototypeOf(Object.getPrototypeOf(t)),
|
||||||
|
Buffer.prototype);
|
||||||
|
|
||||||
t.fill(5);
|
t.fill(5);
|
||||||
let cntr = 0;
|
let cntr = 0;
|
||||||
|
@ -7,9 +7,9 @@ var spawn = require('child_process').spawn;
|
|||||||
var env = {
|
var env = {
|
||||||
'HELLO': 'WORLD'
|
'HELLO': 'WORLD'
|
||||||
};
|
};
|
||||||
env.__proto__ = {
|
Object.setPrototypeOf(env, {
|
||||||
'FOO': 'BAR'
|
'FOO': 'BAR'
|
||||||
};
|
});
|
||||||
|
|
||||||
var child;
|
var child;
|
||||||
if (common.isWindows) {
|
if (common.isWindows) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user