args-attributes.js (2817B)
1 function strictArgs() { 2 return (function (a, b, c) {'use strict'; return arguments; })(1, 2); 3 } 4 5 function normalArgs() { 6 return (function (a, b, c) { return arguments; })(1, 2); 7 } 8 9 function checkProperty(options, prop, shouldThrow) { 10 var desc, orig; 11 var obj = options.strict ? strictArgs() : normalArgs(); 12 var objType = options.strict ? "strict arguments." : "normal arguments."; 13 14 function check() { 15 orig = Object.getOwnPropertyDescriptor(obj, prop); 16 17 var threw = false; 18 try { 19 obj[prop] = obj[prop]; 20 } 21 catch (e) { 22 threw = true; 23 } 24 assertEq(threw, shouldThrow, objType + prop + " threw"); 25 26 if (orig === undefined) { 27 // The property wasn't defined, so we can skip it. 28 return; 29 } 30 31 desc = Object.getOwnPropertyDescriptor(obj, prop); 32 if ("value" in orig) { 33 assertEq(desc.value, orig.value, objType + prop + " value"); 34 } else { 35 assertEq(desc.get, orig.get, objType + prop + " get"); 36 assertEq(desc.set, orig.set, objType + prop + " set"); 37 } 38 assertEq(desc.writable, orig.writable, objType + prop + " writable"); 39 assertEq(desc.enumerable, orig.enumerable, objType + prop + " enumerable"); 40 assertEq(desc.configurable, orig.configurable, objType + prop + " configurable"); 41 } 42 43 check(); 44 45 if (orig && orig.configurable) { 46 if(options.refresh) { obj = options.strict ? strictArgs() : normalArgs(); } 47 Object.defineProperty(obj, prop, {writable: false, enumerable: true}); 48 check(); 49 50 if(options.refresh) { obj = options.strict ? strictArgs() : normalArgs(); } 51 Object.defineProperty(obj, prop, {writable: true, enumerable: false}); 52 check(); 53 54 if(options.refresh) { obj = options.strict ? strictArgs() : normalArgs(); } 55 Object.defineProperty(obj, prop, {writable: false, configurable: false}); 56 check(); 57 } 58 } 59 60 checkProperty({strict: true, refresh: true}, 'callee', true); 61 checkProperty({strict: true, refresh: false}, 'callee', true); 62 checkProperty({strict: false, refresh: true}, 'callee', false); 63 checkProperty({strict: false, refresh: false}, 'callee', false); 64 65 checkProperty({strict: true, refresh: true}, 'length', false); 66 checkProperty({strict: true, refresh: false}, 'length', false); 67 checkProperty({strict: false, refresh: true}, 'length', false); 68 checkProperty({strict: false, refresh: false}, 'length', false); 69 70 for (var i = 0; i <= 5; i++) { 71 checkProperty({strict: true, refresh: true}, "" + i, false); 72 checkProperty({strict: true, refresh: false}, "" + i, false); 73 checkProperty({strict: false, refresh: true}, "" + i, false); 74 checkProperty({strict: false, refresh: false}, "" + i, false); 75 }