ExecutionContext.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/FlyString.h>
  9. #include <AK/WeakPtr.h>
  10. #include <LibJS/Forward.h>
  11. #include <LibJS/Heap/MarkedVector.h>
  12. #include <LibJS/Module.h>
  13. #include <LibJS/Runtime/PrivateEnvironment.h>
  14. #include <LibJS/Runtime/Value.h>
  15. namespace JS {
  16. using ScriptOrModule = Variant<Empty, NonnullGCPtr<Script>, NonnullGCPtr<Module>>;
  17. // 9.4 Execution Contexts, https://tc39.es/ecma262/#sec-execution-contexts
  18. struct ExecutionContext {
  19. explicit ExecutionContext(Heap& heap)
  20. : arguments(heap)
  21. {
  22. }
  23. [[nodiscard]] ExecutionContext copy() const
  24. {
  25. ExecutionContext copy { arguments };
  26. copy.function = function;
  27. copy.realm = realm;
  28. copy.script_or_module = script_or_module;
  29. copy.lexical_environment = lexical_environment;
  30. copy.variable_environment = variable_environment;
  31. copy.private_environment = private_environment;
  32. copy.current_node = current_node;
  33. copy.function_name = function_name;
  34. copy.this_value = this_value;
  35. copy.is_strict_mode = is_strict_mode;
  36. return copy;
  37. }
  38. private:
  39. explicit ExecutionContext(MarkedVector<Value> existing_arguments)
  40. : arguments(move(existing_arguments))
  41. {
  42. }
  43. public:
  44. FunctionObject* function { nullptr }; // [[Function]]
  45. Realm* realm { nullptr }; // [[Realm]]
  46. ScriptOrModule script_or_module; // [[ScriptOrModule]]
  47. Environment* lexical_environment { nullptr }; // [[LexicalEnvironment]]
  48. Environment* variable_environment { nullptr }; // [[VariableEnvironment]]
  49. PrivateEnvironment* private_environment { nullptr }; // [[PrivateEnvironment]]
  50. ASTNode const* current_node { nullptr };
  51. FlyString function_name;
  52. Value this_value;
  53. MarkedVector<Value> arguments;
  54. bool is_strict_mode { false };
  55. // https://html.spec.whatwg.org/multipage/webappapis.html#skip-when-determining-incumbent-counter
  56. // FIXME: Move this out of LibJS (e.g. by using the CustomData concept), as it's used exclusively by LibWeb.
  57. size_t skip_when_determining_incumbent_counter { 0 };
  58. };
  59. }