test_window_define_nonconfigurable.html (5193B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1107443 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 1107443</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 11 <script type="application/javascript"> 12 13 /** 14 * Test for Bug 1107443, modified when it was backed out in bug 1329323. 15 * This is now testing the _current_ behavior, not the desired one; expect 16 * failures in this test and needing to update it when bug 1329324 is 17 * fixed. 18 */ 19 var retval = Object.defineProperty(window, "nosuchprop", 20 { value: 5, configurable: false }); 21 todo_is(retval, null, 22 "Should return null when 'failing' to define non-configurable property via Object.defineProperty.") 23 24 var desc = Object.getOwnPropertyDescriptor(window, "nosuchprop"); 25 is(typeof(desc), "object", "Should have a property 'nosuchprop' now"); 26 todo_is(desc.configurable, true, 27 "Property 'nosuchprop' should be configurable"); 28 is(desc.writable, false, "Property 'nosuchprop' should be readonly"); 29 is(desc.value, 5, "Property 'nosuchprop' should have the right value"); 30 31 retval = Object.defineProperties(window, { 32 "firstProp": { value: 1 }, 33 "secondProp": { value: 2, configurable: false }, 34 "thirdProp": { value: 3 }, 35 }); 36 todo_is(retval, null, 37 "Should return null when 'failing' to define non-configurable property via Object.defineProperties.") 38 // The properties should all be defined. 39 for (var [prop, val] of [["firstProp", 1], ["secondProp", 2], ["thirdProp", 3]]) { 40 desc = Object.getOwnPropertyDescriptor(window, prop); 41 is(typeof(desc), "object", `Should have a property '${prop}' now`); 42 todo_is(desc.configurable, true, 43 `Property '${prop}' should be configurable`); 44 is(desc.writable, false, `Property '${prop}' should be readonly`); 45 is(desc.value, val, `Property '${prop}' should have the right value`); 46 } 47 48 retval = Object.defineProperty(window, "nosuchprop2", { value: 6 }); 49 is(retval, window, 50 "Should return object when succesfully defining 'nosuchprop2'"); 51 desc = Object.getOwnPropertyDescriptor(window, "nosuchprop2"); 52 is(typeof(desc), "object", "Should have a property 'nosuchprop2' now"); 53 todo_is(desc.configurable, true, 54 "Property 'nosuchprop2' should be configurable"); 55 is(desc.writable, false, "Property 'nosuchprop2' should be readonly"); 56 is(desc.value, 6, "Property 'nosuchprop2' should have the right value"); 57 58 retval = Object.defineProperty(window, "nosuchprop3", 59 { value: 7, configurable: true }); 60 is(retval, window, 61 "Should return object when succesfully defining 'nosuchprop3'"); 62 desc = Object.getOwnPropertyDescriptor(window, "nosuchprop3"); 63 is(typeof(desc), "object", "Should have a property 'nosuchprop3' now"); 64 is(desc.configurable, true, 65 "Property 'nosuchprop3' should be configurable"); 66 is(desc.writable, false, "Property 'nosuchprop3' should be readonly"); 67 is(desc.value, 7, "Property 'nosuchprop3' should have the right value"); 68 69 retval = Reflect.defineProperty(window, "nosuchprop4", 70 { value: 8, configurable: false }); 71 todo_is(retval, false, 72 "Should not be able to Reflect.defineProperty if non-configurable"); 73 desc = Object.getOwnPropertyDescriptor(window, "nosuchprop4"); 74 is(typeof(desc), "object", "Should have a property 'nosuchprop4' now"); 75 todo_is(desc.configurable, true, 76 "Property 'nosuchprop4' should be configurable"); 77 is(desc.writable, false, "Property 'nosuchprop4' should be readonly"); 78 is(desc.value, 8, "Property 'nosuchprop4' should have the right value"); 79 80 retval = Reflect.defineProperty(window, "nosuchprop5", 81 { value: 9 }); 82 is(retval, true, 83 "Should be able to Reflect.defineProperty with default configurability"); 84 desc = Object.getOwnPropertyDescriptor(window, "nosuchprop5"); 85 is(typeof(desc), "object", "Should have a property 'nosuchprop5' now"); 86 todo_is(desc.configurable, true, 87 "Property 'nosuchprop5' should be configurable"); 88 is(desc.writable, false, "Property 'nosuchprop5' should be readonly"); 89 is(desc.value, 9, "Property 'nosuchprop5' should have the right value"); 90 91 retval = Reflect.defineProperty(window, "nosuchprop6", 92 { value: 10, configurable: true }); 93 is(retval, true, 94 "Should be able to Reflect.defineProperty if configurable"); 95 desc = Object.getOwnPropertyDescriptor(window, "nosuchprop6"); 96 is(typeof(desc), "object", "Should have a property 'nosuchprop6' now"); 97 is(desc.configurable, true, "Property 'nosuchprop6' should be configurable"); 98 is(desc.writable, false, "Property 'nosuchprop6' should be readonly"); 99 is(desc.value, 10, "Property 'nosuchprop6' should have the right value"); 100 </script> 101 </head> 102 <body> 103 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1107443">Mozilla Bug 1107443</a> 104 <p id="display"></p> 105 <div id="content" style="display: none"> 106 107 </div> 108 <pre id="test"> 109 </pre> 110 </body> 111 </html>