Skip to content

Commit

Permalink
[Fix] CreateDataProperty: update an existing property
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Mar 22, 2020
1 parent 920a682 commit bdd77b5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 11 deletions.
4 changes: 2 additions & 2 deletions 2015/CreateDataProperty.js
Expand Up @@ -24,8 +24,8 @@ module.exports = function CreateDataProperty(O, P, V) {
throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
}
var oldDesc = OrdinaryGetOwnProperty(O, P);
var extensible = oldDesc || IsExtensible(O);
var immutable = oldDesc && (!oldDesc.writable || !oldDesc.configurable);
var extensible = !oldDesc || IsExtensible(O);
var immutable = oldDesc && (!oldDesc['[[Writable]]'] || !oldDesc['[[Configurable]]']);
if (immutable || !extensible) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions 2016/CreateDataProperty.js
Expand Up @@ -24,8 +24,8 @@ module.exports = function CreateDataProperty(O, P, V) {
throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
}
var oldDesc = OrdinaryGetOwnProperty(O, P);
var extensible = oldDesc || IsExtensible(O);
var immutable = oldDesc && (!oldDesc.writable || !oldDesc.configurable);
var extensible = !oldDesc || IsExtensible(O);
var immutable = oldDesc && (!oldDesc['[[Writable]]'] || !oldDesc['[[Configurable]]']);
if (immutable || !extensible) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions 2017/CreateDataProperty.js
Expand Up @@ -24,8 +24,8 @@ module.exports = function CreateDataProperty(O, P, V) {
throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
}
var oldDesc = OrdinaryGetOwnProperty(O, P);
var extensible = oldDesc || IsExtensible(O);
var immutable = oldDesc && (!oldDesc.writable || !oldDesc.configurable);
var extensible = !oldDesc || IsExtensible(O);
var immutable = oldDesc && (!oldDesc['[[Writable]]'] || !oldDesc['[[Configurable]]']);
if (immutable || !extensible) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions 2018/CreateDataProperty.js
Expand Up @@ -24,8 +24,8 @@ module.exports = function CreateDataProperty(O, P, V) {
throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
}
var oldDesc = OrdinaryGetOwnProperty(O, P);
var extensible = oldDesc || IsExtensible(O);
var immutable = oldDesc && (!oldDesc.writable || !oldDesc.configurable);
var extensible = !oldDesc || IsExtensible(O);
var immutable = oldDesc && (!oldDesc['[[Writable]]'] || !oldDesc['[[Configurable]]']);
if (immutable || !extensible) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions 2019/CreateDataProperty.js
Expand Up @@ -24,8 +24,8 @@ module.exports = function CreateDataProperty(O, P, V) {
throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
}
var oldDesc = OrdinaryGetOwnProperty(O, P);
var extensible = oldDesc || IsExtensible(O);
var immutable = oldDesc && (!oldDesc.writable || !oldDesc.configurable);
var extensible = !oldDesc || IsExtensible(O);
var immutable = oldDesc && (!oldDesc['[[Writable]]'] || !oldDesc['[[Configurable]]']);
if (immutable || !extensible) {
return false;
}
Expand Down
10 changes: 9 additions & 1 deletion test/tests.js
Expand Up @@ -1430,7 +1430,8 @@ var es2015 = function ES2015(ES, ops, expectedMissing, skips) {
);
});

var sentinel = {};
var sentinel = { id: 'sentinel' };
var secondSentinel = { id: 'second sentinel' };
forEach(v.propertyKeys, function (propertyKey) {
var obj = {};
var status = ES.CreateDataProperty(obj, propertyKey, sentinel);
Expand All @@ -1440,6 +1441,13 @@ var es2015 = function ES2015(ES, ops, expectedMissing, skips) {
sentinel,
debug(sentinel) + ' is installed on "' + debug(propertyKey) + '" on the object'
);
var secondStatus = ES.CreateDataProperty(obj, propertyKey, secondSentinel);
t.equal(secondStatus, true, 'second status is true');
t.equal(
obj[propertyKey],
secondSentinel,
debug(secondSentinel) + ' is installed on "' + debug(propertyKey) + '" on the object'
);

t.test('with defineProperty', { skip: !defineProperty.oDP }, function (st) {
var nonWritable = defineProperty({}, propertyKey, { configurable: true, writable: false });
Expand Down

0 comments on commit bdd77b5

Please sign in to comment.