Skip to content

Commit

Permalink
js: Fix that auto completion of properties failed
Browse files Browse the repository at this point in the history
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 SerenityOS#10281
  • Loading branch information
davidot authored and awesomekling committed Oct 3, 2021
1 parent ac2c3a7 commit 0be0e7e
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions Userland/Utilities/js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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<Line::CompletionSuggestion> {
auto complete = [&interpreter, &global_environment](Line::Editor const& editor) -> Vector<Line::CompletionSuggestion> {
auto line = editor.line(editor.cursor());

JS::Lexer lexer { line };
Expand Down Expand Up @@ -1337,18 +1339,13 @@ int main(int argc, char** argv)
switch (mode) {
case CompleteProperty: {
Optional<JS::Value> 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())
Expand Down

0 comments on commit 0be0e7e

Please sign in to comment.