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 = '15.2.3.10-01.js'; |
michael@0 | 9 | //----------------------------------------------------------------------------- |
michael@0 | 10 | var BUGNUMBER = 492849; |
michael@0 | 11 | var summary = 'ES5: Implement Object.preventExtensions, Object.isExtensible'; |
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 | function trySetProperty(o, p, v, strict) |
michael@0 | 20 | { |
michael@0 | 21 | function strictSetProperty() |
michael@0 | 22 | { |
michael@0 | 23 | "use strict"; |
michael@0 | 24 | o[p] = v; |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | function setProperty() |
michael@0 | 28 | { |
michael@0 | 29 | o[p] = v; |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | assertEq(Object.prototype.hasOwnProperty.call(o, p), false); |
michael@0 | 33 | |
michael@0 | 34 | try |
michael@0 | 35 | { |
michael@0 | 36 | if (strict) |
michael@0 | 37 | strictSetProperty(); |
michael@0 | 38 | else |
michael@0 | 39 | setProperty(); |
michael@0 | 40 | if (o[p] === v) |
michael@0 | 41 | return "set"; |
michael@0 | 42 | if (p in o) |
michael@0 | 43 | return "set-converted"; |
michael@0 | 44 | return "swallowed"; |
michael@0 | 45 | } |
michael@0 | 46 | catch (e) |
michael@0 | 47 | { |
michael@0 | 48 | return "throw"; |
michael@0 | 49 | } |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | function tryDefineProperty(o, p, v) |
michael@0 | 53 | { |
michael@0 | 54 | assertEq(Object.prototype.hasOwnProperty.call(o, p), false); |
michael@0 | 55 | |
michael@0 | 56 | try |
michael@0 | 57 | { |
michael@0 | 58 | Object.defineProperty(o, p, { value: v }); |
michael@0 | 59 | if (o[p] === v) |
michael@0 | 60 | return "set"; |
michael@0 | 61 | if (p in o) |
michael@0 | 62 | return "set-converted"; |
michael@0 | 63 | return "swallowed"; |
michael@0 | 64 | } |
michael@0 | 65 | catch (e) |
michael@0 | 66 | { |
michael@0 | 67 | return "throw"; |
michael@0 | 68 | } |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | assertEq(typeof Object.preventExtensions, "function"); |
michael@0 | 72 | assertEq(Object.preventExtensions.length, 1); |
michael@0 | 73 | |
michael@0 | 74 | var slowArray = [1, 2, 3]; |
michael@0 | 75 | slowArray.slow = 5; |
michael@0 | 76 | var objs = |
michael@0 | 77 | [{}, { 1: 2 }, { a: 3 }, [], [1], [, 1], slowArray, function a(){}, /a/]; |
michael@0 | 78 | |
michael@0 | 79 | for (var i = 0, sz = objs.length; i < sz; i++) |
michael@0 | 80 | { |
michael@0 | 81 | var o = objs[i]; |
michael@0 | 82 | assertEq(Object.isExtensible(o), true, "object " + i + " not extensible?"); |
michael@0 | 83 | |
michael@0 | 84 | var o2 = Object.preventExtensions(o); |
michael@0 | 85 | assertEq(o, o2); |
michael@0 | 86 | |
michael@0 | 87 | assertEq(Object.isExtensible(o), false, "object " + i + " is extensible?"); |
michael@0 | 88 | |
michael@0 | 89 | assertEq(trySetProperty(o, "baz", 17, true), "throw", |
michael@0 | 90 | "unexpected behavior for strict-mode property-addition to " + |
michael@0 | 91 | "object " + i); |
michael@0 | 92 | assertEq(trySetProperty(o, "baz", 17, false), "swallowed", |
michael@0 | 93 | "unexpected behavior for property-addition to object " + i); |
michael@0 | 94 | |
michael@0 | 95 | assertEq(tryDefineProperty(o, "baz", 17), "throw", |
michael@0 | 96 | "unexpected behavior for new property definition on object " + i); |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | /******************************************************************************/ |
michael@0 | 100 | |
michael@0 | 101 | reportCompare(true, true); |
michael@0 | 102 | |
michael@0 | 103 | print("All tests passed!"); |