summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-03-12 19:57:40 +0100
committerAndreas Kling <kling@serenityos.org>2020-03-12 19:57:40 +0100
commit32963cf74a9e4b66ba3122a5e52a62911de65746 (patch)
treed9f3debdda341a8f5f09304922f9b1024d62f646
parent7912f33ea0c223b88ff79ad4c072ec87dd0c29c4 (diff)
downloadserenity-32963cf74a9e4b66ba3122a5e52a62911de65746.zip
LibJS: Allow implicit Value construction from GC-allocated things
-rw-r--r--Libraries/LibJS/AST.cpp8
-rw-r--r--Libraries/LibJS/Interpreter.cpp4
-rw-r--r--Libraries/LibJS/Value.cpp4
-rw-r--r--Libraries/LibJS/Value.h4
4 files changed, 10 insertions, 10 deletions
diff --git a/Libraries/LibJS/AST.cpp b/Libraries/LibJS/AST.cpp
index bc65f30c11..af0f21aef3 100644
--- a/Libraries/LibJS/AST.cpp
+++ b/Libraries/LibJS/AST.cpp
@@ -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
diff --git a/Libraries/LibJS/Interpreter.cpp b/Libraries/LibJS/Interpreter.cpp
index b62c7db5ca..637736b97e 100644
--- a/Libraries/LibJS/Interpreter.cpp
+++ b/Libraries/LibJS/Interpreter.cpp
@@ -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()
diff --git a/Libraries/LibJS/Value.cpp b/Libraries/LibJS/Value.cpp
index c62c84d496..c4c25b2e1e 100644
--- a/Libraries/LibJS/Value.cpp
+++ b/Libraries/LibJS/Value.cpp
@@ -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();
}
diff --git a/Libraries/LibJS/Value.h b/Libraries/LibJS/Value.h
index 010d8d3e6c..95db26df83 100644
--- a/Libraries/LibJS/Value.h
+++ b/Libraries/LibJS/Value.h
@@ -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;