ladybird/Userland/Libraries/LibJS/Tests/modules/accessing-lex-import-before-decl.mjs
davidot 0fc67ffd62 LibJS: Make indirect bindings of module behave like normal bindings
Before this we attempted to hack around this by only overriding
has_binding. However this did not cover all cases, for example when
assigning to variables before their declaration it didn't throw.
By using the new find_binding_and_index virtual method we can just
pretend the indirect bindings are real.

Since indirect binding do come from a normal environment we need to
ensure you cannot modify the binding and that properties like mutable
are false as expected by the spec for such an indirect binding.
2022-09-02 02:07:37 +01:00

23 lines
639 B
JavaScript

let passed = true;
try {
importedLexVariable;
passed = false;
} catch (e) {
if (!(e instanceof ReferenceError))
throw new Error("Expected importedLexVariable; to throw ReferenceError got " + e);
}
try {
// Even though value is let, this should still throw TypeError because it is immutable!
importedLexVariable = 0;
passed = false;
} catch (e) {
if (!(e instanceof TypeError))
throw new Error("Expected importedLexVariable = 0; to throw TypeError got " + e);
}
import { value as importedLexVariable } from "./accessing-lex-import-before-decl.mjs";
export let value = 123;
export { passed };