diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2020-09-18 18:00:57 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-09-19 00:33:56 +0200 |
commit | 21f513fe0f4fe4ba18bda86ff9299d0aee736ff7 (patch) | |
tree | 9c7321b8ce60292b4f72db82f668c1f306b3564e /Libraries/LibJS/AST.cpp | |
parent | e317ee75415763cf55e8c812696f49833fddd136 (diff) | |
download | serenity-21f513fe0f4fe4ba18bda86ff9299d0aee736ff7.zip |
LibJS: Do not revisit already visited values in update_function_name()
Fixes #3471, adds a test.
Diffstat (limited to 'Libraries/LibJS/AST.cpp')
-rw-r--r-- | Libraries/LibJS/AST.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Libraries/LibJS/AST.cpp b/Libraries/LibJS/AST.cpp index 3886950442..96a8d49d14 100644 --- a/Libraries/LibJS/AST.cpp +++ b/Libraries/LibJS/AST.cpp @@ -26,6 +26,7 @@ */ #include <AK/HashMap.h> +#include <AK/HashTable.h> #include <AK/ScopeGuard.h> #include <AK/StringBuilder.h> #include <LibCrypto/BigInt/SignedBigInteger.h> @@ -49,10 +50,13 @@ namespace JS { -static void update_function_name(Value& value, const FlyString& name) +static void update_function_name(Value& value, const FlyString& name, HashTable<const JS::Cell*>& visited) { if (!value.is_object()) return; + if (visited.contains(value.as_cell())) + return; + visited.set(value.as_cell()); auto& object = value.as_object(); if (object.is_function()) { auto& function = static_cast<Function&>(object); @@ -61,10 +65,16 @@ static void update_function_name(Value& value, const FlyString& name) } else if (object.is_array()) { auto& array = static_cast<Array&>(object); for (auto& entry : array.indexed_properties().values_unordered()) - update_function_name(entry.value, name); + update_function_name(entry.value, name, visited); } } +static void update_function_name(Value& value, const FlyString& name) +{ + HashTable<const JS::Cell*> visited; + update_function_name(value, name, visited); +} + static String get_function_name(Interpreter& interpreter, Value value) { if (value.is_symbol()) |