mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
LibJS: Implement 'new.target'
This adds a new MetaProperty AST node which will be used for 'new.target' and 'import.meta' meta properties. The parser now distinguishes between "in function context" and "in arrow function context" (which is required for this). When encountering TokenType::New we will attempt to parse it as meta property and resort to regular new expression parsing if that fails, much like the parsing of labelled statements.
This commit is contained in:
committed by
Andreas Kling
parent
e07a39c816
commit
39a1c9d827
Notes:
sideshowbarker
2024-07-19 01:34:39 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/39a1c9d8276 Pull-request: https://github.com/SerenityOS/serenity/pull/3923 Reviewed-by: https://github.com/awesomekling
@@ -1655,6 +1655,28 @@ Value MemberExpression::execute(Interpreter& interpreter, GlobalObject& global_o
|
||||
return object_result->get(property_name).value_or(js_undefined());
|
||||
}
|
||||
|
||||
void MetaProperty::dump(int indent) const
|
||||
{
|
||||
String name;
|
||||
if (m_type == MetaProperty::Type::NewTarget)
|
||||
name = "new.target";
|
||||
else if (m_type == MetaProperty::Type::ImportMeta)
|
||||
name = "import.meta";
|
||||
else
|
||||
ASSERT_NOT_REACHED();
|
||||
print_indent(indent);
|
||||
printf("%s %s\n", class_name(), name.characters());
|
||||
}
|
||||
|
||||
Value MetaProperty::execute(Interpreter& interpreter, GlobalObject&) const
|
||||
{
|
||||
if (m_type == MetaProperty::Type::NewTarget)
|
||||
return interpreter.vm().get_new_target().value_or(js_undefined());
|
||||
if (m_type == MetaProperty::Type::ImportMeta)
|
||||
TODO();
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
Value StringLiteral::execute(Interpreter& interpreter, GlobalObject&) const
|
||||
{
|
||||
return js_string(interpreter.heap(), m_value);
|
||||
|
||||
Reference in New Issue
Block a user