2021-09-14 18:21:07 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
|
|
|
* Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
|
2022-12-11 18:16:15 +00:00
|
|
|
* Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
|
2021-09-14 18:21:07 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/FlyString.h>
|
2022-02-07 21:48:57 +01:00
|
|
|
#include <AK/WeakPtr.h>
|
2021-09-14 18:21:07 +02:00
|
|
|
#include <LibJS/Forward.h>
|
2022-02-09 10:06:40 +00:00
|
|
|
#include <LibJS/Heap/MarkedVector.h>
|
2021-10-14 16:12:53 +01:00
|
|
|
#include <LibJS/Module.h>
|
2021-10-11 20:29:31 +02:00
|
|
|
#include <LibJS/Runtime/PrivateEnvironment.h>
|
2021-09-14 18:21:07 +02:00
|
|
|
#include <LibJS/Runtime/Value.h>
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2022-09-05 14:31:25 +02:00
|
|
|
using ScriptOrModule = Variant<Empty, NonnullGCPtr<Script>, NonnullGCPtr<Module>>;
|
2022-01-17 14:48:22 +01:00
|
|
|
|
2021-09-14 18:21:07 +02:00
|
|
|
// 9.4 Execution Contexts, https://tc39.es/ecma262/#sec-execution-contexts
|
|
|
|
struct ExecutionContext {
|
2022-12-11 18:16:15 +00:00
|
|
|
explicit ExecutionContext(Heap& heap);
|
|
|
|
|
|
|
|
[[nodiscard]] ExecutionContext copy() const;
|
2021-11-09 20:39:22 +02:00
|
|
|
|
|
|
|
private:
|
2022-12-11 18:16:15 +00:00
|
|
|
explicit ExecutionContext(MarkedVector<Value> existing_arguments);
|
2021-11-09 20:39:22 +02:00
|
|
|
|
|
|
|
public:
|
2021-10-11 20:29:31 +02:00
|
|
|
FunctionObject* function { nullptr }; // [[Function]]
|
|
|
|
Realm* realm { nullptr }; // [[Realm]]
|
2022-01-17 14:48:22 +01:00
|
|
|
ScriptOrModule script_or_module; // [[ScriptOrModule]]
|
2021-10-11 20:29:31 +02:00
|
|
|
Environment* lexical_environment { nullptr }; // [[LexicalEnvironment]]
|
|
|
|
Environment* variable_environment { nullptr }; // [[VariableEnvironment]]
|
|
|
|
PrivateEnvironment* private_environment { nullptr }; // [[PrivateEnvironment]]
|
2021-09-14 18:21:07 +02:00
|
|
|
|
2022-11-21 11:18:15 +01:00
|
|
|
// Non-standard: This points at something that owns this ExecutionContext, in case it needs to be protected from GC.
|
|
|
|
Cell* context_owner { nullptr };
|
|
|
|
|
2021-09-14 18:21:07 +02:00
|
|
|
ASTNode const* current_node { nullptr };
|
|
|
|
FlyString function_name;
|
|
|
|
Value this_value;
|
2022-02-09 10:06:40 +00:00
|
|
|
MarkedVector<Value> arguments;
|
2021-09-14 18:21:07 +02:00
|
|
|
bool is_strict_mode { false };
|
2021-10-14 16:12:53 +01:00
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/webappapis.html#skip-when-determining-incumbent-counter
|
|
|
|
// FIXME: Move this out of LibJS (e.g. by using the CustomData concept), as it's used exclusively by LibWeb.
|
|
|
|
size_t skip_when_determining_incumbent_counter { 0 };
|
2021-09-14 18:21:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|