summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-11-14 00:48:15 +0000
committerLinus Groh <mail@linusgroh.de>2021-11-14 15:27:46 +0000
commit68ac13a192a9d15a67e706658aaf808fe0c4fe9f (patch)
tree741b6de1d2f7944899602be607d000ff429503e8 /Userland/Libraries/LibJS
parent01c2570678edad6896e22d1a951002bb5718113e (diff)
downloadserenity-68ac13a192a9d15a67e706658aaf808fe0c4fe9f.zip
LibJS: Add a Completion(ThrowCompletionOr<Value> const&) constructor
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Completion.cpp12
-rw-r--r--Userland/Libraries/LibJS/Runtime/Completion.h2
2 files changed, 14 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Completion.cpp b/Userland/Libraries/LibJS/Runtime/Completion.cpp
index b29a1af86d..09d9a7002b 100644
--- a/Userland/Libraries/LibJS/Runtime/Completion.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Completion.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
+ * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -15,6 +16,17 @@
namespace JS {
+Completion::Completion(ThrowCompletionOr<Value> const& throw_completion_or_value)
+{
+ if (throw_completion_or_value.is_throw_completion()) {
+ m_type = Type::Throw;
+ m_value = throw_completion_or_value.throw_completion().value();
+ } else {
+ m_type = Type::Normal;
+ m_value = throw_completion_or_value.value();
+ }
+}
+
// 6.2.3.1 Await, https://tc39.es/ecma262/#await
ThrowCompletionOr<Value> await(GlobalObject& global_object, Value value)
{
diff --git a/Userland/Libraries/LibJS/Runtime/Completion.h b/Userland/Libraries/LibJS/Runtime/Completion.h
index 26c4c07ae7..f801aa15cf 100644
--- a/Userland/Libraries/LibJS/Runtime/Completion.h
+++ b/Userland/Libraries/LibJS/Runtime/Completion.h
@@ -46,6 +46,8 @@ public:
VERIFY(!m_value->is_empty());
}
+ Completion(ThrowCompletionOr<Value> const&);
+
// 5.2.3.1 Implicit Completion Values, https://tc39.es/ecma262/#sec-implicit-completion-values
// Not `explicit` on purpose.
Completion(Value value)