1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit-test/tests/arguments/args-attributes.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,75 @@ 1.4 +function strictArgs() { 1.5 + return (function (a, b, c) {'use strict'; return arguments; })(1, 2); 1.6 +} 1.7 + 1.8 +function normalArgs() { 1.9 + return (function (a, b, c) { return arguments; })(1, 2); 1.10 +} 1.11 + 1.12 +function checkProperty(options, prop, shouldThrow) { 1.13 + var desc, orig; 1.14 + var obj = options.strict ? strictArgs() : normalArgs(); 1.15 + var objType = options.strict ? "strict arguments." : "normal arguments."; 1.16 + 1.17 + function check() { 1.18 + orig = Object.getOwnPropertyDescriptor(obj, prop); 1.19 + 1.20 + var threw = false; 1.21 + try { 1.22 + obj[prop] = obj[prop]; 1.23 + } 1.24 + catch (e) { 1.25 + threw = true; 1.26 + } 1.27 + assertEq(threw, shouldThrow, objType + prop + " threw"); 1.28 + 1.29 + if (orig === undefined) { 1.30 + // The property wasn't defined, so we can skip it. 1.31 + return; 1.32 + } 1.33 + 1.34 + desc = Object.getOwnPropertyDescriptor(obj, prop); 1.35 + if ("value" in orig) { 1.36 + assertEq(desc.value, orig.value, objType + prop + " value"); 1.37 + } else { 1.38 + assertEq(desc.get, orig.get, objType + prop + " get"); 1.39 + assertEq(desc.set, orig.set, objType + prop + " set"); 1.40 + } 1.41 + assertEq(desc.writable, orig.writable, objType + prop + " writable"); 1.42 + assertEq(desc.enumerable, orig.enumerable, objType + prop + " enumerable"); 1.43 + assertEq(desc.configurable, orig.configurable, objType + prop + " configurable"); 1.44 + } 1.45 + 1.46 + check(); 1.47 + 1.48 + if (orig && orig.configurable) { 1.49 + if(options.refresh) { obj = options.strict ? strictArgs() : normalArgs(); } 1.50 + Object.defineProperty(obj, prop, {writable: false, enumerable: true}); 1.51 + check(); 1.52 + 1.53 + if(options.refresh) { obj = options.strict ? strictArgs() : normalArgs(); } 1.54 + Object.defineProperty(obj, prop, {writable: true, enumerable: false}); 1.55 + check(); 1.56 + 1.57 + if(options.refresh) { obj = options.strict ? strictArgs() : normalArgs(); } 1.58 + Object.defineProperty(obj, prop, {writable: false, configurable: false}); 1.59 + check(); 1.60 + } 1.61 +} 1.62 + 1.63 +checkProperty({strict: true, refresh: true}, 'callee', true); 1.64 +checkProperty({strict: true, refresh: false}, 'callee', true); 1.65 +checkProperty({strict: false, refresh: true}, 'callee', false); 1.66 +checkProperty({strict: false, refresh: false}, 'callee', false); 1.67 + 1.68 +checkProperty({strict: true, refresh: true}, 'length', false); 1.69 +checkProperty({strict: true, refresh: false}, 'length', false); 1.70 +checkProperty({strict: false, refresh: true}, 'length', false); 1.71 +checkProperty({strict: false, refresh: false}, 'length', false); 1.72 + 1.73 +for (var i = 0; i <= 5; i++) { 1.74 + checkProperty({strict: true, refresh: true}, "" + i, false); 1.75 + checkProperty({strict: true, refresh: false}, "" + i, false); 1.76 + checkProperty({strict: false, refresh: true}, "" + i, false); 1.77 + checkProperty({strict: false, refresh: false}, "" + i, false); 1.78 +}