summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/pic/length_string_object.js
blob: 534c6b451ed519501ebbeaa14c928d1076a422f3 (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
//length, string, object

var expected = "3,6,4,3,6,4,3,6,4,3,6,4,";
var actual = '';

function f() {
    var ss = [new String("abc"), new String("foobar"), new String("quux")];

    for (var i = 0; i < 12; ++i) {
        actual += ss[i%3].length + ',';
    }
}

f();

assertEq(actual, expected);


function g(s) {
    return new String(s).length;
}

assertEq(g("x"), 1); // Warm-up
assertEq(g("x"), 1); // Create IC
assertEq(g("x"), 1); // Test IC

function h(s) {
    var x = new String(s);
    for (var i = 0; i < 100; i++)
        x[i] = i;
    return x.length;
}

assertEq(h("x"), 1);
assertEq(h("x"), 1);
assertEq(h("x"), 1);