Skip to content
Snippets Groups Projects
Commit 6ccabc09 authored by smikes's avatar smikes
Browse files

strict mode: use new property helpers

Object.freeze fixes
global object tests: noStrict
preventExtensions tests
Object.seal tests

one more freeze test
parent 61cd8c6a
No related branches found
No related tags found
No related merge requests found
Showing
with 200 additions and 290 deletions
......@@ -7,26 +7,18 @@
/*---
es5id: 15.2.3.9-2-4
description: Object.freeze - Non-enumerable own properties of 'O' are frozen
includes: [runTestCase.js]
includes: [propertyHelper.js]
---*/
function testcase() {
var obj = {};
var obj = {};
Object.defineProperty(obj, "foo", {
value: 10,
enumerable: false,
configurable: true
});
Object.defineProperty(obj, "foo", {
value: 10,
enumerable: false,
configurable: true
});
Object.freeze(obj);
Object.freeze(obj);
var desc = Object.getOwnPropertyDescriptor(obj, "foo");
var beforeDeleted = obj.hasOwnProperty("foo");
delete obj.foo;
var afterDeleted = obj.hasOwnProperty("foo");
return beforeDeleted && afterDeleted && desc.configurable === false && desc.writable === false;
}
runTestCase(testcase);
assert(obj.hasOwnProperty("foo"));
verifyNotConfigurable(obj, "foo");
......@@ -7,19 +7,16 @@
/*---
es5id: 15.2.3.9-2-a-1
description: Object.freeze - 'P' is own data property
includes: [runTestCase.js]
includes: [propertyHelper.js]
---*/
function testcase() {
var obj = {};
var obj = {};
obj.foo = 10; // default [[Configurable]] attribute value of foo: true
obj.foo = 10; // default [[Configurable]] attribute value of foo: true
Object.freeze(obj);
Object.freeze(obj);
var desc = Object.getOwnPropertyDescriptor(obj, "foo");
verifyNotWritable(obj, "foo");
verifyNotConfigurable(obj, "foo");
delete obj.foo;
return obj.foo === 10 && desc.configurable === false && desc.writable === false;
}
runTestCase(testcase);
assert.sameValue(obj.foo, 10);
......@@ -9,19 +9,16 @@ es5id: 15.2.3.9-2-a-10
description: >
Object.freeze - 'P' is own named property of an Array object that
uses Object's [[GetOwnProperty]]
includes: [runTestCase.js]
includes: [propertyHelper.js]
---*/
function testcase() {
var arrObj = [];
var arrObj = [];
arrObj.foo = 10; // default [[Configurable]] attribute value of foo: true
arrObj.foo = 10; // default [[Configurable]] attribute value of foo: true
Object.freeze(arrObj);
Object.freeze(arrObj);
var desc = Object.getOwnPropertyDescriptor(arrObj, "foo");
verifyNotWritable(arrObj, "foo");
verifyNotConfigurable(arrObj, "foo");
delete arrObj.foo;
return arrObj.foo === 10 && desc.configurable === false && desc.writable === false;
}
runTestCase(testcase);
assert.sameValue(arrObj.foo, 10);
......@@ -9,19 +9,17 @@ es5id: 15.2.3.9-2-a-11
description: >
Object.freeze - 'P' is own index property of the Arguments object
that implements its own [[GetOwnProperty]]
includes: [runTestCase.js]
includes: [propertyHelper.js]
---*/
function testcase() {
// default [[Configurable]] attribute value of "0": true
var argObj = (function () { return arguments; }(1, 2, 3));
// default [[Configurable]] attribute value of "0": true
var argObj = (function () { return arguments; }(1, 2, 3));
Object.freeze(argObj);
Object.freeze(argObj);
var desc = Object.getOwnPropertyDescriptor(argObj, "0");
var desc = Object.getOwnPropertyDescriptor(argObj, "0");
verifyNotWritable(argObj, "0");
verifyNotConfigurable(argObj, "0");
delete argObj[0];
return argObj[0] === 1 && desc.configurable === false && desc.writable === false;
}
runTestCase(testcase);
......@@ -9,19 +9,14 @@ es5id: 15.2.3.9-2-a-12
description: >
Object.freeze - 'P' is own index property of a String object that
implements its own [[GetOwnProperty]]
includes: [runTestCase.js]
includes: [propertyHelper.js]
---*/
function testcase() {
// default [[Configurable]] attribute value of "0": true
var strObj = new String("abc");
// default [[Configurable]] attribute value of "0": true
var strObj = new String("abc");
Object.freeze(strObj);
Object.freeze(strObj);
var desc = Object.getOwnPropertyDescriptor(strObj, "0");
delete strObj[0];
return strObj[0] === "a" && desc.configurable === false && desc.writable === false;
}
runTestCase(testcase);
verifyNotWritable(strObj, "0");
verifyNotConfigurable(strObj, "0");
......@@ -7,19 +7,14 @@
/*---
es5id: 15.2.3.9-2-a-13
description: Object.freeze - 'P' is own index property of the Object
includes: [runTestCase.js]
includes: [propertyHelper.js]
---*/
function testcase() {
// default [[Configurable]] attribute value of "0": true
var obj = { 0: 0, 1: 1, length: 2};
// default [[Configurable]] attribute value of "0": true
var obj = { 0: 0, 1: 1, length: 2};
Object.freeze(obj);
Object.freeze(obj);
var desc = Object.getOwnPropertyDescriptor(obj, "0");
delete obj[0];
return obj[0] === 0 && desc.configurable === false && desc.writable === false;
}
runTestCase(testcase);
verifyNotWritable(obj, "0");
verifyNotConfigurable(obj, "0");
......@@ -9,19 +9,14 @@ es5id: 15.2.3.9-2-a-14
description: >
Object.freeze - 'P' is own index property of an Array object that
uses Object's [[GetOwnProperty]]
includes: [runTestCase.js]
includes: [propertyHelper.js]
---*/
function testcase() {
// default [[Configurable]] attribute value of "0": true
var arrObj = [0, 1, 2];
// default [[Configurable]] attribute value of "0": true
var arrObj = [0, 1, 2];
Object.freeze(arrObj);
Object.freeze(arrObj);
var desc = Object.getOwnPropertyDescriptor(arrObj, "0");
delete arrObj[0];
return arrObj[0] === 0 && desc.configurable === false && desc.writable === false;
}
runTestCase(testcase);
verifyNotWritable(arrObj, "0");
verifyNotConfigurable(arrObj, "0");
assert.sameValue(arrObj[0], 0);
......@@ -9,25 +9,20 @@ es5id: 15.2.3.9-2-a-2
description: >
Object.freeze - 'P' is own data property that overrides an
inherited data property
includes: [runTestCase.js]
includes: [propertyHelper.js]
---*/
function testcase() {
var proto = { foo: 0 }; // default [[Configurable]] attribute value of foo: true
var proto = { foo: 0 }; // default [[Configurable]] attribute value of foo: true
var Con = function () { };
Con.prototype = proto;
var Con = function () { };
Con.prototype = proto;
var child = new Con();
var child = new Con();
child.foo = 10; // default [[Configurable]] attribute value of foo: true
Object.freeze(child);
child.foo = 10; // default [[Configurable]] attribute value of foo: true
var desc = Object.getOwnPropertyDescriptor(child, "foo");
Object.freeze(child);
delete child.foo;
return child.foo === 10 && desc.configurable === false && desc.writable === false;
}
runTestCase(testcase);
verifyNotWritable(child, "foo");
verifyNotConfigurable(child, "foo");
......@@ -9,33 +9,29 @@ es5id: 15.2.3.9-2-a-3
description: >
Object.freeze - 'P' is own data property that overrides an
inherited accessor property
includes: [runTestCase.js]
includes: [propertyHelper.js]
---*/
function testcase() {
var proto = {};
var proto = {};
Object.defineProperty(proto, "foo", {
get: function () {
return 0;
},
configurable: true
});
Object.defineProperty(proto, "foo", {
get: function () {
return 0;
},
configurable: true
});
var Con = function () { };
Con.prototype = proto;
var Con = function () { };
Con.prototype = proto;
var child = new Con();
Object.defineProperty(child, "foo", {
value: 10,
configurable: true
});
var child = new Con();
Object.defineProperty(child, "foo", {
value: 10,
configurable: true
});
Object.freeze(child);
Object.freeze(child);
var desc = Object.getOwnPropertyDescriptor(child, "foo");
delete child.foo;
return child.foo === 10 && desc.configurable === false && desc.writable === false;
}
runTestCase(testcase);
verifyNotWritable(child, "foo");
verifyNotConfigurable(child, "foo");
assert.sameValue(child.foo, 10);
......@@ -7,24 +7,19 @@
/*---
es5id: 15.2.3.9-2-a-4
description: Object.freeze - 'P' is own accessor property
includes: [runTestCase.js]
includes: [propertyHelper.js]
---*/
function testcase() {
var obj = {};
var obj = {};
Object.defineProperty(obj, "foo", {
get: function () {
return 10;
},
configurable: true
});
Object.defineProperty(obj, "foo", {
get: function () {
return 10;
},
configurable: true
});
Object.freeze(obj);
Object.freeze(obj);
var desc = Object.getOwnPropertyDescriptor(obj, "foo");
delete obj.foo;
return obj.foo === 10 && desc.configurable === false;
}
runTestCase(testcase);
verifyNotConfigurable(obj, "foo");
assert.sameValue(obj.foo, 10);
......@@ -9,32 +9,27 @@ es5id: 15.2.3.9-2-a-5
description: >
Object.freeze - 'P' is own accessor property that overrides an
inherited data property
includes: [runTestCase.js]
includes: [propertyHelper.js]
---*/
function testcase() {
var proto = {};
var proto = {};
proto.foo = 0; // default [[Configurable]] attribute value of foo: true
proto.foo = 0; // default [[Configurable]] attribute value of foo: true
var Con = function () { };
Con.prototype = proto;
var Con = function () { };
Con.prototype = proto;
var child = new Con();
var child = new Con();
Object.defineProperty(child, "foo", {
get: function () {
return 10;
},
configurable: true
});
Object.defineProperty(child, "foo", {
get: function () {
return 10;
},
configurable: true
});
Object.freeze(child);
Object.freeze(child);
var desc = Object.getOwnPropertyDescriptor(child, "foo");
delete child.foo;
return child.foo === 10 && desc.configurable === false;
}
runTestCase(testcase);
verifyNotConfigurable(child, "foo");
assert.sameValue(child.foo, 10);
......@@ -9,36 +9,31 @@ es5id: 15.2.3.9-2-a-6
description: >
Object.freeze - 'P' is own accessor property that overrides an
inherited accessor property
includes: [runTestCase.js]
includes: [propertyHelper.js]
---*/
function testcase() {
var proto = {};
var proto = {};
Object.defineProperty(proto, "foo", {
get: function () {
return 0;
},
configurable: true
});
Object.defineProperty(proto, "foo", {
get: function () {
return 0;
},
configurable: true
});
var Con = function () { };
Con.prototype = proto;
var Con = function () { };
Con.prototype = proto;
var child = new Con();
var child = new Con();
Object.defineProperty(child, "foo", {
get: function () {
return 10;
},
configurable: true
});
Object.defineProperty(child, "foo", {
get: function () {
return 10;
},
configurable: true
});
Object.freeze(child);
Object.freeze(child);
var desc = Object.getOwnPropertyDescriptor(child, "foo");
delete child.foo;
return child.foo === 10 && desc.configurable === false;
}
runTestCase(testcase);
verifyNotConfigurable(child, "foo");
assert.sameValue(child.foo, 10);
......@@ -9,19 +9,15 @@ es5id: 15.2.3.9-2-a-7
description: >
Object.freeze - 'P' is own named property of an Arguments object
that implements its own [[GetOwnProperty]]
includes: [runTestCase.js]
includes: [propertyHelper.js]
---*/
function testcase() {
var argObj = (function () { return arguments; }());
var argObj = (function () { return arguments; }());
argObj.foo = 10; // default [[Configurable]] attribute value of foo: true
argObj.foo = 10; // default [[Configurable]] attribute value of foo: true
Object.freeze(argObj);
Object.freeze(argObj);
var desc = Object.getOwnPropertyDescriptor(argObj, "foo");
delete argObj.foo;
return argObj.foo === 10 && desc.configurable === false && desc.writable === false;
}
runTestCase(testcase);
verifyNotWritable(argObj, "foo");
verifyNotConfigurable(argObj, "foo");
assert.sameValue(argObj.foo, 10);
......@@ -9,19 +9,15 @@ es5id: 15.2.3.9-2-a-8
description: >
Object.freeze - 'P' is own named property of the String object
that implements its own [[GetOwnProperty]]
includes: [runTestCase.js]
includes: [propertyHelper.js]
---*/
function testcase() {
var strObj = new String("abc");
var strObj = new String("abc");
strObj.foo = 10; // default [[Configurable]] attribute value of foo: true
strObj.foo = 10; // default [[Configurable]] attribute value of foo: true
Object.freeze(strObj);
Object.freeze(strObj);
var desc = Object.getOwnPropertyDescriptor(strObj, "foo");
delete strObj.foo;
return strObj.foo === 10 && desc.configurable === false && desc.writable === false;
}
runTestCase(testcase);
verifyNotWritable(strObj, "foo");
verifyNotConfigurable(strObj, "foo");
assert.sameValue(strObj.foo, 10);
......@@ -9,19 +9,16 @@ es5id: 15.2.3.9-2-a-9
description: >
Object.freeze - 'P' is own property of the Function object that
uses Object's [[GetOwnProperty]]
includes: [runTestCase.js]
includes: [propertyHelper.js]
---*/
function testcase() {
var funObj = function () { };
var funObj = function () { };
funObj.foo = 10; // default [[Configurable]] attribute value of foo: true
funObj.foo = 10; // default [[Configurable]] attribute value of foo: true
Object.freeze(funObj);
Object.freeze(funObj);
var desc = Object.getOwnPropertyDescriptor(funObj, "foo");
verifyNotWritable(funObj, "foo");
verifyNotConfigurable(funObj, "foo");
delete funObj.foo;
return funObj.foo === 10 && desc.configurable === false && desc.writable === false;
}
runTestCase(testcase);
assert.sameValue(funObj.foo, 10);
......@@ -10,47 +10,38 @@ description: >
Object.freeze - The [[Configurable]] attribute of own accessor
property of 'O' is set to false while other attributes are
unchanged
includes: [runTestCase.js]
includes: [propertyHelper.js]
---*/
function testcase() {
var obj = {};
function get_func() {
return 10;
}
var resultSetFun = false;
function set_func() {
resultSetFun = true;
}
Object.defineProperty(obj, "foo", {
get: get_func,
set: set_func,
enumerable: true,
configurable: true
});
Object.freeze(obj);
var res1 = obj.hasOwnProperty("foo");
delete obj.foo;
var res2 = obj.hasOwnProperty("foo");
var resultConfigurable = (res1 && res2);
var resultGetFun = (obj.foo === 10);
obj.foo = 12;
var resultEnumerable = false;
for (var prop in obj) {
if (prop === "foo") {
resultEnumerable = true;
}
}
var desc = Object.getOwnPropertyDescriptor(obj, "foo");
var result = resultConfigurable && resultEnumerable && resultGetFun && resultSetFun;
return desc.configurable === false && result;
}
runTestCase(testcase);
var obj = {};
function get_func() {
return 10;
}
var set_funcCalled = false;
function set_func() {
set_funcCalled = true;
}
Object.defineProperty(obj, "foo", {
get: get_func,
set: set_func,
enumerable: true,
configurable: true
});
Object.freeze(obj);
assert(obj.hasOwnProperty("foo"));
verifyNotConfigurable(obj, "foo");
assert.sameValue(obj.foo, 10);
obj.foo = 12;
assert(set_funcCalled);
verifyEnumerable(obj, "foo");
var desc = Object.getOwnPropertyDescriptor(obj, "foo");
assert.sameValue(desc.configurable, false);
......@@ -7,15 +7,11 @@
/*---
es5id: 15.2.3.13-2-1
description: Object.isExtensible returns true for all built-in objects (Global)
includes: [runTestCase.js]
flags: [noStrict]
---*/
var global = this;
function testcase() {
// in non-strict mode, 'this' is bound to the global object.
var e = Object.isExtensible(this);
if (e === true) {
return true;
}
}
runTestCase(testcase);
// in non-strict mode, 'this' is bound to the global object.
assert(Object.isExtensible(this));
......@@ -7,14 +7,8 @@
/*---
es5id: 15.2.3.12-3-1
description: Object.isFrozen returns false for all built-in objects (Global)
includes: [runTestCase.js]
flags: [noStrict]
---*/
function testcase() {
// in non-strict mode, 'this' is bound to the global object.
var b = Object.isFrozen(this);
if (b === false) {
return true;
}
}
runTestCase(testcase);
// in non-strict mode, 'this' is bound to the global object.
assert(!Object.isFrozen(this));
......@@ -7,14 +7,8 @@
/*---
es5id: 15.2.3.11-4-1
description: Object.isSealed returns false for all built-in objects (Global)
includes: [runTestCase.js]
flags: [noStrict]
---*/
function testcase() {
// in non-strict mode, 'this' is bound to the global object.
var b = Object.isSealed(this);
if (b === false) {
return true;
}
}
runTestCase(testcase);
// in non-strict mode, 'this' is bound to the global object.
assert(!Object.isSealed(this));
......@@ -9,15 +9,16 @@ es5id: 15.2.3.10-3-10
description: >
Object.preventExtensions - indexed properties cannot be added into
an Error object
includes: [runTestCase.js]
includes: [propertyHelper.js]
---*/
function testcase() {
var errObj = new Error();
var preCheck = Object.isExtensible(errObj);
Object.preventExtensions(errObj);
var errObj = new Error();
assert(Object.isExtensible(errObj));
Object.preventExtensions(errObj);
assert(!Object.isExtensible(errObj));
verifyNotWritable(errObj, "0", "nocheck");
assert(!errObj.hasOwnProperty("0"));
errObj[0] = 12;
return preCheck && !errObj.hasOwnProperty("0");
}
runTestCase(testcase);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment