2014-11-12 14:41:09 +01:00
|
|
|
|
|
|
|
function isConfigurable(obj, name) {
|
|
|
|
try {
|
|
|
|
delete obj[name];
|
|
|
|
} catch (e) {
|
|
|
|
if (!(e instanceof TypeError)) {
|
|
|
|
$ERROR("Expected TypeError, got " + e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return !Object.prototype.hasOwnProperty.call(obj, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
function isEnumerable(obj, name) {
|
|
|
|
for (var prop in obj) {
|
|
|
|
if (Object.prototype.hasOwnProperty.call(obj, prop) &&
|
|
|
|
assert._isSameValue(prop, name)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isEqualTo(obj, name, expectedValue) {
|
|
|
|
var actualValue = obj[name];
|
|
|
|
|
|
|
|
return assert._isSameValue(actualValue, expectedValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
function isWritable(obj, name, verifyProp, value) {
|
|
|
|
var newValue = value || "unlikelyValue";
|
|
|
|
|
|
|
|
try {
|
|
|
|
obj[name] = newValue;
|
|
|
|
} catch (e) {
|
|
|
|
if (!(e instanceof TypeError)) {
|
|
|
|
$ERROR("Expected TypeError, got " + e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((verifyProp && isEqualTo(obj, verifyProp, newValue)) ||
|
|
|
|
isEqualTo(obj, name, newValue)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function verifyEqualTo(obj, name, value) {
|
|
|
|
if (!isEqualTo(obj, name, value)) {
|
|
|
|
$ERROR("Expected obj[" + String(name) + "] to equal " + value +
|
|
|
|
", actually " + obj[name]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function verifyWritable(obj, name, verifyProp, value) {
|
2015-02-20 02:11:53 +01:00
|
|
|
if (!verifyProp) {
|
|
|
|
assert(Object.getOwnPropertyDescriptor(obj, name).writable,
|
|
|
|
"Expected obj[" + String(name) + "] to have writable:true.");
|
|
|
|
}
|
2014-11-12 14:41:09 +01:00
|
|
|
if (!isWritable(obj, name, verifyProp, value)) {
|
|
|
|
$ERROR("Expected obj[" + String(name) + "] to be writable, but was not.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function verifyNotWritable(obj, name, verifyProp, value) {
|
2015-02-20 02:11:53 +01:00
|
|
|
if (!verifyProp) {
|
|
|
|
assert(!Object.getOwnPropertyDescriptor(obj, name).writable,
|
|
|
|
"Expected obj[" + String(name) + "] to have writable:false.");
|
|
|
|
}
|
2014-11-12 14:41:09 +01:00
|
|
|
if (isWritable(obj, name, verifyProp)) {
|
|
|
|
$ERROR("Expected obj[" + String(name) + "] NOT to be writable, but was.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function verifyEnumerable(obj, name) {
|
2015-02-20 02:11:53 +01:00
|
|
|
assert(Object.getOwnPropertyDescriptor(obj, name).enumerable,
|
|
|
|
"Expected obj[" + String(name) + "] to have enumerable:true.");
|
2014-11-12 14:41:09 +01:00
|
|
|
if (!isEnumerable(obj, name)) {
|
|
|
|
$ERROR("Expected obj[" + String(name) + "] to be enumerable, but was not.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function verifyNotEnumerable(obj, name) {
|
2015-02-20 02:11:53 +01:00
|
|
|
assert(!Object.getOwnPropertyDescriptor(obj, name).enumerable,
|
|
|
|
"Expected obj[" + String(name) + "] to have enumerable:false.");
|
2014-11-12 14:41:09 +01:00
|
|
|
if (isEnumerable(obj, name)) {
|
|
|
|
$ERROR("Expected obj[" + String(name) + "] NOT to be enumerable, but was.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function verifyConfigurable(obj, name) {
|
2015-02-20 02:11:53 +01:00
|
|
|
assert(Object.getOwnPropertyDescriptor(obj, name).configurable,
|
|
|
|
"Expected obj[" + String(name) + "] to have configurable:true.");
|
2014-11-12 14:41:09 +01:00
|
|
|
if (!isConfigurable(obj, name)) {
|
|
|
|
$ERROR("Expected obj[" + String(name) + "] to be configurable, but was not.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function verifyNotConfigurable(obj, name) {
|
2015-02-20 02:11:53 +01:00
|
|
|
assert(!Object.getOwnPropertyDescriptor(obj, name).configurable,
|
|
|
|
"Expected obj[" + String(name) + "] to have configurable:false.");
|
2014-11-12 14:41:09 +01:00
|
|
|
if (isConfigurable(obj, name)) {
|
|
|
|
$ERROR("Expected obj[" + String(name) + "] NOT to be configurable, but was.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|