mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibJS: Do not revisit already visited values in update_function_name()
Fixes #3471, adds a test.
This commit is contained in:
parent
e317ee7541
commit
21f513fe0f
Notes:
sideshowbarker
2024-07-19 02:20:39 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/21f513fe0f4 Pull-request: https://github.com/SerenityOS/serenity/pull/3535 Issue: https://github.com/SerenityOS/serenity/issues/3471 Reviewed-by: https://github.com/linusg
2 changed files with 19 additions and 2 deletions
|
@ -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())
|
||||
|
|
|
@ -48,3 +48,10 @@ test("names of native functions", () => {
|
|||
expect((console.debug.name = "warn")).toBe("warn");
|
||||
expect(console.debug.name).toBe("debug");
|
||||
});
|
||||
|
||||
test("cyclic members should not cause infinite recursion (#3471)", () => {
|
||||
let a = [() => 4];
|
||||
a[1] = a;
|
||||
a = a;
|
||||
expect(a[0].name).toBe("a");
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue