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 | function strictArgs() { |
michael@0 | 2 | return (function (a, b, c) {'use strict'; return arguments; })(1, 2); |
michael@0 | 3 | } |
michael@0 | 4 | |
michael@0 | 5 | function normalArgs() { |
michael@0 | 6 | return (function (a, b, c) { return arguments; })(1, 2); |
michael@0 | 7 | } |
michael@0 | 8 | |
michael@0 | 9 | function checkProperty(options, prop, shouldThrow) { |
michael@0 | 10 | var desc, orig; |
michael@0 | 11 | var obj = options.strict ? strictArgs() : normalArgs(); |
michael@0 | 12 | var objType = options.strict ? "strict arguments." : "normal arguments."; |
michael@0 | 13 | |
michael@0 | 14 | function check() { |
michael@0 | 15 | orig = Object.getOwnPropertyDescriptor(obj, prop); |
michael@0 | 16 | |
michael@0 | 17 | var threw = false; |
michael@0 | 18 | try { |
michael@0 | 19 | obj[prop] = obj[prop]; |
michael@0 | 20 | } |
michael@0 | 21 | catch (e) { |
michael@0 | 22 | threw = true; |
michael@0 | 23 | } |
michael@0 | 24 | assertEq(threw, shouldThrow, objType + prop + " threw"); |
michael@0 | 25 | |
michael@0 | 26 | if (orig === undefined) { |
michael@0 | 27 | // The property wasn't defined, so we can skip it. |
michael@0 | 28 | return; |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | desc = Object.getOwnPropertyDescriptor(obj, prop); |
michael@0 | 32 | if ("value" in orig) { |
michael@0 | 33 | assertEq(desc.value, orig.value, objType + prop + " value"); |
michael@0 | 34 | } else { |
michael@0 | 35 | assertEq(desc.get, orig.get, objType + prop + " get"); |
michael@0 | 36 | assertEq(desc.set, orig.set, objType + prop + " set"); |
michael@0 | 37 | } |
michael@0 | 38 | assertEq(desc.writable, orig.writable, objType + prop + " writable"); |
michael@0 | 39 | assertEq(desc.enumerable, orig.enumerable, objType + prop + " enumerable"); |
michael@0 | 40 | assertEq(desc.configurable, orig.configurable, objType + prop + " configurable"); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | check(); |
michael@0 | 44 | |
michael@0 | 45 | if (orig && orig.configurable) { |
michael@0 | 46 | if(options.refresh) { obj = options.strict ? strictArgs() : normalArgs(); } |
michael@0 | 47 | Object.defineProperty(obj, prop, {writable: false, enumerable: true}); |
michael@0 | 48 | check(); |
michael@0 | 49 | |
michael@0 | 50 | if(options.refresh) { obj = options.strict ? strictArgs() : normalArgs(); } |
michael@0 | 51 | Object.defineProperty(obj, prop, {writable: true, enumerable: false}); |
michael@0 | 52 | check(); |
michael@0 | 53 | |
michael@0 | 54 | if(options.refresh) { obj = options.strict ? strictArgs() : normalArgs(); } |
michael@0 | 55 | Object.defineProperty(obj, prop, {writable: false, configurable: false}); |
michael@0 | 56 | check(); |
michael@0 | 57 | } |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | checkProperty({strict: true, refresh: true}, 'callee', true); |
michael@0 | 61 | checkProperty({strict: true, refresh: false}, 'callee', true); |
michael@0 | 62 | checkProperty({strict: false, refresh: true}, 'callee', false); |
michael@0 | 63 | checkProperty({strict: false, refresh: false}, 'callee', false); |
michael@0 | 64 | |
michael@0 | 65 | checkProperty({strict: true, refresh: true}, 'length', false); |
michael@0 | 66 | checkProperty({strict: true, refresh: false}, 'length', false); |
michael@0 | 67 | checkProperty({strict: false, refresh: true}, 'length', false); |
michael@0 | 68 | checkProperty({strict: false, refresh: false}, 'length', false); |
michael@0 | 69 | |
michael@0 | 70 | for (var i = 0; i <= 5; i++) { |
michael@0 | 71 | checkProperty({strict: true, refresh: true}, "" + i, false); |
michael@0 | 72 | checkProperty({strict: true, refresh: false}, "" + i, false); |
michael@0 | 73 | checkProperty({strict: false, refresh: true}, "" + i, false); |
michael@0 | 74 | checkProperty({strict: false, refresh: false}, "" + i, false); |
michael@0 | 75 | } |