author | Bobby Holley <bobbyholley@gmail.com> |
Mon, 05 Nov 2012 17:10:34 -0800 | |
changeset 112367 | 5165ee49c7dbc6aa9740c9991496955b98db59a3 |
parent 112366 | b5d3c03ee2b8a364376b66bcb65c11746af7217a |
child 112368 | 57d9fa15f3e1891dad77036ea8fa3768deb4c4a2 |
push id | 23812 |
push user | emorley@mozilla.com |
push date | Tue, 06 Nov 2012 14:01:34 +0000 |
treeherder | mozilla-central@f4aeed115e54 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | mrbkap |
bugs | 793969 |
milestone | 19.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
js/xpconnect/tests/mochitest/Makefile.in | file | annotate | diff | comparison | revisions | |
js/xpconnect/tests/mochitest/test_bug793969.html | file | annotate | diff | comparison | revisions |
--- a/js/xpconnect/tests/mochitest/Makefile.in +++ b/js/xpconnect/tests/mochitest/Makefile.in @@ -75,16 +75,17 @@ MOCHITEST_FILES = chrome_wrappers_helper test_bug745483.html \ file_bug760131.html \ test_bug764389.html \ test_bug772288.html \ test_bug781476.html \ file_bug781476.html \ test_bug785096.html \ test_bug789713.html \ + test_bug793969.html \ file_bug795275.html \ file_bug795275.xml \ file_bug799348.html \ $(NULL) ifneq ($(OS_TARGET),Android) ifndef MOZ_PLATFORM_MAEMO MOCHITEST_FILES += test_bug564330.html \
new file mode 100644 --- /dev/null +++ b/js/xpconnect/tests/mochitest/test_bug793969.html @@ -0,0 +1,58 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=793969 +--> +<head> + <meta charset="utf-8"> + <title>Test for Bug 793969</title> + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=793969">Mozilla Bug 793969</a> +<p id="display"></p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +<script type="application/javascript"> + +/** Test for Bug 793969 **/ +function checkThrows(f, desc, skipMessageCheck) { + try { + f(); + ok(false, "Should have thrown for " + desc); + } catch (e) { + ok(true, "threw correctly"); + if (!skipMessageCheck) + ok(/denied/.exec(e), "Correctly threw a security exception: " + e); + } +} + +checkThrows(function() { location.valueOf = 'hah'; }, 'Shadow with string'); +checkThrows(function() { location.valueOf = function() { return {a: 'hah'};} }, 'Shadow with function'); +checkThrows(function() { Object.defineProperty(location, 'valueOf', { value: function() { return 'hah'; } }); }, 'defineProperty with value'); +checkThrows(function() { delete location.valueOf; Object.defineProperty(location, 'valueOf', { value: function() { return 'hah'; } }); }, 'delete + defineProperty with value'); +checkThrows(function() { Object.defineProperty(location, 'valueOf', { getter: function() { return 'hah'; } }); }, 'defineProperty with getter'); +checkThrows(function() { delete location.valueOf; Object.defineProperty(location, 'valueOf', { getter: function() { return 'hah'; } }); }, 'delete + defineProperty with getter'); + +Object.prototype.valueOf = function() { return 'hah'; }; +is(({}).valueOf(), 'hah', "Shadowing on Object.prototype works for vanilla objects"); +is(location.valueOf(), location, "Shadowing on Object.prototype and Location.prototype doesn't for location objects"); + +// Make sure that Location.prototype can't be mucked with. +function checkProto() { + "use strict" + checkThrows(function() { Location.prototype.foo = 'hah'; }, 'adding new property to Location.prototype', /* skipMessageCheck = */ true); + checkThrows(function() { Location.prototype.valueOf = 'hah'; }, 'defining valueOf on Location.prototype', /* skipMessageCheck = */ true); + checkThrows(function() { delete Location.prototype.toString; }, 'deleting property on Location.prototype', /* skipMessageCheck = */ true); + checkThrows(function() { Location.prototype.toString = 'hah'; }, 'setting property on Location.prototype', /* skipMessageCheck = */ true); + checkThrows(function() { Object.defineProperty(Location.prototype, 'toString', {value: 'hah'}); }, 'defining property on Location.prototype', /* skipMessageCheck = */ true); +}; +checkProto(); + +</script> +</pre> +</body> +</html>