Skip to content

Commit

Permalink
Revert "src: don't overwrite non-writable vm globals"
Browse files Browse the repository at this point in the history
This reverts commit 524f693.

Fixes: #10806
Fixes: #10492
Ref: #10227
PR-URL: #10920
Reviewed-By: Franziska Hinkelmann <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
  • Loading branch information
addaleax authored and italoacasas committed Jan 30, 2017
1 parent d39543e commit 8a6367c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
23 changes: 10 additions & 13 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -383,22 +383,19 @@ class ContextifyContext {
if (ctx->context_.IsEmpty())
return;

auto attributes = PropertyAttribute::None;
bool is_declared =
ctx->global_proxy()->GetRealNamedPropertyAttributes(ctx->context(),
property)
.To(&attributes);
bool read_only =
static_cast<int>(attributes) &
static_cast<int>(PropertyAttribute::ReadOnly);

if (is_declared && read_only)
return;
ctx->global_proxy()->HasRealNamedProperty(ctx->context(),
property).FromJust();
bool is_contextual_store = ctx->global_proxy() != args.This();

if (!is_declared && args.ShouldThrowOnError())
return;
bool set_property_will_throw =
args.ShouldThrowOnError() &&
!is_declared &&
is_contextual_store;

ctx->sandbox()->Set(property, value);
if (!set_property_will_throw) {
ctx->sandbox()->Set(property, value);
}
}


Expand Down
11 changes: 0 additions & 11 deletions test/parallel/test-vm-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,3 @@ assert.throws(function() {
// https://github.com/nodejs/node/issues/6158
ctx = new Proxy({}, {});
assert.strictEqual(typeof vm.runInNewContext('String', ctx), 'function');

// https://github.com/nodejs/node/issues/10223
ctx = vm.createContext();
vm.runInContext('Object.defineProperty(this, "x", { value: 42 })', ctx);
assert.strictEqual(ctx.x, undefined); // Not copied out by cloneProperty().
assert.strictEqual(vm.runInContext('x', ctx), 42);
vm.runInContext('x = 0', ctx); // Does not throw but x...
assert.strictEqual(vm.runInContext('x', ctx), 42); // ...should be unaltered.
assert.throws(() => vm.runInContext('"use strict"; x = 0', ctx),
/Cannot assign to read only property 'x'/);
assert.strictEqual(vm.runInContext('x', ctx), 42);

0 comments on commit 8a6367c

Please sign in to comment.