mirror of
https://github.com/nodejs/node.git
synced 2025-05-20 23:55:47 +00:00

Adds `--disable-proto` CLI option which can be set to `delete` or `throw`. Fixes #31951 PR-URL: https://github.com/nodejs/node/pull/32279 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
45 lines
802 B
JavaScript
45 lines
802 B
JavaScript
// Flags: --disable-proto=throw
|
|
|
|
'use strict';
|
|
|
|
require('../common');
|
|
const assert = require('assert');
|
|
const vm = require('vm');
|
|
const { Worker, isMainThread } = require('worker_threads');
|
|
|
|
assert(Object.prototype.hasOwnProperty('__proto__'));
|
|
|
|
assert.throws(() => {
|
|
// eslint-disable-next-line no-proto
|
|
({}).__proto__;
|
|
}, {
|
|
code: 'ERR_PROTO_ACCESS'
|
|
});
|
|
|
|
assert.throws(() => {
|
|
// eslint-disable-next-line no-proto
|
|
({}).__proto__ = {};
|
|
}, {
|
|
code: 'ERR_PROTO_ACCESS',
|
|
});
|
|
|
|
const ctx = vm.createContext();
|
|
|
|
assert.throws(() => {
|
|
vm.runInContext('({}).__proto__;', ctx);
|
|
}, {
|
|
code: 'ERR_PROTO_ACCESS'
|
|
});
|
|
|
|
assert.throws(() => {
|
|
vm.runInContext('({}).__proto__ = {};', ctx);
|
|
}, {
|
|
code: 'ERR_PROTO_ACCESS',
|
|
});
|
|
|
|
if (isMainThread) {
|
|
new Worker(__filename);
|
|
} else {
|
|
process.exit();
|
|
}
|