Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | * http://creativecommons.org/licenses/publicdomain/ |
michael@0 | 4 | * Contributor: |
michael@0 | 5 | * Jeff Walden <jwalden+code@mit.edu> |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | var gTestfile = 'mutation-prevention-methods.js'; |
michael@0 | 9 | //----------------------------------------------------------------------------- |
michael@0 | 10 | var BUGNUMBER = 492849; |
michael@0 | 11 | var summary = 'Object.is{Sealed,Frozen}, Object.{seal,freeze}'; |
michael@0 | 12 | |
michael@0 | 13 | print(BUGNUMBER + ": " + summary); |
michael@0 | 14 | |
michael@0 | 15 | /************** |
michael@0 | 16 | * BEGIN TEST * |
michael@0 | 17 | **************/ |
michael@0 | 18 | |
michael@0 | 19 | // Empty object |
michael@0 | 20 | |
michael@0 | 21 | var o1 = {}; |
michael@0 | 22 | |
michael@0 | 23 | assertEq(Object.isExtensible(o1), true); |
michael@0 | 24 | assertEq(Object.isSealed(o1), false); |
michael@0 | 25 | assertEq(Object.isFrozen(o1), false); |
michael@0 | 26 | |
michael@0 | 27 | Object.preventExtensions(o1); |
michael@0 | 28 | |
michael@0 | 29 | // An non-extensible empty object has no properties, so it is vacuously sealed |
michael@0 | 30 | // and frozen. |
michael@0 | 31 | assertEq(Object.isExtensible(o1), false); |
michael@0 | 32 | assertEq(Object.isSealed(o1), true); |
michael@0 | 33 | assertEq(Object.isFrozen(o1), true); |
michael@0 | 34 | |
michael@0 | 35 | |
michael@0 | 36 | // Object with a data property |
michael@0 | 37 | |
michael@0 | 38 | var o2 = { 1: 2 }; |
michael@0 | 39 | |
michael@0 | 40 | assertEq(Object.isExtensible(o2), true); |
michael@0 | 41 | assertEq(Object.isSealed(o2), false); |
michael@0 | 42 | assertEq(Object.isFrozen(o2), false); |
michael@0 | 43 | |
michael@0 | 44 | Object.preventExtensions(o2); |
michael@0 | 45 | |
michael@0 | 46 | assertEq(Object.isExtensible(o2), false); |
michael@0 | 47 | assertEq(Object.isSealed(o2), false); |
michael@0 | 48 | assertEq(Object.isFrozen(o2), false); |
michael@0 | 49 | |
michael@0 | 50 | Object.seal(o2); |
michael@0 | 51 | |
michael@0 | 52 | assertEq(Object.isExtensible(o2), false); |
michael@0 | 53 | assertEq(Object.isSealed(o2), true); |
michael@0 | 54 | assertEq(Object.isFrozen(o2), false); |
michael@0 | 55 | |
michael@0 | 56 | assertEq(o2[1], 2); |
michael@0 | 57 | |
michael@0 | 58 | var desc; |
michael@0 | 59 | |
michael@0 | 60 | desc = Object.getOwnPropertyDescriptor(o2, "1"); |
michael@0 | 61 | assertEq(typeof desc, "object"); |
michael@0 | 62 | assertEq(desc.enumerable, true); |
michael@0 | 63 | assertEq(desc.configurable, false); |
michael@0 | 64 | assertEq(desc.value, 2); |
michael@0 | 65 | assertEq(desc.writable, true); |
michael@0 | 66 | |
michael@0 | 67 | o2[1] = 17; |
michael@0 | 68 | |
michael@0 | 69 | assertEq(o2[1], 17); |
michael@0 | 70 | |
michael@0 | 71 | desc = Object.getOwnPropertyDescriptor(o2, "1"); |
michael@0 | 72 | assertEq(typeof desc, "object"); |
michael@0 | 73 | assertEq(desc.enumerable, true); |
michael@0 | 74 | assertEq(desc.configurable, false); |
michael@0 | 75 | assertEq(desc.value, 17); |
michael@0 | 76 | assertEq(desc.writable, true); |
michael@0 | 77 | |
michael@0 | 78 | Object.freeze(o2); |
michael@0 | 79 | |
michael@0 | 80 | assertEq(o2[1], 17); |
michael@0 | 81 | |
michael@0 | 82 | desc = Object.getOwnPropertyDescriptor(o2, "1"); |
michael@0 | 83 | assertEq(typeof desc, "object"); |
michael@0 | 84 | assertEq(desc.enumerable, true); |
michael@0 | 85 | assertEq(desc.configurable, false); |
michael@0 | 86 | assertEq(desc.value, 17); |
michael@0 | 87 | assertEq(desc.writable, false); |
michael@0 | 88 | |
michael@0 | 89 | |
michael@0 | 90 | // Object with an accessor property |
michael@0 | 91 | |
michael@0 | 92 | var o3 = { get foo() { return 17; } }; |
michael@0 | 93 | |
michael@0 | 94 | assertEq(Object.isExtensible(o3), true); |
michael@0 | 95 | assertEq(Object.isSealed(o3), false); |
michael@0 | 96 | assertEq(Object.isFrozen(o3), false); |
michael@0 | 97 | |
michael@0 | 98 | Object.preventExtensions(o3); |
michael@0 | 99 | |
michael@0 | 100 | assertEq(Object.isExtensible(o3), false); |
michael@0 | 101 | assertEq(Object.isSealed(o3), false); |
michael@0 | 102 | assertEq(Object.isFrozen(o3), false); |
michael@0 | 103 | |
michael@0 | 104 | Object.seal(o3); |
michael@0 | 105 | |
michael@0 | 106 | // An accessor property in a sealed object is unchanged if that object is |
michael@0 | 107 | // frozen, so a sealed object containing only accessor properties is also |
michael@0 | 108 | // vacuously frozen. |
michael@0 | 109 | assertEq(Object.isExtensible(o3), false); |
michael@0 | 110 | assertEq(Object.isSealed(o3), true); |
michael@0 | 111 | assertEq(Object.isFrozen(o3), true); |
michael@0 | 112 | |
michael@0 | 113 | Object.freeze(o3); |
michael@0 | 114 | |
michael@0 | 115 | assertEq(Object.isExtensible(o3), false); |
michael@0 | 116 | assertEq(Object.isSealed(o3), true); |
michael@0 | 117 | assertEq(Object.isFrozen(o3), true); |
michael@0 | 118 | |
michael@0 | 119 | |
michael@0 | 120 | /******************************************************************************/ |
michael@0 | 121 | |
michael@0 | 122 | reportCompare(true, true); |
michael@0 | 123 | |
michael@0 | 124 | print("All tests passed!"); |