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 | */ |
michael@0 | 5 | |
michael@0 | 6 | //----------------------------------------------------------------------------- |
michael@0 | 7 | var BUGNUMBER = 430133; |
michael@0 | 8 | var summary = 'ES5 Object.defineProperties(O, Properties)'; |
michael@0 | 9 | |
michael@0 | 10 | print(BUGNUMBER + ": " + summary); |
michael@0 | 11 | |
michael@0 | 12 | /************** |
michael@0 | 13 | * BEGIN TEST * |
michael@0 | 14 | **************/ |
michael@0 | 15 | |
michael@0 | 16 | assertEq("defineProperties" in Object, true); |
michael@0 | 17 | assertEq(Object.defineProperties.length, 2); |
michael@0 | 18 | |
michael@0 | 19 | var o, props, desc, passed; |
michael@0 | 20 | |
michael@0 | 21 | o = {}; |
michael@0 | 22 | props = |
michael@0 | 23 | { |
michael@0 | 24 | a: { value: 17, enumerable: true, configurable: true, writable: true }, |
michael@0 | 25 | b: { value: 42, enumerable: false, configurable: false, writable: false } |
michael@0 | 26 | }; |
michael@0 | 27 | Object.defineProperties(o, props); |
michael@0 | 28 | assertEq("a" in o, true); |
michael@0 | 29 | assertEq("b" in o, true); |
michael@0 | 30 | desc = Object.getOwnPropertyDescriptor(o, "a"); |
michael@0 | 31 | assertEq(desc.value, 17); |
michael@0 | 32 | assertEq(desc.enumerable, true); |
michael@0 | 33 | assertEq(desc.configurable, true); |
michael@0 | 34 | assertEq(desc.writable, true); |
michael@0 | 35 | desc = Object.getOwnPropertyDescriptor(o, "b"); |
michael@0 | 36 | assertEq(desc.value, 42); |
michael@0 | 37 | assertEq(desc.enumerable, false); |
michael@0 | 38 | assertEq(desc.configurable, false); |
michael@0 | 39 | assertEq(desc.writable, false); |
michael@0 | 40 | |
michael@0 | 41 | props = |
michael@0 | 42 | { |
michael@0 | 43 | c: { value: NaN, enumerable: false, configurable: true, writable: true }, |
michael@0 | 44 | b: { value: 44 } |
michael@0 | 45 | }; |
michael@0 | 46 | var error = "before"; |
michael@0 | 47 | try |
michael@0 | 48 | { |
michael@0 | 49 | Object.defineProperties(o, props); |
michael@0 | 50 | error = "no exception thrown"; |
michael@0 | 51 | } |
michael@0 | 52 | catch (e) |
michael@0 | 53 | { |
michael@0 | 54 | if (e instanceof TypeError) |
michael@0 | 55 | error = "typeerror"; |
michael@0 | 56 | else |
michael@0 | 57 | error = "bad exception: " + e; |
michael@0 | 58 | } |
michael@0 | 59 | assertEq(error, "typeerror", "didn't throw or threw wrongly"); |
michael@0 | 60 | assertEq("c" in o, true, "new property added"); |
michael@0 | 61 | assertEq(o.b, 42, "old property value preserved"); |
michael@0 | 62 | |
michael@0 | 63 | function Properties() { } |
michael@0 | 64 | Properties.prototype = { b: { value: 42, enumerable: true } }; |
michael@0 | 65 | props = new Properties(); |
michael@0 | 66 | Object.defineProperty(props, "a", { enumerable: false }); |
michael@0 | 67 | o = {}; |
michael@0 | 68 | Object.defineProperties(o, props); |
michael@0 | 69 | assertEq("a" in o, false); |
michael@0 | 70 | assertEq(Object.getOwnPropertyDescriptor(o, "a"), undefined, |
michael@0 | 71 | "Object.defineProperties(O, Properties) should only use enumerable " + |
michael@0 | 72 | "properties on Properties"); |
michael@0 | 73 | assertEq("b" in o, false); |
michael@0 | 74 | assertEq(Object.getOwnPropertyDescriptor(o, "b"), undefined, |
michael@0 | 75 | "Object.defineProperties(O, Properties) should only use enumerable " + |
michael@0 | 76 | "properties directly on Properties"); |
michael@0 | 77 | |
michael@0 | 78 | Number.prototype.foo = { value: 17, enumerable: true }; |
michael@0 | 79 | Boolean.prototype.bar = { value: 8675309, enumerable: true }; |
michael@0 | 80 | String.prototype.quux = { value: "Are you HAPPY yet?", enumerable: true }; |
michael@0 | 81 | o = {}; |
michael@0 | 82 | Object.defineProperties(o, 5); // ToObject only throws for null/undefined |
michael@0 | 83 | assertEq("foo" in o, false, "foo is not an enumerable own property"); |
michael@0 | 84 | Object.defineProperties(o, false); |
michael@0 | 85 | assertEq("bar" in o, false, "bar is not an enumerable own property"); |
michael@0 | 86 | Object.defineProperties(o, ""); |
michael@0 | 87 | assertEq("quux" in o, false, "quux is not an enumerable own property"); |
michael@0 | 88 | |
michael@0 | 89 | error = "before"; |
michael@0 | 90 | try |
michael@0 | 91 | { |
michael@0 | 92 | Object.defineProperties(o, "1"); |
michael@0 | 93 | } |
michael@0 | 94 | catch (e) |
michael@0 | 95 | { |
michael@0 | 96 | if (e instanceof TypeError) |
michael@0 | 97 | error = "typeerror"; |
michael@0 | 98 | else |
michael@0 | 99 | error = "bad exception: " + e; |
michael@0 | 100 | } |
michael@0 | 101 | assertEq(error, "typeerror", |
michael@0 | 102 | "should throw on Properties == '1' due to '1'[0] not being a " + |
michael@0 | 103 | "property descriptor"); |
michael@0 | 104 | |
michael@0 | 105 | error = "before"; |
michael@0 | 106 | try |
michael@0 | 107 | { |
michael@0 | 108 | Object.defineProperties(o, null); |
michael@0 | 109 | } |
michael@0 | 110 | catch (e) |
michael@0 | 111 | { |
michael@0 | 112 | if (e instanceof TypeError) |
michael@0 | 113 | error = "typeerror"; |
michael@0 | 114 | else |
michael@0 | 115 | error = "bad exception: " + e; |
michael@0 | 116 | } |
michael@0 | 117 | assertEq(error, "typeerror", "should throw on Properties == null"); |
michael@0 | 118 | |
michael@0 | 119 | error = "before"; |
michael@0 | 120 | try |
michael@0 | 121 | { |
michael@0 | 122 | Object.defineProperties(o, undefined); |
michael@0 | 123 | } |
michael@0 | 124 | catch (e) |
michael@0 | 125 | { |
michael@0 | 126 | if (e instanceof TypeError) |
michael@0 | 127 | error = "typeerror"; |
michael@0 | 128 | else |
michael@0 | 129 | error = "bad exception: " + e; |
michael@0 | 130 | } |
michael@0 | 131 | assertEq(error, "typeerror", "should throw on Properties == undefined"); |
michael@0 | 132 | |
michael@0 | 133 | /******************************************************************************/ |
michael@0 | 134 | |
michael@0 | 135 | reportCompare(true, true); |
michael@0 | 136 | |
michael@0 | 137 | print("All tests passed!"); |