summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/language/statements/class/definition/this-check-ordering.js
blob: c7f867db9b91064005a1f1c9e32f4f2eff275b01 (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
67
68
69
70
71
72
// Copyright (C) 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.5
description: >
    class this check ordering
---*/
var baseCalled = 0;
class Base {
  constructor() { baseCalled++ }
}

var fCalled = 0;
function f() { fCalled++; return 3; }

class Subclass1 extends Base {
  constructor() {
    baseCalled = 0;
    super();
    assert.sameValue(baseCalled, 1, "The value of `baseCalled` is `1`");
    var obj = this;

    var exn = null;
    baseCalled = 0;
    fCalled = 0;
    try {
      super(f());
    } catch (e) { exn = e; }
    assert.sameValue(
      exn instanceof ReferenceError,
      true,
      "The result of `exn instanceof ReferenceError` is `true`"
    );
    assert.sameValue(fCalled, 1, "The value of `fCalled` is `1`");
    assert.sameValue(baseCalled, 1, "The value of `baseCalled` is `1`");
    assert.sameValue(this, obj, "`this` is `obj`");

    exn = null;
    baseCalled = 0;
    fCalled = 0;
    try {
      super(super(), f());
    } catch (e) { exn = e; }
    assert.sameValue(
      exn instanceof ReferenceError,
      true,
      "The result of `exn instanceof ReferenceError` is `true`"
    );
    assert.sameValue(fCalled, 0, "The value of `fCalled` is `0`");
    assert.sameValue(baseCalled, 1, "The value of `baseCalled` is `1`");
    assert.sameValue(this, obj, "`this` is `obj`");

    exn = null;
    baseCalled = 0;
    fCalled = 0;
    try {
      super(f(), super());
    } catch (e) { exn = e; }
    assert.sameValue(
      exn instanceof ReferenceError,
      true,
      "The result of `exn instanceof ReferenceError` is `true`"
    );
    assert.sameValue(fCalled, 1, "The value of `fCalled` is `1`");
    assert.sameValue(baseCalled, 1, "The value of `baseCalled` is `1`");
    assert.sameValue(this, obj, "`this` is `obj`");
  }
}

new Subclass1();

reportCompare(0, 0);