mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
src: fix vm bug for configurable globalThis
Object.defineProperty allows to change the value for non-writable properties if they are configurable. We missed that case when checking if a property is read-only. Fixes: https://github.com/nodejs/node/issues/47799 PR-URL: https://github.com/nodejs/node/pull/51602 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
a7eb72d23d
commit
1cd9a95e29
@ -609,11 +609,14 @@ void ContextifyContext::PropertyDefinerCallback(
|
||||
bool read_only =
|
||||
static_cast<int>(attributes) &
|
||||
static_cast<int>(PropertyAttribute::ReadOnly);
|
||||
bool dont_delete = static_cast<int>(attributes) &
|
||||
static_cast<int>(PropertyAttribute::DontDelete);
|
||||
|
||||
// If the property is set on the global as read_only, don't change it on
|
||||
// the global or sandbox.
|
||||
if (is_declared && read_only)
|
||||
// If the property is set on the global as neither writable nor
|
||||
// configurable, don't change it on the global or sandbox.
|
||||
if (is_declared && read_only && dont_delete) {
|
||||
return;
|
||||
}
|
||||
|
||||
Local<Object> sandbox = ctx->sandbox();
|
||||
|
||||
|
15
test/parallel/test-vm-global-configurable-properties.js
Normal file
15
test/parallel/test-vm-global-configurable-properties.js
Normal file
@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
// https://github.com/nodejs/node/issues/47799
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
const vm = require('vm');
|
||||
|
||||
const ctx = vm.createContext();
|
||||
|
||||
const window = vm.runInContext('this', ctx);
|
||||
|
||||
Object.defineProperty(window, 'x', { value: '1', configurable: true });
|
||||
assert.strictEqual(window.x, '1');
|
||||
Object.defineProperty(window, 'x', { value: '2', configurable: true });
|
||||
assert.strictEqual(window.x, '2');
|
Loading…
Reference in New Issue
Block a user