ExecutionContext.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 <LibJS/Forward.h>
  10. #include <LibJS/Runtime/MarkedValueList.h>
  11. #include <LibJS/Runtime/PrivateEnvironment.h>
  12. #include <LibJS/Runtime/Value.h>
  13. namespace JS {
  14. using ScriptOrModule = Variant<Empty, Script*, Module*>;
  15. // 9.4 Execution Contexts, https://tc39.es/ecma262/#sec-execution-contexts
  16. struct ExecutionContext {
  17. explicit ExecutionContext(Heap& heap)
  18. : arguments(heap)
  19. {
  20. }
  21. [[nodiscard]] ExecutionContext copy() const
  22. {
  23. ExecutionContext copy { arguments };
  24. copy.function = function;
  25. copy.realm = realm;
  26. copy.script_or_module = script_or_module;
  27. copy.lexical_environment = lexical_environment;
  28. copy.variable_environment = variable_environment;
  29. copy.private_environment = private_environment;
  30. copy.current_node = current_node;
  31. copy.function_name = function_name;
  32. copy.this_value = this_value;
  33. copy.is_strict_mode = is_strict_mode;
  34. return copy;
  35. }
  36. private:
  37. explicit ExecutionContext(MarkedValueList existing_arguments)
  38. : arguments(move(existing_arguments))
  39. {
  40. }
  41. public:
  42. FunctionObject* function { nullptr }; // [[Function]]
  43. Realm* realm { nullptr }; // [[Realm]]
  44. ScriptOrModule script_or_module; // [[ScriptOrModule]]
  45. Environment* lexical_environment { nullptr }; // [[LexicalEnvironment]]
  46. Environment* variable_environment { nullptr }; // [[VariableEnvironment]]
  47. PrivateEnvironment* private_environment { nullptr }; // [[PrivateEnvironment]]
  48. ASTNode const* current_node { nullptr };
  49. FlyString function_name;
  50. Value this_value;
  51. MarkedValueList arguments;
  52. bool is_strict_mode { false };
  53. };
  54. }