ExecutionContext.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
  4. * Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include <AK/DeprecatedFlyString.h>
  10. #include <AK/WeakPtr.h>
  11. #include <LibJS/Forward.h>
  12. #include <LibJS/Heap/MarkedVector.h>
  13. #include <LibJS/Module.h>
  14. #include <LibJS/Runtime/PrivateEnvironment.h>
  15. #include <LibJS/Runtime/Value.h>
  16. namespace JS {
  17. using ScriptOrModule = Variant<Empty, NonnullGCPtr<Script>, NonnullGCPtr<Module>>;
  18. // 9.4 Execution Contexts, https://tc39.es/ecma262/#sec-execution-contexts
  19. struct ExecutionContext {
  20. explicit ExecutionContext(Heap& heap);
  21. [[nodiscard]] ExecutionContext copy() const;
  22. void visit_edges(Cell::Visitor&);
  23. private:
  24. explicit ExecutionContext(MarkedVector<Value> existing_arguments);
  25. public:
  26. GCPtr<FunctionObject> function; // [[Function]]
  27. GCPtr<Realm> realm; // [[Realm]]
  28. ScriptOrModule script_or_module; // [[ScriptOrModule]]
  29. GCPtr<Environment> lexical_environment; // [[LexicalEnvironment]]
  30. GCPtr<Environment> variable_environment; // [[VariableEnvironment]]
  31. GCPtr<PrivateEnvironment> private_environment; // [[PrivateEnvironment]]
  32. // Non-standard: This points at something that owns this ExecutionContext, in case it needs to be protected from GC.
  33. GCPtr<Cell> context_owner;
  34. ASTNode const* current_node { nullptr };
  35. DeprecatedFlyString function_name;
  36. Value this_value;
  37. MarkedVector<Value> arguments;
  38. bool is_strict_mode { false };
  39. // https://html.spec.whatwg.org/multipage/webappapis.html#skip-when-determining-incumbent-counter
  40. // FIXME: Move this out of LibJS (e.g. by using the CustomData concept), as it's used exclusively by LibWeb.
  41. size_t skip_when_determining_incumbent_counter { 0 };
  42. };
  43. }