Skip to content

Commit

Permalink
fix for issue #25 when updating a property
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Van Cutsem committed Apr 6, 2014
1 parent 3d15200 commit ac34f70
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
8 changes: 4 additions & 4 deletions reflect.js
Expand Up @@ -366,10 +366,10 @@ function isFixed(name, target) {
function isSealed(name, target) {
var desc = Object.getOwnPropertyDescriptor(target, name);
if (desc === undefined) { return false; }
return !desc.configurable;
return desc.configurable === false;
}
function isSealedDesc(desc) {
return desc !== undefined && !desc.configurable;
return desc !== undefined && desc.configurable === false;
}

/**
Expand Down Expand Up @@ -544,7 +544,7 @@ Validator.prototype = {
}
}

if (!desc.configurable && !isSealedDesc(targetDesc)) {
if (desc.configurable === false && !isSealedDesc(targetDesc)) {
// if the property is configurable or non-existent on the target,
// but is reported as a non-configurable property, it may later be
// reported as configurable or non-existent, which violates the
Expand Down Expand Up @@ -668,7 +668,7 @@ Validator.prototype = {
}
}

if (!desc.configurable && !isSealedDesc(targetDesc)) {
if (desc.configurable === false && !isSealedDesc(targetDesc)) {
// if the property is configurable or non-existent on the target,
// but is successfully being redefined as a non-configurable property,
// it may later be reported as configurable or non-existent, which violates
Expand Down
17 changes: 16 additions & 1 deletion test/testProxies.js
Expand Up @@ -98,6 +98,7 @@ load('../reflect.js');
testRevocableProxies();
testSetPrototypeOf();
testSetPrototypeOfUndefined();
testUpdatePropertyDescriptor();
//testInvokeTrap();

for (var testName in TESTS) {
Expand Down Expand Up @@ -820,7 +821,21 @@ load('../reflect.js');
} catch (ex) {
shouldThrow = ex;
}
assert(shouldThrow);
assert(shouldThrow, 'testSetPrototypeOfUndefined: cannot set to undefined');
}

function testUpdatePropertyDescriptor() {
var obj = {};
Object.defineProperty(obj, 'prop', {value: true, configurable: true});
var proxy = Proxy(obj, {
defineProperty: function(target, name, desc) {
return Object.defineProperty(obj, name, desc);
}
});
Object.defineProperty(proxy, 'prop', {value: function() { return false; }});
var descriptor = Object.getOwnPropertyDescriptor(obj, 'prop');
assert(typeof descriptor.value === 'function',
'testUpdatePropertyDescriptor: prop updated');
}

// invoke experiment
Expand Down

0 comments on commit ac34f70

Please sign in to comment.