ladybird/Libraries/LibJS/Tests/variable-declaration.js
Matthew Olsson 78155a6668 LibJS: Consolidate error messages into ErrorTypes.h
Now, exceptions can be thrown with
interpreter.throw_exception<T>(ErrorType:TYPE, "format", "args",
"here").
2020-06-11 07:46:20 +02:00

25 lines
552 B
JavaScript

load("test-common.js");
try {
const constantValue = 1;
assertThrowsError(() => {
constantValue = 2;
}, {
error: TypeError,
message: "Invalid assignment to const 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);
}