js/src/jit-test/tests/ion/evalCallingName.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 function a() {
michael@0 3 return "a";
michael@0 4 }
michael@0 5 function b() {
michael@0 6 return "b";
michael@0 7 }
michael@0 8 function c() {
michael@0 9 return "c";
michael@0 10 }
michael@0 11 var names = ["a","b","c"];
michael@0 12
michael@0 13 function foo(name) {
michael@0 14 return eval(name + "()");
michael@0 15 }
michael@0 16
michael@0 17 for (var i = 0; i < names.length; i++)
michael@0 18 assertEq(foo(names[i]), names[i]);
michael@0 19
michael@0 20 // Test bailout due to bad name passed to eval.
michael@0 21 try {
michael@0 22 foo("missing");
michael@0 23 } catch (e) {
michael@0 24 assertEq(/missing/.test(e), true);
michael@0 25 }
michael@0 26
michael@0 27 function bar(name) {
michael@0 28 return eval(name + "()");
michael@0 29 }
michael@0 30
michael@0 31 for (var i = 0; i < names.length; i++)
michael@0 32 assertEq(bar(names[i]), names[i]);
michael@0 33
michael@0 34 function recursion() {
michael@0 35 return bar({ valueOf: function() { return "gotcha"; }});
michael@0 36 }
michael@0 37
michael@0 38 function gotcha() {
michael@0 39 return "gotcha";
michael@0 40 }
michael@0 41
michael@0 42 // Test invalidation within call made after name lookup.
michael@0 43 assertEq(bar("recursion"), "gotcha");

mercurial