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

Frozen object tries to create property on receiver #346

Merged
merged 1 commit into from May 14, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -995,6 +995,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