1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 11:54:57 +00:00

LibJS: Add the Set built-in object

This commit is contained in:
Idan Horowitz 2021-06-09 00:08:47 +03:00 committed by Linus Groh
parent b17a282b4b
commit 670be04c81
15 changed files with 359 additions and 30 deletions

View file

@ -35,6 +35,7 @@
#include <LibJS/Runtime/ProxyObject.h>
#include <LibJS/Runtime/RegExpObject.h>
#include <LibJS/Runtime/ScriptFunction.h>
#include <LibJS/Runtime/Set.h>
#include <LibJS/Runtime/Shape.h>
#include <LibJS/Runtime/StringObject.h>
#include <LibJS/Runtime/TypedArray.h>
@ -277,6 +278,22 @@ static void print_proxy_object(const JS::Object& object, HashTable<JS::Object*>&
print_value(&proxy_object.handler(), seen_objects);
}
static void print_set(const JS::Object& object, HashTable<JS::Object*>& seen_objects)
{
auto& set = static_cast<const JS::Set&>(object);
auto& values = set.values();
print_type("Set");
out(" {{");
bool first = true;
for (auto& value : values) {
print_separator(first);
print_value(value, seen_objects);
}
if (!first)
out(" ");
out("}}");
}
static void print_promise(const JS::Object& object, HashTable<JS::Object*>& seen_objects)
{
auto& promise = static_cast<const JS::Promise&>(object);
@ -398,6 +415,8 @@ static void print_value(JS::Value value, HashTable<JS::Object*>& seen_objects)
return print_error(object, seen_objects);
if (is<JS::RegExpObject>(object))
return print_regexp_object(object, seen_objects);
if (is<JS::Set>(object))
return print_set(object, seen_objects);
if (is<JS::ProxyObject>(object))
return print_proxy_object(object, seen_objects);
if (is<JS::Promise>(object))