summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/ion/bug717466.js
blob: cd1b7b3e2c25bc3c4ced6d8ec370ea7516e29c6f (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
function Person(){}
function Ninja(){}
Ninja.prototype = new Person();
function House(){}

var empty = {};
var person = new Person();
var ninja = new Ninja();
var house = new House();
var string = new String();
var bindNinja = Ninja.bind({});

var array = {};
array.__proto__ = Array.prototype;
var array2 = {};
array2.__proto__ = array.prototype;

function test(v, v2) {
  return v instanceof v2;
}
function test2(v, v2) {
  return v instanceof v2;
}
function test3(v, v2) {
  return v instanceof v2;
}
function test4(v, v2) {
  return v instanceof v2;
}

// Test if specialized for object works
for (var i=0; i!=41; i++) {
  assertEq(test(person, Person), true);
  assertEq(test(empty, Person), false);
  assertEq(test(ninja, Person), true);
  assertEq(test(house, Person), false);
  assertEq(test(string, Person), false);
  assertEq(test(new bindNinja(), Person), true);
  assertEq(test(new Ninja(), bindNinja), true);
  assertEq(test(string, String), true);
  assertEq(test(array, Array), true);
  assertEq(test(empty, Object), true);
  
  // Test if bailout works
  assertEq(test(0.1, Object), false);
  
  // Should generate TypeError
  var err = false;
  try {
    test(0.1, 5);
  } catch (e) { err = true; }
  assertEq(err, true);
  
  // Should generate TypeError
  var err = false;
  try {
    test(empty, empty);
  } catch (e) { err = true; }
  assertEq(err, true);
  
  // Should generate TypeError
  var err = false;
  try {
    test(5.0, empty);
  } catch (e) { err = true; }
  assertEq(err, true);
}

// Test if specialized for non-object lhs
for (var i=0; i!=41; i++) {
  assertEq(test2(0.1, Object), false);
}

// Check if we don't regress on https://bugzilla.mozilla.org/show_bug.cgi?id=7635
function Foo() {};
theproto = {};
Foo.prototype = theproto;

for (var i=0; i!=41; i++) {
  assertEq(test3(theproto, Foo), false);
}