blob: e293a290d91b24d53b8dea692886a1488a226af8 [file] [log] [blame]
sbarati@apple.com848cbbb2016-06-30 22:06:44 +00001function assert(b) {
2 if (!b)
3 throw new Error("Bad assertion")
4}
5
6function test(f, n = 1000) {
7 for (let i = 0; i < n; ++i)
8 f();
9}
10
11let o1 = {
12 get foo() {
13 "use strict";
14 return this;
15 }
16};
17
18let o2 = {
19 __proto__: o1,
20 a() {
21 return super.foo;
22 },
23
24 aa() {
25 let arr = () => super.foo;
26 return arr();
27 },
28
29 b() {
30 "use strict";
31 return super.foo;
32 },
33
34 bb() {
35 "use strict";
36 let arr = () => super.foo;
37 return arr();
38 }
39};
40
41var A = o2.a;
42var AA = o2.aa;
43var B = o2.b;
44var BB = o2.b;
45
46let globalObj = this;
47
48test(function() {
49 let num = o2.a.call(25);
50 assert(typeof num === "object");
51 assert(num instanceof Number);
52
53 let str = o2.a.call("foo bar");
54 assert(typeof str === "object");
55 assert(str instanceof String);
56 assert(str == "foo bar");
57
58 let o = {};
59 assert(o2.a.call(o) === o);
60
61 assert(A() === globalObj);
62});
63
64test(function() {
65 let num = o2.aa.call(25);
66 assert(typeof num === "object");
67 assert(num instanceof Number);
68
69 let str = o2.aa.call("foo bar");
70 assert(typeof str === "object");
71 assert(str instanceof String);
72 assert(str == "foo bar");
73
74 let o = {};
75 assert(o2.aa.call(o) === o);
76
77 assert(AA() === globalObj);
78});
79
80test(function() {
81 let num = o2.b.call(25);
82 assert(typeof num === "number");
83 assert(num === 25);
84
85 let str = o2.b.call("foo bar");
86 assert(typeof str === "string");
87 assert(str === "foo bar");
88
89 let o = {};
90 assert(o2.b.call(o) === o);
91
92 assert(B() === undefined);
93});
94
95test(function() {
96 let num = o2.bb.call(25);
97 assert(typeof num === "number");
98 assert(num === 25);
99
100 let str = o2.bb.call("foo bar");
101 assert(typeof str === "string");
102 assert(str === "foo bar");
103
104 let o = {};
105 assert(o2.bb.call(o) === o);
106
107 assert(BB() === undefined);
108});