mirror of https://github.com/tc39/test262.git
Make writability helper function non-destructive
After checking the writability of a given property, restore the property value to its original state.
This commit is contained in:
parent
2eca2c71e8
commit
9f8f0284c3
|
@ -29,6 +29,9 @@ function isEqualTo(obj, name, expectedValue) {
|
||||||
|
|
||||||
function isWritable(obj, name, verifyProp, value) {
|
function isWritable(obj, name, verifyProp, value) {
|
||||||
var newValue = value || "unlikelyValue";
|
var newValue = value || "unlikelyValue";
|
||||||
|
var hadValue = Object.prototype.hasOwnProperty.call(obj, name);
|
||||||
|
var oldValue = obj[name];
|
||||||
|
var result;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
obj[name] = newValue;
|
obj[name] = newValue;
|
||||||
|
@ -38,12 +41,16 @@ function isWritable(obj, name, verifyProp, value) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((verifyProp && isEqualTo(obj, verifyProp, newValue)) ||
|
result = (verifyProp && isEqualTo(obj, verifyProp, newValue)) ||
|
||||||
isEqualTo(obj, name, newValue)) {
|
isEqualTo(obj, name, newValue);
|
||||||
return true;
|
|
||||||
|
if (hadValue) {
|
||||||
|
obj[name] = oldValue;
|
||||||
|
} else {
|
||||||
|
delete obj[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function verifyEqualTo(obj, name, value) {
|
function verifyEqualTo(obj, name, value) {
|
||||||
|
|
Loading…
Reference in New Issue