summaryrefslogtreecommitdiff
path: root/js/src/jit-test/tests/basic/wrap-primitive-this.js
blob: 5c9db8085c4a60f4e05f045cf4850e188fa134a4 (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
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */

/*
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/licenses/publicdomain/
 */

/*
 * If the tracer fails to notice that computeThis() will produce a wrapped
 * primitive, then we may get:
 *
 * Assertion failure: thisObj == globalObj
 */

var HOTLOOP = this.tracemonkey ? tracemonkey.HOTLOOP : 8;
var a;
function f(n) {
    for (var i = 0; i < HOTLOOP; i++)
        if (i == HOTLOOP - 2)
            a = this;
}

/*
 * Various sorts of events can cause the global to be reshaped, which
 * resets our loop counts. Furthermore, we don't record a branch off a
 * trace until it has been taken HOTEXIT times. So simply calling the
 * function twice may not be enough to ensure that the 'a = this' branch
 * gets recorded. This is probably excessive, but it'll work.
 */
f.call("s", 1);
f.call("s", 1);
f.call("s", 1);
f.call("s", 1);
f.call("s", 1);
f.call("s", 1);
f.call("s", 1);
f.call("s", 1);
assertEq(typeof a, "object");
assertEq("" + a, "s");