1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/xpconnect/tests/mochitest/test_bug793969.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,59 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=793969 1.8 +--> 1.9 +<head> 1.10 + <meta charset="utf-8"> 1.11 + <title>Test for Bug 793969</title> 1.12 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.14 +</head> 1.15 +<body> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=793969">Mozilla Bug 793969</a> 1.17 +<p id="display"></p> 1.18 +<div id="content" style="display: none"> 1.19 + 1.20 +</div> 1.21 +<pre id="test"> 1.22 +<script type="application/javascript"> 1.23 + 1.24 +/** Test for Bug 793969 **/ 1.25 +function checkThrows(f, desc, skipMessageCheck) { 1.26 + try { 1.27 + f(); 1.28 + ok(false, "Should have thrown for " + desc); 1.29 + } catch (e) { 1.30 + ok(true, "threw correctly"); 1.31 + if (!skipMessageCheck) 1.32 + ok(/denied/.exec(e), "Correctly threw a security exception: " + e); 1.33 + } 1.34 +} 1.35 + 1.36 +// NB: These sets will be no-ops (throw in strict mode) because setting an inherited readonly value prop has those semantics. 1.37 +checkThrows(function() { "use strict"; location.valueOf = 'hah'; }, 'Shadow with string', /* skipMessageCheck = */ true); 1.38 +checkThrows(function() { "use strict"; location.valueOf = function() { return {a: 'hah'};} }, 'Shadow with function', /* skipMessageCheck = */ true); 1.39 +checkThrows(function() { Object.defineProperty(location, 'valueOf', { value: function() { return 'hah'; } }); }, 'defineProperty with value'); 1.40 +checkThrows(function() { delete location.valueOf; Object.defineProperty(location, 'valueOf', { value: function() { return 'hah'; } }); }, 'delete + defineProperty with value'); 1.41 +checkThrows(function() { Object.defineProperty(location, 'valueOf', { getter: function() { return 'hah'; } }); }, 'defineProperty with getter'); 1.42 +checkThrows(function() { delete location.valueOf; Object.defineProperty(location, 'valueOf', { getter: function() { return 'hah'; } }); }, 'delete + defineProperty with getter'); 1.43 + 1.44 +Object.prototype.valueOf = function() { return 'hah'; }; 1.45 +is(({}).valueOf(), 'hah', "Shadowing on Object.prototype works for vanilla objects"); 1.46 +is(location.valueOf(), location, "Shadowing on Object.prototype and Location.prototype doesn't for location objects"); 1.47 + 1.48 +// Make sure that Location.prototype can't be mucked with. 1.49 +function checkProto() { 1.50 + "use strict" 1.51 + checkThrows(function() { Location.prototype.foo = 'hah'; }, 'adding new property to Location.prototype', /* skipMessageCheck = */ true); 1.52 + checkThrows(function() { Location.prototype.valueOf = 'hah'; }, 'defining valueOf on Location.prototype', /* skipMessageCheck = */ true); 1.53 + checkThrows(function() { delete Location.prototype.toString; }, 'deleting property on Location.prototype', /* skipMessageCheck = */ true); 1.54 + checkThrows(function() { Location.prototype.toString = 'hah'; }, 'setting property on Location.prototype', /* skipMessageCheck = */ true); 1.55 + checkThrows(function() { Object.defineProperty(Location.prototype, 'toString', {value: 'hah'}); }, 'defining property on Location.prototype', /* skipMessageCheck = */ true); 1.56 +}; 1.57 +checkProto(); 1.58 + 1.59 +</script> 1.60 +</pre> 1.61 +</body> 1.62 +</html>