summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/ion/bug670484.js
blob: 81422f02f75a43779dd021ffdf56fe0619a2511d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Call a function with no arguments.
function a_g() {
	return 5;
}

function a_f(g) {
	return g();
}

a_g();
assertEq(a_f(a_g), 5);

///////////////////////////////////////////////////////////////////////////////
// Call a function with one argument.
function b_g(a) {
	return a;
}

function b_f(h,b) {
	return h(5);
}
b_g(5);
assertEq(b_f(b_g,4), 5);

///////////////////////////////////////////////////////////////////////////////
// Try to confuse the register allocator.
function c_g(a) {
	return a;
}
function c_f(h,b) {
	var x = h(5);
	var y = x + 1;
	var z = h(h(y + x + 2));
	var k = 2 + z + 3;
	return h(h(h(k)));
}
c_g(2); // prime g().
assertEq(c_f(c_g,7), 18)

///////////////////////////////////////////////////////////////////////////////
// Fail during unboxing, get kicked to interpreter.
// Interpreter throws an exception; handle it.

function d_f(a) {
	return a(); // Call a known non-object. This fails in unboxing.
}
var d_x = 0;
try {
	d_f(1); // Don't assert.
} catch(e) {
	d_x = 1;
}
assertEq(d_x, 1);

///////////////////////////////////////////////////////////////////////////////
// Try passing an uncompiled function.

function e_uncompiled(a,b,c) {
	return eval("b");
}
function e_f(h) {
	return h(0,h(2,4,6),1);
}
assertEq(e_f(e_uncompiled),4);

///////////////////////////////////////////////////////////////////////////////
// Try passing a native function.

function f_app(f,n) {
	return f(n);
}
assertEq(f_app(Math.sqrt, 16), 4);

///////////////////////////////////////////////////////////////////////////////
// Handle the case where too few arguments are passed.
function g_g(a,b,c,d,e) {
	return e;
}

function g_f(g) {
	return g(2);
}

g_g();
assertEq(g_f(g_g), undefined);

///////////////////////////////////////////////////////////////////////////////
// Don't assert when given a non-function object.
function h_f(a) {
	return a();
}

var x = new Object();
var h_ret = 0;
try {
	h_f(x); // don't assert.
} catch (e) {
	h_ret = 1;
}
assertEq(h_ret, 1);