Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8a6367c

Browse filesBrowse files
addaleaxItalo A. Casas
authored andcommitted
Revert "src: don't overwrite non-writable vm globals"
This reverts commit 524f693. Fixes: #10806 Fixes: #10492 Ref: #10227 PR-URL: #10920 Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent d39543e commit 8a6367c
Copy full SHA for 8a6367c

File tree

Expand file treeCollapse file tree

2 files changed

+10
-24
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+10
-24
lines changed
Open diff view settings
Collapse file

‎src/node_contextify.cc‎

Copy file name to clipboardExpand all lines: src/node_contextify.cc
+10-13Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -383,22 +383,19 @@ class ContextifyContext {
383383
if (ctx->context_.IsEmpty())
384384
return;
385385

386-
auto attributes = PropertyAttribute::None;
387386
bool is_declared =
388-
ctx->global_proxy()->GetRealNamedPropertyAttributes(ctx->context(),
389-
property)
390-
.To(&attributes);
391-
bool read_only =
392-
static_cast<int>(attributes) &
393-
static_cast<int>(PropertyAttribute::ReadOnly);
394-
395-
if (is_declared && read_only)
396-
return;
387+
ctx->global_proxy()->HasRealNamedProperty(ctx->context(),
388+
property).FromJust();
389+
bool is_contextual_store = ctx->global_proxy() != args.This();
397390

398-
if (!is_declared && args.ShouldThrowOnError())
399-
return;
391+
bool set_property_will_throw =
392+
args.ShouldThrowOnError() &&
393+
!is_declared &&
394+
is_contextual_store;
400395

401-
ctx->sandbox()->Set(property, value);
396+
if (!set_property_will_throw) {
397+
ctx->sandbox()->Set(property, value);
398+
}
402399
}
403400

404401

Collapse file

‎test/parallel/test-vm-context.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-vm-context.js
-11Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,3 @@ assert.throws(function() {
7575
// https://github.com/nodejs/node/issues/6158
7676
ctx = new Proxy({}, {});
7777
assert.strictEqual(typeof vm.runInNewContext('String', ctx), 'function');
78-
79-
// https://github.com/nodejs/node/issues/10223
80-
ctx = vm.createContext();
81-
vm.runInContext('Object.defineProperty(this, "x", { value: 42 })', ctx);
82-
assert.strictEqual(ctx.x, undefined); // Not copied out by cloneProperty().
83-
assert.strictEqual(vm.runInContext('x', ctx), 42);
84-
vm.runInContext('x = 0', ctx); // Does not throw but x...
85-
assert.strictEqual(vm.runInContext('x', ctx), 42); // ...should be unaltered.
86-
assert.throws(() => vm.runInContext('"use strict"; x = 0', ctx),
87-
/Cannot assign to read only property 'x'/);
88-
assert.strictEqual(vm.runInContext('x', ctx), 42);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.