1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_5/Function/arguments-caller-callee.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,66 @@ 1.4 +/* 1.5 + * Any copyright is dedicated to the Public Domain. 1.6 + * http://creativecommons.org/licenses/publicdomain/ 1.7 + */ 1.8 + 1.9 +var gTestfile = 'arguments-caller-callee.js'; 1.10 +var BUGNUMBER = 514563; 1.11 +var summary = "arguments.caller and arguments.callee are poison pills in ES5"; 1.12 + 1.13 +print(BUGNUMBER + ": " + summary); 1.14 + 1.15 +/************** 1.16 + * BEGIN TEST * 1.17 + **************/ 1.18 + 1.19 +// behavior 1.20 + 1.21 +function expectTypeError(fun) 1.22 +{ 1.23 + try 1.24 + { 1.25 + fun(); 1.26 + throw new Error("didn't throw"); 1.27 + } 1.28 + catch (e) 1.29 + { 1.30 + assertEq(e instanceof TypeError, true, 1.31 + "expected TypeError calling function" + 1.32 + ("name" in fun ? " " + fun.name : "") + ", instead got: " + e); 1.33 + } 1.34 +} 1.35 + 1.36 +function bar() { "use strict"; return arguments; } 1.37 +expectTypeError(function barCaller() { bar().caller; }); 1.38 +expectTypeError(function barCallee() { bar().callee; }); 1.39 + 1.40 +function baz() { return arguments; } 1.41 +assertEq(baz().callee, baz); 1.42 + 1.43 + 1.44 +// accessor identity 1.45 + 1.46 +function strictMode() { "use strict"; return arguments; } 1.47 +var canonicalTTE = Object.getOwnPropertyDescriptor(strictMode(), "caller").get; 1.48 + 1.49 +var args = strictMode(); 1.50 + 1.51 +var argsCaller = Object.getOwnPropertyDescriptor(args, "caller"); 1.52 +assertEq("get" in argsCaller, true); 1.53 +assertEq("set" in argsCaller, true); 1.54 +assertEq(argsCaller.get, canonicalTTE); 1.55 +assertEq(argsCaller.set, canonicalTTE); 1.56 + 1.57 +var argsCallee = Object.getOwnPropertyDescriptor(args, "callee"); 1.58 +assertEq("get" in argsCallee, true); 1.59 +assertEq("set" in argsCallee, true); 1.60 +assertEq(argsCallee.get, canonicalTTE); 1.61 +assertEq(argsCallee.set, canonicalTTE); 1.62 + 1.63 + 1.64 +/******************************************************************************/ 1.65 + 1.66 +if (typeof reportCompare === "function") 1.67 + reportCompare(true, true); 1.68 + 1.69 +print("All tests passed!");