ExecutionContext.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #include <LibJS/Runtime/ExecutionContext.h>
  9. #include <LibJS/Runtime/FunctionObject.h>
  10. namespace JS {
  11. ExecutionContext::ExecutionContext(Heap& heap)
  12. : arguments(heap)
  13. , local_variables(heap)
  14. {
  15. }
  16. ExecutionContext::ExecutionContext(MarkedVector<Value> existing_arguments, MarkedVector<Value> existing_local_variables)
  17. : arguments(move(existing_arguments))
  18. , local_variables(move(existing_local_variables))
  19. {
  20. }
  21. ExecutionContext ExecutionContext::copy() const
  22. {
  23. ExecutionContext copy { arguments, local_variables };
  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. void ExecutionContext::visit_edges(Cell::Visitor& visitor)
  37. {
  38. visitor.visit(function);
  39. visitor.visit(realm);
  40. visitor.visit(variable_environment);
  41. visitor.visit(lexical_environment);
  42. visitor.visit(private_environment);
  43. visitor.visit(context_owner);
  44. visitor.visit(this_value);
  45. script_or_module.visit(
  46. [](Empty) {},
  47. [&](auto& script_or_module) {
  48. visitor.visit(script_or_module);
  49. });
  50. }
  51. }