js/src/tests/ecma_5/Object/add-property-non-extensible.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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 = 'add-property-non-extensible.js';
michael@0 9 //-----------------------------------------------------------------------------
michael@0 10 var BUGNUMBER = 602144;
michael@0 11 var summary =
michael@0 12 'Properly method-compile attempted addition of properties to ' +
michael@0 13 'non-extensible objects';
michael@0 14
michael@0 15 print(BUGNUMBER + ": " + summary);
michael@0 16
michael@0 17 /**************
michael@0 18 * BEGIN TEST *
michael@0 19 **************/
michael@0 20
michael@0 21 // No property
michael@0 22
michael@0 23 var o1 = {};
michael@0 24 for (var i = 0; i < 5; i++)
michael@0 25 o1.a = 3;
michael@0 26 assertEq(o1.a, 3);
michael@0 27
michael@0 28 var o2 = Object.preventExtensions({});
michael@0 29 for (var i = 0; i < 5; i++)
michael@0 30 o2.a = 3;
michael@0 31 assertEq(Object.getOwnPropertyDescriptor(o2, "a"), undefined);
michael@0 32
michael@0 33 var o3 = Object.seal({});
michael@0 34 for (var i = 0; i < 5; i++)
michael@0 35 o3.a = 3;
michael@0 36 assertEq(Object.getOwnPropertyDescriptor(o3, "a"), undefined);
michael@0 37
michael@0 38 var o4 = Object.freeze({});
michael@0 39 for (var i = 0; i < 5; i++)
michael@0 40 o4.a = 3;
michael@0 41 assertEq(Object.getOwnPropertyDescriptor(o4, "a"), undefined);
michael@0 42
michael@0 43
michael@0 44 // Has property
michael@0 45
michael@0 46 var o5 = { a: 2 };
michael@0 47 for (var i = 0; i < 5; i++)
michael@0 48 o5.a = 3;
michael@0 49 assertEq(o5.a, 3);
michael@0 50
michael@0 51 var o6 = Object.preventExtensions({ a: 2 });
michael@0 52 for (var i = 0; i < 5; i++)
michael@0 53 o6.a = 3;
michael@0 54 assertEq(o6.a, 3);
michael@0 55
michael@0 56 var o7 = Object.seal({ a: 2 });
michael@0 57 for (var i = 0; i < 5; i++)
michael@0 58 o7.a = 3;
michael@0 59 assertEq(o7.a, 3);
michael@0 60
michael@0 61 var o8 = Object.freeze({ a: 2 });
michael@0 62 for (var i = 0; i < 5; i++)
michael@0 63 o8.a = 3;
michael@0 64 assertEq(o8.a, 2);
michael@0 65
michael@0 66
michael@0 67 // Extensible, hit up the prototype chain
michael@0 68
michael@0 69 var o9 = Object.create({ a: 2 });
michael@0 70 for (var i = 0; i < 5; i++)
michael@0 71 o9.a = 3;
michael@0 72 assertEq(o9.a, 3);
michael@0 73
michael@0 74 var o10 = Object.create(Object.preventExtensions({ a: 2 }));
michael@0 75 for (var i = 0; i < 5; i++)
michael@0 76 o10.a = 3;
michael@0 77 assertEq(o10.a, 3);
michael@0 78
michael@0 79 var o11 = Object.create(Object.seal({ a: 2 }));
michael@0 80 for (var i = 0; i < 5; i++)
michael@0 81 o11.a = 3;
michael@0 82 assertEq(o11.a, 3);
michael@0 83
michael@0 84 var o12 = Object.create(Object.freeze({ a: 2 }));
michael@0 85 for (var i = 0; i < 5; i++)
michael@0 86 o12.a = 3;
michael@0 87 assertEq(Object.getOwnPropertyDescriptor(o12, "a"), undefined);
michael@0 88
michael@0 89
michael@0 90 // Not extensible, hit up the prototype chain
michael@0 91
michael@0 92 var o13 = Object.preventExtensions(Object.create({ a: 2 }));
michael@0 93 for (var i = 0; i < 5; i++)
michael@0 94 o13.a = 3;
michael@0 95 assertEq(Object.getOwnPropertyDescriptor(o13, "a"), undefined);
michael@0 96
michael@0 97 var o14 =
michael@0 98 Object.preventExtensions(Object.create(Object.preventExtensions({ a: 2 })));
michael@0 99 for (var i = 0; i < 5; i++)
michael@0 100 o14.a = 3;
michael@0 101 assertEq(Object.getOwnPropertyDescriptor(o14, "a"), undefined);
michael@0 102
michael@0 103 var o15 = Object.preventExtensions(Object.create(Object.seal({ a: 2 })));
michael@0 104 for (var i = 0; i < 5; i++)
michael@0 105 o15.a = 3;
michael@0 106 assertEq(Object.getOwnPropertyDescriptor(o15, "a"), undefined);
michael@0 107
michael@0 108 var o16 = Object.preventExtensions(Object.create(Object.freeze({ a: 2 })));
michael@0 109 for (var i = 0; i < 5; i++)
michael@0 110 o16.a = 3;
michael@0 111 assertEq(Object.getOwnPropertyDescriptor(o16, "a"), undefined);
michael@0 112
michael@0 113
michael@0 114 /******************************************************************************/
michael@0 115
michael@0 116 reportCompare(true, true);
michael@0 117
michael@0 118 print("All tests passed!");

mercurial