• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2010 the V8 project authors. All rights reserved.
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6//     * Redistributions of source code must retain the above copyright
7//       notice, this list of conditions and the following disclaimer.
8//     * Redistributions in binary form must reproduce the above
9//       copyright notice, this list of conditions and the following
10//       disclaimer in the documentation and/or other materials provided
11//       with the distribution.
12//     * Neither the name of Google Inc. nor the names of its
13//       contributors may be used to endorse or promote products derived
14//       from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28var except = "exception";
29
30var correct_answer_index = 0;
31var correct_answers = [
32 false,  false,   true,   true,  false,  false,   true,   true,
33  true,  false,  false,   true,   true,  false,  false,   true,
34 false,   true,   true,  false,  false,   true,   true,  false,
35  true,   true,  false,  false,   true,   true,  false,  false,
36except, except,   true,   true, except, except,   true,   true,
37except, except,  false,   true, except, except,  false,   true,
38except, except,   true,  false, except, except,   true,  false,
39except, except,  false,  false, except, except,  false,  false,
40 false,  false, except, except,  false,  false, except, except,
41  true,  false, except, except,   true,  false, except, except,
42 false,   true, except, except,  false,   true, except, except,
43  true,   true, except, except,   true,   true, except, except,
44except, except, except, except, except, except, except, except,
45except, except, except, except, except, except, except, except,
46except, except, except, except, except, except, except, except,
47except, except, except, except, except, except, except, except,
48 false,  false,   true,   true,  false,  false,   true,   true,
49  true,  false,  false,   true,  false,  false,   true,   true,
50 false,   true,   true,  false,  false,   true,   true,  false,
51  true,   true,  false,  false,  false,   true,   true,  false,
52except, except,   true,   true, except, except,   true,   true,
53except, except,  false,   true, except, except,   true,   true,
54except, except,   true,  false, except, except,   true,  false,
55except, except,  false,  false, except, except,   true,  false,
56 false,  false, except, except,  false,  false, except, except,
57  true,  false, except, except,   true,  false, except, except,
58 false,   true, except, except,  false,   true, except, except,
59  true,   true, except, except,   true,   true, except, except,
60except, except, except, except, except, except, except, except,
61except, except, except, except, except, except, except, except,
62except, except, except, except, except, except, except, except,
63except, except, except, except, except, except, except, except,
64 false,  false,   true,   true,  false,   true,   true,  false,
65  true,  false,  false,   true,   true,   true,  false,  false,
66 false,   true,   true,  false,  false,   true,   true,  false,
67  true,   true,  false,  false,   true,   true,  false,  false,
68except, except,   true,   true, except, except,   true,   true,
69except, except,  false,   true, except, except,  false,   true,
70except, except,   true,  false, except, except,   true,  false,
71except, except,  false,  false, except, except,  false,  false,
72 false,  false, except, except,  false,   true, except, except,
73  true,  false, except, except,   true,   true, except, except,
74 false,   true, except, except,  false,   true, except, except,
75  true,   true, except, except,   true,   true, except, except,
76except, except, except, except, except, except, except, except,
77except, except, except, except, except, except, except, except,
78except, except, except, except, except, except, except, except,
79except, except, except, except, except, except, except, except,
80 false,  false,   true,   true,  false,   true,   true,  false,
81  true,  false,  false,   true,  false,   true,   true,  false,
82 false,   true,   true,  false,  false,   true,   true,  false,
83  true,   true,  false,  false,  false,   true,   true,  false,
84except, except,   true,   true, except, except,   true,   true,
85except, except,  false,   true, except, except,   true,   true,
86except, except,   true,  false, except, except,   true,  false,
87except, except,  false,  false, except, except,   true,  false,
88 false,  false, except, except,  false,   true, except, except,
89  true,  false, except, except,   true,   true, except, except,
90 false,   true, except, except,  false,   true, except, except,
91  true,   true, except, except,   true,   true, except, except,
92except, except, except, except, except, except, except, except,
93except, except, except, except, except, except, except, except,
94except, except, except, except, except, except, except, except,
95except, except, except, except, except, except, except, except,
96 false,  false,   true,   true,  false,  false,   true,   true,
97  true,  false,  false,   true,  false,  false,   true,   true,
98 false,   true,   true,  false,   true,   true,  false,  false,
99  true,   true,  false,  false,   true,   true,  false,  false,
100except, except,   true,   true, except, except,   true,   true,
101except, except,  false,   true, except, except,   true,   true,
102except, except,   true,  false, except, except,  false,  false,
103except, except,  false,  false, except, except,  false,  false,
104 false,  false, except, except,  false,  false, except, except,
105  true,  false, except, except,  false,  false, except, except,
106 false,   true, except, except,   true,   true, except, except,
107  true,   true, except, except,   true,   true, except, except,
108except, except, except, except, except, except, except, except,
109except, except, except, except, except, except, except, except,
110except, except, except, except, except, except, except, except,
111except, except, except, except, except, except, except, except,
112 false,  false,   true,   true,  false,  false,   true,   true,
113  true,  false,  false,   true,  false,  false,   true,   true,
114 false,   true,   true,  false,   true,   true,  false,  false,
115  true,   true,  false,  false,   true,   true,  false,  false,
116except, except,   true,   true, except, except,   true,   true,
117except, except,  false,   true, except, except,   true,   true,
118except, except,   true,  false, except, except,  false,  false,
119except, except,  false,  false, except, except,  false,  false,
120 false,  false, except, except,  false,  false, except, except,
121  true,  false, except, except,  false,  false, except, except,
122 false,   true, except, except,   true,   true, except, except,
123  true,   true, except, except,   true,   true, except, except,
124except, except, except, except, except, except, except, except,
125except, except, except, except, except, except, except, except,
126except, except, except, except, except, except, except, except,
127except, except, except, except, except, except, except, except,
128 false,  false,   true,   true,   true,   true,  false,  false,
129  true,  false,  false,   true,   true,   true,  false,  false,
130 false,   true,   true,  false,   true,   true,  false,  false,
131  true,   true,  false,  false,   true,   true,  false,  false,
132except, except,   true,   true, except, except,   true,   true,
133except, except,  false,   true, except, except,   true,   true,
134except, except,   true,  false, except, except,  false,  false,
135except, except,  false,  false, except, except,  false,  false,
136 false,  false, except, except,   true,   true, except, except,
137  true,  false, except, except,   true,   true, except, except,
138 false,   true, except, except,   true,   true, except, except,
139  true,   true, except, except,   true,   true, except, except,
140except, except, except, except, except, except, except, except,
141except, except, except, except, except, except, except, except,
142except, except, except, except, except, except, except, except,
143except, except, except, except, except, except, except, except,
144 false,  false,   true,   true,   true,   true,  false,  false,
145  true,  false,  false,   true,   true,   true,  false,  false,
146 false,   true,   true,  false,   true,   true,  false,  false,
147  true,   true,  false,  false,   true,   true,  false,  false,
148except, except,   true,   true, except, except,   true,   true,
149except, except,  false,   true, except, except,   true,   true,
150except, except,   true,  false, except, except,  false,  false,
151except, except,  false,  false, except, except,  false,  false,
152 false,  false, except, except,   true,   true, except, except,
153  true,  false, except, except,   true,   true, except, except,
154 false,   true, except, except,   true,   true, except, except,
155  true,   true, except, except,   true,   true, except, except,
156except, except, except, except, except, except, except, except,
157except, except, except, except, except, except, except, except,
158except, except, except, except, except, except, except, except,
159except, except, except, except, except, except, except, except,
160 false,  false,   true,   true,  false,  false,   true,   true,
161  true,  false,  false,   true,   true,   true,  false,  false,
162 false,   true,   true,  false,  false,  false,   true,   true,
163  true,   true,  false,  false,   true,   true,  false,  false,
164except, except,   true,   true, except, except,   true,   true,
165except, except,  false,   true, except, except,  false,  false,
166except, except,   true,  false, except, except,   true,   true,
167except, except,  false,  false, except, except,  false,  false,
168 false,  false, except, except,  false,  false, except, except,
169  true,  false, except, except,   true,   true, except, except,
170 false,   true, except, except,  false,  false, except, except,
171  true,   true, except, except,   true,   true, except, except,
172except, except, except, except, except, except, except, except,
173except, except, except, except, except, except, except, except,
174except, except, except, except, except, except, except, except,
175except, except, except, except, except, except, except, except,
176 false,  false,   true,   true,  false,  false,   true,   true,
177  true,  false,  false,   true,  false,  false,   true,   true,
178 false,   true,   true,  false,  false,  false,   true,   true,
179  true,   true,  false,  false,  false,  false,   true,   true,
180except, except,   true,   true, except, except,   true,   true,
181except, except,  false,   true, except, except,   true,   true,
182except, except,   true,  false, except, except,   true,   true,
183except, except,  false,  false, except, except,   true,   true,
184 false,  false, except, except,  false,  false, except, except,
185  true,  false, except, except,   true,   true, except, except,
186 false,   true, except, except,  false,  false, except, except,
187  true,   true, except, except,   true,   true, except, except,
188except, except, except, except, except, except, except, except,
189except, except, except, except, except, except, except, except,
190except, except, except, except, except, except, except, except,
191except, except, except, except, except, except, except, except,
192 false,  false,   true,   true,  false,  false,   true,   true,
193  true,  false,  false,   true,   true,   true,  false,  false,
194 false,   true,   true,  false,  false,  false,   true,   true,
195  true,   true,  false,  false,   true,   true,  false,  false,
196except, except,   true,   true, except, except,   true,   true,
197except, except,  false,   true, except, except,  false,  false,
198except, except,   true,  false, except, except,   true,   true,
199except, except,  false,  false, except, except,  false,  false,
200 false,  false, except, except,  false,  false, except, except,
201  true,  false, except, except,   true,   true, except, except,
202 false,   true, except, except,  false,  false, except, except,
203  true,   true, except, except,   true,   true, except, except,
204except, except, except, except, except, except, except, except,
205except, except, except, except, except, except, except, except,
206except, except, except, except, except, except, except, except,
207except, except, except, except, except, except, except, except,
208 false,  false,   true,   true,  false,  false,   true,   true,
209  true,  false,  false,   true,  false,  false,   true,   true,
210 false,   true,   true,  false,  false,  false,   true,   true,
211  true,   true,  false,  false,  false,  false,   true,   true,
212except, except,   true,   true, except, except,   true,   true,
213except, except,  false,   true, except, except,   true,   true,
214except, except,   true,  false, except, except,   true,   true,
215except, except,  false,  false, except, except,   true,   true,
216 false,  false, except, except,  false,  false, except, except,
217  true,  false, except, except,   true,   true, except, except,
218 false,   true, except, except,  false,  false, except, except,
219  true,   true, except, except,   true,   true, except, except,
220except, except, except, except, except, except, except, except,
221except, except, except, except, except, except, except, except,
222except, except, except, except, except, except, except, except,
223except, except, except, except, except, except, except, except,
224 false,  false,   true,   true,  false,  false,   true,   true,
225  true,  false,  false,   true,  false,  false,   true,   true,
226 false,   true,   true,  false,   true,   true,  false,  false,
227  true,   true,  false,  false,   true,   true,  false,  false,
228except, except,   true,   true, except, except,   true,   true,
229except, except,  false,   true, except, except,   true,   true,
230except, except,   true,  false, except, except,  false,  false,
231except, except,  false,  false, except, except,  false,  false,
232 false,  false, except, except,  false,  false, except, except,
233  true,  false, except, except,  false,  false, except, except,
234 false,   true, except, except,   true,   true, except, except,
235  true,   true, except, except,   true,   true, except, except,
236except, except, except, except, except, except, except, except,
237except, except, except, except, except, except, except, except,
238except, except, except, except, except, except, except, except,
239except, except, except, except, except, except, except, except,
240 false,  false,   true,   true,  false,  false,   true,   true,
241  true,  false,  false,   true,  false,  false,   true,   true,
242 false,   true,   true,  false,   true,   true,  false,  false,
243  true,   true,  false,  false,   true,   true,  false,  false,
244except, except,   true,   true, except, except,   true,   true,
245except, except,  false,   true, except, except,   true,   true,
246except, except,   true,  false, except, except,  false,  false,
247except, except,  false,  false, except, except,  false,  false,
248 false,  false, except, except,  false,  false, except, except,
249  true,  false, except, except,  false,  false, except, except,
250 false,   true, except, except,   true,   true, except, except,
251  true,   true, except, except,   true,   true, except, except,
252except, except, except, except, except, except, except, except,
253except, except, except, except, except, except, except, except,
254except, except, except, except, except, except, except, except,
255except, except, except, except, except, except, except, except,
256 false,  false,   true,   true,   true,   true,  false,  false,
257  true,  false,  false,   true,   true,   true,  false,  false,
258 false,   true,   true,  false,   true,   true,  false,  false,
259  true,   true,  false,  false,   true,   true,  false,  false,
260except, except,   true,   true, except, except,   true,   true,
261except, except,  false,   true, except, except,   true,   true,
262except, except,   true,  false, except, except,  false,  false,
263except, except,  false,  false, except, except,  false,  false,
264 false,  false, except, except,   true,   true, except, except,
265  true,  false, except, except,   true,   true, except, except,
266 false,   true, except, except,   true,   true, except, except,
267  true,   true, except, except,   true,   true, except, except,
268except, except, except, except, except, except, except, except,
269except, except, except, except, except, except, except, except,
270except, except, except, except, except, except, except, except,
271except, except, except, except, except, except, except, except,
272 false,  false,   true,   true,   true,   true,  false,  false,
273  true,  false,  false,   true,   true,   true,  false,  false,
274 false,   true,   true,  false,   true,   true,  false,  false,
275  true,   true,  false,  false,   true,   true,  false,  false,
276except, except,   true,   true, except, except,   true,   true,
277except, except,  false,   true, except, except,   true,   true,
278except, except,   true,  false, except, except,  false,  false,
279except, except,  false,  false, except, except,  false,  false,
280 false,  false, except, except,   true,   true, except, except,
281  true,  false, except, except,   true,   true, except, except,
282 false,   true, except, except,   true,   true, except, except,
283  true,   true, except, except,   true,   true, except, except,
284except, except, except, except, except, except, except, except,
285except, except, except, except, except, except, except, except,
286except, except, except, except, except, except, except, except,
287except, except, except, except, except, except, except, except];
288
289for (var i = 0; i < 256; i++) {
290  Test(i & 1, i & 2, i & 4, i & 8, i & 0x10, i & 0x20, i & 0x40, i & 0x80);
291}
292
293
294function InstanceTest(x, func) {
295  try {
296    var answer = (x instanceof func);
297    assertEquals(correct_answers[correct_answer_index], answer);
298  } catch (e) {
299    assertTrue(/prototype/.test(e));
300    assertEquals(correct_answers[correct_answer_index], except);
301  }
302  correct_answer_index++;
303}
304
305
306function Test(a, b, c, d, e, f, g, h) {
307  var Foo = function() { }
308  var Bar = function() { }
309
310  if (c) Foo.prototype = 12;
311  if (d) Bar.prototype = 13;
312  var x = a ? new Foo() : new Bar();
313  var y = b ? new Foo() : new Bar();
314  InstanceTest(x, Foo);
315  InstanceTest(y, Foo);
316  InstanceTest(x, Bar);
317  InstanceTest(y, Bar);
318  if (e) x.__proto__ = Bar.prototype;
319  if (f) y.__proto__ = Foo.prototype;
320  if (g) {
321    x.__proto__ = y;
322  } else {
323    if (h) y.__proto__ = x
324  }
325  InstanceTest(x, Foo);
326  InstanceTest(y, Foo);
327  InstanceTest(x, Bar);
328  InstanceTest(y, Bar);
329}
330