ExecutionContext.h 1.8 KB

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