summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavidot <david.tuin@gmail.com>2021-09-18 16:31:50 +0200
committerLinus Groh <mail@linusgroh.de>2021-09-30 08:16:32 +0100
commitce3f29a135730dfce3864816ad9e82a6717e4509 (patch)
treee46f67fd61693bd2445b275a36fda58912883823
parent53cc7e839868e61af3d24e03e044c1048d5ecde0 (diff)
downloadserenity-ce3f29a135730dfce3864816ad9e82a6717e4509.zip
LibJS + test-js: Get results from the global object directly
This is as the spec would require you to do it and necessary for changes to come in the following commits.
-rw-r--r--Tests/LibJS/test-js.cpp14
-rw-r--r--Userland/Libraries/LibTest/JavaScriptTestRunner.h10
2 files changed, 14 insertions, 10 deletions
diff --git a/Tests/LibJS/test-js.cpp b/Tests/LibJS/test-js.cpp
index 3b15cb2fa7..6909de1617 100644
--- a/Tests/LibJS/test-js.cpp
+++ b/Tests/LibJS/test-js.cpp
@@ -77,19 +77,19 @@ TESTJS_GLOBAL_FUNCTION(mark_as_garbage, markAsGarbage)
return {};
}
- auto variable = outer_environment.value()->lexical_environment->get_from_environment(variable_name.string());
- if (!variable.has_value()) {
- vm.throw_exception<JS::ReferenceError>(global_object, JS::ErrorType::UnknownIdentifier, variable_name.string());
+ auto reference = vm.resolve_binding(variable_name.string(), outer_environment.value()->lexical_environment);
+
+ auto value = reference.get_value(global_object);
+ if (vm.exception())
return {};
- }
- if (!variable->value.is_object()) {
+ if (!value.is_object()) {
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAnObject, String::formatted("Variable with name {}", variable_name.string()));
return {};
}
- vm.heap().uproot_cell(&variable->value.as_object());
- outer_environment.value()->lexical_environment->delete_from_environment(variable_name.string());
+ vm.heap().uproot_cell(&value.as_object());
+ reference.delete_(global_object);
return JS::js_undefined();
}
diff --git a/Userland/Libraries/LibTest/JavaScriptTestRunner.h b/Userland/Libraries/LibTest/JavaScriptTestRunner.h
index 307da13c7d..641b4e8a3d 100644
--- a/Userland/Libraries/LibTest/JavaScriptTestRunner.h
+++ b/Userland/Libraries/LibTest/JavaScriptTestRunner.h
@@ -237,8 +237,9 @@ inline AK::Result<NonnullRefPtr<JS::SourceTextModule>, ParserError> parse_module
inline Optional<JsonValue> get_test_results(JS::Interpreter& interpreter)
{
- auto result = g_vm->get_variable("__TestResults__", interpreter.global_object());
- auto json_string = JS::JSONObject::stringify_impl(interpreter.global_object(), result, JS::js_undefined(), JS::js_undefined());
+ auto results = interpreter.global_object().get("__TestResults__");
+ VERIFY(!results.is_empty());
+ auto json_string = JS::JSONObject::stringify_impl(interpreter.global_object(), results, JS::js_undefined(), JS::js_undefined());
auto json = JsonValue::from_string(json_string);
if (!json.has_value())
@@ -382,7 +383,10 @@ inline JSFileResult TestRunner::run_file_test(const String& test_path)
JSFileResult file_result { test_path.substring(m_test_root.length() + 1, test_path.length() - m_test_root.length() - 1) };
// Collect logged messages
- auto& arr = interpreter->vm().get_variable("__UserOutput__", interpreter->global_object()).as_array();
+ auto user_output = interpreter->global_object().get("__UserOutput__");
+ VERIFY(!user_output.is_empty());
+
+ auto& arr = user_output.as_array();
for (auto& entry : arr.indexed_properties()) {
auto message = arr.get(entry.index());
file_result.logged_messages.append(message.to_string_without_side_effects());