Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: fix vm bug for configurable globalThis #51602

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
15 changes: 15 additions & 0 deletions test/parallel/test-vm-global-configurable-properties.js
Original file line number Diff line number Diff line change
@@ -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