mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:47:45 +00:00
LibJS: Allow implicit Value construction from GC-allocated things
This commit is contained in:
parent
7912f33ea0
commit
32963cf74a
4 changed files with 10 additions and 10 deletions
|
@ -44,8 +44,8 @@ Value ScopeNode::execute(Interpreter& interpreter) const
|
||||||
Value FunctionDeclaration::execute(Interpreter& interpreter) const
|
Value FunctionDeclaration::execute(Interpreter& interpreter) const
|
||||||
{
|
{
|
||||||
auto* function = interpreter.heap().allocate<Function>(name(), body(), parameters());
|
auto* function = interpreter.heap().allocate<Function>(name(), body(), parameters());
|
||||||
interpreter.set_variable(m_name, Value(function));
|
interpreter.set_variable(m_name, function);
|
||||||
return Value(function);
|
return function;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ExpressionStatement::execute(Interpreter& interpreter) const
|
Value ExpressionStatement::execute(Interpreter& interpreter) const
|
||||||
|
@ -564,7 +564,7 @@ void ExpressionStatement::dump(int indent) const
|
||||||
|
|
||||||
Value ObjectExpression::execute(Interpreter& interpreter) const
|
Value ObjectExpression::execute(Interpreter& interpreter) const
|
||||||
{
|
{
|
||||||
return Value(interpreter.heap().allocate<Object>());
|
return interpreter.heap().allocate<Object>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemberExpression::dump(int indent) const
|
void MemberExpression::dump(int indent) const
|
||||||
|
@ -591,7 +591,7 @@ Value MemberExpression::execute(Interpreter& interpreter) const
|
||||||
|
|
||||||
Value StringLiteral::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
|
Value NumericLiteral::execute(Interpreter&) const
|
||||||
|
|
|
@ -38,11 +38,11 @@ Interpreter::Interpreter()
|
||||||
: m_heap(*this)
|
: m_heap(*this)
|
||||||
{
|
{
|
||||||
m_global_object = heap().allocate<Object>();
|
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)
|
for (auto& argument : arguments)
|
||||||
printf("%s ", argument.value.to_string().characters());
|
printf("%s ", argument.value.to_string().characters());
|
||||||
return js_undefined();
|
return js_undefined();
|
||||||
})));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
Interpreter::~Interpreter()
|
Interpreter::~Interpreter()
|
||||||
|
|
|
@ -81,10 +81,10 @@ bool Value::to_boolean() const
|
||||||
Value Value::to_object(Heap& heap) const
|
Value Value::to_object(Heap& heap) const
|
||||||
{
|
{
|
||||||
if (is_object())
|
if (is_object())
|
||||||
return Value(as_object());
|
return const_cast<Object*>(as_object());
|
||||||
|
|
||||||
if (is_string())
|
if (is_string())
|
||||||
return Value(heap.allocate<StringObject>(m_value.as_string));
|
return heap.allocate<StringObject>(m_value.as_string);
|
||||||
|
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,13 +70,13 @@ public:
|
||||||
m_value.as_double = value;
|
m_value.as_double = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit Value(Object* object)
|
Value(Object* object)
|
||||||
: m_type(Type::Object)
|
: m_type(Type::Object)
|
||||||
{
|
{
|
||||||
m_value.as_object = object;
|
m_value.as_object = object;
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit Value(PrimitiveString* string)
|
Value(PrimitiveString* string)
|
||||||
: m_type(Type::String)
|
: m_type(Type::String)
|
||||||
{
|
{
|
||||||
m_value.as_string = string;
|
m_value.as_string = string;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue