ladybird/Libraries/LibJS/Tests/variable-declaration.js
Brian Gianforcaro d74ad81402 js/LibJS: Move test functions to pure javascript.
The addition of assert functions to Userland/js
was done before we had load(..) implemented. Now
that it exists, it seems like the right move the
test helper functions to pure javascript instead
of poluting js with random global functions.
2020-04-14 12:55:31 +02:00

26 lines
594 B
JavaScript

load("test-common.js");
try {
const constantValue = 1;
try {
constantValue = 2;
assertNotReached();
} catch (e) {
assert(e.name === "TypeError");
assert(e.message === "Assignment to constant variable");
assert(constantValue === 1);
}
// Make sure we can define new constants in inner scopes.
const constantValue2 = 1;
do {
const constantValue2 = 2;
assert(constantValue2 === 2);
} while (false);
assert(constantValue2 === 1);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}