Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / jit-test / tests / basic / wrap-primitive-this.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
3 /*
4  * Any copyright is dedicated to the Public Domain.
5  * http://creativecommons.org/licenses/publicdomain/
6  */
7
8 /*
9  * If the tracer fails to notice that computeThis() will produce a wrapped
10  * primitive, then we may get:
11  *
12  * Assertion failure: thisObj == globalObj
13  */
14
15 var HOTLOOP = this.tracemonkey ? tracemonkey.HOTLOOP : 8;
16 var a;
17 function f(n) {
18     for (var i = 0; i < HOTLOOP; i++)
19         if (i == HOTLOOP - 2)
20             a = this;
21 }
22
23 /*
24  * Various sorts of events can cause the global to be reshaped, which
25  * resets our loop counts. Furthermore, we don't record a branch off a
26  * trace until it has been taken HOTEXIT times. So simply calling the
27  * function twice may not be enough to ensure that the 'a = this' branch
28  * gets recorded. This is probably excessive, but it'll work.
29  */
30 f.call("s", 1);
31 f.call("s", 1);
32 f.call("s", 1);
33 f.call("s", 1);
34 f.call("s", 1);
35 f.call("s", 1);
36 f.call("s", 1);
37 f.call("s", 1);
38 assertEq(typeof a, "object");
39 assertEq("" + a, "s");