diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /js/src/tests/ecma_5/Object/mutation-prevention-methods.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/tests/ecma_5/Object/mutation-prevention-methods.js')
-rw-r--r-- | js/src/tests/ecma_5/Object/mutation-prevention-methods.js | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/js/src/tests/ecma_5/Object/mutation-prevention-methods.js b/js/src/tests/ecma_5/Object/mutation-prevention-methods.js new file mode 100644 index 000000000..01b4c19cb --- /dev/null +++ b/js/src/tests/ecma_5/Object/mutation-prevention-methods.js @@ -0,0 +1,124 @@ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/licenses/publicdomain/ + * Contributor: + * Jeff Walden <jwalden+code@mit.edu> + */ + +var gTestfile = 'mutation-prevention-methods.js'; +//----------------------------------------------------------------------------- +var BUGNUMBER = 492849; +var summary = 'Object.is{Sealed,Frozen}, Object.{seal,freeze}'; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +// Empty object + +var o1 = {}; + +assertEq(Object.isExtensible(o1), true); +assertEq(Object.isSealed(o1), false); +assertEq(Object.isFrozen(o1), false); + +Object.preventExtensions(o1); + +// An non-extensible empty object has no properties, so it is vacuously sealed +// and frozen. +assertEq(Object.isExtensible(o1), false); +assertEq(Object.isSealed(o1), true); +assertEq(Object.isFrozen(o1), true); + + +// Object with a data property + +var o2 = { 1: 2 }; + +assertEq(Object.isExtensible(o2), true); +assertEq(Object.isSealed(o2), false); +assertEq(Object.isFrozen(o2), false); + +Object.preventExtensions(o2); + +assertEq(Object.isExtensible(o2), false); +assertEq(Object.isSealed(o2), false); +assertEq(Object.isFrozen(o2), false); + +Object.seal(o2); + +assertEq(Object.isExtensible(o2), false); +assertEq(Object.isSealed(o2), true); +assertEq(Object.isFrozen(o2), false); + +assertEq(o2[1], 2); + +var desc; + +desc = Object.getOwnPropertyDescriptor(o2, "1"); +assertEq(typeof desc, "object"); +assertEq(desc.enumerable, true); +assertEq(desc.configurable, false); +assertEq(desc.value, 2); +assertEq(desc.writable, true); + +o2[1] = 17; + +assertEq(o2[1], 17); + +desc = Object.getOwnPropertyDescriptor(o2, "1"); +assertEq(typeof desc, "object"); +assertEq(desc.enumerable, true); +assertEq(desc.configurable, false); +assertEq(desc.value, 17); +assertEq(desc.writable, true); + +Object.freeze(o2); + +assertEq(o2[1], 17); + +desc = Object.getOwnPropertyDescriptor(o2, "1"); +assertEq(typeof desc, "object"); +assertEq(desc.enumerable, true); +assertEq(desc.configurable, false); +assertEq(desc.value, 17); +assertEq(desc.writable, false); + + +// Object with an accessor property + +var o3 = { get foo() { return 17; } }; + +assertEq(Object.isExtensible(o3), true); +assertEq(Object.isSealed(o3), false); +assertEq(Object.isFrozen(o3), false); + +Object.preventExtensions(o3); + +assertEq(Object.isExtensible(o3), false); +assertEq(Object.isSealed(o3), false); +assertEq(Object.isFrozen(o3), false); + +Object.seal(o3); + +// An accessor property in a sealed object is unchanged if that object is +// frozen, so a sealed object containing only accessor properties is also +// vacuously frozen. +assertEq(Object.isExtensible(o3), false); +assertEq(Object.isSealed(o3), true); +assertEq(Object.isFrozen(o3), true); + +Object.freeze(o3); + +assertEq(Object.isExtensible(o3), false); +assertEq(Object.isSealed(o3), true); +assertEq(Object.isFrozen(o3), true); + + +/******************************************************************************/ + +reportCompare(true, true); + +print("All tests passed!"); |