From 0be0e7ea6efada35ba6eab72041009501e192892 Mon Sep 17 00:00:00 2001 From: davidot Date: Sun, 3 Oct 2021 13:17:33 +0200 Subject: [PATCH] js: Fix that auto completion of properties failed For this we store the global environment in which we can do a lookup for the references variable. This is probably not entirely as the spec would specify as we would need a running executing context at all times you do things with references. Fixes #10281 --- Userland/Utilities/js.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp index 0fbc91efa4..6148243228 100644 --- a/Userland/Utilities/js.cpp +++ b/Userland/Utilities/js.cpp @@ -1174,6 +1174,8 @@ int main(int argc, char** argv) #endif interpreter->vm().set_underscore_is_last_value(true); + auto& global_environment = interpreter->realm().global_environment(); + s_editor = Line::Editor::construct(); s_editor->load_history(s_history_path); @@ -1246,7 +1248,7 @@ int main(int argc, char** argv) editor.set_prompt(prompt_for_level(open_indents)); }; - auto complete = [&interpreter](Line::Editor const& editor) -> Vector { + auto complete = [&interpreter, &global_environment](Line::Editor const& editor) -> Vector { auto line = editor.line(editor.cursor()); JS::Lexer lexer { line }; @@ -1337,18 +1339,13 @@ int main(int argc, char** argv) switch (mode) { case CompleteProperty: { Optional maybe_value; - auto maybe_variable = vm->resolve_binding(variable_name); + auto maybe_variable = vm->resolve_binding(variable_name, &global_environment); if (vm->exception()) break; - if (!maybe_variable.is_unresolvable()) { - maybe_value = maybe_variable.get_value(interpreter->global_object()); - if (vm->exception()) - break; - } else { - maybe_value = interpreter->global_object().get(FlyString(variable_name)); - if (maybe_value->is_empty()) - break; - } + maybe_value = maybe_variable.get_value(interpreter->global_object()); + if (vm->exception()) + break; + VERIFY(!maybe_value->is_empty()); auto variable = *maybe_value; if (!variable.is_object())