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