mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-28 05:52:53 +00:00
JSSpecCompiler: Pave a way for representing compile-time objects
This commit is contained in:
parent
3077e516a2
commit
d99d66e358
Notes:
sideshowbarker
2024-07-18 03:35:30 +09:00
Author: https://github.com/DanShaders
Commit: d99d66e358
Pull-request: https://github.com/SerenityOS/serenity/pull/23647
Reviewed-by: https://github.com/ADKaster ✅
12 changed files with 418 additions and 0 deletions
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Dan Klishch <danilklishch@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "Runtime/Object.h"
|
||||
#include "Function.h"
|
||||
|
||||
namespace JSSpecCompiler::Runtime {
|
||||
|
||||
Optional<DataProperty&> Property::get_data_property_or_diagnose(Realm* realm, QualifiedName name, Location current_location)
|
||||
{
|
||||
if (!has<DataProperty>()) {
|
||||
realm->diag().error(current_location,
|
||||
"{} must be a data property", name.to_string());
|
||||
realm->diag().note(location(),
|
||||
"defined as an accessor property here");
|
||||
return {};
|
||||
}
|
||||
return get<DataProperty>();
|
||||
}
|
||||
|
||||
static StringView well_known_symbol_to_sv(WellKnownSymbol symbol)
|
||||
{
|
||||
static Array string_value = {
|
||||
#define STRING_VALUE(enum_name, spec_name) "@@" #spec_name##sv,
|
||||
ENUMERATE_WELL_KNOWN_SYMBOLS(STRING_VALUE)
|
||||
#undef STRING_VALUE
|
||||
};
|
||||
return string_value[to_underlying(symbol)];
|
||||
}
|
||||
|
||||
void Object::do_dump(Printer& printer) const
|
||||
{
|
||||
printer.block([&] {
|
||||
for (auto const& [key, value] : m_properties) {
|
||||
key.visit(
|
||||
[&](Slot const& slot) { printer.format("[[{}]]", slot.key); },
|
||||
[&](StringPropertyKey const& string_property) { printer.format("{}", string_property.key); },
|
||||
[&](WellKnownSymbol const& symbol) { printer.format("{}", well_known_symbol_to_sv(symbol)); });
|
||||
printer.format(": ");
|
||||
value.visit(
|
||||
[&](DataProperty const& data) {
|
||||
printer.format(
|
||||
"[{}{}{}] ",
|
||||
data.is_configurable ? "c" : "",
|
||||
data.is_enumerable ? "e" : "",
|
||||
data.is_writable ? "w" : "");
|
||||
data.value->dump(printer);
|
||||
},
|
||||
[&](AccessorProperty const& accessor) {
|
||||
printer.format(
|
||||
"[{}{}] AccessorProperty",
|
||||
accessor.is_configurable ? "c" : "",
|
||||
accessor.is_enumerable ? "e" : "");
|
||||
printer.block([&] {
|
||||
if (accessor.getter.has_value())
|
||||
printer.formatln("get: {},", accessor.getter.value()->name());
|
||||
if (accessor.setter.has_value())
|
||||
printer.formatln("set: {},", accessor.setter.value()->name());
|
||||
});
|
||||
});
|
||||
printer.formatln(",");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue