summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/property-error-message-fix.js
blob: 69092e7601312c5620aaeff1433d6c35df7b99a2 (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
function check(f, message) {
  let caught = false;
  try {
    f();
  } catch (e) {
    assertEq(e.message, message);
    caught = true;
  }
  assertEq(caught, true);
}

check(() => {
  let obj = {
    prop: undefined
  };
  obj.prop.prop2();
}, "can't access property \"prop2\", obj.prop is undefined");

check(() => {
  let obj = {
    prop: null
  };
  obj.prop.prop2();
}, "can't access property \"prop2\", obj.prop is null");

check(() => {
  let prop = "prop";
  undefined[prop]();
}, "can't access property \"prop\" of undefined");

check(() => {
  let prop = "prop";
  null[prop]();
}, "can't access property \"prop\" of null");