LibJS: Allow implicit Value construction from GC-allocated things

This commit is contained in:
Andreas Kling 2020-03-12 19:57:40 +01:00
parent 7912f33ea0
commit 32963cf74a
Notes: sideshowbarker 2024-07-19 08:20:22 +09:00
4 changed files with 10 additions and 10 deletions

View File

@ -44,8 +44,8 @@ Value ScopeNode::execute(Interpreter& interpreter) const
Value FunctionDeclaration::execute(Interpreter& interpreter) const
{
auto* function = interpreter.heap().allocate<Function>(name(), body(), parameters());
interpreter.set_variable(m_name, Value(function));
return Value(function);
interpreter.set_variable(m_name, function);
return function;
}
Value ExpressionStatement::execute(Interpreter& interpreter) const
@ -564,7 +564,7 @@ void ExpressionStatement::dump(int indent) const
Value ObjectExpression::execute(Interpreter& interpreter) const
{
return Value(interpreter.heap().allocate<Object>());
return interpreter.heap().allocate<Object>();
}
void MemberExpression::dump(int indent) const
@ -591,7 +591,7 @@ Value MemberExpression::execute(Interpreter& interpreter) const
Value StringLiteral::execute(Interpreter& interpreter) const
{
return Value(js_string(interpreter.heap(), m_value));
return js_string(interpreter.heap(), m_value);
}
Value NumericLiteral::execute(Interpreter&) const

View File

@ -38,11 +38,11 @@ Interpreter::Interpreter()
: m_heap(*this)
{
m_global_object = heap().allocate<Object>();
m_global_object->put("print", Value(heap().allocate<NativeFunction>([](Vector<Argument> arguments) -> Value {
m_global_object->put("print", heap().allocate<NativeFunction>([](Vector<Argument> arguments) -> Value {
for (auto& argument : arguments)
printf("%s ", argument.value.to_string().characters());
return js_undefined();
})));
}));
}
Interpreter::~Interpreter()

View File

@ -81,10 +81,10 @@ bool Value::to_boolean() const
Value Value::to_object(Heap& heap) const
{
if (is_object())
return Value(as_object());
return const_cast<Object*>(as_object());
if (is_string())
return Value(heap.allocate<StringObject>(m_value.as_string));
return heap.allocate<StringObject>(m_value.as_string);
ASSERT_NOT_REACHED();
}

View File

@ -70,13 +70,13 @@ public:
m_value.as_double = value;
}
explicit Value(Object* object)
Value(Object* object)
: m_type(Type::Object)
{
m_value.as_object = object;
}
explicit Value(PrimitiveString* string)
Value(PrimitiveString* string)
: m_type(Type::String)
{
m_value.as_string = string;