1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:57:34 +00:00

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
This commit is contained in:
davidot 2021-10-03 13:17:33 +02:00 committed by Andreas Kling
parent ac2c3a73b1
commit 0be0e7ea6e

View file

@ -1174,6 +1174,8 @@ int main(int argc, char** argv)
#endif #endif
interpreter->vm().set_underscore_is_last_value(true); interpreter->vm().set_underscore_is_last_value(true);
auto& global_environment = interpreter->realm().global_environment();
s_editor = Line::Editor::construct(); s_editor = Line::Editor::construct();
s_editor->load_history(s_history_path); 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)); 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()); auto line = editor.line(editor.cursor());
JS::Lexer lexer { line }; JS::Lexer lexer { line };
@ -1337,18 +1339,13 @@ int main(int argc, char** argv)
switch (mode) { switch (mode) {
case CompleteProperty: { case CompleteProperty: {
Optional<JS::Value> maybe_value; 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()) if (vm->exception())
break; break;
if (!maybe_variable.is_unresolvable()) { maybe_value = maybe_variable.get_value(interpreter->global_object());
maybe_value = maybe_variable.get_value(interpreter->global_object()); if (vm->exception())
if (vm->exception()) break;
break; VERIFY(!maybe_value->is_empty());
} else {
maybe_value = interpreter->global_object().get(FlyString(variable_name));
if (maybe_value->is_empty())
break;
}
auto variable = *maybe_value; auto variable = *maybe_value;
if (!variable.is_object()) if (!variable.is_object())