summaryrefslogtreecommitdiff
path: root/Userland/js.cpp
diff options
context:
space:
mode:
authorMatthew Olsson <matthewcolsson@gmail.com>2020-07-07 21:38:46 -0700
committerAndreas Kling <kling@serenityos.org>2020-07-09 23:33:00 +0200
commit7a1d485b19a43b3538b3ac69040ebc2b3bb14d85 (patch)
tree911f871ab04920383b79d24ae22c9ea80976685c /Userland/js.cpp
parent9783a4936cd0677dc3fe12cbf9009eceb47c4d1f (diff)
downloadserenity-7a1d485b19a43b3538b3ac69040ebc2b3bb14d85.zip
LibJS: Integrate Symbols into objects as valid keys
This allows objects properties to be created for symbol keys in addition to just plain strings/numbers
Diffstat (limited to 'Userland/js.cpp')
-rw-r--r--Userland/js.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/Userland/js.cpp b/Userland/js.cpp
index d18354bb4f..42ea3705cb 100644
--- a/Userland/js.cpp
+++ b/Userland/js.cpp
@@ -197,7 +197,11 @@ static void print_object(JS::Object& object, HashTable<JS::Object*>& seen_object
size_t index = 0;
for (auto& it : object.shape().property_table_ordered()) {
- printf("\"\033[33;1m%s\033[0m\": ", it.key.characters());
+ if (it.key.is_string()) {
+ printf("\"\033[33;1m%s\033[0m\": ", it.key.to_display_string().characters());
+ } else {
+ printf("\033[33;1m%s\033[0m: ", it.key.to_display_string().characters());
+ }
print_value(object.get_direct(it.value.offset), seen_objects);
if (index != object.shape().property_count() - 1)
fputs(", ", stdout);
@@ -792,10 +796,13 @@ int main(int argc, char** argv)
Function<void(const JS::Shape&, const StringView&)> list_all_properties = [&results, &list_all_properties](const JS::Shape& shape, auto& property_pattern) {
for (const auto& descriptor : shape.property_table()) {
- if (descriptor.key.view().starts_with(property_pattern)) {
- Line::CompletionSuggestion completion { descriptor.key, Line::CompletionSuggestion::ForSearch };
+ if (!descriptor.key.is_string())
+ continue;
+ auto key = descriptor.key.as_string();
+ if (key.view().starts_with(property_pattern)) {
+ Line::CompletionSuggestion completion { key, Line::CompletionSuggestion::ForSearch };
if (!results.contains_slow(completion)) { // hide duplicates
- results.append({ descriptor.key });
+ results.append(key);
}
}
}