test_defineProperty.html (3381B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=910220 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 910220</title> 9 <script 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=910220">Mozilla Bug 910220</a> 14 <p id="display"></p> 15 <div id="content" style="display: none"> 16 <form name="x"></form> 17 </div> 18 <pre id="test"> 19 </pre> 20 <script type="application/javascript"> 21 22 /** Test for Bug 910220 */ 23 24 function getX() { 25 return "x"; 26 } 27 28 function namedSetStrict(obj) { 29 "use strict"; 30 var threw; 31 try { 32 obj.x = 5; 33 threw = false; 34 } catch (e) { 35 threw = true; 36 } 37 ok(threw, 38 "Should throw in strict mode when setting named property on " + obj); 39 40 try { 41 obj[getX()] = 5; 42 threw = false; 43 } catch (e) { 44 threw = true; 45 } 46 ok(threw, 47 "Should throw in strict mode when setting named property via SETELEM on " + obj); 48 49 try { 50 Object.defineProperty(obj, "x", { value: 17 }); 51 threw = false; 52 } catch (e) { 53 threw = true; 54 } 55 ok(threw, 56 "Should throw in strict mode when defining named property on " + obj); 57 } 58 function namedSetNonStrict(obj) { 59 var threw; 60 try { 61 obj.x = 5; 62 threw = false; 63 } catch (e) { 64 threw = true; 65 } 66 ok(!threw, 67 "Should not throw in non-strict mode when setting named property on " + obj); 68 69 try { 70 obj[getX()] = 5; 71 threw = false; 72 } catch (e) { 73 threw = true; 74 } 75 ok(!threw, 76 "Should not throw in non-strict mode when setting named property via SETELEM on" + obj); 77 78 try { 79 Object.defineProperty(obj, "x", { value: 17 }); 80 threw = false; 81 } catch (e) { 82 threw = true; 83 } 84 ok(threw, 85 "Should throw in non-strict mode when defining named property on " + obj); 86 } 87 for (let obj of [ document, document.forms ]) { 88 namedSetStrict(obj); 89 namedSetNonStrict(obj); 90 } 91 92 function indexedSetStrict(obj) { 93 "use strict"; 94 var threw; 95 try { 96 obj[0] = 5; 97 threw = false; 98 } catch (e) { 99 threw = true; 100 } 101 ok(threw, 102 "Should throw in strict mode when setting indexed property on " + obj); 103 104 try { 105 obj[1000] = 5; 106 threw = false; 107 } catch (e) { 108 threw = true; 109 } 110 ok(threw, 111 "Should throw in strict mode when setting out of bounds indexed property on " + obj); 112 113 try { 114 Object.defineProperty(obj, "0", { value: 17 }); 115 threw = false; 116 } catch (e) { 117 threw = true; 118 } 119 ok(threw, 120 "Should throw in strict mode when defining indexed property on " + obj); 121 } 122 function indexedSetNonStrict(obj) { 123 var threw; 124 try { 125 obj[0] = 5; 126 threw = false; 127 } catch (e) { 128 threw = true; 129 } 130 ok(!threw, 131 "Should not throw in non-strict mode when setting indexed property on " + obj); 132 133 try { 134 obj[1000] = 5; 135 threw = false; 136 } catch (e) { 137 threw = true; 138 } 139 ok(!threw, 140 "Should not throw in non-strict mode when setting out of bounds indexed property on " + obj); 141 142 try { 143 Object.defineProperty(obj, "0", { value: 17 }); 144 threw = false; 145 } catch (e) { 146 threw = true; 147 } 148 ok(threw, 149 "Should throw in non-strict mode when defining indexed property on " + obj); 150 } 151 for (let obj of [ document.forms, document.childNodes ]) { 152 indexedSetStrict(obj); 153 indexedSetNonStrict(obj); 154 } 155 </script> 156 </body> 157 </html>