ladybird/Userland/Libraries/LibJS/Runtime/PromiseJobs.h
Linus Groh 5832de62fe LibJS: Convert NativeFunction::{call,construct}() to ThrowCompletionOr
Both at the same time because many of them call construct() in call()
and I'm not keen on adding a bunch of temporary plumbing to turn
exceptions into throw completions.
Also changes the return value of construct() to Object* instead of Value
as it always needs to return an object; allowing an arbitrary Value is a
massive foot gun.
2021-10-21 09:02:23 +01:00

53 lines
1.4 KiB
C++

/*
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/JobCallback.h>
#include <LibJS/Runtime/NativeFunction.h>
#include <LibJS/Runtime/Promise.h>
namespace JS {
class PromiseReactionJob final : public NativeFunction {
JS_OBJECT(PromiseReactionJob, NativeFunction);
public:
static PromiseReactionJob* create(GlobalObject&, PromiseReaction&, Value argument);
explicit PromiseReactionJob(PromiseReaction&, Value argument, Object& prototype);
virtual ~PromiseReactionJob() override = default;
virtual ThrowCompletionOr<Value> call() override;
private:
virtual void visit_edges(Visitor&) override;
PromiseReaction& m_reaction;
Value m_argument;
};
class PromiseResolveThenableJob final : public NativeFunction {
JS_OBJECT(PromiseReactionJob, NativeFunction);
public:
static PromiseResolveThenableJob* create(GlobalObject&, Promise&, Value thenable, JobCallback then);
explicit PromiseResolveThenableJob(Promise&, Value thenable, JobCallback then, Object& prototype);
virtual ~PromiseResolveThenableJob() override = default;
virtual ThrowCompletionOr<Value> call() override;
private:
virtual void visit_edges(Visitor&) override;
Promise& m_promise_to_resolve;
Value m_thenable;
JobCallback m_then;
};
}