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) {
|
||||
var newValue = value || "unlikelyValue";
|
||||
var hadValue = Object.prototype.hasOwnProperty.call(obj, name);
|
||||
var oldValue = obj[name];
|
||||
var result;
|
||||
|
||||
try {
|
||||
obj[name] = newValue;
|
||||
|
@ -38,12 +41,16 @@ function isWritable(obj, name, verifyProp, value) {
|
|||
}
|
||||
}
|
||||
|
||||
if ((verifyProp && isEqualTo(obj, verifyProp, newValue)) ||
|
||||
isEqualTo(obj, name, newValue)) {
|
||||
return true;
|
||||
result = (verifyProp && isEqualTo(obj, verifyProp, newValue)) ||
|
||||
isEqualTo(obj, name, newValue);
|
||||
|
||||
if (hadValue) {
|
||||
obj[name] = oldValue;
|
||||
} else {
|
||||
delete obj[name];
|
||||
}
|
||||
|
||||
return false;
|
||||
return result;
|
||||
}
|
||||
|
||||
function verifyEqualTo(obj, name, value) {
|
||||
|
|
Loading…
Reference in New Issue