1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/bindings/test/test_defineProperty.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,157 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=910220 1.8 +--> 1.9 +<head> 1.10 + <meta charset="utf-8"> 1.11 + <title>Test for Bug 910220</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=910220">Mozilla Bug 910220</a> 1.17 +<p id="display"></p> 1.18 +<div id="content" style="display: none"> 1.19 +<form name="x"></form> 1.20 +</div> 1.21 +<pre id="test"> 1.22 +</pre> 1.23 +<script type="application/javascript"> 1.24 + 1.25 +/** Test for Bug 910220 **/ 1.26 + 1.27 +function getX() { 1.28 + return "x"; 1.29 +} 1.30 + 1.31 +function namedSetStrict(obj) { 1.32 + "use strict"; 1.33 + var threw; 1.34 + try { 1.35 + obj.x = 5; 1.36 + threw = false; 1.37 + } catch (e) { 1.38 + threw = true; 1.39 + } 1.40 + ok(threw, 1.41 + "Should throw in strict mode when setting named property on " + obj); 1.42 + 1.43 + try { 1.44 + obj[getX()] = 5; 1.45 + threw = false; 1.46 + } catch (e) { 1.47 + threw = true; 1.48 + } 1.49 + ok(threw, 1.50 + "Should throw in strict mode when setting named property via SETELEM on " + obj); 1.51 + 1.52 + try { 1.53 + Object.defineProperty(obj, "x", { value: 17 }); 1.54 + threw = false; 1.55 + } catch (e) { 1.56 + threw = true; 1.57 + } 1.58 + ok(threw, 1.59 + "Should throw in strict mode when defining named property on " + obj); 1.60 +} 1.61 +function namedSetNonStrict(obj) { 1.62 + var threw; 1.63 + try { 1.64 + obj.x = 5; 1.65 + threw = false; 1.66 + } catch (e) { 1.67 + threw = true; 1.68 + } 1.69 + ok(!threw, 1.70 + "Should not throw in non-strict mode when setting named property on " + obj); 1.71 + 1.72 + try { 1.73 + obj[getX()] = 5; 1.74 + threw = false; 1.75 + } catch (e) { 1.76 + threw = true; 1.77 + } 1.78 + ok(!threw, 1.79 + "Should not throw in non-strict mode when setting named property via SETELEM on" + obj); 1.80 + 1.81 + try { 1.82 + Object.defineProperty(obj, "x", { value: 17 }); 1.83 + threw = false; 1.84 + } catch (e) { 1.85 + threw = true; 1.86 + } 1.87 + ok(threw, 1.88 + "Should throw in non-strict mode when defining named property on " + obj); 1.89 +} 1.90 +for (var obj of [ document, document.forms ]) { 1.91 + namedSetStrict(obj); 1.92 + namedSetNonStrict(obj); 1.93 +} 1.94 + 1.95 +function indexedSetStrict(obj) { 1.96 + "use strict"; 1.97 + var threw; 1.98 + try { 1.99 + obj[0] = 5; 1.100 + threw = false; 1.101 + } catch (e) { 1.102 + threw = true; 1.103 + } 1.104 + ok(threw, 1.105 + "Should throw in strict mode when setting indexed property on " + obj); 1.106 + 1.107 + try { 1.108 + obj[1000] = 5; 1.109 + threw = false; 1.110 + } catch (e) { 1.111 + threw = true; 1.112 + } 1.113 + ok(threw, 1.114 + "Should throw in strict mode when setting out of bounds indexed property on " + obj); 1.115 + 1.116 + try { 1.117 + Object.defineProperty(obj, "0", { value: 17 }); 1.118 + threw = false; 1.119 + } catch (e) { 1.120 + threw = true; 1.121 + } 1.122 + ok(threw, 1.123 + "Should throw in strict mode when defining indexed property on " + obj); 1.124 +} 1.125 +function indexedSetNonStrict(obj) { 1.126 + var threw; 1.127 + try { 1.128 + obj[0] = 5; 1.129 + threw = false; 1.130 + } catch (e) { 1.131 + threw = true; 1.132 + } 1.133 + ok(!threw, 1.134 + "Should not throw in non-strict mode when setting indexed property on " + obj); 1.135 + 1.136 + try { 1.137 + obj[1000] = 5; 1.138 + threw = false; 1.139 + } catch (e) { 1.140 + threw = true; 1.141 + } 1.142 + ok(!threw, 1.143 + "Should not throw in non-strict mode when setting out of bounds indexed property on " + obj); 1.144 + 1.145 + try { 1.146 + Object.defineProperty(obj, "0", { value: 17 }); 1.147 + threw = false; 1.148 + } catch (e) { 1.149 + threw = true; 1.150 + } 1.151 + ok(threw, 1.152 + "Should throw in non-strict mode when defining indexed property on " + obj); 1.153 +} 1.154 +for (var obj of [ document.forms, document.childNodes ]) { 1.155 + indexedSetStrict(obj); 1.156 + indexedSetNonStrict(obj); 1.157 +} 1.158 +</script> 1.159 +</body> 1.160 +</html>