diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-06-12 23:54:40 +0300 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-06-13 00:33:18 +0100 |
commit | a96ac8bd56f5a06552ed2a6fe7b21388d5454250 (patch) | |
tree | 3424f68ac39ce4676d3b38dc726c6fa89b5c40c6 /Userland/Utilities | |
parent | f9d58ec0b444e7e4ff2f4cd443f8f046e5abf9ae (diff) | |
download | serenity-a96ac8bd56f5a06552ed2a6fe7b21388d5454250.zip |
LibJS: Add the Map built-in object
Diffstat (limited to 'Userland/Utilities')
-rw-r--r-- | Userland/Utilities/js.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp index 181e4a476d..7abce34589 100644 --- a/Userland/Utilities/js.cpp +++ b/Userland/Utilities/js.cpp @@ -27,6 +27,7 @@ #include <LibJS/Runtime/Error.h> #include <LibJS/Runtime/Function.h> #include <LibJS/Runtime/GlobalObject.h> +#include <LibJS/Runtime/Map.h> #include <LibJS/Runtime/NativeFunction.h> #include <LibJS/Runtime/NumberObject.h> #include <LibJS/Runtime/Object.h> @@ -278,6 +279,24 @@ static void print_proxy_object(const JS::Object& object, HashTable<JS::Object*>& print_value(&proxy_object.handler(), seen_objects); } +static void print_map(const JS::Object& object, HashTable<JS::Object*>& seen_objects) +{ + auto& map = static_cast<const JS::Map&>(object); + auto& entries = map.entries(); + print_type("Map"); + out(" {{"); + bool first = true; + for (auto& entry : entries) { + print_separator(first); + print_value(entry.key, seen_objects); + out(" => "); + print_value(entry.value, seen_objects); + } + if (!first) + out(" "); + out("}}"); +} + static void print_set(const JS::Object& object, HashTable<JS::Object*>& seen_objects) { auto& set = static_cast<const JS::Set&>(object); @@ -415,6 +434,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::Map>(object)) + return print_map(object, seen_objects); if (is<JS::Set>(object)) return print_set(object, seen_objects); if (is<JS::ProxyObject>(object)) |