js/src/tests/ecma_5/Object/15.2.3.3-01.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 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 //-----------------------------------------------------------------------------
michael@0 7 var BUGNUMBER = 505587;
michael@0 8 var summary = 'ES5 Object.getOwnPropertyDescriptor(O)';
michael@0 9 var actual = '';
michael@0 10 var expect = '';
michael@0 11
michael@0 12 printBugNumber(BUGNUMBER);
michael@0 13 printStatus (summary);
michael@0 14
michael@0 15 /**************
michael@0 16 * BEGIN TEST *
michael@0 17 **************/
michael@0 18
michael@0 19 function assertEq(a, e, msg)
michael@0 20 {
michael@0 21 function SameValue(v1, v2)
michael@0 22 {
michael@0 23 if (v1 === 0 && v2 === 0)
michael@0 24 return 1 / v1 === 1 / v2;
michael@0 25 if (v1 !== v1 && v2 !== v2)
michael@0 26 return true;
michael@0 27 return v1 === v2;
michael@0 28 }
michael@0 29
michael@0 30 if (!SameValue(a, e))
michael@0 31 {
michael@0 32 var stack = new Error().stack || "";
michael@0 33 throw "Assertion failed: got " + a + ", expected " + e +
michael@0 34 (msg ? ": " + msg : "") +
michael@0 35 (stack ? "\nStack:\n" + stack : "");
michael@0 36 }
michael@0 37 }
michael@0 38
michael@0 39 function expectDescriptor(actual, expected)
michael@0 40 {
michael@0 41 if (actual === undefined && expected === undefined)
michael@0 42 return;
michael@0 43
michael@0 44 assertEq(typeof actual, "object");
michael@0 45 assertEq(typeof expected, "object");
michael@0 46
michael@0 47 var fields =
michael@0 48 {
michael@0 49 value: true,
michael@0 50 get: true,
michael@0 51 set: true,
michael@0 52 enumerable: true,
michael@0 53 writable: true,
michael@0 54 configurable: true
michael@0 55 };
michael@0 56 for (var p in fields)
michael@0 57 assertEq(actual.hasOwnProperty(p), expected.hasOwnProperty(p), p);
michael@0 58 for (var p in actual)
michael@0 59 assertEq(p in fields, true, p);
michael@0 60 for (var p in expected)
michael@0 61 assertEq(p in fields, true, p);
michael@0 62
michael@0 63 assertEq(actual.hasOwnProperty("value"), actual.hasOwnProperty("writable"));
michael@0 64 assertEq(actual.hasOwnProperty("get"), actual.hasOwnProperty("set"));
michael@0 65 if (actual.hasOwnProperty("value"))
michael@0 66 {
michael@0 67 assertEq(actual.value, expected.value);
michael@0 68 assertEq(actual.writable, expected.writable);
michael@0 69 }
michael@0 70 else
michael@0 71 {
michael@0 72 assertEq(actual.get, expected.get);
michael@0 73 assertEq(actual.set, expected.set);
michael@0 74 }
michael@0 75
michael@0 76 assertEq(actual.hasOwnProperty("enumerable"), true);
michael@0 77 assertEq(actual.hasOwnProperty("configurable"), true);
michael@0 78 assertEq(actual.enumerable, expected.enumerable);
michael@0 79 assertEq(actual.configurable, expected.configurable);
michael@0 80 }
michael@0 81
michael@0 82 function adjustDescriptorField(o, actual, expect, field)
michael@0 83 {
michael@0 84 assertEq(field === "get" || field === "set", true);
michael@0 85 var lookup = "__lookup" + (field === "get" ? "G" : "S") + "etter";
michael@0 86 if (typeof o[lookup] === "function")
michael@0 87 expect[field] = o[lookup](field);
michael@0 88 else
michael@0 89 actual[field] = expect[field] = undefined; /* censor if we can't lookup */
michael@0 90 }
michael@0 91
michael@0 92 /******************************************************************************/
michael@0 93
michael@0 94 var o, pd, expected;
michael@0 95
michael@0 96 o = { get x() { return 12; } };
michael@0 97
michael@0 98 pd = Object.getOwnPropertyDescriptor(o, "x");
michael@0 99 expected =
michael@0 100 {
michael@0 101 set: undefined,
michael@0 102 enumerable: true,
michael@0 103 configurable: true
michael@0 104 };
michael@0 105 adjustDescriptorField(o, pd, expected, "get");
michael@0 106
michael@0 107 expectDescriptor(pd, expected);
michael@0 108
michael@0 109 /******************************************************************************/
michael@0 110
michael@0 111 var o2;
michael@0 112
michael@0 113 o = Object.create(Object.prototype, { x: {get: function () { return 12; } } });
michael@0 114
michael@0 115 pd = Object.getOwnPropertyDescriptor(o, "x");
michael@0 116 expected =
michael@0 117 {
michael@0 118 set: undefined,
michael@0 119 enumerable: false,
michael@0 120 configurable: false
michael@0 121 };
michael@0 122 adjustDescriptorField(o, pd, expected, "get");
michael@0 123
michael@0 124 expectDescriptor(pd, expected);
michael@0 125
michael@0 126 o2 = Object.create(o);
michael@0 127 assertEq(Object.getOwnPropertyDescriptor(o2, "x"), undefined);
michael@0 128
michael@0 129 /******************************************************************************/
michael@0 130
michael@0 131 o = {};
michael@0 132 o.b = 12;
michael@0 133
michael@0 134 pd = Object.getOwnPropertyDescriptor(o, "b");
michael@0 135 expected =
michael@0 136 {
michael@0 137 value: 12,
michael@0 138 writable: true,
michael@0 139 enumerable: true,
michael@0 140 configurable: true
michael@0 141 };
michael@0 142 expectDescriptor(pd, expected);
michael@0 143
michael@0 144 /******************************************************************************/
michael@0 145
michael@0 146 o = { get y() { return 17; }, set y(z) { } };
michael@0 147
michael@0 148 pd = Object.getOwnPropertyDescriptor(o, "y");
michael@0 149 expected =
michael@0 150 {
michael@0 151 enumerable: true,
michael@0 152 configurable: true
michael@0 153 };
michael@0 154 adjustDescriptorField(o, pd, expected, "get");
michael@0 155 adjustDescriptorField(o, pd, expected, "set");
michael@0 156
michael@0 157 expectDescriptor(pd, expected);
michael@0 158
michael@0 159 /******************************************************************************/
michael@0 160
michael@0 161 o = {};
michael@0 162
michael@0 163 pd = Object.getOwnPropertyDescriptor(o, "absent");
michael@0 164
michael@0 165 expectDescriptor(pd, undefined);
michael@0 166
michael@0 167 /******************************************************************************/
michael@0 168
michael@0 169 pd = Object.getOwnPropertyDescriptor([], "length");
michael@0 170 expected =
michael@0 171 {
michael@0 172 value: 0,
michael@0 173 writable: true,
michael@0 174 enumerable: false,
michael@0 175 configurable: false
michael@0 176 };
michael@0 177
michael@0 178 expectDescriptor(pd, expected);
michael@0 179
michael@0 180 pd = Object.getOwnPropertyDescriptor([1], "length");
michael@0 181 expected =
michael@0 182 {
michael@0 183 value: 1,
michael@0 184 writable: true,
michael@0 185 enumerable: false,
michael@0 186 configurable: false
michael@0 187 };
michael@0 188
michael@0 189 expectDescriptor(pd, expected);
michael@0 190
michael@0 191 pd = Object.getOwnPropertyDescriptor([1,], "length");
michael@0 192 expected =
michael@0 193 {
michael@0 194 value: 1,
michael@0 195 writable: true,
michael@0 196 enumerable: false,
michael@0 197 configurable: false
michael@0 198 };
michael@0 199
michael@0 200 expectDescriptor(pd, expected);
michael@0 201
michael@0 202 pd = Object.getOwnPropertyDescriptor([1,,], "length");
michael@0 203 expected =
michael@0 204 {
michael@0 205 value: 2,
michael@0 206 writable: true,
michael@0 207 enumerable: false,
michael@0 208 configurable: false
michael@0 209 };
michael@0 210
michael@0 211 expectDescriptor(pd, expected);
michael@0 212
michael@0 213 /******************************************************************************/
michael@0 214
michael@0 215 pd = Object.getOwnPropertyDescriptor(new String("foobar"), "length");
michael@0 216 expected =
michael@0 217 {
michael@0 218 value: 6,
michael@0 219 writable: false,
michael@0 220 enumerable: false,
michael@0 221 configurable: false
michael@0 222 };
michael@0 223
michael@0 224 expectDescriptor(pd, expected);
michael@0 225
michael@0 226 /******************************************************************************/
michael@0 227
michael@0 228 function foo() { }
michael@0 229 o = foo;
michael@0 230
michael@0 231 pd = Object.getOwnPropertyDescriptor(o, "length");
michael@0 232 expected =
michael@0 233 {
michael@0 234 value: 0,
michael@0 235 writable: false,
michael@0 236 enumerable: false,
michael@0 237 configurable: false
michael@0 238 };
michael@0 239
michael@0 240 expectDescriptor(pd, expected);
michael@0 241
michael@0 242 pd = Object.getOwnPropertyDescriptor(o, "prototype");
michael@0 243 expected =
michael@0 244 {
michael@0 245 value: foo.prototype,
michael@0 246 writable: true,
michael@0 247 enumerable: false,
michael@0 248 configurable: false
michael@0 249 };
michael@0 250
michael@0 251 expectDescriptor(pd, expected);
michael@0 252
michael@0 253 /******************************************************************************/
michael@0 254
michael@0 255 pd = Object.getOwnPropertyDescriptor(Function, "length");
michael@0 256 expected =
michael@0 257 {
michael@0 258 value: 1,
michael@0 259 writable: false,
michael@0 260 enumerable: false,
michael@0 261 configurable: false
michael@0 262 };
michael@0 263
michael@0 264 expectDescriptor(pd, expected);
michael@0 265
michael@0 266 /******************************************************************************/
michael@0 267
michael@0 268 o = /foo/im;
michael@0 269
michael@0 270 pd = Object.getOwnPropertyDescriptor(o, "source");
michael@0 271 expected =
michael@0 272 {
michael@0 273 value: "foo",
michael@0 274 writable: false,
michael@0 275 enumerable: false,
michael@0 276 configurable: false
michael@0 277 };
michael@0 278
michael@0 279 expectDescriptor(pd, expected);
michael@0 280
michael@0 281 pd = Object.getOwnPropertyDescriptor(o, "global");
michael@0 282 expected =
michael@0 283 {
michael@0 284 value: false,
michael@0 285 writable: false,
michael@0 286 enumerable: false,
michael@0 287 configurable: false
michael@0 288 };
michael@0 289
michael@0 290 expectDescriptor(pd, expected);
michael@0 291
michael@0 292 pd = Object.getOwnPropertyDescriptor(o, "ignoreCase");
michael@0 293 expected =
michael@0 294 {
michael@0 295 value: true,
michael@0 296 writable: false,
michael@0 297 enumerable: false,
michael@0 298 configurable: false
michael@0 299 };
michael@0 300
michael@0 301 expectDescriptor(pd, expected);
michael@0 302
michael@0 303 pd = Object.getOwnPropertyDescriptor(o, "multiline");
michael@0 304 expected =
michael@0 305 {
michael@0 306 value: true,
michael@0 307 writable: false,
michael@0 308 enumerable: false,
michael@0 309 configurable: false
michael@0 310 };
michael@0 311
michael@0 312 expectDescriptor(pd, expected);
michael@0 313
michael@0 314 pd = Object.getOwnPropertyDescriptor(o, "lastIndex");
michael@0 315 expected =
michael@0 316 {
michael@0 317 value: 0,
michael@0 318 writable: true,
michael@0 319 enumerable: false,
michael@0 320 configurable: false
michael@0 321 };
michael@0 322
michael@0 323 expectDescriptor(pd, expected);
michael@0 324
michael@0 325 /******************************************************************************/
michael@0 326
michael@0 327 reportCompare(expect, actual, "Object.getOwnPropertyDescriptor");
michael@0 328
michael@0 329 printStatus("All tests passed");

mercurial