js/src/jit-test/tests/basic/functionnames.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 * Most of these test cases are adapted from:
michael@0 3 * http://johnjbarton.github.com/nonymous/index.html
michael@0 4 */
michael@0 5
michael@0 6 function assertName(fn, name) {
michael@0 7 assertEq(displayName(fn), name)
michael@0 8 }
michael@0 9
michael@0 10 /* simple names */
michael@0 11 var a = function b() {};
michael@0 12 function c() {};
michael@0 13 assertName(a, 'b');
michael@0 14 assertName(c, 'c');
michael@0 15
michael@0 16 var a = function(){},
michael@0 17 b = function(){};
michael@0 18 assertName(a, 'a');
michael@0 19 assertName(b, 'b');
michael@0 20
michael@0 21 /* nested names */
michael@0 22 var main = function() {
michael@0 23 function Foo(a) { assertName(a, 'main/foo<') }
michael@0 24 var foo = new Foo(function() {});
michael@0 25 };
michael@0 26 assertName(main, 'main')
michael@0 27 main();
michael@0 28
michael@0 29 /* duplicated */
michael@0 30 var Baz = Bar = function(){}
michael@0 31 assertName(Baz, 'Bar');
michael@0 32 assertName(Bar, 'Bar');
michael@0 33
michael@0 34 /* returned from an immediate function */
michael@0 35 var Foo = function (){
michael@0 36 assertName(arguments.callee, 'Foo<')
michael@0 37 return function(){};
michael@0 38 }();
michael@0 39 assertName(Foo, 'Foo</<');
michael@0 40
michael@0 41 /* various properties and such */
michael@0 42 var x = {fox: { bax: function(){} } };
michael@0 43 assertName(x.fox.bax, 'x.fox.bax');
michael@0 44 var foo = {foo: {foo: {}}};
michael@0 45 foo.foo.foo = function(){};
michael@0 46 assertName(foo.foo.foo, 'foo.foo.foo');
michael@0 47 var z = {
michael@0 48 foz: function() {
michael@0 49 var baz = function() {
michael@0 50 var y = {bay: function() {}};
michael@0 51 assertName(y.bay, 'z.foz/baz/y.bay');
michael@0 52 };
michael@0 53 assertName(baz, 'z.foz/baz');
michael@0 54 baz();
michael@0 55 }
michael@0 56 };
michael@0 57 assertName(z.foz, 'z.foz');
michael@0 58 z.foz();
michael@0 59
michael@0 60 var outer = function() {
michael@0 61 x.fox.bax.nx = function(){};
michael@0 62 var w = {fow: { baw: function(){} } };
michael@0 63 assertName(x.fox.bax.nx, 'outer/x.fox.bax.nx')
michael@0 64 assertName(w.fow.baw, 'outer/w.fow.baw');
michael@0 65 };
michael@0 66 assertName(outer, 'outer');
michael@0 67 outer();
michael@0 68 function Fuz(){};
michael@0 69 Fuz.prototype = {
michael@0 70 add: function() {}
michael@0 71 }
michael@0 72 assertName(Fuz.prototype.add, 'Fuz.prototype.add');
michael@0 73
michael@0 74 var x = 1;
michael@0 75 x = function(){};
michael@0 76 assertName(x, 'x');
michael@0 77
michael@0 78 var a = {b: {}};
michael@0 79 a.b.c = (function() {
michael@0 80 assertName(arguments.callee, 'a.b.c<')
michael@0 81 }());
michael@0 82
michael@0 83 a.b = function() {
michael@0 84 function foo(f) { assertName(f, 'a.b/<'); };
michael@0 85 return foo(function(){});
michael@0 86 }
michael@0 87 a.b();
michael@0 88
michael@0 89 var bar = 'bar';
michael@0 90 a.b[bar] = function(){};
michael@0 91 assertName(a.b.bar, 'a.b[bar]');
michael@0 92
michael@0 93 a.b = function() {
michael@0 94 assertName(arguments.callee, 'a.b<');
michael@0 95 return { a: function() {} }
michael@0 96 }();
michael@0 97 assertName(a.b.a, 'a.b</<.a');
michael@0 98
michael@0 99 a = {
michael@0 100 b: function(a) {
michael@0 101 if (a)
michael@0 102 return function() {};
michael@0 103 else
michael@0 104 return function() {};
michael@0 105 }
michael@0 106 };
michael@0 107 assertName(a.b, 'a.b');
michael@0 108 assertName(a.b(true), 'a.b/<')
michael@0 109 assertName(a.b(false), 'a.b/<')
michael@0 110
michael@0 111 function f(g) {
michael@0 112 assertName(g, 'x<');
michael@0 113 return g();
michael@0 114 }
michael@0 115 var x = f(function () { return function() {}; });
michael@0 116 assertName(x, 'x</<');
michael@0 117
michael@0 118 var a = {'b': function(){}};
michael@0 119 assertName(a.b, 'a.b');
michael@0 120
michael@0 121 function g(f) {
michael@0 122 assertName(f, '');
michael@0 123 }
michael@0 124 label: g(function () {});
michael@0 125
michael@0 126 var z = [function() {}];
michael@0 127 assertName(z[0], 'z<');
michael@0 128
michael@0 129 /* fuzz bug from 785089 */
michael@0 130 odeURIL:(function(){})
michael@0 131
michael@0 132 a = { 1: function () {} };
michael@0 133 assertName(a[1], 'a[1]');
michael@0 134
michael@0 135 a = {
michael@0 136 "embedded spaces": function(){},
michael@0 137 "dots.look.like.property.references": function(){},
michael@0 138 "\"\'quotes\'\"": function(){},
michael@0 139 "!@#$%": function(){}
michael@0 140 };
michael@0 141 assertName(a["embedded spaces"], 'a["embedded spaces"]');
michael@0 142 assertName(a["dots.look.like.property.references"], 'a["dots.look.like.property.references"]');
michael@0 143 assertName(a["\"\'quotes\'\""], 'a["\\\"\'quotes\'\\\""]');
michael@0 144 assertName(a["!@#$%"], 'a["!@#$%"]');
michael@0 145
michael@0 146 a.b = {};
michael@0 147 a.b.c = {};
michael@0 148 a.b["c"]["d e"] = { f: { 1: { "g": { "h i": function() {} } } } };
michael@0 149 assertName(a.b.c["d e"].f[1].g["h i"], 'a.b.c["d e"].f[1].g["h i"]');
michael@0 150
michael@0 151 this.m = function () {};
michael@0 152 assertName(m, "this.m");
michael@0 153
michael@0 154 function N() {
michael@0 155 this.o = function () {}
michael@0 156 }
michael@0 157 let n = new N()
michael@0 158 assertName(n.o, "N/this.o");

mercurial