mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:17:44 +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:
parent
2ea85355fe
commit
c485c86015
7 changed files with 42 additions and 31 deletions
|
@ -81,7 +81,7 @@ void ArrayPrototype::initialize(Interpreter& interpreter, GlobalObject& global_o
|
|||
// Use define_property here instead of define_native_function so that
|
||||
// Object.is(Array.prototype[Symbol.iterator], Array.prototype.values)
|
||||
// evaluates to true
|
||||
define_property(interpreter.get_well_known_symbol("iterator"), get("values"), attr);
|
||||
define_property(interpreter.well_known_symbol_iterator(), get("values"), attr);
|
||||
}
|
||||
|
||||
ArrayPrototype::~ArrayPrototype()
|
||||
|
|
|
@ -36,7 +36,7 @@ Object* get_iterator(Object& obj, String hint, Value method)
|
|||
if (method.is_empty()) {
|
||||
if (hint == "async")
|
||||
TODO();
|
||||
method = obj.get(obj.interpreter().get_well_known_symbol("iterator"));
|
||||
method = obj.get(obj.interpreter().well_known_symbol_iterator());
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ IteratorPrototype::IteratorPrototype(GlobalObject& global_object)
|
|||
void IteratorPrototype::initialize(Interpreter& interpreter, GlobalObject& global_object)
|
||||
{
|
||||
Object::initialize(interpreter, global_object);
|
||||
define_native_function(interpreter.get_well_known_symbol("iterator"), symbol_iterator, 0, Attribute::Writable | Attribute::Enumerable);
|
||||
define_native_function(interpreter.well_known_symbol_iterator(), symbol_iterator, 0, Attribute::Writable | Attribute::Enumerable);
|
||||
}
|
||||
|
||||
IteratorPrototype::~IteratorPrototype()
|
||||
|
|
|
@ -46,8 +46,10 @@ void SymbolConstructor::initialize(Interpreter& interpreter, GlobalObject& globa
|
|||
define_native_function("for", for_, 1, Attribute::Writable | Attribute::Configurable);
|
||||
define_native_function("keyFor", key_for, 1, Attribute::Writable | Attribute::Configurable);
|
||||
|
||||
for (auto& entry : interpreter.get_well_known_symbol_map({}))
|
||||
define_property(entry.key, entry.value, 0);
|
||||
#define __JS_ENUMERATE(SymbolName, snake_name) \
|
||||
define_property(#SymbolName, interpreter.well_known_symbol_##snake_name(), 0);
|
||||
JS_ENUMERATE_WELL_KNOWN_SYMBOLS
|
||||
#undef __JS_ENUMERATE
|
||||
}
|
||||
|
||||
SymbolConstructor::~SymbolConstructor()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue