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>
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
no-control-regex: 2
## check debugger sentence
function protoCtrChain(o) {
var result = [];
- for (; o; o = o.__proto__) { result.push(o.constructor); }
+ for (; o; o = Object.getPrototypeOf(o)) { result.push(o.constructor); }
return result.join();
}
assert.throws(function() {
function AB() { }
- AB.__proto__ = ArrayBuffer;
- AB.prototype.__proto__ = ArrayBuffer.prototype;
+ Object.setPrototypeOf(AB, ArrayBuffer);
+ Object.setPrototypeOf(AB.prototype, ArrayBuffer.prototype);
new Buffer(new AB());
}, TypeError);
const Buffer = require('buffer').Buffer;
function FakeBuffer() { }
-FakeBuffer.__proto__ = Buffer;
-FakeBuffer.prototype.__proto__ = Buffer.prototype;
+Object.setPrototypeOf(FakeBuffer, Buffer);
+Object.setPrototypeOf(FakeBuffer.prototype, Buffer.prototype);
const fb = new FakeBuffer();
vals.forEach(function(t) {
assert.equal(t.constructor, T);
- assert.equal(t.__proto__, T.prototype);
- assert.equal(t.__proto__.__proto__, Buffer.prototype);
+ assert.equal(Object.getPrototypeOf(t), T.prototype);
+ assert.equal(Object.getPrototypeOf(Object.getPrototypeOf(t)),
+ Buffer.prototype);
t.fill(5);
let cntr = 0;
var env = {
'HELLO': 'WORLD'
};
-env.__proto__ = {
+Object.setPrototypeOf(env, {
'FOO': 'BAR'
-};
+});
var child;
if (common.isWindows) {