mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 05:55:36 +02:00
fix tests in strict mode - Object/defineProperty
This commit is contained in:
parent
08575d89b7
commit
26ede592a8
@ -26,7 +26,7 @@ try {
|
||||
|
||||
assert.sameValue(obj.prop, 2010);
|
||||
verifyNotWritable(obj, "prop");
|
||||
|
||||
assert.sameValue(obj.prop, 2010);
|
||||
} finally {
|
||||
delete obj.prop;
|
||||
}
|
||||
|
@ -12,11 +12,10 @@ description: >
|
||||
to an accessor property, 'O' is the global object (8.12.9 - step
|
||||
9.b.i)
|
||||
includes:
|
||||
- runTestCase.js
|
||||
- propertyHelper.js
|
||||
- fnGlobalObject.js
|
||||
---*/
|
||||
|
||||
function testcase() {
|
||||
var obj = fnGlobalObject();
|
||||
try {
|
||||
Object.defineProperty(obj, "prop", {
|
||||
@ -35,11 +34,13 @@ function testcase() {
|
||||
});
|
||||
var desc2 = Object.getOwnPropertyDescriptor(obj, "prop");
|
||||
|
||||
return desc1.hasOwnProperty("value") && desc2.hasOwnProperty("get") &&
|
||||
desc2.enumerable === true && desc2.configurable === true &&
|
||||
obj.prop === 20 && typeof desc2.set === "undefined" && desc2.get === getFunc;
|
||||
assert(desc1.hasOwnProperty("value"));
|
||||
assert(desc2.hasOwnProperty("get"));
|
||||
assert.sameValue(desc2.enumerable, true);
|
||||
assert.sameValue(desc2.configurable, true);
|
||||
assert.sameValue(obj.prop, 20);
|
||||
assert.sameValue(typeof desc2.set, "undefined");
|
||||
assert.sameValue(desc2.get, getFunc);
|
||||
} finally {
|
||||
delete obj.prop;
|
||||
}
|
||||
}
|
||||
runTestCase(testcase);
|
||||
|
@ -10,10 +10,9 @@ description: >
|
||||
ES5 Attributes - Updating a named accessor property 'P' without
|
||||
[[Set]] using simple assignment is failed, 'O' is an Arguments
|
||||
object (8.12.5 step 5.b)
|
||||
includes: [runTestCase.js]
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
function testcase() {
|
||||
var obj = (function () {
|
||||
return arguments;
|
||||
}());
|
||||
@ -29,10 +28,9 @@ function testcase() {
|
||||
configurable: true
|
||||
});
|
||||
|
||||
obj.prop = "overrideData";
|
||||
var propertyDefineCorrect = obj.hasOwnProperty("prop");
|
||||
assert(obj.hasOwnProperty("prop"));
|
||||
verifyNotWritable(obj, "prop");
|
||||
var desc = Object.getOwnPropertyDescriptor(obj, "prop");
|
||||
|
||||
return propertyDefineCorrect && typeof desc.set === "undefined" && obj.prop === "data";
|
||||
}
|
||||
runTestCase(testcase);
|
||||
assert.sameValue(typeof desc.set, "undefined");
|
||||
assert.sameValue(obj.prop, "data");
|
||||
|
@ -11,11 +11,10 @@ description: >
|
||||
[[Set]] using simple assignment is failed, 'O' is the global
|
||||
object (8.12.5 step 5.b)
|
||||
includes:
|
||||
- runTestCase.js
|
||||
- propertyHelper.js
|
||||
- fnGlobalObject.js
|
||||
---*/
|
||||
|
||||
function testcase() {
|
||||
var obj = fnGlobalObject();
|
||||
try {
|
||||
obj.verifySetFunc = "data";
|
||||
@ -29,14 +28,13 @@ function testcase() {
|
||||
configurable: true
|
||||
});
|
||||
|
||||
obj.prop = "overrideData";
|
||||
var propertyDefineCorrect = obj.hasOwnProperty("prop");
|
||||
assert(obj.hasOwnProperty("prop"));
|
||||
var desc = Object.getOwnPropertyDescriptor(obj, "prop");
|
||||
|
||||
return propertyDefineCorrect && typeof desc.set === "undefined" && obj.prop === "data";
|
||||
verifyNotWritable(obj, "prop");
|
||||
assert.sameValue(typeof desc.set, "undefined");
|
||||
assert.sameValue(obj.prop, "data");
|
||||
} finally {
|
||||
delete obj.prop;
|
||||
delete obj.verifySetFunc;
|
||||
}
|
||||
}
|
||||
runTestCase(testcase);
|
||||
|
@ -11,10 +11,9 @@ description: >
|
||||
accessor property ([[Get]] is a Function, [[Set]] is a Function,
|
||||
[[Enumerable]] is true, [[Configurable]] is true) to different
|
||||
value
|
||||
includes: [runTestCase.js]
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
function testcase() {
|
||||
var obj = {};
|
||||
|
||||
var getFunc = function () {
|
||||
@ -32,14 +31,15 @@ function testcase() {
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
var desc1 = Object.getOwnPropertyDescriptor(obj, "prop");
|
||||
|
||||
Object.defineProperty(obj, "prop", {
|
||||
configurable: false
|
||||
});
|
||||
var desc2 = Object.getOwnPropertyDescriptor(obj, "prop");
|
||||
delete obj.prop;
|
||||
|
||||
return desc1.configurable === true && desc2.configurable === false && obj.hasOwnProperty("prop");
|
||||
}
|
||||
runTestCase(testcase);
|
||||
verifyNotConfigurable(obj, "prop");
|
||||
assert.sameValue(desc1.configurable, true);
|
||||
assert.sameValue(desc2.configurable, false);
|
||||
assert(obj.hasOwnProperty("prop"));
|
||||
|
@ -10,10 +10,9 @@ description: >
|
||||
Object.defineProperty - 'name' property doesn't exist in 'O', test
|
||||
[[Set]] of 'name' property of 'Attributes' is set as undefined
|
||||
value if absent in accessor descriptor 'desc' (8.12.9 step 4.b.i)
|
||||
includes: [runTestCase.js]
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
function testcase() {
|
||||
var obj = {};
|
||||
|
||||
Object.defineProperty(obj, "property", {
|
||||
@ -25,23 +24,10 @@ function testcase() {
|
||||
});
|
||||
|
||||
|
||||
if (obj.property !== "property") {
|
||||
return false;
|
||||
}
|
||||
var desc = Object.getOwnPropertyDescriptor(obj, "property");
|
||||
if (typeof desc.set !== "undefined") {
|
||||
return false;
|
||||
}
|
||||
for (var p in obj) {
|
||||
if (p === "property") {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
delete obj.property;
|
||||
if (!obj.hasOwnProperty("property")) {
|
||||
return false;
|
||||
}
|
||||
assert.sameValue(obj.property, "property");
|
||||
|
||||
return true;
|
||||
}
|
||||
runTestCase(testcase);
|
||||
var desc = Object.getOwnPropertyDescriptor(obj, "property");
|
||||
assert.sameValue(typeof desc.set, "undefined");
|
||||
|
||||
verifyNotEnumerable(obj, "property");
|
||||
verifyNotConfigurable(obj, "property");
|
||||
|
@ -10,10 +10,9 @@ description: >
|
||||
ES5 Attributes - property ([[Get]] is a Function, [[Set]] is a
|
||||
Function, [[Enumerable]] is true, [[Configurable]] is false) is
|
||||
undeletable
|
||||
includes: [runTestCase.js]
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
function testcase() {
|
||||
var obj = {};
|
||||
|
||||
var getFunc = function () {
|
||||
@ -32,11 +31,5 @@ function testcase() {
|
||||
configurable: false
|
||||
});
|
||||
|
||||
var propertyDefineCorrect = obj.hasOwnProperty("prop");
|
||||
var desc = Object.getOwnPropertyDescriptor(obj, "prop");
|
||||
|
||||
delete obj.prop;
|
||||
|
||||
return propertyDefineCorrect && desc.configurable === false && obj.hasOwnProperty("prop");
|
||||
}
|
||||
runTestCase(testcase);
|
||||
assert(obj.hasOwnProperty("prop"));
|
||||
verifyNotConfigurable(obj, "prop");
|
||||
|
@ -11,10 +11,9 @@ description: >
|
||||
accessor property ([[Get]] is a Function, [[Set]] is a Function,
|
||||
[[Enumerable]] is true, [[Configurable]] is false) to different
|
||||
value
|
||||
includes: [runTestCase.js]
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
function testcase() {
|
||||
var obj = {};
|
||||
|
||||
var getFunc = function () {
|
||||
@ -39,12 +38,13 @@ function testcase() {
|
||||
configurable: true
|
||||
});
|
||||
|
||||
return false;
|
||||
$ERROR("Expected TypeError");
|
||||
} catch (e) {
|
||||
var desc2 = Object.getOwnPropertyDescriptor(obj, "prop");
|
||||
delete obj.prop;
|
||||
assert(e instanceof TypeError);
|
||||
assert.sameValue(desc1.configurable, false);
|
||||
|
||||
return desc1.configurable === false && desc2.configurable === false && obj.hasOwnProperty("prop") && e instanceof TypeError;
|
||||
var desc2 = Object.getOwnPropertyDescriptor(obj, "prop");
|
||||
assert.sameValue(desc2.configurable, false);
|
||||
|
||||
verifyNotConfigurable(obj, "prop");
|
||||
}
|
||||
}
|
||||
runTestCase(testcase);
|
||||
|
@ -11,10 +11,9 @@ description: >
|
||||
accessor property ([[Get]] is a Function, [[Set]] is a Function,
|
||||
[[Enumerable]] is false, [[Configurable]] is true) to different
|
||||
value
|
||||
includes: [runTestCase.js]
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
function testcase() {
|
||||
var obj = {};
|
||||
|
||||
var getFunc = function () {
|
||||
@ -34,13 +33,10 @@ function testcase() {
|
||||
});
|
||||
|
||||
var desc1 = Object.getOwnPropertyDescriptor(obj, "prop");
|
||||
assert.sameValue(desc1.configurable, true);
|
||||
|
||||
Object.defineProperty(obj, "prop", {
|
||||
configurable: false
|
||||
});
|
||||
var desc2 = Object.getOwnPropertyDescriptor(obj, "prop");
|
||||
delete obj.prop;
|
||||
|
||||
return desc1.configurable === true && desc2.configurable === false && obj.hasOwnProperty("prop");
|
||||
}
|
||||
runTestCase(testcase);
|
||||
verifyNotConfigurable(obj, "prop");
|
||||
|
@ -10,10 +10,9 @@ description: >
|
||||
ES5 Attributes - property ([[Get]] is a Function, [[Set]] is a
|
||||
Function, [[Enumerable]] is false, [[Configurable]] is false) is
|
||||
undeletable
|
||||
includes: [runTestCase.js]
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
function testcase() {
|
||||
var obj = {};
|
||||
|
||||
var getFunc = function () {
|
||||
@ -32,11 +31,5 @@ function testcase() {
|
||||
configurable: false
|
||||
});
|
||||
|
||||
var propertyDefineCorrect = obj.hasOwnProperty("prop");
|
||||
var desc = Object.getOwnPropertyDescriptor(obj, "prop");
|
||||
|
||||
delete obj.prop;
|
||||
|
||||
return propertyDefineCorrect && desc.configurable === false && obj.hasOwnProperty("prop");
|
||||
}
|
||||
runTestCase(testcase);
|
||||
assert(obj.hasOwnProperty("prop"));
|
||||
verifyNotConfigurable(obj, "prop");
|
||||
|
@ -11,10 +11,9 @@ description: >
|
||||
accessor property ([[Get]] is a Function, [[Set]] is a Function,
|
||||
[[Enumerable]] is false, [[Configurable]] is false) to different
|
||||
value
|
||||
includes: [runTestCase.js]
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
function testcase() {
|
||||
var obj = {};
|
||||
|
||||
var getFunc = function () {
|
||||
@ -39,12 +38,9 @@ function testcase() {
|
||||
configurable: true
|
||||
});
|
||||
|
||||
return false;
|
||||
$ERROR("Expected TypeError");
|
||||
} catch (e) {
|
||||
var desc2 = Object.getOwnPropertyDescriptor(obj, "prop");
|
||||
delete obj.prop;
|
||||
|
||||
return desc1.configurable === false && desc2.configurable === false && obj.hasOwnProperty("prop") && e instanceof TypeError;
|
||||
assert(e instanceof TypeError);
|
||||
assert.sameValue(desc1.configurable, false);
|
||||
verifyNotConfigurable(obj, "prop");
|
||||
}
|
||||
}
|
||||
runTestCase(testcase);
|
||||
|
@ -7,10 +7,9 @@
|
||||
/*---
|
||||
es5id: 15.2.3.6-4-581
|
||||
description: ES5 Attributes - Fail to add property into object (Number instance)
|
||||
includes: [runTestCase.js]
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
function testcase() {
|
||||
var data = "data";
|
||||
try {
|
||||
Object.defineProperty(Number.prototype, "prop", {
|
||||
@ -21,11 +20,12 @@ function testcase() {
|
||||
configurable: true
|
||||
});
|
||||
var numObj = new Number();
|
||||
numObj.prop = "myOwnProperty";
|
||||
|
||||
return !numObj.hasOwnProperty("prop") && numObj.prop === "data" && data === "data";
|
||||
verifyNotWritable(numObj, "prop", "nocheck");
|
||||
|
||||
assert(!numObj.hasOwnProperty("prop"));
|
||||
assert.sameValue(numObj.prop, "data");
|
||||
assert.sameValue(data, "data");
|
||||
} finally {
|
||||
delete Number.prototype.prop;
|
||||
}
|
||||
}
|
||||
runTestCase(testcase);
|
||||
|
@ -9,10 +9,9 @@ es5id: 15.2.3.6-4-586
|
||||
description: >
|
||||
ES5 Attributes - Fail to update value of property into of
|
||||
[[Proptotype]] internal property (JSON)
|
||||
includes: [runTestCase.js]
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
function testcase() {
|
||||
var data = "data";
|
||||
try {
|
||||
Object.defineProperty(Object.prototype, "prop", {
|
||||
@ -22,11 +21,11 @@ function testcase() {
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
JSON.prop = "myOwnProperty";
|
||||
verifyNotWritable(JSON, "prop", "nocheck");
|
||||
|
||||
return !JSON.hasOwnProperty("prop") && JSON.prop === "data" && data === "data";
|
||||
assert(!JSON.hasOwnProperty("prop"));
|
||||
assert.sameValue(JSON.prop, "data");
|
||||
assert.sameValue(data, "data");
|
||||
} finally {
|
||||
delete Object.prototype.prop;
|
||||
}
|
||||
}
|
||||
runTestCase(testcase);
|
||||
|
@ -9,10 +9,9 @@ es5id: 15.2.3.6-4-591
|
||||
description: >
|
||||
ES5 Attributes - Fail to update value of property of
|
||||
[[Proptotype]] internal property (Object.create)
|
||||
includes: [runTestCase.js]
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
function testcase() {
|
||||
var appointment = {};
|
||||
|
||||
var data1 = 1001;
|
||||
@ -43,17 +42,28 @@ function testcase() {
|
||||
});
|
||||
|
||||
var teamMeeting = Object.create(meeting);
|
||||
|
||||
verifyNotWritable(teamMeeting, "name", "nocheck");
|
||||
verifyNotWritable(teamMeeting, "startTime", "nocheck");
|
||||
verifyNotWritable(teamMeeting, "conferenceCall", "nocheck");
|
||||
|
||||
try {
|
||||
teamMeeting.name = "IE Team Meeting";
|
||||
} catch (e) {}
|
||||
|
||||
try {
|
||||
var dateObj = new Date("10/31/2010 08:00");
|
||||
teamMeeting.startTime = dateObj;
|
||||
} catch (e) {}
|
||||
|
||||
try {
|
||||
teamMeeting.conferenceCall = "4255551212";
|
||||
} catch (e) {}
|
||||
|
||||
var hasOwnProperty = !teamMeeting.hasOwnProperty("name") &&
|
||||
!teamMeeting.hasOwnProperty("startTime") &&
|
||||
!teamMeeting.hasOwnProperty('conferenceCall');
|
||||
assert(!teamMeeting.hasOwnProperty("name"));
|
||||
assert(!teamMeeting.hasOwnProperty("startTime"));
|
||||
assert(!teamMeeting.hasOwnProperty('conferenceCall'));
|
||||
|
||||
return hasOwnProperty && teamMeeting.name === "NAME" &&
|
||||
teamMeeting.startTime === 1001 &&
|
||||
teamMeeting.conferenceCall === "In-person meeting";
|
||||
}
|
||||
runTestCase(testcase);
|
||||
assert.sameValue(teamMeeting.name, "NAME");
|
||||
assert.sameValue(teamMeeting.startTime, 1001);
|
||||
assert.sameValue(teamMeeting.conferenceCall, "In-person meeting");
|
||||
|
@ -9,10 +9,9 @@ es5id: 15.2.3.6-4-596
|
||||
description: >
|
||||
ES5 Attributes - Fail to update value of property into of
|
||||
[[Proptotype]] internal property (Function.prototype.bind)
|
||||
includes: [runTestCase.js]
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
function testcase() {
|
||||
var foo = function () { };
|
||||
var data = "data";
|
||||
try {
|
||||
@ -25,11 +24,10 @@ function testcase() {
|
||||
});
|
||||
|
||||
var obj = foo.bind({});
|
||||
obj.prop = "overrideData";
|
||||
|
||||
return !obj.hasOwnProperty("prop") && obj.prop === "data";
|
||||
assert(!obj.hasOwnProperty("prop"));
|
||||
verifyNotWritable(obj, "prop", "nocheck");
|
||||
assert.sameValue(obj.prop, "data");;
|
||||
} finally {
|
||||
delete Function.prototype.prop;
|
||||
}
|
||||
}
|
||||
runTestCase(testcase);
|
||||
|
@ -9,37 +9,19 @@ es5id: 15.2.3.6-4-63
|
||||
description: >
|
||||
Object.defineProperty - both desc.value and name.value are NaN
|
||||
(8.12.9 step 6)
|
||||
includes: [runTestCase.js]
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
function testcase() {
|
||||
|
||||
var obj = {};
|
||||
|
||||
Object.defineProperty(obj, "foo", { value: NaN });
|
||||
|
||||
Object.defineProperty(obj, "foo", { value: NaN });
|
||||
|
||||
if (!isNaN(obj.foo)) {
|
||||
return false;
|
||||
}
|
||||
assert(isNaN(obj.foo));
|
||||
|
||||
obj.foo = "verifyValue";
|
||||
if (obj.foo === "verifyValue") {
|
||||
return false;
|
||||
}
|
||||
verifyNotWritable(obj, "foo");
|
||||
|
||||
for (var prop in obj) {
|
||||
if (obj.hasOwnProperty(prop) && prop === "foo") {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
verifyNotEnumerable(obj, "foo");
|
||||
|
||||
delete obj.foo;
|
||||
if (!obj.hasOwnProperty("foo")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
runTestCase(testcase);
|
||||
verifyNotConfigurable(obj, "foo");
|
||||
|
@ -10,11 +10,9 @@ description: >
|
||||
Object.defineProperty will not throw TypeError if
|
||||
name.configurable = false, name.writable = false, name.value = NaN
|
||||
and desc.value = NaN (8.12.9 step 10.a.ii.1)
|
||||
includes: [runTestCase.js]
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
function testcase() {
|
||||
|
||||
var obj = {};
|
||||
|
||||
Object.defineProperty(obj, "foo", {
|
||||
@ -29,26 +27,10 @@ function testcase() {
|
||||
configurable: false
|
||||
});
|
||||
|
||||
if (!isNaN(obj.foo)) {
|
||||
return false;
|
||||
}
|
||||
assert(isNaN(obj.foo));
|
||||
|
||||
obj.foo = "verifyValue";
|
||||
if (obj.foo === "verifyValue") {
|
||||
return false;
|
||||
}
|
||||
verifyNotWritable(obj, "foo");
|
||||
|
||||
for (var prop in obj) {
|
||||
if (obj.hasOwnProperty(prop) && prop === "foo") {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
verifyNotEnumerable(obj, "foo");
|
||||
|
||||
delete obj.foo;
|
||||
if (!obj.hasOwnProperty("foo")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
runTestCase(testcase);
|
||||
verifyNotConfigurable(obj, "foo");
|
||||
|
Loading…
x
Reference in New Issue
Block a user