Skip to content

Commit

Permalink
Merge pull request #346 from XmiliaH/fix-330
Browse files Browse the repository at this point in the history
Frozen object tries to create property on receiver
  • Loading branch information
XmiliaH committed May 14, 2021
2 parents 12e721b + 42c7b83 commit 82caa5b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lib/contextify.js
Expand Up @@ -44,13 +44,25 @@ const DEBUG = false;
const OPNA = 'Operation not allowed on contextified object.';
const captureStackTrace = Error.captureStackTrace;

const FROZEN_TRAPS = host.Object.create(null);
FROZEN_TRAPS.set = (target, key) => false;
FROZEN_TRAPS.setPrototypeOf = (target, key) => false;
FROZEN_TRAPS.defineProperty = (target, key) => false;
FROZEN_TRAPS.deleteProperty = (target, key) => false;
FROZEN_TRAPS.isExtensible = (target, key) => false;
FROZEN_TRAPS.preventExtensions = (target) => false;
const RETURN_FALSE = () => false;

const FROZEN_TRAPS = {
__proto__: null,
set(target, key, value, receiver) {
return local.Reflect.defineProperty(receiver, key, {
__proto__: null,
value: value,
writable: true,
enumerable: true,
configurable: true
});
},
setPrototypeOf: RETURN_FALSE,
defineProperty: RETURN_FALSE,
deleteProperty: RETURN_FALSE,
isExtensible: RETURN_FALSE,
preventExtensions: RETURN_FALSE
};

// Map of contextified objects to original objects
const Contextified = new host.WeakMap();
Expand Down
3 changes: 3 additions & 0 deletions test/vm.js
Expand Up @@ -1009,6 +1009,9 @@ describe('freeze, protect', () => {

vm.run('x.c.d = () => { return `---` };');
assert.strictEqual(x.c.d(), 'd');

// Extension of frozen objects should be writeable.
assert.strictEqual(vm.run('y = Object.create(x); y.f = 1; y.f'), 1);
});

it('without protect', () => {
Expand Down

0 comments on commit 82caa5b

Please sign in to comment.