mirror of
https://github.com/tc39/test262.git
synced 2025-05-07 00:10:33 +02:00
- Remove no longer needed noStrict flags. - Change tests to use propertyHelper.js for strict mode compatibility. - Add tests for return value of `delete` operator, e.g. `delete Array.prototype === false`. - Add non-writable tests for global NaN property. - Split some tests to run in strict mode. - Change tests with global `var length` declaration to use a different variable name for browser environments. - Merge duplicated tests symbol-data-property-configurable-non-strict and symbol-data-property-configurable-strict. - Merge duplicated tests symbol-data-property-writable-non-strict and symbol-data-property-writable-strict. - (And a small change in propertyHelper to reduce code duplication in function call.)
119 lines
3.6 KiB
JavaScript
119 lines
3.6 KiB
JavaScript
|
|
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";
|
|
var hadValue = Object.prototype.hasOwnProperty.call(obj, name);
|
|
var oldValue = obj[name];
|
|
var writeSucceeded;
|
|
|
|
try {
|
|
obj[name] = newValue;
|
|
} catch (e) {
|
|
if (!(e instanceof TypeError)) {
|
|
$ERROR("Expected TypeError, got " + e);
|
|
}
|
|
}
|
|
|
|
writeSucceeded = isEqualTo(obj, verifyProp || name, newValue);
|
|
|
|
// Revert the change only if it was successful (in other cases, reverting
|
|
// is unnecessary and may trigger exceptions for certain property
|
|
// configurations)
|
|
if (writeSucceeded) {
|
|
if (hadValue) {
|
|
obj[name] = oldValue;
|
|
} else {
|
|
delete obj[name];
|
|
}
|
|
}
|
|
|
|
return writeSucceeded;
|
|
}
|
|
|
|
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) {
|
|
if (!verifyProp) {
|
|
assert(Object.getOwnPropertyDescriptor(obj, name).writable,
|
|
"Expected obj[" + String(name) + "] to have writable:true.");
|
|
}
|
|
if (!isWritable(obj, name, verifyProp, value)) {
|
|
$ERROR("Expected obj[" + String(name) + "] to be writable, but was not.");
|
|
}
|
|
}
|
|
|
|
function verifyNotWritable(obj, name, verifyProp, value) {
|
|
if (!verifyProp) {
|
|
assert(!Object.getOwnPropertyDescriptor(obj, name).writable,
|
|
"Expected obj[" + String(name) + "] to have writable:false.");
|
|
}
|
|
if (isWritable(obj, name, verifyProp)) {
|
|
$ERROR("Expected obj[" + String(name) + "] NOT to be writable, but was.");
|
|
}
|
|
}
|
|
|
|
function verifyEnumerable(obj, name) {
|
|
assert(Object.getOwnPropertyDescriptor(obj, name).enumerable,
|
|
"Expected obj[" + String(name) + "] to have enumerable:true.");
|
|
if (!isEnumerable(obj, name)) {
|
|
$ERROR("Expected obj[" + String(name) + "] to be enumerable, but was not.");
|
|
}
|
|
}
|
|
|
|
function verifyNotEnumerable(obj, name) {
|
|
assert(!Object.getOwnPropertyDescriptor(obj, name).enumerable,
|
|
"Expected obj[" + String(name) + "] to have enumerable:false.");
|
|
if (isEnumerable(obj, name)) {
|
|
$ERROR("Expected obj[" + String(name) + "] NOT to be enumerable, but was.");
|
|
}
|
|
}
|
|
|
|
function verifyConfigurable(obj, name) {
|
|
assert(Object.getOwnPropertyDescriptor(obj, name).configurable,
|
|
"Expected obj[" + String(name) + "] to have configurable:true.");
|
|
if (!isConfigurable(obj, name)) {
|
|
$ERROR("Expected obj[" + String(name) + "] to be configurable, but was not.");
|
|
}
|
|
}
|
|
|
|
function verifyNotConfigurable(obj, name) {
|
|
assert(!Object.getOwnPropertyDescriptor(obj, name).configurable,
|
|
"Expected obj[" + String(name) + "] to have configurable:false.");
|
|
if (isConfigurable(obj, name)) {
|
|
$ERROR("Expected obj[" + String(name) + "] NOT to be configurable, but was.");
|
|
}
|
|
}
|
|
|