1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 02:17:35 +00:00

js: Implement pretty-printing of generator objects

This commit is contained in:
Linus Groh 2022-05-05 20:50:32 +02:00
parent 53619176f5
commit 2ad9641315

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -24,6 +24,7 @@
#include <LibJS/Parser.h>
#include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/ArrayBuffer.h>
#include <LibJS/Runtime/AsyncGenerator.h>
#include <LibJS/Runtime/BooleanObject.h>
#include <LibJS/Runtime/DataView.h>
#include <LibJS/Runtime/Date.h>
@ -31,6 +32,7 @@
#include <LibJS/Runtime/ECMAScriptFunctionObject.h>
#include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/FunctionObject.h>
#include <LibJS/Runtime/GeneratorObject.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Intl/Collator.h>
#include <LibJS/Runtime/Intl/DateTimeFormat.h>
@ -451,6 +453,16 @@ static void print_shadow_realm(JS::Object const&, HashTable<JS::Object*>&)
print_type("ShadowRealm");
}
static void print_generator(JS::Object const&, HashTable<JS::Object*>&)
{
print_type("Generator");
}
static void print_async_generator(JS::Object const&, HashTable<JS::Object*>&)
{
print_type("AsyncGenerator");
}
template<typename T>
static void print_number(T number) requires IsArithmetic<T>
{
@ -914,6 +926,10 @@ static void print_value(JS::Value value, HashTable<JS::Object*>& seen_objects)
return print_array_buffer(object, seen_objects);
if (is<JS::ShadowRealm>(object))
return print_shadow_realm(object, seen_objects);
if (is<JS::GeneratorObject>(object))
return print_generator(object, seen_objects);
if (is<JS::AsyncGenerator>(object))
return print_async_generator(object, seen_objects);
if (object.is_typed_array())
return print_typed_array(object, seen_objects);
if (is<JS::StringObject>(object))