node/test/parallel/test-disable-proto-throw.js
Rich Trott e2e2bc83c0
test: use Object.hasOwn() where applicable
Replace Object.prototpye.hasOwnProperty() with Object.hasOwn() where
applicable.

PR-URL: https://github.com/nodejs/node/pull/41664
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Mestery <mestery@protonmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Tierney Cyren <hello@bnb.im>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2022-01-25 07:03:17 +00:00

45 lines
824 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.hasOwn(Object.prototype, '__proto__'));
assert.throws(() => {
// eslint-disable-next-line no-proto,no-unused-expressions
({}).__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();
}