summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-12-14 12:10:40 +0100
committerAndreas Kling <kling@serenityos.org>2022-12-14 15:11:57 +0100
commit42b5c896e86b0d77d62ecae0ec78802aaff285a1 (patch)
tree9f48119e0ce6e1a3556597c9f96af0e212d74a3f /Userland/Libraries/LibJS
parent3ea1584f2eafc9988bade98cb605ff72c7bcf3e1 (diff)
downloadserenity-42b5c896e86b0d77d62ecae0ec78802aaff285a1.zip
LibJS: Don't "copy construct" temporary value in ThrowCompletionOr ctor
It was possible for the generic ThrowCompletionOr constructor to "copy-construct" a JS Object when instantiating a ThrowCompletionOr via e.g `return *object;`. This happened because it chose the Object(Object& prototype) constructor which will be removed in a subsequent commit. It was not easy to debug. As a first step towards avoiding this in the future, the generic ThrowCompletionOr constructor now takes the value as a const reference.
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Completion.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Completion.h b/Userland/Libraries/LibJS/Runtime/Completion.h
index cae9f8b8ff..0367d25727 100644
--- a/Userland/Libraries/LibJS/Runtime/Completion.h
+++ b/Userland/Libraries/LibJS/Runtime/Completion.h
@@ -268,9 +268,9 @@ public:
// Most commonly: Value from Object* or similar, so we can omit the curly braces from "return { TRY(...) };".
// Disabled for POD types to avoid weird conversion shenanigans.
template<typename WrappedValueType>
- ThrowCompletionOr(WrappedValueType value)
+ ThrowCompletionOr(WrappedValueType const& value)
requires(!IsPOD<ValueType>)
- : m_value(move(value))
+ : m_value(value)
{
}