1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:08:12 +00:00

LibJS: Use macros to enumerate well-known symbols

Not only is this a much nicer api (can't pass a typo'd string into the
get_well_known_symbol function), it is also a bit more performant since
there are no hashmap lookups.
This commit is contained in:
Matthew Olsson 2020-07-09 15:34:20 -07:00 committed by Andreas Kling
parent 2ea85355fe
commit c485c86015
7 changed files with 42 additions and 31 deletions

View file

@ -112,8 +112,6 @@ public:
Reference get_reference(const FlyString& name);
Symbol* get_global_symbol(const String& description);
Symbol* get_well_known_symbol(const String& description) const;
const HashMap<String, Symbol*>& get_well_known_symbol_map(Badge<SymbolConstructor>) const { return m_well_known_symbol_map; };
void gather_roots(Badge<Heap>, HashTable<Cell*>&);
@ -209,6 +207,11 @@ public:
const LexicalEnvironment* get_this_environment() const;
Value get_new_target() const;
#define __JS_ENUMERATE(SymbolName, snake_name) \
Symbol* well_known_symbol_##snake_name() const { return m_well_known_symbol_##snake_name; }
JS_ENUMERATE_WELL_KNOWN_SYMBOLS
#undef __JS_ENUMERATE
private:
Interpreter();
@ -221,9 +224,6 @@ private:
Object* m_global_object { nullptr };
HashMap<String, Symbol*> m_well_known_symbol_map;
HashMap<String, Symbol*> m_global_symbol_map;
Exception* m_exception { nullptr };
ScopeType m_unwind_until { ScopeType::None };
@ -232,6 +232,13 @@ private:
bool m_underscore_is_last_value { false };
Console m_console;
HashMap<String, Symbol*> m_global_symbol_map;
#define __JS_ENUMERATE(SymbolName, snake_name) \
Symbol* m_well_known_symbol_##snake_name { nullptr };
JS_ENUMERATE_WELL_KNOWN_SYMBOLS
#undef __JS_ENUMERATE
};
}