summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/destructuring-null-or-undefined-into-computed-property-name.js
blob: c5d75801ab491141d7482da7a6025af7a169fad4 (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
load(libdir + 'asserts.js');
load(libdir + 'iteration.js');

var outer = "unmodified";

function f(v)
{
  if (v + "")
    ({ [(outer = "modified")]: v } = v);
}

assertEq(outer, "unmodified");
f(true);
assertEq(outer, "modified");

outer = "unmodified";
f({});
assertEq(outer, "modified");

outer = "unmodified";
assertThrowsInstanceOf(() => f(null), TypeError);
assertEq(outer, "unmodified");

assertThrowsInstanceOf(() => f(undefined), TypeError);
assertEq(outer, "unmodified");


function g(v)
{
  if (v + "")
    ({ [{ toString() { outer = "modified"; return 0; } }]: v } = v);
}

outer = "unmodified";
g(true);
assertEq(outer, "modified");

outer = "unmodified";
g({});
assertEq(outer, "modified");

outer = "unmodified";
assertThrowsInstanceOf(() => g(undefined), TypeError);
assertEq(outer, "unmodified");

assertThrowsInstanceOf(() => g(null), TypeError);
assertEq(outer, "unmodified");