4 https://bugzilla.mozilla.org/show_bug.cgi?id=793969
8 <title>Test for Bug
793969</title>
9 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
13 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=793969">Mozilla Bug
793969</a>
15 <div id=
"content" style=
"display: none">
19 <script type=
"application/javascript">
21 /** Test for Bug
793969 **/
22 function checkThrows(f, desc, skipMessageCheck) {
25 ok(false,
"Should have thrown for " + desc);
27 ok(true,
"threw correctly");
28 if (!skipMessageCheck)
29 ok(/denied/.exec(e) ||
30 /can't redefine non-configurable property/.exec(e),
31 "Correctly threw a security exception: " + e);
35 // NB: These sets will be no-ops (throw in strict mode) because setting an inherited readonly value prop has those semantics.
36 checkThrows(function() {
"use strict"; location.valueOf = 'hah'; }, 'Shadow with string', /* skipMessageCheck = */ true);
37 checkThrows(function() {
"use strict"; location.valueOf = function() { return {a: 'hah'};} }, 'Shadow with function', /* skipMessageCheck = */ true);
38 checkThrows(function() { Object.defineProperty(location, 'valueOf', { value: function() { return 'hah'; } }); }, 'defineProperty with value');
39 checkThrows(function() { delete location.valueOf; Object.defineProperty(location, 'valueOf', { value: function() { return 'hah'; } }); }, 'delete + defineProperty with value');
40 checkThrows(function() { Object.defineProperty(location, 'valueOf', { get: function() { return 'hah'; } }); }, 'defineProperty with getter');
41 checkThrows(function() { delete location.valueOf; Object.defineProperty(location, 'valueOf', { get: function() { return 'hah'; } }); }, 'delete + defineProperty with getter');
43 Object.prototype.valueOf = function() { return 'hah'; };
44 is(({}).valueOf(), 'hah',
"Shadowing on Object.prototype works for vanilla objects");
45 is(location.valueOf(), location,
"Shadowing on Object.prototype and Location.prototype doesn't for location objects");
47 location[Symbol.toPrimitive] = function() { return 'hah'; }
48 is(location +
"", location.toString(),
"Should't be able to shadow with toPrimitive");