summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/ion/recover-newstringiterator.js
blob: 14a7d46b6ef41d746f4353b435203ce895a8dd2b (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var max = 40;
setJitCompilerOption("ion.warmup.trigger", max - 10);

// Prevent the GC from cancelling Ion compilations, when we expect them to succeed
gczeal(0);

function selfhosted() {
    if (typeof getSelfHostedValue === "undefined")
        return;

    var NewStringIterator = getSelfHostedValue("NewStringIterator");
    var iter = NewStringIterator();
    bailout();
    // assertRecoveredOnBailout(iter, true);
}

function iterator(i) {
    var string = String.fromCharCode(0x41, i);
    var iter = string[Symbol.iterator]();
    assertEq(iter.next().value, 'A');
    bailout();
    // This sometimes fails
    // assertRecoveredOnBailout(iter, true);
    var result = iter.next();
    assertEq(result.value, String.fromCharCode(i));
    assertEq(result.done, false);
    assertEq(iter.next().done, true);
}

function forof(i) {
    var string = String.fromCharCode(0x41, i);
    var first = true;

    for (var x of string) {
        if (first) {
            assertEq(x, 'A');
            bailout();
            first = false;
        } else {
            assertEq(x, String.fromCharCode(i));
        }
    }
}

var data = {
  a: 'foo',
  b: {c: 'd'},
  str: 'ABC'
};

function fn() {
  var {a, b:{c:b}, str:[, c]} = data;
  return c;
}

function destructuring() {
    for (var i = 0; i < max; i++)
        assertEq(fn(), 'B');
}

for (var i = 0; i < max; i++) {
    selfhosted();
    iterator(i);
    forof(i);
    destructuring();
}