fix tests in strict mode - Object/defineProperty

This commit is contained in:
smikes 2015-05-06 13:26:45 -06:00
parent 08575d89b7
commit 26ede592a8
17 changed files with 346 additions and 414 deletions

View File

@ -26,7 +26,7 @@ try {
assert.sameValue(obj.prop, 2010); assert.sameValue(obj.prop, 2010);
verifyNotWritable(obj, "prop"); verifyNotWritable(obj, "prop");
assert.sameValue(obj.prop, 2010);
} finally { } finally {
delete obj.prop; delete obj.prop;
} }

View File

@ -12,11 +12,10 @@ description: >
to an accessor property, 'O' is the global object (8.12.9 - step to an accessor property, 'O' is the global object (8.12.9 - step
9.b.i) 9.b.i)
includes: includes:
- runTestCase.js - propertyHelper.js
- fnGlobalObject.js - fnGlobalObject.js
---*/ ---*/
function testcase() {
var obj = fnGlobalObject(); var obj = fnGlobalObject();
try { try {
Object.defineProperty(obj, "prop", { Object.defineProperty(obj, "prop", {
@ -35,11 +34,13 @@ function testcase() {
}); });
var desc2 = Object.getOwnPropertyDescriptor(obj, "prop"); var desc2 = Object.getOwnPropertyDescriptor(obj, "prop");
return desc1.hasOwnProperty("value") && desc2.hasOwnProperty("get") && assert(desc1.hasOwnProperty("value"));
desc2.enumerable === true && desc2.configurable === true && assert(desc2.hasOwnProperty("get"));
obj.prop === 20 && typeof desc2.set === "undefined" && desc2.get === getFunc; 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 { } finally {
delete obj.prop; delete obj.prop;
} }
}
runTestCase(testcase);

View File

@ -10,10 +10,9 @@ description: >
ES5 Attributes - Updating a named accessor property 'P' without ES5 Attributes - Updating a named accessor property 'P' without
[[Set]] using simple assignment is failed, 'O' is an Arguments [[Set]] using simple assignment is failed, 'O' is an Arguments
object (8.12.5 step 5.b) object (8.12.5 step 5.b)
includes: [runTestCase.js] includes: [propertyHelper.js]
---*/ ---*/
function testcase() {
var obj = (function () { var obj = (function () {
return arguments; return arguments;
}()); }());
@ -29,10 +28,9 @@ function testcase() {
configurable: true configurable: true
}); });
obj.prop = "overrideData"; assert(obj.hasOwnProperty("prop"));
var propertyDefineCorrect = obj.hasOwnProperty("prop"); verifyNotWritable(obj, "prop");
var desc = Object.getOwnPropertyDescriptor(obj, "prop"); var desc = Object.getOwnPropertyDescriptor(obj, "prop");
return propertyDefineCorrect && typeof desc.set === "undefined" && obj.prop === "data"; assert.sameValue(typeof desc.set, "undefined");
} assert.sameValue(obj.prop, "data");
runTestCase(testcase);

View File

@ -11,11 +11,10 @@ description: >
[[Set]] using simple assignment is failed, 'O' is the global [[Set]] using simple assignment is failed, 'O' is the global
object (8.12.5 step 5.b) object (8.12.5 step 5.b)
includes: includes:
- runTestCase.js - propertyHelper.js
- fnGlobalObject.js - fnGlobalObject.js
---*/ ---*/
function testcase() {
var obj = fnGlobalObject(); var obj = fnGlobalObject();
try { try {
obj.verifySetFunc = "data"; obj.verifySetFunc = "data";
@ -29,14 +28,13 @@ function testcase() {
configurable: true configurable: true
}); });
obj.prop = "overrideData"; assert(obj.hasOwnProperty("prop"));
var propertyDefineCorrect = obj.hasOwnProperty("prop");
var desc = Object.getOwnPropertyDescriptor(obj, "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 { } finally {
delete obj.prop; delete obj.prop;
delete obj.verifySetFunc; delete obj.verifySetFunc;
} }
}
runTestCase(testcase);

View File

@ -11,10 +11,9 @@ description: >
accessor property ([[Get]] is a Function, [[Set]] is a Function, accessor property ([[Get]] is a Function, [[Set]] is a Function,
[[Enumerable]] is true, [[Configurable]] is true) to different [[Enumerable]] is true, [[Configurable]] is true) to different
value value
includes: [runTestCase.js] includes: [propertyHelper.js]
---*/ ---*/
function testcase() {
var obj = {}; var obj = {};
var getFunc = function () { var getFunc = function () {
@ -32,14 +31,15 @@ function testcase() {
enumerable: true, enumerable: true,
configurable: true configurable: true
}); });
var desc1 = Object.getOwnPropertyDescriptor(obj, "prop"); var desc1 = Object.getOwnPropertyDescriptor(obj, "prop");
Object.defineProperty(obj, "prop", { Object.defineProperty(obj, "prop", {
configurable: false configurable: false
}); });
var desc2 = Object.getOwnPropertyDescriptor(obj, "prop"); var desc2 = Object.getOwnPropertyDescriptor(obj, "prop");
delete obj.prop;
return desc1.configurable === true && desc2.configurable === false && obj.hasOwnProperty("prop"); verifyNotConfigurable(obj, "prop");
} assert.sameValue(desc1.configurable, true);
runTestCase(testcase); assert.sameValue(desc2.configurable, false);
assert(obj.hasOwnProperty("prop"));

View File

@ -10,10 +10,9 @@ description: >
Object.defineProperty - 'name' property doesn't exist in 'O', test Object.defineProperty - 'name' property doesn't exist in 'O', test
[[Set]] of 'name' property of 'Attributes' is set as undefined [[Set]] of 'name' property of 'Attributes' is set as undefined
value if absent in accessor descriptor 'desc' (8.12.9 step 4.b.i) value if absent in accessor descriptor 'desc' (8.12.9 step 4.b.i)
includes: [runTestCase.js] includes: [propertyHelper.js]
---*/ ---*/
function testcase() {
var obj = {}; var obj = {};
Object.defineProperty(obj, "property", { Object.defineProperty(obj, "property", {
@ -25,23 +24,10 @@ function testcase() {
}); });
if (obj.property !== "property") { assert.sameValue(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;
}
return true; var desc = Object.getOwnPropertyDescriptor(obj, "property");
} assert.sameValue(typeof desc.set, "undefined");
runTestCase(testcase);
verifyNotEnumerable(obj, "property");
verifyNotConfigurable(obj, "property");

View File

@ -10,10 +10,9 @@ description: >
ES5 Attributes - property ([[Get]] is a Function, [[Set]] is a ES5 Attributes - property ([[Get]] is a Function, [[Set]] is a
Function, [[Enumerable]] is true, [[Configurable]] is false) is Function, [[Enumerable]] is true, [[Configurable]] is false) is
undeletable undeletable
includes: [runTestCase.js] includes: [propertyHelper.js]
---*/ ---*/
function testcase() {
var obj = {}; var obj = {};
var getFunc = function () { var getFunc = function () {
@ -32,11 +31,5 @@ function testcase() {
configurable: false configurable: false
}); });
var propertyDefineCorrect = obj.hasOwnProperty("prop"); assert(obj.hasOwnProperty("prop"));
var desc = Object.getOwnPropertyDescriptor(obj, "prop"); verifyNotConfigurable(obj, "prop");
delete obj.prop;
return propertyDefineCorrect && desc.configurable === false && obj.hasOwnProperty("prop");
}
runTestCase(testcase);

View File

@ -11,10 +11,9 @@ description: >
accessor property ([[Get]] is a Function, [[Set]] is a Function, accessor property ([[Get]] is a Function, [[Set]] is a Function,
[[Enumerable]] is true, [[Configurable]] is false) to different [[Enumerable]] is true, [[Configurable]] is false) to different
value value
includes: [runTestCase.js] includes: [propertyHelper.js]
---*/ ---*/
function testcase() {
var obj = {}; var obj = {};
var getFunc = function () { var getFunc = function () {
@ -39,12 +38,13 @@ function testcase() {
configurable: true configurable: true
}); });
return false; $ERROR("Expected TypeError");
} catch (e) { } catch (e) {
var desc2 = Object.getOwnPropertyDescriptor(obj, "prop"); assert(e instanceof TypeError);
delete obj.prop; 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);

View File

@ -11,10 +11,9 @@ description: >
accessor property ([[Get]] is a Function, [[Set]] is a Function, accessor property ([[Get]] is a Function, [[Set]] is a Function,
[[Enumerable]] is false, [[Configurable]] is true) to different [[Enumerable]] is false, [[Configurable]] is true) to different
value value
includes: [runTestCase.js] includes: [propertyHelper.js]
---*/ ---*/
function testcase() {
var obj = {}; var obj = {};
var getFunc = function () { var getFunc = function () {
@ -34,13 +33,10 @@ function testcase() {
}); });
var desc1 = Object.getOwnPropertyDescriptor(obj, "prop"); var desc1 = Object.getOwnPropertyDescriptor(obj, "prop");
assert.sameValue(desc1.configurable, true);
Object.defineProperty(obj, "prop", { Object.defineProperty(obj, "prop", {
configurable: false configurable: false
}); });
var desc2 = Object.getOwnPropertyDescriptor(obj, "prop");
delete obj.prop;
return desc1.configurable === true && desc2.configurable === false && obj.hasOwnProperty("prop"); verifyNotConfigurable(obj, "prop");
}
runTestCase(testcase);

View File

@ -10,10 +10,9 @@ description: >
ES5 Attributes - property ([[Get]] is a Function, [[Set]] is a ES5 Attributes - property ([[Get]] is a Function, [[Set]] is a
Function, [[Enumerable]] is false, [[Configurable]] is false) is Function, [[Enumerable]] is false, [[Configurable]] is false) is
undeletable undeletable
includes: [runTestCase.js] includes: [propertyHelper.js]
---*/ ---*/
function testcase() {
var obj = {}; var obj = {};
var getFunc = function () { var getFunc = function () {
@ -32,11 +31,5 @@ function testcase() {
configurable: false configurable: false
}); });
var propertyDefineCorrect = obj.hasOwnProperty("prop"); assert(obj.hasOwnProperty("prop"));
var desc = Object.getOwnPropertyDescriptor(obj, "prop"); verifyNotConfigurable(obj, "prop");
delete obj.prop;
return propertyDefineCorrect && desc.configurable === false && obj.hasOwnProperty("prop");
}
runTestCase(testcase);

View File

@ -11,10 +11,9 @@ description: >
accessor property ([[Get]] is a Function, [[Set]] is a Function, accessor property ([[Get]] is a Function, [[Set]] is a Function,
[[Enumerable]] is false, [[Configurable]] is false) to different [[Enumerable]] is false, [[Configurable]] is false) to different
value value
includes: [runTestCase.js] includes: [propertyHelper.js]
---*/ ---*/
function testcase() {
var obj = {}; var obj = {};
var getFunc = function () { var getFunc = function () {
@ -39,12 +38,9 @@ function testcase() {
configurable: true configurable: true
}); });
return false; $ERROR("Expected TypeError");
} catch (e) { } catch (e) {
var desc2 = Object.getOwnPropertyDescriptor(obj, "prop"); assert(e instanceof TypeError);
delete obj.prop; assert.sameValue(desc1.configurable, false);
verifyNotConfigurable(obj, "prop");
return desc1.configurable === false && desc2.configurable === false && obj.hasOwnProperty("prop") && e instanceof TypeError;
} }
}
runTestCase(testcase);

View File

@ -7,10 +7,9 @@
/*--- /*---
es5id: 15.2.3.6-4-581 es5id: 15.2.3.6-4-581
description: ES5 Attributes - Fail to add property into object (Number instance) description: ES5 Attributes - Fail to add property into object (Number instance)
includes: [runTestCase.js] includes: [propertyHelper.js]
---*/ ---*/
function testcase() {
var data = "data"; var data = "data";
try { try {
Object.defineProperty(Number.prototype, "prop", { Object.defineProperty(Number.prototype, "prop", {
@ -21,11 +20,12 @@ function testcase() {
configurable: true configurable: true
}); });
var numObj = new Number(); 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 { } finally {
delete Number.prototype.prop; delete Number.prototype.prop;
} }
}
runTestCase(testcase);

View File

@ -9,10 +9,9 @@ es5id: 15.2.3.6-4-586
description: > description: >
ES5 Attributes - Fail to update value of property into of ES5 Attributes - Fail to update value of property into of
[[Proptotype]] internal property (JSON) [[Proptotype]] internal property (JSON)
includes: [runTestCase.js] includes: [propertyHelper.js]
---*/ ---*/
function testcase() {
var data = "data"; var data = "data";
try { try {
Object.defineProperty(Object.prototype, "prop", { Object.defineProperty(Object.prototype, "prop", {
@ -22,11 +21,11 @@ function testcase() {
enumerable: false, enumerable: false,
configurable: true 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 { } finally {
delete Object.prototype.prop; delete Object.prototype.prop;
} }
}
runTestCase(testcase);

View File

@ -9,10 +9,9 @@ es5id: 15.2.3.6-4-591
description: > description: >
ES5 Attributes - Fail to update value of property of ES5 Attributes - Fail to update value of property of
[[Proptotype]] internal property (Object.create) [[Proptotype]] internal property (Object.create)
includes: [runTestCase.js] includes: [propertyHelper.js]
---*/ ---*/
function testcase() {
var appointment = {}; var appointment = {};
var data1 = 1001; var data1 = 1001;
@ -43,17 +42,28 @@ function testcase() {
}); });
var teamMeeting = Object.create(meeting); var teamMeeting = Object.create(meeting);
verifyNotWritable(teamMeeting, "name", "nocheck");
verifyNotWritable(teamMeeting, "startTime", "nocheck");
verifyNotWritable(teamMeeting, "conferenceCall", "nocheck");
try {
teamMeeting.name = "IE Team Meeting"; teamMeeting.name = "IE Team Meeting";
} catch (e) {}
try {
var dateObj = new Date("10/31/2010 08:00"); var dateObj = new Date("10/31/2010 08:00");
teamMeeting.startTime = dateObj; teamMeeting.startTime = dateObj;
} catch (e) {}
try {
teamMeeting.conferenceCall = "4255551212"; teamMeeting.conferenceCall = "4255551212";
} catch (e) {}
var hasOwnProperty = !teamMeeting.hasOwnProperty("name") && assert(!teamMeeting.hasOwnProperty("name"));
!teamMeeting.hasOwnProperty("startTime") && assert(!teamMeeting.hasOwnProperty("startTime"));
!teamMeeting.hasOwnProperty('conferenceCall'); assert(!teamMeeting.hasOwnProperty('conferenceCall'));
return hasOwnProperty && teamMeeting.name === "NAME" && assert.sameValue(teamMeeting.name, "NAME");
teamMeeting.startTime === 1001 && assert.sameValue(teamMeeting.startTime, 1001);
teamMeeting.conferenceCall === "In-person meeting"; assert.sameValue(teamMeeting.conferenceCall, "In-person meeting");
}
runTestCase(testcase);

View File

@ -9,10 +9,9 @@ es5id: 15.2.3.6-4-596
description: > description: >
ES5 Attributes - Fail to update value of property into of ES5 Attributes - Fail to update value of property into of
[[Proptotype]] internal property (Function.prototype.bind) [[Proptotype]] internal property (Function.prototype.bind)
includes: [runTestCase.js] includes: [propertyHelper.js]
---*/ ---*/
function testcase() {
var foo = function () { }; var foo = function () { };
var data = "data"; var data = "data";
try { try {
@ -25,11 +24,10 @@ function testcase() {
}); });
var obj = foo.bind({}); 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 { } finally {
delete Function.prototype.prop; delete Function.prototype.prop;
} }
}
runTestCase(testcase);

View File

@ -9,37 +9,19 @@ es5id: 15.2.3.6-4-63
description: > description: >
Object.defineProperty - both desc.value and name.value are NaN Object.defineProperty - both desc.value and name.value are NaN
(8.12.9 step 6) (8.12.9 step 6)
includes: [runTestCase.js] includes: [propertyHelper.js]
---*/ ---*/
function testcase() {
var obj = {}; var obj = {};
Object.defineProperty(obj, "foo", { value: NaN }); Object.defineProperty(obj, "foo", { value: NaN });
Object.defineProperty(obj, "foo", { value: NaN }); Object.defineProperty(obj, "foo", { value: NaN });
if (!isNaN(obj.foo)) { assert(isNaN(obj.foo));
return false;
}
obj.foo = "verifyValue"; verifyNotWritable(obj, "foo");
if (obj.foo === "verifyValue") {
return false;
}
for (var prop in obj) { verifyNotEnumerable(obj, "foo");
if (obj.hasOwnProperty(prop) && prop === "foo") {
return false;
}
}
delete obj.foo; verifyNotConfigurable(obj, "foo");
if (!obj.hasOwnProperty("foo")) {
return false;
}
return true;
}
runTestCase(testcase);

View File

@ -10,11 +10,9 @@ description: >
Object.defineProperty will not throw TypeError if Object.defineProperty will not throw TypeError if
name.configurable = false, name.writable = false, name.value = NaN name.configurable = false, name.writable = false, name.value = NaN
and desc.value = NaN (8.12.9 step 10.a.ii.1) and desc.value = NaN (8.12.9 step 10.a.ii.1)
includes: [runTestCase.js] includes: [propertyHelper.js]
---*/ ---*/
function testcase() {
var obj = {}; var obj = {};
Object.defineProperty(obj, "foo", { Object.defineProperty(obj, "foo", {
@ -29,26 +27,10 @@ function testcase() {
configurable: false configurable: false
}); });
if (!isNaN(obj.foo)) { assert(isNaN(obj.foo));
return false;
}
obj.foo = "verifyValue"; verifyNotWritable(obj, "foo");
if (obj.foo === "verifyValue") {
return false;
}
for (var prop in obj) { verifyNotEnumerable(obj, "foo");
if (obj.hasOwnProperty(prop) && prop === "foo") {
return false;
}
}
delete obj.foo; verifyNotConfigurable(obj, "foo");
if (!obj.hasOwnProperty("foo")) {
return false;
}
return true;
}
runTestCase(testcase);