summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Tests/modules/accessing-lex-import-before-decl.mjs
diff options
context:
space:
mode:
authordavidot <davidot@serenityos.org>2022-09-01 23:48:57 +0200
committerLinus Groh <mail@linusgroh.de>2022-09-02 02:07:37 +0100
commit0fc67ffd623d62797fe81da215045b599b0f5661 (patch)
tree70c51a1c28576aec565072f9447b3e2bac58eb17 /Userland/Libraries/LibJS/Tests/modules/accessing-lex-import-before-decl.mjs
parent2484bbc4e03744f3b9a17649d81b6e5952fd348b (diff)
downloadserenity-0fc67ffd623d62797fe81da215045b599b0f5661.zip
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.
Diffstat (limited to 'Userland/Libraries/LibJS/Tests/modules/accessing-lex-import-before-decl.mjs')
-rw-r--r--Userland/Libraries/LibJS/Tests/modules/accessing-lex-import-before-decl.mjs23
1 files changed, 23 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Tests/modules/accessing-lex-import-before-decl.mjs b/Userland/Libraries/LibJS/Tests/modules/accessing-lex-import-before-decl.mjs
new file mode 100644
index 0000000000..1b96bf8aef
--- /dev/null
+++ b/Userland/Libraries/LibJS/Tests/modules/accessing-lex-import-before-decl.mjs
@@ -0,0 +1,23 @@
+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 };