mirror of
https://github.com/RGBCube/serenity
synced 2025-07-10 08:47:35 +00:00
LibJS: Introduce Builtins
Builtins are functions that can be detected during bytecode generation and enable fast-paths in the JIT.
This commit is contained in:
parent
b9141d85d8
commit
86b85aa68b
13 changed files with 191 additions and 4 deletions
26
Userland/Libraries/LibJS/Bytecode/Builtins.cpp
Normal file
26
Userland/Libraries/LibJS/Bytecode/Builtins.cpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Simon Wanner <simon@skyrising.xyz>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibJS/AST.h>
|
||||
#include <LibJS/Bytecode/Builtins.h>
|
||||
|
||||
namespace JS::Bytecode {
|
||||
|
||||
Optional<Builtin> get_builtin(MemberExpression const& expression)
|
||||
{
|
||||
if (expression.is_computed() || !expression.object().is_identifier() || !expression.property().is_identifier())
|
||||
return {};
|
||||
auto base_name = static_cast<Identifier const&>(expression.object()).string();
|
||||
auto property_name = static_cast<Identifier const&>(expression.property()).string();
|
||||
#define CHECK_MEMBER_BUILTIN(name, snake_case_name, base, property, ...) \
|
||||
if (base_name == #base##sv && property_name == #property##sv) \
|
||||
return Builtin::name;
|
||||
JS_ENUMERATE_BUILTINS(CHECK_MEMBER_BUILTIN)
|
||||
#undef CHECK_MEMBER_BUILTIN
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue