Browse Source

src: fix delete operator on vm context

In the implementation of the vm module,
if a property is successfully deleted
on the sandbox, we also need to delete it
on the global_proxy object. Therefore, we
must not call args.GetReturnValue().Set().

We only intercept, i.e., call
args.GetReturnValue().Set(), in the
DeleterCallback, if Delete() failed, e.g. because
the property was read only.

PR-URL: https://github.com/nodejs/node/pull/11266
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
v6.x
Franziska Hinkelmann 8 years ago
committed by Myles Borins
parent
commit
587857e301
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 8
      src/node_contextify.cc
  2. 2
      test/parallel/test-vm-deleting-property.js

8
src/node_contextify.cc

@ -441,8 +441,12 @@ class ContextifyContext {
Maybe<bool> success = ctx->sandbox()->Delete(ctx->context(), property);
if (success.IsJust())
args.GetReturnValue().Set(success.FromJust());
if (success.FromMaybe(false))
return;
// Delete failed on the sandbox, intercept and do not delete on
// the global object.
args.GetReturnValue().Set(false);
}

2
test/known_issues/test-vm-deleting-property.js → test/parallel/test-vm-deleting-property.js

@ -12,4 +12,4 @@ const res = vm.runInContext(`
Object.getOwnPropertyDescriptor(this, 'x');
`, context);
assert.strictEqual(res.value, undefined);
assert.strictEqual(res, undefined);
Loading…
Cancel
Save