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 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=793969 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <meta charset="utf-8"> |
michael@0 | 8 | <title>Test for Bug 793969</title> |
michael@0 | 9 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 11 | </head> |
michael@0 | 12 | <body> |
michael@0 | 13 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=793969">Mozilla Bug 793969</a> |
michael@0 | 14 | <p id="display"></p> |
michael@0 | 15 | <div id="content" style="display: none"> |
michael@0 | 16 | |
michael@0 | 17 | </div> |
michael@0 | 18 | <pre id="test"> |
michael@0 | 19 | <script type="application/javascript"> |
michael@0 | 20 | |
michael@0 | 21 | /** Test for Bug 793969 **/ |
michael@0 | 22 | function checkThrows(f, desc, skipMessageCheck) { |
michael@0 | 23 | try { |
michael@0 | 24 | f(); |
michael@0 | 25 | ok(false, "Should have thrown for " + desc); |
michael@0 | 26 | } catch (e) { |
michael@0 | 27 | ok(true, "threw correctly"); |
michael@0 | 28 | if (!skipMessageCheck) |
michael@0 | 29 | ok(/denied/.exec(e), "Correctly threw a security exception: " + e); |
michael@0 | 30 | } |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | // NB: These sets will be no-ops (throw in strict mode) because setting an inherited readonly value prop has those semantics. |
michael@0 | 34 | checkThrows(function() { "use strict"; location.valueOf = 'hah'; }, 'Shadow with string', /* skipMessageCheck = */ true); |
michael@0 | 35 | checkThrows(function() { "use strict"; location.valueOf = function() { return {a: 'hah'};} }, 'Shadow with function', /* skipMessageCheck = */ true); |
michael@0 | 36 | checkThrows(function() { Object.defineProperty(location, 'valueOf', { value: function() { return 'hah'; } }); }, 'defineProperty with value'); |
michael@0 | 37 | checkThrows(function() { delete location.valueOf; Object.defineProperty(location, 'valueOf', { value: function() { return 'hah'; } }); }, 'delete + defineProperty with value'); |
michael@0 | 38 | checkThrows(function() { Object.defineProperty(location, 'valueOf', { getter: function() { return 'hah'; } }); }, 'defineProperty with getter'); |
michael@0 | 39 | checkThrows(function() { delete location.valueOf; Object.defineProperty(location, 'valueOf', { getter: function() { return 'hah'; } }); }, 'delete + defineProperty with getter'); |
michael@0 | 40 | |
michael@0 | 41 | Object.prototype.valueOf = function() { return 'hah'; }; |
michael@0 | 42 | is(({}).valueOf(), 'hah', "Shadowing on Object.prototype works for vanilla objects"); |
michael@0 | 43 | is(location.valueOf(), location, "Shadowing on Object.prototype and Location.prototype doesn't for location objects"); |
michael@0 | 44 | |
michael@0 | 45 | // Make sure that Location.prototype can't be mucked with. |
michael@0 | 46 | function checkProto() { |
michael@0 | 47 | "use strict" |
michael@0 | 48 | checkThrows(function() { Location.prototype.foo = 'hah'; }, 'adding new property to Location.prototype', /* skipMessageCheck = */ true); |
michael@0 | 49 | checkThrows(function() { Location.prototype.valueOf = 'hah'; }, 'defining valueOf on Location.prototype', /* skipMessageCheck = */ true); |
michael@0 | 50 | checkThrows(function() { delete Location.prototype.toString; }, 'deleting property on Location.prototype', /* skipMessageCheck = */ true); |
michael@0 | 51 | checkThrows(function() { Location.prototype.toString = 'hah'; }, 'setting property on Location.prototype', /* skipMessageCheck = */ true); |
michael@0 | 52 | checkThrows(function() { Object.defineProperty(Location.prototype, 'toString', {value: 'hah'}); }, 'defining property on Location.prototype', /* skipMessageCheck = */ true); |
michael@0 | 53 | }; |
michael@0 | 54 | checkProto(); |
michael@0 | 55 | |
michael@0 | 56 | </script> |
michael@0 | 57 | </pre> |
michael@0 | 58 | </body> |
michael@0 | 59 | </html> |