js/src/tests/ecma_5/Function/function-caller.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Any copyright is dedicated to the Public Domain.
michael@0 3 * http://creativecommons.org/licenses/publicdomain/
michael@0 4 */
michael@0 5
michael@0 6 var gTestfile = 'function-caller.js';
michael@0 7 var BUGNUMBER = 514581;
michael@0 8 var summary = "Function.prototype.caller should throw a TypeError for " +
michael@0 9 "strict-mode functions";
michael@0 10
michael@0 11 print(BUGNUMBER + ": " + summary);
michael@0 12
michael@0 13 /**************
michael@0 14 * BEGIN TEST *
michael@0 15 **************/
michael@0 16
michael@0 17 // behavior
michael@0 18
michael@0 19 function expectTypeError(fun)
michael@0 20 {
michael@0 21 try
michael@0 22 {
michael@0 23 fun();
michael@0 24 throw new Error("didn't throw");
michael@0 25 }
michael@0 26 catch (e)
michael@0 27 {
michael@0 28 assertEq(e instanceof TypeError, true,
michael@0 29 "expected TypeError calling function" +
michael@0 30 ("name" in fun ? " " + fun.name : "") + ", instead got: " + e);
michael@0 31 }
michael@0 32 }
michael@0 33
michael@0 34 function bar() { "use strict"; }
michael@0 35 expectTypeError(function barCaller() { bar.caller; });
michael@0 36
michael@0 37 function baz() { "use strict"; return 17; }
michael@0 38 expectTypeError(function bazCaller() { baz.caller; });
michael@0 39
michael@0 40
michael@0 41 // accessor identity
michael@0 42
michael@0 43 function strictMode() { "use strict"; return 42; }
michael@0 44 var canonicalTTE = Object.getOwnPropertyDescriptor(strictMode, "caller").get;
michael@0 45
michael@0 46 var barCaller = Object.getOwnPropertyDescriptor(bar, "caller");
michael@0 47 assertEq("get" in barCaller, true);
michael@0 48 assertEq("set" in barCaller, true);
michael@0 49 assertEq(barCaller.get, canonicalTTE);
michael@0 50 assertEq(barCaller.set, canonicalTTE);
michael@0 51
michael@0 52 var barArguments = Object.getOwnPropertyDescriptor(bar, "arguments");
michael@0 53 assertEq("get" in barArguments, true);
michael@0 54 assertEq("set" in barArguments, true);
michael@0 55 assertEq(barArguments.get, canonicalTTE);
michael@0 56 assertEq(barArguments.set, canonicalTTE);
michael@0 57
michael@0 58 var bazCaller = Object.getOwnPropertyDescriptor(baz, "caller");
michael@0 59 assertEq("get" in bazCaller, true);
michael@0 60 assertEq("set" in bazCaller, true);
michael@0 61 assertEq(bazCaller.get, canonicalTTE);
michael@0 62 assertEq(bazCaller.set, canonicalTTE);
michael@0 63
michael@0 64 var bazArguments = Object.getOwnPropertyDescriptor(baz, "arguments");
michael@0 65 assertEq("get" in bazArguments, true);
michael@0 66 assertEq("set" in bazArguments, true);
michael@0 67 assertEq(bazArguments.get, canonicalTTE);
michael@0 68 assertEq(bazArguments.set, canonicalTTE);
michael@0 69
michael@0 70
michael@0 71 // [[ThrowTypeError]] characteristics
michael@0 72
michael@0 73 assertEq(Object.prototype.toString.call(canonicalTTE), "[object Function]");
michael@0 74 assertEq(Object.getPrototypeOf(canonicalTTE), Function.prototype);
michael@0 75 assertEq(canonicalTTE.length, 0);
michael@0 76 assertEq(Object.isExtensible(canonicalTTE), false);
michael@0 77 canonicalTTE.lumpy = 17;
michael@0 78 assertEq(canonicalTTE.hasOwnProperty("lumpy"), false);
michael@0 79 assertEq("lumpy" in canonicalTTE, false);
michael@0 80 expectTypeError(function setTTEProp() { "use strict"; canonicalTTE.x = 42; });
michael@0 81
michael@0 82 /******************************************************************************/
michael@0 83
michael@0 84 if (typeof reportCompare === "function")
michael@0 85 reportCompare(true, true);
michael@0 86
michael@0 87 print("All tests passed!");

mercurial