summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/constAssignError.js
blob: 3e93fb464c8ba38edc6cf8f03d6160289111c882 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Can't assign to const is a runtime TypeError

load(libdir + 'asserts.js');

function assertTypeError(str) {
  assertThrowsInstanceOf(function () { eval(str); }, TypeError);
}

assertTypeError("(function() { const x = 3; (() => x++)(); return x })()");
assertTypeError("(function() { const x = 3; (() => x++)(); return x++ })()");
assertTypeError("(function() { const x = 2; (() => x++)(); return ++x })()");
assertTypeError("(function() { const x = 2; (() => x++)(); return x += 1 })()");

assertTypeError("(function() { const x = 3; x = 1; return (function() { return x})() })()");
assertTypeError("(function() { const x = 3; x = 1; return (function() { return x})() })()");
assertTypeError("(function() { const x = 3; x++; return (function() { return x})() })()");
assertTypeError("(function() { const x = 3; ++x; return (function() { return x})() })()");
assertTypeError("(function() { const x = 3; x--; return (function() { return x})() })()");
assertTypeError("(function() { const x = 3; --x; return (function() { return x})() })()");
assertTypeError("(function() { const x = 3; x += 1; return (function() { return x})() })()");
assertTypeError("(function() { const x = 3; x -= 1; return (function() { return x})() })()");

assertTypeError("(function() { const x = 3; [x] = [1]; })()");