LibJS: Improve UpdateExpression::execute()

- Let undefined variables throw a ReferenceError by using
  Identifier::execute() rather than doing variable lookup manually and
  ASSERT()ing
- Coerce value to number rather than ASSERT()ing
- Make code DRY
- Add tests
This commit is contained in:
Linus Groh 2020-04-21 23:27:11 +01:00 committed by Andreas Kling
commit a1b820b11c
Notes: sideshowbarker 2024-07-19 07:23:45 +09:00
2 changed files with 63 additions and 11 deletions

View file

@ -0,0 +1,54 @@
load("test-common.js");
try {
assertThrowsError(() => {
++x;
}, {
error: ReferenceError,
message: "'x' not known"
});
var n = 0;
assert(++n === 1);
assert(n === 1);
var n = 0;
assert(n++ === 0);
assert(n === 1);
var n = 0;
assert(--n === -1);
assert(n === -1);
var n = 0;
assert(n-- === 0);
assert(n === -1);
var a = [];
assert(a++ === 0);
assert(a === 1);
var b = true;
assert(b-- === 1);
assert(b === 0);
var s = "foo";
assert(isNaN(++s));
assert(isNaN(s));
var s = "foo";
assert(isNaN(s++));
assert(isNaN(s));
var s = "foo";
assert(isNaN(--s));
assert(isNaN(s));
var s = "foo";
assert(isNaN(s--));
assert(isNaN(s));
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}